File: 0.02.14a/server/web/firstrun.php (View as Code)

1: 2: require("include.php"); 3: $sn=$_SERVER['SCRIPT_NAME']; 4: $script=""; 5: for ($a=strlen($sn)-1; $a>0; $a--) 6: { 7: $c=$sn[$a]; 8: if ($c=="/") $a=-1; 9: else $script=$c.$script; 10: } 11: if ($script!="firstrun.php") 12: { 13: echo "Error: This script is not correctly named. In order to run it please rename "".$script."" to "firstrun.php"."; 14: echo "

";
15: exit(); 16: } 17: if (isset($_REQUEST['stage'])) $stage=$_REQUEST['stage']; 18: else $stage=0; 19: 20: function sqlfile($file) 21: { 22: global $BaseDir; 23: $fn=$BaseDir."sql/".$file.".sql"; 24: echo "Processing ".$fn."

";
25: $fp=fopen($fn,"r"); 26: if ($fp<=0) 27: { 28: echo "ERROR: Cannot Open File!

";
29: return false; 30: } 31: $q=""; 32: $qc=0; 33: $qok=0; 34: $qerr=0; 35: while ($s=fgets($fp,1024)) 36: { 37: if ($s[0]!="-") 38: { 39: for ($a=0; $a 40: { 41: $c=$s[$a]; 42: if ($c==";") 43: { 44: mysql_query($q); 45: $qc++; 46: if (mysql_errno()!=0) 47: { 48: echo "Warning/Error
";
49: echo "SQL: ".$q."
";
50: echo "Error: ".mysql_error()." (Code ".mysql_errno().")

";
51: $qerr++; 52: } 53: else $qok++; 54: $q=""; 55: } 56: else 57: $q.=$c; 58: } 59: } 60: } 61: echo "Finished Processing: ".$qc." queries (".$qok." ok, ".$qerr." warnings/errors)

";
62: fclose($fp); 63: } 64: 65: echo "

First Run Setup: Stage ".$stage."

";
66: 67: echo "Testing database connectivity...
";
68: $sql=mysql_connect($fnCfg['db.server'],$fnCfg['db.username'],$fnCfg['db.password']) 69: or die("Failed to connect to database server ".$fnCfg['db.server']." with username ".$fnCfg['db.username']."
Details: ".mysql_error());
70: mysql_select_db($fnCfg['db.database']) 71: or die("Connected ok but failed to select database ".$fnCfg['db.database']."
Details: ".mysql_error());
72: echo "Database connection succeeded!

";
73: 74: switch($stage) 75: { 76: case 0: 77: echo "
"; 78: echo ""; 79: echo "Setup Database Schema and Defaults

";
80: echo " Include Example Setup (Recommended)

";
81: echo ""; 82: echo "";
83: exit(); 84: break; 85: 86: case 1: 87: echo "Setting Up Schema...

";
88: sqlfile("schema"); 89: echo "Setting Up Defaults...

";
90: sqlfile("default"); 91: if (isset($_REQUEST['example'])) 92: { 93: echo "Setting Up Examples...

";
94: sqlfile("example"); 95: } 96: echo "

";
97: echo "CONGRATULATIONS!!

";
98: echo "Setup should now be complete. If you saw errors etc above please see the "; 99: echo "project homepage for help.

";
100: echo "RENAME THIS FILE "firstrun.php" TO SOMETHING ELSE LIKE "firstrun-.php" TO STOP OTHERS RUNNING IT"; 101: echo "

";
102: echo "Click here to continue - login admin password admin (click settings once logged in to change)

";
103: 104: 105: exit(); 106: break; 107: 108: default: 109: echo "Sorry - unknown step in setup process!

";
110: exit(); 111: } 112: 113: ?>