<?php
include_once("../include/main.inc.php");
include_once("../ajax_functions.php");
check_session('MyCpanel','index.php');
$record=$_REQUEST['recordID'];
if($_POST['submit'])
{
$record=$_REQUEST['recordID'];
$cids=$_POST['sps'];
$cids1=implode("^", $cids);
$ins=mysql_query("update member_tbl set premiumMember='Y', pcat='$cids1' where memberID='$record'");

?>

<script type="text/javascript">
        function RefreshParent() {
            if (window.opener != null && !window.opener.closed) {
                window.opener.location.reload();
            }
        }
		
        window.onbeforeunload = RefreshParent;
		
</script>

<?php
}
?>
<HTML>
<HEAD>
    <STYLE type="text/css">
 
    body { font-family:Arial; }
    a { color:#00f; text-decoration:none; }
 
    </STYLE>
 
    <SCRIPT type="text/javascript">
     
    function listbox_move(listID,direction){
    var listbox=document.getElementById(listID);
    var selIndex=listbox.selectedIndex;
    if(-1==selIndex){alert("Please select an option to move.");return;}
    var increment=-1;
    if(direction=='up')
        increment=-1;
    else
        increment=1;
    if((selIndex+increment)<0||(selIndex+increment)>(listbox.options.length-1)){return;}
     
    var selValue=listbox.options[selIndex].value;
    var selText=listbox.options[selIndex].text;
    listbox.options[selIndex].value=listbox.options[selIndex+increment].value;
    listbox.options[selIndex].text=listbox.options[selIndex+increment].text;
    listbox.options[selIndex+increment].value=selValue;
    listbox.options[selIndex+increment].text=selText;
    listbox.selectedIndex=selIndex+increment;
    }
 
    function listbox_moveacross(sourceID,destID){
    var src=document.getElementById(sourceID);
    var dest=document.getElementById(destID);
     
    var picked1 = false;
    for(var count=0;count<src.options.length;count++){
        if(src.options[count].selected==true){picked1=true;}
    }
 
    if(picked1==false){alert("Please select an option to move.");return;}
 
    for(var count=0;count<src.options.length;count++){
        if(src.options[count].selected==true){var option=src.options[count];
            var newOption=document.createElement("option");
            newOption.value=option.value;
            newOption.text=option.text;
            newOption.selected=true;
            try{dest.add(newOption,null);
            src.remove(count,null);
        }
            catch(error){dest.add(newOption);src.remove(count);
        }
        count--;
        }
    }}
 
    function listbox_selectall(listID,isSelect){
        var listbox=document.getElementById(listID);
        for(var count=0;count<listbox.options.length;count++){
            listbox.options[count].selected=isSelect;
            }
    }
 
    </SCRIPT>
 
 
</HEAD>
 
<BODY>
<form name="" method="post" action="">
 <table border="0" align="center" style="border-collapse:collapse;">
<tr>
<td colspan="5" align="center"><font size="+2"><b>Set Member To Premium</b></font></td>
</tr>
<tr valign="top">
<br>

<th colspan="3">Move left/right</th>
<br>
</tr>
<tr valign="top">

<td>

	<select id="s" multiple size="20" name="sp[]">
	
	<?php
	$catQry=db_query("select catID, catName from  category_tbl where parentID='0' order by catOrder asc");
	while($catRes=mysql_fetch_array($catQry)) {
		
		if(trim($catRes[catID])==trim($value)) {
		echo "<option value='".$catRes[catID]."' selected='selected'><strong>".$catRes[catName]."</strong></option>";
		$qry=db_query("select catID from category_tbl where parentID='".$catRes[catID]."' and status='Y' order by catName");
		$num=NumRows($qry);
		if($num>0) {
			
			while($row=mysql_fetch_array($qry)) {
			echo "<option value='".$row[catID]."' selected='selected'>".$row[catName]."</option>";
			}
			}
		}
		else {
		echo "<option value='".$catRes[catID]."'>".$catRes[catName]."</option>";
		$qry=db_query("select catID, catName from category_tbl where parentID='".$catRes[catID]."' and status='Y' order by catName");
		$num=NumRows($qry);
		if($num>0) {
			
			while($row=mysql_fetch_array($qry)) {
			echo "<option value='".$row[catID]."'>-".$row[catName]."</option>";
			}
			}
		}
	}
	?>
	
	</select>
 

</td>
<td valign="middle">
<a href="#" onclick="listbox_moveacross('s', 'd')">Add</a>
<br/>
<a href="#" onclick="listbox_moveacross('d', 's')">Remove</a>
</td>
<td>
<?php
 $sql=mysql_query("select * from member_tbl where memberID='$record'");
 $res=mysql_fetch_array($sql);
 $catid=$res['pcat'];
 $catids=explode("^", $catid);
 ?>
<SELECT id="d" size="20" multiple name="sps[]">
 <?php
 foreach($catids as $ba[x])
 {
 $catQry=db_query("select catID, catName from category_tbl where catID='$ba[x]' ");
 $catres=mysql_fetch_array($catQry);
 ?>
 
 <option value="<?php echo $catres[catID]; ?>"><?php echo $catres[catName]; ?></option>
 <?php
 }
 ?> 

</SELECT>
</td>
</tr>
<tr>
<td colspan="2">
Select
<a href="#" onclick="listbox_selectall('s', true)">all</a>,
<a href="#" onclick="listbox_selectall('s', false)">none</a>
</td>
<td>
</td>
<tr><td colspan="3" align="center"><input type="submit" name="submit" value="Set Premium"  /></td></tr>
<!--<td>
Select
<a href="#" onclick="listbox_selectall('d', true)">all</a>,
<a href="#" onclick="listbox_selectall('d', false)">none</a>
</td>-->
</tr>
</table>
</form>
</BODY>
</HTML>