[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/ -> select_project.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4 encoding=utf-8: */
   3  // +----------------------------------------------------------------------+
   4  // | Eventum - Issue Tracking System                                      |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 2003, 2004, 2005, 2006, 2007 MySQL AB                  |
   7  // |                                                                      |
   8  // | This program is free software; you can redistribute it and/or modify |
   9  // | it under the terms of the GNU General Public License as published by |
  10  // | the Free Software Foundation; either version 2 of the License, or    |
  11  // | (at your option) any later version.                                  |
  12  // |                                                                      |
  13  // | This program is distributed in the hope that it will be useful,      |
  14  // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  15  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
  16  // | GNU General Public License for more details.                         |
  17  // |                                                                      |
  18  // | You should have received a copy of the GNU General Public License    |
  19  // | along with this program; if not, write to:                           |
  20  // |                                                                      |
  21  // | Free Software Foundation, Inc.                                       |
  22  // | 59 Temple Place - Suite 330                                          |
  23  // | Boston, MA 02111-1307, USA.                                          |
  24  // +----------------------------------------------------------------------+
  25  // | Authors: João Prado Maia <jpm@mysql.com>                             |
  26  // +----------------------------------------------------------------------+
  27  //
  28  // @(#) $Id: select_project.php 3394 2007-11-04 08:33:06Z balsdorf $
  29  
  30  require_once(dirname(__FILE__) . "/init.php");
  31  require_once (APP_INC_PATH . "class.template.php");
  32  require_once (APP_INC_PATH . "class.project.php");
  33  require_once (APP_INC_PATH . "class.auth.php");
  34  require_once (APP_INC_PATH . "class.customer.php");
  35  require_once (APP_INC_PATH . "db_access.php");
  36  
  37  $tpl = new Template_API();
  38  $tpl->setTemplate("select_project.tpl.html");
  39  
  40  // check if cookies are enabled, first of all
  41  if (!Auth::hasCookieSupport(APP_COOKIE)) {
  42      Auth::redirect(APP_RELATIVE_URL . "index.php?err=11");
  43  }
  44  
  45  if (!Auth::hasValidCookie(APP_COOKIE)) {
  46      Auth::redirect(APP_RELATIVE_URL . "index.php?err=5");
  47  }
  48  
  49  if (@$_GET["err"] == '') {
  50      $cookie = Auth::getCookieInfo(APP_PROJECT_COOKIE);
  51      if ($cookie["remember"]) {
  52          if (!empty($_GET["url"])) {
  53              Auth::redirect($_GET["url"]);
  54          } else {
  55              Auth::redirect(APP_RELATIVE_URL . "main.php");
  56          }
  57      }
  58  
  59      Language::setPreference();
  60  
  61      // check if the list of active projects consists of just
  62      // one project, and redirect the user to the main page of the
  63      // application on that case
  64      $assigned_projects = Project::getAssocList(Auth::getUserID());
  65      if (count($assigned_projects) == 1) {
  66          list($prj_id,) = each($assigned_projects);
  67          Auth::setCurrentProject($prj_id, 0);
  68          handleExpiredCustomer($prj_id);
  69  
  70          if (!empty($_GET["url"])) {
  71              Auth::redirect($_GET["url"]);
  72          } else {
  73              Auth::redirect(APP_RELATIVE_URL . "main.php");
  74          }
  75      } elseif ((!empty($_GET["url"])) && (
  76              (preg_match("/.*view\.php\?id=(\d*)/", $_GET["url"], $matches) > 0) ||
  77              (preg_match("/switch_prj_id=(\d*)/", $_GET["url"], $matches) > 0)
  78              )) {
  79          // check if url is directly linking to an issue, and if it is, don't prompt for project
  80          if (stristr($_GET["url"], 'view.php')) {
  81              $prj_id = Issue::getProjectID($matches[1]);
  82          } else {
  83              $prj_id = $matches[1];
  84          }
  85          if (!empty($assigned_projects[$prj_id])) {
  86              Auth::setCurrentProject($prj_id, 0);
  87              handleExpiredCustomer($prj_id);
  88              Auth::redirect($_GET["url"]);
  89          }
  90      }
  91  }
  92  
  93  if (@$_GET["err"] != '') {
  94      Auth::removeCookie(APP_PROJECT_COOKIE);
  95      $tpl->assign("err", $_GET["err"]);
  96  }
  97  
  98  if (@$_POST["cat"] == "select") {
  99      $usr_id = Auth::getUserID();
 100      $projects = Project::getAssocList($usr_id);
 101      if (!in_array($_POST["project"], array_keys($projects))) {
 102          // show error message
 103          $tpl->assign("err", 1);
 104      } else {
 105          // create cookie and redirect
 106          if (empty($_POST["remember"])) {
 107              $_POST["remember"] = 0;
 108          }
 109          Auth::setCurrentProject($_POST["project"], $_POST["remember"]);
 110          handleExpiredCustomer($_POST["project"]);
 111  
 112          if (!empty($_POST["url"])) {
 113              Auth::redirect($_POST["url"]);
 114          } else {
 115              Auth::redirect(APP_RELATIVE_URL . "main.php");
 116          }
 117      }
 118  }
 119  
 120  $tpl->displayTemplate();
 121  
 122  function handleExpiredCustomer($prj_id)
 123  {
 124      GLOBAL $tpl;
 125  
 126      if (Customer::hasCustomerIntegration($prj_id)) {
 127          // check if customer is expired
 128          $usr_id = Auth::getUserID();
 129          $contact_id = User::getCustomerContactID($usr_id);
 130          $customer_id = User::getCustomerID($usr_id);
 131          if ((!empty($contact_id)) && ($contact_id != -1)) {
 132              Customer::authenticateCustomer($prj_id, $customer_id, $contact_id);
 133          }
 134      }
 135  }


Generated: Wed Dec 19 21:21:33 2007 Cross-referenced by PHPXref 0.7