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

// filter forms..
/*
$filtersessionname=$_POST['sessionname'];
$filteruserpkey=$_POST['userpkey'];
$filterstartdate=$_POST['startdate'];
$filterstopdate=$_POST['stopdate'];
$realstartdate=converttounix($filterstartdate);
$realstopdate=converttounix($filterstopdate)+86399;
*/
?>

<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(projectpkey,mrotype) {
  document.location='index.php?module=mro&task=add&pid='+projectpkey+'&type='+mrotype;
}

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_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 browse_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="Quotation Evaluation";
if (($pubtask=="main")||($pubtask=="submenu")) {
  $subtitle="List";
} 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 {
  $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');
  include_once('views/general-invalidtask.php');

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

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

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

  $mro_data = $mymroModel->getdata_mro($pubitemid);
  if ($mro_data['mro_type']=="") $mro_data['mro_type']=$pubtype;
  if ($mro_data['mro_projectpkey']=="") $mro_data['mro_projectpkey']=$pubprojectpkey;
  include_once('views/mro-edit.tpl');

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

  $mro_data = $mymroModel->getdata_mro($pubitemid);
  $item_list = $mymroModel->getlist_mroitems($pubitemid);
  include_once('views/mro-view.tpl');

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

  $mro_data = $mymroModel->getdata_mro($pubitemid);
  $item_list = $mymroModel->getlist_mroitems($pubitemid);
  include_once('views/mro-view.tpl');

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

  $item_data = $mymroModel->getdata_mroitem($pubitemid);
  include_once('views/mro-edititem.tpl');

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

  $item_data = $mymroModel->getdata_mroitem($pubitemid);
  include_once('views/mro-viewitem.tpl');

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

  $item_data = $mymroModel->getdata_mroitem($pubitemid);
  include_once('views/mro-viewitem.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>";
  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>";
  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_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>";
  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;";
  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") {

  echo "<br><hr size=1>";
  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;";
  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=="delete") {

  echo "<br><hr size=1>";
  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>";
  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_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

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

  echo "<br><hr size=1>";
  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_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel</button>&nbsp;";
  echo "<br><hr size=1><br>";

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

  echo "<br><hr size=1>";
  echo "<button name=\"edit\" id=\"edit\" onClick=\"mro_button_edititem('".$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('".$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&nbsp;</button>&nbsp;";
  echo "<br><hr size=1><br>";

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

  echo "<br><hr size=1>";
  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');

?>