/[drupal]/contributions/modules/og_teampage/og_teampage.module
ViewVC logotype

Contents of /contributions/modules/og_teampage/og_teampage.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.36 - (show annotations) (download) (as text)
Thu Jul 12 07:37:49 2007 UTC (2 years, 4 months ago) by martinsfromb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.35: +2 -2 lines
File MIME type: text/x-php
- converted files to utf-8 and unix newline format
1 <?php
2 // $Id: og_teampage.module,v 1.35 2007/07/10 12:00:37 martinsfromb Exp $
3
4 function og_teampage_admin_settings_form() {
5 _og_teampage_check_settings();
6 $form['og_teampage_image_default_path'] = array('#type' => 'textfield', '#title' => t('Default image path'), '#default_value' => variable_get('og_teampage_image_default_path', 'og_teampage_images'), '#description' => t('Subdirectory in the directory %dir where pictures will be stored. Do not include trailing slash.', array('%dir' => theme('placeholder', variable_get('file_directory_path', 'files')))));
7 $form['og_teampage_colcount'] = array('#type' => 'textfield', '#title' => t('Column count in members table'), '#default_value' => variable_get('og_teampage_colcount',5), '#description' => t('How many members should be shown in one row?'));
8 $form['og_teampage_imagewidth'] = array('#type' => 'textfield', '#title' => t('Width of images in members table'), '#default_value' => variable_get('og_teampage_imagewidth',''), '#description' => t('Wich width should a team mebers picture have?'));
9 $form['og_teampage_imageheight'] = array('#type' => 'textfield', '#title' => t('Height of images in members table'), '#default_value' => variable_get('og_teampage_imageheight',''), '#description' => t('Wich height should a team mebers picture have?'));
10 $form['help_text'] = array('#type' => 'markup', '#title' => t('Help'), '#value' => t('Please give at least width or height of the images
11 in the team table! Remember it should be a table, so the layout should be human viewable! ;)<br /><br />'));
12 return system_settings_form($form);
13 }
14
15 function _og_teampage_check_settings() {
16 $image_path = file_create_path(variable_get('og_teampage_image_default_path', 'og_teampage_images'));
17 if (!file_check_directory($image_path, FILE_CREATE_DIRECTORY, 'og_teampage_image_default_path')) {
18 return false;
19 }
20 return true;
21 }
22
23 function og_teampage_menu($may_cache) {
24 drupal_add_css(drupal_get_path('module', 'og_teampage').'/og_teampage.css');
25 $items = array();
26
27 if (arg(0) == 'node' && is_numeric(arg(1))) {
28 $node = node_load(arg(1));
29
30 if (og_is_group_type($node->type)) {
31 $items[] = array('path' => 'node/'. arg(1). '/members', 'title' => t('Team Table View'), 'callback' => 'og_teampage_admin_members', 'callback arguments' => array(arg(1)), 'access' => og_teampage_check_access($node->nid), 'type' => MENU_LOCAL_TASK, 'weight' => 7);
32 };
33 }
34 $items[] = array(
35 'path' => 'admin/og/og_teampage',
36 'title' => t('OG Teampage settings'),
37 'description' => t('Set some preferences to og_teampage module.'),
38 'callback' => 'drupal_get_form',
39 'callback arguments' => array('og_teampage_admin_settings_form'),
40 'access' => user_access('administer site configuration'),
41 'type' => MENU_NORMAL_ITEM
42 );
43 return $items;
44 }
45
46 function og_teampage_nodeapi(&$node, $op, $teaser = FALSE, $page = FALSE) {
47 if (($op == 'view') && (og_is_group_type($node->type))) {
48 if ($teaser == FALSE) {
49 $res = db_query("SELECT * FROM {og_teampage}
50 WHERE gid='".$node->nid."' AND show_in_mission='1'");
51 if (db_num_rows($res) > 0) {
52 $node->content['og_mission']['#value'] =
53 substr($node->content['og_mission']['#value'],0,
54 strlen($node->content['og_mission']['#value'])-6);
55 $node->content['og_mission']['#value'] =
56 $node->content['og_mission']['#value'].og_teampage_teamtable($node->nid)."</div>";
57 }
58 }
59 }
60 }
61
62 function sort_members_array($a, $b) {
63 if ($a[data]->weight == $b[data]->weight) return 0;
64 return ($a[data]->weight > $b[data]->weight) ? 1 : -1;
65 }
66
67 function og_teampage_teamtable($gid) {
68 $res = db_query("SELECT * FROM {og_teampage} WHERE gid='".$gid."'");
69 $test = db_fetch_object($res);
70 $use_userimage = $test->use_user_images;
71
72 $table = '<div class="clear-block"><br /></div><div class="teammembers-list">';
73 $table .= '<table width="100%">';
74 $min_is_active = 1;
75 $min_is_admin = 0;
76
77 $sql = "SELECT u.uid, u.name, u.picture, ou.* FROM {og_uid} ou INNER JOIN {users} u ON ou.uid = u.uid WHERE ou.nid = %b AND u.status > 0 AND is_active >= $min_is_active AND is_admin >= $min_is_admin ORDER BY u.name ASC";
78 $result = db_query($sql, $gid);
79 $i=0;
80 while ($account = db_fetch_object($result)) {
81 $rows[$i][username] = $account->name;
82 $rows[$i][uid] = $account->uid;
83 $rows[$i][picture] = $account->picture;
84 $res = db_query("SELECT * FROM {og_teampage_members} WHERE uid='".$account->uid."' AND gid='".$gid."'");
85 $rows[$i][data] = db_fetch_object($res);
86 $i++;
87 }
88 $trows = array();
89 $rowcounter = 1;
90 $colcounter = 0;
91 $colcount = variable_get('og_teampage_colcount',5);
92 $colwidth = 100/variable_get('og_teampage_colcount',5);
93 $colwidth = round($colwidth);
94 $colwidthstring = $colwidth.'%';
95
96 usort($rows, sort_members_array);
97 foreach($rows as $row)
98 {
99 if ($row[data]->hidden != '1') {
100 $colcounter++;
101 if ($colcounter > $colcount) {
102 $rowcounter++;
103 $colcounter = 1;
104 }
105 $picsource = base_path().drupal_get_path('module', 'og_teampage').'/no-pic.png';
106 if ($row[data]->picture1 != '')
107 {
108 $picsource = $row[data]->picture1;
109 $picsource = str_replace("system/files/", "", $picsource);
110 $picsource = file_create_url($picsource);
111 } else if (($row[picture] != '') && ($use_userimage == 1) && (file_exists($row[picture]))) $picsource = file_create_url($row[picture]);
112 if ($row[data]->name != '')
113 {
114 $name = $row[data]->name;
115 } else $name = $row[username];
116
117 $description = $row[data]->description;
118 $width = variable_get('og_teampage_imagewidth','');
119 $height = variable_get('og_teampage_imageheight','');
120 $width_attr = '';
121 $height_attr = '';
122 if ($width != '') $width_attr = 'width="'.$width.'" ';
123 if ($height != '') $height_attr = 'height="'.$height.'" ';
124
125 $attr=array();
126 $attr['target'] = '_blank';
127 $piclink = l('<img src="'.$picsource.'" '.$width_attr.$height_attr.'alt="user-image">','user/'.$row[uid], $attr, NULL, NULL, FALSE, TRUE);
128 $textlink = l($name,'user/'.$row[uid], $attr);
129 $member = '<table class="teammember"><tr><td align="center">'.$piclink.'</td></tr>';
130 $member .= '<tr><td align="center">'.$textlink.'</td></tr>';
131 if ($description != '') $member .= '<tr><td align="center" class="small">'.$description.'</td></tr>';
132 $member .= '</table>';
133
134 $cell = '<td align="center" valign="top" width="'.$colwidthstring.'">'.$member.'</td>';
135 $trows[$rowcounter] .= $cell;
136 }
137
138 }
139 foreach ($trows as $trow) {
140 $trcount++;
141 if (($trcount < $rowcounter) || ($colcounter == $colcount)) {
142 $table .= '<tr>'.$trow.'</tr>';
143 };
144 }
145 $table .= '</table>';
146 if ($colcounter < $colcount)
147 {
148 $table .= '<table width="100%"><tr>';
149 $diff = $colcount - $colcounter;
150 $dummywidth = $colwidth * $diff / 2;
151 $dummywidth = round($dummywidth);
152 $dummywidthstr = $dummywidth.'%';
153 $table .= '<td width="'.$dummywidthstr.'">&nbsp;</td>';
154 $table .= $trows[$rowcounter];
155 $table .= '<td width="'.$dummywidthstr.'">&nbsp;</td>';
156 $table .= '</tr></table>';
157 }
158 $table .= '</div>';
159 $table .= '<br class="clear">';
160 return $table;
161 }
162
163 function og_teampage_admin_members($gid) {
164 $node = node_load($gid);
165 drupal_set_title(t('Administer memberships of %group', array('%group' => $node->title)));
166 $output = drupal_get_form('og_teampage_admin_members_form', $gid);
167 return $output;
168 }
169 function og_teampage_admin_members_form($gid) {
170 _og_teampage_check_settings();
171 $node = node_load($gid);
172 $access = og_teampage_check_access($gid);
173 $form['attributes'] = array("#enctype" => "multipart/form-data");
174 $form['#attributes']['enctype'] = 'multipart/form-data';
175 $form['gid'] = array('#type' => 'value', '#value' => $gid);
176 $form['submit'] = array('#type' => 'submit', '#value' => t('Save changes'));
177 $res = db_query("SELECT * FROM {og_teampage} WHERE gid='".$gid."'");
178 $teampage_data = db_fetch_object($res);
179 $form['showtable'] = array('#type' => 'checkbox', '#default_value' => $teampage_data->show_in_mission, '#title' => t('Show teamtable on group home page').'?');
180 $form['use_userimage'] = array('#type' => 'checkbox', '#default_value' => $teampage_data->use_user_images, '#title' => t('Show user image if available and no image uploaded for this team').'?');
181 $sql = og_list_users_sql(0);
182 $result = db_query($sql, $gid);
183 while ($account = db_fetch_object($result)) {
184 $uid = $account->uid;
185 $operations = array();
186 if (($access) && ($account->uid != $node->uid)) {
187 if ($account->is_active) {
188 $operations[] = l(t('unsubscribe'), "og/unsubscribe/$gid/$account->uid", array(), "destination=og/users/$gid");
189 if ($account->is_admin) {
190 $operations[] = l(t('admin: remove'), "og/delete_admin/$gid/$account->uid", array(), 'destination='. $_GET['q']);
191 }
192 else {
193 $operations[] = l(t('admin: create'), "og/create_admin/$gid/$account->uid", array(), 'destination='. $_GET['q']);
194 }
195 }
196 else {
197 $operations[] = l(t('approve'), "og/approve/$gid/$account->uid", array(), "destination=og/users/$gid");
198 $operations[] = l(t('deny'), "og/deny/$gid/$account->uid", array(), "destination=og/users/$gid");
199 }
200 }
201 $ophtml = '<ul>';
202 foreach ($operations as $operation) {
203 $ophtml .= '<li>'.$operation.'</li>';
204 }
205 $ophtml .= '</ul>';
206
207 $form[$uid]['#tree'] = TRUE;
208 $form[$uid][op] = array('#type' => 'markup', '#value' => $ophtml);
209 $form[$uid][username] = array('#type' => 'markup', '#value' => theme('username', $account));
210
211 $res = db_query("SELECT * FROM {og_teampage_members} WHERE uid='".$uid."' AND gid='".$gid."'");
212 if (db_num_rows($res) < 1) {
213 $res = db_query("SELECT * FROM {og_teampage_members} WHERE uid='".$uid."' AND gid='0'");
214 }
215 $data = db_fetch_object($res);
216 $form[$uid][weight] = array('#type' => 'weight', '#default_value' => $data->weight, '#title' => t('Weight'), '#delta' => 10);
217 $form[$uid][description] = array('#type' => 'textarea', '#default_value' => $data->description, '#title' => t('Description'));
218 $form[$uid][name] = array('#type' => 'textfield', '#default_value' => $data->name, '#size' => 20, '#title' => t('Name in team'));
219 $form[$uid][hidden] = array('#type' => 'checkbox', '#default_value' => $data->hidden, '#title' => t('Hide from team table').'?');
220
221 $picsource = base_path().drupal_get_path('module', 'og_teampage').'/no-pic.png';
222 if ($data->picture1 != '')
223 {
224 $picsource = $data->picture1;
225 $picsource = str_replace("system/files/", "", $picsource);
226 $picsource = file_create_url($picsource);
227 }
228 $form[$uid][image] = array('#type' => 'markup', '#value' => '<img src="'.$picsource.'" alt="user-image">');
229
230 $form['image_upload'.$uid] = array('#type' => 'file', '#size' => 10, '#title' => t('Upload new picture'));
231 if ($data->picture1 != '') $form[$uid][image_delete] = array('#type' => 'checkbox', '#title' => t('delete this picture').'?');
232
233 $form[$uid][image_oldpath] = array('#type' => 'value', '#value' => $data->picture1);
234 }
235 return $form;
236 }
237
238 function theme_og_teampage_admin_members_form($form) {
239 $rows= array();
240 foreach ($form as $name => $element) {
241 if (isset($element['description'])&& is_array($element['description'])) {
242 $rows[] = '<td valign="top"><strong>'.drupal_render($element[username]).'</strong></td><td valign="top">'.drupal_render($element[op]).'</td><td valign="top">'.drupal_render($element[name]).'</td><td valign="top">'.drupal_render($element[weight]).'</td><td valign="top">'.drupal_render($element[hidden]).'</td>';
243 $rows[] = '<td colspan="4" valign="top">'.drupal_render($element[description]).'</td><td><table><tr><td valign="top"><div style="float:left;">'.drupal_render($element[image]).'</div> '.drupal_render($element['image_delete']).'</td></tr><tr><td valign="top">'.drupal_render($form['image_upload'.$name]).'</td></tr></table></td>';
244 unset ($form[$name]);
245 unset ($form['image_upload'.$name]);
246 }
247 }
248 $gid = $form['gid']['#value'];
249 $output .= '<p>'.t('If you want to add some users to the team, click').' '.l(t('here'),"og/users/$gid/add_user").'!</p>';
250 $output .= '<p>'.drupal_render($form['showtable']).'</p>';
251 $output .= '<p>'.drupal_render($form['use_userimage']).'</p>';
252 $output .= '<table>';
253 $counter = 0;
254 $class = 'even';
255 foreach ($rows as $row) {
256 $counter++;
257 if ($counter == 3) {
258 $counter = 1;
259 if ($class == 'odd') {
260 $class = 'even';
261 } else $class = 'odd';
262 }
263 $output .= '<tr valign="top" class="'.$class.'">'.$row.'</tr>';
264 if ($counter == 2) $output .= '<tr valign="top" class="'.$class.'"><td colspan="5">&nbsp;</td></tr>';
265 }
266 $output .= '</table>';
267 $output .= drupal_render($form);
268 return $output;
269 }
270
271 function og_teampage_filter($op, $delta = 0, $format = -1, $text = '') {
272 switch ($op) {
273 case 'list':
274 return array(0 => t('og group members table'));
275 //case 'no cache':
276 // return TRUE;
277 case 'description':
278 return t('Show the group members of an organic group in a table.');
279 case 'process':
280 $tag_start = strpos($text, '[teamtable:');
281 if ($tag_start === FALSE) {
282 return $text;
283 } else {
284 $tag_end = strpos($text, ']',$tag_start);
285 $tag = substr($text, $tag_start, $tag_end - $tag_start + 1);
286 $gid = $tag;
287 $gid = str_replace('[teamtable:', '', $gid);
288 $gid = str_replace(']', '', $gid);
289 $text = str_replace($tag, og_teampage_teamtable($gid), $text);
290 return $text;
291 }
292 default:
293 return $text;
294 }
295 }
296
297 function og_teampage_admin_members_form_submit($form_id, $form_values) {
298 $error = FALSE;
299 $gid = $form_values['gid'];
300 db_query("DELETE FROM {og_teampage} WHERE gid='".$gid."'");
301 if ($form_values['showtable'] == 1)
302 {
303 $show_in_mission = 1;
304 } else $show_in_mission =0;
305 if ($form_values['use_userimage'] == 1)
306 {
307 $use_user_images= 1;
308 } else $use_user_images =0;
309 db_query("INSERT INTO {og_teampage} SET gid='".$gid."', show_in_mission='".$show_in_mission."',use_user_images='".$use_user_images."'");
310 foreach ($form_values as $uid => $value) {
311 if (isset($value['description'])&& is_array($value)) {
312 if ($value['image_delete'] == 1)
313 {
314 $value['image_oldpath'] = '';
315 }
316 $newfilename = '';
317 $file = file_check_upload('image_upload'.$uid);
318 if ($file) {
319 if (substr($file->filemime, 0, 6) == 'image/') {
320 file_save_upload('image_upload'.$uid, variable_get('og_teampage_image_default_path', 'images') .'/teampage_overview_'.$gid.'_'.$uid.'.'.substr($file->filemime, 6),FILE_EXISTS_REPLACE);
321 $newfilename = variable_get('og_teampage_image_default_path', 'images') .'/teampage_overview_'.$gid.'_'.$uid.'.'.substr($file->filemime, 6);
322 } else
323 {
324 $error = TRUE;
325 drupal_set_message(t('Uploaded file "').$file->filename.t('" is not a correct image file!'), 'error');
326 }
327 }
328 if ($newfilename == '') $newfilename = $value['image_oldpath'];
329 $res = db_query("DELETE FROM {og_teampage_members} WHERE uid='".$uid."' AND gid='".$gid."'");
330 $res = db_query("INSERT INTO {og_teampage_members} SET weight='".$value['weight']."', uid='".$uid."', gid='".$gid."', hidden='".$value['hidden']."', name='".$value['name']."', description='".$value['description']."', picture1='".$newfilename."'");
331 }
332 }
333 $res = db_query("DELETE FROM {cache} WHERE 1 = 1");
334 $node = node_load($gid);
335 if (!$error) drupal_set_message(t('Saved your changes to group ').$node->title.'.');
336 }
337
338 function og_teampage_check_access($gid)
339 {
340 $ret = false;
341 global $user;
342 $res = db_query("SELECT * FROM {og_uid} WHERE uid='".$user->uid."' AND nid='".$gid."'");
343 $data = db_fetch_object($res);
344 if (($data->is_active == 1) && ($data->is_admin == 1)) $ret = true;
345 return $ret;
346 }
347 ?>

  ViewVC Help
Powered by ViewVC 1.1.2