Subversion Repositories computer_asset_manager_v1

Rev

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