コード例 #1
0
ファイル: required.php プロジェクト: Br3nda/mahara
/**
 * Checks whether the field has been specified.
 *
 * @param Pieform $form    The form the rule is being applied to
 * @param string  $value   The value of the field
 * @param array   $element The element to check
 * @param string  $check   Whether to check the element
 * @return string         The error message, if the value is invalid.
 */
function pieform_rule_required(Pieform $form, $value, $element, $check)
{
    /*{{{*/
    if ($check && ($value == '' || $value == array())) {
        return $form->i18n('rule', 'required', 'required', $element);
    }
}
コード例 #2
0
ファイル: email.php プロジェクト: Br3nda/mahara
/**
 * Returns whether the given field is a valid e-mail address.
 *
 * Currently, the check is [anything]@[anything]. Someone is welcome to write
 * something better, this was made just for testing.
 *
 * @param Pieform $form    The form the rule is being applied to
 * @param string  $value   The e-mail address to check
 * @param array   $element The element to check
 * @return string          The error message, if there is something wrong with
 *                         the address.
 */
function pieform_rule_email(Pieform $form, $value, $element)
{
    /*{{{*/
    if (!preg_match('/^[A-Za-z0-9\\._%-]+@(?:[A-Za-z0-9-]+\\.)+[a-z]{2,4}$/', $value)) {
        return $form->i18n('rule', 'email', 'email', $element);
    }
}
コード例 #3
0
ファイル: changerole.php プロジェクト: patkira/mahara
function changerole_validate(Pieform $form, $values)
{
    global $user, $group;
    if (!group_can_change_role($group->id, $user->id, $values['role'])) {
        $form->set_error('role', get_string('usercannotchangetothisrole', 'group'));
    }
}
コード例 #4
0
/**
 * Renders a set of radio buttons for a form
 *
 * @param array    $element The element to render
 * @param Pieform  $form    The form to render the element for
 * @return string           The HTML for the element
 */
function pieform_element_radio(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) {
        throw new PieformException('Radio elements should have at least one option');
    }
    $result = '';
    $form_value = $form->get_value($element);
    $id = $element['id'];
    $separator = "\n";
    if (isset($element['separator'])) {
        $separator = $element['separator'] . $separator;
    }
    foreach ($element['options'] as $value => $data) {
        $uid = $id . substr(md5(microtime()), 0, 4);
        $element['id'] = $uid;
        if (is_array($data)) {
            $text = $data['text'];
            $description = isset($data['description']) ? $data['description'] : '';
        } else {
            $text = $data;
            $description = '';
        }
        $result .= '<input type="radio"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($value) . '"' . ($form_value == $value ? ' checked="checked"' : '') . '> <label for="' . $form->get_name() . '_' . $uid . '">' . Pieform::hsc($text) . "</label>" . ($description != '' ? '<div class="radio-description">' . $description . '</div>' : '') . $separator;
    }
    $result = substr($result, 0, -strlen($separator));
    return $result;
}
コード例 #5
0
ファイル: captcha.php プロジェクト: Br3nda/mahara
function pieform_element_captcha_get_value(Pieform $form, $element)
{
    global $SESSION;
    $name = $element['name'];
    $global = $form->get_property('method') == 'get' ? $_GET : $_POST;
    return isset($global[$name]) && strtolower($global[$name]) == strtolower($SESSION->get($form->get_name() . '_' . $name));
}
コード例 #6
0
ファイル: networking.php プロジェクト: sarahjcotton/mahara
function networkingform_submit(Pieform $form, $values)
{
    $reply = '';
    if ($form->get_submitvalue() === 'deletekey') {
        global $SESSION;
        $openssl = OpenSslRepo::singleton();
        $openssl->get_keypair(true);
        $SESSION->add_info_msg(get_string('keydeleted', 'admin'));
        // Using cancel here as a hack to get it to redirect so it shows the new keys
        $form->reply(PIEFORM_CANCEL, array('location' => get_config('wwwroot') . 'admin/site/networking.php'));
    }
    if (get_config('enablenetworking') != $values['enablenetworking']) {
        if (!set_config('enablenetworking', $values['enablenetworking'])) {
            networkingform_fail($form);
        } else {
            if (empty($values['enablenetworking'])) {
                $reply .= get_string('networkingdisabled', 'admin');
            } else {
                $reply .= get_string('networkingenabled', 'admin');
            }
        }
    }
    if (get_config('promiscuousmode') != $values['promiscuousmode']) {
        if (!set_config('promiscuousmode', $values['promiscuousmode'])) {
            networkingform_fail($form);
        } else {
            if (empty($values['promiscuousmode'])) {
                $reply .= get_string('promiscuousmodedisabled', 'admin');
            } else {
                $reply .= get_string('promiscuousmodeenabled', 'admin');
            }
        }
    }
    $form->reply(PIEFORM_OK, array('message' => $reply == '' ? get_string('networkingunchanged', 'admin') : $reply, 'goto' => '/admin/site/networking.php'));
}
コード例 #7
0
ファイル: div.php プロジェクト: Br3nda/mahara
/**
 * Renders form elements inside <div>s.
 *
 * @param Pieform $form    The form the element is being rendered for
 * @param array   $element The element to be rendered
 * @return string          The element rendered inside an appropriate container
 */
