Subversion Repositories computer_asset_manager_v2

Rev

Rev 54 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

<?php

   class Camp {
      protected static $dbStructure;
      public static $myName;
      protected static $viewName = 'view_device_location_owner_type';
            
      public static function getStats () {
         global $dbConnection;
         
         $return = array();
         $restrictions = array();
         foreach ( $_SESSION['restrictions'] as $class => $restriction ) {
            $restrictions[] = $_SESSION['restrictions'][$class];
         }
         $whereClause = count($restrictions) ? ' and ' . implode( ' and ', $restrictions) : '';
         // total kludge, I'll work on it later
         $active = 'owner_removed is null and location_removed is null and device_removed is null';
         $inactive = 'owner_removed is not null and location_removed is not null and device_removed is not null';
            
         $query = sprintf( 'select count(distinct %s) from %s', static::$dbStructure['table']['primaryKey'],  self::$viewName );
         $return['active'] = $dbConnection->getOneDBValue( "$query where $active $whereClause" );
         $return['inactive'] = $dbConnection->getOneDBValue( "$query where $inactive $whereClause"  );
         return $return;
      }
      
      public static function showSelectionList() {
         global $url;
         $list = self::getAll();
         foreach ( $list as $id => $name ) {
            $return[] = "<a href='$url?id=$id'>$name</a>";
         }
         return '<ul><li>' . implode( '</li><li>', $return ) . '</li></ul>';
      }
      
      public static function getAll() {
         global $activeOnly;
         global $dbConnection;
         
         $return = array();
         $query = sprintf( 'select %s id, %s name from %s', 
               self::$dbStructure['primaryKey'],
               self::$dbStructure['selectionDisplay'],
               self::$dbStructure['tableName']
               );
         if ( $activeOnly )
            $query .= ' where removed is null';
         $result = $dbConnection->doSQL( $query );
         foreach ( $result['returnData'] as $row ) {
            $return[$row['id']] = $row['name'];
         }
         return $return;
      }
         
      public function __toString() {
         return $this->name;
      }
      
   } // abstract class Camp

?>