/dd/ -> ordertable.php
1 <?php
2
3 // we don't want Ethan to end up with another ordertable:
4 $newtablename="Ordering";
5 if (!get_cell($db,"tableoftables","id","tablename",$newtablename)) {
6 $newtableid=$db->GenID("tableoftables_gen_id_seq");
7 $newtablelabel="Ordering";
8 for ($i=0;$i<$hownew;$i++) {$newtablelabel.="new";}
9 while (get_cell($db,"tableoftables","id","tablename",$newtablename)) {
10 $newtablename.="n";
11 $hownew++;
12 }
13 for ($i=0;$i<$hownew;$i++)
14 $newtablelabel.="new";
15 $newtableshortname=substr($newtablename,0,3).$newtableid;
16 $newtable_realname=$newtablename."_".$newtableid;
17 $newtable_desc_name=$newtable_realname."_desc";
18 $r=$db->Execute("INSERT INTO tableoftables (id,sortkey,tablename,shortname,display,permission,custom,real_tablename,table_desc_name,label,plugin_code) VALUES ('$newtableid','0','$newtablename','$newtableshortname','Y','Users',NULL,'$newtable_realname','$newtable_desc_name','$newtablelabel','plugins/ordering_plugin.php')");
19 $rg=$db->Execute ("SELECT id FROM groups");
20 while (!$rg->EOF) {
21 $groupid=$rg->fields[0];
22 $db->Execute ("INSERT INTO groupxtable_display VALUES ($groupid,$newtableid)");
23 $rg->MoveNext();
24 }
25
26 if ($r) {
27 $rb=$db->Execute("CREATE TABLE $newtable_desc_name (
28 id int NOT NULL,
29 sortkey int,
30 label text,
31 columnname text,
32 display_table char(1),
33 display_record char(1),
34 required char(1),
35 type text,
36 datatype text,
37 associated_table text,
38 associated_column text,
39 associated_local_key text,
40 key_table text,
41 thumb_x_size int,
42 thumb_y_size int,
43 link_first text,
44 link_last text,
45 modifiable char(1) )");
46 if ($rb) {
47 $newid=$db->GenID("$newtable_desc_name"."_id");
48 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'110','access','access','N','N','N','varchar(9)','text','','','','',NULL,NULL,'','','')");
49 $newid=$db->GenID("$newtable_desc_name"."_id");
50 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'10009','Submitted by','ownerid','N','Y','N','int','user','','','','',NULL,NULL,'','','')");
51 $newid=$db->GenID("$newtable_desc_name"."_id");
52 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'130','magic','magic','N','N','N','int','text','','','','',NULL,NULL,'','','')");
53 $newid=$db->GenID("$newtable_desc_name"."_id");
54 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'1','title','title','Y','Y','Y','text','text','','','','',NULL,NULL,'','','Y')");
55 $newid=$db->GenID("$newtable_desc_name"."_id");
56 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'10029','Last modified on','lastmoddate','N','N','N','int','date','','','','',NULL,NULL,'','','')");
57 $newid=$db->GenID("$newtable_desc_name"."_id");
58 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'10039','Last modified by','lastmodby','N','N','N','int','user','','','','',NULL,NULL,'','','')");
59 $newid=$db->GenID("$newtable_desc_name"."_id");
60 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'10019','Date entered','date','N','Y','N','int','date','','','','',NULL,NULL,'','','')");
61 $newid=$db->GenID("$newtable_desc_name"."_id");
62 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'8','Company','Company','Y','Y','N','text','text','','','','',NULL,NULL,'','','Y')");
63 $newid=$db->GenID("$newtable_desc_name"."_id");
64 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'4','date_requested','date_requested','Y','Y','N','text','text','','','','',NULL,NULL,'','','Y')");
65 $newid=$db->GenID("$newtable_desc_name"."_id");
66 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'6','date_ordered','date_ordered','Y','Y','N','text','text','','','','',NULL,NULL,'','','Y')");
67 $newid=$db->GenID("$newtable_desc_name"."_id");
68 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'13','reorder','reorder','N','Y','N','text','link','','','','',NULL,NULL,'','','Y')");
69 $newid=$db->GenID("$newtable_desc_name"."_id");
70 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'3','ordered_by','ordered_by','Y','Y','N','text','text','','','','',NULL,NULL,'','','Y')");
71 $newid=$db->GenID("$newtable_desc_name"."_id");
72 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'9','catalog number','catnum','Y','Y','N','text','text','','','','',NULL,NULL,'','','Y')");
73 $newid=$db->GenID("$newtable_desc_name"."_id");
74 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'15','Notes','notes','Y','Y','N','text','textlong','','','','',NULL,NULL,'','','Y')");
75 $newid=$db->GenID("$newtable_desc_name"."_id");
76 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'10','Quantity','quantity','Y','Y','N','text','text','','','','',NULL,NULL,'','','Y')");
77 $newid=$db->GenID("$newtable_desc_name"."_id");
78 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'11','price','price','Y','Y','N','text','text','','','','',NULL,NULL,'','','Y')");
79 $newid=$db->GenID("$newtable_desc_name"."_id");
80 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'2','urgency','urgency','Y','Y','N','text','pulldown','Ordering_10010ass_20','urgency from Ordering_10010ass_20 where ','','',NULL,NULL,'','','Y')");
81 $ass_table=$newtable_realname."ass";
82 $id_ass=$db->GenId($ass_table,20);
83 $ass_table.="_$id_ass";
84 $db->Execute("CREATE TABLE $ass_table (
85 id int PRIMARY KEY,
86 sortkey int,
87 type text,
88 typeshort text)");
89 $db->Execute("UPDATE $newtable_desc_name SET associated_table='$ass_table' WHERE id=$newid");
90 $newid=$db->GenID("$newtable_desc_name"."_id");
91 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'12','email_me','confirmme','N','Y','N','int','pulldown','Ordering_10010ass_22','','','',NULL,NULL,'','','Y')");
92 $ass_table=$newtable_realname."ass";
93 $id_ass=$db->GenId($ass_table,20);
94 $ass_table.="_$id_ass";
95 $db->Execute("CREATE TABLE $ass_table (
96 id int PRIMARY KEY,
97 sortkey int,
98 type text,
99 typeshort text)");
100 $db->Execute("UPDATE $newtable_desc_name SET associated_table='$ass_table' WHERE id=$newid");
101 $newid=$db->GenID("$newtable_desc_name"."_id");
102 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'9999','confirmed','confirmed','N','N','N','text','text','','','','',NULL,NULL,'','','Y')");
103 $newid=$db->GenID("$newtable_desc_name"."_id");
104 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'7','Date recieved','date_rec','Y','Y','N','text','text','','','','',NULL,NULL,'','','Y')");
105 $newid=$db->GenID("$newtable_desc_name"."_id");
106 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'5','Has been Ordered','isordered','Y','Y','N','int','pulldown','Ordering_10010ass_23','','','',NULL,NULL,'','','Y')");
107 $ass_table=$newtable_realname."ass";
108 $id_ass=$db->GenId($ass_table,20);
109 $ass_table.="_$id_ass";
110 $db->Execute("CREATE TABLE $ass_table (
111 id int PRIMARY KEY,
112 sortkey int,
113 type text,
114 typeshort text)");
115 $db->Execute("UPDATE $newtable_desc_name SET associated_table='$ass_table' WHERE id=$newid");
116 $newid=$db->GenID("$newtable_desc_name"."_id");
117 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'111','group read','gr','N','N','N','smallint','int','','','','',NULL,NULL,'','','Y')");
118 $newid=$db->GenID("$newtable_desc_name"."_id");
119 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'112','group write','gw','N','N','N','smallint','int','','','','',NULL,NULL,'','','Y')");
120 $newid=$db->GenID("$newtable_desc_name"."_id");
121 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'113','everyone read','er','N','N','N','smallint','int','','','','',NULL,NULL,'','','Y')");
122 $newid=$db->GenID("$newtable_desc_name"."_id");
123 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'114','everyone write','ew','N','N','N','smallint','int','','','','',NULL,NULL,'','','Y')");
124
125 for ($i=0;$i<sizeof($lid);$i++) {
126 // find local associated column
127 $r=$db->Execute("SELECT id FROM $newtable_desc_name WHERE columnname='{$lasscolumnname[$i]}'");
128 $db->Execute("UPDATE $newtable_desc_name SET associated_local_key='{$r->fields[0]}' WHERE id='{$lid[$i]}'");
129 }
130 // and finally create the table
131 $rc=$db->Execute(" CREATE TABLE $newtable_realname (
132 id int NOT NULL,
133 access varchar(9) ,
134 ownerid int ,
135 magic int ,
136 title text ,
137 lastmoddate int ,
138 lastmodby int ,
139 date int ,
140 Company text ,
141 date_requested text ,
142 date_ordered text ,
143 reorder text ,
144 ordered_by text ,
145 catnum text ,
146 notes text ,
147 quantity text ,
148 price text ,
149 urgency text ,
150 confirmme int ,
151 confirmed text ,
152 date_rec text ,
153 isordered int ,
154 gr smallint ,
155 gw smallint ,
156 er smallint ,
157 ew smallint ) ");
158
159 }
160 }
161 }
162 ?>