<?
/* index.php: $pubmodule, $pubtask, $pubitemid */
/*
$pubsubjectid = $_REQUEST["subjectid"];
$pubtypeid = $_REQUEST["typeid"];
$pubgroupid = $_REQUEST["groupid"];
*/

// filter forms..
$filtersubconname=$_POST['subconname'];
?>

<script type="text/javascript">

// ................................................................................
// user-interaction handlers..
// ................................................................................

function subcon_button_search() {
  document.subconform.job.value='subcon_search';
  document.subconform.submit();
}

function subcon_button_add() {
  <?php 
  # myapit issue no 4
  # document.subconform.job.value='subcon_add';
  # document.subconform.submit();
  ?>
  document.location='index.php?module=subcon&task=add';
}

function subcon_button_edit() {
  document.subconform.job.value='subcon_edit';
  document.subconform.submit();
}

function subcon_button_remove() {
  document.subconform.job.value='subcon_remove';
  document.subconform.submit();
}

function subcon_button_back() {
  history.go(-1);
}

<?php # myapit issue no 4 # TODO: myapit validation ?>
function subcon_button_save() {	//(accesslevel,userrole) {
  if (validateForm()==true) {		//accesslevel,userrole)==true) {
    document.subconform.job.value='subcon_add'; document.subconform.submit();
  }
}
function subcon_button_update() {	//(accesslevel,userrole) {
	  if (validateForm()==true) {		//accesslevel,userrole)==true) {
	    document.subconform.job.value='subcon_edit'; document.subconform.submit();
	  }
}
	  
function subcon_button_purge() {
		document.subconform.job.value='subcon_remove';
		document.subconform.submit();
	  //alert('testing123'+document.getElementById('job').value);
}	  

function subcon_button_backtolist() {
  document.location='index.php?module=subcon&task=main';
}
<?php # myapit end ?>
</script>

<?

// ................................................................................
// model..
// ................................................................................

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

// ................................................................................
// default to list view if none specified..
// ................................................................................
if ($pubtask=="") $pubtask="main";

// ................................................................................
// display page header..
// ................................................................................

$pagetitle="Master Data";
if (($pubtask=="main")||($pubtask=="submenu")) {
  $subtitle="Sub-contractors List";
} else if ($pubtask=="view") {
  $subtitle="Sub-contractor Information";
} else if ($pubtask=="add") {
  $subtitle="Add Sub-contractor Information";
} else if ($pubtask=="edit") {
  $subtitle="Edit Sub-contractor Information";
} else if ($pubtask=="delete") {
  $subtitle="Delete Sub-contractor Information";
    
} else {
  $subtitle="Error: Invalid Option";
}

$headercaption=$pagetitle." --&raquo; ".$subtitle;
include_once('header.php');

include_once('views/general-header.tpl');


// TODO: Later to show list of available variables here if in DEBUG mode!!

// ................................................................................
// display main area..
// ................................................................................

if (($pubtask=="main")||($pubtask=="submenu")) {

  $subcon_list = $mysubconModel->getlist_subcons();
  include_once('views/subcon-list.tpl');

} else if ($pubtask=="view") {
  $subcon_data = $mysubconModel->getdata_subcon($pubitemid);
  include_once('views/subcon-view.tpl');
  
# myapit start issue no 4
} else if ((($pubtask=="add")||($pubtask=="edit"))&&(($pubuseraccess['access_subcon_edit']==1)||($pubuserrole>=2)) ) {
  $subcon_data = $mysubconModel->getdata_subcon($pubitemid); 
  include_once('views/subcon-add.tpl');
   
} else if ((($pubtask=="delete"))&&(($pubuseraccess['access_subcon_edit']==1)||($pubuserrole>=2))) {
    $subcon_data = $mysubconModel->getdata_subcon($pubitemid);
    //echo "---".$pubitemid;
    include_once('views/subcon-view.tpl');
    
# end isu no 4
} else {
  include_once('views/general-invalidtask.php');
}

// ...............................................................................
// display button options area..
// ...............................................................................

$prevurl = explode('/',$_SESSION['Xpreviousurl']);
$prevfile = $prevurl[count($prevurl)-1];
if ($prevfile=='inputController.php') $backstatus="style='display: none;'";

