Example #1
0
function template_define_elements()
{
    global $CONF, $CONF_PAGE, $DB, $CUR_TEMPLATE, $PAGE_ELEMENT;
    $types = array("ge" => "GLOB", "ue" => "USER", "pe" => "PAGE");
    foreach ($types as $conf => $type) {
        switch ($CONF["templ_" . $conf . "_source"]) {
            case "conf":
                $elements = $PAGE_ELEMENT[$type];
                break;
            case "session":
                $elements = $_SESSION[$CONF["templ_" . $conf . "_ses_array"]];
                break;
            case "db":
                $sql = "SELECT * FROM " . $CONF["templ_" . $conf . "_db_table"] . " order by id asc";
                $rs = $DB->Execute($sql);
                $elements = $rs->GetArray();
                //REMEBER We have to convert db to normal array format
                break;
        }
        //Let's parse the array for foreach scan for Global part in template, second foreach cycle through objects to insert in it
        if (is_array($elements)) {
            foreach ($elements as $key => $value) {
                unset($tmp_output);
                unset($output);
                foreach ($value as $key2 => $value2) {
                    $function_part = explode("_", $value2[func]);
                    module_add_css_js($function_part[0]);
                    require_once $CONF[path_base] . $CONF[dir_modules] . $function_part[0] . "/objects.php";
                    $tmp_output = $value2[func]($value2[param]);
                    //FIX PATH FOR MODULES IMAGES
                    if (file_exists($CONF[path_base] . $CONF[dir_modules] . $function_part[0] . "/template/" . $CUR_TEMPLATE[name] . "/images/")) {
                        $tmp_output = str_replace("%[IMAGE_MPATH]%", $CONF[abs_url] . $CONF[dir_modules] . $function_part[0] . "/template/" . $CUR_TEMPLATE[name] . "/images/", $tmp_output);
                    } elseif (file_exists($CONF[path_base] . $CONF[dir_modules] . $function_part[0] . "/template/" . $CONF[default_template] . "/images/")) {
                        $tmp_output = str_replace("%[IMAGE_MPATH]%", $CONF[abs_url] . $CONF[dir_modules] . $function_part[0] . "/template/" . $CONF[default_template] . "/images/", $tmp_output);
                    } else {
                        $tmp_output = str_replace("%[IMAGE_MPATH]%", $CONF[abs_url] . $CONF[common_image], $tmp_output);
                    }
                    $output .= $tmp_output;
                }
                $CUR_TEMPLATE[content] = str_replace("%[" . $type . "_SPACE_{$key}]%", $output, $CUR_TEMPLATE[content]);
            }
        }
    }
}
Example #2
0
function draw_form($Form, $module = "", $error = "", $result = "", $page = 1)
{
    global $CONF, $FORM_TEMPLATE, $cur_style, $max_col, $cur_vis, $TSEL_JS, $PAGE, $GLOBCNT, $CUR_FORMNAME;
    $CUR_FORMNAME = $Form[name];
    $GLOBCNT = 0;
    $cur_page = 1;
    if ($page == "") {
        $page = 1;
    }
    //$FORM_TEMPLATE["start_box_form"]
    //Should we use GET ?
    if (strtoupper($Form[form_method]) == "GET") {
        $method = "GET";
    } else {
        $method = "POST";
    }
    //Do we have a TARGET ?
    if (isset($Form[form_target])) {
        $target = "target=\"" . $Form[form_target] . "\"";
    } else {
        $target = "";
    }
    //Init form
    $output .= '<FORM	name="' . $Form[name] . '" action="' . $_SERVER[REQUEST_URI] . '"	method="' . $method . '"	enctype="multipart/form-data" class="' . $FORM_TEMPLATE[form_style] . '"  ' . $target . '>
				<input type="hidden" name="form_id"	value="' . $Form[name] . '">
				<input type="hidden" name="form_page"	value="' . $page . '">';
    if (strlen($Form["box_title"]) > 0) {
        $output .= str_replace("%[TITLE]%", $Form[box_title], $FORM_TEMPLATE[form_title]);
    }
    if (strlen($error["resp"]) > 1) {
        $output .= str_replace("%[ERROR_RESP]%", $error[resp], $FORM_TEMPLATE[form_error_resp]);
    }
    //Get	default	line style & Js
    if (isset($Form[line_style])) {
        $tmp = explode("||", $Form[line_style]);
        foreach ($tmp as $value_style) {
            if (strlen($value_style) > 0) {
                $tmp2 = explode("::", $value_style);
                $form_style[$tmp2[0]] = $tmp2[1];
            }
        }
    } else {
        //Get default value from	template definitions
        $tmp = explode("||", $FORM_TEMPLATE[line_style]);
        foreach ($tmp as $value_style) {
            if (strlen($value_style) > 0) {
                $tmp2 = explode("::", $value_style);
                $form_style[$tmp2[0]] = $tmp2[1];
            }
        }
    }
    $cur_style = $form_style;
    $in_group = 0;
    //Start	of form	table
    $output .= $FORM_TEMPLATE[form_table_start];
    foreach ($Form["Fields"] as $key => $value) {
        $GLOBCNT++;
        list($InputType, $value, $options) = explode("||", $Form["Fields"][$key]["content"]);
        //check	if we're changing	page
        if ($InputType == "page" && $value != $cur_page) {
            $cur_page = $value;
        }
        //Scan all the array for the current page	and	draw the form
        if ($cur_page == $page && !in_array($InputType, $CONF[form_ignoretype])) {
            //Start	checking for default input type
            switch ($InputType) {
                case "text":
                    $output .= fw_form_text($Form["Fields"][$key], $key, $result[$key], $error[$key]);
                    break;
                case "pratval":
                    $output .= fw_form_pratiche_value($Form["Fields"][$key], $key, $result[$key], $error[$key]);
                    break;
                case "htmltext":
                    $output .= fw_html_text($Form["Fields"][$key], $key, $result[$key], $error[$key]);
                    break;
                case "date":
                    $output .= fw_form_date($Form["Fields"][$key], $key, $result[$key], $error[$key]);
                    break;
                case "time":
                    $output .= fw_form_time($Form["Fields"][$key], $key, $result[$key], $error[$key]);
                    break;
                case "password":
                    $output .= fw_form_password($Form["Fields"][$key], $key, $result[$key], $error[$key]);
                    break;
                case "hidden":
                    $output .= fw_form_hidden($Form["Fields"][$key], $key, $result[$key], $error[$key]);
                    break;
                case "textarea":
                    $output .= fw_form_textarea($Form["Fields"][$key], $key, $result[$key], $error[$key]);
                    break;
                case "checkbox":
                    $output .= fw_form_checkbox($Form["Fields"][$key], $key, $result[$key], $error[$key]);
                    break;
                case "select":
                    $output .= fw_form_select($Form["Fields"][$key], $key, $result[$key], $error[$key]);
                    break;
                case "mselect":
                    $output .= fw_form_mselect($Form["Fields"][$key], $key, $result[$key], $error[$key], $Form[name]);
                    break;
                case "tselect":
                    $output .= fw_form_text_select($Form["Fields"][$key], $key, $result[$key], $error[$key], $Form[name], $module);
                    break;
                case "line":
                    $output .= "";
                    //REMEMBER
                    break;
                case "permission":
                    if (isset($_GET[id])) {
                        $id = $_GET[id];
                    } else {
                        $id = "";
                    }
                    $output .= fw_form_perm($Form["Fields"][$key], $key, $module, $Form[name], $id, $result[$key], $error[$key]);
                    break;
                case "ug_value":
                    $output .= fw_form_value($Form["Fields"][$key], $key, $module, $Form[name], $result[$key], $error[$key]);
                    break;
                case "tnf":
                    if (isset($_GET[id])) {
                        $id = $_GET[id];
                    } else {
                        $id = "";
                    }
                    $output .= fw_form_tnf($Form["Fields"][$key], $key, $module, $result["ref_id"], $id, $error[$key]);
                    break;
                case "file":
                    $output .= fw_form_file($Form["Fields"][$key], $key);
                    break;
                case "html":
                    $output .= fw_form_html($Form["Fields"][$key], $key, $result[$key]);
                    break;
                case "submit":
                    $output .= fw_form_submit($Form["Fields"][$key], $key);
                    break;
                case "group":
                    $group_part = explode("_", $key);
                    if ($group_part[1] == "start") {
                        if (isset($Form["Fields"][$key][line_style])) {
                            $tmp = explode("||", $Form["Fields"][$key][line_style]);
                            foreach ($tmp as $value_style) {
                                if (strlen($value_style) > 0) {
                                    $tmp2 = explode("::", $value_style);
                                    $cur_style[$tmp2[0]] = $tmp2[1];
                                }
                            }
                        }
                        $in_group = 1;
                        $cur_group = str_replace("_start", "", $key);
                        $output .= fw_form_group("s", $key, $Form[Fields][$key], $error[$key]);
                    } elseif ($group_part[1] == "end") {
                        $in_group = 0;
                        $cur_group = "";
                        $inv_group = str_replace(",", "','", "'" . implode(",", $group_fields) . "'");
                        $output = str_replace("%[VIS_FIELD_ARRAY]%", $inv_group, $output);
                        $group_start = str_replace("_end", "_start", $key);
                        $output .= fw_form_group("e", $Form[Fields][$key], $error[$group_start]);
                        $cur_style = $form_style;
                    }
                    break;
                default:
                    //If it's	not	a	standard input type, lets	check	if it's	a	module defined type	and	run	it
                    if (strstr($InputType, "_")) {
                        $func_name = str_replace("_", "_form_", $InputType);
                        if (!function_exists($func_name)) {
                            $function_part = explode("_", $InputType);
                            module_add_css_js($function_part[0]);
                            require_once $CONF[path_base] . $CONF[dir_modules] . $function_part[0] . "/form.php";
                            if (!function_exists($func_name)) {
                                trigger_error(str_replace("%ELEMENT%", $InputType, FW_ERROR_NOFORMELEMENT), E_USER_ERROR);
                            }
                        }
                        $output .= $func_name("d", $Form["Fields"][$key], $key, $result[$key], $error[$key]);
                    } else {
                        trigger_error(str_replace("%ELEMENT%", $InputType, FW_ERROR_NOFORMELEMENT), E_USER_ERROR);
                    }
                    break;
            }
            if ($in_group == 1 && $InputType != "group") {
                $group_fields[] = $key;
            }
            $output = str_replace("%[TR_VIS]%", $cur_vis, $output);
            $output = str_replace("%[TR_ID]%", "id=\"" . $key . "\"", $output);
        }
    }
    $output .= "</table></form>\n";
    $PAGE[JS_AC] = $TSEL_JS;
    // Fix table colspan according to	max_col	used
    if ($max_col == 1) {
        $tdcs1 = "";
        $tdcs2 = "";
    } elseif ($max_col == 2) {
        $tdcs1 = "2";
        $tdcs2 = "";
    } elseif ($max_col == 3) {
        $tdcs1 = "3";
        $tdcs2 = "2";
    }
    $output = str_replace("%[COLSPAN1]%", $tdcs1, $output);
    $output = str_replace("%[COLSPAN2]%", $tdcs2, $output);
    return $output;
}