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

// filter forms..
$filtermrono1=$_POST['mrono1'];
$filtermrodate1=$_POST['mrodate1'];
$filtermrono2=$_POST['mrono2'];
$filtermrodate2=$_POST['mrodate2'];
$filtertabid=$_POST['tabid'];
$_SESSION['Xactivetab']=$filtertabid;
/*
$filtersessionname=$_POST['sessionname'];
$filteruserpkey=$_POST['userpkey'];
$filterstartdate=$_POST['startdate'];
$filterstopdate=$_POST['stopdate'];
$realstartdate=converttounix($filterstartdate);
$realstopdate=converttounix($filterstopdate)+86399;
*/

$pubpageno1 = $_REQUEST['pageno1'];
if ($pubpageno1=="") $pubpageno1=1;
$pubpageno2 = $_REQUEST['pageno2'];
if ($pubpageno2=="") $pubpageno2=1;
?>

<script type="text/javascript">

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

/*
function browse_tree_open(catnode,nodeno) {
  document.getElementById(catnode).style.cssText="display: block;";
  document.getElementById('open'+nodeno).style.cssText="display: none; cursor: hand;";
  document.getElementById('close'+nodeno).style.cssText="display: block; cursor: hand;";
  document.getElementById('spanopen'+nodeno).style.cssText="display: none; cursor: hand;";
  document.getElementById('spanclose'+nodeno).style.cssText="display: inline; cursor: hand;";
}

function browse_tree_close(catnode,nodeno) {
  document.getElementById(catnode).style.cssText="display: none;";
  document.getElementById('open'+nodeno).style.cssText="display: block; cursor: hand;";
  document.getElementById('close'+nodeno).style.cssText="display: none; cursor: hand;";
  document.getElementById('spanopen'+nodeno).style.cssText="display: inline; cursor: hand;";
  document.getElementById('spanclose'+nodeno).style.cssText="display: none; cursor: hand;";
}

function browse_tree_select(categorypkey,categoryname,subjectpkey,subjectname) {
  document.getElementById('newclass').innerHTML=categoryname+' -> '+subjectname;
  document.getElementById('page_subjectpkey').value=subjectpkey;
}

function browse_button_search() {
  var keywords=document.getElementById('searchkeywords');
  var searchtitle=document.getElementById('searchsearchtitle');
  var searchheaders=document.getElementById('searchsearchheaders');
  var searchcontent=document.getElementById('searchsearchcontent');
  if (keywords.value=="") {
    alert('Error: No Keywords specified!');
  } else if ((searchtitle.checked==false)&&(searchheaders.checked==false)&&(searchcontent.checked==false)) {
    alert('Error: At least one search option (Title/Headers/Content) must be selected!');
  } else {
    document.browseform.job.value='browser_search'; document.browseform.submit();
  }
}

function browse_button_treeview() {
  document.location='index.php?module=browser&task=byclasstree';
}

function browse_button_normalview() {
  document.location='index.php?module=browser&task=byclass';
}

function browse_button_updateratings() {
  // go thru rows and compile strings..
  var mypkey = "";
  var myrate = "";
  // get values..
  for(var i=0;i<20;i++){
    var pkeyfield = document.getElementById('pkey'+i);
    if (pkeyfield!=null) mypkey += "|"+pkeyfield.getAttribute('value');
    for(var j=1;j<=10;j++) {
      var ratefield = document.getElementById('rate'+i+j);
      if (ratefield!=null) {
        if (ratefield.checked) {
          myrate += "|"+j;
        }
      }
    }
  }
  document.rateform.fullpkey.value=mypkey.substr(1);
  document.rateform.fullratings.value=myrate.substr(1);
  document.rateform.submit();
}

function browse_button_updatetags() {
  document.tagform.submit();
}

function browse_button_updateclass() {
  document.classificationform.submit();
}

function browse_button_showheadings() {
  document.getElementById('divheadings').style.cssText="display: block;";
  document.getElementById('showheadings').style.cssText="display: none;";
  document.getElementById('hideheadings').style.cssText="display: inline;";
}

function browse_button_hideheadings() {
  document.getElementById('divheadings').style.cssText="display: none;";
  document.getElementById('hideheadings').style.cssText="display: none;";
  document.getElementById('showheadings').style.cssText="display: inline;";
}

function browse_button_showothersratings() {
  document.getElementById('divothersrating').style.cssText="display: block;";
  document.getElementById('showotherrating').style.cssText="display: none;";
  document.getElementById('hideotherrating').style.cssText="display: inline;";
}

function browse_button_hideothersratings() {
  document.getElementById('divothersrating').style.cssText="display: none;";
  document.getElementById('hideotherrating').style.cssText="display: none;";
  document.getElementById('showotherrating').style.cssText="display: inline;";
}

function browse_button_addsubject(subjectname) {
  // add subject with no category specified (different behaviour in add page - i.e. has dropdown list of cats)
  document.location='index.php?module=classifier&task=subjectadd&subjectname='+escape(subjectname);
}

function browse_button_addnclassify(pagepkey,subjectname) {
  document.location='index.php?module=classifier&task=subjectadd&subjectname='+escape(subjectname)+'&assignto='+pagepkey;
}

function browse_button_discardheading(pagepkey,subjectname) {
  document.location='index.php?module=classifier&task=discardheading&itemid='+pagepkey+'&subjectname='+escape(subjectname);
}

function browse_button_formatpage() {
  document.formatform.submit();
}

function browse_button_exportpage() {
  document.exportform.submit();
}

function browse_button_refreshpage() {
  document.otherform.job.value='browser_refresh';
  document.otherform.submit();
}

function browse_button_purgepage() {
  if (confirm('Are you sure to purge this Web page?')) {
    document.otherform.job.value='browser_purge';
    document.otherform.submit();
  }
}

function browse_button_shortlist() {
  document.otherform.job.value='browser_shortlist';
  document.otherform.submit();
}

function browse_button_actiontaken(pagepkey) {
  if (confirm('Are you sure to mark this page as completed?')) {
    document.location='index.php?module=browser&task=actiontaken&itemid='+pagepkey;
  }
}

function browse_button_viewpage(pagepkey) {
  document.location='index.php?module=browser&task=view&itemid='+pagepkey;
}

function browse_button_unignorepage(pagepkey) {
  document.location='index.php?module=browser&task=unignore&itemid='+pagepkey;
}

function browse_button_unprocesspage(pagepkey) {
  document.location='index.php?module=browser&task=unprocess&itemid='+pagepkey;
}

function browse_button_printlist() {
  document.browseform.job.value='browser_listprint'; document.browseform.submit();
}

function browse_button_printsession(itemid) {
  window.open('views/report-crawlsession.php?itemid='+itemid, 'reportwindow');
}

function browse_button_printwebpage(itemid) {
  window.open('views/report-pagedetails.php?itemid='+itemid, 'reportwindow');
}
*/

