Esempio n. 1
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $path = rtrim($path, "/");
     $datas = self::_get_data($path);
     $rows = array();
     $i = 0;
     foreach ($datas as $data) {
         $i++;
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 case "id":
                     $row[$field] = $path . "/?" . $i;
                     break;
                 case "sort":
                     $row[$field] = $i;
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "created":
                     $row[$field] = 0;
                     break;
                 case "lastmodified":
                     $row[$field] = 0;
                     break;
                 case "lastmodifiedby":
                     $row[$field] = "";
                     break;
                 case "searchcontent":
                     $row[$field] = implode(" ", $data);
                     break;
                 default:
                     if (isset($data[$field])) {
                         $row[$field] = $data[$field];
                     } else {
                         $row[$field] = "";
                     }
                     break;
             }
         }
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     //  $order = str_replace("category","",$order);
     $rows = sys_select($rows, $order, $limit, $fields);
     return $rows;
 }
Esempio n. 2
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $rows = array();
     $modules = select::modules();
     asort($modules);
     foreach ($modules as $module => $name) {
         if ($name[0] == " ") {
             continue;
         }
         $file = sys_find_module($module);
         $row = array("id" => $file, "name" => $name, "modulename" => $module, "created" => @filectime($file), "lastmodified" => @filemtime($file), "lastmodifiedby" => "", "searchcontent" => $file, "filename" => $file, "filemtime" => @filemtime($file), "filectime" => @filectime($file), "filesize" => @filesize($file), "filecontent" => "");
         if (sys_select_where($row, $where, $vars)) {
             $rows[$file] = $row;
         }
     }
     return sys_select($rows, $order, $limit, $fields);
 }
Esempio n. 3
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $path = rtrim($path, "/");
     $datas = self::_parse($path);
     $rows = array();
     foreach ($datas as $data) {
         if (empty($data["title"])) {
             continue;
         }
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 case "id":
                     $row[$field] = $path . "/?" . md5($data["link"]);
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "created":
                     $row[$field] = 0;
                     break;
                 case "lastmodifiedby":
                     $row[$field] = "";
                     break;
                 case "searchcontent":
                     $row[$field] = implode(" ", $data);
                     break;
                 default:
                     $row[$field] = "";
                     if (isset($data[$field])) {
                         $row[$field] = trim(preg_replace("/<img[^>]+>/i", "", $data[$field]));
                     }
                     break;
             }
         }
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     $rows = sys_select($rows, $order, $limit, $fields);
     return $rows;
 }
Esempio n. 4
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $path = rtrim($path, "/");
     $datas = self::_parse($path);
     $rows = array();
     $i = 0;
     foreach ($datas as $data) {
         $i++;
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 case "id":
                     $row[$field] = $path . "/?" . $i;
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "searchcontent":
                     $row[$field] = implode(" ", $data);
                     break;
                 case "lastmodifiedby":
                     $row[$field] = "";
                     break;
                 default:
                     if (isset($data[$field])) {
                         $row[$field] = $data[$field];
                     } else {
                         $row[$field] = "";
                     }
                     break;
             }
         }
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     // fix for missing sql filtering
     $limit = array(0, count($rows));
     $rows = sys_select($rows, $order, $limit, $fields);
     return $rows;
 }
