2 /****************************************************************/
\r
4 /****************************************************************/
\r
5 /* Copyright (c) 2002-2009 */
\r
6 /* Inclusive Design Institute */
\r
7 /* http://atutor.ca */
\r
9 /* This program is free software. You can redistribute it and/or*/
\r
10 /* modify it under the terms of the GNU General Public License */
\r
11 /* as published by the Free Software Foundation. */
\r
12 /****************************************************************/
\r
14 $_user_location = 'public';
\r
15 define('AT_INCLUDE_PATH', '../../../include/');
\r
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
\r
17 $member_id = $_SESSION['member_id'];
\r
18 $_custom_css = $_base_path . AT_SOCIAL_BASENAME . 'module.css'; // use a custom stylesheet
\r
20 function resize_image($src, $dest, $src_h, $src_w, $dest_h, $dest_w, $type, $src_x=0, $src_y=0) {
\r
21 $thumbnail_img = imagecreatetruecolor($dest_w, $dest_h);
\r
23 if ($type == 'gif') {
\r
24 $source = imagecreatefromgif($src);
\r
25 } else if ($type == 'jpg') {
\r
26 $source = imagecreatefromjpeg($src);
\r
28 $source = imagecreatefrompng($src);
\r
31 if ($src_x > 0 || $src_y > 0){
\r
32 imagecopyresized($thumbnail_img, $source, 0, 0, $src_x, $src_y, $dest_w, $dest_h, $src_w, $src_h);
\r
34 imagecopyresampled($thumbnail_img, $source, $src_x, $src_y, 0, 0, $dest_w, $dest_h, $src_w, $src_h);
\r
37 if ($type == 'gif') {
\r
38 imagegif($thumbnail_img, $dest);
\r
39 } else if ($type == 'jpg') {
\r
40 imagejpeg($thumbnail_img, $dest, 75);
\r
42 imagepng($thumbnail_img, $dest, 7);
\r
46 // check if GD is installed
\r
47 if (!extension_loaded('gd')) {
\r
48 require(AT_INCLUDE_PATH.'header.inc.php');
\r
49 $msg->printInfos('FEATURE_NOT_AVAILABLE');
\r
50 require(AT_INCLUDE_PATH.'footer.inc.php');
\r
54 // check if folder exists, if not, create it
\r
55 if (!is_dir(AT_CONTENT_DIR.'/profile_pictures/profile')) {
\r
56 mkdir(AT_CONTENT_DIR.'/profile_pictures/profile');
\r
59 $gd_info = gd_info();
\r
60 $supported_images = array();
\r
61 if ($gd_info['GIF Create Support']) {
\r
62 $supported_images[] = 'gif';
\r
64 if ($gd_info['JPG Support'] || $gd_info['JPEG Support']) {
\r
65 $supported_images[] = 'jpg';
\r
67 if ($gd_info['PNG Support']) {
\r
68 $supported_images[] = 'png';
\r
71 if (!$supported_images) {
\r
72 require(AT_INCLUDE_PATH.'header.inc.php');
\r
73 $msg->printInfos('FEATURE_NOT_AVAILABLE');
\r
74 require(AT_INCLUDE_PATH.'footer.inc.php');
\r
78 if (isset($_POST['cancel'])) {
\r
79 $msg->addFeedback('CANCELLED');
\r
80 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
82 } else if (isset($_POST['submit'])) {
\r
83 if (isset($_POST['delete']) && !$_FILES['file']['size']) {
\r
84 profile_image_delete($member_id);
\r
86 $msg->addFeedback('PROFILE_UPDATED');
\r
88 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
90 } else if ($_FILES['file']['error'] == UPLOAD_ERR_FORM_SIZE) {
\r
91 $msg->addError(array('FILE_MAX_SIZE', $_config['prof_pic_max_file_size'] . ' ' . _AT('bytes')));
\r
92 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
94 } else if (!$_FILES['file']['size']) {
\r
95 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
99 // check if this is a supported file type
\r
100 $filename = $stripslashes($_FILES['file']['name']);
\r
101 $path_parts = pathinfo($filename);
\r
102 $extension = strtolower($path_parts['extension']);
\r
103 $image_attributes = getimagesize($_FILES['file']['tmp_name']);
\r
105 if ($extension == 'jpeg') {
\r
106 $extension = 'jpg';
\r
109 if (!in_array($extension, $supported_images)) {
\r
110 $msg->addError(array('FILE_ILLEGAL', $extension));
\r
111 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
113 } else if ($image_attributes[2] > IMAGETYPE_PNG) {
\r
114 $msg->addError(array('FILE_ILLEGAL', $extension));
\r
115 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
119 // make sure under max file size
\r
120 if ($_FILES['file']['size'] > $_config['prof_pic_max_file_size']) {
\r
121 $msg->addError('FILE_MAX_SIZE');
\r
122 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
126 // delete the old images (if any)
\r
127 profile_image_delete($member_id);
\r
129 $new_filename = $member_id . '.' . $extension;
\r
130 $original_img = AT_CONTENT_DIR.'profile_pictures/originals/'. $new_filename;
\r
131 $profile_img = AT_CONTENT_DIR.'profile_pictures/profile/'. $new_filename;
\r
132 $thumbnail_img = AT_CONTENT_DIR.'profile_pictures/thumbs/'. $new_filename;
\r
135 if (!move_uploaded_file($_FILES['file']['tmp_name'], $original_img)) {
\r
136 $msg->addError('CANNOT_OVERWRITE_FILE');
\r
137 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
141 // resize the original and save it at $thumbnail_file
\r
142 $width = $image_attributes[0];
\r
143 $height = $image_attributes[1];
\r
145 $thumbnail_fixed_height = 60;
\r
146 $thumbnail_fixed_width = 60;
\r
148 if ($width > $height && $height > $thumbnail_fixed_height) {
\r
149 $thumbnail_height= $thumbnail_fixed_height;
\r
150 $thumbnail_width = intval($thumbnail_fixed_height * $width / $height);
\r
151 resize_image($original_img, $thumbnail_img, $height, $width, $thumbnail_height, $thumbnail_width, $extension);
\r
153 resize_image($thumbnail_img, $thumbnail_img, $thumbnail_fixed_height, $thumbnail_fixed_width, $thumbnail_fixed_height, $thumbnail_fixed_width, $extension, ($thumbnail_width-$thumbnail_fixed_width)/2);
\r
154 } else if ($width <= $height && $width>$thumbnail_fixed_width) {
\r
155 $thumbnail_height = intval($thumbnail_fixed_width * $height / $width);
\r
156 $thumbnail_width = $thumbnail_fixed_width;
\r
157 resize_image($original_img, $thumbnail_img, $height, $width, $thumbnail_height, $thumbnail_width, $extension);
\r
159 resize_image($thumbnail_img, $thumbnail_img, $thumbnail_fixed_height, $thumbnail_fixed_width, $thumbnail_fixed_height, $thumbnail_fixed_width, $extension, 0, ($thumbnail_height-$thumbnail_fixed_height)/2);
\r
161 // no resizing, just copy the image.
\r
162 // it's too small to resize.
\r
163 copy($original_img, $thumbnail_img);
\r
166 // resize the original and save it to profile
\r
167 $profile_fixed_height = 320;
\r
168 $profile_fixed_width = 240;
\r
169 if ($width > $height && $height>$profile_fixed_height) {
\r
170 $profile_width = intval($profile_fixed_height * $width / $height);
\r
171 $profile_height = $profile_fixed_height;
\r
172 resize_image($original_img, $profile_img, $height, $width, $profile_height, $profile_width, $extension);
\r
174 resize_image($profile_img, $profile_img, $profile_fixed_height, $profile_fixed_width, $profile_fixed_height, $profile_fixed_width, $extension, ($profile_width-$profile_fixed_width)/2);
\r
175 } else if ($width <= $height && $width > $profile_fixed_width) {
\r
176 $profile_width = $profile_fixed_width;
\r
177 $profile_height = intval($profile_fixed_width * $height / $width);
\r
178 resize_image($original_img, $profile_img, $height, $width, $profile_height, $profile_width, $extension);
\r
180 resize_image($profile_img, $profile_img, $profile_fixed_height, $profile_fixed_width, $profile_fixed_height, $profile_fixed_width, $extension, 0, ($profile_height-$profile_fixed_height)/2);
\r
182 // no resizing, just copy the image.
\r
183 // it's too small to resize.
\r
184 copy($original_img, $profile_img);
\r
187 $msg->addFeedback('PROFILE_UPDATED');
\r
189 header('Location: '.$_SERVER['PHP_SELF'].'?member_id='.$member_id);
\r
193 require(AT_INCLUDE_PATH.'header.inc.php');
\r
194 $savant->assign('member_id', $member_id);
\r
195 $savant->assign('supported_images', $supported_images);
\r
196 $savant->display('social/profile_picture.html.php');
\r
197 require(AT_INCLUDE_PATH.'footer.inc.php');
\r