Updates for new Hallinta and aliases
[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_set()">Passwort setzen</button>
7 </p>
8 EOC;
9
10 $jscode = <<<EOC
11 function user_pre_save()
12 {
13   if ($('#edit_username').val() == '*') {
14     alert("Fehler aufgetreten!\\nCatch-All-Einträge sind nur bei Weiterleitungen zulässig.");
15     $('#edit_username').focus();
16     return false;
17   }
18
19   return true;
20 }
21
22 function user_post_insert(data)
23 {
24     Hallinta.showMsg("Bitte als nächstes ein Passwort setzen die Mailbox direkt mit Mailprogram aktivieren.", {timeout: 10});
25 }
26
27 var passwd_popup = false;
28 function passwd_setpw()
29 {
30     passwd_popup.closePopup();
31
32     if (!$('#pw_pass1').val().length || !$('#pw_pass2').val().length || $('#pw_pass1').val() != $('#pw_pass2').val()) {
33         alert("Die Passwörter stimmen nicht überein!");
34         return false;
35     }
36
37     var parms = 'callback=setpw';
38     parms += '&id=' + $('#pw_id').val();
39     parms += '&passwd=' + $('#pw_pass1').val();
40
41     ajax_request('function', parms, function(data){
42         info('Passwort gespeichert');
43         Hallinta.showMsg('Neues Passwort gespeichert', {timeout: 3});
44     });
45
46     return false;
47 }
48
49 function passwd_set()
50 {
51     if (!$('#edit_id').val().length) return false;
52
53     var width = 245;
54     var height = 163;
55     var centerDialog = false;
56
57     if (!passwd_popup) {
58         passwd_popup = new Rico.Window('<b>Neues Passwort setzen</b>', {zIndex: 100});
59         $(passwd_popup.contentDiv).html([
60             '<div class="form" style="margin-left: 10px; margin-right: 12px; padding-left: 10px; padding-bottom: 7px;">',
61             '<input type="hidden" name="pw_id" id="pw_id">',
62             '<label for="pw_email">E-Mail Adresse:</label><br>',
63             '<input type="text" name="pw_email" id="pw_email" size="23" readonly style="background:#eee;">',
64             '<div style="height: 5px;"></div>',
65             '<label for="pw_pass1">Neues Passwort:</label><br>',
66             '<input type="password" name="pw_pass1" id="pw_pass1" size="23">',
67             '<div style="height: 5px;"></div>',
68             '<label for="pw_pass2">erneut eingeben:</label><br>',
69             '<input type="password" name="pw_pass2" id="pw_pass2" size="23">',
70             '<div style="height: 5px;"></div>',
71             '<button onclick="return passwd_setpw()">Passwort setzen</button>',
72             '</div>',
73         ].join(''));
74         centerDialog = true;;
75     }
76
77     $('#pw_id').val($('#edit_id').val());
78     $('#pw_email').val($('#edit_username').val() + '@' + $('#edit_vmail_domain_id option[value="'+$('#edit_vmail_domain_id').val()+'"]').text());
79
80     $('#pw_pass1').val('');
81     $('#pw_pass2').val('');
82
83     if (centerDialog)
84         passwd_popup.centerPopup();
85     else
86         passwd_popup.openPopup();
87
88     $('#pw_pass1').focus();
89     return false;
90 }
91
92 EOC;
93 JavaScript::instance()->add($jscode);
94 JavaScript::instance()->add("Hallinta.preSave = user_pre_save;");
95 JavaScript::instance()->add("Hallinta.preInsert = user_pre_save;");
96 JavaScript::instance()->add("Hallinta.postInsert = user_post_insert;");
97 JavaScript::instance()->add("Hallinta.fetchItemAfterInsert = true;");
98
99 $mask = array(
100               'table' => 'vmail_user',
101               'title' => 'Mailboxen und Adressen',
102               'join' => array('vmail_domain ON vmail_domain_id = vmail_domain.id'),
103               'list' => array(
104                               'id' => array(
105                                             'name' => 'ID',
106                                             'visible' => false,
107                                             'sql' => 'vmail_user.id',
108                                             ),
109                               'name' => array(
110                                             'name' => 'Domain',
111                                             'visible' => false,
112                                             'width' => 200,
113                                             'type' => 'text',
114                                             'filter' => 's',
115                                             ),
116                               'username' => array(
117                                             'name' => 'Username',
118                                             'visible' => false,
119                                             'width' => 200,
120                                             'type' => 'text',
121                                             'filter' => 't',
122                                             ),
123                               'email' => array(
124                                             'name' => 'E-Mail',
125                                             'width' => 400,
126                                             'type' => 'text',
127                                             'filter' => 't',
128                                             'sql' => "username || '@' || name",
129                                             ),
130                               'active' => array(
131                                             'name' => 'aktiv',
132                                             'width' => 60,
133                                             'specs' => array('ClassName' => 'aligncenter'),
134                                             'control' => "new Rico.TableColumn.checkbox(1,0,0,1)",
135                                             ),
136                               ),
137               'edit' => array(
138                               'username' => array(
139                                             'name' => 'Usename',
140                                             'type' => 'text',
141                                             'size' => 21,
142                                             'required' => true,
143                                             ),
144                               'vmail_domain_id' => array(
145                                             'name' => 'Domain',
146                                             'type' => 'select',
147                                             'options' => 'SELECT id,name AS text FROM vmail_domain ORDER BY name',
148                                             'option_empty' => '-- select --',
149                                             'required' => true,
150                                             ),
151                               'active' => array(
152                                             'name' => 'Mailbox aktiv',
153                                             'type' => 'boolean',
154                                             ),
155                               'buttons' => array(
156                                             'type' => 'html',
157                                             'code' => $buttons,
158                                             'sql' => false,
159                                             ),
160                               ),
161               'callbacks' => array(
162                                   'setpw' => 'cb_setpw',
163                                   ),
164               );
165
166 function passwd_encrypt($pw)
167 {
168   return md5($pw);
169 }
170
171 function cb_setpw()
172 {
173   global $db;
174
175   $sql = sprintf("UPDATE vmail_user SET password = '%s' WHERE id = %d",
176                  passwd_encrypt($_POST['passwd']),
177                  $_POST['id']);
178
179   $sth = $db->query($sql);
180
181   return true;
182 }