09c3e83330410a2c1685a5c968918f85aef8c7fc
1 <?php
2 class kolabAccount extends plugin
3 {
4 /* Definitions */
5 var $plHeadline= "Kolab";
6 var $plDescription= "This does something";
8 /* CLI vars */
9 var $cli_summary= "Manage users Kolab account";
10 var $cli_description= "Some longer text\nfor help";
11 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
13 /* Kolab attributes */
14 var $kolabInvitationPolicy= array();
15 var $kolabFreeBusyFuture= 60;
16 var $unrestrictedMailSize= 0;
17 var $calFBURL= "";
18 var $kolabDelegate= array();
20 /* attribute list for save action */
21 var $attributes= array( "kolabFreeBusyFuture", "unrestrictedMailSize", "calFBURL");
22 var $objectclasses= array();
24 /* Helper */
25 var $imapping= array();
27 function kolabAccount ($config, $dn= NULL)
28 {
29 plugin::plugin ($config, $dn);
31 /* Pull arrays */
32 foreach(array("kolabDelegate", "kolabInvitationPolicy") as $attr){
33 if (isset($this->attrs["$attr"]["count"])){
34 for ($i= 0; $i<$this->attrs["$attr"]["count"]; $i++){
35 array_push($this->$attr, $this->attrs["$attr"][$i]);
36 }
37 }
38 }
40 /* If this one is empty, preset with ACT_MANUAL for anonymous users */
41 if (count ($this->kolabInvitationPolicy) == 0){
42 $this->kolabInvitationPolicy= array("ACT_MANUAL");
43 }
45 }
47 function execute()
48 {
49 /* Show tab dialog headers */
50 $display= "";
52 /* Show main page */
53 $smarty= get_smarty();
55 /* Load attributes */
56 foreach($this->attributes as $val){
57 $smarty->assign("$val", $this->$val);
58 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
59 }
61 /* Check for invitation action */
62 $nr= 0;
63 while (isset($_POST["policy$nr"])){
64 if (isset($_POST["add$nr"])){
65 $this->kolabInvitationPolicy[]= ": ACT_MANUAL";
66 }
67 if (isset($_POST["remove$nr"])){
68 $new= array();
69 foreach ($this->kolabInvitationPolicy as $entry){
70 if (!preg_match("/^".$this->imapping[$nr].":/", $entry)){
71 $new[]= $entry;
72 }
73 }
74 $this->kolabInvitationPolicy= $new;
75 }
76 $nr++;
77 }
79 /* Unify addresses */
80 $new= array();
81 foreach($this->kolabInvitationPolicy as $value){
82 if (preg_match('/^:/', $value)){
83 continue;
84 }
85 $address= preg_replace('/^([^:]+:).*$/', '\1', $value);
86 $new[$address]= $value;
87 }
88 $this->kolabInvitationPolicy= array();
89 foreach($new as $value){
90 $this->kolabInvitationPolicy[]= $value;
91 }
93 /* Add delegation */
94 if (isset($_POST['add_delegation'])){
95 if ($_POST['delegate_address'] != ""){
97 /* Valid email address specified? */
98 $address= $_POST['delegate_address'];
99 $valid= FALSE;
100 if (!is_email($address)){
101 if (!is_email($address, TRUE)){
102 print_red (_("You're trying to add an invalid email address to the list of delegations."));
103 }
104 } else {
106 $ldap= $this->config->get_ldap_link();
107 $ldap->cd ($this->config->current['BASE']);
108 $ldap->search('(mail='.$address.')');
109 if ($ldap->count() == 0){
110 print_red (_("The mail address you're trying to add is no primary mail address of an existing user."));
111 } else {
112 $valid= TRUE;
113 }
114 }
116 if ($valid){
117 /* Add it */
118 if (chkacl ($this->acl, "kolabDelegate") == ""){
119 $this->addDelegate ($address);
120 $this->is_modified= TRUE;
121 }
123 }
124 }
125 }
127 /* Delete forward email addresses */
128 if (isset($_POST['delete_delegation'])){
129 if (count($_POST['delegate_list'])
130 && chkacl ($this->acl, "kolabDelegate") == ""){
132 $this->delDelegate ($_POST['delegate_list']);
133 }
134 }
136 /* Assemble policies */
137 $policies= array( 'ACT_ALWAYS_ACCEPT' => _("Always accept"),
138 'ACT_ALWAYS_REJECT' => _("Always reject"),
139 'ACT_REJECT_IF_CONFLICTS' => _("Reject if conflicts"),
140 'ACT_MANUAL_IF_CONFLICTS' => _("Manual if conflicts"),
141 'ACT_MANUAL' => _("Manual"));
142 $smarty->assign('policies', $policies);
144 /* Adjust checkbox */
145 if ($this->unrestrictedMailSize){
146 $smarty->assign('unrestrictedMailSizeState', "checked");
147 } else {
148 $smarty->assign('unrestrictedMailSizeState', "");
149 }
151 /* Transfer account states for this union */
152 if ($this->parent->by_object['mailAccount']->is_account){
153 $smarty->assign('is_account', 'true');
154 } else {
155 $smarty->assign('is_account', '');
156 }
158 /* Transfer delegation list */
159 if (!count($this->kolabDelegate)){
160 $smarty->assign("kolabDelegate", array(""));
161 } else {
162 $smarty->assign("kolabDelegate", $this->kolabDelegate);
163 }
164 $smarty->assign("kolabDelegateACL", chkacl($this->acl, $this->kolabDelegate));
166 /* Create InvitationPolicy table */
167 $invitation= "";
168 $this->imapping= array();
169 $nr= 0;
170 $acl= chkacl($this->acl, "kolabInvitationPolicy");
171 foreach ($this->kolabInvitationPolicy as $entry){
172 $invitation.= "<tr><td>";
174 /* The default entry does not have colons... */
175 if (!preg_match('/:/', $entry)){
176 $invitation.= _("Anonymous");
177 $name= "";
178 $mode= $entry;
179 } else {
180 $name= preg_replace('/:.*$/', '', $entry);
181 $mode= preg_replace('/^[^:]*: */', '', $entry);
182 $invitation.= "<input name=\"address$nr\" size=16 maxlength=60 $acl value=\"$name\">";
183 }
184 $invitation.= "</td>";
186 /* Add mode switch */
187 $invitation.= "<td><select size=\"1\" name=\"policy$nr\" $acl>";
188 foreach($policies as $key => $value){
189 if ($key == $mode){
190 $invitation.= "<option value=\"$key\" selected>$value</option>";
191 } else {
192 $invitation.= "<option value=\"$key\">$value</option>";
193 }
194 }
196 /* Assign buttons */
197 $button= "";
198 if ($nr == count($this->kolabInvitationPolicy)-1){
199 $button= "<input type=submit name=\"add$nr\" value=\""._("Add")."\">";
200 }
201 if ($nr != 0) {
202 $button.= "<input type=submit name=\"remove$nr\" value=\""._("Remove")."\">";
203 }
205 $invitation.= "</select> $button</td></tr>\n";
206 $this->imapping[$nr]= $name;
207 $nr++;
208 }
209 $smarty->assign("invitation", $invitation);
211 $display.= $smarty->fetch (get_template_path('kolab.tpl', TRUE, dirname(__FILE__)));
212 return ($display);
213 }
215 function remove_from_parent()
216 {
217 /* Optionally execute a command after we're done */
218 $this->handle_post_events('remove');
219 }
222 function check()
223 {
224 $message= array();
226 /* FBFuture is in days... */
227 if ($this->kolabFreeBusyFuture != "" && !preg_match('/^[0-9]+$/', $this->kolabFreeBusyFuture)){
228 $message[]= _("The value specified as Free Busy future needs to be an integer.");
229 }
231 /* Check for URL scheme... */
232 if ($this->calFBURL != "" && !preg_match('/^[^:/]+://[a-z0-9_/.+~-]+$/i', $this->calFBURL)){
233 $message[]= _("The value specified as Free Busy Information URL is invalid.");
234 }
236 /* Check invitation policy for existing mail addresses */
237 foreach($this->kolabInvitationPolicy as $policy){
239 /* Ignore anonymous string */
240 if (!preg_match('/:/', $policy)){
241 continue;
242 }
244 $address= preg_replace('/^([^:]+).*$/', '\1', $policy);
245 if (!is_email($address)){
246 if (!is_email($address, TRUE)){
247 $message[]= sprintf(_("The invitation policy entry for address '%s' is not valid."), $address);
248 }
249 } else {
251 $ldap= $this->config->get_ldap_link();
252 $ldap->cd ($this->config->current['BASE']);
253 $ldap->search('(mail='.$address.')');
254 if ($ldap->count() == 0){
255 $message[]= sprintf(_("There's no mail user with address '%s' for your invitation policy!"), $address);
256 } else {
257 $valid= TRUE;
258 }
259 }
260 }
262 return ($message);
263 }
265 /* Save data to object */
266 function save_object()
267 {
268 /* Do we need to flip is_account state? */
269 if (isset($_POST['connectivityTab'])){
270 if (chkacl('unrestrictedMailSize', $this->acl == "")){
271 if (isset($_POST['unrestrictedMailSize']) && $_POST['unrestrictedMailSize'] == 1){
272 $this->unrestrictedMailSize= 1;
273 } else {
274 $this->unrestrictedMailSize= 0;
275 }
276 }
277 }
279 plugin::save_object();
281 /* Save changes done in invitation policies */
282 $nr= 0;
283 $this->kolabInvitationPolicy= array();
284 while (isset($_POST["policy$nr"])){
286 /* Anonymous? */
287 if (!isset($_POST["address$nr"])){
288 $this->kolabInvitationPolicy[]= $_POST["policy$nr"];
289 } else {
290 $this->kolabInvitationPolicy[]= $_POST["address$nr"].": ".$_POST["policy$nr"];
291 }
293 $nr++;
294 }
296 /* If this one is empty, preset with ACT_MANUAL for anonymous users */
297 if (count ($this->kolabInvitationPolicy) == 0){
298 $this->kolabInvitationPolicy= array("ACT_MANUAL");
299 }
301 }
304 /* Save to LDAP */
305 function save()
306 {
307 plugin::save();
309 /* Transfer arrays */
310 $this->attrs['kolabDelegate']= $this->kolabDelegate;
311 $this->attrs['kolabInvitationPolicy']= $this->kolabInvitationPolicy;
313 /* Write back to ldap */
314 $ldap= $this->config->get_ldap_link();
315 $ldap->cd($this->dn);
316 $ldap->modify($this->attrs);
317 show_ldap_error($ldap->get_error());
319 /* Optionally execute a command after we're done */
320 if ($this->initially_was_account == $this->is_account){
321 if ($this->is_modified){
322 $this->handle_post_events("mofify");
323 }
324 } else {
325 $this->handle_post_events("add");
326 }
327 }
330 /* Add entry to delegation list */
331 function addDelegate($address)
332 {
333 $this->kolabDelegate[]= $address;
334 $this->kolabDelegate= array_unique ($this->kolabDelegate);
336 sort ($this->kolabDelegate);
337 reset ($this->kolabDelegate);
338 $this->is_modified= TRUE;
339 }
341 function delDelegate($addresses)
342 {
343 $this->kolabDelegate= array_remove_entries ($addresses, $this->kolabDelegate);
344 $this->is_modified= TRUE;
345 }
347 }
349 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
350 ?>