Location: PHPKode > projects > QuickTicket > quickticket/quickticket/qti_adm_status.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

$id = '-1';
if ( isset($_GET['id']) ) $id = strip_tags($_GET['id']);
if ( isset($_POST['id']) ) $id = strip_tags($_POST['id']);
if ( $id=='-1' ) die('Missing parameter id');

$oVIP->selfurl = 'qti_adm_status.php';
$oVIP->exiturl = 'qti_adm_statuses.php';
$oVIP->selfname = $L['Status_upd'];
$oVIP->exitname = '&laquo;'.S.$L['Status_man'];

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

if ( isset($_POST['ok']) )
{
  // check id
  if (!ereg('[A-Z]',$id)) $qti_error="Id $id ".$L['E_invalid'].' (B-Y)';


  // change id
  if ( empty($qti_error) )
  {
    if ( $_POST['oldid']!=$id )
    {
    $qti_error = cStatus::Rename($_POST['oldid'],$id);
    }
  }

  // check name
  if ( empty($qti_error) )
  {
    $name = strip_tags(trim($_POST['name'])); if ( get_magic_quotes_gpc() ) $name = stripslashes($name);
    if ( $name=='' ) $qti_error = 'Status name '.S.$L['E_invalid'];
    $name = QTconv($name,'3',QTI_CONVERT_AMP);
  }

  // check unic name
  if ( empty($qti_error) )
  {
    if ( $_POST['oldname']!=$_POST['name'] )
    {
    $oDB->Query('SELECT count(id) as countid FROM '.TABSTATUS.' WHERE name="'.addslashes($name).'"');
    $row = $oDB->Getrow();
    if ($row['countid']>0) $qti_warning = 'Name ['.$name.'] '.$L['E_already_used'];
    }
  }

  // check color
  if ( empty($qti_error) )
  {
    $color = strip_tags(trim($_POST['color']));
  }

  // check icon
  if ( empty($qti_error) )
  {
    $icon = strip_tags(trim($_POST['icon']));
    $icon = htmlspecialchars($icon,ENT_QUOTES);
    if ( $icon!=trim($_POST['icon']) ) $qti_error = $L['Icon'].S.$L['E_invalid'];
  }

  // check notified
  if ( empty($qti_error) )
  {
    $lst_mail = array();
    if (isset($_POST['mailto'])) $lst_mail = $_POST['mailto'];
    $lst_others = explode(',',strip_tags(trim($_POST['others'])));
    $lst_saved = array();

    $i=array_search('U',$lst_mail);
    if ( ($i===false) || (is_null($i)) ) { $bolUser=false; } else { $bolUser=true; $lst_saved[] = 'U'; }
    $i=array_search('MA',$lst_mail);
    if ( ($i===false) || (is_null($i)) ) { $bolOper=false; } else { $bolOper=true; $lst_saved[] = 'MA'; }
    $i=array_search('MF',$lst_mail);
    if ( ($i===false) || (is_null($i)) ) { $bolMode=false; } else { $bolMode=true; $lst_saved[] = 'MF'; }
    $i=array_search('1',$lst_mail);
    if ( ($i===false) || (is_null($i)) ) { $bolAdmi=false; } else { $bolAdmi=true; $lst_saved[] = '1'; }
    $lst_saved = array_merge($lst_saved,$lst_others);
    $lst_saved = array_unique($lst_saved);
    $saved = implode(",",$lst_saved);
  }

  // save

  if ( empty($qti_error) )
  {
    $oDB->Query('UPDATE '.TABSTATUS.' SET name="'.addslashes($name).'",color="'.$color.'",mailto="'.$saved.'",icon="'.$icon.'" WHERE id="'.$id.'"');

    //  save translation

    $oDB->Query('DELETE FROM '.TABLANG.' WHERE (objtype="status" OR objtype="statusdesc") AND objid="'.$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('status',substr($strKey,1),$id,$strTranslation);
        }
      }
      if ( substr($strKey,0,1)=='D' )
      {
        if ( !empty($strTranslation) )
        {
        if ( get_magic_quotes_gpc() ) $strTranslation = stripslashes($strTranslation);
        cLang::Add('statusdesc',substr($strKey,1),$id,$strTranslation);
        }
      }
    }

    //exit

    unset($_SESSION['qtiTstatus']);
    $oVIP->EndMessage(NULL,$L['S_update'],'admin',2);
  }
}

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

