3 include("energie/common.php");
6 .name { font-weight: bold; }
7 .PublAuthor { font-variant: small-caps; }
13 prepvar("find" ,".*" ,false /* require */);
16 prepvar("confirm" ,$buttonre,false /* require */);
17 prepvar("delete" ,$buttonre,false /* require */);
18 prepvar("isolate" ,$buttonre,false /* require */);
19 prepvar("edit" ,$buttonre,false /* require */);
20 prepvar("update" ,$buttonre,false /* require */);
21 prepvar("move" ,$buttonre,false /* require */);
22 prepvar("reorder" ,$buttonre,false /* require */);
24 prepvar("move_src","[-0-9 ,]+" ,isset($move ) /* require */);
25 prepvar("move_dst","[-0-9]+" ,isset($move ) /* require */);
26 prepvar("confirming","[a-z]+" ,isset($confirm) /* require */);
27 prepvar("reorder_by","[+-]?[0-9]+",isset($reorder) /* require */);
29 prepvar("id" ,"[-0-9]+",(isset($update) || isset($confirm) || isset($delete) || isset($isolate) || isset($edit)) || isset($reorder) /* require */);
30 prepvar("winclose" ,"1",false /* require */);
33 prepvar("name" ,".*" ,false /* require */);
34 prepvar("PublAuthor" ,".*" ,false /* require */);
35 prepvar("Publication",".*" ,false /* require */);
36 prepvar("html" ,".*" ,false /* require */);
38 // "find" dump limits:
39 prepvar("limit_from","[0-9]*",false /* require */);
40 if (!isset($limit_from))
42 prepvar("limit_max" ,"[0-9]*",false /* require */);
43 if (!isset($limit_max))
44 $limit_max=$limit_max_default;
46 $permanents_array=array("find","limit_from","limit_max","winclose");
50 function fieldupdate($field)
52 global $cmd,$cmdargnum;
54 $cmd.=(!$cmdargnum?" ":",")."$field=";
55 if ($GLOBALS[$field]!="")
56 $cmd.="\"".mysql_escape_string($GLOBALS[$field])."\"";
62 $cmd="update $tb_tree set";
65 fieldupdate("PublAuthor");
66 fieldupdate("Publication");
68 $cmd.=" where id=\"".mysql_escape_string($id)."\"";
74 db_query("delete from $tb_tree where id=\"".mysql_escape_string($id)."\"");
77 if (isset($isolate)) {
78 $family_id=db_item("select family_id from $tb_tree where id=\"".mysql_escape_string($id)."\"");
80 db_query("update $tb_tree set family_id=id where id=\"".mysql_escape_string($id)."\"");
82 $where="where family_id=\"".mysql_escape_string($family_id)."\" and family_id<>id";
83 $other_id=db_item("select id from $tb_tree $where limit 1");
84 db_query("update $tb_tree set family_id=\"".mysql_escape_string($other_id)."\" $where");
89 $order=db_item("select max(family_order) from $tb_tree where family_id=\"".mysql_escape_string($move_dst)."\"");
90 foreach(preg_split('/[ ,]/',$move_src,-1,PREG_SPLIT_NO_EMPTY) as $src) {
91 // UGLY but how to do sequential setting of increasing family_order?
92 $result=db_query("select id from $tb_tree where family_id=\"".mysql_escape_string($src)."\" order by family_order");
93 while (($row=mysql_fetch_array($result)))
94 db_query("update $tb_tree set family_order=\"".(++$order)."\",family_id=\"".mysql_escape_string($move_dst)."\""
95 ." where id=\"".mysql_escape_string($row["id"])."\"");
99 if (isset($reorder)) {
100 $row=db_array("select family_id,family_order from $tb_tree where id=\"".mysql_escape_string($id)."\"");
101 $other_order=db_item("select family_order from $tb_tree where family_id=\"".mysql_escape_string($row["family_id"])."\""
102 ." and family_order".($reorder_by<0 ? "<" : ">").$row["family_order"]
103 ." order by family_order ".($reorder_by<0 ? "desc" : "asc")." limit 1");
104 db_query("update $tb_tree set family_order=family_order".($reorder_by>=0 ? "+" : "").$reorder_by
105 ." where family_id=\"".mysql_escape_string($row["family_id"])."\""
106 ." and family_order".($reorder_by<0 ? "<" : ">").$other_order);
107 db_query("update $tb_tree set family_order=".($other_order+$reorder_by)." where id=\"".mysql_escape_string($id)."\"");
111 function hiddens($array,$doinputs)
113 global $permanents_array;
115 foreach ($permanents_array as $key)
116 if (!isset($key,$array) && isset($GLOBALS[$key]))
117 $array[$key]=$GLOBALS[$key];
118 foreach ($array as $key=>$val) {
120 $r.="<input type=\"hidden\" name=\"".htmlspecialchars($key)."\" value=\"".htmlspecialchars($val)."\" />\n";
122 $r.=($r==""?"?":"&").addpercents($key)."=".addpercents($val);
124 if (!$doinputs && $r=="")
129 if (isset($delete) || isset($update) || isset($move) || isset($isolate) || isset($reorder)) {
130 if (isset($winclose)) {
131 header("Content-type: text/html");
133 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
134 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs">
135 <head><title>Uzavreni okna</title></head>
136 <body onload="window.close();">
142 // OK: Redirect will NOT keep the request type "POST"!
143 $redir="http://".$HTTP_SERVER_VARS["HTTP_HOST"].$HTTP_SERVER_VARS["REQUEST_URI"].hiddens(array(),false/*doinputs*/);
144 header("Location: $redir");
149 heading(false/*title*/);
151 function fieldedit($field,$size,$append="")
154 return("<input type=\"text\" name=\"".htmlspecialchars($field)."\" size=\"$size\" value=\""
155 .(!isset($row[$field]) ? "" : htmlspecialchars($row[$field]))."\"$append />");
158 function formconvert($id,$name,$text,$readonly,$anchor,$hiddens=array())
160 global $tb_tree,$row,$winclose;
161 $readonly=(!$readonly ? "" : " readonly=\"readonly\"");
163 $text.=" (uzavre okno)";
164 $row=db_array("select name,PublAuthor,Publication,html from $tb_tree"
165 ." where id=\"".mysql_escape_string($id)."\"");
167 print("<!-- ID=$id -->"
168 ."<form action=\"index.php$anchor\" method=\"POST\">\n"
169 ."<table border=\"0\" width=\"100%\"><tr><td align=\"center\"><table border=\"0\"><tr><td>\n"
170 .fieldedit("name",50,$readonly)
171 ."\n".fieldedit("PublAuthor",50,$readonly)
172 ."<br />\n".fieldedit("Publication",100,$readonly)
173 ."<br /><textarea name=\"html\" rows=\"20\" cols=\"80\">"
174 .(!isset($row["html"]) ? "" : htmlspecialchars($row["html"]))
176 ."</td></tr></table><p> </p>\n"
177 ."<input type=\"submit\" name=\"".htmlspecialchars($name)."\" value=\"".htmlspecialchars($text)."\" />\n"
178 .hiddens($hiddens,true/*doinputs*/)
179 ."</td></tr></table></form>");
180 footer(true /* delimit */);
184 formconvert($id,"update","Aktualizuj zaznam",false/*readonly*/,"#id_$id");
185 if (isset($confirm) && $confirming=="delete")
186 formconvert($id,$confirming,"Opravdu smazat zaznam?",true/*readonly*/,
187 "#family_".db_item("select family_id from $tb_tree where id=\"".mysql_escape_string($id)."\""));
188 if (isset($confirm) && $confirming=="isolate")
189 formconvert($id,$confirming,"Opravdu izolovat zaznam?",true/*readonly*/,"#id_$id");
191 $reset_from_script="this.form.elements['limit_from'].value=0;";
192 print('<form action="index.php" method="GET">'."\n"
193 .'<h1 align="center">'
194 .'<input type="text" name="find" size="40" '
195 .(!isset($find)?"":" value=\"".htmlspecialchars($find)."\"")
196 ." onkeyup=\"$reset_from_script\" onchange=\"$reset_from_script\" onfocus=\"$reset_from_script\""
198 .' <input type="submit" value="Vyhledat" />'."\n"
199 .'</h1><h2 align="center">'."\n"
200 .'Prvni skupina: <input type="text" name="limit_from" size="6" value="'.$limit_from.'" />'."\n"
201 .' '
202 .'Max skupin: '.'<input type="text" name="limit_max" size="6" value="'.$limit_max .'" />'."\n"
203 .'</h2></form>'."\n");
205 footer(true /* delimit */);
209 function fieldquote($prefix,$field,$suffix="")
211 global $row,$fieldquote_tot;
212 if (!isset($row[$field]))
214 return($prefix."<span class=\"$field\">".htmlspecialchars($row[$field])."</span>".$suffix);
217 function formbutton($name,$text,$method="GET",$hidden=array(),$newwin=false,$anchor="")
221 $r.="<table border=\"0\"><tr><td>".formbutton($name,$text,$method,$hidden,false/*newwin*/)."</td><td>";
222 $hidden["winclose"]=1;
225 ."<form action=\"index.php".($anchor=="" ? "" : "#$anchor")."\" method=\"$method\""
226 .(!$newwin ? "" : " target=\"_blank\"").">"
227 ."<input type=\"submit\" "
228 .($name=="" ? "" : " name=\"".htmlspecialchars($name)."\"")
229 ." value=\"".htmlspecialchars($newwin ? "(v okne)" : $text)."\" />"
230 .hiddens($hidden,true/*doinputs*/)
234 $r.="</td></tr></table>";
238 $families=db_query("select distinct family_id from $tb_tree"
239 ." where name like \"".mysql_escape_string($find)."%\""
240 ." order by name limit $limit_from,".($limit_max+1));
242 $arrows="<table border=\"0\" width=\"100%\"><tr><td align=\"center\">\n"
243 ."<table border=\"0\" width=\"80%\"><tr><td align=\"left\">";
245 $arrows.=formbutton("","Predchozi","GET",array("limit_from"=>max(0,$limit_from-$limit_max)));
246 $arrows.="</td><td align=\"right\">";
247 if (mysql_num_rows($families)>$limit_max)
248 $arrows.=formbutton("","Dalsi","GET",array("limit_from"=>$limit_from+$limit_max));
249 $arrows.="</td></tr></table></td></tr></table>";
251 print "$arrows<hr />\n";
253 while (($family_row=mysql_fetch_array($families))) {
256 $family_id=$family_row["family_id"];
257 print("<table border=\"0\" width=\"90%\"><tr><td align=\"right\"><a name=\"family_$family_id\">"
258 ."<form action=\"index.php#family_$family_id\" method=\"POST\">" // WARNING: <form> will break the line!
259 ."Skupina c. <input type=\"text\" size=\"10\" readonly=\"readonly\" value=\"$family_id\" />"
261 ."Zaradit do teto skupiny: <input type=\"text\" name=\"move_src\" size=\"21\" value=\"\" />"
262 ." <input type=\"submit\" name=\"move\" value=\"Zarad\" />\n"
263 .hiddens(array("move_dst"=>$family_id),true/*doinputs*/)
265 ."</td></tr></table>\n");
266 $result=db_query("select id,family_order,name,PublAuthor,Publication,html from $tb_tree"
267 ." where family_id=\"$family_id\""
268 ." order by family_order");
270 while (($row=mysql_fetch_array($result))) {
272 print "<blockquote>";
274 print("<a name=\"id_".$row["id"]."\"><!-- family_order=".$row["family_order"]." --><table border=\"0\" width=\"90%\">");
276 print("<tr><td align=\"left\" valign=\"center\"><table border=\"0\"><tr>");
278 print "<td>•</td>";
283 print("<td>".fieldquote("","name","\n")
284 .fieldquote("","PublAuthor")."</td></tr>");
285 print(fieldquote("<tr>$tabpfx<td>","Publication","</td></tr>"));
286 if (isset($row["html"])) {
287 $import="import: [".$row["id"]."]";
289 $html=eregi_replace("< *"."/? *a( [^>]*)?>","",$html);
290 print("<tr>$tabpfx<td><blockquote><!-- BEGIN $import -->\n".$html."\n<!-- END $import --></blockquote></td></tr>");
292 print("</table></td><td align=\"right\" valign=\"center\"><table border=\"0\">");
293 $l="<tr><td align=\"center\">";
297 $l.formbutton("reorder","^^^ Nahoru ^^^","POST",
298 array("id"=>$row["id"],"reorder_by"=>-1),false/*newwin*/,"family_$family_id").$r)
299 .$l.formbutton("confirm","Smaz zaznam" ,"GET",
300 array("id"=>$row["id"],"confirming"=>"delete"),true/*newwin*/).$r
301 .$l.formbutton("edit" ,"Edituj zaznam","GET",
302 array("id"=>$row["id"]),true/*newwin*/).$r
303 .(mysql_num_rows($result)<=1 ? "" :
304 $l.formbutton("confirm","Izoluj zaznam","GET",
305 array("id"=>$row["id"],"confirming"=>"isolate"),true/*newwin*/).$r)
306 .($order+1 >= mysql_num_rows($result) ? "" :
307 $l.formbutton("reorder","vvv Dolu vvv" ,"POST",
308 array("id"=>$row["id"],"reorder_by"=>+1),false/*newwin*/,"family_$family_id").$r)
309 ."</table></td></tr></table></a>\n"
313 print "</blockquote>";
317 mysql_free_result($result);
320 print "</a>\n"; // <a name="family_X"
322 if ($family_tot >= $limit_max)
325 mysql_free_result($families);
326 print "<hr />$arrows\n";
328 footer(false /* delimit */);