<?
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"];
$pubsubcons = $_REQUEST["subcons"];
$selected=explode(";",$pubsubcons);
/* **************************************************************************************************** */
?>
<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 hiliteSubcon(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 subcons="";
  var subnames="";
  var subpkeys="";
  var j=0;
  for (i=1;i<=5000;i++) {
    var subcheck=document.getElementById('check'+i);
    var subname=document.getElementById('sname'+i);
    if (subcheck!=null) {
      if (subcheck.checked) {
        j++;
        subpkeys=subpkeys+";"+subcheck.value;
        subcons=subcons+j+". "+subname.value+"\r\n";
        subnames=subnames+";"+subname.value;
      }
    }
  }
  subpkeys=subpkeys.substr(1);
  subnames=subnames.substr(1);
  subcons="Debit to:\r\n"+subcons;
  if (j==0) {
    opener.document.mroform.mro_remarks.value = "";
    opener.document.mroform.mro_debitaccount.value = "";
    opener.document.mroform.mro_subconname.value = "";
  } else if (j==1) {
    opener.document.mroform.mro_debitaccount.value = subpkeys;
    opener.document.mroform.mro_subconname.value = subnames;
    opener.document.mroform.mro_remarks.value = "";
  } else if (j>1) {
    opener.document.mroform.mro_remarks.value = subcons;
    opener.document.mroform.mro_debitaccount.value = "";
    opener.document.mroform.mro_subconname.value = "Please Refer Remarks";
  }
  opener.document.mroform.mro_subcons.value = subpkeys;
  self.close();
}

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

</script>

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

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

  <?
  include_once('../models/subconModel.php');
  $mysubconModel=new subconModel;

  $subcon_list = $mysubconModel->getlist_subcons();
  ?>

  <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 Sub-contractor :
  </td>
  </tr>

  <tr valign=top>
  <td valign=top width=48 class=listheader>No.</td>
  <td valign=top width=520 class=listheader>Sub-contractor Name</td>
  </tr>

  <? foreach ($subcon_list as $mysubcon) { ?>

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

    <tr valign=top>
    <td valign=top width=48 class=listnumber><?=$mysubcon['recordno'];?></td>
    <td valign=top width=520 class=listcontent>
    <label style="display: block; background: <?=$mycolor;?>;">
    <input name="check<?=$mysubcon['recordno'];?>" id="check<?=$mysubcon['recordno'];?>" type="checkbox" value="<?=$mysubcon['subconmasterpkey'];?>" <?=$mychecked;?> onChange="hiliteSubcon(this);" onClick="hiliteSubcon(this);">
    <input name="sname<?=$mysubcon['recordno'];?>" id="sname<?=$mysubcon['recordno'];?>" type="hidden" value="<?=$mysubcon['subconname'];?>">
    &nbsp;&nbsp;<?=$mysubcon['subconname'];?>
    </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>