root/admin/admin_adduser.php

Revision 212, 5.2 kB (checked in by Nafania, 3 years ago)

--

Line 
1 <?php
2
3 if( !empty($setmodules) )</span>
4 <span class="code-keyword">{
5         $filename = basename(__FILE__);
6         $module['users']['add_user'] = $filename;
7
8         return;
9 }
10
11 define('IN_PHPBB', 1);
12
13 $root_path = './../';</span>
14 <span class="code-lang">require($root_path . 'extension.inc');
15 require('./pagestart.' . $phpEx);
16 require($root_path . "include/functions_check.php");
17 require($root_path . 'include/functions_selects.'.$phpEx);
18
19 $html_entities_match = array('#<#', '#>#');
20 $html_entities_replace = array('&lt;', '&gt;');</span>
21 <span class="code-lang">
22 if (isset( $_POST['submit'] ) ) {
23
24     foreach (array('wantusername','wantpassword','passagain','gender','year', 'month', 'day', 'download', 'upload', 'country', 'email') as $x) {
25         if(isset($_POST["$x"])) {
26             $$x = request_var($x, '');
27         }
28     }
29
30     if ( !isset($wantusername) || !isset($wantpassword) || !isset($gender) || !isset($country)) {
31         trigger_error($lang['dont_empty_fields'], E_USER_WARNING);
32     }
33     if ($wantpassword != $passagain) {
34         trigger_error($lang['passwords_not_the_same'], E_USER_WARNING);
35     }
36
37     if (strlen($wantpassword) < 6 || strlen($wantpassword) > 40) {
38         trigger_error($lang['pass_too_long'], E_USER_WARNING);
39     }
40
41     if ($wantpassword == $wantusername) {
42         trigger_error($lang['pass_and_username_are_the_same'], E_USER_WARNING);
43     }
44
45     if ($error = check_email($email)) {
46         trigger_error($error['error_msg'], E_USER_WARNING);
47     }
48
49     if ( !check_internet_speed($upload) || !check_internet_speed($download) ) {
50         trigger_error($lang['speed_invalid'], E_USER_WARNING);
51     }
52
53     if ($error = check_username($wantusername)) {
54         trigger_error($error['error_msg'], E_USER_WARNING);
55     }
56
57     if ( !check_internet_speed($upload) || !check_internet_speed($download) ) {
58         trigger_error($lang['speed_invalid'], E_USER_WARNING);
59     }
60
61     $gender = ( $gender ? 1 : 0 );
62
63     $country = intval($country);
64
65     if ( !checkdate($month, $day, $year) ) {
66         trigger_error($lang['birthday_invalid'], E_USER_WARNING);
67     }
68     $birthday = $year . '-' . $month . '-' . $day;
69
70     $secret = mksecret();
71     $wantpasshash = md5($secret . $wantpassword . $secret);
72
73     $torrent_pass = md5($wantusername . time() . $wantpasshash);
74
75     $user_limit_ary_torrents = unserialize($config['user_limit_ary_torrents']);
76     $user_limit_ary_allow_download = unserialize($config['user_limit_ary_allow_download']);
77
78     $result = $db->sql_query('SELECT MAX(uid) AS max_uid FROM ' . USERS_TABLE);
79      $id = ( $row = $db->sql_fetchrow($result) ) ? intval($row['max_uid']) + 1 : 1;
80
81     //now we generate insert sql
82     $sql_ary = array('uid' => $id,
83             'name'       => $wantusername,
84              'pass'       => $wantpasshash,
85              'secret'     => $secret,
86              'email'      => $email,
87              'country'    => $country,
88              'torrent_pass' => $torrent_pass,
89              'status'     => 1,
90              'added'      => time(),
91              'upload'     => $upload,
92              'download'   => $download,
93              'gender'     => $gender,
94              'birthday'   => $birthday,
95              'user_style' => $config['default_style'],
96              'language'   => $config['default_lang'],
97              'tzoffset'   => doubleval($config['board_timezone']),
98              'user_dst'   => $config['board_dst'],
99              'can_leech'      => ( isset($user_limit_ary_allow_download[UC_USER]) ? 1 : 0 ),
100              'torrents_limit' => $user_limit_ary_torrents[UC_USER]
101     );
102
103     $db->sql_query('INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
104     $id = $db->sql_nextid();
105     $db->sql_query('INSERT INTO ' . GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', array('group_name'    => '',
106                                               'group_description' => 'Personal User',
107                                               'group_single_user' => 1,
108                                               'group_moderator'   => 0)));
109     $group_id = $db->sql_nextid();
110     $db->sql_query('INSERT INTO ' . USER_GROUP_TABLE . ' ' . $db->sql_build_array('INSERT', array('user_id'    => $id,
111                                                   'group_id' => $group_id,
112                                                   'user_pending' => 0)));
113     $db->sql_query('INSERT INTO ' . USER_GROUP_TABLE . ' ' . $db->sql_build_array('INSERT', array('user_id'    => $id,
114                                                   'group_id' => $phpbb_class[UC_USER],
115                                                   'user_pending' => 0)));
116     $message = $lang['add_user_sucefully'];
117     $message .= '<br /><br />' . sprintf($lang['click_return_useradmin'], '<a href="' . append_sid("admin_adduser.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
118     trigger_error($message);
119     return;
120 }
121
122 else {
123     $template->set_filenames(array(
124         "body" => "../admin/user_add_body.tpl")
125     );
126
127     $downloadspeed = generate_internet_speed(0, 'download');
128     $uploadspeed = generate_internet_speed(0, 'upload');
129     $countries = countries_select(0);
130     $birthday_select = birthday_select();
131
132     $template->assign_vars(array(
133         'S_PROFILE_ACTION' => append_sid("admin_adduser.$phpEx"),
134         'L_PASSAGAIN' => $lang['change_pass_again'],
135         'L_PASS_DESCR' => $lang['password_descr'],
136         'L_MALE' => $lang['gender_male'],
137         'L_FEMALE' => $lang['gender_female'],
138         'BIRTHDAY_SELECT' => $birthday_select,
139         'L_UPLOAD_SPEED' => $lang['internet_speed_upload'],
140         'UPLOAD_SPEED_SELECT' => $uploadspeed,
141         'L_DOWNLOAD_SPEED' => $lang['internet_speed_download'],
142         'DOWNLOAD_SPEED_SELECT' => $downloadspeed,
143         'COUNTRY_SELECT' => $countries)
144     );
145     $template->display('body');
146 }
147
148 ?>
Note: See TracBrowser for help on using the browser.