1 | <?php
|
---|
2 |
|
---|
3 | class PageUserRegistration extends Page
|
---|
4 | {
|
---|
5 | function ShowForm()
|
---|
6 | {
|
---|
7 | if(array_key_exists('sc', $_POST)) $Human = true;
|
---|
8 | else $Human = false;
|
---|
9 | if(array_key_exists('user', $_POST)) $UserName = $_POST['user'];
|
---|
10 | else $UserName = '';
|
---|
11 | if(array_key_exists('Email', $_POST)) $Email = $_POST['Email'];
|
---|
12 | else $Email = '';
|
---|
13 | if(array_key_exists('Team', $_POST)) $Team = $_POST['Team'];
|
---|
14 | else $Team = '';
|
---|
15 | if(array_key_exists('Language', $_POST)) $Language = $_POST['Language'];
|
---|
16 | else $Language = 1;
|
---|
17 |
|
---|
18 | $Output = '<form action="?" method="post" class="Form">
|
---|
19 | <fieldset><legend>'.T('New user registration').'</legend>
|
---|
20 | <table>
|
---|
21 | <tr><td colspan="2">'.T('Please read carefully <a href="'.$this->System->Link('/info/').'">translation guidelines</a> and follow them. Translate with diacritics!').'<br/><br/></td></tr>
|
---|
22 | <tr>
|
---|
23 | <th class="Left">'.T('Are you human?').'</th>';
|
---|
24 | if($Human) $Checked = ' checked="checked"';
|
---|
25 | else $Checked = '';
|
---|
26 | $Output .= '<td><input type="checkbox" name="sc" '.$Checked.'/></td>
|
---|
27 | </tr>
|
---|
28 | <tr>
|
---|
29 | <th class="Left">'.T('Name:').'</th>
|
---|
30 | <td><input type="text" name="user" value="'.$UserName.'"/></td>
|
---|
31 | </tr>
|
---|
32 | <tr>
|
---|
33 | <th class="Left">'.T('Password:').'</th>
|
---|
34 | <td><input type="password" name="pass" /></td>
|
---|
35 | </tr>
|
---|
36 | <tr>
|
---|
37 | <th class="Left">'.T('Password confirmation:').'</th>
|
---|
38 | <td><input type="password" name="pass2" /></td>
|
---|
39 | </tr>
|
---|
40 | <tr>
|
---|
41 | <th class="Left">'.T('E-mail:').'</th>
|
---|
42 | <td><input type="text" name="Email" value="'.$Email.'"/></td>
|
---|
43 | </tr>
|
---|
44 | <tr>
|
---|
45 | <th class="Left">'.T('I will translate normally to:').'</th>
|
---|
46 | <td>'.WriteLanguages($Language).'</td>
|
---|
47 | </tr>
|
---|
48 | <tr>
|
---|
49 | <th class="Left">'.T('I belong to team:').'</th>';
|
---|
50 | if($Team == '') $Selected = ' selected="selected"';
|
---|
51 | else $Selected = '';
|
---|
52 | $Output .= '<td><select name="Team"><option value="0"'.$Selected.'>'.T('none').'</option>';
|
---|
53 | $DbResult = $this->Database->query('SELECT `Name`, `Id` FROM `Team`');
|
---|
54 | while($Line = $DbResult->fetch_assoc())
|
---|
55 | {
|
---|
56 | if($Team == $Line['Id']) $Selected = ' selected="selected"';
|
---|
57 | else $Selected = '';
|
---|
58 | $Output .= '<option value="0'.$Line['Id'].'"'.$Selected.'>'.$Line['Name'].'</option>';
|
---|
59 | }
|
---|
60 | $Output .= '</select>';
|
---|
61 | $Output .= '</td></tr>'.
|
---|
62 | '<tr><th class="Left">'.T('Preferred client version:').'</th><td>'.ClientVersionSelection('').'</td></tr>';
|
---|
63 |
|
---|
64 | $Query = 'SELECT * FROM UserTagType';
|
---|
65 | $DbResult = $this->Database->query($Query);
|
---|
66 | $Output .= '<tr><th class="Left">'.
|
---|
67 | T('Select rules which you will apply during translation:').'</th><td>';
|
---|
68 | while ($UserTag = $DbResult->fetch_array())
|
---|
69 | {
|
---|
70 | $checked = false;
|
---|
71 |
|
---|
72 | $Output .= CheckBox('Tag'.$UserTag['ID'], $checked, 'CheckBox');
|
---|
73 | $Output .= ''.$UserTag['Text'].'<br />';
|
---|
74 | }
|
---|
75 | $Output .= '</td></tr>';
|
---|
76 |
|
---|
77 | $Output .= '<tr>
|
---|
78 | <th colspan="2" class="Center"><input type="submit" value="'.T('Register').'" /></th>
|
---|
79 | </tr>
|
---|
80 | </table></fieldset></form>';
|
---|
81 | return($Output);
|
---|
82 | }
|
---|
83 |
|
---|
84 | function CheckRegistration()
|
---|
85 | {
|
---|
86 | global $Config;
|
---|
87 |
|
---|
88 | $Output = '';
|
---|
89 | $ShowForm = true;
|
---|
90 |
|
---|
91 | if(array_key_exists('user', $_POST)) $UserName = $_POST['user'];
|
---|
92 | else $UserName = '';
|
---|
93 | if(array_key_exists('pass', $_POST)) $Pass = $_POST['pass'];
|
---|
94 | else $Pass = '';
|
---|
95 | if(array_key_exists('pass2', $_POST)) $Pass2 = $_POST['pass2'];
|
---|
96 | else $Pass2 = '';
|
---|
97 | if(array_key_exists('Email', $_POST)) $Email = $_POST['Email'];
|
---|
98 | else $Email = '';
|
---|
99 | if(array_key_exists('Team', $_POST)) $Team = $_POST['Team'] * 1;
|
---|
100 | else $Team = '';
|
---|
101 | if(array_key_exists('Language', $_POST)) $Language = $_POST['Language'] * 1;
|
---|
102 | else $Language = '';
|
---|
103 | if(array_key_exists('ClientVersion', $_POST)) $PreferredVersion = $_POST['ClientVersion'] * 1;
|
---|
104 | else $PreferredVersion = '';
|
---|
105 | if($PreferredVersion == '') $PreferredVersion = 'NULL';
|
---|
106 | if(array_key_exists('sc', $_POST)) $SpamCheck = $_POST['sc'];
|
---|
107 | else $SpamCheck = '';
|
---|
108 |
|
---|
109 | if($SpamCheck != '')
|
---|
110 | {
|
---|
111 | if(($UserName != '') and ($Pass != '') and ($Pass2 != ''))
|
---|
112 | {
|
---|
113 | if(!in_array(strtolower($UserName), $Config['ForbiddedUserNames']))
|
---|
114 | {
|
---|
115 | if($Pass == $Pass2)
|
---|
116 | {
|
---|
117 | $DbResult = $this->Database->query('SELECT * FROM `User` WHERE LOWER(`Name`) = LOWER("'.$UserName.'")');
|
---|
118 | $Line = $DbResult->fetch_row();
|
---|
119 | if(!$Line)
|
---|
120 | {
|
---|
121 | if($Team == 0) $Team = 'NULL';
|
---|
122 | $this->System->User->Register($UserName, $Pass, $Email, $Language, $Team, $PreferredVersion);
|
---|
123 | $Output .= ShowMessage(T('Registration was successful'));
|
---|
124 | $Output .= 'Přečtěte si pozorně <a href="'.$this->System->Link('/info/').'">pokyny pro překladání</a> a můžete pak hned začít překládat.';
|
---|
125 | $this->System->User->Login($UserName, $Pass);
|
---|
126 | $this->System->ModuleManager->Modules['Log']->WriteLog('Uživatel se zaregistroval: '.$UserName, LOG_TYPE_USER);
|
---|
127 | $ShowForm = false;
|
---|
128 |
|
---|
129 | // User tags
|
---|
130 | $Query = 'SELECT * FROM `UserTagType`';
|
---|
131 | $DbResult = $this->Database->query($Query);
|
---|
132 | while ($UserTag = $DbResult->fetch_array()) {
|
---|
133 | if (array_key_exists('Tag'.$UserTag['ID'], $_POST)) {
|
---|
134 | $Query = 'SELECT * FROM `UserTag` '.
|
---|
135 | 'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
|
---|
136 | $DbResult2 = $this->Database->query($Query);
|
---|
137 | if ($DbResult2->num_rows == 0) {
|
---|
138 | $Query = 'INSERT INTO `UserTag` (`ID` ,`UserTagType`,`User` ) '.
|
---|
139 | 'VALUES (NULL, '.$UserTag['ID'].' , '.($this->System->User->Id * 1).')';
|
---|
140 | $DbResult2 = $this->Database->query($Query);
|
---|
141 | }
|
---|
142 | } else {
|
---|
143 | $Query = 'DELETE FROM `UserTag` '.
|
---|
144 | 'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
|
---|
145 | $DbResult2 = $this->Database->query($Query);
|
---|
146 | }
|
---|
147 | }
|
---|
148 | } else $Output = ShowMessage('Uživatel se zadanou přezdívkou již existuje.', MESSAGE_CRITICAL);
|
---|
149 | } else $Output = ShowMessage('Hesla se neshodují.', MESSAGE_CRITICAL);
|
---|
150 | } else $Output = ShowMessage('To jméno uživatele nemůžete použít.', MESSAGE_CRITICAL);
|
---|
151 | } else $Output = ShowMessage('Nelze použít prázdné jméno nebo heslo.', MESSAGE_CRITICAL);
|
---|
152 | } else $Output = ShowMessage('Nejsi člověk. Strojům není dovoleno se registrovat.', MESSAGE_CRITICAL);
|
---|
153 |
|
---|
154 | if($ShowForm) $Output .= $this->ShowForm();
|
---|
155 | return($Output);
|
---|
156 | }
|
---|
157 |
|
---|
158 | function Show()
|
---|
159 | {
|
---|
160 | $this->Title = T('User registration');
|
---|
161 | $Output = '';
|
---|
162 | if(array_key_exists('user', $_POST))
|
---|
163 | {
|
---|
164 | $Output .= $this->CheckRegistration();
|
---|
165 | } else $Output .= $this->ShowForm();
|
---|
166 | return($Output);
|
---|
167 | }
|
---|
168 | }
|
---|