Esempio n. 1
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $type = $path;
     $filename = sys_find_module($type);
     $custom_schema = "";
     if (!file_exists($filename)) {
         if (!is_numeric($path)) {
             $type = "sys_nodb_" . $vars["handler"];
         } else {
             $row = db_select_first("simple_sys_tree", array("ftype", "folders"), "id=@id@", "", array("id" => $path));
             if (empty($row["ftype"])) {
                 throw new Exception("{t}Folder not found.{/t}");
             }
             $type = $row["ftype"];
         }
         $filename = sys_find_module($type);
         $custom_schema = db_select_value("simple_sys_tree", "custom_schema", "id=@id@", array("id" => $path));
     }
     // TODO optimize
     $rows = db_select("simple_sys_custom_fields", array("custom_schema"), array("module=@schema@", "(ffolder='' or ffolder like @folder@)", "activated=1"), "", "", array("schema" => $type, "folder" => "%|" . $path . "|%"));
     if (is_array($rows) and count($rows) > 0) {
         $custom_schema = str_replace("</table>", "", $custom_schema);
         if (!strpos($custom_schema, "<table")) {
             $custom_schema = "<table>";
         }
         foreach ($rows as $row) {
             $custom_schema .= $row["custom_schema"];
         }
         $custom_schema .= "</table>";
     }
     return array(array("id" => $filename, "filename" => $filename, "filemtime" => filemtime($filename), "filecontent" => sgsml_parser::file_get_contents($filename, $type, $custom_schema)));
 }
 private static function _get_obj($module, $xpath = "")
 {
     $content = sgsml_parser::file_get_contents(sys_find_module($module), $module, "");
     $obj = new SimpleXMLElement($content);
     if ($xpath != "") {
         return $obj->xpath($xpath);
     }
     return $obj;
 }
Esempio n. 3
0
 static function rebuild_schema($rebuild_search = false)
 {
     if ($rebuild_search) {
         self::_out(sprintf("{t}Processing %s ...{/t}", "schema, search index"));
     } else {
         self::_out(sprintf("{t}Processing %s ...{/t}", "schema"));
     }
     if (sgsml_parser::table_exists("simple_sys_search") and $rebuild_search) {
         db_delete("simple_sys_search", array(), array());
     }
     $files = array();
     $folders = array("modules/schema/", "modules/schema_sys/", SIMPLE_EXT . "/modules/schema/", SIMPLE_EXT . "/modules/schema_sys/", SIMPLE_CUSTOM . "/modules/schema/", SIMPLE_CUSTOM . "/modules/schema_sys/");
     foreach ($folders as $folder) {
         if (!is_dir($folder)) {
             continue;
         }
         foreach (scandir($folder) as $file) {
             if (!strpos($file, ".xml")) {
                 continue;
             }
             $files[$file] = $folder . $file;
         }
     }
     @set_time_limit(60 * count($files));
     foreach ($files as $file) {
         self::_out(basename($file) . " ", false);
         $schema = db_get_schema($file, "", "", false);
         sys::$db_queries = array();
         // reduce memory usage
         if (!$rebuild_search or sys_strbegins(basename($file), "nodb_") or empty($schema["views"]["display"])) {
             continue;
         }
         if (!empty($schema["att"]["SQL_HANDLER"]) or !empty($schema["att"]["NO_SEARCH_INDEX"])) {
             continue;
         }
         $table = $schema["att"]["NAME"];
         $fields = $schema["fields"];
         $rows = db_select($table, array("id", "folder"), array(), "", "");
         if (!is_array($rows) or count($rows) == 0) {
             continue;
         }
         self::_out("... ", false);
         foreach ($rows as $row) {
             if (folder_in_trash($row["folder"])) {
                 continue;
             }
             db_search_update($table, $row["id"], $fields);
         }
     }
     self::_out("<br>", false);
 }
