PhpLabWare version 0.3 
/dd/ -> 0_0041_inc.php

1  <?php
2 
3 
4  // updates table antibodies and removes settings from tableoftables
5 
6  $newtableid=$db->GenID("tableoftables_gen_id_seq");
7  $newtablename=ab;
8  $newtablelabel="antibodies";
9  unset($hownew);
10  while (get_cell($db,"tableoftables","id","tablename",$newtablename)) {
11     $newtablename.="n";
12     $hownew++;
13  }
14  for ($i=0;$i<$hownew;$i++)
15     $newtablelabel.="new";
16  $newtableshortname=substr($newtablename,0,3).$newtableid;
17  $newtable_realname=$newtablename."_".$newtableid;
18  $newtable_desc_name=$newtable_realname."_desc";
19  $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/antibodies_plugin.php')");
20  $rg=$db->Execute ("SELECT id FROM groups");
21  while (!$rg->EOF) {
22     $groupid=$rg->fields[0];
23     $db->Execute ("INSERT INTO groupxtable_display VALUES ($groupid,$newtableid)");
24     $rg->MoveNext();
25  }
26 
27  if ($r) {
28     $rb=$db->Execute("CREATE TABLE $newtable_desc_name (
29        id int NOT NULL,
30        sortkey int,
31        label text,
32        columnname text,
33        display_table char(1),
34        display_record char(1),
35        required char(1),
36        type text,
37        datatype text,
38        associated_table text,
39        associated_column text,
40        associated_local_key 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,'100','id','id','N','N','N','int','text','','','','','','','','')");
49        $newid=$db->GenID("newtable_desc_name"."_id");
50        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'110','access','access','N','N','N','varchar(9)','text','','','','','','','','')");
51        $newid=$db->GenID("newtable_desc_name"."_id");
52        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'120','ownerid','ownerid','N','N','N','int','text','','','','','','','','')");
53        $newid=$db->GenID("newtable_desc_name"."_id");
54        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'130','magic','magic','N','N','N','int','text','','','','','','','','')");
55        $newid=$db->GenID("newtable_desc_name"."_id");
56        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'150','lastmoddate','lastmoddate','N','N','N','int','text','','','','','','','','')");
57        $newid=$db->GenID("newtable_desc_name"."_id");
58        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'160','lastmodby','lastmodby','N','N','N','int','text','','','','','','','','')");
59        $newid=$db->GenID("newtable_desc_name"."_id");
60        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'170','date','date','N','N','N','int','text','','','','','','','','')");
61        $newid=$db->GenID("newtable_desc_name"."_id");
62        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'140','Name','title','Y','Y','Y','text','text','','','','','','','','Y')");
63        $newid=$db->GenID("newtable_desc_name"."_id");
64        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'160','Antigen','antigen','Y','Y','N','text','text','','','','','','','','Y')");
65        $newid=$db->GenID("newtable_desc_name"."_id");
66        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'180','Notes','notes','Y','Y','N','text','textlong','','','','','','','','Y')");
67        $newid=$db->GenID("newtable_desc_name"."_id");
68        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'200','Prim/Sec','type1','Y','Y','N','int','pulldown','antibodiesnew_10061ass_20','','','','','','','Y')");
69        $ass_table_t1=$newtable_realname."ass";
70        $id_ass=$db->GenId($ass_table_t1,20);
71        $ass_table_t1.="_$id_ass";
72        $db->Execute("CREATE TABLE $ass_table_t1 (
73           id int PRIMARY KEY,
74           sortkey int,
75           type text,
76           typeshort text)");
77        $db->Execute("UPDATE $newtable_desc_name SET associated_table='$ass_table_t1' WHERE id=$newid");
78        $newid=$db->GenID("newtable_desc_name"."_id");
79        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'220','Label','type5','Y','Y','N','int','pulldown','antibodiesnew_10061ass_21','','','','','','','Y')");
80        $ass_table_t5=$newtable_realname."ass";
81        $id_ass=$db->GenId($ass_table_t5,20);
82        $ass_table_t5.="_$id_ass";
83        $db->Execute("CREATE TABLE $ass_table_t5 (
84           id int PRIMARY KEY,
85           sortkey int,
86           type text,
87           typeshort text)");
88        $db->Execute("UPDATE $newtable_desc_name SET associated_table='$ass_table_t5' WHERE id=$newid");
89        $newid=$db->GenID("newtable_desc_name"."_id");
90        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'240','Mono-/Polyclonal','type2','Y','Y','N','int','pulldown','antibodiesnew_10061ass_22','','','','','','','Y')");
91        $ass_table_t2=$newtable_realname."ass";
92        $id_ass=$db->GenId($ass_table_t2,20);
93        $ass_table_t2.="_$id_ass";
94        $db->Execute("CREATE TABLE $ass_table_t2 (
95           id int PRIMARY KEY,
96           sortkey int,
97           type text,
98           typeshort text)");
99        $db->Execute("UPDATE $newtable_desc_name SET associated_table='$ass_table_t2' WHERE id=$newid");
100        $newid=$db->GenID("newtable_desc_name"."_id");
101        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'260','Host','type3','Y','Y','N','int','pulldown','antibodiesnew_10061ass_23','','','','','','','Y')");
102        $ass_table_t3=$newtable_realname."ass";
103        $id_ass=$db->GenId($ass_table_t3,20);
104        $ass_table_t3.="_$id_ass";
105        $db->Execute("CREATE TABLE $ass_table_t3 (
106           id int PRIMARY KEY,
107           sortkey int,
108           type text,
109           typeshort text)");
110        $db->Execute("UPDATE $newtable_desc_name SET associated_table='$ass_table_t3' WHERE id=$newid");
111        $newid=$db->GenID("newtable_desc_name"."_id");
112        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'280','Class','type4','Y','Y','N','int','pulldown','antibodiesnew_10061ass_24','','','','','','','Y')");
113        $ass_table_t4=$newtable_realname."ass";
114        $id_ass=$db->GenId($ass_table_t4,20);
115        $ass_table_t4.="_$id_ass";
116        $db->Execute("CREATE TABLE $ass_table_t4 (
117           id int PRIMARY KEY,
118           sortkey int,
119           type text,
120           typeshort text)");
121        $db->Execute("UPDATE $newtable_desc_name SET associated_table='$ass_table_t4' WHERE id=$newid");
122        $newid=$db->GenID("newtable_desc_name"."_id");
123        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'300','Location','location','Y','Y','N','text','text','','','','','','','','Y')");
124        $newid=$db->GenID("newtable_desc_name"."_id");
125        $filecolumnid=$newid;
126        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'300','Files','files','Y','Y','N','text','file','','','','','','','','Y')");
127        $newid=$db->GenID("newtable_desc_name"."_id");
128        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'340','Buffer','buffer','N','Y','N','text','text','','','','','','','','Y')");
129        $newid=$db->GenID("newtable_desc_name"."_id");
130        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'360','Concentration (mg/ml)','concentration','Y','Y','N','float','float','','','','','','','','Y')");
131        $newid=$db->GenID("newtable_desc_name"."_id");
132        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'380','Source','source','N','Y','N','text','text','','','','','','','','Y')");
133        $newid=$db->GenID("newtable_desc_name"."_id");
134        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'170','Epitope','epitope','N','Y','N','text','text','','','','','','','','Y')");
135        // and finally create the table
136        $rc=$db->Execute(" CREATE TABLE $newtable_realname (
137           id int NOT NULL,
138           access varchar(9) ,
139           ownerid int ,
140           magic int ,
141           lastmoddate int ,
142           lastmodby int ,
143           date int ,
144           title text ,
145           antigen text ,
146           notes text ,
147           type1 int ,
148           type5 int ,
149           type2 int ,
150           type3 int ,
151           type4 int ,
152           location text ,
153           files text ,
154           buffer text ,
155           concentration float ,
156           source text ,
157           epitope text ) ");
158 
159     }
160 
161 
162     // copy data from 'old' protocol table to the new one
163     unset($counter);
164     set_magic_quotes_runtime(1);
165     $tablesfk=get_cell($db,"tableoftables","id","real_tablename","antibodies");
166     $rcb=$db->Execute("SELECT * FROM antibodies");
167     while (!$rcb->EOF && $rcb) {
168        $newid=$db->Genid($newtable_realname."_id_seq");
169        $row=$rcb->fields;
170        $rcopy=$db->Execute("INSERT INTO $newtable_realname VALUES ('$newid','$row[access]','$row[ownerid]','$row[magic]','$row[lastmoddate]','$row[lastmodby]','$row[date]','$row[name]','$row[antigen]','$row[notes]','$row[type1]','$row[type5]','$row[type2]','$row[type3]','$row[type4]','$row[location]','$row[files]','$row[buffer]','$row[concentration]','$row[source]','$row[epitope]')");
171        if (!$rcopy)
172           $failed=true;
173        else {
174           $counter++;
175           //change ownership of file to new table:
176           $rfile=$db->Execute("UPDATE files SET tablesfk='$newtableid',ftableid='$newid',ftablecolumnid='$filecolumnid' WHERE tablesfk='$tablesfk' AND ftableid='$row[id]'");
177           //adjust trusted users:
178           $db->Execute("UPDATE trust SET tableid='$newtableid',recordid='$newid' WHERE tableid=$tablesfk AND recordid='$row[id]'");
179        }
180        $rcb->MoveNext();
181     }
182     if ($counter)
183        echo "(antibodies:) Inserted $counter records.<br>";
184     // Now copy supporting table (type1=author, type2=categories
185     for ($i=1;$i<=5;$i++) {
186        $tablestring="ass_table_t".$i;
187        $ass_table=${$tablestring};
188        $rcj=$db->Execute("SELECT * FROM ab_type$i ORDER BY id");
189        while ($rcj && !$rcj->EOF) {
190           $newid=$db->Genid($ass_table."_id_seq");
191           $row=$rcj->fields;
192           $rcj_copy=$db->Execute("INSERT INTO $ass_table VALUES ('$newid','$row[sortkey]','$row[type]','$row[type]')");
193           if (!$rcj_copy)
194              $failed=true;
195           // since the ids are not necessarily the same, we'll have to adjust the links
196           // in the main table
197           $db->Execute("UPDATE $newtable_realname SET type$i='$newid' WHERE type$i='$row[id]'");
198           $rcj->MoveNext();
199        }
200     }
201     if ($failed)
202        echo "Failed copying contents of table protocols.<br>";
203     else {
204        echo "Succes!<br>";
205        // delete the old tables
206        $rnt=$db->Execute("SELECT * FROM $newtable_realname");
207        if ($rnt->Numrows==$rcb->Numrows) {
208           $db->Execute("DROP TABLE antibodies");
209           $db->Execute("DROP TABLE antibodies_id_seq");
210           $db->Execute("DROP SEQUENCE antibodies_id_seq");
211           $db->Execute("DROP TABLE ab_type1");
212           $db->Execute("DROP TABLE ab_type1_id_seq");
213           $db->Execute("DROP SEQUENCE ab_type1_id_seq");
214           $db->Execute("DROP TABLE ab_type2");
215           $db->Execute("DROP TABLE ab_type2_id_seq");
216           $db->Execute("DROP SEQUENCE ab_type2_id_seq");
217           $db->Execute("DROP TABLE ab_type3");
218           $db->Execute("DROP TABLE ab_type3_id_seq");
219           $db->Execute("DROP SEQUENCE ab_type3_id_seq");
220           $db->Execute("DROP TABLE ab_type4");
221           $db->Execute("DROP TABLE ab_type4_id_seq");
222           $db->Execute("DROP SEQUENCE ab_type4_id_seq");
223           $db->Execute("DROP TABLE ab_type5");
224           $db->Execute("DROP TABLE ab_type5_id_seq");
225           $db->Execute("DROP SEQUENCE ab_type5_id_seq");
226           $db->Execute("DELETE FROM tableoftables WHERE tablename='antibodies'");
227           $db->Execute("UPDATE tableoftables SET label='antibodies' WHERE id='$newtableid'");
228        }
229        else
230           echo "Problems copying the content of table protocols to the new table protocols.<br>";
231     }
232  }
233 
234  // settings does not appear any more along with other tables in navbar:
235  $db->Execute("DELETE FROM tableoftables WHERE tablename='settings'");
236  ?>


Generated: Sun Oct 5 21:17:35 2003 SourceForge Logo Generated by PHPXref 0.2