aadc9cd34e4b42f90e2865f3ba1a80b5d251f713
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= "ACT_MANUAL";
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( "kolabInvitationPolicy", "kolabFreeBusyFuture",
22 "unrestrictedMailSize", "calFBURL");
23 var $objectclasses= array();
25 function kolabAccount ($config, $dn= NULL)
26 {
27 plugin::plugin ($config, $dn);
29 /* Pull delegation array */
30 if (isset($this->attrs["kolabDelegate"]["count"])){
31 for ($i= 0; $i<$this->attrs["kolabDelegate"]["count"]; $i++){
32 array_push($this->kolabDelegate, $this->attrs["kolabDelegate"][$i]);
33 }
34 }
36 }
38 function execute()
39 {
40 /* Show tab dialog headers */
41 $display= "";
43 /* Show main page */
44 $smarty= get_smarty();
46 /* Load attributes */
47 foreach($this->attributes as $val){
48 $smarty->assign("$val", $this->$val);
49 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
50 }
52 /* Add delegation */
53 if (isset($_POST['add_delegation'])){
54 if ($_POST['delegate_address'] != ""){
56 /* Valid email address specified? */
57 $address= $_POST['delegate_address'];
58 $valid= FALSE;
59 if (!is_email($address)){
60 if (!is_email($address, TRUE)){
61 print_red (_("You're trying to add an invalid email address to the list of delegations."));
62 }
63 } else {
65 $ldap= $this->config->get_ldap_link();
66 $ldap->cd ($this->config->current['BASE']);
67 $ldap->search('(mail='.$address.')');
68 if ($ldap->count() == 0){
69 print_red (_("The mail address you're trying to add is no primary mail address of an existing user."));
70 } else {
71 $valid= TRUE;
72 }
73 }
75 if ($valid){
76 /* Add it */
77 if (chkacl ($this->acl, "kolabDelegate") == ""){
78 $this->addDelegate ($address);
79 $this->is_modified= TRUE;
80 }
82 }
83 }
84 }
86 /* Delete forward email addresses */
87 if (isset($_POST['delete_delegation'])){
88 if (count($_POST['delegate_list'])
89 && chkacl ($this->acl, "kolabDelegate") == ""){
91 $this->delDelegate ($_POST['delegate_list']);
92 }
93 }
95 /* Assemble policies */
96 $policies= array( 'ACT_ALWAYS_ACCEPT' => _("Always accept"),
97 'ACT_ALWAYS_REJECT' => _("Always reject"),
98 'ACT_REJECT_IF_CONFLICTS' => _("Reject if conflicts"),
99 'ACT_MANUAL_IF_CONFLICTS' => _("Manual if conflicts"),
100 'ACT_MANUAL' => _("Manual"));
101 $smarty->assign('policies', $policies);
103 /* Adjust checkbox */
104 if ($this->unrestrictedMailSize){
105 $smarty->assign('unrestrictedMailSizeState', "checked");
106 } else {
107 $smarty->assign('unrestrictedMailSizeState', "");
108 }
110 /* Transfer account states for this union */
111 if ($this->parent->by_object['mailAccount']->is_account){
112 $smarty->assign('is_account', 'true');
113 } else {
114 $smarty->assign('is_account', '');
115 }
117 /* Transfer delegation list */
118 $smarty->assign("kolabDelegate", $this->kolabDelegate);
120 $display.= $smarty->fetch (get_template_path('kolab.tpl', TRUE, dirname(__FILE__)));
121 return ($display);
122 }
124 function remove_from_parent()
125 {
126 /* Optionally execute a command after we're done */
127 $this->handle_post_events('remove');
128 }
131 function check()
132 {
133 $message= array();
135 /* FBFuture is in days... */
136 if ($this->kolabFreeBusyFuture != "" && !preg_match('/^[0-9]+$/', $this->kolabFreeBusyFuture)){
137 $message[]= _("The value specified as Free Busy future needs to be an integer.");
138 }
140 /* Check for URL scheme... */
141 if ($this->calFBURL != "" && !preg_match('/^[^:/]+://[a-z0-9_/.+~-]+$/i', $this->calFBURL)){
142 $message[]= _("The value specified as Free Busy Information URL is invalid.");
143 }
145 return ($message);
146 }
148 /* Save data to object */
149 function save_object()
150 {
151 /* Do we need to flip is_account state? */
152 if (isset($_POST['connectivityTab'])){
153 if (chkacl('unrestrictedMailSize', $this->acl == "")){
154 if (isset($_POST['unrestrictedMailSize']) && $_POST['unrestrictedMailSize'] == 1){
155 $this->unrestrictedMailSize= 1;
156 } else {
157 $this->unrestrictedMailSize= 0;
158 }
159 }
160 }
162 plugin::save_object();
163 }
166 /* Save to LDAP */
167 function save()
168 {
169 plugin::save();
171 /* Transfer delegation array */
172 $this->attrs['kolabDelegate']= $this->kolabDelegate;
174 /* Write back to ldap */
175 $ldap= $this->config->get_ldap_link();
176 $ldap->cd($this->dn);
177 $ldap->modify($this->attrs);
178 show_ldap_error($ldap->get_error());
180 /* Optionally execute a command after we're done */
181 if ($this->initially_was_account == $this->is_account){
182 if ($this->is_modified){
183 $this->handle_post_events("mofify");
184 }
185 } else {
186 $this->handle_post_events("add");
187 }
188 }
191 /* Add entry to delegation list */
192 function addDelegate($address)
193 {
194 $this->kolabDelegate[]= $address;
195 $this->kolabDelegate= array_unique ($this->kolabDelegate);
197 sort ($this->kolabDelegate);
198 reset ($this->kolabDelegate);
199 $this->is_modified= TRUE;
200 }
202 function delDelegate($addresses)
203 {
204 $this->kolabDelegate= array_remove_entries ($addresses, $this->kolabDelegate);
205 $this->is_modified= TRUE;
206 }
208 }
210 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
211 ?>