PhpLabWare version 0.3 
/ -> report.php

1  <?php
2    
3  // report.php - Outputs one or more reocrds based on specified format
4  // report.php - author: Nico Stuurman <nicost@soureforge.net>
5    /***************************************************************************
6    * Copyright (c) 2003 by Nico Stuurman<nicost@sf.net> *
7    * ------------------------------------------------------------------------ *
8    * This program is free software; you can redistribute it and/or modify it *
9    * under the terms of the GNU General Public License as published by the *
10    * Free Software Foundation; either version 2 of the License, or (at your *
11    * option) any later version. *
12    \**************************************************************************/
13 
14  // Needs getvars:tablename,reportid,recordid
15  // optional getvar: tableview
16 
17  /// main include thingies
18  require("include.php");
19  require("includes/db_inc.php");
20  require("includes/general_inc.php");
21  require("includes/report_inc.php");
22 
23  $tableinfo=new tableinfo($db);
24 
25  if (!$tableinfo->id) {
26     printheader($httptitle);
27     navbar($USER["permissions"]);
28     echo "<h3 align='center'> Table: <i>$HTTP_GET_VARS[tablename]</i> does not exist.</h3>";
29     printfooter();
30     exit();
31  }
32 
33  $reportid=(int)$HTTP_GET_VARS['reportid'];
34  $recordid=(int)$HTTP_GET_VARS['recordid'];
35  $tableview=$HTTP_GET_VARS['tableview'];
36   
37  if (!($reportid && ($recordid || $tableview)) ) {
38     printheader($httptitle);
39     navbar($USER["permissions"]);
40     echo "<h3 align='center'>Not enough information to generate the report.</h3>";
41     printfooter();
42     exit();
43  }
44 
45  if (!may_read($db,$tableinfo,$recordid,$USER)) {
46     printheader($httptitle);
47     navbar($USER["permissions"]);
48     echo "<h3 align='center'>This information is not intended to be seen by you.</h3>";
49     printfooter();
50     exit();
51  }
52     
53  if ($reportid>0) {
54     $tp=@fopen($system_settings["templatedir"]."/$reportid.tpl","r");
55     if ($tp) {
56        while (!feof($tp)) {
57           $line=fgets($tp);
58           if (stristr($line,"<!--fields-->")) {
59              $header=$template;
60              unset($template);
61           }
62           elseif (stristr($line,"<!--/fields-->")) {
63              $footerset=true;
64           }
65           elseif ($footerset)
66              $footer.=$line;
67           else
68              $template.=$line;
69        }
70        fclose($tp);
71     }
72   
73     if (!$template) {
74        printheader($httptitle);
75        navbar($USER["permissions"]);
76        echo "<h3 align='center'>Template file was not found!</h3>";
77        printfooter();
78        exit();
79     }
80  }
81 
82  // displays multiple records in a report (last search statement)
83  if ($HTTP_GET_VARS["tableview"]) {
84     // figure out the current query:
85     $queryname=$tableinfo->short.'_query';
86     if (session_is_registered ($queryname) && isset($HTTP_SESSION_VARS[$queryname])) {
87        // get a list with all records we may see, create temp table tempb
88        $listb=may_read_SQL($db,$tableinfo,$USER,"tempb");
89 
90        // read all fields in from the description file
91        $fields_table=comma_array_SQL($db,$tableinfo->desname,columnname,"");
92        $fields_table="id,".$fields_table;
93 
94        // prepare the search statement
95        $query=make_search_SQL($db,$tableinfo,$fields_table,$USER,$search,$sortstring,$listb["sql"]);
96        //$db->debug=true;
97        $r=$db->Execute($query);
98        //$db->debug=false;
99        if ($reportid>0)
100           echo $header;
101        else //xml
102           echo "<phplabware_base>\n";
103        $counter=1;
104        while ($r && !$r->EOF) {
105           $Allfields=getvalues($db,$tableinfo,$fields_table,"id",$r->fields["id"]);
106           if ($reportid>0)
107              echo make_report($db,$template,$Allfields,$tableinfo,$counter);
108           else
109              echo make_xml ($db,$Allfields,$tableinfo);
110           //echo $report;
111           $r->MoveNext();
112           $counter++;
113        }
114       if ($reportid>0)
115           echo $footer;
116        else
117           echo '</'."phplabware_base>\n>";
118     }
119  }
120  else { // just a single record
121     $fields=comma_array_SQL($db,$tableinfo->desname,"columnname");
122     $Allfields=getvalues($db,$tableinfo,$fields,"id",$recordid);
123 
124     $report=make_report($db,$template,$Allfields,$tableinfo);
125     echo $report;
126  }
127  ?>


Generated: Sun Oct 5 21:17:35 2003 SourceForge Logo Generated by PHPXref 0.2