2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2009 */
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
14 $_user_location = 'public';
16 define('AT_INCLUDE_PATH', '../../../include/');
17 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 require(AT_SOCIAL_INCLUDE.'constants.inc.php');
19 require(AT_SOCIAL_INCLUDE.'friends.inc.php');
20 require(AT_SOCIAL_INCLUDE.'classes/SocialGroups/SocialGroup.class.php');
21 require(AT_SOCIAL_INCLUDE.'classes/SocialGroups/SocialGroups.class.php');
22 $_custom_css = $_base_path . AT_SOCIAL_BASENAME . 'module.css'; // use a custom stylesheet
24 // Get social group class
25 $social_groups = new SocialGroups();
28 $id = intval($_REQUEST['id']); //make sure $_GET and $_POST don't overlap the use of 'id'
29 $group = new SocialGroup($id);
31 //validate if this user is the administrator of the group
32 if ($group->getUser() != $_SESSION['member_id']){
33 $msg->addError('CANT_EDIT_GROUP');
34 header('Location: index.php');
39 //validate the group_admin is indeed a group member
41 function resize_image($src, $dest, $src_h, $src_w, $dest_h, $dest_w, $type) {
42 $thumbnail_img = imagecreatetruecolor($dest_w, $dest_h);
45 $source = imagecreatefromgif($src);
46 } else if ($type == 'jpg') {
47 $source = imagecreatefromjpeg($src);
49 $source = imagecreatefrompng($src);
52 imagecopyresampled($thumbnail_img, $source, 0, 0, 0, 0, $dest_w, $dest_h, $src_w, $src_h);
55 imagegif($thumbnail_img, $dest);
56 } else if ($type == 'jpg') {
57 imagejpeg($thumbnail_img, $dest, 75);
59 imagepng($thumbnail_img, $dest, 7);
63 // check if GD is installed
64 if (!extension_loaded('gd')) {
65 require(AT_INCLUDE_PATH.'header.inc.php');
66 $msg->printInfos('FEATURE_NOT_AVAILABLE');
67 require(AT_INCLUDE_PATH.'footer.inc.php');
73 if (isset($_POST['save'])){
75 if ($_FILES['logo']['name']!=''){
77 $supported_images = array();
78 if ($gd_info['GIF Create Support']) {
79 $supported_images[] = 'gif';
81 if ($gd_info['JPG Support']) {
82 $supported_images[] = 'jpg';
84 if ($gd_info['PNG Support']) {
85 $supported_images[] = 'png';
88 if (!$supported_images) {
89 require(AT_INCLUDE_PATH.'header.inc.php');
90 $msg->printInfos('FEATURE_NOT_AVAILABLE');
91 require(AT_INCLUDE_PATH.'footer.inc.php');
95 // check if this is a supported file type
96 $filename = $stripslashes($_FILES['logo']['name']);
97 $path_parts = pathinfo($filename);
98 $extension = strtolower($path_parts['extension']);
99 $image_attributes = getimagesize($_FILES['logo']['tmp_name']);
101 if ($extension == 'jpeg') {
105 if (!in_array($extension, $supported_images)) {
106 $msg->addError(array('FILE_ILLEGAL', $extension));
107 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id);
109 } else if ($image_attributes[2] > IMAGETYPE_PNG) {
110 $msg->addError(array('FILE_ILLEGAL', $extension));
111 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id);
115 // make sure under max file size
116 if ($_FILES['logo']['size'] > $_config['prof_pic_max_file_size']) {
117 $msg->addError('FILE_MAX_SIZE');
118 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id);
122 // delete the old images (if any)
123 foreach ($supported_images as $ext) {
124 if (file_exists(AT_CONTENT_DIR.'social/'. $id.'.'.$ext)) {
125 unlink(AT_CONTENT_DIR.'social/'. $id.'.'.$ext);
129 $new_filename = $id . '.' . $extension;
130 $original_img = AT_CONTENT_DIR.'social/temp_'. $new_filename;
131 $thumbnail_img= AT_CONTENT_DIR.'social/'. $new_filename;
133 // only want the resized logo. (for now)
134 if (!move_uploaded_file($_FILES['logo']['tmp_name'], $original_img)) {
135 $msg->addError('CANNOT_OVERWRITE_FILE');
136 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id);
140 // resize the original and save it at $thumbnail_file
141 $width = $image_attributes[0];
142 $height = $image_attributes[1];
144 if ($width > $height && $width>100) {
145 $thumbnail_height = intval(100 * $height / $width);
146 $thumbnail_width = 100;
148 resize_image($original_img, $thumbnail_img, $height, $width, $thumbnail_height, $thumbnail_width, $extension);
149 } else if ($width <= $height && $height > 100) {
150 $thumbnail_height= 100;
151 $thumbnail_width = intval(100 * $width / $height);
152 resize_image($original_img, $thumbnail_img, $height, $width, $thumbnail_height, $thumbnail_width, $extension);
154 // no resizing, just copy the image.
155 // it's too small to resize.
156 copy($original_img, $thumbnail_img);
158 // clean the original
159 unlink($original_img);
163 //check if fields are empty
164 if ($_POST['group_name']==''){
165 $missing_fields[] = _AT('group_name');
166 } elseif (intval($_POST['group_type'])<=0){
167 $missing_fields[] = _('group_type');
169 if ($missing_fields) {
170 $missing_fields = implode(', ', $missing_fields);
171 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
173 $isSucceded = $social_groups->updateGroup($id, $_POST['group_admin'], $_POST['group_type'], $_POST['group_name'], $_POST['description'], $new_filename, $_POST['group_privacy']);
176 $msg->addFeedback('SOCIAL_GROUP_UPDATED');
177 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'groups/index.php', AT_PRETTY_URL_HEADER));
180 //Something went bad in the backend, contact admin?
181 $msg->addError('GROUP_EDIT_FAILED');
184 } elseif (isset($_POST['cancel'])){
185 $msg->addFeedback('CANCELLED');
186 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'groups/index.php', AT_PRETTY_URL_HEADER));
191 include(AT_INCLUDE_PATH.'header.inc.php');
192 $savant->display('pubmenu.tmpl.php');
193 $savant->assign('group_obj', $group);
194 $savant->assign('group_types', $social_groups->getAllGroupType());
195 $savant->display('sgroup_edit.tmpl.php');
196 include(AT_INCLUDE_PATH.'footer.inc.php');