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
24 // Get social group class
25 $social_groups = new SocialGroups();
27 //validate if this script is being run by the group admin
28 //validate the group_admin is indeed a group member
30 function resize_image($src, $dest, $src_h, $src_w, $dest_h, $dest_w, $type) {
31 $thumbnail_img = imagecreatetruecolor($dest_w, $dest_h);
34 $source = imagecreatefromgif($src);
35 } else if ($type == 'jpg') {
36 $source = imagecreatefromjpeg($src);
38 $source = imagecreatefrompng($src);
41 imagecopyresampled($thumbnail_img, $source, 0, 0, 0, 0, $dest_w, $dest_h, $src_w, $src_h);
44 imagegif($thumbnail_img, $dest);
45 } else if ($type == 'jpg') {
46 imagejpeg($thumbnail_img, $dest, 75);
48 imagepng($thumbnail_img, $dest, 7);
52 if (isset($_POST['create'])){
54 if ($_FILES['logo']['name']!=''){
56 $supported_images = array();
57 if ($gd_info['GIF Create Support']) {
58 $supported_images[] = 'gif';
60 if ($gd_info['JPG Support'] || $gd_info['JPEG Support']) {
61 $supported_images[] = 'jpg';
63 if ($gd_info['PNG Support']) {
64 $supported_images[] = 'png';
67 if (!$supported_images) {
68 require(AT_INCLUDE_PATH.'header.inc.php');
69 $msg->printInfos('FEATURE_NOT_AVAILABLE');
70 require(AT_INCLUDE_PATH.'footer.inc.php');
74 // check if this is a supported file type
75 $filename = $stripslashes($_FILES['logo']['name']);
76 $path_parts = pathinfo($filename);
77 $extension = strtolower($path_parts['extension']);
78 $image_attributes = getimagesize($_FILES['logo']['tmp_name']);
80 if ($extension == 'jpeg') {
84 if (!in_array($extension, $supported_images)) {
85 $msg->addError(array('FILE_ILLEGAL', $extension));
86 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id);
88 } else if ($image_attributes[2] > IMAGETYPE_PNG) {
89 $msg->addError(array('FILE_ILLEGAL', $extension));
90 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id);
94 // make sure under max file size
95 if ($_FILES['logo']['size'] > $_config['prof_pic_max_file_size']) {
96 $msg->addError('FILE_MAX_SIZE');
97 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id);
101 // delete the old images (if any)
102 foreach ($supported_images as $ext) {
103 if (file_exists(AT_CONTENT_DIR.'social/'. $id.'.'.$ext)) {
104 unlink(AT_CONTENT_DIR.'social/'. $id.'.'.$ext);
108 $new_filename = 'no_id'. '.' . $extension;
109 $original_img = AT_CONTENT_DIR.'social/temp_'. $new_filename;
110 $thumbnail_img= AT_CONTENT_DIR.'social/'. $new_filename;
112 // only want the resized logo. (for now)
113 if (!move_uploaded_file($_FILES['logo']['tmp_name'], $original_img)) {
114 $msg->addError('CANNOT_OVERWRITE_FILE');
115 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id);
119 // resize the original and save it at $thumbnail_file
120 $width = $image_attributes[0];
121 $height = $image_attributes[1];
123 if ($width > $height && $width>100) {
124 $thumbnail_height = intval(100 * $height / $width);
125 $thumbnail_width = 100;
127 resize_image($original_img, $thumbnail_img, $height, $width, $thumbnail_height, $thumbnail_width, $extension);
128 } else if ($width <= $height && $height > 100) {
129 $thumbnail_height= 100;
130 $thumbnail_width = intval(100 * $width / $height);
131 resize_image($original_img, $thumbnail_img, $height, $width, $thumbnail_height, $thumbnail_width, $extension);
133 // no resizing, just copy the image.
134 // it's too small to resize.
135 copy($original_img, $thumbnail_img);
137 // clean the original
138 unlink($original_img);
141 //check if fields are empty
142 if ($_POST['group_name']==''){
143 $missing_fields[] = _AT('group_name');
144 } elseif (intval($_POST['group_type'])<=0){
145 $missing_fields[] = _('group_type');
147 if ($missing_fields) {
148 $missing_fields = implode(', ', $missing_fields);
149 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
151 $group_id = $social_groups->addGroup($_POST['group_type'], $_POST['group_name'], $_POST['description'], $_POST['group_privacy']);
153 //Add the logo in now that we have the group id. And rename the old one.
154 if ($thumbnail_img!=''){
155 $new_group = new SocialGroup($group_id);
156 $new_group->updateGroupLogo($group_id . '.' . $extension);
157 $new_location = AT_CONTENT_DIR.'social/'. $group_id . '.' . $extension;
158 copy($thumbnail_img, $new_location);
159 unlink($thumbnail_img);
161 $msg->addFeedback('GROUP_CREATED');
162 header('Location: index.php');
165 //Something went bad in the backend, contact admin?
166 $msg->addError('GROUP_CREATION_FAILED');
172 include(AT_INCLUDE_PATH.'header.inc.php');
173 $savant->display('social/pubmenu.tmpl.php');
174 $savant->assign('group_types', $social_groups->getAllGroupType());
175 $savant->display('social/sgroup_edit.tmpl.php');
176 include(AT_INCLUDE_PATH.'footer.inc.php');