2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2009 */
6 /* Inclusive Design Institute */
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
25 // Get social group class
26 $social_groups = new SocialGroups();
29 $id = intval($_REQUEST['id']); //make sure $_GET and $_POST don't overlap the use of 'id'
30 $group = new SocialGroup($id);
32 //validate if this user is the administrator of the group
33 if ($group->getUser() != $_SESSION['member_id']){
34 $msg->addError('CANT_EDIT_GROUP');
35 header('Location: index.php');
40 //validate the group_admin is indeed a group member
42 function resize_image($src, $dest, $src_h, $src_w, $dest_h, $dest_w, $type) {
43 $thumbnail_img = imagecreatetruecolor($dest_w, $dest_h);
46 $source = imagecreatefromgif($src);
47 } else if ($type == 'jpg') {
48 $source = imagecreatefromjpeg($src);
50 $source = imagecreatefrompng($src);
53 imagecopyresampled($thumbnail_img, $source, 0, 0, 0, 0, $dest_w, $dest_h, $src_w, $src_h);
56 imagegif($thumbnail_img, $dest);
57 } else if ($type == 'jpg') {
58 imagejpeg($thumbnail_img, $dest, 75);
60 imagepng($thumbnail_img, $dest, 7);
64 // check if GD is installed
65 if (!extension_loaded('gd')) {
66 require(AT_INCLUDE_PATH.'header.inc.php');
67 $msg->printInfos('FEATURE_NOT_AVAILABLE');
68 require(AT_INCLUDE_PATH.'footer.inc.php');
74 if (isset($_POST['save'])){
76 if ($_FILES['logo']['name']!=''){
78 $supported_images = array();
79 if ($gd_info['GIF Create Support']) {
80 $supported_images[] = 'gif';
82 if ($gd_info['JPG Support'] || $gd_info['JPEG Support']) {
83 $supported_images[] = 'jpg';
85 if ($gd_info['PNG Support']) {
86 $supported_images[] = 'png';
89 if (!$supported_images) {
90 require(AT_INCLUDE_PATH.'header.inc.php');
91 $msg->printInfos('FEATURE_NOT_AVAILABLE');
92 require(AT_INCLUDE_PATH.'footer.inc.php');
96 // check if this is a supported file type
97 $filename = $stripslashes($_FILES['logo']['name']);
98 $path_parts = pathinfo($filename);
99 $extension = strtolower($path_parts['extension']);
100 $image_attributes = getimagesize($_FILES['logo']['tmp_name']);
102 if ($extension == 'jpeg') {
106 if (!in_array($extension, $supported_images)) {
107 $msg->addError(array('FILE_ILLEGAL', $extension));
108 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id);
110 } else if ($image_attributes[2] > IMAGETYPE_PNG) {
111 $msg->addError(array('FILE_ILLEGAL', $extension));
112 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id);
116 // make sure under max file size
117 if ($_FILES['logo']['size'] > $_config['prof_pic_max_file_size']) {
118 $msg->addError('FILE_MAX_SIZE');
119 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id);
123 // delete the old images (if any)
124 foreach ($supported_images as $ext) {
125 if (file_exists(AT_CONTENT_DIR.'social/'. $id.'.'.$ext)) {
126 unlink(AT_CONTENT_DIR.'social/'. $id.'.'.$ext);
130 $new_filename = $id . '.' . $extension;
131 $original_img = AT_CONTENT_DIR.'social/temp_'. $new_filename;
132 $thumbnail_img= AT_CONTENT_DIR.'social/'. $new_filename;
134 // only want the resized logo. (for now)
135 if (!move_uploaded_file($_FILES['logo']['tmp_name'], $original_img)) {
136 $msg->addError('CANNOT_OVERWRITE_FILE');
137 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id);
141 // resize the original and save it at $thumbnail_file
142 $width = $image_attributes[0];
143 $height = $image_attributes[1];
145 if ($width > $height && $width>100) {
146 $thumbnail_height = intval(100 * $height / $width);
147 $thumbnail_width = 100;
149 resize_image($original_img, $thumbnail_img, $height, $width, $thumbnail_height, $thumbnail_width, $extension);
150 } else if ($width <= $height && $height > 100) {
151 $thumbnail_height= 100;
152 $thumbnail_width = intval(100 * $width / $height);
153 resize_image($original_img, $thumbnail_img, $height, $width, $thumbnail_height, $thumbnail_width, $extension);
155 // no resizing, just copy the image.
156 // it's too small to resize.
157 copy($original_img, $thumbnail_img);
159 // clean the original
160 unlink($original_img);
164 //check if fields are empty
165 if ($_POST['group_name']==''){
166 $missing_fields[] = _AT('group_name');
167 } elseif (intval($_POST['group_type'])<=0){
168 $missing_fields[] = _('group_type');
170 if ($missing_fields) {
171 $missing_fields = implode(', ', $missing_fields);
172 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
174 $isSucceded = $social_groups->updateGroup($id, $_POST['group_admin'], $_POST['group_type'], $_POST['group_name'], $_POST['description'], $new_filename, $_POST['group_privacy']);
177 $msg->addFeedback('SOCIAL_GROUP_UPDATED');
178 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'groups/index.php', AT_PRETTY_URL_HEADER));
181 //Something went bad in the backend, contact admin?
182 $msg->addError('GROUP_EDIT_FAILED');
185 } elseif (isset($_POST['cancel'])){
186 $msg->addFeedback('CANCELLED');
187 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'groups/index.php', AT_PRETTY_URL_HEADER));
192 include(AT_INCLUDE_PATH.'header.inc.php');
193 $savant->display('social/pubmenu.tmpl.php');
194 $savant->assign('group_obj', $group);
195 $savant->assign('group_types', $social_groups->getAllGroupType());
196 $savant->display('social/sgroup_edit.tmpl.php');
197 include(AT_INCLUDE_PATH.'footer.inc.php');