function sys_process_session_request() { if (!empty($_REQUEST["popup"]) and !empty($_REQUEST["iframe"])) { unset($_REQUEST["iframe"]); } if (!empty($_REQUEST["iframe"])) { sys::$smarty->assign("iframe", 1); } $keep_vars = array("popup", "preview", "lookup", "eto"); foreach ($keep_vars as $var) { if (empty($_REQUEST[$var])) { continue; } sys::$urladdon .= "&" . $var . "=" . $_REQUEST[$var]; sys::$smarty->assign($var, $_REQUEST[$var]); } $_SESSION["view"]["_" . $GLOBALS["tfolder"]] = $GLOBALS["tview"]; sys::$urladdon = "folder2=" . rawurlencode($GLOBALS["tfolder"]) . "&view2=" . $GLOBALS["tview"] . sys::$urladdon; sys::$smarty->assign("urladdon", sys::$urladdon); if (!empty($_REQUEST["action_sys"]) and !empty($_SESSION["username"]) and sys_is_super_admin($_SESSION["username"])) { admin::process_action_sys(); } if (!empty($_REQUEST["style"])) { $_SESSION["theme"] = basename($_REQUEST["style"]); } sys::$smarty->assign("sys_style", !empty($_SESSION["theme"]) ? $_SESSION["theme"] : DEFAULT_STYLE); $table = $GLOBALS["table"]; if ($GLOBALS["tview"] != $table["view"]) { $GLOBALS["tview"] = $table["view"]; } $tview = $GLOBALS["tview"]; $tfolder = $GLOBALS["tfolder"]; $tfolders = $GLOBALS["tfolders"]; $tname = $GLOBALS["tname"]; $tquota = $GLOBALS["tquota"]; $anchor = $GLOBALS["sel_folder"]["anchor"]; if (!empty($_REQUEST["reset_view"])) { $_SESSION[$tname][$tview] = array(); $_SESSION["_" . $tfolder] = array(); $_SESSION["view"]["_" . $tfolder] = $tview; $_SESSION[$tname]["_" . $tfolder] = array(); } $current_view = $table["views"][$tview]; $cview = $current_view; $template = $tview; if ($current_view["TEMPLATE"] != "") { $template = $current_view["TEMPLATE"]; } if (isset($current_view["SCHEMA"]) and $current_view["SCHEMA"] != "") { $table2 = db_get_schema(sys_find_module($current_view["SCHEMA"])); $current_view = array_shift($table2["views"]); // preserve in search, override for schema=x if (!empty($table["att"]["SQL_HANDLER"]) and empty($current_view["SQL_HANDLER"])) { $current_view["SQL_HANDLER"] = $table["att"]["SQL_HANDLER"]; } $GLOBALS["table"] = $table2; // needed for asset-functions and triggers $table["att"] = $table2["att"]; if ($current_view["TEMPLATE"] != "") { $template = $current_view["TEMPLATE"]; } } $GLOBALS["current_view"] = $current_view; $field_names = array(); foreach ($current_view["fields"] as $key => $field) { if (isset($field["NODB"]) and empty($current_view["SQL_HANDLER"])) { continue; } $field_names[] = $key; } if (!empty($_SESSION["alert"])) { sys::$alert = array_merge(sys::$alert, $_SESSION["alert"]); $_SESSION["alert"] = array(); } if (!empty($_SESSION["notification"])) { sys::$notification = array_merge(sys::$notification, $_SESSION["notification"]); $_SESSION["notification"] = array(); } if (!empty($_SESSION["warning"])) { sys::$warning = array_merge(sys::$warning, $_SESSION["warning"]); $_SESSION["warning"] = array(); } if ($table["views"][$tview]["SCHEMA_MODE"] != "") { $tfolders = _build_merge_folders(array_keys($tfolders), $tfolder, $tview, true); } $dclick = $current_view["DOUBLECLICK"]; if ($dclick == "") { if (in_array($template, array("display", "free")) and isset($current_view["views"]["details"])) { $dclick = "details"; } else { $dclick = "edit"; } } if (isset($current_view["MERGE_TABS"])) { unset($current_view["tabs"]); foreach (array_keys($current_view["fields"]) as $key) { $current_view["fields"][$key]["SIMPLE_TAB"] = array("general"); } } $tfield_1 = isset($current_view["TFIELD_1"]) ? $current_view["TFIELD_1"] : modify::get_required_field($current_view["fields"]); $tfield_2 = isset($current_view["TFIELD_2"]) ? $current_view["TFIELD_2"] : ""; // TODO2 reduce ?? $t = array("anchor" => $anchor, "att" => $table["att"], "buttons" => $current_view["buttons"], "custom_name" => $table["att"]["CUSTOM_NAME"], "data" => array(), "default_sql" => $current_view["DEFAULT_SQL"], "disable_tabs" => isset($current_view["DISABLE_TABS"]) ? $current_view["DISABLE_TABS"] : "", "doubleclick" => array_key_exists($dclick, $current_view["views"]) ? $dclick : "", "fields" => $current_view["fields"], "fields_all" => $table["fields"], "fields_query" => array_unique(array_merge(array($current_view["id"]), $field_names, array("created", "lastmodified", "createdby", "lastmodifiedby", "folder"))), "field_1" => $tfield_1, "field_2" => $tfield_2, "filter" => isset($current_view["FILTERS"]) ? $current_view["FILTERS"] : "", "filters" => $current_view["filters"], "folder" => $tfolder, "folders" => $tfolders, "folder_preview" => isset($_REQUEST["tpreview"]), "function" => isset($current_view["FUNCTION"]) ? $current_view["FUNCTION"] : "", "id" => $current_view["id"], "isdbfolder" => is_numeric($tfolder) ? true : false, "limit" => $current_view["LIMIT"], "links" => $current_view["links"], "linkstext" => $current_view["linkstext"], "load_css" => isset($table["att"]["LOAD_CSS"]) ? $table["att"]["LOAD_CSS"] : "", "load_js" => isset($table["att"]["LOAD_JS"]) ? $table["att"]["LOAD_JS"] : "", "lookup" => isset($_REQUEST["lookup"]) ? $_REQUEST["lookup"] : "", "order" => $current_view["ORDER"], "orderby" => $current_view["ORDERBY"], "groupby" => $current_view["GROUPBY"], "group" => $current_view["GROUP"], "handler" => $current_view["SQL_HANDLER"], "hidedata" => $_SESSION["hidedata"], "nosinglebuttons" => isset($cview["NOSINGLEBUTTONS"]) ? $cview["NOSINGLEBUTTONS"] : "", "notification" => &sys::$notification, "warning" => &sys::$warning, "noviewbuttons" => isset($cview["NOVIEWBUTTONS"]) ? $cview["NOVIEWBUTTONS"] : "", "page" => 1, "quota" => $tquota, "restore" => $current_view["restore"], "rights" => $GLOBALS["sel_folder"]["rights"], "vright" => isset($cview["RIGHT"]) ? $cview["RIGHT"] : "", "rowfilters" => $current_view["rowfilters"], "rowvalidates" => $current_view["rowvalidates"], "schema_mode" => $current_view["SCHEMA_MODE"], "singlebuttons" => $current_view["singlebuttons"], "sqllimit" => array(), "sqlorder" => "", "sqlvars" => array("folder" => $tfolder, "folders" => array_keys($tfolders)), "sqlvarsnoquote" => array(), "sqlwhere" => $current_view["SQLWHERE"], "sqlwhere_default" => $current_view["SQLWHERE_DEFAULT"], "subitem" => 0, "tabs" => isset($current_view["tabs"]) ? $current_view["tabs"] : array("general" => array("NAME" => "general")), "template" => "asset_" . $template . ".tpl", "template_mode" => isset($current_view["TEMPLATE_MODE"]) ? $current_view["TEMPLATE_MODE"] : "", "title" => $tname, "view" => $tview, "views" => $table["views"][$tview]["views"]); $GLOBALS["t"] = $t; if (!empty($current_view["SCHEMA_MODE"])) { sys_process_schema_request(); } }
private static function _restore($filename) { ob_end_flush(); $filename = str_replace(" ", "+", $filename); $filename = SIMPLE_STORE . "/backup/" . basename($filename); if (!file_exists($filename)) { return "{t}file not found.{/t} (" . $filename . ")"; } if (filesize($filename) == 0) { return "{t}No entries found.{/t} (" . $filename . ")"; } self::_out("{t}Extracting files{/t}: " . $filename); self::_out(""); if (self::$_restore_here) { $ftitle = str_replace(array("__", "---", "--"), array("/", " ", " "), substr(modify::basename($filename), 0, -4)); $ftitle = substr($ftitle, strrpos($ftitle, "/") + 1); $id = folders::create(substr($ftitle, 0, 40), "blank", "", $_SESSION["folder"], false); self::$_restore_folder = $id; self::_out("{t}Insert{/t}: simple_sys_tree: " . $ftitle . " [" . $id . "]"); } $result = sys_exec(sys_find_bin("tar") . " -tf " . modify::realfilename($filename)); $file_list = explode("\n", $result); if (count($file_list) == 0) { return ""; } $base_dir = SIMPLE_STORE . "/restore_" . NOW . "/"; sys_mkdir($base_dir); $cmd = "cd " . modify::realfilename($base_dir) . " && " . sys_find_bin("tar") . " -xf " . modify::realfilename($filename); if (DEBUG) { self::_out("TAR: " . $cmd . "\n\n"); } echo sys_exec($cmd); $update_ids = array(); $update_folders = array(); $restore_maps = array(); $xml_file = array_shift($file_list); self::_out("{t}Parsing{/t}: " . $xml_file); $xml = simplexml_load_file($base_dir . $xml_file); foreach ($xml->table as $data) { $data = get_object_vars($data->assetfolder); unset($data["@attributes"]); $id = $data["id"]; if (!empty($data["anchor"])) { $existing = db_select_first("simple_sys_tree", array("id", "'' as lastmodified"), "anchor=@anchor@", "", array("anchor" => $data["anchor"])); if (!empty($existing["id"])) { unset($data["anchor"]); } } else { $existing = db_select_first("simple_sys_tree", array("id", "lastmodified"), "id=@id@", "", array("id" => $id)); } if (!isset($data["fdescription"])) { $data["fdescription"] = ""; } $ftype = $data["ftype"]; $keys = array("fsizecount", "fchsizecount", "fcount", "fchcount", "ffcount", "lft", "rgt", "flevel", "folder", "id", "ftype"); foreach ($keys as $key) { unset($data[$key]); } if (isset($restore_maps[$data["parent"]])) { $data["parent"] = $restore_maps[$data["parent"]]; } if (empty($existing["id"]) or self::$_restore_here) { $parent = db_select_value("simple_sys_tree", "id", "id=@id@", array("id" => $data["parent"])); if (empty($parent) or count($restore_maps) == 0 and self::$_restore_here) { $data["parent"] = self::$_restore_folder; } $id2 = folders::create($data["ftitle"], $ftype, $data["fdescription"], $data["parent"], false); self::_out("{t}Insert{/t}: simple_sys_tree: " . $data["ftitle"] . " [ID " . $id . " -> parent/id: " . $data["parent"] . "/" . $id2 . "]"); $restore_maps[$id] = $id2; $id = $id2; } else { $restore_maps[$id] = $existing["id"]; } if (!self::$_restore_missing and (!self::$_restore_onlynewer or $data["lastmodified"] > $existing["lastmodified"])) { self::_out("{t}Update{/t}: simple_sys_tree " . $id); $error = db_update("simple_sys_tree", $data, array("id=@id@"), array("id" => $id)); if ($error) { self::_out($error); } } } foreach ($xml->table as $table_item) { if (!isset($table_item->asset) or count($table_item->asset) == 0) { continue; } foreach ($table_item->asset as $asset) { $table = $table_item["name"]; if ($table == "simple_sys_tree") { continue; } $data = get_object_vars($asset); unset($data["@attributes"]); foreach ($data as $dkey => $val) { $obj = $asset->{$dkey}; if (!isset($obj["is_file"]) or $val == "") { continue; } $file_arr[$key] = ""; $file_arr = explode("|", trim($val, "|")); foreach ($file_arr as $key => $value) { foreach ($file_list as $file) { if (basename($file) != basename($value)) { continue; } $value = $base_dir . $file; break; } $file_arr[$key] = $value; } $data[$dkey] = "|" . implode("|", $file_arr) . "|"; } $id = $data["id"]; $existing = db_select_first($table, array("id", "lastmodified"), "id=@id@", "", array("id" => $id)); $folder = $data["folder"]; if (isset($restore_maps[$folder])) { $data["folder"] = $restore_maps[$folder]; } if (empty($existing["id"]) or self::$_restore_here) { if (self::$_restore_missing) { $data["id"] = $id; } else { $data["id"] = sql_genID($table) * 100; } self::_out("{t}Insert{/t}: " . $table . ": " . $data["id"]); $error = db_insert($table, $data); if ($error) { self::_out($error); } $update_folders[$data["folder"]] = $table; $update_ids[$data["folder"]][] = $data["id"]; } else { if (!self::$_restore_missing) { if (!self::$_restore_onlynewer or $data["lastmodified"] > $existing["lastmodified"]) { self::_out("{t}Update{/t}: " . $table . " " . $id); $error = db_update($table, $data, array("id=@id@"), array("id" => $id)); if ($error) { self::_out($error); } $update_folders[$data["folder"]] = $table; $update_ids[$data["folder"]][] = $id; } } } } } if (count($update_folders) > 0) { foreach ($update_folders as $folder => $table) { if (strpos($table, "nodb_")) { continue; } db_update_treesize($table, $folder); $ftype = str_replace("simple_", "", $table); $schema = db_get_schema(sys_find_module($ftype)); if (empty($schema["views"]["display"])) { continue; } if (!empty($schema["att"]["SQL_HANDLER"]) or !empty($schema["att"]["NO_SEARCH_INDEX"])) { continue; } self::_out("... "); $fields = $schema["fields"]; if (folder_in_trash($folder)) { continue; } foreach ($update_ids[$folder] as $id) { self::_out("{t}Rebuild search index{/t}: " . $table . " [" . $id . "]"); db_search_update($table, $id, $fields); } } } self::_out(""); $message = "{t}Restore complete{/t}: " . str_replace(array("__", "---", "--"), array("/", "] [", " ["), substr(modify::basename($filename), 0, -4)) . "]"; sys_log_message_log("info", $message); self::_out($message); return ""; }
static function folder_rename($folder, $title, $type, $description, $icon, $notification) { if ($title == "") { return ""; } self::_require_access($folder, "write"); if (!is_numeric($folder)) { $url = sys_parse_folder($folder); $handler = "lib_" . $url["handler"]; self::require_method("rename_folder", $handler); $title = str_replace(array(".", "\\", "/"), "", $title); $return = call_user_func(array($handler, "rename_folder"), $title, $url["mountpoint"], $url["mfolder"]); if ($return == "ok") { return dirname($folder) . "/" . $title . "/"; } else { if ($return != "") { exit($return); } } } else { $row = db_select_first("simple_sys_tree", array("notification", "ftype"), "id=@id@", "", array("id" => $folder)); if (empty($row["ftype"])) { exit("{t}Folder not found.{/t}"); } if ($notification != "" and ($notification != $row["notification"] or $type != $row["ftype"])) { $schema = db_get_schema(sys_find_module($type)); if (!empty($schema["att"]["ENABLE_ASSET_RIGHTS"]) and $schema["att"]["ENABLE_ASSET_RIGHTS"] != "owner_write") { self::_require_access($folder, "admin"); } } $result = folders::rename($folder, $title, $type, $description, $icon, trim($notification)); if ($result == "") { exit("{t}Folder already exists.{/t}"); } return $folder; } return ""; }
static function delete($folder) { $row = db_select_first("simple_sys_tree", array("id", "rgt", "lft", "ftitle", "parent"), "id=@id@", "", array("id" => $folder)); $rows = array(); if (!empty($row["id"])) { $rows = db_select("simple_sys_tree", array("id", "ftype"), "lft between @left@ and @right@", "lft asc", "", array("left" => $row["lft"], "right" => $row["rgt"])); } if (!is_array($rows) or count($rows) == 0) { return ""; } if (!folder_in_trash($folder)) { $trash = db_select_value("simple_sys_tree", "id", "anchor=@anchor@", array("anchor" => "trash")); if (empty($trash)) { exit("{t}Error{/t}: {t}Trash folder not found.{/t}"); } $id = self::create(sys_date("{t}m/d/Y{/t}"), "blank", "", $trash, true); $old_path = modify::getpath($folder); if (!self::move($row["id"], $id, true)) { exit("{t}The folder cannot be deleted.{/t}"); } $data = array("rread_users" => "", "rread_groups" => "", "rwrite_users" => "", "rwrite_groups" => "", "radmin_users" => "", "radmin_groups" => "", "rexception_users" => "", "rexception_groups" => "", "anchor" => ""); $data["history"] = sprintf("{t}Item deleted by %s at %s{/t}\n", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}")); foreach ($rows as $folder) { db_update("simple_sys_tree", $data, array("id=@id@"), array("id" => $folder["id"])); } db_update("simple_sys_tree", array("history" => "{t}Origin{/t}: " . $old_path . "\n"), array("id=@id@"), array("id" => $rows[0]["id"])); sys_log_stat("deleted_folders", count($rows)); } else { foreach ($rows as $folder) { if ($folder["ftype"] != "sys_tree") { $schema_data = db_get_schema(sys_find_module($folder["ftype"])); $tname = $schema_data["att"]["NAME"]; if (!strpos($tname, "_nodb_")) { $delete_fields = array(); foreach ($schema_data["fields"] as $key => $field) { if ($field["SIMPLE_TYPE"] == "files") { $delete_fields[] = $key; } } if (count($delete_fields) > 0) { $data = db_select($tname, $delete_fields, "folder=@folder@", "created asc", "", array("folder" => $folder["id"])); if (is_array($data) and count($data) > 0) { foreach ($data as $ditem) { foreach ($delete_fields as $field) { $files = explode("|", $ditem[$field]); sys_unlink($files); } } } } db_delete($tname, array("folder=@folder@"), array("folder" => $folder["id"])); } } db_search_delete("simple_sys_tree", $folder["id"], $folder["id"]); db_search_delete_folder($folder["id"]); db_delete("simple_sys_tree", array("id=@id@"), array("id" => $folder["id"])); } db_update_subfolder_count($row["parent"]); } $folder = $row["id"]; if (isset($_SESSION["folder_states"][$folder])) { foreach ($_SESSION["folder_states"][$folder] as $child) { unset($_SESSION["folder_states"][$child]); } unset($_SESSION["folder_states"][$folder]); } return $row["parent"]; }
set_error_handler("debug_handler"); if (empty($_SERVER["SERVER_ADDR"])) { $_SERVER["SERVER_ADDR"] = "127.0.0.1"; } if (!isset($_SERVER["HTTP_USER_AGENT"])) { $_SERVER["HTTP_USER_AGENT"] = "mozilla/5 rv:1.4"; } if (!isset($_SERVER["SERVER_SOFTWARE"])) { $_SERVER["SERVER_SOFTWARE"] = "Apache"; } browser_detect(); sys::init(); if (!defined("NOCONTENT")) { folder_process_session_request(); folder_build_folders(); $GLOBALS["table"] = db_get_schema($GLOBALS["schemafile"], $GLOBALS["tfolder"], $GLOBALS["tview"], true, !empty($_REQUEST["popup"])); $GLOBALS["tname"] = $GLOBALS["table"]["att"]["NAME"]; if (!empty($GLOBALS["table"]["att"]["LOAD_LIBRARY"])) { require $GLOBALS["table"]["att"]["LOAD_LIBRARY"]; } sys_process_session_request(); if (!empty($GLOBALS["current_view"]["ENABLE_CALENDAR"])) { date::process_session_request(); $session = $_SESSION[$GLOBALS["tname"]]["_" . $GLOBALS["tfolder"]]; date::build_datebox($session["today"], $session["markdate"], $session["weekstart"]); } asset_process_session_request(); if (!empty($GLOBALS["current_view"]["ENABLE_CALENDAR"]) and (empty($_REQUEST["iframe"]) or $_REQUEST["iframe"] == "2")) { date::build_views(); } $output = ob_get_contents();
function __construct($folder, $view, $items = array(), $writeable = true) { // Mountpoint $folders = array($folder); if (!is_numeric($folder)) { $url = sys_parse_folder($folder); $type = "sys_nodb_" . $url["handler"]; $mfolder = $url["mfolder"]; sys_credentials($mfolder); } else { $row = db_select_first("simple_sys_tree", array("ftype", "folders"), "id=@id@", "", array("id" => $folder)); if (empty($row["ftype"])) { throw new Exception("{t}Folder not found.{/t}"); } $type = $row["ftype"]; if ($row["folders"] != "") { $folders = array(); foreach (explode("|", trim($row["folders"], "|")) as $val) { if (empty($val) or !db_get_right($val, $writeable ? "write" : "read", $view)) { continue; } $folders[] = $val; } } $mfolder = ""; } if (isset($_SESSION["disabled_modules"][$type])) { exit("{t}Module disabled.{/t}"); } $this->schema = db_get_schema(sys_find_module($type), $folder, $view); $view = sys_array_shift(array_keys($this->schema["views"])); $this->current_view =& $this->schema["views"][$view]; if (isset($this->current_view["SCHEMA"]) and $this->current_view["SCHEMA"] != "") { $this->schema = db_get_schema(sys_find_module($this->current_view["SCHEMA"]), "", $view); $view = sys_array_shift(array_keys($this->schema["views"])); $this->current_view =& $this->schema["views"][$view]; } $this->folder = $folder; $this->view = $view; $this->fields =& $this->schema["fields"]; $this->att =& $this->schema["att"]; $this->tname = $this->att["NAME"]; $this->where = $this->current_view["SQLWHERE"]; $this->handler = $this->current_view["SQL_HANDLER"]; $this->buttons = $this->current_view["buttons"]; $this->rowvalidates = $this->current_view["rowvalidates"]; $this->rowfilters = $this->current_view["rowfilters"]; $this->current_fields =& $this->current_view["fields"]; $this->notification = true; $this->vars = array("item" => $items, "folder" => $this->folder, "folders" => $folders, "mfolder" => $mfolder); $this->vars_noquote = array(); if (!empty($this->att["ENABLE_ASSET_RIGHTS"])) { if ($writeable) { $this->where[] = "@permission_sql_write_nq@"; } $this->vars_noquote["permission_sql_read_nq"] = $_SESSION["permission_sql_read"]; $this->vars_noquote["permission_sql_write_nq"] = $_SESSION["permission_sql_write"]; } if (is_array($this->where) and count($this->where) > 0) { foreach ($this->where as $key => $val) { $matches = array(); if (!preg_match_all("|@(.*?)@|i", $val, $matches, PREG_SET_ORDER)) { continue; } foreach ($matches as $match) { if (count($match) != 2) { continue; } $wkey = $match[1]; if (empty($this->vars[$wkey]) and empty($this->vars_noquote[$wkey])) { $this->where[$key] = "1=1"; } } } } }
$link = file($target_lnk); $match = array(); if (preg_match("|^/sgdav/(.+)/(\\d+)_0__.+|", $link[0], $match)) { $_REQUEST["folder"] = "/" . $match[1] . "/"; $_REQUEST["item"] = array($match[2]); } } else { $db_path = substr($path, strlen("/sgdav")); _upload_create_file($db_path, $target_lnk, $path, $filename); } } } // TODO use sgsml class folder_process_session_request(); folder_build_folders(); $GLOBALS["table"] = db_get_schema($GLOBALS["schemafile"], $GLOBALS["tfolder"], $GLOBALS["tview"]); $GLOBALS["tname"] = $GLOBALS["table"]["att"]["NAME"]; sys_process_session_request(); if (empty($_REQUEST["field"])) { $field = "filedata"; } else { $field = ltrim($_REQUEST["field"], "_"); } $field = sql_fieldname($field); if ($content_length > _upload_get_limit($field)) { sys_error(trans("{t}Upload failed{/t}: {t}file is too big. Please upload a smaller one.{/t} ({t}insufficient folder rights{/t})"), "409 Conflict"); } $t =& $GLOBALS["t"]; $t["sqlvars"]["item"] = $_REQUEST["item"]; $t["sqlvarsnoquote"]["permission_sql_read_nq"] = $_SESSION["permission_sql_write"]; $t["sqlvarsnoquote"]["permission_sql_write_nq"] = $_SESSION["permission_sql_write"];