Code

8f1262b40bc3c2ddc36f978fbcbb2a5de510d405
[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();
53         $smarty->assign("single","");
54         $smarty->assign("base", $this->baseSelector->render());
56         // fill in old vars in the Export form
57         if(isset($_POST['single'])) $smarty->assign("single",get_post('single'));
59         // Get the LDAP link, to generate the Export
60         $ldap = $this->config->get_ldap_link();
61         $dn = "";
62         if(isset($_POST['sfrmgetsingle']))
63         {  
64             $dn   = get_post('single');
65             $scope= "base";
66             $acls = $this->ui->get_permissions($dn,"ldapmanager/ldif");
67             $name = "entryExport.ldif";
68             if(!$ldap->dn_exists($dn)){
69                 msg_dialog::display(_("LDAP error"),
70                         sprintf(_("No such object %s!"),bold(LDAP::fix($dn))),
71                         ERROR_DIALOG);
72                 $dn ="";
73             }
75         }elseif(isset($_POST['sfrmgetfull'])){
76             $dn   = $this->base;
77             $scope= "sub";
78             $acls = $this->ui->get_permissions($dn,"ldapmanager/ldif");
79             $name = "fullExport.ldif";
80         }
82         if(!empty($dn)){
84             // Check permissions before sending the output
85             if(!preg_match("/r/",$acls)){
86                 msg_dialog::display(_("Permission error"), 
87                         sprintf(_("You have no permission to export %s!"), bold(LDAP::fix($dn))),
88                         ERROR_DIALOG);
89             }else{
90                 $data = $ldap->generateLdif(LDAP::fix($dn), 'objectClass=*',array(),$scope, $limit=0);
91                 if($data === NULL){
92                     msg_dialog::display(_("Error"), 
93                             sprintf(_("Failed to generate ldap export, error was '%s'!"), $ldap->get_error()),
94                             ERROR_DIALOG);
95                 }else{
96                     send_binary_content($data,$name);
97                 }
98             }
99         }
101         // Show the main form
102         return ($smarty->fetch (get_template_path('contentexport.tpl', TRUE)));
103     }
107 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
108 ?>