2 define('INSTALLDIR', dirname(__FILE__));
7 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
14 function checkPrereqs()
21 <p>Enter your database connection information below to initialize the database.</p>
22 <form method='post' action='install.php'>
24 <ul class='form_data'>
26 <label for='sitename'>Site name</label>
27 <input type='text' id='sitename' name='sitename' />
28 <p>The name of your site</p>
32 <label for='host'>Hostname</label>
33 <input type='text' id='host' name='host' />
34 <p>Database hostname</p>
37 <label for='host'>Database</label>
38 <input type='text' id='database' name='database' />
42 <label for='username'>Username</label>
43 <input type='text' id='username' name='username' />
44 <p>Database username</p>
47 <label for='password'>Password</label>
48 <input type='password' id='password' name='password' />
49 <p>Database password</p>
52 <input type='submit' name='submit' value='Submit'>
58 function updateStatus($status, $error=false)
74 $host = $_POST['host'];
75 $database = $_POST['database'];
76 $username = $_POST['username'];
77 $password = $_POST['password'];
78 $sitename = $_POST['sitename'];
80 updateStatus("Starting installation...");
81 updateStatus("Checking database...");
82 $conn = mysql_connect($host, $username, $password);
84 updateStatus("Can't connect to server '$host' as '$username'.", true);
88 updateStatus("Changing to database...");
89 $res = mysql_select_db($database, $conn);
91 updateStatus("Can't change to database.", true);
95 updateStatus("Running database script...");
96 $res = runDbScript(INSTALLDIR.'/db/laconica.sql', $conn);
98 updateStatus("Can't run database script.", true);
102 updateStatus("Writing config file...");
103 $sqlUrl = "mysqli://$username:$password@$host/$database";
104 $res = writeConf($sitename, $sqlUrl);
106 updateStatus("Can't write config file.", true);
110 updateStatus("Done!");
116 function writeConf($sitename, $sqlUrl)
118 $res = file_put_contents(INSTALLDIR.'/config.php',
120 "\$config['site']['name'] = \"$sitename\";\n\n".
121 "\$config['db']['database'] = \"$sqlUrl\";\n\n");
125 function runDbScript($filename, $conn)
127 $sql = trim(file_get_contents($filename));
128 $stmts = explode(';', $sql);
129 foreach ($stmts as $stmt) {
131 if (!mb_strlen($stmt)) {
134 $res = mysql_query($stmt, $conn);
135 if ($res === false) {
145 <title>Install Laconica</title>
146 <link rel="stylesheet" type="text/css" href="theme/base/css/display.css?version=0.7.1" media="screen, projection, tv"/>
147 <link rel="stylesheet" type="text/css" href="theme/base/css/modal.css?version=0.7.1" media="screen, projection, tv"/>
148 <link rel="stylesheet" type="text/css" href="theme/default/css/display.css?version=0.7.1" media="screen, projection, tv"/>
154 <h1>Install Laconica</h1>