Esempio n. 1
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $type = $path;
     $filename = sys_find_module($type);
     $custom_schema = "";
     if (!file_exists($filename)) {
         if (!is_numeric($path)) {
             $type = "sys_nodb_" . $vars["handler"];
         } else {
             $row = db_select_first("simple_sys_tree", array("ftype", "folders"), "id=@id@", "", array("id" => $path));
             if (empty($row["ftype"])) {
                 throw new Exception("{t}Folder not found.{/t}");
             }
             $type = $row["ftype"];
         }
         $filename = sys_find_module($type);
         $custom_schema = db_select_value("simple_sys_tree", "custom_schema", "id=@id@", array("id" => $path));
     }
     // TODO optimize
     $rows = db_select("simple_sys_custom_fields", array("custom_schema"), array("module=@schema@", "(ffolder='' or ffolder like @folder@)", "activated=1"), "", "", array("schema" => $type, "folder" => "%|" . $path . "|%"));
     if (is_array($rows) and count($rows) > 0) {
         $custom_schema = str_replace("</table>", "", $custom_schema);
         if (!strpos($custom_schema, "<table")) {
             $custom_schema = "<table>";
         }
         foreach ($rows as $row) {
             $custom_schema .= $row["custom_schema"];
         }
         $custom_schema .= "</table>";
     }
     return array(array("id" => $filename, "filename" => $filename, "filemtime" => filemtime($filename), "filecontent" => sgsml_parser::file_get_contents($filename, $type, $custom_schema)));
 }
Esempio n. 2
0
 static function ajax_store_vote($folder, $votes)
 {
     self::_require_access($folder, "read");
     if (empty($votes) or !is_array($votes)) {
         return "";
     }
     foreach ($votes as $qid => $vote_elems) {
         if (!is_array($vote_elems) or implode("", $vote_elems) == "") {
             continue;
         }
         $row = db_select_first("simple_surveys", "answers,votedby", "id=@id@", "", array("id" => $qid));
         if (empty($row)) {
             continue;
         }
         $answers = json_decode($row["answers"], true);
         $votedby = json_decode($row["votedby"], true);
         $id = self::_get_voter_id();
         if (isset($votedby[$id])) {
             exit("{t}Already voted.{/t} (" . $qid . ")");
         }
         foreach ($vote_elems as $vote_elem) {
             if ($vote_elem == "") {
                 continue;
             }
             if (!isset($answers[$vote_elem])) {
                 $answers[$vote_elem] = 0;
             }
             $answers[$vote_elem]++;
         }
         $votedby[$id] = 0;
         db_update("simple_surveys", array("votedby" => json_encode($votedby), "answers" => json_encode($answers)), array("id=@id@"), array("id" => $qid));
     }
     return $folder;
 }
