/** * \brief Enable/Disable Tag on one folder(all uploads under this folder) or one upload * * \param $folder_id - folder id * \param $upload_id - upload id * \param $manage - enable or disable * * \return return null when no uploads to manage, return 1 after setting */ function ManageTag($folder_id, $upload_id, $manage) { global $PG_CONN; /** no operation */ if (empty($manage)) { return; } if (empty($folder_id) && empty($upload_id)) { return; } /** get upload list */ $upload_list = array(); if (!empty($upload_id)) { $upload_list[0] = array('upload_pk' => $upload_id); } else { $upload_list = FolderListUploadsRecurse($folder_id, NULL, Auth::PERM_WRITE); } // want to manage all uploads under a folder foreach ($upload_list as $upload) { $upload_id = $upload['upload_pk']; if ("Enable" === $manage) { $manage_value = false; } else { $manage_value = true; } /** check if this upload has been disabled */ $sql = "select * from tag_manage where upload_fk = {$upload_id} and is_disabled = true;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $count = pg_num_rows($result); pg_free_result($result); if (empty($count) && $manage_value == true) { $sql = "INSERT INTO tag_manage(upload_fk, is_disabled) VALUES({$upload_id}, true);"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); pg_free_result($result); } else { if ($count == 1 && $manage_value == false) { $sql = "delete from tag_manage where upload_fk = {$upload_id};"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); pg_free_result($result); } } } return 1; }
/** * @brief Get uploads and folder info, starting from $ParentFolder. * The array is sorted by folder and upload name. * Folders that are empty do not show up. * This is recursive! * NOTE: If there is a recursive loop in the folder table, then * this will loop INFINITELY. * * @param int $ParentFolder folder_pk, -1 for users root folder * @param string $FolderPath Used for recursion, caller should not specify. * @param Auth::PERM_READ | Auth::PERM_WRITE * @return array of {upload_pk, upload_desc, name, folder} */ function FolderListUploadsRecurse($ParentFolder = -1, $FolderPath = '', $perm = Auth::PERM_READ) { global $PG_CONN; if (empty($PG_CONN)) { return array(); } if (empty($ParentFolder)) { return array(); } if ($perm != Auth::PERM_READ && ($perm = Auth::PERM_WRITE)) { return array(); } if ($ParentFolder == "-1") { $ParentFolder = FolderGetTop(); } $groupId = Auth::getGroupId(); /* @var $uploadDao UploadDao */ $uploadDao = $GLOBALS['container']->get('dao.upload'); $List = array(); /* Get list of uploads */ /** mode 1<<1 = upload_fk **/ $sql = "SELECT upload_pk, upload_desc, ufile_name, folder_name FROM folder,foldercontents,uploadtree, upload\n WHERE \n foldercontents.parent_fk = '{$ParentFolder}'\n AND foldercontents.foldercontents_mode = " . FolderDao::MODE_UPLOAD . "\n AND foldercontents.child_id = upload.upload_pk\n AND folder.folder_pk = {$ParentFolder}\n AND uploadtree.upload_fk = upload.upload_pk\n AND uploadtree.parent is null\n ORDER BY uploadtree.ufile_name,upload.upload_desc"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); while ($R = pg_fetch_assoc($result)) { if (empty($R['upload_pk'])) { continue; } if ($perm == Auth::PERM_READ && !$uploadDao->isAccessible($R['upload_pk'], $groupId)) { continue; } if ($perm == Auth::PERM_WRITE && !$uploadDao->isEditable($R['upload_pk'], $groupId)) { continue; } $New['upload_pk'] = $R['upload_pk']; $New['upload_desc'] = $R['upload_desc']; $New['name'] = $R['ufile_name']; $New['folder'] = $FolderPath . "/" . $R['folder_name']; array_push($List, $New); } pg_free_result($result); /* Get list of subfolders and recurse */ /** mode 1<<0 = folder_pk **/ $sql = "SELECT A.child_id AS id,B.folder_name AS folder,B.folder_name AS subfolder\n\tFROM foldercontents AS A\n\tINNER JOIN folder AS B ON A.parent_fk = B.folder_pk\n\tAND A.foldercontents_mode = " . FolderDao::MODE_FOLDER . "\n\tAND A.parent_fk = '{$ParentFolder}'\n AND B.folder_pk = {$ParentFolder}\n\tORDER BY B.folder_name;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); while ($R = pg_fetch_assoc($result)) { if (empty($R['id'])) { continue; } /* RECURSE! */ $SubList = FolderListUploadsRecurse($R['id'], $FolderPath . "/" . $R['folder'], $perm); $List = array_merge($List, $SubList); } pg_free_result($result); /* Return findings */ return $List; }
$Found = 0; foreach (explode(',', $options["A"]) as $Val) { if (!strcmp($Val, $agent_list[$ac]->URI)) { $Found = 1; } } if ($Found == 0) { $agent_list[$ac]->URI = NULL; } } } /* List available uploads */ if (array_key_exists("u", $options)) { $root_folder_pk = GetUserRootFolder(); $FolderPath = NULL; $FolderList = FolderListUploadsRecurse($root_folder_pk, $FolderPath, Auth::PERM_WRITE); print "# The following uploads are available (upload id: name)\n"; foreach ($FolderList as $Folder) { $Label = $Folder['name'] . " (" . $Folder['upload_desc'] . ')'; print $Folder['upload_pk'] . ": {$Label}\n"; } exit(0); } /* @var $uploadDao UploadDao */ $uploadDao = $GLOBALS['container']->get('dao.upload'); if (array_key_exists("U", $options)) { /* $options['U'] can either be 'ALL', a string (the upload_pk), or an array of upload_pk's if multiple -U's were specified. */ $upload_options = $options['U']; $upload_pk_array = array();
/** * \brief Get uploads and folder info, starting from $ParentFolder. * The array is sorted by folder and upload name. * Folders that are empty do not show up. * This is recursive! * NOTE: If there is a recursive loop in the folder table, then * this will loop INFINITELY. * * \param $ParentFolder folder_pk, -1 for users root folder * \param $FolderPath Used for recursion, caller should not specify. * * \return array of {upload_pk, upload_desc, name, folder} */ function FolderListUploadsRecurse($ParentFolder = -1, $FolderPath = NULL, $perm = PERM_READ) { global $PG_CONN; if (empty($PG_CONN)) { return; } if (empty($ParentFolder)) { return; } if ($ParentFolder == "-1") { $ParentFolder = FolderGetTop(); } $List = array(); /* Get list of uploads */ /** mode 1<<1 = upload_fk **/ $sql = "SELECT upload_pk, upload_desc, ufile_name, folder_name FROM folder,foldercontents,uploadtree, upload\n WHERE \n foldercontents.parent_fk = '{$ParentFolder}'\n AND foldercontents.foldercontents_mode = 2 \n AND foldercontents.child_id = upload.upload_pk\n AND folder.folder_pk = {$ParentFolder}\n AND uploadtree.upload_fk = upload.upload_pk\n AND uploadtree.parent is null\n ORDER BY uploadtree.ufile_name,upload.upload_desc;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); while ($R = pg_fetch_assoc($result)) { if (empty($R['upload_pk'])) { continue; } /* Check upload permission */ $UploadPerm = GetUploadPerm($R['upload_pk']); if ($UploadPerm < $perm) { continue; } $New['upload_pk'] = $R['upload_pk']; $New['upload_desc'] = $R['upload_desc']; $New['name'] = $R['ufile_name']; $New['folder'] = $FolderPath . "/" . $R['folder_name']; array_push($List, $New); } pg_free_result($result); /* Get list of subfolders and recurse */ /** mode 1<<0 = folder_pk **/ $sql = "SELECT A.child_id AS id,B.folder_name AS folder,B.folder_name AS subfolder\n\tFROM foldercontents AS A\n\tINNER JOIN folder AS B ON A.parent_fk = B.folder_pk\n\tAND A.foldercontents_mode = 1\n\tAND A.parent_fk = '{$ParentFolder}'\n AND B.folder_pk = {$ParentFolder}\n\tORDER BY B.folder_name;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); while ($R = pg_fetch_assoc($result)) { if (empty($R['id'])) { continue; } /* RECURSE! */ $SubList = FolderListUploadsRecurse($R['id'], $FolderPath . "/" . $R['folder']); $List = array_merge($List, $SubList); } pg_free_result($result); /* Return findings */ return $List; }