Esempio n. 5
0
 static function select($folder, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $tname = "simple_sys_stats";
     $today = $_SESSION[$tname]["_" . $folder]["today"];
     $today_arr = sys_getdate($today);
     $weekdays = array("{t}Su{/t}", "{t}Mo{/t}", "{t}Tu{/t}", "{t}We{/t}", "{t}Th{/t}", "{t}Fr{/t}", "{t}Sa{/t}");
     $weekstart = $_SESSION[$tname]["_" . $folder]["weekstart"];
     $t_today = date::$today;
     $t_then = date::$then;
     $s_today = $t_today;
     $s_then = $t_then;
     if ($_SESSION[$tname]["_" . $folder]["markdate"] == "day") {
         $dstrings = array(sys_date("Y_M_d", $today), 24, "loghour");
         $labels = range(1, 24);
     } else {
         if ($_SESSION[$tname]["_" . $folder]["markdate"] == "week") {
             $dstrings = array(sys_date("Y_W_", $today) . $_SESSION[$tname]["_" . $folder]["weekstart"], 28, "logweekpart");
             $labels = array($weekdays[$weekstart], "", "", "", $weekdays[($weekstart + 1) % 7], "", "", "", $weekdays[($weekstart + 2) % 7], "", "", "", $weekdays[($weekstart + 3) % 7], "", "", "", $weekdays[($weekstart + 4) % 7], "", "", "", $weekdays[($weekstart + 5) % 7], "", "", "", $weekdays[($weekstart + 6) % 7], "", "", "");
         } else {
             if ($_SESSION[$tname]["_" . $folder]["markdate"] == "month") {
                 $s_today = mktime(0, 0, 0, $today_arr["mon"], 1, $today_arr["year"]);
                 $s_then = strtotime("+1 month -1 day", $s_today);
                 $dstrings = array(sys_date("Y_M", $today), 31, "logday");
                 $labels = range(1, 31);
             } else {
                 $s_today = mktime(0, 0, 0, 1, 1, $today_arr["year"]);
                 $s_then = mktime(0, 0, 0, 12, 31, $today_arr["year"]);
                 $dstrings = array(sys_date("Y", $today), 52, "logweek");
                 $labels = range(1, 52);
             }
         }
     }
     if ($t_today != "" and $t_today != $s_today) {
         foreach ($where as $key => $val) {
             if (strpos($val, (string) $t_today)) {
                 $where[$key] = str_replace(array($t_today, $t_then), array($s_today, $s_then), $val);
             }
         }
     }
     $rows = array();
     if (in_array("id in (@item@)", $where)) {
         unset($where[array_search("id in (@item@)", $where)]);
     }
     $rows2 = db_select("simple_sys_stats", array("action", $dstrings[2] . " as id", "sum(weight) as weight"), $where, "", "", $vars, array("groupby" => "action, " . $dstrings[2]));
     $data_all = array("logins" => array(), "pages" => array(), "downloads" => array());
     if (is_array($rows2) and count($rows2) > 0) {
         foreach ($rows2 as $row) {
             if (!isset($data_all[$row["action"]]) or count($data_all[$row["action"]]) == 0) {
                 $data_all[$row["action"]] = array_fill(0, $dstrings[1], "");
             }
             $data_all[$row["action"]][$row["id"] - 1] = $row["weight"];
         }
     }
     if (count($data_all) > 0) {
         foreach ($data_all as $stat => $data) {
             if (count($data) == 0) {
                 continue;
             }
             $id = md5($_SESSION["style"] . $stat . $dstrings[0]);
             $stat = str_replace("_", " ", ucfirst($stat));
             $filename = "preview.php?type=bar&stat=" . $stat . "&style=" . $_SESSION["style"] . "&width=550&height=175&data=" . implode(",", array_slice($data, 0, $dstrings[1])) . "&labels=" . implode(",", array_slice($labels, 0, $dstrings[1]));
             $row = array();
             foreach ($fields as $field) {
                 switch ($field) {
                     case "id":
                         $row[$field] = $id;
                         break;
                     case "created":
                         $row[$field] = 0;
                         break;
                     case "lastmodified":
                         $row[$field] = 0;
                         break;
                     case "lastmodifiedby":
                         $row[$field] = "";
                         break;
                     case "image":
                         $row[$field] = "<img src='" . $filename . "'/>";
                         break;
                     case "title":
                         $row[$field] = $stat;
                         break;
                     case "searchcontent":
                         $row[$field] = $stat;
                         break;
                 }
             }
             if (sys_select_where($row, $where, $vars)) {
                 $rows[] = $row;
             }
         }
         $rows = sys_select($rows, $order, $limit, $fields);
     }
     return $rows;
 }
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $path = rtrim($path, "/");
     $datas = sys_parse_csv($path);
     $rows = array();
     $index = array_shift($datas);
     $i = 0;
     $map = array("subject" => "Subject", "description" => "Description", "location" => "Location", "category" => "Categories", "organizer" => "Meeting Organizer");
     foreach ($datas as $data) {
         $i++;
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 case "id":
                     $row[$field] = $path . "/?" . $i;
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "created":
                     $row[$field] = 0;
                     break;
                 case "createdby":
                     $row[$field] = "";
                     break;
                 case "lastmodified":
                     $row[$field] = 0;
                     break;
                 case "lastmodifiedby":
                     $row[$field] = "";
                     break;
                 case "searchcontent":
                     $row[$field] = implode(" ", $data);
                     break;
                 case "begin":
                     $key1 = array_search("Start Date", $index);
                     $key2 = array_search("Start Time", $index);
                     $row[$field] = modify::datetime_to_int($data[$key1] . " " . $data[$key2]);
                     break;
                 case "ending":
                     $key1 = array_search("End Date", $index);
                     $key2 = array_search("End Time", $index);
                     $row[$field] = modify::datetime_to_int($data[$key1] . " " . $data[$key2]);
                     $row["until"] = $row[$field];
                     break;
                 case "duration":
                     $row[$field] = $row["ending"] - $row["begin"];
                     break;
                 case "priority":
                     $key = array_search("Priority", $index);
                     $row[$field] = strtolower($data[$key]);
                     break;
                 case "allday":
                     $key = array_search("All day event", $index);
                     $row[$field] = $data[$key] == "False" ? 0 : 1;
                     break;
                 case "participants_ext":
                     $key = array_search("Required Attendees", $index);
                     $row[$field] = $data[$key];
                     $key = array_search("Optional Attendees", $index);
                     if ($row[$field] != "" and $data[$key] != "") {
                         $row[$field] .= ", ";
                     }
                     $row[$field] .= $data[$key];
                     break;
                 default:
                     $row[$field] = "";
                     if (!isset($row[$field]) and in_array($field, $index)) {
                         $key = array_search($field, $index);
                         $row[$field] = $data[$key];
                     } else {
                         if (isset($map[$field])) {
                             $key = array_search($map[$field], $index);
                             $row[$field] = $data[$key];
                         }
                     }
                     break;
             }
         }
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     $rows = sys_select($rows, $order, $limit, $fields);
     return $rows;
 }
Esempio n. 7
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     if ($fields == array("*")) {
         $fields = array("id", "folder");
     }
     $rows = array();
     $entries = self::_select_xml($path, $mfolder);
     foreach ($entries as $entry) {
         $ext = modify::getfileext($entry->title);
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 case "filedata":
                 case "id":
                     $row[$field] = basename($entry->id);
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "filedata_show":
                 case "filename":
                 case "searchcontent":
                     $row[$field] = (string) $entry->title;
                     break;
                 case "fileext":
                     $row[$field] = $ext;
                     break;
                 case "created":
                     $row[$field] = strtotime($entry->published);
                     break;
                 case "lastmodified":
                     $row[$field] = strtotime($entry->updated);
                     break;
                 case "lastmodifiedby":
                     $row[$field] = (string) $entry->author->name;
                     break;
                 case "filesize":
                     $row[$field] = (int) $entry->gd_quotaBytesUsed;
                     break;
                 default:
                     $row[$field] = "";
                     break;
             }
         }
         $row["_lastmodified"] = strtotime($entry->updated);
         $row["_url"] = (string) $entry->content["src"];
         $row["_filename"] = (string) $entry->title;
         $meta = sys_build_meta($entry->docs_description, array());
         if (empty($meta)) {
             $meta["description"] = (string) $entry->docs_description;
         }
         $row = array_merge($row, $meta);
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     $rows = sys_select($rows, $order, $limit, $fields);
     if (count($rows) > 0 and in_array("filedata", $fields)) {
         foreach ($rows as $key => $row) {
             $filename = sys_cache_get_file("gdocs", $row["id"] . $row["_lastmodified"], "--" . modify::basename($row["_filename"]), true);
             if (!file_exists($filename) and (!isset($row["filesize"]) or $row["filesize"] < GDOCS_PREVIEW_LIMIT)) {
                 $fout = fopen($filename, "wb");
                 $fin = fopen($row["_url"], "rb", false, self::_get_context($mfolder));
                 if (is_resource($fin) and is_resource($fout)) {
                     while (!feof($fin)) {
                         fwrite($fout, fread($fin, 8192));
                     }
                     fclose($fin);
                     fclose($fout);
                 }
             }
             $rows[$key]["filedata"] = $filename;
         }
     }
     return $rows;
 }
Esempio n. 8
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $cid = "pop3_" . md5(serialize(sys_credentials($mfolder)));
     $datas = self::_get_datas($mfolder, $cid);
     if (!isset($datas[0])) {
         return array();
     }
     $rows = array();
     foreach ($datas[0] as $key => $data) {
         $msg_id = $datas[1][$key]["msg_id"];
         $msg_uid = $datas[1][$key]["uidl"];
         $structure = array();
         $row = array();
         $row_id = "pop3_fields_" . md5(implode("_", $fields) . $msg_uid);
         if (!($row = sys_cache_get($row_id))) {
             if (!($pop3 = self::_connect($mfolder)) or !$pop3) {
                 return array();
             }
             foreach ($fields as $field) {
                 switch ($field) {
                     case "id":
                         $row[$field] = $path . "/?" . md5($msg_uid);
                         break;
                     case "folder":
                         $row[$field] = $path;
                         break;
                     case "searchcontent":
                         $row[$field] = $data["subject"] . " " . $data["from"];
                         break;
                     case "subject":
                         $row[$field] = !empty($data["subject"]) ? $data["subject"] : "- {t}Empty{/t} -";
                         break;
                     case "efrom":
                         $row[$field] = isset($data["from"]) ? $data["from"] : "";
                         break;
                     case "eto":
                         $row[$field] = isset($data["to"]) ? $data["to"] : "";
                         break;
                     case "cc":
                         $row[$field] = isset($data["cc"]) ? $data["cc"] : "";
                         break;
                     case "receipt":
                         $row[$field] = !empty($data["disposition-notification-to"]) ? "1" : "0";
                         break;
                     case "created":
                     case "lastmodified":
                         $row[$field] = isset($data["date"]) ? strtotime($data["date"]) : "0";
                         break;
                     case "lastmodifiedby":
                         $row[$field] = "";
                         break;
                     case "dsize":
                     case "size":
                         $row[$field] = $datas[1][$key]["size"];
                         break;
                     case "headers":
                         $row[$field] = "";
                         foreach ($data as $data_key => $data_item) {
                             $row[$field] .= ucfirst($data_key) . ": " . (is_array($data_item) ? implode("\n  ", $data_item) : $data_item) . "\n";
                         }
                         break;
                     case "message_html":
                     case "message":
                         if ($field == "message_html") {
                             $html = true;
                         } else {
                             $html = false;
                         }
                         $row[$field] = "";
                         if (empty($structure)) {
                             $input = $pop3->getMsg($msg_id);
                             $decode = new Mail_mimeDecode($input);
                             $structure = self::_parse_structure($decode->decode(array("include_bodies" => true, "decode_bodies" => true)), 1, $msg_uid);
                             $raw_file = sys_cache_get_file("pop3", $msg_uid, "--original.eml.txt", true);
                             file_put_contents($raw_file, $input);
                         }
                         $file_index = -1;
                         foreach ($structure as $skey => $item) {
                             $is_attachment = self::_is_attachment($item);
                             if ($is_attachment) {
                                 $file_index++;
                             }
                             $content = "";
                             if (sys_strbegins($item["contenttype"], "multipart") and $skey != 0) {
                                 if (isset($item["header"]["subject"])) {
                                     $content = self::_drawheader($item["header"]);
                                     if (!sys_contains($item["charset"], "utf")) {
                                         $content = modify::utf8_encode($content, $item["charset"]);
                                     }
                                     if ($html) {
                                         $content .= modify::nl2br(q(trim($content)), false, true);
                                     }
                                 }
                             } else {
                                 if (!$is_attachment and $item["size"] > 0 and strpos($item["contenttype"], "text/") !== false) {
                                     $data_body = $item["body"];
                                     if (!strpos("#" . $item["charset"], "utf")) {
                                         $data_body = modify::utf8_encode($data_body, $item["charset"]);
                                     }
                                     if ($html) {
                                         if ($content != "") {
                                             $content .= "<hr>";
                                         }
                                         if ($item["contenttype"] != "text/html") {
                                             $data_body = modify::nl2br(q(trim($data_body)), false, true);
                                             if ($item["contenttype"] != "text/plain") {
                                                 $content .= "<b>[" . $item["contenttype"] . "]</b><br>";
                                             }
                                         }
                                         $item["level"] = substr_count($item["id"], ".");
                                         $content .= "<div style='margin-left:" . $item["level"] * 20 . "px;'><code>" . $data_body . "</code></div>";
                                     } else {
                                         if ($content != "") {
                                             $content .= "\n";
                                         }
                                         if ($item["contenttype"] == "text/html") {
                                             $data_body = modify::htmlmessage($data_body);
                                         } else {
                                             if ($item["contenttype"] != "text/plain") {
                                                 $content .= "[" . $item["contenttype"] . "]\n";
                                             }
                                         }
                                         $content .= trim($data_body) . "\n";
                                     }
                                 } else {
                                     if (strpos($item["contenttype"], "image/") !== false and !empty($item["cid"])) {
                                         $url = "download.php?folder=@folder@&view=attachment_show&field=attachment&item[]=@id@&subitem=" . $file_index;
                                         $row[$field] = str_replace("cid:" . $item["cid"], $url, $row[$field]);
                                     }
                                 }
                             }
                             if ($row[$field] != "" and $content != "") {
                                 if ($html) {
                                     $row[$field] .= "<hr><br>";
                                 } else {
                                     $row[$field] .= "\n----\n\n";
                                 }
                             }
                             $row[$field] .= $content;
                         }
                         break;
                     case "attachment":
                         $row[$field] = "";
                         if (empty($structure)) {
                             $input = $pop3->getMsg($msg_id);
                             $decode = new Mail_mimeDecode($input);
                             $structure = self::_parse_structure($decode->decode(array("include_bodies" => true, "decode_bodies" => true)), 1, $msg_uid);
                             $raw_file = sys_cache_get_file("pop3", $msg_uid, "--original.eml.txt", true);
                             file_put_contents($raw_file, $input);
                         }
                         $files = array();
                         foreach ($structure as $item) {
                             if ($item["disposition"] == "attachment") {
                                 $files[] = sys_cache_get_file("pop3", $msg_uid, "--" . $item["name"]);
                             }
                         }
                         $files[] = sys_cache_get_file("pop3", $msg_uid, "--original.eml.txt");
                         if (count($files) > 0) {
                             $row[$field] = "|" . implode("|", $files) . "|";
                         }
                         break;
                 }
             }
             sys_cache_set($row_id, $row, POP3_MAIL_CACHE);
         }
         $row["_msg_id"] = $msg_id;
         $row["seen"] = file_exists(sys_cache_get_file("pop3", md5($msg_uid), "seen_" . $mfolder)) ? "1" : "";
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     return sys_select($rows, $order, $limit, $fields);
 }
Esempio n. 9
0
function db_select($table, $fields, $sql_where, $order, $limit, $vars = array(), $optional = array())
{
    $fields = (array) $fields;
    $sql_where = (array) $sql_where;
    if (!is_array($limit)) {
        if ($limit != "") {
            $limit = array($limit);
        } else {
            $limit = array();
        }
    }
    $rows = array();
    if (!empty($optional["handler"])) {
        $handler = "lib_" . $optional["handler"];
        $folder = $vars["folder"];
        $vars = sys_remove_handler($vars);
        $rows = call_user_func(array($handler, "select"), $vars["folder"], $fields, $sql_where, $order, $limit, $vars, $vars["mfolder"]);
        if (count($rows) > 0 and in_array("id", $fields)) {
            foreach (array_keys($rows) as $key) {
                $rows[$key]["folder"] = $folder;
                $rows[$key]["id"] = $handler . ":" . $vars["mfolder"] . "/" . $rows[$key]["id"];
            }
        }
        return $rows;
    }
    $groupby = "";
    $where = "";
    if (count($sql_where) > 0) {
        $where = str_replace("and 1=1", "", " where " . implode(" and ", $sql_where));
    }
    if ($order != "") {
        $order = " order by " . $order;
    }
    if (!empty($optional["groupby"])) {
        $groupby = " group by " . $optional["groupby"];
    }
    if (!empty($optional["custom_name"])) {
        $table = sql_translate(sql_concat($optional["custom_name"]));
    }
    $sql = "select " . implode(",", $fields) . " from " . $table . $where . sql_fieldname($order . $groupby, true);
    if (!empty($optional["default_sql"]) and $optional["default_sql"] != "no_select") {
        $sql = str_replace("@table@", $table, sql_translate($optional["default_sql"]));
    }
    if (is_array($vars) and count($vars) > 0) {
        foreach (array_keys($vars) as $key) {
            $sql = str_replace("@" . $key . "@", sys_correct_quote($vars[$key]), $sql);
        }
    }
    if (!empty($optional["sqlvarsnoquote"]) and count($optional["sqlvarsnoquote"]) > 0) {
        foreach ($optional["sqlvarsnoquote"] as $key => $val) {
            $sql = str_replace("@" . $key . "@", $val, $sql);
        }
    }
    $sql = str_replace("1=1 and ", "", $sql);
    if (count($limit) > 0) {
        $sql = sql_limit($sql, isset($limit[1]) ? $limit[0] : 0, isset($limit[1]) ? $limit[1] : $limit[0]);
    }
    if ($sql != "none") {
        $time_start = sys_get_microtime();
        if (($rows = sql_fetch($sql)) === false) {
            $msg = sql_error();
            if (DEBUG) {
                debug_sql("ERROR " . $sql, $msg);
            }
            sys_log_message_log("db-fail", $sql . " " . $msg, sys_backtrace());
            return "error";
        }
        $time = number_format(sys_get_microtime() - $time_start, 4);
        if ($time > DB_SLOW) {
            $slow_log = var_export(sql_explain($sql), true);
            sys_log_message_log("db-slow", sprintf("{t}%s secs{/t}", $time) . " " . $sql, sys_backtrace() . " " . $slow_log);
        }
        sys::$db_queries[] = array($sql, $time);
        if (in_array("pid", $fields) and count($rows) > 0) {
            $rows = modify::threadsort($rows);
        }
    }
    if (!empty($optional["default_sql"]) and $optional["default_sql"] != "no_select") {
        foreach ($rows as $key => $row) {
            if (!sys_select_where($row, $sql_where, $vars)) {
                unset($rows[$key]);
            }
        }
        return sys_select($rows, substr($order, 10), $limit, $fields);
    }
    if ($limit == array("1") and count($rows) > 1) {
        $rows = array(array("count" => count($rows)));
    }
    if (count($limit) > 0) {
        if (count($limit) == 2 and count($rows) > $limit[1]) {
            $rows = array_slice($rows, $limit[0], $limit[1]);
        }
        if (count($limit) == 1 and count($rows) > $limit[0]) {
            $rows = array_slice($rows, 0, $limit[0]);
        }
    }
    return $rows;
}
Esempio n. 10
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $path = rtrim($path, "/");
     $datas = self::_parse($path);
     $rows = array();
     $ids = array();
     $mapping = array("c" => "country", "cn" => "contactid", "company" => "company", "department" => "department", "dn" => "id", "description" => "description", "facsimiletelephonenumber" => "fax", "fax" => "fax", "sn" => "lastname", "homephone" => "phoneprivate", "ipphone" => "skype", "l" => "city", "mail" => "email", "mobile" => "mobile", "mozillasecondemail" => "emailprivate", "mozillanickname" => "nickname", "pager" => "pager", "postalcode" => "zipcode", "givenname" => "firstname", "st" => "state", "streetaddress" => "street", "street" => "street", "telephonenumber" => "phone", "title" => "title");
     foreach ($datas as $key => $data) {
         $id = $key;
         if (!empty($data["id"])) {
             $id = md5($data["id"]);
         }
         $row = array();
         foreach ($fields as $field) {
             $row[$field] = "";
             switch ($field) {
                 case "id":
                     $row[$field] = $path . "/?" . $id;
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "created":
                     $row[$field] = 0;
                     break;
                 case "lastmodified":
                     $row[$field] = 0;
                     break;
                 case "lastmodifiedby":
                     $row[$field] = "";
                     break;
                 case "searchcontent":
                     $row[$field] = implode(" ", $data);
                     break;
                 case "contactid":
                     if (empty($data["cn"])) {
                         if (!empty($data["sn"])) {
                             $row[$field] = $data["sn"];
                         }
                         if (!empty($data["givenname"])) {
                             $row[$field] .= " " . $data["givenname"];
                         }
                         if ($row[$field] == "" and !empty($data["mail"])) {
                             $row[$field] = $data["mail"];
                         }
                     } else {
                         $row[$field] = $data["cn"];
                     }
                     $row[$field] = str_replace(array(" ", ".", ",", "@", "\"", "'"), array("_", "_", "", "_", "", ""), $row[$field]);
                     $row[$field] = substr(trim($row[$field], " _-."), 0, 15);
                     while (isset($ids[$row[$field]])) {
                         $row[$field] .= "_2";
                     }
                     $ids[$row[$field]] = "";
                     break;
                 case "lastname":
                     if (!empty($data["sn"])) {
                         $row[$field] = $data["sn"];
                     }
                     if ($row[$field] == "" and !empty($data["mail"])) {
                         preg_match("/[.-_]?([^.-_@]+)@/i", $data["mail"], $match);
                         if (!empty($match[1])) {
                             $row[$field] = ucfirst(strtolower($match[1]));
                         }
                     }
                     $row[$field] = trim($row[$field], " ,");
                     break;
                 case "firstname":
                     if (!empty($data["givenname"])) {
                         $row[$field] = $data["givenname"];
                     }
                     if ($row[$field] == "" and !empty($data["mail"])) {
                         preg_match("/([^._@]+)[._][^._@]*@/i", $data["mail"], $match);
                         if (!empty($match[1])) {
                             $row[$field] = ucfirst(strtolower($match[1]));
                         }
                     }
                     $row[$field] = trim($row[$field], " ,");
                     break;
                 default:
                     if ($field_key = array_search($field, $mapping) and !empty($data[$field_key])) {
                         $row[$field] = str_replace(array("\"", "'"), "", $data[$field_key]);
                     }
                     break;
             }
         }
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     $rows = sys_select($rows, $order, $limit, $fields);
     return $rows;
 }
