1 <?php
2 class phpgwAccount extends plugin
3 {
4 /* Definitions */
5 var $plHeadline= "PHPGroupware";
6 var $plDescription= "Manage PHPGroupware user settings";
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", set_post( $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" => _("PHPGroupware"),
161 "plDescription" => _("PHPGroupware account settings")." ("._("Connectivity add-on").")",
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(),
168 "plRequirements"=> array(
169 'ldapSchema' => array('phpgwAccount' => ''),
170 'onFailureDisablePlugin' => array(get_class())
171 ),
173 "plProvidedAcls" => array()
174 ));
175 }
178 function multiple_save_object()
179 {
180 if (isset($_POST['connectivityTab'])){
181 plugin::multiple_save_object();
183 /* Do we need to flip is_account state? */
184 if(isset($_POST['use_phpgw'])){
185 $this->multi_boxes[] = "phpgw";
186 if (isset($_POST['connectivityTab'])){
187 if (isset($_POST['phpgw'])){
188 if (!$this->is_account && $_POST['phpgw'] == "B"){
189 if($this->acl_is_createable()){
190 $this->is_account= TRUE;
191 }
192 }
193 } else {
194 if($this->acl_is_removeable()){
195 $this->is_account= FALSE;
196 }
197 }
198 }
199 }
200 }
201 }
203 function get_multi_edit_values()
204 {
205 $ret = plugin::get_multi_edit_values();
206 if(in_array("phpgw",$this->multi_boxes)){
207 $ret['is_account'] = $this->is_account;
208 }
209 return($ret);
210 }
212 function set_multi_edit_values($values)
213 {
214 plugin::set_multi_edit_values($values);
215 if(isset($values['is_account'])){
216 $this->is_account = $values['is_account'];
217 }
218 }
220 function init_multiple_support($attrs,$all)
221 {
222 plugin::init_multiple_support($attrs,$all);
223 if(isset($attrs['objectClass']) && in_array("phpgwAccount",$attrs['objectClass'])){
224 $this->is_account = TRUE;
225 }
226 }
227 }
229 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
230 ?>