Location: PHPKode > projects > QuickTicket > quickticket/quickticket/qti_adm_section.php
<?php

/*
 * PHP versions 4 and 5
 *
 * LICENSE: This source file is subject to version 3.0 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license. If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to hide@address.com so we can mail you a copy immediately.
 *
 * @category   Troubleticket
 * @package    QuickTicket
 * @author     Philippe Vandenberghe <hide@address.com>
 * @copyright  2008-2012 The PHP Group
 * @license    http://www.php.net/license  PHP License 3.0
 * @version    1.9.0.3 build:20081001
 * @link       http://www.qt-cute.org/doc/package/qti
 * @since      File available since Release 1.0.0
 * @deprecated File deprecated in Release 2.0.0
 *
 */

session_start();
require_once('bin/qti_init.php');
include(Translate('qti_lang_adm.inc'));

if ( $oVIP->role!='A' ) die($L['E_admin']);

// INITIALISE

$s = -1;
if ( isset($_GET['s']) ) $s = intval($_GET['s']);
if ( isset($_POST['s']) ) $s = intval($_POST['s']);
if ( $s<0 ) die('Missing parameters');

$oVIP->selfurl = 'qti_adm_section.php';
$oVIP->selfname = $L['Section_upd'];
$oVIP->exiturl = 'qti_adm_sections.php';
$oVIP->exitname = '&laquo;'.S.$L['Section_man'];

$arrStaff = GetUsers('M');
if ( count($arrStaff)>10 ) { $bAjax=true; } else { $bAjax=false; }

$oSEC = new cSection($s);

// --------
// SUBMITTED
// --------

if ( isset($_POST['ok']) )
{
  // CHECK MANDATORY VALUE

  $str = trim($_POST['title']); if ( get_magic_quotes_gpc() ) $str = stripslashes($str);
  $str = QTconv($str,'3',QTI_CONVERT_AMP,false);
  if ( empty($str) ) $qti_error = $L['Title'].S.$L['E_invalid'];

  if ( empty($qti_error) )
  {
    $oSEC->domid = intval($_POST['domain']);
    $oSEC->idtitle = $str;
    $oSEC->name = $str;
    $oSEC->type = intval($_POST['type']);
    $oSEC->status = intval($_POST['status']);
    $oSEC->notify= intval($_POST['notify']);
    if ( isset($_POST['modname']) )
    {
      if ( $_POST['modname']!=$_POST['modnameold'] )
      {
      $oSEC->modname = $_POST['modname'];
      $oSEC->modid = array_search($_POST['modname'],$arrStaff);
      if ( $oSEC->modid==FALSE || empty($oSEC->modid) ) { $oSEC->modid=1; $oSEC->modname=$arrStaff[1]; $qti_warning=$L['Userrole_MF'].S.$L['E_invalid']; }
      }
    }
    if ( isset($_POST['modid']) )
    {
      if ( $_POST['modid']!=$_POST['modidold'] )
      {
        $oSEC->modname = $arrStaff[$_POST['modid']];
        $oSEC->modid = $_POST['modid'];
      }
    }
    $oSEC->titlefield = intval($_POST['titlefield']);
    $oSEC->numfield = trim($_POST['numfield']); if ( strlen($oSEC->numfield)==0 ) $oSEC->numfield='N';
    $oSEC->infofield = $_POST['infofield'];
    $oSEC->prefix = $_POST['prefix'];
    $oSEC->wisheddate = intval($_POST['wisheddate']);
    $oSEC->notifycc = intval($_POST['alternate']);
  }

  // SAVE

  if ( empty($qti_error) )
  {
    // update
    $strQ = 'UPDATE '.TABSECTION.' SET';
    $strQ .= ' domainid='.$oSEC->domid;
    $strQ .= ',title="'.addslashes($oSEC->idtitle).'"';
    $strQ .= ',type="'.$oSEC->type.'"';
    $strQ .= ',status="'.$oSEC->status.'"';
    $strQ .= ',notify="'.$oSEC->notify.'"';
    $strQ .= ',moderator='.$oSEC->modid;
    $strQ .= ',moderatorname="'.$oSEC->modname.'"';
    $strQ .= ',titlefield="'.$oSEC->titlefield.'"';
    $strQ .= ',numfield="'.$oSEC->numfield.'"';
    $strQ .= ',infofield="'.$oSEC->infofield.'"';
    $strQ .= ',alternate="'.$oSEC->notifycc.'"';
    $strQ .= ',wisheddate="'.$oSEC->wisheddate.'"';
    $strQ .= ',prefix="'.$oSEC->prefix.'"';
    $strQ .= ' WHERE id='.$oSEC->id;
    $oDB->Query($strQ);

    // translation
    $oDB->Query('DELETE FROM '.TABLANG.' WHERE (objtype="sec" OR objtype="secdesc") AND objid="s'.$oSEC->id.'"');
    foreach ($_POST as $strKey => $strTranslation)
    {
      if ( substr($strKey,0,1)=='T' )
      {
        if ( !empty($strTranslation) )
        {
        if ( get_magic_quotes_gpc() ) $strTranslation = stripslashes($strTranslation);
        cLang::Add('sec',substr($strKey,1),'s'.$oSEC->id,$strTranslation);
        }
      }
      if ( substr($strKey,0,1)=='D' )
      {
        if ( !empty($strTranslation) )
        {
        if ( get_magic_quotes_gpc() ) $strTranslation = stripslashes($strTranslation);
        cLang::Add('secdesc',substr($strKey,1),'s'.$oSEC->id,$strTranslation);
        }
      }
    }

    // register section lang and description

    $_SESSION['L']['sec'] = cLang::GetName('sec',$_SESSION[QT]['lang_iso'],'*');
    $_SESSION['L']['secdesc'] = cLang::GetName('secdesc',$_SESSION[QT]['lang_iso'],'*');
    Unset($_SESSION['qtiGoto']);
    Unset($_SESSION[QT]['sys_notifysections']);

    // exit
    $strInfo = $L['S_save'];
  }
}

