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

// QuickTicket 1.9.0.3 build:20081001

class cVIP
{

// --------

var $auth = false;
var $id = 0;
var $username = 'Guest';
var $role = 'V'; //A=Administator,M=Moderator,U=User,V=Visitor
var $numpost = 0;
var $selfurl = '';
var $selfname = '';
var $exiturl = 'qti_index.php';
var $exitname = 'Back';

// --------
// CLASS CONSTRUCTOR
// Get authentified user info, if exists in session (or if coockie is set)

function cVIP()
{
  if ( isset($_SESSION[QT.'_usr_auth']) ) {
  if ( $_SESSION[QT.'_usr_auth']=='yes' ) {

    $this->auth = true;
    if ( isset($_SESSION[QT.'_usr_id']) ) $this->id = intval($_SESSION[QT.'_usr_id']);
    if ( isset($_SESSION[QT.'_usr_name']) ) $this->username = $_SESSION[QT.'_usr_name'];
    if ( isset($_SESSION[QT.'_usr_role']) ) $this->role = $_SESSION[QT.'_usr_role'];
    if ( isset($_SESSION[QT.'_usr_posts']) ) $this->numpost = $_SESSION[QT.'_usr_posts'];

  }}

  if ( !$this->auth ) {
  if ( isset($_COOKIE[QT.'_cookname']) && isset($_COOKIE[QT.'_cookpass']) ) {

    global $oDB;
    $oDB->Query('SELECT * FROM '.TABUSER.' WHERE name="'.$_COOKIE[QT.'_cookname'].'" AND pwd="'.$_COOKIE[QT.'_cookpass'].'"');
    if ( $row = $oDB->Getrow() )
    {
      $this->auth = true;
      if ( isset($row['id']) ) $this->id = intval($row['id']);
      if ( isset($row['name']) ) $this->username= $row['name'];
      if ( isset($row['role']) ) $this->role = substr($row['role'],0,1);
      if ( isset($row['numpost']) ) { if ( !empty($row['numpost']) ) $this->numpost=intval($row['numpost']); }
      $this->Register();
    }

  }}
}

// --------
// DOLOGIN login and return extra info (fullname and coppa)

function Login($strUsername='',$strPwd='',$bRemember=FALSE)
{
  global $oDB;

  $oDB->Query( 'SELECT count(*) as countid FROM '.TABUSER.' WHERE name="'.$strUsername.'" AND pwd="'.sha1($strPwd).'"' );

  if ( $row = $oDB->Getrow() ) {
  if ( isset($row['countid']) ) {
  if ( $row['countid']==1 ) {

    $this->auth = true;

    // Get user info
    $oDB->Query('SELECT id,role,children,numpost,closed FROM '.TABUSER.' WHERE name="'.$strUsername.'" AND pwd="'.sha1($strPwd).'"');
    $row = $oDB->Getrow();
    $this->id = intval($row['id']);
    $this->username = $strUsername;
    $this->role = $row['role'];
    if ( !empty($row['numpost']) ) $this->numpost=intval($row['numpost']);

    // Register VIP info in session
    $this->Register();

    if ( $bRemember )
    {
    setcookie(QT.'_cookname', htmlspecialchars($this->username,ENT_QUOTES), time()+60*60*24*100, '/');
    setcookie(QT.'_cookpass', sha1($strPwd), time()+60*60*24*100, '/');
    }

    // Reset parameters (because the Role can impact the lists)
    unset($_SESSION['qtiGoto']);
    unset($_SESSION['qtiTstatus']);
    unset($_SESSION['qtiTtypes']);
    unset($_SESSION['qtiDomains']);

    return array('fullname'=>$strUsername,'coppa'=>intval($row['children']),'closed'=>intval($row['closed']));

  }}}

  return array('fullname'=>'','coppa'=>0,'closed'=>0);

}

// --------
// LOGOUT
// Remove session info (and cookie)

function Logout()
{
  $_SESSION=array();
  session_destroy();
  if ( isset($_COOKIE[QT.'_cookname']) ) setcookie(QT.'_cookname', '', time()+60*60*24*100, '/');
  if ( isset($_COOKIE[QT.'_cookpass']) ) setcookie(QT.'_cookpass', '', time()+60*60*24*100, '/');
}

// --------
// REGISTER

function Register()
{
  $_SESSION[QT.'_usr_auth'] = 'yes';
  $_SESSION[QT.'_usr_id'] = $this->id;
  $_SESSION[QT.'_usr_name'] = $this->username;
  $_SESSION[QT.'_usr_role'] = $this->role;
  $_SESSION[QT.'_usr_posts']= $this->numpost;
}

// --------
// @$strTitle: title of the message box. When null or empty string, uses the page name ($this->selfname)
//  when $strTitle=="0", it makes a direct exit
// @$strMessage: message body.
// @$strSkin: the skin folder
// @$intTime: the pause (in second) before redirecting to the exit page. Use 0 to NOT redirect.
// @$strWidth: css width parameter ("300px" or "90%")
// @$strIdHead: css id of the header
// @$strIdMain: css id of the body

function EndMessage($strTitle,$strMessage='Access denied',$strSkin='skin/default',$intTime=0,$strWidth='300px',$strTitleId='msgboxtitle',$strBodyId='msgbox')
{
  $this->exiturl = str_replace('&amp;','&',$this->exiturl);
  if ( $strTitle=='0' )
  {
    if ( headers_sent() )
    {
    echo '<a href="',$this->exiturl,'">',$this->exitname,'</a><meta http-equiv="REFRESH" content="0;url=',$this->exiturl,'">';
    }
    else
    {
    header('Location: '.$this->exiturl);
    }
    exit;
  }
  if ( empty($strTitle) ) $strTitle = $this->selfname;
  HtmlDtd();
  HtmlHead('',$strSkin,array(),'',array('com'=>false));
  HtmlPageCtrl(0,'90%');
  HtmlMsg(0,$strWidth,$strTitleId,$strTitle,$strBodyId);
  echo $strMessage,'
  <p><a id="exiturl" href="',$this->exiturl,'">',$this->exitname,'</a></p>';
  HtmlMsg(1);
  HtmlPageCtrl(1);

  if ( $intTime>0 )
  {
  echo '
  <script type="text/javascript">
  <!--
  setTimeout(\'window.location=document.getElementById("exiturl").href\',',($intTime*1000),');
  -->
  </script>
  ';
  }
  echo '</body></html>';
  exit;
}

// --------
// $strUsers, user roles that can access the page (ex: "MUV")
// $intVlevel, maximum access level for visitor
// $bStopOff, stop when board off-line (default=true)

function CanAccess($strUsers='---',$intVlevel=5,$bStopOff=true)
{
  if ( $_SESSION[QT]['board_offline']=='1' && $this->role=='A' ) echo '<p>Board is offline but Administrators can make some actions.</p>',N;
  if ( $this->role=='A' ) return true;
  if ( $_SESSION[QT]['board_offline']=='1' && $bStopOff ) return false;
  if ( strpos($strUsers, $this->role) === false ) return false;
  if ( $this->role=='V' && $_SESSION[QT]['visitor_right']<$intVlevel ) return false;
  return true;
}

// --------
}

?>
Return current item: QuickTicket