PhpLabware PHP Cross Reference Learning Management Systems

Source: /editreports.php - 179 lines - 6984 bytes - Summary - Text - Print

Description: Design and change reportsauthor: Nico Stuurman <nicost@soureforge.net>

   1  <?php
   2  
   3  // editreports.php - Design and change reports
   4  // editreports.php - author: Nico Stuurman <nicost@soureforge.net>
   5  
   6    /***************************************************************************
   7    * This script edits templates for reports                                  *
   8    *                                                                          *
   9    * Copyright (c) 2006 by Nico Stuurman                                      *
  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  require ('./include.php');
  19  require ('./includes/db_inc.php');
  20  require ('./includes/general_inc.php');
  21  require ('./includes/tablemanage_inc.php');
  22  include_once  ('./includes/defines_inc.php');
  23  
  24  //$editreport=$_GET['editreport'];
  25  //$editreport=true;
  26  $get_vars='tablename,editreport,table_id';
  27  $post_vars='table_id,tablename';
  28  globalize_vars($post_vars, $_POST);
  29  globalize_vars($get_vars, $_GET);
  30  if (!$editreport)
  31     $editreport=$tablename;
  32  if (!$tablename)
  33     $tablename=$editreport;
  34  
  35  // this needs to be done before headers are sent in printheader
  36  while((list($key, $val) = each($_POST))) {
  37     if (substr($key, 0, 9) == 'expreport') { 
  38        $modarray = explode('_', $key);
  39        export_report($db,$modarray[1]);
  40        exit;
  41     }
  42  }
  43  reset($_POST);
  44  
  45  printheader($httptitle,false,$jsfiles);
  46  
  47  while((list($key, $val) = each($_POST))) {
  48    if (substr($key, 0, 9) == "modreport") {  
  49        $modarray = explode("_", $key);
  50        $tplmessage=mod_report($db,$modarray[1]);
  51        break;
  52     } elseif (substr($key, 0, 9) == "delreport") { 
  53        $modarray = explode("_", $key);
  54        rm_report($db,$modarray[1]);
  55        break;
  56     } elseif (substr($key, 0, 10) == "testreport") { 
  57        $modarray = explode("_", $key);
  58        $tplmessage=test_report($db,$modarray[1],$editreport);
  59        break;
  60     } elseif ($key=="addreport") {
  61        $tplmessage=add_report($db);
  62        break;
  63     }
  64  }
  65  
  66  navbar($USER['permissions']);
  67  // when no tablename is given, list all tables this user can write to 
  68  if (!$tablename) {
  69     echo "<br><br>\n";
  70     echo "<form name='views' method='post' action='$PHP_SELF'>\n";
  71     echo "<table width='100%' border='0'>\n";
  72     echo "<tr>\n";
  73     echo "<td align='center'><h3>Edit report templates for table: </h3>";
  74  
  75     // make dropdown with accessible tablenames, select the current tablename
  76     if ($USER['permissions'] & $SUPER) {
  77        $r=$db->Execute ("SELECT label,tablename FROM tableoftables ORDER by sortkey ");
  78     } else {
  79        $r=$db->Execute("SELECT tableoftables.label,tableoftables.tablename FROM tableoftables LEFT JOIN groupxtable_display ON tableoftables.id=groupxtable_display.tableid WHERE groupxtable_display.groupid IN ({$USER['group_list']}) ORDER BY tableoftables.sortkey");
  80     }                                                                            
  81     echo $r->GetMenu2('tablename',$tablename,true,false,0,'OnChange="document.views.submit()"');
  82     echo "</td></tr></table></form>\n";
  83     printfooter();
  84     exit;
  85  }
  86  
  87  echo $tplmessage;
  88  
  89  $r=$db->Execute("SELECT id,table_desc_name,label FROM tableoftables WHERE tablename='$tablename'");
  90  $tableid=$r->fields['id'];
  91  $tablelabel=$r->fields['label'];
  92  $tabledesc=$r->fields[1];
  93  echo "<h3 align='center'>$string</h3>";
  94  echo "<h3 align='center'>Edit report templates for table <i>$tablelabel</i></h3><br>";
  95  
  96  echo "<form method='post' name='reportform' id='repedit' enctype='multipart/form-data' ";
  97  $dbstring=$PHP_SELF;
  98  echo "action='$dbstring?editreport=$editreport&".SID."'>\n"; 
  99  
 100  // Tableheader
 101  echo "<table align='center' border='0' cellpadding='2' cellspacing='0'>\n";
 102  echo "<tr>\n";
 103  echo "<th>Report Name</th>\n";
 104  echo "<th>Sortkey</th>\n";
 105  echo "<th>Template File Add/Change</th>\n";
 106  echo "<th>File present</th>";
 107  echo "<th>Action</th>\n";
 108  echo "</tr>\n";
 109  
 110  // New addition
 111  echo "<input type='hidden' name='tablename' value='$editreport'>\n";
 112  echo "<tr align='center' >\n";
 113  echo "<td><input type='text' name='addrep_label' value='' size='10'></td>\n";
 114  echo "<td><input type='text' name='addrep_sortkey' value='' size='5'></td>\n";
 115  echo "<td><input type='file' name='addrep_template'></td>\n";
 116  echo "<td>&nbsp;</td>\n";
 117  echo "<td align='center'><input type='submit' name='addreport' value='Add'></td></tr>\n\n";
 118  
 119  // Loop through existing templates
 120  $rp=$db->Execute("SELECT id,label,sortkey,filesize FROM reports WHERE tableid='$tableid' ORDER BY sortkey");
 121  $rownr=0;
 122  while ($rp && !$rp->EOF) {
 123     $id=$rp->fields["id"];
 124     echo "<input type='hidden' name='report_id[$rownr]' value='$id'>\n";
 125     if ($rownr % 2) 
 126       echo "<tr class='row_odd' align='center'>\n";    
 127     else 
 128        echo "<tr class='row_even' align='center'>\n";         
 129  
 130     echo "<td><input type='text' name='report_label[$rownr]' value='".$rp->fields["label"]."' size=10></td>\n";
 131     echo "<td><input type='text' name='report_sortkey[$rownr]' value='".$rp->fields["sortkey"]."'size=5></td>\n";
 132     echo "<td><input type='file' name='report_template[$rownr]'</td>\n";
 133     if (is_readable($system_settings["templatedir"]."/$id.tpl"))
 134        echo "<td>Yes</td>\n";
 135     else
 136        echo "<td>No</td>\n";
 137     $modstring = "<input type='submit' name='modreport"."_$rownr' value='Modify'>\n";
 138     $exportstring = "<input type='submit' name='expreport"."_$rownr' value='Export'>\n";
 139     $teststring = "<input type='submit' name='testreport"."_$rownr' value='Test'>\n";
 140     $delstring = "<input type='submit' name='delreport"."_$rownr' value='Remove' ";
 141     $delstring .= "Onclick=\"if(confirm('Are you absolutely sure that the report ".$rp->fields["label"] ." should be removed? (No undo possible!)')){return true;}return false;\">";  
 142     echo "<td>$modstring &nbsp;\n$delstring &nbsp;\n$exportstring &nbsp;\n$teststring</td>\n";
 143     echo "</tr>\n";
 144     $rp->MoveNext();
 145     $rownr++;
 146  }
 147  echo "</table>\n";
 148  
 149  echo "<br>\n";
 150  // list all available fields and field labels :
 151  echo "<table width=75% align='center' border='0' cellpadding='2' cellspacing='0'>\n";
 152  echo "<tr><td> </td><td colspan=2 align='right' >Column names available:</td></tr>\n";
 153  echo "<tr><td> </td><th>Column Name</th><th>Column Label</th></tr>\n";
 154  $r=$db->Execute("SELECT columnname,label FROM {$tabledesc}");
 155  // show the help text in the left most column
 156  $rowspan=$r->RecordCount() + 1;
 157  echo "<tr><td rowspan=$rowspan valign='top'>";
 158  include  'documents/help_reports.php';
 159  echo "</td>\n";
 160  $first=true;
 161  while ($r && !$r->EOF) {
 162     if ($first) {
 163        echo "<td>{$r->fields[0]}</td><td>{$r->fields[1]}</td></tr>\n";
 164        $first=false;
 165     } else {
 166        echo "<tr><td>{$r->fields[0]}</td><td>{$r->fields[1]}</td></tr>\n";
 167     }
 168  
 169     $r->MoveNext();
 170  }
 171  echo "</table\n";
 172  
 173  
 174  
 175  
 176  printfooter();
 177  exit;
 178  
 179  ?>

title

Description

title

Description

title

Description

title

title

Body