From ea4152cdbf28ed94620d0a0f7cc3bc856a8cd6b5 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 18 Feb 2007 18:37:15 +0000 Subject: [PATCH] allow uploading of images --- lam/HISTORY | 2 ++ lam/lib/modules/inetOrgPerson.inc | 55 ++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/lam/HISTORY b/lam/HISTORY index 886b47d8..ec02fc26 100644 --- a/lam/HISTORY +++ b/lam/HISTORY @@ -1,5 +1,7 @@ ??? 1.3.0 - improved design + - user list can now display jpegPhoto attributes + - LAM Pro: users may change their photos (jpegPhoto) - fixed bugs: -> ShadowAccount: PDF entry for expire date was wrong (1658868) -> Debian package did not include lamdaemonOld.pl (1660493) diff --git a/lam/lib/modules/inetOrgPerson.inc b/lam/lib/modules/inetOrgPerson.inc index 5379e79f..6ed53e25 100644 --- a/lam/lib/modules/inetOrgPerson.inc +++ b/lam/lib/modules/inetOrgPerson.inc @@ -113,7 +113,7 @@ class inetOrgPerson extends baseModule { $return['selfServiceFieldSettings'] = array('firstName' => _('First name'), 'lastName' => _('Last name'), 'mail' => _('eMail address'), 'telephoneNumber' => _('Telephone number'), 'mobile' => _('Mobile number'), 'faxNumber' => _('Fax number'), 'street' => _('Street'), 'postalAddress' => _('Postal address'), - 'postalCode' => _('Postal code'), 'postOfficeBox' => _('Post office box')); + 'postalCode' => _('Postal code'), 'postOfficeBox' => _('Post office box'), 'jpegPhoto' => _('Photo')); // profile elements $return['profile_options'] = array( array( @@ -1133,6 +1133,39 @@ class inetOrgPerson extends baseModule { 1 => array('kind' => 'input', 'name' => 'inetOrgPerson_postOfficeBox', 'type' => 'text', 'size' => '30', 'maxlength' => '255', 'value' => $postOfficeBox)); } + if (in_array('jpegPhoto', $fields)) { + if (isset($attributes['jpegPhoto'][0])) { + $jpeg_filename = 'jpegPhoto' . session_id() . '.jpg'; + $outjpeg = fopen(realpath('../../') . '/tmp/' . $jpeg_filename, "wb"); + fwrite($outjpeg, $attributes['jpegPhoto'][0]); + fclose ($outjpeg); + $photoFile = '../../tmp/' . $jpeg_filename; + $return['jpegPhoto'] = array( + array('kind' => 'text', 'text' => _('Photo')), + array('kind' => 'table', 'value' => array( + array( + array('kind' => 'image', 'alt' => _('Photo'), 'path' => $photoFile) + ), + array( + array('kind' => 'table', 'value' => array(array( + array('kind' => 'input', 'type' => 'checkbox', 'name' => 'removeReplacePhoto'), + array('kind' => 'text', 'text' => _('Remove/replace photo')), + array('kind' => 'input', 'name' => 'replacePhotoFile', 'type' => 'file') + ))), + ) + )) + ); + } + else { + $return['jpegPhoto'] = array( + array('kind' => 'text', 'text' => _('Photo')), + array('kind' => 'table', 'value' => array(array( + array('kind' => 'text', 'text' => _('Add photo')), + array('kind' => 'input', 'name' => 'photoFile', 'type' => 'file') + ))) + ); + } + } return $return; } @@ -1239,6 +1272,26 @@ class inetOrgPerson extends baseModule { } elseif (isset($attributes['postOfficeBox'])) unset($attributesNew['postOfficeBox']); } + // photo + if (in_array('jpegPhoto', $fields)) { + if ($_FILES['photoFile'] && ($_FILES['photoFile']['size'] > 0)) { + $handle = fopen($_FILES['photoFile']['tmp_name'], "r"); + $data = fread($handle, 1000000); + fclose($handle); + $return['add']['jpegPhoto'][0] = $data; + } + if ($_POST['removeReplacePhoto'] == 'on') { + if ($_FILES['replacePhotoFile'] && ($_FILES['replacePhotoFile']['size'] > 0)) { + $handle = fopen($_FILES['replacePhotoFile']['tmp_name'], "r"); + $data = fread($handle, 1000000); + fclose($handle); + $return['mod']['jpegPhoto'][0] = $data; + } + else { + $return['mod']['jpegPhoto'] = array(); + } + } + } // find differences for ($i = 0; $i < sizeof($attributeNames); $i++) { $attrName = $attributeNames[$i];