// --------
// HTML START
// --------

if ( $bAjax )
{
$arrCss = array('qt_jquery.css'); 
$strHeaderAddScript = '
<script type="text/javascript" src="bin/qt_jquery.js"></script>
<script type="text/javascript" src="bin/qt_jquery_auto.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function() {
  $("#modname").autocomplete("qti_j_name.php", {
    selectFirst: false,
    extraParams: { r:"M" }
  });
});
-->
</script>';
}

include('qti_adm_p_header.php');
include('qti_adm_p_title.php');

$arrDest = $_SESSION['qtiDomains'];
Unset($arrDest[$oSEC->domid]);

// FORM

echo '
<script type="text/javascript">
<!--
function ValidateForm(theForm)
{
  if (theForm.title.value.length==0) { alert(html_entity_decode("',$L['E_mandatory'],': ',$L['Title'],'")); return false; }
  return null;
}
-->
</script>
';

echo '<form method="post" action="',$oVIP->selfurl,'" onsubmit="return ValidateForm(this);">
<table class="ta" cellspacing="0">
<tr class="tr tr_o">
<th class="th_o th_o_all" style="text-align:left" colspan="2"><b>',$L['Definition'],'</b></th>
</tr>
';
$str = QTconv($oSEC->idtitle,'I');
echo '<tr class="tr tr_o">
<th class="th_o" style="width:150px; text-align:right"><span class="texthead"><label for="title">',$L['Title'],'</label></span></th>
<td class="td_o"><input type="text" id="title" name="title" size="55" maxlength="64" value="',$str,'" style="background-color:#FFFF99;"/>',(strstr($str,'&amp;') ?  ' <span class="small">'.$oSEC->idtitle.'</span>' : ''),'</td>
</tr>
';
echo '<tr class="tr tr_o">
<th class="th_o" style="width:150px; text-align:right"><span class="texthead">',$L['Domain'],'</span></th>
<td class="td_o"><select name="domain">
<option value="',$oSEC->domid,'"',QSEL,'>',$_SESSION['qtiDomains'][$oSEC->domid],'</option>',QTastags($arrDest,$L['Move_to'].': %s'),'</select></td>
</tr>
';
echo '<tr class="tr tr_o">
<th class="th_o th_o_all" style="text-align:left" colspan="2"><b>',$L['Properties'],'</b></th>
</tr>
';
echo '<tr class="tr tr_o">
<th class="th_o" style="text-align: right; width:150px"><span class="texthead"><label for="type">',$L['Type'],'</label></span></th>
<td class="td_o">
<select id="type" name="type">
<option value="1"',($oSEC->type==1 ? QSEL : ''),'>',$L['Section_type'][1],'</option>
<option value="0"',($oSEC->type==0 ? QSEL : ''),'>',$L['Section_type'][0],'</option>
<option value="2"',($oSEC->type==2 ? QSEL : ''),'>',$L['Section_type'][2],'</option>
</select>
 ',$L['Status'],' <select id="status" name="status">