Esempio n. 3
0
 static function icalendar_data($data = array())
 {
     $output = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Simple Groupware and CMS//iCalendar 2.0//EN\nMETHOD:REQUEST\n";
     $data = self::_build_data(false, $data, false, false, true);
     if (count($data) == 0) {
         $output .= "BEGIN:VEVENT\nDTSTART:" . sys_date("Ymd\\THis") . "\n";
         $output .= "DURATION:PT1H\nSUMMARY:{t}No entries found.{/t}\nEND:VEVENT\n";
     } else {
         $url = self::_url_folder();
         foreach ($data as $asset) {
             $output .= "BEGIN:VEVENT\n";
             if (!empty($asset["begin"]["data"])) {
                 $begin = $asset["begin"]["data"];
             } else {
                 $begin = $asset["created"]["data"];
             }
             if (!empty($asset["ending"]["data"])) {
                 $end = $asset["ending"]["data"];
             } else {
                 $end = $begin + 3600;
             }
             if (!isset($asset["subject"]["filter"])) {
                 $subject = "";
                 foreach ($asset as $aval) {
                     if ($aval["type"] == "text" and $aval["filter"] != "") {
                         $subject .= $aval["filter"] . " ";
                     }
                 }
                 $subject .= "[" . $asset["_id"]["data"] . "]";
             } else {
                 $subject = $asset["subject"]["filter"];
             }
             if (isset($asset["description"]["filter"])) {
                 $description = $asset["description"]["filter"];
             } else {
                 $description = "";
             }
             if (!empty($asset["recurrence"]["data"])) {
                 $recurrence = $asset["recurrence"]["data"];
             } else {
                 $recurrence = "";
             }
             if (!empty($asset["repeatinterval"]["data"])) {
                 $repeatinterval = $asset["repeatinterval"]["data"];
             } else {
                 $repeatinterval = 1;
             }
             if (!empty($asset["repeatcount"]["data"])) {
                 $repeatcount = $asset["repeatcount"]["data"];
             } else {
                 $repeatcount = 0;
             }
             if (!empty($asset["repeatuntil"]["data"])) {
                 $repeatuntil = $asset["repeatuntil"]["data"];
             } else {
                 $repeatuntil = 0;
             }
             if (!empty($asset["repeatexcludes"]["data"])) {
                 $excludes = (array) $asset["repeatexcludes"]["data"];
             } else {
                 $excludes = array();
             }
             $filter = array("LOCATION" => "location", "CATEGORIES" => "category");
             foreach ($filter as $key => $field) {
                 if (!empty($asset[$field]["filter"])) {
                     $filter[$key] = $asset[$field]["filter"];
                 } else {
                     $filter[$key] = "";
                 }
             }
             if (!is_array($asset["created"]["data"])) {
                 $output .= "DTSTAMP:" . sys_date("Ymd\\THis", $asset["created"]["data"]) . "\n";
             }
             if (!is_array($asset["lastmodified"]["data"])) {
                 $output .= "LAST-MODIFIED:" . sys_date("Ymd\\THis", $asset["lastmodified"]["data"]) . "\n";
             }
             $uid = is_numeric($asset["_id"]["data"]) ? $asset["_id"]["data"] : md5($asset["_id"]["data"]);
             $output .= "UID:" . $uid . "@" . $_SERVER["SERVER_NAME"] . "\n";
             $output .= "URL;VALUE=URI:" . $url . "&item%5B%5D=" . $asset["_id"]["data"] . "\n";
             if (!empty($asset["allday"]["data"]) and $asset["allday"]["data"] == 1) {
                 $output .= "DTSTART;VALUE=DATE:" . sys_date("Ymd", $begin) . "\n";
                 $output .= "DTEND;VALUE=DATE:" . sys_date("Ymd", $end + 60) . "\n";
             } else {
                 $output .= "DTSTART:" . sys_date("Ymd\\THis", $begin) . "\n";
                 $output .= "DTEND:" . sys_date("Ymd\\THis", $end) . "\n";
             }
             $output .= "SUMMARY:" . self::_icalendar_quote($subject) . "\n";
             if ($description) {
                 $output .= "DESCRIPTION:" . self::_icalendar_quote($description) . "\n";
             }
             $attendees = array();
             if (!empty($asset["organizer"]["data"])) {
                 $row = db_select_first("simple_sys_users", array("firstname", "lastname", "email"), "username=@username@", "", array("username" => $asset["organizer"]["data"]));
                 if (!empty($row["email"])) {
                     $attendees[] = array("ORGANIZER", $row["firstname"] . " " . $row["lastname"], $row["email"]);
                 }
             }
             if (!empty($asset["participants"]["data"])) {
                 $rows = db_select("simple_sys_users", array("firstname", "lastname", "email"), "username in (@username@)", "", "", array("username" => $asset["participants"]["data"]));
                 if (is_array($rows) and count($rows) > 0) {
                     foreach ($rows as $row) {
                         $attendees[] = array("ATTENDEE", $row["firstname"] . " " . $row["lastname"], $row["email"]);
                     }
                 }
             }
             if (!empty($asset["participants_ext"]["data"])) {
                 $rows = db_select("simple_contacts", array("firstname", "lastname", "email", "company"), "contactid in (@ids@)", "", "", array("ids" => $asset["participants_ext"]["data"]));
                 if (is_array($rows) and count($rows) > 0) {
                     foreach ($rows as $row) {
                         $attendees[] = array("ATTENDEE", $row["firstname"] . " " . $row["lastname"] . " " . $row["company"], $row["email"]);
                     }
                 }
             }
             foreach ($attendees as $data) {
                 $output .= $data[0] . ";ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;CN=" . self::_icalendar_quote($data[1]) . ":MAILTO:" . self::_icalendar_quote($data[2]) . "\n";
             }
             foreach ($filter as $key => $field) {
                 if ($field) {
                     $output .= $key . ":" . self::_icalendar_quote($field) . "\n";
                 }
             }
             if ($recurrence) {
                 switch ($recurrence) {
                     case "years":
                         $recurrence = "YEARLY";
                         break;
                     case "months":
                         $recurrence = "MONTHLY";
                         break;
                     case "weeks":
                         $recurrence = "WEEKLY";
                         break;
                     case "days":
                         $recurrence = "DAILY";
                         break;
                 }
                 $output .= "RRULE:FREQ=" . $recurrence . ";INTERVAL=" . $repeatinterval;
                 if ($repeatcount != 0) {
                     $output .= ";COUNT=" . $repeatcount;
                 }
                 if ($repeatuntil != 0) {
                     $output .= ";UNTIL=" . sys_date("Ymd", $repeatuntil) . "T235900";
                 }
                 $output .= "\n";
                 if (count($excludes) > 0) {
                     foreach ($excludes as $key => $val) {
                         $excludes[$key] = sys_date("Ymd", $val);
                     }
                     $output .= "EXDATE;VALUE=DATE:" . implode(",", $excludes) . "\n";
                 }
             }
             $output .= "END:VEVENT\n";
             // TODO2 code / test
             /*
               PRIORITY:[0..9]
               <field name="priority" displayname="{t}Priority{/t}" simple_type="select" simple_size="1" simple_default="3">
               ATTACH;FMTTYPE=application/binary:http://host.com/templates/agenda.doc
               <field name="image" displayname="{t}Image{/t}" simple_type="files" simple_file_size="1M" simple_size="1">
               <field name="attachment" displayname="{t}Attachment{/t}" simple_type="files" simple_file_size="2M" simple_size="1">
             */
         }
     }
     return $output . "END:VCALENDAR\n";
 }
