Code

remove examples not necessary to make plugin work
[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
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 require_once "../include/php_writeexcel/class.writeexcel_workbook.inc.php";
22 require_once "../include/php_writeexcel/class.writeexcel_worksheet.inc.php";
24 function dump_ldap ($mode= 0)
25 {
26   global $config;
27   $ldap= $config->get_ldap_link();
28   error_reporting (E_ALL & ~E_NOTICE);
30   $display = "";
31   if($mode == 2){       // Single Entry Export !
32     $d =  base64_decode($_GET['d']);
33     $n =  base64_decode($_GET['n']);
34     //  print_r($_GET);
35     $dn=$d.$n;
36     //  echo $dn ;
37     $fname = tempnam("/tmp", "demo.xls");
38     $workbook= new writeexcel_workbook($fname);
40     $title_bold= $workbook->addformat(array(
41           bold    => 1,
42           color   => 'black',
43           size    => 10,
44           font    => 'Helvetica'
45           ));
48     switch ($d){
49       case "ou=people," : 
50         $user=                             $ldap->gen_xls($dn,"(objectClass=*)",array("uid","dateOfBirth","gender","givenName","preferredLanguage"));
51       $intitul=array("Date de naissance:","Sexe:","Nom/prénom","Langue");
53       $worksheet= $workbook->addworksheet('Users');
54       $worksheet->set_column('A:B', 32);
57       $user_nbr=count($user);
58       $r=1;
59       for($i=1;$i<$user_nbr;$i++)
60       {
61         if($i>1)
62           $worksheet->write('A'.$r++,"");
63         $worksheet->write('A'.$r++,"uid : ".$user[$i][0],$title_bold);
64         for($j=1;$j<5;$j++)
65         {
66           $r++;
67           $worksheet->write('A'.$r,$intitul[$j-1]);
68           $worksheet->write('B'.$r,$user[$i][$j]);
69         }
70         $worksheet->write('A'.$r++,"");
71       }
72       break;
74       case "ou=groups,": $groups= $ldap->gen_xls($dn,"(objectClass=*)",array("cn","memberUid"),TRUE,1);
75       $intitul=array("Membres:");
76       $worksheet =& $workbook->addworksheet('Groups');
77       $worksheet->set_column('A:B', 32);
79       //count number of groups
80       $groups_nbr=count($groups);
81       $r=1;
82       for($i=1;$i<$groups_nbr;$i++)
83       {
84         $worksheet->write('A'.$r++,"uid : ".$groups[$i][0][0],$title_bold);
85         for($j=1;$j<=2;$j++)
86         {
87           $r++;
88           $worksheet->write('A'.$r,$intitul[$j-1]);
89           for($k=0;$k<= $groups[$i][$j]['count'];$k++)
90           {
91             $worksheet->write('B'.$r,$groups[$i][$j][$k]);
92             $r++;
93           }
94         }
95       }
96       break;
98       case "ou=computers,": $computers= $ldap->gen_xls($dn,"(objectClass=*)",array("cn","description","uid"));
99       $intitul=array("Description:","Uid:");
100       $worksheet =& $workbook->addworksheet('Computers');
101       $worksheet->set_column('A:B', 32);
103       //count number of computers
104       $computers_nbr=count($computers);
105       $r=1;
106       for($i=1;$i<$computers_nbr;$i++)
107       {
108         if($i>1)
109           $worksheet->write('A'.$r++,"");
110         $worksheet->write('A'.$r++,"cn : ".$computers[$i][0],$title_bold);
111         for($j=1;$j<3;$j++)
112         {
113           $r++;
114           $worksheet->write('A'.$r,$intitul[$j-1]);
115           $worksheet->write('B'.$r,$computers[$i][$j]);
116         }
117         $worksheet->write('A'.$r++,"");
118       }
119       break;
121       case "ou=servers,ou=systems,": $servers= $ldap->gen_xls($dn,"(objectClass=*)",array("cn"));
122       $intitul=array("cn:");
124       $worksheet =& $workbook->addworksheet('Servers');
125       $worksheet->set_column('A:B', 32);
127       //count number of servers
128       $servers_nbr=count($servers);
129       $r=1;
130       $worksheet->write('A'.$r++,"Servers : ",$title_bold);
131       for($i=1;$i<$servers_nbr;$i++)
132       {
133         for($j=0;$j<1;$j++)
134         {
135           $r++;
136           $worksheet->write('A'.$r,$intitul[$j]);
137           $worksheet->write('B'.$r,$servers[$i][$j]);
138         }
139       }
140       break;
142       case "dc=addressbook,": //data about addressbook
143         $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"));
145       $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:");
147       $worksheet =& $workbook->addworksheet('Servers');
148       $worksheet->set_column('A:B', 32);
150       //count number of entries
151       $address_nbr=count($address);
152       $r=1;
153       for($i=1;$i<$address_nbr;$i++)
154       {
155         if($i>1)
156           $worksheet->write('A'.$r++,"");
157         $worksheet->write('A'.$r++,"cn : ".$address[$i][0],$title_bold);
158         for($j=1;$j<19;$j++)
159         {
160           $r++;
161           $worksheet->write('A'.$r,$intitul[$j]);
162           $worksheet->write('B'.$r,$address[$i][$j]);
163         }
164         $worksheet->write('A'.$r++,"");
165       }
167       break;
169       default: echo "error!!";
170     }
172     $workbook->close();
175     // We'll be outputting a xls
176     header('Content-type: application/x-msexcel');
178     // It will be called demo.xls
179     header('Content-Disposition: attachment; filename="demo.xls"');
181     // The PDF source is in original.xl
182     readfile($fname);
184   }
185   elseif($mode == 3){ // Full LDIF Export !
186     $dn =  base64_decode($_GET['dn']);
188     //data about users
189     $user= $ldap->gen_xls("ou=people,".$dn,"(objectClass=*)",array("uid","dateOfBirth","gender","givenName","preferredLanguage"));
190     $user_intitul=array("Date de naissance:","Sexe:","Nom/prénom","Langue");
191     //data about groups
192     $groups= $ldap->gen_xls("ou=groups,".$dn,"(objectClass=*)",array("cn","memberUid"),TRUE,1);
193     $groups_intitul=array("Membres:");
194     //data about computers
195     $computers= $ldap->gen_xls("ou=computers,".$dn,"(objectClass=*)",array("cn","description","uid"));
196     $computers_intitul=array("Description:","Uid:");
197     //data about servers
198     $servers= $ldap->gen_xls("ou=servers,ou=systems,".$dn,"(objectClass=*)",array("cn"));
199     $servers_intitul=array("cn:");
200     //data about addressbook
201     $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"));
202     $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:");
205     $fname = tempnam("/tmp", "demo.xls");
206     $workbook = new writeexcel_workbook($fname);
207     $worksheet = $workbook->addworksheet('Users');
208     $worksheet2 = $workbook->addworksheet('Groups');
209     $worksheet3 = $workbook->addworksheet('Servers');
210     $worksheet4 = $workbook->addworksheet('Computers');
211     $worksheet5 = $workbook->addworksheet('Adressbook');
213     $worksheet->set_column('A:B', 32);
214     $worksheet2->set_column('A:B', 32);
215     $worksheet3->set_column('A:B', 32);
216     $worksheet4->set_column('A:B', 32);
217     $worksheet5->set_column('A:B', 32);
219     $title_bold =& $workbook->addformat(array(
220           bold    => 1,
221           color   => 'black',
222           size    => 10,
223           font    => 'Helvetica'
224           ));
227     //count number of users
228     $user_nbr=count($user);
229     $r=1;
230     for($i=1;$i<$user_nbr;$i++)
231     {
232       if($i>1)
233         $worksheet->write('A'.$r++,"");
234       $worksheet->write('A'.$r++,"uid : ".$user[$i][0],$title_bold);
235       for($j=1;$j<5;$j++)
236       {
237         $r++;
238         $worksheet->write('A'.$r,$user_intitul[$j-1]);
239         $worksheet->write('B'.$r,$user[$i][$j]);
240       }
241       $worksheet->write('A'.$r++,"");
242     }
244     //count number of groups
245     $groups_nbr=count($groups);
246     $r=1;
247     for($i=1;$i<$groups_nbr;$i++)
248     {
249       $worksheet2->write('A'.$r++,"uid : ".$groups[$i][0][0],$title_bold);
250       for($j=1;$j<=2;$j++)
251       {
252         $r++;
253         $worksheet2->write('A'.$r,$group_intitul[$j-1]);
254         for($k=0;$k<= $groups[$i][$j]['count'];$k++)
255         {
256           $worksheet2->write('B'.$r,$groups[$i][$j][$k]);
257           $r++;
258         }
259       }
260     }
262     //count number of servers
263     $servers_nbr=count($servers);
264     $r=1;
265     $worksheet3->write('A'.$r++,"Servers : ",$title_bold);
266     for($i=1;$i<$servers_nbr;$i++)
267     {
268       for($j=0;$j<1;$j++)
269       {
270         $r++;
271         $worksheet3->write('A'.$r,$servers_intitul[$j]);
272         $worksheet3->write('B'.$r,$servers[$i][$j]);
273       }
274     }
276     //count number of computers
277     $computers_nbr=count($computers);
278     $r=1;
279     for($i=1;$i<$computers_nbr;$i++)
280     {
281       if($i>1)
282         $worksheet->write('A'.$r++,"");
283       $worksheet4->write('A'.$r++,"cn : ".$computers[$i][0],$title_bold);
284       for($j=1;$j<3;$j++)
285       {
286         $r++;
287         $worksheet4->write('A'.$r,$computers_intitul[$j-1]);
288         $worksheet4->write('B'.$r,$computers[$i][$j]);
289       }
290       $worksheet4->write('A'.$r++,"");
291     }
293     //count number of entries
294     $address_nbr=count($address);
295     $r=1;
296     for($i=1;$i<$address_nbr;$i++)
297     {
298       if($i>1)
299         $worksheet5->write('A'.$r++,"");
300       $worksheet5->write('A'.$r++,"cn : ".$address[$i][0],$title_bold);
301       for($j=1;$j<19;$j++)
302       {
303         $r++;
304         $worksheet5->write('A'.$r,$address_intitul[$j]);
305         $worksheet5->write('B'.$r,$address[$i][$j]);
306       }
307       $worksheet5->write('A'.$r++,"");
308     }
309     $workbook->close();
312     // We'll be outputting a xls
313     header('Content-type: application/x-msexcel');
315     // It will be called demo.xls
316     header('Content-Disposition: attachment; filename="demo.xls"');
318     // The PDF source is in original.xl
319     readfile($fname);
321   }
322   elseif($mode == 4){ // IVBB LDIF Export
323     $dn =  base64_decode($_GET['dn']);
324     /*$display= $ldap->gen_ldif($dn,"(objectClass=ivbbEntry)",array(
325       "GouvernmentOrganizationalUnit","houseIdentifier","vocation",
326       "ivbbLastDeliveryCollective","gouvernmentOrganizationalPersonLocality",
327       "gouvernmentOrganizationalUnitDescription","gouvernmentOrganizationalUnitSubjectArea",
328       "functionalTitle","role","certificateSerialNumber","userCertificate","publicVisible",
329       "telephoneNumber","seeAlso","description","title","x121Address","registeredAddress",
330       "destinationIndicator","preferredDeliveryMethod","telexNumber","teletexTerminalIdentifier",
331       "telephoneNumber","internationaliSDNNumber","facsimileTelephoneNumber","street",
332       "postOfficeBox","postalCode","postalAddress","physicalDeliveryOfficeName","ou",
333       "st","l","audio","businessCategory","carLicense","departmentNumber","displayName",
334       "employeeNumber","employeeType","givenName","homePhone","homePostalAddress",
335       "initials","jpegPhoto","labeledURI","mail","manager","mobile","o","pager","photo",
336       "roomNumber","secretary","userCertificate","x500uniqueIdentifier","preferredLanguage",
337       "userSMIMECertificate","userPKCS12"));*/
339     echo $display;
340   }
344 /* Basic setup, remove eventually registered sessions */
345 @require_once ("../include/php_setup.inc");
346 @require_once ("functions.inc");
347 error_reporting (E_ALL);
348 session_start ();
350 /* Logged in? Simple security check */
351 if (!isset($_SESSION['ui'])){
352   gosa_log ("Error: getldif.php called without session");
353   header ("Location: ../index.php");
354   exit;
356 $ui= $_SESSION["ui"];
357 $config= $_SESSION['config'];
359 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
360 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
361 header("Cache-Control: no-cache");
362 header("Pragma: no-cache");
363 header("Cache-Control: post-check=0, pre-check=0");
365 header("Content-type: text/plain");
367 /* Check ACL's */
368 $acl= get_permissions ($config->current['BASE'], $ui->subtreeACL);
369 $acl= get_module_permission($acl, "all", $config->current['BASE']);
370 if (chkacl($acl, "all") != ""){
371   header ("Location: ../index.php");
372   exit;
375 switch ($_GET['ivbb']){
376   case 2: dump_ldap (2);
377           break;
379   case 3: dump_ldap (3);
380           break;
382   case 4: dump_ldap (4);
383           break;
385   default:
386           echo "Error in ivbb parameter. Request aborted.";
388 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
389 ?>