FOSSology  4.4.0
Open Source License Compliance by Open Source Software
admin-tag-manage.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2012-2013 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
8 
9 
15 define("TITLE_ADMIN_TAG_MANAGE", _("Enable/Disable Tag Display"));
16 
18 {
19  function __construct()
20  {
21  $this->Name = "admin_tag_manage";
22  $this->Title = TITLE_ADMIN_TAG_MANAGE;
23  $this->MenuList = "Admin::Tag::Enable/Disable Tag";
24  $this->Version = "1.3";
25  $this->DBaccess = PLUGIN_DB_ADMIN;
26  parent::__construct();
27  }
28 
29 
39  function ManageTag($folder_id, $upload_id, $manage)
40  {
41  global $PG_CONN;
42 
44  if (empty($manage)) {
45  return;
46  }
47  if (empty($folder_id) && empty($upload_id)) {
48  return;
49  }
50 
52  $upload_list = array();
53  if (!empty($upload_id)) {
54  $upload_list[0] = array('upload_pk'=>$upload_id);
55  } else {
56  $upload_list = FolderListUploadsRecurse($folder_id, NULL, Auth::PERM_WRITE); // want to manage all uploads under a folder
57  }
58 
59  foreach ($upload_list as $upload) {
60  $upload_id = $upload['upload_pk'];
61 
62  if ("Enable" === $manage) {
63  $manage_value = false;
64  } else {
65  $manage_value = true;
66  }
67 
69  $sql = "select * from tag_manage where upload_fk = $upload_id and is_disabled = true;";
70  $result = pg_query($PG_CONN, $sql);
71  DBCheckResult($result, $sql, __FILE__, __LINE__);
72  $count = pg_num_rows($result);
73  pg_free_result($result);
74  if (empty($count) && $manage_value == true) { // has not been disabled, and want to disable this upload
75  $sql = "INSERT INTO tag_manage(upload_fk, is_disabled) VALUES($upload_id, true);";
76  $result = pg_query($PG_CONN, $sql);
77  DBCheckResult($result, $sql, __FILE__, __LINE__);
78  pg_free_result($result);
79  } else if ($count == 1 && $manage_value == false) { // has been disabled, and want to enable this upload
80  $sql = "delete from tag_manage where upload_fk = $upload_id;";
81  $result = pg_query($PG_CONN, $sql);
82  DBCheckResult($result, $sql, __FILE__, __LINE__);
83  pg_free_result($result);
84  }
85  }
86  return 1;
87  }
88 
89 
90  public function Output()
91  {
92  $V="";
93  $upload_id = GetParm('upload', PARM_INTEGER);
94  $manage = GetParm('manage', PARM_TEXT);
95  /* If this is a POST, then process the request. */
96  $Folder = GetParm('folder',PARM_INTEGER);
97  if (empty($Folder)) {
98  $Folder = FolderGetTop();
99  }
100 
101  $rc = $this->ManageTag($Folder, $upload_id, $manage);
102  if (1 == $rc) {
103 
104  $text1 = _("all uploads in folder");
105  $text2 = _("in folder");
106  $folder_path = FolderGetName($Folder);
107  $upload_name = GetUploadName($upload_id);
108 
109  if (empty($upload_id)) {
110  $text = $text1;
111  } else {
112  $text = "'$upload_name' $text2";
113  }
114 
115  $Msg = "$manage $text '$folder_path'";
116  $this->vars['message'] = $Msg;
117  // reset form fields
118  }
119 
125  $V .= ActiveHTTPscript("Uploads");
126  $V .= "<script language='javascript'>\n";
127  $V .= "function Uploads_Reply()\n";
128  $V .= " {\n";
129  $V .= " if ((Uploads.readyState==4) && (Uploads.status==200))\n";
130  $V .= " {\n";
131  $V .= " document.getElementById('tagdiv').innerHTML = '<select size=\'10\' name=\'upload\' onChange=\'Tagging_Get(\"" . Traceback_uri() . "?mod=upload_tagging&upload=\" + this.value)\'>' + Uploads.responseText+ '</select><P/>';\n";
132  $V .= " document.getElementById('manage_tag').style.display= 'none';\n";
133  $V .= " document.getElementById('manage_tag_all').style.display= 'block';\n";
134  $V .= " }\n";
135  $V .= " }\n";
136  $V .= "</script>\n";
137 
139  $V .= ActiveHTTPscript("Tagging");
140  $V .= "<script language='javascript'>\n";
141  $V .= "function Tagging_Reply()\n";
142  $V .= " {\n";
143  $V .= " if ((Tagging.readyState==4) && (Tagging.status==200))\n";
144  $V .= " {\n";
145  $V .= " document.getElementById('manage_tag_all').style.display= 'none';\n";
146  $V .= " document.getElementById('manage_tag').style.display= 'block';\n";
147  $V .= " document.getElementById('manage_tag').innerHTML = Tagging.responseText;\n";
148  $V .= " }\n";
149  $V .= " }\n";
150  $V .= "</script>\n";
151 
152  $V .= "<form name='formy' method='post'>\n"; // no url = this url
153  $V .= _("Displaying tags while browsing can be slow for large uploads. This interface allows you to select an upload to disable (or enable) the tag display. By default the tag display is enabled.<p>\n");
154 
155  $V .= "<ol>\n";
156  $text = _("Select the folder containing the upload you wish to enable/disable:");
157  $V .= "<li>$text<br>\n";
158  $V .= "<select name='folder'\n";
159  $V .= "onLoad='Uploads_Get((\"" . Traceback_uri() . "?mod=upload_options&folder=$Folder' ";
160  $V .= "onChange='Uploads_Get(\"" . Traceback_uri() . "?mod=upload_options&folder=\" + this.value)' ";
161  $V .= "class='ui-render-select2'>\n";
162  $V .= FolderListOption(-1,0,1,$Folder);
163  $V .= "</select><P />\n";
164 
165  $text = _("Select the upload to enable/disable:");
166  $V .= "<li>$text<br>";
167  $V .= "<div id='tagdiv'>\n";
168  $V .= "<select size='10' name='upload' onChange='Tagging_Get(\"" . Traceback_uri() . "?mod=upload_tagging&upload=\" + this.value)'>\n";
169  $List = FolderListUploads_perm($Folder, Auth::PERM_WRITE);
170  foreach ($List as $L) {
171  $V .= "<option value='" . $L['upload_pk'] . "'>";
172  $V .= htmlentities($L['name']);
173  if (! empty($L['upload_desc'])) {
174  $V .= " (" . htmlentities($L['upload_desc']) . ")";
175  }
176  $V .= "</option>\n";
177  }
178  $V .= "</select><P />\n";
179  $V .= "</div>\n";
180  $V .= "<div id='manage_tag_all'>";
181  $text = _("Disable");
182  $V .= "<input type='submit' name='manage' value='$text'>\n";
183  $text = _("Enable");
184  $V .= "<input type='submit' name='manage' value='$text'>\n";
185  $V .= "</div>";
186 
187  $V .= "<div id='manage_tag'>";
188  $V .= "</div>";
189 
190  return $V;
191  }
192 }
193 $NewPlugin = new admin_tag_manage;
194 $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
ManageTag($folder_id, $upload_id, $manage)
Enable/Disable Tag on one folder(all uploads under this folder) or one upload.
Output()
This function is called when user output is requested. This function is responsible for content....
__construct()
base constructor. Most plugins will just use this
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
FolderGetName($FolderPk, $Top=-1)
Given a folder_pk, return the full path to this folder.
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
FolderListUploadsRecurse($ParentFolder=-1, $FolderPath='', $perm=Auth::PERM_READ)
Get uploads and folder info, starting from $ParentFolder.
FolderGetTop()
DEPRECATED! Find the top-of-tree folder_pk for the current user.
FolderListUploads_perm($ParentFolder, $perm)
Returns an array of uploads in a folder.
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
GetUploadName($upload_pk)
Get Upload Name through upload id.
Definition: common-ui.php:251
#define PERM_WRITE
Read-Write permission.
Definition: libfossology.h:33
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
Definition: libfossology.h:39
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN