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

// QuickTicket 2.5.1 build:20110305

// --------
// HIGH LEVEL
// --------

function CheckDico($arr)
{
  if ( is_string($arr) ) $arr=explode(' ',$arr);
  if ( !is_array($arr) ) die('CheckDico: arg #1 be an array');
  foreach($arr as $str)
  {
  if ( !isset($_SESSION['L'][$str]) ) $_SESSION['L'][$str] = cVIP::LangGet($str,GetIso(),'*');
  }
}

// --------

function Error($i=0)
{
  include(Translate('qti_error.php'));
  if ( isset($e[$i]) ) return $e[$i];
  return 'Error '.$i;
}

// --------

function GetIso($str='')
{
  if ( empty($str) ) $str=$_SESSION[QT]['language'];
  switch(strtolower($str))
  {
  case 'english': return 'en'; break;
  case 'francais': return 'fr'; break;
  case 'nederlands': return 'nl'; break;
  default: include('bin/qti_lang.php'); $arr=array_flip(QTarrget($arrLang,2)); if ( isset($arr[$str]) ) return $arr[$str]; break;
  }
  return 'en';
}

// --------

function GetLang($str='')
{
  if ( empty($str) ) $str=$_SESSION[QT]['language'];
  return 'language/'.$str.'/';
}
// --------

function Href($str='')
{
  // When urlrewriting is active, the url can be displayed in html format (they will be converted by the server's rewrite rule).
  // This function transforms a php url into a html like url (the url can have arguments): 'qti_login.php' is displayed as 'login.html'.
  // Note: Don't worry, server's rewriting has NO effect when the url is in php format (i.e. when this function is not used or when QTI_URLREWRITE is FALSE)
  if ( empty($str) ) { global $oVIP; $str=$oVIP->selfurl; }
  if ( QTI_URLREWRITE ) {
  if ( substr($str,0,4)=='qti_' && strstr($str,'.php') ) {
    $str = substr($str,4);
    $str = str_replace('.php','.html',$str);
  }}
  return $str;
}

// --------

function L($str='') { global $L; return (isset($L[$str]) ? $L[$str] : $str); }

// --------

function LangS($strVar,$intVar,$bInclude=true)
{  
  //  Returns the plural when $intVal>1 (and if the plural word exists)
  //  The variable $strVar can be composed of 2 strings (comma separated): LangS['userrole,A',25] returns $L['Userroles']['A']
  //  $bInclude=true will returns number + space + the word

  global $L;
  if ( !strstr($strVar,',') )
  {
    if ( !isset($L[$strVar]) ) return ($bInclude ? $intVar.' ' : '').$strVar;
    if ( $intVar>1 && isset($L[$strVar.'s']) ) return ($bInclude ? $intVar.' ' : '').$L[$strVar.'s'];
    return ($bInclude ? $intVar.' ' : '').$L[$strVar];
  }
  else
  {
    $arr = explode(',',$strVar);
    if ( !isset($L[$arr[0]][$arr[1]]) ) return ($bInclude ? $intVar.' ' : '').$strVar;
    if ( $intVar>1 && isset($L[$arr[0].'s'][$arr[1]]) ) return ($bInclude ? $intVar.' ' : '').$L[$arr[0].'s'][$arr[1]];
    return ($bInclude ? $intVar.' ' : '').$L[$arr[0]][$arr[1]];    
  }
}

// --------

function ObjTrans($strType,$strId,$bGenerate=true,$intMax=0,$strTrunc='...')
{
  // This function returns the translation of the objid
  // When translation is not defined and generate is true, returns the ucfirst(objid)
  // otherwise, returns ''
  // When $intMax>1, the text is truncated to intMax characters and the $strTrunc is added.

  $str = '';
  if ( isset($_SESSION['L'][$strType][$strId]) ) $str = $_SESSION['L'][$strType][$strId];

  if ( empty($str) && $bGenerate ) {
  switch($strType) {
    case 'field': $str = ucfirst(str_replace('_',' ',$strId)); break;
    case 'tabdesc': $str = $bGenerate ;
    case 'tab': $str = ucfirst(str_replace('_',' ',$strId)); break;
    case 'tabdesc': $str = $bGenerate; break;
    case 'index': $str = $_SESSION[QT]['index_name']; break;
    case 'domain': $str = $bGenerate; break;
    case 'sec': $str = $bGenerate; break;
    case 'secdesc': $str = $bGenerate; break;
  }}
  
  if ( $intMax>1 && strlen($str)>$intMax ) return substr($str,0,$intMax).$strTrunc;
  return $str;
}

