Code

Made proxy account compatible with acls
[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();
120     print_red(_("New ACLs are not implemeneted yet."));
122                 /* set default values */
123                 foreach(array("validLocationTeam","validTemplateUser","validLocationTeams","validTemplateUsers") as $ar){
124                         $smarty->assign($ar,array());
125                 }
126                 $smarty->assign("OGWstate"," disabled ");
127                 foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount","is_account"/*,"OGWPassword"*/) as $ar){
128                         $smarty->assign($ar,"");
129                         $smarty->assign($ar."CHK","");
130                         $smarty->assign($ar."ACL"," disabled ");
131                 }
133                 /* Check database extension */    
134                 if(!is_callable("pg_connect")){
135                         print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries."));
136                 }else
138                         /* Check if config exists */
139                         if(search_config($this->config->data,"opengwAccount","DATABASE")==""){
140                                 print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations."));
141                         }else{
143                                 /* Create handle */
144                                 $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
146                                 /* Check if we are successfully connected to db */
147                                 if(!$this->handle->connected){
148                                         print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice."));
149                                 }else{
151                                         /* Show main page */
152                                         $smarty->assign("OGWstate"," disabled ");
153                                         foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount"/*,"OGWPassword"*/) as $ar){
154                                                 $smarty->assign($ar."ACL",chkacl($this->acl,$ar));
155                                         }
157                                         /* Assign LocationTeams */
158                                         $tmp = array(""=>"none");
159                                         foreach($this->handle->validLocationTeam as $id){
160                                                 $tmp[$id['company_id']] = $id['description']; 
161                                         }
162                                         $smarty->assign("validLocationTeam",$tmp);
163                                         $smarty->assign("validLocationTeams",array_flip($tmp));
164                                         $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
166                                         /* Assign TemplateUsers*/
167                                         $tmp = array();
168                                         foreach($this->handle->validTemplateUser as $id){
169                                                 $tmp[$id['company_id']] = $id['name']; 
170                                         }
171                                         $smarty->assign("validTemplateUser",$tmp);
172                                         $smarty->assign("validTemplateUsers",array_flip($tmp));
173                                         $smarty->assign("TemplateUser",$this->info['template_user_id']);
175                                         /* Create Team membership */ 
176                                         $str = "";
177                                         if(($this->is_account)&&(chkacl($this->acl,"TeamIDs")=="")){
178                                                 $dis = "";
179                                         }else{
180                                                 $dis = " disabled ";
181                                         }
183                                         foreach($this->handle->validTeams as $id){
184                                                 if(in_array($id['company_id'],$this->info['TeamIDis'])){
185                                                         $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
186                                                                 checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
187                                                 }else{
188                                                         $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
189                                                                 name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
190                                                 }
191                                         }
192                                         $smarty->assign("validTeams",$str);
194                                         /* Assign ogw checkbox */
195                                         if($this->is_account){
196                                                 $smarty->assign("OGWstate","");
197                                                 $smarty->assign("is_account", " checked ");
198                                         }else{
199                                                 $smarty->assign("is_account", " ");
200                                                 $smarty->assign("OGWstate"," disabled ");
201                                         }
203                                         /* Assign acls */
204                                         foreach(array("LocationTeam","TemplateUser","Teams","is_locked") as $atr){
205                                                 $smarty->assign($atr."ACL",chkacl($this->acl,$atr));
206                                         }
208                                         /* Assign lock status */
209                                         if($this->info['is_locked']){
210                                                 $smarty->assign("is_lockedCHK", " checked ");
211                                         }else{
212                                                 $smarty->assign("is_lockedCHK", "  ");
213                                         }
214                                         $smarty->assign("is_locked", $this->info['is_locked']);
216                                 } 
217                         }
218       /*
219       if($this->SetPassword == false){
220         if($_SESSION['js'] == 1){
221           $smarty->assign("OGWPasswordACL"," disabled ");
222         }else{
223           $smarty->assign("OGWPasswordACL","");
224         }
225         $smarty->assign("OGWPassword","");
226         $smarty->assign("OGWPasswordCHK"," ");
227       }else{
228         $smarty->assign("OGWPasswordACL","");
229         $smarty->assign("OGWPassword",$this->OGWPassword);
230         $smarty->assign("OGWPasswordCHK"," checked ");
231       }
232       */
233                 $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
234                 return ($display);
235         }
237         function remove_from_parent()
238         {
239                 /* remove database entries */
240                 if($this->initialy_was_account){
241                         $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
242                         $this->handle->SetInfos($this->info);
243                         $this->handle->Perform("REMOVE");
244                 }
245         }
248         /* Save data to object */
249         function save_object()
250         {
251                 /* get post data */
252                 if($this->is_account){
254       /*
255       if(isset($_POST['SetPassword'])){
256         $this->SetPassword =true;
257       }else{
258         $this->SetPassword = false;
259       }
261       if((isset($_POST['OGWPassword']))&&($this->SetPassword)){
262         $this->OGWPassword      = $_POST['OGWPassword'];
263         $pwd = new passwordMethodCrypt($this->config);
264         
265         $this->info['password'] = preg_replace("/^{crypt}/","",$pwd->generate_hash($_POST['OGWPassword']));
266       }else{
267         if(isset($this->info['password'])){
268           unset($this->info['password']);
269         }
270       }
271       */
273                         /* Get selected team chkboxes */
274                         $this->info['TeamIDis'] = array();
275                         foreach($_POST as $name => $value ){
276                                 if(preg_match("/team_/i",$name)){
277                                         if(!in_array($value,$this->info['TeamIDis'])){
278                                                 $this->info['TeamIDis'][]=$value;
279                                         }
280                                 }
281                         }
283                         /* Get location Team*/
284                         if(isset($_POST['LocationTeam'])){
285                                 $this->info['LocationTeamID'] = $_POST['LocationTeam'];
286                         }
288                         /* Get template user */
289                         if(isset($_POST['TemplateUser'])){
290                                 $this->info['template_user_id'] = $_POST['TemplateUser'];
291                         }
293                         /* get lock status */
294                         if(isset($_POST['is_locked'])){
295                                 $this->info['is_locked'] = $_POST['is_locked'];
296                         }else{
297                                 $this->info['is_locked'] = 0;
298                         }
299                 }
301                 /* change account status */
302                 if(isset($_POST['is_account'])){
303                         $this->is_account = $_POST['is_account'];
304                 }else{
305                         $this->is_account = false;//$_POST['is_account'];
306                 }
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                 }else{
321                         $this->handle->Perform("ADD");
322                 }
323         }
325   
326   function PrepareForCopyPaste($src){
327     // Nothing to do, because this object can't be copied ... yet
328   }
331  /* Return plugin informations for acl handling 
332       #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */   
333   function plInfo()
334   {
335     return (array(
336           "plShortName"     => _("Opengroupware"),
337           "plDescription"   => _("Open groupware account settings"),
338           "plSelfModify"    => TRUE,
339           "plDepends"       => array("connectivity"),
340           "plPriority"      => 3,                                 // Position in tabs
341           "plSection"       => "personal",                        // This belongs to personal
342           "plCategory"      => array("gosaAccount"),
343           "plOptions"       => array(),
345           "plProvidedAcls"  => array(
346             "opengwAccount"   => "!!! FIXME "._("Open groupware account"))
347           ));
348   }
350 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
351 ?>