<?php
include("../includes/site_config.php");
include('../session_handler.inc');
//include("../includes/functions.php");
include("../languages/english_admin.php");
include("include/header.php");
include("../includes/tab_functions.js");
$block = ereg("MSIE",$_SERVER['HTTP_USER_AGENT'])?'block':'table-row';
$Sess_UserType= $_SESSION['Sess_UserType'];
if ($Sess_UserType != "A") {
	exit;
}


if(isset($_REQUEST['opt'])){
$opt=form_get('opt');
$del=mysql_query("DELETE from options where MD5(Name)='$opt'");
}

if(isset($_REQUEST['save']) && $_REQUEST['days']!='' && $_REQUEST['name']!=''){
$days=form_get('days');
$name=form_get('name');
$string= str_replace(' ','', $name);
//$days=$days." days";
$t='$t';
$insOp = "INSERT IGNORE INTO  options set Name='$string', Value='$days', Label='$name', Config='$t = array(
\"min\"=>0,
\"max\"=>99999999
);
return $t;', OptionsGroup_ID='1', Type='numeric', Comments='custom'"; 

mysql_query($insOp) or die(mysql_error());

}


# retrieve the template
//$area = 'member';

# select all parameters from table

//$group= $_REQUEST['group'];

/**
 * Display correct inpur field for current option
 *
 * @param object $option
 * @return string
 *
 */
function display_option($option) {
    $res = "";

    if($option->type=='list' || $option->type=='skin'|| $option->type=='language'){
       $res .= "<select name=\"options[$option->name]\">";
		foreach ($option->list as $value => $label){
            $selected = ($value == $option->value) ? "SELECTED" : "";
			$res .= "<option value=\"$value\" $selected>$label</option>";
   		}
        $res .= "</select>";
    } else {
        $res = "<input class=\"input\" type=\"text\" name=\"options[$option->name]\" value=\"$option->value\"><br>";
		
    }
    return $res;
}
?>
<? include("admin_tabs.php");?>
<style type="text/css">
<!--
.style1 {
	color: #FF0000;
	font-weight: bold;
}
-->
</style>



<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Memberships</div></div>
<div class="clear"></div>
<div class="admin-page">
  <table width="804" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">
    <!--DWLayoutTable-->
  <form method='post' action='<?php echo $CONST_LINK_ROOT?>/admin/com_settings.php<?php print("?PHPSESSID=".session_id()); ?>'>
<?
$manager = &OptionManager::GetInstance();
 $aGroups = $manager->GetGroupList();

//if ($group=== null && count($aGroups)) {
//for($j=0; $j<count($aGroups); $j++){

    //$group = $aGroups[$j]->Name; 
$group = 'payment'; 

 $aOptions = ($group !== null) ? $manager->GetListByGroup($group) : array();
 

?>
<script>
<!--

function switchBlock(id,show){

    if (document.getElementById(id).disabled){
        document.getElementById(id).style.display=show;
        document.getElementById(id).disabled=false;
        document.getElementById(id+'_up').style.display='none';
        document.getElementById(id+'_down').style.display=show;
    }else{
        document.getElementById(id).style.display='none';
        document.getElementById(id).disabled=true;
        document.getElementById(id+'_up').style.display=show;
        document.getElementById(id+'_down').style.display='none';
    }
}

-->
function validMem(){
if(document.memUpg.name.value=='')
{
	alert("Name field can't be blank!");
	document.memUpg.name.focus();
	return (false);
	}
if(document.memUpg.days.value=='')
{
	alert("Days field can't be blank!");
	document.memUpg.days.focus();
	return (false);
}

}
</script>

    
	
	<!-- -->
	
	
	<!--<tr class="tdeven" >
