/ -> tablemanage.php
1 <?php
2
3 // tablemanage.php - Design and change tables
4 // tablemanage.php - author: Ethan Garner, Nico Stuurman <nicost@soureforge.net>
5
6 /***************************************************************************
7 * This script tables in phplabware. *
8 * *
9 * Copyright (c) 2001 by Ethan Garner, 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 ('includes/defines_inc.php');
23
24 $editfield=$HTTP_GET_VARS["editfield"];
25 $editreport=$HTTP_GET_VARS["editreport"];
26 $post_vars="newtable_name,newtable_label,newtable_sortkey,newtable_plugincode,addtable,table_id,table_name,table_display,addcol_name,addcol_label,addcol_sort,addcol_dtable,addcol_drecord,addcol_required,addcol_modifiable,addcol_datatype";
27 globalize_vars($post_vars, $HTTP_POST_VARS);
28
29 // this needs to be done before headers are sent in printheader
30 while((list($key, $val) = each($HTTP_POST_VARS))) {
31 if (substr($key, 0, 9) == "expreport") {
32 $modarray = explode("_", $key);
33 export_report($db,$modarray[1]);
34 exit;
35 }
36 }
37 reset($HTTP_POST_VARS);
38
39 $permissions=$USER["permissions"];
40 if ($addcol_datatype=="table")
41 $jsfile="includes/js/tablemanage.js";
42 printheader($httptitle,false,$jsfile);
43
44 if (!($permissions & $SUPER)) {
45 navbar($USER["permissions"]);
46 echo "<h3 align='center'><b>Sorry, this page is not for you</B></h3>";
47 printfooter($db,$USER);
48 exit;
49 }
50
51 while((list($key, $val) = each($HTTP_POST_VARS))) {
52 if ($key == "addtable") {
53 add_table($db,$newtable_name,$newtable_label,$newtable_sortkey,$newtable_plugincode);
54 break;
55 }
56 elseif (substr($key, 0, 8) == "modtable") {
57 $modarray = explode("_", $key);
58 $id=$HTTP_POST_VARS["table_id"][$modarray[1]];
59 mod_table($db,$id,$modarray[1]);
60 break;
61 }
62 elseif (substr($key, 0, 8) == "deltable") {
63 $modarray = explode("_", $key);
64 $id=$HTTP_POST_VARS["table_id"][$modarray[1]];
65 $tablename=$HTTP_POST_VARS["table_name"][$modarray[1]];
66 del_table($db,$tablename,$id,$USER);
67 break;
68 }
69 elseif ($key=="table_column_select") {
70 add_associated_table($db,$table_name,$addcol_name,$HTTP_POST_VARS['table_select'],$HTTP_POST_VARS['table_column_select']);
71 break;
72 }
73 elseif ($key=="ass_to") {
74 add_associated_table($db,$table_name,$addcol_name,false,false);
75 break;
76 }
77 elseif ($key=="link_part_a") {
78 add_active_link($db,$table_name,$addcol_name,$HTTP_POST_VARS["link_part_a"],$HTTP_POST_VARS["link_part_b"]);
79 break;
80 }
81 elseif ($key == "addcolumn") {
82 $result=add_columnECG($db,$table_name,$addcol_name,$addcol_label,$addcol_datatype,$addcol_drecord,$addcol_dtable,$addcol_required,$addcol_modifiable,$addcol_sort);
83 if ($addcol_datatype=="table" && $result) {
84 navbar($USER["permissions"]);
85 show_table_column_page($db,$table_name,$addcol_name,$addcol_label);
86 printfooter();
87 exit();
88 }
89 break;
90 }
91 elseif (substr($key, 0, 9) == "modcolumn") {
92 $modarray = explode("_", $key);
93 mod_columnECG($db,$sort,$modarray[1]);
94 break;
95 }
96 elseif (substr($key, 0, 9) == "delcolumn") {
97 $modarray = explode("_", $key);
98 $tablename=$HTTP_POST_VARS["table_name"];
99 $id=$HTTP_POST_VARS["column_id"][$modarray[1]];
100 $colname=$HTTP_POST_VARS["column_name"][$modarray[1]];
101 $datatype=$HTTP_POST_VARS["column_datatype"][$modarray[1]];
102 rm_columnecg($db,$tablename,$id,$colname,$datatype);
103 break;
104 }
105 elseif (substr($key, 0, 11) == "alinkcolumn") {
106 $modarray = explode("_", $key);
107 $tablename=$HTTP_POST_VARS["table_name"];
108 $id=$HTTP_POST_VARS["column_id"][$modarray[1]];
109 $colname=$HTTP_POST_VARS["column_name"][$modarray[1]];
110 $collabel=$HTTP_POST_VARS["column_label"][$modarray[1]];
111 $datatype=$HTTP_POST_VARS["column_datatype"][$modarray[1]];
112 $table_desc=get_cell($db,"tableoftables","table_desc_name","tablename",$tablename);
113 $link_a=get_cell($db,$table_desc,"link_first","id",$id);
114 $link_b=get_cell($db,$table_desc,"link_last","id",$id);
115 navbar($USER["permissions"]);
116 show_active_link_page($db,$tablename,$colname,$collabel,$link_a,$link_b);
117 printfooter();
118 exit();
119 break;
120 }
121 elseif (substr($key, 0, 9) == "modreport") {
122 $modarray = explode("_", $key);
123 $tplmessage=mod_report($db,$modarray[1]);
124 break;
125 }
126 elseif (substr($key, 0, 9) == "delreport") {
127 $modarray = explode("_", $key);
128 rm_report($db,$modarray[1]);
129 break;
130 }
131 elseif (substr($key, 0, 10) == "testreport") {
132 $modarray = explode("_", $key);
133 $tplmessage=test_report($db,$modarray[1],$editreport);
134 break;
135 }
136 elseif ($key=="addreport") {
137 $tplmessage=add_report($db);
138 break;
139 }
140 }
141
142 if ($editfield) {
143 $noshow=array('id','access','magic','lastmoddate','lastmodby','gr','gw','er','ew');
144 $nodel=array('title','date','ownerid','lastmodby','lastmoddate');
145 $nomodifiable=array('ownerid','date','lastmodby','lastmoddate');
146 navbar($USER["permissions"]);
147
148 $r=$db->Execute("SELECT id,table_desc_name,label FROM tableoftables WHERE tablename='$editfield'");
149 $id=$r->fields["id"];
150 $currdesc=$r->fields['table_desc_name'];
151 $tablelabel=$r->fields['label'];
152 echo "<h3 align='center'>$string</h3>";
153 echo "<h3 align='center'>Edit columns of table <i>$tablelabel</i></h3><br>";
154
155 echo "<form method='post' name='tableform' id='coledit' enctype='multipart/form-data' ";
156 $dbstring=$PHP_SELF;echo "action='$dbstring?editfield=$editfield&".SID."'>\n";
157 echo "<table align='center' border='0' cellpadding='2' cellspacing='0'>\n";
158 echo "<tr>\n";
159 echo '<th>(SQL) Column Name</th>';
160 echo '<th>Label</th>';
161 echo '<th>Sortkey</th>';
162 echo '<th>Table display</th>';
163 echo "<th>Record display</th>\n";
164 echo "<th>Required </th>\n";
165 echo "<th>Modifiable </th>\n";
166 echo "<th>Datatype</th>\n";
167 echo "<th>Ass. Table/Column</th>\n";
168 echo "<th>Active Link</th>\n";
169 echo "<th>Action</th>\n";
170 echo "</tr>\n";
171 echo "<input type='hidden' name='table_name' value='$editfield'>\n";
172 echo "<tr align='center' ><td><input type='text' name='addcol_name' value='' size='10'></td>\n";
173 echo "<td><input type='text' name='addcol_label' value='' size='10'></td>\n";
174 echo "<td><input type='text' name='addcol_sort' value='' size='5'></td>\n";
175 echo "<td><input type='radio' name='addcol_dtable' checked value='Y'>yes<input type='radio' name='addcol_dtable' value='N'>no</td>\n";
176 echo "<td><input type='radio' name='addcol_drecord' checked value='Y'>yes<input type='radio' name='addcol_drecord' value='N'>no</td>\n";
177 echo "<td><input type='radio' name='addcol_required' value='Y'>yes<input type='radio' name='addcol_required' checked value='N'>no</td>\n";
178 echo "<td><input type='radio' name='addcol_modifiable' checked value='Y'>yes<input type='radio' name='addcol_modifiable' value='N'>no</td>\n";
179 echo "<td><select name='addcol_datatype'>\n";
180 echo "<option value='text'>text</option>\n";
181 echo "<option value='textlong'>textlong</option>\n";
182 echo "<option value='int'>int</option>\n";
183 echo "<option value='float'>float</option>\n";
184 echo "<option value='sequence'>sequence</option>\n";
185 echo "<option value='date'>date</option>\n";
186 echo "<option value='table'>table</option>\n";
187 echo "<option value='pulldown'>pulldown</option>\n";
188 echo "<option value='mpulldown'>mpulldown</option>\n";
189 echo "<option value='link'>weblink</option>\n";
190 echo "<option value='file'>file</option>\n";
191 if ($system_settings["convert"])
192 echo "<option value='image'>image</option>\n";
193 echo "</select></td>\n";
194 echo "<td> </td>\n";
195 echo "<td> </td>\n";
196 echo "<td align='center'><input type='submit' name='addcolumn' value='Add'></td></tr>\n\n";
197
198 $query = "SELECT id,sortkey,columnname,label,display_table,display_record,required,datatype,thumb_x_size,associated_table,associated_column,associated_local_key,link_first,modifiable FROM $currdesc order by sortkey,label";
199 $r=$db->Execute($query);
200 $rownr=0;
201 // print all entries
202 while (!($r->EOF) && $r) {
203 $label = $r->fields["label"];
204 $columnname = $r->fields["columnname"];
205 $id = $r->fields["id"];
206 $display_table = $r->fields["display_table"];
207 $display_record = $r->fields["display_record"];
208 $display_required= $r->fields["required"];
209 $datatype = $r->fields["datatype"];
210 $thumbsize=$r->fields["thumb_x_size"];
211 $modifiable = $r->fields["modifiable"];
212 $link_first = $r->fields["link_first"];
213 $sort = $r->fields["sortkey"];
214 unset ($ass_table);
215 unset($ass_column);
216 if ($r->fields["associated_table"]) {
217 $ass_table=get_cell($db,"tableoftables","tablename","id",$r->fields["associated_table"]);
218 $ass_desc_table=get_cell($db,"tableoftables","table_desc_name","id",$r->fields["associated_table"]);
219 $ass_column=get_cell($db,$ass_desc_table,"label","id",$r->fields["associated_column"]);
220 }
221 $show=1;
222 foreach($noshow as $donotshow) {
223 if ($columnname==$donotshow)
224 $show=0;
225 }
226 // print start of row of selected group
227 if ($show==1) {
228 echo "<input type='hidden' name='column_id[$rownr]' value='$id'>\n";
229 echo "<input type='hidden' name='column_datatype[$rownr]' value='$datatype'>\n";
230 if ($rownr % 2)
231 echo "<tr class='row_odd' align='center'>\n";
232 else
233 echo "<tr class='row_even' align='center'>\n";
234 echo "<input type='hidden' name='column_name[$rownr]' value='$columnname'>\n";echo "<td>$columnname</td>\n";
235 echo "<td><input type='text' name='column_label[$rownr]' value='$label' size='10'></td>\n";
236 echo "<td><input type='text' name='column_sort[$rownr]' value='$sort' size='5'></td>\n";
237 if($display_table=='Y') {
238 echo "<td><input type='radio' name='column_dtable[$rownr]' value='Y' CHECKED >yes";
239 echo "<input type='radio' name='column_dtable[$rownr]' value='N'>no</td>\n";
240 }
241 else {
242 echo "<td><input type='radio' name='column_dtable[$rownr]' value='Y'>yes";
243 echo" <input type='radio' name='column_dtable[$rownr]' value='N' CHECKED >no</td>";
244 }
245 if($display_record=='Y') {
246 echo "<td><input type='radio' name='column_drecord[$rownr]' value='Y' CHECKED>yes";
247 echo" <input type='radio' name='column_drecord[$rownr]' value='N'> no </td>\n";
248 }
249 else {
250 echo "<td><input type='radio' name='column_drecord[$rownr]' value='Y'>yes";
251 echo" <input type='radio' name='column_drecord[$rownr]' checked value='N'> no </td>\n";
252 }
253
254 if($display_required=='Y') {
255 echo "<td><input type='radio' name='column_required[$rownr]' value='Y' CHECKED>yes";
256 echo" <input type='radio' name='column_required[$rownr]' value='N'> no </td>\n";
257 }
258 else {
259 echo "<td><input type='radio' name='column_required[$rownr]' value='Y'>yes";
260 echo" <input type='radio' name='column_required[$rownr]' checked value='N'> no </td>\n";
261 }
262
263 if (in_array($columnname,$nomodifiable))
264 echo "<td>no</td>\n";
265 elseif($modifiable=='Y') {
266 echo "<td><input type='radio' name='column_modifiable[$rownr]' value='Y' CHECKED>yes";
267 echo" <input type='radio' name='column_modifiable[$rownr]' value='N'> no </td>\n";
268 }
269 else {
270 echo "<td><input type='radio' name='column_modifiable[$rownr]' value='Y'>yes";
271 echo" <input type='radio' name='column_modifiable[$rownr]' checked value='N'> no </td>\n";
272 }
273
274 echo "<input type='hidden' name='column_datatype[]' value='$label'>\n";
275 echo "<td>$datatype</td>\n";
276 if ($ass_table || $ass_column) {
277 echo "<td>";
278 if (! $r->fields['associated_local_key']) {
279 echo "<b>primary key</b><br>";
280 echo "$ass_table<br>$ass_column</td>\n";
281 }
282 else {
283 $ass_local_column=get_cell($db,$currdesc,'label','id',$r->fields['associated_local_key']);
284 echo "primary key: $ass_local_column<br>\n";
285 echo "$ass_column</td>\n";
286 }
287 }
288 else
289 echo "<td> </td>\n";
290 if ($link_first)
291 echo "<td>Y</td>\n";
292 else
293 echo "<td>N</td>\n";
294 $modstring = "<input type='submit' name='modcolumn"."_$rownr' value='Modify'>\n";
295 if ($datatype=="image") {
296 $alinkstring = "<input type='hidden' name='thumbsize"."_$rownr' value='$thumbsize'>\n";
297 $alinkstring.="<input type='submit' name='modcolumn"."_$rownr' value='Thumbnail size' Onclick='var temp=window.prompt(\"Please enter the maximum thumbnail size (in pixels):\",\"$thumbsize\");if (temp) {document.tableform.thumbsize"."_$rownr.value=temp} else {return false}; return true;' >\n";
298 }
299 else
300 $alinkstring = "<input type='submit' name='alinkcolumn"."_$rownr' value='Active Link'>\n";
301 $delstring = "<input type='submit' name='delcolumn"."_$rownr' value='Remove' ";
302 $delstring .= "Onclick=\"if(confirm('Are you absolutely sure that the column $label should be removed? (No undo possible!)')){return true;}return false;\">";
303 echo "<td align='center'>$modstring".$alinkstring;
304 $candel=1;
305 foreach($nodel as $checkme){
306 if ($columnname==$checkme){
307 $candel=0;
308 }
309 }
310 if ($candel==1)
311 echo "$delstring</td>\n";
312 echo "</tr>\n";
313 }
314 $r->MoveNext();
315 $rownr+=1;
316 }
317
318 echo "</table></form>\n";
319 printfooter($db,$USER);
320 exit;
321 }
322
323 ///// Reports
324 elseif ($editreport) {
325 navbar($USER["permissions"]);
326 echo $tplmessage;
327
328 $r=$db->Execute("SELECT id,table_desc_name,label FROM tableoftables WHERE tablename='$editreport'");
329 $tableid=$r->fields["id"];
330 $tablelabel=$r->fields["label"];
331 echo "<h3 align='center'>$string</h3>";
332 echo "<h3 align='center'>Edit report templates for table <i>$tablelabel</i></h3><br>";
333
334 echo "<form method='post' name='reportform' id='repedit' enctype='multipart/form-data' ";
335 $dbstring=$PHP_SELF;
336 echo "action='$dbstring?editreport=$editreport&".SID."'>\n";
337
338 // Tableheader
339 echo "<table align='center' border='0' cellpadding='2' cellspacing='0'>\n";
340 echo "<tr>\n";
341 echo "<th>Report Name</th>\n";
342 echo "<th>Sortkey</th>\n";
343 echo "<th>Template File Add/Change</th>\n";
344 echo "<th>File present</th>";
345 echo "<th>Action</th>\n";
346 echo "</tr>\n";
347
348 // New addition
349 echo "<input type='hidden' name='table_name' value='$editreport'>\n";
350 echo "<tr align='center' >\n";
351 echo "<td><input type='text' name='addrep_label' value='' size='10'></td>\n";
352 echo "<td><input type='text' name='addrep_sortkey' value='' size='5'></td>\n";
353 echo "<td><input type='file' name='addrep_template'</td>\n";
354 echo "<td> </td>\n";
355 echo "<td align='center'><input type='submit' name='addreport' value='Add'></td></tr>\n\n";
356
357 // Loop through existing templates
358 $rp=$db->Execute("SELECT id,label,sortkey,filesize FROM reports WHERE tableid='$tableid' ORDER BY sortkey");
359 $rownr=0;
360 while ($rp && !$rp->EOF) {
361 $id=$rp->fields["id"];
362 echo "<input type='hidden' name='report_id[$rownr]' value='$id'>\n";
363 if ($rownr % 2)
364 echo "<tr class='row_odd' align='center'>\n";
365 else
366 echo "<tr class='row_even' align='center'>\n";
367
368 echo "<td><input type='text' name='report_label[$rownr]' value='".$rp->fields["label"]."' size=10></td>\n";
369 echo "<td><input type='text' name='report_sortkey[$rownr]' value='".$rp->fields["sortkey"]."'size=5></td>\n";
370 echo "<td><input type='file' name='report_template[$rownr]'</td>\n";
371 if (is_readable($system_settings["templatedir"]."/$id.tpl"))
372 echo "<td>Yes</td>\n";
373 else
374 echo "<td>No</td>\n";
375 $modstring = "<input type='submit' name='modreport"."_$rownr' value='Modify'>\n";
376 $exportstring = "<input type='submit' name='expreport"."_$rownr' value='Export'>\n";
377 $teststring = "<input type='submit' name='testreport"."_$rownr' value='Test'>\n";
378 $delstring = "<input type='submit' name='delreport"."_$rownr' value='Remove' ";
379 $delstring .= "Onclick=\"if(confirm('Are you absolutely sure that the report ".$rp->fields["label"] ." should be removed? (No undo possible!)')){return true;}return false;\">";
380 echo "<td>$modstring \n$delstring \n$exportstring \n$teststring</td>\n";
381 echo "</tr>\n";
382 $rp->MoveNext();
383 $rownr++;
384 }
385 echo "</table>\n";
386 printfooter();
387 exit;
388 }
389
390 navbar($USER["permissions"]);
391 echo "<h3 align='center'>$string</h3>";
392 echo "<h3 align='center'>Edit Tables</h3>\n";
393 echo "<form method='post' id='tablemanage' enctype='multipart/form-data' ";
394 $dbstring=$PHP_SELF;echo "action='$dbstring?".SID."'>\n";
395 echo "<table align='center' border='0' cellpadding='2' cellspacing='0'>\n";
396
397 echo "<tr>\n";
398 echo "<th>Table Name</th>\n";
399 echo "<th>Name in linkbar</th>\n";
400 echo "<th>Display</th>\n";
401 echo "<th>Groups</th>\n";
402 echo "<th>Sort key</th>\n";
403 echo "<th>Plugin code</th>\n";
404 echo "<th>Action</th>\n";
405 echo "<th>Fields</th>\n";
406 echo "<th>Reports</th>\n";
407
408 echo "</tr>\n";
409 echo "<tr><td><input type='text' name='newtable_name' value='' ></td>\n";
410 echo "<td><input type='text' name='newtable_label' value=''></td>\n";
411 echo "<td></td>\n";
412 echo "<td></td>\n";
413 echo "<td><input type='text' name='newtable_sortkey' value='' size=6></td>\n";
414 echo "<td><input type='text' name='newtable_plugincode' value=''></td>\n";
415 echo "<td align='center'><input type='submit' name='addtable' value='New'></td>\n";
416 echo "<td></td>\n<td></td>\n</tr>\n";
417
418 $query = "SELECT id,tablename,label,display,sortkey,plugin_code FROM tableoftables where display='Y' or display='N' ORDER BY sortkey";
419 $r=$db->Execute($query);
420
421 // query for group select boxes
422 $rg=$db->Execute("SELECT name,id from groups");
423 $rownr=0;
424
425 // print all entries
426 while (!($r->EOF) && $r) {
427 // get results of each row
428 $id = $r->fields["id"];
429 $name = $r->fields["tablename"];
430 $label = $r->fields["label"];
431 $Display = $r->fields["display"];
432 $sortkey = $r->fields["sortkey"];
433 $plugincode=$r->fields["plugin_code"];
434
435 // print start of row of selected group
436 if ($rownr % 2)
437 echo "<tr class='row_odd' align='center'>\n";
438 else
439 echo "<tr class='row_even' align='center'>\n";
440
441 echo "<input type='hidden' name='table_id[]' value='$id'>\n";
442 echo "<input type='hidden' name='table_name[]' value='$name'>\n";
443 echo "<td><b>$name</b></td>";
444 echo "<td><input type='text' name='table_label[]' value='$label'></td>\n";
445 if($Display=="Y")
446 echo "<td><input type='radio' checked value='Y' name='table_display[$rownr]'>yes<input type='radio' value='N' name='table_display[$rownr]'>no</td>\n";
447 else
448 echo "<td><input type='radio' value='Y' name='table_display[$rownr]'>yes<input type='radio' checked value='N' name='table_display[$rownr]'>no</td>\n";
449 $rgs=$db->Execute("SELECT groupid FROM groupxtable_display WHERE tableid='$id'");
450 while ($rgs && !$rgs->EOF) {
451 $groups_table[]=$rgs->fields["groupid"];
452 $rgs->MoveNext();
453 }
454 echo "<td>".$rg->GetMenu2("tablexgroups[$id][]",$groups_table,true,true,3)."</td>\n";
455 $rg->MoveFirst();
456 unset($groups_table);
457 echo "<td><input type='text' name='table_sortkey[]' value='$sortkey' size=6></td>\n";
458 if ($Custom=="")
459 echo "<td><input type='text' name='table_plugincode[]' value='$plugincode'></td>\n";
460 else
461 echo "<td> <input type='hidden' name='table_plugincode[]' value=''></td>\n";
462 $modstring = "<input type='submit' name='modtable"."_$rownr' value='Modify'>";
463 $delstring = "<input type='submit' name='deltable"."_$rownr' value='Remove' ";
464 $delstring .= "Onclick=\"if(confirm('Are you absolutely sure the table $name should be removed? (No Undo possible!)')){return true;}return false;\">";
465 if ($Custom=="") {
466 echo "<td align='center'>$modstring $delstring</td>\n";
467 echo "<td><a href='$PHP_SELF?editfield=$name&'>Edit Fields</td></a>";
468 echo "<td><a href='$PHP_SELF?editreport=$name&'>Edit Reports</td></a>";
469 }
470 else
471 echo "<td align='center'>$modstring</td><td></td>";
472
473 echo "</tr>\n";
474 $r->MoveNext();
475 $rownr+=1;
476 }
477
478 echo "</table>\n";
479
480 printfooter($db,$USER);
481 ?>