[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/customer/example/ -> create_customers.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: Bryan Alsdorf <bryan@mysql.com>                             |
  26  // +----------------------------------------------------------------------+
  27  //
  28  //
  29  require_once(dirname(__FILE__) . "/../../init.php");
  30  require_once (APP_INC_PATH . "db_access.php");
  31  require_once (APP_INC_PATH . "class.customer.php");
  32  require_once (APP_INC_PATH . "class.user.php");
  33  
  34  // creates user accounts for all the customers
  35  $prj_id = 1;
  36  
  37  $customers = Customer::getAssocList($prj_id);
  38  
  39  foreach ($customers as $customer_id => $customer_name) {
  40      echo "Customer: $customer_name<br />\n";
  41      
  42      $details = Customer::getDetails($prj_id, $customer_id);
  43      
  44      foreach ($details['contacts'] as $contact) {
  45          echo "Contact: " . $contact['first_name'] . " " . $contact['last_name'] . " (" . $contact['email'] . ")<br />\n";
  46          $contact_id = User::getUserIDByContactID($contact['contact_id']);
  47          if (empty($contact_id)) {
  48              $sql = "INSERT INTO
  49                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user
  50                      SET
  51                          usr_created_date = '" . Date_API::getCurrentDateGMT() . "',
  52                          usr_full_name = '" . Misc::escapeString($contact['first_name'] . " " . $contact['last_name']) . "',
  53                          usr_email = '" . $contact['email'] . "',
  54                          usr_customer_id = " . $customer_id . ",
  55                          usr_customer_contact_id = " . $contact['contact_id'] . ",
  56                          usr_preferences = '" . Misc::escapeString(Prefs::getDefaults(array($prj_id))) . "'";
  57              $res = $GLOBALS["db_api"]->dbh->query($sql);
  58              if (PEAR::isError($res)) {
  59                  echo "Error inserting user<br /><pre>";
  60                  print_r($res);
  61                  echo "</pre>";
  62              }
  63              $new_usr_id = $GLOBALS['db_api']->get_last_insert_id();
  64              Project::associateUser($prj_id, $new_usr_id, User::getRoleID("Customer"));
  65          }
  66      }
  67      echo "<hr />";
  68  }


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