// --------

function Translate($strFile)
{
  if ( file_exists(GetLang().$strFile) ) Return GetLang().$strFile;
  Return 'language/english/'.$strFile;
}

// --------
// COMMON FUNCTIONS
// --------

function AsMailsExplode($str,$intMax=0)
{
  // Returns an array. Separator can be: space, comma or semi-colomn. Use $intMax>0 to return only $intMax entries
  if ( !is_string($str) ) return array();
  if ( empty($str) ) return array();
  $arr = explode(';',str_replace(';;',';',strtr(trim($str),' ,',';;')));
  $n=count($arr); //required
  for($i=0;$i<$n;$i++) { if ( empty($arr[$i]) ) unset($arr[$i]); } // drop empty (and '0')
  $arr = array_values($arr); // reset the keys
  if ( $intMax>0 ) return array_slice($arr, 0, $intMax);
  return $arr;
}

function AsEmails($strEmails,$strId,$strSection='0',$strRender='txt',$bFirst=false,$strSkin='skin/default',$strNojava='Java protected email',$strEmpty='&nbsp;')
{
  if ( !is_string($strEmails) ) return $strEmpty;
  if ( empty($strEmails) ) return $strEmpty;
  // get list of Emails
  if ( strstr($strEmails,' ; ') ) { $arrEmails = explode(' ; ',$strEmails); } else { $arrEmails = array($strEmails); }
  // get first Email
  $strFirst = $arrEmails[0];
  // only one email
  if ( $bFirst ) $arrEmails = array($strFirst);
  // build expression
  $strReturn = '';
  switch ($strRender)
  {
  case 'txt':
    $strReturn .= '<a id="href'.$strId.'s'.$strSection.'" class="small" href="mailto:'.implode(';',$arrEmails).'">';
    $strReturn .= implode(' ; ',$arrEmails);
    $strReturn .= '</a>';
    break;
  case 'img':
    $strReturn .= '<a id="href'.$strId.'s'.$strSection.'" class="small" href="mailto:'.implode(';',$arrEmails).'">';
    $strReturn .= '<img class="ico ico_user" id="img'.$strId.'s'.$strSection.'" src="'.$strSkin.'/ico_user_e_1.gif" alt="email" title="'.$strFirst.'" />';
    $strReturn .= '</a>';
    break;
  case 'txtjava':
    $strReturn .= '<script type="text/javascript">';
    foreach($arrEmails as $strEmail)
    {
    $arr = explode('@',$strEmail);
    $strReturn .= 'qtWritemailto("'.$arr[0].'","'.$arr[1].'"," ");';
    }
    $strReturn .= '</script><noscript class="small">'.$strNojava.'</noscript>';
    break;
  case 'imgjava':
    $str = implode(';',$arrEmails);
    $str = str_replace('@','-at-',$str);
    $str = str_replace('.','-dot-',$str);
    $strFirst = str_replace('@','-at-',$strFirst);
    $strFirst = str_replace('.','-dot-',$strFirst);
    $strReturn .= '<a id="href'.$strId.'s'.$strSection.'" onmouseover="qtVmail(\''.$strId.'s'.$strSection.'\');" onmouseout="qtHmail(\''.$strId.'s'.$strSection.'\');" class="small" href="javamail:'.$str.'">';
    $strReturn .= '<img class="ico ico_user" id="img'.$strId.'s'.$strSection.'" src="'.$strSkin.'/ico_user_e_1.gif" alt="email" title="'.$strFirst.'" />';
    $strReturn .= '</a>';
    break;
  }

  return $strReturn;
}

// --------

function AsImg($strSrc='',$strAlt='',$strTitle='',$strClass='',$strStyle='',$strHref='',$strId='')
{
  QTargs( 'AsImg',array($strSrc,$strAlt,$strClass,$strStyle,$strHref,$strId) );

  if ( empty($strSrc) ) return '';
  $strSrc = '<img src="'.$strSrc.'" alt="'.(empty($strAlt) ? '' : QTconv($strAlt)).'" title="'.(empty($strTitle) ? '' : QTconv($strTitle)).'"'.(!empty($strClass) ? ' class="'.$strClass.'"' : '').(empty($strStyle) ? '' : ' style="'.$strStyle.'"').(empty($strId) ? '' : ' id="'.$strId.'"').' />';
  if ( empty($strHref) ) { return $strSrc; } else { return '<a href="'.Href($strHref).'">'.$strSrc.'</a>' ; }
}

// --------

function AsImgBox($strSrc='',$strClass='',$strStyle='',$strCaption='',$strHref='',$strId='')
{
  QTargs( 'AsImgBox',array($strSrc,$strClass,$strStyle,$strCaption,$strHref) );

  if ( !empty($strHref) ) $strCaption = '<a href="'.Href($strHref).'" class="small">'.$strCaption.'</a>';
  return '<div'.(empty($strClass) ? '' : ' class="'.$strClass.'"').(empty($strStyle) ? '' : ' style="'.$strStyle.'"').(empty($strId) ? '' : ' id="'.$strId.'"').'>'.$strSrc.(empty($strCaption) ? '' : '<p class="imgcaption">'.$strCaption.'</p>').'</div>';
}

// --------

function AsAvatarScr($str='')
{
  if ( empty($str) ) return '';
  if ( isset($_SESSION[QT]['avatar']) ) { if ( $_SESSION[QT]['avatar']=='0' ) return ''; }
  return QTI_DIR_PIC.$str;
}

// --------

function DateAdd($d='0',$i=-1,$str='year')
{
   if ( $d=='0' ) die('DateAdd: Argument #1 must be a string');
   QTargs( 'DateAdd',array($d,$i,$str),array('str','int','str') );

   $intY = intval(substr($d,0,4));
   $intM = intval(substr($d,4,2));
   $intD = intval(substr($d,6,2));
   switch($str)
   {
   case 'year': $intY += $i; break;
   case 'month': $intM += $i; break;
   case 'day': $intD += $i; break;
   }
   if ( in_array($intM,array(1,3,5,7,8,10,12)) && $intD>31 ) { $intM++; $intD -= 31; }
   if ( in_array($intM,array(4,6,9,11)) && $intD>30 ) { $intM++; $intD -= 30; }
   if ( $intD<1 ) { $intM--; $intD += 30; }
   if ( $intM>12 ) { $intY++; $intM -= 12; }
   if ( $intM<1 ) { $intY--; $intM += 12; }
   if ( $intM==2 && $intD>28 ) { $intM++; $intD -= 28; }
   return strval($intY*10000+$intM*100+$intD).(strlen($d)>8 ? substr($d,8) : '');
}

// --------

function CanPerform($strParam,$strRole='V')
{
  // valid parameter are: upload, show_calendar, show_stats
  if ( empty($strParam) || !isset($_SESSION[QT][$strParam]) ) return false;
  if ( $_SESSION[QT][$strParam]=='A' && $strRole=='A' ) return true;
  if ( $_SESSION[QT][$strParam]=='M' && ($strRole=='A' || $strRole=='M') ) return true;
  if ( $_SESSION[QT][$strParam]=='U' && $strRole!='V' ) return true;
  if ( $_SESSION[QT][$strParam]=='V' ) return true;
  return false;
}

// --------

