Subversion Repositories computer_asset_manager_v1

Rev

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

Rev Author Line No. Line
1 rodolico 1
<?php
52 rodolico 2
   include_once( './database.php' );
3
 
1 rodolico 4
   define(SQL_GET_PACKAGES,
5
          'select client.name,device.name,software.package_name,software_version.version
6
           from client join site on client.client_id = site.client_id
7
                join device on device.site_id = site.site_id
8
                join installed_packages on device.device_id = installed_packages.device_id
9
                join software on installed_packages.software_id = software.software_id
10
                join software_version on installed_packages.software_version_id = software_version.software_version_id
11
           where <whereClause>
12
           order by package_name,version
13
          '
14
   );
15
 
16
   define( SQL_AVAILABLE_PACKAGES,
17
       'select distinct software.software_id,software.package_name 
18
        from installed_packages join software on installed_packages.software_id = software.software_id 
19
        where <whereClause>
20
        order by software.package_name'
21
   );
22
 
23
   define( SQL_DEVICE_LIST,
24
      'select client.name,device.name,device.added_date \'Initial Date\', max(disk_space.added_date) \'Last Update\'
25
        from client join site on site.client_id = client.client_id
26
              join device on device.site_id = site.site_id
27
              join device_type on device_type.device_type_id = device.device_type_id
28
              join disk_info on disk_info.device_id = device.device_id
29
              join disk_space on disk_space.disk_info_id = disk_info.disk_info_id
30
        where <whereClause>
31
        group by client.name,device.name,device.added_date
32
        order by client.name,device.name
33
    '
34
   );
35
 
36
   define( SQL_AVAILABLE_DEVICES,
37
      'select distinct device_id,device.name
38
       from device join site on site.site_id=device.site_id
39
            join client on client.client_id = site.client_id
40
       where <whereClause>
41
       order by device.name
42
      '
43
   );
44
 
45
   define ( SQL_SOFTWARE_UPDATES,
46
      "select date(installed_packages.added_date) 'Added',
47
              date(installed_packages.removed_date) 'Removed',
48
              device.name 'Device',
49
              package_name 'Package', 
50
              version 'Version'
51
       from installed_packages join software on installed_packages.software_id = software.software_id
52
          join software_version on installed_packages.software_version_id = software_version.software_version_id
53
          join device on installed_packages.device_id = device.device_id
54
          join site on device.site_id = site.site_id
55
          join client on site.client_id = client.client_id
56
       where <whereClause>
57
       order by device.name,package_name,installed_packages.added_date
58
      "
59
   );
60
 
61
 
62
   define (SQL_GET_DISKSPACE,
63
           'select device.name,date(disk_space.added_date) \'Date Added\',  space_used/capacity*100 "used %", space_used/1048576 used, capacity/1048576 Part_Size, mount_point,  disk_device, filesystem
64
       from device join disk_info on disk_info.device_id = device.device_id
65
          join disk_space on disk_info.disk_info_id=disk_space.disk_info_id
66
       where disk_info.removed_date is null
67
            and device.removed_date is null
68
            and disk_space.added_date = (select max(added_date) from disk_space b where b.disk_info_id = disk_space.disk_info_id)
69
            and <whereClause>
70
       order by device.name,disk_device
71
      '
72
   );
73
 
74
   define (SQL_DO_MAINTENANCE,
75
      "select login.name 'Maintainer', 
76
            concat(client.name,'<br /> ',site.name) 'Site',
77
            device.name 'Device',
78
            date(date_add(maintenance_performed.maintenance_date,interval maintenance_schedule.schedule day)) 'Next Due',
79
            concat('<INPUT type=\"checkbox\" name=\"',device.device_id,'-',maintenance_task.maintenance_task_id,'_done\"><b>Completed</b><br/>',maintenance_task.description) 'Work',
80
            concat(
81
            '<b>Date</b> <INPUT type=\"text\" name=\"',device.device_id,'-',maintenance_task.maintenance_task_id,'_date\" value=\"',date(now()),'\" size=\"10\" maxlength=\"10\">',
82
            '<br /><textarea name=\"',device.device_id,'-',maintenance_task.maintenance_task_id,'_notes\" cols=\"20\" rows=\"4\"></textarea>') 'Notes'
83
      from device join maintenance_schedule on device.device_id=maintenance_schedule.device_id
84
            join maintenance_task on maintenance_task.maintenance_task_id = maintenance_schedule.maintenance_task_id
85
            join maintenance_performed on maintenance_performed.device_id = maintenance_schedule.device_id
86
               and maintenance_performed.maintenance_task_id = maintenance_schedule.maintenance_task_id
87
            join login on maintenance_schedule.login_id = login.login_id
88
            join site on site.site_id = device.site_id
89
            join client on site.client_id = client.client_id
90
      where device.removed_date is null
91
            and maintenance_task.removed_date is null
92
            and <additionalWhere>
93
      order by login.email,client.name,site.name,device.name,maintenance_task.description"   
94
   );
