1 <?php
5 /*!
6 \author Harald Falk <hf@doellken-weimar.de>
7 \version 1.00
8 \date 1.07.2005
10 \brief Enables Apache authentification for Intranet through openldap with .htaccess files
11 */
13 class intranetAccount extends plugin
14 {
15 /*! Definitions */
16 var $plHeadline= "Intranet";
17 /*! Definitions */
18 var $plDescription= "This does something";
20 /* attribute list for save action */
21 var $attributes= array();
22 /* ObjectClasses list for save action */
23 var $objectclasses= array("gosaIntranetAccount");
24 var $ReadOnly = false;
26 var $uid ="";
28 var $view_logged = FALSE;
29 var $multiple_support = TRUE;
31 /*! \brief Konstructor
33 \param $config The Config Object used to initialise plugin
34 \param $dn The DN of the currently edited entry
35 \author Harald Falk <hf@doellken-weimar.de>
36 \version 1.00
37 \date 1.07.2005
38 */
39 function intranetAccount (&$config, $dn= NULL, $parent=NULL)
40 {
41 plugin::plugin ($config, $dn,$parent);
43 /* Setting uid to default */
44 if(isset($this->attrs['uid'][0])){
45 $this->uid = $this->attrs['uid'][0];
46 }
47 }
49 /*!
50 \brief General execution
51 \author Harald Falk <hf@doellken-weimar.de>
52 \version 1.00
53 \date 1.07.2005
55 Load smarty Template and assign needed smarty vars
56 */
59 function execute()
60 {
61 /* Call parent execute */
62 // plugin::execute();
64 /* Log view */
65 if($this->is_account && !$this->view_logged){
66 $this->view_logged = TRUE;
67 new log("view","users/".get_class($this),$this->dn);
68 }
70 $display= "";
72 $smarty= get_smarty();
74 if ($this->is_account){
75 $smarty->assign("intranetState", "checked");
76 $smarty->assign("wstate", "");
77 } else {
78 $smarty->assign("wstate", "disabled");
79 $smarty->assign("intranetState", "");
80 }
82 //! Ever assign vars to smarty in both cases, to avoid php errors (missing variable aso. )
83 if ($this->parent !== NULL){
84 $smarty->assign("tabbed", 1);
85 }else{
86 $smarty->assign("tabbed", 0);
87 }
89 /* check if we are allowed to switch the checkbox.
90 */
91 $smarty->assign('gosaIntranetACL', preg_replace("/w/","",$this->getacl("",$this->ReadOnly)));
92 if(($this->acl_is_removeable() && $this->is_account) ||
93 ($this->acl_is_createable() && !$this->is_account)){
94 $smarty->assign('gosaIntranetACL', $this->getacl("",$this->ReadOnly));
95 }
97 $smarty->assign("use_intranet",in_array("intranet",$this->multi_boxes));
98 $smarty->assign("multiple_support",$this->multiple_support_active);
99 $display.= $smarty->fetch (get_template_path('intranet.tpl', TRUE, dirname(__FILE__)));
100 return ($display);
101 }
103 /*!
104 \brief Delete ext from User
105 \author Harald Falk <hf@doellken-weimar.de>
106 \version 1.00
107 \date 1.07.2005
108 Handles deletion of this object
109 */
110 function remove_from_parent()
111 {
112 if($this->acl_is_removeable() && $this->initially_was_account){
113 plugin::remove_from_parent();
114 $ldap= $this->config->get_ldap_link();
116 $ldap->cd($this->dn);
117 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
118 $this->attributes, "Save");
119 $this->cleanup();
120 $ldap->modify ($this->attrs);
122 /* Log last action */
123 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
125 if (!$ldap->success()){
126 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
127 }
129 /* Optionally execute a command after we're done */
130 $this->postremove(array("uid"=>$this->uid));
131 }
132 }
135 /*!
136 \brief handles Post data
137 \author Harald Falk <hf@doellken-weimar.de>
138 \version 1.00
139 \date 1.07.2005
140 Save data to object
141 */
142 function save_object()
143 {
144 /* Do we need to flip is_account state? */
145 if (isset($_POST['connectivityTab'])){
146 if (isset($_POST['intranet'])){
147 if (!$this->is_account && $_POST['intranet'] == "B"){
148 if($this->acl_is_createable()){
149 $this->is_account= TRUE;
150 }
151 }
152 } else {
153 if($this->acl_is_removeable()){
154 $this->is_account= FALSE;
155 }
156 }
157 }
159 plugin::save_object();
160 if (isset($_POST["INTRANETStatus"])){
161 $this->INTRANETStatus = "disabled";
162 } else {
163 $this->INTRANETStatus = "enabled";
164 }
165 }
168 /*! \brief Handles LDAP saves
169 \author Harald Falk <hf@doellken-weimar.de>
170 \version 1.00
171 \date 1.07.2005
172 Save objectClass for User in LDAP
174 */
175 function save()
176 {
177 plugin::save();
179 /* Write back to ldap */
180 $ldap= $this->config->get_ldap_link();
181 $ldap->cd($this->dn);
182 $this->cleanup();
183 $ldap->modify ($this->attrs);
185 /* Log last action */
186 if($this->initially_was_account){
187 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
188 }else{
189 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
190 }
192 if (!$ldap->success()){
193 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
194 }
196 /* Optionally execute a command after we're done */
197 $this->postcreate(array("uid" => $this->uid));
198 }
201 /* Return plugin informations for acl handling */
202 static function plInfo()
203 {
204 return (array(
205 "plShortName" => _("Intranet"),
206 "plDepends" => array("user"),
207 "plPriority" => 25, // Position in tabs
208 "plSection" => array("personal" => _("My account")),
209 "plCategory" => array("users"),
210 "plOptions" => array(),
212 "plDescription" => _("Intranet account settings")." : <u>"._("Connectivity addon")."</u>",
213 "plSelfModify" => TRUE,
215 "plProvidedAcls" => array()
216 ));
217 }
220 function multiple_save_object()
221 {
222 if (isset($_POST['connectivityTab'])){
223 plugin::multiple_save_object();
224 if(isset($_POST['use_intranet'])){
225 $this->multi_boxes[] = "intranet";
226 if (isset($_POST['intranet'])){
227 if (!$this->is_account && $_POST['intranet'] == "B"){
228 if($this->acl_is_createable()){
229 $this->is_account= TRUE;
230 }
231 }
232 } else {
233 if($this->acl_is_removeable()){
234 $this->is_account= FALSE;
235 }
236 }
237 }
238 }
239 }
241 function get_multi_edit_values()
242 {
243 $ret = plugin::get_multi_edit_values();
244 if(in_array("intranet",$this->multi_boxes)){
245 $ret['is_account'] = $this->is_account;
246 }
247 return($ret);
248 }
250 function set_multi_edit_values($values)
251 {
252 plugin::set_multi_edit_values($values);
253 if(isset($values['is_account'])){
254 $this->is_account = $values['is_account'];
255 }
256 }
258 function init_multiple_support($attrs,$all)
259 {
260 plugin::init_multiple_support($attrs,$all);
261 if(isset($attrs['objectClass']) && in_array("gosaIntranetAccount",$attrs['objectClass'])){
262 $this->is_account = TRUE;
263 }
264 }
265 }
267 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
268 ?>