Code

Added remove multiple entries to macro list
[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;
15   function ldifimport ($config, $dn= NULL)
16   {
17     /* Include config object */
18     $this->config= $config;
20     $this->ui = get_userinfo();
21   }
23   function execute()
24   {
25     /* Call parent execute */
26     plugin::execute();
28     /* Set government mode */
29     $smarty= get_smarty();
31     // Get the LDAP link, to generate the Export
32     $ldap = $this->config->get_ldap_link();
34     $smarty->assign("LDIFError",FALSE);
35     $smarty->assign("type",FALSE);
37     /* Get acls */
38     $acl = $this->ui->get_permissions($this->config->current['BASE'],"all/all");
39     
40     /* Import requested check file and acls */
41     if((isset($_FILES['userfile']['name']))&&(isset($_POST['fileup']))){
43       /* Check acls */
44       if(!preg_match("/w/",$acl)){
45         print_red(_("You need full access to all objects, to execute the import command."));
46       }else{
48         $smarty->assign("type","importfile");
49         $handle = NULL;
51         // Check if there is a file submitted
52         if(!$_FILES['userfile']['size'] > 0 )
53         {
54           print_red(_("The specified file is empty."));
55           $smarty->assign("LDIFError",TRUE);  
56         }
58         // Is there a tmp file, which we can use ?
59         elseif(!file_exists($_FILES['userfile']['tmp_name']))  
60         {
61           print_red(_("There is no file uploaded."));
62           $smarty->assign("LDIFError",TRUE);
64         }
66         // Can we open the tmp file, for reading
67         elseif(!$handle = @fopen($_FILES['userfile']['tmp_name'],"r"))
68         {
69           print_red(_("There is no file uploaded."));
70           $smarty->assign("LDIFError",TRUE);  
71         }
72         else
73         {
74           // Everything just fine :)
75           $str = ""; 
77           // Reading content 
78           while(!feof($handle))
79           {
80             $str .= fread($handle,1024);
81           }
82           @fclose($handle);
84           // Should we use Overwrite ?
85           if(!empty($_POST['overwrite'])) $overwrite = true; else $overwrite = false;;
86           if(!empty($_POST['cleanup']))   $cleanup   = true; else $cleanup = false;
88           $ErrorStr="";
89           $check = $ldap->import_complete_ldif($str,$ErrorStr,$overwrite,$cleanup);
91           if($check == INSERT_OK  )
92             $smarty->assign("LDIFError",FALSE);
93           else
94             $smarty->assign("LDIFError",TRUE);
96           switch($check)
97           {
98             case INSERT_OK : break;
99             case ALREADY_EXISTING_ENTRY      : print_red($ErrorStr); break;
100             case UNKNOWN_TOKEN_IN_LDIF_FILE  : print_red($ErrorStr);break;
102             default : print_red(_("Unknown Error"));break;
103           }
104         }
105       }
106     }
107     return ($smarty->fetch (get_template_path('contentimport.tpl', TRUE)));
108   }
112 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
113 ?>