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

// filter forms..
//$filtermainname=$_POST['mainname'];
?>

<script type="text/javascript">

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

function main_button_search() {
  document.mainform.job.value='main_search';
  document.mainform.submit();
}

function main_button_select() {
  document.location='index.php?module=main&task=select';
}

function main_button_selectcms() {
  document.location='index.php?module=main&task=selectcms';
}

function main_button_open(mainpkey) {
  document.location='index.php?module=main&task=open&itemid='+mainpkey;
}

function main_button_import(mainpkey) {
  document.location='index.php?module=main&task=import&itemid='+mainpkey;
}

function main_button_edit(mainpkey) {
  document.location='index.php?module=main&task=edit&itemid='+mainpkey;
}

function main_button_view(mainpkey) {
  document.location='index.php?module=main&task=view&itemid='+mainpkey;
}

function main_button_delete(mainpkey) {
  document.location='index.php?module=main&task=delete&itemid='+mainpkey;
}

function main_button_save() {
  if (validateForm()==true) {
    document.mainform.job.value='main_add'; document.mainform.submit();
  }
}

function main_button_update() {
  if (validateForm()==true) {
    document.mainform.job.value='main_edit'; document.mainform.submit();
  }
}

function main_button_purge() {
  document.mainform.job.value='main_remove'; document.mainform.submit();
}

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

</script>

<?

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

include_once('models/mainModel.php');
$mymainModel=new mainModel;

?>

<?

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

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

$pagetitle="Main";
if (($pubtask=="main")||($pubtask=="submenu")) {
  $subtitle="Main";
} else if ($pubtask=="login") {
  $subtitle="Login";
} else if ($pubtask=="logout") {
  $subtitle="Logout";
} else if ($pubtask=="dashboard") {
  $subtitle="Dashboard";
} 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/main-list.tpl');

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

  //$main_list = $mymainModel->getlist_mains();
  //include_once('views/main-select.tpl');

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

  echo "<form action='input.php' method='post' name='frm_logout' id='frm_logout'>";
  echo "<input name='job' type='hidden' id='job' value='general_logout'>";
  echo "<button name='logout' type='submit' id='logout' value='logout'>&nbsp;</button>";
  echo "</form>";
  echo "<script type='text/javascript'>";
  echo "document.frm_logout.submit();";
  echo "</script>";
  exit;

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

  $dashboard_list = $mymainModel->getlist_dashboard($pubprojectpkey);
  include_once('views/main-dashboard.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=\"print\" id=\"print\" onClick=\"main_button_printlist();\">&nbsp;<img src='gfx/options/b_print1.png' class='actionbutton'>&nbsp;&nbsp;Print&nbsp;</button>&nbsp;";
  //echo "<button name=\"add\" id=\"add\" onClick=\"main_button_add();\"><img src='gfx/options/b_add.png' class='actionbutton'>&nbsp;&nbsp;Add New main</button>&nbsp;";
  //echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"main_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=="login") {

  echo "<br><hr size=1>";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"main_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=="logout") {

  echo "<br><hr size=1>";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"main_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=="dashboard") {

  echo "<br><hr size=1>";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"main_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');

?>