Code

b4fd138f197199ef05730a5006eef874785c4646
[gosa.git] / gosa-plugins / phpgw / personal / connectivity / phpgw / class_phpgwAccount.inc
1 <?php
2 class phpgwAccount extends plugin
3 {
4   /* Definitions */
5   var $plHeadline= "PHPGroupware";
6   var $plDescription= "This does something";
8   /* GW attributes */
9   var $phpgwAccountExpires= "-1";
10   var $phpgwAccountStatus= "A";
11   var $phpgwAccountType= "u";
13   /* attribute list for save action */
14   var $attributes= array("phpgwAccountExpires", "phpgwAccountStatus", "phpgwAccountType");
15   var $objectclasses= array("phpgwAccount");
16   var $ReadOnly = false;
18   var $uid  = "";
19   var $view_logged = FALSE;
20   
21   var $multiple_support = TRUE;
23   function phpgwAccount (&$config, $dn= NULL)
24   {
25     plugin::plugin ($config, $dn);
27     /* Setting uid to default */
28     if(isset($this->attrs['uid'][0])){
29       $this->uid = $this->attrs['uid'][0];
30     }
31   }
33   function execute()
34   {
35         /* Call parent execute */
36 //      plugin::execute();
37  
38     /* Log view */
39     if($this->is_account && !$this->view_logged){
40       $this->view_logged = TRUE;
41       new log("view","users/".get_class($this),$this->dn);
42     }
43  
44     /* Show tab dialog headers */
45     $display= "";
47     /* Show main page */
48     $smarty= get_smarty();
50     /* Load attributes */
51     foreach($this->attributes as $val){
52       $smarty->assign("$val", $this->$val);
53     }
54     if ($this->is_account){
55       $smarty->assign("phpgwState", "checked");
56     } else {
57       $smarty->assign("phpgwState", "");
58     }
60     $smarty->assign('phpgwAccountACL', $this->getacl("",$this->ReadOnly));
61     $smarty->assign("multiple_support",$this->multiple_support_active);
62     $smarty->assign("use_phpgw",in_array("phpgw",$this->multi_boxes));
63     $display.= $smarty->fetch (get_template_path('phpgw.tpl', TRUE, dirname(__FILE__)));
64     return ($display);
65   }
67   function remove_from_parent()
68   {
69     if($this->acl_is_removeable()){
70       /* Cancel if there's nothing to do here */
71       if (!$this->initially_was_account){
72         return;
73       }
75       plugin::remove_from_parent();
76       $ldap= $this->config->get_ldap_link();
78       $ldap->cd($this->dn);
79       @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
80           $this->attributes, "Save");
81       $this->cleanup();
82       $ldap->modify ($this->attrs); 
84       if (!$ldap->success()){
85         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
86       }
88       new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
90       /* Optionally execute a command after we're done */
91       $this->handle_post_events('remove',array("uid" => $this->uid));
92     }
93   }
96   /* Save data to object */
97   function save_object()
98   {
99     /* Do we need to flip is_account state? */
100     if (isset($_POST['connectivityTab'])){
101       if (isset($_POST['phpgw'])){
102         if (!$this->is_account && $_POST['phpgw'] == "B"){
103           if($this->acl_is_createable()){
104             $this->is_account= TRUE;
105           }
106         }
107       } else {
108         if($this->acl_is_removeable()){
109           $this->is_account= FALSE;
110         }
111       }
112     }
114     plugin::save_object();
115     if (isset($_POST["phpgwStatus"])){
116       $this->phpgwStatus = "disabled";
117     } else {
118       $this->phpgwStatus = "enabled";
119     }
120   }
123   /* Save to LDAP */
124   function save()
125   {
126     plugin::save();
128     /* Write back to ldap */
129     $ldap= $this->config->get_ldap_link();
130     $ldap->cd($this->dn);
131     $this->cleanup();
132     $ldap->modify ($this->attrs); 
134     if($this->initially_was_account){
135       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
136     }else{
137       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
138     }
140     if (!$ldap->success()){
141       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
142     }
144     /* Optionally execute a command after we're done */
145     if ($this->initially_was_account == $this->is_account){
146       if ($this->is_modified){
147         $this->handle_post_events("modify",array("uid" => $this->uid));
148       }
149     } else {
150       $this->handle_post_events("add",array("uid" => $this->uid));
151     }
153   }
156   /* Return plugin informations for acl handling */
157   static function plInfo()
158   {
159     return (array(
160           "plShortName"     => _("PHP GW"),
161           "plDescription"   => _("PHP GW account settings")."&nbsp;("._("Connectivity addon").")",
162           "plSelfModify"    => TRUE,
163           "plDepends"       => array("user"),
164           "plPriority"      => 24,                                 // Position in tabs
165           "plSection"     => array("personal" => _("My account")),
166           "plCategory"    => array("users"),
167           "plOptions"       => array(),
169           "plProvidedAcls"  => array()
170           ));
171   }
174   function multiple_save_object()
175   {
176     if (isset($_POST['connectivityTab'])){
177       plugin::multiple_save_object();
179       /* Do we need to flip is_account state? */
180       if(isset($_POST['use_phpgw'])){
181         $this->multi_boxes[] = "phpgw";
182         if (isset($_POST['connectivityTab'])){
183           if (isset($_POST['phpgw'])){
184             if (!$this->is_account && $_POST['phpgw'] == "B"){
185               if($this->acl_is_createable()){
186                 $this->is_account= TRUE;
187               }
188             }
189           } else {
190             if($this->acl_is_removeable()){
191               $this->is_account= FALSE;
192             }
193           }
194         }
195       }
196     }
197   }
199   function get_multi_edit_values()
200   {
201     $ret = plugin::get_multi_edit_values();
202     if(in_array("phpgw",$this->multi_boxes)){
203       $ret['is_account'] = $this->is_account;
204     }
205     return($ret);
206   }
208   function set_multi_edit_values($values)
209   {
210     plugin::set_multi_edit_values($values);
211     if(isset($values['is_account'])){
212       $this->is_account = $values['is_account'];
213     }
214   }
216   function init_multiple_support($attrs,$all)
217   {
218     plugin::init_multiple_support($attrs,$all);
219     if(isset($attrs['objectClass']) && in_array("phpgwAccount",$attrs['objectClass'])){
220       $this->is_account = TRUE;
221     }
222   }
225 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
226 ?>