static function match($data, $condition, $fields)
 {
     $match = true;
     $ops = array("eq", "neq", "lt", "gt", "like", "nlike", "starts", "oneof");
     foreach (explode("||", $condition) as $filter) {
         $filter = explode("|", $filter);
         if (count($filter) != 3 or !isset($data[$filter[0]]) or !in_array($filter[1], $ops)) {
             continue;
         }
         $f_value = $filter[2];
         if (in_array($fields[$filter[0]]["SIMPLE_TYPE"], array("date", "dateselect", "time", "datetime"))) {
             $f_value = self::datetime_to_int($f_value);
         }
         $f_value = sgsml::scalarize((array) $f_value, $fields[$filter[0]]);
         $value = sgsml::scalarize($data[$filter[0]]["data"], $fields[$filter[0]]);
         if (sys_contains($f_value, "@")) {
             $key = substr(trim($f_value, "|"), 1, -1);
             if (!empty($_SESSION[$key])) {
                 $f_value = str_replace("@" . $key . "@", $_SESSION[$key], $f_value);
             }
         }
         if ($filter[1] == "oneof") {
             $f_value = explode(",", $f_value);
         }
         switch ($filter[1]) {
             case "neq":
                 $match = $value != $f_value;
                 break;
             case "oneof":
                 $match = in_array($value, $f_value);
                 break;
             case "lt":
                 $match = $value < $f_value;
                 break;
             case "gt":
                 $match = $value > $f_value;
                 break;
             case "like":
                 $match = sys_contains($value, $f_value);
                 break;
             case "nlike":
                 $match = !sys_contains($value, $f_value);
                 break;
             case "starts":
                 $match = sys_strbegins($value, $f_value);
                 break;
             default:
                 $match = $value == $f_value;
                 break;
         }
         if (!$match) {
             return false;
         }
     }
     return $match;
 }
 static function cutcopy_items($folder, $view, $items, $operation)
 {
     if (!is_array($items)) {
         return array();
     }
     $writeable = $operation == "cut";
     $sgsml = new sgsml($folder, $view, $items, $writeable);
     if (!isset($sgsml->buttons[$operation])) {
         return array();
     }
     $tname = $sgsml->tname;
     $rows = $sgsml->get_rows(array("id"));
     if (is_array($rows) and count($rows) == 0 and count($items) == 0) {
         return array();
     }
     if (!is_array($rows) or count($rows) == 0 or count($rows) < count($items)) {
         exit("{t}Item(s) not found or access denied.{/t}");
     }
     $items = array();
     foreach ($rows as $row) {
         $items[] = $row["id"];
     }
     $unique_fields = array();
     $file_fields = array();
     $data_fields = array();
     foreach ($sgsml->fields as $field) {
         if (isset($field["DISABLE_CCP"])) {
             continue;
         }
         if (isset($field["KEY"]) or isset($field["IS_UNIQUE"])) {
             $unique_fields[] = $field["NAME"];
         }
         if ($field["SIMPLE_TYPE"] == "files") {
             $file_fields[] = $field["NAME"];
         }
         $data_fields[] = $field["NAME"];
     }
     $delete_mode = isset($sgsml->buttons["delete"]) ? "delete" : "purge";
     return array("operation" => $operation, "tname" => $tname, "custom_name" => $sgsml->att["CUSTOM_NAME"], "default_sql" => $sgsml->current_view["DEFAULT_SQL"], "handler" => $sgsml->handler, "items" => $items, "folder" => $folder, "folders" => $sgsml->vars["folders"], "unique_fields" => $unique_fields, "file_fields" => $file_fields, "delete_mode" => $delete_mode, "data_fields" => $data_fields, "where" => $sgsml->where, "vars_noquote" => $sgsml->vars_noquote);
 }
 private static function _build_data($html, $data_arr = array(), $xml = false, $rss = false, $hidden = false)
 {
     $t = $GLOBALS["t"];
     $data = array();
     $i = 0;
     if (count($data_arr) == 0) {
         $data_arr = $t["data"];
     } else {
         $data_arr = array($data_arr);
     }
     foreach ($data_arr as $asset) {
         if (!isset($asset["_id"])) {
             continue;
         }
         if (!in_array("id", $t["hidden_fields"]) and is_numeric($asset["_id"])) {
             $data[$i]["id"] = array("name" => "Id", "displayname" => "{t}Id{/t}", "type" => "", "field" => "id", "filter" => $asset["_id"], "width" => "");
         }
         foreach ($t["fields"] as $akey => $value) {
             if ((isset($value["HIDDENIN"][$t["view"]]) or isset($value["HIDDENIN"]["all"])) and !$hidden) {
                 continue;
             }
             if ($value["SIMPLE_TYPE"] == "password") {
                 continue;
             }
             $aval = $asset[$akey];
             if (!is_array($aval)) {
                 $aval_data = explode("|", trim($aval, "|"));
                 $aval = array("name" => "", "type" => "", "data" => $aval_data, "filter" => $aval_data);
             }
             if ($value["SIMPLE_TYPE"] == "checkbox") {
                 if ($aval["data"][0] == "1") {
                     $aval["filter"][0] = "{t}yes{/t}";
                 } else {
                     $aval["filter"][0] = "";
                 }
             }
             if ($value["SIMPLE_TYPE"] == "date") {
                 $aval["filter"][0] = modify::dateformat($aval["data"][0], "{t}m/d/Y{/t}");
             }
             if ($value["SIMPLE_TYPE"] == "datetime") {
                 $aval["filter"][0] = modify::dateformat($aval["data"][0], "{t}m/d/Y g:i a{/t}");
             }
             $filter = "";
             if (isset($aval["filter"]) and is_array($aval["filter"]) and isset($aval["filter"][0])) {
                 if ($xml and !$rss and sgsml::type_is_multiple($value["SIMPLE_TYPE"]) and (empty($value["SIMPLE_SIZE"]) or $value["SIMPLE_SIZE"] != "1")) {
                     $filter = "|" . implode("|", $aval["data"]) . "|";
                 } else {
                     if ($xml and !$rss) {
                         $filter = implode("|", $aval["data"]);
                     } else {
                         $filter = implode(" ", $aval["filter"]);
                     }
                 }
             } else {
                 if (!is_array($aval["filter"]) and $aval != "") {
                     $filter = $aval;
                 } else {
                     if ($html) {
                         $filter = " ";
                     }
                 }
             }
             if (!empty($value["DISPLAYNAME"])) {
                 $name = $value["DISPLAYNAME"];
                 $displayname = $value["DISPLAYNAME"];
             } else {
                 $name = $value["NAME"];
                 $displayname = $value["NAME"];
             }
             if (!isset($value["WIDTH"])) {
                 $value["WIDTH"] = "";
             }
             if (count($aval["data"]) < 2) {
                 $aval["data"] = implode(" ", $aval["data"]);
             }
             $linktext = "";
             if (!empty($value["LINKTEXT"][0]["VALUE"][1]) and strpos($value["LINKTEXT"][0]["VALUE"][1], "ext/norefer.php") !== false) {
                 $linktext = modify::link($value["LINKTEXT"][0]["VALUE"][1], $asset, 0, "folder2=" . rawurlencode($t["folder"]) . "&view2=" . rawurlencode($t["view"]));
                 $linktext = str_replace("&iframe=1", "", $linktext);
             }
             $link = "";
             if (!empty($value["LINK"][0]["VALUE"][1]) and strpos($value["LINK"][0]["VALUE"][1], "ext/norefer.php") !== false) {
                 $link = modify::link($value["LINK"][0]["VALUE"][1], $asset, 0, "folder2=" . rawurlencode($t["folder"]) . "&view2=" . rawurlencode($t["view"]));
                 $link = str_replace("&iframe=1", "", $link);
             }
             $data[$i][$akey] = array("name" => $name, "displayname" => $displayname, "field" => $value["NAME"], "data" => $aval["data"], "filter" => $filter, "type" => $value["SIMPLE_TYPE"], "width" => $value["WIDTH"], "linktext" => $linktext, "link" => $link);
         }
         if (!isset($asset["created"])) {
             $asset["created"] = 0;
         }
         if (!isset($asset["lastmodified"])) {
             $asset["lastmodified"] = 0;
         }
         if (is_array($asset["created"])) {
             $asset["lastmodified"] = $asset["created"]["data"][0];
         }
         if (is_array($asset["lastmodified"])) {
             $asset["lastmodified"] = $asset["lastmodified"]["data"][0];
         }
         if (empty($data[$i]["created"])) {
             $data[$i]["created"] = array("name" => "", "type" => "", "data" => $asset["created"]);
         }
         if (empty($data[$i]["lastmodified"])) {
             $data[$i]["lastmodified"] = array("name" => "", "type" => "", "data" => $asset["lastmodified"]);
         }
         if (!empty($asset["lastmodifiedby"]) and !isset($data[$i]["lastmodifiedby"]) and $html) {
             if (!in_array("lastmodified", $t["hidden_fields"])) {
                 $data[$i]["lastmodified"] = array("name" => "lastmodified", "displayname" => "{t}Modified{/t}", "type" => "", "field" => "lastmodified", "filter" => sys_date("{t}m/d/Y{/t}", $asset["lastmodified"]), "width" => "");
             }
             if (!in_array("lastmodifiedby", $t["hidden_fields"])) {
                 $data[$i]["lastmodifiedby"] = array("name" => "lastmodifiedby", "displayname" => "{t}Modified by{/t}", "type" => "", "field" => "lastmodifiedby", "filter" => $asset["lastmodifiedby"], "width" => "");
             }
         }
         $data[$i]["_id"] = array("name" => "", "type" => "", "data" => $asset["_id"]);
         $i++;
     }
     return $data;
 }
