Location: PHPKode > projects > QuickTalk Forum > quicktalk/bin/qtf_fn_base.php
<?php

// QuickTalk 2.5 build:20100924

// --------
// 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('qtf_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/qtf_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): 'qtf_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 QTF_URLREWRITE is FALSE)
  if ( empty($str) ) { global $oVIP; $str=$oVIP->selfurl; }
  if ( QTF_URLREWRITE ) {
  if ( substr($str,0,4)=='qtf_' && 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); } // 2.4

// --------

//  Returns the plural (if $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

function LangS($strVar,$intVar,$bInclude=true)
{  
  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 '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 i_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 .= 'writemailto("'.$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="vmail(\''.$strId.'s'.$strSection.'\');" onmouseout="hmail(\''.$strId.'s'.$strSection.'\');" class="small" href="javamail:'.$str.'">';
    $strReturn .= '<img class="ico i_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="'.$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="'.$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 DateAdd($d='0',$i=-1,$str='year')
{
   if ( $d=='0' ) die('DateAdd: Argument #1 must be a string');
   if ( !is_string($d) ) die('DateAdd: Argument #1 must be a string');
   if ( !is_integer($i) ) die('DateAdd: Argument #2 must be an integer');
   if ( !is_string($str) ) die('DateAdd: Argument #3 must be a string');
   $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 ( $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]) ) { echo 'undefined CanPerform()'; 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 GetDomains($strRole='A',$strOrder='titleorder')
{
  // 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 ( $strRole=='A' || $strRole=='M' )
  {
  $oDB->Query( 'SELECT id,title FROM '.TABDOMAIN.' ORDER BY '.$strOrder );
  }
  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.'.$strOrder );
  }
  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']]=strval($row['setting']);
  if ( $bRegister ) $_SESSION[QT][$row['param']]=strval($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 ) { if ( isset($onerror) ) return $onerror; 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));
}

/**
 *
 * GetUsers
 *
 * Return an array of (maximum 200) users id/name
 * number = returns 1 user [id][name]
 * "A"   = returns administrators (default)
 * "M"   = returns moderators (+Admin)
 * "M-"   = returns moderators (-Admin)
 * "name" = return the user having the name [strValue]
 * "A*"   = returns names beginning by A
 *
 * Attention: names are htmlquoted in the db, no need to stripslashes
 *
 **/
function GetUsers($strRole='A',$strValue='')
{
  global $oDB;
  $strQ = 'SELECT id,name FROM '.TABUSER.' WHERE role="A"';

  if ( $strRole=='M' )  $strQ = 'SELECT id,name FROM '.TABUSER.' WHERE role="A" OR role="M" ORDER BY name';
  if ( $strRole=='M-' )  $strQ = 'SELECT id,name FROM '.TABUSER.' WHERE role="M" ORDER BY name';
  if ( $strRole=='name') $strQ = 'SELECT id,name FROM '.TABUSER.' WHERE name="'.$strValue.'" ORDER BY name';
  if ( substr($strRole,-1,1)=='*' )
  {
    $like = 'LIKE'; if ( $oDB->type=='pg' ) $like = 'ILIKE';
    $strQ = 'SELECT id,name FROM '.TABUSER.' WHERE name '.$like.' "'.substr($strRole,0,-1).'%" ORDER BY name';
  }
  $oDB->Query($strQ);

  $arrUsers = array();
  $i=1;
  while ($row=$oDB->Getrow())
  {
    $arrUsers[$row['id']]=$row['name'];
    $i++;
    if ( $i>200 ) 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). Empty to skip.
   * @$strMimes: List of valid mimetypes (as string). 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.
   */
  
  // check arguments
  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']) ) 
  {
    unlink($arrFile['tmp_name']);
    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) )
  {
    $ext = strtolower(substr($arrFile['name'],-4,4)); if ( substr($ext,0,1)=='.' ) $ext = substr($ext,1);
    if ( strpos(strtolower($strExtensions),$ext)===FALSE )
    {
    unlink($arrFile['tmp_name']);
    return 'Format ['.substr($arrFile['name'],-4,4).'] 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 ReadValues($str='',$arrChg=array())
{
  // Convert $str to an array. Also changes/adds $arrChg values to the list
  $arrValues = array();
  if ( empty($str) ) return $arrValues;
  $arr = explode(';',$str);
  foreach($arr as $str)
  {
  $a = explode('=',$str);
  if ( count($a)==2 ) $arrValues[$a[0]]=$a[1];
  }
  foreach($arrChg as $strKey=>$strValue) $arrValues[$strKey]=$strValue; // add or change values
  return $arrValues;
}

// --------

function ResumeValues($arr)
{
  // Convert an array to a string "key=value;..."
  if ( !is_array($arr) ) die('ResumeValues: argument #1 must be an array');
  $str = '';
  foreach($arr as $strKey=>$strValue) $str .= (empty($str) ? '' : ';').$strKey.'='.$strValue;
  return $str;
}

// --------

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)
{
  if ( !is_string($strName) ) die('UseModule: arg #1 must be an string');
  if ( isset($_SESSION[QT]['module_'.$strName]) ) return TRUE;
  return FALSE;  
}

?>
Return current item: QuickTalk Forum