function mro_button_add() {
  document.location='index.php?module=mro&task=add';
}

function mro_button_edit(mropkey) {
  document.location='index.php?module=mro&task=edit&itemid='+mropkey;
}

function mro_button_view(mropkey) {
  document.location='index.php?module=mro&task=view&itemid='+mropkey;
}

function mro_button_delete(mropkey) {
  document.location='index.php?module=mro&task=delete&itemid='+mropkey;
}

function mro_button_additem(mropkey) {
  document.location='index.php?module=mro&task=additem&mroid='+mropkey;
}

function mro_button_edititem(mropkey,itempkey) {
  document.location='index.php?module=mro&task=edititem&mroid='+mropkey+'&itemid='+itempkey;
}

function mro_button_viewitem(mropkey,itempkey) {
  document.location='index.php?module=mro&task=viewitem&mroid='+mropkey+'&itemid='+itempkey;
}

function mro_button_deleteitem(mropkey,itempkey) {
  document.location='index.php?module=mro&task=deleteitem&mroid='+mropkey+'&itemid='+itempkey;
}

function mro_button_submit(mropkey) {
  if (confirm("Are you sure to submit this MRO?")) {
    document.location='index.php?module=mro&task=submit&itemid='+mropkey;
  }
}

function mro_button_recommend(mropkey) {
  //if (confirm("Are you sure to recommend this MRO?")) {
    document.location='index.php?module=mro&task=recommend&itemid='+mropkey;
  //}
}

