Code

Updated ldap export
[gosa.git] / gosa-plugins / ldapmanager / addons / ldapmanager / class_export.inc
1 <?php
3 class ldifexport extends plugin
4 {
5     /* Definitions */
6     var $plHeadline= "CSV import";
7     var $plDescription= "This does something";
9     /* attribute list for save action */
10     var $attributes= array();
11     var $objectclasses= array();
12     var $view_logged = FALSE;
14     var $base;
16     function ldifexport (&$config, $dn= NULL)
17     {
18         /* Include config object */
19         $this->config= &$config;
20         $this->ui = get_userinfo();
22         $this->baseSelector= new baseSelector($this->config->idepartments, $this->config->current['BASE']);
23         $this->baseSelector->setSubmitButton(false);
24         $this->baseSelector->setHeight(300);
25         $this->baseSelector->update(true);
27     }
29     function execute()
30     {
31         /* Call parent execute */
32         plugin::execute();
34         /* Log view */
35         if(!$this->view_logged){
36             $this->view_logged = TRUE;
37             new log("view","all/".get_class($this),$this->dn);
38         }
40         // Update baseSelector
41         if (!$this->baseSelector->update()) {
42             msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
43         }
44         if ($this->base != $this->baseSelector->getBase()) {
45             $this->base= $this->baseSelector->getBase();
46             $this->is_modified= TRUE;
47         }
50         // Assign smarty values 
51         $smarty= get_smarty();
52         $smarty->assign("single","");
53         $smarty->assign("base", $this->baseSelector->render());
55         // fill in old vars in the Export form
56         if(isset($_POST['single'])) $smarty->assign("single",$_POST['single']);
58         // Get the LDAP link, to generate the Export
59         $ldap = $this->config->get_ldap_link();
60         $dn = "";
61         if(isset($_POST['sfrmgetsingle']))
62         {  
63             $dn   = $_POST['single'];
64             $scope= "base";
65             $acls = $this->ui->get_permissions($dn,"ldapmanager/ldif");
66             $name = "entryExport.ldif";
67             if(!$ldap->dn_exists($dn)){
68                 msg_dialog::display(_("Ldap error"),
69                         sprintf(_("No such object '%s'!"),bold(LDAP::fix($dn))),
70                         ERROR_DIALOG);
71                 $dn ="";
72             }
74         }elseif(isset($_POST['sfrmgetfull'])){
75             $dn   = $this->base;
76             $scope= "sub";
77             $acls = $this->ui->get_permissions($dn,"ldapmanager/ldif");
78             $name = "fullExport.ldif";
79         }
81         if(!empty($dn)){
82             // Check permissions before sending the output
83             if(!preg_match("/r/",$acls)){
84                 msg_dialog::display(_("Permission error"), 
85                         sprintf(_("You have no permission to export '%s'!"),LDAP::fix($dn)),
86                         ERROR_DIALOG);
87             }else{
88                 $data = $ldap->generateLdif($dn, 'objectClass=*',array(),$scope);
89                 send_binary_content($data,$name);
90             }
91         }
93         // Show the main form
94         return ($smarty->fetch (get_template_path('contentexport.tpl', TRUE)));
95     }
96 }
99 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
100 ?>