From: hickert Date: Tue, 6 Dec 2005 14:38:31 +0000 (+0000) Subject: Big commit for opengroupware account X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3add590869fa80579f8bcc0658eb7ead1b514640;p=gosa.git Big commit for opengroupware account git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2241 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/contrib/gosa.conf b/contrib/gosa.conf index 6d392760d..c1ff3770d 100644 --- a/contrib/gosa.conf +++ b/contrib/gosa.conf @@ -168,6 +168,7 @@ + diff --git a/include/class_config.inc b/include/class_config.inc index a5eecb263..edffe0dac 100644 --- a/include/class_config.inc +++ b/include/class_config.inc @@ -341,6 +341,12 @@ class config { 'PASSWORD' => $attrs['goFaxPassword'][0]); } + $this->data['SERVERS']['OPENGROUPWARE']= array( + 'SERVER' => "vserver-18", + 'LOGIN' => "ogo", + 'PASSWORD' => "", + 'DB' => "ogo"); + /* Get asterisk servers */ $ldap->cd ($this->current['BASE']); $ldap->search ("(objectClass=goFonServer)"); diff --git a/include/class_opengw.inc b/include/class_opengw.inc index 159ddf28b..62ff56473 100755 --- a/include/class_opengw.inc +++ b/include/class_opengw.inc @@ -22,25 +22,71 @@ class ogw{ var $LastError = ""; var $option = ""; + var $connected = false; function ogw($username,$password,$host,$db) { $this->ogo = new pgre_sql($username,$password,$host,$db); - $this->validLocationTeam = $this->ogo->GetLocationTeam(); - $this->validTemplateUser = $this->ogo->GetTemplateUser(); - $this->validTeams = $this->ogo->GetTeams(); + if($this->ogo->is_connected){ + $this->validLocationTeam = $this->ogo->GetLocationTeam(); + $this->validTemplateUser = $this->ogo->GetTemplateUser(); + $this->validTeams = $this->ogo->GetTeams(); + $this->connected = true; + }else{ + $this->validLocationTeam = array();//$this->ogo->GetLocationTeam(); + $this->validTemplateUser = array();//$this->ogo->GetTemplateUser(); + $this->validTeams = array();//$this->ogo->GetTeams(); + $this->connected = false; + } } function SetInfos($infos) { + $infos['name1'] = $infos['name']; $this->info = $infos; - $info['name1'] = $info['name']; } - function GetInfos() - { - return("NIY"); + function GetInfos($uid) + { + $ret = array(); + $qry = "SELECT is_person,is_account,is_intra_account,is_extra_account, + number,owner_id,object_version,company_id,template_user_id,is_locked, + name,firstname,description,salutation,login,degree,birthday,sex + FROM person WHERE login='".$uid."';"; + $res = $this->ogo->FetchAllRows($this->ogo->Query($qry)); + $ret = $res[0]; + + $qry = "SELECT street,zip,zipcity,country,state FROM address WHERE company_id = ".$ret['company_id']." limit 1;"; + $res = $this->ogo->FetchAllRows($this->ogo->Query($qry)); + $ret = array_merge($ret,$res[0]); + + $qry = "SELECT company_id FROM company_assignment + WHERE (sub_company_id=".$ret['company_id'].") + AND company_id IN + (SELECT company_id FROM team WHERE (is_team=1) + AND + company_id NOT IN (SELECT company_id FROM team WHERE is_location_team=1));"; + $res = $this->ogo->FetchAllRows($this->ogo->Query($qry)); + if(is_array($res)){ + foreach($res as $r){ + $ret['TeamIDis'][]=$r['company_id']; + } + }else{ + $ret['TeamIDis']=array(); + } + + $qry = "SELECT value_string from company_value WHERE company_id=".$ret['company_id'].";"; + $res = $this->ogo->FetchAllRows($this->ogo->Query($qry)); + $ret = array_merge($ret,$res[0]); + + $qry ="SELECT company_id FROM company_assignment + WHERE (sub_company_id=".$ret['company_id'].") + AND company_id IN (SELECT company_id FROM team WHERE (is_location_team=1));"; + $res = $this->ogo->FetchAllRows($this->ogo->Query($qry)); + $ret['LocationTeamID'] = $res[0]['company_id']; + + return($ret); } function Perform($option) @@ -110,7 +156,7 @@ class ogw{ function CheckExistence() { /* Check if thios entry already exists */ - $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';"; + $qry = "SELECT login,name FROM person WHERE login='".$this->info['login']."';"; $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry)); if($ist){ return(true); @@ -130,7 +176,7 @@ class ogw{ foreach($this->MAY as $name){ if((!isset($this->info[$name]))||(empty($this->info[$name]))){ - $info[$name] = false; + $this->info[$name] = false; } } @@ -196,7 +242,7 @@ class ogw{ "number","description","is_locked","login","name","name","firstname", "salutation","degree","birthday","sex","db_status"); $this->info['company_id'] = $this->ogo->gen_id(); - $userID = "OGo".$this->info['company_id']; + $this->info['userID'] = "OGo".$this->info['company_id']; foreach($arr as $attr){ if($attr == "number"){ $add_user[$attr] = $this->info['userID']; @@ -370,13 +416,14 @@ class ogw{ /* Create entries for company value */ + $QUERY[] = "DELETE FROM company_value WHERE company_id=".$ist[0]['company_id']." AND attribute='mail1';"; $arr = array("db_status","value_string","attribute","company_id","company_value_id"); $this->info['attribute'] = "email1"; $this->info['company_value_id'] = $this->ogo->gen_id(); foreach($arr as $attr){ $add_company_value[$attr] = $this->info[$attr]; } - $QUERY[] = gen_syntax($add_company_value,"company_value","EDIT",$ist); + $QUERY[] = gen_syntax($add_company_value,"company_value","ADD",false); /* diff --git a/include/class_pgsql_opengw.inc b/include/class_pgsql_opengw.inc index ed9544ada..2c6ce876d 100644 --- a/include/class_pgsql_opengw.inc +++ b/include/class_pgsql_opengw.inc @@ -19,22 +19,20 @@ class pgre_sql{ if($this->_connect()){ $this->is_connected = true; - } - - return($this->is_connected); + }else{ + $this->is_connected = false; + } } function _connect() { error_reporting(E_ALL); if(is_callable("pg_connect")){ - $this->handle = pg_connect("dbname=".$this->db." host=".$this->server." user=".$this->user); + $this->handle = @pg_connect("dbname=".$this->db." host=".$this->server." user=".$this->user); if(!$this->handle){ - print "can't connect to pgsql :"; - exit(); + $this->handle = false; } }else{ - print "Extension fpr pgsql is missing"; $this->handle = false; } return($this->handle); @@ -111,8 +109,12 @@ function gen_syntax($array,$tablename,$act,$ist) $company_id = $ist[0]['company_id']; foreach($array as $name => $value){ - if(empty($value)) continue; - + if((empty($value))&&(!preg_match("/^is_/i",$name))) continue; + + if((empty($value))&&(preg_match("/^is_/i",$name))){ + $value= 0; + } + if(!is_numeric($value)){ $str.= " ".$name."='".$value."', "; }else{ @@ -128,8 +130,11 @@ function gen_syntax($array,$tablename,$act,$ist) $attrs = ""; $values = ""; foreach($array as $name => $attribute){ - - if(empty($attribute)) continue; + if((empty($attribute))&&(!preg_match("/^is_/i",$name))) continue; + + if((empty($attribute))&&(preg_match("/^is_/i",$name))){ + $attribute= 0; + } if(is_numeric($attribute)){ $attrs .= $name.", "; diff --git a/plugins/personal/connectivity/class_opengwAccount.inc b/plugins/personal/connectivity/class_opengwAccount.inc index 0980c8867..c4a7f8c2c 100644 --- a/plugins/personal/connectivity/class_opengwAccount.inc +++ b/plugins/personal/connectivity/class_opengwAccount.inc @@ -15,68 +15,169 @@ class opengwAccount extends plugin var $attributes= array(); var $objectclasses= array("gosaWebdavAccount"); + var $attrsToUse = array( "salutation" =>"vocation", + "name" =>"sn", + "firstname" =>"givenName", + "login" =>"uid", + "degree" =>"academicTitle", + "birthday" =>"dateOfBirth", + "sex" =>"gender", + "street" =>"street", + "zip" =>"postalCode", + "value_string"=>"mail", + "number" =>"telephoneNumber" + ); + var $serverCon = false; + var $handle = NULL; + var $is_account = false; function opengwAccount ($config, $dn= NULL) { plugin::plugin ($config, $dn); - $this->handle = new ogw("ogo","","vserver-18","ogo");//username,$password,$host,$db - $info['login'] = $this->uid; - if($this->handle->CheckExistence()){ - $this->info = $this->handle->GetInfo(); - }else{ - /* Generic attributes */ - $info['salutation'] = $this->attrs['vocation']; - $info['name'] = $this->attrs['sn']; - $info['firstname'] = $this->attrs['givenName']; - $info['login'] = $this->attrs['uid']; - $info['description'] = $info['firstname']." ".$info['name']; - $info['degree'] = $this->attrs['academicTitle']; - $info['birthday'] = $this->attrs['dateOfBirth']; - - if($this->attrs['gender'] == "F"){ - $info['sex'] = "female"; - }else{ - $info['sex'] = "male"; - } - /* address settings */ - $info['street'] = $this->attrs['street'];//"iweg 2"; - $info['zip'] = $this->attrs['postalCode'];//"59821"; -// $info['country'] = $this->attrs[''];//"Arnbserg"; - $info['zipcity'] = $info['zip']." ".$info['country']; -// $info['state'] = $this->attrs[''];//"Germany"; + $this->info=array(); - /* the email address*/ - $info['value_string'] = $this->attrs['mail']; + $this->initialy_was_account = false; + $this->is_account= false; + if(!is_callable("pg_connect")){ +// print_red(_("Your configuration is missing a postgresql extension. Can't perform any database queries.")); + }elseif(!isset($this->config->data['SERVERS']['OPENGROUPWARE'])){ +// print_red(_("Missing database configuration for opengroupware. Can't get or set any informations.")); + }else{ + $this->serverCon = $this->config->data['SERVERS']['OPENGROUPWARE']; + $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']); - /* telephone number */ - $info['number'] = $this->attrs['telephoneNumber']; + if(!$this->handle->connected){ +// print_red(_("Can't connect to specified database. Please check given configuration twice.")); + }else{ + $this->handle->info['login'] = $this->attrs['uid'][0]; + if($this->handle->CheckExistence()){ + $this->info = $this->handle->GetInfos($this->attrs['uid'][0]); + $this->initialy_was_account = true; + $this->is_account= true; + }else{ + $this->initialy_was_account = false; + $this->is_account= false; + + foreach($this->attrsToUse as $name=>$attr){ + if(isset($this->attrs[$attr][0])){ + $this->info[$name] = $this->attrs[$attr][0]; + }else{ + $this->info[$name] = false; + } + } + $this->info['description'] = $this->info['firstname']." ".$this->info['name']; + if($this->info['sex'] == "F"){ + $this->info['sex'] = "female"; + }else{ + $this->info['sex'] = "male"; + } + + /* Selectable in GOsa */ + $this->info['template_user_id'] = 0; + $this->info['is_locked'] = 0; + $this->info['LocationTeamID'] = 0; + $this->info['TeamIDis'] = array(); + } - /* Selectable in GOsa */ - $info['template_user_id'] = 10130; - $info['is_locked'] = 0; - $info['LocationTeamID'] = ""; - $info['TeamIDis'] = array(); + if(!is_array($this->info['TeamIDis'])){ + $this->info['TeamIDis'] = array(); + } + $this->handle->SetInfos($this->info); + } } - $this->info = $info; - $this->handle->SetInfos($info); } function execute() { /* Show tab dialog headers */ $display= ""; + $smarty= get_smarty(); + foreach(array("validLocationTeam","validTemplateUser","validLocationTeams","validTemplateUsers") as $ar){ + $smarty->assign($ar,array()); + } - print_a($this->info); + $smarty->assign("OGWstate"," disabled "); + foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount") as $ar){ + $smarty->assign($ar,""); + $smarty->assign($ar."CHK",""); + $smarty->assign($ar."ACL"," disabled "); + } - /* Show main page */ - $smarty= get_smarty(); + + if(!is_callable("pg_connect")){ + print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries.")); + }elseif(!isset($this->config->data['SERVERS']['OPENGROUPWARE'])){ + print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations.")); + }else{ + $this->serverCon = $this->config->data['SERVERS']['OPENGROUPWARE']; + $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']); + if(!$this->handle->connected){ + print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice.")); + }else{ + $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']); + /* Show main page */ + + $smarty->assign("OGWstate"," disabled "); + foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount") as $ar){ + $smarty->assign($ar."ACL",chkacl($this->acl,$ar)); + } - if ($this->is_account){ - $smarty->assign("is_account", "true"); - } else { - $smarty->assign("is_account", "false"); + $tmp = array(""=>"none"); + foreach($this->handle->validLocationTeam as $id){ + $tmp[$id['company_id']] = $id['description']; + } + $smarty->assign("validLocationTeam",$tmp); + $smarty->assign("validLocationTeams",array_flip($tmp)); + $smarty->assign("LocationTeam",$this->info['LocationTeamID']); + + $tmp = array(); + foreach($this->handle->validTemplateUser as $id){ + $tmp[$id['company_id']] = $id['name']; + } + $smarty->assign("validTemplateUser",$tmp); + $smarty->assign("validTemplateUsers",array_flip($tmp)); + $smarty->assign("TemplateUser",$this->info['template_user_id']); + + + $this->handle->CheckExistence(); + $str = ""; + if($this->is_account){ + $dis = ""; + }else{ + $dis = " disabled "; + } + + foreach($this->handle->validTeams as $id){ + if(in_array($id['company_id'],$this->info['TeamIDis'])){ + $str .= "".$id['description']."
"; + }else{ + $str .= "".$id['description']."
"; + } + } + $smarty->assign("validTeams",$str); + + if($this->is_account){ + $smarty->assign("OGWstate",""); + $smarty->assign("is_account", " checked "); + }else{ + $smarty->assign("is_account", " "); + $smarty->assign("OGWstate"," disabled "); + } + + foreach(array("LocationTeam","TemplateUser","Teams","is_locked") as $atr){ + $smarty->assign($atr."ACL",chkacl($this->acl,$atr)); + } + + if($this->info['is_locked']){ + $smarty->assign("is_lockedCHK", " checked "); + }else{ + $smarty->assign("is_lockedCHK", " "); + } + + $smarty->assign("is_locked", $this->info['is_locked']); + } } $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__))); return ($display); @@ -84,23 +185,10 @@ class opengwAccount extends plugin function remove_from_parent() { - if(chkacl($this->acl,"webdavAccount")==""){ - /* Cancel if there's nothing to do here */ - if (!$this->initially_was_account){ - return; - } - - plugin::remove_from_parent(); - $ldap= $this->config->get_ldap_link(); - - $ldap->cd($this->dn); - @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, - $this->attributes, "Save"); - $ldap->modify($this->attrs); - show_ldap_error($ldap->get_error()); - - /* Optionally execute a command after we're done */ - $this->handle_post_events('remove'); + if($this->initialy_was_account){ + $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']); + $this->handle->SetInfos($this->info); + $this->handle->Perform("REMOVE"); } } @@ -108,46 +196,49 @@ class opengwAccount extends plugin /* Save data to object */ function save_object() { - /* Do we need to flip is_account state? */ - if (isset($_POST['connectivityTab'])){ - if (isset($_POST['webdav'])){ - if (!$this->is_account && $_POST['webdav'] == "B"){ - $this->is_account= TRUE; + if($this->is_account){ + $this->info['TeamIDis'] = array(); + foreach($_POST as $name => $value ){ + if(preg_match("/team_/i",$name)){ + if(!in_array($value,$this->info['TeamIDis'])){ + $this->info['TeamIDis'][]=$value; + } } - } else { - $this->is_account= FALSE; + } + if(isset($_POST['LocationTeam'])){ + $this->info['LocationTeamID'] = $_POST['LocationTeam']; + } + + if(isset($_POST['TemplateUser'])){ + $this->info['template_user_id'] = $_POST['TemplateUser']; + } + + if(isset($_POST['is_locked'])){ + $this->info['is_locked'] = $_POST['is_locked']; + }else{ + $this->info['is_locked'] = 0; } } - - plugin::save_object(); - if (isset($_POST["WEBDAVStatus"])){ - $this->WEBDAVStatus = "disabled"; - } else { - $this->WEBDAVStatus = "enabled"; + + if(isset($_POST['is_account'])){ + $this->is_account = $_POST['is_account']; + }else{ + $this->is_account = false;//$_POST['is_account']; } + } /* Save to LDAP */ function save() - { - if(chkacl($this->acl,"webdavAccount")==""){ - plugin::save(); - - /* Write back to ldap */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->dn); - $ldap->modify($this->attrs); - show_ldap_error($ldap->get_error()); - - /* Optionally execute a command after we're done */ - if ($this->initially_was_account == $this->is_account){ - if ($this->is_modified){ - $this->handle_post_events("mofify"); - } - } else { - $this->handle_post_events("add"); - } + { + $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']); + $this->handle->SetInfos($this->info); + $this->handle->checkInfos(); + if($this->initialy_was_account){ + $this->handle->Perform("EDIT"); + }else{ + $this->handle->Perform("ADD"); } } diff --git a/plugins/personal/connectivity/opengw.tpl b/plugins/personal/connectivity/opengw.tpl index f13588b91..ff94ad601 100644 --- a/plugins/personal/connectivity/opengw.tpl +++ b/plugins/personal/connectivity/opengw.tpl @@ -1 +1,49 @@ -asdfasdf +

 {t}Opengroupware{/t}

+ + + + + +
+ + + + + + + + + + + + + +
+ {t}Location team{/t} :  + + +
+ {t}Template user{/t} :  + + +
+ {t}Locked{/t} :  + + +
+
+ + + + + +
+ {t}Teams{/t} :  + + {$validTeams} +
+