<?
/* index.php: $pubmodule, $pubtask, $pubitemid */

// filter forms..
$filteruserpkey=$_POST['userpkey'];
$filterstartdate=$_POST['startdate'];
$filterstopdate=$_POST['stopdate'];
$filterstarttime=$_POST['starttime'];
$filterstoptime=$_POST['stoptime'];

$pubpageno = $_REQUEST['pageno'];
if ($pubpageno=="") $pubpageno=1;
?>

<script type="text/javascript">

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

function system_button_addnews() {
  document.location='index.php?module=system&task=newsadd';
}

function system_button_editnews(newspkey) {
  document.location='index.php?module=system&task=newsedit&itemid='+newspkey;
}

function system_button_viewnews(newspkey) {
  document.location='index.php?module=system&task=newsview&itemid='+newspkey;
}

function system_button_deletenews(newspkey) {
  document.location='index.php?module=system&task=newsdelete&itemid='+newspkey;
}

function system_button_savenews() {
  if (validateForm()==true) {
    document.systemform.job.value='system_newsadd'; document.systemform.submit();
  }
}

function system_button_updatenews() {
  if (validateForm()==true) {
    document.systemform.job.value='system_newsedit'; document.systemform.submit();
  }
}

function system_button_purgenews() {
  document.systemform.job.value='system_newsremove'; document.systemform.submit();
}

function system_button_addforeword() {
  document.location='index.php?module=system&task=forewordadd';
}

function system_button_saveforeword() {
  document.systemform.job.value='system_forewordadd'; document.systemform.submit();
}

function system_button_printaudittrail() {
  document.location='index.php?module=report&task=audit';
}

function system_button_printauditview() {
  document.location='index.php?module=report&task=auditview';
}

function system_button_purgedb() {
  document.location='index.php?module=system&task=purgedb';
}

function system_button_purgecache() {
  document.location='index.php?module=system&task=purgecache';
}

function system_button_purgedbconfirm() {
  document.systemform.job.value='system_purgedb'; document.systemform.submit();
}

function system_button_purgecacheconfirm() {
  document.systemform.job.value='system_purgecache'; document.systemform.submit();
}

function system_button_savesettings() {
  var mysettings = "";
  var myvalues = "";

  // go thru rows and compile strings..

  // gui..
  var settingfield = document.getElementById('system_gui_cssfile');
  mysettings += "|" + "system_gui_cssfile";
  myvalues += "|" + settingfield.value;
  var settingfield = document.getElementById('system_gui_logincountdate');
  mysettings += "|" + "system_gui_logincountdate";
  myvalues += "|" + settingfield.value;
  var settingfield = document.getElementById('system_gui_hscroll');
  mysettings += "|" + "system_gui_hscroll";
  if (settingfield.checked==true) { myvalues += "|" + "yes"; } else { myvalues += "|"; }
  var settingfield = document.getElementById('system_gui_vscroll');
  mysettings += "|" + "system_gui_vscroll";
  if (settingfield.checked==true) { myvalues += "|" + "yes"; } else { myvalues += "|"; }

  // security..
  var settingfield = document.getElementById('system_security_lockdown');
  mysettings += "|" + "system_security_lockdown";
  if (settingfield.checked==true) { myvalues += "|" + "yes"; } else { myvalues += "|"; }
  var settingfield = document.getElementById('system_security_nologin');
  mysettings += "|" + "system_security_nologin";
  if (settingfield.checked==true) { myvalues += "|" + "yes"; } else { myvalues += "|"; }
  var settingfield = document.getElementById('system_audit_purge');
  mysettings += "|" + "system_audit_purge";
  if (settingfield.checked==true) { myvalues += "|" + "yes"; } else { myvalues += "|"; }
  var settingfield = document.getElementById('system_audit_purgeage');
  mysettings += "|" + "system_audit_purgeage";
  var selindex = settingfield.selectedIndex;
  myvalues += "|" + settingfield[selindex].value;

  // submit..
  if (validateForm()==true) {
    document.systemform.fullsettings.value=mysettings.substr(1);
    document.systemform.fullvalues.value=myvalues.substr(1);
    document.systemform.job.value='system_settingsedit';
    document.systemform.submit();
  }
}

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

</script>

<?

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