$arrJava = array('com'=>false);

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

$arrStatus = cStatus::GetStatus($id);

// ANALYSE NOTIFY

$lst_mail = explode(',',$arrStatus[$id]['mailto']);
$lst_mail = array_unique($lst_mail);
$others = '';

$i=array_search('U',$lst_mail);
if ( ($i===false) || (is_null($i)) ) { $bolUser=false; } else { unset($lst_mail[$i]); $bolUser=true; }
$i=array_search('MA',$lst_mail);
if ( ($i===false) || (is_null($i)) ) { $bolOper=false; } else { unset($lst_mail[$i]); $bolOper=true; }
$i=array_search('MF',$lst_mail);
if ( ($i===false) || (is_null($i)) ) { $bolMode=false; } else { unset($lst_mail[$i]); $bolMode=true; }
$i=array_search('1',$lst_mail);
if ( ($i===false) || (is_null($i)) ) { $bolAdmi=false; } else { unset($lst_mail[$i]); $bolAdmi=true; }

$others = implode(',',$lst_mail);

// DISPLAY RESULT

echo '<table cellspacing="0" class="ta_hidden">
<tr>
<td style="width:25px">',$id,'</td>
<td style="width:30px">',AsImg($_SESSION[QT]['skin_dir'].'/'.$arrStatus[$id]['icon'],'-',$arrStatus[$id]['statusdesc'],'ico ico_status'),'</td>
<td style="width:100px;padding:3px 10px 3px 10px;text-align:center;background-color:',$arrStatus[$id]['color'],'; border-style:solid; border-color:#dddddd; border-width:1px">',$arrStatus[$id]['statusname'],'</td>
<td>&nbsp;</td>
</tr>
</table>
<br/>',N;
echo '<form method="POST" action="',$oVIP->selfurl,'">',N;
echo '<table width="500" cellspacing="0" class="ta">',N;

echo '<tr class="tr_o">';
echo '<th class="th_o th_o_all" colspan="2">',$L['Definition'],'</th>';
echo '</tr>',N;

