Code

Added comments and translation tags to connectivity plinfo functions
[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          = "";
35         function opengwAccount ($config, $dn= NULL)
36         {
37                 plugin::plugin ($config, $dn);
39                 $this->info=array();
41                 /* is no account and was no account */
42                 $this->initialy_was_account = false;
43                 $this->is_account           = false;
45                 /* check if datebase funktions are available, and if database configurations are available */ 
46                 if(is_callable("pg_connect")){
48                         /* Get configurations */
49                         if(search_config($this->config->data,"opengwAccount","USERNAME")){
50                                 $atr = array();
51                                 $atr['LOGIN']   =       search_config($this->config->data,"opengwAccount","USERNAME");
52                                 $atr['PASSWORD']=       search_config($this->config->data,"opengwAccount","PASSWORD");
53                                 $atr['SERVER']  =       search_config($this->config->data,"opengwAccount","DATAHOST");
54                                 $atr['DB']              =       search_config($this->config->data,"opengwAccount","DATABASE");
55                                 $this->serverCon = $atr;
56                         }else{
57                                 $this->serverCon  = $this->config->data['SERVERS']['OPENGROUPWARE'];
58                         }
59                         $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
61                         /* Check if current configuration allows database connection */
62                         if($this->handle->connected){
64                                 /* Set login name, to check if this is_account */
65                                 if(isset($this->attrs['uid'][0])){
66                                         $this->handle->info['login'] = $this->attrs['uid'][0];
67                                 }else{
68                                         $this->handle->info['login'] = ""; 
69                                 }
71                                 /* If this is account get data from database first */
72                                 if($this->handle->CheckExistence()){
73                                         $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
75                                         /* This is an account */
76                                         $this->initialy_was_account = true;
77                                         $this->is_account= true;
78                                 }else{
79                                         /* this is no account */ 
80                                         $this->initialy_was_account = false;
81                                         $this->is_account= false;
83                                         /* Selectable in GOsa */
84                                         $this->info['template_user_id']   = 0;
85                                         $this->info['is_locked']          = 0;
86                                         $this->info['LocationTeamID']     = 0;
87                                         $this->info['TeamIDis']           = array();
88                                 }
90                                 /* Set settings from ldap */
91                                 foreach($this->attrsToUse as $name=>$attr){
92                                         if(isset($this->attrs[$attr][0])){
93                                                 $this->info[$name] = $this->attrs[$attr][0];
94                                         }else{
95                                                 $this->info[$name] = false;
96                                         }
97                                 } 
99                                 /* Description is displayed as 'Nickname' */
100                                 $this->info['description']          = $this->info['login'];
102                                 if($this->info['sex'] == "F"){
103                                         $this->info['sex']                = "female";
104                                 }else{
105                                         $this->info['sex']                = "male";
106                                 }
108                         }
110                         /* Transmit data back to ogw handle */
111                         $this->handle->SetInfos($this->info);
112                 }
113         }
115         function execute()
116         {
117                 /* Show tab dialog headers */
118                 $display= "";
119                 $smarty= get_smarty();
121                 /* set default values */
122                 foreach(array("validLocationTeam","validTemplateUser","validLocationTeams","validTemplateUsers") as $ar){
123                         $smarty->assign($ar,array());
124                 }
125                 $smarty->assign("OGWstate"," disabled ");
126                 foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount","is_account"/*,"OGWPassword"*/) as $ar){
127                         $smarty->assign($ar,"");
128                         $smarty->assign($ar."CHK","");
129                         $smarty->assign($ar."ACL"," disabled ");
130                 }
132                 /* Check database extension */    
133                 if(!is_callable("pg_connect")){
134                         print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries."));
135                 }else
137                         /* Check if config exists */
138                         if(search_config($this->config->data,"opengwAccount","DATABASE")==""){
139                                 print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations."));
140                         }else{
142                                 /* Create handle */
143                                 $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
145                                 /* Check if we are successfully connected to db */
146                                 if(!$this->handle->connected){
147                                         print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice."));
148                                 }else{
150                                         /* Show main page */
151                                         $smarty->assign("OGWstate"," disabled ");
152                                         foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount"/*,"OGWPassword"*/) as $ar){
153                                                 $smarty->assign($ar."ACL",chkacl($this->acl,$ar));
154                                         }
156                                         /* Assign LocationTeams */
157                                         $tmp = array(""=>"none");
158                                         foreach($this->handle->validLocationTeam as $id){
159                                                 $tmp[$id['company_id']] = $id['description']; 
160                                         }
161                                         $smarty->assign("validLocationTeam",$tmp);
162                                         $smarty->assign("validLocationTeams",array_flip($tmp));
163                                         $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
165                                         /* Assign TemplateUsers*/
166                                         $tmp = array();
167                                         foreach($this->handle->validTemplateUser as $id){
168                                                 $tmp[$id['company_id']] = $id['name']; 
169                                         }
170                                         $smarty->assign("validTemplateUser",$tmp);
171                                         $smarty->assign("validTemplateUsers",array_flip($tmp));
172                                         $smarty->assign("TemplateUser",$this->info['template_user_id']);
174                                         /* Create Team membership */ 
175                                         $str = "";
176                                         if(($this->is_account)&&(chkacl($this->acl,"TeamIDs")=="")){
177                                                 $dis = "";
178                                         }else{
179                                                 $dis = " disabled ";
180                                         }
182                                         foreach($this->handle->validTeams as $id){
183                                                 if(in_array($id['company_id'],$this->info['TeamIDis'])){
184                                                         $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
185                                                                 checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
186                                                 }else{
187                                                         $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
188                                                                 name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
189                                                 }
190                                         }
191                                         $smarty->assign("validTeams",$str);
193                                         /* Assign ogw checkbox */
194                                         if($this->is_account){
195                                                 $smarty->assign("OGWstate","");
196                                                 $smarty->assign("is_account", " checked ");
197                                         }else{
198                                                 $smarty->assign("is_account", " ");
199                                                 $smarty->assign("OGWstate"," disabled ");
200                                         }
202                                         /* Assign acls */
203                                         foreach(array("LocationTeam","TemplateUser","Teams","is_locked") as $atr){
204                                                 $smarty->assign($atr."ACL",chkacl($this->acl,$atr));
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       /*
218       if($this->SetPassword == false){
219         if($_SESSION['js'] == 1){
220           $smarty->assign("OGWPasswordACL"," disabled ");
221         }else{
222           $smarty->assign("OGWPasswordACL","");
223         }
224         $smarty->assign("OGWPassword","");
225         $smarty->assign("OGWPasswordCHK"," ");
226       }else{
227         $smarty->assign("OGWPasswordACL","");
228         $smarty->assign("OGWPassword",$this->OGWPassword);
229         $smarty->assign("OGWPasswordCHK"," checked ");
230       }
231       */
232                 $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
233                 return ($display);
234         }
236         function remove_from_parent()
237         {
238                 /* remove database entries */
239                 if($this->initialy_was_account){
240                         $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
241                         $this->handle->SetInfos($this->info);
242                         $this->handle->Perform("REMOVE");
243                 }
244         }
247         /* Save data to object */
248         function save_object()
249         {
250                 /* get post data */
251                 if($this->is_account){
253       /*
254       if(isset($_POST['SetPassword'])){
255         $this->SetPassword =true;
256       }else{
257         $this->SetPassword = false;
258       }
260       if((isset($_POST['OGWPassword']))&&($this->SetPassword)){
261         $this->OGWPassword      = $_POST['OGWPassword'];
262         $pwd = new passwordMethodCrypt($this->config);
263         
264         $this->info['password'] = preg_replace("/^{crypt}/","",$pwd->generate_hash($_POST['OGWPassword']));
265       }else{
266         if(isset($this->info['password'])){
267           unset($this->info['password']);
268         }
269       }
270       */
272                         /* Get selected team chkboxes */
273                         $this->info['TeamIDis'] = array();
274                         foreach($_POST as $name => $value ){
275                                 if(preg_match("/team_/i",$name)){
276                                         if(!in_array($value,$this->info['TeamIDis'])){
277                                                 $this->info['TeamIDis'][]=$value;
278                                         }
279                                 }
280                         }
282                         /* Get location Team*/
283                         if(isset($_POST['LocationTeam'])){
284                                 $this->info['LocationTeamID'] = $_POST['LocationTeam'];
285                         }
287                         /* Get template user */
288                         if(isset($_POST['TemplateUser'])){
289                                 $this->info['template_user_id'] = $_POST['TemplateUser'];
290                         }
292                         /* get lock status */
293                         if(isset($_POST['is_locked'])){
294                                 $this->info['is_locked'] = $_POST['is_locked'];
295                         }else{
296                                 $this->info['is_locked'] = 0;
297                         }
298                 }
300                 /* change account status */
301                 if(isset($_POST['is_account'])){
302                         $this->is_account = $_POST['is_account'];
303                 }else{
304                         $this->is_account = false;//$_POST['is_account'];
305                 }
307         }
310         /* Save to LDAP */
311         function save()
312         {
313                 /* Save data */ 
314                 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
315                 $this->handle->SetInfos($this->info);
316                 $this->handle->checkInfos();
317                 if($this->initialy_was_account){
318                         $this->handle->Perform("EDIT");
319                 }else{
320                         $this->handle->Perform("ADD");
321                 }
322         }
324   
325   function PrepareForCopyPaste($src){
326     // Nothing to do, because this object can't be copied ... yet
327   }
330  /* Return pluign informations for acl handling 
331       #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */   
332   function plInfo()
333   {
334     return (array(      
335           "plDescription"   => _("Open groupware account settings"),
336           "plSelfModify"    => TRUE,
337           "plDepends"       => array("objectClass" => "gosaAccount"),
338           "opengwAccount"   => "!!! FIXME "._("Open groupware account")));
339   }
340   
342 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
343 ?>