Code

ca5a02ea0ce7c9b4dae600ed41463110dd92185d
[gosa.git] / plugins / addons / ldapmanager / class_import.inc
1 <?php
3 class ldifimport extends plugin
4 {
5   /* Definitions */
6   var $plHeadline= "LDIF export";
7   var $plDescription= "This does something";
8   var $access= "";
10   /* attribute list for save action */
11   var $attributes= array();
12   var $objectclasses= array();
13   var $ui;
14   var $view_logged = FALSE;
16   function ldifimport ($config, $dn= NULL)
17   {
18     /* Include config object */
19     $this->config= $config;
21     $this->ui = get_userinfo();
22   }
24   function execute()
25   {
26     /* Call parent execute */
27     plugin::execute();
29     /* Log view */
30     if(!$this->view_logged){
31       $this->view_logged = TRUE;
32       new log("view","all/".get_class($this),$this->dn);
33     }
35     /* Set government mode */
36     $smarty= get_smarty();
38     // Get the LDAP link, to generate the Export
39     $ldap = $this->config->get_ldap_link();
41     $smarty->assign("LDIFError",FALSE);
42     $smarty->assign("type",FALSE);
44     /* Get acls */
45     $acl = $this->ui->get_permissions($this->config->current['BASE'],"all/all");
46     
47     /* Import requested check file and acls */
48     if((isset($_FILES['userfile']['name']))&&(isset($_POST['fileup']))){
50       /* Check acls */
51       if(!preg_match("/w/",$acl)){
52         print_red(_("You need full access to all objects, to execute the import command."));
53       }else{
55         $smarty->assign("type","importfile");
56         $handle = NULL;
58         // Check if there is a file submitted
59         if(!$_FILES['userfile']['size'] > 0 )
60         {
61           print_red(_("The specified file is empty."));
62           $smarty->assign("LDIFError",TRUE);  
63         }
65         // Is there a tmp file, which we can use ?
66         elseif(!file_exists($_FILES['userfile']['tmp_name']))  
67         {
68           print_red(_("There is no file uploaded."));
69           $smarty->assign("LDIFError",TRUE);
71         }
73         // Can we open the tmp file, for reading
74         elseif(!$handle = @fopen($_FILES['userfile']['tmp_name'],"r"))
75         {
76           print_red(_("There is no file uploaded."));
77           $smarty->assign("LDIFError",TRUE);  
78         }
79         else
80         {
81           // Everything just fine :)
82           $str = ""; 
84           // Reading content 
85           while(!feof($handle))
86           {
87             $str .= fread($handle,1024);
88           }
89           @fclose($handle);
91           // Should we use Overwrite ?
92           if(!empty($_POST['overwrite'])) $overwrite = true; else $overwrite = false;;
93           if(!empty($_POST['cleanup']))   $cleanup   = true; else $cleanup = false;
95           $ErrorStr="";
96           $check = $ldap->import_complete_ldif($str,$ErrorStr,$overwrite,$cleanup);
98           if($check == INSERT_OK  )
99             $smarty->assign("LDIFError",FALSE);
100           else
101             $smarty->assign("LDIFError",TRUE);
103           switch($check)
104           {
105             case INSERT_OK : break;
106             case ALREADY_EXISTING_ENTRY      : print_red($ErrorStr); break;
107             case UNKNOWN_TOKEN_IN_LDIF_FILE  : print_red($ErrorStr);break;
109             default : print_red(_("Unknown Error"));break;
110           }
111         }
112       }
113     }
114     return ($smarty->fetch (get_template_path('contentimport.tpl', TRUE)));
115   }
119 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
120 ?>