Esempio n. 11
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $path = rtrim($path, "/");
     $folder = substr($path, strrpos($path, "/") + 1);
     $file_path = substr($path, 0, strrpos($path, "/"));
     if (is_dir($file_path) or !file_exists($file_path) or sys_allowedpath(dirname($file_path)) != "") {
         return array();
     }
     $datas = self::_get_data($file_path);
     if (!isset($datas[$folder]) or count($datas[$folder]) == 0) {
         return array();
     }
     $datas = $datas[$folder];
     $rows = array();
     $i = 0;
     foreach ($datas as $data) {
         $i++;
         $row = array();
         foreach ($fields as $field) {
             $row[$field] = "";
             switch ($field) {
                 case "id":
                     $row[$field] = $path . "/?" . $i;
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "created":
                     $row[$field] = 0;
                     break;
                 case "lastmodified":
                     $row[$field] = 0;
                     break;
                 case "lastmodifiedby":
                     $row[$field] = "";
                     break;
                 case "searchcontent":
                     $row[$field] = implode(" ", $data);
                     break;
                 default:
                     if (empty($row[$field]) and isset($data->{$field})) {
                         $row[$field] = (string) $data->{$field};
                     }
                     break;
             }
         }
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     return sys_select($rows, $order, $limit, $fields);
 }