function FieldQuote($strValue,$strTable,$strField)
{
  // Returns a quoted value, except for these fields:
  if ( $strTable==TABTOPIC && in_array($strField,array('id','numid','forum','firstpostid','lastpostid','firstpostuser','lastpostuser','x','y','z','actorid','notifiedid','replies','views'),$strField) ) return ($strValue==='' || is_null($strValue) ? 'NULL' : $strValue);
  if ( $strTable==TABPOST && in_array($strField,array('id','forum','topic','userid','modifuser')) ) return ($strValue==='' || is_null($strValue) ? 'NULL' : $strValue);
  if ( $strTable==TABUSER && $strField=='id' ) return ($strValue==='' || is_null($strValue) ? 'NULL' : $strValue);  
  if ( $strTable==TABSECTION && in_array($strField,array('id','domainid','titleorder','moderator')) ) return ($strValue==='' || is_null($strValue) ? 'NULL' : $strValue);
  if ( $strTable==TABDOMAIN && in_array($strField,array('id','titleorder')) ) return ($strValue==='' || is_null($strValue) ? 'NULL' : $strValue);
  if ( $strTable==TABSTATUS && $strField=='id' ) return ($strValue==='' || is_null($strValue) ? 'NULL' : $strValue);
  if ( empty($strValue) ) {
  if ( in_array($strField,array('birthday','docdate','eventdate','fielddate','firstdate','firstpostdate','issuedate','lastdate','lastpostdate','modifdate','statusdate','wisheddate')) ) {
    return '"0"';
  }}
  return '"'.$strValue.'"';
}

// --------

function GetDomains($strRole='0')
{
  // Returns an array of [key] id, [value] title (title is translated)
  // When $strRole is defined, returns only the domains containing visible sections
  
  global $oDB;
  $arr = array();
  
  if ( empty($strRole) || $strRole=='A' || $strRole=='M' )
  {
  $oDB->Query( 'SELECT id,title FROM '.TABDOMAIN.' ORDER BY titleorder' );
  }
  else
  {
  $oDB->Query( 'SELECT d.id,d.title FROM '.TABDOMAIN.' d INNER JOIN '.TABSECTION.' s ON s.domainid=d.id WHERE s.type<>1 ORDER BY d.titleorder' );
  }
  while($row=$oDB->Getrow())
  {
    $id = intval($row['id']);
    $arr[$id] = ObjTrans('domain','d'.$id,false); if ( empty($arr[$id]) ) $arr[$id]=$row['title'];
  }  
  return $arr;
}

// --------

function GetParam($bRegister=false,$strWhere='loaded<>"9"')
{
  global $oDB;
  $arrParam = array();
  $oDB->Query('SELECT param,setting FROM '.TABSETTING.' WHERE '.$strWhere);
  while($row=$oDB->Getrow())
  {
  $arrParam[$row['param']]=$row['setting'];
  if ( $bRegister ) $_SESSION[QT][$row['param']]=$row['setting'];
  }
  Return $arrParam;
}

// --------

function GetSections($strRole='V',$intDomain=-1,$intReject=-1,$strExtra='',$strOrder='d.titleorder,s.titleorder')
{
  // Returns an array of [key] section id, array of [values] section

  QTargs( 'GetSections',array($strRole,$intDomain,$intReject,$strExtra,$strOrder),array('str','int','int','str','str') );

  global $oDB;

  if ( $intDomain>=0 ) { $strWhere = 's.domainid='.$intDomain; } else { $strWhere = 's.domainid>=0'; }
  if ( $strRole=='V' || $strRole=='U' ) $strWhere .= ' AND s.type<>"1"';
  if ( !empty($strExtra) ) $strWhere .= ' AND '.$strExtra;

  $arr = array();
  $oDB->Query( 'SELECT s.* FROM '.TABSECTION.' s INNER JOIN '.TABDOMAIN.' d ON s.domainid=d.id WHERE '.$strWhere.' ORDER BY '.$strOrder );
  while($row=$oDB->Getrow())
  {
    $id = intval($row['id']);
    // if reject
    if ( $intReject>=0 && $id==$intReject ) continue;
    // section create
    $arr[$id] = $row;
    // search translation
    $str = ObjTrans('sec','s'.$id,false);
    if ( !empty($str) ) $arr[$id]['title']=$str;
  }
  return $arr;
}
// --------

