source: branches/2.2/expressoMail1_2/inc/show_user_photo.php @ 3018

Revision 3018, 2.0 KB checked in by amuller, 14 years ago (diff)

Ticket #1135 - Aplicando alterações do branches 2.0 no branches 2.2

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2
3        require_once '../../header.session.inc.php';
4
5
6        function ldapRebind($ldap_connection, $ldap_url)
7        {
8                @ldap_bind($ldap_connection, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']);
9        }
10
11        if ($_SESSION['phpgw_info']['expressomail']['user']['account_lid'] == '')
12                exit;
13       
14        $mail = $_GET['mail'];
15       
16        if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $mail))
17                exit;
18       
19        $ldap_host      = $_SESSION['phpgw_info']['expressomail']['ldap_server']['host'];
20        $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
21       
22        $ldap_conn=ldap_connect($ldap_host);
23        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
24        ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1);
25        ldap_set_rebind_proc($ldap_conn, ldapRebind);
26       
27        $r=ldap_bind($ldap_conn, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']);
28       
29        if (!$r)
30        {
31                echo 'Sem BIND: ' . ldap_error ( $ldap_conn );
32                exit;
33        }
34
35        $justthese = array("jpegPhoto");
36        $filter="(mail=$mail)";
37        $search=ldap_search($ldap_conn, $ldap_context, $filter, $justthese);
38
39        $entry = ldap_first_entry($ldap_conn, $search);
40        $contact = ldap_get_attributes($ldap_conn, $entry);
41       
42        if($contact['jpegPhoto'])
43        {
44                $contact['jpegPhoto'] = ldap_get_values_len ($ldap_conn, $entry, "jpegPhoto");
45                $image = imagecreatefromstring ($contact['jpegPhoto'][0]);
46        }
47        else
48        {
49                $loadFile = "../templates/default/images/photo.jpg";
50                $image = imagecreatefromjpeg($loadFile);
51        }
52       
53        header("Content-Type: image/jpeg");
54       
55        $pic = $image;
56        if ($pic)
57        {
58                $width = imagesx($pic);
59                $height = imagesy($pic);
60                $twidth = 60; # width of the thumb 160 pixel
61                $theight = $twidth * $height / $width; # calculate height
62                $thumb = imagecreatetruecolor ($twidth, $theight);
63                imagecopyresampled($thumb, $pic, 0, 0, 0, 0,$twidth, $theight, $width, $height); # resize image into thumb
64                imagejpeg($thumb,"",80); # Thumbnail as JPEG
65        }
66                                                                                                                   
67        ldap_close($ldap_conn);
68?>
Note: See TracBrowser for help on using the repository browser.