/includes/ -> report_inc.php
1 <?php
2
3 // report_inc.php - support functions dealing with reports
4 // report_inc.php - author: Nico Stuurman <nicost@sf.net>
5 /***************************************************************************
6 * Copyright (c) 2003 by Nico Stuurman *
7 * ------------------------------------------------------------------------ *
8 * Part of phplabware, a web-driven groupware suite for research labs *
9 * This file contains classes and functions needed in reports.php. *
10 * *
11 * This program is free software; you can redistribute it and/or modify it *
12 * under the terms of the GNU General Public License as published by the *
13 * Free Software Foundation; either version 2 of the License, or (at your *
14 * option) any later version. *
15 \**************************************************************************/
16
17 ////
18 // !Formats record(s) into xml
19 function make_xml ($db,$data,$tableinfo) {
20 $xml.="<{$tableinfo->label} record>\n";
21 foreach ($data as $column) {
22 $xml.="<{$column['name']}>\n";
23 $xml.="{$column['text']}\n";
24 $xml.="</{$column['name']}>\n";
25 }
26 $xml.="</{$tableinfo->label} record>\n";
27 return $xml;
28 }
29
30 ////
31 // !Takes a template and data and generates a report
32 function make_report ($db,$template,$data,$tableinfo,$counter=false) {
33 foreach ($data as $column) {
34 if ($column['name']) {
35 // give a chance to replace with value only
36 $template=str_replace("%".$column['name'],$column['values'],$template);
37 if ($column['datatype']=='textlong') {
38 $textlarge=nl2br(htmlentities($column['values']));
39 $template=str_replace("$".$column['name'],$textlarge,$template);
40 }
41 // we'll need to squeeze in images and files too
42
43 elseif ($column['datatype']=='file' || $column['datatype']=='image') {
44 $files=get_files($db,$tableinfo->name,$column['recordid'],$column['columnid'],0,'big');
45 unset ($ftext);
46 for ($i=0;$i<sizeof($files);$i++) {
47 $ftext.=$files[$i]['link'];
48 }
49 $template=str_replace("$".$column['name'],$ftext,$template);
50 }
51 elseif ($column['link'])
52 $template=str_replace("$".$column['name'],$column['link'],$template);
53 else
54 $template=str_replace("$".$column['name'],$column['text'],$template);
55 }
56 }
57 // Replace $counter with current sequence number
58 if ($counter)
59 $template=str_replace('$counter',$counter,$template);
60 return $template;
61 }