source: trunk/Modules/User/Options.php

Last change on this file was 893, checked in by chronos, 21 months ago
  • Fixed: Class types casting for better type checking.
  • Fixed: XML direct export.
  • Modified: User class instance moved from Core class to ModuleUser class.
File size: 6.9 KB
Line 
1<?php
2
3class PageUserOptions extends Page
4{
5 function UserOptionsFrom()
6 {
7 $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
8 $Output = '<form action="'.$this->System->Link('/options/?action=save').'" method="post">
9 <fieldset><legend>'.T('User settings').'</legend>
10 <table>
11 <tr><td>'.T('E-mail').':</td><td><input type="text" name="Email" value="'.$User->Email.'" /></td></tr>
12 <tr><td>'.T('Original password').':</td><td><input type="password" name="OldPass" /></td></tr>
13 <tr><td>'.T('New password').':</td><td><input type="password" name="NewPass" /></td></tr>
14 <tr><td>'.T('New password confirmation').': </td><td><input type="password" name="NewPass2" /></td></tr>
15 <tr><td>'.T('I will translate normally to').': </td><td>'.WriteLanguages($User->Language).'</td></tr>
16 <tr><td>'.T('After save translation redirect to').': </td><td>';
17 $Output .= '<select name="redirecting">'.
18 '<option value="0">'.T('Nowhere').'</option>'.
19 '<option value="1"';
20 if ($User->Redirecting == '1') $Output .= ' selected="selected"';
21 $Output .= '>'.T('To untranslated').'</option>';
22 $Output .= '<option value="2"';
23 if ($User->Redirecting == '2') $Output .= ' selected="selected"';
24 $Output .= '>'.T('To next translation').'</option>';
25 $Output .= '<option value="3"';
26 if ($User->Redirecting == '3') $Output .= ' selected="selected"';
27 $Output .= '>'.T('To previous translation').'</option>';
28 $Output .= '</select>';
29
30 $Output .= '</td></tr>'.
31 '<tr><td>'.T('Preferred client version').': </td><td>'.ClientVersionSelection($User->PreferredVersion).'</td></tr>'.
32 '<tr><td>'.T('Public profile text').':</td><td>'.
33 '<textarea name="info" cols="60" rows="10">'.htmlspecialchars($User->Info).'</textarea></td></tr>';
34
35 $Output .= '<tr><td>';
36 $Query = 'SELECT * FROM UserTagType';
37 $DbResult = $this->Database->query($Query);
38 $Output .= T('User obey selected rules').':</td><td>';
39 while ($UserTag = $DbResult->fetch_array())
40 {
41 $Query = 'SELECT * FROM `UserTag` '.
42 //'LEFT JOIN `UserTagType` ON `UserTagType`.`ID` = `UserTag`.`UserTagType` '.
43 'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($User->Id * 1);
44 $DbResult2 = $this->Database->query($Query);
45 if ($DbResult2->num_rows != 0) $checked = true;
46 else $checked = false;
47
48 $Output .= CheckBox('Tag'.$UserTag['ID'], $checked, 'CheckBox');
49 $Output .= ''.$UserTag['Text'].'<br />';
50 }
51 $Output .= '</td></tr>';
52
53 $Output .= '<tr><td colspan="2"><input type="submit" value="'.T('Save').'" /></td></tr>'.
54 '</table></fieldset>'.
55 '</form>';
56
57 $Output .= '<fieldset><legend>'.T('Translation team').'</legend>';
58 $DbResult = $this->Database->query('SELECT `Id`, `Name` FROM `Team`');
59 $Output .= '<a href="'.$this->System->Link('/team/?action=create').'">'.T('Create team').'</a><br />'.
60 '<a href="'.$this->System->Link('/team/?action=leave').'">'.T('Leave team').'</a><br />'.
61 '<br /><form action="'.$this->System->Link('/team/').'" method="get">'.
62 '<input type="hidden" name="action" value="gointeam"/>'.
63 '<select name="id">';
64 while ($LineTeam = $DbResult->fetch_assoc())
65 {
66 $Output .= '<option value="'.$LineTeam['Id'].'"';
67 if ($LineTeam['Id'] == $User->Team) $Output .= ' selected="selected"';
68 $Output .= '>'.htmlspecialchars($LineTeam['Name']).'</option>';
69 }
70 $Output .= '</select>'.
71 '<input type="submit" value="'.T('Enter').'" />'.
72 '</form>';
73 '</fieldset>';
74 return $Output;
75 }
76
77 function UserOptionsSave()
78 {
79 $Output = '';
80 $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
81 if (array_key_exists('Email', $_POST))
82 {
83 $Email = $_POST['Email'];
84 $OldPass = $_POST['OldPass'];
85 $NewPass = $_POST['NewPass'];
86 $NewPass2 = $_POST['NewPass2'];
87 $Language = $_POST['Language'];
88 $Redirecting = $_POST['redirecting'];
89 $PreferredVersion = $_POST['ClientVersion'];
90 if ($PreferredVersion == '') $PreferredVersion = null;
91 $Info = $_POST['info'];
92
93 // Do user want to change password?
94 if (($OldPass != '') or ($NewPass != '') or ($NewPass2 != ''))
95 {
96 if ($NewPass == $NewPass2)
97 {
98 $DbResult = $this->System->Database->query('SELECT `Pass`, '.$User->CryptPasswordSQL('"'.$OldPass.'"', '`Salt`').' AS `Hash` FROM `User` WHERE `ID`= '.$User->Id);
99 $DbRow = $DbResult->fetch_assoc();
100 if ($DbRow['Hash'] == $DbRow['Pass'])
101 {
102 // Update password
103 $Salt = $User->GetPasswordSalt();
104 $this->Database->query('UPDATE `User` SET `Pass` = '.$User->CryptPasswordSQL('"'.$NewPass.'"', '"'.$Salt.'"').', `Salt`="'.$Salt.'" WHERE `ID` = '.$User->Id);
105 $Output .= ShowMessage('Heslo změněno.');
106 } else $Output .= ShowMessage('Staré heslo neodpovídá.', MESSAGE_CRITICAL);
107 } else $Output .= ShowMessage('Hesla se neshodují.', MESSAGE_CRITICAL);
108 }
109 //tag
110 $Query = 'SELECT * FROM UserTagType';
111 $DbResult = $this->Database->query($Query);
112 while ($UserTag = $DbResult->fetch_array())
113 {
114 if (array_key_exists('Tag'.$UserTag['ID'], $_POST))
115 {
116 $Query = 'SELECT * FROM `UserTag` '.
117 'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($User->Id * 1);
118 $DbResult2 = $this->Database->query($Query);
119 if ($DbResult2->num_rows == 0)
120 {
121 $Query = 'INSERT INTO `UserTag` (`ID` ,`UserTagType`,`User` ) '.
122 'VALUES (NULL, '.$UserTag['ID'].' , '.($User->Id * 1).')';
123 $DbResult2 = $this->Database->query($Query);
124 }
125 } else
126 {
127 $Query = 'DELETE FROM `UserTag` '.
128 'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($User->Id * 1);
129 $DbResult2 = $this->Database->query($Query);
130 }
131 }
132
133 $this->Database->update('User', '`ID` = '.$User->Id, array('Email' => $Email,
134 'Language' => $Language, 'Redirecting' => $Redirecting, 'Info' => $Info,
135 'PreferredVersion' => $PreferredVersion));
136 $Output .= ShowMessage('Úprava nastavení proběhla v pořádku, Email: <b>'.$Email.'</b> Uživatel: <b>'.$User->Name.'</b>');
137 $this->System->ModuleManager->Modules['Log']->WriteLog('Úprava nastavení!', LOG_TYPE_USER);
138 $User->Load();
139 } else $Output .= ShowMessage('Nezadány údaje.', MESSAGE_CRITICAL);
140 return $Output;
141 }
142
143 function Show(): string
144 {
145 $this->Title = T('User settings');
146 $Output = '';
147 $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
148 if ($User->Licence(LICENCE_USER))
149 {
150 if (array_key_exists('action', $_GET) and ($_GET['action'] == 'save'))
151 {
152 $Output .= $this->UserOptionsSave();
153 }
154 $Output .= $this->UserOptionsFrom();
155 } else $Output .= ShowMessage('Nejste přihlášený.', MESSAGE_CRITICAL);
156 return $Output;
157 }
158}
Note: See TracBrowser for help on using the repository browser.