Code

Moved opengroupware
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 17 Jan 2008 14:04:51 +0000 (14:04 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 17 Jan 2008 14:04:51 +0000 (14:04 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8461 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/personal/connectivity/opengroupware/class_opengw.inc [deleted file]
gosa-core/plugins/personal/connectivity/opengroupware/class_opengwAccount.inc [deleted file]
gosa-core/plugins/personal/connectivity/opengroupware/opengw.tpl [deleted file]
gosa-plugins/opengroupware/personal/connectivity/opengroupware/class_opengw.inc [new file with mode: 0644]
gosa-plugins/opengroupware/personal/connectivity/opengroupware/class_opengwAccount.inc [new file with mode: 0644]
gosa-plugins/opengroupware/personal/connectivity/opengroupware/opengw.tpl [new file with mode: 0644]

diff --git a/gosa-core/plugins/personal/connectivity/opengroupware/class_opengw.inc b/gosa-core/plugins/personal/connectivity/opengroupware/class_opengw.inc
deleted file mode 100644 (file)
index de50ef9..0000000
+++ /dev/null
@@ -1,547 +0,0 @@
-<?php
-
-require_once("class_pgsql_opengw.inc");
-
-class ogw{
-  var $info;
-  var $ogo;
-  
-  var $validLocationTeam;
-  var $validTemplateUser;
-  var $validTeams;
-
-
-  var $InfoOK = false;
-
-  var $MUST = array("name","login","template_user_id");
-  
-  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","password");
-
-  var $LastError  = "";
-  var $option     = "";
-  var $connected = false;
-
-  function ogw($username,$password,$host,$db)
-  {
-    $this->ogo  = new pgre_sql($username,$password,$host,$db);
-
-    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;
-  }
-
-  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)
-  {
-    if(!in_array($option,array("ADD","EDIT","REMOVE"))){
-      $this->LastError = sprintf("Option '%s' is not allowed, possible options are 'ADD' 'EDIT' 'REMOVE'.",$option);
-      return(false);
-    }else{
-      $this->option = $option;
-      if(($this->option == "EDIT")||($this->option=="ADD")){
-
-        /* Static variables */
-        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();
-
-        if($this->InfoOK){
-          $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';";
-          $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
-
-          if($this->option == "ADD"){
-            if($this->CheckExistence()){
-              $this->LastError="Can't add entry already exists.";
-              return(false);
-            }else{
-              $this->info['db_status']          = "inserted";
-              $this->info['object_version']     = 1;
-              return($this->ADD());
-            }
-          }else{
-            if(!$this->CheckExistence()){
-              $this->LastError="Can't edit entry, entry doesn't exists.";
-              return(false);
-            }else{
-              $this->info['db_status']          = "updated";
-              $this->info['object_version']     = $ist[0]['object_version']++;
-              return($this->EDIT());
-            }
-          }
-        }else{
-          return($this->InfoOK);
-        }
-      }
-      if($this->option == "REMOVE"){
-    
-        if((!isset($this->info['login']))||(empty($this->info['login']))){
-          $this->LastError = "Require login to detect existence";
-          return(false);
-        }else{
-    
-          if($this->CheckExistence()){
-            return($this->REMOVE());
-          }else{
-            $this->LastError="Can't remove non existing entry";
-            return(false);
-          }
-        }
-      }
-    }
-  }
-
-  function CheckExistence()
-  {
-    /* Check if thios entry already exists */
-    $qry = "SELECT login,name FROM person WHERE login='".$this->info['login']."';";
-    $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
-    if($ist){
-      return(true);
-    }else{
-      return(false);
-    }
-  }
-
-  function checkInfos()
-  {
-    foreach($this->MUST as $name){
-      if((!isset($this->info[$name]))||(empty($this->info[$name]))){
-        $this->LastError = sprintf("Must attribute '%s' wasn't set.",$name);
-        return(false);
-      }
-    }
-
-    foreach($this->MAY as $name){
-      if((!isset($this->info[$name]))||(empty($this->info[$name]))){
-        $this->info[$name] = false;
-      }
-    }
-
-    $tmp = array(false,"",0);
-    foreach($this->validLocationTeam as $id){
-      $tmp[]= $id['company_id'];
-    }
-    if(!in_array($this->info['LocationTeamID'],$tmp)){
-      $this->LastError = "Given 'Location Team' is invalid.";
-      return(false);
-    }
-
-    $tmp = array();
-    foreach($this->validTemplateUser as $id){
-      $tmp[]= $id['company_id'];
-    }
-    if(!in_array($this->info['template_user_id'],$tmp)){
-      $this->LastError = "Given 'Template User ID' is invalid.";
-      return(false);
-    }
-
-    
-    $tmp = array();
-    foreach($this->validTeams as $id){
-      $tmp[]= $id['company_id'];
-    }
-    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);
-  }
-
-  function REMOVE()
-  {
-    $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';";
-    $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
-    if((!$ist)||(!isset($ist[0]['company_id']))||($ist[0]['company_id']<=0)){
-      $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.";");
-      $this->ogo->Query("DELETE FROM company_value WHERE company_id=".$company_id.";");
-      $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);
-    }
-  }
-
-  function ADD()
-  {
-    /* 
-       Entry settings for personm table 
-     */
-    $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","password");
-    $this->info['company_id']  = $this->ogo->gen_id();
-    $this->info['userID']             = "OGo".$this->info['company_id'];
-    foreach($arr as $attr){
-      if($attr == "number"){
-        $add_user[$attr]  = $this->info['userID'];
-      }else{
-        $add_user[$attr]  = $this->info[$attr];
-      }
-    }
-    $QUERY[] = gen_syntax($add_user,"person","ADD",false);
-
-
-    /*
-       Entry for staff table
-     */
-    $arr = array("staff_id","company_id","description","login","is_team","is_account","db_status");
-    $this->info['staff_id'] = $this->ogo->gen_id();
-    foreach($arr as $attr){
-      $add_staff[$attr] = $this->info[$attr];
-    }
-    $QUERY[] = gen_syntax($add_staff,"staff","ADD",false);
-
-
-    /* 
-       Create entries for company nfo 
-     */
-    $arr = array("company_info_id","company_id","db_status");
-    $this->info['company_info_id']  = $this->ogo->gen_id();
-    foreach($arr as $attr){
-      $add_company_info[$attr]  = $this->info[$attr];
-    }
-    $QUERY[] = gen_syntax($add_company_info,"company_info","ADD",false);
-
-
-    /* 
-       Create entries for company value 
-     */
-    $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","ADD",false);
-
-
-    /* 
-       address entries 
-     */
-    $arr = array("company_id","address_id","street","zip","country","zipcity","state","db_status","name1","type");
-    foreach(array("private","mailing","location") as  $type){
-      
-      $this->info['address_id'] = $this->ogo->gen_id();
-      $this->info['type']       = $type;
-      foreach($arr as $attr){
-        $add_address[$attr]  = $this->info[$attr];
-      }
-      $QUERY[] = gen_syntax($add_address,"address","ADD",false);
-    }
-
-
-    /*
-       telephone entries 
-     */
-    $arr = array("telephone_id","object_version","company_id","number","type","db_status");
-    foreach(array("01_tel","02_tel","03_tel_funk","05_tel_private","10_fax","fax_private") as $type){
-      $this->info['type']       = $type;
-      $this->info['telephone_id']     = $this->ogo->gen_id();
-      foreach($arr as $attr){
-        $add_telephone[$attr]  = $this->info[$attr];
-      }
-      $QUERY[] = gen_syntax($add_telephone,"telephone","ADD",false);
-    }
-
-    /*
-       company_assignment entries (Location Team) 
-     */
-    $this->info['old_company_id']       = $this->info['company_id'];
-    $this->info['sub_company_id']       = $this->info['old_company_id'];
-
-    $this->info['company_assignment_id']= $this->ogo->gen_id();
-    $this->info['company_id']           = $this->info['LocationTeamID'];
-    $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
-    foreach($arr as $attr){
-      $add_company_assignment[$attr]  = $this->info[$attr];
-    }
-    $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false);
-
-
-    /*
-       company_assignment entries (Teams) 
-     */
-    $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']       = $this->info['old_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);
-    }
-
-    $remove_all = false;
-    foreach($QUERY as $q ){
-      if(!$this->ogo->Query($q)){
-        $remove_all = true;
-        break;
-      }
-    }
-    
-    if($remove_all== true){
-      $this->ogo->Query("DELETE FROM telephone WHERE company_id=".$this->info['company_id'].";");
-      $this->ogo->Query("DELETE FROM address WHERE company_id=".$this->info['company_id'].";");
-      $this->ogo->Query("DELETE FROM company_assignment WHERE company_id=".$this->info['company_id'].";");
-      $this->ogo->Query("DELETE FROM company_info WHERE company_id=".$this->info['company_id'].";");
-      $this->ogo->Query("DELETE FROM company_value WHERE company_id=".$this->info['company_id'].";");
-      $this->ogo->Query("DELETE FROM staff WHERE company_id=".$this->info['company_id'].";");
-      $this->ogo->Query("DELETE FROM person WHERE company_id=".$this->info['company_id'].";");
-      $this->LastError="Query failed, removed all added entries";
-      return(false);
-    }
-    return(true);
-  }
-
-
-  function EDIT()
-  {
-    $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';";
-    $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
-    /* 
-       Entry settings for personm table 
-     */
-    $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","password");
-    $this->info['company_id'] = $ist[0]['company_id'];
-    $this->info['userID']     = "OGo".$this->info['company_id'];
-    foreach($arr as $attr){
-      if($attr == "number"){
-        $add_user[$attr]  = $this->info['userID'];
-      }else{
-        $add_user[$attr]  = $this->info[$attr];
-      }
-    }
-    $QUERY[] = gen_syntax($add_user,"person","EDIT",$ist);
-
-
-    /*
-       Entry for staff table
-     */
-    $arr = array("staff_id","company_id","description","login","is_team","is_account","db_status");
-    $this->info['staff_id'] = $this->ogo->gen_id();
-    foreach($arr as $attr){
-      $add_staff[$attr] = $this->info[$attr];
-    }
-    $QUERY[] = gen_syntax($add_staff,"staff","EDIT",$ist);
-
-
-    /* 
-       Create entries for company nfo 
-     */
-    $arr = array("company_info_id","company_id","db_status");
-    $this->info['company_info_id']    = $this->ogo->gen_id();
-    foreach($arr as $attr){
-      $add_company_info[$attr]  = $this->info[$attr];
-    }
-    $QUERY[] = gen_syntax($add_company_info,"company_info","EDIT",$ist);
-
-
-    /* 
-       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","ADD",false);
-
-
-    /* 
-       address entries 
-     */
-    $QUERY[] = "DELETE FROM address WHERE company_id=".$ist[0]['company_id'].";";
-    $this->info['company_id'] = $ist[0]['company_id'];
-    $arr = array("company_id","address_id","street","zip","country","zipcity","state","db_status","name1","type");
-    foreach(array("private","mailing","location") as  $type){
-      $this->info['type']       = $type;
-      $this->info['address_id'] = $this->ogo->gen_id();
-      foreach($arr as $attr){
-        $add_address[$attr]  = $this->info[$attr];
-      } 
-      $QUERY[] = gen_syntax($add_address,"address","ADD",false);
-    }
-
-
-    /*
-       telephone entries 
-     */
-    $QUERY[] = "DELETE FROM telephone WHERE company_id=".$ist[0]['company_id'].";";
-    $this->info['company_id'] = $ist[0]['company_id'];
-    $arr = array("telephone_id","object_version","company_id","number","type","db_status");
-    foreach(array("01_tel","02_tel","03_tel_funk","05_tel_private","10_fax","fax_private") as $type){
-      $this->info['type']           = $type;
-      $this->info['telephone_id']   = $this->ogo->gen_id();
-      foreach($arr as $attr){
-        $add_telephone[$attr]  = $this->info[$attr];
-      }
-
-      $QUERY[] = gen_syntax($add_telephone,"telephone","ADD",false);
-    }
-
-
-    /*
-       company_assignment entries (Location Team) 
-     */
-    $this->info['old_company_id'] = $this->info['company_id'];
-    
-    /* First remove location team */
-    $QUERY[] = "DELETE FROM company_assignment WHERE (sub_company_id=".$ist[0]['company_id'].") AND
-      company_id in (SELECT company_id FROM team WHERE is_location_team=1);";
-
-    $this->info['sub_company_id']       = $ist[0]['company_id'];
-    $this->info['company_assignment_id']= $this->ogo->gen_id();
-    $this->info['company_id']           = $this->info['LocationTeamID'];
-    $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
-    foreach($arr as $attr){
-      $add_company_assignment[$attr]  = $this->info[$attr];
-    }
-    $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false);
-
-
-    /*
-       company_assignment entries (Teams) 
-     */
-    /* First remove location team */
-    $QUERY[] = "DELETE FROM company_assignment 
-                WHERE 
-                    (sub_company_id=".$ist[0]['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));";
-
-    $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
-
-    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 ){
-      if(!$this->ogo-> Query($q)){
-        print $q;
-        $remove_all = true;
-        break;
-      }
-    }
-  }
-}
-
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-?>
diff --git a/gosa-core/plugins/personal/connectivity/opengroupware/class_opengwAccount.inc b/gosa-core/plugins/personal/connectivity/opengroupware/class_opengwAccount.inc
deleted file mode 100644 (file)
index e2b4f5e..0000000
+++ /dev/null
@@ -1,356 +0,0 @@
-<?php
-
-class opengwAccount extends plugin
-{
-       /* Definitions */
-       var $plHeadline       = "Opengroupware account";
-       var $plDescription    = "This does something";
-
-       /* attribute list for save action */
-       var $attributes       = array();
-       var $objectclasses    = array();
-
-  var $SetPassword   = false;
-
-       /* Attribute mapping opengroupware->ldap  */
-       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;
-       var $initialy_was_account = false;
-  var $OGWPassword          = "";
-  var $ReadOnly = false;
-  var $view_logged = FALSE;  
-  var $uid = "";
-
-       function opengwAccount (&$config, $dn= NULL)
-       {
-               plugin::plugin ($config, $dn);
-
-    /* Setting uid to default */
-    if(isset($this->attrs['uid'][0])){
-      $this->uid = $this->attrs['uid'][0];
-    }
-
-               $this->info=array();
-
-               /* is no account and was no account */
-               $this->initialy_was_account = false;
-               $this->is_account           = false;
-
-               /* Get configurations */
-    if($this->config->search("opengwAccount", 'USERNAME',array('tabs'))){
-      $atr = array();
-      $atr['LOGIN']    =         $this->config->search("opengwAccount", 'USERNAME',array('tabs'));
-      $atr['PASSWORD']=        $this->config->search("opengwAccount", 'PASSWORD',array('tabs'));
-      $atr['SERVER']   =       $this->config->search("opengwAccount", 'DATAHOST',array('tabs'));
-      $atr['DB']               =         $this->config->search("opengwAccount", 'DATABASE',array('tabs'));
-      $this->serverCon = $atr;
-    }elseif(isset($this->config->data['SERVERS']['OPENGROUPWARE'])){
-      $this->serverCon  = $this->config->data['SERVERS']['OPENGROUPWARE'];
-    }else{
-      $this->serverCon = array();
-    }
-
-    /* check if datebase funktions are available, and if database configurations are available */ 
-               if(is_callable("pg_connect") && count($this->serverCon)){
-
-                       $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
-
-                       /* Check if current configuration allows database connection */
-                       if($this->handle->connected){
-
-                               /* Set login name, to check if this is_account */
-                               if(isset($this->attrs['uid'][0])){
-                                       $this->handle->info['login'] = $this->attrs['uid'][0];
-                               }else{
-                                       $this->handle->info['login'] = ""; 
-                               }
-
-                               /* If this is account get data from database first */
-                               if($this->handle->CheckExistence()){
-                                       $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
-
-                                       /* This is an account */
-                                       $this->initialy_was_account = true;
-                                       $this->is_account= true;
-                               }else{
-                                       /* this is no account */ 
-                                       $this->initialy_was_account = false;
-                                       $this->is_account= false;
-
-                                       /* Selectable in GOsa */
-                                       $this->info['template_user_id']   = 0;
-                                       $this->info['is_locked']          = 0;
-                                       $this->info['LocationTeamID']     = 0;
-                                       $this->info['TeamIDis']           = array();
-                               }
-
-                               /* Set settings from ldap */
-                               foreach($this->attrsToUse as $name=>$attr){
-                                       if(isset($this->attrs[$attr][0])){
-                                               $this->info[$name] = $this->attrs[$attr][0];
-                                       }else{
-                                               $this->info[$name] = false;
-                                       }
-                               } 
-
-                               /* Description is displayed as 'Nickname' */
-                               $this->info['description']          = $this->info['login'];
-
-                               if($this->info['sex'] == "F"){
-                                       $this->info['sex']                = "female";
-                               }else{
-                                       $this->info['sex']                = "male";
-                               }
-
-                       }
-
-                       /* Transmit data back to ogw handle */
-                       $this->handle->SetInfos($this->info);
-               }
-       }
-
-       function execute()
-       {
-    /* Log view */
-    if($this->is_account && !$this->view_logged){
-      $this->view_logged = TRUE;
-      new log("view","users/".get_class($this),$this->dn);
-    }
-
-               /* Show tab dialog headers */
-               $display= "";
-               $smarty= get_smarty();
-
-    $smarty->assign("serverCon",count($this->serverCon));
-    $smarty->assign("validTeams","");
-    $smarty->assign("is_account", " ");
-    $smarty->assign("OGWstate"," disabled ");
-    $smarty->assign("validLocationTeam",array("&nbsp;"));
-    $smarty->assign("validLocationTeams",array("&nbsp;"));
-    $smarty->assign("LocationTeam",0);
-    $smarty->assign("validTemplateUser",array("&nbsp;"));
-    $smarty->assign("validTemplateUsers",array("&nbsp;"));
-    $smarty->assign("TemplateUser",0);
-    $smarty->assign("is_lockedCHK", "  ");
-    $smarty->assign("is_locked", "  ");
-               /* set default values */
-    $tmp = $this->plInfo();
-    foreach($tmp['plProvidedAcls'] as $acl => $desc){
-      $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
-    } 
-
-    if((!$this->ReadOnly)&&(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))) {
-      $smarty->assign('opengwAccountACL', "");
-    }else{
-      $smarty->assign('opengwAccountACL', " disabled ");
-    }
-
-    if(count($this->serverCon))
-
-               /* Check database extension */    
-               if(!is_callable("pg_connect") && count($this->serverCon)){
-      msg_dialog::display(_("Configuration error"), sprintf(_("Missing %s PHP extension!"), "postgresql"), ERROR_DIALOG);
-               }elseif(count($this->serverCon)){
-
-                       /* Check if config exists */
-                       if($this->config->search("opengwAccount", 'DATABASE',array('tabs'))){
-        msg_dialog::display(_("Configuration error"), sprintf(_("%s database configuration is missing!"), "Open Groupware"), ERROR_DIALOG);
-                       }else{
-
-                               /* Create handle */
-                               $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
-
-                               /* Check if we are successfully connected to db */
-                               if(!$this->handle->connected){
-          msg_dialog::display(_("Configuration error"), sprintf( _("Cannot connect to %s database!"), "Open Groupware"), ERROR_DIALOG);
-                               }else{
-
-                                       /* Assign LocationTeams */
-                                       $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']);
-
-                                       /* Assign TemplateUsers*/
-                                       $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']);
-
-                                       /* Create Team membership */ 
-                                       $str = "";
-                                       if(($this->is_account)==""){
-                                               $dis = "";
-                                       }else{
-                                               $dis = " disabled ";
-                                       }
-
-          if($this->acl_is_readable("Teams")){
-            foreach($this->handle->validTeams as $id){
-              if(in_array($id['company_id'],$this->info['TeamIDis'])){
-                $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
-                  checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
-              }else{
-                $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
-                  name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
-              }
-            }
-          }
-                                       $smarty->assign("validTeams",$str);
-
-                                       /* Assign ogw checkbox */
-                                       if($this->is_account){
-                                               $smarty->assign("OGWstate","");
-                                               $smarty->assign("is_account", " checked ");
-                                       }else{
-                                               $smarty->assign("is_account", " ");
-                                               $smarty->assign("OGWstate"," disabled ");
-                                       }
-
-                                       /* Assign lock status */
-                                       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);
-       }
-
-       function remove_from_parent()
-       {
-               /* remove database entries */
-               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");
-
-      new log("remove","users/".get_class($this),$this->dn);
-               }
-       }
-
-
-       /* Save data to object */
-       function save_object()
-       {
-               /* get post data */
-               if($this->is_account){
-
-      /* Get selected team chkboxes */
-      $this->info['TeamIDis'] = array();
-      if($this->acl_is_writeable("Teams")) {
-        foreach($_POST as $name => $value ){
-          if(preg_match("/team_/i",$name)){
-            if(!in_array($value,$this->info['TeamIDis'])){
-              $this->info['TeamIDis'][]=$value;
-            }
-          }
-        }
-      }
-
-
-                       /* Get location Team*/
-                       if(isset($_POST['LocationTeam']) && $this->acl_is_writeable("LocationTeam")){
-                               $this->info['LocationTeamID'] = $_POST['LocationTeam'];
-                       }
-
-                       /* Get template user */
-                       if(isset($_POST['TemplateUser']) && $this->acl_is_writeable("TemplateUser") ){
-                               $this->info['template_user_id'] = $_POST['TemplateUser'];
-                       }
-
-      /* get lock status */
-      if($this->acl_is_writeable("Locked")){
-        if(isset($_POST['is_locked'])){
-          $this->info['is_locked'] = $_POST['is_locked'];
-        }else{
-          $this->info['is_locked'] = 0;
-        }
-      }
-               }
-
-               /* change account status */
-               if(isset($_POST['is_account'])){
-      if($this->acl_is_createable()){
-        $this->is_account = $_POST['is_account'];
-      }
-    }else{
-      if($this->acl_is_removeable()){
-        $this->is_account = false;//$_POST['is_account'];
-      }
-               }
-       }
-
-
-       /* Save to LDAP */
-       function save()
-       {
-               /* Save data */ 
-               $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");
-      new log("modify","users/".get_class($this),$this->dn);
-               }else{
-                       $this->handle->Perform("ADD");
-      new log("create","users/".get_class($this),$this->dn);
-               }
-       }
-
-  
-  function PrepareForCopyPaste($src){
-    // Nothing to do, because this object can't be copied ... yet
-  }
-
-
- /* Return plugin informations for acl handling 
-      #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */  
-  static function plInfo()
-  {
-    return (array(
-          "plShortName"     => _("Opengroupware"),
-          "plDescription"   => _("Open groupware account settings")."&nbsp;:&nbsp;<u>"._("Connectivity addon")."</u>",
-          "plSelfModify"    => TRUE,
-          "plDepends"       => array("user"),
-          "plPriority"      => 26,                                 // Position in tabs
-          "plSection"     => array("personal" => _("My account")),
-          "plCategory"    => array("users"),
-          "plOptions"       => array(),
-
-          "plProvidedAcls"  => array(
-            "LocationTeam"  => _("Location team"),
-            "TemplateUser"  => _("Template user"),
-            "Locked"        => _("Locked"),
-            "Teams"         => _("Teams"))
-          ));
-  }
-}
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-?>
diff --git a/gosa-core/plugins/personal/connectivity/opengroupware/opengw.tpl b/gosa-core/plugins/personal/connectivity/opengroupware/opengw.tpl
deleted file mode 100644 (file)
index 5687417..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-<h2><input type="checkbox" value="1" name="is_account" {$is_account} {$opengwAccountACL} onClick="document.mainform.submit();">&nbsp;{t}Opengroupware{/t}</h2>
-<table width="100%" summary="">
-       <tr>
-               <td width="50%">
-                       <table summary="">
-                               <tr>
-                                       <td>
-                                               {t}Location team{/t} &nbsp;
-                                       </td>
-                                       <td>
-{render acl=$LocationTeamACL}
-                                               <select size="1" id="LocationTeam" name="LocationTeam"
-                                                       {if $OGWstate!=""} disabled {/if}>
-                                                       {html_options values=$validLocationTeams output=$validLocationTeam selected=$LocationTeam}
-                                               </select>
-{/render}
-                                       </td>
-                               </tr>
-                               <tr>
-                                       <td>
-                                               {t}Template user{/t} &nbsp;
-                                       </td>
-                                       <td>
-{render acl=$TemplateUserACL}
-                                               <select size="1" id="TemplateUser" name="TemplateUser" {if $OGWstate!=""} disabled {/if}>
-                                                       {html_options values=$validTemplateUsers output=$validTemplateUser selected=$TemplateUser}
-                                               </select>
-{/render}
-                                       </td>
-                               </tr>   
-                               <tr>
-                                       <td valign="top">
-                                               {t}Locked{/t} &nbsp; 
-                                       </td>
-                                       <td valign="top">
-{render acl=$LockedACL}
-                                               <input type="checkbox" value="1" name="is_locked" {$is_lockedCHK}  
-                                                  {if $OGWstate!=""} disabled {/if}>
-{/render}
-                                       </td>
-                               </tr>
-                       </table>
-               </td>
-               <td valign="top" style="border-left: 1px solid rgb(160, 160, 160);">
-                       <table summary="">
-                               <tr>
-                                       <td valign="top">
-                                               {t}Teams{/t} &nbsp; 
-                                       </td>
-                                       <td valign="top">
-{render acl=$TeamsACL}
-                                               {$validTeams}   
-{/render}
-                                       </td>
-                               </tr>
-                       </table>
-               </td>
-       </tr>
-</table>
diff --git a/gosa-plugins/opengroupware/personal/connectivity/opengroupware/class_opengw.inc b/gosa-plugins/opengroupware/personal/connectivity/opengroupware/class_opengw.inc
new file mode 100644 (file)
index 0000000..de50ef9
--- /dev/null
@@ -0,0 +1,547 @@
+<?php
+
+require_once("class_pgsql_opengw.inc");
+
+class ogw{
+  var $info;
+  var $ogo;
+  
+  var $validLocationTeam;
+  var $validTemplateUser;
+  var $validTeams;
+
+
+  var $InfoOK = false;
+
+  var $MUST = array("name","login","template_user_id");
+  
+  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","password");
+
+  var $LastError  = "";
+  var $option     = "";
+  var $connected = false;
+
+  function ogw($username,$password,$host,$db)
+  {
+    $this->ogo  = new pgre_sql($username,$password,$host,$db);
+
+    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;
+  }
+
+  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)
+  {
+    if(!in_array($option,array("ADD","EDIT","REMOVE"))){
+      $this->LastError = sprintf("Option '%s' is not allowed, possible options are 'ADD' 'EDIT' 'REMOVE'.",$option);
+      return(false);
+    }else{
+      $this->option = $option;
+      if(($this->option == "EDIT")||($this->option=="ADD")){
+
+        /* Static variables */
+        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();
+
+        if($this->InfoOK){
+          $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';";
+          $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+
+          if($this->option == "ADD"){
+            if($this->CheckExistence()){
+              $this->LastError="Can't add entry already exists.";
+              return(false);
+            }else{
+              $this->info['db_status']          = "inserted";
+              $this->info['object_version']     = 1;
+              return($this->ADD());
+            }
+          }else{
+            if(!$this->CheckExistence()){
+              $this->LastError="Can't edit entry, entry doesn't exists.";
+              return(false);
+            }else{
+              $this->info['db_status']          = "updated";
+              $this->info['object_version']     = $ist[0]['object_version']++;
+              return($this->EDIT());
+            }
+          }
+        }else{
+          return($this->InfoOK);
+        }
+      }
+      if($this->option == "REMOVE"){
+    
+        if((!isset($this->info['login']))||(empty($this->info['login']))){
+          $this->LastError = "Require login to detect existence";
+          return(false);
+        }else{
+    
+          if($this->CheckExistence()){
+            return($this->REMOVE());
+          }else{
+            $this->LastError="Can't remove non existing entry";
+            return(false);
+          }
+        }
+      }
+    }
+  }
+
+  function CheckExistence()
+  {
+    /* Check if thios entry already exists */
+    $qry = "SELECT login,name FROM person WHERE login='".$this->info['login']."';";
+    $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+    if($ist){
+      return(true);
+    }else{
+      return(false);
+    }
+  }
+
+  function checkInfos()
+  {
+    foreach($this->MUST as $name){
+      if((!isset($this->info[$name]))||(empty($this->info[$name]))){
+        $this->LastError = sprintf("Must attribute '%s' wasn't set.",$name);
+        return(false);
+      }
+    }
+
+    foreach($this->MAY as $name){
+      if((!isset($this->info[$name]))||(empty($this->info[$name]))){
+        $this->info[$name] = false;
+      }
+    }
+
+    $tmp = array(false,"",0);
+    foreach($this->validLocationTeam as $id){
+      $tmp[]= $id['company_id'];
+    }
+    if(!in_array($this->info['LocationTeamID'],$tmp)){
+      $this->LastError = "Given 'Location Team' is invalid.";
+      return(false);
+    }
+
+    $tmp = array();
+    foreach($this->validTemplateUser as $id){
+      $tmp[]= $id['company_id'];
+    }
+    if(!in_array($this->info['template_user_id'],$tmp)){
+      $this->LastError = "Given 'Template User ID' is invalid.";
+      return(false);
+    }
+
+    
+    $tmp = array();
+    foreach($this->validTeams as $id){
+      $tmp[]= $id['company_id'];
+    }
+    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);
+  }
+
+  function REMOVE()
+  {
+    $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';";
+    $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+    if((!$ist)||(!isset($ist[0]['company_id']))||($ist[0]['company_id']<=0)){
+      $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.";");
+      $this->ogo->Query("DELETE FROM company_value WHERE company_id=".$company_id.";");
+      $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);
+    }
+  }
+
+  function ADD()
+  {
+    /* 
+       Entry settings for personm table 
+     */
+    $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","password");
+    $this->info['company_id']  = $this->ogo->gen_id();
+    $this->info['userID']             = "OGo".$this->info['company_id'];
+    foreach($arr as $attr){
+      if($attr == "number"){
+        $add_user[$attr]  = $this->info['userID'];
+      }else{
+        $add_user[$attr]  = $this->info[$attr];
+      }
+    }
+    $QUERY[] = gen_syntax($add_user,"person","ADD",false);
+
+
+    /*
+       Entry for staff table
+     */
+    $arr = array("staff_id","company_id","description","login","is_team","is_account","db_status");
+    $this->info['staff_id'] = $this->ogo->gen_id();
+    foreach($arr as $attr){
+      $add_staff[$attr] = $this->info[$attr];
+    }
+    $QUERY[] = gen_syntax($add_staff,"staff","ADD",false);
+
+
+    /* 
+       Create entries for company nfo 
+     */
+    $arr = array("company_info_id","company_id","db_status");
+    $this->info['company_info_id']  = $this->ogo->gen_id();
+    foreach($arr as $attr){
+      $add_company_info[$attr]  = $this->info[$attr];
+    }
+    $QUERY[] = gen_syntax($add_company_info,"company_info","ADD",false);
+
+
+    /* 
+       Create entries for company value 
+     */
+    $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","ADD",false);
+
+
+    /* 
+       address entries 
+     */
+    $arr = array("company_id","address_id","street","zip","country","zipcity","state","db_status","name1","type");
+    foreach(array("private","mailing","location") as  $type){
+      
+      $this->info['address_id'] = $this->ogo->gen_id();
+      $this->info['type']       = $type;
+      foreach($arr as $attr){
+        $add_address[$attr]  = $this->info[$attr];
+      }
+      $QUERY[] = gen_syntax($add_address,"address","ADD",false);
+    }
+
+
+    /*
+       telephone entries 
+     */
+    $arr = array("telephone_id","object_version","company_id","number","type","db_status");
+    foreach(array("01_tel","02_tel","03_tel_funk","05_tel_private","10_fax","fax_private") as $type){
+      $this->info['type']       = $type;
+      $this->info['telephone_id']     = $this->ogo->gen_id();
+      foreach($arr as $attr){
+        $add_telephone[$attr]  = $this->info[$attr];
+      }
+      $QUERY[] = gen_syntax($add_telephone,"telephone","ADD",false);
+    }
+
+    /*
+       company_assignment entries (Location Team) 
+     */
+    $this->info['old_company_id']       = $this->info['company_id'];
+    $this->info['sub_company_id']       = $this->info['old_company_id'];
+
+    $this->info['company_assignment_id']= $this->ogo->gen_id();
+    $this->info['company_id']           = $this->info['LocationTeamID'];
+    $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
+    foreach($arr as $attr){
+      $add_company_assignment[$attr]  = $this->info[$attr];
+    }
+    $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false);
+
+
+    /*
+       company_assignment entries (Teams) 
+     */
+    $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']       = $this->info['old_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);
+    }
+
+    $remove_all = false;
+    foreach($QUERY as $q ){
+      if(!$this->ogo->Query($q)){
+        $remove_all = true;
+        break;
+      }
+    }
+    
+    if($remove_all== true){
+      $this->ogo->Query("DELETE FROM telephone WHERE company_id=".$this->info['company_id'].";");
+      $this->ogo->Query("DELETE FROM address WHERE company_id=".$this->info['company_id'].";");
+      $this->ogo->Query("DELETE FROM company_assignment WHERE company_id=".$this->info['company_id'].";");
+      $this->ogo->Query("DELETE FROM company_info WHERE company_id=".$this->info['company_id'].";");
+      $this->ogo->Query("DELETE FROM company_value WHERE company_id=".$this->info['company_id'].";");
+      $this->ogo->Query("DELETE FROM staff WHERE company_id=".$this->info['company_id'].";");
+      $this->ogo->Query("DELETE FROM person WHERE company_id=".$this->info['company_id'].";");
+      $this->LastError="Query failed, removed all added entries";
+      return(false);
+    }
+    return(true);
+  }
+
+
+  function EDIT()
+  {
+    $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';";
+    $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+    /* 
+       Entry settings for personm table 
+     */
+    $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","password");
+    $this->info['company_id'] = $ist[0]['company_id'];
+    $this->info['userID']     = "OGo".$this->info['company_id'];
+    foreach($arr as $attr){
+      if($attr == "number"){
+        $add_user[$attr]  = $this->info['userID'];
+      }else{
+        $add_user[$attr]  = $this->info[$attr];
+      }
+    }
+    $QUERY[] = gen_syntax($add_user,"person","EDIT",$ist);
+
+
+    /*
+       Entry for staff table
+     */
+    $arr = array("staff_id","company_id","description","login","is_team","is_account","db_status");
+    $this->info['staff_id'] = $this->ogo->gen_id();
+    foreach($arr as $attr){
+      $add_staff[$attr] = $this->info[$attr];
+    }
+    $QUERY[] = gen_syntax($add_staff,"staff","EDIT",$ist);
+
+
+    /* 
+       Create entries for company nfo 
+     */
+    $arr = array("company_info_id","company_id","db_status");
+    $this->info['company_info_id']    = $this->ogo->gen_id();
+    foreach($arr as $attr){
+      $add_company_info[$attr]  = $this->info[$attr];
+    }
+    $QUERY[] = gen_syntax($add_company_info,"company_info","EDIT",$ist);
+
+
+    /* 
+       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","ADD",false);
+
+
+    /* 
+       address entries 
+     */
+    $QUERY[] = "DELETE FROM address WHERE company_id=".$ist[0]['company_id'].";";
+    $this->info['company_id'] = $ist[0]['company_id'];
+    $arr = array("company_id","address_id","street","zip","country","zipcity","state","db_status","name1","type");
+    foreach(array("private","mailing","location") as  $type){
+      $this->info['type']       = $type;
+      $this->info['address_id'] = $this->ogo->gen_id();
+      foreach($arr as $attr){
+        $add_address[$attr]  = $this->info[$attr];
+      } 
+      $QUERY[] = gen_syntax($add_address,"address","ADD",false);
+    }
+
+
+    /*
+       telephone entries 
+     */
+    $QUERY[] = "DELETE FROM telephone WHERE company_id=".$ist[0]['company_id'].";";
+    $this->info['company_id'] = $ist[0]['company_id'];
+    $arr = array("telephone_id","object_version","company_id","number","type","db_status");
+    foreach(array("01_tel","02_tel","03_tel_funk","05_tel_private","10_fax","fax_private") as $type){
+      $this->info['type']           = $type;
+      $this->info['telephone_id']   = $this->ogo->gen_id();
+      foreach($arr as $attr){
+        $add_telephone[$attr]  = $this->info[$attr];
+      }
+
+      $QUERY[] = gen_syntax($add_telephone,"telephone","ADD",false);
+    }
+
+
+    /*
+       company_assignment entries (Location Team) 
+     */
+    $this->info['old_company_id'] = $this->info['company_id'];
+    
+    /* First remove location team */
+    $QUERY[] = "DELETE FROM company_assignment WHERE (sub_company_id=".$ist[0]['company_id'].") AND
+      company_id in (SELECT company_id FROM team WHERE is_location_team=1);";
+
+    $this->info['sub_company_id']       = $ist[0]['company_id'];
+    $this->info['company_assignment_id']= $this->ogo->gen_id();
+    $this->info['company_id']           = $this->info['LocationTeamID'];
+    $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
+    foreach($arr as $attr){
+      $add_company_assignment[$attr]  = $this->info[$attr];
+    }
+    $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false);
+
+
+    /*
+       company_assignment entries (Teams) 
+     */
+    /* First remove location team */
+    $QUERY[] = "DELETE FROM company_assignment 
+                WHERE 
+                    (sub_company_id=".$ist[0]['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));";
+
+    $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
+
+    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 ){
+      if(!$this->ogo-> Query($q)){
+        print $q;
+        $remove_all = true;
+        break;
+      }
+    }
+  }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/gosa-plugins/opengroupware/personal/connectivity/opengroupware/class_opengwAccount.inc b/gosa-plugins/opengroupware/personal/connectivity/opengroupware/class_opengwAccount.inc
new file mode 100644 (file)
index 0000000..e2b4f5e
--- /dev/null
@@ -0,0 +1,356 @@
+<?php
+
+class opengwAccount extends plugin
+{
+       /* Definitions */
+       var $plHeadline       = "Opengroupware account";
+       var $plDescription    = "This does something";
+
+       /* attribute list for save action */
+       var $attributes       = array();
+       var $objectclasses    = array();
+
+  var $SetPassword   = false;
+
+       /* Attribute mapping opengroupware->ldap  */
+       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;
+       var $initialy_was_account = false;
+  var $OGWPassword          = "";
+  var $ReadOnly = false;
+  var $view_logged = FALSE;  
+  var $uid = "";
+
+       function opengwAccount (&$config, $dn= NULL)
+       {
+               plugin::plugin ($config, $dn);
+
+    /* Setting uid to default */
+    if(isset($this->attrs['uid'][0])){
+      $this->uid = $this->attrs['uid'][0];
+    }
+
+               $this->info=array();
+
+               /* is no account and was no account */
+               $this->initialy_was_account = false;
+               $this->is_account           = false;
+
+               /* Get configurations */
+    if($this->config->search("opengwAccount", 'USERNAME',array('tabs'))){
+      $atr = array();
+      $atr['LOGIN']    =         $this->config->search("opengwAccount", 'USERNAME',array('tabs'));
+      $atr['PASSWORD']=        $this->config->search("opengwAccount", 'PASSWORD',array('tabs'));
+      $atr['SERVER']   =       $this->config->search("opengwAccount", 'DATAHOST',array('tabs'));
+      $atr['DB']               =         $this->config->search("opengwAccount", 'DATABASE',array('tabs'));
+      $this->serverCon = $atr;
+    }elseif(isset($this->config->data['SERVERS']['OPENGROUPWARE'])){
+      $this->serverCon  = $this->config->data['SERVERS']['OPENGROUPWARE'];
+    }else{
+      $this->serverCon = array();
+    }
+
+    /* check if datebase funktions are available, and if database configurations are available */ 
+               if(is_callable("pg_connect") && count($this->serverCon)){
+
+                       $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
+
+                       /* Check if current configuration allows database connection */
+                       if($this->handle->connected){
+
+                               /* Set login name, to check if this is_account */
+                               if(isset($this->attrs['uid'][0])){
+                                       $this->handle->info['login'] = $this->attrs['uid'][0];
+                               }else{
+                                       $this->handle->info['login'] = ""; 
+                               }
+
+                               /* If this is account get data from database first */
+                               if($this->handle->CheckExistence()){
+                                       $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
+
+                                       /* This is an account */
+                                       $this->initialy_was_account = true;
+                                       $this->is_account= true;
+                               }else{
+                                       /* this is no account */ 
+                                       $this->initialy_was_account = false;
+                                       $this->is_account= false;
+
+                                       /* Selectable in GOsa */
+                                       $this->info['template_user_id']   = 0;
+                                       $this->info['is_locked']          = 0;
+                                       $this->info['LocationTeamID']     = 0;
+                                       $this->info['TeamIDis']           = array();
+                               }
+
+                               /* Set settings from ldap */
+                               foreach($this->attrsToUse as $name=>$attr){
+                                       if(isset($this->attrs[$attr][0])){
+                                               $this->info[$name] = $this->attrs[$attr][0];
+                                       }else{
+                                               $this->info[$name] = false;
+                                       }
+                               } 
+
+                               /* Description is displayed as 'Nickname' */
+                               $this->info['description']          = $this->info['login'];
+
+                               if($this->info['sex'] == "F"){
+                                       $this->info['sex']                = "female";
+                               }else{
+                                       $this->info['sex']                = "male";
+                               }
+
+                       }
+
+                       /* Transmit data back to ogw handle */
+                       $this->handle->SetInfos($this->info);
+               }
+       }
+
+       function execute()
+       {
+    /* Log view */
+    if($this->is_account && !$this->view_logged){
+      $this->view_logged = TRUE;
+      new log("view","users/".get_class($this),$this->dn);
+    }
+
+               /* Show tab dialog headers */
+               $display= "";
+               $smarty= get_smarty();
+
+    $smarty->assign("serverCon",count($this->serverCon));
+    $smarty->assign("validTeams","");
+    $smarty->assign("is_account", " ");
+    $smarty->assign("OGWstate"," disabled ");
+    $smarty->assign("validLocationTeam",array("&nbsp;"));
+    $smarty->assign("validLocationTeams",array("&nbsp;"));
+    $smarty->assign("LocationTeam",0);
+    $smarty->assign("validTemplateUser",array("&nbsp;"));
+    $smarty->assign("validTemplateUsers",array("&nbsp;"));
+    $smarty->assign("TemplateUser",0);
+    $smarty->assign("is_lockedCHK", "  ");
+    $smarty->assign("is_locked", "  ");
+               /* set default values */
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $acl => $desc){
+      $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
+    } 
+
+    if((!$this->ReadOnly)&&(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))) {
+      $smarty->assign('opengwAccountACL', "");
+    }else{
+      $smarty->assign('opengwAccountACL', " disabled ");
+    }
+
+    if(count($this->serverCon))
+
+               /* Check database extension */    
+               if(!is_callable("pg_connect") && count($this->serverCon)){
+      msg_dialog::display(_("Configuration error"), sprintf(_("Missing %s PHP extension!"), "postgresql"), ERROR_DIALOG);
+               }elseif(count($this->serverCon)){
+
+                       /* Check if config exists */
+                       if($this->config->search("opengwAccount", 'DATABASE',array('tabs'))){
+        msg_dialog::display(_("Configuration error"), sprintf(_("%s database configuration is missing!"), "Open Groupware"), ERROR_DIALOG);
+                       }else{
+
+                               /* Create handle */
+                               $this->handle     = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
+
+                               /* Check if we are successfully connected to db */
+                               if(!$this->handle->connected){
+          msg_dialog::display(_("Configuration error"), sprintf( _("Cannot connect to %s database!"), "Open Groupware"), ERROR_DIALOG);
+                               }else{
+
+                                       /* Assign LocationTeams */
+                                       $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']);
+
+                                       /* Assign TemplateUsers*/
+                                       $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']);
+
+                                       /* Create Team membership */ 
+                                       $str = "";
+                                       if(($this->is_account)==""){
+                                               $dis = "";
+                                       }else{
+                                               $dis = " disabled ";
+                                       }
+
+          if($this->acl_is_readable("Teams")){
+            foreach($this->handle->validTeams as $id){
+              if(in_array($id['company_id'],$this->info['TeamIDis'])){
+                $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
+                  checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
+              }else{
+                $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."' 
+                  name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
+              }
+            }
+          }
+                                       $smarty->assign("validTeams",$str);
+
+                                       /* Assign ogw checkbox */
+                                       if($this->is_account){
+                                               $smarty->assign("OGWstate","");
+                                               $smarty->assign("is_account", " checked ");
+                                       }else{
+                                               $smarty->assign("is_account", " ");
+                                               $smarty->assign("OGWstate"," disabled ");
+                                       }
+
+                                       /* Assign lock status */
+                                       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);
+       }
+
+       function remove_from_parent()
+       {
+               /* remove database entries */
+               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");
+
+      new log("remove","users/".get_class($this),$this->dn);
+               }
+       }
+
+
+       /* Save data to object */
+       function save_object()
+       {
+               /* get post data */
+               if($this->is_account){
+
+      /* Get selected team chkboxes */
+      $this->info['TeamIDis'] = array();
+      if($this->acl_is_writeable("Teams")) {
+        foreach($_POST as $name => $value ){
+          if(preg_match("/team_/i",$name)){
+            if(!in_array($value,$this->info['TeamIDis'])){
+              $this->info['TeamIDis'][]=$value;
+            }
+          }
+        }
+      }
+
+
+                       /* Get location Team*/
+                       if(isset($_POST['LocationTeam']) && $this->acl_is_writeable("LocationTeam")){
+                               $this->info['LocationTeamID'] = $_POST['LocationTeam'];
+                       }
+
+                       /* Get template user */
+                       if(isset($_POST['TemplateUser']) && $this->acl_is_writeable("TemplateUser") ){
+                               $this->info['template_user_id'] = $_POST['TemplateUser'];
+                       }
+
+      /* get lock status */
+      if($this->acl_is_writeable("Locked")){
+        if(isset($_POST['is_locked'])){
+          $this->info['is_locked'] = $_POST['is_locked'];
+        }else{
+          $this->info['is_locked'] = 0;
+        }
+      }
+               }
+
+               /* change account status */
+               if(isset($_POST['is_account'])){
+      if($this->acl_is_createable()){
+        $this->is_account = $_POST['is_account'];
+      }
+    }else{
+      if($this->acl_is_removeable()){
+        $this->is_account = false;//$_POST['is_account'];
+      }
+               }
+       }
+
+
+       /* Save to LDAP */
+       function save()
+       {
+               /* Save data */ 
+               $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");
+      new log("modify","users/".get_class($this),$this->dn);
+               }else{
+                       $this->handle->Perform("ADD");
+      new log("create","users/".get_class($this),$this->dn);
+               }
+       }
+
+  
+  function PrepareForCopyPaste($src){
+    // Nothing to do, because this object can't be copied ... yet
+  }
+
+
+ /* Return plugin informations for acl handling 
+      #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */  
+  static function plInfo()
+  {
+    return (array(
+          "plShortName"     => _("Opengroupware"),
+          "plDescription"   => _("Open groupware account settings")."&nbsp;:&nbsp;<u>"._("Connectivity addon")."</u>",
+          "plSelfModify"    => TRUE,
+          "plDepends"       => array("user"),
+          "plPriority"      => 26,                                 // Position in tabs
+          "plSection"     => array("personal" => _("My account")),
+          "plCategory"    => array("users"),
+          "plOptions"       => array(),
+
+          "plProvidedAcls"  => array(
+            "LocationTeam"  => _("Location team"),
+            "TemplateUser"  => _("Template user"),
+            "Locked"        => _("Locked"),
+            "Teams"         => _("Teams"))
+          ));
+  }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/gosa-plugins/opengroupware/personal/connectivity/opengroupware/opengw.tpl b/gosa-plugins/opengroupware/personal/connectivity/opengroupware/opengw.tpl
new file mode 100644 (file)
index 0000000..5687417
--- /dev/null
@@ -0,0 +1,59 @@
+<h2><input type="checkbox" value="1" name="is_account" {$is_account} {$opengwAccountACL} onClick="document.mainform.submit();">&nbsp;{t}Opengroupware{/t}</h2>
+<table width="100%" summary="">
+       <tr>
+               <td width="50%">
+                       <table summary="">
+                               <tr>
+                                       <td>
+                                               {t}Location team{/t} &nbsp;
+                                       </td>
+                                       <td>
+{render acl=$LocationTeamACL}
+                                               <select size="1" id="LocationTeam" name="LocationTeam"
+                                                       {if $OGWstate!=""} disabled {/if}>
+                                                       {html_options values=$validLocationTeams output=$validLocationTeam selected=$LocationTeam}
+                                               </select>
+{/render}
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>
+                                               {t}Template user{/t} &nbsp;
+                                       </td>
+                                       <td>
+{render acl=$TemplateUserACL}
+                                               <select size="1" id="TemplateUser" name="TemplateUser" {if $OGWstate!=""} disabled {/if}>
+                                                       {html_options values=$validTemplateUsers output=$validTemplateUser selected=$TemplateUser}
+                                               </select>
+{/render}
+                                       </td>
+                               </tr>   
+                               <tr>
+                                       <td valign="top">
+                                               {t}Locked{/t} &nbsp; 
+                                       </td>
+                                       <td valign="top">
+{render acl=$LockedACL}
+                                               <input type="checkbox" value="1" name="is_locked" {$is_lockedCHK}  
+                                                  {if $OGWstate!=""} disabled {/if}>
+{/render}
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+               <td valign="top" style="border-left: 1px solid rgb(160, 160, 160);">
+                       <table summary="">
+                               <tr>
+                                       <td valign="top">
+                                               {t}Teams{/t} &nbsp; 
+                                       </td>
+                                       <td valign="top">
+{render acl=$TeamsACL}
+                                               {$validTeams}   
+{/render}
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+       </tr>
+</table>