Example #1
0
function local_obu_forms_extend_navigation($navigation)
{
    global $CFG, $USER, $PAGE;
    if (!isloggedin() || isguestuser()) {
        return;
    }
    $context = context_system::instance();
    $staff_manager = has_capability('local/obu_forms:manage_pg', $context) || has_capability('local/obu_forms:manage_ump_staff', $context);
    $students_manager = has_capability('local/obu_forms:manage_pg', $context) || has_capability('local/obu_forms:manage_ump_students', $context);
    $manager = $staff_manager || $students_manager;
    $staff = is_staff($USER->username);
    // Has a 'p' number?
    $student = is_student($USER->id);
    // Enrolled on a PIP-based course (programme)?
    // Add the 'My Forms' option
    if ($manager || $staff || $student || !empty(get_form_data($USER->id))) {
        // Find the 'myprofile' node
        $nodeParent = $navigation->find('myprofile', navigation_node::TYPE_UNKNOWN);
        // Add the option to list their completed forms
        if ($nodeParent) {
            $node = $nodeParent->add(get_string('myforms', 'local_obu_forms'), '/local/obu_forms/index.php?userid=' . $USER->id);
        }
    }
    if (!$manager && !$staff && !$student) {
        // Move on now please, nothing more to see here...
        return;
    }
    // Find the 'forms' node
    $nodeParent = $navigation->find(get_string('forms', 'local_obu_forms'), navigation_node::TYPE_SYSTEM);
    // If necessary, add the 'forms' node to 'home'
    if (!$nodeParent) {
        $nodeHome = $navigation->children->get('1')->parent;
        if ($nodeHome) {
            $nodeParent = $nodeHome->add(get_string('forms', 'local_obu_forms'), null, navigation_node::TYPE_SYSTEM);
        }
    }
    if ($nodeParent) {
        // For form managers, add the privileged maintenance and enquiry options
        if ($manager) {
            $node = $nodeParent->add(get_string('settings_nav', 'local_obu_forms'), '/local/obu_forms/forms.php');
            $node = $nodeParent->add(get_string('template_nav', 'local_obu_forms'), '/local/obu_forms/template.php');
            $node = $nodeParent->add(get_string('auths_nav', 'local_obu_forms'), '/local/obu_forms/auths.php');
            $node = $nodeParent->add(get_string('sc_auths', 'local_obu_forms'), '/local/obu_forms/auths.php?authoriser=csa');
            $node = $nodeParent->add(get_string('list_users_forms', 'local_obu_forms'), '/local/obu_forms/list.php');
            $node = $nodeParent->add(get_string('formslist', 'local_obu_forms'), '/local/obu_forms/formslist.php');
        } else {
            // For other users, add the option(s) to list all the relevant forms
            if ($staff) {
                $node = $nodeParent->add(get_string('staff_forms', 'local_obu_forms'), '/local/obu_forms/formslist.php?type=staff');
            }
            $node = $nodeParent->add(get_string('student_forms', 'local_obu_forms'), '/local/obu_forms/formslist.php?type=student');
            // Both staff and students can view student forms
            if ($staff) {
                $node = $nodeParent->add(get_string('list_users_forms', 'local_obu_forms'), '/local/obu_forms/list.php');
            }
        }
    }
}
function smarty_block_select($params, $content, $template, &$repeat)
{
    if ($repeat) {
        // Skip the first time
        return;
    }
    $attr = get_attr($params, $template);
    $field = get_field($params, $template);
    $CI =& get_instance();
    if (isset($field->model)) {
        $CI->load->model($field->model);
        $parent_vars = $template->parent->tpl_vars;
        $form_data = get_form_data($parent_vars);
        $options = widget_select_get_options(get_default($params, 'options', array()), $form_data, $field, $CI->{$field->model});
    } else {
        $options = get_default($params, 'options', array());
    }
    $attr['url'] = current_url();
    if (isset($field->filters)) {
        $hasfield = false;
        $rel = array();
        foreach ($field->filters as $key => $filter) {
            if (isset($filter->field)) {
                $rel[] = $filter->field;
                $hasfield = true;
            }
        }
        if ($hasfield) {
            $attr['data-rel'] = implode(',', $rel);
        }
    }
    if (isset($params['noselectboxit']) && $params['noselectboxit'] != '') {
        $attr["data-no-selectBoxIt"] = true;
    }
    $parent_vars = $template->parent->tpl_vars;
    $form_data = get_form_data($parent_vars);
    $selected = get_default($params, 'selected', array());
    $extra = _parse_form_attributes($attr, array());
    if (count($selected) == 0) {
        $selected = $attr['value'];
    }
    return form_dropdown($attr['name'], $options, $selected, $extra);
}
{
    $persona_array = array();
    if (isset($_POST)) {
        $persona_array['nombre'] = $_POST['nombre'];
        $persona_array['ap_pa'] = $_POST['ap_pa'];
        $persona_array['ap_ma'] = $_POST['ap_ma'];
        $persona_array['f_nacimiento'] = $_POST['f_nacimiento'];
        $persona_array['l_nacimiento'] = $_POST['l_nacimiento'];
        $persona_array['vio_sw'] = $_POST['star_wars'];
        $persona_array['prog_lang'] = $_POST['prog_lang'];
        $persona_array['star_wars'] = $_POST['star_wars'];
        return $persona_array;
    }
    return false;
}
$p_arr = get_form_data();
// var_dump($p_arr);
$p->set_nombre($p_arr['nombre']);
$p->set_ap_pa($p_arr['ap_pa']);
$p->set_ap_ma($p_arr['ap_ma']);
$p->set_l_nacimiento($p_arr['l_nacimiento']);
$p->set_f_nacimiento($p_arr['f_nacimiento']);
$p->set_vio_sw($p_arr['vio_sw']);
// var_dump($p); exit;
if ($p_errors = $p->get_errors()) {
    var_dump($p_errors);
    exit;
    foreach ($p_errors as $e) {
        echo $e;
    }
} else {
function get_attr($params, $template)
{
    $CI =& get_instance();
    $CI->load->helper('form');
    $parent_vars = $template->parent->tpl_vars;
    $f = get_field($params, $template);
    $field = $f->name;
    $state = get_default($params, 'state', null);
    if ($state != null) {
        $f->state = $state;
    }
    $classes = array();
    $value = get_default($params, 'value');
    $classes[] = get_default($params, 'class');
    $classes[] = 'form-control';
    $attr = get_default($params, 'attr', array());
    $class = implode(' ', $classes);
    $type = get_default($params, 'type', 'text');
    if ($f->defaultValue != '') {
        $value = $f->defaultValue;
    }
    // Added the support for CI Form Validation
    $setValue = set_value($f->name);
    if ($value == '' && $setValue != '') {
        $value = $setValue;
    }
    // Now for form object rendering
    $form_data = get_form_data($parent_vars);
    if (isset($f->mask)) {
        $json = new stdclass();
        if (is_string($f->mask)) {
            $json->mask = $f->mask;
        } else {
            $json = '';
            $jsonarray = (array) $f->mask;
            foreach ($jsonarray as $key => $value) {
                $json .= "'" . $key . "':'" . $value . "'";
            }
        }
        $json = str_replace('"', "'", json_encode($json));
        $attr['data-inputmask'] = substr($json, 1, strlen($json) - 2);
    }
    if (isset($form_data) && isset($form_data->{$field})) {
        $value = $form_data->{$field};
    }
    $attr['class'] = $class;
    $attr['name'] = $f->name;
    $attr['id'] = $f->getId();
    $attr['type'] = $type;
    $attr['value'] = $value;
    if ($f->state == 'disabled') {
        $attr['disabled'] = 'true';
    }
    $rules = $f->getJQValidationRules();
    foreach ($rules as $k => $v) {
        $attr[$k] = $v;
    }
    if (isset($f->placeholder) && $f->placeholder != '') {
        $attr['placeholder'] = lang($f->placeholder);
    } else {
        $attr['placeholder'] = get_default($params, 'placeholder', '');
    }
    if (isset($params['type']) && $params['type'] != '') {
        $attr['data-type'] = $params['type'];
    }
    return $attr;
}
        if (empty($_POST[$field_name])) {
            $err = "Field is required";
        } else {
            $val = process_input($_POST[$field_name]);
        }
    }
}
get_form_data("title", $title, $titleErr);
get_form_data("lecturer_name", $lecturer, $lecturerErr);
get_form_data("description", $description, $descriptionErr);
get_form_data("program", $program, $programErr);
get_form_data("course", $course, $courseErr);
get_form_data("type", $type, $typeErr);
get_form_data("name", $name, $nameErr);
get_form_data("lecturer_email", $lecturerEmail, $lecturerEmailErr);
get_form_data("materials", $materials, $materialsErr);
if (!empty($lecturerEmail)) {
    if (!ereg("^[A-Za-z0-9\\.|-|_]*[@]{1}[A-Za-z0-9\\.|-|_]*[.]{1}[a-z]{2,5}\$", $lecturerEmail)) {
        $lecturerEmailErr = "Invalid email format";
    }
}
if (!empty($materials)) {
    if (!ereg("^*.zip\$", $materials)) {
        $materialsErr = "File not zip.";
    }
}
?>

    <form method="post" action="<?php 
