Code

Updated macro class. Added check -> Empty macros can't be saved.
[gosa.git] / plugins / personal / connectivity / 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   
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                 /* check if datebase funktions are available, and if database configurations are available */ 
54                 if(is_callable("pg_connect")){
56                         /* Get configurations */
57                         if(search_config($this->config->data,"opengwAccount","USERNAME")){
58                                 $atr = array();
59                                 $atr['LOGIN']   =       search_config($this->config->data,"opengwAccount","USERNAME");
60                                 $atr['PASSWORD']=       search_config($this->config->data,"opengwAccount","PASSWORD");
61                                 $atr['SERVER']  =       search_config($this->config->data,"opengwAccount","DATAHOST");
62                                 $atr['DB']              =       search_config($this->config->data,"opengwAccount","DATABASE");
63                                 $this->serverCon = $atr;
64                         }else{
65                                 $this->serverCon  = $this->config->data['SERVERS']['OPENGROUPWARE'];
66                         }
67                         $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
69                         /* Check if current configuration allows database connection */
70                         if($this->handle->connected){
72                                 /* Set login name, to check if this is_account */
73                                 if(isset($this->attrs['uid'][0])){
74                                         $this->handle->info['login'] = $this->attrs['uid'][0];
75                                 }else{
76                                         $this->handle->info['login'] = ""; 
77                                 }
79                                 /* If this is account get data from database first */
80                                 if($this->handle->CheckExistence()){
81                                         $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
83                                         /* This is an account */
84                                         $this->initialy_was_account = true;
85                                         $this->is_account= true;
86                                 }else{
87                                         /* this is no account */ 
88                                         $this->initialy_was_account = false;
89                                         $this->is_account= false;
91                                         /* Selectable in GOsa */
92                                         $this->info['template_user_id']   = 0;
93                                         $this->info['is_locked']          = 0;
94                                         $this->info['LocationTeamID']     = 0;
95                                         $this->info['TeamIDis']           = array();
96                                 }
98                                 /* Set settings from ldap */
99                                 foreach($this->attrsToUse as $name=>$attr){
100                                         if(isset($this->attrs[$attr][0])){
101                                                 $this->info[$name] = $this->attrs[$attr][0];
102                                         }else{
103                                                 $this->info[$name] = false;
104                                         }
105                                 } 
107                                 /* Description is displayed as 'Nickname' */
108                                 $this->info['description']          = $this->info['login'];
110                                 if($this->info['sex'] == "F"){
111                                         $this->info['sex']                = "female";
112                                 }else{
113                                         $this->info['sex']                = "male";
114                                 }
116                         }
118                         /* Transmit data back to ogw handle */
119                         $this->handle->SetInfos($this->info);
120                 }
121         }
123         function execute()
124         {
125                 /* Show tab dialog headers */
126                 $display= "";
127                 $smarty= get_smarty();
129                 /* set default values */
130     $tmp = $this->plInfo();
131     foreach($tmp['plProvidedAcls'] as $acl => $desc){
132       $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
133     } 
135     if((!$this->ReadOnly)&&(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))) {
136       $smarty->assign('opengwAccountACL', "");
137     }else{
138       $smarty->assign('opengwAccountACL', " disabled ");
139     }
141                 /* Check database extension */    
142                 if(!is_callable("pg_connect")){
143                         print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries."));
144                 }else
146                         /* Check if config exists */
147                         if(search_config($this->config->data,"opengwAccount","DATABASE")==""){
148                                 print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations."));
149                         }else{
151                                 /* Create handle */
152                                 $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
154                                 /* Check if we are successfully connected to db */
155                                 if(!$this->handle->connected){
156                                         print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice."));
157                                 }else{
159                                         /* Assign LocationTeams */
160                                         $tmp = array(""=>"none");
161                                         foreach($this->handle->validLocationTeam as $id){
162                                                 $tmp[$id['company_id']] = $id['description']; 
163                                         }
164                                         $smarty->assign("validLocationTeam",$tmp);
165                                         $smarty->assign("validLocationTeams",array_flip($tmp));
166                                         $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
168                                         /* Assign TemplateUsers*/
169                                         $tmp = array();
170                                         foreach($this->handle->validTemplateUser as $id){
171                                                 $tmp[$id['company_id']] = $id['name']; 
172                                         }
173                                         $smarty->assign("validTemplateUser",$tmp);
174                                         $smarty->assign("validTemplateUsers",array_flip($tmp));
175                                         $smarty->assign("TemplateUser",$this->info['template_user_id']);
177                                         /* Create Team membership */ 
178                                         $str = "";
179                                         if(($this->is_account)==""){
180                                                 $dis = "";
181                                         }else{
182                                                 $dis = " disabled ";
183                                         }
185           if($this->acl_is_readable("Teams")){
186             foreach($this->handle->validTeams as $id){
187               if(in_array($id['company_id'],$this->info['TeamIDis'])){
188                 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
189                   checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
190               }else{
191                 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
192                   name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
193               }
194             }
195           }
196                                         $smarty->assign("validTeams",$str);
198                                         /* Assign ogw checkbox */
199                                         if($this->is_account){
200                                                 $smarty->assign("OGWstate","");
201                                                 $smarty->assign("is_account", " checked ");
202                                         }else{
203                                                 $smarty->assign("is_account", " ");
204                                                 $smarty->assign("OGWstate"," disabled ");
205                                         }
207                                         /* Assign lock status */
208                                         if($this->info['is_locked']){
209                                                 $smarty->assign("is_lockedCHK", " checked ");
210                                         }else{
211                                                 $smarty->assign("is_lockedCHK", "  ");
212                                         }
213                                         $smarty->assign("is_locked", $this->info['is_locked']);
215                                 } 
216                         }
217                 $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
218                 return ($display);
219         }
221         function remove_from_parent()
222         {
223                 /* remove database entries */
224                 if($this->initialy_was_account){
225                         $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
226                         $this->handle->SetInfos($this->info);
227                         $this->handle->Perform("REMOVE");
228                 }
229         }
232         /* Save data to object */
233         function save_object()
234         {
235                 /* get post data */
236                 if($this->is_account){
238       /* Get selected team chkboxes */
239       $this->info['TeamIDis'] = array();
240       if($this->acl_is_writeable("Teams")) {
241         foreach($_POST as $name => $value ){
242           if(preg_match("/team_/i",$name)){
243             if(!in_array($value,$this->info['TeamIDis'])){
244               $this->info['TeamIDis'][]=$value;
245             }
246           }
247         }
248       }
251                         /* Get location Team*/
252                         if(isset($_POST['LocationTeam']) && $this->acl_is_writeable("LocationTeam")){
253                                 $this->info['LocationTeamID'] = $_POST['LocationTeam'];
254                         }
256                         /* Get template user */
257                         if(isset($_POST['TemplateUser']) && $this->acl_is_writeable("TemplateUser") ){
258                                 $this->info['template_user_id'] = $_POST['TemplateUser'];
259                         }
261       /* get lock status */
262       if($this->acl_is_writeable("Locked")){
263         if(isset($_POST['is_locked'])){
264           $this->info['is_locked'] = $_POST['is_locked'];
265         }else{
266           $this->info['is_locked'] = 0;
267         }
268       }
269                 }
271                 /* change account status */
272                 if(isset($_POST['is_account'])){
273       if($this->acl_is_createable()){
274         $this->is_account = $_POST['is_account'];
275       }
276     }else{
277       if($this->acl_is_removeable()){
278         $this->is_account = false;//$_POST['is_account'];
279       }
280                 }
281         }
284         /* Save to LDAP */
285         function save()
286         {
287                 /* Save data */ 
288                 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
289                 $this->handle->SetInfos($this->info);
290                 $this->handle->checkInfos();
291                 if($this->initialy_was_account){
292                         $this->handle->Perform("EDIT");
293                 }else{
294                         $this->handle->Perform("ADD");
295                 }
296         }
298   
299   function PrepareForCopyPaste($src){
300     // Nothing to do, because this object can't be copied ... yet
301   }
304  /* Return plugin informations for acl handling 
305       #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */   
306   function plInfo()
307   {
308     return (array(
309           "plShortName"     => _("Opengroupware"),
310           "plDescription"   => _("Open groupware account settings")."&nbsp;:&nbsp;<u>"._("Connectivity addon")."</u>",
311           "plSelfModify"    => TRUE,
312           "plDepends"       => array("user"),
313           "plPriority"      => 26,                                 // Position in tabs
314           "plSection"     => array("personal" => _("My account")),
315           "plCategory"    => array("users"),
316           "plOptions"       => array(),
318           "plProvidedAcls"  => array(
319             "LocationTeam"  => _("Location team"),
320             "TemplateUser"  => _("Template user"),
321             "Locked"        => _("Locked"),
322             "Teams"         => _("Teams"))
323           ));
324   }
326 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
327 ?>