[gosa.git] / gosa-plugins / opengroupware / personal / connectivity / opengroupware / class_opengwAccount.inc
1 <?php
3 class opengwAccount extends plugin
4 {
5 /* Definitions */
6 var $plHeadline = "Opengroupware account";
7 var $plDescription = "Manage Opengroupware user settings";
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 var $view_logged = FALSE;
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 /* Get configurations */
54 $tmp = $this->config->get_cfg_value("opengwAccount",'username');
55 if(!empty($tmp)){
56 $atr = array();
57 $atr['LOGIN'] = $this->config->get_cfg_value("opengwAccount", 'username');
58 $atr['PASSWORD'] = $this->config->get_cfg_value("opengwAccount", 'password');
59 $atr['SERVER'] = $this->config->get_cfg_value("opengwAccount", 'datahost');
60 $atr['DB'] = $this->config->get_cfg_value("opengwAccount", 'database');
61 $this->serverCon = $atr;
62 }elseif(isset($this->config->data['SERVERS']['OPENGROUPWARE'])){
63 $this->serverCon = $this->config->data['SERVERS']['OPENGROUPWARE'];
64 }else{
65 $this->serverCon = array();
66 }
68 /* check if datebase funktions are available, and if database configurations are available */
69 if(is_callable("pg_connect") && count($this->serverCon)){
71 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
73 /* Check if current configuration allows database connection */
74 if($this->handle->connected){
76 /* Set login name, to check if this is_account */
77 if(isset($this->attrs['uid'][0])){
78 $this->handle->info['login'] = $this->attrs['uid'][0];
79 }else{
80 $this->handle->info['login'] = "";
81 }
83 /* If this is account get data from database first */
84 if($this->handle->CheckExistence()){
85 $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
87 /* This is an account */
88 $this->initialy_was_account = true;
89 $this->is_account= true;
90 }else{
91 /* this is no account */
92 $this->initialy_was_account = false;
93 $this->is_account= false;
95 /* Selectable in GOsa */
96 $this->info['template_user_id'] = 0;
97 $this->info['is_locked'] = 0;
98 $this->info['LocationTeamID'] = 0;
99 $this->info['TeamIDis'] = array();
100 }
102 /* Set settings from ldap */
103 foreach($this->attrsToUse as $name=>$attr){
104 if(isset($this->attrs[$attr][0])){
105 $this->info[$name] = $this->attrs[$attr][0];
106 }else{
107 $this->info[$name] = false;
108 }
109 }
111 /* Description is displayed as 'Nickname' */
112 $this->info['description'] = $this->info['login'];
114 if($this->info['sex'] == "F"){
115 $this->info['sex'] = "female";
116 }else{
117 $this->info['sex'] = "male";
118 }
120 }
122 /* Transmit data back to ogw handle */
123 $this->handle->SetInfos($this->info);
124 }
125 }
127 function execute()
128 {
129 plugin::execute();
130 /* Log view */
131 if($this->is_account && !$this->view_logged){
132 $this->view_logged = TRUE;
133 new log("view","users/".get_class($this),$this->dn);
134 }
136 /* Show tab dialog headers */
137 $display= "";
138 $smarty= get_smarty();
140 $smarty->assign("serverCon",count($this->serverCon));
141 $smarty->assign("validTeams","");
142 $smarty->assign("is_account", " ");
143 $smarty->assign("OGWstate"," disabled ");
144 $smarty->assign("validLocationTeam",array(" "));
145 $smarty->assign("validLocationTeams",array(" "));
146 $smarty->assign("LocationTeam",0);
147 $smarty->assign("validTemplateUser",array(" "));
148 $smarty->assign("validTemplateUsers",array(" "));
149 $smarty->assign("TemplateUser",0);
150 $smarty->assign("is_lockedCHK", " ");
151 $smarty->assign("is_locked", " ");
153 /* set default values */
154 $tmp = $this->plInfo();
155 foreach($tmp['plProvidedAcls'] as $acl => $desc){
156 $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
157 }
159 if((!$this->ReadOnly)&&(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))) {
160 $smarty->assign('opengwAccountACL', "");
161 }else{
162 $smarty->assign('opengwAccountACL', " disabled ");
163 }
165 if(count($this->serverCon))
167 /* Check database extension */
168 if(!is_callable("pg_connect") && count($this->serverCon)){
169 msg_dialog::display(_("Configuration error"), msgPool::missingext("postgresql"), ERROR_DIALOG);
170 }elseif(count($this->serverCon)){
172 /* Check if config exists */
173 $tmp2 = $this->config->get_cfg_value("opengwAccount", 'database');
174 if(empty($tmp2)){
175 msg_dialog::display(_("Configuration error"), msgPool::noserver(_("Opengroupware database")), ERROR_DIALOG);
176 }else{
178 /* Create handle */
179 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
181 /* Check if we are successfully connected to db */
182 if(!$this->handle->connected){
183 msg_dialog::display(_("Configuration error"), msgPool::dbconnect(_("Opengroupware")), ERROR_DIALOG);
184 }else{
186 /* Assign LocationTeams */
187 $tmp = array(""=>"none");
188 foreach($this->handle->validLocationTeam as $id){
189 $tmp[$id['company_id']] = $id['description'];
190 }
191 $smarty->assign("validLocationTeam",$tmp);
192 $smarty->assign("validLocationTeams",array_flip($tmp));
193 $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
195 /* Assign TemplateUsers*/
196 $tmp = array();
197 foreach($this->handle->validTemplateUser as $id){
198 $tmp[$id['company_id']] = $id['name'];
199 }
200 $smarty->assign("validTemplateUser",$tmp);
201 $smarty->assign("validTemplateUsers",array_flip($tmp));
202 $smarty->assign("TemplateUser",$this->info['template_user_id']);
204 /* Create Team membership */
205 $str = "";
206 if($this->is_account){
207 $dis = "";
208 }else{
209 $dis = " disabled ";
210 }
212 if($this->acl_is_readable("Teams")){
213 foreach($this->handle->validTeams as $id){
214 if(in_array_strict($id['company_id'],$this->info['TeamIDis'])){
215 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
216 checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
217 }else{
218 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
219 name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
220 }
221 }
222 }
223 $smarty->assign("validTeams",$str);
225 /* Assign ogw checkbox */
226 if($this->is_account){
227 $smarty->assign("OGWstate","");
228 $smarty->assign("is_account", " checked ");
229 }else{
230 $smarty->assign("is_account", " ");
231 $smarty->assign("OGWstate"," disabled ");
232 }
234 /* Assign lock status */
235 if($this->info['is_locked']){
236 $smarty->assign("is_lockedCHK", " checked ");
237 }else{
238 $smarty->assign("is_lockedCHK", " ");
239 }
240 $smarty->assign("is_locked", $this->info['is_locked']);
242 }
243 }
244 }
245 $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
246 return ($display);
247 }
249 function remove_from_parent()
250 {
251 /* remove database entries */
252 if($this->initialy_was_account){
253 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
254 $this->handle->SetInfos($this->info);
255 $this->handle->Perform("REMOVE");
257 new log("remove","users/".get_class($this),$this->dn);
258 }
259 }
262 /* Save data to object */
263 function save_object()
264 {
265 /* get post data */
266 if($this->is_account){
268 /* Get selected team chkboxes */
269 $this->info['TeamIDis'] = array();
270 if($this->acl_is_writeable("Teams")) {
271 foreach($_POST as $name => $value ){
272 if(preg_match("/team_/i",$name)){
273 if(!in_array_strict($value,$this->info['TeamIDis'])){
274 $this->info['TeamIDis'][]=$value;
275 }
276 }
277 }
278 }
281 /* Get location Team*/
282 if(isset($_POST['LocationTeam']) && $this->acl_is_writeable("LocationTeam")){
283 $this->info['LocationTeamID'] = get_post('LocationTeam');
284 }
286 /* Get template user */
287 if(isset($_POST['TemplateUser']) && $this->acl_is_writeable("TemplateUser") ){
288 $this->info['template_user_id'] = get_post('TemplateUser');
289 }
291 /* get lock status */
292 if($this->acl_is_writeable("Locked")){
293 if(isset($_POST['is_locked'])){
294 $this->info['is_locked'] = get_post('is_locked');
295 }else{
296 $this->info['is_locked'] = 0;
297 }
298 }
299 }
301 /* change account status */
302 if(isset($_POST['is_account'])){
303 if($this->acl_is_createable()){
304 $this->is_account = get_post('is_account');
305 }
306 }else{
307 if($this->acl_is_removeable()){
308 $this->is_account = false;//$_POST['is_account'];
309 }
310 }
311 }
314 /* Save to LDAP */
315 function save()
316 {
317 /* Save data */
318 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
319 $this->handle->SetInfos($this->info);
320 $this->handle->checkInfos();
321 if($this->initialy_was_account){
322 $this->handle->Perform("EDIT");
323 new log("modify","users/".get_class($this),$this->dn);
324 }else{
325 $this->handle->Perform("ADD");
326 new log("create","users/".get_class($this),$this->dn);
327 }
328 }
331 function PrepareForCopyPaste($src){
332 // Nothing to do, because this object can't be copied ... yet
333 }
336 /* Return plugin informations for acl handling
337 #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */
338 static function plInfo()
339 {
340 return (array(
341 "plShortName" => "OpenGroupware.org",
342 "plDescription" => _("OpenGroupware.org account settings")." ("._("Connectivity add-on").")",
343 "plSelfModify" => TRUE,
344 "plDepends" => array("user"),
345 "plPriority" => 26, // Position in tabs
346 "plSection" => array("personal" => _("My account")),
347 "plCategory" => array("users"),
348 "plOptions" => array(),
350 "plProperties" => array(
351 array(
352 "name" => "datahost",
353 "type" => "string",
354 "default" => "",
355 "description" => _("Server name used for OpenGroupware.org connections."),
356 "check" => "",
357 "migrate" => "",
358 "group" => "OpenGroupware",
359 "mandatory" => FALSE),
360 array(
361 "name" => "password",
362 "type" => "string",
363 "default" => "",
364 "description" => _("Password used OpenGroupware.org connections."),
365 "check" => "",
366 "migrate" => "",
367 "group" => "OpenGroupware",
368 "mandatory" => FALSE),
369 array(
370 "name" => "username",
371 "type" => "string",
372 "default" => "",
373 "description" => _("Username used for OpenGroupware.org connections."),
374 "check" => "",
375 "migrate" => "",
376 "group" => "OpenGroupware",
377 "mandatory" => FALSE),
378 array(
379 "name" => "database",
380 "type" => "string",
381 "default" => "",
382 "description" => _("Name of the database used for OpenGroupware.org connections."),
383 "check" => "",
384 "migrate" => "",
385 "group" => "OpenGroupware",
386 "mandatory" => FALSE),
387 ),
390 "plProvidedAcls" => array(
391 "LocationTeam" => _("Location team"),
392 "TemplateUser" => _("Template user"),
393 "Locked" => _("Locked"),
394 "Teams" => _("Teams"))
395 ));
396 }
397 }
398 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
399 ?>