00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: groups.php 5497 2006-02-25 14:08:31Z toddy $
00006 #
00007 # Copyright 2003-2006 (c) Frederik Orellana <frederik.orellana--cern.ch>
00008 # Mathieu Roy <yeupou--gnu.org>
00009 #
00010 # The Savane project is free software; you can redistribute it and/or
00011 # modify it under the terms of the GNU General Public License
00012 # as published by the Free Software Foundation; either version 2
00013 # of the License, or (at your option) any later version.
00014 #
00015 # The Savane project is distributed in the hope that it will be useful,
00016 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 # GNU General Public License for more details.
00019 #
00020 # You should have received a copy of the GNU General Public License
00021 # along with the Savane project; if not, write to the Free Software
00022 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00023
00024
00025 require "../include/pre.php";
00026 require_directory("search");
00027 require_directory("trackers");
00028
00029 # Make this page register global off compliant
00030 register_globals_off();
00031
00032 # Obtain general user info
00033 $res_user = db_query("SELECT * FROM user WHERE user_id=" . user_getid());
00034 $row_user = db_fetch_array($res_user);
00035
00036 # Obtain approval_user_gen_email() for site specific content
00037 utils_get_content("my/request_for_inclusion");
00038
00039
00040 ###################################################################
00041
00079 function send_pending_user_email($group_id, $user_id, $user_message)
00080 {
00081
00082 $res_grp = db_query("SELECT * FROM groups WHERE group_id='$group_id'");
00083
00084 if (db_numrows($res_grp) < 1)
00085 {
00086 return 0;
00087 }
00088
00089 $row_grp = db_fetch_array($res_grp);
00090
00091 $res_admins = db_query("SELECT user.user_name FROM user,user_group WHERE "
00092 . "user.user_id=user_group.user_id AND user_group.group_id='$group_id' AND "
00093 . "user_group.admin_flags='A'");
00094
00095 if (db_numrows($res_admins) < 1)
00096 {
00097 return 0;
00098 }
00099
00100 # send one email per admin, in one command line coma separated
00101 $admin_list = '';
00102 while ($row_admins = db_fetch_array($res_admins))
00103 {
00104 $admin_list .= ($admin_list ? ',':'').$row_admins['user_name'];
00105 }
00106
00107 $message = approval_user_gen_email($row_grp['group_name'],
00108 $row_grp['unix_group_name'],
00109 $group_id,
00110 user_getname($user_id),
00111 user_getrealname($user_id),
00112 user_getemail($user_id),
00113 $user_message);
00114
00115
00116 sendmail_mail(user_getname(),
00117 $admin_list,
00118 sprintf(_("Membership request for group %s"), $row_grp['group_name']),
00119 $message,
00120 $row_grp['unix_group_name'],
00121 "usermanagement");
00122 }
00123
00124 # Request for inclusion
00125 if (sane_post("update"))
00126 {
00127 $result_upd = db_query("SELECT group_id FROM groups WHERE status='A' AND
00128 is_public='1' ORDER BY group_id");
00129 $form_id = sane_post("form_id");
00130
00131 # Check for duplicates
00132 if (!form_check($form_id))
00133 { return 0; }
00134 unset($form_cleaned_already);
00135
00136 while ($val = db_fetch_array($result_upd))
00137 {
00138 if(sane_post("form_groups_$val[group_id]"))
00139 {
00140 # If not in group, add user with admin_flag "P"
00141 # (not very sensible, but this way we avoid changing
00142 # the table layout)
00143 if(!member_check_pending($row_user[user_id], $val[group_id]))
00144 {
00145 if(!sane_post("form_message"))
00146 {
00147 fb(_("Error: When joining you must provide a message for the administrator, a short explanation of why you want to join this/these project(s)."), 1);
00148 }
00149 else
00150 {
00151 if(member_add($row_user[user_id], $val[group_id], 'P'))
00152 {
00153 send_pending_user_email($val[group_id], $row_user[user_id], $GLOBALS["form_message"]);
00154 if (!$form_cleaned_already)
00155 {
00156 form_clean($form_id);
00157 $form_cleaned_already = 1;
00158 }
00159 }
00160 }
00161 }
00162 else
00163 {
00164 fb(_("Request for inclusion already registered"),1);
00165 }
00166 }
00167 }
00168 }
00169
00170
00171
00172
00173 # ###### get global user and group vars
00174
00175 $sql = "SELECT groups.group_name,"
00176 . "groups.group_id,"
00177 . "groups.unix_group_name,"
00178 . "groups.status,"
00179 . "user_group.admin_flags, "
00180 . "group_history.date "
00181 . "FROM groups,user_group,group_history "
00182 . "WHERE groups.group_id=user_group.group_id "
00183 . "AND user_group.user_id='".user_getid()."' "
00184 . "AND groups.status='A' "
00185 . "AND (group_history.field_name='Added User' OR group_history.field_name='Approved User' OR user_group.admin_flags='P')"
00186 . "AND group_history.group_id=user_group.group_id "
00187 . "AND group_history.old_value='".user_getname()."' "
00188 . "GROUP BY groups.unix_group_name "
00189 . "ORDER BY groups.unix_group_name";
00190
00191 $result = db_query($sql);
00192 $rows = db_numrows($result);
00193
00194 # Alternative sql that do not use group_history, just in case this history
00195 # would be flawed (history usage has been inconsistent over Savane history)
00196 $sql_without_history = "SELECT groups.group_name,"
00197 . "groups.group_id,"
00198 . "groups.unix_group_name,"
00199 . "groups.status,"
00200 . "user_group.admin_flags "
00201 . "FROM groups,user_group "
00202 . "WHERE groups.group_id=user_group.group_id "
00203 . "AND user_group.user_id='".user_getid()."' "
00204 . "AND groups.status='A' "
00205 . "GROUP BY groups.unix_group_name "
00206 . "ORDER BY groups.unix_group_name";
00207
00208 $result_without_history = db_query($sql_without_history);
00209 $rows_without_history = db_numrows($result_without_history);
00210
00211 if ($rows_without_history != $rows)
00212 {
00213 # If number of rows differ, assume that history is flawed. Print a
00214 # feedback incitating to fix the installation and override flawed result
00215 #
00216 # The following update script was maybe forgot:
00217 # update/1.0.6/update_group_history.pl
00218 fb(_("Groups history appears to be flawed. This is a site installation problem. Please report the incident to administrators, asking them to get in touch with their Savane supplier."), 1);
00219 $result = $result_without_history;
00220 $rows = $rows_without_history;
00221 }
00222
00223
00224 ###################################################################
00225 # Start HTML
00226
00227 # page header
00228 site_user_header(array('context'=>'mygroups'));
00229
00230 print '<p>'._("Here is the list of groups you are member of, plus a form which allows you to ask for inclusion in a Group. Clicking on the trash permits you to quit a project.").'</p>';
00231
00232 # we get site-specific content
00233 utils_get_content("my/groups");
00234
00235
00236 ################ RIGHT PART ###########################
00237
00238 print html_splitpage(1); # Watching other users.
00239
00240 print $HTML->box_top(_("Watched Partners"));
00241
00242 $result_w = trackers_data_get_watchees(user_getid());
00243 $rows_w=db_numrows($result_w);
00244
00245 if (!$result_w || $rows_w < 1)
00246 {
00247 print '<p>'._("You are not watching any partners.").'</p>';
00248 print '<p>'._("Watching a partner (receiving a copy of all notifications sent to them) permits you to be their backup when they are away from the office, or to review all their activities on a project.");
00249 print '</p><p>'._("To watch someone, click 'Watch partner' in the project memberlist page. You need to be member of that project yourself.");
00250 print '<br />';
00251 print db_error();
00252 }
00253 else
00254 {
00255 print '<table>';
00256 for ($i=0; $i<$rows_w; $i++)
00257 {
00258 print '<tr class="'.utils_get_alt_row_color($i).'"><td width="99%"><strong>'.
00259 utils_user_link(user_getname(db_result($result_w, $i, 'watchee_id')), user_getrealname(db_result($result_w, $i, 'watchee_id'))).
00260 '</strong> <span class="smaller">['.group_getname(db_result($result_w, $i, 'group_id')).']'.
00261 '</span>';
00262
00263 print '</td>'.
00264 '<td><a href="'.$_SERVER['PHP_SELF'].'?func=delwatchee&group_id='.db_result($result_w,$i,'group_id').'&watchee_id='.db_result($result_w, $i, 'watchee_id').
00265 '" onClick="return confirm(\''._("Stop watching this user?").'\')">'.
00266 '<img src="'.$GLOBALS['sys_home'].'images/'.SV_THEME.'.theme/trash.png" border="0" alt="'._("Stop watching this user?").'" /></a></td></tr>';
00267 }
00268 print '</table>';
00269
00270 }
00271
00272 $result_w = trackers_data_get_watchers(user_getid());
00273 $arr_watchers = array();
00274 while ($row_watcher = db_fetch_array($result_w))
00275 {
00276 $watchers .= utils_user_link(user_getname($row_watcher['user_id']), user_getrealname($row_watcher['user_id'])).' <span class="smaller">['.group_getname($row_watcher['group_id']).']</span>, ';
00277 }
00278
00279 if ($watchers)
00280 {
00281 $watchers = substr($watchers,0,-2); # remove extra comma at the end
00282 $watchers .= ".";
00283
00284 print '<p>';
00285 printf (_("My own notifications are currently watched by: %s"),$watchers);
00286 print '</p>';
00287 }
00288 else
00289 {
00290 print '<p>'._("Nobody is currently watching my own notifications.").'</p>';
00291 }
00292
00293 print $HTML->box_bottom();
00294
00295 print "<br />\n";
00296
00297 print $HTML->box_top(_("Request for Inclusion"),'',1);
00298
00299 print '<div class="boxitem">'."\n";
00300 print '<p>';
00301 print _("If there is a project - or several - you would like to be member of, to be able to fully contribute, it is possible to search for the names in the whole group database with the following search tool. A list of groups will be generated, depending on the word(s) typed in this form.")."\n";
00302 print '</p>';
00303
00304 print '
00305 <form action="'.$PHP_SELF.'#searchgroup" method="post">
00306 <input type="hidden" name="action" value="searchgroup" />
00307 <input type="text" size="35" name="words" value="'.$words.'" /><br />
00308 <br /><br />
00309 <input type="submit" name="Submit" value="'
00310 ._("Search Group(s)").'" />
00311 </form>
00312
00313 </div><!-- end boxitem -->';
00314
00315 $words = sane_all("words");
00316 if ($words)
00317 {
00318 # Avoid to big search by asking for more than 3 characters.
00319 if (strlen($words) > 3)
00320 {
00321 $result_search = search_run($words, "soft", 0);
00322 }
00323 else
00324 { $result_search = 0; }
00325
00326 print '<div class="boxitemalt"><a name="searchgroup"></a>';
00327 print '<p>';
00328 print _("Below is the result of the research in the groups database.");
00329 print '</p>';
00330
00331 if (db_numrows($result_search) < 1)
00332 {
00333 print '<p class="warn">'._("None found. Please note that only search words of more than three characters are valid.").'</p>';
00334 }
00335 else
00336 {
00337 # We do not put pointer to group page along with checkbox,
00338 # to avoid creating any confusion (for instance, should I check the
00339 # box or click on the link?).
00340 # This tool is to search groups for inclusion, not to look around
00341 # to get information about groups.
00342 print '<p>';
00343 print _("To request inclusion in one or several groups, check the correspondant boxes, write a meaningful message for the project administrator who will approve or disapprove the request, and submit the form.");
00344
00345 print '</p>'.form_header($PHP_SELF);
00346
00347 while ($val = db_fetch_array($result_search))
00348 {
00349 if (!user_is_group_member($row_user[user_id], $val[group_id]))
00350 {
00351 print '<input type="checkbox" name="form_groups_'.$val[group_id].'" /> ';
00352 print $val[group_name];
00353 print '<br />';
00354 }
00355 }
00356
00357 print '<br />'._("Comments (required):").'<br />
00358 <textarea name="form_message" cols="40" rows="7"></textarea><br /><br />
00359 <input type="submit" name="update" value="';
00360 print _("Request Inclusion").'" /></form>';
00361 }
00362 print '</div><!-- end boxitemalt -->';
00363 }
00364
00365 print $HTML->box_bottom(1);
00366
00367
00368 print html_splitpage(2);
00369
00370 ################ LEFT PART ###########################
00371
00372
00373 if (!$result || $rows < 1)
00374 {
00375
00376 print $HTML->box_top(_("My Groups"),'',1);
00377 print _("You're not a member of any public projects");
00378 print $HTML->box_bottom(1);
00379
00380 }
00381 else
00382 {
00383
00384
00385
00386
00387
00388 print $HTML->box_top(_("Groups I'm Administrator of"),'',1);
00389
00390 $j = 1;
00391 unset($content);
00392 for ($i=0; $i<$rows; $i++)
00393 {
00394 if (db_result($result,$i,'admin_flags') == 'A')
00395 {
00396 $content .= '<li class="'.utils_get_alt_row_color($j).'">';
00397 $content .= '<span class="trash"><a href="../my/quitproject.php?quitting_group_id='. db_result($result,$i,'group_id').
00398 '">'.
00399 '<img src="'.$GLOBALS['sys_home'].'images/'.SV_THEME.'.theme/trash.png" alt="'._("Quit this project?").'" /></a><br /></span>';
00400
00401 $content .= '<a href="'.$GLOBALS['sys_home'].'projects/'. db_result($result,$i,'unix_group_name') .'/">'.db_result($result,$i,'group_name').'</a><br />';
00402 $date_joined = db_result($result, $i, 'date');
00403 if ($date_joined)
00404 {
00405 # If the group history is flawed (site install problem), the
00406 # date may be unavailable
00407 $content .= '<span class="smaller">'.
00408 sprintf(_("Member since %s"),
00409 format_date('', $date_joined)).
00410 '</span>';
00411 }
00412 $content .= '</li>';
00413 $exists=1;
00414 $j++;
00415 }
00416 }
00417 if (!$exists)
00418 {
00419 print _("I am not administrator of any projects");
00420 }
00421 else
00422 {
00423 print '<ul class="boxli">'.$content.'</ul>';
00424 }
00425 unset($exists);
00426
00427 print $HTML->box_bottom(1);
00428
00429 print "<br />\n";
00430
00431
00432
00433
00434
00435 print $HTML->box_top(_("Groups I'm Contributor of"),'',1);
00436
00437 $j = 1;
00438 unset($content);
00439 for ($i=0; $i<$rows; $i++)
00440 {
00441 if (db_result($result,$i,'admin_flags') == '')
00442 {
00443 $content .= '<li class="'.utils_get_alt_row_color($j).'">';
00444 $content .= '<span class="trash"><a href="../my/quitproject.php?quitting_group_id='. db_result($result,$i,'group_id').
00445 '">'.
00446 '<img src="'.$GLOBALS['sys_home'].'images/'.SV_THEME.'.theme/trash.png" alt="'._("Quit this project?").'" /></a></span>';
00447
00448 $content .= '<a href="'.$GLOBALS['sys_home'].'projects/'. db_result($result,$i,'unix_group_name') .'/">'.db_result($result,$i,'group_name').'</a><br />';
00449 $date_joined = db_result($result, $i, 'date');
00450 if ($date_joined)
00451 {
00452 # If the group history is flawed (site install problem), the
00453 # date may be unavailable
00454 $content .= '<span class="smaller">'.
00455 sprintf(_("Member since %s"),
00456 format_date('', $date_joined)).
00457 '</span>';
00458 }
00459 $content .= '</li>';
00460 $exists=1;
00461 $j++;
00462 }
00463 }
00464
00465 if (!$exists)
00466 {
00467 print _("I am not contributor member of any projects");
00468 }
00469 else
00470 {
00471 print '<ul class="boxli">'.$content.'</ul>';
00472 }
00473 unset($exists);
00474
00475 print $HTML->box_bottom(1);
00476
00477
00478 print "<br />\n";
00479
00480
00481
00482
00483
00484 print $HTML->box_top(_("Request for Inclusion Waiting For Approval"),'',1);
00485
00486 unset($content);
00487
00488 for ($i=0; $i<$rows; $i++)
00489 {
00490 if (db_result($result,$i,'admin_flags') == 'P')
00491 {
00492 $content .= '<li class="'.utils_get_alt_row_color($j).'">';
00493 $content .= '<span class="trash"><a href="../my/quitproject.php?quitting_group_id='. db_result($result,$i,'group_id').'&pending=1">'.
00494 '<img src="'.$GLOBALS['sys_home'].'images/'.SV_THEME.'.theme/trash.png" alt="'._("Discard this request?").'" /></a></span>';
00495
00496 $content .= '<a href="'.$GLOBALS['sys_home'].'projects/'. db_result($result,$i,'unix_group_name') .'/">'.db_result($result,$i,'group_name').'</a><br /> </li>';
00497 $exists=1;
00498
00499 }
00500 }
00501
00502 if (!$exists)
00503 {
00504 print _("None found");
00505 }
00506 else
00507 {
00508 print '<ul class="boxli">'.$content.'</ul>';
00509 }
00510 unset($exists);
00511
00512 print $HTML->box_bottom(1);
00513
00514 }
00515
00516 print html_splitpage(3);
00517
00518
00519
00520 $HTML->footer(array());
00521
00522 ?>