/plugins/ -> pdbs_plugin.php
1 <?php
2
3 // pdbs_plugin.php - skeleton file for plugin codes
4 // pdbs_plugin.php - author: Nico Stuurman
5
6 /*
7 Copyright 2002, Nico Stuurman
8
9 This program is free software: you can redistribute it and/ormodify it under
10 the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
11
12 */
13
14
15
16 ////
17 // !Change/calculate/check values just before they are added/modified
18 // $fieldvalues is an array with the column names as key.
19 // Any changes you make in the values of $fieldvalues will result in
20 // changes in the database.
21 // You could, for instance, calculate a value of a field based on other fields
22 function plugin_check_data($db,&$field_values,$table_desc,$modify=false)
23 {
24 global $HTTP_POST_VARS, $HTTP_POST_FILES;
25 // read title, author, pdbid from file
26 // we can not demand a file to be there since this might be a modify
27 if (is_readable($HTTP_POST_FILES["file"]["tmp_name"][0])) {
28 // force the mime-type to be pdb compliant
29 $HTTP_POST_FILES["file"]["type"][0]="chemical/x-pdb";
30 $fh=fopen($HTTP_POST_FILES["file"]["tmp_name"][0],"r");
31 $test1=false;
32 $test2=true;
33 $llength=71;
34 // protect quotes in imported data
35 set_magic_quotes_runtime(1);
36 while ($fh && $test2 && !feof($fh)) {
37 $line=chop(fgets($fh,1024));
38 $lid=strtok($line," ");
39 switch ($lid) {
40 case "HEADER":
41 $pdbid=trim(strrchr($line," "));
42 if (strlen($pdbid)<4) {
43 // this must be an old pdb format
44 $pdbid=substr($line,62,4);
45 $llength=62;
46 }
47 $field_values["pdbid"]=$pdbid;
48 break;
49 case "TITLE":
50 $field_values["title"].=substr($line,10,$llength);
51 break;
52 case "COMPND":
53 $compnd.=substr($line,10,$llength);
54 break;
55 case "AUTHOR":
56 $field_values["author"].=substr($line,10,$llength);
57 $test1=true;
58 break;
59 default:
60 if ($test1) $test2=false;
61 }
62 }
63 }
64 if (!$field_values["title"])
65 $field_values["title"]=$compnd;
66 set_magic_quotes_runtime(0);
67 return true;
68 }
69
70 /*
71 ////
72 // !Overrides the standard 'show record'function
73 function plugin_show($db,$tableinfo,$id,$USER,$system_settings,$backbutton=true)
74 {
75 }
76
77
78 ////
79 // !Extends the search query
80 // $query is the complete query that you can change and must return
81 // $fieldvalues is an array with the column names as key.
82 // if there is an $existing_clause (boolean) you should prepend your additions
83 // with ' AND' or ' OR', otherwise you should not
84 function plugin_search($query,$fieldvalues,$existing_clause)
85 {
86 return $query;
87 }
88 */
89
90 ////
91 // !Extends function getvalues
92 // $allfields is a 2-D array containing the field names of the table in the first dimension
93 // and name,columnid,label,datatype,display_table,display_record,ass_t,ass_column,
94 // ass_local_key,required,modifiable,text,values in the 2nd D
95 function plugin_getvalues($db,&$allfields,$id,$tableid)
96 {
97 if (!$id)
98 return true;
99 $table_desc=get_cell($db,"tableoftables","table_desc_name","id",$tableid);
100 $webmollink=get_cell($db,$table_desc,"link_first","columnname","webmol");
101
102 while (list($key,$value)=each($allfields)) {
103 if ($value[name]=="webmol")
104 $index=$key;
105 if ($value[name]=="pdbid")
106 $pdindex=$key;
107 }
108 if ($index) {
109 $pdbid=$allfields[$pdindex]["values"];
110 if ($pdbid) {
111 $link=$webmollink . $pdbid;
112 $allfields[$index]["text"]="<a href=$link>$pdbid</a>";
113 }
114 }
115 }
116
117
118 ////
119 // !Extends function display_add
120 // This lets you add information to every specific item
121 function plugin_display_add ($db,$tableid,$nowfield)
122 {
123 if ($nowfield["name"]=="pdbid") {
124 echo "<br>If a pdb file is uploaded (below), the fields PDBID,Title, and Author(s) will be extracted from the file.";
125 }
126 }
127
128
129 ?>