PHPOpenChat PHP Cross Reference Customer Relationship Management

Source: /index.php - 464 lines - 20299 bytes - Summary - Text - Print

   1  <?php // -*-php-*-
   2  /*   ********************************************************************   **
   3  **   Copyright notice                                                       **
   4  **                                                                          **
   5  **   (c) 1995-2004 PHPOpenChat Development Team                             **
   6  **   http://phpopenchat.sourceforge.net/                                    **
   7  **                                                                          **
   8  **   All rights reserved                                                    **
   9  **                                                                          **
  10  **   This script is part of the PHPOpenChat project. The PHPOpenChat        **
  11  **   project is free software; you can redistribute it and/or modify        **
  12  **   it under the terms of the GNU General Public License as published by   **
  13  **   the Free Software Foundation; either version 2 of the License, or      **
  14  **   (at your option) any later version.                                    **
  15  **                                                                          **
  16  **   The GNU General Public License can be found at                         **
  17  **   http://www.gnu.org/copyleft/gpl.html.                                  **
  18  **   A copy is found in the textfile GPL and important notices to the       **
  19  **   license from the team is found in the textfile LICENSE distributed     **
  20  **   with these scripts.                                                    **
  21  **                                                                          **
  22  **   This script is distributed in the hope that it will be useful,         **
  23  **   but WITHOUT ANY WARRANTY; without even the implied warranty of         **
  24  **   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          **
  25  **   GNU General Public License for more details.                           **
  26  **                                                                          **
  27  **   This copyright notice MUST APPEAR in all copies of the script!         **
  28  **   ********************************************************************   */
  29  
  30  /*
  31    $Author: letreo $
  32    $Date: 2004/08/26 11:57:24 $
  33    $Source: /cvsroot/phpopenchat/chat3/index.php,v $
  34    $Revision: 1.74.2.32 $
  35  */
  36  // Get default values
  37  require_once ('config.inc.php');
  38  
  39  require_once (POC_INCLUDE_PATH . '/adodb/adodb.inc.php');
  40  
  41  require_once (POC_INCLUDE_PATH . '/class.Chat.inc');
  42  require_once (POC_INCLUDE_PATH . '/class.Chatter.inc');
  43  require_once (POC_INCLUDE_PATH . '/class.Line.inc');
  44  require_once (POC_INCLUDE_PATH . '/class.Channel.inc');
  45  require_once(POC_INCLUDE_PATH . '/class.Channel_Buffer_' . CHANNEL_BUFFER_TYPE . '.inc');
  46  require_once (POC_INCLUDE_PATH . '/class.Template.inc');
  47  require_once (POC_INCLUDE_PATH . '/class.Translator.inc');
  48  require_once (POC_INCLUDE_PATH . '/class.Logger.inc');
  49  require_once (POC_INCLUDE_PATH . '/class.HttpNegotiation.inc');
  50  
  51  function session_error($errno, $errmsg, $filename, $linenum, $vars)
  52  {
  53      POC_Chat::display_error($errno, $errmsg, $filename, $linenum, $vars, POC_SESSION_ERROR);
  54  } 
  55  function db_error($errno, $errmsg, $filename, $linenum, $vars)
  56  {
  57      POC_Chat::display_error($errno, $errmsg, $filename, $linenum, $vars, POC_DB_ERROR);
  58  } 
  59  
  60  set_error_handler('session_error');
  61  /*don't start the the session, if we are in postnuke context*/
  62  if (!function_exists('pnUserGetVar')) {
  63      session_start();
  64  } 
  65  restore_error_handler();
  66  
  67  $jScript = '';
  68  $operator_passwd = '';
  69  $chatters_online_list = '';
  70  $_tmp = (isset($_SESSION['chatter'])&&is_object($_SESSION['chatter']))? $_SESSION['chatter']->get_user():'';
  71  if (!isset($_GET['nickname']))
  72      $_GET['nickname'] = (isset($_COOKIE['poc_nick']))? $_COOKIE['poc_nick']:$_tmp;
  73  if (!isset($_GET['password']))
  74      $_GET['password'] = (isset($_COOKIE['poc_password']))? $_COOKIE['poc_password']:$_tmp; //it's a fake, only to show some stars in the password field
  75  unset($_tmp);
  76  
  77  function check_private_icon($nick)
  78  {
  79      global $ACCEPTED_MIME_TYPES;
  80      $smiley_dir = '/images/icons/chatter';
  81      for ($i = 0;$i < count($ACCEPTED_MIME_TYPES);$i++) {
  82          preg_match('#image/[x\-]?(.*)#', $ACCEPTED_MIME_TYPES[$i], $parts);
  83          $file_extension = $parts[1];
  84          $smiley_path = $smiley_dir . '/' . strtolower($nick) . '.' . $file_extension;
  85          if (file_exists($_SESSION['template']->get_tmpl_sys_path() . $smiley_path))
  86              return '<img src="' . $_SESSION['template']->get_tmpl_web_path() . $smiley_path . '" align="middle" alt="' . $_SESSION['translator']->out('PRIVATE_IMAGE') . '" />';
  87      }
  88  
  89      return '&nbsp;';
  90  } 
  91  
  92  if (!isset($_SESSION['chat']) || !is_object($_SESSION['chat'])) {
  93      if (!isset($_SESSION['chatter']) && function_exists('session_register')) {
  94          session_register('chatter');
  95      } 
  96      if (!isset($_SESSION['template']) && function_exists('session_register')) {
  97          session_register('template');
  98      } 
  99      if (function_exists('session_register')) {
 100          session_register('chat', 'translator', 'channel', 'channel_buffer', 'lastRedLine', 'mailbox', 'current_mailbox_type', 'curr_mail_idx', 'inbox_count_new', 'outbox_count_new', 'trash_count_new', 'session_get', 'session_post', 'reload_count', 'logger', 'autologin_directly','httpneg');
 101      } 
 102      if (AUTOLOGIN_DIRECTLY && is_null($_SESSION['autologin_directly'])) {
 103          $_SESSION['autologin_directly'] = true;
 104      } 
 105  
 106      $reload_count = 0;
 107      $session_get = session_name() . '=' . session_id();
 108      $_SESSION['session_get'] = $session_get;
 109      $session_post = '<input type="hidden" name="' . session_name() . '" value="' . session_id() . '" />';
 110      $_SESSION['session_post'] = $session_post;
 111      $logger = &new POC_Logger();
 112      $_SESSION['logger'] = $logger;
 113      $chat = &new POC_Chat(strval(CHAT_NAME), $supported_languages);
 114      $_SESSION['chat'] = $chat;
 115      $translator = &new POC_Translator($_SESSION['chat']->get_language());
 116      $_SESSION['translator'] = $translator;
 117      $httpneg = &new HttpNegotiation();
 118      $_SESSION['httpneg'] = $httpneg;
 119      
 120      $_SESSION['chat']->set_deathless_chatters($DEATHLESS_CHATTERS);
 121      if (isset($_SERVER['HTTP_REFERER'])) {
 122          $_SESSION['chat']->set_referer($_SERVER['HTTP_REFERER']);
 123      } 
 124      set_error_handler('db_error');
 125      $_SESSION['chat']->connect();
 126      restore_error_handler();
 127      $_SESSION['chat']->alter_db_schema();
 128      $_SESSION['chat']->make_clean(); 
 129      // Set operator password
 130      $operator_passwd = $_SESSION['chat']->set_operator_passwd();
 131      $_SESSION['chat']->disconnect();
 132  } 
 133  
 134  if (isset($_GET['pnlogin']) || isset($_GET['use_db_instance']) ){
 135  
 136      $_nickname = (isset($_GET['use_db_instance']))? $_GET['use_db_instance']:$_GET['pnlogin'];
 137      // here a postnuke user has a chatter object already in the db
 138      // this object was created by the first request from postnuke enviroment
 139      // see below if( function_exists('pnUserGetVar') )...
 140      set_error_handler('db_error');
 141      $_SESSION['chat']->connect();
 142      restore_error_handler();
 143      $_SESSION['chatter'] = $_SESSION['chat']->get_chatter_instance($_nickname);
 144      if (!is_object($_SESSION['chatter']) || $_SESSION['chatter']->db_instance_is_outdated()){
 145          unset($_SESSION['chatter']);
 146      } else {
 147          $_SESSION['chatter']->mkinstance_clean();
 148          $_SESSION['chat']->set_show_profile(false); //profile data are managed by PN or other application
 149      } 
 150      $_SESSION['chat']->disconnect();
 151  }
 152  
 153  if( isset($_GET['language']) && in_array($_GET['language'], $supported_languages) )
 154  {
 155    $_SESSION['chat']->set_language($_GET['language']);
 156    $_SESSION['translator']->set_language($_GET['language']);
 157  }
 158  
 159  if (!isset($_SESSION['template'])) {
 160      $template = &new POC_Template();
 161      $_SESSION['template'] = $template;
 162      
 163      if (isset($_SESSION['chatter'])){
 164        
 165        $_SESSION['template']->set_theme($_SESSION['chatter']->get_theme());
 166      }
 167      unset($theme);
 168  
 169      if (function_exists('pnUserGetVar')) {
 170          // this is a request from the postnuke enviroment
 171          if (pnUserLoggedIn()) {
 172              // register or update POC userdata
 173              $_chatter = POC_Chat::mkinstance_chatter(pnUserGetVar('uname'), true);
 174              $poc_current_chatter = $_chatter;
 175              
 176              $_chatter->set_user(pnUserGetVar('uname'));
 177              $_chatter->set_email(pnUserGetVar('email')); //is hidden by default
 178              $_chatter->set_name(pnUserGetVar('name'));
 179              $_chatter->set_homePageURL(pnUserGetVar('url'));
 180              $_chatter->set_icqNumber(pnUserGetVar('user_icq'));
 181              $_chatter->set_motto(pnUserGetVar('user_sig'));
 182              $_chatter->set_aimNickname(pnUserGetVar('user_aim'));
 183              $_chatter->set_yimNickname(pnUserGetVar('user_yim'));
 184              $_chatter->set_interests(pnUserGetVar('user_intrest'));
 185              
 186              if (!$_chatter->is_registered()) $_chatter->register();
 187  
 188              $data   = array();
 189              $data[] = $_SESSION['translator']->out('MISCELLANEOUS');
 190              $data[] = pnUserGetVar('bio');
 191              $_chatter->insert_profile_misc($data);
 192  
 193              /* setup group rights */
 194              if (pnSecAuthAction(0, 'Blocks::', '::', ACCESS_ADMIN)) {
 195                  $_chatter->add_to_group('operator');
 196              } 
 197              
 198              /* setup language settings */
 199              if( $pn_lang = pnUserGetLang() ){
 200                $_chatter->set_preferred_language($pn_lang);
 201              }
 202              
 203              /* setup theme */
 204              $pnTheme = pnUserGetTheme();
 205              if( in_array($pnTheme, $_SESSION['template']->get_theme_list()) ) {
 206                $_chatter->set_theme( $pnTheme );
 207                $_SESSION['template']->set_theme( $pnTheme );
 208              }
 209              
 210              if( $poc_current_chatter != $_chatter ){
 211                $_chatter->update();
 212              }
 213              unset($poc_current_chatter);
 214              
 215              //$_chatter->set_db_instance_lifetime();
 216              $_chatter->mkinstance_persist();
 217              unset($_chatter);
 218              $poc_web_root = $_SESSION['template']->get_poc_web_root(); 
 219              // clean PN session
 220              unset($_SESSION['chat']); 
 221              // unset($_SESSION['chatter']);
 222              unset($_SESSION['reload_count']);
 223              unset($_SESSION['template']);
 224              unset($_SESSION['translator']);
 225              unset($_SESSION['logger']);
 226              unset($_SESSION['session_post']);
 227              unset($_SESSION['session_get']);
 228  
 229              header('Status: 301');
 230              header('Location: ' . $poc_web_root . '/index.php?pnlogin=' . pnUserGetVar('uname'));
 231              exit;
 232          } else {
 233              $_SESSION['template']->get_template('pn_login_failure');
 234          } 
 235      } 
 236  } 
 237  //$TEMPLATE_OUT['lang_switch'] = $_SESSION['chat']->get_lang_switch();
 238  
 239  if ( isset($_POST['account_data']) ||
 240  (isset($_SESSION['chatter']) 
 241   && is_object($_SESSION['chatter'])
 242   && !$_SESSION['chatter']->is_kicked() 
 243   && !$_SESSION['chatter']->is_disabled() 
 244   && (AUTOLOGIN_DIRECTLY && $_SESSION['autologin_directly'] && !isset($_GET['no_autologin'])))) {
 245  
 246      if( file_exists(POC_BASE.DELI.'install.php') ){
 247        POC_Chat::display_error(0, '
 248            <span style="font-size:14px;">Congratulations, the installation is complete but<br />
 249              <span style="font-weight:bold">
 250                please remember to <span style="text-decoration:underline">delete install.php</span>
 251              </span>
 252              before you start with your community!
 253            </span>
 254          ', __FILE__, __LINE__);
 255      }
 256  
 257      /*
 258       * Create a new chatter to check account data
 259       * Object chatter has no nick, if
 260       *  -the password doesn't match
 261       *  -the nick contains incorrect characters
 262       *  -the nick is too long
 263       */
 264      if (isset($_POST['nick']) && $_POST['nick'] == strval(STATUS_BOT_NAME))
 265          unset($_POST['nick']);
 266  
 267      if (!isset($_SESSION['chatter']) || $_SESSION['chatter']->is_guest()) {
 268          if (!POC_Chat::mkinstance_channel($_POST['channel']))
 269              die('Channel doesn\'t exists!');
 270          $_chatter = &new POC_Chatter($_POST['nick'], $_POST['password']);
 271      } else {
 272          if (!isset($_POST['channel']))
 273              $_POST['channel'] = ENTRY_CHANNEL;
 274          if (!POC_Chat::mkinstance_channel($_POST['channel']))
 275              die('Channel doesn\'t exists!');
 276          $_chatter = $_SESSION['chatter'];
 277      } 
 278  
 279      if (!is_null($_chatter->get_nick()) || isset($_SESSION['chatter'])) {
 280          if (!isset($_SESSION['chatter']) || $_SESSION['chatter']->is_guest())
 281              $_SESSION['chatter'] = $_chatter;
 282  
 283          if (isset($_POST['storeAccountData'])) {
 284              setcookie('poc_nick', $_POST['nick'], COOKIE_EXPIRE, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);
 285              setcookie('poc_password', $_POST['password'], COOKIE_EXPIRE, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);
 286          } 
 287          // connect to the line buffer of choosen channel
 288          $channel_buffer = &new POC_Channel_Buffer($_POST['channel']);
 289          $_SESSION['channel_buffer'] = $channel_buffer;
 290  
 291          $_SESSION['channel_buffer']->connect();
 292          $lastRedLine = $_SESSION['channel_buffer']->get_cur_line_idx();
 293          $_SESSION['lastRedLine'] = $lastRedLine;
 294  
 295          $max_lines = $_SESSION['channel_buffer']->get_max_line_idx();
 296          if( defined('SHOW_CHAT_HISTORY') && SHOW_CHAT_HISTORY && $max_lines>SHOW_CHAT_HISTORY){
 297            $_SESSION['lastRedLine'] = ($_SESSION['lastRedLine']+($max_lines-SHOW_CHAT_HISTORY)) % $max_lines;
 298          }
 299          unset($max_lines);
 300          $_SESSION['channel_buffer']->disconnect();
 301  
 302          $_SESSION['chat']->connect();
 303          $_SESSION['chat']->create_private_channel($_chatter->get_nick(true));
 304          $_SESSION['chat']->disconnect();
 305  
 306          $banned_msg = '';
 307          if ($_SESSION['chatter']->is_banned($_POST['channel'])) {
 308              $banned_msg = ' ###BANNED_MSG###';
 309              $_SESSION['chatter']->join_channel($_SESSION['chatter']->get_nick());
 310          } 
 311  
 312          if (!$_SESSION['chatter']->already_seen_today())
 313              $_SESSION['chatter']->count_hit('login');
 314  
 315          $_SESSION['chatter']->refresh();
 316          $_SESSION['chatter']->set_grade($GRADES);
 317          $_SESSION['template']->set_theme($_SESSION['chatter']->get_theme()); 
 318          // hey, the chatter is authorized
 319          $_SESSION['chatter']->go_online($_SESSION['channel']->get_name()); 
 320          // we have to say hello in the current channel first»
 321          $bot = &new POC_Chatter(strval(STATUS_BOT_NAME));
 322  
 323          $said = $_SESSION['chatter']->get_nick(true) . ' ###JOINS_THE_CHAT###';
 324          $said .= $banned_msg;
 325          $line = &new POC_Line($bot, $said);
 326          $line->set_login($_SESSION['chatter']->get_nick(true));
 327  
 328          $_SESSION['channel_buffer']->connect(); 
 329          // get current line number within channel buffer
 330          $_SESSION['channel_buffer']->put_line($line);
 331          $_SESSION['channel_buffer']->disconnect();
 332          if ($_SESSION['channel']->get_message() != '') {
 333              $_SESSION['chat']->write_sys_msg('<br />' . $_SESSION['channel']->get_message(), $_SESSION['chatter'], true);
 334          } 
 335  
 336          /* if current user has a preferred language, we use this language */
 337          if( $pref_lang = $_SESSION['chatter']->get_preferred_language() ){
 338            $_SESSION['translator']->set_language($pref_lang);
 339          }
 340  
 341          unset($pref_lang);
 342          unset($line);
 343          unset($line_message);
 344          unset($bot);
 345          unset($said);
 346          unset($_SESSION['in']);
 347  
 348          header('Status: 301');
 349          header('Location: frameset.php?' . session_name() . '=' . session_id());
 350  
 351          exit;
 352      } else {
 353          unset($_SESSION['channel']);
 354          unset($_chatter);
 355      } 
 356  } else {
 357      header('Content-type: text/html; charset=' . $_SESSION['translator']->out('CHARACTER_ENCODING'));
 358      $_SESSION['template']->get_cached_content(60 * 2); //get cached content with a max age of 2 minutes
 359  } 
 360  
 361  $TEMPLATE_OUT['lang_switch'] = $_SESSION['chat']->get_lang_switch();
 362  
 363  set_error_handler('db_error');
 364  if (!$_SESSION['chat']->connect()) {
 365      restore_error_handler();
 366      unset($_SESSION['chat']);
 367      unset($_SESSION['chatter']);
 368      unset($_SESSION['channel_buffer']);
 369      unset($_SESSION['lastRedLine']);
 370  
 371      header('Status: 301');
 372      header('Location: test.php');
 373      exit;
 374  } 
 375  restore_error_handler();
 376  
 377  $chatters_online = array();
 378  $chatters_online = $_SESSION['chat']->get_chatters('%');
 379  $count_chatters_online = count($chatters_online);
 380  if ($count_chatters_online > 0) {
 381      $td_count = 0;
 382      for($i = 0;$i < $count_chatters_online;$i++) {
 383          $td_count++;
 384          if ($i == 0 || ($i % COL_COUNT_CHATTER_LIST) == 0) $chatters_online_list .= NL . TAB . '<tr>';
 385          $chatters_online_list .= NL . TAB . TAB . '<td class="chatterTableImgCell">' . check_private_icon($chatters_online[$i]) . '</td>
 386       <td class="chatterTable">&nbsp;' . preg_replace("/\#{3}([^#]*)\#{3}/e", "htmlentities(\$_SESSION['translator']->out('\\1'))", $chatters_online[$i]) . '&nbsp;</td>';
 387          if ($i > 0 && ($i % COL_COUNT_CHATTER_LIST) == 0) {
 388              $td_count = 0;
 389              $chatters_online_list .= NL . TAB . '</tr>';
 390          } 
 391      } 
 392      for ($i = $td_count; $i < COL_COUNT_CHATTER_LIST; $i++) {
 393          $chatters_online_list .= NL . TAB . TAB . '<td colspan="2"></td>';
 394      } 
 395      if ($td_count > 0) $chatters_online_list .= NL . TAB . '</tr>';
 396  } else
 397      $chatters_online_list = '<tr><td>&nbsp;</td></tr>';
 398  
 399  $TEMPLATE_OUT['count_chatters_online'] = $count_chatters_online; 
 400  // get statistics
 401  $TEMPLATE_OUT['online_count_last24h'] = $_SESSION['chat']->get_online_count_last24h();
 402  $TEMPLATE_OUT['online_time_avg'] = round($_SESSION['chat']->get_online_time_avg() / (60 * 60 * 24), 3);
 403  $TEMPLATE_OUT['registered_count'] = $_SESSION['chat']->get_registered_count();
 404  $TEMPLATE_OUT['last_registered'] = array();
 405  $last_registered_user = $_SESSION['chat']->get_last_registered();
 406  $TEMPLATE_OUT['last_registered']['NICK'] = $last_registered_user[0]['NICK'];
 407  $TEMPLATE_OUT['last_registered']['REGTIME'] = $last_registered_user[0]['REGTIME'];
 408  $TEMPLATE_OUT['mail_count'] = $_SESSION['chat']->get_mail_count();
 409  $TEMPLATE_OUT['mail_count_last_24h'] = $_SESSION['chat']->get_mail_count_last_24h();
 410  $TEMPLATE_OUT['option_list_of_channels'] = $_SESSION['chat']->get_channels_option_list(CHANNEL_SELECTED);
 411  $_SESSION['chat']->disconnect();
 412  // unset objects in session
 413  // unset($_SESSION['chatter']);
 414  unset($_SESSION['channel_buffer']);
 415  unset($_SESSION['lastRedLine']);
 416  if (AUTOLOGIN_DIRECTLY && !isset($_GET['no_autologin'])) {
 417      $_SESSION['autologin_directly'] = true;
 418  }
 419  
 420  $jump = (isset($_GET['jump']))? $_GET['jump']:'index.php';
 421  
 422  if (isset($_GET['onTop']))
 423      $jScript .= '
 424    if( opener ) {
 425      /*click on exit within satellit*/
 426      opener.parent.location.href="' . $jump . '";
 427      window.close();
 428    }
 429    else {
 430      //alert(\'debug\');
 431      top.location.href="' . $jump . '";
 432    }
 433    ';
 434  if (isset($_GET['forceOnTop']))
 435      $jScript .= '
 436       top.location.href="' . $jump . '";
 437     ';
 438  
 439  $TEMPLATE_OUT['disable'] = '';
 440  if (isset($_SESSION['chatter']) && !AUTOLOGIN_DIRECTLY && !$_SESSION['chatter']->is_guest()) {
 441      $TEMPLATE_OUT['disable'] = 'disabled="disabled"';
 442  } 
 443  
 444  $TEMPLATE_OUT['spy_icon'] = ( defined('ALLOW_SPYING') && ALLOW_SPYING )? 
 445  '<a class="imageLink" title="'.$_SESSION['translator']->out('SPY_THIS_CHANNEL').'" href="#" onclick="spy(document.forms[0].elements[\'channel\'].options[document.forms[0].elements[\'channel\'].selectedIndex].value)">
 446    <img style="border:0;background-image:none" src="'.$_SESSION['template']->get_theme_path().'/images/icons/watch.gif" width="18" height="12" alt="'.$_SESSION['translator']->out('SPY_THIS_CHANNEL').'" />
 447  </a>':'';
 448  
 449  $TEMPLATE_OUT['nickname'] = '';
 450  $TEMPLATE_OUT['greeting'] = '';
 451  if (isset($_SESSION['chatter'])) {
 452      $TEMPLATE_OUT['nickname'] = $_SESSION['chatter']->get_nick() . ':';
 453      $TEMPLATE_OUT['greeting'] = $_SESSION['translator']->out('GREETING');
 454  } 
 455  $TEMPLATE_OUT['jScript'] = $jScript;
 456  $TEMPLATE_OUT['operator_passwd'] = $operator_passwd;
 457  $TEMPLATE_OUT['chatters_online_list'] = $chatters_online_list;
 458  
 459  //nocaching headers
 460  header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
 461  header ('Expires: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
 462  header ('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
 463  $_SESSION['template']->get_template('index');
 464  ?>

title

Description

title

Description

title

Description

title

title

Body