private static function _apply_schema($schema_name, $schema_fields)
 {
     $types = self::_get_types();
     $text = $types["text"];
     $types = array("text" => $types["string"], "password" => $types["string"], "checkbox" => $types["bool"], "time" => $types["date"], "date" => $types["date"], "datetime" => $types["date"], "id" => $types["id"], "folder" => $types["id"], "pid" => $types["id"], "float" => $types["float"], "int" => $types["int"], "textarea" => $types["text"], "dateselect" => $types["text"], "select" => $types["text"], "multitext" => $types["text"], "files" => $types["text"], "dateselect_small" => $types["string"], "select_small" => $types["string"], "files_small" => $types["string"]);
     $buffer = array();
     if (!self::table_exists($schema_name) and !sql_table_create($schema_name)) {
         $buffer[] = sprintf("{t}SQL FAILED: %s{/t}\n", "table_exists") . sql_error();
     }
     foreach ($schema_fields as $field) {
         if (!isset($field["SIMPLE_TYPE"]) or isset($field["NODB"])) {
             continue;
         }
         $type = $field["SIMPLE_TYPE"];
         if (!empty($field["SIMPLE_SIZE"])) {
             if ($type == "dateselect" and $field["SIMPLE_SIZE"] == "1") {
                 $type = "dateselect_small";
             }
             if ($type == "select" and $field["SIMPLE_SIZE"] == "1") {
                 $type = "select_small";
             }
             if ($type == "files" and $field["SIMPLE_SIZE"] == "1") {
                 $type = "files_small";
             }
         }
         $ftype = $text;
         if (isset($types[$type])) {
             $ftype = $types[$type];
         }
         if (isset($field["DB_TYPE"])) {
             $ftype[0] = $field["DB_TYPE"];
         }
         if (isset($field["DB_SIZE"])) {
             $ftype[1] = $field["DB_SIZE"];
         }
         if (self::table_column_exists($schema_name, $field["NAME"])) {
             $result = self::table_change_column($schema_name, $field["NAME"], sprintf($ftype[0], $ftype[1]));
         } else {
             if (!empty($field["SIMPLE_DEFAULT"])) {
                 $default = $field["SIMPLE_DEFAULT"];
                 if ($field["SIMPLE_TYPE"] == "select") {
                     $default = trim($default, "|");
                     if (substr_count($default, "|") != 0) {
                         $default = "|" . $default . "|";
                     }
                 }
                 if ($field["SIMPLE_TYPE"] == "checkbox") {
                     $default = str_replace("checked", "1", $default);
                 }
             } else {
                 $default = "";
             }
             if (!empty($field["STORE"]) and is_array($field["STORE"])) {
                 foreach ($field["STORE"] as $store) {
                     list($class, $function, $params) = sys_find_callback("modify", $store["FUNCTION"]);
                     $default = call_user_func(array($class, $function), $default, array(), $params);
                 }
             }
             $result = self::table_add_column($schema_name, $field["NAME"], sprintf($ftype[0], $ftype[1]), $default);
         }
         if (!$result) {
             $buffer[] = sprintf("{t}SQL FAILED: %s{/t}\n", "sql_table_modify - " . $schema_name . " - " . $field["NAME"]) . sql_error();
         }
     }
     $buffer = array_merge($buffer, self::_apply_indexes($schema_name, $schema_fields));
     if (count($buffer) != 0) {
         sys_alert(implode("\n\n", $buffer));
         return false;
     }
     return true;
 }
Example #2
0
function sys_process_schema_request()
{
    $defaults = folder_get_default_values($GLOBALS["t"]["folder"]);
    if (!empty($_REQUEST["defaults"])) {
        $defaults = array_merge(json_decode($_REQUEST["defaults"], true), $defaults);
    }
    if (empty($GLOBALS["t"]["fields"])) {
        return;
    }
    foreach (array_keys($GLOBALS["t"]["fields"]) as $key) {
        $field =& $GLOBALS["t"]["fields"][$key];
        if (isset($field["SIMPLE_DEFAULT_FUNCTION"])) {
            list($class, $function, $params) = sys_find_callback("modify", $field["SIMPLE_DEFAULT_FUNCTION"]);
            $field["SIMPLE_DEFAULT"] = call_user_func(array($class, $function), $params);
        }
        if (isset($defaults[$key])) {
            $field["SIMPLE_DEFAULT"] = $defaults[$key];
        }
        if (empty($field["DATA"])) {
            continue;
        }
        foreach ($field["DATA"] as $vkey => $val) {
            if (!isset($val["_FUNCTION_"])) {
                continue;
            }
            list($class, $function, $params) = sys_find_callback("select", $val["_FUNCTION_"]);
            $result = call_user_func(array($class, $function), $params, array(), true);
            if (!empty($result["_ticket_"])) {
                $field["SIMPLE_LOOKUP"][$vkey] = array("ticket" => $result["_ticket_"], "schema" => $result["_params_"][1], "overload" => isset($result["_overload_"]));
                $_SESSION["tickets"][$result["_ticket_"]] = $result["_params_"];
                unset($result["_ticket_"]);
                unset($result["_params_"]);
                unset($result["_overload_"]);
            }
            $field["DATA"][$vkey] = $result;
        }
    }
}
Example #3
0
 static function search_data($ticket, $search, $page, $ids = array())
 {
     if ($ticket == "" or empty($_SESSION["tickets"][$ticket])) {
         exit("[2] {t}Your session has timed out.{/t}");
     }
     $params = $_SESSION["tickets"][$ticket];
     list($class, $function, $unused) = sys_find_callback("select", array_shift($params));
     if (!empty($ids)) {
         $params[2][] = "id in (@ids@)";
     } else {
         if (!empty($params[1])) {
             $where = array();
             foreach (array_unique($params[1]) as $field) {
                 $where[] = sql_concat($field) . " like @search@";
             }
             $params[2][] = "(" . implode(" or ", $where) . ")";
         }
     }
     return call_user_func(array($class, $function), $params, array("search" => "%" . $search . "%", "ids" => $ids, "page" => $page));
 }
Example #4
0
 private static function _modifystore($store_arr, $value, $row)
 {
     if (!is_array($store_arr) or count($store_arr) == 0) {
         return $value;
     }
     foreach ($store_arr as $store) {
         list($class, $function, $params) = sys_find_callback("modify", $store["FUNCTION"]);
         $value = call_user_func(array($class, $function), $value, $row, $params);
     }
     return $value;
 }
Example #5
0
 private function _validate($data, $id)
 {
     $error = array();
     foreach (array_keys($this->current_fields) as $field_name) {
         if ($result = $this->validate_field($field_name, $data[$field_name], $id)) {
             $error[$field_name] = $result;
         }
     }
     foreach ($this->rowvalidates as $validate) {
         list($class, $function, $params) = sys_find_callback("validate", $validate["FUNCTION"]);
         $result = call_user_func(array($class, $function), $data, $params);
         if ($result != "") {
             $vfields = array();
             foreach (explode("|", $validate["FIELDS"]) as $vfield) {
                 $tfield = $this->fields[$vfield];
                 $vfields[] = isset($tfield["DISPLAYNAME"]) ? $tfield["DISPLAYNAME"] : $tfield["NAME"];
                 $error[$vfield][] = array();
             }
             $error[$validate["FIELDS"]][] = array(implode(", ", $vfields), $result);
         }
     }
     return $error;
 }
Example #6
0
 static function callfunc($func, $folder, $view)
 {
     list($class, $function, $params) = sys_find_callback("custom", $func);
     return call_user_func(array($class, $function), $folder, $view, $params);
 }