home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / departments / departments.class.php < prev    next >
Encoding:
PHP Script  |  2003-09-10  |  2.0 KB  |  90 lines

  1. <?php /* DEPARTMENTS $Id: departments.class.php,v 1.3 2003/09/09 23:31:47 ajdonnison Exp $ */
  2. ##
  3. ## CDepartment Class
  4. ##
  5.  
  6. class CDepartment {
  7.     var $dept_id = NULL;
  8.     var $dept_parent = NULL;
  9.     var $dept_company = NULL;
  10.     var $dept_name = NULL;
  11.     var $dept_phone = NULL;
  12.     var $dept_fax = NULL;
  13.     var $dept_address1 = NULL;
  14.     var $dept_address2 = NULL;
  15.     var $dept_city = NULL;
  16.     var $dept_state = NULL;
  17.     var $dept_zip = NULL;
  18.     var $dept_url = NULL;
  19.     var $dept_desc = NULL;
  20.     var $dept_owner = NULL;
  21.  
  22.     function CDepartment() {
  23.         // empty constructor
  24.     }
  25.  
  26.     function load( $oid ) {
  27.         $sql = "SELECT * FROM departments WHERE dept_id = $oid";
  28.         return db_loadObject( $sql, $this );
  29.     }
  30.  
  31.     function bind( $hash ) {
  32.         if (!is_array( $hash )) {
  33.             return get_class( $this )."::bind failed";
  34.         } else {
  35.             bindHashToObject( $hash, $this );
  36.             return NULL;
  37.         }
  38.     }
  39.  
  40.     function check() {
  41.         if ($this->dept_id === NULL) {
  42.             return 'department id is NULL';
  43.         }
  44.         // TODO MORE
  45.         if ($this->dept_id && $this->dept_id == $this->dept_parent) {
  46.              return "cannot make myself my own parent (" . $this->dept_id . "=" . $this->dept_parent . ")";
  47.         }
  48.         return NULL; // object is ok
  49.     }
  50.  
  51.     function store() {
  52.         $msg = $this->check();
  53.         if( $msg ) {
  54.             return get_class( $this )."::store-check failed - $msg";
  55.         }
  56.         if( $this->dept_id ) {
  57.             $ret = db_updateObject( 'departments', $this, 'dept_id', false );
  58.         } else {
  59.             $ret = db_insertObject( 'departments', $this, 'dept_id' );
  60.         }
  61.         if( !$ret ) {
  62.             return get_class( $this )."::store failed <br />" . db_error();
  63.         } else {
  64.             return NULL;
  65.         }
  66.     }
  67.  
  68.     function delete() {
  69.         $sql = "SELECT * FROM departments WHERE dept_parent = $this->dept_id";
  70.  
  71.         $res = db_exec( $sql );
  72.         if (db_num_rows( $res )) {
  73.             return "deptWithSub";
  74.         }
  75.         $sql = "SELECT * FROM projects WHERE project_department = $this->dept_id";
  76.  
  77.         $res = db_exec( $sql );
  78.         if (db_num_rows( $res )) {
  79.             return "deptWithProject";
  80.         }
  81.         $sql = "DELETE FROM departments WHERE dept_id = $this->dept_id";
  82.         if (!db_exec( $sql )) {
  83.             return db_error();
  84.         } else {
  85.             return NULL;
  86.         }
  87.     }
  88. }
  89. ?>
  90.