function GetStats($bClosed=false)
{
  // returns topics and replies per section id
  $arr = array('all'=>array('topics'=>0,'replies'=>0,'topicsZ'=>0,'repliesZ'=>0));
  global $oDB;
  $oDB->Query( 'SELECT s.id,count(t.id) as topics,sum(t.replies) as replies FROM '.TABSECTION.' s LEFT JOIN '.TABTOPIC.' t ON s.id=t.forum GROUP BY s.id' );
  while($row=$oDB->Getrow())
  { 
    $i = (isset($row['topics']) ? intval($row['topics']) : 0);
    $arr[intval($row['id'])]['topics']=$i; $arr['all']['topics'] += $i;
    $i = (isset($row['replies']) ? intval($row['replies']) : 0);
    $arr[intval($row['id'])]['replies']=$i; $arr['all']['replies'] += $i;
  }
  if ( $bClosed )
  {
    $oDB->Query( 'SELECT s.id,count(t.id) as topics,sum(t.replies) as replies FROM '.TABSECTION.' s LEFT JOIN '.TABTOPIC.' t ON s.id=t.forum WHERE t.status="1" GROUP BY s.id' );
    while($row=$oDB->Getrow())
    {
    $i = (isset($row['topicsZ']) ? intval($row['topicsZ']) : 0);
    $arr[intval($row['id'])]['topicsZ']=$i; $arr['all']['topicsZ'] += $i;
    $i = (isset($row['repliesZ']) ? intval($row['repliesZ']) : 0);
    $arr[intval($row['id'])]['repliesZ']=$i; $arr['all']['repliesZ'] += $i;
    }
  }
  return $arr;
}

/**
 *
 * GetUserInfo
 *
 * Options supported for the $intUser:
 * i [int] a userid,
 * "S" [string] all staff members,
 * "A" [string] all administrators,
 * "i" [string] the coordinator of section i
 * will return a list of values (as string)
 *
 **/
function GetUserInfo($intUser=null,$strField='name',$oSEC=null)
{
  global $oDB;

  if ( is_string($intUser) )
  {
    if ( $intUser=='A' || $intUser=='S' )
    {
      $lst = array();
      $oDB->Query('SELECT '.$strField.' FROM '.TABUSER.' WHERE role="'.$intUser.'"');
      while( $row=$oDB->Getrow() )
      {
      $lst[] = $row[$strField];
      }
      return $lst;
    }
    if ( is_numeric($intUser) )
    {
      if ( !isset($oSEC) ) $oSEC = new cSection(intval($intUser));
      $oDB->Query('SELECT '.$strField.' FROM '.TABUSER.' WHERE id='.$oSEC->modid);
      $row=$oDB->Getrow();
      return $row[$strField];
    }
  }
  if ( is_int($intUser) )
  {
    if ( $intUser<0 ) die ('GetUserInfo: Missing user id');
    $oDB->Query('SELECT '.$strField.' FROM '.TABUSER.' WHERE id='.$intUser);
    $row = $oDB->Getrow();
    return $row[$strField];
  }
  die ('GetUserInfo: Invalid argument #1 '.var_dump($intUser));
}

// --------

function GetUsers($strRole='A',$strValue='',$strOrder='name',$iMax=200)
{
  // Return an array of maximum iMax=200 users id/name
  // $strRole: Search 'A' admins, 'M' staff(+admin), 'M-' staff(-admin), 'NAME' a name, 'A*' a name beginning by A, 'ID' the user having id=$strValue
  // Attention: names are htmlquoted in the db, no need to stripslashes

  global $oDB; 
  if ( substr($strRole,-1,1)==='*' )
  {
    $strQ = 'name '.($oDB->type=='pg' ? 'ILIKE' : 'LIKE' ).' "'.substr($strRole,0,-1).'%" ORDER BY '.$strOrder;
  }
  else
  {
    switch(strtoupper($strRole))
    {
    case 'A':   $strQ = 'role="A" ORDER BY '.$strOrder; break;
    case 'M':   $strQ = 'role="A" OR role="M" ORDER BY '.$strOrder; break;
    case 'M-':  $strQ = 'role="M" ORDER BY '.$strOrder; break;
    case 'NAME':$strQ = 'name="'.$strValue.'" ORDER BY '.$strOrder; break;
    case 'ID':  $strQ = 'id='.$strValue; break;
    default: die('GetUsers: Unkown search rule ['.$strRole.']');
    }
  }
  $oDB->Query( 'SELECT id,name FROM '.TABUSER.' WHERE '.$strQ );
  $arrUsers = array();
  $i=1;
  while ($row=$oDB->Getrow())
  {
    $arrUsers[$row['id']]=$row['name'];
    $i++; if ( $i>$iMax ) break;
  }
  return $arrUsers;
}

