~budgester/irm/trunk

« back to all changes in this revision

Viewing changes to users/reports/software.php

  • Committer: budgester at budgester
  • Date: 2008-03-05 23:14:13 UTC
  • Revision ID: budgester@budgester.com-20080305231413-k5vqfuckfo09ju42
Initial import of IRM codebase

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
#    IRM - The Information Resource Manager
 
3
#
 
4
#    Software Report Module
 
5
#    Copyright (C) 2002 Big Walnut Local Schools
 
6
#    written by David Maxwell, Technician Big Walnut Local Schools
 
7
#    Contains altered code from irm.inc and default.php files included with
 
8
#    the 1.3.4 version of IRM.         
 
9
#    
 
10
#    This program is free software; you can redistribute it and/or modify
 
11
#    it under the terms of the GNU General Public License as published by
 
12
#    the Free Software Foundation; either version 2 of the License, or
 
13
#    (at your option) any later version.
 
14
#
 
15
#    This program is distributed in the hope that it will be useful,
 
16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
#    GNU General Public License (in file COPYING) for more details.
 
19
#
 
20
#    You should have received a copy of the GNU General Public License
 
21
#    along with this program; if not, write to the Free Software
 
22
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
23
#
 
24
################################################################################
 
25
#                                  CHANGELOG                                   
 
26
#
 
27
#  v0.01 First functional version of Software Report Module                    
 
28
#  v0.02 Better formatting of number of installs, name of software in question
 
29
#        printed on the reports.
 
30
#
 
31
#  v0.03 Ability to sort results added.
 
32
#  v0.1  Configurable number of results per search page.
 
33
#  v0.11 Results pages have link to return to the modules's main menu. Functions
 
34
#        commented.
 
35
#
 
36
#  v0.2  Code cleanups.  Rewrote and renamed the function that was used to 
 
37
#        obtain the number of installs.  Some of the code was in the main
 
38
#        menu portion of the module.  It worked but was ugly.  This rewrite
 
39
#        simplified both the main menu and the function in question.
 
40
#
 
41
#  v0.3  Module will now report a software package if it has been installed
 
42
#        through a bundle.  It will also report how many from a bundle and
 
43
#        indicate which machines having the package are installed in that
 
44
#        bundle.  Included code from irm.inc cleaned up and even more 
 
45
#        heavily altered to make the bundle reporting work.  Also eliminated
 
46
#        the numInstalledShow function. softwareComputerListView now returns
 
47
#        the number of installs.
 
48
#
 
49
#        The software bundle changes break the code that limits the number 
 
50
#        of rows in the html table.  The code is still present but commented
 
51
#        out until I can figure out how to fix it.
 
52
#
 
53
#  v0.4  Ability to select number of results per HTML page re-enabled. Added
 
54
#        newlines to end of strings that generate HTML for HTML source
 
55
#        readability. 
 
56
#
 
57
#  v0.41 Computer ID correctly displayed in reports.  Fix contributed by
 
58
#        Stephen J. Lawrence Jr. <slawrence@ucdavis.edu>
 
59
#
 
60
#  v0.5  Made compatible with IRM 1.5.x. Will no longer work with 1.4.x and
 
61
#        before.
 
62
#
 
63
#  v0.51 Missed a bug in autogenerated computers-info.php URLs. Fixed.
 
64
################################################################################
 
65
#  NOTE
 
66
#
 
67
#  The format of the report is the same as Computers list view and is        
 
68
#  controlled by the same preferences.            
 
69
################################################################################
 
70
 
 
71
require_once '../../include/irm.inc';
 
72
require_once 'include/reports.inc.php';
 
73
require_once 'lib/Config.php';
 
74
 
 
75
AuthCheck("normal");
 
76
 
 
77
# softwareComputerListView function actually generates the results
 
78
# table when called with the appropriate argument.  This is a modified
 
79
# version of the ComputerListView function from irm.inc. It requires
 
80
# a software ID, sort criteria (one of computers table column name),
 
81
# and the number of results per page of HTML.  It generates on screen
 
82
# tables and returns the number of installs of the software in question.
 
83
 
 
84
function softwareComputerListView($sID, $sort, $numresults) 
 
