X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=include%2Fclass_opengw.inc;h=de50ef93690e6d277524bdc528515372df4d8132;hb=ac39e67e18bc613177d6f5a7229929f7e930a22a;hp=159ddf28b82926ad6b655d70709f6888fad9faa9;hpb=109185cb5f552e468119d99238d16aee58f96157;p=gosa.git diff --git a/include/class_opengw.inc b/include/class_opengw.inc index 159ddf28b..de50ef936 100755 --- a/include/class_opengw.inc +++ b/include/class_opengw.inc @@ -18,29 +18,77 @@ class ogw{ var $MAY = array( "salutation","firstname","description","degree", "birthday","sex","street","zip","country","zipcity", "state","name1","value_string","number","db_status", - "object_version","is_locked","LocationTeamID","TeamIDis"); + "object_version","is_locked","LocationTeamID","TeamIDis","password"); 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) - { + { + if(isset($infos['name'])) { + $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) @@ -53,12 +101,29 @@ class ogw{ if(($this->option == "EDIT")||($this->option=="ADD")){ /* Static variables */ - $this->info['is_person'] = 1; - $this->info['is_account'] = 1; - $this->info['is_intra_account'] = 1; - $this->info['is_extra_account'] = 0; - $this->info['owner_id'] = 10000; - $this->info['is_team'] = 0; + if(!isset($this->info['is_person'])){ + $this->info['is_person'] = 1; + } + + if(!isset($this->is_account)){ + $this->info['is_account'] = 1; + } + + if(!isset($this->info['is_intra_account'])){ + $this->info['is_intra_account'] = 1; + } + + if(!isset($this->info['is_extra_account'])){ + $this->info['is_extra_account'] = 0; + } + + if(!isset($this->info['owner_id'])){ + $this->info['owner_id'] = 10000; + } + + if(!isset($this->info['is_team'])){ + $this->info['is_team'] = 0; + } $this->InfoOK = $this->checkInfos(); @@ -80,7 +145,7 @@ class ogw{ $this->LastError="Can't edit entry, entry doesn't exists."; return(false); }else{ - $this->info['db_status'] = "edited"; + $this->info['db_status'] = "updated"; $this->info['object_version'] = $ist[0]['object_version']++; return($this->EDIT()); } @@ -110,7 +175,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 +195,7 @@ class ogw{ foreach($this->MAY as $name){ if((!isset($this->info[$name]))||(empty($this->info[$name]))){ - $info[$name] = false; + $this->info[$name] = false; } } @@ -157,10 +222,12 @@ class ogw{ foreach($this->validTeams as $id){ $tmp[]= $id['company_id']; } - foreach($this->info['TeamIDis'] as $id){ - if(!in_array($id,$tmp)){ - $this->LastError = sprintf("Given 'Team ID':%s is invalid.",$id); - return(false); + if(is_array($this->info['TeamIDis'])){ + foreach($this->info['TeamIDis'] as $id){ + if(!in_array($id,$tmp)){ + $this->LastError = sprintf("Given 'Team ID':%s is invalid.",$id); + return(false); + } } } return(true); @@ -174,7 +241,12 @@ class ogw{ $this->LastError(sprintf("Can't get company id for login %s",$this->info['login'])); return(false); }else{ + $company_id = $ist[0]['company_id']; + + $qry = "UPDATE person SET login='SKY".$company_id.$this->info['login']."', is_account=0, is_intra_account=0 WHERE company_id=".$company_id.";"; + $this->ogo->Query($qry); + /* $this->ogo->Query("DELETE FROM telephone WHERE company_id=".$company_id.";"); $this->ogo->Query("DELETE FROM address WHERE company_id=".$company_id.";"); $this->ogo->Query("DELETE FROM company_info WHERE company_id=".$company_id.";"); @@ -182,6 +254,7 @@ class ogw{ $this->ogo->Query("DELETE FROM company_assignment WHERE sub_company_id=".$company_id.";"); $this->ogo->Query("DELETE FROM person WHERE company_id=".$company_id.";"); $this->ogo->Query("DELETE FROM staff WHERE company_id=".$company_id.";"); + */ return(true); } } @@ -194,9 +267,9 @@ class ogw{ $arr = array( "company_id","object_version","owner_id","template_user_id", "is_person","is_account","is_intra_account","is_extra_account", "number","description","is_locked","login","name","name","firstname", - "salutation","degree","birthday","sex","db_status"); + "salutation","degree","birthday","sex","db_status","password"); $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']; @@ -332,7 +405,7 @@ class ogw{ $arr = array( "company_id","object_version","owner_id", "template_user_id","is_person","is_account","is_intra_account", "is_extra_account","number","description","is_locked","login","name", - "firstname","salutation","degree","birthday","sex","db_status"); + "firstname","salutation","degree","birthday","sex","db_status","password"); $this->info['company_id'] = $ist[0]['company_id']; $this->info['userID'] = "OGo".$this->info['company_id']; foreach($arr as $attr){ @@ -370,13 +443,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); /* @@ -444,16 +518,19 @@ class ogw{ (SELECT company_id FROM team WHERE is_location_team=1));"; $arr = array("company_assignment_id","company_id","sub_company_id","db_status"); - foreach($this->info['TeamIDis'] as $TeamID){ - $this->info['company_id'] = $TeamID; - $this->info['sub_company_id'] = $ist[0]['company_id']; - $this->info['company_assignment_id']= $this->ogo->gen_id(); - foreach($arr as $attr){ - $add_company_assignment[$attr] = $this->info[$attr]; - } - $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false); - } + if(is_array($this->info['TeamIDis'])){ + foreach($this->info['TeamIDis'] as $TeamID){ + $this->info['company_id'] = $TeamID; + $this->info['sub_company_id'] = $ist[0]['company_id']; + $this->info['company_assignment_id']= $this->ogo->gen_id(); + $add_company_assignment = array(); + foreach($arr as $attr){ + $add_company_assignment[$attr] = $this->info[$attr]; + } + $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false); + } + } $remove_all = false; foreach($QUERY as $q ){