/** * Show the link account form. */ public function showlinkform() { global $USER; $form = array('name' => 'auth_oidc_loginlink', 'renderer' => 'div', 'successcallback' => array($this, 'loginlink_submit'), 'method' => 'post', 'plugintype' => 'auth', 'pluginname' => 'oidc', 'elements' => array('linklogins' => array('value' => '<div>' . get_string('linkaccounts', 'auth.oidc', $this->oidcusername, $USER->username) . '</div>'), 'submit' => array('type' => 'submitcancel', 'value' => array(get_string('confirm', 'auth.oidc'), get_string('cancel')), 'goto' => get_config('wwwroot'))), 'dieaftersubmit' => false, 'iscancellable' => true); $form = new \Pieform($form); $smarty = smarty(array(), array(), array(), array('pagehelp' => false, 'sidebars' => false)); $smarty->assign('form', $form->build()); $smarty->assign('PAGEHEADING', get_string('link', 'auth.oidc')); $smarty->display('form.tpl'); die; }
function auth_generate_registration_form_js($aform, $registerconfirm) { // The javascript needs to refer to field names, but they are obfuscated in this form, // so construct and build the form in separate steps, so we can get the field names. $form = new Pieform($aform); $institutionid = $form->get_name() . '_' . $form->hashedfields['institution']; $reasonid = $form->get_name() . '_' . $form->hashedfields['reason']; $formhtml = $form->build(); if (count($registerconfirm) == 1) { $js = ' $j(function() { $j("#' . $reasonid . '_container").removeClass("js-hidden"); $j("#' . $reasonid . '_container textarea").removeClass("js-hidden"); $j("#' . $reasonid . '_container").next("tr.textarea").removeClass("js-hidden"); }); '; } else { $url = get_config('wwwroot') . 'json/termsandconditions.php'; $js = ' var registerconfirm = ' . json_encode($registerconfirm) . '; $j(function() { $j("#' . $institutionid . '").change(function() { if (this.value && registerconfirm[this.value] == 1) { $j("#' . $reasonid . '_container").removeClass("js-hidden"); $j("#' . $reasonid . '_container textarea").removeClass("js-hidden"); $j("#' . $reasonid . '_container").next("tr.textarea").removeClass("js-hidden"); } else { $j("#' . $reasonid . '_container").addClass("js-hidden"); $j("#' . $reasonid . '_container textarea").addClass("js-hidden"); $j("#' . $reasonid . '_container").next("tr.textarea").addClass("js-hidden"); } // need to fetch the correct terms and conditions for the institution if (this.value) { $j.ajax({ type: "POST", dataType: "json", url: "' . $url . '", data: { "institution": this.value, } }).done(function (data) { if (data.content) { $j("#termscontainer").html(data.content); } }); } }); }); '; } return array($formhtml, $js); }
addLoadEvent(function() { connect('usertype_type', 'onchange', function() { if (suspendedlist.type != \$('usertype_type').value) { suspendedlist.offset = 0; suspendedlist.type = \$('usertype_type').value; suspendedlist.doupdate(); } }); }); EOF ); $form = new Pieform(array('name' => 'buttons', 'renderer' => 'div', 'autofocus' => false, 'elements' => array('buttons' => array('type' => 'fieldset', 'class' => 'btn-group pull-right', 'isformgroup' => false, 'elements' => array('unsuspend' => array('class' => 'btn-default text-inline', 'type' => 'submit', 'isformgroup' => false, 'renderelementsonly' => true, 'name' => 'unsuspend', 'value' => get_string('unsuspendusers', 'admin')), 'unexpire' => array('class' => 'btn-default text-inline', 'type' => 'submit', 'isformgroup' => false, 'renderelementsonly' => true, 'name' => 'unexpire', 'value' => get_string('unexpireusers', 'admin')), 'delete' => array('class' => 'btn-default text-inline', 'type' => 'submit', 'isformgroup' => false, 'renderelementsonly' => true, 'confirm' => get_string('confirmdeleteusers', 'admin'), 'name' => 'delete', 'value' => get_string('deleteusers', 'admin'))))))); $smarty->assign('buttonformopen', $form->get_form_tag()); $smarty->assign('buttonform', $form->build(false)); $smarty->assign('PAGEHEADING', TITLE); $smarty->display('admin/users/suspended.tpl'); function buttons_submit_unsuspend(Pieform $form, $values) { global $SESSION; $ids = get_user_ids_from_post(); foreach ($ids as $userid) { unsuspend_user($userid); } $SESSION->add_ok_msg(get_string('usersunsuspendedsuccessfully', 'admin')); redirect('/admin/users/suspended.php'); } function buttons_submit_unexpire(Pieform $form, $values) { global $SESSION;
/** * Builds the configuration pieform for this blockinstance * * @return array Array with two keys: 'html' for raw html, 'javascript' for * javascript to run, 'css' for dynamic css to add to header */ public function build_configure_form($new = false) { static $renderedform; if (!empty($renderedform)) { return $renderedform; } safe_require('blocktype', $this->get('blocktype')); $blocktypeclass = generate_class_name('blocktype', $this->get('blocktype')); $elements = call_static_method($blocktypeclass, 'instance_config_form', $this, $this->get_view()->get('template')); // Block types may specify a method to generate a default title for a block $hasdefault = method_exists($blocktypeclass, 'get_instance_title'); $title = $this->get('title'); $configdata = $this->get('configdata'); $retractable = isset($configdata['retractable']) ? $configdata['retractable'] : false; $retractedonload = isset($configdata['retractedonload']) ? $configdata['retractedonload'] : $retractable; if (call_static_method($blocktypeclass, 'override_instance_title', $this)) { $titleelement = array('type' => 'hidden', 'value' => $title); } else { $titleelement = array('type' => 'text', 'title' => get_string('blocktitle', 'view'), 'description' => $hasdefault ? get_string('defaulttitledescription', 'blocktype.' . blocktype_name_to_namespaced($this->get('blocktype'))) : null, 'defaultvalue' => $title, 'rules' => array('maxlength' => 255), 'hidewhenempty' => $hasdefault, 'expandtext' => get_string('setblocktitle')); } $elements = array_merge(array('title' => $titleelement, 'blockconfig' => array('type' => 'hidden', 'value' => $this->get('id')), 'id' => array('type' => 'hidden', 'value' => $this->get('view')), 'change' => array('type' => 'hidden', 'value' => 1), 'new' => array('type' => 'hidden', 'value' => $new)), $elements, array('retractable' => array('type' => 'select', 'title' => get_string('retractable', 'view'), 'description' => get_string('retractabledescription', 'view'), 'options' => array(BlockInstance::RETRACTABLE_NO => get_string('no'), BlockInstance::RETRACTABLE_YES => get_string('yes'), BlockInstance::RETRACTABLE_RETRACTED => get_string('retractedonload', 'view')), 'defaultvalue' => $retractable + $retractedonload))); if ($new) { $cancel = get_string('remove'); $elements['removeoncancel'] = array('type' => 'hidden', 'value' => 1); $elements['sure'] = array('type' => 'hidden', 'value' => 1); } else { $cancel = get_string('cancel'); } // Add submit/cancel buttons $elements['action_configureblockinstance_id_' . $this->get('id')] = array('type' => 'submitcancel', 'class' => 'btn-default', 'value' => array(get_string('save'), $cancel), 'goto' => View::make_base_url()); $configdirs = array(get_config('libroot') . 'form/'); if ($this->get('artefactplugin')) { $configdirs[] = get_config('docroot') . 'artefact/' . $this->get('artefactplugin') . '/form/'; } $form = array('name' => 'instconf', 'renderer' => 'div', 'validatecallback' => array(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_validate'), 'successcallback' => array($this, 'instance_config_store'), 'jsform' => true, 'jssuccesscallback' => 'blockConfigSuccess', 'jserrorcallback' => 'blockConfigError', 'elements' => $elements, 'viewgroup' => $this->get_view()->get('group'), 'group' => $this->get_view()->get('group'), 'viewinstitution' => $this->get_view()->get('institution'), 'institution' => $this->get_view()->get('institution'), 'configdirs' => $configdirs, 'plugintype' => 'blocktype', 'pluginname' => $this->get('blocktype')); if (param_variable('action_acsearch_id_' . $this->get('id'), false)) { $form['validate'] = false; } require_once 'pieforms/pieform.php'; $pieform = new Pieform($form); if ($pieform->is_submitted()) { global $SESSION; $SESSION->add_error_msg(get_string('errorprocessingform')); } $html = $pieform->build(); // We probably need a new version of $pieform->build() that separates out the js // Temporary evil hack: if (preg_match('/<script type="(text|application)\\/javascript">(new Pieform\\(.*\\);)<\\/script>/', $html, $matches)) { $js = "var pf_{$form['name']} = " . $matches[2] . "pf_{$form['name']}.init();"; } else { $js = ''; } // We need to load any javascript required for the pieform. We do this // by checking for an api function that has been added especially for // the purpose, but that is not part of Pieforms. Maybe one day later // it will be though foreach ($elements as $key => $element) { $element['name'] = $key; $function = 'pieform_element_' . $element['type'] . '_views_js'; if (is_callable($function)) { $js .= call_user_func_array($function, array($pieform, $element)); } } $configjs = call_static_method($blocktypeclass, 'get_instance_config_javascript', $this); if (is_array($configjs)) { $js .= $this->get_get_javascript_javascript($configjs); } else { if (is_string($configjs)) { $js .= $configjs; } } // We need to load any dynamic css required for the pieform. We do this // by checking for an api function that has been added especially for // the purpose, but that is not part of Pieforms. Maybe one day later // it will be though $css = array(); foreach ($elements as $key => $element) { $element['name'] = $key; $function = 'pieform_element_' . $element['type'] . '_views_css'; if (is_callable($function)) { $css[] = call_user_func_array($function, array($pieform, $element)); } } $renderedform = array('html' => $html, 'javascript' => $js, 'css' => $css); return $renderedform; }
function auth_generate_registration_form_js($aform, $registerconfirm) { // The javascript needs to refer to field names, but they are obfuscated in this form, // so construct and build the form in separate steps, so we can get the field names. $form = new Pieform($aform); $institutionid = $form->get_name() . '_' . $form->hashedfields['institution']; $reasonid = $form->get_name() . '_' . $form->hashedfields['reason']; $formhtml = $form->build(); if (count($registerconfirm) == 1) { $js = ' jQuery(function($) { $("#' . $reasonid . '_container").removeClass("js-hidden"); $("#' . $reasonid . '_container textarea").removeClass("js-hidden"); $("#' . $reasonid . '_container").next("tr.textarea").removeClass("js-hidden"); }); '; } else { $url = get_config('wwwroot') . 'json/termsandconditions.php'; $js = ' var registerconfirm = ' . json_encode($registerconfirm) . '; jQuery(function($) { function show_reason(reasonid, value) { if (value) { $("#" + reasonid + "_container").removeClass("js-hidden"); $("#" + reasonid + "_container textarea").removeClass("js-hidden"); $("#" + reasonid + "_container").next("tr.textarea").removeClass("js-hidden"); // need to fetch the correct terms and conditions for the institution $.ajax({ type: "POST", dataType: "json", url: "' . $url . '", data: { "institution": value, } }).done(function (data) { if (data.content) { $("#termscontainer").html(data.content); } }); } else { $("#" + reasonid + "_container").addClass("js-hidden"); $("#" + reasonid + "_container textarea").addClass("js-hidden"); $("#" + reasonid + "_container").next("tr.textarea").addClass("js-hidden"); } } // For when page loads after error found on form completion var defaultselect = $j("#' . $institutionid . '").val(); var reasonid = "' . $reasonid . '"; if (defaultselect != 0 && registerconfirm[defaultselect] == 1) { show_reason(reasonid, defaultselect); } // For when select changes $("#' . $institutionid . '").change(function() { if (this.value && registerconfirm[this.value] == 1) { show_reason(reasonid, this.value); } else { show_reason(reasonid, null); } }); }); '; } return array($formhtml, $js); }
/** * present the login-link screen where users are asked if they want to link * the current loggedin local account to the remote saml one * * @param string $remoteuser * @param string $currentuser */ function auth_saml_loginlink_screen($remoteuser, $currentuser) { require_once 'pieforms/pieform.php'; $form = array('name' => 'loginlink', 'renderer' => 'div', 'successcallback' => 'auth_saml_loginlink_submit', 'method' => 'post', 'plugintype' => 'auth', 'pluginname' => 'saml', 'elements' => array('linklogins' => array('value' => '<div><b>' . get_string('linkaccounts', 'auth.saml', $remoteuser, $currentuser) . '</b></div><br/>'), 'submit' => array('type' => 'submitcancel', 'value' => array(get_string('link', 'auth.saml'), get_string('cancel')), 'goto' => get_config('wwwroot')), 'link_submitted' => array('type' => 'hidden', 'value' => 1)), 'dieaftersubmit' => false, 'iscancellable' => true); $form = new Pieform($form); $smarty = smarty(array(), array(), array(), array('pagehelp' => false, 'sidebars' => false)); $smarty->assign('form', $form->build()); $smarty->assign('PAGEHEADING', get_string('link', 'auth.saml')); $smarty->display('form.tpl'); exit; }
/** * Given an artefact object, return the form already rendered. * * @param object The artefact * @return string HTML containing <tr> tags at the top level. */ function license_form_files($prefix, $prefix2 = null) { if (!get_config('licensemetadata')) { return ''; } require_once 'pieforms/pieform.php'; if ($prefix2 !== null) { $prefix .= '_' . $prefix2; } $form = array('name' => $prefix, 'plugintype' => 'artefact', 'pluginname' => 'file', 'elements' => array($prefix . '_license' => license_form_el_basic(null), 'license_advanced' => license_form_el_advanced(null, $prefix . '_'))); $pie = new Pieform($form); $pie->build(); $rendered = $pie->get_property('elements'); if (empty($form['elements'][$prefix . '_license']['rules']['required'])) { $rowattr = ''; } else { $rowattr = 'class="required"'; } $html = ''; foreach (array($rendered[$prefix . '_license'], $rendered['license_advanced']['elements'][$prefix . '_licensor'], $rendered['license_advanced']['elements'][$prefix . '_licensorurl']) as $e) { $helphtml = preg_replace('/files_filebrowser_(edit_)?licens/', 'licens', $e['helphtml']); $html .= '<div class="form-group">' . $rowattr . '' . $e['labelhtml'] . '' . '' . $e['html'] . $helphtml . '</div>'; $rowattr = ''; } $html = str_replace('id="' . $prefix . '_' . $prefix . '_', 'id="' . $prefix . '_', $html); $html = str_replace('for="' . $prefix . '_' . $prefix . '_', 'for="' . $prefix . '_', $html); return $html; }
/** * Processes the form. Called by the {@link pieform} function. It simply * builds the form (processing it if it has been submitted), and returns * the HTML to display the form. * * @param array $data The form description hash * @return string The HTML representing the form */ public static function process($data) { /*{{{*/ $form = new Pieform($data); return $form->build(); }
$functions = get_records_array('external_services_functions', 'externalserviceid', $token->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>'; } } $oauthform['elements']['id' . $token->id . '_functions'] = array('value' => implode(', ', $function_list), 'type' => 'html', 'key' => $token->id); // token last access time $oauthform['elements']['id' . $token->id . '_last_access'] = array('value' => format_date(strtotime($token->ctime)), 'type' => 'html', 'key' => $token->id); // edit and delete buttons $oauthform['elements']['id' . $token->id . '_actions'] = array('value' => '<span class="actions text-inline">' . pieform(array('name' => 'webservices_server_delete_' . $token->id, 'renderer' => 'div', 'elementclasses' => false, 'successcallback' => 'webservices_oauth_token_submit', 'class' => 'div text-inline', 'jsform' => false, 'elements' => array('token' => array('type' => 'hidden', 'value' => $token->id), 'action' => array('type' => 'hidden', 'value' => 'delete'), 'submit' => array('type' => 'submit', 'class' => 'linkbtn text-inline', 'value' => get_string('delete'))))) . '</span>', 'type' => 'html', 'key' => $token->id, 'class' => 'actions'); } $pieform = new Pieform($oauthform); $oauthform = $pieform->build(false); } // put together the whole page $elements = array('user_tokens' => array('type' => 'fieldset', 'legend' => get_string('usertokens', 'auth.webservice'), 'elements' => array('sflist' => array('type' => 'html', 'value' => $userform)), 'collapsible' => false), 'oauth_tokens' => array('type' => 'fieldset', 'legend' => get_string('accesstokens', 'auth.webservice'), 'elements' => array('sflist' => array('type' => 'html', 'value' => $oauthform)), 'collapsible' => false)); $form = array('renderer' => 'div', 'type' => 'div', 'id' => 'maintable', 'name' => 'maincontainer', 'dieaftersubmit' => false, 'successcallback' => 'webservice_main_submit', 'elements' => $elements); /** * handle the callback for actions on the user token panel * - generate noew token * - delete token * * @param Pieform $form * @param array $values */ function webservices_user_token_submit(Pieform $form, $values) { global $USER, $SESSION;
/** * Custom webservices config page * - activate/deactivate webservices comletely * - activate/deactivat protocols - SOAP/XML-RPC/REST * - manage service clusters * - manage users and access tokens * * @return pieforms $element array */ function get_config_options_extended() { $protosform = array('name' => 'activate_webservice_protos', 'elements' => webservices_protocol_switch_form()); $protos = new Pieform($protosform); // certificate values from MNet $openssl = OpenSslRepo::singleton(); $yesno = array(true => get_string('yes'), false => get_string('no')); $elements = array('webservicesmaster' => array('type' => 'fieldset', 'legend' => get_string('protocolswitches', 'auth.webservice'), 'elements' => array('protos_help' => array('type' => 'html', 'value' => '<div><p>' . get_string('manage_protocols', 'auth.webservice') . '</p></div>'), 'masterswitchlabel' => array('type' => 'html', 'value' => '<h4 class="mtxl">' . get_string('masterswitch', 'auth.webservice') . '</h4>'), 'webservicesmasterswitchform' => webservices_master_switch_form()['webservicesmasterswitchform'], 'enablewebserviceprotos' => array('type' => 'html', 'value' => $protos->build(false))), 'collapsible' => true, 'collapsed' => true, 'name' => 'activate_webservices'), 'certificates' => array('type' => 'fieldset', 'legend' => get_string('certificates', 'auth.webservice'), 'elements' => array('protos_help' => array('type' => 'html', 'value' => '<div><p>' . get_string('manage_certificates', 'auth.webservice', get_config('wwwroot') . 'admin/site/networking.php') . '</p></div>'), 'pubkey' => array('type' => 'html', 'value' => '<h3 class="title">' . get_string('publickey', 'admin') . '</h3>' . '<div class="detail">' . get_string('publickeydescription2', 'admin', 365) . '</div>' . '<pre style="font-size: 0.7em; white-space: pre;">' . $openssl->certificate . '</pre>'), 'sha1fingerprint' => array('type' => 'html', 'value' => '<div><p>' . get_string('sha1fingerprint', 'auth.webservice', $openssl->sha1_fingerprint) . '</p></div>'), 'md5fingerprint' => array('type' => 'html', 'value' => '<div><p>' . get_string('md5fingerprint', 'auth.webservice', $openssl->md5_fingerprint) . '</p></div>'), 'expires' => array('type' => 'html', 'value' => '<div><p>' . get_string('publickeyexpireson', 'auth.webservice', format_date($openssl->expires)) . '</p></div>')), 'collapsible' => true, 'collapsed' => true, 'name' => 'activate_webservices_networking'), 'servicefunctiongroups' => array('type' => 'fieldset', 'legend' => get_string('servicefunctiongroups', 'auth.webservice'), 'elements' => array('sfgdescription' => array('value' => '<div><p>' . get_string('sfgdescription', 'auth.webservice') . '</p></div>'), 'webservicesservicecontainer' => array('type' => 'html', 'value' => service_fg_edit_form())), 'collapsible' => true, 'collapsed' => true, 'name' => 'webservices_function_groups'), 'servicetokens' => array('type' => 'fieldset', 'legend' => get_string('servicetokens', 'auth.webservice'), 'elements' => array('stdescription' => array('value' => '<div><p>' . get_string('stdescription', 'auth.webservice') . '</p></div>'), 'webservicestokenscontainer' => array('type' => 'html', 'value' => service_tokens_edit_form())), 'collapsible' => true, 'collapsed' => false, 'name' => 'webservices_token'), 'serviceusers' => array('type' => 'fieldset', 'legend' => get_string('manageserviceusers', 'auth.webservice'), 'elements' => array('sudescription' => array('value' => '<div><p>' . get_string('sudescription', 'auth.webservice') . '</p></div>'), 'webservicesuserscontainer' => array('type' => 'html', 'value' => service_users_edit_form())), 'collapsible' => true, 'collapsed' => false, 'name' => 'webservices_user')); $form = array('renderer' => 'div', 'type' => 'div', 'elements' => $elements); return $form; }
function webservice_server_list_form($sopts, $iopts) { global $USER, $THEME; $dbconsumers = get_records_sql_assoc(' SELECT osr.id as id, userid as userid, institution as institution, externalserviceid as externalserviceid, u.username as username, u.email as email, consumer_key as consumer_key, consumer_secret as consumer_secret, enabled as enabled, status as status, osr.ctime as issue_date, application_uri as application_uri, application_title as application_title, application_descr as application_descr, requester_name as requester_name, requester_email as requester_email, callback_uri as callback_uri FROM {oauth_server_registry} osr JOIN {usr} u ON osr.userid = u.id ORDER BY application_title, username ', array()); $form = ''; if (!empty($dbconsumers)) { $form = array('name' => 'webservices_tokens', 'elementclasses' => false, 'successcallback' => 'webservices_tokens_submit', 'renderer' => 'multicolumntable', 'elements' => array('application' => array('title' => ' ', 'class' => 'heading', 'type' => 'html', 'value' => get_string('application', 'auth.webservice')), 'username' => array('title' => ' ', 'type' => 'html', 'value' => get_string('owner', 'auth.webservice')), 'consumer_key' => array('title' => ' ', 'type' => 'html', 'value' => get_string('consumer_key', 'auth.webservice')), 'consumer_secret' => array('title' => ' ', 'type' => 'html', 'value' => get_string('consumer_secret', 'auth.webservice')), 'enabled' => array('title' => ' ', 'type' => 'html', 'value' => get_string('enabled')), 'calback_uri' => array('title' => ' ', 'type' => 'html', 'value' => get_string('callback', 'auth.webservice')), 'consumer_secret' => array('title' => ' ', 'type' => 'html', 'value' => get_string('consumer_secret', 'auth.webservice')))); foreach ($dbconsumers as $consumer) { $form['elements']['id' . $consumer->id . '_application'] = array('value' => $consumer->application_title, 'type' => 'html', 'key' => $consumer->consumer_key); if ($USER->is_admin_for_user($consumer->userid)) { $user_url = get_config('wwwroot') . 'admin/users/edit.php?id=' . $consumer->userid; } else { $user_url = get_config('wwwroot') . 'user/view.php?id=' . $consumer->userid; } $form['elements']['id' . $consumer->id . '_username'] = array('value' => '<a href="' . $user_url . '">' . $consumer->username . '</a>', 'type' => 'html', 'key' => $consumer->consumer_key); $form['elements']['id' . $consumer->id . '_consumer_key'] = array('value' => $consumer->consumer_key, 'type' => 'html', 'key' => $consumer->consumer_key); $form['elements']['id' . $consumer->id . '_consumer_secret'] = array('value' => $consumer->consumer_secret, 'type' => 'html', 'key' => $consumer->consumer_key); $form['elements']['id' . $consumer->id . '_enabled'] = array('value' => $consumer->enabled == 1 ? display_icon('enabled') : display_icon('disabled'), 'type' => 'html', 'class' => 'center', 'key' => $consumer->consumer_key); $form['elements']['id' . $consumer->id . '_calback_uri'] = array('value' => $consumer->callback_uri, 'type' => 'html', 'key' => $consumer->consumer_key); // edit and delete buttons $form['elements']['id' . $consumer->id . '_actions'] = array('value' => '<span class="actions inline">' . pieform(array('name' => 'webservices_server_edit_' . $consumer->id, 'renderer' => 'div', 'elementclasses' => false, 'successcallback' => 'webservices_server_submit', 'jsform' => false, 'elements' => array('token' => array('type' => 'hidden', 'value' => $consumer->id), 'action' => array('type' => 'hidden', 'value' => 'edit'), 'submit' => array('type' => 'image', 'src' => $THEME->get_url('images/btn_edit.png'), 'alt' => get_string('editspecific', 'mahara', $consumer->id), 'elementtitle' => get_string('edit'))))) . pieform(array('name' => 'webservices_server_delete_' . $consumer->id, 'renderer' => 'div', 'elementclasses' => false, 'successcallback' => 'webservices_server_submit', 'jsform' => false, 'elements' => array('token' => array('type' => 'hidden', 'value' => $consumer->id), 'action' => array('type' => 'hidden', 'value' => 'delete'), 'submit' => array('type' => 'image', 'src' => $THEME->get_url('images/btn_deleteremove.png'), 'alt' => get_string('deletespecific', 'mahara', $consumer->id), 'elementtitle' => get_string('delete'))))) . '</span>', 'type' => 'html', 'key' => $consumer->consumer_key, 'class' => 'webserviceconfigcontrols'); } $pieform = new Pieform($form); $form = $pieform->build(false); } $form = '<tr><td colspan="2">' . $form . '</td></tr><tr><td colspan="2">' . pieform(array('name' => 'webservices_token_generate', 'renderer' => 'div', 'validatecallback' => 'webservices_add_application_validate', 'successcallback' => 'webservices_add_application_submit', 'class' => 'oneline inline', 'jsform' => false, 'action' => get_config('wwwroot') . 'webservice/admin/oauthv1sregister.php', 'elements' => array('application' => array('type' => 'text', 'title' => get_string('application', 'auth.webservice') . ': '), 'institution' => array('type' => 'select', 'options' => $iopts), 'service' => array('type' => 'select', 'options' => $sopts), 'action' => array('type' => 'hidden', 'value' => 'add'), 'submit' => array('type' => 'submit', 'value' => get_string('add', 'auth.webservice'))))) . '</td></tr>'; $elements = array('register_server' => array('type' => 'fieldset', 'legend' => get_string('userapplications', 'auth.webservice'), 'elements' => array('sflist' => array('type' => 'html', 'value' => $form)), 'collapsible' => false)); $form = array('renderer' => 'table', 'type' => 'div', 'id' => 'maintable', 'name' => 'maincontainer', 'dieaftersubmit' => false, 'successcallback' => 'webservice_main_submit', 'elements' => $elements); return $form; }
/** * Builds the configuration pieform for the image browser * * @return array Array with two keys: 'html' for raw html, 'javascript' for * javascript to run */ public function build_image_browser_form() { require_once 'view.php'; static $renderedform; if (!empty($renderedform)) { return $renderedform; } safe_require('artefact', 'file'); $this->set('artefactplugin', 'file'); $elements['url'] = array('type' => 'text', 'title' => get_string('url'), 'size' => 50); $elements['artefactfieldset'] = array('type' => 'fieldset', 'collapsible' => true, 'collapsed' => true, 'legend' => get_string('image'), 'class' => 'last select-file mtl', 'elements' => array('artefactid' => self::config_filebrowser_element($this, null))); $configdata = $this->get('configdata'); $elements['sure'] = array('type' => 'hidden', 'value' => 1); // use these to determine which space to display to upload files to $elements['post'] = array('type' => 'hidden', 'value' => $this->post); $elements['group'] = array('type' => 'hidden', 'value' => $this->group); $elements['institution'] = array('type' => 'hidden', 'value' => $this->institution); $elements['view'] = array('type' => 'hidden', 'value' => $this->view); // tinymce specific elements $alignoptions = array('none' => '--', 'top' => 'Top', 'middle' => 'Middle', 'bottom' => 'Bottom', 'left' => 'Left', 'right' => 'Right'); $elements['toggleformatting'] = array('type' => 'html', 'class' => 'toggleablecontainer', 'value' => '<div id="formattingoptionstoggle" class="retracted arrow"><label>Image formatting options</label></div>'); $elements['formattingoptions'] = array('type' => 'container', 'name' => 'formattingoptions', 'class' => 'js-hidden', 'elements' => array('width' => array('type' => 'text', 'title' => get_string('dimensions'), 'size' => 3, 'rules' => array('maxlength' => 4)), 'height' => array('type' => 'text', 'size' => 3, 'rules' => array('maxlength' => 4)), 'constrain' => array('type' => 'switchbox', 'title' => get_string('constrain'), 'defaultvalue' => true), 'vspace' => array('type' => 'text', 'title' => get_string('vspace'), 'size' => 3, 'rules' => array('maxlength' => 2)), 'hspace' => array('type' => 'text', 'title' => get_string('hspace'), 'size' => 3, 'rules' => array('maxlength' => 2)), 'border' => array('type' => 'text', 'title' => get_string('border'), 'size' => 3, 'rules' => array('maxlength' => 2)), 'align' => array('defaultvalue' => 'none', 'type' => 'select', 'title' => get_string('alignment'), 'options' => $alignoptions), 'style' => array('type' => 'text', 'title' => get_string('style'), 'size' => 50))); $wwwroot = get_config('wwwroot'); $goto = ""; if ($this->view) { $goto = $wwwroot . 'view/blocks.php' . View::make_base_url(); // editing forum topic } else { if ($this->post) { $goto = $wwwroot . "interaction/forum/edittopic.php?id=" . $this->post; } else { if ($this->group) { // editing forum itself $goto = $wwwroot . "interaction/edit.php?id=" . $this->group; } } } // Add submit/cancel buttons // goto should not be used by those with javascript - cancel is handled by js function which simply removes the image browser $elements['action_submitimage'] = array('type' => 'submitcancel', 'class' => 'btn-default', 'value' => array(get_string('submit'), get_string('cancel')), 'goto' => $goto); $configdirs = array(get_config('libroot') . 'form/'); if ($this->get('artefactplugin')) { $configdirs[] = get_config('docroot') . 'artefact/' . $this->get('artefactplugin') . '/form/'; } $form = array('name' => 'imgbrowserconf', 'action' => get_config('wwwroot') . 'json/imagebrowser.json.php', 'renderer' => 'div', 'validatecallback' => array($this, 'config_validate'), 'successcallback' => array($this, 'config_success'), 'jsform' => true, 'jssuccesscallback' => 'imageBrowserConfigSuccess', 'jserrorcallback' => 'imageBrowserConfigError', 'elements' => $elements, 'viewgroup' => $this->get_view()->get('group'), 'group' => $this->get('group'), 'viewinstitution' => $this->get_view()->get('institution'), 'institution' => $this->get('institution'), 'configdirs' => $configdirs, 'plugintype' => 'blocktype', 'pluginname' => $this->get('blocktype')); require_once 'pieforms/pieform.php'; $pieform = new Pieform($form); if ($pieform->is_submitted()) { global $SESSION; $SESSION->add_error_msg(get_string('errorprocessingform')); } $html = $pieform->build(); // We probably need a new version of $pieform->build() that separates out the js // Temporary evil hack: if (preg_match('/<script type="(text|application)\\/javascript">(new Pieform\\(.*\\);)<\\/script>/', $html, $matches)) { $js = "var pf_{$form['name']} = " . $matches[2] . "pf_{$form['name']}.init();"; } else { $js = ''; } // We need to load any javascript required for the pieform. We do this // by checking for an api function that has been added especially for // the purpose, but that is not part of Pieforms. Maybe one day later // it will be though // $js = ''; foreach ($elements as $key => $element) { $element['name'] = $key; $function = 'pieform_element_' . $element['type'] . '_views_js'; if (is_callable($function)) { $js .= call_user_func_array($function, array($pieform, $element)); } } $renderedform = array('html' => $html, 'javascript' => $js); return $renderedform; }
/** * Builds the configuration pieform for this blockinstance * * @return array Array with two keys: 'html' for raw html, 'javascript' for * javascript to run */ public function build_configure_form($new = false) { static $renderedform; if (!empty($renderedform)) { return $renderedform; } safe_require('blocktype', $this->get('blocktype')); $elements = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_form', $this, $this->get_view()->get('template')); $blocktypeclass = generate_class_name('blocktype', $this->get('blocktype')); if ($this->get('title') != call_static_method($blocktypeclass, 'get_title')) { // If the title for this block has been set to something other than // the block title, use it unconditionally $title = $this->get('title'); } else { if (method_exists($blocktypeclass, 'get_instance_title')) { // Block types can specify a default title for a block $title = call_static_method($blocktypeclass, 'get_instance_title', $this); } else { // A block that doesn't have a method for setting an instance // title, and hasn't had its title changed (e.g. a new textbox) $title = $this->get('title'); } } $elements = array_merge(array('title' => array('type' => 'text', 'title' => get_string('blocktitle', 'view'), 'description' => method_exists($blocktypeclass, 'get_instance_title') ? get_string('defaulttitledescription', 'blocktype.' . blocktype_name_to_namespaced($this->get('blocktype'))) : null, 'defaultvalue' => $title), 'blockconfig' => array('type' => 'hidden', 'value' => $this->get('id')), 'id' => array('type' => 'hidden', 'value' => $this->get('view')), 'change' => array('type' => 'hidden', 'value' => 1), 'new' => array('type' => 'hidden', 'value' => $new)), $elements); if ($new) { $cancel = get_string('remove'); $elements['removeoncancel'] = array('type' => 'hidden', 'value' => 1); $elements['sure'] = array('type' => 'hidden', 'value' => 1); } else { $cancel = get_string('cancel'); } // Add submit/cancel buttons $elements['action_configureblockinstance_id_' . $this->get('id')] = array('type' => 'submitcancel', 'value' => array(get_string('save'), $cancel), 'goto' => View::make_base_url()); $configdirs = array(get_config('libroot') . 'form/'); if ($this->get('artefactplugin')) { $configdirs[] = get_config('docroot') . 'artefact/' . $this->get('artefactplugin') . '/form/'; } $form = array('name' => 'instconf', 'renderer' => 'maharatable', 'validatecallback' => array(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_validate'), 'successcallback' => array($this, 'instance_config_store'), 'jsform' => true, 'jssuccesscallback' => 'blockConfigSuccess', 'jserrorcallback' => 'blockConfigError', 'elements' => $elements, 'viewgroup' => $this->get_view()->get('group'), 'group' => $this->get_view()->get('group'), 'viewinstitution' => $this->get_view()->get('institution'), 'institution' => $this->get_view()->get('institution'), 'configdirs' => $configdirs, 'plugintype' => 'blocktype', 'pluginname' => $this->get('blocktype')); if (param_variable('action_acsearch_id_' . $this->get('id'), false)) { $form['validate'] = false; } require_once 'pieforms/pieform.php'; $pieform = new Pieform($form); if ($pieform->is_submitted()) { global $SESSION; $SESSION->add_error_msg(get_string('errorprocessingform')); } $html = $pieform->build(); // We probably need a new version of $pieform->build() that separates out the js // Temporary evil hack: if (preg_match('/<script type="text\\/javascript">(new Pieform\\(.*\\);)<\\/script>/', $html, $matches)) { $js = "var pf_{$form['name']} = " . $matches[1] . "pf_{$form['name']}.init();"; } else { $js = ''; } // We need to load any javascript required for the pieform. We do this // by checking for an api function that has been added especially for // the purpose, but that is not part of Pieforms. Maybe one day later // it will be though // $js = ''; foreach ($elements as $key => $element) { $element['name'] = $key; $function = 'pieform_element_' . $element['type'] . '_views_js'; if (is_callable($function)) { $js .= call_user_func_array($function, array($pieform, $element)); } } $renderedform = array('html' => $html, 'javascript' => $js); return $renderedform; }
/** * Processes the form. Called by the {@link pieform} function. It simply * builds the form (processing it if it has been submitted), and returns * the HTML to display the form. * * @param array $data The form description hash * @return string The HTML representing the form */ public static function process($data) { /*{{{*/ $form = new Pieform($data); if ($form->get_property('backingout')) { return FALSE; } else { return $form->build(); } }
/** * Creates and displays the transient login page. * * This login page remembers all GET/POST data and passes it on. This way, * users can have their sessions time out, and then can log in again without * losing any of their data. * * As this function builds and validates a login form, it is possible that * calling this may validate a user to be logged in. * * @param Pieform $form If specified, just build this form to get the HTML * required. Otherwise, this function will build and * validate the form itself. * @access private */ function auth_draw_login_page($message = null, Pieform $form = null) { global $USER, $SESSION; if ($form != null) { $loginform = get_login_form_js($form->build()); } else { require_once 'pieforms/pieform.php'; $loginform = get_login_form_js(pieform(auth_get_login_form())); /* * If $USER is set, the form was submitted even before being built. * This happens when a user's session times out and they resend post * data. The request should just continue if so. */ if ($USER->is_logged_in()) { return; } } if ($message) { $SESSION->add_info_msg($message); } $smarty = smarty(array(), array(), array(), array('pagehelp' => false)); $smarty->assign('login_form', $loginform); $smarty->assign('loginmessage', get_string('loginto', 'mahara', get_config('sitename'))); $smarty->display('login.tpl'); exit; }