<?
include_once('../hdr_general.php');
/* **************************************************************************************************** */
if (!isset($_REQUEST["module"])) $_REQUEST["module"] = "general";
if (!isset($_REQUEST["task"])) $_REQUEST["task"] = "main";
$pubmodule = $_REQUEST["module"];
$pubtask = $_REQUEST["task"];
$pubitemid = $_REQUEST["itemid"];
$pubsuppliers = $_REQUEST["suppliers"];
$selected=explode(";",$pubsuppliers);
/* **************************************************************************************************** */
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../css/<?=$_SESSION['Xcssfile'];?>" type="text/css" media=all>
<title>Purchasing Online (ZIKAY)</title>

<script type="text/javascript">

function hiliteSupplier(cbox) {
  var lbox=cbox.parentNode;
  if (cbox.checked) {
    lbox.style.cssText="display: block; background: #80ffff;";
  } else {
    lbox.style.cssText="display: block; background: #ffffff;";
  }
}

function acceptSelect() {

  var pkeystr="";
  var namestr="";
  var unapprovedfound=false;

  //var suppList = opener.document.getElementById("itq_suppliers");
  //var pkeyList = opener.document.getElementById("itq_supppkey");
  //var nameList = opener.document.getElementById("itq_suppname");

  // clear the list 
  //for (var count = suppList.options.length-1; count >-1; count--)
  //{
  //  suppList.options[count] = null;
  //}

  // populate the dropdown list..
  //var idValue;
  //var textValue; 
  //var optionItem;

  for (i=1;i<=2000;i++) {
    var subcheck=document.getElementById('check'+i);
    var subname=document.getElementById('sname'+i);
    if (subcheck!=null) {
      if (subcheck.checked) {
        //idValue = new String(subcheck.value);
    	//textValue = new String(subname.value);
        //optionItem = new Option(textValue,idValue, false, false);
        //suppList.options[suppList.length] = optionItem;
        pkeystr=pkeystr+";"+subcheck.value;
        namestr=namestr+"\r\n"+subname.value;
      }
    }
  }
  for (i=1;i<=2000;i++) {
    var subcheckun=document.getElementById('checkun'+i);
    var subnameun=document.getElementById('snameun'+i);
    if (subcheckun!=null) {
      if (subcheckun.checked) {
        pkeystr=pkeystr+";"+subcheckun.value;
        namestr=namestr+"\r\n"+subnameun.value;
        unapprovedfound=true;
      }
    }
  }
  pkeystr=pkeystr.substr(1);
  namestr=namestr.substr(2);
  opener.document.itqform.itq_supppkey.value = pkeystr;
  opener.document.itqform.itq_suppliers.value = namestr;
  if (unapprovedfound==true) {
    opener.document.itqform.itq_approvealert.value = "1";
  } else {
    opener.document.itqform.itq_approvealert.value = "0";
  }
  self.close();
}

function cancelSelect() {
  self.close();
}

</script>

</head>
<body leftmargin=5 topmargin=5 style="background: #ffffff;">
<table border=0 cellspacing=0 cellpadding=0 width=578>

<tr valign=top>
<td valign=top width=100%>

  <?
  include_once('../models/supplierModel.php');
  $mysupplierModel=new supplierModel;

  $supplier_list = $mysupplierModel->getlist_suppliers("supplier_name","ASC","","1","1","");
  ?>

  <table border=1 cellspacing=1 cellpadding=2 width=568 style="border: 1px inset;">

  <tr valign=top>
  <td valign=top width=568 colspan=2 class=listheader style="border-bottom: 1px solid;">
  Select Supplier :
  </td>
  </tr>

  <tr valign=top>
  <td valign=top width=48 class=listheader>No.</td>
  <td valign=top width=520 class=listheader>Supplier Name (Products) - Approved</td>
  </tr>

  <? foreach ($supplier_list as $mysupplier) { ?>

    <?
    $mychecked="";
    $mycolor="#ffffff";
    foreach ($selected as $mysel) {
      if ($mysupplier['supplier_pkey']==$mysel) {
        $mychecked="checked";
        $mycolor="#80ffff";
      }
    }
    ?>

    <tr valign=top>
    <td valign=top width=48 class=listnumber><?=$mysupplier['recordno'];?></td>
    <td valign=top width=520 class=listcontent>
    <label style="display: block; background: <?=$mycolor;?>;">
    <input name="check<?=$mysupplier['recordno'];?>" id="check<?=$mysupplier['recordno'];?>" type="checkbox" value="<?=$mysupplier['supplier_pkey'];?>" <?=$mychecked;?> onChange="hiliteSupplier(this);" onClick="hiliteSupplier(this);">
    <input name="sname<?=$mysupplier['recordno'];?>" id="sname<?=$mysupplier['recordno'];?>" type="hidden" value="<?=$mysupplier['supplier_name'];?>">
    &nbsp;&nbsp;<?=$mysupplier['supplier_name'];?> (<?=$mysupplier['supplier_products'];?>)
    </label>
    </td>
    </tr>

  <? } ?>

  </table>

  <?
  if (($pubuseraccess['access_supplier_approve']=="1")||($pubuserrole>=2)) {
  ?>

    <?
    $unapproved_list = $mysupplierModel->getlist_suppliers("supplier_name","ASC","","0","0","");
    ?>

    <br>
    <table border=1 cellspacing=1 cellpadding=2 width=568 style="border: 1px inset;">

    <tr valign=top>
    <td valign=top width=48 class=listheader>No.</td>
    <td valign=top width=520 class=listheader>Supplier Name (Products) - NOT Approved</td>
    </tr>

    <? foreach ($unapproved_list as $myunapproved) { ?>

      <?
      $mychecked="";
      $mycolor="#ffffff";
      foreach ($selected as $mysel) {
        if ($myunapproved['supplier_pkey']==$mysel) {
          $mychecked="checked";
          $mycolor="#80ffff";
        }
      }
      ?>

      <tr valign=top>
      <td valign=top width=48 class=listnumber><?=$myunapproved['recordno'];?></td>
      <td valign=top width=520 class=listcontent>
      <label style="display: block; background: <?=$mycolor;?>;">
      <input name="checkun<?=$myunapproved['recordno'];?>" id="checkun<?=$myunapproved['recordno'];?>" type="checkbox" value="<?=$myunapproved['supplier_pkey'];?>" <?=$mychecked;?> onChange="hiliteSupplier(this);" onClick="hiliteSupplier(this);">
      <input name="snameun<?=$myunapproved['recordno'];?>" id="snameun<?=$myunapproved['recordno'];?>" type="hidden" value="<?=$myunapproved['supplier_name'];?>">
      &nbsp;&nbsp;<?=$myunapproved['supplier_name'];?> (<?=$myunapproved['supplier_products'];?>)
      </label>
      </td>
      </tr>

    <? } ?>

    </table>

  <? } ?>

  <br>
  <table border=1 cellspacing=1 cellpadding=2 width=568>
  <tr valign=top>
  <td valign=top width=568 class=listcontent>
  <button name="update" id="update" onClick="acceptSelect();">Accept Selections</button>&nbsp;
  <button name="cancel" id="cancel" onClick="cancelSelect();">Cancel</button>
  </td>
  </tr>
  </table>

</td>
</tr>
</table>

</body>
</html>