/plugins/ -> protocols_plugin.php
1 <?php
2
3 // plugin_inc.php - skeleton file for plugin codes
4 // plugin_inc.php - author: Nico Stuurman
5
6 /*
7 Copyright 2002, Nico Stuurman
8
9 This is a skeleton file to code your own plugins.
10 To use it, rename this file to something meaningfull,
11 add the path and name to this file (relative to the phplabware root)
12 in the column 'plugin_code' of 'tableoftables', and code away.
13 And, when you make something nice, please send us a copy!
14
15 This program is free software: you can redistribute it and/ormodify it under
16 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.
17
18 */
19
20 ////
21 // !When a record has been added,some data are written to a file fro inclusion
22 // in a webpage (to announce the addition)
23 function plugin_add ($db,$tableid,$id)
24 {
25 global $system_settings;
26
27 $table_desc=get_cell($db,"tableoftables","table_desc_name","id",$tableid);
28 $tablename=get_cell($db,"tableoftables","tablename","id",$tableid);
29 $real_tablename=get_cell($db,"tableoftables","real_tablename","table_desc_name",$table_desc);
30 $authortable=get_cell($db,$table_desc,"associated_table","columnname","type2");
31
32 if (!$system_settings["protocols_file"])
33 return false;
34 $r=$db->Execute("SELECT ownerid,title,type1,type2 FROM $real_tablename WHERE id=$id");
35 $fid=fopen($system_settings["protocols_file"],w);
36 if ($fid) {
37 $link= $system_settings["baseURL"].getenv("SCRIPT_NAME")."?tablename=$tablename&showid=$id";
38 $author=get_cell($db,$authortable,"type","id",$r->fields["type2"]);
39 $author.=" ".get_cell($db,$authortable,"typeshort","id",$r->fields["type2"]);
40 $submitter=get_person_link($db,$r->fields["ownerid"]);
41 $text="<a href='$link'><b>".$r->fields["title"]."</b></a>";
42 $text.= ". Written by $author.<br> Submitted by $submitter.";
43 fwrite($fid,$text);
44 fclose($fid);
45 }
46 }
47
48
49 ////
50 // !Change/calculate/check values just before they are added/modified
51 // $fieldvalues is an array with the column names as key.
52 // Any changes you make in the values of $fieldvalues will result in
53 // changes in the database.
54 // You could, for instance, calculate a value of a field based on other fields
55 function plugin_check_data($db,&$fieldvalues,$table_desc,$modify=false)
56 {
57
58 $protocoltable=get_cell($db,"tableoftables","real_tablename","table_desc_name",$table_desc);
59 $protocoltablelabel=get_cell($db,"tableoftables","tablename","table_desc_name",$table_desc);
60 $authortable=get_cell($db,$table_desc,"associated_table","columnname","type2");
61
62 // When a new author was entered
63 $firstname=$fieldvalues["firstname"];
64 $lastname=$fieldvalues["lastname"];
65 if ($firstname || $lastname) {
66 // check if this entry exists already
67 $r=$db->Execute("SELECT id FROM $authortable WHERE type='$firstname' AND typeshort='$lastname'");
68 if ($r && !$r->EOF) {
69 $fieldvalues["type2"]=$r->fields["id"];
70 return true;
71 }
72 $id=$db->GenID($authortable."_id_seq");
73 $db->Execute("INSERT INTO $authortable (id,type,typeshort) VALUES ('$id','".
74 $fieldvalues["firstname"]."','".$fieldvalues["lastname"]."')");
75 $fieldvalues["type2"]=$id;
76 }
77 return true;
78 }
79
80
81 /*
82 ////
83 // !Overrides the standard 'show record'function
84 function plugin_show($db,$tableinfo,$id,$USER,$system_settings,$backbutton=false)
85 {
86 }
87
88
89 ////
90 // !Extends the search query
91 // $query is the complete query that you can change and must return
92 // $fieldvalues is an array with the column names as key.
93 // if there is an $existing_clause (boolean) you should prepend your additions
94 // with ' AND' or ' OR', otherwise you should not
95 function plugin_search($query,$fieldvalues,$existing_clause)
96 {
97 return $query;
98 }
99
100 */
101
102 ////
103 // !Extends function getvalues
104 // $allfields is a 2-D array containing the field names of the table in the first dimension
105 // and name,columnid,label,datatype,display_table,display_record,ass_t,ass_column,
106 // ass_local_key,required,modifiable,text,values in the 2nd D
107 function plugin_getvalues($db,&$allfields,$id,$tableid)
108 {
109 if (!$id)
110 return true;
111
112 $table_desc=get_cell($db,"tableoftables","table_desc_name","id",$tableid);
113 $authortable=get_cell($db,$table_desc,"associated_table","columnname","type2");
114 while (list($key,$value)=each ($allfields)) {
115 if ($value[name]=="type2")
116 $index=$key;
117 }
118 if ($index) {
119 $firstname=get_cell($db,$authortable,"type","id",$allfields[$index][values]);
120 $lastname=get_cell($db,$authortable,"typeshort","id",$allfields[$index][values]);
121 if ($firstname || $lastname)
122 $allfields[$index][text]="$firstname $lastname";
123 }
124 }
125
126
127 ////
128 // !Extends display_add
129 function plugin_display_add ($db,$tableid,$nowfield)
130 {
131 global $HTTP_POST_VARS;
132
133 if ($nowfield[name]=="type2") {
134 echo "<br>Or: Firstname: <input type='text' name='firstname' value='$HTTP_POST_VARS[firstname]'>\n";
135 echo "Lastname: <input type='text'name='lastname' value='$HTTP_POST_VARS[lastname]'>";
136 }
137 }
138
139 ?>