<?php

  /*

      publicnotice.php

      Public Notice. Allow the user to set the public notice of this domain.
      [Commented]

      Changelog:
        2006-01-14 dave: Cleaned up code for v1.0 release

      ## PAGE CONTAINS HANDYANDY MYSQL MODS ##
      ## Copyright (C) 2005 Andy Deakin (handyandy.org.uk) ##

      ----

      Copyright (C) 2003  Central Manchester CLC
      Copyright (C) 2003  David Thorne (davethorne@gmail.com)

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation version 2.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  */

  // Start session and populate it with data
  session_start();

  // Page Security
  if (($_SESSION['_usertype'] != 'Administrator'
       && $_SESSION['_usertype'] != 'Domain Administrator'
       && $_SESSION['_usertype'] != 'Root') ||
      (isset($_REQUEST['global']) && $_SESSION['_usertype'] != 'Root')) {
    require_once 'system/security.php';
    ThrowOut();
  }

  // Retrieve Get/Post variables
  $act = $_REQUEST['act'];
  $notice = $_POST['notice'];
  $msglang = $_REQUEST['msglang'];
  $global = $_REQUEST['global'];

  // Page Title
  if ($global) {
    $ptitle = 'Front Page Notice';
  } else {
    $ptitle = 'Public Notice';
  }

  // Includes
  require_once 'system/db.php';
  require_once 'system/lang.php';
  require_once 'system/global_preferences.php';
  require_once 'system/message.php';
  require 'header.php';

  // Language selection
  set_text_domain("publicnotice");

  if (!$msglang) {
    $msglang = $_lang;
  }

  if ($global == 'true') {
    $domain = 0;
  } else {
    $domain = $_SESSION['_domain'];
  }

  // Action: Set the public notice of this domain
  if ($act == 'action') {
    $act = '';

    $op = db_recordset("SELECT count(*) FROM tbl_News WHERE frontpagepara=3 and domain_id=".$domain." and lang='".$msglang."'");
  
    if ($op[0][count] == 0) {
      db_send("INSERT INTO tbl_News (content,frontpagepara,domain_id,lang) VALUES ('" . $notice . "','3','".$domain."','".$msglang."')");
    } else {
      $sql = "UPDATE tbl_News SET content='" . $notice . "' WHERE domain_id=$domain and frontpagepara=3 and lang='".$msglang."'";
      db_send($sql);
    }

    $message = gettext("NOTE: Notice successfully updated.");
  }

  // Default action: Request details of the publi notice and choose action...
  if ($act == '') {

    $noticeRS = db_recordset("SELECT content FROM tbl_News WHERE frontpagepara=3 and domain_id=".$domain." and lang='".$msglang."'");

    if ($message) { display($message); }
?>

<?php
    if ($global) {
      print "<h1>".gettext('Front Page Notice')."</h1>";
    } else {
      print "<h1>".gettext('Public Notice')."</h1>";
    }
?>
<?php
    if ($global) {
      print '<h2>'.gettext('Here you can enter a global notice to be displayed on the front page:').'</h2>';
    } else {
      print '<h2>'.gettext('Here you can enter a public notice:').'</h2>';
    }
?>
  
  <div class="block">
    <form name="langform" id="langform" method="post" action="publicnotice.php">
<?php
  if ($global) {
?>
      <input type="hidden" name="global" value="true" />
<?php
  }
?>
      <div class="buttonpanel">
      <select name="msglang">
<?php
  if ($langfile = fopen("./locale/locale.alias","r"))  {
    while ($aline= fgets($langfile, 1024)) {
      if (!($aline[0] == '#')) {
        $aline = trim($aline);
        if (substr($aline, 1, 7) != "default") {
          $res = preg_split('/\s+/',$aline);
          if ($msglang == $res[1]) {
            print '          <option value="'.$res[1].'" selected="selected">'.$res[0].' ('.$res[1].')</option>\n';
          } else {
            print '          <option value="'.$res[1].'">'.$res[0].' ('.$res[1].')</option>\n';
          }
        }
      }
    }
    fclose($langfile);
  }
?>
        </select>
        <input type="submit" value="<?php echo gettext("Change Language")?>" />
      </div>
    </form>
    <form name="mainform" id="mainform" method="post" action="">
      <input type="hidden" name="act" value="action" />
    <input type="hidden" name="msglang" value="<?php echo $msglang?>" />
<?php
  if ($global) {
?>
      <input type="hidden" name="global" value="true" />
<?php
  }
?>
      <div class="labelfieldpair">
        <div class="name">
       <label for="notice"><?php echo gettext('Notice')?></label>
        </div>
        <div class="field">
          <textarea name="notice" id="notice" cols="60" rows="6"><?php echo $noticeRS[0][content]?></textarea>
        </div>
      </div>
      <div class="buttonpanel">
        <input name="submit" type="submit" id="submit" value="<?php echo gettext('Commit Changes')?>" />
        <input name="reset" type="reset" id="reset" value="<?php echo gettext('Reset')?>" />
      </div>
    </form>
  </div>

<?php
  }

  // Include
  require 'footer.php';
?>
