Subversion Repositories computer_asset_manager_v1

Rev

Rev 1 | Rev 52 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 38
Line 1... Line 1...
1
<?php
1
<?php
-
 
2
   /*
-
 
3
    * Revision History:
-
 
4
    * 20161217 RWR
-
 
5
    * Added cleanLineReturn, removeBlanLines and getDOMUDOM0
-
 
6
    */
-
 
7
    
2
   include_once( './maintenance_database.php' ); 
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
-
 
27
 
-
 
28
 
-
 
29
   function removeBlankLines( $subject, $eoln = "\n" ) {
-
 
30
      return preg_replace( '/^[ \t]*[\r\n]+/m', '', $subject );
-
 
31
   }
-
 
32
      
3
 
33
 
4
   function postMaintenance($device = '', $task = '', $notes = '', $technician = '', $date = '') {
34
   function postMaintenance($device = '', $task = '', $notes = '', $technician = '', $date = '') {
5
      if ( $device ) { # parameters are being passed directly in
35
      if ( $device ) { # parameters are being passed directly in
6
         $sql = 'insert into maintenance_performed (device_id,maintenance_task_id,maintenance_date,notes,login_id) values (' .
36
         $sql = 'insert into maintenance_performed (device_id,maintenance_task_id,maintenance_date,notes,login_id) values (' .
7
               implode( ',', 
37
               implode( ',', 
Line 62... Line 92...
62
                  from maintenance_schedule 
92
                  from maintenance_schedule 
63
                  where maintenance_schedule_id = $id";
93
                  where maintenance_schedule_id = $id";
64
         doSQL($sql);
94
         doSQL($sql);
65
      }
95
      }
66
   }
96
   }
-
 
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
      
67
 
150
 
68
 
151
 
69
 
152
 
70
?>
-
 
71
 
153
?>
-
 
154