Esempio n. 12
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     if (sys_allowedpath($path) != "") {
         return array();
     }
     $file_array = array();
     if (!($handle = @opendir($path))) {
         return array();
     }
     while (false !== ($file = readdir($handle))) {
         if ($file == '.' or $file == '..' or is_dir($path . $file)) {
             continue;
         }
         $file_array[] = $file;
     }
     closedir($handle);
     if ($fields == array("*")) {
         $fields = array("id", "folder");
     }
     $rows = array();
     foreach ($file_array as $filename) {
         $ext = modify::getfileext($filename);
         if ($ext == "meta") {
             continue;
         }
         $data = stat($path . $filename);
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 case "filedata":
                 case "id":
                     $row[$field] = $path . $filename;
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "filename":
                 case "searchcontent":
                     $row[$field] = $filename;
                     break;
                 case "fileext":
                     $row[$field] = $ext;
                     break;
                 case "fileatime":
                     $row[$field] = $data["atime"];
                     break;
                 case "created":
                     $row[$field] = $data["ctime"];
                     break;
                 case "lastmodified":
                     $row[$field] = $data["mtime"];
                     break;
                 case "lastmodifiedby":
                     $row[$field] = "";
                     break;
                 case "fileperms":
                     $row[$field] = $data["mode"];
                     break;
                 case "filesize":
                     $row[$field] = $data["size"];
                     break;
                 default:
                     $row[$field] = "";
                     break;
             }
         }
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     $rows = sys_select($rows, $order, $limit, $fields);
     if (count($rows) > 0) {
         foreach ($rows as $key => $row) {
             $meta = self::_get_meta($row["id"]);
             foreach ($meta as $mkey => $mval) {
                 $rows[$key][$mkey] = $mval;
             }
         }
     }
     return $rows;
 }
Esempio n. 13
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $path = rtrim($path, "/");
     $csv_data = sys_parse_csv($path);
     $rows = array();
     $index = array_shift($csv_data);
     $i = 0;
     $ids = array();
     $datas = array();
     foreach ($csv_data as $row) {
         $n_row = array();
         foreach ($row as $key => $val) {
             if (!empty($index[$key])) {
                 $key = strtolower($index[$key]);
             }
             $n_row[$key] = $val;
         }
         $datas[] = $n_row;
     }
     /*  
     "Middle Name","Suffix","Business Street 2","Business Street 3",
     "Home Street","Home Street 2","Home Street 3","Home City","Home State","Home Postal Code",
     "Home Country/Region","Other Street","Other Street 2","Other Street 3","Other City",
     "Other State","Other Postal Code","Other Country/Region",
     "Assistant's Phone","Business Phone 2","Callback","Car Phone",
     "Company Main Phone","Home Fax","Home Phone 2","ISDN",
     "Other Fax","Other Phone","Primary Phone","Radio Phone","TTY/TDD Phone","Telex",
     "Account","Anniversary","Assistant's Name","Billing Information",
     "Business Address PO Box","Categories","Children","Directory Server"
     "E-mail Type","E-mail Display Name","E-mail 2 Address","E-mail 2 Type",
     "E-mail 2 Display Name","E-mail 3 Address","E-mail 3 Type","E-mail 3 Display Name",
     "Gender","Government ID Number","Hobby","Home Address PO Box","Initials",
     "Internet Free Busy","Keywords","Language","Location","Manager's Name","Mileage",
     "Office Location","Organizational ID Number","Other Address PO Box","Priority",
     "Private","Profession","Referred By","Sensitivity","Spouse","Web Page"  
     */
     $mapping = array("e-mail address" => "email", "company" => "company", "first name" => "firstname", "last name" => "lastname", "title" => "title", "mobile phone" => "mobile", "pager" => "pager", "business phone" => "phone", "business fax" => "fax", "notes" => "description", "job title" => "position", "e-mail 2" => "emailprivate", "home phone" => "phoneprivate", "business address" => "street", "business street" => "street", "business city" => "city", "business postal code" => "zipcode", "business state" => "state", "business country/region" => "country", "department" => "department", "birthday" => "birthday");
     foreach ($datas as $data) {
         $i++;
         $row = array();
         foreach ($fields as $field) {
             $row[$field] = "";
             switch ($field) {
                 case "id":
                     $row[$field] = $path . "/?" . $i;
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "created":
                     $row[$field] = 0;
                     break;
                 case "lastmodified":
                     $row[$field] = 0;
                     break;
                 case "lastmodifiedby":
                     $row[$field] = "";
                     break;
                 case "searchcontent":
                     $row[$field] = implode(" ", $data);
                     break;
                 case "contactid":
                     if (empty($data["name"])) {
                         if (!empty($data["last name"])) {
                             $row[$field] = $data["last name"];
                         }
                         if (!empty($data["first name"])) {
                             $row[$field] .= " " . $data["first name"];
                         }
                         if ($row[$field] == "" and !empty($data["e-mail address"])) {
                             $row[$field] = $data["e-mail address"];
                         }
                     } else {
                         $row[$field] = $data["name"];
                     }
                     $row[$field] = str_replace(array(" ", ".", ",", "@", "\"", "'"), array("_", "_", "", "_", "", ""), $row[$field]);
                     $row[$field] = substr(trim($row[$field], " _-."), 0, 15);
                     while (isset($ids[$row[$field]])) {
                         $row[$field] .= "_2";
                     }
                     $ids[$row[$field]] = "";
                     break;
                 case "lastname":
                     if (!empty($data["last name"])) {
                         $row[$field] = $data["last name"];
                     }
                     if ($row[$field] == "" and !empty($data["name"])) {
                         if ($pos = strpos($data["name"], " ")) {
                             $row[$field] = substr($data["name"], $pos + 1);
                         } else {
                             $row[$field] = $data["name"];
                         }
                     }
                     if ($row[$field] == "" and !empty($data["e-mail address"])) {
                         preg_match("/[-._]?([^-._@]+)@/i", $data["e-mail address"], $match);
                         if (!empty($match[1])) {
                             $row[$field] = ucfirst(strtolower($match[1]));
                         }
                     }
                     $row[$field] = trim($row[$field], " ,");
                     break;
                 case "firstname":
                     if (!empty($data["first name"])) {
                         $row[$field] = $data["first name"];
                     }
                     if ($row[$field] == "" and !empty($data["name"]) and $pos = strpos($data["name"], " ")) {
                         $row[$field] = substr($data["name"], 0, $pos);
                     }
                     if ($row[$field] == "" and !empty($data["e-mail address"])) {
                         preg_match("/([^-._@]+)[-._][^-._@]*@/i", $data["e-mail address"], $match);
                         if (!empty($match[1])) {
                             $row[$field] = ucfirst(strtolower($match[1]));
                         }
                     }
                     $row[$field] = trim($row[$field], " ,");
                     break;
                 default:
                     if ($field_key = array_search($field, $mapping) and !empty($data[$field_key])) {
                         $row[$field] = str_replace(array("\"", "'"), "", $data[$field_key]);
                     }
                     if ($field == "birthday" and $row[$field] != "0/0/00") {
                         $row[$field] = modify::datetime_to_int($row[$field]);
                     }
                     break;
             }
         }
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     $rows = sys_select($rows, $order, $limit, $fields);
     return $rows;
 }
