Code

b541b5214626dd267644946c0eb613a4c49eba01
[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)){
88             // Check permissions before sending the output
89             if(!preg_match("/r/",$acls)){
90                 msg_dialog::display(_("Permission error"), 
91                         sprintf(_("You have no permission to export %s!"), bold(LDAP::fix($dn))),
92                         ERROR_DIALOG);
93             }else{
95                 // Check permissions before sending the output
96                 if(!preg_match("/r/",$acls)){
97                     msg_dialog::display(_("Permission error"),
98                             sprintf(_("You have no permission to export %s!"), bold(LDAP::fix($dn))),
99                             ERROR_DIALOG);
100                 }else{
101                     $data = $ldap->generateLdif(LDAP::fix($dn), 'objectClass=*',$scope);
102                     if($data === NULL){
103                         msg_dialog::display(_("Error"),
104                                 sprintf(_("Failed to generate ldap export, error was '%s'!"), $ldap->get_error()),
105                                 ERROR_DIALOG);
106                     }else{
107                         send_binary_content($data,$name);
108                     }
109                 }
110             }
111         }
112     
113         // Show the main form
114         return ($smarty->fetch (get_template_path('contentexport.tpl', TRUE)));
115     }
119 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
120 ?>