Exemplo n.º 1
0
function renderForm($form, $pageName, $options)
{
    global $fyr_form, $fyr_values, $warning_text;
    global $rep_text, $fyr_group_msg, $fyr_valid_reps, $cobrand;
    global $general_error, $cocode;
    debug("FRONTEND", "Form values:", $fyr_values);
    
    // $renderer =& $page->defaultRenderer();
    if (is_object($form)) {
        $renderer =& $options['renderer'];
        if ($options['table_layout']){
            $renderer->setGroupTemplate('<TR><TD ALIGN=right colspan=2> {content} </TD></TR>', 'previewStuff'); // TODO CSS this
            $renderer->setElementTemplate('
            <!-- BEGIN error -->
            <TR><TD colspan=2>
            <span class="error">{error}:</span>
            </TD></TR>                                                   
            <!-- END error -->
            <TR><TD colspan=2>
            {element}
            </TD></TR>', 'body');
        } else {
            $renderer->setElementTemplate('
            <!-- BEGIN error -->
            <p class="error">{error}:</p>
            <!-- END error -->
            {element}', 'body');
        }
        $renderer->setElementTemplate('{element}', 'previewStuff');
        $form->accept($renderer);
    // Make HTML
        $fyr_form = $renderer->toHtml();
        if ($options['table_layout']){     
            $fyr_form = preg_replace('#(<form.*?>)(.*?)(</form>)#s','$1<div id="writebox">$2</div>$3',$fyr_form);
        }
    } else {
        $fyr_form = $form;
    }

    // Add time-shift warning if in debug mode
    if (OPTION_FYR_REFLECT_EMAILS) {
        $fyr_today = msg_get_date();
        msg_check_error($fyr_today);
        if ($fyr_today != date('Y-m-d')) {
            $fyr_form = "<p style=\"text-align: center; color: #ff0000; \">Note: On this test site, the date is faked to be $fyr_today</p>" . $fyr_form;
        }
    }

    $prime_minister = false;
    global $fyr_preview, $fyr_representative, $fyr_voting_area, $fyr_date;
    if ($fyr_values['who'] == 47292) { # Hardcoded
        $prime_minister = true;
    }

    $cobrand_letter_help = false;
    global $cobrand;
    if ($pageName == 'writeForm' && $cobrand) {
        $cobrand_letter_help = cobrand_get_letter_help($cobrand, $fyr_values);

   }
    $our_values = array_merge($fyr_values, array('representative' => $fyr_representative,
            'voting_area' => $fyr_voting_area, 'form' => $fyr_form,
            'date' => $fyr_date, 'prime_minister' => $prime_minister,
            'cobrand_letter_help' => $cobrand_letter_help, 
            'cobrand' => $cobrand,
            'group_msg' => $fyr_group_msg, 'warning_text' => $warning_text, 
            'general_error' => $general_error, 
            'host' => fyr_get_host()));

    if ($fyr_group_msg) {
        # check if there are any reps whose message will be sent via somewhere 
        # else
        $any_via = false;
        foreach ($fyr_valid_reps as $rep) {
            if ($rep['method'] == 'via') {
                $any_via = true;
            }
        }
        $our_values['any_via'] = $any_via;
        $our_values['title_text'] = "your " . $fyr_voting_area['rep_name_long_plural'] ;
    } else {
        $our_values['title_text'] = trim($fyr_voting_area['rep_prefix'] . " " .
            $fyr_representative['name'] . " " . $fyr_voting_area['rep_suffix']) . ", " .
            $fyr_voting_area['name'];
    }
    if ($pageName == "writeForm") {
        template_draw("write-write", $our_values);
    } elseif ($pageName == 'previewForm') {
        // Generate preview
        $formatted_body = fyr_format_message_body_for_preview($our_values['body']);
        $our_values['body_indented'] = $formatted_body;
        $our_values['rep_text'] = $rep_text;
        $fyr_preview = template_string("fax-content", $our_values);
        template_draw("write-preview", array_merge($our_values, array('preview' => $fyr_preview)));
    } else {
        $message = cobrand_generic_error_message($cobrand, $cocode, $pageName);
        if (!$message) {
             $message = 'Sorry. An error has occurred: pageName "'
                    . htmlspecialchars($pageName) .
                '". Please get in touch with us at
                <a href="mailto:team&#64;writetothem.com">team&#64;writetothem.com</a>,
                quoting this message. You can <a href="/">try again from the
                beginning</a>.';
        }
        template_show_error($message);
    }
}
Exemplo n.º 2
0
function renderForm($form, $pageName, $options)
{
    global $fyr_form, $fyr_values, $stash;
    global $fyr_representative, $fyr_voting_area;
    global $cobrand, $cocode;
    debug("FRONTEND", "Form values:", $fyr_values);
    // $renderer =& $page->defaultRenderer();
    if (is_object($form)) {
        $renderer =& $options['renderer'];
        $renderer->setElementTemplate('{element}', 'previewStuff');
        $form->accept($renderer);
        // Make HTML
        $fyr_form = $renderer->toHtml();
        if ($options['table_layout']) {
            $fyr_form = preg_replace('#(<form.*?>)(.*?)(</form>)#s', '$1<div id="writebox">$2</div>$3', $fyr_form);
        }
    } else {
        $fyr_form = $form;
    }
    // Add time-shift warning if in debug mode
    if (OPTION_FYR_REFLECT_EMAILS) {
        $fyr_today = strftime('%Y-%m-%d', $stash['time']);
        if ($fyr_today != date('Y-m-d')) {
            $fyr_form = "<p style=\"text-align: center; color: #ff0000; \">Note: On this test site, the date is faked to be {$fyr_today}</p>" . $fyr_form;
        }
    }
    $prime_minister = false;
    if ($fyr_values['who'] == 47292) {
        # Hardcoded
        $prime_minister = true;
    }
    $cobrand_letter_help = false;
    if ($cobrand && $pageName == 'writeForm') {
        $cobrand_letter_help = cobrand_get_letter_help($cobrand, $fyr_values);
    }
    $our_values = array_merge($fyr_values, $stash, array('representative' => $fyr_representative, 'voting_area' => $fyr_voting_area, 'form' => $fyr_form, 'prime_minister' => $prime_minister, 'cobrand_letter_help' => $cobrand_letter_help, 'cobrand' => $cobrand, 'host' => fyr_get_host()));
    if ($stash['group_msg']) {
        # check if there are any reps whose message will be sent via somewhere
        # else
        $any_via = false;
        foreach ($stash['valid_reps'] as $rep) {
            if ($rep['method'] == 'via') {
                $any_via = true;
            }
        }
        $our_values['any_via'] = $any_via;
        $our_values['title_text'] = "your " . $fyr_voting_area['rep_name_long_plural'];
    } else {
        $our_values['title_text'] = trim($fyr_voting_area['rep_prefix'] . " " . $fyr_representative['name'] . " " . $fyr_voting_area['rep_suffix']) . ", " . $fyr_voting_area['name'];
    }
    if ($pageName == "writeForm") {
        template_draw("write-write", $our_values);
    } elseif ($pageName == 'previewForm') {
        // Generate preview
        $formatted_body = fyr_format_message_body_for_preview($our_values['body']);
        $our_values['body_indented'] = $formatted_body;
        $fyr_preview = template_string("fax-content", $our_values);
        template_draw("write-preview", array_merge($our_values, array('preview' => $fyr_preview)));
    } else {
        $message = cobrand_generic_error_message($cobrand, $cocode, $pageName);
        if (!$message) {
            $message = 'Sorry. An error has occurred: pageName "' . htmlspecialchars($pageName) . '". Please <a href="/about-contact">get in touch with us</a>,
                quoting this message. You can <a href="/">try again from the
                beginning</a>.';
        }
        template_show_error($message);
    }
}