Code

Additional translation
[gosa.git] / html / getxls.php
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
5    Copyright (C) 2005  Guillaume Delecourt
6    Copyright (C) 2005  Vincent Seynhaeve
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 require_once "../include/php_writeexcel/class.writeexcel_workbook.inc.php";
24 require_once "../include/php_writeexcel/class.writeexcel_worksheet.inc.php";
26 function dump_ldap ($mode= 0)
27 {
28   global $config;
29   $ldap= $config->get_ldap_link();
30   error_reporting (E_ALL & ~E_NOTICE);
32   $display = "";
33   if($mode == 2){       // Single Entry Export !
34     $d =  base64_decode($_GET['d']);
35     $n =  base64_decode($_GET['n']);
36     //  print_r($_GET);
37     $dn=$d.$n;
38     //  echo $dn ;
39     $fname = tempnam("/tmp", "demo.xls");
40     $workbook=& new writeexcel_workbook($fname);
42     $title_bold=& $workbook->addformat(array(
43           bold    => 1,
44           color   => 'black',
45           size    => 10,
46           font    => 'Helvetica'
47           ));
50     switch ($d){
51       case "ou=people," : 
52         $user=                             $ldap->gen_xls($dn,"(objectClass=*)",array("uid","dateOfBirth","gender","givenName","preferredLanguage"));
53       $intitul=array(_("Birthday").":", _("Sexe").":", _("Name")."/"._("Firstname").":",_("Language").":");
55       $worksheet=& $workbook->addworksheet('Users');
56       $worksheet->set_column('A:B', 32);
59       $user_nbr=count($user);
60       $r=1;
61       for($i=1;$i<$user_nbr;$i++)
62       {
63         if($i>1)
64           $worksheet->write('A'.$r++,"");
65         $worksheet->write('A'.$r++,"uid : ".$user[$i][0],$title_bold);
66         for($j=1;$j<5;$j++)
67         {
68           $r++;
69           $worksheet->write('A'.$r,$intitul[$j-1]);
70           $worksheet->write('B'.$r,$user[$i][$j]);
71         }
72         $worksheet->write('A'.$r++,"");
73       }
74       break;
76       case "ou=groups,": $groups= $ldap->gen_xls($dn,"(objectClass=*)",array("cn","memberUid"),TRUE,1);
77       $intitul=array("Membres:");
78       $worksheet =& $workbook->addworksheet('Groups');
79       $worksheet->set_column('A:B', 32);
81       //count number of groups
82       $groups_nbr=count($groups);
83       $r=1;
84       for($i=1;$i<$groups_nbr;$i++)
85       {
86         $worksheet->write('A'.$r++,"uid : ".$groups[$i][0][0],$title_bold);
87         for($j=1;$j<=2;$j++)
88         {
89           $r++;
90           $worksheet->write('A'.$r,$intitul[$j-1]);
91           for($k=0;$k<= $groups[$i][$j]['count'];$k++)
92           {
93             $worksheet->write('B'.$r,$groups[$i][$j][$k]);
94             $r++;
95           }
96         }
97       }
98       break;
100       case "ou=computers,": $computers= $ldap->gen_xls($dn,"(objectClass=*)",array("cn","description","uid"));
101       $intitul=array(_("Description").":",_("User ID").":");
102       $worksheet =& $workbook->addworksheet(_("Computers"));
103       $worksheet->set_column('A:B', 32);
105       //count number of computers
106       $computers_nbr=count($computers);
107       $r=1;
108       for($i=1;$i<$computers_nbr;$i++)
109       {
110         if($i>1)
111           $worksheet->write('A'.$r++,"");
112         $worksheet->write('A'.$r++,"cn : ".$computers[$i][0],$title_bold);
113         for($j=1;$j<3;$j++)
114         {
115           $r++;
116           $worksheet->write('A'.$r,$intitul[$j-1]);
117           $worksheet->write('B'.$r,$computers[$i][$j]);
118         }
119         $worksheet->write('A'.$r++,"");
120       }
121       break;
123       case "ou=servers,ou=systems,": $servers= $ldap->gen_xls($dn,"(objectClass=*)",array("cn"));
124       $intitul=array("cn:");
126       $worksheet =& $workbook->addworksheet(_("Servers"));
127       $worksheet->set_column('A:B', 32);
129       //count number of servers
130       $servers_nbr=count($servers);
131       $r=1;
132       $worksheet->write('A'.$r++,_("Servers").": ",$title_bold);
133       for($i=1;$i<$servers_nbr;$i++)
134       {
135         for($j=0;$j<1;$j++)
136         {
137           $r++;
138           $worksheet->write('A'.$r,$intitul[$j]);
139           $worksheet->write('B'.$r,$servers[$i][$j]);
140         }
141       }
142       break;
144       case "dc=addressbook,": //data about addressbook
145         $address= $ldap->gen_xls($dn,"(objectClass=*)",array("cn","displayName","facsimileTelephoneNumber","givenName","homePhone","homePostalAddress","initials","l","mail","mobile","o","ou","pager","telephoneNumber","postalAddress","postalCode","sn","st","title"));
147       $intitul=array(_("Common name").":",_("Display Name").":",_("Fax").":",_("Name")."/"._("Firstname").":",_("Home phone").":",_("Home postal address").":",_("Initiales).":",_("Location").":",_("Mail address").":",_("Mobile phone").":",_("City").":",_("Postal address").":",_("Pager").":",_("Phone number").":",_("Adress").":",_("Postal code").":",_("Surename").":",_("State").":",_("Function").":");
149       $worksheet =& $workbook->addworksheet(_("Servers"));
150       $worksheet->set_column('A:B', 32);
152       //count number of entries
153       $address_nbr=count($address);
154       $r=1;
155       for($i=1;$i<$address_nbr;$i++)
156       {
157         if($i>1)
158           $worksheet->write('A'.$r++,"");
159         $worksheet->write('A'.$r++,"cn : ".$address[$i][0],$title_bold);
160         for($j=1;$j<19;$j++)
161         {
162           $r++;
163           $worksheet->write('A'.$r,$intitul[$j]);
164           $worksheet->write('B'.$r,$address[$i][$j]);
165         }
166         $worksheet->write('A'.$r++,"");
167       }
169       break;
171       default: echo "error!!";
172     }
174     $workbook->close();
177     // We'll be outputting a xls
178     header('Content-type: application/x-msexcel');
180     // It will be called demo.xls
181     header('Content-Disposition: attachment; filename="demo.xls"');
183     // The source is in original.xls
184     readfile($fname);
185     unlink ($fname);
186   }
187   elseif($mode == 3){ // Full Export !
188     $dn =  base64_decode($_GET['dn']);
190     //data about users
191     $user= $ldap->gen_xls("ou=people,".$dn,"(objectClass=*)",array("uid","dateOfBirth","gender","givenName","preferredLanguage"));
192     $user_intitul=array("Date de naissance:","Sexe:","Nom/prénom","Langue");
193     //data about groups
194     $groups= $ldap->gen_xls("ou=groups,".$dn,"(objectClass=*)",array("cn","memberUid"),TRUE,1);
195     $groups_intitul=array("Membres:");
196     //data about computers
197     $computers= $ldap->gen_xls("ou=computers,".$dn,"(objectClass=*)",array("cn","description","uid"));
198     $computers_intitul=array("Description:","Uid:");
199     //data about servers
200     $servers= $ldap->gen_xls("ou=servers,ou=systems,".$dn,"(objectClass=*)",array("cn"));
201     $servers_intitul=array("cn:");
202     //data about addressbook
203     $address= $ldap->gen_xls("dc=addressbook,".$dn,"(objectClass=*)",array("cn","displayName","facsimileTelephoneNumber","givenName","homePhone","homePostalAddress","initials","l","mail","mobile","o","ou","pager","telephoneNumber","postalAddress","postalCode","sn","st","title"));
204     $address_intitul=array("cn","DisplayName:","Fax:","Nom/prénom:","Numero de telelphone:","Adresse du domicile:","Initiales:","Ville:","Adresse email:","GSM:","Societe:","Poste:","Pager:","Numero de telelphone:","Adresse:","Code postal:","Sn:","Pays:","Fonction:");
207     $fname = tempnam("/tmp", "demo.xls");
208     $workbook =& new writeexcel_workbook($fname);
209     $worksheet =& $workbook->addworksheet('Users');
210     $worksheet2 =& $workbook->addworksheet('Groups');
211     $worksheet3 =& $workbook->addworksheet('Servers');
212     $worksheet4 =& $workbook->addworksheet('Computers');
213     $worksheet5 =& $workbook->addworksheet('Adressbook');
215     $worksheet->set_column('A:B', 32);
216     $worksheet2->set_column('A:B', 32);
217     $worksheet3->set_column('A:B', 32);
218     $worksheet4->set_column('A:B', 32);
219     $worksheet5->set_column('A:B', 32);
221     $title_bold =& $workbook->addformat(array(
222           bold    => 1,
223           color   => 'black',
224           size    => 10,
225           font    => 'Helvetica'
226           ));
229     //count number of users
230     $user_nbr=count($user);
231     $r=1;
232     for($i=1;$i<$user_nbr;$i++)
233     {
234       if($i>1)
235         $worksheet->write('A'.$r++,"");
236       $worksheet->write('A'.$r++,"uid : ".$user[$i][0],$title_bold);
237       for($j=1;$j<5;$j++)
238       {
239         $r++;
240         $worksheet->write('A'.$r,$user_intitul[$j-1]);
241         $worksheet->write('B'.$r,$user[$i][$j]);
242       }
243       $worksheet->write('A'.$r++,"");
244     }
246     //count number of groups
247     $groups_nbr=count($groups);
248     $r=1;
249     for($i=1;$i<$groups_nbr;$i++)
250     {
251       $worksheet2->write('A'.$r++,"uid : ".$groups[$i][0][0],$title_bold);
252       for($j=1;$j<=2;$j++)
253       {
254         $r++;
255         $worksheet2->write('A'.$r,$group_intitul[$j-1]);
256         for($k=0;$k<= $groups[$i][$j]['count'];$k++)
257         {
258           $worksheet2->write('B'.$r,$groups[$i][$j][$k]);
259           $r++;
260         }
261       }
262     }
264     //count number of servers
265     $servers_nbr=count($servers);
266     $r=1;
267     $worksheet3->write('A'.$r++,"Servers : ",$title_bold);
268     for($i=1;$i<$servers_nbr;$i++)
269     {
270       for($j=0;$j<1;$j++)
271       {
272         $r++;
273         $worksheet3->write('A'.$r,$servers_intitul[$j]);
274         $worksheet3->write('B'.$r,$servers[$i][$j]);
275       }
276     }
278     //count number of computers
279     $computers_nbr=count($computers);
280     $r=1;
281     for($i=1;$i<$computers_nbr;$i++)
282     {
283       if($i>1)
284         $worksheet->write('A'.$r++,"");
285       $worksheet4->write('A'.$r++,"cn : ".$computers[$i][0],$title_bold);
286       for($j=1;$j<3;$j++)
287       {
288         $r++;
289         $worksheet4->write('A'.$r,$computers_intitul[$j-1]);
290         $worksheet4->write('B'.$r,$computers[$i][$j]);
291       }
292       $worksheet4->write('A'.$r++,"");
293     }
295     //count number of entries
296     $address_nbr=count($address);
297     $r=1;
298     for($i=1;$i<$address_nbr;$i++)
299     {
300       if($i>1)
301         $worksheet5->write('A'.$r++,"");
302       $worksheet5->write('A'.$r++,"cn : ".$address[$i][0],$title_bold);
303       for($j=1;$j<19;$j++)
304       {
305         $r++;
306         $worksheet5->write('A'.$r,$address_intitul[$j]);
307         $worksheet5->write('B'.$r,$address[$i][$j]);
308       }
309       $worksheet5->write('A'.$r++,"");
310     }
311     $workbook->close();
314     // We'll be outputting a xls
315     header('Content-type: application/x-msexcel');
317     // It will be called demo.xls
318     header('Content-Disposition: attachment; filename="demo.xls"');
320     // The PDF source is in original.xl
321     readfile($fname);
323     unlink ($fname);
324   }
325   elseif($mode == 4){ // IVBB LDIF Export
326     $dn =  base64_decode($_GET['dn']);
327     /*$display= $ldap->gen_ldif($dn,"(objectClass=ivbbEntry)",array(
328       "GouvernmentOrganizationalUnit","houseIdentifier","vocation",
329       "ivbbLastDeliveryCollective","gouvernmentOrganizationalPersonLocality",
330       "gouvernmentOrganizationalUnitDescription","gouvernmentOrganizationalUnitSubjectArea",
331       "functionalTitle","role","certificateSerialNumber","userCertificate","publicVisible",
332       "telephoneNumber","seeAlso","description","title","x121Address","registeredAddress",
333       "destinationIndicator","preferredDeliveryMethod","telexNumber","teletexTerminalIdentifier",
334       "telephoneNumber","internationaliSDNNumber","facsimileTelephoneNumber","street",
335       "postOfficeBox","postalCode","postalAddress","physicalDeliveryOfficeName","ou",
336       "st","l","audio","businessCategory","carLicense","departmentNumber","displayName",
337       "employeeNumber","employeeType","givenName","homePhone","homePostalAddress",
338       "initials","jpegPhoto","labeledURI","mail","manager","mobile","o","pager","photo",
339       "roomNumber","secretary","userCertificate","x500uniqueIdentifier","preferredLanguage",
340       "userSMIMECertificate","userPKCS12"));*/
342     echo $display;
343   }
347 /* Basic setup, remove eventually registered sessions */
348 @require_once ("../include/php_setup.inc");
349 @require_once ("functions.inc");
350 error_reporting (E_ALL);
351 session_start ();
353 /* Logged in? Simple security check */
354 if (!isset($_SESSION['ui'])){
355   gosa_log ("Error: getldif.php called without session");
356   header ("Location: ../index.php");
357   exit;
359 $ui= $_SESSION["ui"];
360 $config= $_SESSION['config'];
362 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
363 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
364 header("Cache-Control: no-cache");
365 header("Pragma: no-cache");
366 header("Cache-Control: post-check=0, pre-check=0");
368 header("Content-type: text/plain");
370 /* Check ACL's */
371 $acl= get_permissions ($config->current['BASE'], $ui->subtreeACL);
372 $acl= get_module_permission($acl, "all", $config->current['BASE']);
373 if (chkacl($acl, "all") != ""){
374   header ("Location: ../index.php");
375   exit;
378 switch ($_GET['ivbb']){
379   case 2: dump_ldap (2);
380           break;
382   case 3: dump_ldap (3);
383           break;
385   case 4: dump_ldap (4);
386           break;
388   default:
389           echo "Error in ivbb parameter. Request aborted.";
391 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
392 ?>