echo htmlspecialchars($_SERVER["PHP_SELF"]);
?>
Example #6
0
     echo "\n        <form action=help_vol_edit.php>\n        <input type=hidden name=old_email_addr value=\"{$email_addr}\">\n        <input type=hidden name=old_password value=\"{$password}\">\n    ";
     print_form($vol, 'edit_action');
     echo "</form>\n";
     page_tail();
 } else {
     if ($edit_action) {
         $old_email_addr = stripslashes($_GET['old_email_addr']);
         $old_password = stripslashes($_GET['old_password']);
         $vol = vol_lookup_email($old_email_addr);
         if (!$vol) {
             boinc_error_page("Bad email address {$old_email_addr}");
         }
         if ($old_password != $vol->password) {
             boinc_error_page("Bad password");
         }
         $vol2 = get_form_data();
         $vol2->timezone = $vol->timezone;
         $vol2->id = $vol->id;
         $retval = vol_update($vol2);
         if (!$retval) {
             echo mysql_error();
             page_head("database error");
             page_tail();
         } else {
             page_head("Update completed");
             echo "Your Help Volunteer account information has been updated.";
             page_tail();
         }
     } else {
         page_head("Register as a BOINC Help Volunteer");
         $vol = null;
if ($user->id == $USER->id) {
    $currentuser = true;
    $heading = get_string('myforms', 'local_obu_forms');
} else {
    $currentuser = false;
    // If we're looking at someone else's forms we may need to lock/remove some UI elements
    $PAGE->navigation->extend_for_user($user);
    $heading = get_string('forms', 'local_obu_forms') . ': ' . $user->firstname . ' ' . $user->lastname;
}
$PAGE->set_context(context_user::instance($user->id));
$PAGE->set_title($heading);
$PAGE->set_heading($heading);
// The page contents
echo $OUTPUT->header();
echo $OUTPUT->heading($heading);
$forms_data = get_form_data();
// get all forms data [*** NEEDS ATTENTION IN FUTURE ***]
foreach ($forms_data as $data) {
    $template = read_form_template_by_id($data->template_id);
    $form = read_form_settings($template->form_id);
    // If a staff form, allow a forms manager to extract any given student number
    $student = '';
    $student_number = '';
    if (!$form->student && is_manager($form)) {
        load_form_fields($data, $fields);
        if (array_key_exists('student_number', $fields)) {
            $student = $fields['student_number'];
            $student_number = ' [' . $student . ']';
        }
    }
    if ($data->author == $user->id || $student == $user->username) {