· 8 years ago · Jul 06, 2018, 10:56 PM
1<?php
2print('<span style="font-size:1.2em">Welcome to the setup for your new Geodatabase </span><br />');
3print(' <br />');
4
5require_once 'config.inc';
6
7function fatal_error($message)
8{
9 die ($message);
10}
11
12
13function create_password()
14{
15 $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
16
17 srand((double)microtime()*1000000);
18
19 $i = 0;
20 $pass = '' ;
21
22 while ($i < 8) {
23 $pass .= $chars[rand() % 62];
24 $i++;
25 }
26 return $pass;
27}
28
29$db = NULL; //mysqli database connection
30
31
32$db = new mysqli($config['db_host'], $config['db_user'], $config['db_password'], $config['db_name']);
33if ($db->connect_error) {
34 $m = 'Connect Error (' . $db->connect_errno . ') ' . $db->connect_error;
35 fatal_error($m);
36 print('Error database connection');
37}
38 else {
39 print("Connected with the Geodatabase {$config['db_name']}<br />
40 Please create the first Admin:<br />");
41 print(' <br />');
42 }
43
44
45if(isset($_GET['submit'])){
46 $error = FALSE;
47 if (!isset($_POST['first_name']) || empty($_POST['first_name'])){
48 print('Missing First name!<br />');
49 $error = true;
50 }
51 if (!isset($_POST['surname']) || empty($_POST['surname'])){
52 print('Missing Surname!<br />');
53 $error = true;
54 }
55 if (!isset($_POST['email']) || empty($_POST['email'])){
56 print('Missing Email!<br />');
57 $error = true;
58 }
59 if (!isset($_POST['function']) || empty($_POST['function'])){
60 print('Missing Function!<br />');
61 $error = true;
62 }
63 if (!isset($_POST['address']) || empty($_POST['address'])){
64 print('Missing Address!<br />');
65 $error = true;
66 }
67 if (!isset($_POST['zip_code']) || empty($_POST['zip_code'])){
68 print('Missing ZIP Code!<br />');
69 $error = true;
70 }
71 if (!isset($_POST['city']) || empty($_POST['city'])){
72 print('Missing City!<br />');
73 $error = true;
74 }
75 if (!isset($_POST['country']) || empty($_POST['country'])){
76 print('Missing Country!<br />');
77 $error = true;
78 }
79 if (!isset($_POST['phone']) || empty($_POST['phone'])){
80 print('Missing Phone!<br />');
81 $error = true;
82 }
83
84 if(!$error){
85
86 $surname = $db->real_escape_string($_POST['surname']);
87 $first_name = $db->real_escape_string($_POST['first_name']);
88 $email = $db->real_escape_string($_POST['email']);
89 $function = $db->real_escape_string($_POST['function']);
90 $address = $db->real_escape_string($_POST['address']);
91 $zip_code = $db->real_escape_string($_POST['zip_code']);
92 $city = $db->real_escape_string($_POST['city']);
93 $country = $db->real_escape_string($_POST['country']);
94 $phone = $db->real_escape_string($_POST['phone']);
95 $user_type = '2';
96
97
98
99 $password = create_password();
100 $password_hash = sha1($password . $config['password_salt']);
101
102
103 print("<span style=\"font-size:1.2em\">Welcome {$_POST['first_name']} {$_POST['surname']}! </span><br />
104
105 Your account information:<br />
106 Email: {$_POST['email']}<br />
107 Function: {$_POST['function']}<br />
108 Address: {$_POST['address']}<br />
109 ZIP Code: {$_POST['zip_code']}<br />
110 City: {$_POST['city']}<br />
111 Country: {$_POST['country']}<br />
112 Phone: {$_POST['phone']}<br />
113 Password: $password<br />");
114 print(' <br />');
115
116 $result = $db->query ("CREATE TABLE IF NOT EXISTS `users` (
117 `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
118 `email` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
119 `password` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
120 `account_type` INT(10) UNSIGNED NOT NULL,
121 `surname` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
122 `first_name` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
123 `function` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
124 `address` VARCHAR(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
125 `zip_code` VARCHAR(8) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
126 `city` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
127 `country` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
128 `phone` VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
129 PRIMARY KEY (`id`)
130 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin");
131
132 $result = $db->query ("INSERT INTO `users` (`email`, `password`, `account_type`, `surname`, `first_name`, `function`, `address`, `zip_code`, `city`, `country`, `phone`)
133 VALUES ('$email', '$password_hash', $user_type, '$surname', '$first_name', '$function', '$address', '$zip_code', '$city', '$country', '$phone')");
134
135 if (!$result){
136 fatal_error('Querry failed');
137 return;
138 }
139 else
140 print('User added!<br />');
141 }
142 else
143 print('Error, please fill in empty forms!');
144
145}
146
147?>
148<form action="setup.php?submit=yes" method="post">
149 <table border="0">
150 <tr><td>Firstname:</td><td><input name="first_name" type="text" size="30" maxlength="256" /></td></tr>
151 <tr><td>Surname:</td><td><input name="surname" type="text" size="30" maxlength="256" /></td></tr>
152 <tr><td>Email:</td><td><input name="email" type="text" size="30" maxlength="128" /></td></tr>
153 <tr><td>Admin:</td><td><input type="checkbox" name="admin" value="2" checked="checked" disabled="disabled" /></td></tr>
154 <tr><td>Function:</td><td><input name="function" type="text" size="30" maxlength="30" /></td></tr>
155 <tr><td>Address:</td><td><input name="address" type="text" size="30" maxlength="40" /></td></tr>
156 <tr><td>ZIP Code:</td><td><input name="zip_code" type="text" size="30" maxlength="8" /></td></tr>
157 <tr><td>City:</td><td><input name="city" type="text" size="30" maxlength="30" /></td></tr>
158 <tr><td>Country:</td><td><input name="country" type="text" size="30" maxlength="30" /></td></tr>
159 <tr><td>Phone:</td><td><input name="phone" type="text" size="30" maxlength="20" /></td></tr>
160 </table>
161 <input type="submit" value="Submit" />
162</form>
163
164<?php
165
166
167?>