Location: PHPKode > projects > QT-registrations > qtregistrations/qtr_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.
*
* @package    QT-registerations
* @author     Philippe Vandenberghe <hide@address.com>
* @copyright  2008-2012 The PHP Group
* @version    2.4 build:20100313
*/

session_start();
require_once('bin/qtr_init.php');
include(Translate('qtr_adm.php'));

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

// INITIALISE

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

$oVIP->selfurl = 'qtr_adm_status.php';
$oVIP->exiturl = 'qtr_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 '.' '.Error(1);
    $name = QTconv($name,'3',QTR_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.'] '.strtolower($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'].' '.Error(1);
  }

  // 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

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

    // Exit
    Unset($_SESSION[QT]['sys_statuses']);
    $oVIP->selfname = $L['Status_upd'];
    $oVIP->EndMessage(NULL,$L['S_update'].'<br/><br/><span class="warning">'.$warning.'</span>','admin',(!empty($warning) ? 0: 2));
  }
  else
  {
    $id = $_POST['oldid'];
  }
}

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

$oVIP->arrCss[] = '../bin/css/qt_jquery_color.css';
$strHeadScript = '
<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('qtr_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 i_status'),'</td>
<td style="width:100px;padding:3px 10px 3px 10px;text-align:center;background-color:',(empty($oVIP->statuses[$id]['color']) ? 'inherit' : $oVIP->statuses[$id]['color']),'; border-style:solid; border-color:#dddddd; border-width:1px">',$oVIP->statuses[$id]['statusname'],'</td>
<td>&nbsp;</td>
</tr>
</table>
<br/>
';
echo '<form method="POST" action="',$oVIP->selfurl,'">
<table width="500" cellspacing="0" class="data_o">
<tr class="data_o">
<td class="th_o th_o_all" colspan="2">',$L['Definition'],'</td>
</tr>
';
echo '<tr class="data_o">';
echo '<td class="th_o th_o_first" style="width:150px;"><label for="id">Id</label></td>';
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 class="data_o">';
$str = QTconv($oVIP->statuses[$id]['name'],'I');
echo '<td class="th_o th_o_first"><label for="name">Name</label></td>';
echo '<td class="td_o"><input type="text" id="name" name="name" size="24" maxlength="24" value="',$str,'" style="background-color:#FFFF99" onchange="bEdited=true;"/>',(strstr($str,'&amp;') ?  ' <span class="disabled">'.$oVIP->statuses[$id]['name'].'</span>' : ''),'</td>';
echo '</tr>',N;
echo '<tr class="data_o">';
echo '<td class="th_o th_o_first"><label for="icon">Icon</label></td>';
echo '<td class="td_o"><input type="text" id="icon" name="icon" size="24" maxlength="64" value="',$oVIP->statuses[$id]['icon'],'" onchange="bEdited=true;"/> ',AsImg($_SESSION[QT]['skin_dir'].'/'.$oVIP->statuses[$id]['icon'],'-',$oVIP->statuses[$id]['statusdesc'],'ico i_status'),'&nbsp;&nbsp;<a href="qtr_ext_statusico.php" target="_blank">show icons</a></td>';
echo '</tr>',N;
echo '<tr class="data_o">';
echo '<td class="th_o th_o_first"><label for="color">',$L['Status_background'],'</label></td>';
echo '<td class="td_o">
<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="th_o th_o_all" colspan="2">',$L['Options'],'</td>';
echo '</tr>
';
echo '<tr class="data_o">
<td class="th_o th_o_first">',$L['Notification'],'</span></td>
<td class="td_o">
<table cellspacing="0" class="hidden">
<tr class="hidden">
<td class="hidden" width="200">
<input id="mailtoU" type="checkbox" name="mailto[]" value="U"',($bolUser ? QCHE : ''),' onchange="bEdited=true;"/> <label for="mailtoU">',$L['Userrole']['U'],'</label><br/>
<input id="mailtoMA" type="checkbox" name="mailto[]" value="MA"',($bolOper ? QCHE : ''),' onchange="bEdited=true;"/> <label for="mailtoMA">',$L['Userrole_MA'],'</label><br/>
<input id="mailtoMF" type="checkbox" name="mailto[]" value="MF"',($bolMode ? QCHE : ''),' onchange="bEdited=true;"/> <label for="mailtoMF">',$L['Userrole_MF'],'</label><br/>
<input id="mailto1" type="checkbox" name="mailto[]" value="1"',($bolAdmi ? QCHE : ''),' onchange="bEdited=true;"/> <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" onchange="bEdited=true;"/>',$others,'</textarea><br/>
<span class="small">',$L['H_Status_notify'],'</span>
</td>
</tr>
</table>
</td>
</tr>
';
echo '<tr class="data_o">
<td class="th_o th_o_all" colspan="2">',$L['Translations'],'</td>
</tr>
';
echo '<tr class="data_o">
<td class="th_o th_o_first">',$L['Status_name_and_desc'],'</td>
<td class="td_o" 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/qtr_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] : ''),'" onchange="bEdited=true;"/>
<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] : ''),'" onchange="bEdited=true;"/>
</td>
</tr>
';
}

echo '</table>
</td>
</tr>
';
echo '<tr class="data_o">
<td 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="',$oVIP->statuses[$id]['name'],'"/>
<input type="submit" name="ok" value="',$L['Save'],'"/></td>
</tr>
</table>
</form>
<p><a href="',$oVIP->exiturl,'" onclick="return qtEdited(bEdited,\'',$L['E_editing'],'\');">',$oVIP->exitname,'</a></p>
';

// HTML END

include('qtr_adm_p_footer.php');

?>
Return current item: QT-registrations