<td align="left" class="links_blue_large" width="25%"><b><?php echo $group ?></b></td>
            <td align="left" valign="top" colspan=2 class=tdunderline> <div id=<?=$group?>_up style="float:left;padding-right:10px;">

                <a href="#" class="switch" onClick="switchBlock('<?=$group?>','<?=$block?>');return false;">[+]</a>

              </div>

              <div id=<?=$group?>_down style="display:none;float:left;padding-right:10px;">

                <a href="#" class="switch" onClick="switchBlock('<?=$group?>','<?=$block?>');return false;">[-]</a>

              </div>

             

            </td>

    </tr>
	
	
          <tr class="<?=$class?>"  id="<?=$group?>" style="display:none" >
		  <td align="left" valign="top">&nbsp; </td>

            <td align="left" valign="top">
			<table border="0" cellpadding="0" cellspacing="0" width="100%">-->

    <?
		
foreach ($aOptions as $option){

//$i=0;
//$class = ($i++%2) ? "tdeven" : "tdodd";
?>
        

            
			<tr>
				
         
           <td  width=160 height="19" align="left" ><?=$option->label?><br></td>
         <td  width=78 align="left" ><?=display_option($option)?><br></td>
          <td  width=563 align="left"><? if($option->comments=='custom'){?> <a href="<?=$_SERVER['PHP_SELF']?>?opt=<?=md5($option->name)?>">delete</a><? }?><br></td>
		  <td width="3"></td>
		</tr>
           <? }?>
		   	<tr align="center">
				<td height="24" colspan="3" class="tdfoot"><input name="Validate2" type="submit" class="normal" value="<?php echo BUTTON_UPDATE ?>"></td>
			    <td></td>
		   	</tr>
			  
			 
			<!--</table>
			
			</td>
          </tr>-->
       <!-- <script language=javascript>document.getElementById('<?=$group?>').disabled = true;</script>-->
    
    
          <?php /*?><tr>
            <td  colspan="3" align="left" valign="top" class="tdhead">&nbsp;</td>
          </tr>
      
          <tr class="tdodd">
		  <td>
			<!--<select name=group onChange="this.form.submit();">-->
<? foreach ($aGroups as $oRow) {
    $selected= ($oRow->Name == $group)? "selected" : "";
?>
				<?php /*?><option value="<?=$oRow->Name?>" <?=$selected?>><?=$oRow->Title?></option>
<? }?>
			<!--</select>-->
		  </td>
		  </tr><?php */?>
		
        
        <input type="hidden" name="group" value="<?=$group?>">
         

  
         <? //}}?>
          <tr>
            <td height="19" colspan="2"  align="left" class="tdhead">&nbsp;</td>
            <td class="tdhead"  align="left">&nbsp;</td>
            <td></td>
          </tr>
    </form>
	<form action="<?=$_SERVER['PHP_SELF']?>" name="memUpg" method="post">
 <tr><td height="19" colspan="3" class="admin-head">Add Custom Membership</td>
   <td></td>
 </tr>
			  <tr><td height="22" align="right" class="blue">Name</td><td colspan="2"><input type="text" name="name" size="30px" /> 
			    i.e. 5000 days Lifetime (see below for notes)</td>
			    <td></td>
			  </tr>
			  <tr><td height="22" align="right" class="blue">Price</td><td colspan="2"><input type="text" name="days" size="10" />
			    Set the price for this membership</td>
			    <td></td>
			  </tr>
			  <tr><td height="24" align="right" class="blue">&nbsp;</td>
		      <td colspan="2"><input type="submit" name="save" value="save" size="10" onclick="return validMem();" /></td>
		      <td></td>
			  </tr>
			  <tr>
			    <td height="36">&nbsp;</td>
			    <td></td>
			    <td></td>
	            <td></td>
	    </tr>
			  <tr>
			    <td height="114" colspan="3" valign="top"><p><span class="style1">Note: </span>When you put the name you must format the name as follows: 5000 days Name<br />
		        So, for example, if you wanted to put a Lifetime Membership and have it expire in 5000 days then you would put: </p>
		        <p>5000 days Lifetime</p>			      <p>If you have any questions, be sure to read the Admin Guide. It will explain this feature in greater detail.</p></td>
        <td></td>
	    </tr>
</form>
</table>
</div><div class="admin-page-bottom"></div></div>



<?php include("include/footer.php"); ?>
