Ejemplo n.º 1
0
function form_wizard($id, $option)
{
    global $mainframe;
    $htmloutput = '';
    $database =& JFactory::getDBO();
    $database->setQuery("SELECT * FROM #__chrono_contact WHERE id='" . $id . "'");
    $row = $database->loadObject();
    if ($id) {
        if (!trim($row->chronocode)) {
            $mainframe->redirect('index2.php?option=' . $option, "Sorry but this form was not created using the wizard");
        }
        define('CPHP_EOL', "\n");
        $old_chrono_code = $row->chronocode;
        $row->chronocode = str_replace('CHRONO_CONSTANT_EOL', CPHP_EOL, $row->chronocode);
        $XHTMLELEMENTS = explode("}]" . CPHP_EOL, $row->chronocode);
        $htmlcode = '';
        $htmloutput = '';
        //load theme
        ob_start();
        require_once JPATH_SITE . DS . "administrator" . DS . "components" . DS . "com_chronocontact" . DS . "wizardthemes" . DS . 'default' . DS . "elements.php";
        $theme_elements = ob_get_clean();
        foreach ($XHTMLELEMENTS as $XHTMLELEMENT) {
            if (trim($XHTMLELEMENT)) {
                $element_pieces = explode(CPHP_EOL, $XHTMLELEMENT);
                $thiselement = array();
                $counter = 0;
                foreach ($element_pieces as $element_piece) {
                    if ($element_piece != '{' && $element_piece != '}' && $counter > 0) {
                        $linepieces = explode(" = ", $element_piece);
                        if (count($linepieces) == 2) {
                            $thiselement[trim($linepieces[0])] = $linepieces[1];
                        } else {
                            $thiselement[trim($linepieces[0])] = '';
                        }
                    }
                    $counter++;
                }
                //get element tag
                $element_type = '';
                if (preg_match("/\\[type=\".*?\"/i", $element_pieces[0], $matches)) {
                    $element_type = str_replace(array('[type="', '"'), array('', ''), $element_pieces[0]);
                } else {
                    continue;
                }
                //get element from theme file
                $element_theme_1 = explode("<!--start_" . $element_type . "-->", $theme_elements);
                $element_theme_2 = explode("<!--end_" . $element_type . "-->", $element_theme_1[1]);
                //fill the element theme
                foreach ($thiselement as $k => $v) {
                    $element_theme_2[0] = str_replace('{cf_' . $k . '}', $v, $element_theme_2[0]);
                }
                if (preg_match("/<cf_theoptions>(.*?)<\\/cf_theoptions>/is", $element_theme_2[0], $matches2)) {
                    //echo str_replace("<", "[", $matches2[0]);//$element_type = str_replace(array('[type="', '"'), array('',''), $element_pieces[0]);
                    $option_element = str_replace(array('<cf_theoptions>', '</cf_theoptions>'), array('', ''), $matches2[0]);
                    $options = explode("*,*", $thiselement['theoptions']);
                    $optionsdata = '';
                    $icounter = 0;
                    foreach ($options as $option) {
                        if (trim($option)) {
                            $optionsdata .= str_replace(array('{value}', '{title}', '{name}'), array($option, $option, str_replace(array('[', ']'), array('', ''), $thiselement['name']) . $icounter), $option_element);
                            $optionsdata .= CPHP_EOL;
                            $icounter++;
                        }
                    }
                    $element_theme_2[0] = str_replace($matches2[0], $optionsdata, $element_theme_2[0]);
                } else {
                    if (preg_match("/<cf_thecells>(.*?)<\\/cf_thecells>/is", $element_theme_2[0], $matches2)) {
                        $option_element = str_replace(array('<cf_thecells>', '</cf_thecells>'), array('', ''), $matches2[0]);
                        $options = explode("*,*", $thiselement['thecells']);
                        $optionsdata = '';
                        $icounter = 0;
                        foreach ($options as $option) {
                            if (trim($option)) {
                                $optionsdata .= str_replace(array('{value}'), array($option), $option_element);
                                $optionsdata .= CPHP_EOL;
                                $icounter++;
                            }
                        }
                        $element_theme_2[0] = str_replace($matches2[0], $optionsdata, $element_theme_2[0]);
                    } else {
                        //echo 'not found<br>';
                    }
                }
                $htmloutput .= $element_theme_2[0];
                //add the tooltips and label styles
                if (trim($thiselement['tooltiptext'])) {
                    $htmloutput = str_replace("{cf_tooltip}", '<a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" alt="" class="tooltipimg" src="components/com_chronocontact/css/images/tooltip.png"/></a>
					<div class="tooltipdiv" style="display: none;">' . trim($thiselement['tooltiptext']) . '</div>', $htmloutput);
                } else {
                    $htmloutput = str_replace("{cf_tooltip}", "", $htmloutput);
                }
                if (trim($thiselement['tooltiptext'])) {
                    $cf_tooltip2 = explode(" :: ", trim($thiselement['tooltiptext']));
                    $htmloutput = str_replace("{cf_tooltip2}", $cf_tooltip2[1], $htmloutput);
                } else {
                    $htmloutput = str_replace("{cf_tooltip2}", "", $htmloutput);
                }
                if ($element_pieces[0] == '[type="cf_button"') {
                    if (trim($thiselement['reset']) == '1') {
                        $htmloutput = str_replace("{cf_resetbutton}", '<input type="reset" name="reset" value="Reset"/>', $htmloutput);
                    } else {
                        $htmloutput = str_replace("{cf_resetbutton}", "", $htmloutput);
                    }
                }
                if (trim($thiselement['hidelabel']) == '1') {
                    $htmloutput = str_replace("{cf_labeloptions}", ' style="display: none;"', $htmloutput);
                } else {
                    if (trim($thiselement['labelwidth']) != 'auto' && trim($thiselement['labelwidth']) != '0px') {
                        $htmloutput = str_replace("{cf_labeloptions}", ' style="width: ' . trim($thiselement['labelwidth']) . ';"', $htmloutput);
                    } else {
                        $htmloutput = str_replace("{cf_labeloptions}", "", $htmloutput);
                    }
                }
                if ($element_pieces[0] == '[type="cf_dropdown"') {
                    if ((int) $thiselement['size'] > 1) {
                        $htmloutput = str_replace("{cf_multiple}", 'multiple="multiple"', $htmloutput);
                    } else {
                        $htmloutput = str_replace("{cf_multiple}", '', $htmloutput);
                    }
                }
                if ($element_pieces[0] == '[type="cf_placeholder"') {
                    $database->setQuery("SELECT * FROM #__chrono_contact_elements WHERE placeholder='" . $thiselement['labeltext'] . "' ORDER BY id");
                    $placeholder = $database->loadObject();
                    if ($placeholder) {
                        $htmloutput = str_replace("{cf_element_id}", $placeholder->id, $htmloutput);
                        $htmloutput = str_replace("{cf_params}", str_replace("\n", "*,*", $placeholder->params), $htmloutput);
                        $wizardelementparams = explode("\n", $placeholder->params);
                        $paramsatts = "";
                        foreach ($wizardelementparams as $wizardelementparam) {
                            if (trim($wizardelementparam)) {
                                $paramdata = explode('=', $wizardelementparam);
                                $paramsatts .= $paramdata[0] . '="' . $thiselement[$paramdata[0]] . '" ';
                            }
                        }
                        $htmloutput = str_replace("{cf_params_elements}", $paramsatts, $htmloutput);
                    } else {
                        $htmloutput = str_replace("{cf_multiple}", '', $htmloutput);
                    }
                }
            }
        }
    }
    HTML_ChronoContact::form_wizard($htmloutput, $row, $option);
}