function mro_button_approvenormal(mropkey) {
  //if (confirm("Are you sure to approve this normal MRO?")) {
    document.location='index.php?module=mro&task=approvenormal&itemid='+mropkey;
  //}
}

function mro_button_approvevariance(mropkey) {
  //if (confirm("Are you sure to approve this variance MRO?")) {
    document.location='index.php?module=mro&task=approvevariance&itemid='+mropkey;
  //}
}

function mro_button_cancel(mropkey) {
  if (confirm("Are you sure to Cancel this MRO?")) {
    document.location='index.php?module=mro&task=cancel&itemid='+mropkey;
  }
}

function mro_button_createitq(mropkey) {
  document.location='index.php?module=itq&task=generate&itemid='+mropkey;
}

function mro_button_save() {
  if (validateForm()==true) {
    document.mroform.job.value='mro_add'; document.mroform.submit();
  }
}

function mro_button_update() {
  if (validateForm()==true) {
    document.mroform.job.value='mro_edit'; document.mroform.submit();
  }
}

function mro_button_purge() {
  document.mroform.job.value='mro_remove'; document.mroform.submit();
}

function mro_button_saveitem() {
  if (validateForm()==true) {
    document.mroform.job.value='mro_additem'; document.mroform.submit();
  }
}

function mro_button_updateitem() {
  if (validateForm()==true) {
    document.mroform.job.value='mro_edititem'; document.mroform.submit();
  }
}

function mro_button_purgeitem() {
  document.mroform.job.value='mro_removeitem'; document.mroform.submit();
}

function mro_button_print(mropkey) {
  window.open('views/rpt_mro.php?itemid='+mropkey,'printwindow', 'menubar=0,toolbar=0,scrollbars=1,resizable=0,location=0,width=800,height=600');
}

function mro_button_backtolist() {
  document.location='index.php?module=mro&task=list';
}

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

</script>

<?

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

include_once('models/mblModel.php');
include_once('models/mroModel.php');
$mymblModel=new mblModel;
$mymroModel=new mroModel;

?>

<?

// ................................................................................
// data retrieval functions..
// ................................................................................


// ................................................................................
// data modifications functions..
// ................................................................................


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

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

$pagetitle="MRO";
if (($pubtask=="main")||($pubtask=="submenu")) {
  $subtitle="Select MRO Type";
} else if ($pubtask=="list") {
  $subtitle="MRO List";
} else if ($pubtask=="add") {
  $subtitle="Add MRO";
} else if ($pubtask=="edit") {
  $subtitle="Edit MRO";
} else if ($pubtask=="view") {
  $subtitle="View MRO";
} else if ($pubtask=="delete") {
  $subtitle="Delete MRO";
} else if ($pubtask=="additem") {
  $subtitle="Add MRO Item";
} else if ($pubtask=="edititem") {
  $subtitle="Edit MRO Item";
} else if ($pubtask=="viewitem") {
  $subtitle="View MRO Item";
} else if ($pubtask=="deleteitem") {
  $subtitle="Delete MRO Item";
} else if ($pubtask=="submit") {
  $subtitle="Submit MRO";
} else if ($pubtask=="recommend") {
  $subtitle="Recommend Variance MRO";
} else if ($pubtask=="approvenormal") {
  $subtitle="Approve MRO";
} else if ($pubtask=="approvevariance") {
  $subtitle="Approve Variance MRO";
} else {
  $subtitle="Error: Invalid Option";
}

