Subversion Repositories computer_asset_manager_v1

Rev

Rev 67 | Rev 84 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 rodolico 1
<?php
2
 
67 rodolico 3
   define(VERSION,'1.6.2');
4
   define(BUILD_DATE,'$Date: 2019-05-11 01:58:43 -0500 (Sat, 11 May 2019) $');
5
   define(SVN_REV,'$Rev: 83 $' );
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'];
88
         redirectPage('index.html');
89
      } else {
90
         return false;
91
      }
92
   }
93
 
94
   function setAuth ( $whereClause = 'true' ) {
83 rodolico 95
      return " ($whereClause) and " . ( $_SESSION['where_clause'] ? $_SESSION['where_clause'] : '1=0' );
1 rodolico 96
   }
97
 
98
   function iAmAdministrator () {
83 rodolico 99
      return ($_SESSION['where_clause'] == '1=1');
1 rodolico 100
   }
101
 
102
   /*
103
      function takes a screen name and looks it up in $MODULE_REPORTS to translate to a bit position.
104
      It will then search the report table in the database to determine which reports need to be run, passing the values in the 
105
      $parameters array to the run command, can capturing the output.
106
      function then returns the html output of the report(s) back to the calling program, which can then paste it into the current
107
      screen.
108
      The concept is that a particular screen may need some sub reports. For example, the display device screen in the Main module
109
      will want to display the information about the device taken from the device_attrib table. To do this, a report is defined
110
      using the query 
111
         select attrib.name,device_attrib.value 
112
         from device_attrib join attrib using (attrib_id) 
113
         where device_id = <device_id> and device_attrib.removed_date is null
114
      where <device_id> is replaced by the report class.
115
      The calling routine would pass 'device_id' => '1' in the parameters array (if the current device had a device_id of 1) and this
116
      routine would run the report and return the results.
117
      This allows newer modules to add reports to existing screens simply by creating a report and setting up parameters correctly.
118
      BY CONVENTION, the following parameters are passed, if applicable:
119
         device_id      - numeric ID of the device in question
120
         device_name    - ascii name of the device in question
121
         site_id        - numeric ID of the site in question
122
         client_id      - numeric ID of the client in question
123
         added_date     - value for added_date
124
         removed_date   - value for removed_date
125
     Not all reports will use the above values, but if they are passed in to the parameters array, they will not cause problems with
126
     the report
127
 
128
     NOTE: the reports will still run in interactive mode. In the above query, it will ask for the device.
129
   */
130
   function screenReports ( $screenName, $parameters = array(), $showTitle = false ) {
131
      global $MODULE_REPORTS;
132
      $result = '';
133
      if ($MODULE_REPORTS[$screenName]) {
134
         $sql = 'select report_id from report where screen_report = ' . $MODULE_REPORTS[$screenName];
135
         $reportIDs = sqlValuesToKeys ($sql);
136
         // print "<pre>"; print_r( $parameters ); print "</pre>";
137
         foreach ( $reportIDs as $thisReport => $data ) {
138
            $report = new Report;
139
            $report->loadFromDatabase ( $thisReport );
140
            $result .= $report->run($parameters, '', $showTitle );
141
         }
142
      }
143
      return $result;
144
   }
145
 
146
   if ($_SESSION['file system root']) { // this is only set if we have logged in
147
      $InstalledModules = array();
148
      // get module information
149
      $data = queryDatabaseExtended( "select theValue from _system where removed_date is null and group_name = 'Modules'");
150
      if ($data) {
151
         foreach ($data['data'] as $row) {
152
            $InstalledModules[] = $row['theValue'];
153
         }
154
         // note, we are only going to include the datagase.php. All other stuff is left to the individual modules
155
         // $_SESSION['file system root'] is set in login.php, and is the path to the root of this application, so all else is relative
156
         foreach ($InstalledModules as $directory) {
157
            include_once( $_SESSION['file system root'] . "/$directory/database.php" );
158
         }
159
      }
160
   }
161
 
62 rodolico 162
   /* 
163
    * finds out if there is a callable script for this screen in the various modules.
164
    * if so, will call the script and return the output
165
    * index is an array of the form 'device_id' => $device_id
166
    * call this as
167
    * print callableOutput( 'device view', array( 'device_id' => $device_id );
168
    */
169
   function callableOutput( $screen, $index ) {
63 rodolico 170
      $result = '';
62 rodolico 171
      $sql = insertValuesIntoQuery(SQL_GET_MODULES,array( 'screen' => $screen ));
172
      $modules = queryDatabaseExtended( $sql );
173
      if ( $modules ) {
174
         $modules = $modules['data'];
175
         $parameters = $index;
63 rodolico 176
/*         $output = array();
177
         $output = "$screen\n" . print_r( $index, true) . print_r( $modules, true ) . "\n$sql\n"
178
         file_put_contents( '/home/rodolico/www/web/computer_asset_manager_v1/modules/file/queryout.sql', implode( "\n", $output)  );
179
*/
62 rodolico 180
         foreach ( $modules as $report ) {
181
            $module = $report['module'];
182
            list($library, $function ) = explode (':', $report['path'] . $report['script']);
183
            //print "$library - $function<br />\n";
63 rodolico 184
            if ( file_exists( $library ) ) {
185
               require_once "$library";
186
               if ( is_callable( $function ) ) {
187
                  $content = call_user_func( $function, $parameters );
188
                  if ( $content )
189
                     $result .= "<div><h4>$module</h4>$content</div>\n";
190
               }
62 rodolico 191
            }
192
         }
193
      }
63 rodolico 194
      return $result;
62 rodolico 195
   } // callableOutput
196
 
197
 
37 rodolico 198
?>