[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/ -> index.php (source)

   1  <?php /* $Id: index.php 183 2008-07-21 01:22:03Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/index.php $ */
   2  
   3  /*
   4  Copyright (c) 2007-2008 The web2Project Development Team <w2p-developers@web2project.net>
   5  Copyright (c) 2003-2005 The dotProject Development Team <core-developers@dotproject.net>
   6  
   7  This file is part of web2Project.
   8  
   9  web2Project is free software; you can redistribute it and/or modify
  10  it under the terms of the GNU General Public License as published by
  11  the Free Software Foundation; either version 2 of the License, or
  12  (at your option) any later version.
  13  
  14  web2Project is distributed in the hope that it will be useful,
  15  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17  GNU General Public License for more details.
  18  
  19  You should have received a copy of the GNU General Public License
  20  along with web2Project; if not, write to the Free Software
  21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22  */
  23  
  24  // If you experience a 'white screen of death' or other problems,
  25  // uncomment the following line of code:
  26  //error_reporting( E_ALL );
  27  
  28  $loginFromPage = 'index.php';
  29  require_once  'base.php';
  30  
  31  clearstatcache();
  32  if (is_file(W2P_BASE_DIR . '/includes/config.php')) {
  33      require_once W2P_BASE_DIR . '/includes/config.php';
  34  } else {
  35      echo '<html><head><meta http-equiv="refresh" content="5; URL=' . W2P_BASE_URL . '/install/index.php"></head><body>';
  36      echo 'Fatal Error. You haven\'t created a config file yet.<br/><a href="./install/index.php">' . 'Click Here To Start Installation and Create One!</a> (forwarded in 5 sec.)</body></html>';
  37      exit();
  38  }
  39  
  40  if (!isset($GLOBALS['OS_WIN'])) {
  41      $GLOBALS['OS_WIN'] = (stristr(PHP_OS, 'WIN') !== false);
  42  }
  43  
  44  // tweak for pathname consistence on windows machines
  45  require_once  W2P_BASE_DIR . '/includes/main_functions.php';
  46  require_once  W2P_BASE_DIR . '/includes/db_adodb.php';
  47  
  48  require_once  W2P_BASE_DIR . '/classes/ui.class.php';
  49  require_once  W2P_BASE_DIR . '/classes/permissions.class.php';
  50  require_once  W2P_BASE_DIR . '/includes/session.php';
  51  
  52  // don't output anything. Usefull for fileviewer.php, gantt.php, etc.
  53  $suppressHeaders = w2PgetParam($_GET, 'suppressHeaders', false);
  54  
  55  // manage the session variable(s)
  56  w2PsessionStart(array('AppUI'));
  57  
  58  // write the HTML headers
  59  header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  60  header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
  61  header('Cache-Control: no-cache, must-revalidate, no-store, post-check=0, pre-check=0'); // HTTP/1.1
  62  header('Pragma: no-cache'); // HTTP/1.0
  63  
  64  // check if session has previously been initialised
  65  if (!isset($_SESSION['AppUI']) || isset($_GET['logout'])) {
  66      if (isset($_GET['logout']) && isset($_SESSION['AppUI']->user_id)) {
  67          $AppUI = &$_SESSION['AppUI'];
  68          $user_id = $AppUI->user_id;
  69          addHistory('login', $AppUI->user_id, 'logout', $AppUI->user_first_name . ' ' . $AppUI->user_last_name);
  70      }
  71  
  72      $_SESSION['AppUI'] = new CAppUI;
  73  }
  74  $AppUI = &$_SESSION['AppUI'];
  75  $last_insert_id = $AppUI->last_insert_id;
  76  
  77  $AppUI->checkStyle();
  78  
  79  // load the commonly used classes
  80  require_once ($AppUI->getSystemClass('date'));
  81  require_once ($AppUI->getSystemClass('w2p'));
  82  require_once ($AppUI->getSystemClass('query'));
  83  
  84  //Now that we have $AppUI lets add our ajax functions in
  85  //require_once ($AppUI->getSystemClass('ajax'));
  86  
  87  //Function for update lost action in user_access_log
  88  $AppUI->updateLastAction($last_insert_id);
  89  // load default preferences if not logged in
  90  if ($AppUI->doLogin()) {
  91      $AppUI->loadPrefs(0);
  92  }
  93  
  94  //Function register logout in user_acces_log
  95  if (isset($user_id) && isset($_GET['logout'])) {
  96      $AppUI->registerLogout($user_id);
  97  }
  98  
  99  // check is the user needs a new password
 100  if (w2PgetParam($_POST, 'lostpass', 0)) {
 101      $uistyle = w2PgetConfig('host_style');
 102      $AppUI->setUserLocale();
 103      @include_once W2P_BASE_DIR . '/locales/' . $AppUI->user_locale . '/locales.php';
 104      include_once  W2P_BASE_DIR . '/locales/core.php';
 105      setlocale(LC_TIME, $AppUI->user_lang);
 106      if (w2PgetParam($_POST, 'sendpass', 0)) {
 107          require  W2P_BASE_DIR . '/includes/sendpass.php';
 108          sendNewPass();
 109      } else {
 110          require W2P_BASE_DIR . '/style/' . $uistyle . '/lostpass.php';
 111      }
 112      exit();
 113  }
 114  
 115  // check if the user is trying to log in
 116  // Note the change to REQUEST instead of POST.  This is so that we can
 117  // support alternative authentication methods such as the PostNuke
 118  // and HTTP auth methods now supported.
 119  if (isset($_REQUEST['login'])) {
 120      $username = w2PgetCleanParam($_POST, 'username', '');
 121      $password = w2PgetCleanParam($_POST, 'password', '');
 122      $redirect = w2PgetCleanParam($_POST, 'redirect', '');
 123      $AppUI->setUserLocale();
 124      @include_once (W2P_BASE_DIR . '/locales/' . $AppUI->user_locale . '/locales.php');
 125      include_once  W2P_BASE_DIR . '/locales/core.php';
 126      $ok = $AppUI->login($username, $password);
 127      if (!$ok) {
 128          $AppUI->setMsg('Login Failed', UI_MSG_ERROR);
 129      } else {
 130          //Register login in user_acces_log
 131          $AppUI->registerLogin();
 132      }
 133      addHistory('login', $AppUI->user_id, 'login', $AppUI->user_first_name . ' ' . $AppUI->user_last_name);
 134      $AppUI->redirect('' . $redirect);
 135  }
 136  
 137  // supported since PHP 4.2
 138  // w2PwriteDebug( var_export( $AppUI, true ), 'AppUI', __FILE__, __LINE__ );
 139  
 140  // set the default ui style
 141  $uistyle = $AppUI->getPref('UISTYLE') ? $AppUI->getPref('UISTYLE') : w2PgetConfig('host_style');
 142  
 143  // clear out main url parameters
 144  $m = '';
 145  $a = '';
 146  $u = '';
 147  
 148  // check if we are logged in
 149  if ($AppUI->doLogin()) {
 150      // load basic locale settings
 151      $AppUI->setUserLocale();
 152      @include_once ('./locales/' . $AppUI->user_locale . '/locales.php');
 153      include_once  ('./locales/core.php');
 154      setlocale(LC_TIME, $AppUI->user_lang);
 155      $redirect = $_SERVER['QUERY_STRING'] ? strip_tags($_SERVER['QUERY_STRING']) : '';
 156      if (strpos($redirect, 'logout') !== false) {
 157          $redirect = '';
 158      }
 159  
 160      if (isset($locale_char_set)) {
 161          header('Content-type: text/html;charset=' . $locale_char_set);
 162      }
 163  
 164      require W2P_BASE_DIR . '/style/' . $uistyle . '/login.php';
 165      // destroy the current session and output login page
 166      session_unset();
 167      session_destroy();
 168      exit;
 169  }
 170  $AppUI->setUserLocale();
 171  
 172  // bring in the rest of the support and localisation files
 173  $perms = &$AppUI->acl();
 174  
 175  $def_a = 'index';
 176  if (!isset($_GET['m']) && !empty($w2Pconfig['default_view_m'])) {
 177      if (!$perms->checkModule($w2Pconfig['default_view_m'], 'view', $AppUI->user_id)) {
 178          $m = 'public';
 179          $def_a = 'welcome';
 180      } else {
 181          $m = $w2Pconfig['default_view_m'];
 182          $def_a = !empty($w2Pconfig['default_view_a']) ? $w2Pconfig['default_view_a'] : $def_a;
 183          $tab = $w2Pconfig['default_view_tab'];
 184      }
 185  } else {
 186      // set the module from the url
 187      $m = $AppUI->checkFileName(w2PgetCleanParam($_GET, 'm', getReadableModule()));
 188  }
 189  // set the action from the url
 190  $a = $AppUI->checkFileName(w2PgetCleanParam($_GET, 'a', $def_a));
 191  if ($m == 'projects' && $a == 'view' && $w2Pconfig['projectdesigner_view_project'] && !w2PgetParam($_GET, 'bypass') && !(isset($_GET['tab']))) {
 192      if ($AppUI->isActiveModule('projectdesigner')) {
 193          $m = 'projectdesigner';
 194          $a = 'index';
 195      }
 196  }
 197  
 198  /* This check for $u implies that a file located in a subdirectory of higher depth than 1
 199  * in relation to the module base can't be executed. So it would'nt be possible to
 200  * run for example the file module/directory1/directory2/file.php
 201  * Also it won't be possible to run modules/module/abc.zyz.class.php for that dots are
 202  * not allowed in the request parameters.
 203  */
 204  
 205  $u = $AppUI->checkFileName(w2PgetCleanParam($_GET, 'u', ''));
 206  
 207  // load module based locale settings
 208  @include_once W2P_BASE_DIR . '/locales/' . $AppUI->user_locale . '/locales.php';
 209  include_once  W2P_BASE_DIR . '/locales/core.php';
 210  
 211  setlocale(LC_TIME, $AppUI->user_lang);
 212  $m_config = w2PgetConfig($m);
 213  
 214  // TODO: canRead/Edit assignements should be moved into each file
 215  
 216  // check overall module permissions
 217  // these can be further modified by the included action files
 218  $canAccess = $perms->checkModule($m, 'access');
 219  $canRead = $perms->checkModule($m, 'view');
 220  $canEdit = $perms->checkModule($m, 'edit');
 221  $canAuthor = $perms->checkModule($m, 'add');
 222  $canDelete = $perms->checkModule($m, 'delete');
 223  
 224  if (!$suppressHeaders) {
 225      // output the character set header
 226      if (isset($locale_char_set)) {
 227          header('Content-type: text/html;charset=' . $locale_char_set);
 228      }
 229  }
 230  
 231  // include the module class file - we use file_exists instead of @ so
 232  // that any parse errors in the file are reported, rather than errors
 233  // further down the track.
 234  $modclass = $AppUI->getModuleClass($m);
 235  if (file_exists($modclass)) {
 236      include_once ($modclass);
 237  }
 238  if ($u && file_exists(W2P_BASE_DIR . '/modules/' . $m . '/' . $u . '/' . $u . '.class.php')) {
 239      include_once W2P_BASE_DIR . '/modules/' . $m . '/' . $u . '/' . $u . '.class.php';
 240  }
 241  
 242  // include the module ajax file - we use file_exists instead of @ so
 243  // that any parse errors in the file are reported, rather than errors
 244  // further down the track.
 245  $modajax = $AppUI->getModuleAjax($m);
 246  if (file_exists($modajax)) {
 247      include_once ($modajax);
 248  }
 249  if ($u && file_exists(W2P_BASE_DIR . '/modules/' . $m . '/' . $u . '/' . $u . '.ajax.php')) {
 250      include_once W2P_BASE_DIR . '/modules/' . $m . '/' . $u . '/' . $u . '.ajax.php';
 251  }
 252  
 253  // do some db work if dosql is set
 254  // TODO - MUST MOVE THESE INTO THE MODULE DIRECTORY
 255  if (isset($_REQUEST['dosql'])) {
 256      //require('./dosql/' . $_REQUEST['dosql'] . '.php');
 257      require W2P_BASE_DIR . '/modules/' . $m . '/' . ($u ? ($u . '/') : '') . $AppUI->checkFileName($_REQUEST['dosql']) . '.php';
 258  }
 259  
 260  // start output proper
 261  include W2P_BASE_DIR . '/style/' . $uistyle . '/overrides.php';
 262  if ($_REQUEST['dosql'] == 'do_file_co') {
 263      ob_start();
 264  } else {
 265      ob_start('ob_gzhandler');
 266  }
 267  
 268  if (!$suppressHeaders) {
 269      require W2P_BASE_DIR . '/style/' . $uistyle . '/header.php';
 270  }
 271  
 272  if (W2P_PERFORMANCE_DEBUG) {
 273      $w2p_performance_setuptime = (array_sum(explode(' ', microtime())) - $w2p_performance_time);
 274  }
 275  
 276  //Set up extra tabs
 277  if (!isset($_SESSION['all_tabs'][$m])) {
 278      // For some reason on some systems if you don't set this up
 279      // first you get recursive pointers to the all_tabs array, creating
 280      // phantom tabs.
 281      if (!isset($_SESSION['all_tabs'])) {
 282          $_SESSION['all_tabs'] = array();
 283      }
 284      $_SESSION['all_tabs'][$m] = array();
 285      $all_tabs = &$_SESSION['all_tabs'][$m];
 286      foreach ($AppUI->getActiveModules() as $dir => $module) {
 287          if (!$perms->checkModule($dir, 'access')) {
 288              continue;
 289          }
 290          $modules_tabs = $AppUI->readFiles(W2P_BASE_DIR . '/modules/' . $dir . '/', '^' . $m . '_tab.*\.php');
 291          foreach ($modules_tabs as $tab) {
 292              // Get the name as the subextension
 293              // cut the module_tab. and the .php parts of the filename
 294              // (begining and end)
 295              $nameparts = explode('.', $tab);
 296              $filename = substr($tab, 0, -4);
 297              if (count($nameparts) > 3) {
 298                  $file = $nameparts[1];
 299                  if (!isset($all_tabs[$file])) {
 300                      $all_tabs[$file] = array();
 301                  }
 302                  $arr = &$all_tabs[$file];
 303                  $name = $nameparts[2];
 304              } else {
 305                  $arr = &$all_tabs;
 306                  $name = $nameparts[1];
 307              }
 308              $arr[] = array('name' => ucfirst(str_replace('_', ' ', $name)), 'file' => W2P_BASE_DIR . '/modules/' . $dir . '/' . $filename, 'module' => $dir);
 309  
 310              /*
 311              ** Don't forget to unset $arr again! $arr is likely to be used in the sequel declaring
 312              ** any temporary array. This may lead to strange bugs with disappearing tabs (cf. #1767).
 313              ** @author: gregorerhardt     @date: 20070203
 314              */
 315              unset($arr);
 316          }
 317      }
 318  } else {
 319      $all_tabs = &$_SESSION['all_tabs'][$m];
 320  }
 321  
 322  //Set up extra crumbs
 323  if (!isset($_SESSION['all_crumbs'][$m])) {
 324      // For some reason on some systems if you don't set this up
 325      // first you get recursive pointers to the all_crumbs array, creating
 326      // phantom crumbs.
 327      if (!isset($_SESSION['all_crumbs'])) {
 328          $_SESSION['all_crumbs'] = array();
 329      }
 330      $_SESSION['all_crumbs'][$m] = array();
 331      $all_crumbs = &$_SESSION['all_crumbs'][$m];
 332      foreach ($AppUI->getActiveModules() as $dir => $module) {
 333          if (!$perms->checkModule($dir, 'access')) {
 334              continue;
 335          }
 336          $modules_crumbs = $AppUI->readFiles(W2P_BASE_DIR . '/modules/' . $dir . '/', '^' . $m . '_crumb.*\.php');
 337          foreach ($modules_crumbs as $tab) {
 338              // Get the name as the subextension
 339              // cut the module_tab. and the .php parts of the filename
 340              // (begining and end)
 341              $nameparts = explode('.', $tab);
 342              $filename = substr($tab, 0, -4);
 343              if (count($nameparts) > 3) {
 344                  $file = $nameparts[1];
 345                  if (!isset($all_crumbs[$file])) {
 346                      $all_crumbs[$file] = array();
 347                  }
 348                  $arr = &$all_crumbs[$file];
 349                  $name = $nameparts[2];
 350              } else {
 351                  $arr = &$all_crumbs;
 352                  $name = $nameparts[1];
 353              }
 354              $arr[] = array('name' => ucfirst(str_replace('_', ' ', $name)), 'file' => W2P_BASE_DIR . '/modules/' . $dir . '/' . $filename, 'module' => $dir);
 355  
 356              unset($arr);
 357          }
 358      }
 359  } else {
 360      $all_crumbs = &$_SESSION['all_crumbs'][$m];
 361  }
 362  
 363  $module_file = W2P_BASE_DIR . '/modules/' . $m . '/' . ($u ? ($u . '/') : '') . $a . '.php';
 364  if (file_exists($module_file)) {
 365      require $module_file;
 366  } else {
 367      // TODO: make this part of the public module?
 368      // TODO: internationalise the string.
 369      $titleBlock = new CTitleBlock('Warning', 'log-error.gif');
 370      $titleBlock->show();
 371  
 372      if (function_exists('styleRenderBoxTop')) {
 373          echo styleRenderBoxTop();
 374      }
 375      echo '<table width="100%" cellspacing="0" cellpadding="3" border="0" class="std">';
 376      echo '<tr>';
 377      echo '    <td>';
 378      echo $AppUI->_('Missing file. Possible Module "' . $m . '" missing!');
 379      echo '    </td>';
 380      echo '</tr>';
 381      echo '</table>';
 382  }
 383  if (!$suppressHeaders) {
 384      echo '<iframe name="thread" src="' . W2P_BASE_URL . '/modules/index.html" width="0" height="0" frameborder="0"></iframe>';
 385      echo '<iframe name="thread2" src="' . W2P_BASE_URL . '/modules/index.html" width="0" height="0" frameborder="0"></iframe>';
 386      require W2P_BASE_DIR . '/style/' . $uistyle . '/footer.php';
 387      if (W2P_PERFORMANCE_DEBUG) {
 388          $db_info = $db->ServerInfo();
 389          print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">web2Project ' . $AppUI->getVersion() . '</p>');
 390          print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">PHP version nr: ' . phpversion() . '</p>');
 391          print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">DB provider and version nr: ' . $db->dataProvider . ' ' . $db_info['version'] . '</p>');
 392          print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">DB Table Prefix: "' . w2PgetConfig('dbprefix') . '"</p>');
 393          print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">PHP Max. Execution Time: ' . ini_get('max_execution_time') . ' seconds</p>');
 394          print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">Memory Limit: ' . (ini_get('memory_limit') ? str_replace('M', ' Mb', ini_get('memory_limit')) : 'Not Defined') . '</p>');
 395          if (function_exists('memory_get_usage')) {
 396              print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">Memory Used: ' . sprintf('%01.2f Mb', memory_get_usage() / pow(1024, 2)) . '</p>');
 397              print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">Memory Unused: ' . sprintf('%01d Kb', (memory_get_usage() - $w2p_performance_memory_marker) / 1024) . '</p>');
 398          }
 399          if (function_exists('memory_get_peak_usage')) {
 400              print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">Memory Peak: ' . sprintf('%01d Kb', (memory_get_peak_usage() - $w2p_performance_memory_marker) / 1024) . '</p>');
 401          }
 402          printf('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">Setup in %.3f seconds</p>', $w2p_performance_setuptime);
 403          printf('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">ACLs checked in %.3f seconds</p>', $w2p_performance_acltime);
 404          print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">ACLs nr of checks: ' . $w2p_performance_aclchecks . '</p>');
 405          printf('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">w2P Data checked in %.3f seconds</p>', $w2p_performance_dbtime);
 406          print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">w2P DBQueries executed: ' . $w2p_performance_dbqueries . ' queries</p>');
 407          print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">w2P Old Queries executed: ' . $w2p_performance_old_dbqueries . ' queries</p>');
 408          print ('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">w2P Total Queries executed: ' . (int)($w2p_performance_old_dbqueries + $w2p_performance_dbqueries) . ' queries</p>');
 409          printf('<p style="margin: 0px;font-size: 7pt; text-align: center; color: #000000">Page generated in %.3f seconds</p>', (array_sum(explode(' ', microtime())) - $w2p_performance_time));
 410      }
 411      echo '</div>';
 412      echo '
 413          <!--AJAX loading messagebox -->
 414          <div id="loadingMessage" style="alpha(opacity=100);opacity:1;position: fixed; left: 50%; top: 0;display: none;">
 415          <table width="80" cellpadding="3" cellspacing="3" border="0">
 416          <tr>
 417              <td>
 418                  <b>' . $AppUI->_('Loading') . '</b>
 419              </td>
 420              <td>';
 421      echo w2PshowImage('progress.gif', '10', '10', 'spinner', 'Loading...');
 422      echo '
 423              </td>
 424          </tr>
 425          </table>
 426          </div>
 427          <!--End AJAX loading messagebox -->';
 428  }
 429  ob_end_flush();
 430  ?>


Generated: Wed Mar 10 03:00:03 2010 Cross-referenced by PHPXref 0.7