Subversion Repositories computer_asset_manager_v1

Rev

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