Code

Big commit for opengroupware account
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 6 Dec 2005 14:38:31 +0000 (14:38 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 6 Dec 2005 14:38:31 +0000 (14:38 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2241 594d385d-05f5-0310-b6e9-bd551577e9d8

contrib/gosa.conf
include/class_config.inc
include/class_opengw.inc
include/class_pgsql_opengw.inc
plugins/personal/connectivity/class_opengwAccount.inc
plugins/personal/connectivity/opengw.tpl

index 6d392760d1e85fba9989e5d8e14239d1858efda5..c1ff3770de316753d1bb8d2c27e5e36176e7f21d 100644 (file)
                <tab class="webdavAccount" />
                <tab class="phpgwAccount" />
                <tab class="intranetAccount" />
+               <tab class="opengwAccount" />
 <!--           <tab class="pptpAccount" /> -->
 <!--           <tab class="phpscheduleitAccount" /> -->
 <!--           <tab class="glpiAccount" /> -->
index a5eecb263c628b1a239c3c351578ebfcbf7c15b9..edffe0dac224004808c1cb2d30fb3ee956903733 100644 (file)
@@ -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)");
index 159ddf28b82926ad6b655d70709f6888fad9faa9..62ff5647319118a49c02d48d06afd169e5e1323d 100755 (executable)
@@ -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);
 
 
     /* 
index ed9544ada82b6cf1134c3d7233b5f295c224b9d6..2c6ce876dd9442f90514960b5388d88b670fa73b 100644 (file)
@@ -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.", ";
index 0980c8867f7c18662b1160a01c081b37e841beb7..c4a7f8c2c849f16466d3d39cbc8a92a21cdb6402 100644 (file)
@@ -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 .= "<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);
+
+        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");
     }
   }
 
index f13588b91f5e9166eefb16d8f71dbd1227753596..ff94ad601c0dd89eec7f5b234f9da193ad2e2b3c 100644 (file)
@@ -1 +1,49 @@
-asdfasdf
+<h2><input type="checkbox" value="1" name="is_account" {$is_account} {$opengwAccountACL} onClick="document.mainform.submit();">&nbsp;{t}Opengroupware{/t}</h2>
+<table width="100%">
+       <tr>
+               <td width="50%">
+                       <table>
+                               <tr>
+                                       <td>
+                                               {t}Location team{/t} :&nbsp;
+                                       </td>
+                                       <td>
+                                               <select size="1" id="LocationTeam" name="LocationTeam" {$LocationTeamACL} {$OGWstate}>
+                                                       {html_options values=$validLocationTeams output=$validLocationTeam selected=$LocationTeam}
+                                               </select>
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>
+                                               {t}Template user{/t} :&nbsp;
+                                       </td>
+                                       <td>
+                                               <select size="1" id="TemplateUser" name="TemplateUser" {$TemplateUserACL} {$OGWstate}>
+                                                       {html_options values=$validTemplateUsers output=$validTemplateUser selected=$TemplateUser}
+                                               </select>
+                                       </td>
+                               </tr>   
+                               <tr>
+                                       <td valign="top">
+                                               {t}Locked{/t} :&nbsp; 
+                                       </td>
+                                       <td valign="top">
+                                               <input type="checkbox" value="1" name="is_locked" {$is_lockedCHK} {$is_lockedACL} {$OGWstate}>
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+               <td valign="top" style="border-left: 1px solid rgb(160, 160, 160);">
+                       <table>
+                               <tr>
+                                       <td valign="top">
+                                               {t}Teams{/t} :&nbsp; 
+                                       </td>
+                                       <td valign="top">
+                                               {$validTeams}   
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+       </tr>
+</table>