/dd/ -> 0_0031_inc.php
1 <?php
2
3 // 0_0031_inc.php - See code
4 // 0_0031_inc.php - author: Nico Stuurman
5
6 /***************************************************************************
7 * Copyright (c) 2002 by Nico Stuurman *
8 * ------------------------------------------------------------------------ *
9 * This code is part of phplabware (http://phplabware.sf.net) *
10 * *
11 * *
12 * This program is free software; you can redistribute it and/or modify it *
13 * under the terms of the GNU General Public License as published by the *
14 * Free Software Foundation; either version 2 of the License, or (at your *
15 * option) any later version. *
16 \**************************************************************************/
17
18 // get the real tablenames into a column
19 $db->Execute("ALTER TABLE tableoftables ADD COLUMN real_tablename text");
20 $r=$db->Execute("SELECT id,tablename FROM tableoftables");
21 while (!$r->EOF) {
22 $real_tablename=$r->fields["tablename"];
23 if ($r->fields["id"]>10000)
24 $real_tablename.="_".$r->fields["id"];
25 $db->Execute("UPDATE tableoftables SET real_tablename='$real_tablename' WHERE id='".$r->fields["id"]."'");
26 $r->MoveNext();
27 }
28
29 // Make it possible to assign a user to multiple groups:
30 $db->Execute("CREATE INDEX usersxgroups_userid ON usersxgroups(usersid)");
31 $db->Execute("CREATE INDEX usersxgroups_groupid ON usersxgroups(groupsid)");
32
33 // Make it possible to assign different 'powers' to different groups
34 $db->Execute("ALTER TABLE groups ADD COLUMN power int");
35
36 // Make a table that allows showing different tables to different groups
37 if ($db_type=="mysql")
38 $db->Execute("CREATE TABLE groupxtable_display (
39 groupid int,
40 tableid int,
41 UNIQUE INDEX (groupid,tableid))");
42 else {
43 $db->Execute("CREATE TABLE groupxtable_display (
44 groupid int,
45 tableid int,
46 CONSTRAINT gxtspecial PRIMARY KEY (groupid,tableid))");
47 $db->Execute("CREATE INDEX groupxtable_display_groupid ON groupxtable_display(groupid)");
48 $db->Execute("CREATE INDEX groupxtable_display_tableid ON groupxtable_display(tableid)");
49 }
50 // Make all current tables visible to all groups
51 $rg=$db->Execute("SELECT id FROM groups");
52 while (!$rg->EOF) {
53 $ag[]=$rg->fields["id"];
54 $rg->MoveNext();
55 }
56 $rt=$db->Execute("SELECT id FROM tableoftables");
57 while (!$rt->EOF) {
58 $at[]=$rt->fields["id"];
59 $rt->MoveNext();
60 }
61 foreach ($ag AS $groupid)
62 foreach ($at AS $tableid)
63 $db->Execute("INSERT INTO groupxtable_display VALUES ('$groupid','$tableid')");
64
65 // Add some indices to tableoftables
66 $db->Execute("CREATE INDEX tableoftables_id ON tableoftables(id)");
67 $db->Execute("CREATE INDEX tableoftables_tablename ON tableoftables(tablename)");
68 $db->Execute("CREATE INDEX tableoftables_tablename ON tableoftables(tablename(10))");
69 ?>