echo "<br>";

if (($pubtask=="main")||($pubtask=="submenu")) {

  echo "<br><hr size=1>";
  # myapit issue no 4
  if (($pubuseraccess['access_subcon_edit']==1)||($pubuserrole>=2)) {
    echo "<button name=\"add\" id=\"add\" onClick=\"subcon_button_add();\"><img src='gfx/options/b_add.png' class='actionbutton'>&nbsp;&nbsp;Add New Sub Con</button>&nbsp;";
  }
  # myapit end
  //echo "<button name=\"print\" id=\"print\" onClick=\"javascript:subcon_button_printlist();\">&nbsp;<img src='gfx/options/b_print1.png' class='actionbutton'>&nbsp;&nbsp;Print&nbsp;</button>&nbsp;";
  //edit 17-08-2010
  //echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"subcon_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";
  
 # myapit issue no 4 
 } else if (($pubtask=="add")&&(($pubuseraccess['access_subcon_edit']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  if (($pubuseraccess['access_subcon_edit']==1)||($pubuserrole>=2)) {
    echo "<button name=\"save\" id=\"save\" onClick=\"subcon_button_save();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Save Sub Con</button>&nbsp;";
  }
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"subcon_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";
  
  
} else if (($pubtask=="edit")&&(($pubuseraccess['access_subcon_edit']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  if (($pubuseraccess['access_subcon_edit']==1)||($pubuserrole>=2)) {
    echo "<button name=\"update\" id=\"update\" onClick=\"subcon_button_update();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Update Sub Con</button>&nbsp;";
  }
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"subcon_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";
  
} else if (($pubtask=="delete")&&(($pubuseraccess['access_subcon_edit']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  if (($pubuseraccess['access_subcon_edit']==1)||($pubuserrole>=2)) {
    echo "<font color='#ff0000'><b>ARE YOU SURE TO PERMANENTLY DELETE THIS SUB CONTRACTOR ?</b></font><br><br>";
    echo "<button name=\"delete\" id=\"delete\" onClick=\"subcon_button_purge();\">&nbsp;Yes, Delete Sub Contractor&nbsp;</button>&nbsp;";
  }
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"subcon_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<brp><hr size=1><br>";
  
 # myapit end
} else if ($pubtask=="view") {

  echo "<br><hr size=1>";
  //echo "<button name=\"print\" id=\"print\" onClick=\"javascript:subcon_button_print('".$pubitemid."');\">&nbsp;<img src='gfx/options/b_print1.png' class='actionbutton'>&nbsp;&nbsp;Print&nbsp;</button>&nbsp;";
  if (($pubuseraccess['access_subcon_edit']==1)||($pubuserrole>=2)) {
    echo "<br><hr size=1>";  
    echo "<button name=\"edit\" id=\"edit\" onClick=\"window.location.href='index.php?module=subcon&task=edit&itemid=".$pubitemid."';\">&nbsp;<img src='gfx/options/b_edit.png' class='actionbutton'>&nbsp;&nbsp;Edit&nbsp;</button>&nbsp;";
    echo "<button name=\"delete\" id=\"delete\" onClick=\"window.location.href='index.php?module=subcon&task=delete&itemid=".$pubitemid."';\"><img src='gfx/options/b_drop.png' class='actionbutton'>&nbsp;&nbsp;Delete</button>&nbsp;";
    //echo "<button name=\"delete\" id=\"delete\" onClick=\"\">&nbsp;Yes, Delete Sub Contractor&nbsp;</button>&nbsp;";
   // echo '<a href="index.php?module=subcon&task=edit&itemid='.$pubitemid.'"><img src="gfx/options/b_edit.png" border=0 title="Edit" alt="Edit"></a>';
   // echo '<a href="index.php?module=subcon&task=delete&itemid='.$pubitemid.'"><img src="gfx/options/b_drop.png" border=0 title="Delete" alt="Delete"></a>';
 }  
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"subcon_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

}

// ................................................................................
// display page footer..
// ................................................................................

include_once('views/general-footer.tpl');

?>
