29 if (! empty($_SESSION[
'Folder'])) {
30 return ($_SESSION[
'Folder']);
36 $sql =
"SELECT root_folder_fk FROM users ORDER BY user_pk ASC LIMIT 1";
39 $row = pg_fetch_assoc($result);
40 pg_free_result($result);
41 return($row[
'root_folder_fk']);
55 $user_pk = Auth::getUserId();
58 if (empty($user_pk)) {
59 return "__FILE__:__LINE__ GetUserRootFolder(Not logged in)<br>";
63 $sql =
"select root_folder_fk from users where user_pk=$user_pk";
66 $UsersRow = pg_fetch_assoc($result);
67 $root_folder_fk = $UsersRow[
'root_folder_fk'];
68 pg_free_result($result);
69 if (empty($root_folder_fk)) {
70 $text = _(
"Missing root_folder_fk for user ");
71 fatal(
"<h2>".$text.$user_pk.
"</h2>", __FILE__, __LINE__);
73 return $root_folder_fk;
93 $FolderList = array();
96 if (empty($folder_pk)) {
97 return __FILE__.
":".__LINE__.
" Folder2Browse(empty)<br>";
104 $sql =
"select folder_pk, folder_name from folder where folder_pk='$folder_pk'";
107 $FolderRow = pg_fetch_assoc($result);
108 pg_free_result($result);
109 array_unshift($FolderList, $FolderRow);
113 if (($folder_pk == $root_folder_fk) || (count($FolderList)>20)) {
117 $sql =
"select parent_fk from foldercontents where child_id='$folder_pk' and foldercontents_mode=".FolderDao::MODE_FOLDER;
120 $FolderRow = pg_fetch_assoc($result);
121 pg_free_result($result);
122 $folder_pk = $FolderRow[
'parent_fk'];
143 if (empty($uploadtree_pk) && empty($upload_pk)) {
144 return "__FILE__:__LINE__ GetFolderFromItem(empty)<br>";
147 if (empty($upload_pk)) {
148 $UTrec =
GetSingleRec(
"uploadtree",
"where uploadtree_pk=$uploadtree_pk");
149 $upload_pk = $UTrec[
'upload_fk'];
152 $sql =
"select parent_fk from foldercontents where child_id='$upload_pk' and foldercontents_mode=".FolderDao::MODE_UPLOAD;
155 $FolderRow = pg_fetch_assoc($result);
156 pg_free_result($result);
157 return $FolderRow[
'parent_fk'];
178 function FolderListOption($ParentFolder,$Depth, $IncludeTop=1, $SelectId=-1, $linkParent=
false, $OldParent=0)
180 if ($ParentFolder ==
"-1") {
183 if (empty($ParentFolder)) {
192 if (($Depth != 0) || $IncludeTop) {
193 if ($ParentFolder == $SelectId) {
194 $V .=
"<option value='$ParentFolder' SELECTED>";
195 } elseif ($linkParent) {
196 if (empty($OldParent)) {
199 $V .=
"<option value='$OldParent $ParentFolder'>";
201 $V .=
"<option value='$ParentFolder'>";
204 $V .=
" ";
206 for ($i=1; $i < $Depth; $i++) {
207 $V .=
" ";
211 $sql =
"SELECT folder_name FROM folder WHERE folder_pk=$ParentFolder LIMIT 1;";
214 $row = pg_fetch_assoc($result);
215 $Name =
trim($row[
'folder_name']);
222 $V .= htmlentities($Name, ENT_HTML5 | ENT_QUOTES);
226 $sql =
"SELECT folder.folder_pk, folder.folder_name AS name,
227 folder.folder_desc AS description,
228 foldercontents.parent_fk AS parent,
229 foldercontents.foldercontents_mode,
230 NULL AS ts, NULL AS upload_pk, NULL AS pfile_fk, NULL AS ufile_mode
231 FROM folder, foldercontents
232 WHERE foldercontents.foldercontents_mode = ".FolderDao::MODE_FOLDER.
"
233 AND foldercontents.parent_fk =$ParentFolder
234 AND foldercontents.child_id = folder.folder_pk
235 AND folder.folder_pk is not null
239 if (pg_num_rows($result) > 0) {
242 $Hide =
"style='display:none;'";
244 while ($row = pg_fetch_assoc($result)) {
245 $V .=
FolderListOption($row[
'folder_pk'], $Depth+1,$IncludeTop,$SelectId,$linkParent,$row[
'parent']);
248 pg_free_result($result);
269 $sql =
"SELECT folder_name,foldercontents.parent_fk FROM folder
270 LEFT JOIN foldercontents ON foldercontents_mode = ".FolderDao::MODE_FOLDER.
"
271 AND child_id = '$FolderPk'
272 WHERE folder_pk = '$FolderPk'
276 $row = pg_fetch_assoc($result);
277 $Parent = $row[
'parent_fk'];
278 $Name = $row[
'folder_name'];
279 if (! empty($Parent) && ($FolderPk != $Top)) {
300 if (empty($Uploadpk)) {
306 if ($Folder == $Stop) {
315 $sql =
"SELECT foldercontents.parent_fk,folder_name FROM foldercontents
316 INNER JOIN folder ON foldercontents.parent_fk = folder.folder_pk
317 AND foldercontents.foldercontents_mode = " . FolderDao::MODE_UPLOAD.
"
318 WHERE foldercontents.child_id = $Parm LIMIT 1;";
322 $sql =
"SELECT foldercontents.parent_fk,folder_name FROM foldercontents
323 INNER JOIN folder ON foldercontents.parent_fk = folder.folder_pk
324 AND foldercontents.foldercontents_mode = 1
325 WHERE foldercontents.child_id = $Parm LIMIT 1;";
329 $R = pg_fetch_assoc($result);
330 if (empty($R[
'parent_fk'])) {
331 pg_free_result($result);
335 $V[
'folder_pk'] = $R[
'parent_fk'];
336 $V[
'folder_name'] = $R[
'folder_name'];
337 if ($R[
'parent_fk'] != 0) {
344 pg_free_result($result);
368 if (empty($ParentFolder)) {
371 if ($ParentFolder ==
"-1") {
374 $groupId = Auth::getGroupId();
376 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
381 $sql =
"SELECT upload_pk, upload_desc, upload_ts, upload_filename
382 FROM foldercontents,upload
383 INNER JOIN uploadtree ON upload_fk = upload_pk AND upload.pfile_fk = uploadtree.pfile_fk AND parent IS NULL AND lft IS NOT NULL
384 WHERE foldercontents.parent_fk = '$ParentFolder'
385 AND foldercontents.foldercontents_mode = ".FolderDao::MODE_UPLOAD.
"
386 AND foldercontents.child_id = upload.upload_pk
387 ORDER BY upload_filename,upload_pk;";
390 while ($R = pg_fetch_assoc($result)) {
391 if (empty($R[
'upload_pk'])) {
395 ! $uploadDao->isAccessible($R[
'upload_pk'], $groupId)) {
399 ! $uploadDao->isEditable($R[
'upload_pk'], $groupId)) {
404 $New[
'upload_pk'] = $R[
'upload_pk'];
405 $New[
'upload_desc'] = $R[
'upload_desc'];
407 $New[
'name'] = $R[
'upload_filename'];
410 pg_free_result($result);
435 if (empty($ParentFolder)) {
441 if ($ParentFolder ==
"-1") {
444 $groupId = Auth::getGroupId();
446 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
451 $sql =
"SELECT upload_pk, upload_desc, ufile_name, folder_name FROM folder,foldercontents,uploadtree, upload
453 foldercontents.parent_fk = '$ParentFolder'
454 AND foldercontents.foldercontents_mode = ". FolderDao::MODE_UPLOAD .
"
455 AND foldercontents.child_id = upload.upload_pk
456 AND folder.folder_pk = $ParentFolder
457 AND uploadtree.upload_fk = upload.upload_pk
458 AND uploadtree.parent is null
459 ORDER BY uploadtree.ufile_name,upload.upload_desc";
462 while ($R = pg_fetch_assoc($result)) {
463 if (empty($R[
'upload_pk'])) {
467 ! $uploadDao->isAccessible($R[
'upload_pk'], $groupId)) {
471 ! $uploadDao->isEditable($R[
'upload_pk'], $groupId)) {
476 $New[
'upload_pk'] = $R[
'upload_pk'];
477 $New[
'upload_desc'] = $R[
'upload_desc'];
478 $New[
'name'] = $R[
'ufile_name'];
479 $New[
'folder'] = $FolderPath .
"/" . $R[
'folder_name'];
482 pg_free_result($result);
486 $sql =
"SELECT A.child_id AS id,B.folder_name AS folder,B.folder_name AS subfolder
487 FROM foldercontents AS A
488 INNER JOIN folder AS B ON A.parent_fk = B.folder_pk
489 AND A.foldercontents_mode = ". FolderDao::MODE_FOLDER .
"
490 AND A.parent_fk = '$ParentFolder'
491 AND B.folder_pk = $ParentFolder
492 ORDER BY B.folder_name;";
495 while ($R = pg_fetch_assoc($result)) {
496 if (empty($R[
'id'])) {
501 $List = array_merge($List,$SubList);
503 pg_free_result($result);
529 if ($RootFolder ==
"-1") {
532 if (empty($RootFolder)) {
537 $sql =
"SELECT folder_name, folder_pk FROM folder WHERE folder_pk=$RootFolder LIMIT 1;";
540 $row = pg_fetch_assoc($result);
541 pg_free_result($result);
543 $Name =
trim($row[
'folder_name']);
544 $FolderArray[$row[
'folder_pk']] = $row[
'folder_name'];
547 $sql =
"SELECT folder.folder_pk, folder.folder_name,
548 foldercontents.parent_fk
549 FROM folder, foldercontents
550 WHERE foldercontents.foldercontents_mode = ".FolderDao::MODE_FOLDER.
"
551 AND foldercontents.parent_fk =$RootFolder
552 AND foldercontents.child_id = folder.folder_pk
553 AND folder.folder_pk is not null
554 ORDER BY folder_name";
557 if (pg_num_rows($result) > 0) {
558 while ($row = pg_fetch_assoc($result)) {
562 pg_free_result($result);
575 $excluding_length = 0;
577 if ($ExcludingText) {
578 $excluding_length = strlen($ExcludingText);
582 if ($excluding_length > 0 && strstr($FilePath, $ExcludingText)) {
585 if (
'/' != $ExcludingText[0] &&
'/' == $ExcludingText[$excluding_length - 1] &&
586 ! strstr($FilePath,
'/'.$ExcludingText)) {
590 return $excluding_flag;
Contains the constants and helpers for authentication of user.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
ContainExcludeString($FilePath, $ExcludingText)
Check if one file path contains an excluding text.
FolderGetName($FolderPk, $Top=-1)
Given a folder_pk, return the full path to this folder.
GetUserRootFolder()
Get the top-of-tree folder_pk for the current user. Fail if there is no user session.
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
GetFolderArray($RootFolder, &$FolderArray)
Get an array of all the folders from a $RootFolder on down.
FolderListUploadsRecurse($ParentFolder=-1, $FolderPath='', $perm=Auth::PERM_READ)
Get uploads and folder info, starting from $ParentFolder.
GetFolderFromItem($upload_pk="", $uploadtree_pk="")
Find what folder an item is in.
FolderGetTop()
DEPRECATED! Find the top-of-tree folder_pk for the current user.
FolderGetFromUpload($Uploadpk, $Folder=-1, $Stop=-1)
DEPRECATED! Given an upload number, return the folder path in an array containing folder_pk and name.
Folder2Path($folder_pk)
Return an array of folder_pk, folder_name from the users.root_folder_fk to $folder_pk.
FolderListUploads_perm($ParentFolder, $perm)
Returns an array of uploads in a folder.
Convert2BrowserTime($server_time)
Convert the server time to browser time.
char * trim(char *ptext)
Trimming whitespace.
#define PERM_WRITE
Read-Write permission.
#define PERM_READ
Read-only permission.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN