Code

- Updating french locale and correctiona spelling error
[gosa.git] / gosa-plugins / opengroupware / personal / connectivity / opengroupware / class_opengwAccount.inc
1 <?php
3 class opengwAccount extends plugin
4 {
5         /* Definitions */
6         var $plHeadline       = "Opengroupware account";
7         var $plDescription    = "This does something";
9         /* attribute list for save action */
10         var $attributes       = array();
11         var $objectclasses    = array();
13   var $SetPassword   = false;
15         /* Attribute mapping opengroupware->ldap  */
16         var $attrsToUse    = array( "salutation"  =>"vocation",
17                         "name"        =>"sn",
18                         "firstname"   =>"givenName",
19                         "login"       =>"uid",
20                         "degree"      =>"academicTitle",
21                         "birthday"    =>"dateOfBirth",
22                         "sex"         =>"gender",
23                         "street"      =>"street",
24                         "zip"         =>"postalCode",
25                         "value_string"=>"mail",
26                         "number"      =>"telephoneNumber"
27                         );
29         var $serverCon            =  false;
30         var $handle               = NULL;
31         var $is_account           = false;
32         var $initialy_was_account = false;
33   var $OGWPassword          = "";
34   var $ReadOnly = false;
35   var $view_logged = FALSE;  
36   var $uid = "";
38         function opengwAccount (&$config, $dn= NULL)
39         {
40                 plugin::plugin ($config, $dn);
42     /* Setting uid to default */
43     if(isset($this->attrs['uid'][0])){
44       $this->uid = $this->attrs['uid'][0];
45     }
47                 $this->info=array();
49                 /* is no account and was no account */
50                 $this->initialy_was_account = false;
51                 $this->is_account           = false;
53                 /* Get configurations */
54     if($this->config->search("opengwAccount", 'USERNAME',array('tabs'))){
55       $atr = array();
56       $atr['LOGIN']     =         $this->config->search("opengwAccount", 'USERNAME',array('tabs'));
57       $atr['PASSWORD']= $this->config->search("opengwAccount", 'PASSWORD',array('tabs'));
58       $atr['SERVER']    =       $this->config->search("opengwAccount", 'DATAHOST',array('tabs'));
59       $atr['DB']                =         $this->config->search("opengwAccount", 'DATABASE',array('tabs'));
60       $this->serverCon = $atr;
61     }elseif(isset($this->config->data['SERVERS']['OPENGROUPWARE'])){
62       $this->serverCon  = $this->config->data['SERVERS']['OPENGROUPWARE'];
63     }else{
64       $this->serverCon = array();
65     }
67     /* check if datebase funktions are available, and if database configurations are available */ 
68                 if(is_callable("pg_connect") && count($this->serverCon)){
70                         $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
72                         /* Check if current configuration allows database connection */
73                         if($this->handle->connected){
75                                 /* Set login name, to check if this is_account */
76                                 if(isset($this->attrs['uid'][0])){
77                                         $this->handle->info['login'] = $this->attrs['uid'][0];
78                                 }else{
79                                         $this->handle->info['login'] = ""; 
80                                 }
82                                 /* If this is account get data from database first */
83                                 if($this->handle->CheckExistence()){
84                                         $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
86                                         /* This is an account */
87                                         $this->initialy_was_account = true;
88                                         $this->is_account= true;
89                                 }else{
90                                         /* this is no account */ 
91                                         $this->initialy_was_account = false;
92                                         $this->is_account= false;
94                                         /* Selectable in GOsa */
95                                         $this->info['template_user_id']   = 0;
96                                         $this->info['is_locked']          = 0;
97                                         $this->info['LocationTeamID']     = 0;
98                                         $this->info['TeamIDis']           = array();
99                                 }
101                                 /* Set settings from ldap */
102                                 foreach($this->attrsToUse as $name=>$attr){
103                                         if(isset($this->attrs[$attr][0])){
104                                                 $this->info[$name] = $this->attrs[$attr][0];
105                                         }else{
106                                                 $this->info[$name] = false;
107                                         }
108                                 } 
110                                 /* Description is displayed as 'Nickname' */
111                                 $this->info['description']          = $this->info['login'];
113                                 if($this->info['sex'] == "F"){
114                                         $this->info['sex']                = "female";
115                                 }else{
116                                         $this->info['sex']                = "male";
117                                 }
119                         }
121                         /* Transmit data back to ogw handle */
122                         $this->handle->SetInfos($this->info);
123                 }
124         }
126         function execute()
127         {
128     /* Log view */
129     if($this->is_account && !$this->view_logged){
130       $this->view_logged = TRUE;
131       new log("view","users/".get_class($this),$this->dn);
132     }
134                 /* Show tab dialog headers */
135                 $display= "";
136                 $smarty= get_smarty();
138     $smarty->assign("serverCon",count($this->serverCon));
139     $smarty->assign("validTeams","");
140     $smarty->assign("is_account", " ");
141     $smarty->assign("OGWstate"," disabled ");
142     $smarty->assign("validLocationTeam",array("&nbsp;"));
143     $smarty->assign("validLocationTeams",array("&nbsp;"));
144     $smarty->assign("LocationTeam",0);
145     $smarty->assign("validTemplateUser",array("&nbsp;"));
146     $smarty->assign("validTemplateUsers",array("&nbsp;"));
147     $smarty->assign("TemplateUser",0);
148     $smarty->assign("is_lockedCHK", "  ");
149     $smarty->assign("is_locked", "  ");
150  
151                 /* set default values */
152     $tmp = $this->plInfo();
153     foreach($tmp['plProvidedAcls'] as $acl => $desc){
154       $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
155     } 
157     if((!$this->ReadOnly)&&(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))) {
158       $smarty->assign('opengwAccountACL', "");
159     }else{
160       $smarty->assign('opengwAccountACL', " disabled ");
161     }
163     if(count($this->serverCon))
165                 /* Check database extension */    
166                 if(!is_callable("pg_connect") && count($this->serverCon)){
167       msg_dialog::display(_("Configuration error"), msgPool::missingext("postgresql"), ERROR_DIALOG);
168                 }elseif(count($this->serverCon)){
170                         /* Check if config exists */
171                         if($this->config->search("opengwAccount", 'DATABASE',array('tabs')) == ""){
172         msg_dialog::display(_("Configuration error"), msgPool::noserver(_("Open Groupware database")), ERROR_DIALOG);
173                         }else{
175                                 /* Create handle */
176                                 $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
178                                 /* Check if we are successfully connected to db */
179                                 if(!$this->handle->connected){
180           msg_dialog::display(_("Configuration error"), msgPool::dbconnect(_("OpenGroupware")), ERROR_DIALOG);
181                                 }else{
183                                         /* Assign LocationTeams */
184                                         $tmp = array(""=>"none");
185                                         foreach($this->handle->validLocationTeam as $id){
186                                                 $tmp[$id['company_id']] = $id['description']; 
187                                         }
188                                         $smarty->assign("validLocationTeam",$tmp);
189                                         $smarty->assign("validLocationTeams",array_flip($tmp));
190                                         $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
192                                         /* Assign TemplateUsers*/
193                                         $tmp = array();
194                                         foreach($this->handle->validTemplateUser as $id){
195                                                 $tmp[$id['company_id']] = $id['name']; 
196                                         }
197                                         $smarty->assign("validTemplateUser",$tmp);
198                                         $smarty->assign("validTemplateUsers",array_flip($tmp));
199                                         $smarty->assign("TemplateUser",$this->info['template_user_id']);
201                                         /* Create Team membership */ 
202                                         $str = "";
203                                         if($this->is_account){
204                                                 $dis = "";
205                                         }else{
206                                                 $dis = " disabled ";
207                                         }
209           if($this->acl_is_readable("Teams")){
210             foreach($this->handle->validTeams as $id){
211               if(in_array($id['company_id'],$this->info['TeamIDis'])){
212                 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
213                   checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
214               }else{
215                 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
216                   name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
217               }
218             }
219           }
220                                         $smarty->assign("validTeams",$str);
222                                         /* Assign ogw checkbox */
223                                         if($this->is_account){
224                                                 $smarty->assign("OGWstate","");
225                                                 $smarty->assign("is_account", " checked ");
226                                         }else{
227                                                 $smarty->assign("is_account", " ");
228                                                 $smarty->assign("OGWstate"," disabled ");
229                                         }
231                                         /* Assign lock status */
232                                         if($this->info['is_locked']){
233                                                 $smarty->assign("is_lockedCHK", " checked ");
234                                         }else{
235                                                 $smarty->assign("is_lockedCHK", "  ");
236                                         }
237                                         $smarty->assign("is_locked", $this->info['is_locked']);
239                                 } 
240                         }
241     }
242                 $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
243                 return ($display);
244         }
246         function remove_from_parent()
247         {
248                 /* remove database entries */
249                 if($this->initialy_was_account){
250                         $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
251                         $this->handle->SetInfos($this->info);
252                         $this->handle->Perform("REMOVE");
254       new log("remove","users/".get_class($this),$this->dn);
255                 }
256         }
259         /* Save data to object */
260         function save_object()
261         {
262                 /* get post data */
263                 if($this->is_account){
265       /* Get selected team chkboxes */
266       $this->info['TeamIDis'] = array();
267       if($this->acl_is_writeable("Teams")) {
268         foreach($_POST as $name => $value ){
269           if(preg_match("/team_/i",$name)){
270             if(!in_array($value,$this->info['TeamIDis'])){
271               $this->info['TeamIDis'][]=$value;
272             }
273           }
274         }
275       }
278                         /* Get location Team*/
279                         if(isset($_POST['LocationTeam']) && $this->acl_is_writeable("LocationTeam")){
280                                 $this->info['LocationTeamID'] = $_POST['LocationTeam'];
281                         }
283                         /* Get template user */
284                         if(isset($_POST['TemplateUser']) && $this->acl_is_writeable("TemplateUser") ){
285                                 $this->info['template_user_id'] = $_POST['TemplateUser'];
286                         }
288       /* get lock status */
289       if($this->acl_is_writeable("Locked")){
290         if(isset($_POST['is_locked'])){
291           $this->info['is_locked'] = $_POST['is_locked'];
292         }else{
293           $this->info['is_locked'] = 0;
294         }
295       }
296                 }
298                 /* change account status */
299                 if(isset($_POST['is_account'])){
300       if($this->acl_is_createable()){
301         $this->is_account = $_POST['is_account'];
302       }
303     }else{
304       if($this->acl_is_removeable()){
305         $this->is_account = false;//$_POST['is_account'];
306       }
307                 }
308         }
311         /* Save to LDAP */
312         function save()
313         {
314                 /* Save data */ 
315                 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
316                 $this->handle->SetInfos($this->info);
317                 $this->handle->checkInfos();
318                 if($this->initialy_was_account){
319                         $this->handle->Perform("EDIT");
320       new log("modify","users/".get_class($this),$this->dn);
321                 }else{
322                         $this->handle->Perform("ADD");
323       new log("create","users/".get_class($this),$this->dn);
324                 }
325         }
327   
328   function PrepareForCopyPaste($src){
329     // Nothing to do, because this object can't be copied ... yet
330   }
333  /* Return plugin informations for acl handling 
334       #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */   
335   static function plInfo()
336   {
337     return (array(
338           "plShortName"     => _("Opengroupware"),
339           "plDescription"   => _("Open groupware account settings")."&nbsp;("._("Connectivity addon").")",
340           "plSelfModify"    => TRUE,
341           "plDepends"       => array("user"),
342           "plPriority"      => 26,                                 // Position in tabs
343           "plSection"     => array("personal" => _("My account")),
344           "plCategory"    => array("users"),
345           "plOptions"       => array(),
347           "plProvidedAcls"  => array(
348             "LocationTeam"  => _("Location team"),
349             "TemplateUser"  => _("Template user"),
350             "Locked"        => _("Locked"),
351             "Teams"         => _("Teams"))
352           ));
353   }
355 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
356 ?>