Subversion Repositories computer_asset_manager_v1

Rev

Rev 46 | Rev 62 | 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
 
46 rodolico 3
   define(VERSION,'1.6.1');
4
   define(BUILD_DATE,'20170709');
1 rodolico 5
 
6
   include_once("database.php");
7
 
8
   include_once("library.php");
9
   include_once('reports.php');
10
 
11
   global $MODULE_REPORTS;
12
   $MODULE_REPORTS = array('main device screen' => 1);
13
 
48 rodolico 14
   define (SQL_GET_MODULES,
15
     "select a.key_name 'module',
16
             a.theValue 'script', 
17
             b.theValue 'path' 
18
      from _system a join _system b using ( key_name )
19
      where
20
         a.group_name = '<screen>' 
21
         and b.group_name = 'Modules' 
22
         and a.removed_date is null
23
         and b.removed_date is null"
24
   );
25
 
1 rodolico 26
   define (SQL_SHOW_SITES,
27
      "select concat('<a href=\"index.html?site_id=',site.site_id,'\">', site.name,'</a>') 'Site',
28
              count(*) 'Devices',
29
              concat('<a href=\"edit.html?site_id=',site.site_id,'\">Edit</a>') Action
30
       from client_site site left outer join current_systems device using (site_id)
31
       where <whereClause>
32
       group by site.site_id
33
       order by site.name"
34
   );
35
 
36
   define (SQL_SHOW_DEVICES,
37
      "select concat('<a href=\"show_device.html?device_id=',device.device_id,'\">',device.name,'</a>') 'Device',
38
       device_type.name 'Type',
39
       concat('<a href=\"edit.html?device_id=',device.device_id,'\">Edit</a>') Action
40
       from device join device_type on device.device_type_id = device_type.device_type_id
41
            join site on device.site_id = site.site_id
42
            join client on site.client_id = client.client_id
43
       where device_type.show_as_system = 'Y' 
44
             and device.removed_date is null
45
             and <whereClause>
46
       order by device_type.name,device.name"
47
   );
48
 
49
   define (SQL_SHOW_CLIENTS,
50
      "select max(concat('<a href=\"index.html?client_id=',client.client_id,'\">',client.name,'</a>')) 'Client', 
51
              count(*) 'Sites',
52
              concat('<a href=\"edit.html?client_id=',client.client_id,'\">Edit</a>') Action
53
       from client left outer join site using (client_id)
54
       where site.removed_date is null and
55
             <whereClause>
56
       group by client.client_id
57
       order by client.name"
58
   );
59
 
