Code

Added empty lines
[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();
14   function ldifimport ($config, $dn= NULL)
15   {
16     /* Include config object */
17     $this->config= $config;
19     $ui= get_userinfo();
20     $acl= get_permissions ($config->current['BASE'], $ui->subtreeACL);
21     $acl= get_module_permission($acl, "ldifimport", $config->current['BASE']);
22     $this->access= $acl;
23   }
25   function execute()
26   {
27         /* Call parent execute */
28         plugin::execute();
30     /* Set government mode */
31     $smarty= get_smarty();
33     // Get the LDAP link, to generate the Export
34     $ldap = $this->config->get_ldap_link();
36     $smarty->assign("LDIFError",FALSE);
37     $smarty->assign("type",FALSE);
39     /* Check permissions for export */
40     if ($this->access != '#all#'){
41       print_red(_("You've no permission to do LDAP imports."));
42     } else { 
43       if((isset($_FILES['userfile']['name']))&&(isset($_POST['fileup'])))
44       {
47         $smarty->assign("type","importfile");
48                         
49                 $handle = NULL;
51         // Check if there is a file submitted
53         if(!$_FILES['userfile']['size'] > 0 )
54         {
55           print_red(_("The specified file is empty."));
56           $smarty->assign("LDIFError",TRUE);  
57         }
59         // Is there a tmp file, which we can use ?
60         elseif(!file_exists($_FILES['userfile']['tmp_name']))  
61         {
62           print_red(_("There is no file uploaded."));
63           $smarty->assign("LDIFError",TRUE);
65         }
67         // Can we open the tmp file, for reading
68         elseif(!$handle = @fopen($_FILES['userfile']['tmp_name'],"r"))
69         {
70           print_red(_("There is no file uploaded."));
71           $smarty->assign("LDIFError",TRUE);  
72         }
73         else
74         {
75           // Everything just fine :)
76           $str = ""; 
78           // Reading content 
79           while(!feof($handle))
80           {
81             $str .= fread($handle,1024);
82           }
83           @fclose($handle);
85           // Try to Import the Data
89           // Should we use Overwrite ?
90           if(!empty($_POST['overwrite'])) $overwrite = true; else $overwrite = false;;
91           if(!empty($_POST['cleanup']))   $cleanup   = true; else $cleanup = false;
93           //
94                   $ErrorStr="";
95           $check = $ldap->import_complete_ldif($str,$ErrorStr,$overwrite,$cleanup);
97           if($check == INSERT_OK  )
98             $smarty->assign("LDIFError",FALSE);
99           else
100             $smarty->assign("LDIFError",TRUE);
102           switch($check)
103           {
104             case INSERT_OK : break;
105             case ALREADY_EXISTING_ENTRY      : print_red($ErrorStr); break;
106             case UNKNOWN_TOKEN_IN_LDIF_FILE  : print_red($ErrorStr);break;
108             default : print_red(_("Unknown Error"));break;
109           }
110         }
111       }
112     }
113     return ($smarty->fetch (get_template_path('contentimport.tpl', TRUE)));
114     
115   }
120 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
121 ?>