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