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");
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 msg_dialog::display(_("Permission error"), _("You need full write access to the LDAP tree to import data!"), ERROR_DIALOG);
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 msg_dialog::display(_("Error"), sprintf(_("Cannot read uploaded file: %s"), _("file is empty")), ERROR_DIALOG);
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 msg_dialog::display(_("Error"), sprintf(_("Cannot read uploaded file: %s"), _("file not found")), ERROR_DIALOG);
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 msg_dialog::display(_("Error"), sprintf(_("Cannot read uploaded file: %s"), _("file not readable")), ERROR_DIALOG);
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);
102 }
104 switch($check)
105 {
106 case INSERT_OK:
107 break;
109 case ALREADY_EXISTING_ENTRY:
110 msg_dialog::display(_("LDAP error"), $ErrorStr, ERROR_DIALOG);
111 break;
113 case UNKNOWN_TOKEN_IN_LDIF_FILE:
114 msg_dialog::display(_("LDAP error"), $ErrorStr, ERROR_DIALOG);
115 break;
117 default:
118 msg_dialog::display(_("Internal error"), sprintf(_("Undefined flag '%s'!"), $check), ERROR_DIALOG);
119 break;
120 }
121 }
122 }
123 }
124 return ($smarty->fetch (get_template_path('contentimport.tpl', TRUE)));
125 }
126 }
129 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
130 ?>