function pieform_renderer_div(Pieform $form, $element)
{
    /*{{{*/
    $formname = $form->get_name();
    // Set the class of the enclosing <div> to match that of the element
    $result = '<div';
    if (isset($element['name'])) {
        $result .= ' id="' . $formname . '_' . $element['name'] . '_container"';
    }
    if (!empty($element['class'])) {
        $result .= ' class="' . $element['class'] . '"';
    }
    $result .= '>';
    if (isset($element['labelhtml'])) {
        $result .= $element['labelhtml'];
    }
    //$result .= $builtelement;
    $result .= $element['html'];
    if (isset($element['helphtml'])) {
        $result .= ' ' . $element['helphtml'];
    }
    // Description - optional description of the element, or other note that should be visible
    // on the form itself (without the user having to hover over contextual help
    if ((!$form->has_errors() || $form->get_property('showdescriptiononerror')) && !empty($element['description'])) {
        $result .= '<div class="description"> ' . Pieform::hsc($element['description']) . "</div>";
    }
    if (!empty($element['error'])) {
        $result .= '<div class="errmsg">' . Pieform::hsc($element['error']) . '</div>';
    }
    $result .= "</div>\n";
    return $result;
}
コード例 #8
0
/**
 * Renders form elements all on one line.
 *
 * @param Pieform $form    The form the element is being rendered for
 * @param array   $element The element that is being rendered
 * @return string          The element rendered inside an appropriate container
 */
function pieform_renderer_oneline(Pieform $form, $element)
{
    /*{{{*/
    $formname = $form->get_name();
    // Set the class of the enclosing <div> to match that of the element
    $result = '<span';
    if (isset($element['name'])) {
        $result .= ' id="' . $formname . '_' . Pieform::hsc($element['name']) . '_container"';
    }
    if (!empty($element['class'])) {
        $result .= ' class="' . Pieform::hsc($element['class']) . '"';
    }
    $result .= '>';
    if (isset($element['labelhtml'])) {
        $result .= $element['labelhtml'];
    }
    if (isset($element['prehtml'])) {
        $result .= '<span class="prehtml">' . $element['prehtml'] . '</span>';
    }
    $result .= $element['html'];
    if (isset($element['posthtml'])) {
        $result .= '<span class="posthtml">' . $element['posthtml'] . '</span>';
    }
    $result .= "</span>";
    return $result;
}
コード例 #9
0
ファイル: cancelbackcreate.php プロジェクト: Br3nda/mahara
/**
 * Renders a submit and cancel button
 *
 * @param array    $element The element to render
 * @param Pieform  $form    The form to render the element for
 * @return string           The HTML for the element
 */
function pieform_element_cancelbackcreate(Pieform $form, $element)
{
    $form->include_plugin('element', 'submit');
    $form->include_plugin('element', 'cancel');
    $cancelelement = $element;
    $cancelelement['value'] = $element['value'][0];
    $backelement = $element;
    $backelement['name'] = 'back';
    $backelement['id'] = 'back';
    $backelement['value'] = $element['value'][1];
    $submitelement = $element;
    $submitelement['value'] = $element['value'][2];
    if (isset($element['confirm']) && isset($element['confirm'][0])) {
        $cancelelement['confirm'] = $element['confirm'][0];
    } else {
        unset($cancelelement['confirm']);
    }
    if (isset($element['confirm']) && isset($element['confirm'][1])) {
        $backelement['confirm'] = $element['confirm'][1];
    } else {
        unset($backelement['confirm']);
    }
    if (isset($element['confirm']) && isset($element['confirm'][2])) {
        $submitelement['confirm'] = $element['confirm'][2];
    } else {
        unset($submitelement['confirm']);
    }
    return pieform_element_cancel($form, $cancelelement) . ' ' . pieform_element_submit($form, $backelement) . ' ' . pieform_element_submit($form, $submitelement);
}
コード例 #10
0
ファイル: contact.php プロジェクト: Br3nda/mahara
function contactus_validate(Pieform $form, $values)
{
    $captcharequired = get_config('captcha_on_contact_form');
    if ((is_null($captcharequired) || $captcharequired) && !$values['captcha']) {
        $form->set_error('captcha', get_string('captchaincorrect'));
    }
}
コード例 #11
0
ファイル: button.php プロジェクト: rboyatt/mahara
/**
 * Renders an <input type="button"> element.
 *
 * The element must have the 'value' field set.
 *
 * @param Pieform $form    The form to render the element for
 * @param array   $element The element to render
 * @return string          The HTML for the element
 * @todo rename to inputbutton
 */
function pieform_element_button(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['value'])) {
        throw new PieformException('Button elements must have a value');
    }
    if (isset($element['confirm'])) {
        $element['data-confirm'] = Pieform::hsc($element['confirm']);
    }
    $element['class'] .= ' btn';
    if (isset($element['usebuttontag']) && $element['usebuttontag'] === true) {
        $value = '';
        $action = '';
        $type = 'type="submit" ';
        if (isset($element['content'])) {
            $content = $element['content'];
            $value = 'value="' . Pieform::hsc($element['value']) . '" ';
        } else {
            $content = $element['value'];
        }
        if (isset($element['action'])) {
            $action = 'formaction="' . Pieform::hsc($element['action']) . '" ';
        }
        $button = '<button ' . $value . $action . $type . $form->element_attributes($element) . '>' . $content . '</button>';
    } else {
        $button = '<input type="button"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($element['value']) . '">';
    }
    return $button;
}
コード例 #12
0
function importeuropassform_validate(Pieform $form, $values)
{
    global $USER, $SESSION;
    $filetype = $values['file']['type'];
    if (!$filetype || $filetype != 'text/xml') {
        $form->set_error('file', get_string('notvalidxmlfile', 'artefact.europass'));
    }
    // Check if at least one import option is checked...
    $options = array();
    if (!empty($values['identification'])) {
        $options[] = 'identification';
    }
    if (!empty($values['application'])) {
        $options[] = 'application';
    }
    if (!empty($values['workexperience'])) {
        $options[] = 'workexperience';
    }
    if (!empty($values['education'])) {
        $options[] = 'education';
    }
    if (!empty($values['languages'])) {
        $options[] = 'languages';
    }
    if (!empty($values['skills'])) {
        $options[] = 'skills';
    }
    if (!empty($values['additionalinfo'])) {
        $options[] = 'additionalinfo';
    }
    if (empty($options)) {
        $form->set_error('additionalinfo', get_string('nocheckedoptions', 'artefact.europass'));
    }
}
コード例 #13
0
ファイル: submitcancel.php プロジェクト: Br3nda/mahara
/**
 * Renders a submit and cancel button
 *
 * @param Pieform  $form    The form to render the element for
 * @param array    $element The element to render
 * @return string           The HTML for the element
 */
function pieform_element_submitcancel(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['value']) || !is_array($element['value']) || count($element['value']) != 2) {
        throw new PieformException('The submitcancel element "' . $element['name'] . '" must have a two element array for its value');
    }
    $form->include_plugin('element', 'submit');
    $form->include_plugin('element', 'cancel');
    $submitelement = $element;
    $submitelement['class'] = isset($submitelement['class']) ? $submitelement['class'] . ' submit' : 'submit';
    $submitelement['value'] = $element['value'][0];
    $cancelelement = $element;
    $cancelelement['class'] = isset($cancelelement['class']) ? $cancelelement['class'] . ' cancel' : 'cancel';
    $cancelelement['value'] = $element['value'][1];
    if (isset($element['confirm']) && isset($element['confirm'][0])) {
        $submitelement['confirm'] = $element['confirm'][0];
    } else {
        unset($submitelement['confirm']);
    }
    if (isset($element['confirm']) && isset($element['confirm'][1])) {
        $cancelelement['confirm'] = $element['confirm'][1];
    } else {
        unset($cancelelement['confirm']);
    }
    return pieform_element_submit($form, $submitelement) . ' ' . pieform_element_cancel($form, $cancelelement);
}
コード例 #14
0
ファイル: edit.php プロジェクト: Br3nda/mahara
function editgroup_validate(Pieform $form, $values)
{
    $cid = get_field('group', 'id', 'name', $values['name']);
    if ($cid && $cid != $values['id']) {
        $form->set_error('name', get_string('groupalreadyexists', 'group'));
    }
}
コード例 #15
0
function personalinformation_submit(Pieform $form, $values)
{
    global $personalinformation, $USER;
    $userid = $USER->get('id');
    $errors = array();
    try {
        if (empty($personalinformation)) {
            $personalinformation = new ArtefactTypePersonalinformation(0, array('owner' => $userid, 'title' => get_string('personalinformation', 'artefact.resume')));
        }
        foreach (array_keys(ArtefactTypePersonalInformation::get_composite_fields()) as $field) {
            $personalinformation->set_composite($field, $values[$field]);
        }
        $personalinformation->commit();
    } catch (Exception $e) {
        $errors['personalinformation'] = true;
    }
    if (empty($errors)) {
        $form->json_reply(PIEFORM_OK, get_string('resumesaved', 'artefact.resume'));
    } else {
        $message = '';
        foreach (array_keys($errors) as $key) {
            $message .= get_string('resumesavefailed', 'artefact.resume') . "\n";
        }
        $form->json_reply(PIEFORM_ERR, $message);
    }
}
コード例 #16
0
ファイル: index.php プロジェクト: sarahjcotton/mahara
function export_validate(Pieform $form, $values)
{
    global $SESSION;
    if ($values['what'] == 'views') {
        $viewchosen = false;
        foreach ($values as $key => $value) {
            if (substr($key, 0, 5) == 'view_' && $value) {
                $viewchosen = true;
            }
        }
        if (!$viewchosen) {
            $form->set_error('what', '');
            $SESSION->add_error_msg(get_string('youmustselectatleastoneviewtoexport', 'export'));
        }
    } else {
        if ($values['what'] == 'collections') {
            $viewchosen = false;
            foreach ($values as $key => $value) {
                if (substr($key, 0, 11) == 'collection_' && $value) {
                    $viewchosen = true;
                }
            }
            if (!$viewchosen) {
                $form->set_error('what', '');
                $SESSION->add_error_msg(get_string('youmustselectatleastonecollectiontoexport', 'export'));
            }
        }
    }
}
コード例 #17
0
ファイル: oneline.php プロジェクト: Br3nda/mahara
/**
 * Renders form elements all on one line.
 *
 * @param Pieform $form    The form the element is being rendered for
 * @param array   $element The element that is being rendered
 * @return string          The element rendered inside an appropriate container
 */
function pieform_renderer_oneline(Pieform $form, $element)
{
    /*{{{*/
    $formname = $form->get_name();
    // Set the class of the enclosing <div> to match that of the element
    $result = '<span';
    if (isset($element['name'])) {
        $result .= ' id="' . $formname . '_' . $element['name'] . '_container"';
    }
    if (!empty($element['class'])) {
        $result .= ' class="' . $element['class'] . '"';
    }
    $result .= '>';
    if (isset($element['title']) && $element['title'] !== '' && $element['type'] != 'fieldset') {
        if (!empty($element['nolabel'])) {
            // Don't bother with a label for the element
            $result .= Pieform::hsc($element['title']);
        } else {
            $result .= '<label for="' . $element['id'] . '">' . Pieform::hsc($element['title']) . '</label>';
        }
        if ($form->get_property('requiredmarker') && !empty($element['rules']['required'])) {
            $result .= ' <span class="requiredmarker">*</span>';
        }
    }
    $result .= $element['html'];
    $result .= "</span>";
    return $result;
}
コード例 #18
0
ファイル: weight.php プロジェクト: Br3nda/mahara
function pieform_element_weight_get_value(Pieform $form, $element)
{
    pieform_element_weight_validate_element($element);
    $name = $element['name'];
    $global = $form->get_property('method') == 'get' ? $_GET : $_POST;
    $value = null;
    if (isset($element['value'])) {
        $value = $element['value'];
    } else {
        if (isset($global[$name])) {
            $value = $global[$name];
        } else {
            if (isset($element['defaultvalue'])) {
                $value = $element['defaultvalue'];
            }
        }
    }
    // How should we return the value? In theory, there could be several ways
    // in which the caller wants the data to be returned. For now, only one
    // "policy" is implemented
    switch ($element['returnpolicy']) {
        case 'renumber-from-zero':
            return pieform_element_weight_returnpolicy_renumber_from_zero($element, $value);
    }
    return null;
}
コード例 #19
0
ファイル: color.php プロジェクト: rboyatt/mahara
/**
 * Returns the color value of the color selector element from the request or transparent
 *
 * @param Pieform $form    The form the element is attached to
 * @param array   $element The element to get the value for
 * @return string A 6-digit hex color value, or the string "transparent"
 */
function pieform_element_color_get_value(Pieform $form, $element)
{
    $name = $element['name'];
    $global = $form->get_property('method') == 'get' ? $_GET : $_POST;
    if ($form->is_submitted() && isset($global[$name . '_color']) && !isset($global[$name . '_optional'])) {
        $color = $global[$name . '_color'];
        // Whitelist for a 6-digit hex color
        $color = preg_replace('/[^a-f0-9]/i', '', $color);
        if (strlen($color) >= 6) {
            $color = substr($color, 0, 6);
        } else {
            if (strlen($color) >= 3) {
                // If they provided a 3-digit color string, convert it into a 6-digit one by doubling each digit
                $color = substr($color, 0, 3);
                $color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2];
            } else {
                $color = '';
            }
        }
        if ($color === '') {
            return 'transparent';
        }
        $color = "#{$color}";
        return $color;
    }
    return 'transparent';
}
コード例 #20
0
/**
 * Checks whether the given value is at most a certain size.
 *
 * @param Pieform $form      The form the rule is being applied to
 * @param string  $value     The value to check
 * @param array   $element   The element to check
 * @param int     $maxvalue  The value to check for
 * @return string            The error message, if the value is invalid.
 */
function pieform_rule_maxvalue(Pieform $form, $value, $element, $maxvalue)
{
    /*{{{*/
    if ($value !== '' && doubleval($value) > $maxvalue) {
        return sprintf($form->i18n('rule', 'maxvalue', 'maxvalue', $element), $maxvalue);
    }
}
コード例 #21
0
function pieform_element_userlist_rule_required(Pieform $form, $value, $element)
{
    if (is_array($value) && count($value)) {
        return null;
    }
    return $form->i18n('rule', 'required', 'required', $element);
}
コード例 #22
0
/**
 * Checks whether the given value is shorter than the allowed length.
 *
 * @param PieForm $form      The form the rule is being applied to
 * @param string  $value     The value to check
 * @param array   $element   The element to check
 * @param int     $minlength The length to check for
 * @return string            The error message, if the value is invalid.
 */
function pieform_rule_minlength(Pieform $form, $value, $element, $minlength)
{
    /*{{{*/
    if (strlen($value) < $minlength) {
        return sprintf($form->i18n('rule', 'minlength', 'minlength', $element), $minlength);
    }
}
コード例 #23
0
ファイル: table.php プロジェクト: Br3nda/mahara
/**
 * Renders form elements inside a <table>.
 *
 * @param Pieform $form    The form the element is being rendered for
 * @param array   $element The element to be rendered
 * @return string          The element rendered inside an appropriate container
 */
function pieform_renderer_table(Pieform $form, $element)
{
    /*{{{*/
    $formname = $form->get_name();
    if ($element['type'] == 'fieldset') {
        // Add table tags to the build element, to preserve HTML compliance
        $builtelement = $element['html'];
        if (0 === strpos($builtelement, "\n<fieldset")) {
            $closelegendpos = strpos($builtelement, '</legend>');
            if ($closelegendpos !== false) {
                $closelegendpos += 9;
                $builtelement = substr($builtelement, 0, $closelegendpos) . '<table><tbody>' . substr($builtelement, $closelegendpos);
            } else {
                $pos = strpos($builtelement, '>') + 1;
                $builtelement = substr($builtelement, 0, $pos) . '<table><tbody>' . substr($builtelement, $pos);
            }
        } else {
            $builtelement = substr($builtelement, 0, 11) . '<table><tbody>' . substr($builtelement, 11);
        }
        $builtelement = substr($builtelement, 0, -12) . '</tbody></table></fieldset>';
        $result = "\t<tr>\n\t\t<td colspan=\"2\">";
        $result .= $builtelement;
        $result .= "</td>\n\t</tr>";
        return $result;
    }
    $result = "\t<tr";
    $result .= ' id="' . $formname . '_' . $element['name'] . '_container"';
    // Set the class of the enclosing <tr> to match that of the element
    if (!empty($element['class'])) {
        $result .= ' class="' . $element['class'] . '"';
    }
    $result .= ">\n\t\t";
    $result .= '<th>';
    if (isset($element['labelhtml'])) {
        $result .= $element['labelhtml'];
    }
    $result .= "</th>\n\t\t<td>";
    $result .= $element['html'];
    if (isset($element['helphtml'])) {
        $result .= ' ' . $element['helphtml'];
    }
    $result .= "</td>\n\t</tr>\n";
    // Description - optional description of the element, or other note that should be visible
    // on the form itself (without the user having to hover over contextual help
    if ((!$form->has_errors() || $form->get_property('showdescriptiononerror')) && !empty($element['description'])) {
        if ($form->get_property('descriptionintwocells')) {
            $result .= "\t<tr>\n\t\t<td></td><td class=\"description\">";
        } else {
            $result .= "\t<tr>\n\t\t<td colspan=\"2\" class=\"description\">";
        }
        $result .= $element['description'];
        $result .= "</td>\n\t</tr>\n";
    }
    if (!empty($element['error'])) {
        $result .= "\t<tr>\n\t\t<td colspan=\"2\" class=\"errmsg\">";
        $result .= $element['error'];
        $result .= "</td>\n\t</tr>\n";
    }
    return $result;
}
コード例 #24
0
function interests_submit(Pieform $form, $values)
{
    global $coverletter, $personalinformation, $interest, $USER;
    $userid = $USER->get('id');
    $errors = array();
    try {
        if (empty($interest) && !empty($values['interest'])) {
            $interest = new ArtefactTypeInterest(0, array('owner' => $userid, 'description' => $values['interest']));
            $interest->commit();
        } else {
            if (!empty($interest) && !empty($values['interest'])) {
                $interest->set('description', $values['interest']);
                $interest->commit();
            } else {
                if (!empty($interest) && empty($values['interest'])) {
                    $interest->delete();
                }
            }
        }
    } catch (Exception $e) {
        $errors['interest'] = true;
    }
    if (empty($errors)) {
        $form->json_reply(PIEFORM_OK, get_string('resumesaved', 'artefact.resume'));
    } else {
        $message = '';
        foreach (array_keys($errors) as $key) {
            $message .= get_string('resumesavefailed', 'artefact.resume') . "\n";
        }
        $form->json_reply(PIEFORM_ERR, $message);
    }
}
コード例 #25
0
/**
 * Returns whether the given field is an integer
 *
 * @param Pieform $form      The form the rule is being applied to
 * @param string  $value     The value to check
 * @param array   $element   The element to check
 * @return string            The error message, if there is something wrong with
 *                           the address.
 */
function pieform_rule_integer(Pieform $form, $value, $element)
{
    /*{{{*/
    if (!is_numeric($value) || floor($value) != $value) {
        return $form->i18n('rule', 'integer', 'integer', $element);
    }
}
コード例 #26
0
function gwfontform_validate(Pieform $form, $values)
{
    global $USER, $SESSION;
    require_once 'file.php';
    require_once 'uploadmanager.php';
    $valid = false;
    if ($values['gwfzipfile'] != null) {
        $filetype = $values['gwfzipfile']['type'];
        // Ensures that the correct file was chosen
        $accepted = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/s-compressed');
        foreach ($accepted as $mimetype) {
            if ($mimetype == $filetype) {
                $valid = true;
                break;
            }
        }
        // Safari and Chrome don't register zip mime types. Something better could be used here.
        // Check if file extension, that is the last 4 characters in file name, equals '.zip'...
        $valid = substr($values['gwfzipfile']['name'], -4) == '.zip' ? true : false;
        if (!$valid) {
            $form->set_error('gwfzipfile', get_string('notvalidzipfile', 'skin'));
        }
        // pass it through the virus checker
        $um = new upload_manager('gwfzipfile');
        if ($error = $um->preprocess_file()) {
            $form->set_error($inputname, $error);
        }
    }
}
コード例 #27
0
ファイル: oneline.php プロジェクト: rboyatt/mahara
/**
 * Renders form elements all on one line.
 *
 * @param Pieform $form    The form the element is being rendered for
 * @param array   $element The element that is being rendered
 * @return string          The element rendered inside an appropriate container
 */
function pieform_renderer_oneline(Pieform $form, $element)
{
    /*{{{*/
    $formname = $form->get_name();
    // Set the class of the enclosing <div> to match that of the element
    $result = '<span';
    if (isset($element['name'])) {
        $result .= ' id="' . $formname . '_' . Pieform::hsc($element['name']) . '_container"';
    }
    if (!empty($element['class'])) {
        // add form-group classes to all real form fields
        if (strpos($element['class'], 'html') === false) {
            // $element['class'] = $element['class'] . ' form-group-inline';
            $element['class'] = 'form-group-inline';
        }
        // add bootstrap has-error class to any error fields
        if (strpos($element['class'], 'error') !== false) {
            $element['class'] = $element['class'] . ' has-error';
        }
        $result .= ' class="' . Pieform::hsc($element['class']) . '"';
    }
    $result .= '>';
    if (isset($element['labelhtml'])) {
        $result .= $element['labelhtml'];
    }
    if (isset($element['prehtml'])) {
        $result .= '<span class="prehtml">' . $element['prehtml'] . '</span>';
    }
    $result .= $element['html'];
    if (isset($element['posthtml'])) {
        $result .= '<span class="posthtml">' . $element['posthtml'] . '</span>';
    }
    $result .= "</span>";
    return $result;
}
コード例 #28
0
ファイル: forgotpass.php プロジェクト: rboyatt/mahara
function forgotpass_validate(Pieform $form, $values)
{
    // See if the user input an email address or a username. We favour email addresses
    if (!$form->get_error('emailusername')) {
        // Check if the user who associates to username or email address is using the external authentication
        if (record_exists_sql('SELECT u.authinstance
            FROM {usr} u INNER JOIN {auth_instance} ai ON (u.authinstance = ai.id)
            WHERE (LOWER(u.email) = ? OR LOWER(u.username) = ?)
            AND ((ai.authname != \'internal\') AND (ai.authname != \'none\'))', array_fill(0, 2, strtolower($values['emailusername'])))) {
            $form->set_error('emailusername', get_string('forgotpassuserusingexternalauthentication', 'mahara', get_config('wwwroot') . 'contact.php'));
        } else {
            if (!($authinstance = get_field_sql('SELECT u.authinstance
                FROM {usr} u INNER JOIN {auth_instance} ai ON (u.authinstance = ai.id)
                WHERE (LOWER(u.email) = ? OR LOWER(u.username) = ?)
                AND ai.authname = \'internal\'', array_fill(0, 2, strtolower($values['emailusername']))))) {
                $form->set_error('emailusername', get_string('forgotpassnosuchemailaddressorusername'));
            }
        }
    }
    if ($form->get_error('emailusername')) {
        return;
    }
    $authobj = AuthFactory::create($authinstance);
    if (!method_exists($authobj, 'change_password')) {
        die_info(get_string('cantchangepassword'));
    }
}
コード例 #29
0
ファイル: minvalue.php プロジェクト: Br3nda/mahara
/**
 * Checks whether the given value is at least a certain size.
 *
 * @param Pieform $form      The form the rule is being applied to
 * @param string  $value     The value to check
 * @param array   $element   The element to check
 * @param int     $maxlength The value to check for
 * @return string            The error message, if the value is invalid.
 */
function pieform_rule_minvalue(Pieform $form, $value, $element, $minvalue)
{
    /*{{{*/
    if ($value != '' && intval($value) < $minvalue) {
        return sprintf($form->i18n('rule', 'minvalue', 'minvalue', $element), $minvalue);
    }
}
コード例 #30
0
/**
 * Returns whether the given field matches the specified regex.
 *
 * @param Pieform $form    The form the rule is being applied to
 * @param string  $value   The value to check
 * @param array   $element The element to check
 * @param string  $regex   The regular expression to use for the check
 * @return string        The error message, if there is something wrong with
 *                       the value.
 */
function pieform_rule_regex(Pieform $form, $value, $element, $regex)
{
    /*{{{*/
    if (!preg_match($regex, $value)) {
        return $form->i18n('rule', 'regex', 'regex', $element);
    }
}