Exemple #4
0
 static function create_edit($tfolder, $tview, $mode)
 {
     $errors = array();
     $defaults = array();
     $form_ids = array();
     $saved_ids = array();
     $sgsml = new sgsml($tfolder, $tview, array_keys($_REQUEST["form_fields"]));
     $file_fields = $sgsml->get_fields_by_type("files");
     foreach ($_REQUEST["form_fields"] as $id) {
         $prefix = "form_" . md5($id);
         $result = array();
         foreach ($file_fields as $field_name) {
             if ($error = self::_processfiles($sgsml, $field_name, $id)) {
                 $result[$field_name] = $error;
             }
         }
         if (!sys_validate_token()) {
             $result['token'] = array(array("{t}validation failed{/t}", "{t}Invalid security token{/t} {t}Please activate cookies.{/t}"));
         }
         $data = array();
         foreach ($sgsml->current_fields as $field_name => $field) {
             $prefix_name = $prefix . $field_name;
             if (isset($_REQUEST[$prefix_name])) {
                 $data[$field_name] = $_REQUEST[$prefix_name];
             }
         }
         if (!$result) {
             if ($mode == "create") {
                 $result = $sgsml->insert($data);
             } else {
                 $result = $sgsml->update($data, $id);
             }
         }
         foreach ($sgsml->current_fields as $field_name => $field) {
             if (!isset($data[$field_name])) {
                 continue;
             }
             $defaults[$prefix][$field_name] = is_array($data[$field_name]) ? implode("|", $data[$field_name]) : $data[$field_name];
         }
         if (!is_array($result)) {
             $form_ids[] = $id;
             $saved_ids[] = $result;
             if ($mode == "create") {
                 unset($defaults[$prefix]);
             }
         } else {
             $errors[$prefix] = $result;
         }
     }
     return array($errors, $defaults, $form_ids, $saved_ids);
 }