echo '<tr>';
echo '<th class="th_o th_o_first" style="width:150px;"><label for="id">Id</label></th>';
echo '<td class="td_o">';
if ( ($id=='A') || ($id=='Z') )
{
  echo $id.'&nbsp;<input type="hidden" name="id" value="',$id,'"/>';
}
else
{
  echo '<input type="text" id="id" name="id" size="1" maxlength="1" value="',$id,'"/>';
}
echo '</td>';
echo '</tr>',N;
echo '<tr>';
echo '<th class="th_o th_o_first"><label for="name">Name</label></th>';
echo '<td class="td_o"><input type="text" id="name" name="name" size="24" maxlength="24" value="',$arrStatus[$id]['name'],'" style="background-color:#FFFF99"/></td>';
echo '</tr>',N;
echo '<tr>';
echo '<th class="th_o th_o_first"><label for="icon">Icon</label></th>';
echo '<td class="td_o"><input type="text" id="icon" name="icon" size="24" maxlength="64" value="',$arrStatus[$id]['icon'],'"/>&nbsp;',AsImg($_SESSION[QT]['skin_dir'].'/'.$arrStatus[$id]['icon'],'-',$arrStatus[$id]['statusdesc'],'ico ico_status'),'&nbsp;&nbsp;<a href="qti_adm_status_ico.php" target="_blank">show icons</a></td>';
echo '</tr>',N;
echo '<tr>';
echo '<th class="th_o th_o_first"><label for="color">',$L['Status_background'],'</label></th>';
echo '<td class="td_o"><input type="text" id="color" name="color" size="10" maxlength="24" value="',$arrStatus[$id]['color'],'"/>&nbsp;<span class="small">',$L['H_Status_background'],'</span></td>';
echo '</tr>',N;
echo '<tr>';
echo '<th class="th_o th_o_all" colspan="2">',$L['Options'],'</th>';
echo '</tr>
';
echo '<tr style="vertical-align:top">
<th class="th_o th_o_first">',$L['Notification'],'</span></th>
<td class="td_o">
<table cellspacing="0" class="ta_hidden">
<tr valign="top">
<td width="200">
<input id="mailtoU" type="checkbox" name="mailto[]" value="U"',($bolUser ? QCHE : ''),'/><label for="mailtoU">',$L['Userrole']['U'],'</label><br/>
<input id="mailtoMA" type="checkbox" name="mailto[]" value="MA"',($bolOper ? QCHE : ''),'/><label for="mailtoO">',$L['Userrole_MA'],'</label><br/>
<input id="mailtoMF" type="checkbox" name="mailto[]" value="MF"',($bolMode ? QCHE : ''),'/><label for="mailtoM">',$L['Userrole_MF'],'</label><br/>
<input id="mailto1" type="checkbox" name="mailto[]" value="1"',($bolAdmi ? QCHE : ''),'/><label for="mailto1">',$L['Userrole']['A'],'</label><br/></td>
<td>Others notified:<br/>
<textarea id="others" name="others" cols="40" rows="2" maxlength="255"/>',$others,'</textarea><br/>
<span class="small">',$L['H_Status_notify'],'</span>
</td>
</tr>
</table>
</td>
</tr>
';
echo '<th class="th_o th_o_all" colspan="2">',$L['Translations'],'</th>
<tr class="tr tr_o">
<th class="th_o th_o_first">',$L['Status_name_and_desc'],'</th>
<td class="td_o" colspan="2">
<p class="help">',sprintf($L['E_no_translation'],ucfirst(str_replace('_',' ',$arrStatus[$id]['name']))),'</p>
<table cellspacing="0" class="ta_hidden">';

$arrTrans = cLang::GetTrans('status',$id);
$arrDescTrans = cLang::GetTrans('statusdesc',$id);
include('bin/qti_lang.php'); // this creates $arrLang
foreach ($arrLang as $strIso => $arr)
{
  echo '
  <tr>
  <td class="td_hidden" style="width:30px"><span title="',$arr[1],'">',$arr[0],'</span></td>
  <td class="td_hidden">
  <input class="small" title="',$L['Status'],' (',$strIso,')" type="text" id="T',$strIso,'" name="T',$strIso,'" size="20" maxlength="64" value="',(isset($arrTrans[$strIso]) ? $arrTrans[$strIso] : ''),'"/>
  <input class="small" title="',$L['Description'],' (',$strIso,')" type="text" id="D',$strIso,'" name="D',$strIso,'" size="55" maxlength="255" value="',(isset($arrDescTrans[$strIso]) ? $arrDescTrans[$strIso] : ''),'"/>
  </td>
  </tr>
  ';
}

echo '</table>
</td>
</tr>
';
echo '<tr>
<th class="th_o th_o_all" colspan="2" style="padding:6px; text-align:center">
<input type="hidden" name="oldid" value="',$id,'"/>
<input type="hidden" name="oldname" value="',$arrStatus[$id]['name'],'"/>
<input type="submit" name="ok" value="',$L['Save'],'"/></th>
</tr>
</table>
</form>
<p><a href="',$oVIP->exiturl,'">',$oVIP->exitname,'</a></p>
';

// HTML END

include('qti_adm_p_footer.php');

?>
Return current item: QuickTicket