<option value="0"',($oSEC->status==0 ? QSEL : ''),'>',$L['Section_status'][0],'</option>
<option value="1"',($oSEC->status==1 ? QSEL : ''),'>',$L['Section_status'][1],'</option>
</select>
 ',$L['Notification'],' <select id="notify" name="notify">
<option value="1"',($oSEC->notify==1 ? QSEL : ''),'>',$L['Y'],'</option>
<option value="0"',($oSEC->notify==0 ? QSEL : ''),'>',$L['N'],'</option>
</select>
</tr>
';
echo '<tr class="tr tr_o">
<th class="th_o" style="text-align: right; width:150px"><span class="texthead"><label for="infofield">',$L['Infofield'],'</label></span></th>
<td class="td_o">
<select id="infofield" name="infofield">',QTastags($L['Last_column_label'],null,$oSEC->infofield),'<option value="N"',($oSEC->infofield=='N' ? QSEL : ''),'>(',$L['None'],')</option>
</select></td>
</tr>
';
if ( $bAjax )
{
echo '<tr class="tr tr_o">
<th class="th_o" style="width:150px; text-align:right"><span class="texthead">',$L['Userrole_MF'],'</span></th>
<td class="td_o">
<input type="hidden" name="modnameold" value="',$oSEC->modname,'"/>
<input name="modname" id="modname" size="20" maxlength="24" value="',$oSEC->modname,'"/>
</td>
</tr>
';
}
else
{
echo '<tr class="tr tr_o">
<th class="th_o" style="width:150px; text-align:right"><span class="texthead">',$L['Userrole_MF'],'</span></th>
<td class="td_o">
<input type="hidden" name="modidold" value="',$oSEC->modid,'"/>
<select name="modid" id="modid"/>',QTastags($arrStaff,null,$oSEC->modid,null,$oSEC->modid,'bold'),'</select>
</td>
</tr>
';
}
echo '<tr class="tr tr_o">
<th class="th_o th_o_all" style="text-align:left" colspan="2"><b>',$L['Specific_fields'],'</b></th>
</tr>
';
echo '<tr class="tr tr_o">
<th class="th_o" style="text-align: right; width:150px"><span class="texthead"><label for="numfield">',$L['Show_topic_id'],'</label></span></th>
<td class="td_o">
<input type="text" size="12" maxlength="24" name="numfield" value="',($oSEC->numfield=='N' ? '' : $oSEC->numfield),'"/>&nbsp;<span class="small">',$L['H_Show_topic_id'],'</span></td>
</tr>
';
echo '<tr class="tr tr_o">
<th class="th_o" style="text-align: right; width:150px"><span class="texthead"><label for="titlefield">',$L['Show_topic_title'],'</label></span></th>
<td class="td_o">
<select id="titlefield" name="titlefield">',QTastags($L['Topic_title'],null,$oSEC->titlefield),'</select>&nbsp;<span class="small">',$L['H_Show_topic_title'],'</span></td>
</tr>
';
echo '<tr class="tr tr_o" title="',$L['H_Topic_prefix'],'">
<th class="th_o" style="text-align: right; width:150px"><span class="texthead"><label for="prefix">',$L['Topic_prefix'],'</label></span></th>
<td class="td_o">
<select id="prefix" name="prefix">
',QTastags($L['Prefix_serie'],null,$oSEC->prefix),'
<option value="0"',($oSEC->prefix=='0' ? QSEL : ''),'>','(',$L['None'],')','</option>
</select>&nbsp;<a class="small" href="qti_adm_prefix.php" target="_blank">',$L['Topic_prefix_demo'],'</a></td>
</tr>
';
echo '<tr class="tr tr_o" title="',$L['H_Show_topic_wisheddate'],'">
<th class="th_o" style="text-align: right; width:150px"><span class="texthead"><label for="wisheddate">',$L['Show_topic_wisheddate'],'</label></span></th>
<td class="td_o">
<select id="wisheddate" name="wisheddate">',QTastags($L['Topic_wisheddate'],null,$oSEC->wisheddate),'</select>
</td>
</tr>
';
echo '<tr class="tr tr_o" title="',$L['H_Show_topic_notify'],'">
<th class="th_o" style="text-align: right; width:150px"><span class="texthead"><label for="prefix">',$L['Show_topic_notify'],'</label></span></th>
<td class="td_o">
<select id="alternate" name="alternate">',QTastags($L['Topic_notify'],null,$oSEC->notifycc),'</select>
</td>
</tr>
';
echo '<th class="th_o th_o_all" colspan="3">',$L['Translations'],'</th>
<tr class="tr tr_o">
<th class="th_o th_o_first">',$L['Section_name_and_desc'],'</th>
<td class="td_o" colspan="2">
<p class="help">',sprintf($L['E_no_translation'],$oSEC->idtitle),'</p>
<table cellspacing="0" class="ta_hidden">';
$arrTrans = cLang::GetTrans('sec','s'.$oSEC->id);
$arrDescTrans = cLang::GetTrans('secdesc','s'.$oSEC->id);
include('bin/qti_lang.php'); // this creates $arrLang
foreach ($arrLang as $strIso => $arr)
{
  $str = '';
  if ( isset($arrTrans[$strIso]) ) {
  if ( !empty($arrTrans[$strIso]) ) {
    $str = QTconv($arrTrans[$strIso],'I');
  }}
  echo '
  <tr class="tr_hidden">
  <td class="td_hidden" style="width:30px"><span title="',$arr[1],'">',$arr[0],'</span></td>
  <td class="td_hidden"><input class="small" title="',$L['Section'],' (',$strIso,')" type="text" id="T',$strIso,'" name="T',$strIso,'" size="30" maxlength="64" value="',$str,'"/>&nbsp;</td>';
  $str = '';
  if ( isset($arrDescTrans[$strIso]) ) {
  if ( !empty($arrDescTrans[$strIso]) ) {
    $str = QTconv($arrDescTrans[$strIso],'I');
  }}
  echo '<td class="td_hidden"><textarea class="small" title="',$L['Description'],' (',$strIso,')" type="text" id="D',$strIso,'" name="D',$strIso,'" cols="45" rows="2">',$str,'</textarea></td>
  </tr>
  ';
}
echo '</table>
</td>
</tr>
';
echo '<tr class="tr tr_o">
<th class="th_o" colspan="2" style="padding:6px; text-align:center"><input type="hidden" name="s" value="',$oSEC->id,'"/><input type="submit" name="ok" value="',$L['Save'],'"/></th>
</tr>
';
echo '</table>
</form><br/>
<a href="',$oVIP->exiturl,'">',$oVIP->exitname,'</a>
<br/>';

// HTML END

include('qti_adm_p_footer.php');

?>
Return current item: QuickTicket