Exemple #5
0
 static function create_user($username, $data = array())
 {
     $data["username"] = $username;
     $data["createdby"] = "auth_" . SETUP_AUTH;
     if (empty($data["password"])) {
         $data["password"] = "******";
     }
     if (empty($data["email"])) {
         $data["email"] = $username;
     }
     if (!strpos($data["email"], "@")) {
         $data["email"] .= "@invalid.local";
     }
     if (empty($_SESSION["username"])) {
         $_SESSION["username"] = "******";
         $_SESSION["permission_sql"] = "1=1";
         $_SESSION["permission_sql_read"] = "1=1";
         $_SESSION["groups"] = array();
     }
     $row_id = db_select_value("simple_sys_users", "id", "username=@username@", array("username" => $username));
     if (!empty($row_id)) {
         return;
     }
     $row = db_select_first("simple_sys_tree", "id", "ftype=@ftype@", "lft asc", array("ftype" => "sys_users"));
     if (empty($row["id"])) {
         return;
     }
     $sgsml = new sgsml($row["id"], "new");
     $result = $sgsml->insert($data);
     if (is_numeric($result)) {
         trigger::addgroupmember(0, array("username" => $username), array("users_self_registration"));
         sys_notification("{t}Item successfully created.{/t} (" . $result . ")");
     } else {
         if (is_array($result) and count($result) > 0) {
             $message = array();
             foreach ($result as $errors) {
                 foreach ($errors as $error) {
                     $message[] = $error[0] . ": " . $error[1];
                 }
             }
             sys_log_message_alert("login", implode("\n", $message));
         }
     }
 }
