Code

Fixed deletion for ogw
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 7 Dec 2005 07:34:29 +0000 (07:34 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 7 Dec 2005 07:34:29 +0000 (07:34 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2242 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_opengw.inc
include/class_pgsql_opengw.inc
plugins/gofon/phoneaccount/class_phoneAccount.inc
plugins/personal/connectivity/class_opengwAccount.inc

index 62ff5647319118a49c02d48d06afd169e5e1323d..6d102198490aee6c7e391ba9e498be7a2ed71f09 100755 (executable)
@@ -99,12 +99,29 @@ class ogw{
       if(($this->option == "EDIT")||($this->option=="ADD")){
 
         /* Static variables */
-        $this->info['is_person']          = 1;
-        $this->info['is_account']         = 1;
-        $this->info['is_intra_account']   = 1;
-        $this->info['is_extra_account']   = 0;
-        $this->info['owner_id']           = 10000;
-        $this->info['is_team']            = 0;
+        if(!isset($this->info['is_person'])){
+          $this->info['is_person']          = 1;  
+        }
+        
+        if(!isset($this->is_account)){
+          $this->info['is_account']         = 1;  
+        }
+        
+        if(!isset($this->info['is_intra_account'])){
+          $this->info['is_intra_account']   = 1;
+        }
+
+        if(!isset($this->info['is_extra_account'])){
+          $this->info['is_extra_account']   = 0;
+        }
+
+        if(!isset($this->info['owner_id'])){
+          $this->info['owner_id']           = 10000;
+        }
+
+        if(!isset($this->info['is_team'])){
+          $this->info['is_team']            = 0;
+        }
 
         $this->InfoOK = $this->checkInfos();
 
@@ -126,7 +143,7 @@ class ogw{
               $this->LastError="Can't edit entry, entry doesn't exists.";
               return(false);
             }else{
-              $this->info['db_status']          = "edited";
+              $this->info['db_status']          = "updated";
               $this->info['object_version']     = $ist[0]['object_version']++;
               return($this->EDIT());
             }
@@ -220,7 +237,12 @@ class ogw{
       $this->LastError(sprintf("Can't get company id for login %s",$this->info['login']));
       return(false);
     }else{
+
       $company_id     = $ist[0]['company_id'];
+
+      $qry = "UPDATE person SET login='SKY".$company_id.$this->info['login']."', is_account=0, is_intra_account=0 WHERE company_id=".$company_id.";";
+      $this->ogo->Query($qry);
+      /*
       $this->ogo->Query("DELETE FROM telephone WHERE company_id=".$company_id.";");
       $this->ogo->Query("DELETE FROM address  WHERE company_id=".$company_id.";");
       $this->ogo->Query("DELETE FROM company_info WHERE company_id=".$company_id.";");
@@ -228,6 +250,7 @@ class ogw{
       $this->ogo->Query("DELETE FROM company_assignment WHERE sub_company_id=".$company_id.";");
       $this->ogo->Query("DELETE FROM person WHERE company_id=".$company_id.";");
       $this->ogo->Query("DELETE FROM staff WHERE company_id=".$company_id.";");
+      */
       return(true);
     }
   }
index 2c6ce876dd9442f90514960b5388d88b670fa73b..7e53cb805bfcc63da0bccafa0d33ff0fa15c2a29 100644 (file)
@@ -28,7 +28,11 @@ class pgre_sql{
   {
        error_reporting(E_ALL);
        if(is_callable("pg_connect")){
-               $this->handle = @pg_connect("dbname=".$this->db." host=".$this->server." user=".$this->user);
+               if(!empty($this->pwd)){
+                       $this->handle = @pg_connect("dbname=".$this->db." host=".$this->server." user=".$this->user);
+               }else{
+                       $this->handle = @pg_connect("dbname=".$this->db." host=".$this->server." user=".$this->user." password=".$this->pwd);
+               }
                if(!$this->handle){
                        $this->handle = false;
                }
index 4610285fb50e38922704978349cd035b99cb2124..031dea731972a59c43119d9fc67dd42f7ddc69e8 100644 (file)
@@ -890,7 +890,6 @@ class phoneAccount extends plugin
       }
     }
 
-
     if((strlen($this->goFonPIN)!=4)){
       $message[]=(_("Phone PIN must be 4 characters long."));
     }else{
index c4a7f8c2c849f16466d3d39cbc8a92a21cdb6402..fcba8b86ff86b8c9e6528bff90715d7eb0210b7f 100644 (file)
@@ -12,9 +12,10 @@ class opengwAccount extends plugin
   var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
 
   /* attribute list for save action */
-  var $attributes= array();
-  var $objectclasses= array("gosaWebdavAccount");
+  var $attributes       = array();
+  var $objectclasses    = array();
 
+  /* Attribute mapping opengroupware->ldap  */
   var $attrsToUse    = array( "salutation"  =>"vocation",
                               "name"        =>"sn",
                               "firstname"   =>"givenName",
@@ -27,10 +28,11 @@ class opengwAccount extends plugin
                               "value_string"=>"mail",
                               "number"      =>"telephoneNumber"
                             );
-  var $serverCon =  false;
 
-  var $handle   = NULL;
-  var $is_account  = false;
+  var $serverCon            =  false;
+  var $handle               = NULL;
+  var $is_account           = false;
+  var $initialy_was_account = false;
 
   function opengwAccount ($config, $dn= NULL)
   {
@@ -38,42 +40,35 @@ class opengwAccount extends plugin
 
     $this->info=array();
 
+    /* is no account and was no account */
     $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']);
+    $this->is_account           = false;
 
-      if(!$this->handle->connected){
-//        print_red(_("Can't connect to specified database. Please check given configuration twice."));
-      }else{
+    /* check if datebase funktions are available, and if database configurations are available */ 
+    if((is_callable("pg_connect"))&&(isset($this->config->data['SERVERS']['OPENGROUPWARE']))){
+
+      /* Get configurations */
+      $this->serverCon  = $this->config->data['SERVERS']['OPENGROUPWARE'];
+      $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 */
         $this->handle->info['login'] = $this->attrs['uid'][0];
+
+        /* 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;
-
-          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;
@@ -81,11 +76,28 @@ class opengwAccount extends plugin
           $this->info['TeamIDis']           = array();
         }
 
-        if(!is_array($this->info['TeamIDis'])){
-          $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";
         }
-        $this->handle->SetInfos($this->info);
+
       }
+    
+      /* Transmit data back to ogw handle */
+      $this->handle->SetInfos($this->info);
     }
   }
 
@@ -94,10 +106,11 @@ class opengwAccount extends plugin
     /* Show tab dialog headers */
     $display= "";
     $smarty= get_smarty();
+
+    /* set default values */
     foreach(array("validLocationTeam","validTemplateUser","validLocationTeams","validTemplateUsers") as $ar){
       $smarty->assign($ar,array());
     }
-
     $smarty->assign("OGWstate"," disabled ");
     foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount") as $ar){
       $smarty->assign($ar,"");
@@ -105,25 +118,32 @@ class opengwAccount extends plugin
       $smarty->assign($ar."ACL"," disabled ");
     }
 
-    
+    /* Check database extension */    
     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'])){
+    }else
+  
+    /* Check if config exists */
+      if(!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']);
+
+      /* Create handle */
+      $this->serverCon  = $this->config->data['SERVERS']['OPENGROUPWARE'];
+      $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){
         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 */
 
+        /* 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));
         }
 
+        /* Assign LocationTeams */
         $tmp = array(""=>"none");
         foreach($this->handle->validLocationTeam as $id){
           $tmp[$id['company_id']] = $id['description']; 
@@ -132,6 +152,7 @@ class opengwAccount extends plugin
         $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']; 
@@ -139,9 +160,8 @@ class opengwAccount extends plugin
         $smarty->assign("validTemplateUser",$tmp);
         $smarty->assign("validTemplateUsers",array_flip($tmp));
         $smarty->assign("TemplateUser",$this->info['template_user_id']);
-        
-
-        $this->handle->CheckExistence();
+       
+        /* Create Team membership */ 
         $str = "";
         if($this->is_account){
           $dis = "";
@@ -151,13 +171,16 @@ class opengwAccount extends plugin
 
         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>";
+            $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>";
+            $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 ");
@@ -166,17 +189,19 @@ class opengwAccount extends plugin
           $smarty->assign("OGWstate"," disabled ");
         }
 
+        /* Assign acls */
         foreach(array("LocationTeam","TemplateUser","Teams","is_locked") as $atr){
           $smarty->assign($atr."ACL",chkacl($this->acl,$atr));
         }
-
+  
+        /* 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__)));
@@ -185,6 +210,7 @@ class opengwAccount extends plugin
 
   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);
@@ -196,7 +222,10 @@ class opengwAccount extends plugin
   /* Save data to object */
   function save_object()
   {
+    /* get post data */
     if($this->is_account){
+    
+      /* Get selected team chkboxes */
       $this->info['TeamIDis'] = array();
       foreach($_POST as $name => $value ){
         if(preg_match("/team_/i",$name)){
@@ -205,14 +234,18 @@ class opengwAccount extends plugin
           }
         }
       }
+
+      /* Get location Team*/
       if(isset($_POST['LocationTeam'])){
         $this->info['LocationTeamID'] = $_POST['LocationTeam'];
       }
       
+      /* Get template user */
       if(isset($_POST['TemplateUser'])){
         $this->info['template_user_id'] = $_POST['TemplateUser'];
       }
       
+      /* get lock status */
       if(isset($_POST['is_locked'])){
         $this->info['is_locked'] = $_POST['is_locked'];
       }else{
@@ -220,6 +253,7 @@ class opengwAccount extends plugin
       }
     }
  
+    /* change account status */
     if(isset($_POST['is_account'])){
       $this->is_account = $_POST['is_account'];
     }else{
@@ -231,7 +265,8 @@ class opengwAccount extends plugin
 
   /* 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();