// --------

function InvalidUpload($arrFile=array(),$strExtensions='',$strMimes='',$intSize=0,$intWidth=0,$intHeight=0)
{
  // For the uploaded document ($arrFile), this function returns (as string):
  // '' (empty string) if it matches with all conditions (see parameters)
  // An error message if not, and unlink the uploaded document.
  //
  // @$arrFile: The uploaded document ($_FILES['fieldname']).
  // @$strExtensions: List of valid extensions (as string, without point). Empty to skip.
  // @$strMimes: List of valid mimetypes as csv (can be an array). Empty to skip
  // @$intSize: Maximum file size (kb). 0 to skip.
  // @$intWidth: Maximum image width (pixels). 0 to skip.
  // @$intHeight: Maximum image width (pixels). 0 to skip.
  
  if ( is_array($strExtensions) ) $strExtensions=implode(', ',$strExtensions);
  if ( is_array($strMimes) ) $strMimes=implode(', ',$strMimes);
  
  if ( !is_array($arrFile) ) die('CheckUpload: argument #1 must be an array');
  if ( !is_string($strExtensions) ) die('CheckUpload: argument #2 must be a string');
  if ( !is_string($strMimes) ) die('CheckUpload: argument #3 must be a string');
  if ( !is_int($intSize) ) die('CheckUpload: argument #4 must be an integer');
  if ( !is_int($intWidth) ) die('CheckUpload: argument #5 must be an integer');
  if ( !is_int($intHeight) ) die('CheckUpload: argument #6 must be an integer');
  
  global $L;
  
  // check load
  
  if ( !is_uploaded_file($arrFile['tmp_name']) ) 
  {
    if ( isset($arrFile['error']) ) 
    {
      switch($arrFile['error'])
      {
      case 1: return 'Upload error #1. File size exceeds the server limit.'; break;
      case 2: return 'Upload error #2. File size exceeds the form limit (&lt;'.$intSize.' Kb)'; break;
      case 3: return 'Upload error #3. File not fully transmitted.'; break;
      default: return 'Upload error #'.$arrFile['error'].'. File not uploaded'; break;
      }
    }
    return 'You id not upload a file!';
  }

  // check size (kb)

  if ( $intSize>0 ) {
  if ( $arrFile['size'] > ($intSize*1024+16) ) {
    unlink($arrFile['tmp_name']);
    return $L['E_file_size'].' (&lt;'.$intSize.' Kb)';
  }}

  // check extension
  
  if ( !empty($strExtensions) )
  {
    $strExt = strrchr($arrFile['name'],'.');
    if ( $strExt===FALSE )
    {
    unlink($arrFile['tmp_name']);
    return 'File without extension not supported... Use '.$strExtensions;
    }    
    $strExt = substr($strExt,1); //remove the point
    if ( strpos(strtolower($strExtensions),strtolower($strExt))===FALSE )
    {
    unlink($arrFile['tmp_name']);
    return 'File extension ['.$strExt.'] not supported... Use '.$strExtensions;
    }
  }

  // check mimetype
  
  if ( !empty($strMimes) ) {
  if ( strpos(strtolower($strMimes),strtolower($arrFile['type']))===FALSE ) {
    unlink($arrFile['tmp_name']);
    return 'Format ['.$arrFile['type'].'] not supported... Use '.$strExtensions;
  }}

  // check size (pixels)

  if ( $intWidth>0 || $intHeight>0 )
  {
    $size = getimagesize($arrFile['tmp_name']);
    if ( $intWidth>0 ) {    
    if ( $size[0] > $intWidth ) {
      unlink($arrFile['tmp_name']);
      return $intWidth.'x'.$intHeight.' '.$L['E_pixels_max'];
    }}
    if ( $intHeight>0 ) {    
    if ( $size[1] > $intHeight ) {
      unlink($arrFile['tmp_name']);
      return $intWidth.'x'.$intHeight.' '.$L['E_pixels_max'];
    }}
  }
 
  return '';
}

