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");
46 $handle = NULL;
48 // Check if there is a file submitted
50 if(!$_FILES['userfile']['size'] > 0 )
51 {
52 print_red(_("The specified file is empty."));
53 $smarty->assign("LDIFError",TRUE);
54 }
56 // Is there a tmp file, which we can use ?
57 elseif(!file_exists($_FILES['userfile']['tmp_name']))
58 {
59 print_red(_("There is no file uploaded."));
60 $smarty->assign("LDIFError",TRUE);
62 }
64 // Can we open the tmp file, for reading
65 elseif(!$handle = @fopen($_FILES['userfile']['tmp_name'],"r"))
66 {
67 print_red(_("There is no file uploaded."));
68 $smarty->assign("LDIFError",TRUE);
69 }
70 else
71 {
72 // Everything just fine :)
73 $str = "";
75 // Reading content
76 while(!feof($handle))
77 {
78 $str .= fread($handle,1024);
79 }
80 @fclose($handle);
82 // Try to Import the Data
86 // Should we use Overwrite ?
87 if(!empty($_POST['overwrite'])) $overwrite = true; else $overwrite = false;;
88 if(!empty($_POST['cleanup'])) $cleanup = true; else $cleanup = false;
90 //
91 $ErrorStr="";
92 $check = $ldap->import_complete_ldif($str,$ErrorStr,$overwrite,$cleanup);
94 if($check == INSERT_OK )
95 $smarty->assign("LDIFError",FALSE);
96 else
97 $smarty->assign("LDIFError",TRUE);
99 switch($check)
100 {
101 case INSERT_OK : break;
102 case ALREADY_EXISTING_ENTRY : print_red($ErrorStr); break;
103 case UNKNOWN_TOKEN_IN_LDIF_FILE : print_red($ErrorStr);break;
105 default : print_red(_("Unknown Error"));break;
106 }
107 }
108 }
109 }
110 return ($smarty->fetch (get_template_path('contentimport.tpl', TRUE)));
112 }
114 }
117 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
118 ?>