40 if (! empty($_SESSION[
'Folder'])) {
41 return ($_SESSION[
'Folder']);
44 if (empty($PG_CONN)) {
47 $sql =
"SELECT root_folder_fk FROM users ORDER BY user_pk ASC LIMIT 1";
48 $result = pg_query($PG_CONN, $sql);
50 $row = pg_fetch_assoc($result);
51 pg_free_result($result);
52 return($row[
'root_folder_fk']);
66 $user_pk = Auth::getUserId();
69 if (empty($user_pk)) {
70 return "__FILE__:__LINE__ GetUserRootFolder(Not logged in)<br>";
74 $sql =
"select root_folder_fk from users where user_pk=$user_pk";
75 $result = pg_query($PG_CONN, $sql);
77 $UsersRow = pg_fetch_assoc($result);
78 $root_folder_fk = $UsersRow[
'root_folder_fk'];
79 pg_free_result($result);
80 if (empty($root_folder_fk)) {
81 $text = _(
"Missing root_folder_fk for user ");
82 fatal(
"<h2>".$text.$user_pk.
"</h2>", __FILE__, __LINE__);
84 return $root_folder_fk;
104 $FolderList = array();
107 if (empty($folder_pk)) {
108 return __FILE__.
":".__LINE__.
" Folder2Browse(empty)<br>";
115 $sql =
"select folder_pk, folder_name from folder where folder_pk='$folder_pk'";
116 $result = pg_query($PG_CONN, $sql);
118 $FolderRow = pg_fetch_assoc($result);
119 pg_free_result($result);
120 array_unshift($FolderList, $FolderRow);
124 if (($folder_pk == $root_folder_fk) || (count($FolderList)>20)) {
128 $sql =
"select parent_fk from foldercontents where child_id='$folder_pk' and foldercontents_mode=".FolderDao::MODE_FOLDER;
129 $result = pg_query($PG_CONN, $sql);
131 $FolderRow = pg_fetch_assoc($result);
132 pg_free_result($result);
133 $folder_pk = $FolderRow[
'parent_fk'];
154 if (empty($uploadtree_pk) && empty($upload_pk)) {
155 return "__FILE__:__LINE__ GetFolderFromItem(empty)<br>";
158 if (empty($upload_pk)) {
159 $UTrec =
GetSingleRec(
"uploadtree",
"where uploadtree_pk=$uploadtree_pk");
160 $upload_pk = $UTrec[
'upload_fk'];
163 $sql =
"select parent_fk from foldercontents where child_id='$upload_pk' and foldercontents_mode=".FolderDao::MODE_UPLOAD;
164 $result = pg_query($PG_CONN, $sql);
166 $FolderRow = pg_fetch_assoc($result);
167 pg_free_result($result);
168 return $FolderRow[
'parent_fk'];
189 function FolderListOption($ParentFolder,$Depth, $IncludeTop=1, $SelectId=-1, $linkParent=
false, $OldParent=0)
191 if ($ParentFolder ==
"-1") {
194 if (empty($ParentFolder)) {
198 if (empty($PG_CONN)) {
203 if (($Depth != 0) || $IncludeTop) {
204 if ($ParentFolder == $SelectId) {
205 $V .=
"<option value='$ParentFolder' SELECTED>";
206 } elseif ($linkParent) {
207 if (empty($OldParent)) {
210 $V .=
"<option value='$OldParent $ParentFolder'>";
212 $V .=
"<option value='$ParentFolder'>";
215 $V .=
" ";
217 for ($i=1; $i < $Depth; $i++) {
218 $V .=
" ";
222 $sql =
"SELECT folder_name FROM folder WHERE folder_pk=$ParentFolder LIMIT 1;";
223 $result = pg_query($PG_CONN, $sql);
225 $row = pg_fetch_assoc($result);
226 $Name =
trim($row[
'folder_name']);
233 $V .= htmlentities($Name);
237 $sql =
"SELECT folder.folder_pk, folder.folder_name AS name, 238 folder.folder_desc AS description, 239 foldercontents.parent_fk AS parent, 240 foldercontents.foldercontents_mode, 241 NULL AS ts, NULL AS upload_pk, NULL AS pfile_fk, NULL AS ufile_mode 242 FROM folder, foldercontents 243 WHERE foldercontents.foldercontents_mode = ".FolderDao::MODE_FOLDER.
" 244 AND foldercontents.parent_fk =$ParentFolder 245 AND foldercontents.child_id = folder.folder_pk 246 AND folder.folder_pk is not null 248 $result = pg_query($PG_CONN, $sql);
250 if (pg_num_rows($result) > 0) {
253 $Hide =
"style='display:none;'";
255 while ($row = pg_fetch_assoc($result)) {
256 $V .=
FolderListOption($row[
'folder_pk'], $Depth+1,$IncludeTop,$SelectId,$linkParent,$row[
'parent']);
259 pg_free_result($result);
280 $sql =
"SELECT folder_name,foldercontents.parent_fk FROM folder 281 LEFT JOIN foldercontents ON foldercontents_mode = ".FolderDao::MODE_FOLDER.
" 282 AND child_id = '$FolderPk' 283 WHERE folder_pk = '$FolderPk' 285 $result = pg_query($PG_CONN, $sql);
287 $row = pg_fetch_assoc($result);
288 $Parent = $row[
'parent_fk'];
289 $Name = $row[
'folder_name'];
290 if (! empty($Parent) && ($FolderPk != $Top)) {
308 if (empty($PG_CONN)) {
311 if (empty($Uploadpk)) {
317 if ($Folder == $Stop) {
326 $sql =
"SELECT foldercontents.parent_fk,folder_name FROM foldercontents 327 INNER JOIN folder ON foldercontents.parent_fk = folder.folder_pk 328 AND foldercontents.foldercontents_mode = " . FolderDao::MODE_UPLOAD.
" 329 WHERE foldercontents.child_id = $Parm LIMIT 1;";
333 $sql =
"SELECT foldercontents.parent_fk,folder_name FROM foldercontents 334 INNER JOIN folder ON foldercontents.parent_fk = folder.folder_pk 335 AND foldercontents.foldercontents_mode = 1 336 WHERE foldercontents.child_id = $Parm LIMIT 1;";
338 $result = pg_query($PG_CONN, $sql);
340 $R = pg_fetch_assoc($result);
341 if (empty($R[
'parent_fk'])) {
342 pg_free_result($result);
346 $V[
'folder_pk'] = $R[
'parent_fk'];
347 $V[
'folder_name'] = $R[
'folder_name'];
348 if ($R[
'parent_fk'] != 0) {
354 array_push($List,$V);
355 pg_free_result($result);
376 if (empty($PG_CONN)) {
379 if (empty($ParentFolder)) {
382 if ($ParentFolder ==
"-1") {
385 $groupId = Auth::getGroupId();
387 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
392 $sql =
"SELECT upload_pk, upload_desc, upload_ts, upload_filename 393 FROM foldercontents,upload 394 INNER JOIN uploadtree ON upload_fk = upload_pk AND upload.pfile_fk = uploadtree.pfile_fk AND parent IS NULL AND lft IS NOT NULL 395 WHERE foldercontents.parent_fk = '$ParentFolder' 396 AND foldercontents.foldercontents_mode = ".FolderDao::MODE_UPLOAD.
" 397 AND foldercontents.child_id = upload.upload_pk 398 ORDER BY upload_filename,upload_pk;";
399 $result = pg_query($PG_CONN, $sql);
401 while ($R = pg_fetch_assoc($result)) {
402 if (empty($R[
'upload_pk'])) {
406 ! $uploadDao->isAccessible($R[
'upload_pk'], $groupId)) {
410 ! $uploadDao->isEditable($R[
'upload_pk'], $groupId)) {
415 $New[
'upload_pk'] = $R[
'upload_pk'];
416 $New[
'upload_desc'] = $R[
'upload_desc'];
418 $New[
'name'] = $R[
'upload_filename'];
419 array_push($List,$New);
421 pg_free_result($result);
443 if (empty($PG_CONN)) {
446 if (empty($ParentFolder)) {
452 if ($ParentFolder ==
"-1") {
455 $groupId = Auth::getGroupId();
457 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
462 $sql =
"SELECT upload_pk, upload_desc, ufile_name, folder_name FROM folder,foldercontents,uploadtree, upload 464 foldercontents.parent_fk = '$ParentFolder' 465 AND foldercontents.foldercontents_mode = ". FolderDao::MODE_UPLOAD .
" 466 AND foldercontents.child_id = upload.upload_pk 467 AND folder.folder_pk = $ParentFolder 468 AND uploadtree.upload_fk = upload.upload_pk 469 AND uploadtree.parent is null 470 ORDER BY uploadtree.ufile_name,upload.upload_desc";
471 $result = pg_query($PG_CONN, $sql);
473 while ($R = pg_fetch_assoc($result)) {
474 if (empty($R[
'upload_pk'])) {
478 ! $uploadDao->isAccessible($R[
'upload_pk'], $groupId)) {
482 ! $uploadDao->isEditable($R[
'upload_pk'], $groupId)) {
487 $New[
'upload_pk'] = $R[
'upload_pk'];
488 $New[
'upload_desc'] = $R[
'upload_desc'];
489 $New[
'name'] = $R[
'ufile_name'];
490 $New[
'folder'] = $FolderPath .
"/" . $R[
'folder_name'];
491 array_push($List,$New);
493 pg_free_result($result);
497 $sql =
"SELECT A.child_id AS id,B.folder_name AS folder,B.folder_name AS subfolder 498 FROM foldercontents AS A 499 INNER JOIN folder AS B ON A.parent_fk = B.folder_pk 500 AND A.foldercontents_mode = ". FolderDao::MODE_FOLDER .
" 501 AND A.parent_fk = '$ParentFolder' 502 AND B.folder_pk = $ParentFolder 503 ORDER BY B.folder_name;";
504 $result = pg_query($PG_CONN, $sql);
506 while ($R = pg_fetch_assoc($result)) {
507 if (empty($R[
'id'])) {
512 $List = array_merge($List,$SubList);
514 pg_free_result($result);
540 if ($RootFolder ==
"-1") {
543 if (empty($RootFolder)) {
548 $sql =
"SELECT folder_name, folder_pk FROM folder WHERE folder_pk=$RootFolder LIMIT 1;";
549 $result = pg_query($PG_CONN, $sql);
551 $row = pg_fetch_assoc($result);
552 pg_free_result($result);
554 $Name =
trim($row[
'folder_name']);
555 $FolderArray[$row[
'folder_pk']] = $row[
'folder_name'];
558 $sql =
"SELECT folder.folder_pk, folder.folder_name, 559 foldercontents.parent_fk 560 FROM folder, foldercontents 561 WHERE foldercontents.foldercontents_mode = ".FolderDao::MODE_FOLDER.
" 562 AND foldercontents.parent_fk =$RootFolder 563 AND foldercontents.child_id = folder.folder_pk 564 AND folder.folder_pk is not null 565 ORDER BY folder_name";
566 $result = pg_query($PG_CONN, $sql);
568 if (pg_num_rows($result) > 0) {
569 while ($row = pg_fetch_assoc($result)) {
573 pg_free_result($result);
586 $excluding_length = 0;
588 if ($ExcludingText) {
589 $excluding_length = strlen($ExcludingText);
593 if ($excluding_length > 0 && strstr($FilePath, $ExcludingText)) {
596 if (
'/' != $ExcludingText[0] &&
'/' == $ExcludingText[$excluding_length - 1] &&
597 ! strstr($FilePath,
'/'.$ExcludingText)) {
601 return $excluding_flag;
ContainExcludeString($FilePath, $ExcludingText)
Check if one file path contains an excluding text.
FolderGetFromUpload($Uploadpk, $Folder=-1, $Stop=-1)
DEPRECATED! Given an upload number, return the folder path in an array containing folder_pk and name...
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.
Convert2BrowserTime($server_time)
Convert the server time to browser time.
FolderGetName($FolderPk, $Top=-1)
Given a folder_pk, return the full path to this folder.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
GetFolderArray($RootFolder, &$FolderArray)
Get an array of all the folders from a $RootFolder on down.
Folder2Path($folder_pk)
Return an array of folder_pk, folder_name from the users.root_folder_fk to $folder_pk.
FolderGetTop()
DEPRECATED! Find the top-of-tree folder_pk for the current user.
GetUserRootFolder()
Get the top-of-tree folder_pk for the current user. Fail if there is no user session.
FolderListUploadsRecurse($ParentFolder=-1, $FolderPath= '', $perm=Auth::PERM_READ)
Get uploads and folder info, starting from $ParentFolder.
#define PERM_READ
Read-only permission.
GetFolderFromItem($upload_pk="", $uploadtree_pk="")
Find what folder an item is in.
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.
char * trim(char *ptext)
Trimming whitespace.
#define PERM_WRITE
Read-Write permission.