95
 
96
   define (SQL_GET_MAINTAINERS,'
97
      select distinct login.login_id,login.name 
98
      from maintenance_schedule join login on maintenance_schedule.login_id = login.login_id
99
      '
100
   );
101
 
102
   define (SQL_GET_MAINTENANCE_CLIENTS,'
103
      select distinct client.client_id,client.name 
104
      from maintenance_schedule join device on maintenance_schedule.device_id = device.device_id 
105
         join site on device.site_id = site.site_id join client on site.client_id = client.client_id
106
      '
107
   );
108
//            DATE(DATE_ADD(maintenance_performed.maintenance_date, INTERVAL schedule DAY)) "Due Date",
109
 
110
   define (SQL_GET_OUTSTANDING_MAINTENANCE, '
111
     select concat( client.name, \' Site \', site.name ) "Site",
38 rodolico 112
            device.device_id "Device ID",
1 rodolico 113
            device.name "Device Name",
114
            device.notes "Device Notes",
37 rodolico 115
            device.restrictions "Restrictions",
1 rodolico 116
            maintenance_task.description "Task",
117
            maintenance_task.notes "Task Notes",
118
            DATEDIFF(DATE_ADD(maintenance_performed.maintenance_date, INTERVAL schedule DAY), now()) "Due",
119
            DATE(DATE_ADD(maintenance_performed.maintenance_date, INTERVAL schedule DAY)) "Date Due",
120
            login.email "Technician",
121
            maintenance_schedule.maintenance_schedule_id "ID"
122
      from maintenance_schedule join maintenance_performed on 
123
                  maintenance_performed.maintenance_task_id = maintenance_schedule.maintenance_task_id
124
                  and maintenance_performed.device_id = maintenance_schedule.device_id
125
         join login on login.login_id = maintenance_schedule.login_id
126
         join maintenance_task on maintenance_task.maintenance_task_id = maintenance_schedule.maintenance_task_id
127
         join device on maintenance_schedule.device_id = device.device_id
128
         join site on device.site_id = site.site_id
129
         join client on site.client_id = client.client_id
130
         join (select max(maintenance_performed_id) last_maintenance from maintenance_performed group by device_id,maintenance_task_id) last_performed on maintenance_performed.maintenance_performed_id = last_performed.last_maintenance
131
      where device.removed_date is null
132
            and site.removed_date is null
133
            and client.removed_date is null
134
            and maintenance_schedule.removed_date is null
135
            and <additionalWhere>
136
     order by DATEDIFF(DATE_ADD(maintenance_performed.maintenance_date, INTERVAL schedule DAY), now()),
137
           client.name,site.name,device.name, maintenance_task.description;
138
      '
139
//            and DATEDIFF(DATE_ADD(maintenance_performed.maintenance_date, INTERVAL schedule DAY), now()) <= 7
140
   );
141
 
142
   define (SQL_MAINTENANCE_REPORT, '
143
      select concat( client.name, \' - \', site.name) "Site",
144
             device.name "Device Name",
145
             maintenance_task.description "Task",
146
             DATE(maintenance_performed.maintenance_date) "Date",
147
             maintenance_performed.notes "Notes",
148
             login.email "Technician"
149
      from maintenance_performed join device on maintenance_performed.device_id = device.device_id
150
         join maintenance_task on maintenance_task.maintenance_task_id = maintenance_performed.maintenance_task_id
151
         join login on login.login_id = maintenance_performed.login_id
152
         join site on device.site_id = site.site_id
153
         join client on client.client_id = site.client_id
154
      <whereClause>
155
      <orderBy>
156
   ');
157
 
158
   define (SQL_SHOW_maintenance_schedule, '
159
      select maintenance_schedule.schedule "Period (d)",
160
            maintenance_task.description "Task",
161
            login.email "Technician",
162
            max(date(maintenance_performed.maintenance_date)) "Last Done",
163
            date(maintenance_schedule.added_date) "Added"
164
      from maintenance_schedule join login on maintenance_schedule.login_id = login.login_id 
165
           join maintenance_task on maintenance_schedule.maintenance_task_id = maintenance_task.maintenance_task_id
166
           join maintenance_performed on maintenance_schedule.device_id = maintenance_performed.device_id 
167
                and maintenance_schedule.maintenance_task_id = maintenance_performed.maintenance_task_id
168
      where maintenance_schedule.device_id = <device_id>
169
      group by maintenance_schedule.schedule,
170
               maintenance_task.description,
171
               login.email,
172
               maintenance_schedule.added_date,
173
               maintenance_schedule.removed_date
174
   ');
175
 
176
?>