Subversion Repositories computer_asset_manager_v1

Rev

Rev 53 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 rodolico 1
<?php
38 rodolico 2
   /*
3
    * Revision History:
4
    * 20161217 RWR
5
    * Added cleanLineReturn, removeBlanLines and getDOMUDOM0
6
    */
7
 
8
   include_once( './maintenance_database.php' );
52 rodolico 9
   include_once( './database.php' );
85 rodolico 10
 
11
   /*
12
    * returns an SQL query to get all available devices
13
    */
14
   function getAllDevices () {
15
      $sql = "select distinct device_id,concat(Device, ' - ', Client, '(', Site, ')' )
16
              from view_client_site_device";
17
      $sql .= ' where ' . $_SESSION['where_clause'];
18
      $sql .= ' order by view_client_site_device.Device';
19
      return $sql;
20
   }
38 rodolico 21
 
85 rodolico 22
   /*
23
    * Simply returns an SQL with the client_id and the client
24
    */
25
   function getClients () {
26
      return 'select distinct client_id,Client
27
               from
28
                  view_client_site_device
29
                  join maintenance_schedule using ( device_id )
30
               where maintenance_schedule.removed_date is null 
31
                     and ' . $_SESSION['where_clause'] .
32
               ' order by Client';
33
   }
34
 
35
   function getTechs () {
36
      return 'select login_id,email from login where removed_date is null order by email';
37
   }
38
 
38 rodolico 39
   /* function will take all eoln ("\n") and convert to <br /> if $makeHTML
40
    * is true, otherwise will replace all <br /> with \n.
41
    * Will then remove duplicates IF THEY ARE EXACTLY NEXT TO EACH OTHER
42
    * ie, with no intervening spaces.
43
    */
44
 
85 rodolico 45
 
38 rodolico 46
   function cleanLineReturn ( $subject, $makeHTML = false ) {
47
      if ( $makeHTML ) {
48
         $search = "\n";
49
         $replace = "<br />";
50
      } else {
51
         $search = "<br />";
52
         $replace = "\n";
53
      }
54
      $subject = str_replace ( $search, $replace, $subject );
55
      return str_replace ( $replace . $replace, $replace, $subject );
56
   } // cleanLineReturn
1 rodolico 57
 
38 rodolico 58
 
59
   function removeBlankLines( $subject, $eoln = "\n" ) {
60
      return preg_replace( '/^[ \t]*[\r\n]+/m', '', $subject );
61
   }
62
 
63
 
1 rodolico 64
   function postMaintenance($device = '', $task = '', $notes = '', $technician = '', $date = '') {
65
      if ( $device ) { # parameters are being passed directly in
66
         $sql = 'insert into maintenance_performed (device_id,maintenance_task_id,maintenance_date,notes,login_id) values (' .
67
               implode( ',', 
68
                  array(
69
                     makeSafeSQLValue($device, 'I'), 
70
                     makeSafeSQLValue( $task, 'I'), 
71
                     makeSafeSQLValue($date, 'I'), 
72
                     makeSafeSQLValue($notes), 
73
                     makeSafeSQLValue($technician, 'I')
74
                  )
75
               ) . ')';
76
         queryDatabaseExtended( $sql );
77
         //print "<pre>$sql</pre>";
78
      } else {
79
         foreach ( $_POST as $parameter => $value ) {
80
            if ( preg_match( '/performed_(\d+)/', $parameter, $id ) ) { // this is the checkbox
81
               if ( $value ) { // and it has a value
82
                  $id = $id[1];
83
                  $sql = array( 'select device_id', 'maintenance_task_id',$_POST["datedone_$id"],makeSafeSQLValue($_POST["notes_$id"],'S'),$_POST["technician_$id"]);
84
                  $sql = implode (',', $sql );
85
                  $sql = 'insert into maintenance_performed (device_id,maintenance_task_id,maintenance_date,notes,login_id) ' . $sql . 
86
                        " from maintenance_schedule where maintenance_schedule_id = $id";
87
                  queryDatabaseExtended( $sql );
88
                  //print "<pre>$sql</pre>";
89
               }
90
            }
91
         }
92
      }
93
   }
