Code

system main page is now, w3c conform
[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     /* Set government mode */
28     $smarty= get_smarty();
30     // Get the LDAP link, to generate the Export
31     $ldap = $this->config->get_ldap_link();
33     $smarty->assign("LDIFError",FALSE);
34     $smarty->assign("type",FALSE);
36     /* Check permissions for export */
37     if ($this->access != '#all#'){
38       print_red(_("You've no permission to do LDAP imports."));
39     } else { 
40       if((isset($_FILES['userfile']['name']))&&(isset($_POST['fileup'])))
41       {
44         $smarty->assign("type","importfile");
47         // Check if there is a file submitted
49         if(!$_FILES['userfile']['size'] > 0 )
50         {
51           print_red(_("The specified file is empty."));
52           $smarty->assign("LDIFError",TRUE);  
53         }
55         // Is there a tmp file, which we can use ?
56         elseif(!file_exists($_FILES['userfile']['tmp_name']))  
57         {
58           print_red(_("There is no file uploaded."));
59           $smarty->assign("LDIFError",TRUE);
61         }
63         // Can we open the tmp file, for reading
64         elseif(!$handle = @fopen($_FILES['userfile']['tmp_name'],"r"))
65         {
66           print_red(_("There is no file uploaded."));
67           $smarty->assign("LDIFError",TRUE);  
68         }
69         else
70         {
71           // Everything just fine :)
72           $str = ""; 
74           // Reading content 
75           while(!feof($handle))
76           {
77             $str .= fread($handle,1024);
78           }
79           @fclose($handle);
81           // Try to Import the Data
85           // Should we use Overwrite ?
86           if(!empty($_POST['overwrite'])) $overwrite = true; else $overwrite = false;;
87           if(!empty($_POST['cleanup']))   $cleanup   = true; else $cleanup = false;
89           //
91           $check = $ldap->import_complete_ldif($str,$ErrorStr,$overwrite,$cleanup);
93           if($check == INSERT_OK  )
94             $smarty->assign("LDIFError",FALSE);
95           else
96             $smarty->assign("LDIFError",TRUE);
98           switch($check)
99           {
100             case INSERT_OK : break;
101             case ALREADY_EXISTING_ENTRY      : print_red($ErrorStr); break;
102             case UNKNOWN_TOKEN_IN_LDIF_FILE  : print_red($ErrorStr);break;
104             default : print_red(_("Unknown Error"));break;
105           }
106         }
107       }
108     }
109     return ($smarty->fetch (get_template_path('contentimport.tpl', TRUE)));
110     
111   }
116 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
117 ?>