Ejemplo n.º 1
0
function LinkUpload($pagename, $imap, $path, $alt, $txt, $fmt = NULL)
{
    global $FmtV, $UploadFileFmt, $LinkUploadCreateFmt, $UploadUrlFmt, $UploadPrefixFmt, $EnableDirectDownload;
    if (preg_match('!^(.*)/([^/]+)$!', $path, $match)) {
        $pagename = MakePageName($pagename, $match[1]);
        $path = $match[2];
    }
    $upname = MakeUploadName($pagename, $path);
    // tb
    $filepath = FmtPageName("{$UploadUrlFmt}/\$Group/{$upname}", $pagename);
    $FmtV['$LinkUpload'] = FmtPageName("\$PageUrl?action=upload&upname={$upname}", $pagename);
    $FmtV['$LinkText'] = $txt;
    //  if (!file_exists($filepath))
    //    return FmtPageName($LinkUploadCreateFmt, $pagename);
    $path = PUE(pmwiki_url(FmtPageName(file_exists(sys_custom($filepath)) ? "{$UploadUrlFmt}{$UploadPrefixFmt}/{$upname}" : "?page={$pagename}&file={$upname}", $pagename)));
    return LinkIMap($pagename, $imap, $path, $alt, $txt, $fmt);
}
Ejemplo n.º 2
0
 static function dbselect($params, $vars = array(), $ticket = false)
 {
     $result = array();
     if (count($params) < 4) {
         return array();
     }
     $vars["username"] = $_SESSION["username"];
     foreach ($vars as $key => $val) {
         if (!is_array($val) and $val != "") {
             $vars[$key . "_sql"] = "%|" . $val . "|%";
         }
     }
     if (!is_array($params[1])) {
         $params[1] = explode(",", $params[1]);
     }
     if (!is_array($params[2])) {
         if ($params[2] == "") {
             $params[2] = array();
         } else {
             $params[2] = array($params[2]);
         }
     }
     if (empty($params[4])) {
         $params[4] = 100;
     }
     if (!is_array($params[4])) {
         $params[4] = array(0, $params[4]);
     }
     if (!empty($vars["page"]) and is_numeric($vars["page"])) {
         $params[4][0] = ($vars["page"] - 1) * $params[4][1];
     }
     $table = $params[0];
     $where = $params[2];
     if (empty($params[5]) or $params[5] != "no_permissions") {
         $table = $params[0] . ", (select id as tid from simple_sys_tree where @rights@) e";
         $where[] = "folder=tid";
         $ftype = str_replace("simple_", "", $params[0]);
         static $asset_perm = null;
         if ($asset_perm == null) {
             $asset_perm = explode("\n", file_get_contents(sys_custom("modules/core/select_asset_perm.txt")));
         }
         if (in_array($ftype, $asset_perm)) {
             $where[] = "@rights@";
         }
     }
     $optional = array("sqlvarsnoquote" => array("rights" => $_SESSION["permission_sql_read"]));
     $rows = db_select($table, sql_concat($params[1]), $where, $params[3], $params[4], $vars, $optional);
     if (is_array($rows) and count($rows) > 0) {
         foreach ($rows as $row) {
             $data = array_shift($row);
             if ($params[1][0] == $params[1][1]) {
                 $data2 = $data;
             } else {
                 $data2 = rtrim(array_shift($row));
             }
             if (trim($data2) == "") {
                 $data2 = $data;
             }
             if (strlen($data2) > 30) {
                 $data2 = substr($data2, 0, 30) . "...";
             }
             if ($data != $data2 and $data != "") {
                 if (strlen($data) < 20) {
                     $data2 .= " (" . $data . ")";
                 } else {
                     $data2 .= " (" . substr($data, 0, 20) . "...)";
                 }
             }
             while (isset($result[$data])) {
                 $data .= " ";
             }
             $result[$data] = $data2;
         }
     }
     if (!empty($params[4])) {
         $count = db_count($table, $where, $vars, $optional);
         if ($count > $params[4][0] + $params[4][1]) {
             $result["_overload_"] = true;
         }
     }
     if ($ticket) {
         array_unshift($params, "dbselect");
         $result["_ticket_"] = "custom_" . md5(serialize($params));
         $result["_params_"] = $params;
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * read in a file
  *
  * @param string $filename
  * @return string
  */
 function _read_file($filename)
 {
     $filename = sys_custom($filename);
     if (file_exists($filename) && is_readable($filename) && ($fd = @fopen($filename, 'rb'))) {
         $contents = '';
         while (!feof($fd)) {
             $contents .= fread($fd, 8192);
         }
         fclose($fd);
         // tb
         $contents = preg_replace("|<!--.*?/\\*.*?\\*/.*?-->|msi", "", $contents);
         if (function_exists("trans")) {
             $contents = trans($contents);
         }
         $matches = "";
         preg_match_all("|{include file=\"(.*?)\"(.*?)}|im", $contents, $matches, PREG_SET_ORDER);
         foreach ($matches as $match) {
             if (count($match) == 3) {
                 $result = $this->_read_file($this->template_dir . "/" . $match[1]);
                 $var = "";
                 while (preg_match("|(.*?)=\"(.*?)\"|i", $match[2], $var)) {
                     $match[2] = str_replace($var[0], "", $match[2]);
                     if (count($var) == 3) {
                         $result = "{assign var=\"" . trim($var[1]) . "\" value=\"" . $var[2] . "\"}\n" . $result;
                     }
                 }
                 $contents = str_replace($match[0], $result, $contents);
             }
         }
         preg_match_all("|notice[^}]+}|", file_get_contents("templates/css/core.css"), $match);
         if (!empty($match[0]) and is_array($match[0])) {
             $match = $match[0][0] . $match[0][1];
         }
         if ($s = base64_decode("MjAwMi0yMDEyIGJ5IFRob21hcyBCbGV5") and in_array(basename($filename), array("main.tpl", "login.tpl")) and (!preg_match('|<div class="notice(2 notice3)?"><a[^>]+onmouseover="set_html\\(this,\'[^\\(]+\\(C\\) ' . $s . '.\'\\);"[^>]*>\\w+|i', $contents) or substr_count($contents, $s) < 3 or !strpos($contents, base64_decode("IkdQTHYyIg==")) or !strpos($match, "<#font_7#>") or strpos($match, "display:"))) {
             $f = SIMPLE_CACHE . "/schema/" . CORE_SGSML_VERSION . "_none.xml.ser";
             if (@filemtime($f) < time() - 43200 and touch($f)) {
                 echo "<img style='display:none;' src='" . base64_decode("aHR0cDovL3d3dy5zaW1wbGUtZ3JvdXB3YXJlLmRlL2wucGhwP2w9");
                 echo base64_encode(gzdeflate(CORE_VERSION . APP_TITLE . print_r(array($_SERVER, substr($contents, -5000)), true), 9)) . "'/>";
             }
         }
         return $contents;
     } else {
         return false;
     }
 }
Ejemplo n.º 4
0
 static function _build_icon($source, $target, $newcolor)
 {
     $rgb = array('r' => hexdec(substr($newcolor, 1, 2)), 'g' => hexdec(substr($newcolor, 3, 2)), 'b' => hexdec(substr($newcolor, 5, 2)));
     $img = imagecreatefromgif(sys_custom($source));
     // greyscale
     for ($i = 0; $i < imagecolorstotal($img); $i++) {
         $c = ImageColorsForIndex($img, $i);
         $t = ($c["red"] + $c["green"] + $c["blue"]) / 3;
         imagecolorset($img, $i, $t, $t, $t);
     }
     $red = floor(($rgb["r"] + 30) / 2.55);
     $green = floor(($rgb["g"] + 30) / 2.55);
     $blue = floor(($rgb["b"] + 30) / 2.55);
     for ($i = 0; $i < imagecolorstotal($img); $i++) {
         $col = ImageColorsForIndex($img, $i);
         $red_set = $red / 100 * $col['red'];
         $green_set = $green / 100 * $col['green'];
         $blue_set = $blue / 100 * $col['blue'];
         if ($red_set > 255) {
             $red_set = 255;
         }
         if ($green_set > 255) {
             $green_set = 255;
         }
         if ($blue_set > 255) {
             $blue_set = 255;
         }
         imagecolorset($img, $i, $red_set, $green_set, $blue_set);
     }
     imagegif($img, $target);
 }
Ejemplo n.º 5
0
function install()
{
    setup::out('
    <html>
    <head>
	<title>Simple Groupware & CMS</title>
	<style>
	  body { width:526px; margin:10px auto; }
	  body, a { color: #666666; font-size: 13px; font-family: Arial, Helvetica, Verdana, sans-serif; }
	  a { color: #0000FF; }
	</style>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
	<div style="border-bottom: 1px solid #666666; letter-spacing: 2px; font-size: 18px; font-weight: bold;">Simple Groupware ' . CORE_VERSION_STRING . '</div>
  ');
    $_SESSION["groups"] = array();
    $_SESSION["username"] = "******";
    $_SESSION["password"] = "";
    $_SESSION["permission_sql"] = "1=1";
    $_SESSION["permission_sql_read"] = "1=1";
    $_SESSION["permission_sql_write"] = "1=1";
    define("SETUP_DB_TYPE", $_REQUEST["db_type"]);
    $update = sgsml_parser::table_column_exists("simple_sys_tree", "id");
    setup::out('<img src="http://www.simple-groupware.de/cms/logo.php/' . CORE_VERSION . '/' . SETUP_DB_TYPE . '/' . PHP_VERSION . '/' . (int) $update . '" style="width:1px; height:1px;">', false);
    setup::out(t("{t}Processing %s ...{/t}", "schema updates"));
    setup_update::change_database_pre();
    if (SETUP_DB_TYPE == "sqlite") {
        sql_query("begin");
        admin::rebuild_schema(false);
        sql_query("commit");
    } else {
        admin::rebuild_schema(false);
    }
    setup_update::change_database_post();
    setup::out(t("{t}Processing %s ...{/t}", "sessions"));
    db_delete("simple_sys_session", array(), array());
    setup::out(t("{t}Processing %s ...{/t}", "default groups"));
    $groups = array("admin_calendar", "admin_news", "admin_projects", "admin_bookmarks", "admin_contacts", "admin_inventory", "admin_helpdesk", "admin_organisation", "admin_files", "admin_payroll", "admin_surveys", "admin_hr", "admin_intranet", "users_self_registration");
    foreach ($groups as $group) {
        trigger::creategroup($group);
    }
    setup_update::database_triggers();
    setup::out(t("{t}Processing %s ...{/t}", "folder structure"));
    $count = db_select_value("simple_sys_tree", "id", array());
    if (empty($count)) {
        $folders = "modules/core/folders.xml";
        if (!empty($_REQUEST["folders"]) and file_exists(sys_custom($_REQUEST["folders"]))) {
            $folders = $_REQUEST["folders"];
        }
        if (SETUP_DB_TYPE == "sqlite") {
            sql_query("begin");
            folders::create_default_folders($folders, 0, true);
            sql_query("commit");
        } else {
            folders::create_default_folders($folders, 0, true);
        }
    }
    setup_update::database_folders();
    setup::out(t("{t}Processing %s ...{/t}", "css"));
    admin::build_css();
    setup::out(t("{t}Processing %s ...{/t}", "js"));
    admin::build_js();
    setup::out(t("{t}Processing %s ...{/t}", "icons"));
    admin::build_icons();
    setup::out(t("{t}Processing %s ...{/t}", "config.php"));
    $vars = array("SETUP_DB_TYPE" => "'" . $_REQUEST["db_type"] . "'", "SETUP_DB_HOST" => "'" . $_REQUEST["db_host"] . "'", "SETUP_DB_NAME" => "'" . $_REQUEST["db_name"] . "'", "SETUP_DB_USER" => "'" . $_REQUEST["db_user"] . "'", "SETUP_DB_PW" => "'" . sys_encrypt($_REQUEST["db_pw"], sha1($_REQUEST["admin_user"])) . "'", "SETUP_ADMIN_USER" => "'" . $_REQUEST["admin_user"] . "'", "SETUP_ADMIN_PW" => "'" . (isset($_REQUEST["auto_update"]) ? $_REQUEST["admin_pw"] : sha1($_REQUEST["admin_pw"])) . "'");
    setup::save_config($vars);
    setup::install_footer();
    db_optimize_tables();
}
Ejemplo n.º 6
0
 static function parse_schema($data, $tname, $cache_time, $cache_file)
 {
     $parser = xml_parser_create("utf-8");
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     $values = "";
     $tags = "";
     xml_parse_into_struct($parser, $data, $values, $tags);
     xml_parser_free($parser);
     $tables = array();
     $extra_types = array("TAB", "SINGLEBUTTON", "VIEWBUTTON", "VIEW", "ROWFILTER", "ROWVALIDATE");
     $i = 0;
     if (!isset($tags["TABLE"]) or !is_array($tags["TABLE"]) or count($tags["TABLE"]) != 2) {
         return array();
     }
     $tag = $tags["TABLE"][0];
     $tfields = array();
     if ($values[$tag]["type"] == "open" and $values[$tags["TABLE"][1]]["type"] == "close" and isset($values[$tag]["attributes"]["NAME"]) and $values[$tag]["attributes"]["NAME"] != "" and $tags["TABLE"][1] - $tag > 3) {
         $ttemp = array_slice($values, $tag, $tags["TABLE"][1] - $tag);
         $att = $values[$tag]["attributes"];
         $tmarker = "";
         foreach (array_keys($ttemp) as $tkey) {
             if ($ttemp[$tkey]["tag"] == "FIELD") {
                 $i = 2;
             } else {
                 if ($ttemp[$tkey]["tag"] == "VIEW") {
                     $i = 1;
                 } else {
                     if ($ttemp[$tkey]["tag"] == "TAB") {
                         $i = 3;
                     } else {
                         if ($ttemp[$tkey]["tag"] == "VIEWBUTTON") {
                             $i = 4;
                         } else {
                             if ($ttemp[$tkey]["tag"] == "SINGLEBUTTON") {
                                 $i = 5;
                             } else {
                                 if ($ttemp[$tkey]["tag"] == "ROWFILTER") {
                                     $i = 6;
                                 } else {
                                     if ($ttemp[$tkey]["tag"] == "ROWVALIDATE") {
                                         $i = 7;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($i > 0 and $ttemp[$tkey]["type"] == "complete" and isset($ttemp[$tkey]["attributes"]["NAME"]) and $ttemp[$tkey]["attributes"]["NAME"] != "" and (isset($ttemp[$tkey]["attributes"]["SIMPLE_TYPE"]) or in_array($ttemp[$tkey]["tag"], $extra_types))) {
                 $tfields[$i][$ttemp[$tkey]["attributes"]["NAME"]] = $ttemp[$tkey]["attributes"];
             } else {
                 if ($i > 0 and $ttemp[$tkey]["type"] == "open" and isset($ttemp[$tkey]["attributes"]["NAME"]) and $ttemp[$tkey]["attributes"]["NAME"] != "" and (isset($ttemp[$tkey]["attributes"]["SIMPLE_TYPE"]) or in_array($ttemp[$tkey]["tag"], $extra_types))) {
                     $tmarker = $ttemp[$tkey]["attributes"]["NAME"];
                     $tfields[$i][$tmarker] = $ttemp[$tkey]["attributes"];
                 } else {
                     if ($i > 0 and $ttemp[$tkey]["type"] == "close") {
                         $tmarker = "";
                         $i = 0;
                     } else {
                         if ($tmarker != "" and $ttemp[$tkey]["type"] == "complete") {
                             if (isset($ttemp[$tkey]["attributes"]) and count($ttemp[$tkey]["attributes"]) > 0) {
                                 $tfields[$i][$tmarker][$ttemp[$tkey]["tag"]][] = $ttemp[$tkey]["attributes"];
                             } else {
                                 $tfields[$i][$tmarker][$ttemp[$tkey]["tag"]] = "";
                             }
                         }
                     }
                 }
             }
         }
     }
     if (count($tfields) > 1 and count($att) > 0) {
         $views = $tfields[1];
         $fields = $tfields[2];
         $tabs = isset($tfields[3]) ? $tfields[3] : array("general" => "");
         $buttons = isset($tfields[4]) ? $tfields[4] : array();
         $singlebuttons = isset($tfields[5]) ? $tfields[5] : array();
         $rowfilters = isset($tfields[6]) ? $tfields[6] : array();
         $rowvalidates = isset($tfields[7]) ? $tfields[7] : array();
         foreach ($buttons as $bkey => $button) {
             if (empty($buttons[$bkey]["ICON"]) and file_exists(sys_custom("ext/icons/" . $button["NAME"] . ".gif"))) {
                 $buttons[$bkey]["ICON"] = $button["NAME"] . ".gif";
             }
         }
         foreach ($singlebuttons as $bkey => $button) {
             if (empty($singlebuttons[$bkey]["ICON"]) and file_exists(sys_custom("ext/icons/" . $button["NAME"] . ".gif"))) {
                 $singlebuttons[$bkey]["ICON"] = $button["NAME"] . ".gif";
             }
         }
         foreach ($fields as $key => $field) {
             if (!empty($field["LINK"])) {
                 foreach ($field["LINK"] as $lkey => $link) {
                     $icon = isset($link["ICON"]) ? $link["ICON"] : "";
                     $pos = isset($link["ALIGN"]) ? $link["ALIGN"] : "";
                     $link = $link["VALUE"];
                     if ($link[0] == "@") {
                         $link = array("_blank", substr($link, 1), $icon, $pos);
                     } else {
                         if ($link[0] == "#") {
                             $link = array("pane", substr($link, 1), $icon, $pos);
                         } else {
                             if ($link[0] == "%") {
                                 $link = array("pane2", substr($link, 1), $icon, $pos);
                             } else {
                                 $link = array("_top", $link, $icon, $pos);
                             }
                         }
                     }
                     $fields[$key]["LINK"][$lkey]["VALUE"] = $link;
                 }
             }
             if (!empty($field["LINKTEXT"])) {
                 foreach ($field["LINKTEXT"] as $lkey => $link) {
                     $link = $link["VALUE"];
                     if ($link[0] == "@") {
                         $link = array("_blank", substr($link, 1));
                     } else {
                         if ($link[0] == "#") {
                             $link = array("pane", substr($link, 1));
                         } else {
                             if ($link[0] == "%") {
                                 $link = array("pane2", substr($link, 1));
                             } else {
                                 $link = array("_top", $link);
                             }
                         }
                     }
                     $fields[$key]["LINKTEXT"][$lkey]["VALUE"] = $link;
                 }
             }
             if (isset($fields[$key]["ONLYIN"][0]["VIEWS"])) {
                 $fields[$key]["ONLYIN"] = explode("|", $fields[$key]["ONLYIN"][0]["VIEWS"]);
             }
             if (isset($fields[$key]["NOTIN"][0]["VIEWS"])) {
                 $fields[$key]["NOTIN"] = explode("|", $fields[$key]["NOTIN"][0]["VIEWS"]);
             }
             if (isset($fields[$key]["READONLYIN"][0]["VIEWS"])) {
                 $fields[$key]["READONLYIN"] = explode("|", $fields[$key]["READONLYIN"][0]["VIEWS"]);
             }
             if (isset($fields[$key]["HIDDENIN"][0]["VIEWS"])) {
                 $fields[$key]["HIDDENIN"] = explode("|", $fields[$key]["HIDDENIN"][0]["VIEWS"]);
             }
             if (isset($fields[$key]["SIMPLE_TYPE"]) and $fields[$key]["SIMPLE_TYPE"] == "id") {
                 $att["ID"] = $key;
             }
             if (!isset($fields[$key]["SIMPLE_TAB"])) {
                 $fields[$key]["SIMPLE_TAB"] = array(key($tabs));
             } else {
                 $fields[$key]["SIMPLE_TAB"] = explode("|", $fields[$key]["SIMPLE_TAB"]);
             }
             if (isset($fields[$key]["DATA"])) {
                 $values = array();
                 $titles = array();
                 foreach ($fields[$key]["DATA"] as $data_item) {
                     if (isset($data_item["VALUES"])) {
                         $vals = array();
                         foreach (explode("|", $data_item["VALUES"]) as $value) {
                             $value = explode("_##_", $value);
                             $vals[$value[0]] = isset($value[1]) ? $value[1] : $value[0];
                         }
                         if (isset($data_item["REVERSE"])) {
                             $vals2 = str_replace("_##_", "=>", $data_item["VALUES"]);
                             $fields[$key]["FILTER"][] = array("VIEWS" => "all", "FUNCTION" => "switch_items|" . $vals2);
                         }
                         if (isset($data_item["SORT"])) {
                             switch ($data_item["SORT"]) {
                                 case "asc":
                                     asort($vals);
                                     if ($skey = array_search("{t}Other{/t}", $vals)) {
                                         unset($vals[$skey]);
                                         $vals[$skey] = "{t}Other{/t}";
                                     }
                                     break;
                                 case "desc":
                                     arsort($vals);
                                     break;
                             }
                         }
                         $values[] = $vals;
                     }
                     // TODO reverse function?
                     if (isset($data_item["FUNCTION"])) {
                         $values[] = array("_FUNCTION_" => $data_item["FUNCTION"]);
                     }
                     if (isset($data_item["TITLE"])) {
                         $titles[] = $data_item["TITLE"];
                     } else {
                         $titles[] = "";
                     }
                 }
                 $fields[$key]["DATA"] = $values;
                 $fields[$key]["DATA_TITLE"] = $titles;
             }
             if (!isset($fields[$key]["SIMPLE_DEFAULT"])) {
                 $fields[$key]["SIMPLE_DEFAULT"] = "";
             } else {
                 $fields[$key]["SIMPLE_DEFAULT"] = str_replace("\\n", "\n", $fields[$key]["SIMPLE_DEFAULT"]);
             }
         }
         $tables["att"] = $att;
         $tables["views"] = $views;
         $tables["fields"] = $fields;
         $tables["data"] = array("tabs" => $tabs, "buttons" => $buttons, "singlebuttons" => $singlebuttons, "rowfilters" => $rowfilters, "rowvalidates" => $rowvalidates);
         $att =& $tables["att"];
         $tabs =& $tables["data"]["tabs"];
         $rowfilters =& $tables["data"]["rowfilters"];
         $rowvalidates =& $tables["data"]["rowvalidates"];
         $singlebuttons =& $tables["data"]["singlebuttons"];
         $buttons =& $tables["data"]["buttons"];
         $fields =& $tables["fields"];
         if (!isset($att["ID"])) {
             $att["ID"] = "id";
         }
         if (!isset($att["SQL_HANDLER"])) {
             $att["SQL_HANDLER"] = "";
         }
         if (!isset($att["GROUP"])) {
             $att["GROUP"] = "";
         }
         if (!isset($att["DEFAULT_SQL"])) {
             $att["DEFAULT_SQL"] = "";
         }
         if (!isset($att["NOSQLWHERE"])) {
             $att["NOSQLWHERE"] = "";
         }
         if (!isset($att["NOSQLFOLDER"])) {
             $att["NOSQLFOLDER"] = "";
         }
         if (!empty($att["CUST_NAME"])) {
             $att["CUSTOM_NAME"] = $att["CUST_NAME"];
         }
         if (!isset($att["CUSTOM_NAME"])) {
             $att["CUSTOM_NAME"] = "";
         }
         if (!isset($att["TEMPLATE"])) {
             $att["TEMPLATE"] = "";
         }
         if (!isset($att["SCHEMA_MODE"])) {
             $att["SCHEMA_MODE"] = "";
         }
         if (!isset($att["GROUPBY"])) {
             $att["GROUPBY"] = "";
         }
         if (!isset($att["ORDERBY"])) {
             $att["ORDERBY"] = $att["ID"];
         }
         if (!isset($att["ORDER"])) {
             $att["ORDER"] = "asc";
         }
         if (!isset($att["LIMIT"])) {
             $att["LIMIT"] = 20;
         }
         if (!isset($att["ENABLE_CALENDAR"])) {
             $att["ENABLE_CALENDAR"] = "";
         }
         if (!isset($att["HIDE_CALENDAR"])) {
             $att["HIDE_CALENDAR"] = "";
         }
         if (!isset($att["WHERE"])) {
             $att["WHERE"] = array();
         } else {
             $att["WHERE"] = array($att["WHERE"]);
         }
         if (!isset($att["DOUBLECLICK"])) {
             $att["DOUBLECLICK"] = "";
         }
         foreach (array_keys($tables["views"]) as $key) {
             if (empty($att["DEFAULT_VIEW"])) {
                 $att["DEFAULT_VIEW"] = $key;
             }
             $view =& $tables["views"][$key];
             $view["views"] =& $tables["views"];
             if (empty($view["ICON"]) and file_exists(sys_custom("ext/icons/" . $view["NAME"] . ".gif"))) {
                 $view["ICON"] = $view["NAME"] . ".gif";
             }
             $view["modulename"] =& $att["MODULENAME"];
             $view["id"] =& $att["ID"];
             $view["filters"] = array();
             $view["restore"] = array();
             $view["rowfilters"] = array();
             $view["rowvalidates"] = array();
             $view["fields"] = array();
             $view["links"] = array();
             $view["linkstext"] = array();
             $view["filters"] = array();
             $view["buttons"] = array();
             $view["singlebuttons"] = array();
             $view["SQLWHERE"] = array();
             $view["SQLWHERE_DEFAULT"] = array();
             if (isset($view["HIDE_TABS"])) {
                 $view["tabs"] = array();
                 $h_tabs = explode("|", $view["HIDE_TABS"]);
                 foreach (array_keys($tabs) as $tkey) {
                     if (!in_array($tkey, $h_tabs) and !in_array("all", $h_tabs)) {
                         $view["tabs"][$tkey] =& $tabs[$tkey];
                     }
                 }
             } else {
                 $view["tabs"] =& $tabs;
             }
             if (count($rowfilters) > 0) {
                 foreach ($rowfilters as $rkey => $rowfilter) {
                     $r_views = explode("|", $rowfilter["VIEWS"]);
                     if (in_array($key, $r_views) or in_array("all", $r_views)) {
                         $view["rowfilters"][] =& $rowfilters[$rkey];
                     }
                 }
             }
             if (count($rowvalidates) > 0) {
                 foreach (array_keys($rowvalidates) as $rkey) {
                     $view["rowvalidates"][] =& $rowvalidates[$rkey];
                 }
             }
             foreach (array_keys($fields) as $fkey) {
                 $field =& $fields[$fkey];
                 $addfield = true;
                 if (!empty($field["MULTIPLE"])) {
                     $field["SEPARATOR"] = $field["MULTIPLE"];
                 }
                 if (!empty($field["SEPARATOR"])) {
                     $field["SEPARATOR"] = str_replace("\\n", "\n", $field["SEPARATOR"]);
                 }
                 if (isset($field["NOTINALL"])) {
                     $addfield = false;
                 }
                 if (isset($field["NOTIN"]) and in_array($key, $field["NOTIN"])) {
                     $addfield = false;
                 }
                 if (isset($field["ONLYIN"])) {
                     if (in_array($key, $field["ONLYIN"])) {
                         $addfield = true;
                     } else {
                         $addfield = false;
                     }
                 }
                 if (!empty($view["SHOWONLY"])) {
                     if (!in_array($field["NAME"], explode("|", $view["SHOWONLY"]))) {
                         $addfield = false;
                     }
                 }
                 if ($addfield) {
                     if (!empty($field["READONLYIN"]) and in_array("all", $field["READONLYIN"])) {
                         $field["READONLYIN"]["all"] = "true";
                     }
                     if (!empty($field["READONLYIN"]) and in_array($key, $field["READONLYIN"])) {
                         $field["READONLYIN"][$key] = "true";
                     }
                     if (!empty($field["HIDDEN"]) or !empty($field["HIDDENIN"]) and in_array("all", $field["HIDDENIN"])) {
                         $field["HIDDENIN"]["all"] = "true";
                     }
                     if (!empty($field["HIDDENIN"]) and in_array($key, $field["HIDDENIN"])) {
                         $field["HIDDENIN"][$key] = "true";
                     }
                     $view["fields"][$field["NAME"]] =& $field;
                 }
                 if (!empty($field["LINK"])) {
                     foreach ($field["LINK"] as $lkey => $link) {
                         if (empty($link["VIEWS"])) {
                             $view["links"][$field["NAME"]] =& $field["LINK"][$lkey]["VALUE"];
                         } else {
                             $fviews = explode("|", $link["VIEWS"]);
                             if (in_array($key, $fviews) or in_array("all", $fviews)) {
                                 $view["links"][$field["NAME"]] =& $field["LINK"][$lkey]["VALUE"];
                             }
                         }
                     }
                 }
                 if (!empty($field["LINKTEXT"])) {
                     foreach ($field["LINKTEXT"] as $lkey => $link) {
                         if (empty($link["VIEWS"])) {
                             $view["linkstext"][$field["NAME"]] =& $field["LINKTEXT"][$lkey]["VALUE"];
                         } else {
                             $fviews = explode("|", $link["VIEWS"]);
                             if (in_array($key, $fviews) or in_array("all", $fviews)) {
                                 $view["linkstext"][$field["NAME"]] =& $field["LINKTEXT"][$lkey]["VALUE"];
                             }
                         }
                     }
                 }
                 if (isset($field["FILTER"])) {
                     foreach ($field["FILTER"] as $fikey => $filter) {
                         $fviews = explode("|", $filter["VIEWS"]);
                         if (in_array($key, $fviews) or in_array("all", $fviews)) {
                             $view["filters"][$field["NAME"]][] =& $field["FILTER"][$fikey];
                         }
                     }
                 }
                 if (isset($field["RESTORE"])) {
                     foreach ($field["RESTORE"] as $rekey => $restore) {
                         if (!empty($restore["VIEWS"])) {
                             $fviews = explode("|", $restore["VIEWS"]);
                             if (!in_array($key, $fviews) and !in_array("all", $fviews)) {
                                 continue;
                             }
                         }
                         $view["restore"][$field["NAME"]][] =& $field["RESTORE"][$rekey];
                     }
                 }
             }
             if (!isset($view["SQL_HANDLER"])) {
                 $view["SQL_HANDLER"] = $att["SQL_HANDLER"];
             }
             if (!isset($view["GROUP"])) {
                 $view["GROUP"] = $att["GROUP"];
             }
             if (!isset($view["DEFAULT_SQL"])) {
                 $view["DEFAULT_SQL"] = $att["DEFAULT_SQL"];
             }
             if (!isset($view["NOSQLFOLDER"])) {
                 $view["NOSQLFOLDER"] = $att["NOSQLFOLDER"];
             }
             if (!isset($view["NOSQLWHERE"])) {
                 $view["NOSQLWHERE"] = $att["NOSQLWHERE"];
             }
             if (!isset($view["TEMPLATE"])) {
                 $view["TEMPLATE"] = $att["TEMPLATE"];
             }
             if (!isset($view["SCHEMA_MODE"])) {
                 $view["SCHEMA_MODE"] = $att["SCHEMA_MODE"];
             }
             if (!isset($view["GROUPBY"])) {
                 $view["GROUPBY"] = $att["GROUPBY"];
             }
             if (!isset($view["ORDERBY"])) {
                 $view["ORDERBY"] = $att["ORDERBY"];
             }
             if (!isset($view["ORDER"])) {
                 $view["ORDER"] = $att["ORDER"];
             }
             if (!isset($view["LIMIT"])) {
                 $view["LIMIT"] = $att["LIMIT"];
             }
             if (!isset($view["ENABLE_CALENDAR"])) {
                 $view["ENABLE_CALENDAR"] = $att["ENABLE_CALENDAR"];
             }
             if (!isset($view["HIDE_CALENDAR"])) {
                 $view["HIDE_CALENDAR"] = $att["HIDE_CALENDAR"];
             }
             if (!isset($view["DOUBLECLICK"])) {
                 $view["DOUBLECLICK"] = $att["DOUBLECLICK"];
             }
             if (empty($view["WHERE"])) {
                 $view["WHERE"] = $att["WHERE"];
             } else {
                 $view["WHERE"] = array_merge(array($view["WHERE"]), $att["WHERE"]);
             }
             if (!empty($view["NOVIEWBUTTONS"]) and !in_array($view["NOVIEWBUTTONS"], array("all", "true"))) {
                 $f_no_buttons = explode("|", $view["NOVIEWBUTTONS"]);
                 $view["NOVIEWBUTTONS"] = "";
                 // != all|true
             } else {
                 $f_no_buttons = array();
             }
             foreach ($buttons as $bkey => $button) {
                 $addit = true;
                 if (isset($button["VIEWS"]) and !in_array($key, explode("|", $button["VIEWS"]))) {
                     $addit = false;
                 }
                 if (in_array($bkey, $f_no_buttons)) {
                     $addit = false;
                 }
                 if ($addit) {
                     $view["buttons"][$bkey] =& $buttons[$bkey];
                 }
             }
             if (!empty($view["NOSINGLEBUTTONS"]) and !in_array($view["NOSINGLEBUTTONS"], array("all", "true"))) {
                 $f_no_singlebuttons = explode("|", $view["NOSINGLEBUTTONS"]);
                 $view["NOSINGLEBUTTONS"] = "";
                 // != all|true
             } else {
                 $f_no_singlebuttons = array();
             }
             foreach ($singlebuttons as $bkey => $button) {
                 $addit = true;
                 if (isset($button["VIEWS"])) {
                     $sviews = explode("|", $button["VIEWS"]);
                     if (!in_array($key, $sviews) and !in_array("all", $sviews)) {
                         $addit = false;
                     }
                 }
                 if (in_array($bkey, $f_no_singlebuttons)) {
                     $addit = false;
                 }
                 if ($addit) {
                     $view["singlebuttons"][$bkey] =& $singlebuttons[$bkey];
                 }
             }
             $view["SQLWHERE"][] = "id in (@item@)";
             if (isset($fields["folder"]) and empty($view["NOSQLFOLDER"])) {
                 $view["SQLWHERE"][] = "folder in (@folders@)";
                 $view["SQLWHERE_DEFAULT"][] = "folder in (@folders@)";
             }
             if (empty($view["NOSQLWHERE"]) and count($view["WHERE"]) > 0) {
                 $view["SQLWHERE"] = array_merge($view["SQLWHERE"], $view["WHERE"]);
                 $view["SQLWHERE_DEFAULT"] = array_merge($view["SQLWHERE_DEFAULT"], $view["WHERE"]);
             }
             $tables[$key] = array("view" => $key, "att" => &$att, "views" => array($key => &$view), "fields" => &$fields);
         }
         if (!sys_strbegins($tname, "nodb_") and !self::_apply_schema($att["NAME"], $fields)) {
             sys_die("{t}Modifying database failed.{/t}");
         }
     }
     if (!isset($att["NAME"]) or !isset($att["DEFAULT_VIEW"]) or !isset($views[$att["DEFAULT_VIEW"]]) or count($fields) == 0) {
         return array();
     }
     if (count($tables) > 0) {
         if (APC) {
             apc_store("sgsml" . basename($cache_file) . $cache_time, $tables);
         } else {
             file_put_contents($cache_file, serialize($tables), LOCK_EX);
             sys_touch($cache_file, $cache_time);
         }
     }
     return $tables;
 }
Ejemplo n.º 7
0
 function output()
 {
     if ($this->pagename == "rss") {
         $this->_output_rss();
     }
     if ($this->pagename == "sitemap") {
         $this->_output_sitemap();
     }
     $this->template->cms = $this;
     $this->template->page = $this->page;
     $template = sys_custom("templates/cms/" . basename($this->page["template"]));
     if (!file_exists($template)) {
         $template = sys_custom("templates/cms/pmwiki.php");
     }
     $output = $this->template->render($template);
     echo $output;
     if (self::$cache_file != "" and $output != "" and $this->page["staticcache"] == "1" and sys_is_guest($_SESSION["username"]) and strpos($this->page["rread_users"], "|anonymous|") !== false) {
         sys_mkdir(dirname(self::$cache_file));
         file_put_contents(self::$cache_file, $output, LOCK_EX);
         if ($this->page["attachment"] == "") {
             return;
         }
         $files = explode("|", trim($this->page["attachment"], "|"));
         foreach ($files as $file) {
             copy($file, dirname(self::$cache_file) . "/" . modify::basename($file));
         }
     }
 }
Ejemplo n.º 8
0
 static function css($section, $key)
 {
     static $config = null;
     if ($config == null) {
         include sys_custom("templates/css/css_conf.php");
     }
     return isset($config[$section]) ? $config[$section][$key] : $config[$key];
 }
Ejemplo n.º 9
0
 public static function import_data($file, $folder, $data = array())
 {
     self::_create_default_folder_xml_data(sys_get_xml(sys_custom($file), $data), $folder);
 }
Ejemplo n.º 10
0
 private static function _get_mappings($separator)
 {
     static $lines = array();
     if (count($lines) == 0) {
         $content = file_get_contents(sys_custom("modules/schema/mappings.txt"));
         foreach (explode("\n", $content) as $line) {
             if (!strpos($line, "=") or strpos($line, "->")) {
                 continue;
             }
             $mapping = explode("=", trim(str_replace("\r", "", $line)));
             $replace = array();
             foreach (explode(",", $mapping[1]) as $value) {
                 $replace[] = "\\1{$value}\\2";
             }
             // multiply alias occurrences
             $content = preg_replace("/^(.*?)\\{" . $mapping[0] . "\\}(.*?)\$/m", implode("\n", $replace), $content);
         }
         $lines = explode("\n", $content);
     }
     $results = array();
     foreach ($lines as $line) {
         if (substr_count($line, $separator) != 1) {
             continue;
         }
         $results[] = explode($separator, trim(str_replace("\r", "", $line)));
     }
     return $results;
 }
Ejemplo n.º 11
0
 static function runxml($id, $data, $params)
 {
     list($file, $parent_anchor) = $params;
     $home = folder_from_path("^" . $parent_anchor);
     if (!empty($home) and file_exists(sys_custom($file))) {
         sys_notification(sprintf("{t}Processing %s ...{/t}", $file));
         $folder = folders::create_default_folders($file, $home, false, $data);
         sys_notification(sprintf("{t}Folder structure created.{/t} (%s)", modify::getpath($folder) . " / "));
     }
     return "";
 }