85
{
 
86
 
 
87
  global $IRMName, $field, $goto, $contains, $style, $USERPREFIX;
 
88
  
 
89
  $USERPREFIX=Config::AbsLoc('users');
 
90
 
 
91
  $DB = Config::Database();
 
92
  $uname = $DB->getTextValue($IRMName);
 
93
                        
 
94
  $query = "SELECT * FROM prefs WHERE (user = $uname)";
 
95
                                
 
96
  $result = $DB->getRow($query);
 
97
  
 
98
  $stype = Checked($result['type']);
 
99
  $sos = Checked($result['os']);
 
100
  $sosver = Checked($result['osver']);
 
101
  $sprocessor = Checked($result['processor']);
 
102
  $sprocessor_speed = Checked($result['processor_speed']);
 
103
  $slocation = Checked($result['location']);
 
104
  $sserial = Checked($result['serial']);
 
105
  $sotherserial = Checked($result['otherserial']);
 
106
  $sramtype = Checked($result['ramtype']);
 
107
  $sram = Checked($result['ram']);
 
108
  $snetwork = Checked($result['network']);
 
109
  $sip = Checked($result['ip']);
 
110
  $smac = Checked($result['mac']);
 
111
  $shdspace = Checked($result['hdspace']);
 
112
  $scontact = Checked($result['contact']);
 
113
  $scontact_num = Checked($result['contact_num']);
 
114
  $scomments = Checked($result['comments']);
 
115
  $sdate_mod = Checked($result['date_mod']);
 
116
 
 
117
  PRINT "<table>";
 
118
  PRINT "<tr>\n";
 
119
 
 
120
  PRINT "<th>"._("Name")."</th>";
 
121
 
 
122
  $numChecked = 1;
 
123
   
 
124
  if ($stype == "checked") 
 
125
  {
 
126
    PRINT "<th>"._("Type")."</th>";
 
127
    $numChecked++;  
 
128
  }
 
129
  if ($sos == "checked") 
 
130
  {
 
131
    PRINT "<th>"._("OS")."</th>";
 
132
    $numChecked++;  
 
133
  }
 
134
  if ($sosver == "checked") 
 
135
  {
 
136
    PRINT "<th>"._("OS Version")."</th>";
 
137
    $numChecked++;  
 
138
  }
 
139
  if ($sprocessor == "checked") 
 
140
  {
 
141
    PRINT "<th>"._("Processor")."</th>";
 
142
    $numChecked++;  
 
143
  }
 
144
  if ($sprocessor_speed == "checked") 
 
145
  {
 
146
    PRINT "<th>"._("Proc. Speed")."</th>";
 
147
    $numChecked++;  
 
148
  }
 
149
  if ($slocation == "checked") 
 
150
  {
 
151
    PRINT "<th>"._("Location")."</th>";
 
152
    $numChecked++;  
 
153
  }
 
154
  if ($sserial == "checked") 
 
155
  {
 
156
    PRINT "<th>"._("Serial Number")."</th>";
 
157
    $numChecked++;  
 
158
  }
 
159
  if ($sotherserial == "checked") 
 
160
  {
 
161
    PRINT "<th>"._("Other Serial Number")."</th>";
 
162
    $numChecked++;  
 
163
  }
 
164
  if ($sramtype == "checked") 
 
165
  {
 
166
    PRINT "<th>"._("RAM Type")."</th>";
 
167
    $numChecked++;  
 
168
  }
 
169
  if ($sram == "checked") 
 
170
  {
 
171
    PRINT "<th>"._("RAM Amount (in MB)")."</th>";
 
172
    $numChecked++;  
 
173
  }
 
174
  if ($snetwork == "checked") 
 
175
  {
 
176
    PRINT "<th>"._("Network")."</th>";
 
177
    $numChecked++;  
 
178
  }
 
179
  if ($sip == "checked")
 
180
  {
 
181
    PRINT "<th>"._("IP")."</th>";
 
182
    $numChecked++;  
 
183
  }
 
184
  if ($smac == "checked")
 
185
  {
 
186
    PRINT "<th>"._("Net/MAC Addr")."</th>";
 
187
    $numChecked++;  
 
188
  }
 
189
  if ($shdspace == "checked") 
 
190
  {
 
191
    PRINT "<th>"._("HD Space")."</th>";
 
192
    $numChecked++;  
 
193
  }
 
194
  if ($scontact == "checked") 
 
195
  {
 
196
    PRINT "<th>"._("Contact Person")."</th>";
 
197
    $numChecked++;  
 
198
  }
 
199
  if ($scontact_num == "checked") 
 
200
  {
 
201
    PRINT "<th>"._("Contact Number")."</th>";
 
202
    $numChecked++;  
 
203
  }
 
204
  if ($scomments == "checked") 
 
205
  {
 
206
    PRINT "<th>"._("Comments")."</th>";
 
207
    $numChecked++;  
 
208
  }
 
209
  if ($sdate_mod == "checked") 
 
210
  {
 
211
    PRINT "<th>"._("Date Modified")."</th>";
 
212
    $numChecked++;  
 
213
  }
 
214
   
 
215
  PRINT "</TR>\n";
 
216
 
 
217
 
 
218
  $bundle_query = "SELECT bID from software_bundles where sID=$sID";
 
219
  $bundles = $DB->getAll($bundle_query);
 
220
  $numbundles = count($bundles);
 
221
  $package[0] = $sID; 
 
222
 
 
223
  $i = 1;
 
224
  foreach ($bundles as $result)
 
225
  {
 
226
   $package[$i] = $result["bID"];
 
227
   $i++;
 
228
  }
 
229
 
 
230
  $where_clause = "inst_software.sID=";
 
231
  
 
232
  $i = 0;
 
233
  
 
234
  foreach($package as $v)
 
235
  {
 
236
   if ($i == 0)
 
237
   $where_clause = "$where_clause"."$v";
 
238
   if ($i > 0)
 
239
   $where_clause = "$where_clause"." OR inst_software.sID=$v";
 
240
   $i++;
 
241
  }
 
242
 
 
243
 $packagename = softwareName($v);
 
244
 $softquery = "SELECT * FROM computers LEFT JOIN inst_software ON computers.ID=inst_software.cID WHERE
 
245
        $where_clause ORDER by sID,$sort";  
 
246
 
 
247
 $data = $DB->getAll($softquery);
 
248
 $numRows = count($data);
 
249
           
 
250
 # Chop off any records we want to skip
 
251
         
 
252
 $data = array_slice($data, $goto);
 
253
 if (count($data) > $numresults)
 
254
 {
 
255
  $nextpage = true;
 
256
  $data = array_slice($data, 0, $numresults);
 
257
 }
 
258
  else
 
259
 {
 
260
  $nextpage = false;
 
261
 }
 
262
                                
 
263
 
 
264
 foreach ($data as $result)
 
265
 {
 
266
        
 
267
  $ID = $result["cID"];
 
268
  $soft_id = $result["sID"];
 
269
  $name = $result["name"];
 
270
  $type = $result["type"];
 
271
  $os = $result["os"];
 
272
  $osver = $result["osver"];
 
273
  $processor = $result["processor"];
 
274
  $processor_speed = $result["processor_speed"];
 
275
  $location = $result["location"];
 
276
  $serial = $result["serial"];
 
277
  $otherserial = $result["otherserial"];
 
278
  $ramtype = $result["ramtype"];
 
279
  $ram = $result["ram"];
 
280
  $network = $result["network"];
 
281
  $ip = $result["ip"];
 
282
  $mac = $result["mac"];
 
283
  $hdspace = $result["hdspace"];
 
284
  $comments = $result["comments"];
 
285
  $date_mod = $result["date_mod"];
 
286
  $contact = $result["contact"];
 
287
  $contact_num = $result["contact_num"]; 
 
288
  $comments = $comments;
 
289
  
 
290
  if($previous_soft != $soft_id)
 
291
  {
 
292
   $query = "SELECT name FROM computers LEFT JOIN inst_software ON computers.ID=inst_software.cID WHERE inst_software.sID=$soft_id";
 
293
   $sth4 = $DB->getAll($query);
 
294
   $soft_num = count($sth4);
 
295
   $soft_name = softwareName($soft_id);
 
296
   print '<tr class="softwareupdate">';
 
297
   PRINT "<TD align=\"center\" COLSPAN=\"$numChecked\"><b>$soft_name - $soft_num</b></TD>";
 
298
   PRINT "</TR>\n";
 
299
  }
 
300
 
 
301
  PRINT '<tr class="softwaredetail">';
 
302
  PRINT "<TD><A HREF=\"$USERPREFIX/computers-info.php?ID=$ID\">$name($ID)</A></TD>\n";
 
303
 
 
304
  if ($stype == "checked")
 
305
  {
 
306
   PRINT "<TD>$type</TD>";
 
307
  }
 
308
  if ($sos == "checked")
 
309
  {
 
310
   PRINT "<TD>$os</TD>";
 
311
  }
 
312
  if ($sosver == "checked")
 
313
  {
 
314
   PRINT "<TD>$osver</TD>";
 
315
  }
 
316
  if ($sprocessor == "checked") 
 
317
  {
 
318
   PRINT "<TD>$processor</TD>";
 
319
  }
 
320
  if ($sprocessor_speed == "checked")
 
321
  {
 
322
   PRINT "<TD>$processor_speed</TD>";
 
323
  }
 
324
  if ($slocation == "checked") 
 
325
  {
 
326
   PRINT "<TD>$location</TD>";
 
327
  }
 
328
  if ($sserial == "checked") 
 
329
  {
 
330
   PRINT "<TD>$serial</TD>";
 
331
  }
 
332
  if ($sotherserial == "checked")
 
333
  {
 
334
   PRINT "<TD>$otherserial</TD>";
 
335
  }
 
336
  if ($sramtype == "checked") 
 
337
  {
 
338
   PRINT "<TD>$ramtype</TD>";
 
339
  }
 
340
  if ($sram == "checked") 
 
341
  {
 
342
   PRINT "<TD>$ram</TD>";
 
343
  }
 
344
  if ($snetwork == "checked") 
 
345
  {
 
346
   PRINT "<TD>$network</TD>";
 
347
  }
 
348
  if ($sip == "checked") 
 
349
  {
 
350
   PRINT "<TD>$ip</TD>";
 
351
  }
 
352
  if ($smac == "checked")
 
353
  { 
 
354
   PRINT "<TD>$mac</TD>";
 
355
  }
 
356
  if ($shdspace == "checked")
 
357
  {
 
358
   PRINT "<TD>$hdspace</TD>";
 
359
  }
 
360
  if ($scontact == "checked") 
 
361
  {
 
362
   PRINT "<TD>$contact</TD>";
 
363
  }
 
364
  if ($scontact_num == "checked") 
 
365
  {
 
366
   PRINT "<TD>$contact_num</TD>";
 
367
  }
 
368
  if ($scomments == "checked") 
 
369
  {
 
370
   PRINT "<TD>$comments</TD>";
 
371
  }
 
372
  if ($sdate_mod == "checked") 
 
373
  {
 
374
   PRINT "<TD>$date_mod</TD>";
 
375
  }
 
376
    
 
377
   PRINT "</TR>\n";
 
378
 
 
379
 
 
380
  $previous_soft = $soft_id;
 
381
   
 
382
}
 
383
  
 
384
  $backgoto = $goto - $numresults;
 
385
  $forgoto = $goto + $numresults;
 
386
  PRINT "</TABLE>\n";
 
387
  PRINT "<TABLE>";
 
388
  PRINT "<TR>";
 
389
  print "<TD>\n";
 
390
    
 
391
  if ($backgoto > -1)
 
392
  {
 
393
   PRINT "<form><input type=hidden name=goto value=$backgoto>
 
394
   <input type=hidden name=Show value=\"yes\">
 
395
   <input type=hidden name=sID value=$sID>
 
396
   <input type=hidden name=sort value=$sort>
 
397
   <input type=hidden name=numresults value=$numresults>
 
398
   <input type=submit value=\"".sprintf(_("Previous %s"), $numresults)."\"></form>\n";
 
399
  }
 
400
 
 
401
  PRINT "</TD>\n";
 
402
  print "<TD>\n";
 
403
 
 
404
  if ($forgoto < $numRows)
 
405
  {  
 
406
   PRINT "<form><input type=hidden name=goto value=$forgoto>
 
407
   <input type=hidden name=Show value=\"yes\">
 
408
   <input type=hidden name=sID value=$sID>
 
409
   <input type=hidden name=sort value=$sort>
 
410
   <input type=hidden name=numresults value=$numresults>
 
411
   <input type=submit value=\"".sprintf(_("Next %s"), $numresults)."\"></form>\n";
 
412
   $nextpage = 1;
 
413
  }
 
414
 
 
415
   PRINT "</TD>\n";
 
416
   PRINT "</TR>\n";
 
417
   PRINT "</TABLE>\n";
 
418
   return($numRows); 
 
419
}
 
