Subversion Repositories computer_asset_manager_v1

Rev

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