Esempio n. 4
0
 public static function import_createedit($tfolder, $module, $username, $lastsync, $fields)
 {
     $table_source = "fnbl_simple_" . $module . "_imp";
     $table_dest = "simple_" . $module;
     $sys_date = date("Y-m-d H:i:s");
     $db_date = sgsml_parser::sql_date();
     if (abs(strtotime($sys_date) - strtotime($db_date)) > 60) {
         sys_warning("{t}Error{/t}: {t}current time{/t} {t}System{/t}: " . $sys_date . " {t}Database{/t}: " . $db_date);
     }
     if (DEBUG) {
         echo "Sync4j: " . $table_source . " lastmodified > " . $lastsync . " " . date("c", $lastsync);
     }
     $count_insert = 0;
     $count_update = 0;
     $rows = db_select($table_source, "*", array("userid=@username@", "lastmodified > @lastmodified@"), "", "", array("username" => $username, "lastmodified" => $lastsync - 600));
     if (is_array($rows) and count($rows) > 0) {
         foreach ($rows as $row) {
             if ($row["status"] == "D") {
                 // delete
                 self::_import_delete($tfolder, $row["syncid"], $table_dest, $module);
                 continue;
             }
             unset($row["userid"]);
             unset($row["status"]);
             if ($table_dest == "simple_contacts" and empty($row["contactid"])) {
                 continue;
             }
             if ($table_dest == "simple_tasks") {
                 if (empty($row["begin"]) and empty($row["ending"])) {
                     continue;
                 }
                 if (empty($row["begin"])) {
                     $row["begin"] = $row["ending"];
                 }
             }
             $exists = db_select_value($table_dest, "id", "syncid=@id@", array("id" => $row["syncid"]));
             if (!empty($exists)) {
                 $id = $exists;
             } else {
                 $id = 0;
             }
             if ($id != 0) {
                 // update
                 $row["history"] = sprintf("{t}Item edited (%s) by %s at %s{/t} (sync)\n", "@fields@", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}"));
                 $cdata = "";
                 $data = $row;
                 $cfields = array();
                 $data_old = db_select_first($table_dest, "*", "id=@id@", "", array("id" => $id));
                 if (!empty($data_old["id"])) {
                     if ($row["lastmodified"] == $data_old["lastmodified"]) {
                         continue;
                     }
                     foreach ($data as $key => $val) {
                         if (isset($data_old[$key]) and $key != "history") {
                             if ($data_old[$key] != $val) {
                                 if (trim($val) != "") {
                                     $cdata .= $key . ": " . $val . "\n";
                                 }
                                 $cfields[] = $key;
                             } else {
                                 unset($data[$key]);
                             }
                         }
                     }
                 }
                 if (count($data) < 3) {
                     continue;
                 }
                 $data["history"] = str_replace("@fields@", implode(", ", $cfields), $data["history"]) . $cdata . "\n";
                 if (DEBUG) {
                     print_r($data);
                 }
                 $error_sql = db_update($table_dest, $data, array("id=@id@"), array("id" => $id));
                 $count_update++;
             } else {
                 // new
                 $id = sql_genID($table_dest) * 100;
                 $row["id"] = $id;
                 $row["folder"] = $tfolder;
                 $row["dsize"] = 0;
                 $row["history"] = sprintf("{t}Item created by %s at %s{/t} (sync)\n", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}"));
                 if (DEBUG) {
                     print_r($row);
                 }
                 $error_sql = db_insert($table_dest, $row);
                 $count_insert++;
             }
             if ($error_sql == "") {
                 if ($module == "calendar") {
                     trigger::calcappointment($id, $row, false, "simple_calendar");
                 }
                 if ($module == "tasks") {
                     trigger::duration($id, $row, false, "simple_tasks");
                 }
                 trigger::notify($id, $row, array(), "simple_" . $module);
                 db_search_update($table_dest, $id, $fields);
                 if ($count_insert > 0) {
                     sys_log_stat("new_records", $count_insert);
                 }
                 if ($count_update > 0) {
                     sys_log_stat("changed_records", $count_update);
                 }
             }
         }
     }
     db_update_treesize($table_dest, $tfolder);
     return "";
 }
