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

1  <?php
2 
3 
4  // updates table pdb to new format
5 
6  $newtableid=$db->GenID("tableoftables_gen_id_seq");
7  $newtablename=pdbs;
8  $newtablelabel="pdbs ";
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/pdbs_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','title','title','Y','Y','N','text','text','','','','','','','','Y')");
63        $newid=$db->GenID("newtable_desc_name"."_id");
64        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'160','Authors','author','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,'100','PDBID','pdbid','Y','Y','N','text','text','','','','','','http://www.rcsb.org/cgi/explre.cgi?pdbId=','','Y')");
69        $newid=$db->GenID("newtable_desc_name"."_id");
70        $filecolumnid=$newid;
71        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'220','File','file','Y','Y','N','text','file','','','','','','','','Y')");
72        $newid=$db->GenID("newtable_desc_name"."_id");
73        $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'200','Webmol','webmol','Y','Y','N','text','text','','','','','','webmol.php?pdbid=','','N')");
74        // and finally create the table
75        $rc=$db->Execute(" CREATE TABLE $newtable_realname (
76           id int NOT NULL,
77           access varchar(9) ,
78           ownerid int ,
79           magic int ,
80           lastmoddate int ,
81           lastmodby int ,
82           date int ,
83           title text ,
84           author text ,
85           notes text ,
86           pdbid text ,
87           file text ,
88           webmol text ) ");
89 
90     }
91 
92     // copy data from 'old' pdbs table to the new one
93     unset($counter);
94     set_magic_quotes_runtime(1);
95     $tablesfk=get_cell($db,"tableoftables","id","real_tablename","pdbs");
96     $rcb=$db->Execute("SELECT * FROM pdbs");
97     while (!$rcb->EOF && $rcb) {
98        $newid=$db->Genid($newtable_realname."_id_seq");
99        $row=$rcb->fields;
100        $rcopy=$db->Execute("INSERT INTO $newtable_realname VALUES ('$newid','$row[access]','$row[ownerid]','$row[magic]','$row[lastmoddate]','$row[lastmodby]','$row[date]','$row[title]','$row[author]','$row[notes]','$row[pdbid]','$row[file]','$row[pdbid]')");
101        if (!$rcopy)
102           $failed=true;
103        else {
104           $counter++;
105           //change ownership of file to new table:
106           $rfile=$db->Execute("UPDATE files SET tablesfk='$newtableid',ftableid='$newid',ftablecolumnid='$filecolumnid' WHERE tablesfk='$tablesfk' AND ftableid='$row[id]'");
107           //adjust trusted users:
108           $db->Execute("UPDATE trust SET tableid='$newtableid',recordid='$newid' WHERE tableid=$tablesfk AND recordid='$row[id]'");
109        }
110        $rcb->MoveNext();
111     }
112     if ($counter)
113        echo "(pdbs:) Inserted $counter records.<br>";
114 
115     if ($failed)
116        echo "Failed copying contents of table pdbs.<br>";
117     else {
118        //echo "Succes!<br>";
119        // delete the old tables
120        $rnt=$db->Execute("SELECT * FROM $newtable_realname");
121        if ($rnt->Numrows==$rcb->Numrows) {
122           $db->Execute("DROP TABLE pdbs");
123           $db->Execute("DROP TABLE pdbs_id_seq");
124           $db->Execute("DROP SEQUENCE pdbs_id_seq");
125           $db->Execute("DELETE FROM tableoftables WHERE tablename='pdbs'");
126           $db->Execute("UPDATE tableoftables SET label='pdbs' WHERE id='$newtableid'");
127        }
128        else
129           echo "Problems copying the content of table pdbs to the new table pdbs.<br>";
130     }
131  }
132 
133  ?>


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