Code

Updated ldap export
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 26 Apr 2010 11:33:50 +0000 (11:33 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 26 Apr 2010 11:33:50 +0000 (11:33 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@17835 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/ldapmanager/addons/ldapmanager/class_export.inc
gosa-plugins/ldapmanager/addons/ldapmanager/contentexport.tpl

index dfd562ccae13dbe15f84046498d4f3856c210266..b61a9de4027fb341c92021b6f9abe3a6a58192ed 100644 (file)
 
 class ldifexport extends plugin
 {
-  /* Definitions */
-  var $plHeadline= "CSV import";
-  var $plDescription= "This does something";
-
-  /* attribute list for save action */
-  var $attributes= array();
-  var $objectclasses= array();
-  var $view_logged = FALSE;
-
-  function ldifexport (&$config, $dn= NULL)
-  {
-    /* Include config object */
-    $this->config= &$config;
-    $this->ui = get_userinfo();
-  }
-
-  function execute()
-  {
-    /* Call parent execute */
-    plugin::execute();
-
-    /* Log view */
-    if(!$this->view_logged){
-      $this->view_logged = TRUE;
-      new log("view","all/".get_class($this),$this->dn);
-    }
-
-    /* Set government mode */
-    $smarty= get_smarty();
-
-    $smarty->assign ("govmode", $this->config->get_cfg_value("honourIvbbAttributes"));
-    $smarty->assign("LDIFError",FALSE);
+    /* Definitions */
+    var $plHeadline= "CSV import";
+    var $plDescription= "This does something";
 
-    $smarty->assign("type",FALSE);
-    $smarty->assign("depselectivbb","");
+    /* attribute list for save action */
+    var $attributes= array();
+    var $objectclasses= array();
+    var $view_logged = FALSE;
 
-    // fill in old vars in the Export form
-    if((isset($_POST['single']))&&(isset($_POST['sfrmgetsingle']))){
-      $smarty->assign("single",$_POST['single']);
-      $smarty->assign("type","single");
-      $dn = $_POST['single'];
-    }
-    if((isset($_POST['selfull']))&&(isset($_POST['sfrmgetfull']))){
-      $smarty->assign("depselectfull",$_POST['selfull']);
-      $smarty->assign("type","full");
-      $dn = $_POST['selfull'];
-    } else {
-      $smarty->assign("depselectfull", "");
-    }
-    if((isset($_POST['selivbb']))&&(isset($_POST['sfrmgetivbb']))){
-      $smarty->assign("depselectivbb",$_POST['selivbb']);
-      $smarty->assign("type","ivbb");
-      $dn = $_POST['selivbb'];
-    } else {
-      $smarty->assign("depselectivbb", "");
-    }
+    var $base;
 
-    // Set values for optionlist in form
-    $bases      = array();
-    $acl_bases  = $this->ui->get_module_departments("ldapmanager");
-    foreach($this->config->idepartments as $base_dn => $name){
-      if(in_array_ics($base_dn,$acl_bases)){
-        $bases[$base_dn] = $name;
-      }
-    }
-    $smarty->assign("deplist", $bases);
+    function ldifexport (&$config, $dn= NULL)
+    {
+        /* Include config object */
+        $this->config= &$config;
+        $this->ui = get_userinfo();
 
-    // Get the LDAP link, to generate the Export
-    $ldap = $this->config->get_ldap_link();
+        $this->baseSelector= new baseSelector($this->config->idepartments, $this->config->current['BASE']);
+        $this->baseSelector->setSubmitButton(false);
+        $this->baseSelector->setHeight(300);
+        $this->baseSelector->update(true);
 
-    if ($this->config->get_cfg_value('honourIvbbAttributes') == 'true'){
-      $smarty->assign ("govmode", $this->config->get_cfg_value("honourIvbbAttributes"));
-      $smarty->assign("LDIFError",FALSE);
     }
 
-    if(isset($dn))
+    function execute()
     {
-      if(!($ldap->dn_exists($dn) && $dn != "")){
-        $smarty->assign("LDIFError",TRUE);
-       msg_dialog::display(_("Error"), _("Cannot export selected entries!"), ERROR_DIALOG);
-      }
-    }
-
-    /* check alcs for given dn */
-    $acls ="";
-    if(isset($dn)){
-      $acls = $this->ui->get_permissions($dn,"ldapmanager/ldif");
-    }
-    if((!preg_match("/r/",$acls)) && (isset($dn))){
-
-      /* Show error msg */      
-      msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to export '%s'!"),LDAP::fix($dn)), ERROR_DIALOG);
-
-      /* Show main page */
-      $smarty->assign("LDIFError",TRUE);
-      $smarty->assign("para","");
-    }else{
-
-      // Export a single LDAP entry
-      if(isset($_POST['sfrmgetsingle']))
-      {
-        $smarty->assign("para","?ivbb=2&amp;dn=".base64_encode($_POST['single']));
-      }
-      elseif(isset($_POST['sfrmgetfull']))
-      {
-        $smarty->assign("para","?ivbb=3&amp;dn=".base64_encode($_POST['selfull']));
-      }
-      elseif(isset($_POST['sfrmgetivbb']))
-      {
-        $smarty->assign("para","?ivbb=4&amp;dn=".base64_encode($_POST['selivbb']));
-      }
+        /* Call parent execute */
+        plugin::execute();
+
+        /* Log view */
+        if(!$this->view_logged){
+            $this->view_logged = TRUE;
+            new log("view","all/".get_class($this),$this->dn);
+        }
+
+        // Update baseSelector
+        if (!$this->baseSelector->update()) {
+            msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
+        }
+        if ($this->base != $this->baseSelector->getBase()) {
+            $this->base= $this->baseSelector->getBase();
+            $this->is_modified= TRUE;
+        }
+
+
+        // Assign smarty values 
+        $smarty= get_smarty();
+        $smarty->assign("single","");
+        $smarty->assign("base", $this->baseSelector->render());
+
+        // fill in old vars in the Export form
+        if(isset($_POST['single'])) $smarty->assign("single",$_POST['single']);
+
+        // Get the LDAP link, to generate the Export
+        $ldap = $this->config->get_ldap_link();
+        $dn = "";
+        if(isset($_POST['sfrmgetsingle']))
+        {  
+            $dn   = $_POST['single'];
+            $scope= "base";
+            $acls = $this->ui->get_permissions($dn,"ldapmanager/ldif");
+            $name = "entryExport.ldif";
+            if(!$ldap->dn_exists($dn)){
+                msg_dialog::display(_("Ldap error"),
+                        sprintf(_("No such object '%s'!"),bold(LDAP::fix($dn))),
+                        ERROR_DIALOG);
+                $dn ="";
+            }
+
+        }elseif(isset($_POST['sfrmgetfull'])){
+            $dn   = $this->base;
+            $scope= "sub";
+            $acls = $this->ui->get_permissions($dn,"ldapmanager/ldif");
+            $name = "fullExport.ldif";
+        }
+
+        if(!empty($dn)){
+            // Check permissions before sending the output
+            if(!preg_match("/r/",$acls)){
+                msg_dialog::display(_("Permission error"), 
+                        sprintf(_("You have no permission to export '%s'!"),LDAP::fix($dn)),
+                        ERROR_DIALOG);
+            }else{
+                $data = $ldap->generateLdif($dn, 'objectClass=*',array(),$scope);
+                send_binary_content($data,$name);
+            }
+        }
+
+        // Show the main form
+        return ($smarty->fetch (get_template_path('contentexport.tpl', TRUE)));
     }
-
-    /* Show main page */
-    return ($smarty->fetch (get_template_path('contentexport.tpl', TRUE)));
-  }
 }
 
 
index bf91edfa7f5aa629a69db25722c9d03c2a88a1e4..1e619e98ad494c7d554310c024358785585a2eda 100644 (file)
@@ -1,4 +1,3 @@
-{if $LDIFError != FALSE || $type == FALSE}
 <p style="margin-top:5px;">
   {t}The LDIF export plugin provides methods to download a complete snapshot of the running LDAP directory as ldif. You may save these files for backup purpose or when initializing a new server.{/t}
 </p>
@@ -10,7 +9,7 @@
                <LABEL for="text" >{t}Export single entry{/t}</LABEL>
        </td>
        <td>
-               <input id="text" type="text" value="" name="single">
+               <input id="text" type="text" value="{$single}" name="single">
        </td>
        <td>
                <button type='submit' name='sfrmgetsingle'>{t}Export{/t}</button>
                <LABEL for="selfull">{t}Export complete LDIF for{/t}</LABEL>
        </td>
        <td>
-               <select id="selfull" name="selfull" size="1" title="{t}Choose the department you want to Export{/t}">
-                       {html_options options=$deplist selected=0}
-               </select>
+        {$base}
        </td>
        <td>
                <button type='submit' name='sfrmgetfull'>{t}Export{/t}</button>
 
        </td>
 </tr>
-       
-{if $govmode eq "true"}
-<tr>
-       <td width="30%">
-               <LABEL for="selivbb">{t}Export IVBB LDIF for{/t}</LABEL>
-       </td>
-       <td>
-               <select id="selivbb" name="selivbb" size="1" title="{t}Choose the department you want to Export{/t}">
-                       {html_options options=$deplist selected=$depselectivbb}
-               </select>
-       </td>
-       <td>
-               <button type='submit' name='sfrmgetivbb'>{t}Export{/t}</button>
-
-       </td>
-</tr>
-{/if}
 </table> 
 
-
-{else}
-
-
-<br>
-       <h3>{t}Export successful{/t}</h3>
-<br>
-       <div>
-               {image path="images/filesaveas.png"}
-
-               <a href = "plugins/ldapmanager/getldif.php{$para}" title="{t}Click here to save the complete LDAP database to a file{/t} ">{t}Click here to save the LDAP Export {/t}</a>
-
-
-               <br>
-               <br>
-       </div>
-       <div align="right">
-               <button type='submit' name='back'>{msgPool type=backButton}</button>
-
-       </div>
-{/if}
-
 <hr>
 
 <input type="hidden" name="ignore">