Subversion Repositories computer_asset_manager_v1

Rev

Rev 104 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 rodolico 1
<?php
2
 
105 rodolico 3
   define(VERSION,'1.8.0');
67 rodolico 4
   define(BUILD_DATE,'$Date: 2020-01-19 23:19:56 -0600 (Sun, 19 Jan 2020) $');
5
   define(SVN_REV,'$Rev: 105 $' );
1 rodolico 6
 
7
   include_once("database.php");
8
 
9
   include_once("library.php");
10
   include_once('reports.php');
11
 
12
   global $MODULE_REPORTS;
13
   $MODULE_REPORTS = array('main device screen' => 1);
14
 
63 rodolico 15
   define ('SQL_GET_MODULES',
48 rodolico 16
     "select a.key_name 'module',
17
             a.theValue 'script', 
18
             b.theValue 'path' 
19
      from _system a join _system b using ( key_name )
20
      where
21
         a.group_name = '<screen>' 
22
         and b.group_name = 'Modules' 
23
         and a.removed_date is null
24
         and b.removed_date is null"
25
   );
26
 
63 rodolico 27
   define ('SQL_SHOW_SITES',
83 rodolico 28
      "select concat('<a href=\"index.html?site_id=',site_id,'\">', Site,'</a>') 'Site',
1 rodolico 29
              count(*) 'Devices',
83 rodolico 30
              concat('<a href=\"edit.html?site_id=',site_id,'\">Edit</a>') Action
31
       from view_client_site_device
1 rodolico 32
       where <whereClause>
83 rodolico 33
       group by site_id
34
       order by view_client_site_device.Site"
1 rodolico 35
   );
36
 
63 rodolico 37
   define ('SQL_SHOW_DEVICES',
83 rodolico 38
      "select concat('<a href=\"show_device.html?device_id=',device_id,'\">',Device,'</a>') 'Device',
39
       Device_Type 'Type',
40
       concat('<a href=\"edit.html?device_id=',device_id,'\">Edit</a>') Action
41
       from view_client_site_device
42
       where <whereClause>
43
       order by view_client_site_device.Device_Type,view_client_site_device.Device"
1 rodolico 44
   );
45
 
63 rodolico 46
   define ('SQL_SHOW_CLIENTS',
83 rodolico 47
      "select max(concat('<a href=\"index.html?client_id=',client_id,'\">',Client,'</a>')) 'Client', 
1 rodolico 48
              count(*) 'Sites',
83 rodolico 49
              concat('<a href=\"edit.html?client_id=',client_id,'\">Edit</a>') Action
50
       from view_client_site_device
51
       where <whereClause>
52
       group by client_id
53
       order by view_client_site_device.Client"
1 rodolico 54
   );
55
 
