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

$id = '-1'; QThttpvar('id','str'); if ( $id=='-1' ) die('Missing status id...');

$oVIP->selfurl = 'qti_adm_status.php';
$oVIP->exiturl = 'qti_adm_statuses.php';
$oVIP->selfname = '<span class="upper">'.$L['Adm_content'].'</span><br />'.$L['Status_upd'];
$oVIP->exitname = '&laquo; '.$L['Statuses'];

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

if ( isset($_POST['ok']) )
{
  // check id
  if (!preg_match('/[A-Z]/',$id)) $error="Id $id ".$L['E_invalid'].' (B-Y)'; //A and Z can be edited (hidden input)


  // change id
  if ( empty($error) )
  {
    if ( $_POST['oldid']!=$id )
    {
    $error = $oVIP->StatusChangeId($_POST['oldid'],$id);
    }
  }

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

  // check unic name
  if ( empty($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) $warning = 'Name ['.$name.'] '.$L['E_already_used'];
    }
  }

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

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

  // check notified
  if ( empty($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($error) )
  {
    $oDB->Query('UPDATE '.TABSTATUS.' SET name="'.addslashes($name).'",color="'.$color.'",mailto="'.$saved.'",icon="'.$icon.'" WHERE id="'.$id.'"');

    //  save translation

    $oVIP->LangDel(array('status','statusdesc'),$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('status',substr($strKey,1),$id,$strTranslation);
        }
      }
      if ( substr($strKey,0,1)=='D' )
      {
        if ( !empty($strTranslation) )
        {
        if ( get_magic_quotes_gpc() ) $strTranslation = stripslashes($strTranslation);
        $oVIP->LangAdd('statusdesc',substr($strKey,1),$id,$strTranslation);
        }
      }
    }

    //exit
    Unset($_SESSION[QT]['sys_statuses']);
    $oVIP->selfname = $L['Status_upd'];
    $oVIP->EndMessage(NULL,$L['S_update'],'admin',2);
  }
  else
  {
    $id = $_POST['oldid'];
  }
}

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

$strHeadScript = '
<link rel="stylesheet" type="text/css" href="bin/css/qt_jquery_color.css" />
<script type="text/javascript" src="bin/qt_jquery.js"></script>
<script type="text/javascript" src="bin/qt_jquery_color.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function() {

  $("#pickerbar").colorPicker({
  columns: 12,
  click: function(color){$("#color").val(color); $("#color").css("background-color",color); $("#color").css("color","#000000"); $("#color").focus();}
  });
  $("#pickerbar").css("visibility","hidden");

  $.farbtastic("#picker");
  $("#picker").css("height","5px");
  $("#picker").css("visibility","hidden");
  $("#color").focus(function() { $.farbtastic("#picker").linkTo(this); $("#picker").css("height","195px"); $("#pickerbar").css("visibility","visible"); $("#picker").css("visibility","visible"); });
  $("input:not(#color)").click(function() { $("#pickerbar").css("visibility","hidden"); $("#picker").css("visibility","hidden"); $("#picker").css("height","5px"); });  

});
-->
</script>
';

include('qti_adm_p_header.php');

// ANALYSE NOTIFY

$lst_mail = explode(',',$oVIP->statuses[$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="hidden">
<tr class="hidden">
<td style="width:25px">',$id,'</td>
<td style="width:30px">',AsImg($_SESSION[QT]['skin_dir'].'/'.$oVIP->statuses[$id]['icon'],'-',$oVIP->statuses[$id]['statusdesc'],'ico ico_status'),'</td>
<td style="width:100px;padding:3px 10px 3px 10px;text-align:center;background-color:',$oVIP->statuses[$id]['color'],'; border-style:solid; border-color:#dddddd; border-width:1px">',$oVIP->statuses[$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="data_o">',N;

echo '<tr class="data_o">';
echo '<td class="colhd colhdgroup" colspan="2">',$L['Definition'],'</td>';
echo '</tr>',N;

echo '<tr class="data_o">';
echo '<td class="colhd colhdfirst" style="width:150px;"><label for="id">Id</label></td>';
echo '<td class="colct">';
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 class="data_o">';
echo '<td class="colhd colhdfirst"><label for="name">Name</label></td>';
echo '<td class="colct"><input type="text" id="name" name="name" size="24" maxlength="24" value="',$oVIP->statuses[$id]['name'],'" style="background-color:#FFFF99" /></td>';
echo '</tr>',N;
echo '<tr class="data_o">';
echo '<td class="colhd colhdfirst"><label for="icon">Icon</label></td>';
echo '<td class="colct"><input type="text" id="icon" name="icon" size="24" maxlength="64" value="',$oVIP->statuses[$id]['icon'],'" />&nbsp;',AsImg($_SESSION[QT]['skin_dir'].'/'.$oVIP->statuses[$id]['icon'],'-',$oVIP->statuses[$id]['statusdesc'],'ico ico_status'),'&nbsp;&nbsp;<a href="qti_ext_statusico.php" target="_blank">show icons</a></td>';
echo '</tr>',N;
echo '<tr class="data_o">';
echo '<td class="colhd colhdfirst"><label for="color">',$L['Status_background'],'</label></td>';
echo '<td class="colct">
<div id="pickerbar" style="float:right;"></div>
<input type="text" class="colortext" id="color" name="color" size="10" maxlength="24" value="',(empty($oVIP->statuses[$id]['color']) ? '#' : $oVIP->statuses[$id]['color']),'" onchange="bEdited=true;" />&nbsp;<span class="small">',$L['H_Status_background'],'</span>
<div id="picker" style="float:right;width:195px;"></div>
</td>';
echo '</tr>',N;
echo '<tr class="data_o">';
echo '<td class="colhd colhdgroup" colspan="2">',$L['Options'],'</td>';
echo '</tr>
';
echo '<tr class="data_o">
<td class="colhd colhdfirst">',$L['Notification'],'</span></td>
<td class="colct">
  <table class="hidden" cellspacing="0">
  <tr class="hidden">
  <td class="hidden" 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="mailtoMA">',$L['Userrole_MA'],'</label><br />
  <input id="mailtoMF" type="checkbox" name="mailto[]" value="MF"',($bolMode ? QCHE : ''),'/> <label for="mailtoMF">',$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 class="hidden">',$L['Notify_also'],':<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 '<td class="colhd colhdgroup" colspan="2">',$L['Translations'],'</td>
<tr class="data_o">
<td class="colhd colhdfirst">',$L['Status_name_and_desc'],'</td>
<td class="colct" colspan="2">
<p class="help">',sprintf($L['E_no_translation'],ucfirst(str_replace('_',' ',$oVIP->statuses[$id]['name']))),'</p>
<table cellspacing="0" class="hidden">';

$arrTrans = cVIP::LangGet('status','*',$id);
$arrDescTrans = cVIP::LangGet('statusdesc','*',$id);
include('bin/qti_lang.php'); // this creates $arrLang
foreach($arrLang as $strIso=>$arr)
{
  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['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 class="hidden">
<td class="colhd colhdgroup" colspan="2" style="padding:6px; text-align:center">
<input type="hidden" name="oldid" value="',$id,'" />
<input type="hidden" name="oldname" value="',$oVIP->statuses[$id]['name'],'" />
<input type="submit" name="ok" value="',$L['Save'],'" /></td>
</tr>
</table>
</form>
<p><a href="',$oVIP->exiturl,'">',$oVIP->exitname,'</a></p>
';

// HTML END

include('qti_adm_p_footer.php');

?>
Return current item: QuickTicket