Esempio n. 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();
}
Esempio n. 6
0
 static function show_list($mirror_id)
 {
     setup::out("\n\t<div style='color:#ff0000;'>\n\t<b>{t}Warning{/t}</b>:<br>\n\t- Please make a complete backup of your database (e.g. using phpMyAdmin)<br>\n\t- Please make a complete backup of your sgs folder (e.g. /var/www/htdocs/sgs/)<br>\n\t- Make sure both backups are complete!\n    </div>\n\t<br>\n\t{t}Downloading update list{/t} ...<br>\n  ");
     $mirror = self::$mirrors[$mirror_id];
     $ctx = stream_context_create(array("http" => array("timeout" => 5)));
     $data = @file_get_contents($mirror["url"], 0, $ctx);
     $match = array();
     preg_match_all($mirror["pattern"], $data, $match);
     if (!empty($match[1]) and $data != "") {
         $found = false;
         foreach ($match[1] as $key => $item) {
             if ($key > 4) {
                 break;
             }
             if (strpos("@" . $item, CORE_VERSION_STRING) and !DEBUG) {
                 break;
             }
             if (!empty($match[3][$key]) and strtotime($match[3][$key]) + 3600 > time()) {
                 continue;
             }
             $found = true;
             $check = true;
             if (!empty($match[2][$key])) {
                 $match_version = array();
                 preg_match("/php (\\d+\\.\\d+\\.\\d+)/i", $match[2][$key], $match_version);
                 if (!empty($match_version[1]) and version_compare(PHP_VERSION, $match_version[1], "<")) {
                     setup::out(sprintf("{t}Setup needs php with at least version %s !{/t}", $match_version[1]));
                     $check = false;
                 }
                 preg_match("/" . SETUP_DB_TYPE . " (\\d+\\.\\d+\\.\\d+)/i", $match[2][$key], $match_version);
                 if (!empty($match_version[1])) {
                     $db_version = str_replace(".", "", $match_version[1]);
                     $curr_version = sgsml_parser::sql_version();
                     if ($curr_version < $db_version) {
                         setup::out(sprintf("{t}Wrong database-version (%s). Please use at least %s !{/t}", $curr_version, $match_version[1]));
                         $check = false;
                     }
                 }
             }
             if ($check) {
                 setup::out("<a href='updater.php?mirror=" . $mirror_id . "&token=" . modify::get_form_token() . "&release=" . $item . "'>{t}I n s t a l l{/t}</a>&nbsp; Simple Groupware ", false);
                 setup::out($item . " (<a target='_blank' href='http://www.simple-groupware.de/cms/Release-" . str_replace(".", "-", $item) . "'>Changelog</a>)<br>");
             }
         }
         if (!$found) {
             setup::out("{t}Already running latest release.{/t}<br>");
         }
     } else {
         setup::out(sprintf("{t}Connection error: %s [%s]{/t}", $mirror["url"], "HTTP") . "<br>" . strip_tags($data, "<br><p><h1><center>"));
     }
     setup::out("{t}Server{/t}: <b>" . $mirror["name"] . "</b>, {t}use mirror from{/t}: ", false);
     foreach (self::$mirrors as $key => $sel_mirror) {
         if ($key == $mirror_id) {
             continue;
         }
         setup::out("<a href='updater.php?mirror=" . $key . "'>" . $sel_mirror["name"] . "</a> ");
     }
     setup::out("<br/>{t}Package from local file system (.tar.gz){/t}:<br/>{t}current path{/t}: " . str_replace("\\", "/", getcwd()) . "/<br/>");
     foreach (scandir("./") as $file) {
         if ($file[0] == "." or !preg_match("|^SimpleGroupware\\_.*?.tar\\.gz\$|i", $file)) {
             continue;
         }
         setup::out("<a href='updater.php?token=" . modify::get_form_token() . "&cfile=" . $file . "'>{t}I n s t a l l{/t}</a>&nbsp; " . $file . "<br/>");
     }
     setup::out("<form method='POST'><input type='hidden' name='token' value='" . modify::get_form_token() . "'><input type='text' name='cfile' value='/tmp/SimpleGroupware_0.xyz.tar.gz' style='width:300px;'>&nbsp;<input type='submit' class='submit' value='{t}I n s t a l l{/t}'><br>");
     setup::out("<input type='checkbox' name='nobackup' value='1' onchange='change_links(this.checked);'/> " . sprintf("{t}Don't move old files to '%s'{/t}", SIMPLE_STORE . "/old/") . "</form>");
     setup::out_exit('<div style="border-top: 1px solid black;">Powered by Simple Groupware, Copyright (C) 2002-2012 by Thomas Bley.</div></div></body></html>');
 }
Esempio n. 7
0
 static function validate_input($databases)
 {
     if ($validate = validate::username($_REQUEST["admin_user"]) and $validate != "") {
         setup::error_add("{t}Admin Username{/t} - {t}validation failed{/t} " . $validate, 30);
     }
     if ($_REQUEST["db_host"] == "") {
         setup::error_add(sprintf("{t}missing field{/t}: %s", "{t}Database Hostname / IP{/t}"), 31);
     }
     if ($_REQUEST["db_user"] == "") {
         setup::error_add(sprintf("{t}missing field{/t}: %s", "{t}Database User{/t}"), 32);
     }
     if ($_REQUEST["db_name"] == "") {
         setup::error_add(sprintf("{t}missing field{/t}: %s", "{t}Database Name{/t}"), 33);
     }
     if ($_REQUEST["admin_pw"] == "") {
         setup::error_add(sprintf("{t}missing field{/t}: %s", "{t}Admin Password{/t}"), 34);
     }
     if ($_REQUEST["admin_pw"] != "" and strlen($_REQUEST["admin_pw"]) < 5) {
         setup::error_add("{t}Admin Password{/t}: {t}Password must be not null, min 5 characters.{/t}", "34b");
     }
     if (!@sql_connect($_REQUEST["db_host"], $_REQUEST["db_user"], $_REQUEST["db_pw"], $_REQUEST["db_name"])) {
         if (!sql_connect($_REQUEST["db_host"], $_REQUEST["db_user"], $_REQUEST["db_pw"])) {
             setup::error_add("{t}Connection to database failed.{/t}\n" . sql_error(), 35);
         }
         setup::errors_show();
         if (!sgsml_parser::create_database($_REQUEST["db_name"])) {
             setup::error_add("{t}Creating database failed.{/t}\n" . sql_error(), 36);
         }
     }
     if (!sql_connect($_REQUEST["db_host"], $_REQUEST["db_user"], $_REQUEST["db_pw"], $_REQUEST["db_name"]) or empty(sys::$db)) {
         setup::error_add("{t}Connection to database failed.{/t}\n" . sql_error(), 37);
         setup::errors_show();
     }
     if (!($version = sgsml_parser::sql_version())) {
         setup::error_add(sprintf("{t}Could not determine database-version.{/t}"), 38);
     }
     $database_min = (int) substr(str_replace(".", "", $databases[SETUP_DB_TYPE][1]), 0, 3);
     if ($version < $database_min) {
         setup::error_add(sprintf("{t}Wrong database-version (%s). Please use at least %s !{/t}", $version, $databases[SETUP_DB_TYPE]), "20" . SETUP_DB_TYPE);
     }
     if (SETUP_DB_TYPE == "pgsql") {
         if (!sql_query("SELECT ''::tsvector;")) {
             setup::error_add("{t}Please install 'tsearch2' for the PostgreSQL database.{/t}\n(Run <postgresql>/share/contrib/tsearch2.sql)\n" . sql_error(), 21);
         }
         if (!sql_query(file_get_contents("modules/core/pgsql.sql"))) {
             setup::error_add("pgsql.sql: " . sql_error(), 50);
         }
     }
     setup::errors_show();
     return $version;
 }
Esempio n. 8
0
function db_get_schema($schema_file, $folder = "", $tview = "", $cache = true, $popup = false)
{
    static $data = array();
    if (!$cache) {
        $data = array();
    }
    $cid = $schema_file . $folder;
    if (!empty($data[$cid])) {
        if ($tview == "") {
            return $data[$cid];
        }
        if (!isset($data[$cid][$tview])) {
            $tview = sys_array_shift(array_keys($data[$cid]));
        }
        return $data[$cid][$tview];
    }
    if (!file_exists($schema_file)) {
        if (basename($schema_file) == "nodb_.xml") {
            sys_warning(sprintf("{t}Folder not found.{/t} (%s)", $folder));
        } else {
            sys_log_message_alert("php-fail", sprintf("{t}Schemafile not found. (%s){/t}", $schema_file . " " . $folder));
        }
        $schema_file = "modules/schema/blank.xml";
    }
    $schema = basename(substr($schema_file, 0, -4));
    $cache_file = SIMPLE_CACHE . "/schema/" . CORE_SGSML_VERSION . "_" . $schema . "_" . LANG . ".ser";
    $custom_schema = "";
    if ($folder != "") {
        if (file_exists(sys_custom($schema_file . "." . $folder))) {
            $schema_file = sys_custom($schema_file . "." . $folder);
            $cache_file .= "." . $folder;
        }
        $custom_schema = db_select_value("simple_sys_tree", "custom_schema", "id=@id@", array("id" => $folder));
        // TODO optimize
        $rows = db_select("simple_sys_custom_fields", array("custom_schema"), array("module=@schema@", "(ffolder='' or ffolder like @folder@)", "activated=1"), "id asc", "", array("schema" => $schema, "folder" => "%|" . $folder . "|%"));
        if (is_array($rows) and count($rows) > 0) {
            $custom_schema = str_replace("</table>", "", $custom_schema);
            if (!strpos($custom_schema, "<table")) {
                $custom_schema = "<table>";
            }
            foreach ($rows as $row) {
                $custom_schema .= $row["custom_schema"] . "\n";
            }
            $custom_schema .= "</table>";
        }
        if ($custom_schema != "") {
            $cache_file .= "." . sha1($custom_schema);
        }
    }
    $custom_dir = sys_custom_dir(substr($schema_file, 0, -4));
    if (is_dir($custom_dir)) {
        $cache_file .= "." . filemtime($custom_dir);
    }
    $schema_mtime = filemtime($schema_file);
    if (APC) {
        $data[$cid] = apc_fetch("sgsml" . basename($cache_file) . $schema_mtime);
    } else {
        if (file_exists($cache_file) and filemtime($cache_file) == $schema_mtime) {
            $data[$cid] = unserialize(file_get_contents($cache_file));
        }
    }
    if (empty($data[$cid])) {
        if (DEBUG and empty($_REQUEST["iframe"])) {
            echo "reload schema";
        }
        $schema_content = sgsml_parser::file_get_contents($schema_file, $schema, $custom_schema);
        $data[$cid] = sgsml_parser::parse_schema($schema_content, $schema, $schema_mtime, $cache_file);
        if (defined("SETUP_DB_HOST")) {
            sys_log_message_log("info", sprintf("{t}Updating schema %s from %s.{/t} {t}Folder{/t}: %s", $schema, $schema_file, $folder));
        }
    }
    if ($tview == "") {
        return $data[$cid];
    }
    if ($folder != "") {
        $write = true;
        if ($popup) {
            $ftype = str_replace("simple_", "", $data[$cid]["att"]["NAME"]);
            if (!in_array($ftype, explode("\n", file_get_contents(sys_custom("modules/core/popup_write.txt"))))) {
                $write = false;
            }
        }
        $superadmin = sys_is_super_admin($_SESSION["username"]);
        foreach (array_keys($data[$cid]["views"]) as $view) {
            if (isset($data[$cid]["views"][$view]["RIGHT"])) {
                $right = $data[$cid]["views"][$view]["RIGHT"];
            } else {
                $right = "read";
            }
            if (($write or $right != "write") and ($superadmin or db_get_right($folder, $right, $view))) {
                continue;
            }
            unset($data[$cid][$view]);
            unset($data[$cid]["views"][$view]);
        }
    }
    if (isset($data[$cid][$tview])) {
        return $data[$cid][$tview];
    } else {
        if ($tview != "none") {
            sys_warning("{t}Item(s) not found or access denied.{/t} (view={$tview})");
        }
        $GLOBALS["tview"] = sys_array_shift(array_keys($data[$cid]["views"]));
        if (empty($GLOBALS["tview"])) {
            return db_get_schema("modules/schema/blank.xml", "", "display");
        }
        return $data[$cid][$GLOBALS["tview"]];
    }
}
Esempio n. 9
0
    if ($content != "") {
        $content = "<pre>" . q($content) . "</pre>";
    }
} else {
    if ($_REQUEST["console"] == "sys") {
        $content = "";
        if ($code != "") {
            $content = sys_exec(str_replace("\n", "&", trim($code)));
        }
        $title = "SYS Console: " . getcwd() . " @ " . $_SERVER["SERVER_NAME"] . " [" . $_SERVER["SERVER_SOFTWARE"] . "]";
        if ($content != "") {
            $content = "<pre>" . q($content) . "</pre>";
        }
    } else {
        $content = "";
        $title = "SQL Console:&nbsp; " . SETUP_DB_USER . " @ " . SETUP_DB_NAME . "&nbsp; [" . SETUP_DB_TYPE . " " . sgsml_parser::sql_version() . "] ";
        if ($code != "") {
            if (($data = sql_fetch($code, false)) === false) {
                $content .= sql_error();
            } else {
                if (is_array($data) and count($data) > 0) {
                    $content .= show_table($data, isset($_REQUEST["full_texts"]), isset($_REQUEST["vertical"]));
                } else {
                    if (SETUP_DB_TYPE == "mysqli" and $num = mysqli_affected_rows(sys::$db)) {
                        $content .= t("{t}%s rows affected{/t}", $num);
                    } else {
                        $content .= t("{t}Empty{/t}");
                    }
                }
            }
        }
Esempio n. 10
0
 static function change_database_pre()
 {
     // 0.730
     $status = array("{t}completed{/t}" => "completed", "{t}confirmed{/t}" => "confirmed", "{t}booked{/t}" => "booked", "{t}canceled{/t}" => "canceled");
     sgsml_parser::table_column_translate("simple_timesheets", "status", $status);
     sgsml_parser::table_column_translate("simple_expenses", "status", $status);
     // completed=0 && status=unconfirmed -> status=open
     // completed=1 && status=unconfirmed -> status=completed
     if (sgsml_parser::table_column_exists("simple_timesheets", "completed")) {
         db_update("simple_timesheets", array("status" => "open"), array("completed=0", "status=@status@"), array("status" => "{t}unconfirmed{/t}"), array("no_defaults" => 1));
         db_update("simple_timesheets", array("status" => "completed"), array("completed=1", "status=@status@"), array("status" => "{t}unconfirmed{/t}"), array("no_defaults" => 1));
     }
     if (sgsml_parser::table_column_exists("simple_expenses", "completed")) {
         db_update("simple_expenses", array("status" => "open"), array("completed=0", "status=@status@"), array("status" => "{t}unconfirmed{/t}"), array("no_defaults" => 1));
         db_update("simple_expenses", array("status" => "completed"), array("completed=1", "status=@status@"), array("status" => "{t}unconfirmed{/t}"), array("no_defaults" => 1));
     }
     // 0.662
     $priority = array("{t}lowest{/t}" => "1", "{t}low{/t}" => "2", "{t}normal{/t}" => "3", "{t}urgent{/t}" => "4", "{t}immediate{/t}" => "5");
     sgsml_parser::table_column_translate("simple_calendar", "priority", $priority);
     sgsml_parser::table_column_translate("simple_tasks", "priority", $priority);
     sgsml_parser::table_column_translate("simple_helpdesk", "priority", $priority);
     sgsml_parser::table_column_translate("simple_projects", "priority", $priority);
     // 0.658
     if (!sgsml_parser::table_column_rename("simple_emails", "attachments", "attachment")) {
         setup::error_add("rename[10]: " . sql_error(), 1152);
     }
     if (!sgsml_parser::table_column_rename("simple_helpdesk", "attachments", "attachment")) {
         setup::error_add("rename[9]: " . sql_error(), 1153);
     }
     // 0.400
     if (!sgsml_parser::table_column_rename("simple_projects", "started", "begin")) {
         setup::error_add("rename[8]: " . sql_error(), 152);
     }
     if (!sgsml_parser::table_column_rename("simple_projects", "finished", "ending")) {
         setup::error_add("rename[7]: " . sql_error(), 153);
     }
     // 0.220
     if (!sgsml_parser::table_column_rename("simple_gallery", "title", "filename")) {
         setup::error_add("rename[5]: " . sql_error(), 52);
     }
     if (!sgsml_parser::table_column_rename("simple_gallery", "attachment", "filedata")) {
         setup::error_add("rename[6]: " . sql_error(), 53);
     }
     // 0.219
     if (!sgsml_parser::table_column_rename("simple_calendar", "end", "ending")) {
         setup::error_add("rename[1]: " . sql_error(), 54);
     }
     if (!sgsml_parser::table_column_rename("simple_contactactivities", "end", "ending")) {
         setup::error_add("rename[2]: " . sql_error(), 55);
     }
     if (!sgsml_parser::table_column_rename("simple_tasks", "end", "ending")) {
         setup::error_add("rename[3]: " . sql_error(), 56);
     }
     // process funambol schema views on sgs update
     if (self::get_config_old("SYNC4J", false, 0) == "1") {
         setup::out(sprintf("{t}Processing %s ...{/t}", "Funambol schema"));
         if (SETUP_DB_TYPE == "mysqli") {
             $data = preg_replace("!/\\*.+?\\*/!s", "", file_get_contents("tools/funambolv7_syncML/mysql/funambol.sql"));
             if ($msg = db_query(explode(";", $data))) {
                 setup::error_add("funambol.sql [mysql]: " . $msg . " " . sql_error(), 100);
             }
         } else {
             if (SETUP_DB_TYPE == "pgsql") {
                 $data = file_get_contents("tools/funambolv7_syncML/postgresql/funambol.sql");
                 if ($msg = db_query($data)) {
                     setup::error_add("funambol.sql [pgsql]: " . $msg . " " . sql_error(), 101);
                 }
             }
         }
     }
     // 0.720
     if (sgsml_parser::table_column_exists("simple_sys_custom_fields", "id")) {
         setup::out(sprintf("{t}Processing %s ...{/t}", "customization fields"));
         $rows = db_select("simple_sys_custom_fields", "*", "activated=1", "", "");
         if (is_array($rows) and count($rows) > 0) {
             foreach ($rows as $row) {
                 sgsml_customizer::trigger_build_field($row["id"], $row, null, "simple_sys_custom_fields");
             }
         }
     }
     setup::errors_show();
 }