Use custom style for buttons
[misc/hallinta-vmail] / user.php
1 <?php
2
3
4 $buttons = <<<EOC
5 <p style="margin-top: 5px; margin-bottom: 4px; text-align: center;">
6 <button class="custom" onclick="return passwd_delete()">Passwort löschen</button>
7 <button class="custom" onclick="return passwd_set()">Passwort setzen</button>
8 </p>
9 EOC;
10
11 $jscode[] = <<<EOC
12 var post_save = user_post_save;
13 var pre_insert = user_pre_save;
14 var pre_save = user_pre_save;
15
16 function user_pre_save()
17 {
18   if ($('edit_username').value == '*' && !$('edit_forward').value.length) {
19     alert("Fehler aufgetreten!\\n\\nFür Catch-All-Einträge muß zwingend\\neine Forward-Adresse angegeben werden.");
20     $('edit_forward').focus();
21     return false;
22   }
23
24   return true;
25 }
26
27 function user_post_save()
28 {
29   grid_update(grid);
30
31   if (!$('edit_id').value.length && !$('edit_forward').value.length)
32     alert("Bitte als nächstes ein Passwort setzen.\\nUnd danach direkt mit Mailprogram aktivieren.");
33 }
34
35 function passwd_delete_callback(data)
36 {
37     grid_update(grid);
38     info('Preis gespeichert');
39 }
40
41 function passwd_delete()
42 {
43     var eid = document.getElementById('edit_id');
44     if (!eid || !eid.value.length) return false;
45
46     var source = document.getElementById('source');
47     if (!source) return false;
48
49     var parms = 'source=' + source.innerHTML + '&callback=delete&';
50     parms += 'id=' + eid.value;
51
52     ajax_request('function', parms, passwd_delete_callback);
53
54     return false;
55 }
56
57 var passwd_popup = false;
58 function passwd_setpw_callback(data)
59 {
60     grid_update(grid);
61     info('Neues Passwort gespeichert');
62 }
63
64 function passwd_setpw()
65 {
66   passwd_popup.closePopup();
67
68   var pw1 = document.getElementById('pw_pass1');
69   var pw2 = document.getElementById('pw_pass2');
70
71   if (!pw1.value.length || !pw2.value.length || pw1.value != pw2.value) {
72     alert("Die Passwörter stimmen nicht überein!");
73     return false;
74   }
75
76   var source = document.getElementById('source');
77   var pw_id = document.getElementById('pw_id');
78   var pw_pass = document.getElementById('pw_pass1');
79
80   var parms = 'source=' + source.innerHTML + '&callback=setpw';
81   parms += '&id=' + pw_id.value;
82   parms += '&passwd=' + pw_pass.value;
83
84   ajax_request('function', parms, passwd_setpw_callback);
85
86   return false;
87 }
88
89 function passwd_set()
90 {
91   var edit_id = document.getElementById('edit_id');
92
93   if (!edit_id.value.length) return false;
94
95   var width = 245;
96   var height = 163;
97
98   if (!passwd_popup) {
99     var options = {hideOnClick: false, canDragFunc: true };
100     passwd_popup = new Rico.Popup(options);
101     passwd_popup.createWindow('<b>Neues Passwort setzen</b>','',height+'px',width+'px');
102     passwd_popup.contentDiv.style.backgroundColor='#e0e0e0';
103     passwd_popup.contentDiv.innerHTML = [
104                                          '<div class="form" style="margin-left: 10px; margin-right: 12px; padding-left: 10px; padding-bottom: 7px;">',
105                                          '<input type="hidden" name="pw_id" id="pw_id">',
106                                          '<label for="pw_email">E-Mail Adresse:</label><br>',
107                                          '<input type="text" name="pw_email" id="pw_email" size="23" readonly>',
108                                          '<div style="height: 5px;"></div>',
109                                          '<label for="pw_pass1">Neues Passwort:</label><br>',
110                                          '<input type="password" name="pw_pass1" id="pw_pass1" size="23">',
111                                          '<div style="height: 5px;"></div>',
112                                          '<label for="pw_pass2">erneut eingeben:</label><br>',
113                                          '<input type="password" name="pw_pass2" id="pw_pass2" size="23">',
114                                          '<div style="height: 5px;"></div>',
115                                          '<button onclick="return passwd_setpw()">Passwort setzen</button>',
116                                          '</div>',
117                                          ].join('');
118   }
119
120   var edit_username = document.getElementById('edit_username');
121   var edit_vmail_domain_id = document.getElementById('edit_vmail_domain_id');
122
123   var pw_id = document.getElementById('pw_id');
124   var pw_email = document.getElementById('pw_email');
125
126   pw_id.value = edit_id.value;
127   pw_email.value = edit_username.value + '@' + edit_vmail_domain_id.options[edit_vmail_domain_id.selectedIndex].innerHTML;
128
129   var x = Math.floor((RicoUtil.windowWidth()-width)/2);
130   var y = Math.floor((RicoUtil.windowHeight()-height)/2);
131   passwd_popup.openPopup(x,y);
132
133   var pw_pass1 = document.getElementById('pw_pass1');
134   pw_pass1.value = '';
135   var pw_pass2 = document.getElementById('pw_pass2');
136   pw_pass2.value = '';
137   pw_pass1.focus();
138
139   return false;
140 }
141 EOC;
142
143 $mask = array(
144               'table' => 'vmail_user',
145               'title' => 'Mailboxen und Weiterleitungen',
146               'join' => array('vmail_domain ON vmail_domain_id = vmail_domain.id'),
147               'list' => array(
148                               'id' => array(
149                                             'name' => 'ID',
150                                             'visible' => false,
151                                             'sql' => 'vmail_user.id',
152                                             ),
153                               'email' => array(
154                                             'name' => 'E-Mail',
155                                             'width' => 330,
156                                             'type' => 'text',
157                                             'sql' => "username || '@' || name",
158                                             'specs' => "filterUI: 't'",
159                                             ),
160                               'forward' => array(
161                                             'name' => 'Forward',
162                                             'width' => 330,
163                                             'specs' => "filterUI: 't'",
164                                             ),
165                               'pw' => array(
166                                             'name' => 'Pass',
167                                             'width' => 40,
168                                             'specs' => "ClassName: 'aligncenter'",
169                                             'control' => "new Rico.TableColumn.checkbox('t', 'f',0,1)",
170                                             'sql' => 'password IS NOT NULL AND length(password) > 0',
171                                             ),
172                               'active' => array(
173                                             'name' => 'on',
174                                             'width' => 40,
175                                             'specs' => "ClassName: 'aligncenter'",
176                                             'control' => "new Rico.TableColumn.checkbox(1, 0,0,1)",
177                                             ),
178                               ),
179               'edit' => array(
180                               'username' => array(
181                                             'name' => 'Usename',
182                                             'type' => 'text',
183                                             'size' => 21,
184                                             'required' => true,
185                                             ),
186                               'vmail_domain_id' => array(
187                                             'name' => 'Domain',
188                                             'type' => 'select',
189                                             'options' => 'SELECT id,name AS text FROM vmail_domain ORDER BY name',
190                                             'option_empty' => '-- select --',
191                                             'required' => true,
192                                             ),
193                               'forward' => array(
194                                             'name' => 'Forward',
195                                             'type' => 'text',
196                                             'size' => 21,
197                                             'null' => true,
198                                             ),
199 /*
200                               'password' => array(
201                                             'name' => 'Passwort',
202                                             'type' => 'passwd',
203                                             'size' => 21,
204                                             'null' => true,
205                                             'func' => 'passwd_encrypt',
206                                             ),
207 */
208                               'active' => array(
209                                             'name' => 'aktiviert',
210                                             'type' => 'boolean',
211                                             ),
212                               'buttons' => array(
213                                             'type' => 'html',
214                                             'code' => $buttons,
215                                             'sql' => false,
216                                             ),
217                               ),
218               'callbacks' => array(
219                                   'delete' => 'cb_delete',
220                                   'setpw' => 'cb_setpw',
221                                   ),
222               );
223
224 function passwd_encrypt($pw)
225 {
226   return md5($pw);
227 }
228
229 function cb_delete()
230 {
231   global $db;
232
233   $sql = sprintf("UPDATE vmail_user SET password = NULL WHERE id = %d", $_POST['id']);
234
235   $sth = $db->query($sql);
236
237   return true;
238 }
239
240 function cb_setpw()
241 {
242   global $db;
243
244   $sql = sprintf("UPDATE vmail_user SET password = '%s' WHERE id = %d",
245                  passwd_encrypt($_POST['passwd']),
246                  $_POST['id']);
247
248   $sth = $db->query($sql);
249
250   return true;
251 }
252
253 ?>