Hey,
Voor een klant is er een heel script gemaakt voor hun gegevens. Dit werkt prima, maar er zit 1 klein foutje in.
Je klikt eerst op de klantnaam, daarna krijg je een overzicht met organisaties en hun telefoonnummer in...Dit wordt netjes alfabetisch gesorteerd op organisatie.
Daarna klik je door op organisatie en dan krijg je een overzicht van alle mensen (Personen genaamd in het script) die daar werken + telefoonnummer.
Nou zit de fout in het sorteren. Ipv de sortering op naam, worden de telefoonnummers gesorteerd.
Hieronder volgt het hele php script waar volgens ons de fout in moet zitten...Is er hier iemand die de fout erin kan ontdekken??
Many thanks alvast!
Voor een klant is er een heel script gemaakt voor hun gegevens. Dit werkt prima, maar er zit 1 klein foutje in.
Je klikt eerst op de klantnaam, daarna krijg je een overzicht met organisaties en hun telefoonnummer in...Dit wordt netjes alfabetisch gesorteerd op organisatie.
Daarna klik je door op organisatie en dan krijg je een overzicht van alle mensen (Personen genaamd in het script) die daar werken + telefoonnummer.
Nou zit de fout in het sorteren. Ipv de sortering op naam, worden de telefoonnummers gesorteerd.
Hieronder volgt het hele php script waar volgens ons de fout in moet zitten...Is er hier iemand die de fout erin kan ontdekken??
Many thanks alvast!
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
| <?php
// A small function to use with usort that will sort without case sensitivity
function CaseFreeSort ($a, $b)
{
//echo $a . ':' . $b . '<br>';
return strcmp (strtoupper ($a), strtoupper($b) );
}
function GetData ( $TitleSearch, & $Search, $PrintTitle, $Zoek )
{
include ( 'Constants.php' );
$arrDept=array();
// Create a flag to check on no matches field.
$Matches = 0;
// Connect to server
if ( !($Connection = ldap_connect($LdapServer, $LdapPort)) )
{
return 1;
}
// We'll need to add account details here
//ldap_bind($Connection, $BaseDN, $LdapPassword );
ldap_bind($Connection, $LdapRDN, $LdapPassword );
// 1. A blanket search of the department.
if ( $Search['Personen'] == '' )
{
// Get the Title - here it's the Gemeente
//+++
//+++ $Result = ldap_read($Connection, $Search ['DN'], $TitleSearch);
//+++ ldap_sort ( $Connection, $Result, "ou" );
//+++ $Info = ldap_get_entries($Connection, $Result);
// Strip the Title field name out of the DN string
if ( strpos ( $Search['DN'], ',' ) )
{
$Title = trim ( substr ( $Search['DN'],
strpos ( $Search['DN'], '=' ) + 1,
strpos ( $Search['DN'], ',' ) -
strpos ( $Search['DN'], '=' ) - 1 ) );
}
else
{
$Title = trim ( substr ( $Search['DN'],
strpos ( $Search['DN'], '=' ) + 1 ) );
}
// Print up a quick list of where we are
PrintTree ( $Search );
PrintTitle ( $Title, $PrintTitle, $Search ['DN'] );
/ldap_sort
...skipping
$SearchString, $DepartmentAttributes);
//++ ldap_sort ( $Connection, $Result, "ou" );
//+++ $Info = ldap_get_entries($Connection, $Result);
$Inf = ldap_get_entries($Connection, $Result);
$Info = multidimsort ( $Inf );
// if ( $Info['count'] > 1 )
if ( count ($Info) >= 1 )
{
// Display the department
// Now we're using ldap_search, we need to make sure
// that the department itself is not displayed when
// there are subdepartments. The trivial single
// entry returned is caught by info ( count ) > 1,
// rather than 0. The rest need testing before printing
$Totaal_Row=array();
TableStart ( 'align="center" border="0" width="70%" cellspacing="2" cellpadding="4"' );
Table2Head ( 'Organisaties', 'Telefoonnummer' );
// for ($i=0; $i<$Info['count']; $i++)
for ($i=0; $i<count ($Info); $i++)
{
//if ( $SaveDN != $Info[$i]['dn'] )
if ( $SaveDN != $Info[$i][1] )
{
//$Search ['Organisatie'] = $Info[$i]['ou'][0];
//$Search ['DN'] = $Info[$i]['dn'];
$Search ['Organisatie'] = $Info[$i][0];
$Search ['DN'] = $Info[$i][1];
//echo $Info[$i]['dn'] . '<br>';
$Department = '';
//$arrDept = ldap_explode_dn ( $Info [$i]['dn'], 1 );
$arrDept = ldap_explode_dn ( $Info [$i][1], 1 );
for ( $LC = $arrDept ['count'] - 2; $LC > 0; $LC-- )
{
$Department .= $arrDept [$LC] . '/';
}
$Department .= $arrDept [0];
//echo $Department . '<br>';
// Table2Row ( $Info[$i]['ou'][0],
/* Table2Row ( $Department,
// $Info[$i]['telephonenumber'][0],
$Info[$i][2],
$Search);*/
array_push($Totaal_Row,ReturnVal_Table2Row ( $Department,$Info[$i][2],$Search));
}
}
Draw_Rows($Totaal_Row);
TableEnd ();
}
}
else
{
$Result = ldap_list($Connection, $Search ['DN'], $SearchString);
//++ ldap_sort ( $Connection, $Result, "ou" );
//+++ $Info = ldap_get_entries($Connection, $Result);
//+++ usort ( $Info, "CaseFreeSort" );
$Inf = ldap_get_entries($Connection, $Result);
$Info = multidimsort ( $Inf );
// if ( $Info['count'] > 0 )
if ( count ($Info) >= 1 )
{
// Display the department
$Totaal_Row=array();
TableStart ( 'align="center" border="0" width="70%" cellspacing="2" cellpadding="4"' );
Table2Head ( 'Organisaties', 'Telefoonnummer' );
// for ($i=0; $i<$Info['count']; $i++)
for ($i=0; $i<count ($Info); $i++)
{
// $Search ['Organisatie'] = $Info[$i]['ou'][0];
// $Search ['DN'] = $Info[$i]['dn'];
// Table2Row ( $Info[$i]['ou'][0],
// $Info[$i]['telephonenumber'][0],
$Search ['Organisatie'] = $Info[$i][0];
$Search ['DN'] = $Info[$i][1];
/*Table2Row ( $Info[$i][0],
$Info[$i][2],
$Search);*/
array_push($Totaal_Row,ReturnVal_Table2Row ( $Info[$i][0], $Info[$i][2],$Search));
}
Draw_Rows($Totaal_Row);
TableEnd ();
}
}
// Now we want to build a table of people in this ou
// restore the DN to the parent from the child
$Search ['DN'] = $SaveDN;
// Use the search criteria passed if it exists
$SearchString = '(objectClass=person)';
if ( $SaveFilter != '' )
{
$SearchString = '(&' . $SearchString . '(ou=*' .
$SaveFilter . '*))';
}
//===
$Result = ldap_list($Connection, $Search['DN'], $SearchString,
$DepartmentAttributes);
// $Info = ldap_get_entries($Connection, $Result);
// if ( $Info['count'] > 0 )
$Inf = ldap_get_entries($Connection, $Result);
$Info = multidimsort2 ( $Inf );
if ( count ($Info) >= 1 )
{
// Display the People
Br();
TableStart ( 'align="center" border="0" width="70%" cellspacing="2" cellpadding="4"' );
Table2Head ( 'Personen', 'Telefoonnummer' );
// for ($i=0; $i<$Info['count']; $i++)
// {
// $Search ['Organisatie'] = $Info[$i]['ou'][0];
// $Search ['DN'] = $Info[$i]['dn'];
// Table2RowPerson ( $Info[$i]['cn'][0],
// $Info[$i]['telephonenumber'][0],
// $Search);
$Totaal_Row=array();
for ($i=0; $i<count ($Info); $i++)
{
$Search ['Organisatie'] = $Info[$i][0];
$Search ['DN'] = $Info[$i][1];
array_push($Totaal_Row,ReturnVal_Table2RowPerson ( $Info[$i][2],
$Info[$i][3],
$Search));
}
Draw_Rows($Totaal_Row);
TableEnd ();
}
}
//OK we're doing a more detailed search here, looking for
//actual people.
else
{
// First off, lets build up the search criteria.
$SearchString = '(&(objectclass=person)(cn=*' .
$Search['Personen'] . '*))';
// $Search['Personen'] . '*)';
// if ( $Search ['Organisatie'] != '' )
// {
// $SearchString .= '(ou=*' . $Search ['Organisatie'] .
// '*))';
// }
// else
// {
// $SearchString .= ')';
// }
//echo $Search ['DN'] . ':' . $SearchString;
// If it's a really short personen field, warn user that this
// is a silly idea, and the results may be incomplete
if ( strlen ($Search ['Personen']) < 3 )
{
SendWarning ( $SearchTooBroad );
}
// Set the error reporting off
$OldLevel = error_reporting ( 1 );
$Result = ldap_search($Connection, $Search ['DN'],
$SearchString, $PersonalAttributes, 0, 0, 0);
$Info = ldap_get_entries($Connection, $Result);
error_reporting ( $OldLevel );
// Strip the Title field name out of the Title search string
$TitleField = trim ( substr ( $SearchString,
strpos ( $TitleSearch, '(' ) + 1,
strpos ( $TitleSearch, '=' ) - 1 ) );
$Title = $Info[0][$TitleField][0];
// Print up a quick list of where we are
PrintRoot ( $Search );
//PrintTitle ( $Title );
// Save the organisational filter for later use
$SaveFilter=$Search['Organisatie'];
if ( $Info ['count'] <= 0 )
{
SendWarning ( $NoMatchesFound );
}
else
{
$HeadingPrinted = 0;
$Totaal_Row=array();
for ($i=0; $i<$Info['count']; $i++)
{
$Department = '';
//echo '<br>' . $Info [$i]['dn'];
$arrDept = ldap_explode_dn ( $Info [$i]['dn'], 1 );
for ( $LC = $arrDept ['count'] - 2; $LC > 1; $LC-- )
{
$Department .= $arrDept [$LC] . '/';
}
$Department .= $arrDept [1];
$Search ['DN'] = $Info [$i]['dn'];
if ( $Search ['Organisatie'] != '' )
{
if (strstr ( strtoupper ($Search['DN']),
strtoupper ($Search ['Organisatie'])))
{
if ( $HeadingPrinted == 0)
{
// First we want to build a table of departments
TableStart ( 'align="center" border="0" width="70%" cellspacing="2" cellpadding="4"' );
Table3Head ( 'Naam', 'Telefoonnummer', 'Organisatie' );
$SaveDN = $Search ['DN'];
$HeadingPrinted = 1;
}
array_push($Totaal_Row,ReturnVal_Table3Row ( $Info[$i]['cn'][0],
$Info[$i]['telephonenumber'][0],
$Department,
$Search ));
}
}
else
{
if ( $HeadingPrinted == 0)
{
// First we want to build a table of departments
TableStart ( 'align="center" border="0" width="70%" cellspacing="2" cellpadding="4"' );
Table3Head ( 'Naam', 'Telefoonnummer', 'Organisatie' );
$SaveDN = $Search ['DN'];
$HeadingPrinted = 1;
}
array_push($Totaal_Row,ReturnVal_Table3Row ( $Info[$i]['cn'][0],
$Info[$i]['telephonenumber'][0],
$Department,
$Search ));
}
}
}
Draw_Rows($Totaal_Row);
if ( $HeadingPrinted == 0)
{
SendWarning ( $NoMatchesFound );
}
else
{
TableEnd ();
}
}
ldap_close($Connection);
}
function GetPerson ( $DN, $Search )
{
include ( 'Constants.php' );
// Connect to server
if ( !($Connection = ldap_connect($LdapServer, $LdapPort)) )
{
return 1;
}
// We'll need to add account details here
ldap_bind($Connection, $LdapRDN, $LdapPassword );
// Print up a quick list of where we are
$Search ['DN'] = $DN;
PrintTree ( $Search );
//echo 'Looking for : ' . $Search ['Personen' ] . '<br>';
PrintTitle ( $Search ['Personen'], 1, $DN );
// This gets a bit messy. Some calls include the cn, and some don't
// fix it so that all use the cn.
if ( mb_substr ( trim ($DN), 0, 2) == 'cn' )
{
$LocalDN = trim ($DN);
}
else
{
$LocalDN = 'cn=' . $Search['Personen'] . ',' . $DN;
}
error_reporting ( E_ALL );
$SearchString = '(cn=' . $Search['Personen'] . ')';
$Result = ldap_read($Connection, $LocalDN, $SearchString );
//$Result = ldap_read($Connection, $LocalDN, $SearchString,
//$PersonalAttributes);
$Info = ldap_get_entries($Connection, $Result);
if ( $Info['count'] > 0 )
{
TableStart ( 'align="center" border="0" width="70%" cellspacing="2" cellpadding="4"' );
if ( $Info[0]['cn'][0] != '' )
{
Table2RowDept ( 'Naam', $Info[0]['cn'][0]);
}
if ( isset ($Info[0]['mail'][0]) )
{
Table2RowDept ( 'E-mail adres', $Info[0]['mail'][0]);
}
if ( isset ($Info[0]['givenname'][0]) )
{
Table2RowDept ( 'Voornaam', $Info[0]['givenname'][0]);
}
if ( isset ($Info[0]['title'][0]) )
{
Table2RowDept ( 'Titel', $Info[0]['title'][0]);
}
if ( isset ($Info[0]['description'][0]) )
{
Table2RowDept ( 'Functie', $Info[0]['description'][0]);
}
if ( isset ($Info[0]['roomnumber'][0]) )
{
Table2RowDept ( 'Kamernummer', $Info[0]['roomnumber'][0]);
}
if ( isset ($Info[0]['telephonenumber'][0]) )
{
Table2RowDept ( 'Telefoonnummer', $Info[0]['telephonenumber'][0]);
}
if ( isset ($Info[0]['mobile'][0]) )
{
Table2RowDept ( 'Mobiel', $Info[0]['mobile'][0]);
}
if ( isset ($Info[0]['facsimiletelephonenumber'][0]) )
{
Table2RowDept ( 'Faxnummer', $Info[0]['facsimiletelephonenumber'][0]);
}
//$Address = isset ($Info[0]['street'][0] . ' ' .
//$Info[0]['roomnumber'][0] . ', ' .
$Address = '';
if ( isset ($Info[0]['street'][0]) )
{
$Address .= $Info[0]['street'][0] . ', ';
}
if ( isset ($Info[0]['postalcode'][0]) )
{
$Address .= $Info[0]['postalcode'][0] . ' ';
}
if ( isset ($Info[0]['l'][0]) )
{
$Address .= $Info[0]['l'][0];
}
//if ( $Address != ' , Rotterdam' && $Address != ' , ' )
//if ( $Address != ' Rotterdam' && $Address != ' ' )
if ( $Address != 'Rotterdam' && $Address != '' )
{
Table2RowDept ( 'Adres', $Address);
}
if ( isset ($Info[0]['postaladdress'][0]) )
{
Table2RowDept ( 'Postadres', $Info[0]['postaladdress'][0]);
}
if ( isset ($Info[0]['businesscategory'][0]) )
{
Table2RowDept ( 'Dienst', $Info[0]['businesscategory'][0]);
}
if ( isset ($Info[0]['homephone'][0]) )
{
Table2RowDept ( 'Telefoonnummer prive', $Info[0]['homephone'][0]);
}
if ( isset ($Info[0]['homepostaladdress'][0]) )
{
Table2RowDept ( 'Adres prive', $Info[0]['homepostaladdress'][0]);
}
if ( isset ($Info[0]['postofficebox'][0]) )
{
Table2RowDept ( 'Postofficebox', $Info[0]['postofficebox'][0]);
}
if ( isset ($Info[0]['employeenumber'][0]) )
{
Table2RowDept ( 'User ID', $Info[0]['employeenumber'][0]);
}
TableEnd ();
}
else
{
echo "No data found";
}
ldap_close($Connection);
}
function GetDepartment ( $DN )
{
include ( 'Constants.php' );
$PrintResults = array ();
// Connect to server
if ( !($Connection = ldap_connect($LdapServer, $LdapPort)) )
{
return 1;
}
// We'll need to add account details here
ldap_bind($Connection, $LdapRDN, $LdapPassword );
$SearchString = 'objectClass=organizationalunit';
//$SearchString = '(objectClass=*)';
// Search the base entry only for details.
$Result = ldap_read($Connection, $DN, $SearchString);
if ( ($Info = ldap_get_entries($Connection, $Result) ) )
{
// Initialise a few variables
$PrintResults ['mail'] = '';
$PrintResults ['address'] = '';
$PrintResults ['postaladdress'] = '';
$PrintResults ['telephone'] = '';
$PrintResults ['fax'] = '';
$PrintResults ['description'] = '';
TableStart ( 'align="center" border="0" width="70%" cellspacing="2" cellpadding="4"' );
for ( $Count = 0; $Count < $Info[0]['count']; $Count++ )
{
if ( $Info[0][$Count] == 'description' )
{
$PrintResults ['description'] =
$Info[0][$Info[0][$Count]][0];
}
elseif ( $Info[0][$Count] == 'street' )
{
$PrintResults ['address'] =
$Info[0][$Info[0][$Count]][0] . ', ';
}
elseif ( $Info[0][$Count] == 'postalcode' )
{
$PrintResults ['address'] .=
$Info[0][$Info[0][$Count]][0] . ' ';
}
elseif ( $Info[0][$Count] == 'l' )
{
$PrintResults ['address'] .=
$Info[0][$Info[0][$Count]][0];
}
elseif ( $Info[0][$Count] == 'postaladdress' )
{
$PrintResults ['postaladdress'] =
$Info[0][$Info[0][$Count]][0];
}
elseif ( $Info[0][$Count] == 'telephonenumber' )
{
$PrintResults ['telephone'] =
$Info[0][$Info[0][$Count]][0];
}
elseif ( $Info[0][$Count] == 'facsimiletelephonenumber' )
{
$PrintResults ['fax'] =
$Info[0][$Info[0][$Count]][0];
}
elseif ( $Info[0][$Count] == 'postofficebox' )
{
$PrintResults ['mail'] =
$Info[0][$Info[0][$Count]][0];
}
}
if ( $PrintResults['description'] != '' )
{
Table2RowDept ( 'Afkorting', $PrintResults['description']);
}
if ( $PrintResults['mail'] != '' )
{
Table2RowDept ( 'E-mail adres', $PrintResults['mail']);
}
if ( $PrintResults['address'] != '' )
{
Table2RowDept ( 'Adres', $PrintResults['address']);
}
if ( $PrintResults['postaladdress'] != '' )
{
Table2RowDept ( 'Postadres', $PrintResults['postaladdress']);
}
if ( $PrintResults['telephone'] != '' )
{
Table2RowDept ( 'Telefoonnummer', $PrintResults['telephone']);
}
if ( $PrintResults['fax'] != '' )
{
Table2RowDept ( 'Faxnummer', $PrintResults['fax']);
}
TableEnd ();
Br ();
}
ldap_close($Connection);
}
function AdvancedSearch ( $TitleSearch, & $Search, $PrintTitle, $Zoek )
{
include ( 'Constants.php' );
// Connect to server
if ( !($Connection = ldap_connect($LdapServer, $LdapPort)) )
{
return 1;
}
// We'll need to add account details here
ldap_bind($Connection, $LdapRDN, $LdapPassword );
// First off, lets build up the search criteria.
// We're only getting people back.
$FieldCount=0;
$GotCN=0;
$GotTel=0;
// $SearchString = '(objectclass=person)';
$SearchString = '';
if ( $Search['Personen'] )
{
$SearchString .= '(cn=*' . $Search['Personen'] . '*)';
$FieldCount++;
$GotCN=1;
}
if ( $Search ['Organisatie'] != '' )
{
$SearchString .= '(ou=*' . $Search ['Organisatie'] . '*)';
$FieldCount++;
}
if ( $Search ['Email'] != '' )
{
$SearchString .= '(mail=*' . $Search ['Email'] . '*)';
$FieldCount++;
}
if ( $Search ['Street'] != '' )
{
$SearchString .= '(street=*' . $Search ['Street'] . '*)';
$FieldCount++;
}
if ( $Search ['Stad'] != '' )
{
$SearchString .= '(l=*' . $Search ['Stad'] . '*)';
$FieldCount++;
}
if ( $Search ['Postadres'] != '' )
{
$SearchString .= '(postaladdress=*' . $Search ['Postadres'] . '*)';
$FieldCount++;
}
if ( $Search ['Telefoonnummer'] != '' )
{
$SearchString .= '(telephonenumber=*' . $Search ['Telefoonnummer'] . '*)';
$FieldCount++;
$GotTel=1;
}
if ( $Search ['Faxnummer'] != '' )
{
$SearchString .= '(facsimiletelephonenumber=*' . $Search ['Faxnummer'] . '*)';
$FieldCount++;
}
// Make sure we've got the display data!
if ( $GotCN == 0 )
{
$SearchString .= '(cn=*)';
$FieldCount++;
}
if ( $GotTel == 0)
{
$SearchString .= '(telephonenumber=*)';
$FieldCount++;
$GotTel=1;
}
// Make sure we and these together if 2 or more.
if ( $FieldCount >= 2 )
{
$SearchString = '(&' . $SearchString . ')';
}
//echo $FieldCount . ':' . $SearchString;
$OldLevel = error_reporting ( 1 );
// Another bit of frigging...
// if the field count is zero, then display the departments
if ( $FieldCount == 2 &&
$SearchString == '(&(cn=*)(telephonenumber=*))' )
// $SearchString == '(&(objectclass=person)(cn=*)(telephonenumber=*))' )
{
GetData ( '(o=*)', $Search, 0, 0 );
return 0;
}
else
{
//+++
$Result = ldap_search($Connection, $Search ['DN'],
$SearchString);
// $SearchString, $PersonalAttributes, 0, 0, 0);
}
$Info = ldap_get_entries($Connection, $Result);
error_reporting ( $OldLevel );
// Strip the Title field name out of the Title search string
$TitleField = trim ( substr ( $SearchString,
strpos ( $TitleSearch, '(' ) + 1,
strpos ( $TitleSearch, '=' ) - 1 ) );
$Title = $Info[0][$TitleField][0];
PrintRoot ( $Search );
// Save the organisational filter for later use
$SaveFilter=$Search['Organisatie'];
if ( $Info ['count'] <= 0 )
{
SendWarning ( $NoMatchesFound );
}
else
{
$HeadingPrinted = 0;
$Totaal_Row=array();
for ($i=0; $i<$Info['count']; $i++)
{
$Department = '';
//echo '<br>' . $Info [$i]['dn'];
$arrDept = ldap_explode_dn ( $Info [$i]['dn'], 1 );
for ( $LC = $arrDept ['count'] - 2; $LC > 1; $LC-- )
{
$Department .= $arrDept [$LC] . '/';
}
$Department .= $arrDept [1];
$Search ['DN'] = $Info [$i]['dn'];
if ( $Search ['Organisatie'] != '' )
{
if (strstr ( strtoupper ($Search['DN']),
strtoupper ($Search ['Organisatie'])))
{
if ( $HeadingPrinted == 0)
{
// First we want to build a table of departments
TableStart ( 'align="center" border="0" width="70%" cellspacing="2" cellpadding="4"' );
Table3Head ( 'Naam', 'Telefoonnummer', 'Organisatie' );
$SaveDN = $Search ['DN'];
$HeadingPrinted = 1;
}
array_push($Totaal_Row,ReturnVal_Table3Row ( $Info[$i]['cn'][0],
$Info[$i]['telephonenumber'][0],
$Department,
$Search ));
}
}
else
{
if ( $HeadingPrinted == 0)
{
// First we want to build a table of departments
TableStart ( 'align="center" border="0" width="70%" cellspacing="2" cellpadding="4"' );
Table3Head ( 'Naam', 'Telefoonnummer', 'Organisatie' );
$SaveDN = $Search ['DN'];
$HeadingPrinted = 1;
}
array_push($Totaal_Row,ReturnVal_Table3Row ( $Info[$i]['cn'][0],
$Info[$i]['telephonenumber'][0],
$Department,
$Search ));
}
}
Draw_Rows($Totaal_Row);
if ( $HeadingPrinted == 0)
{
SendWarning ( $NoMatchesFound );
}
else
{
TableEnd ();
}
}
ldap_close($Connection);
}
function GetDescription ( $DN )
{
global $LdapServer, $LdapPort, $LdapRDN, $LdapPassword;
// Connect to server
if ( !($Connection = ldap_connect($LdapServer, $LdapPort)) )
{
return '';
}
// We'll need to add account details here
if ( !ldap_bind($Connection, $LdapRDN, $LdapPassword ) )
{
return '';
}
$LocalDN = strtr ( trim ( $DN ), '^+', '& ' );
$Result = ldap_read($Connection, $LocalDN, "(objectClass=organizationalunit)");
$Info = ldap_get_entries($Connection, $Result);
if ( $Info['count'] > 0 )
{
$RetStr = $Info [0] ['description'] [0];
}
else
{
$RetStr='';
}
ldap_close($Connection);
return $RetStr;
}
function multidimsort($array_in)
{
$multiarray = array();
$array_out = array();
$array_1 = array();
$array_2 = array();
$array_3 = array();
$loopvalue = 0;
/* -1 as traversal of array starts from 0, count() starts from 1 */
$multicount = count($array_in) - 1;
/* add the indexes you wish to sort array by to a new array in this
case index is two levels down, but shouldn't make a difference if it
goes further indexes down. (Not tested!) */
for($i = 0; $i <= $multicount; $i++)
{
array_push($multiarray, strtoupper ($array_in[$i]['ou'][0]));
array_push($array_1, $array_in[$i]['ou'][0]);
array_push($array_2, $array_in[$i]['dn']);
array_push($array_3, $array_in[$i]['telephonenumber'][0]);
}
/* alphabetically sort the new array (Ascending in this case) can chage
sort to whatever type you like. Even apply user-defined sort. */
//asort($multiarray, "CaseFreeSort");
array_multisort ( $multiarray, SORT_STRING, SORT_ASC,
$array_1, $array_2, $array_3 );
/* traverse new array of index values and add the corresponding element
//of the input array to the correct position in the output array */
for ( $loopvalue=1; $loopvalue < count ($array_1); $loopvalue++)
{
$array_out[$loopvalue-1][0] = $array_1[$loopvalue];
$array_out[$loopvalue-1][1] = $array_2[$loopvalue];
$array_out[$loopvalue-1][2] = $array_3[$loopvalue];
//echo $array_out[$loopvalue][0] . ':' . $array_out[$loopvalue][1] . ':'
//. $array_out[$loopvalue][2] . '<br>';
}
/* return the output array which is all nicely sorted by the index you
wanted! */
return $array_out;
}
function multidimsort2($array_in)
{
$multiarray = array();
$array_out = array();
$array_1 = array();
$array_2 = array();
$array_3 = array();
$array_4 = array();
$loopvalue = 0;
/* -1 as traversal of array starts from 0, count() starts from 1 */
$multicount = count($array_in) - 1;
/* add the indexes you wish to sort array by to a new array in this
case index is two levels down, but shouldn't make a difference if it
goes further indexes down. (Not tested!) */
for($i = 0; $i <= $multicount; $i++)
{
array_push($multiarray, strtoupper ($array_in[$i]['ou'][0]));
array_push($array_1, $array_in[$i]['ou'][0]);
array_push($array_2, $array_in[$i]['dn']);
array_push($array_3, $array_in[$i]['cn'][0]);
array_push($array_4, $array_in[$i]['telephonenumber'][0]);
}
/* alphabetically sort the new array (Ascending in this case) can chage
sort to whatever type you like. Even apply user-defined sort. */
//asort($multiarray, "CaseFreeSort");
array_multisort ( $multiarray, SORT_STRING, SORT_ASC,
$array_1, $array_2, $array_3, $array_4 );
/* traverse new array of index values and add the corresponding element
//of the input array to the correct position in the output array */
for ( $loopvalue=1; $loopvalue < count ($array_1); $loopvalue++)
{
$array_out[$loopvalue-1][0] = $array_1[$loopvalue];
$array_out[$loopvalue-1][1] = $array_2[$loopvalue];
$array_out[$loopvalue-1][2] = $array_3[$loopvalue];
$array_out[$loopvalue-1][3] = $array_4[$loopvalue];
//echo $array_out[$loopvalue][0] . ':' . $array_out[$loopvalue][1] . ':'
//. $array_out[$loopvalue][2] . $array_out[$loopvalue][3] . '<br>';
}
/* return the output array which is all nicely sorted by the index you
wanted! */
return $array_out;
}
?> |