/dd/ -> 0_0037_inc.php
1 <?php
2
3
4
5
6 $newtableid=$db->GenID("tableoftables_gen_id_seq");
7 $newtablename=pdfsw;
8 $newtablelabel="pdfs";
9 unset($hownew);
10 while (get_cell($db,"tableoftables","id","tablename",$newtablename)) {
11 $newtablename.="new";
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/pdfs_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,'200','Category','category','Y','Y','N','text','pulldown','pdfs_new_10015ass_21','','','','','','','Y')");
63 $ass_tablec=$newtable_realname."ass";
64 $id_ass=$db->GenId($ass_tablec,20);
65 $ass_tablec.="_$id_ass";
66 $db->Execute("CREATE TABLE $ass_tablec (
67 id int PRIMARY KEY,
68 sortkey int,
69 type text,
70 typeshort text)");
71 $db->Execute("UPDATE $newtable_desc_name SET associated_table='$ass_tablec' WHERE id=$newid");
72 $newid=$db->GenID("newtable_desc_name"."_id");
73 $filecolumnid=$newid;
74 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'300','PDF File','file','Y','Y','N','text','file','','','','','','','','Y')");
75 $newid=$db->GenID("newtable_desc_name"."_id");
76 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'180','Author(s)','author','Y','Y','N','text','text','','','','','','','','N')");
77 $newid=$db->GenID("newtable_desc_name"."_id");
78 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'210','Journal','journal','Y','Y','N','text','pulldown','pdfs_new_10015ass_23','','','','','','','N')");
79 $ass_tablej=$newtable_realname."ass";
80 $id_ass=$db->GenId($ass_tablej,20);
81 $ass_tablej.="_$id_ass";
82 $db->Execute("CREATE TABLE $ass_tablej (
83 id int PRIMARY KEY,
84 sortkey int,
85 type text,
86 typeshort text)");
87 $db->Execute("UPDATE $newtable_desc_name SET associated_table='$ass_tablej' WHERE id=$newid");
88 $newid=$db->GenID("newtable_desc_name"."_id");
89 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'240','First page','fpage','Y','Y','N','int','int','','','','','','','','N')");
90 $newid=$db->GenID("newtable_desc_name"."_id");
91 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'260','Last Page','lpage','N','Y','N','int','int','','','','','','','','N')");
92 $newid=$db->GenID("newtable_desc_name"."_id");
93 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'140','Title','title','Y','Y','N','text','text','','','','','','','','N')");
94 $newid=$db->GenID("newtable_desc_name"."_id");
95 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'205','Abstract','abstract','Y','Y','N','text','textlong','','','','','','','','N')");
96 $newid=$db->GenID("newtable_desc_name"."_id");
97 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'300','Notes','notes','N','Y','N','text','textlong','','','','','','','','Y')");
98 $newid=$db->GenID("newtable_desc_name"."_id");
99 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'219','Volume','volume','Y','Y','N','int','int','','','','','','','','N')");
100 $newid=$db->GenID("newtable_desc_name"."_id");
101 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'215','Year','pubyear','Y','Y','N','int','int','','','','','','','','N')");
102 $newid=$db->GenID("newtable_desc_name"."_id");
103 $db->Execute("INSERT INTO $newtable_desc_name VALUES($newid,'160','PMID','pmid','N','Y','N','int','int','','','','','','','','Y')");
104 // and finally create the table
105 $rc=$db->Execute(" CREATE TABLE $newtable_realname (
106 id int NOT NULL,
107 access varchar(9) ,
108 ownerid int ,
109 magic int ,
110 lastmoddate int ,
111 lastmodby int ,
112 date int ,
113 category text ,
114 file text ,
115 author text ,
116 journal text ,
117 fpage int ,
118 lpage int ,
119 title text ,
120 abstract text ,
121 notes text ,
122 volume int ,
123 pubyear int ,
124 pmid int ) ");
125
126 }
127
128
129 // copy data from 'old' pdfs table to the new one
130 set_magic_quotes_runtime(1);
131 $tablesfk=get_cell($db,"tableoftables","id","real_tablename","pdfs");
132 $rcb=$db->Execute("SELECT * FROM pdfs");
133 while (!$rcb->EOF && $rcb) {
134 $newid=$db->Genid($newtable_realname."_id_seq");
135 $row=$rcb->fields;
136 $rcopy=$db->Execute("INSERT INTO $newtable_realname VALUES ('$newid','$row[access]','$row[ownerid]','$row[magic]','$row[lastmoddate]','$row[lastmodby]','$row[date]','$row[type2]','$row[file]','$row[author]','$row[type1]','$row[fpage]','$row[lpage]','$row[title]','$row[abstract]','$row[notes]','$row[volume]','$row[year]','$row[pmid]')");
137 if (!$rcopy)
138 $failed=true;
139 else {
140 $counter++;
141 //change ownership of file to new table:
142 $rfile=$db->Execute("UPDATE files SET tablesfk='$newtableid',ftableid='$newid',ftablecolumnid='$filecolumnid' WHERE tablesfk='$tablesfk' AND ftableid='$row[id]'");
143 //adjust trusted users:
144 $db->Execute("UPDATE trust SET tableid='$newtableid',recordid='$newid' WHERE tableid=$tablesfk AND recordid='$row[id]'");
145 }
146 $rcb->MoveNext();
147 }
148 if ($counter)
149 echo "(pdfs:) Inserted $counter records.<br>";
150 // Now copy supporting table (type1=journal, type2=categories
151 $rcj=$db->Execute("SELECT * FROM pd_type1 ORDER By id");
152 while ($rcj && !$rcj->EOF) {
153 $newid=$db->Genid($ass_tablej."_id_seq");
154 $row=$rcj->fields;
155 $rcj_copy=$db->Execute("INSERT INTO $ass_tablej VALUES ('$newid','$row[sortkey]','$row[type]','$row[typeshort]')");
156 if (!$rcj_copy)
157 $failed=true;
158 // since the ids are not necessarily the same, we'll have to adjust the links
159 // in the main table
160 $db->Execute("UPDATE $newtable_realname SET journal='$newid' WHERE journal='$row[id]'");
161 $rcj->MoveNext();
162 }
163 $rcc=$db->Execute("SELECT * FROM pd_type2 ORDER BY id");
164 while ($rcc && !$rcc->EOF) {
165 $newid=$db->Genid($ass_tablec."_id_seq");
166 $row=$rcc->fields;
167 $rcc_copy=$db->Execute("INSERT INTO $ass_tablec VALUES ('$newid','$row[sortkey]','$row[type]','$row[typeshort]')");
168 if (!$rcc_copy)
169 $failed=true;
170 $db->Execute("UPDATE $newtable_realname SET category='$newid' WHERE category='$row[id]'");
171 $rcc->MoveNext();
172 }
173 if ($failed)
174 echo "Failed copying contents of table pdbs.<br>";
175 else {
176 //echo "Succes!<br>";
177 $rpdn=$db->Execute("SELECT * FROM $newtable_realname");
178 if ($rpdn->Numrows==$rcb->Numrows) {
179 $db->Execute("DROP TABLE pdfs");
180 $db->execute("DROP TABLE pdfs_id_seq");
181 $db->Execute("DROP SEQUENCE pdfs_id_seq");
182 $db->Execute("DROp TABLE pd_type1");
183 $db->Execute("DROp TABLE pd_type1_id_seq");
184 $db->Execute("DROp SEQUENCE pd_type1_id_seq");
185 $db->Execute("DROp TABLE pd_type2");
186 $db->Execute("DROp TABLE pd_type2_id_seq");
187 $db->Execute("DROp SEQUENCE pd_type2_id_seq");
188 $db->Execute("DELETE FROM tableoftables WHERE tablename='pdfs'");
189 $db->Execute("UPDATE tableoftables SET label='pdfs' WHERE id='$newtableid'");
190 }
191 else
192 echo "Failed to copy contents of old table pdfs to new table pdfs.<br>";
193 }
194 }
195 ?>