HRDIODB
[ class tree: HRDIODB ] [ index: HRDIODB ] [ all elements ]

Source for file hrdi_db_class.php

Documentation is available at hrdi_db_class.php

  1. <?php
  2. /**
  3.  * HRDI DB class.
  4.  * This file contains the {@link hrdi_db} class, a customized HRDI class
  5.  * extending the generic {@link mcpear} class.
  6.  * @package HRDIODB
  7.  */
  8.  
  9. /**
  10.  * This file is part of HRDIODB.
  11.  *
  12.  * HRDIODB is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * HRDIODB is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with HRDIODB; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25.  */
  26.  
  27. /** PEAR DB wrapper class */
  28. require_once('mcpear_class.php');
  29.  
  30. /** 
  31.  * HRDI database class.
  32.  * An inherited class containing HRDI database specific actions. The class
  33.  * contains all of the mcpear methods but adds HRDI specific functionality.
  34.  * @package HRDIODB
  35.  */
  36. class hrdi_db extends mcpear {
  37.   /**
  38.    * HRDI specific add function.
  39.    * This function adds the creation date and time to the data and calls the
  40.    * parent's add() function.
  41.    * @param array $values Associative array of keys and values
  42.    * @param string $table Table name
  43.    * @return mixed Query result resource or FALSE on error
  44.    */
  45.   function add ($values$table{
  46.     $values['Created'$this->datetime();
  47.     return parent::add($values$table);
  48.   }
  49.     
  50.   /**
  51.    * HRDI specific update function.
  52.    * This function adds a history entry for this update, adds the update
  53.    * date and time to the data and then calls the parent's update() function.
  54.    * @param array $values Associative array of key values
  55.    * @param string $table Table name
  56.    * @param string $where_key Where clause
  57.    * @return mixed Query result resource or FALSE on error
  58.    */
  59.   function update($values$table$where_key){
  60.     $update_key "$where_key = '{$values[$where_key]}'";
  61.  
  62.     $sql "SELECT *
  63.             FROM $table
  64.             WHERE $update_key";
  65.  
  66.     $previous_data $this->get_row($sql);
  67.     $this->make_history($table$previous_data);
  68.  
  69.     $values['Modified'$this->datetime();
  70.  
  71.     return parent::update($values$table$where_key);
  72.   }
  73.  
  74.   /**
  75.   * Creates a history entry.
  76.   * This function creates an entry in the HRDI history table. The entry is
  77.   * made for the specified $table. The $previous_data is serialized and added
  78.   * to the entry. The previous data can be later unserialized using the PHP
  79.   * {@link PHP_MANUAL#unserialize} function.
  80.   * @param string $table The name of the table that was updated
  81.   * @param mixed $previous_data The data before the updated
  82.   * @return mixed Query result resource or FALSE on error
  83.   */
  84.   function make_history ($table$previous_data{
  85.     //$session = new session();
  86.     //$admin = $session->get_var("user_id");
  87.     $history['UserID'"0";
  88.     if(isset($_SESSION['user_data']['ID'])){
  89.       $history['UserID']=$_SESSION['user_data']['ID'];
  90.     }
  91.     
  92.     $history['Altered_Table'$table;
  93.  
  94.     /* The previous data is serialized. It can be later restored by calling
  95.        the unserialize() method. */
  96.     $history['Previous_Data'serialize($previous_data);
  97.  
  98.     return $this->add($history"HRDI_History");
  99.   }
  100.  
  101.   /**
  102.    * ISO 8601 date and time.
  103.    * This function returns an ISO 8601 date and time used for created/updated
  104.    * date and time.
  105.    * @return string ISO 8601 date and time
  106.    */
  107.   function datetime({
  108.     return date("Y-m-d\TH:i:s");
  109.   }
  110. }
  111. ?>

Documentation generated on Tue, 23 Jan 2007 22:57:48 -0500 by phpDocumentor 1.3.0RC6