// --------

function MakePager($uri,$count,$intPagesize=50,$currentpage=1)
{
  global $L;
  $arrUri = parse_url($uri);
  $uri = Href($arrUri['path']);
  $arg = $arrUri['query'];
  $arrArg = explode('&',$arg);
  $arrNew = array();
  foreach($arrArg as $strValue)
  {
    if ( substr($strValue,0,4)=='page' ) continue;
    $arrNew[]=$strValue;
  }
  $arg = implode('&amp;',$arrNew);

  $strPages='';
  $firstpage='';
  $lastpage='';
  $top = ceil($count/$intPagesize);
  if ( $currentpage<5 )
  {
    $arrPages=array(1,2,3,4,5);
  }
  elseif ( $currentpage==$top )
  {
    $arrPages=array($currentpage-4,$currentpage-3,$currentpage-2,$currentpage-1,$currentpage); 
  }
  else 
  {
    $arrPages=array($currentpage-2,$currentpage-1,$currentpage,$currentpage+1,$currentpage+2);
  }

  // pages
  foreach($arrPages as $page)
  {
    if ( $count>$intPagesize && $page>=1 && $page<=$top )
    {
    $strPages .= ' '.($currentpage==$page ? '<b>'.$page.'</b>' : '<a href="'.$uri.'?'.$arg.'&amp;page='.$page.'">'.$page.'</a>');
    }
  }
  // extreme
  if ( $count>($intPagesize*5) )
  {
    if ( $arrPages[0]>1 ) $firstpage = ' <a href="'.$uri.'?'.$arg.'&amp;page=1" title="'.$L['First'].'">&laquo;</a>';
    if ( $arrPages[4]<$top ) $lastpage = ' <a href="'.$uri.'?'.$arg.'&amp;page='.$top.'" title="'.$L['Last'].': '.$top.'">&raquo;</a>';
  }
  return $firstpage.$strPages.$lastpage;
}

// --------

function TargetDir($strRoot='',$intId=0)
{
  // This check if directory/subdirectory is available for an Id

  $strDir = '';
  $intDir = ($intId>0 ? floor($intId/1000) : 0);
  if ( is_dir($strRoot.strval($intDir).'000') )
  {
    $strDir = strval($intDir).'000/';    
    $intSDir = $intId-($intDir*1000);
    $intSDir = ($intSDir>0 ? floor($intSDir/100) : 0);
    if ( is_dir($strRoot.$strDir.strval($intDir).strval($intSDir).'00') ) $strDir .= strval($intDir).strval($intSDir).'00/';
  }
  return $strDir;
}

// --------

function ToCsv($str,$strSep=';',$strEnc='"',$strSepAlt=',',$strEncAlt="'")
{
  // Converts a value ($str) to a csv text with final separator [;]. A string is enclosed by ["].
  // When $str contains the separator or the encloser character, they are replaced by the alternates ($strSepAlt,$strEncAlt)
  // TIP: $strSep empty (or "\r\n") to generate a end-line value
  if ( is_int($str) || is_float($str) ) return $str.$strSep;
  if ( $str==='' || is_null($str) ) return $strEnc.$strEnc.$strSep;
  $str = str_replace('&nbsp;',' ',$str);
  $str = str_replace("\r\n",' ',$str);
  $str = QTconv($str,'-4');
  $str = str_replace($strSep,$strSepAlt,$str);
  $str = str_replace($strEnc,$strEncAlt,$str);
  return $strEnc.$str.$strEnc.$strSep;
}

// --------

function UseModule($strName=null)
{
  if ( !is_string($strName) ) die('UseModule: arg #1 must be a string');
  if ( isset($_SESSION[QT]['module_'.$strName]) ) return TRUE;
  return FALSE;
}

?>
Return current item: QuickTicket