94
 
95
   function getSoftwareVersions ( $currentOnly = true, $softwareID = '',$computerID='' ) {
96
      $whereClause = array();
97
      if ( $currentOnly ) {
98
         $whereClause[] = 'installed_packages.removed_date is null';
99
      }
100
      if ( $softwareID ) {
101
         $whereClause[] = "package_name like '%$softwareID%'";
102
      }
103
      print '<pre>' . implode( ' and ', $whereClause ) . '</pre>';
104
     return array($sql, implode ( ' and ', $whereClause ), ' order by ');
105
   }
106
 
107
   function EditMaintenanceRecord( $id ) {
108
      global $DATABASE_DEFINITION;
109
      print $id == -1 ? addData( $DATABASE_DEFINITION['maintenance_schedule'] ) : editData( $DATABASE_DEFINITION['maintenance_schedule'], $id );
110
   }
111
 
112
   function postChanges( $id = '' ) {
113
      global $DATABASE_DEFINITION;
114
      if ($id) {
115
         updateData( $DATABASE_DEFINITION['maintenance_schedule'], $id );
116
      } else {
117
         $result = insertData( $DATABASE_DEFINITION['maintenance_schedule'] );
118
         // There MUST be a record in maintenance_performed or this is not visible
119
         $id = $result['insert_id'];
120
         $sql = "insert into maintenance_performed (device_id,maintenance_task_id,maintenance_date,notes,login_id)
121
                  select device_id,maintenance_task_id,added_date,'Added to System',login_id 
122
                  from maintenance_schedule 
123
                  where maintenance_schedule_id = $id";
124
         doSQL($sql);
125
      }
126
   }
38 rodolico 127
 
128
   /*
129
    * Determine if the machine is a DOMU or a DOM0 (it can not be both, obviously)
130
    * If it is a DOMU, return the DOM0 name
131
    * If it is a DOM0, return an array containing all DOMU's on it
132
    */
133
 
134
   function getDOMUDOM0 ( $id = '' ) {
135
      if ( $id ) {
136
         // first, get See if it is a DOMU (ie, it has a "part_of" that is not null)
137
         $query = "select
138
                     DOM0.device_id id,
139
                     DOM0.name      name
140
                  from 
141
                     device DOMU join device DOM0
142
                  where
143
                     DOMU.part_of = DOM0.device_id
144
                     and DOMU.removed_date is null
145
                     and DOMU.device_id = $id";
146
         $results = queryDatabaseExtended(  $query );
147
         if ( $results['count'] == 1 ) { // can not have more than 1
148
            return array( 
149
                          'name' => $results['data'][0]['name'],
150
                          'id'   => $results['data'][0]['id']
151
                        );
152
         } else {
153
            // see if it is a DOM0
154
            $query = "select 
155
                        device.name      name,
156
                        device.device_id id
157
                     from
158
                        device join device_type using (device_type_id)
159
                     where
160
                        device.removed_date is null
161
                        and device_type.show_as_system = 'Y'
162
                        and device.part_of = $id";
163
            $results = queryDatabaseExtended(  $query );
164
            if ( $results['count'] ) {
165
               $returnValue = array();
166
               $results = $results['data'];
167
               foreach ( $results as $entry ) {
168
                  $returnValue[] = array( 'name' => $entry['name'],
169
                                            'id' => $entry['id']
170
                                           );
171
               }
172
               return $returnValue;
173
            } // if we are a dom0
174
         } // if..else
175
      } // if id
176
      return null;
177
   } // function getDOMUDOM0
178
 
179
 
1 rodolico 180
 
181
 
182
 
38 rodolico 183
?>