63 rodolico 56
   define ('SQL_SHOW_DEVICE', '
1 rodolico 57
      select device.device_id "ID",
58
             concat(client.name, \' - \', site.name) "Site",
59
             device_type.name "Type",
60
             device.name "Name",
48 rodolico 61
             device.serial "Serial",
1 rodolico 62
             device.notes "Notes",
37 rodolico 63
             device.restrictions "Restrictions",
1 rodolico 64
             partof.name "Part Of",
65
             date(device.added_date) "Added",
66
             date(device.removed_date) "Removed"
67
      from device join site on device.site_id = site.site_id 
68
           join client on site.client_id = client.client_id 
69
           join device_type on device.device_type_id = device_type.device_type_id 
70
           left outer join device as partof on partof.device_id = device.part_of
71
      where device.device_id = <device_id>
72
   ');
73
 
74
   $LOGIN_PAGE = $_SESSION['html root'] . '/login.html';
75
 
76
   function verifyLogin( $username, $password ) {
77
      $sql = "select login_id login_id, email, where_clause
78
              from login 
79
              where email = " . makeSafeSQLValue($username) . ' 
80
                    and pass = md5(' . makeSafeSQLValue($password) . ") 
81
                    and removed_date is null";
82
      $info = queryDatabaseExtended( $sql );
83
      if ( $info['count'] == 1 ) {
84
         $info = $info['data'][0];
85
         $_SESSION['login_id'] = ($info['login_id'] ? $info['login_id'] : -1);
86
         $_SESSION['email'] = $info['email'];
87
         $_SESSION['where_clause'] = $info['where_clause'];
84 rodolico 88
         $_SESSION['menu items'] = array_keys( sqlValuesToKeys( 'select menu_id from login_menu where login_id = ' . $_SESSION['login_id'] ) );
1 rodolico 89
         redirectPage('index.html');
90
      } else {
91
         return false;
92
      }
93
   }
94
 
95
   function setAuth ( $whereClause = 'true' ) {
83 rodolico 96
      return " ($whereClause) and " . ( $_SESSION['where_clause'] ? $_SESSION['where_clause'] : '1=0' );
1 rodolico 97
   }
98
 
99
   function iAmAdministrator () {
83 rodolico 100
      return ($_SESSION['where_clause'] == '1=1');
1 rodolico 101
   }
102
 
103
   /*
104
      function takes a screen name and looks it up in $MODULE_REPORTS to translate to a bit position.
105
      It will then search the report table in the database to determine which reports need to be run, passing the values in the 
106
      $parameters array to the run command, can capturing the output.
107
      function then returns the html output of the report(s) back to the calling program, which can then paste it into the current
108
      screen.
109
      The concept is that a particular screen may need some sub reports. For example, the display device screen in the Main module
110
      will want to display the information about the device taken from the device_attrib table. To do this, a report is defined
111
      using the query 
112
         select attrib.name,device_attrib.value 
113
         from device_attrib join attrib using (attrib_id) 
114
         where device_id = <device_id> and device_attrib.removed_date is null
115
      where <device_id> is replaced by the report class.
116
      The calling routine would pass 'device_id' => '1' in the parameters array (if the current device had a device_id of 1) and this
117
      routine would run the report and return the results.
118
      This allows newer modules to add reports to existing screens simply by creating a report and setting up parameters correctly.
119
      BY CONVENTION, the following parameters are passed, if applicable:
120
         device_id      - numeric ID of the device in question
121
         device_name    - ascii name of the device in question
122
         site_id        - numeric ID of the site in question
123
         client_id      - numeric ID of the client in question
124
         added_date     - value for added_date
125
         removed_date   - value for removed_date
126
     Not all reports will use the above values, but if they are passed in to the parameters array, they will not cause problems with
127
     the report
128
 
129
     NOTE: the reports will still run in interactive mode. In the above query, it will ask for the device.
130
   */
104 rodolico 131
   function screenReports ( $screenName, $parameters = array(), $showTitle = false, $titleBlocks = array() ) {
1 rodolico 132
      global $MODULE_REPORTS;
133
      $result = '';
134
      if ($MODULE_REPORTS[$screenName]) {
135
         $sql = 'select report_id from report where screen_report = ' . $MODULE_REPORTS[$screenName];
136
         $reportIDs = sqlValuesToKeys ($sql);
137
         // print "<pre>"; print_r( $parameters ); print "</pre>";
138
         foreach ( $reportIDs as $thisReport => $data ) {
139
            $report = new Report;
140
            $report->loadFromDatabase ( $thisReport );
104 rodolico 141
            $result .= $report->run($parameters, '', $showTitle, $titleBlocks );
1 rodolico 142
         }
143
      }
144
      return $result;
145
   }
146
 
147
   if ($_SESSION['file system root']) { // this is only set if we have logged in
148
      $InstalledModules = array();
149
      // get module information
150
      $data = queryDatabaseExtended( "select theValue from _system where removed_date is null and group_name = 'Modules'");
151
      if ($data) {
152
         foreach ($data['data'] as $row) {
153
            $InstalledModules[] = $row['theValue'];
154
         }
155
         // note, we are only going to include the datagase.php. All other stuff is left to the individual modules
156
         // $_SESSION['file system root'] is set in login.php, and is the path to the root of this application, so all else is relative
157
         foreach ($InstalledModules as $directory) {
158
            include_once( $_SESSION['file system root'] . "/$directory/database.php" );
159
         }
160
      }
161
   }
162
 
62 rodolico 163
   /* 
164
    * finds out if there is a callable script for this screen in the various modules.
165
    * if so, will call the script and return the output
166
    * index is an array of the form 'device_id' => $device_id
167
    * call this as
168
    * print callableOutput( 'device view', array( 'device_id' => $device_id );
169
    */
170
   function callableOutput( $screen, $index ) {
63 rodolico 171
      $result = '';
62 rodolico 172
      $sql = insertValuesIntoQuery(SQL_GET_MODULES,array( 'screen' => $screen ));
173
      $modules = queryDatabaseExtended( $sql );
174
      if ( $modules ) {
175
         $modules = $modules['data'];
176
         $parameters = $index;
63 rodolico 177
/*         $output = array();
178
         $output = "$screen\n" . print_r( $index, true) . print_r( $modules, true ) . "\n$sql\n"
179
         file_put_contents( '/home/rodolico/www/web/computer_asset_manager_v1/modules/file/queryout.sql', implode( "\n", $output)  );
180
*/
62 rodolico 181
         foreach ( $modules as $report ) {
182
            $module = $report['module'];
183
            list($library, $function ) = explode (':', $report['path'] . $report['script']);
184
            //print "$library - $function<br />\n";
63 rodolico 185
            if ( file_exists( $library ) ) {
186
               require_once "$library";
187
               if ( is_callable( $function ) ) {
188
                  $content = call_user_func( $function, $parameters );
189
                  if ( $content )
190
                     $result .= "<div><h4>$module</h4>$content</div>\n";
191
               }
62 rodolico 192
            }
193
         }
194
      }
63 rodolico 195
      return $result;
62 rodolico 196
   } // callableOutput
86 rodolico 197
 
198
   /*
199
    * returns an SQL query to get all available devices
200
    */
201
   function getAllDevices () {
202
      $sql = "select distinct device_id,concat(Device, ' - ', Client, '(', Site, ')' )
203
              from view_client_site_device";
204
      $sql .= ' where ' . $_SESSION['where_clause'];
205
      $sql .= ' order by view_client_site_device.Device';
206
      return $sql;
207
   }
208
 
209
   /*
210
    * Simply returns an SQL with the client_id and the client
211
    */
212
   function getClients () {
213
      return 'select distinct client_id,Client
214
               from
215
                  view_client_site_device
216
                  join maintenance_schedule using ( device_id )
217
               where maintenance_schedule.removed_date is null 
218
                     and ' . $_SESSION['where_clause'] .
219
               ' order by Client';
220
   }
221
 
222
   /*
223
    * Return query selecting available sites
224
    */
225
   function getSites () {
226
      return 'select distinct site_id,Site from view_client_site_device where ' . $_SESSION['where_clause'] . ' order by Client,Site';
227
   }
62 rodolico 228
 
229
 
86 rodolico 230
   function getTechs () {
231
      return 'select login_id,email from login where removed_date is null order by email';
232
   }
233
 
234
 
235
 
236
 
37 rodolico 237
?>