Esempio n. 4
0
 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 "";
 }
Esempio n. 5
0
 public static function import_createedit($tfolder, $module, $username, $lastsync, $fields)
 {
     $table_source = "fnbl_simple_" . $module . "_imp";
     $table_dest = "simple_" . $module;
     $sys_date = date("Y-m-d H:i:s");
     $db_date = sgsml_parser::sql_date();
     if (abs(strtotime($sys_date) - strtotime($db_date)) > 60) {
         sys_warning("{t}Error{/t}: {t}current time{/t} {t}System{/t}: " . $sys_date . " {t}Database{/t}: " . $db_date);
     }
     if (DEBUG) {
         echo "Sync4j: " . $table_source . " lastmodified > " . $lastsync . " " . date("c", $lastsync);
     }
     $count_insert = 0;
     $count_update = 0;
     $rows = db_select($table_source, "*", array("userid=@username@", "lastmodified > @lastmodified@"), "", "", array("username" => $username, "lastmodified" => $lastsync - 600));
     if (is_array($rows) and count($rows) > 0) {
         foreach ($rows as $row) {
             if ($row["status"] == "D") {
                 // delete
                 self::_import_delete($tfolder, $row["syncid"], $table_dest, $module);
                 continue;
             }
             unset($row["userid"]);
             unset($row["status"]);
             if ($table_dest == "simple_contacts" and empty($row["contactid"])) {
                 continue;
             }
             if ($table_dest == "simple_tasks") {
                 if (empty($row["begin"]) and empty($row["ending"])) {
                     continue;
                 }
                 if (empty($row["begin"])) {
                     $row["begin"] = $row["ending"];
                 }
             }
             $exists = db_select_value($table_dest, "id", "syncid=@id@", array("id" => $row["syncid"]));
             if (!empty($exists)) {
                 $id = $exists;
             } else {
                 $id = 0;
             }
             if ($id != 0) {
                 // update
                 $row["history"] = sprintf("{t}Item edited (%s) by %s at %s{/t} (sync)\n", "@fields@", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}"));
                 $cdata = "";
                 $data = $row;
                 $cfields = array();
                 $data_old = db_select_first($table_dest, "*", "id=@id@", "", array("id" => $id));
                 if (!empty($data_old["id"])) {
                     if ($row["lastmodified"] == $data_old["lastmodified"]) {
                         continue;
                     }
                     foreach ($data as $key => $val) {
                         if (isset($data_old[$key]) and $key != "history") {
                             if ($data_old[$key] != $val) {
                                 if (trim($val) != "") {
                                     $cdata .= $key . ": " . $val . "\n";
                                 }
                                 $cfields[] = $key;
                             } else {
                                 unset($data[$key]);
                             }
                         }
                     }
                 }
                 if (count($data) < 3) {
                     continue;
                 }
                 $data["history"] = str_replace("@fields@", implode(", ", $cfields), $data["history"]) . $cdata . "\n";
                 if (DEBUG) {
                     print_r($data);
                 }
                 $error_sql = db_update($table_dest, $data, array("id=@id@"), array("id" => $id));
                 $count_update++;
             } else {
                 // new
                 $id = sql_genID($table_dest) * 100;
                 $row["id"] = $id;
                 $row["folder"] = $tfolder;
                 $row["dsize"] = 0;
                 $row["history"] = sprintf("{t}Item created by %s at %s{/t} (sync)\n", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}"));
                 if (DEBUG) {
                     print_r($row);
                 }
                 $error_sql = db_insert($table_dest, $row);
                 $count_insert++;
             }
             if ($error_sql == "") {
                 if ($module == "calendar") {
                     trigger::calcappointment($id, $row, false, "simple_calendar");
                 }
                 if ($module == "tasks") {
                     trigger::duration($id, $row, false, "simple_tasks");
                 }
                 trigger::notify($id, $row, array(), "simple_" . $module);
                 db_search_update($table_dest, $id, $fields);
                 if ($count_insert > 0) {
                     sys_log_stat("new_records", $count_insert);
                 }
                 if ($count_update > 0) {
                     sys_log_stat("changed_records", $count_update);
                 }
             }
         }
     }
     db_update_treesize($table_dest, $tfolder);
     return "";
 }
Esempio n. 6
0
function sys_log_message($component, $message, $message_trace, $username, $forcedb, $time = 0)
{
    if ($username == "") {
        if (isset($_SESSION["username"])) {
            $username = $_SESSION["username"];
        } else {
            $username = "******";
        }
    }
    if (USE_SYSLOG_FUNCTION) {
        syslog(LOG_WARNING, $_SERVER["SERVER_NAME"] . " (" . $_SERVER["SERVER_ADDR"] . ") " . $component . ", user: "******"\r\n" . $message . "\r\n" . $message_trace . "\r\n");
        return;
    }
    if ($forcedb and defined("SETUP_DB_HOST") and !empty(sys::$db) and (is_resource(sys::$db) or is_object(sys::$db))) {
        $id = sql_genID("simple_sys_events") * 100;
        $row = db_select_first("simple_sys_tree", "id", "ftype=@ftype@", "lft asc", array("ftype" => "sys_events"));
        if (!empty($row["id"])) {
            $error_sql = db_insert("simple_sys_events", array("created" => $time, "servername" => $_SERVER["SERVER_NAME"], "serverip" => $_SERVER["SERVER_ADDR"], "username" => $username, "id" => $id, "component" => $component, "message" => $message, "message_trace" => $message_trace));
            if ($error_sql == "") {
                db_search_update("simple_sys_events", $id, array(), array("created" => "datetime", "component" => "text", "message" => "text", "username" => "text", "serverip" => "text", "servername" => "text"));
            } else {
                echo q($message) . "<br>" . $error_sql . "<br>";
            }
        }
    } else {
        $out = serialize(array($component, str_replace(array("\n", "\r"), "", $message), str_replace(array("\n", "\r"), "", nl2br($message_trace)), $username, NOW));
        // current directory is changed in destructor
        chdir(dirname(__FILE__) . "/../../");
        if (sys_file_append(SIMPLE_CACHE . "/debug/error.txt", $out . "\r\n")) {
            return;
        }
        $message = $_SERVER["SERVER_NAME"] . " (" . $_SERVER["SERVER_ADDR"] . ") " . $component . ", user: "******"\r\n" . $message . "\r\n" . $message_trace . "\r\n";
        echo $message . $message_trace;
        echo q($message);
        @error_log($message, 3, SIMPLE_CACHE . "/debug/php_error.log");
    }
}
Esempio n. 7
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));
         }
     }
 }
Esempio n. 8
0
 private static function _tree_open_session($item)
 {
     if (is_numeric($item)) {
         $where = array("id=@id@", $_SESSION["permission_sql_read"]);
         $item_arr = db_select_first("simple_sys_tree", array("id", "lft", "rgt"), $where, "lft asc", array("id" => $item));
     } else {
         $item_arr = array("id" => $item);
     }
     if (empty($item_arr["id"])) {
         return false;
     }
     $_SESSION["folder_states"][$item] = array(1);
     $parents = db_get_parents($item_arr);
     if (is_array($parents) and count($parents) > 0) {
         foreach ($parents as $parent) {
             $id = $parent["id"];
             if (!isset($_SESSION["folder_states"][$id]) or !in_array($item, $_SESSION["folder_states"][$id])) {
                 $_SESSION["folder_states"][$id][] = $item;
             }
         }
     }
     self::session_save();
     return true;
 }
Esempio n. 9
0
 public static function moveupdown($fmoveupdown, $path)
 {
     db_lock_tree(true);
     $row = db_select_first("simple_sys_tree", array("id", "lft", "rgt", "flevel", "parent"), "id=@id@", "", array("id" => $path));
     if (isset($row["lft"])) {
         if ($fmoveupdown == "up") {
             $lower = $row;
             $upper = db_select_first("simple_sys_tree", array("id", "lft", "rgt"), array("parent=@row_parent@", "lft<@row_lft@"), "lft desc", array("row_parent" => $row["parent"], "row_lft" => $row["lft"]));
         }
         if ($fmoveupdown == "down") {
             $upper = $row;
             $lower = db_select_first("simple_sys_tree", array("id", "lft", "rgt"), array("parent=@row_parent@", "lft>@row_rgt@"), "lft asc", array("row_parent" => $row["parent"], "row_rgt" => $row["rgt"]));
         }
         if (isset($lower["lft"]) and isset($upper["lft"])) {
             $distance = $lower["lft"] - $upper["lft"];
             $distance2 = $lower["rgt"] - $upper["rgt"];
             $lowers = db_select("simple_sys_tree", "id", "lft between @lft@ and @rgt@", "lft desc", "", array("lft" => $lower["lft"], "rgt" => $lower["rgt"]));
             $uppers = db_select("simple_sys_tree", "id", "lft between @lft@ and @rgt@", "lft desc", "", array("lft" => $upper["lft"], "rgt" => $upper["rgt"]));
             if (is_numeric($distance) and $distance != 0 and is_array($lowers) and count($lowers) > 0) {
                 foreach ($lowers as $lowers_item) {
                     db_update("simple_sys_tree", array("lft" => "lft-" . $distance, "rgt" => "rgt-" . $distance), array("id=@id@"), array("id" => $lowers_item["id"]), array("quote" => false, "no_defaults" => true));
                 }
             }
             if (is_numeric($distance2) and $distance2 != 0 and is_array($uppers) and count($uppers) > 0) {
                 foreach ($uppers as $uppers_item) {
                     db_update("simple_sys_tree", array("lft" => "lft+" . $distance2, "rgt" => "rgt+" . $distance2), array("id=@id@"), array("id" => $uppers_item["id"]), array("quote" => false, "no_defaults" => true));
                 }
             }
         }
     }
     db_lock_tree(false);
 }
Esempio n. 10
0
 out("sending mails:\n");
 foreach ($notifications as $notification) {
     $smtp_data = array("efrom" => "", "eto" => $notification["eto"], "subject" => $notification["subject"], "message" => trim($notification["message"]), "attachment" => $notification["attachment"], "folder" => "cron");
     $result = asset_process_trigger("sendmail", "", $smtp_data);
     if ($result != "") {
         echo "ERROR " . $notification["eto"] . ": " . $result . "\n";
         sys_log_message_log("php-fail", $result, var_export($smtp_data, true));
         db_update("simple_sys_notifications", array("error" => $result), array("id=@id@"), array("id" => $notification["id"]));
     } else {
         $data = array("error" => "");
         if (!empty($notification["recurrence"])) {
             if ($notification["recurrence"][0] == "|") {
                 $match = array();
                 preg_match("/([^\\|]+)\\|([^&]+)/", $notification["reference"], $match);
                 if (!empty($match) and count($match) == 3) {
                     $row = db_select_first($match[1], "*", "id=@id@", "", array("id" => $match[2]));
                     if (!empty($row)) {
                         trigger::notify($match[2], $row, array(), $match[1]);
                     }
                 }
             } else {
                 $counter = 0;
                 $data["delivery"] = $notification["delivery"];
                 while ($data["delivery"] < NOW and $counter < 150) {
                     $data["delivery"] = strtotime($notification["recurrence"], $data["delivery"]);
                     $counter++;
                 }
             }
         } else {
             $data["sent"] = "1";
         }
Esempio n. 11
0
 static function sendmail_getconn($username, $efrom)
 {
     $concat = sql_concat("concat(firstname;' ';lastname)");
     if ($efrom != "") {
         $row = db_select_first("simple_sys_identities", array("smtp", "email", "name"), array("email=@email@", "users like @username_sql@"), "", array("username_sql" => "%|" . $username . "|%", "email" => $efrom));
         if (empty($row["smtp"]) and !USE_MAIL_FUNCTION) {
             $row["smtp"] = db_select_value("simple_sys_users", "smtp", "username=@username@", array("username" => $username));
         }
     } else {
         $row = db_select_first("simple_sys_users", array("smtp", "email", "{$concat} as name"), "username=@username@", "", array("username" => $username));
         if (empty($row["smtp"]) and !USE_MAIL_FUNCTION) {
             $row = db_select_first("simple_sys_identities", array("smtp", "email", "name"), "users like @username_sql@", "", array("username_sql" => "%|" . $username . "|%"));
         }
     }
     return $row;
 }
Esempio n. 12
0
 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";
                 }
             }
         }
     }
 }
Esempio n. 13
0
$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"];
$row = db_select_first($GLOBALS["tname"], array_unique(array($field, "folder", "id", "dsize")), $t["sqlwhere"], "", $t["sqlvars"], array("sqlvarsnoquote" => $t["sqlvarsnoquote"]));
if (empty($row["folder"])) {
    sys_error(t("{t}file not found in database.{/t}"));
}
if (!db_get_right($row["folder"], "write")) {
    sys_error(trans("{t}Access to this file has been denied.{/t} ({t}insufficient folder rights{/t})"), "403 Forbidden");
}
if (empty($row[$field])) {
    $row[$field] = "";
}
$row_filename = $row[$field];
if ($row_filename != "") {
    $file = explode("|", trim($row[$field], "|"));
    if (empty($_REQUEST["subitem"])) {
        $_REQUEST["subitem"] = 0;
    }
Esempio n. 14
0
 static function getpathfull($folder, $workspace = false, $spacer = " / ")
 {
     static $cache = array();
     if ($folder == "") {
         return "";
     }
     $cid = $folder . $workspace . $spacer;
     if (isset($cache[$cid])) {
         return $cache[$cid];
     }
     if (is_numeric($folder)) {
         $sel_folder = db_select_first("simple_sys_tree", array("id", "rgt", "lft", "ftitle"), "id=@id@", "", array("id" => $folder));
         if (empty($sel_folder["id"])) {
             return $folder;
         }
     } else {
         $sel_folder = array("id" => $folder, "ftitle" => basename($folder));
     }
     $parents = db_get_parents($sel_folder);
     if (!is_array($parents) or count($parents) == 0) {
         if (!is_numeric($folder)) {
             return substr($folder, strpos($folder, "/") + 1);
         } else {
             return $spacer . $sel_folder["ftitle"];
         }
     }
     $result = "";
     if ($workspace) {
         array_shift($parents);
     }
     foreach ($parents as $parent) {
         $result .= $spacer . $parent["ftitle"];
     }
     $cache[$cid] = $result . $spacer . $sel_folder["ftitle"];
     return $cache[$cid];
 }