Code

Big commit for opengroupware account
[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("gosaWebdavAccount");
18   var $attrsToUse    = array( "salutation"  =>"vocation",
19                               "name"        =>"sn",
20                               "firstname"   =>"givenName",
21                               "login"       =>"uid",
22                               "degree"      =>"academicTitle",
23                               "birthday"    =>"dateOfBirth",
24                               "sex"         =>"gender",
25                               "street"      =>"street",
26                               "zip"         =>"postalCode",
27                               "value_string"=>"mail",
28                               "number"      =>"telephoneNumber"
29                             );
30   var $serverCon =  false;
32   var $handle   = NULL;
33   var $is_account  = false;
35   function opengwAccount ($config, $dn= NULL)
36   {
37     plugin::plugin ($config, $dn);
39     $this->info=array();
41     $this->initialy_was_account = false;
42     $this->is_account= false;
43     if(!is_callable("pg_connect")){
44 //      print_red(_("Your configuration is missing a postgresql extension. Can't perform any database queries."));
45     }elseif(!isset($this->config->data['SERVERS']['OPENGROUPWARE'])){
46 //      print_red(_("Missing database configuration for opengroupware. Can't get or set any informations."));
47     }else{
48       $this->serverCon = $this->config->data['SERVERS']['OPENGROUPWARE'];
49       $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
51       if(!$this->handle->connected){
52 //        print_red(_("Can't connect to specified database. Please check given configuration twice."));
53       }else{
54         $this->handle->info['login'] = $this->attrs['uid'][0];
55         if($this->handle->CheckExistence()){
56           $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
57           $this->initialy_was_account = true;
58           $this->is_account= true;
59         }else{
60           $this->initialy_was_account = false;
61           $this->is_account= false;
63           foreach($this->attrsToUse as $name=>$attr){
64             if(isset($this->attrs[$attr][0])){
65               $this->info[$name] = $this->attrs[$attr][0];
66             }else{
67               $this->info[$name] = false;
68             }
69           } 
70           $this->info['description']        = $this->info['firstname']." ".$this->info['name'];
71           if($this->info['sex'] == "F"){
72             $this->info['sex']                = "female";
73           }else{
74             $this->info['sex']                = "male";
75           }
77           /* Selectable in GOsa */
78           $this->info['template_user_id']   = 0;
79           $this->info['is_locked']          = 0;
80           $this->info['LocationTeamID']     = 0;
81           $this->info['TeamIDis']           = array();
82         }
84         if(!is_array($this->info['TeamIDis'])){
85           $this->info['TeamIDis'] = array();
86         }
87         $this->handle->SetInfos($this->info);
88       }
89     }
90   }
92   function execute()
93   {
94     /* Show tab dialog headers */
95     $display= "";
96     $smarty= get_smarty();
97     foreach(array("validLocationTeam","validTemplateUser","validLocationTeams","validTemplateUsers") as $ar){
98       $smarty->assign($ar,array());
99     }
101     $smarty->assign("OGWstate"," disabled ");
102     foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount") as $ar){
103       $smarty->assign($ar,"");
104       $smarty->assign($ar."CHK","");
105       $smarty->assign($ar."ACL"," disabled ");
106     }
108     
109     if(!is_callable("pg_connect")){
110       print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries."));
111     }elseif(!isset($this->config->data['SERVERS']['OPENGROUPWARE'])){
112       print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations."));
113     }else{
114       $this->serverCon = $this->config->data['SERVERS']['OPENGROUPWARE'];
115       $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
116       if(!$this->handle->connected){
117         print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice."));
118       }else{
119         $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
120         /* Show main page */
122         $smarty->assign("OGWstate"," disabled ");
123         foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount") as $ar){
124           $smarty->assign($ar."ACL",chkacl($this->acl,$ar));
125         }
127         $tmp = array(""=>"none");
128         foreach($this->handle->validLocationTeam as $id){
129           $tmp[$id['company_id']] = $id['description']; 
130         }
131         $smarty->assign("validLocationTeam",$tmp);
132         $smarty->assign("validLocationTeams",array_flip($tmp));
133         $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
135         $tmp = array();
136         foreach($this->handle->validTemplateUser as $id){
137           $tmp[$id['company_id']] = $id['name']; 
138         }
139         $smarty->assign("validTemplateUser",$tmp);
140         $smarty->assign("validTemplateUsers",array_flip($tmp));
141         $smarty->assign("TemplateUser",$this->info['template_user_id']);
142         
144         $this->handle->CheckExistence();
145         $str = "";
146         if($this->is_account){
147           $dis = "";
148         }else{
149           $dis = " disabled ";
150         }
152         foreach($this->handle->validTeams as $id){
153           if(in_array($id['company_id'],$this->info['TeamIDis'])){
154             $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
155           }else{
156             $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
157           }
158         }
159         $smarty->assign("validTeams",$str);
161         if($this->is_account){
162           $smarty->assign("OGWstate","");
163           $smarty->assign("is_account", " checked ");
164         }else{
165           $smarty->assign("is_account", " ");
166           $smarty->assign("OGWstate"," disabled ");
167         }
169         foreach(array("LocationTeam","TemplateUser","Teams","is_locked") as $atr){
170           $smarty->assign($atr."ACL",chkacl($this->acl,$atr));
171         }
173         if($this->info['is_locked']){
174           $smarty->assign("is_lockedCHK", " checked ");
175         }else{
176           $smarty->assign("is_lockedCHK", "  ");
177         }
179         $smarty->assign("is_locked", $this->info['is_locked']);
180       } 
181     }
182     $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
183     return ($display);
184   }
186   function remove_from_parent()
187   {
188     if($this->initialy_was_account){
189       $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
190       $this->handle->SetInfos($this->info);
191       $this->handle->Perform("REMOVE");
192     }
193   }
196   /* Save data to object */
197   function save_object()
198   {
199     if($this->is_account){
200       $this->info['TeamIDis'] = array();
201       foreach($_POST as $name => $value ){
202         if(preg_match("/team_/i",$name)){
203           if(!in_array($value,$this->info['TeamIDis'])){
204             $this->info['TeamIDis'][]=$value;
205           }
206         }
207       }
208       if(isset($_POST['LocationTeam'])){
209         $this->info['LocationTeamID'] = $_POST['LocationTeam'];
210       }
211       
212       if(isset($_POST['TemplateUser'])){
213         $this->info['template_user_id'] = $_POST['TemplateUser'];
214       }
215       
216       if(isset($_POST['is_locked'])){
217         $this->info['is_locked'] = $_POST['is_locked'];
218       }else{
219         $this->info['is_locked'] = 0;
220       }
221     }
222  
223     if(isset($_POST['is_account'])){
224       $this->is_account = $_POST['is_account'];
225     }else{
226       $this->is_account = false;//$_POST['is_account'];
227     }
229   }
232   /* Save to LDAP */
233   function save()
234   { 
235     $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
236     $this->handle->SetInfos($this->info);
237     $this->handle->checkInfos();
238     if($this->initialy_was_account){
239       $this->handle->Perform("EDIT");
240     }else{
241       $this->handle->Perform("ADD");
242     }
243   }
247 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
248 ?>