include_once('models/systemModel.php');
$mysystemModel=new systemModel;

?>

<?

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


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


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

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

$pagetitle="System";
if ($pubtask=="submenu") {
  $subtitle="System Menu";
} else if ($pubtask=="editwelcome") {
  $subtitle="Edit Welcome Note";
} else if ($pubtask=="news") {
  $subtitle="News Items";
} else if ($pubtask=="newsread") {
  $subtitle="News Item";
} else if ($pubtask=="newsadd") {
  $subtitle="Add News Item";
} else if ($pubtask=="newsedit") {
  $subtitle="Edit News Item";
} else if ($pubtask=="newsview") {
  $subtitle="View News Item";
} else if ($pubtask=="newsdelete") {
  $subtitle="Delete News Item";
} else if ($pubtask=="audit") {
  $subtitle="Audit Trail";
} else if ($pubtask=="auditview") {
  $subtitle="Audit Trail Item Details";
} else if ($pubtask=="settings") {
  $subtitle="System Settings";
} else if ($pubtask=="operations") {
  $subtitle="System Operations";
} else if ($pubtask=="purgedb") {
  $subtitle="Purge Database";
} else if ($pubtask=="purgecache") {
  $subtitle="Purge Cache";
  
} else if ($pubtask=="date_change") {
  $subtitle="Change Date";
} 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=="submenu")&&((($pubuseraccess['access_system_managewelcome']==1)||($pubuseraccess['access_system_managenews']==1))||($pubuserrole>=2))) {

  include_once('views/system-submenu.tpl');

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

  $welcomenote_data = $mysystemModel->getdata_welcomenote();
  include_once('views/welcomenote-edit.tpl');

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

  $news_list = $mysystemModel->getlist_news();
  include_once('views/news-list.tpl');

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

  $news_data = $mysystemModel->getdata_news($pubitemid);
  include_once('views/news-read.tpl');

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

  $news_data = $mysystemModel->getdata_news($pubitemid);
  if ($pubtask=="newsadd") $news_data['news_date']=gettimestamp();
  include_once('views/news-edit.tpl');

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

  $news_data = $mysystemModel->getdata_news($pubitemid);
  include_once('views/news-view.tpl');

} else if (($pubtask=="audit")&&($pubuserrole>=2)) {

  if ($pubuserrole>=2) {
    // $audittrail_list = $mysystemModel->getlist_audittrail($filteruserpkey,$filterstartdate,$filterstarttime,$filterstopdate,$filterstoptime);
    // data retrieval done in below file..
    include_once('views/audittrail-list.tpl');
  }
  //include_once('views/general-invalidtask.php');

} else if (($pubtask=="auditview")&&($pubuserrole>=2)) {

  if ($pubuserrole>=2) {
    $audittrail_data = $mysystemModel->getdata_audittrail($pubitemid);
    include_once('views/audittrail-view.tpl');
  }

} else if (($pubtask=="settings")&&($pubuserrole>=2)) {

  if ($pubuserrole>=2) {
    $systemsettings_data = $mysystemModel->getdata_systemsettings();
    include_once('views/systemsettings-edit.tpl');
  }
  //include_once('views/general-invalidtask.php');

} else if (($pubtask=="operations")&&($pubuserrole>=2)) {

  if ($pubuserrole>=2) {
    include_once('views/system-operations.tpl');
  }

} else if (($pubtask=="purgedb")&&($pubuserrole>=2)) {

  if ($pubuserrole>=2) {
    include_once('views/system-purgedb.tpl');
  }

} else if (($pubtask=="purgecache")&&($pubuserrole>=2)) {

  if ($pubuserrole>=2) {
    include_once('views/system-purgecache.tpl');
  }
  
  /*
  date change implimentation
  date: 9/03/2011
  */
  } else if ($pubtask=="date_change") {
  include_once('views/date_change.tpl');
  /*
  end date change
  */

} 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;'";

if (($pubtask=="submenu")&&((($pubuseraccess['access_system_managewelcome']==1)||($pubuseraccess['access_system_managenews']==1))||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"system_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=="editwelcome")&&(($pubuseraccess['access_system_managewelcome']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"save\" id=\"save\" onClick=\"system_button_saveforeword();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Save Welcome Note</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"system_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=="news")&&(($pubuseraccess['access_system_managenews']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"add\" id=\"add\" onClick=\"system_button_addnews();\">&nbsp;<img src='gfx/options/b_add.png' class='actionbutton'>&nbsp;&nbsp;Add News Item</button>&nbsp;";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"system_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=="newsread") {

  echo "<br><hr size=1>";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"system_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=="newsadd")&&(($pubuseraccess['access_system_managenews']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"save\" id=\"save\" onClick=\"system_button_savenews();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Save News Item</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"system_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=="newsedit")&&(($pubuseraccess['access_system_managenews']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"update\" id=\"update\" onClick=\"system_button_updatenews();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Update News Item</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"system_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=="newsview")&&(($pubuseraccess['access_system_managenews']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<button name=\"edit\" id=\"edit\" onClick=\"javascript:system_button_editnews('".$news_data['news_pkey']."');\">&nbsp;<img src='gfx/options/b_edit.png' class='actionbutton'>&nbsp;&nbsp;Edit&nbsp;</button>&nbsp;";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"javascript:system_button_deletenews('".$news_data['news_pkey']."');\"><img src='gfx/options/b_drop.png' class='actionbutton'>&nbsp;&nbsp;Delete</button>&nbsp;";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"javascript:system_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=="newsdelete")&&(($pubuseraccess['access_system_managenews']==1)||($pubuserrole>=2))) {

  echo "<br><hr size=1>";
  echo "<font color='#ff0000'><b>ARE YOU SURE TO PERMANENTLY DELETE THIS NEWS ITEM?</b></font><br><br>";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"system_button_purgenews();\">&nbsp;Yes, Delete News Item&nbsp;</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"system_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=="audit")&&($pubuserrole>=2)) {

  echo "<br><hr size=1>";
  //echo "<button name=\"print\" id=\"print\" onClick=\"system_button_printaudittrail();\">&nbsp;<img src='gfx/options/b_print1.png' class='actionbutton'>&nbsp;&nbsp;Print&nbsp;</button>&nbsp;";
  //echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"system_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=="auditview")&&($pubuserrole>=2)) {

  echo "<br><hr size=1>";
  echo "<button name=\"print\" id=\"print\" onClick=\"system_button_printauditview();\">&nbsp;<img src='gfx/options/b_print1.png' class='actionbutton'>&nbsp;&nbsp;Print&nbsp;</button>&nbsp;";
  echo "<button name=\"back\" id=\"back\" ".$backstatus." onClick=\"system_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=="settings")&&($pubuserrole>=2)) {

  echo "<br><hr size=1>";
  echo "<button name=\"save\" id=\"save\" onClick=\"system_button_savesettings();\"><img src='gfx/options/b_save.png' class='actionbutton'>&nbsp;&nbsp;Save Settings</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"system_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=="operations")&&($pubuserrole>=2)) {

  echo "<br><hr size=1>";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"system_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=="purgedb")&&($pubuserrole>=2)) {

  echo "<br><hr size=1>";
  echo "<font color='#ff0000'><b>ARE YOU SURE TO PURGE ALL WEB PAGE CONTENTS STORED IN THE DATABASE?<br>(ONLY HTML & PLAIN TEXT CONTENT WILL BE DELETED. HOWEVER, YOU WILL NO LONGER BE ABLE TO SEARCH THE REPOSITORY FOR PURGED PAGES)</b></font><br><br>";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"system_button_purgedbconfirm();\">&nbsp;Yes, Purge Database&nbsp;</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"system_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=="purgecache")&&($pubuserrole>=2)) {

  echo "<br><hr size=1>";
  echo "<font color='#ff0000'><b>ARE YOU SURE TO PURGE ALL WEB PAGE CONTENTS STORED IN THE REPOSITORY?<br>(ALL COPIES OF WEB PAGES AND RELATED DOCUMENTS/FILES IN THE CACHE SHALL BE DELETED)</b></font><br><br>";
  echo "<button name=\"delete\" id=\"delete\" onClick=\"system_button_purgecacheconfirm();\">&nbsp;Yes, Purge Cache&nbsp;</button>&nbsp;";
  echo "<button name=\"cancel\" id=\"cancel\" onClick=\"system_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');

?>