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;
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();
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 }
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 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/PHPgw account with dn '%s' failed."),$this->dn));
86 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
88 /* Optionally execute a command after we're done */
89 $this->handle_post_events('remove',array("uid" => $this->uid));
90 }
91 }
94 /* Save data to object */
95 function save_object()
96 {
97 /* Do we need to flip is_account state? */
98 if (isset($_POST['connectivityTab'])){
99 if (isset($_POST['phpgw'])){
100 if (!$this->is_account && $_POST['phpgw'] == "B"){
101 if($this->acl_is_createable()){
102 $this->is_account= TRUE;
103 }
104 }
105 } else {
106 if($this->acl_is_removeable()){
107 $this->is_account= FALSE;
108 }
109 }
110 }
112 plugin::save_object();
113 if (isset($_POST["phpgwStatus"])){
114 $this->phpgwStatus = "disabled";
115 } else {
116 $this->phpgwStatus = "enabled";
117 }
118 }
121 /* Save to LDAP */
122 function save()
123 {
124 plugin::save();
126 /* Write back to ldap */
127 $ldap= $this->config->get_ldap_link();
128 $ldap->cd($this->dn);
129 $this->cleanup();
130 $ldap->modify ($this->attrs);
132 if($this->initially_was_account){
133 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
134 }else{
135 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
136 }
138 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/PHPgw account with dn '%s' failed."),$this->dn));
140 /* Optionally execute a command after we're done */
141 if ($this->initially_was_account == $this->is_account){
142 if ($this->is_modified){
143 $this->handle_post_events("modify",array("uid" => $this->uid));
144 }
145 } else {
146 $this->handle_post_events("add",array("uid" => $this->uid));
147 }
149 }
152 /* Return plugin informations for acl handling */
153 static function plInfo()
154 {
155 return (array(
156 "plShortName" => _("PHP GW"),
157 "plDescription" => _("PHP GW account settings")." : <u>"._("Connectivity addon")."</u>",
158 "plSelfModify" => TRUE,
159 "plDepends" => array("user"),
160 "plPriority" => 24, // Position in tabs
161 "plSection" => array("personal" => _("My account")),
162 "plCategory" => array("users"),
163 "plOptions" => array(),
165 "plProvidedAcls" => array()
166 ));
167 }
170 function multiple_save_object()
171 {
172 if (isset($_POST['connectivityTab'])){
173 plugin::multiple_save_object();
175 /* Do we need to flip is_account state? */
176 if(isset($_POST['use_phpgw'])){
177 $this->multi_boxes[] = "phpgw";
178 if (isset($_POST['connectivityTab'])){
179 if (isset($_POST['phpgw'])){
180 if (!$this->is_account && $_POST['phpgw'] == "B"){
181 if($this->acl_is_createable()){
182 $this->is_account= TRUE;
183 }
184 }
185 } else {
186 if($this->acl_is_removeable()){
187 $this->is_account= FALSE;
188 }
189 }
190 }
191 }
192 }
193 }
195 function get_multi_edit_values()
196 {
197 $ret = plugin::get_multi_edit_values();
198 if(in_array("phpgw",$this->multi_boxes)){
199 $ret['is_account'] = $this->is_account;
200 }
201 return($ret);
202 }
204 function set_multi_edit_values($values)
205 {
206 plugin::set_multi_edit_values($values);
207 if(isset($values['is_account'])){
208 $this->is_account = $values['is_account'];
209 }
210 }
212 function init_multiple_support($attrs,$all)
213 {
214 plugin::init_multiple_support($attrs,$all);
215 if(isset($attrs['objectClass']) && in_array("phpgwAccount",$attrs['objectClass'])){
216 $this->is_account = TRUE;
217 }
218 }
219 }
221 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
222 ?>