Example #1
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();
}
 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();
 }