$headercaption=$pagetitle."  --> ".$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")) {

  include_once('views/mro-menu.tpl');

} else if ($pubtask=="list") {

  //$mro_list = $mymroModel->getlist_mro($pubprojectpkey,$pubtype);
  //include_once('views/mro-list.tpl');

  $mro_new = $mymroModel->getlist_mrobystatus($pubprojectpkey, "0", "mro_id", "desc");
  //$mro_submitted = $mymroModel->getlist_mrobystage($pubprojectpkey, "0", "2", $filtermrono1, $filtermrodate1);
  //$mro_approved = $mymroModel->getlist_mrobystage($pubprojectpkey, "3", "5", $filtermrono2, $filtermrodate2);
  //$mro_submitted = $mymroModel->getlist_mrolist($pubprojectpkey, $filtermrono1, $filtermrodate1);
  $mro_submitted = $mymroModel->getlist_mrolist_arie($pubprojectpkey, $filtermrono1, $filtermrodate1);
  $mro_approved = $mymroModel->getlist_mrohistory($pubprojectpkey, $filtermrono2, $filtermrodate2);
  include_once('views/mro-tabbed.tpl');

} else if ((($pubtask=="add")||($pubtask=="edit"))&&(($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2))) {

  include_once('models/tradeModel.php');
  $mytradeModel=new tradeModel;

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

  $mro_data = $mymroModel->getdata_mro($pubitemid);
  $link_data = $mymroModel->getdata_mro($mro_data['mro_exceedpkey']);
  $trade_data = $mytradeModel->getdata_trade($mro_data['mro_subtradepkey']);
  $item_list = $mymroModel->getlist_mroitems($pubitemid);
  $mbl_subtrades = $mymblModel->getlist_mblsubtrades($pubprojectpkey);
  if ($mro_data['mro_type']=="") $mro_data['mro_type']="1";
  if ($mro_data['mro_projectpkey']=="") $mro_data['mro_projectpkey']=$pubprojectpkey;
  if ($mro_data['mro_subconref']=="") $mro_data['mro_subconref']="-NA-";
  if ($mro_data['mro_clientref']=="") $mro_data['mro_clientref']="-NA-";
  $subcon_data = $mysubconModel->getdata_subcon($mro_data['mro_debitaccount']);
  include_once('views/mro-edit.tpl');

} else if ($pubtask=="view") {

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

  $mro_data = $mymroModel->getdata_mro($pubitemid);
  $reject_data = $mymroModel->getdata_lastrejection($pubitemid);
  $link_data = $mymroModel->getdata_mro($mro_data['mro_exceedpkey']);
  $subcon_data = $mysubconModel->getdata_subcon($mro_data['mro_debitaccount']);
  $trade_data = $mytradeModel->getdata_trade($mro_data['mro_subtradepkey']);
  $item_list = $mymroModel->getlist_mroitems($pubitemid);
  include_once('views/mro-view.tpl');

} else if (($pubtask=="delete")&&(($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2))) {

  include_once('models/supplierModel.php');
  include_once('models/tradeModel.php');
  $mysupplierModel=new supplierModel;
  $mytradeModel=new tradeModel;

  $mro_data = $mymroModel->getdata_mro($pubitemid);
  $link_data = $mymroModel->getdata_mro($mro_data['mro_exceedpkey']);
  $supplier_data = $mysupplierModel->getdata_supplier($mro_data['mro_debitaccount']);
  $trade_data = $mytradeModel->getdata_trade($mro_data['mro_subtradepkey']);
  $item_list = $mymroModel->getlist_mroitems($pubitemid);
  include_once('views/mro-view.tpl');

} else if ((($pubtask=="additem")||($pubtask=="edititem"))&&(($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2))) {

  $mro_data = $mymroModel->getdata_mro($pubmroid);
  $item_data = $mymroModel->getdata_mroitem($pubitemid);
  //if ($item_data['item_rate']=="") $item_data['item_rate']=0;
  if ($pubtask=="additem") {
    $item_data['item_no'] = $mymroModel->getlast_itemno($pubmroid);
    $item_data['item_no']++;
  }
  include_once('views/mro-edititem.tpl');

} else if ($pubtask=="viewitem") {

  include_once('models/tradeModel.php');
  $mytradeModel=new tradeModel;

  $item_data = $mymroModel->getdata_mroitem($pubitemid);
  $mro_data = $mymroModel->getdata_mro($item_data['item_mropkey']);
  $trade_data = $mytradeModel->getdata_trade($item_data['item_subsubtradepkey']);
  include_once('views/mro-viewitem.tpl');

} else if (($pubtask=="deleteitem")&&(($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2))) {

  include_once('models/tradeModel.php');
  $mytradeModel=new tradeModel;

  $item_data = $mymroModel->getdata_mroitem($pubitemid);
  $mro_data = $mymroModel->getdata_mro($item_data['item_mropkey']);
  $trade_data = $mytradeModel->getdata_trade($item_data['item_subsubtradepkey']);
  include_once('views/mro-viewitem.tpl');

} else if (($pubtask=="submit")&&(($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2))) {

  // NOTE: user tanggung if submit exceeded MRO while linked normal MRO not yet submitted!!
  $mro_data = $mymroModel->getdata_mro($pubitemid);

  $opresult = $mymroModel->updatestatus_mro($pubitemid,"1");
  $g=goto('index.php?module=mro&task=list&tab=1');
  echo $g;
  exit;

} else if (($pubtask=="cancel")&&(($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2))) {

  $mro_data = $mymroModel->getdata_mro($pubitemid);

  $opresult = $mymroModel->cancel_mro($pubitemid);
  $g=goto('index.php?module=mro&task=list');
  echo $g;
  exit;

} else if (($pubtask=="recommend")&&(($pubuseraccess['access_mro_recommendvariance']==1)||($pubuserrole>=2))) {

  /*
  $mro_data = $mymroModel->getdata_mro($pubitemid);

  include_once('models/userModel.php');
  $myuserModel=new userModel;

  $user_data = $myuserModel->getdata_user($_SESSION['Xuserpkey']);
  $opresult = $mymroModel->insertdata_approval('', $pubitemid, 2, $_SESSION['Xuserpkey'], $user_data['staff_name'], unconverttounixfull(gettimestamp()), 1, '');
  $g=goto('index.php?module=mro&task=list');
  echo $g;
  exit;
  */

  /*
  echo "<script type='text/javascript'>";
  echo "window.open('views/ibox_mroapproval.php?itemid=".$pubitemid."&type=2','printwindow', 'menubar=0,toolbar=0,scrollbars=1,resizable=0,location=0,width=800,height=600');";
  echo "</script>";
  */

  $pubtype="2";
  include_once('views/mro-approval.tpl');

} else if (($pubtask=="approvenormal")&&(($pubuseraccess['access_mro_approvenormal']==1)||($pubuserrole>=2))) {

  /*
  $mro_data = $mymroModel->getdata_mro($pubitemid);

  include_once('models/userModel.php');
  $myuserModel=new userModel;

  $user_data = $myuserModel->getdata_user($_SESSION['Xuserpkey']);
  $opresult = $mymroModel->insertdata_approval('', $pubitemid, 3, $_SESSION['Xuserpkey'], $user_data['staff_name'], unconverttounixfull(gettimestamp()), 1, '');
  $g=goto('index.php?module=mro&task=list');
  echo $g;
  exit;
  */

  /*
  echo "<script type='text/javascript'>";
  echo "window.open('views/ibox_mroapproval.php?itemid=".$pubitemid."&type=3','printwindow', 'menubar=0,toolbar=0,scrollbars=1,resizable=0,location=0,width=800,height=600');";
  echo "</script>";
  */

  $pubtype="3";
  include_once('views/mro-approval.tpl');

} else if (($pubtask=="approvevariance")&&(($pubuseraccess['access_mro_approvevariance']==1)||($pubuserrole>=2))) {

  /*
  $mro_data = $mymroModel->getdata_mro($pubitemid);

  include_once('models/userModel.php');
  $myuserModel=new userModel;

  $user_data = $myuserModel->getdata_user($_SESSION['Xuserpkey']);
  $opresult = $mymroModel->insertdata_approval('', $pubitemid, 3, $_SESSION['Xuserpkey'], $user_data['staff_name'], unconverttounixfull(gettimestamp()), 1, '');
  $g=goto('index.php?module=mro&task=list');
  echo $g;
  exit;
  */

  /*
  echo "<script type='text/javascript'>";
  echo "window.open('views/ibox_mroapproval.php?itemid=".$pubitemid."&type=3','printwindow', 'menubar=0,toolbar=0,scrollbars=1,resizable=0,location=0,width=800,height=600');";
  echo "</script>";
  */

  $pubtype="3";
  include_once('views/mro-approval.tpl');

} 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>";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"mro_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if ($pubtask=="list") {

  echo "<br><hr size=1>";
  if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) {
    echo "<button name=\"add\" id=\"add\" onClick=\"mro_button_add();\"><img src='gfx/options/b_add.png' class='actionbutton'>&nbsp;&nbsp;Create New MRO</button>&nbsp;";
  }
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"mro_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if ($pubtask=="add") {

  echo "<br><hr size=1>";
  if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) {
    echo "<button name=\"save\" id=\"save\" onClick=\"mro_button_save();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Save MRO</button>&nbsp;";
  }
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"mro_button_backtolist();\"><img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back to MRO List</button>&nbsp;";
  //echo "<button name=\"cancel\" id=\"cancel\" onClick=\"mro_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") {

  echo "<br><hr size=1>";
  if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) {
    if ($mro_data['mro_cancel']!="1") {
      echo "<button name=\"update\" id=\"update\" onClick=\"mro_button_update();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Update MRO</button>&nbsp;";
      // new - submit at edit screen as well as at view screen
      if ($mro_data['mro_status']==0) {
        if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) {
          echo "<button name=\"save\" id=\"save\" onClick=\"mro_button_submit('".$pubitemid."');\"><img src='gfx/options/b_approve.png' class='actionbutton'>&nbsp;&nbsp;Submit MRO</button>&nbsp;";
        }
      }
    }
  }
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"mro_button_backtolist();\"><img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back to MRO List</button>&nbsp;";
  //echo "<button name=\"cancel\" id=\"cancel\" onClick=\"mro_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=="view") {

  // Notes:
  // 1. user cannot delete mro at any point
  // 2. user can edit mro before submission or upon item rejected by recommender/approver (mcm belum submit gak)
  // 

  echo "<br><hr size=1>";
  echo "<table border=0 cellspacing=0 cellpadding=0 width=928>";
  echo "<tr valign=top>";
  echo "<td valign=top width=700>";
  if ($mro_data['mro_cancel']!=1) {
    if ($mro_data['mro_type']==1) {
      if (($pubuseraccess['access_mro_approvenormal']==1)||($pubuserrole>=2)) {
        if ($mro_data['mro_status']==1) {
          echo "<button name=\"approve\" id=\"approve\" onClick=\"mro_button_approvenormal('".$pubitemid."');\"><img src='gfx/options/b_approve.png' class='actionbutton'>&nbsp;&nbsp;Approve Normal MRO</button>&nbsp;";
        }
      }
    } else {
      if (($pubuseraccess['access_mro_recommendvariance']==1)||($pubuserrole>=2)) {
        if ($mro_data['mro_status']==1) {
          echo "<button name=\"recommend\" id=\"recommend\" onClick=\"mro_button_recommend('".$pubitemid."');\"><img src='gfx/options/b_approve.png' class='actionbutton'>&nbsp;&nbsp;Recommend Variance MRO</button>&nbsp;";
        }
      }
      if (($pubuseraccess['access_mro_approvevariance']==1)||($pubuserrole>=2)) {
        if ($mro_data['mro_status']==2) {
          echo "<button name=\"approve\" id=\"approve\" onClick=\"mro_button_approvevariance('".$pubitemid."');\"><img src='gfx/options/b_approve.png' class='actionbutton'>&nbsp;&nbsp;Approve Variance MRO</button>&nbsp;";
        }
      }
    }
    if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) {
      if ($mro_data['mro_status']==0) {
        echo "<button name=\"edit\" id=\"edit\" onClick=\"mro_button_edit('".$pubitemid."');\">&nbsp;<img src='gfx/options/b_edit.png' class='actionbutton'>&nbsp;&nbsp;Edit&nbsp;</button>&nbsp;";
        //echo "<button name=\"delete\" id=\"delete\" onClick=\"mro_button_delete('".$pubitemid."');\"><img src='gfx/options/b_drop.png' class='actionbutton'>&nbsp;&nbsp;Delete</button>&nbsp;";
      }
    }
    if ($mro_data['mro_status']==0) {
      if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) {
        echo "<button name=\"save\" id=\"save\" onClick=\"mro_button_submit('".$pubitemid."');\"><img src='gfx/options/b_approve.png' class='actionbutton'>&nbsp;&nbsp;Submit MRO</button>&nbsp;";
      }
    }
  }
  // later only allow print once approved? probably..
  echo "<button name=\"print\" id=\"print\" onClick=\"mro_button_print('".$pubitemid."');\">&nbsp;<img src='gfx/options/b_print1.png' class='actionbutton'>&nbsp;&nbsp;Print&nbsp;</button>&nbsp;";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"mro_button_backtolist();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back to MRO List&nbsp;</button>&nbsp;";
  echo "</td>";
  echo "<td valign=top width=228 style='text-align: right;'>";
  //if ($mro_data['mro_cancel']!=1) {
  //  if ($mro_data['mro_status']!=0) {
  //    if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) {
  //      echo "<button name=\"cancel\" id=\"cancel\" onClick=\"mro_button_cancel('".$pubitemid."');\"><img src='gfx/options/b_stop.png' class='actionbutton'>&nbsp;&nbsp;Cancel MRO</button>&nbsp;";
  //    }
  //  }
  //}
  echo "</td>";
  echo "</tr>";
  echo "</table>";
  echo "<hr size=1><br>";

} else if ($pubtask=="delete") {

  echo "<br><hr size=1>";
  if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) {
    if ($mro_data['mro_status']=="0") {
      echo "<font color='#ff0000'><b>ARE YOU SURE TO PERMANENTLY DELETE THIS MRO?</b></font><br><br>";
      echo "<button name=\"delete\" id=\"delete\" onClick=\"mro_button_purge();\">&nbsp;Yes, Delete MRO&nbsp;</button>&nbsp;";
    }
  }
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"mro_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<brp><hr size=1><br>";

} else if ($pubtask=="additem") {

  echo "<br><hr size=1>";
  if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) {
    if ($mro_data['mro_status']=="0") {
      echo "<button name=\"save\" id=\"save\" onClick=\"mro_button_saveitem();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Save MRO Item</button>&nbsp;";
    }
  }
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"mro_button_back();\"><img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back to MRO Details</button>&nbsp;";
  //echo "<button name=\"cancel\" id=\"cancel\" onClick=\"mro_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=="edititem") {

  echo "<br><hr size=1>";
  if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) {
    if ($mro_data['mro_status']=="0") {
      echo "<button name=\"update\" id=\"update\" onClick=\"mro_button_updateitem();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Update MRO Item</button>&nbsp;";
    }
  }
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"mro_button_back();\"><img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back to MRO Details</button>&nbsp;";
  //echo "<button name=\"cancel\" id=\"cancel\" onClick=\"mro_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=="viewitem") {

  echo "<br><hr size=1>";
  if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) {
    if ($mro_data['mro_status']=="0") {
      //echo "<button name=\"edit\" id=\"edit\" onClick=\"mro_button_edititem('".$pubmroid."','".$pubitemid."');\">&nbsp;<img src='gfx/options/b_edit.png' class='actionbutton'>&nbsp;&nbsp;Edit&nbsp;</button>&nbsp;";
      echo "<button name=\"delete\" id=\"delete\" onClick=\"mro_button_deleteitem('".$pubmroid."','".$pubitemid."');\"><img src='gfx/options/b_drop.png' class='actionbutton'>&nbsp;&nbsp;Delete</button>&nbsp;";
    }
  }
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"mro_button_back();\">&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back to MRO Details&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

} else if ($pubtask=="deleteitem") {

  echo "<br><hr size=1>";
  if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) {
    if ($mro_data['mro_status']=="0") {
      echo "<font color='#ff0000'><b>ARE YOU SURE TO PERMANENTLY DELETE THIS MRO ITEM?</b></font><br><br>";
      echo "<button name=\"delete\" id=\"delete\" onClick=\"mro_button_purgeitem();\">&nbsp;Yes, Delete MRO Item&nbsp;</button>&nbsp;";
    }
  }
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"mro_button_back();\"><img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<brp><hr size=1><br>";

}

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

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

?>