Code

Updated ldifExport for plugin ldapManager
[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     {
19         $this->initTime = microtime(TRUE);
20         /* Include config object */
21         $this->config= &$config;
22         $this->ui = get_userinfo();
24         $this->baseSelector= new baseSelector($this->config->idepartments, $this->config->current['BASE']);
25         $this->baseSelector->setSubmitButton(false);
26         $this->baseSelector->setHeight(300);
27         $this->baseSelector->update(true);
28         stats::log('plugin', $class = get_class($this), $category = array($this->acl_category),  $action = 'open',
29                 $amount = 1, $duration = (microtime(TRUE) - $this->initTime));
31     }
33     function execute()
34     {
35         /* Call parent execute */
36         plugin::execute();
38         /* Log view */
39         if(!$this->view_logged){
40             $this->view_logged = TRUE;
41             new log("view","all/".get_class($this),$this->dn);
42         }
44         // Update baseSelector
45         if (!$this->baseSelector->update()) {
46             msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
47         }
48         if ($this->base != $this->baseSelector->getBase()) {
49             $this->base= $this->baseSelector->getBase();
50             $this->is_modified= TRUE;
51         }
54         // Assign smarty values 
55         $smarty= get_smarty();
57         $smarty->assign("single","");
58         $smarty->assign("base", $this->baseSelector->render());
60         // fill in old vars in the Export form
61         if(isset($_POST['single'])) $smarty->assign("single",set_post(get_post('single')));
63         // Get the LDAP link, to generate the Export
64         $ldap = $this->config->get_ldap_link();
65         $dn = "";
66         if(isset($_POST['sfrmgetsingle']))
67         {  
68             $dn   = get_post('single');
69             $scope= "base";
70             $acls = $this->ui->get_permissions($dn,"ldapmanager/ldif");
71             $name = "entryExport.ldif";
72             if(!$ldap->dn_exists($dn)){
73                 msg_dialog::display(_("LDAP error"),
74                         sprintf(_("No such object %s!"),bold(LDAP::fix($dn))),
75                         ERROR_DIALOG);
76                 $dn ="";
77             }
79         }elseif(isset($_POST['sfrmgetfull'])){
80             $dn   = $this->base;
81             $scope= "sub";
82             $acls = $this->ui->get_permissions($dn,"ldapmanager/ldif");
83             $name = "fullExport.ldif";
84         }
86         if(!empty($dn)){
87             // Check permissions before sending the output
88             if(!preg_match("/r/",$acls)){
89                 msg_dialog::display(_("Permission error"), 
90                         sprintf(_("You have no permission to export %s!"), bold(LDAP::fix($dn))),
91                         ERROR_DIALOG);
92             }else{
93                 $data = $ldap->generateLdif(LDAP::fix($dn), 'objectClass=*',$scope);
94                 send_binary_content($data,$name);
95             }
96         }
98         // Show the main form
99         return ($smarty->fetch (get_template_path('contentexport.tpl', TRUE)));
100     }
104 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
105 ?>