<?php
include("../include/session.php");
if( !$session->isAdmin()){
	//header("Location: ../Store/storeMenu.php");?>
<script language="javascript" type="text/javascript">
        <!--
		  window.location="denied.php";
        -->
       </script>
<?php 
}else{
	include("../storeHeader.php");
	    
	$list_item = "";
    $page = $_GET['page_select'];
  
   $table_name = '';
   if ($page=="places") { $table_name = "nam_rad_list_places"; }
   if ($page=="country") { $table_name = "nam_rad_list_country"; }
   if ($page=="designation") { $table_name = "nam_rad_list_designation"; }
   if ($page=="make") { $table_name = "nam_rad_list_vehicle"; }
   if ($page=="model") { $table_name = "nam_rad_list_model"; }
   
   
   $set = $_GET['set'];
   
    
if ($set==0) {
	
    $page_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC ";
	$arrId2 = array ();
	$arrName2 = array ();
	$page_result = execsql($page_query);
	if ($page_result!="") {
	$page_num = mysql_num_rows($page_result);
	$b = 0;
	while ($b < $page_num) {
		$arrId2[$b] = mysql_result($page_result, $b, "item_name");
		$arrName2[$b] = mysql_result($page_result, $b, "item_name");
		$b++;
	}
	}
}

if ($set==1) {
	$item = $_GET['item_text'];
	
    $item_query  = "INSERT INTO $table_name (item_name) VALUES ('" . $item . "')";
    execsql($item_query);
	
	
    $page_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId2 = array ();
	$arrName2 = array ();
	$page_result = execsql($page_query);
	$page_num = mysql_num_rows($page_result);
	$b = 0;
	while ($b < $page_num) {
		$arrId2[$b] = mysql_result($page_result, $b, "item_name");
		$arrName2[$b] = mysql_result($page_result, $b, "item_name");
		$b++;
	}
}

if ($set==2) {
	
	$list_item = $_GET['list_select'];
	
	$del_query = "DELETE FROM $table_name WHERE  item_name ='".$list_item."'";
	$del_result = execsql($del_query);
    $message= "<font color=red><b>Permission was removed.</b></font>";
	
	$page_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId2 = array ();
	$arrName2 = array ();
	$page_result = execsql($page_query);
	$page_num = mysql_num_rows($page_result);
	$b = 0;
	while ($b < $page_num) {
		$arrId2[$b] = mysql_result($page_result, $b, "item_name");
		$arrName2[$b] = mysql_result($page_result, $b, "item_name");
		$b++;
	}
}
	

	
	
?>
<script type="text/javascript" src="../css/tablesort.js"></script>
<link href="../css/main.css" rel="stylesheet" type="text/css" />


<script type="text/javascript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<link href="../css/wizard.css" rel="stylesheet" type="text/css" />
<div class="headerbox2">Pre defined lists</div>
<table id="tabledisplay_3"  >
  <tr>
    <td height="104" colspan="3" align="left" valign="top">
      <br />
       <div id="coloredContainer">
        <form name="form1" id="form1" action="dropList.php" method="get">
          <label class="std">Select a pre-defined list to manage: &nbsp;&nbsp;</label>
          <select name="page_select" id="page_select" class="wizard2">
            <option value="country">country</option>
            <option value="designation">designation</option>
            <option value="make">make</option>
            <option value="model">model</option>
            <option value="places">places</option>
            <option value=" " selected="selected"></option>
          </select>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <input name="button" type="submit" class="imagebutton" id="button" value="Select" />
          <input name="set" type="hidden" id="set" value="0" />
        </form>
        <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("user_select","req","Please select user.");
  </script>
      </div>
    </td>
  </tr>
  <tr>
    <td height="42" colspan="3" valign="top"><div id="coloredContainer">
      <label class="std">listing  for:&nbsp;&nbsp;&nbsp;<font size="3"><?php echo $page ?></font></label>
    </div></td>
  </tr>
  <tr>
    <td width="255" height="158" valign="top"><div id="coloredContainer3">
      <form action="dropList.php" method="get" name="remove_form" id="remove_form">
        <select name="list_select" size="20" class="wizard4" >
          <?php
        	for ($j = 0; $j < count($arrId2); $j++) {
    		echo "<option value=" . "\"" . $arrId2[$j] . "\"" . ">" . $arrName2[$j] . "</option>";
	}
?>
        </select>
        <p>To remove an item, select the item<br />
          in the above list and click 'Remove'<br />
          <br />
          <input name="button3" type="submit" class="imagebutton" id="button3" value="Remove" />
          <input name="page_select" type="hidden" id="page_select" value="<?php echo $page?>" />
          <input name="set" type="hidden" id="set" value="2" />
          <br />
        </p>
      </form>
      <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("remove_form");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("permission_select","req","Please select permission to remove.");
</script>
    </div></td>
    <td width="68" height="158" valign="top">&nbsp;</td>
    <td width="286"  valign="top"><div id="coloredContainer3" >Type the name of the item and click &quot;add&quot; to add it to the list.<br />
      <br />
      <form action="dropList.php" method="get" name="set_form" id="set_form">
        &nbsp;&nbsp;
        <input name="item_text" type="text" class="wizard1" id="item_text" onblur="capitalize(this)" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
        <br />
        &nbsp;
        <input name="button2" type="submit" class="imagebutton" id="button2" value="Add" />
        <input name="page_select" type="hidden" id="page_select" value="<?php echo $page ?>" />
        <input name="set" type="hidden" id="set" value="1" />
      </form>
      <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("set_form");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("page_select","req","Please select permission to set.");
    </script>
    </div></td>
  </tr>
</table>



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

?>