Subversion Repositories computer_asset_manager_v2

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
53 rodolico 1
<?php
2
 
3
   class Camp {
4
      protected static $dbStructure;
5
      public static $myName;
6
      protected static $viewName = 'view_device_location_owner_type';
7
 
8
      public static function getStats () {
9
         global $dbConnection;
10
 
11
         $return = array();
12
         $restrictions = array();
13
         foreach ( $_SESSION['restrictions'] as $class => $restriction ) {
14
            $restrictions[] = $_SESSION['restrictions'][$class];
15
         }
16
         $whereClause = count($restrictions) ? ' and ' . implode( ' and ', $restrictions) : '';
17
         // total kludge, I'll work on it later
18
         $active = 'owner_removed is null and location_removed is null and device_removed is null';
19
         $inactive = 'owner_removed is not null and location_removed is not null and device_removed is not null';
20
 
21
         $query = sprintf( 'select count(distinct %s) from %s', static::$dbStructure['table']['primaryKey'],  self::$viewName );
22
         $return['active'] = $dbConnection->getOneDBValue( "$query where $active $whereClause" );
23
         $return['inactive'] = $dbConnection->getOneDBValue( "$query where $inactive $whereClause"  );
24
         return $return;
25
      }
26
 
27
      public static function showSelectionList() {
28
         global $url;
29
         $list = self::getAll();
30
         foreach ( $list as $id => $name ) {
31
            $return[] = "<a href='$url?id=$id'>$name</a>";
32
         }
33
         return '<ul><li>' . implode( '</li><li>', $return ) . '</li></ul>';
34
      }
35
 
36
      public static function getAll() {
37
         global $activeOnly;
38
         global $dbConnection;
39
 
40
         $return = array();
41
         $query = sprintf( 'select %s id, %s name from %s', 
42
               self::$dbStructure['primaryKey'],
43
               self::$dbStructure['selectionDisplay'],
44
               self::$dbStructure['tableName']
45
               );
46
         if ( $activeOnly )
47
            $query .= ' where removed is null';
48
         $result = $dbConnection->doSQL( $query );
49
         foreach ( $result['returnData'] as $row ) {
50
            $return[$row['id']] = $row['name'];
51
         }
52
         return $return;
53
      }
54
 
55
      public function __toString() {
56
         return $this->name;
57
      }
58
 
59
   } // abstract class Camp
60
 
61
?>