예제 #1
0
function template_preprocess_filedepot_filelisting(&$variables)
{
    global $user;
    $filedepot = filedepot_filedepot();
    $nexcloud = filedepot_nexcloud();
    /* listing rec format
       file.fid as fid,file.cid,file.title,file.fname,file.date,file.version,file.submitter,file.status,
       detail.description,category.name as foldername,category.pid,category.last_modified_date,status_changedby_uid as changedby_uid, size
       */
    $rec = $variables['listingrec'];
    $level = $variables['level'];
    $variables['subfolder_id'] = $rec['cid'];
    $variables['show_submitter'] = 'none';
    $variables['padding_left'] = $level * $filedepot->listingpadding + $filedepot->listingpadding;
    $variables['file_desc_padding_left'] = $filedepot->filedescriptionOffset + $level * $filedepot->listingpadding;
    $variables['locked_icon'] = base_path() . drupal_get_path('module', 'filedepot') . '/css/images/' . $filedepot->getFileIcon('locked');
    $variables['submitter'] = '';
    $variables['favorite_status_image'] = '';
    $variables['filesize'] = '';
    if ($rec['status'] == 2) {
        $variables['show_lock'] = '';
    } else {
        $variables['show_lock'] = 'none';
    }
    $variables['details_link_parms'] = "?fid={$rec['fid']}";
    $variables['fid'] = $rec['fid'];
    if (isset($rec['size'])) {
        $variables['filesize'] = filedepot_formatFileSize($rec['size']);
    }
    $variables['file_name'] = filter_xss($rec['title']);
    if (isset($rec['date']) and $rec['date'] > 0) {
        $variables['modified_date'] = strftime($filedepot->shortdate, $rec['date']);
    } else {
        $variables['modified_date'] = '';
    }
    $variables['folder_link'] = url('filedepot', array('query' => array('cid' => $rec['cid']), 'absolute' => true));
    $variables['folder_name'] = filter_xss($rec['foldername']);
    $filenum = $rec['fileorder'] / 10;
    if (variable_get('filedepot_show_index_enabled', 1) == 1) {
        // Check admin config setting
        $variables['file_number'] = "{$rec['folderprefix']}.{$filenum}";
    } else {
        $variables['file_number'] = '';
    }
    $variables['file_description'] = nl2br(filter_xss($rec['description']));
    $variables['actionclass'] = 'twoactions';
    $tags = $nexcloud->get_itemtags($variables['fid']);
    $variables['tags'] = filedepot_formatfiletags($tags);
    $variables['show_favorite'] = FALSE;
    if ($rec['status'] > 0 and user_is_logged_in()) {
        $variables['show_favorite'] = TRUE;
        if (db_query("SELECT count(fid) FROM {filedepot_favorites} WHERE uid=:uid AND fid=:fid", array(':uid' => $user->uid, ':fid' => $variables['fid']))->fetchField() > 0) {
            $variables['favorite_status_image'] = "{$variables['layout_url']}/css/images/{$filedepot->iconmap['favorite-on']}";
            $variables['LANG_favorite_status'] = t('Click to clear favorite');
        } else {
            $variables['favorite_status_image'] = "{$variables['layout_url']}/css/images/{$filedepot->iconmap['favorite-off']}";
            $variables['LANG_favorite_status'] = t('Click to mark item as a favorite');
        }
    }
    $variables['show_approvalsubmitter'] = 'none';
    $variables['show_foldername'] = '';
    if ($filedepot->activeview == 'approvals') {
        $variables['show_approvalsubmitter'] = '';
        $variables['show_submitter'] = 'none';
        $variables['submitter'] = db_query("SELECT name FROM {users} WHERE uid=:uid", array(':uid' => $rec['submitter']))->fetchField();
    } elseif ($filedepot->activeview == 'incoming') {
        $movelink = "<a class=\"moveincoming\" href=\"?fid={$rec['fid']}\" onClick=\"return false;\">" . t('Move') . '</a>';
        $deletelink = "<a class=\"deleteincoming\" href=\"?fid={$rec['fid']}\" onClick=\"return false;\">" . t('Delete') . '</a>';
        $variables['action1_link'] = $movelink;
        $variables['action2_link'] = $deletelink;
        $variables['submitter'] = db_query("SELECT name FROM {users} WHERE uid=:uid", array(':uid' => $rec['submitter']))->fetchField();
        $variables['show_submitter'] = '';
        $variables['show_foldername'] = 'none';
    } else {
        $folder_admin = $filedepot->checkPermission($rec['cid'], 'admin');
        if ($filedepot->cid > 0 or empty($filedepot->activeview)) {
            $variables['show_foldername'] = 'none';
        }
        $variables['action1_link'] = '&nbsp;';
        $variables['action2_link'] = '&nbsp;';
        $variables['actionclass'] = 'noactions';
        $allowLockedFileDownloads = variable_get('filedepot_locked_file_download_enabled', 0);
        // Check admin config setting
        if ($rec['status'] == FILEDEPOT_LOCKED_STATUS) {
            if ($folder_admin or $rec['changedby_uid'] == $user->uid) {
                // File locked and folder admin or file owner
                $path = drupal_get_path('module', 'filedepot') . '/css/images/' . $filedepot->getFileIcon('download');
                $downloadlinkimage = theme('image', array('path' => $path));
                $variables['action1_link'] = l($downloadlinkimage, "filedepot_download/{$rec['nid']}/{$rec['fid']}", array('html' => TRUE, 'attributes' => array('title' => t('Download File'))));
                if (FILEDEPOT_CLIENT_SUPPORT and $user->uid > 0 and $filedepot->checkPermission($rec['cid'], array('upload_dir'), $user->uid)) {
                    $variables['actionclass'] = 'twoactions';
                    $path = drupal_get_path('module', 'filedepot') . '/css/images/' . $filedepot->getFileIcon('editfile');
                    $editlinkimage = theme('image', array('path' => $path));
                    $variables['action2_link'] = l($editlinkimage, "filedepot_download/{$rec['nid']}/{$rec['fid']}/0/edit", array('html' => TRUE, 'attributes' => array('title' => t('Download for Editing'))));
                } else {
                    $variables['action2_link'] = '';
                    $variables['actionclass'] = 'oneaction';
                }
            } elseif ($allowLockedFileDownloads == 1) {
                // File locked and downloads allowed
                $path = drupal_get_path('module', 'filedepot') . '/css/images/' . $filedepot->getFileIcon('download');
                $downloadlinkimage = theme('image', array('path' => $path));
                $variables['action1_link'] = l($downloadlinkimage, "filedepot_download/{$rec['nid']}/{$rec['fid']}", array('html' => TRUE, 'attributes' => array('title' => t('Download File'))));
                $variables['action2_link'] = '';
                $variables['actionclass'] = 'oneaction';
            }
        } else {
            if ($folder_admin or $rec['changedby_uid'] == $user->uid) {
                $path = drupal_get_path('module', 'filedepot') . '/css/images/' . $filedepot->getFileIcon('download');
                $downloadlinkimage = theme('image', array('path' => $path));
                $variables['action1_link'] = l($downloadlinkimage, "filedepot_download/{$rec['nid']}/{$rec['fid']}", array('html' => TRUE, 'attributes' => array('title' => t('Download File'))));
                if (FILEDEPOT_CLIENT_SUPPORT and $user->uid > 0 and $filedepot->checkPermission($rec['cid'], array('upload_dir'), $user->uid)) {
                    $variables['actionclass'] = 'twoactions';
                    $path = drupal_get_path('module', 'filedepot') . '/css/images/' . $filedepot->getFileIcon('editfile');
                    $editlinkimage = theme('image', array('path' => $path));
                    $variables['action2_link'] = l($editlinkimage, "filedepot_download/{$rec['nid']}/{$rec['fid']}/0/edit", array('html' => TRUE, 'attributes' => array('title' => t('Download for Editing'))));
                } else {
                    $variables['action2_link'] = '';
                    $variables['actionclass'] = 'oneaction';
                }
            } else {
                $path = drupal_get_path('module', 'filedepot') . '/css/images/' . $filedepot->getFileIcon('download');
                $downloadlinkimage = theme('image', array('path' => $path));
                $variables['action1_link'] = l($downloadlinkimage, "filedepot_download/{$rec['nid']}/{$rec['fid']}", array('html' => TRUE, 'attributes' => array('title' => t('Download File'))));
                $variables['action2_link'] = '';
                $variables['actionclass'] = 'oneaction';
            }
        }
        //Restrict to download
        $download_access = check_downloadaccess($rec['downloadroles']);
        if ($download_access == 0) {
            $path = drupal_get_path('module', 'filedepot') . '/css/images/' . $filedepot->getFileIcon('download');
            $downloadlinkimage = theme('image', array('path' => $path));
            $variables['action1_link'] = '<div style="width:25px;">&nbsp;</div>';
            $variables['action2_link'] = '';
            $variables['actionclass'] = 'oneaction';
        }
    }
    $icon = $filedepot->getFileIcon($rec['fname']);
    $variables['extension_icon'] = "{$variables['layout_url']}/css/images/{$icon}";
    if ($variables['morerecords'] == 'loadfolder_msg') {
        $variables['more_records_message'] = theme('filedepot_filelisting_loadfolder', array('cid' => $rec['cid'], 'fid' => $variables['fid'], 'foldernumber' => $variables['file_number'], 'level' => $level));
    } elseif ($variables['morerecords'] != '') {
        $variables['more_records_message'] = theme('filedepot_filelisting_moredata', array('cid' => $rec['cid'], 'fid' => $variables['fid'], 'foldernumber' => $variables['file_number'], 'level' => $level));
    } else {
        $variables['more_records_message'] = '';
    }
}
예제 #2
0
function filedepotAjaxServer_loadFileDetails()
{
    global $user;
    $filedepot = filedepot_filedepot();
    $nexcloud = filedepot_nexcloud();
    $reportmode = check_plain($_POST['reportmode']);
    $retval = array();
    $retval['editperm'] = FALSE;
    $retval['token'] = drupal_get_token(FILEDEPOT_TOKEN_FILEDETAILS);
    $retval['deleteperm'] = FALSE;
    $retval['addperm'] = FALSE;
    $retval['lockperm'] = FALSE;
    $retval['notifyperm'] = FALSE;
    $retval['broadcastperm'] = FALSE;
    $retval['readroles'] = FALSE;
    $retval['downloadroles'] = FALSE;
    $retval['tags'] = '';
    $validfile = FALSE;
    if ($reportmode == 'approvals') {
        $id = intval($_POST['id']);
        if (db_query("SELECT count(*) FROM {filedepot_filesubmissions} WHERE id=:id", array(':id' => $id))->fetchField() == 1) {
            $validfile = TRUE;
            $sql = "SELECT file.id as fid,file.cid,file.title,file.fname,file.date,file.size,file.version,file.submitter,file.tags,u.name, ";
            $sql .= "file.status,file.description,category.pid,category.name as folder,category.nid,file.version_note,tags ";
            $sql .= "FROM {filedepot_filesubmissions} file ";
            $sql .= "LEFT JOIN {filedepot_categories} category ON file.cid=category.cid ";
            $sql .= "LEFT JOIN {users} u ON u.uid=file.submitter ";
            $sql .= "WHERE file.id=:id ";
            $rec = db_query($sql, array(':id' => $id))->fetchAssoc();
            $retval = array_merge($retval, $rec);
            $retval['displayhtml'] = theme('filedepot_filedetail', array('fid' => $id, 'reportmode' => $reportmode));
            $retval['locked'] = FALSE;
            $retval['subscribed'] = FALSE;
        }
    } elseif ($reportmode == 'incoming') {
        $id = intval($_POST['id']);
        if (db_result(db_query("SELECT count(*) FROM {filedepot_import_queue} WHERE id=:id", array(':id' => $id))) == 1) {
            $validfile = TRUE;
            $sql = "SELECT file.id as fid,file.orig_filename as title,file.description,file.version_note,u.name ";
            $sql .= "FROM {filedepot_import_queue} file ";
            $sql .= "LEFT JOIN {users} u ON u.uid=file.uid ";
            $sql .= "WHERE file.id=:id ";
            $rec = db_query($sql, array(':id' => $id))->fetchAssoc();
            $retval = array_merge($retval, $rec);
            if (empty($retval['version_note'])) {
                $retval['version_note'] = '';
            }
            $retval['displayhtml'] = theme('filedepot_filedetail', array('fid' => $id, 'reportmode' => $reportmode));
            $retval['locked'] = FALSE;
            $retval['subscribed'] = FALSE;
            // Need to reference a valid filedepot_folder node for the filedepot_download callback to work - required for the File Details 'Download' menuitem
            $retval['nid'] = db_query_range("SELECT nid FROM {filedepot_categories} WHERE pid=0", 0, 1, array())->fetchField();
        }
    } else {
        // Check that record exists
        $fid = intval($_POST['id']);
        $cid = db_query("SELECT cid FROM {filedepot_files} WHERE fid=:fid", array(':fid' => $fid))->fetchField();
        if ($filedepot->checkPermission($cid, 'view') and db_query("SELECT count(*) FROM {filedepot_files} WHERE fid=:fid", array(':fid' => $fid))->fetchField() == 1) {
            $validfile = TRUE;
            $sql = "SELECT file.fid,file.cid,file.title,file.description,file.fname,file.date,file.size,file.version,file.submitter,u.name, ";
            $sql .= "file.status,category.pid,category.name as folder,category.nid,v.notes as version_note,file.status_changedby_uid, ";
            $sql .= "file.readroles,file.downloadroles ";
            $sql .= "FROM {filedepot_files} file ";
            $sql .= "LEFT JOIN {filedepot_categories} category ON file.cid=category.cid ";
            $sql .= "LEFT JOIN {filedepot_fileversions} v ON v.fid=file.fid ";
            $sql .= "LEFT JOIN {users} u ON u.uid=file.submitter ";
            $sql .= "WHERE file.fid=:fid ORDER BY v.version DESC";
            $rec = db_query($sql, array(':fid' => $fid))->fetchAssoc();
            $retval = array_merge($retval, $rec);
            $retval['tags'] = $nexcloud->get_itemtags($fid);
            $retval['displayhtml'] = theme('filedepot_filedetail', array('fid' => $fid, 'reportmode' => $reportmode));
            // Check if file is locked
            if ($retval['status'] == FILEDEPOT_LOCKED_STATUS) {
                $retval['locked'] = TRUE;
            } else {
                $retval['locked'] = FALSE;
            }
            $download_roles = $retval['downloadroles'];
            // Check and see if user has subscribed to this file
            $direct = FALSE;
            $ignorefilechanges = FALSE;
            // Check if user has an ignore file changes record or a subscribe to changes record for this file
            $query = db_query("SELECT fid,ignore_filechanges FROM {filedepot_notifications} WHERE fid=:fid and uid=:uid", array(':fid' => $fid, ':uid' => $user->uid));
            $A = $query->fetchAssoc();
            if ($A['ignore_filechanges'] == 1) {
                $ignorefilechanges = TRUE;
            } elseif ($A['fid'] == $fid) {
                $direct = TRUE;
            }
            // Check and see if user has indirectly subscribed to file by subscribing to folder
            $sql = "SELECT count(*) FROM {filedepot_notifications} WHERE cid_changes=1 AND cid=:cid AND uid=:uid";
            $indirect = db_query($sql, array(':cid' => $rec['cid'], ':uid' => $user->uid))->fetchField();
            if (($direct or $indirect) and !$ignorefilechanges) {
                $retval['subscribed'] = TRUE;
            } else {
                $retval['subscribed'] = FALSE;
            }
        }
    }
    if ($validfile) {
        $retval['error'] = '';
        $retval['retcode'] = 200;
        if ($reportmode == 'incoming') {
            $retval['downloadperm'] = TRUE;
            $retval['editperm'] = TRUE;
            $retval['deleteperm'] = TRUE;
            $retval['addperm'] = FALSE;
            $retval['lockperm'] = FALSE;
            $retval['notifyperm'] = FALSE;
            $retval['broadcastperm'] = FALSE;
            $folderoptions = filedepot_recursiveAccessOptions('admin', 0);
            $retval['folderoptions'] = '<select name="folder" style="width:220px;">' . $folderoptions . '</select>';
            $readroles = explode(",", $retval['readroles']);
            $readrolesoptions = filedepot_getRoleOptionsWithMultipleSelectedValue($readroles);
            $retval['readroles'] = '<select name="readroles[]" multiple size=10 class="form-select" style="width:100%;">' . $readrolesoptions . '</select>';
            $downloadroles = explode(",", $retval['downloadroles']);
            $downloadrolesoptions = filedepot_getRoleOptionsWithMultipleSelectedValue($downloadroles);
            $retval['downloadroles'] = '<select name="downloadroles[]" multiple size=10 class="form-select" style="width:100%;">' . $downloadrolesoptions . '</select>';
        } else {
            $retval['dispfolder'] = $retval['folder'];
            $retval['description'] = nl2br($retval['description']);
            $retval['version_note'] = nl2br($retval['version_note']);
            $retval['date'] = strftime('%b %d %Y %I:%M %p', $retval['date']);
            $retval['size'] = filedepot_formatFileSize($retval['size']);
            // Setup the folder option select HTML options
            $cid = intval($retval['cid']);
            $folderoptions = filedepot_recursiveAccessOptions('admin', $cid, 0, 1, FALSE);
            if (!empty($folderoptions) and $filedepot->checkPermission($retval['cid'], 'admin')) {
                $retval['folderoptions'] = '<select name="folder" style="width:220px;">' . $folderoptions . '</select>';
            } else {
                $retval['folderoptions'] = '<input type="text" name="folder" value="' . $retval['folder'] . '" READONLY />';
            }
            $readroles = explode(",", $retval['readroles']);
            $readrolesoptions = filedepot_getRoleOptionsWithMultipleSelectedValue($readroles);
            $retval['readroles'] = '<select name="readroles[]" multiple size=10 class="form-select" style="width:100%;">' . $readrolesoptions . '</select>';
            $downloadroles = explode(",", $retval['downloadroles']);
            $downloadrolesoptions = filedepot_getRoleOptionsWithMultipleSelectedValue($downloadroles);
            $retval['downloadroles'] = '<select name="downloadroles[]" multiple size=10 class="form-select" style="width:100%;">' . $downloadrolesoptions . '</select>';
            if ($filedepot->checkPermission($retval['cid'], 'admin')) {
                $retval['downloadperm'] = TRUE;
                $retval['editperm'] = TRUE;
                $retval['deleteperm'] = TRUE;
                $retval['addperm'] = TRUE;
                $retval['lockperm'] = TRUE;
                $retval['notifyperm'] = TRUE;
                $retval['broadcastperm'] = TRUE;
            } elseif ($retval['locked']) {
                if ($retval['status_changedby_uid'] == $user->uid) {
                    $retval['lockperm'] = TRUE;
                    if ($filedepot->checkPermission($retval['cid'], 'upload_ver')) {
                        $retval['addperm'] = TRUE;
                    }
                    if ($retval['submitter'] == $user->uid) {
                        $retval['deleteperm'] = TRUE;
                    }
                } elseif ($retval['status_changedby_uid'] > 0) {
                    if ($retval['submitter'] == $user->uid) {
                        $retval['lockperm'] = TRUE;
                    } else {
                        $retval['downloadperm'] = FALSE;
                    }
                }
                $retval['notifyperm'] = TRUE;
            } elseif ($user->uid > 0) {
                if ($retval['submitter'] == $user->uid) {
                    $retval['deleteperm'] = TRUE;
                    $retval['lockperm'] = TRUE;
                }
                if ($filedepot->checkPermission($retval['cid'], 'upload_ver')) {
                    $retval['addperm'] = TRUE;
                }
                $retval['notifyperm'] = TRUE;
            }
            // Changed
            if ($filedepot->checkPermission($retval['cid'], 'view', 0, TRUE)) {
                $retval['tagperms'] = TRUE;
                // Able to set or change tags
                if ($retval['locked']) {
                    if ($retval['submitter'] == $user->uid or $retval['status_changedby_uid'] == $user->uid) {
                        $retval['downloadperm'] = TRUE;
                    } elseif (variable_get('filedepot_locked_file_download_enabled', 0) == 1) {
                        // Check admin config setting
                        $retval['downloadperm'] = TRUE;
                    } else {
                        $retval['downloadperm'] = FALSE;
                    }
                } else {
                    $retval['downloadperm'] = TRUE;
                    if ($retval['submitter'] == $user->uid) {
                        $retval['editperm'] = TRUE;
                    }
                }
                $download_access = check_downloadaccess($download_roles);
                if ($download_access == 0) {
                    $retval['downloadperm'] = FALSE;
                }
            } else {
                $retval['tagperms'] = FALSE;
                $retval['downloadperm'] = FALSE;
            }
        }
    } else {
        $retval['retcode'] = 400;
        $retval['error'] = t('Invalid access');
    }
    return $retval;
}