Exemple #6
0
 /**
  * Upload a file to the temp directory (data comes from php://input)
  * 
  * @param string $filename Filename
  * @return array Array( tmp_path=>Path of the file, basename=>filename, filesize=>filesize)
  */
 static function upload_file($filename)
 {
     if (empty($filename) or empty($_SESSION["username"])) {
         exit("{t}Upload failed{/t}");
     }
     if (strpos($filename, "://")) {
         $target = sgsml::getfile_url($filename);
     } else {
         $target = sgsml::getfile_upload($filename);
     }
     if ($target == "" or !file_exists($target)) {
         exit("{t}Upload failed{/t}: {t}Failed to write file to disk.{/t}");
     }
     return array("tmp_path" => $target, "basename" => modify::basename($target), "filesize" => modify::filesize($target));
 }
 private static function _create_default_folder_xml_data($xml, $folder)
 {
     $assets = sys_array_shift(get_object_vars($xml));
     if (is_object($assets)) {
         $assets = array($assets);
     }
     if (!is_array($assets) or count($assets) == 0) {
         return;
     }
     @set_time_limit(60);
     $sgsml = new sgsml($folder, "new");
     $sgsml->notification = false;
     foreach ($assets as $asset) {
         $data = get_object_vars($asset);
         if (isset($data["@attributes"])) {
             unset($data["@attributes"]);
         }
         $result = $sgsml->insert($data);
         if (DEBUG and !is_int($result)) {
             print_r($result);
         }
         if (DEBUG) {
             echo " @" . memory_get_usage(true);
         }
         sys::$cache = array();
         sys::$db_queries = array();
     }
 }
Exemple #8
0
 function filter_field($field_name, $value, $row)
 {
     if ($field_name == "" or !isset($this->fields[$field_name])) {
         return $value;
     }
     $field = $this->current_fields[$field_name];
     $type = $field["SIMPLE_TYPE"];
     if (!empty($field["NO_CHECKS"])) {
         return $value;
     }
     $filters = array();
     if (isset($this->current_view["filters"][$field_name])) {
         $filters = $this->current_view["filters"][$field_name];
     }
     if (is_call_type($type)) {
         $filters[] = array("FUNCTION" => "modify::nl2br");
         $filters[] = array("FUNCTION" => "quote");
         /* TODO implement
             $filters[] = array("FUNCTION"=>"type_".$type."::render_page");
         	$filters[] = array("FUNCTION"=>"modify::htmlfield");
         	$filters[] = array("FUNCTION"=>"quote");
         	$filters[] = array("FUNCTION"=>"type_".$type."::render_value");
         	$values[$key] = call_user_func(array($class, $function), $val, $value, $params, self::_explode($row));
         */
     } else {
         if ($type == "textarea") {
             $filters[] = array("FUNCTION" => "modify::nl2br");
             $filters[] = array("FUNCTION" => "quote");
         } else {
             $filters[] = array("FUNCTION" => "modify::field");
             $filters[] = array("FUNCTION" => "quote");
         }
     }
     if (empty($filters)) {
         return $value;
     }
     if (sgsml::type_is_multiple($type)) {
         $values = explode("|", trim($value, "|"));
     } else {
         $values = (array) $value;
     }
     foreach ($filters as $filter) {
         list($class, $function, $params) = sys_find_callback("modify", $filter["FUNCTION"]);
         if (isset($filter["TYPE"])) {
             continue;
         }
         // TODO implement
         foreach ($values as $key => $value) {
             $values[$key] = call_user_func(array($class, $function), $value, $params, self::_explode($row));
         }
     }
     return $values;
 }