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

/**
* PHP versions 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.
*
* @package    QuickTicket
* @author     Philippe Vandenberghe <hide@address.com>
* @copyright  2008-2012 The PHP Group
* @version    2.5 build:20101222
*/

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

if ( $oVIP->role!='A' ) die(Error(13));

// INITIALISE

$s = -1;
$tt = 0; // 0:definition, 1:display or 9:translation
QThttpvar('s tt','int int');
if ( $s<0 ) die('Missing parameters');
if ( $tt!=0 && $tt!=1 && $tt!=9 ) die('Missing parameters');

$oVIP->selfurl = 'qti_adm_section.php';
$oVIP->selfname = '<span class="upper">'.$L['Adm_content'].'</span><br />'.$L['Section_upd'];
$oVIP->exiturl = 'qti_adm_sections.php';
$oVIP->exitname = '&laquo; '.$L['Sections'];

$arrDomains = GetDomains();
$arrStaff = GetUsers('M');
if ( count($arrStaff)>10 && $tt==0 ) { $bAjax=true; } else { $bAjax=false; }

$oSEC = new cSection($s);

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

if ( isset($_POST['ok']) && $tt==0 )
{
  // 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) ) $error = $L['Title'].' '.$L['E_invalid'];

  if ( empty($error) )
  {
    $oSEC->parentid = intval($_POST['domain']);
    $oSEC->title = $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]; $warning=$L['Userrole_MF'].' '.$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->prefix = $_POST['prefix'];
    $oSEC->wisheddate = intval($_POST['wisheddate']);
    $oSEC->wisheddflt = 0; if ( $oSEC->wisheddate==2 && isset($_POST['wisheddflt']) ) $oSEC->wisheddflt=intval($_POST['wisheddflt']);
    $oSEC->notifycc = intval($_POST['alternate']);
    if ( $oSEC->notify==0 && $oSEC->notifycc!=0 )
    {
      $oSEC->notifycc=0;
      $warning=$L['Topic_no_notify'];
    }
  }

  // SAVE

  if ( empty($error) )
  {
    // update
    
    $strQ = 'UPDATE '.TABSECTION.' SET';
    $strQ .= ' domainid='.$oSEC->parentid;
    $strQ .= ',title="'.addslashes($oSEC->title).'"';
    $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 .= ',alternate="'.$oSEC->notifycc.'"';
    $strQ .= ',wisheddate="'.($oSEC->wisheddate+$oSEC->wisheddflt).'"';
    $strQ .= ',prefix="'.$oSEC->prefix.'"';
    $strQ .= ' WHERE id='.$oSEC->id;
    $oDB->Query($strQ);

    // unregister and exit

    if ( isset($_SESSION['L']) ) $_SESSION['L'] = array();
    if ( isset($_SESSION[QT]['sys_sections']) ) Unset($_SESSION[QT]['sys_sections']);    
    $strInfo = $L['S_save'];
  }
}

if ( isset($_POST['ok']) && $tt==1 )
{
    $oSEC->d_order = $_POST['d_order'];
    $oSEC->d_last = $_POST['d_last'];
    $oSEC->d_logo = $_POST['d_logo'];
    $oSEC->options = 'order='.$oSEC->d_order.';last='.$oSEC->d_last.';logo='.$oSEC->d_logo;
    $oDB->Query( 'UPDATE '.TABSECTION.' SET options="'.$oSEC->options.'" WHERE id='.$oSEC->id );
    $strInfo = $L['S_save'];
}

if ( isset($_POST['ok']) && $tt==9 )
{
    // translations

    $oVIP->LangDel(array('sec','secdesc'),'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);
        $oVIP->LangAdd('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);
        $oVIP->LangAdd('secdesc',substr($strKey,1),'s'.$oSEC->id,$strTranslation);
        }
      }
    }
    
    // unregister and exit

    if ( isset($_SESSION['L']) ) $_SESSION['L'] = array();
    if ( isset($_SESSION[QT]['sys_sections']) ) Unset($_SESSION[QT]['sys_sections']);    
    $strInfo = $L['S_save'];
}

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

