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 function kolabAccount ($config, $dn= NULL)
25 {
26 plugin::plugin ($config, $dn);
28 /* Pull arrays */
29 foreach(array("kolabDelegate", "kolabInvitationPolicy") as $attr){
30 if (isset($this->attrs["$attr"]["count"])){
31 for ($i= 0; $i<$this->attrs["$attr"]["count"]; $i++){
32 array_push($this->$attr, $this->attrs["$attr"][$i]);
33 }
34 }
35 }
37 /* If this one is empty, preset with ACT_MANUAL for anonymous users */
38 if (count ($this->kolabInvitationPolicy) == 0){
39 $this->kolabInvitationPolicy= array("ACT_MANUAL");
40 }
42 }
44 function execute()
45 {
46 /* Show tab dialog headers */
47 $display= "";
49 /* Show main page */
50 $smarty= get_smarty();
52 /* Load attributes */
53 foreach($this->attributes as $val){
54 $smarty->assign("$val", $this->$val);
55 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
56 }
58 /* Add delegation */
59 if (isset($_POST['add_delegation'])){
60 if ($_POST['delegate_address'] != ""){
62 /* Valid email address specified? */
63 $address= $_POST['delegate_address'];
64 $valid= FALSE;
65 if (!is_email($address)){
66 if (!is_email($address, TRUE)){
67 print_red (_("You're trying to add an invalid email address to the list of delegations."));
68 }
69 } else {
71 $ldap= $this->config->get_ldap_link();
72 $ldap->cd ($this->config->current['BASE']);
73 $ldap->search('(mail='.$address.')');
74 if ($ldap->count() == 0){
75 print_red (_("The mail address you're trying to add is no primary mail address of an existing user."));
76 } else {
77 $valid= TRUE;
78 }
79 }
81 if ($valid){
82 /* Add it */
83 if (chkacl ($this->acl, "kolabDelegate") == ""){
84 $this->addDelegate ($address);
85 $this->is_modified= TRUE;
86 }
88 }
89 }
90 }
92 /* Delete forward email addresses */
93 if (isset($_POST['delete_delegation'])){
94 if (count($_POST['delegate_list'])
95 && chkacl ($this->acl, "kolabDelegate") == ""){
97 $this->delDelegate ($_POST['delegate_list']);
98 }
99 }
101 /* Assemble policies */
102 $policies= array( 'ACT_ALWAYS_ACCEPT' => _("Always accept"),
103 'ACT_ALWAYS_REJECT' => _("Always reject"),
104 'ACT_REJECT_IF_CONFLICTS' => _("Reject if conflicts"),
105 'ACT_MANUAL_IF_CONFLICTS' => _("Manual if conflicts"),
106 'ACT_MANUAL' => _("Manual"));
107 $smarty->assign('policies', $policies);
109 /* Adjust checkbox */
110 if ($this->unrestrictedMailSize){
111 $smarty->assign('unrestrictedMailSizeState', "checked");
112 } else {
113 $smarty->assign('unrestrictedMailSizeState', "");
114 }
116 /* Transfer account states for this union */
117 if ($this->parent->by_object['mailAccount']->is_account){
118 $smarty->assign('is_account', 'true');
119 } else {
120 $smarty->assign('is_account', '');
121 }
123 /* Transfer delegation list */
124 $smarty->assign("kolabDelegate", $this->kolabDelegate);
126 /* Create InvitationPolicy table */
127 $invitation= "";
128 $nr= 0;
129 $acl= chkacl($this->acl, "kolabInvitationPolicy");
130 foreach ($this->kolabInvitationPolicy as $entry){
131 $invitation.= "<tr><td>";
133 /* The default entry does not have colons... */
134 if (!preg_match('/:/', $entry)){
135 $invitation.= _("Anonymous");
136 $mode= $entry;
137 } else {
138 $name= preg_replace('/:.*$/', '', $entry);
139 $mode= preg_replace('/^[^:]+: */', '', $entry);
140 $invitation.= "<input name=\"address$nr\" size=25 maxlength=60 $acl value=\"$name\">";
141 }
142 $invitation.= "</td>";
144 /* Add mode switch */
145 $invitation.= "<td><select size=\"1\" name=\"policy$nr\" $acl>";
146 foreach($policies as $key => $value){
147 if ($key == $mode){
148 $invitation.= "<option value=\"$key\" selected>$value</option>";
149 } else {
150 $invitation.= "<option value=\"$key\">$value</option>";
151 }
152 }
154 /* Assign buttons */
155 $button= "";
156 if ($nr == count($this->kolabInvitationPolicy)-1){
157 $button= "[Add button]";
158 } elseif ($nr != 0) {
159 $button= "[Remove button]";
160 }
162 $invitation.= "</select> $button</td></tr>\n";
163 $nr++;
164 }
165 $smarty->assign("invitation", $invitation);
167 $display.= $smarty->fetch (get_template_path('kolab.tpl', TRUE, dirname(__FILE__)));
168 return ($display);
169 }
171 function remove_from_parent()
172 {
173 /* Optionally execute a command after we're done */
174 $this->handle_post_events('remove');
175 }
178 function check()
179 {
180 $message= array();
182 /* FBFuture is in days... */
183 if ($this->kolabFreeBusyFuture != "" && !preg_match('/^[0-9]+$/', $this->kolabFreeBusyFuture)){
184 $message[]= _("The value specified as Free Busy future needs to be an integer.");
185 }
187 /* Check for URL scheme... */
188 if ($this->calFBURL != "" && !preg_match('/^[^:/]+://[a-z0-9_/.+~-]+$/i', $this->calFBURL)){
189 $message[]= _("The value specified as Free Busy Information URL is invalid.");
190 }
192 return ($message);
193 }
195 /* Save data to object */
196 function save_object()
197 {
198 /* Do we need to flip is_account state? */
199 if (isset($_POST['connectivityTab'])){
200 if (chkacl('unrestrictedMailSize', $this->acl == "")){
201 if (isset($_POST['unrestrictedMailSize']) && $_POST['unrestrictedMailSize'] == 1){
202 $this->unrestrictedMailSize= 1;
203 } else {
204 $this->unrestrictedMailSize= 0;
205 }
206 }
207 }
209 plugin::save_object();
211 /* Save changes done in invitation policies */
212 $nr= 0;
213 $this->kolabInvitationPolicy= array();
214 while (isset($_POST["policy$nr"])){
216 /* Anonymous? */
217 if (!isset($_POST["address$nr"])){
218 $this->kolabInvitationPolicy[]= $_POST["policy$nr"];
219 } else {
220 $this->kolabInvitationPolicy[]= $_POST["address$nr"].": ".$_POST["policy$nr"];
221 }
223 $nr++;
224 }
226 }
229 /* Save to LDAP */
230 function save()
231 {
232 plugin::save();
234 /* Transfer delegation array */
235 $this->attrs['kolabDelegate']= $this->kolabDelegate;
237 /* Write back to ldap */
238 $ldap= $this->config->get_ldap_link();
239 $ldap->cd($this->dn);
240 $ldap->modify($this->attrs);
241 show_ldap_error($ldap->get_error());
243 /* Optionally execute a command after we're done */
244 if ($this->initially_was_account == $this->is_account){
245 if ($this->is_modified){
246 $this->handle_post_events("mofify");
247 }
248 } else {
249 $this->handle_post_events("add");
250 }
251 }
254 /* Add entry to delegation list */
255 function addDelegate($address)
256 {
257 $this->kolabDelegate[]= $address;
258 $this->kolabDelegate= array_unique ($this->kolabDelegate);
260 sort ($this->kolabDelegate);
261 reset ($this->kolabDelegate);
262 $this->is_modified= TRUE;
263 }
265 function delDelegate($addresses)
266 {
267 $this->kolabDelegate= array_remove_entries ($addresses, $this->kolabDelegate);
268 $this->is_modified= TRUE;
269 }
271 }
273 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
274 ?>