60
   define (SQL_SHOW_DEVICE, '
61
      select device.device_id "ID",
62
             concat(client.name, \' - \', site.name) "Site",
63
             device_type.name "Type",
64
             device.name "Name",
48 rodolico 65
             device.serial "Serial",
1 rodolico 66
             device.notes "Notes",
37 rodolico 67
             device.restrictions "Restrictions",
1 rodolico 68
             partof.name "Part Of",
69
             date(device.added_date) "Added",
70
             date(device.removed_date) "Removed"
71
      from device join site on device.site_id = site.site_id 
72
           join client on site.client_id = client.client_id 
73
           join device_type on device.device_type_id = device_type.device_type_id 
74
           left outer join device as partof on partof.device_id = device.part_of
75
      where device.device_id = <device_id>
76
   ');
77
 
78
   $LOGIN_PAGE = $_SESSION['html root'] . '/login.html';
79
 
80
   function verifyLogin( $username, $password ) {
81
      $sql = "select login_id login_id, email, where_clause
82
              from login 
83
              where email = " . makeSafeSQLValue($username) . ' 
84
                    and pass = md5(' . makeSafeSQLValue($password) . ") 
85
                    and removed_date is null";
86
      $info = queryDatabaseExtended( $sql );
87
      if ( $info['count'] == 1 ) {
88
         $info = $info['data'][0];
89
         $_SESSION['login_id'] = ($info['login_id'] ? $info['login_id'] : -1);
90
         $_SESSION['email'] = $info['email'];
91
         $_SESSION['where_clause'] = $info['where_clause'];
92
         redirectPage('index.html');
93
      } else {
94
         return false;
95
      }
96
   }
97
 
98
   function setAuth ( $whereClause = 'true' ) {
99
      if ( iAmAdministrator() ) return $whereClause;
100
      $whereClause = " ($whereClause)"; // ensure that the whereClause passed will not override our limits
101
      switch ( $_SESSION['where_clause'] ) {
102
         case '' : $whereClause .= ' and false'; // no login allowed if empty string
103
                  break;
104
         default : $whereClause .= ' and ' . $_SESSION['where_clause'];
105
      }
106
      return $whereClause;
107
   }
108
 
109
   function iAmAdministrator () {
110
      return ($_SESSION['where_clause'] == 'ADMINISTRATOR');
111
   }
112
 
113
   /*
114
      function takes a screen name and looks it up in $MODULE_REPORTS to translate to a bit position.
115
      It will then search the report table in the database to determine which reports need to be run, passing the values in the 
116
      $parameters array to the run command, can capturing the output.
117
      function then returns the html output of the report(s) back to the calling program, which can then paste it into the current
118
      screen.
119
      The concept is that a particular screen may need some sub reports. For example, the display device screen in the Main module
120
      will want to display the information about the device taken from the device_attrib table. To do this, a report is defined
121
      using the query 
122
         select attrib.name,device_attrib.value 
123
         from device_attrib join attrib using (attrib_id) 
124
         where device_id = <device_id> and device_attrib.removed_date is null
125
      where <device_id> is replaced by the report class.
126
      The calling routine would pass 'device_id' => '1' in the parameters array (if the current device had a device_id of 1) and this
127
      routine would run the report and return the results.
128
      This allows newer modules to add reports to existing screens simply by creating a report and setting up parameters correctly.
129
      BY CONVENTION, the following parameters are passed, if applicable:
130
         device_id      - numeric ID of the device in question
131
         device_name    - ascii name of the device in question
132
         site_id        - numeric ID of the site in question
133
         client_id      - numeric ID of the client in question
134
         added_date     - value for added_date
135
         removed_date   - value for removed_date
136
     Not all reports will use the above values, but if they are passed in to the parameters array, they will not cause problems with
137
     the report
138
 
139
     NOTE: the reports will still run in interactive mode. In the above query, it will ask for the device.
140
   */
141
   function screenReports ( $screenName, $parameters = array(), $showTitle = false ) {
142
      global $MODULE_REPORTS;
143
      $result = '';
144
      if ($MODULE_REPORTS[$screenName]) {
145
         $sql = 'select report_id from report where screen_report = ' . $MODULE_REPORTS[$screenName];
146
         $reportIDs = sqlValuesToKeys ($sql);
147
         // print "<pre>"; print_r( $parameters ); print "</pre>";
148
         foreach ( $reportIDs as $thisReport => $data ) {
149
            $report = new Report;
150
            $report->loadFromDatabase ( $thisReport );
151
            $result .= $report->run($parameters, '', $showTitle );
152
         }
153
      }
154
      return $result;
155
   }
156
 
157
   if ($_SESSION['file system root']) { // this is only set if we have logged in
158
      $InstalledModules = array();
159
      // get module information
160
      $data = queryDatabaseExtended( "select theValue from _system where removed_date is null and group_name = 'Modules'");
161
      if ($data) {
162
         foreach ($data['data'] as $row) {
163
            $InstalledModules[] = $row['theValue'];
164
         }
165
         // note, we are only going to include the datagase.php. All other stuff is left to the individual modules
166
         // $_SESSION['file system root'] is set in login.php, and is the path to the root of this application, so all else is relative
167
         foreach ($InstalledModules as $directory) {
168
            include_once( $_SESSION['file system root'] . "/$directory/database.php" );
169
         }
170
      }
171
   }
172
 
37 rodolico 173
?>