420
 
 
421
 
 
422
# softwareName returns the name of an installed software package when 
 
423
# passed a numeric software ID.
 
424
 
 
425
function softwareName($softID)
 
426
{
 
427
 $DB = Config::Database();
 
428
 $query = "SELECT name FROM software WHERE ID = $softID";
 
429
 $sth = $DB->getRow($query);
 
430
 $software = $sth["name"];
 
431
 return ($software);
 
432
 
433
 
 
434
# The following code generate the main menu and results tables.
 
435
 
 
436
$USERPREFIX=Config::AbsLoc('users/reports');
 
437
 
 
438
if ($Show == "yes")
 
439
 
440
 
 
441
 
 
442
 commonHeader(_("Software Installation Report"));
 
443
 $software_name = softwareName($sID); 
 
444
 
 
445
 PRINT "<table>";
 
446
 PRINT '<tr class="softwareheader">';
 
447
 PRINT "<th colspan=2>\n";
 
448
 printf(_("Machines that have %s installed, sorted by %s"), "<i>$software_name</i>", "<i>$sort</i>");
 
449
 PRINT "\n</th>";
 
450
 PRINT "</TR>\n";
 
451
        
 
452
 $numinstalled=softwareComputerListView($sID,$sort, $numresults);
 
453
 
 
454
 PRINT "<tr>";
 
455
 PRINT "<td><b>"._("Number of Installs:")."</td>";
 
456
 PRINT "<td>$numinstalled</b></td>";
 
457
 PRINT "</tr>";
 
458
 PRINT "</TABLE>\n";
 
459
 
 
460
 printf('<a href="%s">%s</a>', Config::AbsLoc("users/reports/software.php"), _("Create a new Software Report"));
 
461
 
 
462
 commonFooter();
 
463
}
 
