FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ui-tags.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2010-2011 Hewlett-Packard Development Company, L.P.
4  SPDX-FileCopyrightText: © 2015 Siemens AG
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
11 
12 
13 class ui_tag extends FO_Plugin
14 {
16  private $uploadDao;
17 
18  function __construct()
19  {
20  $this->Name = "tag";
21  $this->Title = _("Tag");
22  $this->DBaccess = PLUGIN_DB_WRITE;
23  parent::__construct();
24  $this->uploadDao = $GLOBALS['container']->get('dao.upload');
25  }
26 
30  function RegisterMenus()
31  {
32  $text = _("Tag files or containers");
33  menu_insert("Browse-Pfile::Tag",0,$this->Name,$text);
34  } // RegisterMenus()
35 
39  function CreateTag($tag_array)
40  {
41  global $PG_CONN;
42 
43  $Upload = GetParm("upload",PARM_INTEGER);
44  $Item = GetParm("item", PARM_INTEGER);
45 
46  if (empty($Item) || empty($Upload)) {
47  return;
48  }
49 
50  if (isset($tag_array)) {
51  $tag_name = $tag_array["tag_name"];
52  $tag_notes = $tag_array["tag_notes"];
53  $tag_file = $tag_array["tag_file"];
54  $tag_package = $tag_array["tag_package"];
55  $tag_container = $tag_array["tag_container"];
56  $tag_desc = $tag_array["tag_desc"];
57  $tag_dir = $tag_array["tag_dir"];
58  } else {
59  $tag_name = GetParm('tag_name', PARM_TEXT);
60  $tag_notes = GetParm('tag_notes', PARM_TEXT);
61  $tag_file = GetParm('tag_file', PARM_TEXT);
62  $tag_package = GetParm('tag_package', PARM_TEXT);
63  $tag_container = GetParm('tag_container', PARM_TEXT);
64  $tag_desc = GetParm('tag_desc', PARM_TEXT);
65  $tag_dir = GetParm('tag_dir', PARM_TEXT);
66  }
67 
68  if (empty($tag_name)) {
69  $text = _("TagName must be specified. Tag Not created.");
70  return ($text);
71  }
72  /* Need select tag file/package/container */
73  if (empty($tag_dir) && empty($tag_file) && empty($tag_package) &&
74  empty($tag_container)) {
75  $text = _(
76  "Need to select one option (dir/file/package/container) to create tag.");
77  return ($text);
78  }
79 
80  pg_exec("BEGIN;");
81 
82  /* See if the tag already exists */
83  $sql = "SELECT * FROM tag WHERE tag = '$tag_name'";
84  $result = pg_query($PG_CONN, $sql);
85  DBCheckResult($result, $sql, __FILE__, __LINE__);
86  if (pg_num_rows($result) < 1) {
87  pg_free_result($result);
88 
89  $Val = str_replace("'", "''", $tag_name);
90  $Val1 = str_replace("'", "''", $tag_desc);
91  $sql = "INSERT INTO tag (tag,tag_desc) VALUES ('$Val', '$Val1');";
92  $result = pg_query($PG_CONN, $sql);
93  DBCheckResult($result, $sql, __FILE__, __LINE__);
94  pg_free_result($result);
95  } else {
96  pg_free_result($result);
97  }
98 
99  /* Make sure it was added */
100  $sql = "SELECT * FROM tag WHERE tag = '$tag_name' LIMIT 1;";
101  $result = pg_query($PG_CONN, $sql);
102  DBCheckResult($result, $sql, __FILE__, __LINE__);
103  if (pg_num_rows($result) < 1) {
104  pg_free_result($result);
105  $text = _("Failed to create tag.");
106  return ($text);
107  }
108 
109  $row = pg_fetch_assoc($result);
110  $tag_pk = $row["tag_pk"];
111  pg_free_result($result);
112 
113  $pfileArray = array();
114  $i = 0;
115 
116  if (! empty($tag_file)) {
117  /* Get pfile_fk from uploadtree_pk */
118  $sql = "SELECT pfile_fk FROM uploadtree
119  WHERE uploadtree_pk = $Item LIMIT 1";
120  $result = pg_query($PG_CONN, $sql);
121  DBCheckResult($result, $sql, __FILE__, __LINE__);
122  while ($row = pg_fetch_assoc($result)) {
123  $pfileArray[$i] = $row['pfile_fk'];
124  $i ++;
125  }
126  pg_free_result($result);
127  }
128 
129  if (! empty($tag_package)) {
130  /* GetPkgMimetypes */
131  $MimetypeArray = GetPkgMimetypes();
132  $sql = "SELECT distinct pfile.pfile_pk FROM uploadtree, pfile WHERE uploadtree.pfile_fk = pfile.pfile_pk AND (pfile.pfile_mimetypefk = $MimetypeArray[0] OR pfile.pfile_mimetypefk = $MimetypeArray[1] OR pfile.pfile_mimetypefk = $MimetypeArray[2]) AND uploadtree.upload_fk = $Upload AND uploadtree.lft >= (SELECT lft FROM uploadtree WHERE uploadtree_pk = $Item) AND uploadtree.rgt <= (SELECT rgt FROM uploadtree WHERE uploadtree_pk = $Item);";
133  $result = pg_query($PG_CONN, $sql);
134  DBCheckResult($result, $sql, __FILE__, __LINE__);
135  while ($row = pg_fetch_assoc($result)) {
136  $pfileArray[$i] = $row['pfile_pk'];
137  $i ++;
138  }
139  pg_free_result($result);
140  }
141  if (! empty($tag_container)) {
142  $sql = "SELECT distinct pfile_fk FROM uploadtree WHERE upload_fk = $Upload AND lft >= (SELECT lft FROM uploadtree WHERE uploadtree_pk = $Item) AND rgt <= (SELECT rgt FROM uploadtree WHERE uploadtree_pk = $Item) AND ((ufile_mode & (1<<28))=0) AND pfile_fk!=0;";
143  $result = pg_query($PG_CONN, $sql);
144  DBCheckResult($result, $sql, __FILE__, __LINE__);
145  while ($row = pg_fetch_assoc($result)) {
146  $pfileArray[$i] = $row['pfile_fk'];
147  $i ++;
148  }
149  pg_free_result($result);
150  }
151 
152  if (! empty($tag_dir)) {
153  $sql = "SELECT tag_uploadtree_pk FROM tag_uploadtree WHERE tag_fk = $tag_pk AND uploadtree_fk = $Item;";
154  $result = pg_query($PG_CONN, $sql);
155  DBCheckResult($result, $sql, __FILE__, __LINE__);
156  if (pg_num_rows($result) < 1) {
157  pg_free_result($result);
158  /* Add record to tag_uploadtree table */
159  $Val = str_replace("'", "''", $tag_notes);
160  $sql = "INSERT INTO tag_uploadtree (tag_fk,uploadtree_fk,tag_uploadtree_date,tag_uploadtree_text) VALUES ($tag_pk, $Item, now(), '$Val');";
161  $result = pg_query($PG_CONN, $sql);
162  DBCheckResult($result, $sql, __FILE__, __LINE__);
163  pg_free_result($result);
164  } else {
165  $text = _("This Tag already associated with this Directory!");
166  pg_exec("ROLLBACK;");
167  pg_free_result($result);
168  return ($text);
169  }
170  } else {
171  foreach ($pfileArray as $pfile) {
172  $sql = "SELECT tag_file_pk FROM tag_file WHERE tag_fk = $tag_pk AND pfile_fk = $pfile;";
173  $result = pg_query($PG_CONN, $sql);
174  DBCheckResult($result, $sql, __FILE__, __LINE__);
175  if (pg_num_rows($result) < 1) {
176  pg_free_result($result);
177  /* Add record to tag_file table */
178  $Val = str_replace("'", "''", $tag_notes);
179  $sql = "INSERT INTO tag_file (tag_fk,pfile_fk,tag_file_date,tag_file_text) VALUES ($tag_pk, $pfile, now(), '$Val');";
180  $result = pg_query($PG_CONN, $sql);
181  DBCheckResult($result, $sql, __FILE__, __LINE__);
182  pg_free_result($result);
183  } else {
184  $text = _("This Tag already associated with this File!");
185  pg_exec("ROLLBACK;");
186  pg_free_result($result);
187  return ($text);
188  }
189  }
190  }
191  pg_exec("COMMIT;");
192  return (null);
193  }
194 
198  function EditTag()
199  {
200  global $PG_CONN;
201 
202  $Upload = GetParm("upload",PARM_INTEGER);
203  $Item = GetParm("item",PARM_INTEGER);
204 
205  if (empty($Item) || empty($Upload)) {
206  return;
207  }
208 
209  $tag_pk = GetParm('tag_pk', PARM_INTEGER);
210  $tag_file_pk = GetParm('tag_file_pk', PARM_INTEGER);
211  $tag_name = GetParm('tag_name', PARM_TEXT);
212  $tag_notes = GetParm('tag_notes', PARM_TEXT);
213  $tag_file = GetParm('tag_file', PARM_TEXT);
214  $tag_package = GetParm('tag_package', PARM_TEXT);
215  $tag_container = GetParm('tag_container', PARM_TEXT);
216  $tag_desc = GetParm('tag_desc', PARM_TEXT);
217  $tag_dir = GetParm('tag_dir', PARM_TEXT);
218 
219  if (empty($tag_name)) {
220  $text = _("TagName must be specified. Tag Not Updated.");
221  return ($text);
222  } else {
223  /* Check if tag_name has changed and if the new name is already in use */
224  $sql = "SELECT tag FROM tag WHERE tag_pk = '$tag_pk';";
225  $result = pg_query($PG_CONN, $sql);
226  DBCheckResult($result, $sql, __FILE__, __LINE__);
227  $row = pg_fetch_row($result);
228  pg_free_result($result);
229  /* Is Tag name changed */
230  if ($row[0] <> $tag_name) {
231  $sql = "SELECT * FROM tag WHERE tag = '$tag_name'";
232  $result = pg_query($PG_CONN, $sql);
233  DBCheckResult($result, $sql, __FILE__, __LINE__);
234  /* Is new Tag name defined in name space */
235  if (pg_num_rows($result) >= 1) {
236  $row = pg_fetch_row($result);
237  pg_free_result($result);
238  /* Delete old tag association */
239  $this->DeleteTag();
240  /* Existing tag values cannot be changed at this phase. */
241  /* Create new tag association, do not delete old notes! */
242 
243  $tag_data = array("tag_pk" => $row[0], "tag_name" => $row[1], "tag_desc" => $row[3],
244  "tag_notes" => $tag_notes, "tag_file" => $tag_file, "tag_package" => $tag_package,
245  "tag_container" => $tag_container, "tag_dir" => $tag_dir);
246  $this->CreateTag($tag_data);
247  return (null);
248  } else {
249  pg_free_result($result);
250  }
251  }
252  }
253  pg_exec("BEGIN;");
254  /* Update the tag table */
255  $Val = str_replace("'", "''", $tag_name);
256  $Val1 = str_replace("'", "''", $tag_desc);
257  $sql = "UPDATE tag SET tag = '$Val', tag_desc = '$Val1' WHERE tag_pk = $tag_pk;";
258  $result = pg_query($PG_CONN, $sql);
259  DBCheckResult($result, $sql, __FILE__, __LINE__);
260  pg_free_result($result);
261 
262  $Val = str_replace("'", "''", $tag_notes);
263  if (! empty($tag_dir)) {
264  $sql = "UPDATE tag_uploadtree SET tag_uploadtree_date = now(), tag_uploadtree_text = '$Val', tag_fk = $tag_pk WHERE tag_uploadtree_pk = $tag_file_pk;";
265  } else {
266  $sql = "UPDATE tag_file SET tag_file_date = now(), tag_file_text = '$Val', tag_fk = $tag_pk WHERE tag_file_pk = $tag_file_pk;";
267  }
268  $result = pg_query($PG_CONN, $sql);
269  DBCheckResult($result, $sql, __FILE__, __LINE__);
270  pg_free_result($result);
271 
272  pg_exec("COMMIT;");
273  return (null);
274  }
275 
279  function DeleteTag()
280  {
281  global $PG_CONN;
282 
283  $Upload = GetParm("upload",PARM_INTEGER);
284  $Item = GetParm("item",PARM_INTEGER);
285 
286  if (empty($Item) || empty($Upload)) {
287  return;
288  }
289  $tag_file_pk = GetParm('tag_file_pk', PARM_INTEGER);
290 
291  $sql = "SELECT ufile_name, ufile_mode FROM uploadtree
292  WHERE uploadtree_pk = $Item";
293  $result = pg_query($PG_CONN, $sql);
294  DBCheckResult($result, $sql, __FILE__, __LINE__);
295  $row = pg_fetch_assoc($result);
296  $ufile_mode = $row["ufile_mode"];
297  pg_free_result($result);
298 
299  if (Isdir($ufile_mode)) {
300  $sql = "DELETE FROM tag_uploadtree WHERE tag_uploadtree_pk = $tag_file_pk";
301  } else {
302  $sql = "DELETE FROM tag_file WHERE tag_file_pk = $tag_file_pk";
303  }
304  $result = pg_query($PG_CONN, $sql);
305  DBCheckResult($result, $sql, __FILE__, __LINE__);
306  pg_free_result($result);
307  }
308 
314  function ShowExistTags($Upload,$Uploadtree_pk)
315  {
316  global $PG_CONN;
317  $VE = "";
318  $VE = _("<h3>Current Tags:</h3>\n");
319  $sql = "SELECT tag_pk, tag, tag_desc, tag_file_pk, tag_file_date, tag_file_text FROM tag, tag_file, uploadtree WHERE tag.tag_pk = tag_file.tag_fk AND tag_file.pfile_fk = uploadtree.pfile_fk AND uploadtree.uploadtree_pk = $Uploadtree_pk UNION SELECT tag_pk, tag, tag_desc, tag_uploadtree_pk AS tag_file_pk, tag_uploadtree_date AS tag_file_date, tag_uploadtree_text AS tag_file_text FROM tag, tag_uploadtree WHERE tag.tag_pk = tag_uploadtree.tag_fk AND tag_uploadtree.uploadtree_fk = $Uploadtree_pk;";
320  $result = pg_query($PG_CONN, $sql);
321  DBCheckResult($result, $sql, __FILE__, __LINE__);
322  if (pg_num_rows($result) > 0) {
323  $VE .= "<table border=1>\n";
324  $text1 = _("Tag");
325  $text2 = _("Tag Description");
326  $text3 = _("Tag Date");
327  $VE .= "<tr><th>$text1</th><th>$text2</th><th>$text3</th><th></th></tr>\n";
328  while ($row = pg_fetch_assoc($result)) {
329  $VE .= "<tr><td align='center'>" . $row['tag'] . "</td><td align='center'>" . $row['tag_desc'] . "</td><td align='center'>" . substr($row['tag_file_date'],0,19) . "</td>";
330  if ($this->uploadDao->isEditable($Upload, Auth::getGroupId())) {
331  $VE .= "<td align='center'><a href='" . Traceback_uri() . "?mod=tag&action=edit&upload=$Upload&item=$Uploadtree_pk&tag_file_pk=" . $row['tag_file_pk'] . "'>View/Edit</a>|<a href='" . Traceback_uri() . "?mod=tag&action=delete&upload=$Upload&item=$Uploadtree_pk&tag_file_pk=" . $row['tag_file_pk'] . "'>Delete</a></td></tr>\n";
332  } else {
333  $nopermtext = _("No permission to edit tag.");
334  $VE .= "<td align='center'>$nopermtext</td></tr>\n";
335  }
336  }
337  $VE .= "</table><p>\n";
338  }
339  pg_free_result($result);
340 
341  return $VE;
342  }
343 
347  function ShowAjaxPage()
348  {
349  $VA = "";
350  /* Create AJAX javascript */
351  $VA .= ActiveHTTPscript("Tags");
352  $VA .= "<script language='javascript'>\n";
353  $VA .= "var swtemp=0,objtemp;\n";
354  $VA .= "function mouseout(o){\n";
355  $VA .= " o.style.display = \"none\";\n";
356  $VA .= " swtemp = 0;\n";
357  $VA .= "}\n";
358  $VA .= "function removediv(inputid){\n";
359  $VA .= " getobj(inputid+\"mydiv\").style.display=\"none\";\n";
360  $VA .= "}\n";
361  $VA .= "function creatediv(_parent,_element,_id,_css){\n";
362  $VA .= " var newObj = document.createElement(_element);\n";
363  $VA .= " if(_id && _id!=\"\")newObj.id=_id;\n";
364  $VA .= " if(_css && _css!=\"\"){\n";
365  $VA .= " newObj.setAttribute(\"style\",_css);\n";
366  $VA .= " newObj.style.cssText = _css;\n";
367  $VA .= " }\n";
368  $VA .= " if(_parent && _parent!=\"\"){\n";
369  $VA .= " var theObj=getobj(_parent);\n";
370  $VA .= " var parent = theObj.parentNode;\n";
371  $VA .= " if(parent.lastChild == theObj){\n";
372  $VA .= " theObj.appendChild(newObj);\n";
373  $VA .= " }\n";
374  $VA .= " else{\n";
375  $VA .= " theObj.insertBefore(newObj, theObj.nextSibling);\n";
376  $VA .= " }\n";
377  $VA .= " }\n";
378  $VA .= " else document.body.appendChild(newObj);\n";
379  $VA .= "}\n";
380  $VA .= "function getobj(o){\n";
381  $VA .= " return document.getElementById(o);\n";
382  $VA .= "}\n";
383  $VA .= "function Tags_Reply()\n";
384  $VA .= "{\n";
385  $VA .= " if ((Tags.readyState==4) && (Tags.status==200))\n";
386  $VA .= " {\n";
387  $VA .= " var list = Tags.responseText;\n";
388  $VA .= " var text_list = list.split(\",\")\n";
389  $VA .= " var inputid = getobj(\"tag_name\");\n";
390  $VA .= " if (swtemp==1){getobj(objtemp+\"mydiv\").style.display=\"none\";}\n";
391  $VA .= " if (!getobj(inputid+\"mydiv\") && list!=\"\"){\n";
392  $VA .= " var divcss=\"width:240px;font-size:12px;position:absolute;left:\"+(inputid.offsetLeft+0)+\"px;top:\"+(inputid.offsetTop+23)+\"px;border:1px solid\";\n";
393  $VA .= " creatediv(\"\",\"div\",inputid+\"mydiv\",divcss);\n";
394  $VA .= " for (var i=0;i<text_list.length-1;i++){\n";
395  $VA .= " creatediv(inputid+\"mydiv\",\"li\",inputid+\"li\"+i,\"color:#000;background:#fff;list-style-type:none;padding:9px;margin:0;CURSOR:pointer\");\n";
396  $VA .= " getobj(inputid+\"li\"+i).innerHTML=text_list[i];\n";
397  $VA .= " getobj(inputid+\"li\"+i).onmouseover=function(){this.style.background=\"#eee\";}\n";
398  $VA .= " getobj(inputid+\"li\"+i).onmouseout=function(){this.style.background=\"#fff\"}\n";
399  $VA .= " getobj(inputid+\"li\"+i).onclick=function(){\n";
400  $VA .= " inputid.value=this.innerHTML;\n";
401  $VA .= " removediv(inputid);\n";
402  $VA .= " }\n";
403  $VA .= " }\n";
404  $VA .= " }\n";
405  $VA .= " var newdiv=getobj(inputid+\"mydiv\");\n";
406  //$VA .= " newdiv.onclick=function(){removediv(inputid);}\n";
407  $VA .= " document.body.onclick = function(){removediv(inputid);}\n";
408  $VA .= " newdiv.onblur=function(){mouseout(this);}\n";
409  $VA .= " newdiv.style.display=\"block\";\n";
410  $VA .= " swtemp=1;\n";
411  $VA .= " objtemp=inputid;\n";
412  $VA .= " newdiv.focus();\n";
413  $VA .= " }\n";
414  $VA .= "}\n;";
415  $VA .= "</script>\n";
416 
417  return $VA;
418  }
419 
423  function ShowCreateTagPage($Upload,$Item)
424  {
425  global $PG_CONN;
426  $VC = "";
427  $VC .= _("<h3>Create Tag:</h3>\n");
428 
429  /* Get ufile_name from uploadtree_pk */
430  $sql = "SELECT ufile_name, ufile_mode FROM uploadtree
431  WHERE uploadtree_pk = $Item";
432  $result = pg_query($PG_CONN, $sql);
433  DBCheckResult($result, $sql, __FILE__, __LINE__);
434  $row = pg_fetch_assoc($result);
435  $ufile_name = $row["ufile_name"];
436  $ufile_mode = $row["ufile_mode"];
437  pg_free_result($result);
438 
439  $VC.= "<form name='form' method='POST' action='" . Traceback_uri() ."?mod=tag&upload=$Upload&item=$Item'>\n";
440 
441  $VC .= "<p>";
442  $text = _("Tag");
443  $VC .= "$text: <input type='text' id='tag_name' name='tag_name' maxlength='32' utocomplete='off' onclick='Tags_Get(\"". Traceback_uri() . "?mod=tag_get&uploadtree_pk=$Item\")'/> ";
444 
445  /****** Permission comments: if user don't have add or high permission, can't see this check box ******/
446  //$VC .= "<input type='checkbox' name='tag_add' value='1'/>";
447  //$VC .= _("Check to confirm this is a new tag.");
448  $VC .= "</p>";
449  $text = _("Tag description:");
450  $VC .= "<p>$text <input type='text' name='tag_desc'/></p>";
451  $VC .= _("<p>Notes:</p>");
452  $VC .= "<p><textarea rows='10' cols='80' name='tag_notes'></textarea></p>";
453 
454  if (Isdir($ufile_mode)) {
455  $VC .= "<p><input type='hidden' name='tag_dir' value='1'/></p>";
456  } else if (Iscontainer($ufile_mode)) {
457  /* Recursively tagging UI part comment out */
458  /*
459  $text = _("Tag this files only.");
460  $VC .= "<p><input type='checkbox' name='tag_file' value='1' checked/>$text</p>";
461  $text = _("Tag all packages (source and binary) in this container tree.");
462  $VC .= "<p><input type='checkbox' name='tag_package' value='1'/> $text</p>";
463  $text = _("Tag every file in this container tree.");
464  $VC .= "<p><input type='checkbox' name='tag_container' value='1'/> $text</p>";
465  */
466  $VC .= "<p><input type='hidden' name='tag_file' value='1'/></p>";
467  } else {
468  $VC .= "<p><input type='hidden' name='tag_file' value='1'/></p>";
469  }
470  $text = _("Create");
471  $VC .= "<input type='hidden' name='action' value='add'/>\n";
472  $VC .= "<input type='submit' value='$text'>\n";
473  $VC .= "</form>\n";
474 
475  return $VC;
476  }
477 
481  function ShowEditTagPage($Upload,$Item)
482  {
483  global $PG_CONN;
484  $VEd = "";
485  $text = _("Create New Tag");
486  $VEd .= "<h4><a href='" . Traceback_uri() . "?mod=tag&upload=$Upload&item=$Item'>$text</a><h4>";
487 
488  $VEd .= _("<h3>Edit Tag:</h3>\n");
489  $tag_file_pk = GetParm("tag_file_pk",PARM_INTEGER);
490 
491  /* Get ufile_name from uploadtree_pk */
492  $sql = "SELECT ufile_name, ufile_mode FROM uploadtree
493  WHERE uploadtree_pk = $Item";
494  $result = pg_query($PG_CONN, $sql);
495  DBCheckResult($result, $sql, __FILE__, __LINE__);
496  $row = pg_fetch_assoc($result);
497  $ufile_name = $row["ufile_name"];
498  $ufile_mode = $row["ufile_mode"];
499  pg_free_result($result);
500 
501  /* Get all information about $tag_file_pk (tag_file/tag_uploadtree table)*/
502  if (Isdir($ufile_mode)) {
503  $sql = "SELECT tag_pk, tag_uploadtree_text, tag, tag_desc FROM tag_uploadtree, tag WHERE tag_uploadtree_pk=$tag_file_pk AND tag_uploadtree.tag_fk = tag.tag_pk";
504  } else {
505  $sql = "SELECT tag_pk, tag_file_text, tag, tag_desc FROM tag_file, tag WHERE tag_file_pk=$tag_file_pk AND tag_file.tag_fk = tag.tag_pk";
506  }
507  $result = pg_query($PG_CONN, $sql);
508  DBCheckResult($result, $sql, __FILE__, __LINE__);
509  $row = pg_fetch_assoc($result);
510  $tag_pk = $row['tag_pk'];
511  $tag = $row['tag'];
512  if (Isdir($ufile_mode)) {
513  $tag_notes = $row['tag_uploadtree_text'];
514  } else {
515  $tag_notes = $row['tag_file_text'];
516  }
517  $tag_desc = $row['tag_desc'];
518  pg_free_result($result);
519 
520  $VEd.= "<form name='form' method='POST' action='" . Traceback_uri() ."?mod=tag&upload=$Upload&item=$Item'>\n";
521  $VEd .= "<p>";
522  $text = _("Tag");
523  $VEd .= "$text: <input type='text' id='tag_name' name='tag_name' autocomplete='off' onclick='Tags_Get(\"". Traceback_uri() . "?mod=tag_get&uploadtree_pk=$Item\")' value=\"$tag\"/> ";
524  $text = _("Tag description:");
525  $VEd .= "<p>$text <input type='text' name='tag_desc' value=\"$tag_desc\"/></p>";
526  $VEd .= _("<p>Notes:</p>");
527  $VEd .= "<p><textarea rows='10' cols='80' name='tag_notes'>$tag_notes</textarea></p>";
528 
529  if (Isdir($ufile_mode)) {
530  $VEd .= "<p><input type='hidden' name='tag_dir' value='1'/></p>";
531  } else if (Iscontainer($ufile_mode)) {
532  /*
533  $text = _("Tag this files only.");
534  $VEd .= "<p><input type='checkbox' name='tag_file' value='1' checked/>$text</p>";
535  $text = _("Tag all packages (source and binary) in this container tree.");
536  $VEd .= "<p><input type='checkbox' name='tag_package' value='1'/> $text</p>";
537  $text = _("Tag every file in this container tree.");
538  $VEd .= "<p><input type='checkbox' name='tag_container' value='1'/> $text</p>";
539  */
540  $VEd .= "<p><input type='hidden' name='tag_file' value='1'/></p>";
541  } else {
542  $VEd .= "<p><input type='hidden' name='tag_file' value='1'/></p>";
543  }
544  $text = _("Save");
545  $VEd .= "<input type='hidden' name='action' value='update'/>\n";
546  $VEd .= "<input type='hidden' name='tag_pk' value='$tag_pk'/>\n";
547  $VEd .= "<input type='hidden' name='tag_file_pk' value='$tag_file_pk'/>\n";
548  $VEd .= "<input type='submit' value='$text'>\n";
549  $VEd .= "</form>\n";
550 
551  return $VEd;
552  }
553 
557  function ShowDeleteTagPage($Upload,$Item)
558  {
559  global $PG_CONN;
560  $VD = "";
561  $VD .= _("<h3>Delete Tag:</h3>\n");
562 
563  /* Get ufile_name from uploadtree_pk */
564  $sql = "SELECT ufile_name, ufile_mode FROM uploadtree
565  WHERE uploadtree_pk = $Item";
566  $result = pg_query($PG_CONN, $sql);
567  DBCheckResult($result, $sql, __FILE__, __LINE__);
568  $row = pg_fetch_assoc($result);
569  $ufile_name = $row["ufile_name"];
570  $ufile_mode = $row["ufile_mode"];
571  pg_free_result($result);
572 
573  $sql = "SELECT tag_pk, tag, tag_file_pk, tag_file_date, tag_file_text FROM tag, tag_file, uploadtree WHERE tag.tag_pk = tag_file.tag_fk AND tag_file.pfile_fk = uploadtree.pfile_fk AND uploadtree.uploadtree_pk = $Item;";
574  $result = pg_query($PG_CONN, $sql);
575  DBCheckResult($result, $sql, __FILE__, __LINE__);
576  if (pg_num_rows($result) > 0) {
577  $VD .= "<form name='form' method='POST' action='" . Traceback_uri() ."?mod=tag&upload=$Upload&item=$Item'>\n";
578  $VD .= "<select multiple size='10' name='tag_file_pk[]'>\n";
579  while ($row = pg_fetch_assoc($result)) {
580  $VD .= "<option value='" . $row['tag_file_pk'] . "'>" . "-" . $row['tag'] . "</option>\n";
581  }
582  $VD .= "</select>\n";
583  if (Iscontainer($ufile_mode)) {
584  $text = _("Delete Tag only for this file.");
585  $VD .= "<p><input type='checkbox' name='tag_file' value='1' checked/>$text</p>";
586  $text = _("Delete Tag for all packages (source and binary) in this container tree.");
587  $VD .= "<p><input type='checkbox' name='tag_package' value='1'/>$text</p>";
588  //$text = _("Delete Tag for every file in this container tree.");
589  //$VD .= "<p><input type='checkbox' name='tag_container' value='1'/> $text</p>";
590  } else {
591  $VD .= "<p><input type='hidden' name='tag_file' value='1'/></p>";
592  }
593  $text = _("Delete");
594  $VD .= "<input type='hidden' name='action' value='delete'/>\n";
595  $VD .= "<input type='submit' value='$text'>\n";
596  $VD .= "</form>\n";
597  }
598  pg_free_result($result);
599 
600  return ($VD);
601  }
602 
608  function ShowTaggingPage($action,$ShowHeader=0)
609  {
610  $V = "";
611  $Upload = GetParm("upload",PARM_INTEGER);
612  $Item = GetParm("item",PARM_INTEGER);
613 
614  if (empty($Item) || empty($Upload)) {
615  return;
616  }
617 
618  /**********************************
619  Display micro header
620  **********************************/
621  if ($ShowHeader) {
622  $V .= Dir2Browse("browse",$Item,NULL,1,"Browse");
623  }
624 
625  $V .= $this->ShowExistTags($Upload,$Item);
626  $V .= $this->ShowAjaxPage();
627 
628  if ($action == 'edit') {
629  $V .= $this->ShowEditTagPage($Upload,$Item);
630  } else {
631  /* Show create tag page */
632  if ($this->uploadDao->isEditable($Upload, Auth::getGroupId())) {
633  $V .= $this->ShowCreateTagPage($Upload, $Item);
634  } else {
635  $nopermtext = _("You do not have permission to tag this upload.");
636  $V .= $nopermtext;
637  }
638  }
639  return($V);
640  }
641 
642 
643  public function Output()
644  {
645  $V="";
646  $action = GetParm('action', PARM_TEXT);
647 
648  if ($action == 'add') {
649  $rc = $this->CreateTag(null);
650  if (! empty($rc)) {
651  $text = _("Create Tag Failed");
652  $this->vars['message'] = "$text: $rc";
653  } else {
654  $this->vars['message'] = _("Create Tag Successful!");
655  }
656  }
657  if ($action == 'update') {
658  $rc = $this->EditTag();
659  if (! empty($rc)) {
660  $text = _("Edit Tag Failed");
661  $this->vars['message'] = "$text: $rc";
662  } else {
663  $this->vars['message'] = _("Edit Tag Successful!");
664  }
665  }
666  if ($action == 'delete') {
667  $rc = $this->DeleteTag();
668  if (! empty($rc)) {
669  $text = _("Delete Tag Failed");
670  $this->vars['message'] = "$text: $rc";
671  } else {
672  $this->vars['message'] = _("Delete Tag Successful!");
673  }
674  }
675  $V .= $this->ShowTaggingPage($action,1);
676 
677  return $V;
678  }
679 }
680 
681 $NewPlugin = new ui_tag();
682 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:57
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
ShowDeleteTagPage($Upload, $Item)
Display the delete tag page.
Definition: ui-tags.php:557
EditTag()
Edit exsit Tag.
Definition: ui-tags.php:198
ShowEditTagPage($Upload, $Item)
Display the edit tag page.
Definition: ui-tags.php:481
__construct()
base constructor. Most plugins will just use this
Definition: ui-tags.php:18
ShowAjaxPage()
Display the ajax page.
Definition: ui-tags.php:347
DeleteTag()
Delete exsit Tag.
Definition: ui-tags.php:279
ShowTaggingPage($action, $ShowHeader=0)
Display the tagging page.
Definition: ui-tags.php:608
ShowCreateTagPage($Upload, $Item)
Display the create tag page.
Definition: ui-tags.php:423
ShowExistTags($Upload, $Uploadtree_pk)
Show all tags about.
Definition: ui-tags.php:314
RegisterMenus()
Customize submenus.
Definition: ui-tags.php:30
Output()
This function is called when user output is requested. This function is responsible for content....
Definition: ui-tags.php:643
CreateTag($tag_array)
Add a new Tag.
Definition: ui-tags.php:39
ActiveHTTPscript($RequestName, $IncludeScriptTags=1)
Given a function name, create the JavaScript needed for doing the request.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:187
Isdir($mode)
Definition: common-dir.php:20
Iscontainer($mode)
Definition: common-dir.php:38
Dir2Browse($Mod, $UploadtreePk, $LinkLast=NULL, $ShowBox=1, $ShowMicro=NULL, $Enumerate=-1, $PreText='', $PostText='', $uploadtree_tablename="uploadtree")
Get an html linked string of a file browse path.
Definition: common-dir.php:263
menu_insert($Path, $LastOrder=0, $URI=NULL, $Title=NULL, $Target=NULL, $HTML=NULL)
Given a Path, order level for the last item, and optional plugin name, insert the menu item.
Traceback_uri()
Get the URI without query to this location.
Definition: common-parm.php:97
const PARM_TEXT
Definition: common-parm.php:20
const PARM_INTEGER
Definition: common-parm.php:14
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:46
GetPkgMimetypes()
Get package mimetype.
Definition: common-pkg.php:22
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
Definition: libfossology.h:38
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN