<?php
/**************************************************************************
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
@Authors: Ryan Thompson(hide@address.com)
***************************************************************************/
$service['no_session'] = TRUE;
require('../config.inc.php');
if(isset($_POST['save_settings']))
{
$user_id = mt_rand(100000, 999999);
$username = $_POST['username'];
$password = md5(md5($_POST['password']));
$fn = $_POST['firstname'];
$ln = $_POST['lastname'];
$now = date('U');
$scheme = $_POST['scheme'];
$db->query("INSERT INTO o_users (user_id, username, firstname, lastname, password, date_created) VALUES
('$user_id','$username','$fn','$ln','$password','$now')");
$db->query("SELECT * FROM o_preferences WHERE user_id='1'");
$i = 0;
while($db->fetch_results())
{
//If I remove the $i does this crash. Earliers errors brought this up.
$prefs[$i] = $db->record;
$i++;
}
$i = 0;
while($i < count($prefs))
{
$root_user = $db->query("INSERT INTO o_preferences (service, user_id, preference, value)
VALUES ('". $prefs[$i]['service'] ."','$user_id','". $prefs[$i]['preference'] ."',
'". $prefs[$i]['value']."')");
$i++;
}
$db->query("SELECT scheme_link FROM o_themes WHERE theme_id='{$_POST['theme']}'");
$db->fetch_results();
$scheme = $db->record['scheme_link'];
$db->query("UPDATE o_preferences SET value='$scheme' WHERE user_id='$user_id'
AND preference='scheme' AND service='gl'");
$db->query("UPDATE o_preferences SET value='$_POST[theme]' WHERE user_id='$user_id'
AND preference='theme' AND service='gl'");
$db->query("SELECT code FROM o_services");
$i = 0;
while($db->fetch_results())
{
$services[$i] = $db->record;
$i++;
}
$i = 0;
while($i < count($services))
{
$user_rights = $db->query("INSERT INTO o_user_rights (user_id, service, rights)
VALUES ('$user_id','". $services[$i][code] ."','3')");
$i++;
}
$now = date('U');
$sql = "INSERT INTO o_user_security (user_id, disabled, expire_type, password_expire, password_change)
VALUES ('$user_id', NULL, 'days', '365', '$now')";
$db->query($sql);
$sql = "INSERT INTO o_tracker (user_id, last_action, last_action_time) VALUES
('$user_id','Account Created','$now')";
$db->query($sql);
//$lines = file ($root_dir ."/services");
$db->query("SELECT * FROM o_home_layout WHERE user_id='1'");
$i = 0;
while($db->fetch_results())
{
$data[$i] = $db->record['service'];
$i++;
}
$i = 0;
while($i < count($data))
{
$db->query("INSERT INTO o_home_layout (user_id, position, service) VALUES ('$user_id', '$i','$data[$i]')");
$i++;
}
header('Location: general_config.php');
//echo "<p class=\"general\">$username has been setup as an administrator with default preferences. <a href=\"../index.php\">Click here to continue</a>";
} else {
?>
<html>
<head>
<title>OpenSource GroupWare Setup</title>
<link rel="stylesheet" type="text/css" href="config.css">
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="setup_root" onSubmit="return check_password(this)">
<table width="700" cellpadding="1" cellspacing="0" style="border: 1px solid #FFFFFF; background: #336699;" align="center">
<table width="700" align="center" style="border: 1px solid #FFFFFF; background: #336699;">
<tr>
<td class="header" style="text-align:right;padding:0px" valign="top" colspan="3">
<?php echo OSGW_NAME?> - Administrator Account <a href="<?php echo HOME?>">
<img src="../osgw/graphics/o.png" border="0" align="top"></a>
</td>
</tr>
<tr>
<td width="150" class="caption">Administrator Username:</td>
<td class="input"><input type="text" value="root" name="username" size="25"></td>
</tr>
<tr>
<td class="caption" width="150">Password:</td>
<td class="input"><input type="password" value="" name="password" size="25"><br></td>
</tr>
<tr>
<td class="caption">Confirm Password:</td>
<td class="input"><input type="password" value="" name="confirm_password" size="25"></td>
</tr>
<tr>
<td class="caption">Firstname:</td>
<td class="input"><input type="text" value="" name="firstname" size="25">
</tr>
<tr>
<td class="caption">Lastname </td>
<td class="input"><input type="text" name="lastname" size="25"> </td>
</tr>
<tr>
<td class="caption">Theme:</td>
<td class="input">
<select name="theme">
<?php
$db->query("SELECT * FROM o_themes");
while($db->fetch_results())
{
echo "<option value=\"". $db->record['theme_id'] ."\">". $db->record['name'] ."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td><input type="submit" name="save_settings" value="Save Settings" class="button"></td>
<td><input type="reset" name="reset" value="Reset" class="button"></td>
</tr>
</table>
</form>
<?php
}
?>