Esempio n. 14
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $ldap_path = substr($path, strpos($path, "/") + 1, -1);
     if ($ldap_path != "") {
         $paths = array_reverse(explode("/", $ldap_path));
     } else {
         $paths = array();
     }
     $paths[] = self::_base_dn($mfolder);
     $new_path = implode(",", $paths);
     $mapping = array("lastname" => "sn", "firstname" => "givenname", "email" => "mail", "phone" => "telephonenumber", "street" => "postaladdress");
     $cid = "ldap_" . md5($mfolder . "/" . $path);
     $datas = sys_cache_get($cid);
     if (!is_array($datas)) {
         $datas = array();
         if (!($ds = self::_connect($mfolder))) {
             return array();
         }
         if (!($sr = @ldap_list($ds, $new_path, "objectClass=*", array("dn", "objectClass")))) {
             sys_warning(ldap_error($ds));
             return array();
         }
         $info = ldap_get_entries($ds, $sr);
         foreach ($info as $item) {
             if (!is_array($item)) {
                 continue;
             }
             $sr = ldap_read($ds, $item["dn"], "objectClass=*", array("*", "modifyTimestamp", "modifiersName", "createTimestamp", "creatorsName"));
             $data = ldap_get_entries($ds, $sr);
             if (empty($data[0])) {
                 continue;
             }
             $data = $data[0];
             $datas[] = $data;
         }
         sys_cache_set($cid, $datas, LDAP_LIST_CACHE);
     }
     $rows = array();
     foreach ($datas as $data) {
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 case "id":
                     $row[$field] = $path . "/?" . md5($data["dn"]);
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "contactid":
                     $data_2 = ldap_explode_dn($data["dn"], 0);
                     $row[$field] = str_replace(array("cn=", " "), "", $data_2[0]);
                     break;
                 case "lastmodified":
                     $row[$field] = 0;
                     // TODO2 parse $data["modifytimestamp"][0] 20060312043657Z
                     break;
                 case "created":
                     $row[$field] = 0;
                     // TODO2 parse $data["createtimestamp"][0]
                     break;
                 case "lastmodifiedby":
                     $data_2 = ldap_explode_dn($data["modifiersname"][0], 0);
                     $row[$field] = $data_2[0];
                     break;
                 case "createdby":
                     $data_2 = ldap_explode_dn($data["creatorsname"][0], 0);
                     $row[$field] = $data_2[0];
                     break;
                 default:
                     $row[$field] = "";
                     if (isset($mapping[$field])) {
                         $ld_field = $mapping[$field];
                     } else {
                         $ld_field = $field;
                     }
                     if (isset($data[$ld_field][0])) {
                         $row[$field] = $data[$ld_field][0];
                     }
                     break;
             }
         }
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     $rows = sys_select($rows, $order, $limit, $fields);
     return $rows;
 }
Esempio n. 15
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $path = SIMPLE_STORE . "/backup/";
     if (sys_allowedpath($path) != "") {
         return array();
     }
     $file_array = array();
     if (!($handle = @opendir($path))) {
         return array();
     }
     while (false !== ($file = readdir($handle))) {
         if ($file == '.' or $file == '..' or is_dir($path . $file)) {
             continue;
         }
         if (modify::getfileext($file) != "tar") {
             continue;
         }
         $file_array[] = $file;
     }
     closedir($handle);
     $rows = array();
     foreach ($file_array as $filename) {
         $data = stat($path . $filename);
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 case "filedata":
                 case "id":
                     $row[$field] = $path . $filename;
                     break;
                 case "folder":
                     $row[$field] = $vars["folder"];
                     break;
                 case "category":
                     $row[$field] = str_replace(array("__"), array("/"), substr(modify::basename($filename), 0, strpos(modify::basename($filename), "--")));
                     break;
                 case "filename":
                     $row[$field] = basename(str_replace(array("__"), array("/"), modify::basename($filename)));
                     $row[$field] = substr($row[$field], 0, strpos($row[$field], "--"));
                     if ($row[$field] == "") {
                         $row[$field] = $filename;
                     }
                     break;
                 case "searchcontent":
                     $row[$field] = $filename;
                     break;
                 case "createdby":
                 case "lastmodifiedby":
                     $row[$field] = "";
                     break;
                 case "created":
                     $row[$field] = $data["ctime"];
                     break;
                 case "lastmodified":
                     $row[$field] = $data["mtime"];
                     break;
                 case "filesize":
                     $row[$field] = $data["size"];
                     break;
                 default:
                     $row[$field] = "";
                     break;
             }
         }
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     $rows = sys_select($rows, $order, $limit, $fields);
     return $rows;
 }
