root/trunk/gui/reseller/orders_add.php

Revision 1408, 7.7 kB (checked in by scitech, 4 days ago)

Add default user with password to statistics

Line 
1 <?php
2 /**
3  * ispCP ω (OMEGA) a Virtual Hosting Control System
4  *
5  * @copyright     2001-2006 by moleSoftware GmbH
6  * @copyright     2006-2008 by ispCP | http://isp-control.net
7  * @version     SVN: $Id$
8  * @link         http://isp-control.net
9  * @author         ispCP Team
10  *
11  * @license
12  *   This program is free software; you can redistribute it and/or modify it under
13  *   the terms of the MPL General Public License as published by the Free Software
14  *   Foundation; either version 1.1 of the License, or (at your option) any later
15  *   version.
16  *   You should have received a copy of the MPL Mozilla Public License along with
17  *   this program; if not, write to the Open Source Initiative (OSI)
18  *   http://opensource.org | osi@opensource.org
19  */
20
21 require '../include/ispcp-lib.php';
22
23 check_login(__FILE__);
24
25 $reseller_id = $_SESSION['user_id'];
26
27 if (isset($_GET['order_id']) && is_numeric($_GET['order_id'])) {
28     $order_id = $_GET['order_id'];
29 } else {
30     set_page_message(tr('Wrong order ID!'));
31     header("Location: orders.php");
32     die();
33 }
34
35 if (Config::exists('HOSTING_PLANS_LEVEL') && Config::get('HOSTING_PLANS_LEVEL') === 'admin') {
36     $query = <<<SQL_QUERY
37     select
38         *
39     from
40         orders
41     where
42             id = ?
43 SQL_QUERY;
44
45     $rs = exec_query($sql, $query, array($order_id));
46 } else {
47     $query = <<<SQL_QUERY
48     select
49         *
50     from
51         orders
52     where
53             id = ?
54         and
55             user_id = ?
56 SQL_QUERY;
57
58     $rs = exec_query($sql, $query, array($order_id, $reseller_id));
59 }
60
61 if ($rs->RecordCount() == 0 || !isset($_SESSION['domain_ip'])) {
62     set_page_message(tr('Permission deny!'));
63     header('Location: orders.php');
64     die();
65 }
66
67 $domain_ip = $_SESSION['domain_ip'];
68 $dmn_user_name = $rs->fields['domain_name'];
69 $dmn_user_name = decode_idna($dmn_user_name);
70
71 $hpid = $rs->fields['plan_id'];
72 $first_name = $rs->fields['fname'];
73 $last_name = $rs->fields['lname'];
74 $firm = $rs->fields['firm'];
75 $zip = $rs->fields['zip'];
76 $city = $rs->fields['city'];
77 $country = $rs->fields['country'];
78 $phone = $rs->fields['phone'];
79 $fax = $rs->fields['fax'];
80 $street_one = $rs->fields['street1'];
81 $street_two = $rs->fields['street2'];
82 $customer_id = $rs->fields['customer_id'];
83 $user_email = $rs->fields['email'];
84 // lets check the reseller limits
85 $err_msg = "";
86
87 if (Config::exists('HOSTING_PLANS_LEVEL') && Config::get('HOSTING_PLANS_LEVEL') === 'admin') {
88     $query = "select props from hosting_plans where id = ?";
89     $res = exec_query($sql, $query, array($hpid));
90 } else {
91     $query = "select props from hosting_plans where reseller_id = ? and id = ?";
92     $res = exec_query($sql, $query, array($reseller_id, $hpid));
93 }
94 $data = $res->FetchRow();
95 $props = $data['props'];
96
97 $_SESSION["ch_hpprops"] = $props;
98
99 if (!reseller_limits_check($sql, $err_msg, $reseller_id, $hpid)) {
100     set_page_message(tr("Order Canceled: resellers maximum exceeded!"));
101     header('Location: orders.php');
102     die();
103 }
104
105 if (!empty($err_msg)) {
106     set_page_message($err_msg);
107     unset($_SESSION['domain_ip']);
108     header('Location: orders.php');
109     die();
110 }
111 unset($_SESSION["ch_hpprops"]);
112 list($php, $cgi, $sub,
113     $als, $mail, $ftp,
114     $sql_db, $sql_user,
115     $traff, $disk) = explode(";", $props);
116
117 $php = preg_replace("/\_/", "", $php);
118 $cgi = preg_replace("/\_/", "", $cgi);
119
120 $timestamp = time();
121 $pure_user_pass = substr($timestamp, 0, 6);
122 $inpass = crypt_user_pass($pure_user_pass);
123
124 if (!chk_dname($dmn_user_name)) {
125     set_page_message(tr('Wrong domain name syntax!'));
126     unset($_SESSION['domain_ip']);
127     header('Location: orders.php');
128     die();
129 }
130 if (ispcp_domain_exists($dmn_user_name, $_SESSION['user_id'])) {
131     set_page_message(tr('Domain with that name already exists on the system!'));
132     unset($_SESSION['domain_ip']);
133     header('Location: orders.php');
134     die();
135 }
136
137 check_for_lock_file();
138
139 $query = <<<ISPCP_SQL_QUERY
140             insert into admin
141                       (
142                         admin_name, admin_pass, admin_type, domain_created,
143                         created_by, fname, lname,
144                         firm, zip, city,
145                         country, email, phone,
146                         fax, street1, street2, customer_id
147                       )
148                 values
149                       (
150                         ?, ?, 'user', unix_timestamp(),
151                         ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
152                       )
153 ISPCP_SQL_QUERY;
154
155 $res = exec_query($sql, $query, array($dmn_user_name, $inpass, $reseller_id, $first_name, $last_name,
156         $firm, $zip, $city, $country, $user_email, $phone, $fax, $street_one, $street_two, $customer_id));
157
158 print $sql->ErrorMsg();
159
160 $record_id = $sql->Insert_ID();
161
162 $query = <<<SQL_QUERY
163     select
164         reseller_ips
165     from
166         reseller_props
167     where
168
169              reseller_id = ?
170 SQL_QUERY;
171
172 $rs = exec_query($sql, $query, array($reseller_id));
173 $domain_ip = $rs->fields['reseller_ips'];
174 $status = Config::get('ITEM_ADD_STATUS');
175
176
177 $query = <<<ISPCP_SQL_QUERY
178             insert into domain (
179                         domain_name, domain_admin_id,
180                         domain_created_id, domain_created,
181                         domain_mailacc_limit, domain_ftpacc_limit,
182                         domain_traffic_limit, domain_sqld_limit,
183                         domain_sqlu_limit, domain_status,
184                         domain_subd_limit, domain_alias_limit,
185                         domain_ip_id, domain_disk_limit,
186                         domain_disk_usage, domain_php, domain_cgi
187                        )
188                 values (
189                         ?, ?,
190                         ?, unix_timestamp(),
191                         ?, ?,
192                         ?, ?,
193                         ?, ?,
194                         ?, ?,
195                         ?, ?, '0',
196                         ?, ?
197                        )
198 ISPCP_SQL_QUERY;
199
200 $res = exec_query($sql, $query, array($dmn_user_name,
201         $record_id,
202         $reseller_id,
203         $mail,
204         $ftp,
205         $traff,
206         $sql_db,
207         $sql_user,
208         $status,
209         $sub,
210         $als,
211         $domain_ip,
212         $disk,
213         $php,
214         $cgi));
215 $dmn_id = $sql->Insert_ID();
216
217 //Add statistics group
218
219 $query = "
220     INSERT INTO `htaccess_users`
221             (dmn_id, uname, upass, status)
222     VALUES
223             (?, ?, ?, ?)
224 ";
225 $rs = exec_query($sql, $query, array($dmn_id, $dmn_name, crypt_user_pass_with_salt($pure_user_pass), $status));
226
227 $user_id = $sql->Insert_ID();
228
229 $awstats_auth = Config::get('AWSTATS_GROUP_AUTH');
230
231 $query = "
232     INSERT INTO `htaccess_groups`
233         (dmn_id, ugroup, members, status)
234     VALUES
235         (?, ?, ?, ?)
236 ";
237 $rs = exec_query($sql, $query, array($dmn_id, $awstats_auth, $user_id, $status));
238
239 // Create the 3 default addresses if wanted
240 if (Config::get('CREATE_DEFAULT_EMAIL_ADDRESSES')) client_mail_add_default_accounts($dmn_id, $user_email, $dmn_user_name); // 'domain', 0
241
242 // ispcp 2.5 feature
243 // add_domain_extras($dmn_id, $record_id, $sql);
244 // lets send mail to user
245 send_add_user_auto_msg ($reseller_id,
246     $dmn_user_name,
247     $pure_user_pass,
248     $user_email,
249     $first_name,
250     $last_name,
251     tr('Domain account')
252     );
253
254 // add user into user_gui_props => domain looser needs language and skin too :-)
255 $user_def_lang = $_SESSION['user_def_lang'];
256 $user_theme_color = $_SESSION['user_theme'];
257
258 $query = <<<SQL_QUERY
259                 insert into
260                   user_gui_props
261                       (user_id, lang, layout)
262                   values
263                       (?, ?, ?)
264 SQL_QUERY;
265
266 $res = exec_query($sql, $query, array($record_id,
267         $user_def_lang,
268         $user_theme_color));
269
270 // send query to the ispcp daemon
271 send_request();
272
273 $admin_login = $_SESSION['user_logged'];
274 write_log("$admin_login: add user: $dmn_user_name (for domain $dmn_user_name)");
275 write_log("$admin_login: add domain: $dmn_user_name");
276
277 au_update_reseller_props($reseller_id, $props);
278 set_page_message(tr('User added!'));
279 $query = <<<SQL_QUERY
280             update
281                 orders
282             set
283                 status=?
284             where
285                 id=?
286 SQL_QUERY;
287 exec_query($sql, $query, array('added', $order_id));
288
289 unset($_SESSION['domain_ip']);
290 header("Location: users.php");
291 die();
292
293 ?>
294
Note: See TracBrowser for help on using the browser.