Exemple #1
0
function publications_admin_create()
{
    if (!xarVarFetch('ptid', 'id', $data['ptid'])) {
        return;
    }
    if (!xarVarFetch('new_cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('preview', 'str', $data['preview'], NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('save', 'str', $save, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Confirm authorisation code
    // This has been disabled for now
    // if (!xarSecConfirmAuthKey()) return;
    $data['items'] = array();
    $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types'));
    $pubtypeobject->getItem(array('itemid' => $data['ptid']));
    $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value));
    $isvalid = $data['object']->checkInput();
    $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid']));
    if ($data['preview'] || !$isvalid) {
        // Show debug info if called for
        if (!$isvalid && xarModVars::get('publications', 'debugmode') && in_array(xarUserGetVar('uname'), xarConfigVars::get(null, 'Site.User.DebugAdmins'))) {
            var_dump($data['object']->getInvalids());
        }
        // Preview or bad data: redisplay the form
        $data['properties'] = $data['object']->getProperties();
        if ($data['preview']) {
            $data['tab'] = 'preview';
        }
        return xarTplModule('publications', 'admin', 'new', $data);
    }
    // Create the object
    $id = $data['object']->createItem();
    // if we can edit publications, go to admin view, otherwise go to user view
    if (xarSecurityCheck('EditPublications', 0, 'Publication', $data['ptid'] . ':All:All:All')) {
        // Redirect if we came from somewhere else
        $cuurent_listview = xarSession::getVar('publications_current_listview');
        if (!empty($cuurent_listview)) {
            xarController::redirect($cuurent_listview);
        }
        xarController::redirect(xarModURL('publications', 'admin', 'view', array('ptid' => $data['ptid'])));
    } else {
        xarController::redirect(xarModURL('publications', 'user', 'view', array('ptid' => $data['ptid'])));
    }
    return true;
}
Exemple #2
0
function publications_admin_update()
{
    // Get parameters
    if (!xarVarFetch('itemid', 'isset', $data['itemid'], NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('items', 'str', $items, '', XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('ptid', 'isset', $data['ptid'], NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('modify_cids', 'isset', $cids, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('preview', 'isset', $data['preview'], NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('quit', 'isset', $data['quit'], NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('front', 'isset', $data['front'], NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('tab', 'str:1', $data['tab'], '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('returnurl', 'str:1', $data['returnurl'], 'view', XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Confirm authorisation code
    // This has been disabled for now
    //    if (!xarSecConfirmAuthKey()) return;
    $items = explode(',', $items);
    $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types'));
    $pubtypeobject->getItem(array('itemid' => $data['ptid']));
    $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value));
    // First we need to check all the data on the template
    // If checkInput fails, don't bail
    $itemsdata = array();
    $isvalid = true;
    foreach ($items as $prefix) {
        $data['object']->setFieldPrefix($prefix);
        // Disable the celkoposition property according if this is not the base document
        $fieldname = $prefix . '_dd_' . $data['object']->properties['parent']->id;
        $data['object']->properties['parent']->checkInput($fieldname);
        if (empty($data['object']->properties['parent']->value)) {
            $data['object']->properties['position']->setDisplayStatus(DataPropertyMaster::DD_DISPLAYSTATE_DISPLAYONLY);
        } else {
            $data['object']->properties['position']->setDisplayStatus(DataPropertyMaster::DD_DISPLAYSTATE_DISABLED);
        }
        // Now get the input from the form
        $thisvalid = $data['object']->checkInput();
        $isvalid = $isvalid && $thisvalid;
        // Store each item for later processing
        $itemsdata[$prefix] = $data['object']->getFieldValues(array(), 1);
    }
    if ($data['preview'] || !$isvalid) {
        // Show debug info if called for
        if (!$isvalid && xarModVars::get('publications', 'debugmode') && in_array(xarUserGetVar('uname'), xarConfigVars::get(null, 'Site.User.DebugAdmins'))) {
            var_dump($data['object']->getInvalids());
        }
        // Preview or bad data: redisplay the form
        $data['properties'] = $data['object']->getProperties();
        if ($data['preview']) {
            $data['tab'] = 'preview';
        }
        $data['items'] = $itemsdata;
        // Get the settings of the publication type we are using
        $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid']));
        return xarTplModule('publications', 'admin', 'modify', $data);
    }
    // call transform input hooks
    $article['transform'] = array('summary', 'body', 'notes');
    $article = xarModCallHooks('item', 'transform-input', $data['itemid'], $article, 'publications', $data['ptid']);
    // Now talk to the database. Loop through all the translation pages
    foreach ($itemsdata as $id => $itemdata) {
        // Get the data for this item
        $data['object']->setFieldValues($itemdata, 1);
        // Save or create the item (depends whether this translation is new)
        if (empty($id)) {
            $item = $data['object']->createItem();
        } else {
            $item = $data['object']->updateItem();
        }
        // Check if we have an alias and set it as an alias of the publications module
        $alias_flag = $data['object']->properties['alias_flag']->value;
        if ($alias_flag == 1) {
            $alias = $data['object']->properties['alias']->value;
            if (!empty($alias)) {
                xarModAlias::set($alias, 'publications');
            }
        } elseif ($alias_flag == 2) {
            $alias = $data['object']->properties['name']->value;
            if (!empty($alias)) {
                xarModAlias::set($alias, 'publications');
            }
        }
        // Clear the itemid property in preparation for the next round
        unset($data['object']->itemid);
    }
    // Success
    xarSession::setVar('statusmsg', xarML('Publication Updated'));
    // If quitting, go to admin view; otherwise redisplay the page
    if (xarSecurityCheck('EditPublications', 0, 'Publication', $data['ptid'] . ':All:All:All')) {
        if ($data['quit']) {
            // Redirect if we came from somewhere else
            $current_listview = xarSession::getVar('publications_current_listview');
            if (!empty($current_listview)) {
                xarController::redirect($current_listview);
            }
            xarController::redirect(xarModURL('publications', 'admin', 'view', array('ptid' => $data['ptid'])));
        } elseif ($data['front']) {
            xarController::redirect(xarModURL('publications', 'user', 'display', array('name' => $pubtypeobject->properties['name']->value, 'itemid' => $data['itemid'])));
        } else {
            xarController::redirect(xarModURL('publications', 'admin', 'modify', array('name' => $pubtypeobject->properties['name']->value, 'itemid' => $data['itemid'])));
        }
        return true;
    }
}