Esempio n. 16
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $path = rtrim($path, "/");
     $datas = self::_parse($path);
     $rows = array();
     $contact_ids = array();
     $i = 0;
     foreach ($datas as $data) {
         $i++;
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 case "id":
                     $row[$field] = $path . "/?" . $i;
                     break;
                 case "contactid":
                     if ($row["firstname"] != "" or $row["lastname"] != "") {
                         $row[$field] = str_replace(array(" ", "."), "", substr($row["firstname"], 0, 2) . substr($row["lastname"], 0, 5));
                         if (isset($contact_ids[$row[$field]])) {
                             $row[$field] .= $i;
                         }
                         $contact_ids[$row[$field]] = "";
                     } else {
                         $row[$field] = basename($path) . "_" . $i;
                     }
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "created":
                     $row[$field] = 0;
                     break;
                 case "lastmodified":
                     $row[$field] = 0;
                     break;
                 case "lastmodifiedby":
                     $row[$field] = "";
                     break;
                 case "searchcontent":
                     $row[$field] = "";
                     if (isset($data["email"][0])) {
                         $row[$field] .= " " . $data["email"][0];
                     }
                     if (isset($data["fn"][0])) {
                         $row[$field] .= " " . $data["fn"][0];
                     }
                     if (isset($data["n"][0])) {
                         $row[$field] .= " " . $data["n"][0];
                     }
                     if (isset($data["n"][1])) {
                         $row[$field] .= " " . $data["n"][1];
                     }
                     break;
                 case "email":
                     $row[$field] = isset($data["email"][0]) ? $data["email"][0] : "";
                     break;
                 case "lastname":
                     $row[$field] = "";
                     if (isset($data["fn"][0])) {
                         $row[$field] = substr($data["fn"][0], 0, strpos($data["fn"][0], " "));
                     }
                     if (isset($data["n"][0])) {
                         $row[$field] = $data["n"][0];
                     }
                     break;
                 case "firstname":
                     $row[$field] = "";
                     if (isset($data["fn"][0])) {
                         $row[$field] = substr($data["fn"][0], strpos($data["fn"][0], " ") + 1);
                     }
                     if (isset($data["n"][1])) {
                         $row[$field] = $data["n"][1];
                     }
                     break;
                 case "title":
                     $row[$field] = isset($data["n"][3]) ? $data["n"][3] : "";
                     break;
                 case "company":
                     $row[$field] = isset($data["org"][0]) ? $data["org"][0] : "";
                     break;
                 case "phone":
                     $row[$field] = isset($data["tel"][0]) ? $data["tel"][0] : "";
                     break;
                 case "birthday":
                     $row[$field] = isset($data["bday"][0]) ? strtotime($data["bday"][0]) : "";
                     break;
             }
         }
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     $rows = sys_select($rows, $order, $limit, $fields);
     return $rows;
 }
Esempio n. 17
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $file_array = array();
     try {
         $ntlm = self::_get_ntlm($mfolder);
         $w = new Java("jcifs.smb.SmbFile", "smb://" . $path, $ntlm);
         if ($files = $w->listFiles()) {
             foreach ($files as $file) {
                 if ($file->isFile()) {
                     $file_array[] = $file;
                 }
             }
         }
     } catch (Exception $e) {
         if (DEBUG_JAVA) {
             $msg = java_cast($e, "string");
         } else {
             $msg = $e->getMessage();
         }
         sys_warning("{t}Access denied.{/t} [select] " . $msg . " " . $path);
     }
     if ($fields == array("*")) {
         $fields = array("id", "folder");
     }
     $rows = array();
     foreach ($file_array as $file) {
         $ext = modify::getfileext($file->getName());
         if ($ext == "meta") {
             continue;
         }
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 case "filedata":
                 case "id":
                     $row[$field] = $path . $file->getName();
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "filedata_show":
                 case "filename":
                 case "searchcontent":
                     $row[$field] = (string) $file->getName();
                     break;
                 case "fileext":
                     $row[$field] = $ext;
                     break;
                 case "fileatime":
                     $row[$field] = $file->getLastAccess();
                     break;
                 case "created":
                     $row[$field] = $file->createTime() / 1000;
                     break;
                 case "lastmodified":
                     $row[$field] = $file->getLastModified() / 1000;
                     break;
                 case "lastmodifiedby":
                     $row[$field] = "";
                     break;
                 case "filesize":
                     $row[$field] = $file->length();
                     break;
                 default:
                     $row[$field] = "";
                     break;
             }
         }
         $row["_lastmodified"] = $file->getLastModified() / 1000;
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     $rows = sys_select($rows, $order, $limit, $fields);
     if (count($rows) > 0) {
         if (in_array("filedata", $fields)) {
             foreach ($rows as $key => $row) {
                 $filename = sys_cache_get_file("cifs", $row["id"] . $row["_lastmodified"], "--" . modify::basename($row["id"]), true);
                 if (!file_exists($filename) and (!isset($row["filesize"]) or $row["filesize"] < CIFS_PREVIEW_LIMIT)) {
                     $w = new Java("jcifs.smb.SmbFile", "smb://" . $row["id"], $ntlm);
                     $out = new Java("java.io.FileOutputStream", modify::realfilename($filename, false));
                     $w->store($out);
                 }
                 $rows[$key]["filedata"] = $filename;
             }
         }
         foreach ($rows as $key => $row) {
             $meta = array();
             try {
                 $meta = self::_get_meta($row["id"], $mfolder, $ntlm);
             } catch (Exception $e) {
                 if (DEBUG_JAVA) {
                     $msg = java_cast($e, "string");
                 } else {
                     $msg = $e->getMessage();
                 }
                 sys_warning("{t}Access denied.{/t} [get_meta] " . $msg . " " . $path);
             }
             foreach ($meta as $mkey => $mval) {
                 $rows[$key][$mkey] = $mval;
             }
         }
     }
     return $rows;
 }