FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
common-buckets.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************
3  Copyright (C) 2010-2014 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 
45 function SelectBucketDataset($upload_pk, &$ars_pk, $id="selectbucketdataset", $extra="")
46 {
47  global $PG_CONN;
48 
49  /* schedule bucket */
50  $NoData = ActiveHTTPscript("Schedule");
51  $NoData .= "<script language='javascript'>\n";
52  $NoData .= "function Schedule_Reply()\n";
53  $NoData .= " {\n";
54  $NoData .= " if ((Schedule.readyState==4) && (Schedule.status==200))\n";
55  $NoData .= " document.getElementById('msgdiv').innerHTML = Schedule.responseText;\n";
56  $NoData .= " }\n";
57  $NoData .= "</script>\n";
58 
59  $NoData .= "<form name='formy' method='post'>\n";
60  $NoData .= "<div id='msgdiv'>\n";
61  $NoData .= _("No data available.");
62  $NoData .= "<input type='button' name='scheduleAgent' value='Schedule Agent'";
63  $NoData .= "onClick='Schedule_Get(\"" . Traceback_uri() . "?mod=schedule_agent&upload=$upload_pk&agent=agent_bucket \")'>\n";
64  $NoData .= "</input>";
65  $NoData .= "</div> \n";
66  $NoData .= "</form>\n";
67 
68  $name = $id;
69  $select = "<select name='$name' id='$id' $extra>";
70 
71  /* get the bucketpool recs */
72  $sql = "select ars_pk, bucketpool_pk, bucketpool_name, version from bucketpool, bucket_ars where active='Y' and bucketpool_fk=bucketpool_pk and ars_success=True and upload_fk='$upload_pk' order by ars_starttime desc";
73  $result = pg_query($PG_CONN, $sql);
74  DBCheckResult($result, $sql, __FILE__, __LINE__);
75  $NumRows = pg_num_rows($result);
76  if ($NumRows == 0) {
77  return $NoData;
78  }
79  $rows = pg_fetch_all($result);
80  pg_free_result($result);
81  if ($NumRows == 1) {
82  $ars_pk = $rows[0]['ars_pk'];
83  return ""; /* only one row */
84  }
85 
86  /* Find the users default_bucketpool_fk */
87  $sql = "select default_bucketpool_fk from users where user_pk='$_SESSION[UserId]'";
88  $result = pg_query($PG_CONN, $sql);
89  DBCheckResult($result, $sql, __FILE__, __LINE__);
90  $row = pg_fetch_assoc($result);
91  $DefaultBucketpool_pk = $row['default_bucketpool_fk'];
92  pg_free_result($result);
93 
94  /* Find the default selected row if ars_pk wasn't passed in */
95  if (empty($ars_pk)) {
96  foreach ($rows as $row) {
97  if ($row['bucketpool_pk'] == $DefaultBucketpool_pk) {
98  $ars_pk = $row['ars_pk'];
99  break;
100  }
101  }
102  reset($rows);
103  }
104 
105  // $select .= "<option value=''";
106  foreach ($rows as $row) {
107  $select .= "<option value='$row[ars_pk]'";
108 
109  if (empty($ars_pk)) {
110  $select .= " SELECTED ";
111  $ars_pk = $row["ars_pk"];
112  } else if ($ars_pk == $row['ars_pk']) {
113  $select .= " SELECTED ";
114  }
115 
116  $select .= ">$row[bucketpool_name], v $row[version]\n";
117  }
118  $select .= "</select>";
119  return $select;
120 }
121 
132 function SelectBucketPool($selected, $active='Y')
133 {
134  global $PG_CONN;
135 
136  $id = "default_bucketpool_fk";
137  $name = $id;
138  $select = "<select name='$name' id='$id' class='ui-render-select2'>";
139 
140  /* get the bucketpool recs */
141  if ($active == 'Y') {
142  $Where = "where active='Y'";
143  } else {
144  $Where = "";
145  }
146  $sql = "select * from bucketpool $Where order by bucketpool_name asc,version desc";
147  $result = pg_query($PG_CONN, $sql);
148  DBCheckResult($result, $sql, __FILE__, __LINE__);
149 
150  while ($row = pg_fetch_assoc($result)) {
151  $select .= "<option value='$row[bucketpool_pk]'";
152  if ($row['bucketpool_pk'] == $selected) {
153  $select .= " SELECTED ";
154  }
155  $select .= ">$row[bucketpool_name], v $row[version]</option>\n";
156  }
157  $select .= "</select>";
158  return $select;
159 }
160 
173 function GetFileBuckets($nomosagent_pk, $bucketagent_pk, $uploadtree_pk, $bucketpool_pk)
174 {
175  global $PG_CONN;
176  $BuckArray = array();
177 
178  if (empty($nomosagent_pk) || empty($bucketagent_pk) || empty($uploadtree_pk)) {
179  Fatal(
180  "Missing parameter: nomosagent_pk $nomosagent_pk, bucketagent_pk: $bucketagent_pk, uploadtree_pk: $uploadtree_pk<br>",
181  __FILE__, __LINE__);
182  }
183 
184  /* Find lft and rgt bounds for this $uploadtree_pk */
185  $sql = "SELECT lft,rgt,upload_fk FROM uploadtree
186  WHERE uploadtree_pk = $uploadtree_pk";
187  $result = pg_query($PG_CONN, $sql);
188  DBCheckResult($result, $sql, __FILE__, __LINE__);
189  if (pg_num_rows($result) < 1) {
190  pg_free_result($result);
191  return $BuckArray;
192  }
193  $row = pg_fetch_assoc($result);
194  $lft = $row["lft"];
195  $rgt = $row["rgt"];
196  $upload_pk = $row["upload_fk"];
197  pg_free_result($result);
198 
199  /*select all the buckets for this tree */
200  $sql = "SELECT distinct(bucket_fk) as bucket_pk
201  from bucket_file, bucket_def,
202  (SELECT distinct(pfile_fk) as PF from uploadtree
203  where upload_fk=$upload_pk
204  and ((ufile_mode & (1<<28))=0)
205  and uploadtree.lft BETWEEN $lft and $rgt) as SS
206  where PF=pfile_fk and agent_fk=$bucketagent_pk
207  and bucket_file.nomosagent_fk=$nomosagent_pk
208  and bucket_pk=bucket_fk
209  and bucketpool_fk=$bucketpool_pk";
210 
211  $result = pg_query($PG_CONN, $sql);
212  DBCheckResult($result, $sql, __FILE__, __LINE__);
213  while ($row = pg_fetch_assoc($result)) {
214  $BuckArray[] = $row['bucket_pk'];
215  }
216  pg_free_result($result);
217 
218  return $BuckArray;
219 }
220 
221 
237 function GetFileBuckets_string($nomosagent_pk, $bucketagent_pk, $uploadtree_pk,
238  $bucketDefArray, $delimiter, $color)
239 {
240  $outstr = "";
241  $defrec = current($bucketDefArray);
242  $bucketpool_pk = $defrec['bucketpool_fk'];
243  $BuckArray = GetFileBuckets($nomosagent_pk, $bucketagent_pk, $uploadtree_pk, $bucketpool_pk);
244  if (empty($BuckArray)) {
245  return "";
246  }
247 
248  /* convert array of bucket_pk's to array of bucket names */
249  $BuckNames = array();
250  foreach ($BuckArray as $bucket_pk) {
251  $BuckNames[$bucket_pk] = $bucketDefArray[$bucket_pk]['bucket_name'];
252  }
253 
254  /* sort $BuckArray */
255  natcasesort($BuckNames);
256 
257  $first = true;
258  foreach ($BuckNames as $bucket_name) {
259  if ($first) {
260  $first = false;
261  } else {
262  $outstr .= $delimiter . " ";
263  }
264 
265  if ($color) {
266  $bucket_pk = array_search($bucket_name, $BuckNames);
267  $bucket_color = $bucketDefArray[$bucket_pk]['bucket_color'];
268  $outstr .= "<span style='background-color:$bucket_color'>";
269  $outstr .= $bucket_name;
270  $outstr .= "</span>";
271  } else {
272  $outstr .= $bucket_name;
273  }
274  }
275 
276  return $outstr;
277 }
278 
279 
290 function BucketInTree($bucket_pk, $uploadtree_pk)
291 {
292  global $PG_CONN;
293  $BuckArray = array();
294 
295  if (empty($bucket_pk) || empty($uploadtree_pk)) {
296  Fatal(
297  "Missing parameter: bucket_pk: $bucket_pk, uploadtree_pk: $uploadtree_pk<br>",
298  __FILE__, __LINE__);
299  }
300 
301  /* Find lft and rgt bounds for this $uploadtree_pk */
302  $sql = "SELECT lft,rgt, upload_fk FROM uploadtree WHERE uploadtree_pk = $uploadtree_pk";
303  $result = pg_query($PG_CONN, $sql);
304  DBCheckResult($result, $sql, __FILE__, __LINE__);
305  if (pg_num_rows($result) < 1) {
306  pg_free_result($result);
307  return false;
308  }
309  $row = pg_fetch_assoc($result);
310  $lft = $row["lft"];
311  $rgt = $row["rgt"];
312  $upload_fk = $row["upload_fk"];
313  pg_free_result($result);
314 
315  /* search for bucket in tree */
316  $sql = "SELECT bucket_fk from bucket_file,
317  (SELECT distinct(pfile_fk) as PF from uploadtree
318  where uploadtree.lft BETWEEN $lft and $rgt and upload_fk='$upload_fk') as SS
319  where PF=pfile_fk and bucket_fk='$bucket_pk' limit 1";
320 
321  $result = pg_query($PG_CONN, $sql);
322  DBCheckResult($result, $sql, __FILE__, __LINE__);
323  if (pg_num_rows($result) == 0) {
324  $rv = false;
325  } else {
326  $rv = true;
327  }
328  pg_free_result($result);
329 
330  return $rv;
331 }
332 
333 
341 function initBucketDefArray($bucketpool_pk)
342 {
343  global $PG_CONN;
344 
345  $sql = "select * from bucket_def where bucketpool_fk=$bucketpool_pk";
346  $result_name = pg_query($PG_CONN, $sql);
347  DBCheckResult($result_name, $sql, __FILE__, __LINE__);
348  $bucketDefArray = array();
349  while ($name_row = pg_fetch_assoc($result_name)) {
350  $bucketDefArray[$name_row['bucket_pk']] = $name_row;
351  }
352  pg_free_result($result_name);
353  return $bucketDefArray;
354 }
355 
SelectBucketPool($selected, $active='Y')
Return a select list containing all the active bucketpool&#39;s.
Traceback_uri()
Get the URI without query to this location.
initBucketDefArray($bucketpool_pk)
Initializes array of bucket_def records.
GetFileBuckets_string($nomosagent_pk, $bucketagent_pk, $uploadtree_pk, $bucketDefArray, $delimiter, $color)
Get string of $delimiter delimited bucket names for the given inputs. Args are same as GetFileBuckets...
ActiveHTTPscript($RequestName, $IncludeScriptTags=1)
Given a function name, create the JavaScript needed for doing the request.
BucketInTree($bucket_pk, $uploadtree_pk)
Check if a bucket_pk is found in a tree for a given nomos and bucket agent.
SelectBucketDataset($upload_pk, &$ars_pk, $id="selectbucketdataset", $extra="")
Return a select list showing all the successful bucket runs on a particular $upload_pk.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
GetFileBuckets($nomosagent_pk, $bucketagent_pk, $uploadtree_pk, $bucketpool_pk)
Get all the unique bucket_pk&#39;s for a given uploadtree_pk and for a given nomos and bucket agent...
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:198
Fatal($msg, $filenm, $lineno)
Write message to stdout and die.
Definition: common-ui.php:75