Exemplo n.º 1
0
function editaccess_submit(Pieform $form, $values)
{
    global $SESSION, $institution, $collections, $views, $view;
    if ($values['accesslist']) {
        $dateformat = get_string('strftimedatetimeshort');
        foreach ($values['accesslist'] as &$item) {
            if (!empty($item['startdate'])) {
                $item['startdate'] = ptimetotime(strptime($item['startdate'], $dateformat));
            }
            if (!empty($item['stopdate'])) {
                $item['stopdate'] = ptimetotime(strptime($item['stopdate'], $dateformat));
            }
        }
    }
    $viewconfig = array('startdate' => $values['startdate'], 'stopdate' => $values['stopdate'], 'template' => (int) $values['template'], 'retainview' => isset($values['retainview']) ? (int) $values['retainview'] : 0, 'allowcomments' => (int) $values['allowcomments'], 'approvecomments' => (int) ($values['allowcomments'] && $values['approvecomments']), 'accesslist' => $values['accesslist']);
    $toupdate = array();
    if ($institution) {
        if (isset($values['copynewuser'])) {
            $viewconfig['copynewuser'] = (int) $values['copynewuser'];
        }
        if ($institution == 'mahara') {
            $createfor = array();
            foreach (group_get_grouptypes() as $grouptype) {
                if ($values['copyfornewgroups_' . $grouptype]) {
                    $createfor[] = $grouptype;
                }
            }
            $viewconfig['copynewgroups'] = $createfor;
        }
    }
    if (isset($values['collections'])) {
        foreach ($values['collections'] as $cid) {
            if (!isset($collections[$cid])) {
                throw new UserException(get_string('editaccessinvalidviewset', 'view'));
            }
            $toupdate = array_merge($toupdate, array_keys($collections[$cid]['views']));
        }
    }
    if (isset($values['views'])) {
        foreach ($values['views'] as $viewid) {
            if (!isset($views[$viewid])) {
                throw new UserException(get_string('editaccessinvalidviewset', 'view'));
            }
            $toupdate[] = $viewid;
        }
    } else {
        if ($view->get('type') == 'profile') {
            // Force default Advanced options
            $felements = $form->get_property('elements');
            if (!empty($felements['more']['elements'])) {
                foreach (array_keys($felements['more']['elements']) as $ename) {
                    if (property_exists($view, $ename)) {
                        $viewconfig[$ename] = $view->get($ename);
                    }
                }
            }
            $toupdate[] = $view->get('id');
        }
    }
    if (!empty($toupdate)) {
        View::update_view_access($viewconfig, $toupdate);
        if ($view->get('type') == 'profile') {
            // Ensure the user's institutions are still added to the access list
            $view->add_owner_institution_access();
            if (get_config('loggedinprofileviewaccess')) {
                // Force logged-in user access
                $viewaccess = new stdClass();
                $viewaccess->accesstype = 'loggedin';
                $view->add_access($viewaccess);
            }
        }
    }
    $SESSION->add_ok_msg(get_string('updatedaccessfornumviews', 'view', count($toupdate)));
    if ($view->get('owner')) {
        redirect('/view/share.php');
    }
    if ($view->get('group')) {
        redirect(get_config('wwwroot') . '/group/shareviews.php?group=' . $view->get('group'));
    }
    if ($view->get('institution')) {
        redirect(get_config('wwwroot') . '/view/institutionshare.php?institution=' . $view->get('institution'));
    }
    $view->post_edit_redirect();
}
Exemplo n.º 2
0
function editaccess_submit(Pieform $form, $values)
{
    global $SESSION, $view, $new, $institution, $collection;
    if (param_boolean('back')) {
        if (!$collection) {
            redirect('/view/edit.php?id=' . $view->get('id') . '&new=' . $new);
        } else {
            redirect('/collection/views.php?id=' . $collection->get('id') . '&new=' . $new);
        }
    }
    if ($values['accesslist']) {
        $dateformat = get_string('strftimedatetimeshort');
        foreach ($values['accesslist'] as &$item) {
            if (!empty($item['startdate'])) {
                $item['startdate'] = ptimetotime(strptime($item['startdate'], $dateformat));
            }
            if (!empty($item['stopdate'])) {
                $item['stopdate'] = ptimetotime(strptime($item['stopdate'], $dateformat));
            }
        }
    }
    $view->set('startdate', $values['startdate']);
    $view->set('stopdate', $values['stopdate']);
    $istemplate = (int) $values['template'];
    $view->set('template', $istemplate);
    if (isset($values['copynewuser'])) {
        $view->set('copynewuser', (int) ($istemplate && $values['copynewuser']));
    }
    if ($institution == 'mahara') {
        $createfor = array();
        foreach (group_get_grouptypes() as $grouptype) {
            if ($istemplate && $values['copyfornewgroups_' . $grouptype]) {
                $createfor[] = $grouptype;
            }
        }
        $view->set('copynewgroups', $createfor);
    }
    $view->set('allowcomments', (int) $values['allowcomments']);
    if ($values['allowcomments']) {
        $view->set('approvecomments', (int) $values['approvecomments']);
    }
    db_begin();
    $view->commit();
    $view->set_access($values['accesslist']);
    if ($collection) {
        $collection->set_access($view->get('id'));
    }
    db_commit();
    if ($values['new']) {
        $str = $collection ? get_string('collectioncreatedsuccessfully', 'collection') : get_string('viewcreatedsuccessfully', 'view');
    } else {
        $str = $collection ? get_string('collectionaccesseditedsuccessfully', 'collection') : get_string('viewaccesseditedsuccessfully', 'view');
    }
    $SESSION->add_ok_msg($str);
    if (!$collection) {
        $view->post_edit_redirect();
    } else {
        $collection->post_edit_redirect();
    }
}