FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
common-tags.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************
3  Copyright (C) 2010-2013 Hewlett-Packard Development Company, L.P.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License version 2.1 as published by the Free Software Foundation.
8 
9  This library 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 GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this library; if not, write to the Free Software Foundation, Inc.0
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  ***********************************************************/
18 
21 
37 function GetAllTags($Item, $Recurse=true, $uploadtree_tablename="uploadtree")
38 {
39  if (empty($Item)) {
40  return array();
41  }
42 
43  global $container;
44 
45  $dbManager = $container->get('db.manager');
46 
47  $stmt = __METHOD__.".$uploadtree_tablename";
48  $sql = "select true from tag_manage, $uploadtree_tablename u where is_disabled = true and tag_manage.upload_fk = u.upload_fk and u.uploadtree_pk = $1";
49  $tagDisabled = $dbManager->getSingleRow($sql, array($Item), $stmt);
50  if ($tagDisabled !== false) {
51  return array();
52  }
53 
54  $stmt2 = $stmt.'.lftRgt';
55  $sql = "select lft,rgt, upload_fk from $uploadtree_tablename where uploadtree_pk=$1";
56  $uploadtree_row = $dbManager->getSingleRow($sql,array($Item), $stmt2);
57 
58  $params = array($Item, $uploadtree_row['upload_fk']);
59  if ($Recurse) {
60  $Condition = " lft between $3 and $4 ";
61  $stmt .= ".recurse";
62  $params[] = $uploadtree_row['lft'];
63  $params[] = $uploadtree_row['rgt'];
64  } else {
65  $Condition = " uploadtree.uploadtree_pk=$1 ";
66  }
67 
68  /* Get list of unique tag_pk's for this item */
69  $sql = "SELECT distinct(tag_fk) as tag_pk FROM tag_file, $uploadtree_tablename WHERE tag_file.pfile_fk = {$uploadtree_tablename}.pfile_fk and upload_fk=$2 AND $Condition UNION SELECT tag_fk as tag_pk FROM tag_uploadtree WHERE tag_uploadtree.uploadtree_fk = $1";
70 
71  $stmt1 = $stmt.'.theTags';
72  $dbManager->prepare($stmt1,"select tag.tag AS tag_name, tag.tag_pk from tag,($sql) subquery where tag.tag_pk=subquery.tag_pk group by tag.tag_pk, tag.tag");
73  $res = $dbManager->execute($stmt1,$params);
74  $List = $dbManager->fetchAll($res);
75  $dbManager->freeResult($res);
76 
77  return($List);
78 } // GetAllTags()
79 
80 
96 function Array2SingleSelectTag($KeyValArray, $SLName="unnamed", $SelectedVal= "",
97 $FirstEmpty=false, $SelElt=true, $Options="")
98 {
99  $str ="\n<select name='$SLName' $Options>\n";
100  if ($FirstEmpty) {
101  $str .= "<option value='' > \n";
102  }
103  foreach ($KeyValArray as $key => $val) {
104  if ($SelElt == true) {
105  $SELECTED = ($val == $SelectedVal) ? "SELECTED" : "";
106  } else {
107  $SELECTED = ($key == $SelectedVal) ? "SELECTED" : "";
108  }
110  // $perm = GetTaggingPerms($_SESSION['UserId'],$key);
111  // if ($perm > 1) {
112  $str .= "<option value='$key' $SELECTED>$val\n";
113  // }
114  }
115  $str .= "</select>";
116  return $str;
117 }
118 
130 function TagSelect($SLName="unnamed", $SelectedVal= "",
131  $FirstEmpty=false, $SelElt=true)
132 {
133  /* Find all the tag namespaces for this user */
134  /* UNUSED
135  $sql = "select lft,rgt from uploadtree where uploadtree_pk=$Item";
136  $result = pg_query($PG_CONN, $sql);
137  DBCheckResult($result, $sql, __FILE__, __LINE__);
138  $uploadtree_row = pg_fetch_assoc($result);
139  */
140 
141  /* Find all the tags for this namespace */
142 
143  $str ="\n<select name='$SLName'>\n";
144  if ($FirstEmpty) {
145  $str .= "<option value='' > \n";
146  }
147  foreach ($KeyValArray as $key => $val) {
148  if ($SelElt == true) {
149  $SELECTED = ($val == $SelectedVal) ? "SELECTED" : "";
150  } else {
151  $SELECTED = ($key == $SelectedVal) ? "SELECTED" : "";
152  }
153  $perm = GetTaggingPerms($_SESSION['UserId'],$key);
154  if ($perm > 1) {
155  $str .= "<option value='$key' $SELECTED>$val\n";
156  }
157  }
158  $str .= "</select>";
159  return $str;
160 }
161 
169 function TagFilter(&$UploadtreeRows, $tag_pk, $uploadtree_tablename)
170 {
171  foreach ($UploadtreeRows as $key=>$UploadtreeRow) {
172  $found = false;
173  $tags = GetAllTags($UploadtreeRow["uploadtree_pk"], true, $uploadtree_tablename);
174  foreach ($tags as $tagArray) {
175  if ($tagArray['tag_pk'] == $tag_pk) {
176  $found = true;
177  break;
178  }
179  if ($found) {
180  break;
181  }
182  }
183  if ($found == false) {
184  unset($UploadtreeRows[$key]);
185  }
186  }
187 }
188 
196 function TagStatus($upload_id)
197 {
198  global $PG_CONN, $container;
200  $uploadDao = $container->get('dao.upload');
201  if (!$uploadDao->isEditable($upload_id, Auth::getGroupId())) {
202  return 0;
203  }
204 
205  /* check if this upload has been disabled */
206  $sql = "select tag_manage_pk from tag_manage where upload_fk = $upload_id and is_disabled = true;";
207  $result = pg_query($PG_CONN, $sql);
208  DBCheckResult($result, $sql, __FILE__, __LINE__);
209  $count = pg_num_rows($result);
210  pg_free_result($result);
211  return ($count > 0) ? 0 : 1;
212 }
GetAllTags($Item, $Recurse=true, $uploadtree_tablename="uploadtree")
Get all Tags of this uploadtree_pk.
Definition: common-tags.php:37
TagSelect($SLName="unnamed", $SelectedVal="", $FirstEmpty=false, $SelElt=true)
Build a single choice select pulldown for the user to select both a tag.
Array2SingleSelectTag($KeyValArray, $SLName="unnamed", $SelectedVal="", $FirstEmpty=false, $SelElt=true, $Options="")
Build a single choice select pull-down for tagging.
Definition: common-tags.php:96
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
TagFilter(&$UploadtreeRows, $tag_pk, $uploadtree_tablename)
Given a list of uploadtree recs, remove recs that do not have $tag_pk.