function installMain(&$s) { global $lll; global $hostName, $dbUser, $dbUserPw, $dbName, $dbPort, $dbSocket; global $scriptName; global $cookiePath; global $phpVersionMin, $mySqlVersionMin; $s = ""; showInstallHeader($s1); $s .= $s1; // Ezt azert kommentezem ki, mert gyakran ujrainstallalok ugy hogy elozoleg // john-kent be voltam jelentkezve. Ilyen esetben mindig john // id-jevel hozta letre eloszor az admint, majd amikor john // letrehozasara kerult a sor, akkor hibat adott az install mondvan, // hogy ilyen id-ju juzer mar letezik: //if (!isset($_COOKIE["globalUserId"])) //{ mt_srand((double) microtime() * 1000000); global $randIdMax, $randIdMin; if (!isset($randIdMin)) { $randIdMin = 0; } if (!isset($randIdMax)) { $randIdMax = getrandmax(); } $randomId = (int) mt_rand($randIdMin, $randIdMax); setcookie("globalUserId", $randomId, Loginlib_ExpirationDate, $cookiePath); $_COOKIE["globalUserId"] = $randomId; //} if (isset($_POST["edit"])) { $s .= showEditForm(TRUE); return; } //if( isset($_POST["submit"]) && // $_POST["submit"]==$lll["install"] ) //{ //check file creation $ret = checkFileCreate(); if ($ret == ok) { iPrint($lll["create_file_ok"], "ok", $sp); $s .= $sp; $createconf = TRUE; } else { if (!isset($_POST["confirm"])) { iPrint($lll["create_file_nok_ext"], "warn", $sp); } else { iPrint($lll["create_file_nok"], "warn", $sp); } $s .= $sp; $createconf = FALSE; } //check mysql connection $db->hostName = $hostName; $db->user = $dbUser; $db->password = $dbUserPw; $db->port = $dbPort; $db->socket = $dbSocket; $connectRet = checkMysql($db, $s1); $s .= $s1; if ($connectRet == ok) { iPrint($lll["mysql_found"], "ok", $sp); $s .= $sp; $connectok = TRUE; $pwok = TRUE; } elseif ($connectRet == mysql_access_denied) { iPrint($lll["mysql_found"], "ok", $sp); $s .= $sp; if ($dbUserPw == "") { iPrint(sprintf($lll["need_pw"], $dbUser), "warn", $sp); $s .= $sp; $s .= showEditForm(TRUE); return ok; } else { iPrint(sprintf($lll["incorr_pw"], $dbUser), "warn", $sp); $s .= $sp; $s .= showEditForm(TRUE); return ok; } } else { iPrint($lll["mysql_not_found"] . " (" . mysql_error() . ")", "warn", $sp); $s .= $sp; $s .= showEditForm(TRUE); return ok; } if (!DbInstall::checkComponentVersions($mySqlVersion, $phpVersion)) { iPrint(sprintf($lll["versionTooLow"], $mySqlVersionMin, $mySqlVersion, $phpVersionMin, $phpVersion), "err", $sp); $s .= $sp; return ok; } if (!isset($_POST["confirm"])) { $s .= showAskConfirm(); return ok; } if (isset($_COOKIE["globalUserId"])) { iPrint($lll["cookieok"], "ok", $sp); $s .= $sp; } else { iPrint($lll["cookienok"], "err", $sp); $s .= $sp; return; } //check if db exists $ret = mysql_select_db($dbName); if ($ret) { iPrint(sprintf($lll["db_installed"], $dbName), "ok", $sp); $s .= $sp; } else { $ret = createDb(); if ($ret != ok) { $s1 = sprintf($lll["cantcreatedb"], $dbUser); iPrint($s1, "warn", $sp); $s .= $sp; return ok; } else { iPrint(sprintf($lll["db_created"], $dbName), "ok", $sp); $s .= $sp; //select db $ret = mysql_select_db($dbName); } } $ret = DbInstall::installCreateTables(); if ($ret != ok) { iPrint($lll["inst_create_table_err"], "err", $sp); $s .= $sp; return $ret; } else { iPrint($lll["tables_installed"], "ok", $sp); $s .= $sp; } createFirstAdmin(); appFillTables(); iPrint($lll["tables_filled"], "ok", $sp); $s .= $sp; if ($createconf) { //config file can be generated $ret = writeConfigFile($s1); if ($ret != ok) { $s .= $s1; return; } } else { //config can't be created iPrint($lll["compare_conf"], "warn", $sp); $s .= $sp; showConfFileHtml($s1); $s .= $s1; iPrint($lll["afterwrconf"], "warn", $s1); $s .= $s1; } iPrint($lll["move_inst_file"], "warn", $s1); $s .= $s1; iPrint(sprintf($lll["congrat"], "Noah's Classifieds"), "hurra", $s1); $s .= $s1; iPrint($lll["inst_ch_pw"], "warn", $s1); $s .= $s1; //send him to the application: $s .= "<a href='{$scriptName}'>" . sprintf($lll["inst_click"], "Noah's Classifieds") . "</a>"; return ok; }
function getCreateTableQuery($typ, $table, &$query) { $query = "CREATE TABLE @{$table} ( "; $firstField = TRUE; foreach ($typ["attributes"] as $attribute => $attrInfo) { if (in_array("no column", $attrInfo)) { continue; } if (!$firstField) { $query .= ", "; } $firstField = FALSE; //if( $attrInfo["type"]=="DATE" ) $query .= " $attribute INT"; //else $query .= " $attribute ".$attrInfo["type"]; $query .= " `{$attribute}` " . $attrInfo["type"]; if (ereg("INT", $attrInfo["type"]) && isset($attrInfo["length"])) { $query .= "(" . $attrInfo["length"] . ")"; } else { if (ereg("CHAR", $attrInfo["type"]) && isset($attrInfo["max"])) { $query .= "(" . $attrInfo["max"] . ")"; } } if (in_array("unsigned", $attrInfo)) { $query .= " UNSIGNED "; } if (ereg("CHAR", $attrInfo["type"]) || ereg("TEXT", $attrInfo["type"])) { $query .= " COLLATE utf8_unicode_ci "; } if (!isset($attrInfo["default null"])) { if (isset($attrInfo["default"]) && $attrInfo["type"] != "TEXT") { $query .= " DEFAULT '" . $attrInfo["default"] . "'"; } elseif (!isset($attrInfo["default"]) && $attrInfo["type"] == "VARCHAR") { $query .= " DEFAULT ''"; } elseif (!isset($attrInfo["default"]) && $attrInfo["type"] == "INT" && !in_array("auto increment", $attrInfo)) { $query .= " DEFAULT 0"; } $query .= " NOT NULL"; } if (in_array("auto increment", $attrInfo)) { $query .= " AUTO_INCREMENT"; } } if (isset($typ["primary_key"])) { $query .= DbInstall::getKeySectionForCreateTableQuery($typ["primary_key"], "PRIMARY KEY"); } if (isset($typ["unique_keys"])) { $query .= DbInstall::getKeySectionForCreateTableQuery($typ["unique_keys"], "UNIQUE"); } if (isset($typ["keys"])) { $query .= DbInstall::getKeySectionForCreateTableQuery($typ["keys"], "KEY"); } $query .= " ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; if (in_array("heap", $typ)) { $query .= " TYPE=HEAP"; } if (isset($typ["select"])) { $query .= " " . $typ["select"]; } $query .= ";"; return $query; }