require_once 'activity.php';
require_once get_config('docroot') . 'artefact/lib.php';
$groupid = param_integer('group');
$returnto = param_variable('returnto', 'view');
$group = get_record_sql('SELECT g.id, g.name, g.grouptype, g.urlid
       FROM {group_member} u
       INNER JOIN {group} g ON (u.group = g.id AND g.deleted = 0)
       WHERE u.member = ?
       AND g.id = ?
       AND g.submittableto = 1', array($USER->get('id'), $groupid));
if (!$group || !group_within_edit_window($group)) {
    throw new AccessDeniedException(get_string('cantsubmittogroup', 'view'));
}
if ($collectionid = param_integer('collection', null)) {
    $collection = new Collection($collectionid);
    if (!$collection || $collection->is_submitted() || $collection->get('owner') !== $USER->get('id')) {
        throw new AccessDeniedException(get_string('cantsubmitcollectiontogroup', 'view'));
    }
    $submissionname = $collection->get('name');
} else {
    $view = new View(param_integer('id'));
    if (!$view || $view->is_submitted() || $view->get('owner') !== $USER->get('id')) {
        throw new AccessDeniedException(get_string('cantsubmitviewtogroup', 'view'));
    }
    $submissionname = $view->get('title');
}
define('TITLE', get_string('submitviewtogroup', 'view', $submissionname, $group->name));
$form = pieform(array('name' => 'submitview', 'renderer' => 'div', 'autofocus' => false, 'method' => 'post', 'elements' => array('submit' => array('type' => 'submitcancel', 'value' => array(get_string('yes'), get_string('no')), 'goto' => get_config('wwwroot') . returnto()))));
$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('message', get_string('submitconfirm', 'view', $submissionname, $group->name));
Example #2
0
    $institutionname = param_alphanum('institution', false);
    if (empty($groupid) && empty($institutionname)) {
        $owner = $USER->get('id');
    }
    $collection = new Collection(null, array('owner' => $owner, 'group' => $groupid, 'institution' => $institutionname));
    define('SUBTITLE', get_string('edittitleanddesc', 'collection'));
} else {
    // if editing an existing or copied collection
    $id = param_integer('id');
    $collection = new Collection($id);
    $owner = $collection->get('owner');
    $groupid = $collection->get('group');
    $institutionname = $collection->get('institution');
    define('SUBTITLE', $collection->get('name') . ': ' . get_string('edittitleanddesc', 'collection'));
}
if ($collection->is_submitted()) {
    $submitinfo = $collection->submitted_to();
    throw new AccessDeniedException(get_string('canteditsubmitted', 'collection', $submitinfo->name));
}
$urlparams = array();
if (!empty($groupid)) {
    define('MENUITEM', 'groups/collections');
    define('GROUP', $groupid);
    $group = group_current_group();
    define('TITLE', $group->name . ' - ' . get_string('editcollection', 'collection'));
    $urlparams['group'] = $groupid;
} else {
    if (!empty($institutionname)) {
        if ($institutionname == 'mahara') {
            define('ADMIN', 1);
            define('MENUITEM', 'configsite/collections');
Example #3
0
/**
 * Submits a view or collection for assessment by a remote service
 *
 * @param string $username
 * @param int $id The ID of the view or collection to be submitted
 * @param boolean $iscollection Indicates whether it's a view or a collection
 * @return array An array of data for the web service to consume
 */
function submit_view_for_assessment($username, $id, $iscollection = false)
{
    global $REMOTEWWWROOT;
    list($user, $authinstance) = find_remote_user($username, $REMOTEWWWROOT);
    if (!$user) {
        return false;
    }
    $id = (int) $id;
    if (!$id) {
        return false;
    }
    require_once 'view.php';
    $remotehost = $authinstance->config['wwwroot'];
    $userid = $user->get('id');
    db_begin();
    if ($iscollection) {
        require_once 'collection.php';
        $collection = new Collection($id);
        $title = $collection->get('name');
        $description = $collection->get('description');
        // Check whether the collection is already submitted
        if ($collection->is_submitted()) {
            // If this is already submitted to something else, throw an exception
            if ($collection->get('submittedgroup') || $collection->get('submittedhost') !== $REMOTEWWWROOT) {
                throw new CollectionSubmissionException(get_string('collectionalreadysubmitted', 'view'));
            }
            // It may have been submitted to a different assignment in the same remote
            // site, but there's no way we can tell. So we'll just send the access token
            // back.
            $access = $collection->get_invisible_token();
        } else {
            $collection->submit(null, $remotehost, $userid);
            $access = $collection->new_token(false);
        }
        // If the collection is empty, $access will be false
        if (!$access) {
            throw new CollectionSubmissionException(get_string('cantsubmitemptycollection', 'view'));
        }
    } else {
        $view = new View($id);
        $title = $view->get('title');
        $description = $view->get('description');
        if ($view->is_submitted()) {
            // If this is already submitted to something else, throw an exception
            if ($view->get('submittedgroup') || $view->get('submittedhost') !== $REMOTEWWWROOT) {
                throw new ViewSubmissionException(get_string('viewalreadysubmitted', 'view'));
            }
            // It may have been submitted to a different assignment in the same remote
            // site, but there's no way we can tell. So we'll just send the access token
            // back.
            $access = View::get_invisible_token($id);
        } else {
            View::_db_submit(array($id), null, $remotehost, $userid);
            $access = View::new_token($id, false);
        }
    }
    $data = array('id' => $id, 'title' => $title, 'description' => $description, 'fullurl' => get_config('wwwroot') . 'view/view.php?mt=' . $access->token, 'url' => '/view/view.php?mt=' . $access->token, 'accesskey' => $access->token);
    // Provide each artefact plugin the opportunity to handle the remote submission and
    // provide return data for the webservice caller
    foreach (plugins_installed('artefact') as $plugin) {
        safe_require('artefact', $plugin->name);
        $classname = generate_class_name('artefact', $plugin->name);
        if (is_callable($classname . '::view_submit_external_data')) {
            $data[$plugin->name] = call_static_method($classname, 'view_submit_external_data', $id, $iscollection);
        }
    }
    db_commit();
    return $data;
}