if ( $bAjax )
{
$oHtml->links[] = '<link rel="stylesheet" type="text/css" href="bin/css/qt_jquery.css" />';
$strHeadScript = '
<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');

$arrDest = $arrDomains;
Unset($arrDest[$oSEC->parentid]);

// DISPLAY TABS

$arrTabs = array(0=>$L['Adm_settings'],1=>$L['Display_options'],9=>$L['Translations']);
echo HtmlTabs($arrTabs, $oVIP->selfurl.'?s='.$s, $tt, 6, true, true, $L['E_editing']);

// DISPLAY TAB PANEL

echo '<table class="pan" cellspacing="0">
<tr class="pan">
<td class="pan">
<div class="pan_top">',$oSEC->title,' &middot; ',$arrTabs[$tt],'</div>
';

// FORM 0

if ( $tt==0 )
{

echo '
<script type="text/javascript">
<!--
function ValidateForm(theForm)
{
  if (theForm.title.value.length==0) { alert(qtHtmldecode("',$L['Missing'],': ',$L['Title'],'")); return false; }
  return null;
}
function wisheddfltdisabled(str)
{
  if (str=="2")
  {
  document.getElementById("wisheddflt").disabled=false;
  }
  else
  {
  document.getElementById("wisheddflt").disabled=true;
  }
  return null;
}
-->
</script>
';

echo '<form method="post" action="',$oVIP->selfurl,'" onsubmit="return ValidateForm(this);">
<table class="data_o" cellspacing="0">
<tr class="data_o">
<td class="colhd colhdgroup" style="text-align:left" colspan="2"><b>',$L['Definition'],'</b></td>
</tr>
';
$str = QTconv($oSEC->title,'I');
echo '<tr class="data_o">
<td class="colhd" style="width:150px; text-align:right"><span class="texthead"><label for="title">',$L['Title'],'</label></span></td>
<td class="colct"><input type="text" id="title" name="title" size="55" maxlength="64" value="',$str,'" style="background-color:#FFFF99;" onchange="bEdited=true;" />',(strstr($str,'&amp;') ?  ' <span class="small">'.$oSEC->title.'</span>' : ''),'</td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd" style="width:150px; text-align:right"><span class="texthead"><label for="domain">',$L['Domain'],'</label></span></td>
<td class="colct"><select id="domain" name="domain" onchange="bEdited=true;">
<option value="',$oSEC->parentid,'"',QSEL,'>',$arrDomains[$oSEC->parentid],'</option>',QTasTag($arrDest,'',array('format'=>$L['Move_to'].': %s')),'</select></td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd colhdgroup" style="text-align:left" colspan="2"><b>',$L['Properties'],'</b></td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd" style="text-align: right; width:150px"><span class="texthead"><label for="type">',$L['Type'],'</label></span></td>
<td class="colct">
<select id="type" name="type" onchange="bEdited=true;">
<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" onchange="bEdited=true;">
<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" onchange="bEdited=true;">
<option value="1"',($oSEC->notify==1 ? QSEL : ''),'>',$L['Y'],'</option>
<option value="0"',($oSEC->notify==0 ? QSEL : ''),'>',$L['N'],'</option>
</select>
</tr>
';
if ( $bAjax )
{
echo '<tr class="data_o">
<td class="colhd" style="width:150px; text-align:right"><span class="texthead"><label for="modname">',$L['Userrole_MF'],'</label></span></td>
<td class="colct">
<input type="hidden" name="modnameold" value="',$oSEC->modname,'" onchange="bEdited=true;" />
<input name="modname" id="modname" size="20" maxlength="24" value="',$oSEC->modname,'" onchange="bEdited=true;" />
</td>
</tr>
';
}
else
{
echo '<tr class="data_o">
<td class="colhd" style="width:150px; text-align:right"><span class="texthead"><label for="modid">',$L['Userrole_MF'],'</label></span></td>
<td class="colct">
<input type="hidden" name="modidold" value="',$oSEC->modid,'" onchange="bEdited=true;" />
<select name="modid" id="modid" onchange="bEdited=true;">',QTasTag($arrStaff,$oSEC->modid,array('current'=>$oSEC->modid,'classC'=>'bold')),'</select>
</td>
</tr>
';
}
echo '<tr class="data_o">
<td class="colhd colhdgroup" style="text-align:left" colspan="2"><b>',$L['Specific_fields'],'</b></td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd" style="text-align: right; width:150px"><span class="texthead"><label for="numfield">',$L['Show_topic_id'],'</label></span></td>
<td class="colct">
<input type="text" size="12" maxlength="24" name="numfield" value="',($oSEC->numfield=='N' ? '' : $oSEC->numfield),'" onchange="bEdited=true;" />&nbsp;<span class="small">',$L['H_Show_topic_id'],'</span></td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd" style="text-align: right; width:150px"><span class="texthead"><label for="titlefield">',$L['Show_topic_title'],'</label></span></td>
<td class="colct">
<select id="titlefield" name="titlefield" onchange="bEdited=true;">',QTasTag($L['Topic_title'],$oSEC->titlefield),'</select>&nbsp;<span class="small">',$L['H_Show_topic_title'],'</span></td>
</tr>
';
echo '<tr class="data_o" title="',$L['H_Topic_prefix'],'">
<td class="colhd" style="text-align: right; width:150px"><span class="texthead"><label for="prefix">',$L['Topic_prefix'],'</label></span></td>
<td class="colct">
<select id="prefix" name="prefix" onchange="bEdited=true;">
',QTasTag($L['Prefix_serie'],$oSEC->prefix),'
<option value="0"',($oSEC->prefix=='0' ? QSEL : ''),'>','(',$L['None'],')','</option>
</select>&nbsp;<a class="small" href="qti_ext_prefix.php" target="_blank">',$L['Topic_prefix_demo'],'</a></td>
</tr>
';
echo '<tr class="data_o" title="',$L['H_Show_topic_wisheddate'],'">
<td class="colhd" style="text-align: right; width:150px"><span class="texthead"><label for="wisheddate">',$L['Show_topic_wisheddate'],'</label></span></td>
<td class="colct">
<select id="wisheddate" name="wisheddate" onchange="wisheddfltdisabled(this.value); bEdited=true;">',QTasTag($L['Topic_wisheddate'],$oSEC->wisheddate),'</select>
 default <select id="wisheddflt" name="wisheddflt" onchange="bEdited=true;"',($oSEC->wisheddate!=2 ? QDIS : ''),'>',QTasTag(array(0=>$L['None'],$L['dateSQL']['Today'],$L['Day'].' +1',$L['Day'].' +2'),$oSEC->wisheddflt),'</select>
</td>
</tr>
';

echo '<tr class="data_o" title="',$L['H_Show_topic_notify'],'">
<td class="colhd" style="text-align: right; width:150px"><span class="texthead"><label for="prefix">',$L['Show_topic_notify'],'</label></span></td>
<td class="colct">
<select id="alternate" name="alternate" onchange="bEdited=true;">',QTasTag($L['Topic_notify'],$oSEC->notifycc),'</select>
</td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd" colspan="2" style="padding:6px; text-align:center"><input type="hidden" name="s" value="',$oSEC->id,'" /><input type="submit" name="ok" value="',$L['Save'],'" /></td>
</tr>
';
echo '</table>
</form>
';

}

// FORM 1

if ( $tt==1 )
{

$str='';
$strFile='';
if ( file_exists('upload/section/'.$s.'.gif') ) $strFile = $s.'.gif';
if ( file_exists('upload/section/'.$s.'.jpg') ) $strFile = $s.'.jpg';
if ( file_exists('upload/section/'.$s.'.png') ) $strFile = $s.'.png';
if ( file_exists('upload/section/'.$s.'.jpeg') ) $strFile = $s.'.jpeg';
if ( !empty($strFile) ) $str = '<option value="'.$strFile.'"'.(!empty($oSEC->d_logo) ? QSEL : '').'>'.$L['Specific_image'].'</option>';

echo '
<script type="text/javascript">
<!--
function switchimage(strId)
{
  var strDefault="'.$_SESSION[QT]['skin_dir'].'/ico_section_'.$oSEC->type.'_'.$oSEC->status.'.gif";
  var strSpecific="upload/section/',$strFile,'";
  document.getElementById(strId).src=(document.getElementById(strId).src.search(strDefault)==-1 ? strDefault : strSpecific);
  return null;
}
-->
</script>
';

echo '<form method="post" action="',$oVIP->selfurl,'">
<table class="data_o" cellspacing="0">
';
echo '<tr class="data_o">
<td class="colhd colhdgroup" style="text-align:left" colspan="2"><b>',$L['Display_options'],'</b></td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd" style="width:150px; text-align:right"><span class="texthead"><label for="d_logo">Logo</label></span></td>
<td class="colct"><select id="d_logo" name="d_logo" onchange="bEdited=true; switchimage(\'idlogo\');">
<option value=""',(empty($oSEC->d_logo) ? QSEL : ''),'>',$L['Default'],'</option>
',(empty($str) ? '' : $str).'
</select> ',AsImg($oSEC->GetLogo(),'S',$L['Ico_section_'.$oSEC->type.'_'.$oSEC->status],'ico i_sec','vertical-align:middle','','idlogo'),' <a class="small" href="qti_adm_section_img.php?s=',$s,'">',$L['Add'],'/',$L['Remove'],'</a>
</td>
</tr>
';
$arr = array('lastpostdate'=>'Date of the last post','numid'=>'Reference number','title'=>'Title');
echo '<tr class="data_o">
<td class="colhd" style="width:150px; text-align:right"><span class="texthead"><label for="d_order">',$L['Topic_order'],'</label></span></td>
<td class="colct">
<select name="d_order" id="d_order" onchange="bEdited=true;" />',QTasTag($arr,$oSEC->d_order,array('current'=>$oSEC->d_order,'classC'=>'bold')),'</select>
</td>
</tr>
';
$arr = array('views'=>$L['Views'],'status'=>$L['Status'],'actorname'=>$L['Userrole_MA']);
if ( $oSEC->wisheddate!=0 ) $arr['wisheddate']=$L['Wisheddate'];
if ( $oSEC->notifycc!=0 ) $arr['notifiedname']=$L['Userrole_UN'];
$arr['tags']=$L['Tags'];
$arr['id']='Id';
$arr['none']='('.$L['None'].')';
echo '<tr class="data_o">
<td class="colhd" style="text-align: right; width:150px"><span class="texthead"><label for="d_last">',$L['Infofield'],'</label></span></td>
<td class="colct"><select id="d_last" name="d_last" onchange="bEdited=true;">',QTasTag($arr,$oSEC->d_last),'</select></td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd" colspan="2" style="padding:6px; text-align:center">
<input type="hidden" name="s" value="',$oSEC->id,'" />
<input type="hidden" name="tt" value="',$tt,'" />
<input type="submit" name="ok" value="',$L['Save'],'" /></td>
</tr>
';
echo '</table>
</form>
';

}

// FORM 9

if ( $tt==9 )
{

echo '<form method="post" action="',$oVIP->selfurl,'">
<table class="data_o" cellspacing="0">
';
echo '<tr class="data_o">
<td class="colhd colhdgroup" colspan="3">',$L['Translations'],'</td>
</tr>
<tr class="data_o">
<td class="colhd colhdfirst">',$L['Section_name_and_desc'],'</td>
<td class="colct" colspan="2">
  <p class="help">',sprintf($L['E_no_translation'],$oSEC->title),'</p>
  <table cellspacing="0" class="hidden">';
$arrTrans = $oVIP->LangGet('sec','*','s'.$oSEC->id);
$arrDescTrans = $oVIP->LangGet('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="hidden">
  <td class="hidden" style="width:30px"><span title="',$arr[1],'">',$arr[0],'</span></td>
  <td class="hidden"><input class="small" title="',$L['Section'],' (',$strIso,')" type="text" id="T',$strIso,'" name="T',$strIso,'" size="30" maxlength="64" value="',$str,'" onchange="bEdited=true;" />&nbsp;</td>';
  $str = '';
  if ( isset($arrDescTrans[$strIso]) ) {
  if ( !empty($arrDescTrans[$strIso]) ) {
    $str = QTconv($arrDescTrans[$strIso],'I');
  }}
  echo '  <td class="hidden"><textarea class="small" title="',$L['Description'],' (',$strIso,')" type="text" id="D',$strIso,'" name="D',$strIso,'" cols="45" rows="2" onchange="bEdited=true;">',$str,'</textarea></td>
  </tr>
  ';
}
echo '  </table>
</td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd" colspan="3" style="padding:6px; text-align:center">
<input type="hidden" name="s" value="',$oSEC->id,'" />
<input type="hidden" name="tt" value="',$tt,'" />
<input type="submit" name="ok" value="',$L['Save'],'" /></td>
</tr>
';
echo '</table>
</form>
';

}

// END TABS

echo '
</td>
</tr>
</table>
';

echo '<p><a href="',$oVIP->exiturl,'" onclick="return qtEdited(bEdited,\''.$L['E_editing'].'\');">',$oVIP->exitname,'</a></p>';

// HTML END

include('qti_adm_p_footer.php');

?>
Return current item: QuickTicket