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