<?php
include "../../include/session.php";
include "../../include/config.php";
include "../../include/opendb.php";
include "../../include/databasepath.php";
include "../../include/applicationsetting.php";
include "../../include/getmythemes.php";
include "../../include/closedb.php";
include "../../systemaccesscontrol.php";
?>
<html><head>
<?php echo "<title>$systemname $systemversion</title>" ?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php echo "<script src=\"$dbprofilejspath/jslib_win.js\"></script>" ?>
<?php echo "<link href=\"$dbprofilecsspath/css_control.css\" rel=\"stylesheet\">" ?>
<script language="JavaScript" type="text/javascript">
cnt=0;
<?php
$phpdir=str_replace($currentform, '', $_SERVER['PHP_SELF']);
if (trim($phpdir =="")){
    echo "var vPhpdir='';";
}
else{
    echo "var vPhpdir='$phpdir';";
}
?>
function EditFile(){
    msg="This will change the holiday control on your popup calendar.\nContinue?";
    var ok=confirm( msg );
    if(ok==true){
        cnt++;
        if(cnt==1){
            document.forms[0].bclick.value = "YES";
            document.forms[0].submit();
        } else {
            alert("Process in progress. Click OK to continue.");
            return;
         }
    }
}
</script></head>
<?php echo "<body text=$alltextcolor bgcolor=$divbgcolor leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>" ?>
<form method="post">
<input type=hidden name="bclick" value="">
<?php
$filename="agenda.js";
$option="r";
$editfield="editfield";
$handle = fopen($filename, $option);
$contents = fread($handle, filesize($filename));
fclose($handle);
?>
<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=2%><td width=96%>
<?php
echo "<img src=$ecblank border=0 height=6 width=1>";
echo "<table width=100% bgcolor=$alltableoutline border=0 cellspacing=1 cellpadding=0><tr><td>";
    echo "<table width=100% bgcolor=$midnavtableoutline border=0 cellspacing=0 cellpadding=5>";
        echo "<tr><td><div align=left><b>MAGISTRATE/PRESIDING OFFICER/PRESIDENT</b></div></td>";
        echo "<td><div align=right><b><i>- view by ".$_SESSION['username']."</i></b></div></td></tr>";
    echo "</table>";
echo "</td></tr></table>";
echo "<img src=$ecblank border=0 height=12 width=1>";
    echo "<table width=100% bgcolor=808080 border=0 cellspacing=1 cellpadding=1><tr><td>";
        echo "<b>Edit agenda.jp system file</b></td></tr><tr><td>";
            echo "<table width=100% bgcolor=ffffff border=0 cellspacing=1 cellpadding=3><tr><td><center>";
                print "<textarea name='".$editfield."' rows=20 cols=80>$contents</textarea>";
            echo "</center></td></tr></table>";
        echo "</td></tr><tr><td><center>";
        echo "<input type=button value=' Save ' name='savenewdoc' onclick='EditFile()'class=form>";
    echo "</center></td></tr></table>";
?>
</td><td width=2%></td></table>
</form>
</body>
</html>
<?php
//Submit Theme
if(isset($_POST['bclick'])){
    $bclick = $_POST['bclick'];
} else {
    $bclick = "";
}
if ($bclick=="YES"){
    $option="w+";
    $handle = fopen($filename, $option);
    $writecontent=$_REQUEST['editfield'];
    if (is_writable($filename)) {
        // The file pointer is at the bottom of the file hence
        // that's where $writecontent will go when we fwrite() it.
        if (!$handle = fopen($filename, 'a')) {
             echo "Cannot open file ($filename)";
             exit;
        }
        // Write $writecontent to our opened file.
        if (fwrite($handle, stripcslashes ($writecontent)) === FALSE) {
            echo "Cannot write to file ($filename)";
            exit;
        }
        echo "Success, wrote ($writecontent) to file ($filename)";
        fclose($handle);
    } else {
        echo "The file $filename is not writable";
    }
}
?>
