FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
admin-tag-manage.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2012-2013 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
19 
20 
26 define("TITLE_ADMIN_TAG_MANAGE", _("Enable/Disable Tag Display"));
27 
29 {
30  function __construct()
31  {
32  $this->Name = "admin_tag_manage";
33  $this->Title = TITLE_ADMIN_TAG_MANAGE;
34  $this->MenuList = "Admin::Tag::Enable/Disable Tag";
35  $this->Version = "1.3";
36  $this->DBaccess = PLUGIN_DB_ADMIN;
37  parent::__construct();
38  }
39 
40 
50  function ManageTag($folder_id, $upload_id, $manage)
51  {
52  global $PG_CONN;
53 
55  if (empty($manage)) {
56  return;
57  }
58  if (empty($folder_id) && empty($upload_id)) {
59  return;
60  }
61 
63  $upload_list = array();
64  if (!empty($upload_id)) {
65  $upload_list[0] = array('upload_pk'=>$upload_id);
66  } else {
67  $upload_list = FolderListUploadsRecurse($folder_id, NULL, Auth::PERM_WRITE); // want to manage all uploads under a folder
68  }
69 
70  foreach ($upload_list as $upload) {
71  $upload_id = $upload['upload_pk'];
72 
73  if ("Enable" === $manage) {
74  $manage_value = false;
75  } else {
76  $manage_value = true;
77  }
78 
80  $sql = "select * from tag_manage where upload_fk = $upload_id and is_disabled = true;";
81  $result = pg_query($PG_CONN, $sql);
82  DBCheckResult($result, $sql, __FILE__, __LINE__);
83  $count = pg_num_rows($result);
84  pg_free_result($result);
85  if (empty($count) && $manage_value == true) { // has not been disabled, and want to disable this upload
86  $sql = "INSERT INTO tag_manage(upload_fk, is_disabled) VALUES($upload_id, true);";
87  $result = pg_query($PG_CONN, $sql);
88  DBCheckResult($result, $sql, __FILE__, __LINE__);
89  pg_free_result($result);
90  } else if ($count == 1 && $manage_value == false) { // has been disabled, and want to enable this upload
91  $sql = "delete from tag_manage where upload_fk = $upload_id;";
92  $result = pg_query($PG_CONN, $sql);
93  DBCheckResult($result, $sql, __FILE__, __LINE__);
94  pg_free_result($result);
95  }
96  }
97  return 1;
98  }
99 
100 
101  public function Output()
102  {
103  $V="";
104  $upload_id = GetParm('upload', PARM_INTEGER);
105  $manage = GetParm('manage', PARM_TEXT);
106  /* If this is a POST, then process the request. */
107  $Folder = GetParm('folder',PARM_INTEGER);
108  if (empty($Folder)) {
109  $Folder = FolderGetTop();
110  }
111 
112  $rc = $this->ManageTag($Folder, $upload_id, $manage);
113  if (1 == $rc) {
114 
115  $text1 = _("all uploads in folder");
116  $text2 = _("in folder");
117  $folder_path = FolderGetName($Folder);
118  $upload_name = GetUploadName($upload_id);
119 
120  if (empty($upload_id)) {
121  $text = $text1;
122  } else {
123  $text = "'$upload_name' $text2";
124  }
125 
126  $Msg = "$manage $text '$folder_path'";
127  $this->vars['message'] = $Msg;
128  // reset form fields
129  }
130 
136  $V .= ActiveHTTPscript("Uploads");
137  $V .= "<script language='javascript'>\n";
138  $V .= "function Uploads_Reply()\n";
139  $V .= " {\n";
140  $V .= " if ((Uploads.readyState==4) && (Uploads.status==200))\n";
141  $V .= " {\n";
142  $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";
143  $V .= " document.getElementById('manage_tag').style.display= 'none';\n";
144  $V .= " document.getElementById('manage_tag_all').style.display= 'block';\n";
145  $V .= " }\n";
146  $V .= " }\n";
147  $V .= "</script>\n";
148 
150  $V .= ActiveHTTPscript("Tagging");
151  $V .= "<script language='javascript'>\n";
152  $V .= "function Tagging_Reply()\n";
153  $V .= " {\n";
154  $V .= " if ((Tagging.readyState==4) && (Tagging.status==200))\n";
155  $V .= " {\n";
156  $V .= " document.getElementById('manage_tag_all').style.display= 'none';\n";
157  $V .= " document.getElementById('manage_tag').style.display= 'block';\n";
158  $V .= " document.getElementById('manage_tag').innerHTML = Tagging.responseText;\n";
159  $V .= " }\n";
160  $V .= " }\n";
161  $V .= "</script>\n";
162 
163  $V .= "<form name='formy' method='post'>\n"; // no url = this url
164  $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");
165 
166  $V .= "<ol>\n";
167  $text = _("Select the folder containing the upload you wish to enable/disable:");
168  $V .= "<li>$text<br>\n";
169  $V .= "<select name='folder'\n";
170  $V .= "onLoad='Uploads_Get((\"" . Traceback_uri() . "?mod=upload_options&folder=$Folder' ";
171  $V .= "onChange='Uploads_Get(\"" . Traceback_uri() . "?mod=upload_options&folder=\" + this.value)' ";
172  $V .= "class='ui-render-select2'>\n";
173  $V .= FolderListOption(-1,0,1,$Folder);
174  $V .= "</select><P />\n";
175 
176  $text = _("Select the upload to enable/disable:");
177  $V .= "<li>$text<br>";
178  $V .= "<div id='tagdiv'>\n";
179  $V .= "<select size='10' name='upload' onChange='Tagging_Get(\"" . Traceback_uri() . "?mod=upload_tagging&upload=\" + this.value)'>\n";
180  $List = FolderListUploads_perm($Folder, Auth::PERM_WRITE);
181  foreach ($List as $L) {
182  $V .= "<option value='" . $L['upload_pk'] . "'>";
183  $V .= htmlentities($L['name']);
184  if (! empty($L['upload_desc'])) {
185  $V .= " (" . htmlentities($L['upload_desc']) . ")";
186  }
187  $V .= "</option>\n";
188  }
189  $V .= "</select><P />\n";
190  $V .= "</div>\n";
191  $V .= "<div id='manage_tag_all'>";
192  $text = _("Disable");
193  $V .= "<input type='submit' name='manage' value='$text'>\n";
194  $text = _("Enable");
195  $V .= "<input type='submit' name='manage' value='$text'>\n";
196  $V .= "</div>";
197 
198  $V .= "<div id='manage_tag'>";
199  $V .= "</div>";
200 
201  return $V;
202  }
203 }
204 $NewPlugin = new admin_tag_manage;
205 $NewPlugin->Initialize();
Traceback_uri()
Get the URI without query to this location.
const PARM_TEXT
Definition: common-parm.php:31
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
Definition: libfossology.h:51
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
FolderListUploads_perm($ParentFolder, $perm)
Returns an array of uploads in a folder.
ActiveHTTPscript($RequestName, $IncludeScriptTags=1)
Given a function name, create the JavaScript needed for doing the request.
FolderGetName($FolderPk, $Top=-1)
Given a folder_pk, return the full path to this folder.
ManageTag($folder_id, $upload_id, $manage)
Enable/Disable Tag on one folder(all uploads under this folder) or one upload.
FolderGetTop()
DEPRECATED! Find the top-of-tree folder_pk for the current user.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
FolderListUploadsRecurse($ParentFolder=-1, $FolderPath= '', $perm=Auth::PERM_READ)
Get uploads and folder info, starting from $ParentFolder.
const PARM_INTEGER
Definition: common-parm.php:25
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67
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
GetUploadName($upload_pk)
Get Upload Name through upload id.
Definition: common-ui.php:237
#define PERM_WRITE
Read-Write permission.
Definition: libfossology.h:45