function cf_shortcode() { ob_start(); submitted(); html_form_code(); return ob_get_clean(); }
private function editForm() { global $CORE; echo '<h2>' . l('Modify Template') . '</h2>'; $map_name = req('show'); if (!$map_name) { throw new NagVisException(l('Map name missing')); } if (count($CORE->getAvailableMaps('/^' . preg_quote($map_name) . '$/')) == 0) { throw new NagVisException(l('A map with this name does not exists')); } $MAPCFG = new GlobalMapCfg($map_name); $MAPCFG->readMapConfig(!ONLY_GLOBAL, false, false); $name = submitted('edit') ? post('name') : null; // Check if the template exists // Read map config but don't resolve templates and don't use the cache if ($name) { if (count($MAPCFG->getTemplateNames('/^' . $name . '$/')) == 0) { throw new FieldInputError('name', l('A template with this name does not exist.')); } $templates = $MAPCFG->getDefinitions('template'); $obj_id = $MAPCFG->getTemplateIdByName($name); $options = array(); foreach ($templates[$obj_id] as $key => $val) { if ($key != 'type' && $key != 'object_id' && $key != 'name') { $options[$key] = $val; } } $num_options = max(post('num_options'), count($options)); } if (is_action() && post('mode') == 'edit') { try { // Get all options from the POST vars $save_options = array('name' => $name); $options = array(); for ($i = 0; $i < $num_options; $i++) { $key = post('key_' . $i); $val = post('val_' . $i); if ($key !== '' && $val !== '') { $save_options[$key] = $val; $options[$key] = $val; } } $MAPCFG->updateElement($obj_id, $save_options, true); success(l('The template has been modified.')); } catch (FieldInputError $e) { form_error($e->field, $e->msg); } catch (NagVisException $e) { form_error(null, $e->message()); } catch (Exception $e) { if (isset($e->msg)) { form_error(null, $e->msg); } else { throw $e; } } } echo $this->error; js_form_start('edit'); hidden('mode', 'edit'); echo '<table class="mytable">'; echo '<tr><td class="tdlabel">' . l('Name') . '</td>'; echo '<td class="tdfield">'; $choices = array('' => l('Please choose')); foreach (array_keys($MAPCFG->getTemplateNames()) as $tmpl_name) { $choices[$tmpl_name] = $tmpl_name; } select('name', $choices, '', 'updateForm(this.form)'); echo '</td></tr>'; if ($name) { hidden('num_options', $num_options); if (post('mode') == 'edit' && post('_add_option')) { $num_options += 1; } echo '<tr><td>' . l('Key') . '</td><td>' . l('Value') . '</td></tr>'; for ($i = 0; $i < $num_options; $i++) { if ($i < count($options)) { $keys = array_keys($options); $_POST['key_' . $i] = $keys[$i]; $values = array_values($options); $_POST['val_' . $i] = $values[$i]; } else { unset($_POST['key_' . $i]); unset($_POST['val_' . $i]); } echo '<tr><td class="tdlabel">'; input('key_' . $i); echo '</td><td class="tdfield">'; input('val_' . $i); echo '</td></tr>'; } echo '<tr><td></td><td class="tdfield">'; button('_add_option', l('Add Option'), 'addOption(this.form)'); echo '</td></tr>'; } echo '</table>'; submit(l('Modify')); form_end(); }
private function editForm($mode = 'add') { global $CORE; if ($mode == 'add') { echo '<h2>' . l('Add Backend') . '</h2>'; } else { echo '<h2>' . l('Edit Backend') . '</h2>'; } $backend_type = submitted($mode) ? post('backend_type') : null; $backend_id = submitted($mode) ? post('backend_id') : null; if (is_action() && post('mode') == $mode) { try { if ($mode == 'add' && (!$backend_type || !in_array($backend_type, $this->available_backends))) { throw new FieldInputError('backend_type', l('You need to choose a backend type.')); } if (!$backend_id || !preg_match(MATCH_BACKEND_ID, $backend_id)) { throw new FieldInputError('backend_id', l('You need to specify a identifier for the backend.')); } if ($mode == 'add' && isset($this->defined_backends[$backend_id])) { throw new FieldInputError('backend_id', l('This ID is already used by another backend.')); } elseif ($mode == 'edit' && !isset($this->editable_backends[$backend_id])) { throw new FieldInputError('backend_id', l('The choosen backend does not exist.')); } if ($mode == 'add') { // Set standard values $CORE->getUserMainCfg()->setSection('backend_' . $backend_id); $CORE->getUserMainCfg()->setValue('backend_' . $backend_id, 'backendtype', $backend_type); } else { $backend_type = cfg('backend_' . $backend_id, 'backendtype'); } $found_option = false; foreach ($this->backend_attributes($backend_type) as $key => $opt) { if ($key == 'backendtype') { continue; } // If there is a value for this option, set it $val = post($key); if ($opt['must'] && !$val) { throw new FieldInputError($key, l('You need to configure this option.')); } elseif ($val != null) { if (!preg_match($opt['match'], $val)) { throw new FieldInputError($key, l('Invalid value provided. Needs to match: [P].', array('P' => $opt['match']))); } $CORE->getUserMainCfg()->setValue('backend_' . $backend_id, $key, $val); } } // Persist the changes $CORE->getUserMainCfg()->writeConfig(); if ($mode == 'add') { success(l('The new backend has been added.')); } else { success(l('The changes have been saved.')); } } catch (FieldInputError $e) { form_error($e->field, $e->msg); } catch (Exception $e) { if (isset($e->msg)) { form_error(null, $e->msg); } else { throw $e; } } } echo $this->error; js_form_start($mode); hidden('mode', $mode); echo '<table name="mytable" class="mytable">'; if ($mode == 'add') { echo '<tr><td class="tdlabel">' . l('Backend ID') . '</td>'; echo '<td class="tdfield">'; input('backend_id'); echo '</td></tr>'; echo '<tr><td class="tdlabel">' . l('Backend Type') . '</td>'; echo '<td class="tdfield">'; $choices = array('' => l('Please choose')); foreach ($this->available_backends as $choice) { $choices[$choice] = $choice; } select('backend_type', $choices, '', 'updateForm(this.form)'); } else { echo '<tr><td class="tdlabel">' . l('Backend ID') . '</td>'; echo '<td class="tdfield">'; $choices = array('' => l('Please choose')); foreach ($this->editable_backends as $choice) { $choices[$choice] = $choice; } select('backend_id', $choices, '', 'updateForm(this.form)'); echo '</td></tr>'; } if ($mode == 'add' && $backend_type || $mode == 'edit' && $backend_id) { if ($mode == 'edit') { $opts = $this->backend_options($backend_id); $backend_type = $opts['backendtype']; } else { $opts = array(); } foreach ($this->backend_attributes($backend_type) as $key => $opt) { if ($key == 'backendtype') { continue; } $val = isset($opts[$key]) ? $opts[$key] : null; echo '<tr><td class="tdlabel">' . $key . '</td>'; // FIXME: Add checkbox for selecting the option, show default values echo '<td class="tdfield">'; input($key, $val); echo '</td></tr>'; } } echo '</td></tr>'; echo '</table>'; submit(l('Save')); form_end(); }
function upload($name) { global $form_keys, $form_errors, $form_name; $form_keys[$name] = true; $class = ''; if (submitted($form_name) && isset($form_errors[$name])) { $class .= ' err'; } if (trim($class)) { $class = ' class="' . $class . '"'; } echo '<input type="file" name="' . $name . '"' . $class . ' />' . N; }
<?php htmlHeader($title, $rRec->strCSSFN, $js); startBody(); submitted($rRec); endBody($this); function htmlHeader($title, $strCSSFN, &$js) { //--------------------------------------------------------------------- // //--------------------------------------------------------------------- echoT(' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>' . $title . '</title> <link href="' . base_url() . 'css/vol_reg/' . $strCSSFN . '" rel="stylesheet" type="text/css" /> <link type="text/css" href="' . base_url() . 'css/shady/jquery-ui-1.8.2.custom.css" rel="stylesheet" /> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css"> <noscript> Javascript is not enabled! Please turn on Javascript to use this site. </noscript> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script> <script type="text/javascript"> //<![CDATA[ base_url = \'' . base_url() . '\';
private function modifyForm() { global $AUTHORISATION; echo '<h2>' . l('Modify Role') . '</h2>'; $role_id = submitted('edit') ? post('role_id') : null; if (is_action() && post('mode') == 'edit') { try { if ($role_id === null || $role_id === '') { throw new FieldInputError('role_id', l('Please choose a role to edit.')); } if (!is_numeric($role_id)) { throw new FieldInputError('role_id', l('Invalid value provided.')); } $role_id = intval($role_id); $found = false; foreach ($AUTHORISATION->getAllRoles() as $role) { if ($role['roleId'] == $role_id) { $found = true; } } if (!$found) { throw new NagVisException('Invalid role id provided'); } // Load permissions from parameters $perms = array(); foreach (array_keys($_POST) as $key) { if (strpos($key, 'perm_') !== false) { $key_parts = explode('_', $key); $perm_id = $key_parts[1]; $perms[$perm_id] = get_checkbox($key); } } scroll_up(); // On success, always scroll to top of page if ($AUTHORISATION->updateRolePerms($role_id, $perms)) { success(l('The permissions for this role have been updated.')); } else { throw new NagVisException(l('Problem while updating role permissions.')); } } catch (FieldInputError $e) { form_error($e->field, $e->msg); } catch (NagVisException $e) { form_error(null, $e->message()); } catch (Exception $e) { if (isset($e->msg)) { form_error(null, $e->msg); } else { throw $e; } } } echo $this->error; js_form_start('edit'); hidden('mode', 'edit'); echo '<table class="mytable">'; echo '<tr><td class="tdlabel">' . l('Select Role') . '</td>'; echo '<td class="tdfield">'; $choices = array('' => l('Please choose')); foreach ($AUTHORISATION->getAllRoles() as $role) { $choices[$role['roleId']] = $role['name']; } select('role_id', $choices, '', 'updateForm(this.form)'); echo '</td></tr>'; echo '</table>'; $this->renderPermissions($role_id); submit(l('Save')); form_end(); }
private function editForm() { global $AUTH, $AUTHORISATION; if (!$AUTHORISATION->rolesConfigurable()) { return; } echo '<h2>' . l('Modify User') . '</h2>'; $user_id = submitted('edit') ? post('user_id') : null; if (is_action() && post('mode') == 'edit') { try { if ($user_id === null || $user_id === '') { throw new FieldInputError('user_id', l('Please choose a user to edit.')); } if (!is_numeric($user_id)) { throw new FieldInputError('user_id', l('Invalid value provided.')); } $user_id = intval($user_id); $roles = explode(',', post('user_roles')); if ($AUTHORISATION->updateUserRoles($user_id, $roles)) { success(l('The roles for this user have been updated.')); } else { throw new NagVisException(l('Problem while updating user roles.')); } } catch (FieldInputError $e) { form_error($e->field, $e->msg); } catch (NagVisException $e) { form_error(null, $e->message()); } catch (Exception $e) { if (isset($e->msg)) { form_error(null, $e->msg); } else { throw $e; } } } echo $this->error; js_form_start('edit'); hidden('mode', 'edit'); echo '<table class="mytable">'; echo '<tr><td class="tdlabel">' . l('Name') . '</td>'; echo '<td class="tdfield">'; $choices = array('' => l('Please choose')); foreach ($AUTH->getAllUsers() as $user) { $choices[$user['userId']] = $user['name']; } select('user_id', $choices, '', 'updateForm(this.form)'); echo '</td></tr>'; echo '</table>'; if ($user_id) { $user_roles = array(); foreach ($AUTHORISATION->getUserRoles($user_id) as $role) { $user_roles[$role['roleId']] = $role['name']; } $available_roles = array(); foreach ($AUTHORISATION->getAllRoles() as $role) { if (!isset($user_roles[$role['roleId']])) { $available_roles[$role['roleId']] = $role['name']; } } hidden('user_roles', implode(',', array_keys($user_roles))); echo '<table class="mytable">'; echo '<tr><td>' . l('Available Roles') . '</td>'; echo '<td style="width:30px"></td>'; echo '<td>' . l('Selected Roles') . '</td></tr>'; echo '<tr><td>'; select('roles_available', $available_roles, '', '', 'width:100%', 5); echo '</td><td style="vertical-align:middle">'; button('add', '>', 'updateUserRoles(true)'); button('remove', '<', 'updateUserRoles()'); echo '</td><td>'; select('roles_selected', $user_roles, '', '', 'width:100%', 5); echo '</td></tr></table>'; } submit(l('Save')); form_end(); }
function select($name, $options, $default = '', $onchange = '', $style = '', $size = null) { global $form_keys, $form_name; $form_keys[$name] = true; $class = ''; if (has_form_error($name)) { $class .= ' err'; } if (trim($class)) { $class = ' class="' . trim($class) . '"'; } if (submitted($form_name) || !submitted()) { // this or none submitted $default = post($name, $default); } if ($onchange != '') { $onchange = ' onchange="' . $onchange . '"'; } if ($style != '') { $style = ' style="' . $style . '"'; } // for sequential arrays use the values for the keys and the values if (array_keys($options) === range(0, count($options) - 1)) { $new_options = array(); foreach ($options as $values) { $new_options[$values] = $values; } $options = $new_options; } $multiple = ''; if ($size !== null) { $multiple = ' size="' . $size . '" multiple'; } $ret = '<select id="' . $name . '" name="' . $name . '"' . $onchange . $class . $style . $multiple . '>' . N; foreach ($options as $value => $display) { $select = ''; if ($value == $default) { $select = ' selected'; } $ret .= '<option value="' . $value . '"' . $select . '>' . $display . '</option>' . N; } $ret .= '</select>' . N; echo $ret; show_form_render_error($name); }
/** * Processes the form submission and redirects if NONCE requirement not met. * If not a post, returns successfully. If POSTed NONCE value exists but * doesn't match SESSSION NONCE, redirects to default NONCE mismatch page. * If POSTed NONCE doesn't exist, either returns "FALSE", or redirects to * NONCE mismatch page, depending on options. If POSTed NONCE exists and matches * SESSION NONCE, returns TRUE. */ function formProcessNonce($nonceFailPage = 'nonce_fail', $ignoreMissing = true) { if (!submitted(true)) { return true; } $noncePass = checkNonce(); $baseUrl = getBaseUrl(); if (!$noncePass) { die("<h2>NONCE failed; see log</h2>"); header("Location: $baseUrl/$nonceFailPage"); } return true; }
/** * @brief display course user assingment * @global type $langNoAssignmentsExist * @global type $langGroupWorkSubmitted * @global type $langGroupWorkNotSubmitted * @global type $langGroupWorkDeadline_of_Submission * @global type $langGroupWorkSubmitted * @global type $urlServer * @param type $param * @param type $type * @return string */ function getUserAssignments($lesson_id) { global $langNoAssignmentsExist, $langGroupWorkSubmitted, $langDays, $langDaysLeft, $langGroupWorkDeadline_of_Submission, $langGroupWorkSubmitted, $urlServer, $uid; $found = false; $assign_content = '<table width="100%">'; foreach ($lesson_id as $lid) { $q = Database::get()->queryArray("SELECT DISTINCT assignment.id, assignment.title, assignment.deadline,\n (TO_DAYS(assignment.deadline) - TO_DAYS(NOW())) AS days_left\n FROM assignment, course, course_module\n WHERE (TO_DAYS(deadline) - TO_DAYS(NOW())) >= '0'\n AND assignment.active = 1\n AND assignment.course_id = ?d\n AND course.id = ?d\n AND course_module.course_id = course.id\n AND course_module.visible = 1 AND course_module.module_id = " . MODULE_ID_ASSIGN . "\n ORDER BY assignment.deadline", $lid, $lid); if ($q) { $found = true; $assign_content .= "<tr><td class='sub_title1'>" . q(ellipsize(course_id_to_title($lid), 70)) . "</td></tr>"; foreach ($q as $data) { $url = $urlServer . "modules/work/index.php?course=" . course_id_to_code($lid) . "&i=" . $data->id; if (submitted($uid, $data->id, $lid)) { $submit_status = $langGroupWorkSubmitted; } else { $submit_status = "({$langDaysLeft} {$data->days_left} {$langDays})"; } $assign_content .= "<tr><td><ul class='custom_list'><li><a href='{$url}'><b>" . q($data->title) . "</b></a><div class='smaller'>{$langGroupWorkDeadline_of_Submission}: <b>" . nice_format($data->deadline, true) . "</b><div class='grey'>" . $submit_status . "</div></div></li></ul></td></tr>"; } } } $assign_content .= "</table>"; if ($found) { return $assign_content; } else { return "<div class='alert alert-warning'>{$langNoAssignmentsExist}</div>"; } }