Esempio n. 1
0
    if (!$permission) {
        fn_set_notification('W', fn_get_lang_var('warning'), fn_get_lang_var('access_denied'));
        if (defined('AJAX_REQUEST')) {
            exit;
        } else {
            return array(CONTROLLER_STATUS_DENIED);
        }
    }
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    //
    // Add attachments
    //
    if ($mode == 'add') {
        if (!empty($_REQUEST['attachment_data'])) {
            fn_add_attachments($_REQUEST['attachment_data'], $_REQUEST['object_type'], $_REQUEST['object_id']);
        }
    }
    //
    // Update attachments
    //
    if ($mode == 'update') {
        if (!empty($_REQUEST['attachment_data'])) {
            fn_update_attachments($_REQUEST['attachment_data'], $_REQUEST['attachment_id'], $_REQUEST['object_type'], $_REQUEST['object_id']);
        }
    }
    return array(CONTROLLER_STATUS_OK);
    // redirect should be performed via redirect_url always
}
if ($mode == 'getfile') {
    if (!empty($_REQUEST['attachment_id']) && !empty($_REQUEST['object_type']) && !empty($_REQUEST['object_id'])) {
Esempio n. 2
0
function fn_clone_attachments($object_type, $target_object_id, $object_id, $action = null)
{
    $revision_id = 0;
    $revision = null;
    if (AREA == 'A' && Registry::is_exist('revisions') && !Registry::get('revisions.working')) {
        $revisions = Registry::get('revisions');
        if (!empty($revisions['objects'][$object_type]) && !empty($revisions['objects'][$object_type]['tables'])) {
            $object_data = $revisions['objects'][$object_type];
            if ($object_data['attachments']) {
                $rev_data = db_get_row("SELECT max(revision) as revision, revision_id FROM ?:revisions WHERE object = ?s AND object_id = ?i GROUP BY revision_id", $object_type, $object_id);
                $revision = $rev_data['revision'];
                $revision_id = $rev_data['revision_id'];
            }
        }
    }
    if ($revision_id && $action != 'create') {
        $_ = 'rev_';
        $revision_condition = db_quote(" AND revision = ?s AND revision_id = ?i", $revision, $revision_id);
    } else {
        $_ = '';
        $revision_condition = '';
    }
    $data = db_get_array("SELECT * FROM ?:{$_}attachments WHERE object_type = ?s AND object_id = ?i ?p", $object_type, $object_id, $revision_condition);
    $files = array();
    $add_data = array();
    $descriptions = array();
    $directory = DIR_ATTACHMENTS . '/' . $object_type . ($revision_condition ? '_rev' : '') . '/' . $target_object_id;
    $i = 1;
    if ($action == 'publish') {
        Registry::set('revisions.working', true);
    }
    foreach ($data as $entry) {
        $files = array();
        if (!empty($entry['filename'])) {
            $f_name = $directory . '/' . $entry['filename'];
            $files[0] = array('path' => $f_name, 'size' => filesize($f_name), 'error' => 0, 'name' => $entry['filename']);
        }
        $add_data = array('attachment_id' => $entry['attachment_id'], 'usergroup_ids' => implode(',', $entry['usergroup_ids']), 'position' => $entry['position'], 'type' => $entry['type'], 'description' => db_get_hash_single_array("SELECT * FROM ?:{$_}attachment_descriptions WHERE attachment_id = ?i ?p", array('lang_code', 'description'), $entry['attachment_id'], $revision_condition));
        fn_add_attachments($add_data, $object_type, $target_object_id, $entry['type'], $files);
    }
    if ($action == 'publish') {
        Registry::set('revisions.working', false);
    }
}