61
61
if (user_access('access content')) {
64
$titles = _signup_list_user_signups($user->uid);
65
$conflicts = _signup_get_conflicts($user->uid);
66
if (count($conflicts)) {
67
$conflict_teaser = '<br>'. l(t('%number schedule %conflict', array('%number' => $conflicts['total'], '%conflict' => format_plural($conflicts['total'], t('conflict exists'), t('conflicts exist')))), "user/$user->uid");
69
$conflict_teaser = '';
71
if (count($titles) > 0) {
64
$titles = signup_list_user_signups($user->uid);
72
66
$block['subject'] = t('Current Signups');
73
$block['content'] = theme_item_list($titles) . l(t('view signup schedule'), "user/$user->uid/signups"). $conflict_teaser;
67
$block['content'] = theme_item_list($titles) . l(t('view signup schedule'), "user/$user->uid/signups");
175
169
'access' => $access);
176
170
$items[] = array('path' => 'admin/signup/overview', 'title' => t('overview'),
177
171
'access' => $access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
178
$items[] = array('path' => 'admin/signup/conflicts', 'title' => t('conflicts'),
179
'callback' => 'signup_conflict_summary', 'access' => $access,
180
'type' => MENU_LOCAL_TASK, 'weight' => 0);
181
$items[] = array('path' => 'admin/signup/conflict_detail', 'title' => t('conflict detail'),
182
'callback' => 'signup_conflict_detail', 'access' => $access,
183
'type' => MENU_LOCAL_TASK, 'weight' => 3);
185
173
//user signup callbacks
186
174
$items[] = array('path' => 'signup', 'access' => TRUE, 'type' => MENU_CALLBACK, 'callback' => 'signup_user_signup');
568
* Callback function for generating a detail report of signup conflicts
569
* @ingroup signup_callback
571
function signup_conflict_detail() {
573
//pull all users who have signed up for a node
574
$result = db_query('SELECT DISTINCT u.uid, u.name FROM {users} u INNER JOIN {signup_log} s on u.uid = s.uid ORDER BY u.name');
576
//for each user, build a conflict detail section, and add their number of conflicts to the total
577
while ($user = db_fetch_object($result)) {
578
$conflicts = _signup_user_conflicts($user->uid);
579
if (isset($conflicts)) {
580
$sum .= $conflicts['title'] . $conflicts['data'];
581
$total_conflicts += $conflicts['total'];
583
$sum .= t('<h4>%user, 0 schedule conflicts</h4>', array('%user' => l($user->name, "user/$user->uid")));
587
//list the number of conflicts at the top of the page
588
if (isset($total_conflicts)) {
589
$output = t('<h2>%total total %conflict</h2>', array('%total' => $total_conflicts, '%conflict' => format_plural($total_conflicts, t('conflict'), t('conflicts')))) . $sum;
591
$output = t('<h2>No schedule conflicts</h2>');
593
print theme('page', $output);
597
* Callback function for generating a summary report of signup conflicts
598
* @ingroup signup_callback
600
function signup_conflict_summary() {
602
//pull all users who have signed up for a node
603
$result = db_query('SELECT DISTINCT u.uid, u.name FROM {users} u INNER JOIN {signup_log} s on u.uid = s.uid ORDER BY u.name');
605
//for each user, build summary table row, and add their number of conflicts to the total
606
while ($user = db_fetch_object($result)) {
607
$conflicts = _signup_user_conflicts($user->uid);
608
$user_total = (count($conflicts) ? $conflicts['total'] : 0);
609
$rows[] = array(l($user->name, "user/$user->uid"), $user_total);
610
$total_conflicts += $user_total;
613
//list the number of conflicts at the top of the page
614
if ($total_conflicts > 0) {
615
$header = array(t('user'), t('conflicts'));
616
$output = t('<h2>%total total %conflict</h2>', array('%total' => $total_conflicts, '%conflict' => format_plural($total_conflicts, t('conflict'), t('conflicts'))));
617
$output .= theme('table', $header, $rows);
619
$output = t('<h2>No schedule conflicts</h2>');
621
print theme('page', $output);
625
551
* Callback function for reopening signups
626
552
* @ingroup signup_callback
615
* Returns an array of node titles w/ links for all events the specified user has signed up for.
617
function signup_list_user_signups($uid) {
621
//tests for optional support of event.module
622
$_EVENT = module_exist('event');
623
$event_join = $_EVENT ? ' LEFT JOIN {event} e ON e.nid = n.nid' : '';
624
$event_where = $_EVENT ? ' AND (e.event_start >= '. time() . ' OR e.event_start IS NULL)' : '';
625
$order_by = $_EVENT ? 'e.event_start' : 'n.title';
627
//pull all open signup nodes for this user
628
$result = db_query("SELECT n.title, n.nid FROM {signup_log} s_l INNER JOIN {node} n ON n.nid = s_l.nid
629
$event_join WHERE s_l.uid = '%s'$event_where ORDER BY $order_by", $uid);
631
while ($node = db_fetch_array($result)) {
632
$titles[$node['nid']] = l($node['title'], 'node/'. $node['nid']);
689
638
* Signs up a user to a node. NOTE: other modules can call this function. To do so, edit must be as follows:
691
640
* edit['nid'] : nid of the node to which the user will be signed up
927
* Returns an array of conflict information for the specified uid
928
* @ingroup signup_internal
930
function _signup_get_conflicts($uid) {
932
$conflicts = array();
933
if (module_exist('event')) {
935
//pull all signup nodes for the specified user
936
$signups = db_query('SELECT n.nid, n.title, e.event_start AS start, e.event_end AS end FROM {signup_log} s INNER JOIN {node} n ON s.nid = n.nid INNER JOIN {event} e ON n.nid = e.nid WHERE s.uid = %d', $uid);
938
//for each signup, pull all nodes that have a time conflict. ignore duplicate conflicts
939
while ($events = db_fetch_array($signups)) {
940
$nid = $events['nid'];
941
$title = $events['title'];
942
$end = $events['end'];
943
$start = $events['start'];
944
$nodes[$nid][] = (integer) $nid;
945
$skip = implode(', ', $nodes[$nid]);
946
$conflicting = db_query('SELECT n.nid, n.title, e.event_start AS start, e.event_end AS end FROM {signup_log} s INNER JOIN {node} n ON s.nid = n.nid INNER JOIN {event} e ON n.nid = e.nid WHERE s.uid = %d AND ((event_start < %d AND event_start > %d) OR(event_end < %d AND event_end > %d) OR (event_end >= %d AND event_start <= %d)) AND n.nid NOT IN(%s)', $uid, $end, $start, $end, $start, $end, $start, $skip);
948
//if there are conflicts, build a conflict array. mark conflicts to prevent duplicates
949
if (db_num_rows($conflicting)) {
950
$conflicts[$nid][] = array('nid' => $nid, 'title' => $title, 'start' => $start, 'end' => $end);
951
while ($conflict = db_fetch_array($conflicting)) {
952
$conflicts[$nid][] = $conflict;
954
$nodes[$conflict['nid']][] = $nid;
960
$conflicts['total'] = $total_conflicts;
967
* Returns an array of node titles w/ links for all events the specified user has signed up for
968
* @ingroup signup_internal
970
function _signup_list_user_signups($uid) {
974
//tests for optional support of event.module
975
$_EVENT = module_exist('event');
976
$event_join = $_EVENT ? ' LEFT JOIN {event} e ON e.nid = n.nid' : '';
977
$event_where = $_EVENT ? ' AND (e.event_start >= '. time() . ' OR e.event_start IS NULL)' : '';
978
$order_by = $_EVENT ? 'e.event_start' : 'n.title';
980
//pull all open signup nodes for this user
981
$result = db_query("SELECT n.title, n.nid FROM {signup_log} s_l INNER JOIN {node} n ON n.nid = s_l.nid
982
$event_join WHERE s_l.uid = '%s'$event_where ORDER BY $order_by", $uid);
984
while ($node = db_fetch_array($result)) {
985
$titles[$node['nid']] = l($node['title'], 'node/'. $node['nid']);
991
* Returns a formatted list of conflict information for the specified user
992
* @ingroup signup_internal
994
function _signup_user_conflicts($uid) {
996
$user = user_load(array('uid' => $uid));
997
$conflicts = _signup_get_conflicts($uid);
999
//if there are conflicts, pull the total from the array, and build a title section
1000
if (count($conflicts)) {
1001
$return['total'] = array_pop($conflicts);
1002
$return['title'] = t('<h4>%user, %total schedule %conflict:</h4>', array('%total' => $return['total'], '%conflict' => format_plural($return['total'], t('conflict'), t('conflicts')), '%user' => l($user->name, "user/$user->uid")));
1006
//pull the main event off the array, and then loop through and put all the conflicts to that event in an item list
1007
foreach($conflicts as $nid) {
1009
$node = array_shift($nid);
1010
$output .= l(check_plain($node['title']), 'node/'. $node['nid']) .' '. t('conflicts with:');
1011
foreach ($nid as $conflict) {
1012
$list[] = l(check_plain($conflict['title']), 'node/'. $conflict['nid']);
1014
$output .= theme('item_list', $list);
1016
$return['data'] = $output;
b'\\ No newline at end of file'