Ejemplo n.º 1
0
/**
 * Service Users edit form
 *
 * @return html
 */
function service_users_edit_form()
{
    global $THEME, $USER;
    $editicon = 'icon icon-pencil prm';
    $deleteicon = 'icon icon-trash prm text-danger';
    $form = array('name' => 'webservices_users', 'elementclasses' => false, 'successcallback' => 'webservices_users_submit', 'renderer' => 'multicolumntable', 'elements' => array('username' => array('title' => ' ', 'datatable' => true, 'type' => 'html', 'value' => get_string('username', 'auth.webservice')), 'institution' => array('title' => ' ', 'datatable' => true, 'type' => 'html', 'value' => get_string('institution')), 'servicename' => array('title' => ' ', 'datatable' => true, 'type' => 'html', 'value' => get_string('servicename', 'auth.webservice')), 'enabled' => array('title' => ' ', 'datatable' => true, 'type' => 'html', 'value' => get_string('enabled')), 'wssigenc' => array('title' => ' ', 'datatable' => true, 'type' => 'html', 'value' => get_string('titlewssigenc', 'auth.webservice')), 'functions' => array('title' => ' ', 'datatable' => true, 'type' => 'html', 'value' => get_string('functions', 'auth.webservice')), 'actions' => array('title' => ' ', 'datatable' => true, 'type' => 'html', 'value' => '')));
    $dbusers = get_records_sql_array('SELECT eu.id as id, eu.userid as userid, eu.wssigenc AS wssigenc, eu.externalserviceid as externalserviceid, eu.institution as institution, u.username as username, es.name as name, es.enabled as enabled FROM {external_services_users} AS eu LEFT JOIN {usr} AS u ON eu.userid = u.id LEFT JOIN {external_services} AS es ON eu.externalserviceid = es.id ORDER BY eu.id', array());
    if (!empty($dbusers)) {
        foreach ($dbusers as $user) {
            $dbinstitution = get_record('institution', 'name', $user->institution);
            if ($USER->is_admin_for_user($user->id)) {
                $user_url = get_config('wwwroot') . 'admin/users/edit.php?id=' . $user->userid;
            } else {
                $user_url = get_config('wwwroot') . 'user/view.php?id=' . $user->userid;
            }
            $form['elements']['id' . $user->id . '_username'] = array('value' => '<a href="' . $user_url . '">' . $user->username . '</a>', 'type' => 'html', 'key' => $user->id);
            $form['elements']['id' . $user->id . '_institution'] = array('value' => $dbinstitution->displayname, 'type' => 'html', 'key' => $user->id);
            $form['elements']['id' . $user->id . '_servicename'] = array('value' => $user->name, 'type' => 'html', 'key' => $user->id);
            $form['elements']['id' . $user->id . '_enabled'] = array('value' => $user->enabled == 1 ? display_icon('enabled') : display_icon('disabled'), 'type' => 'html', 'class' => 'center', 'key' => $user->id);
            $form['elements']['id' . $user->id . '_wssigenc'] = array('value' => $user->wssigenc == 1 ? display_icon('enabled') : display_icon('disabled'), 'type' => 'html', 'class' => 'center', 'key' => $user->id);
            $functions = get_records_array('external_services_functions', 'externalserviceid', $user->externalserviceid);
            $function_list = array();
            if ($functions) {
                foreach ($functions as $function) {
                    $dbfunction = get_record('external_functions', 'name', $function->functionname);
                    $function_list[] = '<a href="' . get_config('wwwroot') . 'webservice/wsdoc.php?id=' . $dbfunction->id . '">' . $function->functionname . '</a>';
                }
            }
            $form['elements']['id' . $user->id . '_functions'] = array('value' => implode(', ', $function_list), 'type' => 'html', 'key' => $user->id);
            // edit and delete buttons
            $form['elements']['id' . $user->id . '_actions'] = array('value' => pieform(array('name' => 'webservices_user_edit_' . $user->id, 'renderer' => 'div', 'elementclasses' => false, 'successcallback' => 'webservices_user_submit', 'class' => 'form-as-button pull-left', 'jsform' => false, 'elements' => array('suid' => array('type' => 'hidden', 'value' => $user->id), 'action' => array('type' => 'hidden', 'value' => 'edit'), 'submit' => array('type' => 'button', 'usebuttontag' => true, 'class' => 'btn-default btn-sm', 'value' => '<span class="' . $editicon . '"></span>' . get_string('edit'), 'elementtitle' => get_string('editspecific', 'mahara', $user->username))))) . pieform(array('name' => 'webservices_user_delete_' . $user->id, 'renderer' => 'div', 'elementclasses' => false, 'successcallback' => 'webservices_user_submit', 'class' => 'form-as-button pull-left', 'jsform' => false, 'elements' => array('suid' => array('type' => 'hidden', 'value' => $user->id), 'action' => array('type' => 'hidden', 'value' => 'delete'), 'submit' => array('type' => 'button', 'usebuttontag' => true, 'class' => 'btn-default btn-sm', 'value' => '<span class="' . $deleteicon . '"></span>' . get_string('delete'), 'elementtitle' => get_string('deletespecific', 'mahara', $user->username))))), 'type' => 'html', 'key' => $user->id, 'class' => 'webserviceconfigcontrols btn-group');
        }
    } else {
        // no results so hide headings
        $form['elements'] = array();
    }
    $username = '';
    if ($user = param_integer('user', 0)) {
        $dbuser = get_record('usr', 'id', $user);
        if (!empty($dbuser)) {
            $username = $dbuser->username;
        }
    } else {
        $username = param_alphanum('username', '');
    }
    $pieform = new pieform($form);
    return $pieform->build(false) . '<div id="user_add">' . pieform(array('name' => 'webservices_user_generate', 'renderer' => 'div', 'successcallback' => 'webservices_user_submit', 'jsform' => false, 'action' => get_config('wwwroot') . 'webservice/admin/index.php', 'elements' => array('userid' => array('type' => 'autocomplete', 'title' => get_string('username') . ': ', 'ajaxurl' => get_config('wwwroot') . 'webservice/admin/users.json.php', 'multiple' => true, 'allowclear' => true, 'ajaxextraparams' => array(), 'extraparams' => array('maximumSelectionLength' => 1), 'width' => '280px'), 'action' => array('type' => 'hidden', 'value' => 'add'), 'submit' => array('type' => 'submit', 'class' => 'submit btn-primary last', 'value' => get_string('add'))))) . '</div>';
}
Ejemplo n.º 2
0
    }
    redirect('/webservice/apptokens.php');
}
/**
 * handle callback actions on the OAuth access tokens panel
 *  - delete token
 *
 * @param Pieform $form
 * @param array $values
 */
function webservices_oauth_token_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    if ($values['action'] == 'delete') {
        delete_records('oauth_server_token', 'id', $values['token'], 'userid', $USER->get('id'));
        $SESSION->add_ok_msg(get_string('oauthtokendeleted', 'auth.webservice'));
    }
    redirect('/webservice/apptokens.php');
}
// render the page
$pieform = new pieform($form);
$form = $pieform->build(false);
$smarty = smarty();
setpageicon($smarty, 'icon-puzzle-piece');
safe_require('auth', 'webservice');
$smarty->assign('form', $form);
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('subsectionheading', get_string('apptokens', 'auth.webservice'));
$webservice_menu = PluginAuthWebservice::admin_menu_items();
$smarty->assign('SUBPAGENAV', $webservice_menu);
$smarty->display('form.tpl');