FOSSology  4.4.0
Open Source License Compliance by Open Source Software
common-tags.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2010-2013 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: LGPL-2.1-only
6 */
7 
10 
26 function GetAllTags($Item, $Recurse=true, $uploadtree_tablename="uploadtree")
27 {
28  if (empty($Item)) {
29  return array();
30  }
31 
32  global $container;
33 
34  $dbManager = $container->get('db.manager');
35 
36  $stmt = __METHOD__.".$uploadtree_tablename";
37  $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";
38  $tagDisabled = $dbManager->getSingleRow($sql, array($Item), $stmt);
39  if ($tagDisabled !== false) {
40  return array();
41  }
42 
43  $stmt2 = $stmt.'.lftRgt';
44  $sql = "select lft,rgt, upload_fk from $uploadtree_tablename where uploadtree_pk=$1";
45  $uploadtree_row = $dbManager->getSingleRow($sql,array($Item), $stmt2);
46 
47  $params = array($Item, $uploadtree_row['upload_fk']);
48  if ($Recurse) {
49  $Condition = " lft between $3 and $4 ";
50  $stmt .= ".recurse";
51  $params[] = $uploadtree_row['lft'];
52  $params[] = $uploadtree_row['rgt'];
53  } else {
54  $Condition = " uploadtree.uploadtree_pk=$1 ";
55  }
56 
57  /* Get list of unique tag_pk's for this item */
58  $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";
59 
60  $stmt1 = $stmt.'.theTags';
61  $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");
62  $res = $dbManager->execute($stmt1,$params);
63  $List = $dbManager->fetchAll($res);
64  $dbManager->freeResult($res);
65 
66  return($List);
67 } // GetAllTags()
68 
69 
85 function Array2SingleSelectTag($KeyValArray, $SLName="unnamed", $SelectedVal= "",
86 $FirstEmpty=false, $SelElt=true, $Options="")
87 {
88  $str ="\n<select name='$SLName' $Options>\n";
89  if ($FirstEmpty) {
90  $str .= "<option value='' > \n";
91  }
92  foreach ($KeyValArray as $key => $val) {
93  if ($SelElt == true) {
94  $SELECTED = ($val == $SelectedVal) ? "SELECTED" : "";
95  } else {
96  $SELECTED = ($key == $SelectedVal) ? "SELECTED" : "";
97  }
99  // $perm = GetTaggingPerms($_SESSION['UserId'],$key);
100  // if ($perm > 1) {
101  $str .= "<option value='$key' $SELECTED>$val\n";
102  // }
103  }
104  $str .= "</select>";
105  return $str;
106 }
107 
119 function TagSelect($SLName="unnamed", $SelectedVal= "",
120  $FirstEmpty=false, $SelElt=true)
121 {
122  /* Find all the tag namespaces for this user */
123  /* UNUSED
124  $sql = "select lft,rgt from uploadtree where uploadtree_pk=$Item";
125  $result = pg_query($PG_CONN, $sql);
126  DBCheckResult($result, $sql, __FILE__, __LINE__);
127  $uploadtree_row = pg_fetch_assoc($result);
128  */
129 
130  /* Find all the tags for this namespace */
131 
132  $str ="\n<select name='$SLName'>\n";
133  if ($FirstEmpty) {
134  $str .= "<option value='' > \n";
135  }
136  foreach ($KeyValArray as $key => $val) {
137  if ($SelElt == true) {
138  $SELECTED = ($val == $SelectedVal) ? "SELECTED" : "";
139  } else {
140  $SELECTED = ($key == $SelectedVal) ? "SELECTED" : "";
141  }
142  $perm = GetTaggingPerms($_SESSION['UserId'],$key);
143  if ($perm > 1) {
144  $str .= "<option value='$key' $SELECTED>$val\n";
145  }
146  }
147  $str .= "</select>";
148  return $str;
149 }
150 
158 function TagFilter(&$UploadtreeRows, $tag_pk, $uploadtree_tablename)
159 {
160  foreach ($UploadtreeRows as $key=>$UploadtreeRow) {
161  $found = false;
162  $tags = GetAllTags($UploadtreeRow["uploadtree_pk"], true, $uploadtree_tablename);
163  foreach ($tags as $tagArray) {
164  if ($tagArray['tag_pk'] == $tag_pk) {
165  $found = true;
166  break;
167  }
168  if ($found) {
169  break;
170  }
171  }
172  if ($found == false) {
173  unset($UploadtreeRows[$key]);
174  }
175  }
176 }
177 
185 function TagStatus($upload_id)
186 {
187  global $PG_CONN, $container;
189  $uploadDao = $container->get('dao.upload');
190  if (!$uploadDao->isEditable($upload_id, Auth::getGroupId())) {
191  return 0;
192  }
193 
194  /* check if this upload has been disabled */
195  $sql = "select tag_manage_pk from tag_manage where upload_fk = $upload_id and is_disabled = true;";
196  $result = pg_query($PG_CONN, $sql);
197  DBCheckResult($result, $sql, __FILE__, __LINE__);
198  $count = pg_num_rows($result);
199  pg_free_result($result);
200  return ($count > 0) ? 0 : 1;
201 }
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:187
TagFilter(&$UploadtreeRows, $tag_pk, $uploadtree_tablename)
Given a list of uploadtree recs, remove recs that do not have $tag_pk.
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:85
GetAllTags($Item, $Recurse=true, $uploadtree_tablename="uploadtree")
Get all Tags of this uploadtree_pk.
Definition: common-tags.php:26
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN