Ejemplo n.º 1
0
/**
  * Shows the add comment form
  *
  * @param int $pageID The page that the comment is to be displayed on
  *
  * @return $display The form
  *
**/
function Comments_showCommentForm($pageID)
{
    if (isset($_SESSION['userdata'])) {
        $userID = $_SESSION['userdata']['id'];
        $user = dbRow('select name, email from user_accounts where id = ' . $userID);
    }
    $noCaptchas = (int) dbOne('select value from site_vars where name = "comments_no_captchas"', 'value');
    $display = '<form id="comment-form" class="comments-form" method="post" 
		action="javascript:comments_check_captcha();">';
    $display .= '<strong>Add Comment</strong>';
    $display .= '<input type="hidden" name="page" id="comments-page-id" 
		value="' . $pageID . '" />';
    $display .= '<table class="comments-form-table"><tr class="comments-name">' . '<th>Name</th><td><input id="comments-name-input" name="name" ';
    if (isset($user)) {
        $display .= ' value="' . htmlspecialchars($user['name']) . '"';
    }
    $display .= ' /></td></tr>';
    $display .= '<tr class="comments-email"><th>Email</th>';
    $display .= '<td><input id="comments-email-input" name="email"';
    if (isset($user)) {
        $display .= ' value="' . htmlspecialchars($user['email']) . '"';
    }
    $display .= ' /></td></tr>' . '<tr class="comments-url"><th>Website</th>' . '<td><input id="site" name="comments-site-input" /></td></tr>' . '<tr class="comments-comment"><th>Comment</th><td>' . '<textarea id="comments-comment-input" name="comment"></textarea></td>' . '</tr>';
    if (!$noCaptchas) {
        $display .= '<tr><td colspan="2"><div id="captcha" class="comments_captcha">' . Recaptcha_getHTML() . '</div></td></tr>';
    }
    $display .= '<tr class="comments-submit-comment"><th>&nbsp;</th><td>' . '<input type="submit" id="submit" value="Submit Comment"  /></td></tr>' . '</table></form><script defer="defer">comments_noCaptchas=' . $noCaptchas . ';</script>';
    return $display;
}
Ejemplo n.º 2
0
/**
 * show the form to be submitted
 *
 * @param array $page       page db row
 * @param array $vars       page meta data
 * @param array $errors     any errors that need to be shown
 * @param array form_fields list of fields in the form
 *
 * @return HTML of the form
 */
function Form_showForm($page, $vars, $errors, $form_fields)
{
    if (!isset($_SESSION['forms'])) {
        $_SESSION['forms'] = array();
    }
    $c = '<form action="' . $_SERVER['REQUEST_URI'] . '" method="post" ' . 'class="ww_form" enctype="multipart/form-data">';
    if (count($errors)) {
        $c .= '<div class="errorbox">' . join('<br />', $errors) . '</div>';
    }
    switch (@$vars['forms_htmltype']) {
        case 'div':
            // {
            $vals_wrapper_start = '';
            $vals_field_start = '<div><span class="__" lang-context="core">';
            $vals_field_middle = '</span>';
            $vals_field_end = '</div>';
            $vals_2col_start = '<div>';
            $vals_2col_end = '</div>';
            $vals_wrapper_end = '';
            break;
            // }
        // }
        default:
            // {
            $vals_wrapper_start = '<table class="forms-table">';
            $vals_field_start = '<tr><th class="__" lang-context="core">';
            $vals_field_middle = '</th><td>';
            $vals_field_end = '</td></tr>';
            $vals_2col_start = '<tr><td colspan="2">';
            $vals_2col_end = '</td></tr>';
            $vals_wrapper_end = '</table>';
            // }
    }
    if (@$vars['forms_template'] && strpos($vars['forms_template'], '{{') === false) {
        $vars['forms_template'] = '';
    }
    // }}
    if (!@$vars['forms_template'] || $vars['forms_template'] == '&nbsp;') {
        $c .= '<div>' . $vals_wrapper_start;
    }
    $required = array();
    $cnt = 0;
    $has_date = false;
    $has_ccdate = false;
    foreach ($form_fields as $r2) {
        if ($r2['type'] == 'hidden') {
            continue;
        }
        $name = preg_replace('/[^a-zA-Z0-9_]/', '', $r2['name']);
        $help = @$r2['help'];
        if ($help != '') {
            $help = ' title="' . htmlspecialchars($help, ENT_QUOTES) . '"';
        }
        $class = '';
        if ($r2['isrequired']) {
            $required[] = $name . ',' . $r2['type'];
            $class = ' required';
        }
        if (isset($_REQUEST[$name])) {
            $_SESSION['forms'][$name] = $_REQUEST[$name];
        }
        $val = Form_valueDefault($name);
        if (!isset($_REQUEST[$name])) {
            $_REQUEST[$name] = '';
        }
        $table_break = 0;
        switch ($r2['type']) {
            case 'checkbox':
                // {
                $d = '<input type="checkbox" id="' . $name . '" name="' . $name . '"' . $help;
                if ($_REQUEST[$name]) {
                    $d .= ' checked="' . $_REQUEST[$name] . '"';
                }
                $d .= ' class="' . $class . ' checkbox" />';
                break;
                // }
            // }
            case 'ccdate':
                // {
                if ($_REQUEST[$name] == '') {
                    $_REQUEST[$name] = date('Y-m');
                }
                $d = '<input name="' . $name . '" value="' . $_REQUEST[$name] . '" class="ccdate"' . $help . '/>';
                $has_ccdate = true;
                break;
                // }
            // }
            case 'date':
                // {
                if ($_REQUEST[$name] == '') {
                    $_REQUEST[$name] = date('Y-m-d');
                }
                $d = '<input name="' . $name . '" value="' . $_REQUEST[$name] . '"' . $help . ' class="date" placeholder="yyyy-mm-dd" ' . 'metadata="' . addslashes($r2['extra']) . '"/>';
                $has_date = true;
                break;
                // }
            // }
            case 'email':
                // {
                if ($r2['extra']) {
                    $class .= ' verify';
                    $verify = '<input style="display:none" class="email-verification" ' . 'name="' . $name . '_verify" value="" placeholder="verification code"' . $help . '/>';
                    $_SESSION['form_input_email_verify_' . $name] = rand(10000, 99999);
                } else {
                    $verify = '';
                }
                $d = '<input type="email" id="' . $name . '" name="' . $name . '" value="' . $val . '" class="email' . $class . ' text"' . $help . '/>' . $verify;
                break;
                // }
            // }
            case 'file':
                // {
                WW_addScript('/j/swfobject.js');
                WW_addScript('/j/jquery.uploadify/jquery.uploadify.min.js');
                $opts = isset($r2['extra']) ? explode(':', $r2['extra']) : array();
                if (!isset($opts[0]) || !isset($opts[1])) {
                    $opts = array('off', '*;');
                }
                $multi = $opts[0] == 'on' ? 'true' : 'false';
                $script = '
				$(function(){
					$("#' . $name . '").uploadify({
						"uploader":"/j/jquery.uploadify/uploadify.swf",
						"script":"/ww.plugins/forms/frontend/file-upload.php",
						"cancelImg":"/ww.plugins/forms/j/cancel.png",
						"multi":' . $multi . ',
						"removeCompleted":false,
						"fileDataName":"file-upload",
						"scriptData":{
							"PHPSESSID":"' . session_id() . '"
						},
						"onComplete":function(event,ID,fileObj,response,data){
							if(response=="deleted"){
								alert("You have uploaded too many large files. These files' . ' have been deleted to conserve space. Please reload the ' . 'page and try again with less or smaller files.");
							}
						},
						"onAllComplete":function(){
							$("input[type=submit]").attr("disabled",false);
						},
						"onSelect":function(){
							$("input[type=submit]").attr("disabled","disabled");
						},
						"fileExt":"' . $opts[1] . '",
						"fileDesc":" ",
						"auto":true
					});
				});';
                WW_addInlineScript($script);
                $d = '<div id="upload">';
                $d .= '<input type="file" id="' . $name . '" name="file-upload"' . $help . '/>';
                $d .= '</div>';
                // { add existing files
                $dir = USERBASE . '/f/.files/forms/' . session_id();
                if (is_dir($dir)) {
                    $files = array();
                    $uploads = new DirectoryIterator($dir);
                    foreach ($uploads as $upload) {
                        if ($upload->isDot() || $upload->isDir()) {
                            continue;
                        }
                        $bytes = $upload->getSize();
                        $kb = round($bytes / 1024, 2);
                        $d .= '<div class="uploadifyQueueItem completed">' . '<div class="cancel"><a class="download-delete-item" ' . 'href="javascript:;" id="' . $upload->getFileName() . '">' . '<img border="0" src="/ww.plugins/forms/j/cancel.png"></a>' . '</div>' . '<span class="fileName">' . $upload->getFileName() . ' (' . $kb . ' KB)</span>' . '<span class="percentage"> - Completed</span>' . '</div>';
                    }
                }
                // }
                break;
                // }
            // }
            case 'hidden':
                // {
                $d = '<textarea id="' . $name . '" name="' . $name . '" class="' . $class . ' hidden"' . $help . '>' . htmlspecialchars($r2['extra']) . '</textarea>';
                break;
                // }
            // }
            case 'html-block':
                // {
                $d = $r2['extra'];
                $table_break = true;
                break;
                // }
            // }
            case 'page-next':
                // {
                $d = '<a href="javascript:;" class="form-page-next">Next</a>';
                $table_break = true;
                break;
                // }
            // }
            case 'page-previous':
                // {
                $d = '<a href="javascript:;" class="form-page-previous">Previous</a>';
                $table_break = true;
                break;
                // }
            // }
            case 'page-break':
                // {
                $d = '</div><div style="display:none">';
                $table_break = true;
                break;
                // }
            // }
            case 'selectbox':
                // {
                $d = '<select id="' . $name . '" name="' . $name . '"' . $help . '>';
                $arr = explode("\n", htmlspecialchars($r2['extra']));
                foreach ($arr as $li) {
                    if ($_REQUEST[$name] == $li) {
                        $d .= '<option selected="selected">' . rtrim($li) . '</option>';
                    } else {
                        $d .= '<option>' . rtrim($li) . '</option>';
                    }
                }
                $d .= '</select>';
                break;
                // }
            // }
            case 'signature':
                // {
                $d = '<div class="signature-wrapper">' . '<canvas class="signature-pad" width="300" height="150">' . '</canvas>' . '<a href="#" class="signature-clear">clear</a>' . '<input type="hidden" name="' . $name . '"/>' . '</div>';
                WW_addScript('forms/j/jquery.signaturepad.js');
                WW_addScript('forms/j/field-type-signature.js');
                break;
                // }
            // }
            case 'textarea':
                // {
                if (!$r2['extra']) {
                    $r2['extra'] = '0,0';
                }
                list($max, $softmax) = explode(',', $r2['extra']);
                $maxlength = $max ? 'maxlength="' . $max . '" ' : '';
                $d = '<textarea ' . $maxlength . ' softmaxlength="' . $softmax . '"' . $help . ' id="' . $name . '" name="' . $name . '" class="' . $class . '">' . $_REQUEST[$name] . '</textarea>';
                break;
                // }
            // }
            default:
                // { # input boxes, and anything which was not handled already
                $d = '<input id="' . $name . '" name="' . $name . '" value="' . $val . '" class="' . $class . ' text"' . $help . '/>';
                // }
        }
        if (@$vars['forms_template'] && $vars['forms_template'] != '&nbsp;') {
            $vars['forms_template'] = str_replace('{{$' . $cnt . '}}', $d, $vars['forms_template']);
            $vars['forms_template'] = str_replace('{{$' . htmlspecialchars($r2['name']) . '}}', $d, $vars['forms_template']);
        } else {
            if ($table_break) {
                $c .= $vals_wrapper_end . $d . $vals_wrapper_start;
            } else {
                $c .= $vals_field_start . $r2['name'];
                if ($r2['isrequired']) {
                    $c .= '<sup>*</sup>';
                }
                $c .= $vals_field_middle . $d . $vals_field_end;
            }
        }
        $cnt++;
    }
    if (@$vars['forms_captcha_required']) {
        require_once SCRIPTBASE . 'ww.incs/recaptcha.php';
        $row = $vals_2col_start . Recaptcha_getHTML() . $vals_2col_end;
        if (isset($vars['forms_template']) && $vars['forms_template']) {
            $vars['forms_template'] .= $vals_wrapper_start . $row . $vals_wrapper_end;
        } else {
            $c .= $row;
        }
    }
    if (@$vars['forms_template'] && $vars['forms_template'] != '&nbsp;') {
        $c .= $vars['forms_template'];
    } else {
        $c .= $vals_2col_start;
    }
    $c .= '<button class="submit __" lang-context="core">Submit Form</button>' . '<input type="hidden" name="funcFormInput" value="submit" />' . '<input type="hidden" name="requiredFields" value="' . join(',', $required) . '" />';
    if (count($required)) {
        $c .= '<br /><span>' . __('* indicates required fields', 'core') . '</span>';
    }
    if (!@$vars['forms_template'] || @$vars['forms_template'] == '&nbsp;') {
        $c .= $vals_2col_end . $vals_wrapper_end . '</div>';
        $c = str_replace('<table></table>', '', $c);
        WW_addInlineScript('var form_rules=' . json_encode(Form_getValidationRules($vars, $form_fields)) . ';');
        WW_addScript('forms/frontend/show.js');
        $c .= '<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/' . 'jquery.validate.min.js"></script>';
    }
    $helpType = (int) @$vars['forms_helpType'];
    $helpSelector = @$vars['forms_helpSelector'];
    $verifiedEmails = isset($_SESSION['forms_verified_emails']) ? json_encode($_SESSION['forms_verified_emails']) : '[]';
    $c .= '<script defer="defer">var forms_helpType=' . $helpType . ',forms_helpSelector="' . $helpSelector . '",forms_verifiedEmails=' . $verifiedEmails . ';</script></form>';
    if ($has_ccdate) {
        WW_addInlineScript('$("input.ccdate").datepicker({"dateFormat":"yy-mm"});');
    }
    WW_addCSS('/ww.plugins/forms/forms.css');
    return $c;
}
Ejemplo n.º 3
0
/**
 * show a registration form for creating a user
 *
 * @param string $error any error messages that need to be displayed
 * @param string $alert any messages that need to be displayed in popups
 *
 * @return string HTML of the form
 */
function Privacy_registrationShowForm($error = '', $alert = '')
{
    global $PAGEDATA;
    /**
     * form validation array
     */
    $validation = array();
    $c = '<div id="userregistration"><em style="color:red" id="error"></em>';
    if (isset($PAGEDATA->vars['userlogin_message_registration'])) {
        $c .= $PAGEDATA->vars['userlogin_message_registration'];
    }
    require_once SCRIPTBASE . 'ww.incs/recaptcha.php';
    $c .= $error . '<form id="reg-form" class="userRegistrationBox" action="' . $GLOBALS['PAGEDATA']->getRelativeUrl() . '#userregistration" method="post"><table>' . '<tr><th>' . __('Name', 'core') . '</th>' . '<td><input type="text" name="name" value="' . htmlspecialchars(@$_REQUEST['name']) . '" /></td>' . '<th>' . __('Email', 'core') . '</th>' . '<td><input type="text" name="email" value="' . htmlspecialchars(@$_REQUEST['email']) . '" /></td></tr>' . '<tr><th>' . __('Preferred Password', 'core') . '</th>' . '<td><input name="pass1" type="password"/></td>' . '<th>' . __('Repeat Password', 'core') . '</th>' . '<td><input name="pass2" type="password"/></td' . '></tr><tr><td colspan="2">' . Recaptcha_getHTML() . '</td></tr></table>';
    if (strlen(@$PAGEDATA->vars['privacy_extra_fields']) > 2) {
        $c .= '<table>';
        $required = array();
        $rs = json_decode($PAGEDATA->vars['privacy_extra_fields']);
        $cnt = 0;
        foreach ($rs as $r) {
            if (!$r->name || $r->type == 'hidden') {
                continue;
            }
            $name = preg_replace('/[^a-zA-Z0-9_]/', '', $r->name);
            $class = '';
            if (isset($r->is_required) && $r->is_required) {
                $required[] = $name . ',' . $r->type;
                $class = ' required';
                $validation['privacy_extras_' . $name] = array('required' => true);
            }
            if (isset($_REQUEST[$name])) {
                $_SESSION['privacys'][$name] = $_REQUEST[$name];
            }
            $val = @$_REQUEST[$name];
            if (!$val && isset($_SESSION['userdata']) && $_SESSION['userdata']) {
                switch ($name) {
                    case 'Email':
                    case '__ezine_subscribe':
                        // {
                        $val = $_SESSION['userdata']['email'];
                        break;
                        // }
                    // }
                    case 'FirstName':
                        // {
                        $val = preg_replace('/ .*/', '', $_SESSION['userdata']['name']);
                        break;
                        // }
                    // }
                    case 'Street':
                        // {
                        $val = $_SESSION['userdata']['address1'];
                        break;
                        // }
                    // }
                    case 'Street2':
                        // {
                        $val = $_SESSION['userdata']['address2'];
                        break;
                        // }
                    // }
                    case 'Surname':
                        // {
                        $val = preg_replace('/.* /', '', $_SESSION['userdata']['name']);
                        break;
                        // }
                    // }
                    case 'Town':
                        // {
                        $val = $_SESSION['userdata']['address3'];
                        break;
                        // }
                }
            }
            if (!isset($_REQUEST[$name])) {
                $_REQUEST[$name] = '';
            }
            switch ($r->type) {
                case 'checkbox':
                    // {
                    $d = '<input type="checkbox" id="privacy_extras_' . $name . '" name="privacy_extras_' . $name . '"';
                    if ($_REQUEST[$name]) {
                        $d .= ' checked="' . $_REQUEST[$name] . '"';
                    }
                    $d .= ' class="' . $class . ' checkbox" />';
                    break;
                    // }
                // }
                case 'ccdate':
                    // {
                    if ($_REQUEST[$name] == '') {
                        $_REQUEST[$name] = date('Y-m');
                    }
                    $d = '<input name="privacy_extras_' . $name . '" value="' . $_REQUEST[$name] . '" class="ccdate" />';
                    break;
                    // }
                // }
                case 'date':
                    // {
                    if ($_REQUEST[$name] == '') {
                        $_REQUEST[$name] = date('Y-m-d');
                    }
                    $d = '<input name="privacy_extras_' . $name . '" value="' . $_REQUEST[$name] . '" class="date" />';
                    break;
                    // }
                // }
                case 'email':
                    // {
                    $d = '<input id="privacy_extras_' . $name . '" name="privacy_extras_' . $name . '" value="' . $val . '" class="email' . $class . ' text" />';
                    if (isset($validation['privacy_extras_' . $name])) {
                        $validation['privacy_extras_' . $name]['email'] = true;
                    } else {
                        $validation['privacy_extras_' . $name] = array('email' => true);
                    }
                    break;
                    // }
                // }
                case 'url':
                    // {
                    $d = '<input id="privacy_extras_' . $name . '" name="privacy_extras_' . $name . '" value="" class="url' . $class . ' text" />';
                    if (isset($validation['privacy_extras_' . $name])) {
                        $validation['privacy_extras_' . $name]['url'] = true;
                    } else {
                        $validation['privacy_extras_' . $name] = array('url' => true);
                    }
                    break;
                    // }
                // }
                case 'file':
                    // {
                    $d = '<input id="privacy_extras_' . $name . '" name="privacy_extras_' . $name . '" type="file" />';
                    break;
                    // }
                // }
                case 'hidden':
                    // {
                    $d = '<textarea id="privacy_extras_' . $name . '" name="privacy_extras_' . $name . '" class="' . $class . ' hidden">' . htmlspecialchars($r->extra) . '</textarea>';
                    break;
                    // }
                // }
                case 'selectbox':
                    // {
                    $d = '<select id="privacy_extras_' . $name . '" name="privacy_extras_' . $name . '">';
                    $arr = explode("\n", htmlspecialchars($r->extra));
                    foreach ($arr as $li) {
                        if ($_REQUEST[$name] == $li) {
                            $d .= '<option selected="selected">' . rtrim($li) . '</option>';
                        } else {
                            $d .= '<option>' . rtrim($li) . '</option>';
                        }
                    }
                    $d .= '</select>';
                    break;
                    // }
                // }
                case 'textarea':
                    // {
                    $d = '<textarea id="privacy_extras_' . $name . '" name="privacy_extras_' . $name . '" class="' . $class . '">' . $_REQUEST[$name] . '</textarea>';
                    break;
                    // }
                // }
                default:
                    // { input boxes, and anything which was not handled already
                    $d = '<input id="privacy_extras_' . $name . '" name="privacy_extras_' . $name . '" value="' . $val . '" class="' . $class . ' text" />';
                    // }
            }
            $c .= '<tr><th>' . htmlspecialchars($r->name);
            if (isset($r->is_required) && $r->is_required) {
                $c .= '<sup>*</sup>';
            }
            $c .= "</th>\n\t<td>" . $d . "</td></tr>\n\n";
            $cnt++;
        }
        $c .= '</table>';
        if (count($required)) {
            $c .= '<br /><span>' . __('* indicates required fields', 'core') . '</span>';
        }
    }
    if (@$PAGEDATA->vars['userlogin_terms_and_conditions']) {
        $c .= '<input type="checkbox" name="terms_and_conditions" /> <span>' . __('I agree to the <a href="javascript:userlogin_t_and_c()">' . 'terms and conditions</a>.', 'core') . '</span><br />';
        $c .= '<script defer="defer">function userlogin_t_and_c(){$("<div>' . addslashes(str_replace(array("\n", "\r"), ' ', $PAGEDATA->vars['userlogin_terms_and_conditions'])) . '</div>").dialog({modal:true,width:"90%"});}</script>';
    }
    if ($alert) {
        WW_addInlineScript('$(function(){$(\'<div>' . addslashes($alert) . '</div>\').dialog({modal:true});});');
    }
    $c .= '<button id="registration-submit">' . __('Register', 'core') . '</button>' . '<input type="hidden" name="a" value="Register" /></form></div>';
    /** 
     * add jquery form validation
     */
    WW_addScript('/j/validate.jquery.min.js');
    $script = ' 
			var options = ' . json_encode($validation) . ';

			$( "#reg-form" ).validate( options, function( message ){
		$( "#userregistration em#error" ).html( message );
	} );
	';
    WW_addInlineScript($script);
    $c .= '<style type="text/css">.error{ border:1px solid #600;' . 'background:#f99 }</style>';
    return $c;
}