Code

Added some acls to connectivity addons
[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         /* CLI vars */
10         var $cli_summary      = "Manage users webdav account";
11         var $cli_description  = "Some longer text\nfor help";
12         var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
14         /* attribute list for save action */
15         var $attributes       = array();
16         var $objectclasses    = array();
18   var $SetPassword   = false;
20         /* Attribute mapping opengroupware->ldap  */
21         var $attrsToUse    = array( "salutation"  =>"vocation",
22                         "name"        =>"sn",
23                         "firstname"   =>"givenName",
24                         "login"       =>"uid",
25                         "degree"      =>"academicTitle",
26                         "birthday"    =>"dateOfBirth",
27                         "sex"         =>"gender",
28                         "street"      =>"street",
29                         "zip"         =>"postalCode",
30                         "value_string"=>"mail",
31                         "number"      =>"telephoneNumber"
32                         );
34         var $serverCon            =  false;
35         var $handle               = NULL;
36         var $is_account           = false;
37         var $initialy_was_account = false;
38   var $OGWPassword          = "";
40         function opengwAccount ($config, $dn= NULL)
41         {
42                 plugin::plugin ($config, $dn);
44                 $this->info=array();
46                 /* is no account and was no account */
47                 $this->initialy_was_account = false;
48                 $this->is_account           = false;
50                 /* check if datebase funktions are available, and if database configurations are available */ 
51                 if(is_callable("pg_connect")){
53                         /* Get configurations */
54                         if(search_config($this->config->data,"opengwAccount","USERNAME")){
55                                 $atr = array();
56                                 $atr['LOGIN']   =       search_config($this->config->data,"opengwAccount","USERNAME");
57                                 $atr['PASSWORD']=       search_config($this->config->data,"opengwAccount","PASSWORD");
58                                 $atr['SERVER']  =       search_config($this->config->data,"opengwAccount","DATAHOST");
59                                 $atr['DB']              =       search_config($this->config->data,"opengwAccount","DATABASE");
60                                 $this->serverCon = $atr;
61                         }else{
62                                 $this->serverCon  = $this->config->data['SERVERS']['OPENGROUPWARE'];
63                         }
64                         $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
66                         /* Check if current configuration allows database connection */
67                         if($this->handle->connected){
69                                 /* Set login name, to check if this is_account */
70                                 if(isset($this->attrs['uid'][0])){
71                                         $this->handle->info['login'] = $this->attrs['uid'][0];
72                                 }else{
73                                         $this->handle->info['login'] = ""; 
74                                 }
76                                 /* If this is account get data from database first */
77                                 if($this->handle->CheckExistence()){
78                                         $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
80                                         /* This is an account */
81                                         $this->initialy_was_account = true;
82                                         $this->is_account= true;
83                                 }else{
84                                         /* this is no account */ 
85                                         $this->initialy_was_account = false;
86                                         $this->is_account= false;
88                                         /* Selectable in GOsa */
89                                         $this->info['template_user_id']   = 0;
90                                         $this->info['is_locked']          = 0;
91                                         $this->info['LocationTeamID']     = 0;
92                                         $this->info['TeamIDis']           = array();
93                                 }
95                                 /* Set settings from ldap */
96                                 foreach($this->attrsToUse as $name=>$attr){
97                                         if(isset($this->attrs[$attr][0])){
98                                                 $this->info[$name] = $this->attrs[$attr][0];
99                                         }else{
100                                                 $this->info[$name] = false;
101                                         }
102                                 } 
104                                 /* Description is displayed as 'Nickname' */
105                                 $this->info['description']          = $this->info['login'];
107                                 if($this->info['sex'] == "F"){
108                                         $this->info['sex']                = "female";
109                                 }else{
110                                         $this->info['sex']                = "male";
111                                 }
113                         }
115                         /* Transmit data back to ogw handle */
116                         $this->handle->SetInfos($this->info);
117                 }
118         }
120         function execute()
121         {
122                 /* Show tab dialog headers */
123                 $display= "";
124                 $smarty= get_smarty();
126                 /* set default values */
127                 foreach(array("validLocationTeam","validTemplateUser","validLocationTeams","validTemplateUsers") as $ar){
128                         $smarty->assign($ar,array());
129                 }
130                 $smarty->assign("OGWstate"," disabled ");
131                 foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount","is_account"/*,"OGWPassword"*/) as $ar){
132                         $smarty->assign($ar,"");
133                         $smarty->assign($ar."CHK","");
134                         $smarty->assign($ar."ACL"," disabled ");
135                 }
137                 /* Check database extension */    
138                 if(!is_callable("pg_connect")){
139                         print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries."));
140                 }else
142                         /* Check if config exists */
143                         if(search_config($this->config->data,"opengwAccount","DATABASE")==""){
144                                 print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations."));
145                         }else{
147                                 /* Create handle */
148                                 $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
150                                 /* Check if we are successfully connected to db */
151                                 if(!$this->handle->connected){
152                                         print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice."));
153                                 }else{
155                                         /* Show main page */
156                                         $smarty->assign("OGWstate"," disabled ");
157                                         foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount"/*,"OGWPassword"*/) as $ar){
158                                                 $smarty->assign($ar."ACL",chkacl($this->acl,$ar));
159                                         }
161                                         /* Assign LocationTeams */
162                                         $tmp = array(""=>"none");
163                                         foreach($this->handle->validLocationTeam as $id){
164                                                 $tmp[$id['company_id']] = $id['description']; 
165                                         }
166                                         $smarty->assign("validLocationTeam",$tmp);
167                                         $smarty->assign("validLocationTeams",array_flip($tmp));
168                                         $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
170                                         /* Assign TemplateUsers*/
171                                         $tmp = array();
172                                         foreach($this->handle->validTemplateUser as $id){
173                                                 $tmp[$id['company_id']] = $id['name']; 
174                                         }
175                                         $smarty->assign("validTemplateUser",$tmp);
176                                         $smarty->assign("validTemplateUsers",array_flip($tmp));
177                                         $smarty->assign("TemplateUser",$this->info['template_user_id']);
179                                         /* Create Team membership */ 
180                                         $str = "";
181                                         if(($this->is_account)&&(chkacl($this->acl,"TeamIDs")=="")){
182                                                 $dis = "";
183                                         }else{
184                                                 $dis = " disabled ";
185                                         }
187                                         foreach($this->handle->validTeams as $id){
188                                                 if(in_array($id['company_id'],$this->info['TeamIDis'])){
189                                                         $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
190                                                                 checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
191                                                 }else{
192                                                         $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
193                                                                 name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
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 acls */
208                                         foreach(array("LocationTeam","TemplateUser","Teams","is_locked") as $atr){
209                                                 $smarty->assign($atr."ACL",chkacl($this->acl,$atr));
210                                         }
212                                         /* Assign lock status */
213                                         if($this->info['is_locked']){
214                                                 $smarty->assign("is_lockedCHK", " checked ");
215                                         }else{
216                                                 $smarty->assign("is_lockedCHK", "  ");
217                                         }
218                                         $smarty->assign("is_locked", $this->info['is_locked']);
220                                 } 
221                         }
222       /*
223       if($this->SetPassword == false){
224         if($_SESSION['js'] == 1){
225           $smarty->assign("OGWPasswordACL"," disabled ");
226         }else{
227           $smarty->assign("OGWPasswordACL","");
228         }
229         $smarty->assign("OGWPassword","");
230         $smarty->assign("OGWPasswordCHK"," ");
231       }else{
232         $smarty->assign("OGWPasswordACL","");
233         $smarty->assign("OGWPassword",$this->OGWPassword);
234         $smarty->assign("OGWPasswordCHK"," checked ");
235       }
236       */
237                 $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
238                 return ($display);
239         }
241         function remove_from_parent()
242         {
243                 /* remove database entries */
244                 if($this->initialy_was_account){
245                         $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
246                         $this->handle->SetInfos($this->info);
247                         $this->handle->Perform("REMOVE");
248                 }
249         }
252         /* Save data to object */
253         function save_object()
254         {
255                 /* get post data */
256                 if($this->is_account){
258       /*
259       if(isset($_POST['SetPassword'])){
260         $this->SetPassword =true;
261       }else{
262         $this->SetPassword = false;
263       }
265       if((isset($_POST['OGWPassword']))&&($this->SetPassword)){
266         $this->OGWPassword      = $_POST['OGWPassword'];
267         $pwd = new passwordMethodCrypt($this->config);
268         
269         $this->info['password'] = preg_replace("/^{crypt}/","",$pwd->generate_hash($_POST['OGWPassword']));
270       }else{
271         if(isset($this->info['password'])){
272           unset($this->info['password']);
273         }
274       }
275       */
277                         /* Get selected team chkboxes */
278                         $this->info['TeamIDis'] = array();
279                         foreach($_POST as $name => $value ){
280                                 if(preg_match("/team_/i",$name)){
281                                         if(!in_array($value,$this->info['TeamIDis'])){
282                                                 $this->info['TeamIDis'][]=$value;
283                                         }
284                                 }
285                         }
287                         /* Get location Team*/
288                         if(isset($_POST['LocationTeam'])){
289                                 $this->info['LocationTeamID'] = $_POST['LocationTeam'];
290                         }
292                         /* Get template user */
293                         if(isset($_POST['TemplateUser'])){
294                                 $this->info['template_user_id'] = $_POST['TemplateUser'];
295                         }
297                         /* get lock status */
298                         if(isset($_POST['is_locked'])){
299                                 $this->info['is_locked'] = $_POST['is_locked'];
300                         }else{
301                                 $this->info['is_locked'] = 0;
302                         }
303                 }
305                 /* change account status */
306                 if(isset($_POST['is_account'])){
307                         $this->is_account = $_POST['is_account'];
308                 }else{
309                         $this->is_account = false;//$_POST['is_account'];
310                 }
312         }
315         /* Save to LDAP */
316         function save()
317         {
318                 /* Save data */ 
319                 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
320                 $this->handle->SetInfos($this->info);
321                 $this->handle->checkInfos();
322                 if($this->initialy_was_account){
323                         $this->handle->Perform("EDIT");
324                 }else{
325                         $this->handle->Perform("ADD");
326                 }
327         }
329   
330   function PrepareForCopyPaste($src){
331     // Nothing to do, because this object can't be copied ... yet
332   }
335   function plInfo()
336   {
337     return (array(      "plDescription"   => _("Open groupware account settings"),
338           "plSelfModify"    => TRUE,
339           "plDepends"       => array("objectClass" => "gosaAccount"),
340           "opengwAccount"   => "Open groupware account"));
341   }
342   
344 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
345 ?>