464
else
 
465
{
 
466
        commonHeader(_("Software Install Report"));
 
467
        
 
468
        __("Welcome to the Software Install Report! This will tell which machines have a particular software package installed.");
 
469
        PRINT "<table>";
 
470
        PRINT "<tr>";
 
471
        PRINT "<th>\n" . _("Select A Software Package") . "\n</th>";
 
472
        PRINT "</tr>\n";
 
473
        
 
474
        PRINT '<tr class="softwaredetail">';
 
475
        PRINT "<td>";
 
476
 
 
477
        PRINT "<form action=\"".Config::AbsLoc('users/reports/software.php')."\">";
 
478
      
 
479
        SoftwareDropdown( "dropdown_software");
 
480
        PRINT "</select>\n";
 
481
 
 
482
        #TODO This should be picked up from the database ?
 
483
        $selbox = "<select name=sort size=1>
 
484
                <option value=\"name\">"._("Name")."</option>
 
485
                <option value=\"ID\">"._("IRM ID")."</option>
 
486
                <option value=\"location\">"._("Location")."</option>
 
487
                <option value=\"type\">"._("Type")."</option>
 
488
                <option value=\"os\">"._("Operating System")."</option>
 
489
                <option value=\"osver\">"._("Operating System Version")."</option>
 
490
                <option value=\"processor\">"._("Processor")."</option>
 
491
                <option value=\"processor_speed\">"._("Processor Speed")."</option>
 
492
                <option value=\"serial\">"._("Serial Number")."</option>
 
493
                <option value=\"otherserial\">"._("Other Number")."</option>
 
494
                <option value=\"ramtype\">"._("RAM Type")."</option>
 
495
                <option value=\"ram\">"._("RAM Amount")."</option>
 
496
                <option value=\"network\">"._("Network Card Type/Brand")."</option>
 
497
                <option value=\"ip\">"._("IP Address")."</option>
 
498
                <option value=\"mac\">"._("MAC/Network Address")."</option>
 
499
                <option value=\"hdspace\">"._("Hard Drive Capacity")."</option>
 
500
                <option value=\"comments\">"._("Comments")."</option>
 
501
                <option value=\"contact\">"._("Contact Person")."</option>
 
502
                <option value=\"contact_num\">"._("Contact Number")."</option>
 
503
                <option value=\"date_mod\">"._("Date Last Modified")."</option>
 
504
                </select>";
 
505
 
 
506
        printf(_("sorted by %s"), $selbox);
 
507
 
 
508
        printf(_("with %s results per page"), "<select name=numresults size=1>
 
509
                                <option value=\"15\">15</option>
 
510
                                <option value=\"25\">25</option>
 
511
                                <option value=\"35\">35</option>
 
512
                                <option value=\"50\">50</option>
 
513
                                <option value=\"100\">100</option>
 
514
                                </select>");
 
515
 
 
516
        PRINT "<input type=submit value=\""._("Show")."\"><input type=hidden name=Show value=yes>\n";
 
517
        PRINT "</form>\n";
 
518
        PRINT "</TD>\n";
 
519
        PRINT "</TR>\n";
 
520
        PRINT "</TABLE>\n";
 
521
        commonFooter();
 
522
}