function printView($start_date = NULL, $end_date = NULL, $editing = FALSE, $public = FALSE) { if (empty($this->_members)) { return; } if (!$editing && !$public) { $my_email = $GLOBALS['user_system']->getCurrentUser('email'); } $GLOBALS['system']->includeDBClass('service'); $dummy_service = new Service(); if (is_null($start_date)) { $start_date = date('Y-m-d'); } $service_params = array('congregationid' => $this->getCongregations(), '>date' => date('Y-m-d', strtotime($start_date . ' -1 day'))); if (!is_null($end_date)) { $service_params['<date'] = date('Y-m-d', strtotime($end_date . ' +1 day')); } $services = $GLOBALS['system']->getDBObjectData('service', $service_params, 'AND', 'date'); $to_print = array(); foreach ($services as $id => $service_details) { $service_details['id'] = $id; $to_print[$service_details['date']]['service'][$service_details['congregationid']] = $service_details; $to_print[$service_details['date']]['assignments'] = array(); } foreach ($this->getAssignments($start_date, $end_date) as $date => $date_assignments) { $to_print[$date]['assignments'] = $date_assignments; } ksort($to_print); $role_objects = array(); $this_sunday = date('Y-m-d', strtotime('Sunday')); if (empty($to_print)) { if ($public) { ?> <div class="alert alert-error">This roster is empty for the current date range.</div> <?php } else { ?> <div class="alert alert-error">There are no services during the date range specified. Please try a different date range, or create some services using the 'Edit service program' page.</div> <?php } return; } if ($editing) { $show_lock_fail_msg = false; $show_group_denied_msg = false; foreach ($this->_members as $id => &$details) { if (!empty($details['role_id'])) { $role = $GLOBALS['system']->getDBObject('roster_role', $details['role_id']); if (!($role->canAcquireLock('assignments') && $role->acquireLock('assignments'))) { $details['readonly'] = true; $show_lock_fail_msg = true; } if (!$role->canEditAssignments()) { $details['readonly'] = true; $show_group_denied_msg = true; } } } if ($show_lock_fail_msg) { print_message("Some of the roles in this roster are currently being edited by another user. To edit assignments for these roles, wait until the other user finishes then try again.", 'failure'); } if ($show_group_denied_msg) { print_message("There are some roles in this roster which you are not able to edit because they refer to a volunteer group you do not have access to."); } ?> <form method="post" class="warn-unsaved bubble-option-props"> <script> $(document).ready(function() { setTimeout('showLockExpiryWarning()', <?php echo (strtotime('+' . LOCK_LENGTH, 0) - 60) * 1000; ?> ); setTimeout('showLockExpiredWarning()', <?php echo strtotime('+' . LOCK_LENGTH, 0) * 1000; ?> ); $('table.roster select').keypress(function() { handleRosterChange(this); }).change(function() { handleRosterChange(this); }); $('table.roster input.person-search-single, table.roster input.person-search-multiple').each(function() { this.onchange = function() { handleRosterChange(this); }; }); $('table.roster > tbody > tr').each(function() { updateClashesForRow($(this)); }); }); function handleRosterChange(inputField) { var row = null; if ($(inputField).hasClass('person-search-single') || $(inputField).hasClass('person-search-multiple')) { row = $(inputField).parents('tr:first'); } else if (inputField.tagName == 'SELECT' || inputField.type == 'hidden') { var expandableParent = $(inputField).parents('table.expandable'); if (expandableParent.length) { var row = $(inputField).parents('table:first').parents('tr:first'); } else { var row = $(inputField).parents('tr:first'); } } if (row) { updateClashesForRow(row); } } function updateClashesForRow(row) { var uses = new Object(); // Deal with the single person choosers and select boxes first var sameRowInputs = row.find('input.person-search-single, select'); sameRowInputs.removeClass('clash'); sameRowInputs.each(function() { var thisElt = this; var thisVal = 0; if (this.className == 'person-search-single') { var hiddenInput = document.getElementsByName(this.id.substr(0, this.id.length-6))[0]; thisVal = hiddenInput.value; } else if (this.tagName == 'SELECT') { thisVal = this.value; } if (thisVal != 0) { if (!uses[thisVal]) { uses[thisVal] = new Array(); } uses[thisVal].push(thisElt); } }); // Now add the multi person choosers row.find('ul.multi-person-finder li').removeClass('clash').each(function() { var thisVal = $(this).find('input')[0].value; if (thisVal != 0) { if (!uses[thisVal]) { uses[thisVal] = new Array(); } uses[thisVal].push(this); } }); for (i in uses) { if (uses[i].length > 1) { for (j in uses[i]) { if (typeof uses[i][j] == 'function') continue; $(uses[i][j]).addClass('clash'); } } } } </script> <?php } ?> <table class="table roster" border="1" cellspacing="0" cellpadding="1"> <?php $this->_printTableHeader($editing, $public); ?> <tbody> <?php foreach ($to_print as $date => $ddetail) { if ($public && empty($ddetail['assignments'])) { continue; } $class_clause = $date == $this_sunday ? 'class="tblib-hover"' : ''; ?> <tr <?php echo $class_clause; ?> > <td class="nowrap"> <?php echo '<strong>' . str_replace(' ', ' ', date('j M y', strtotime($date))) . '</strong>'; if (!$editing && !$public) { $emails = array(); foreach ($ddetail['assignments'] as $roleid => $assignees) { foreach ($assignees as $pid => $pdetails) { if (!empty($pdetails['email']) && $pdetails['email'] != $my_email) { $emails[] = $pdetails['email']; } } } $emails = array_unique($emails); if (!empty($emails)) { ?> <p class="smallprint no-print"> <a href="<?php echo get_email_href($my_email, NULL, $emails, date('jS F', strtotime($date))); ?> " <?php echo email_link_extras(); ?> >Email All</a> <?php if (defined('SMS_HTTP_URL') && constant('SMS_HTTP_URL') && $GLOBALS['user_system']->havePerm(PERM_SENDSMS)) { ?> | <span class="clickable" onclick="$(this).parent().next('form').toggle(); $(this).parents('tr:first').addClass('tblib-hover')">SMS All</span> <?php } ?> </p> <?php if (defined('SMS_HTTP_URL') && constant('SMS_HTTP_URL') && $GLOBALS['user_system']->havePerm(PERM_SENDSMS)) { $url = build_url(array('view' => '_send_sms_http', 'roster_view' => $this->id, 'start_date' => $date, 'end_date' => $date)); ?> <form method="post" action="<?php echo $url; ?> " style="position: absolute; display: none"> <div class="standard" style="border-width: 2px; border-radius: 8px"> <h3>Send SMS</h3> <textarea name="message" rows="5" cols="30" maxlength="<?php echo SMS_MAX_LENGTH; ?> "></textarea> <br /> <input type="submit" value="Send" /> <input type="button" onclick="$(this).parents('form').toggle(); $(this).parents('tr:first').removeClass('tblib-hover')" value="Cancel" /> </div> </form> <?php } } } ?> </td> <?php $last_congid = NULL; foreach ($this->_members as $id => $mdetail) { $td_class = ''; if ($mdetail['congregationid'] != $last_congid) { $td_class = 'thick-left-border'; $last_congid = $mdetail['congregationid']; } ?> <td class="<?php echo $td_class; ?> "> <?php if ($mdetail['role_id']) { if ($editing && empty($mdetail['readonly'])) { $currentval = array(); foreach (array_get($ddetail['assignments'], $mdetail['role_id'], array()) as $pid => $pdetails) { $currentval[$pid] = $pdetails['name']; } if (empty($role_objects[$mdetail['role_id']])) { $role_objects[$mdetail['role_id']] =& $GLOBALS['system']->getDBObject('roster_role', $mdetail['role_id']); } if (empty($role_objects[$mdetail['role_id']])) { // must've been a problem continue; } $role_objects[$mdetail['role_id']]->printChooser($date, $currentval); } else { $names = array(); foreach (array_get($ddetail['assignments'], $mdetail['role_id'], array()) as $personid => $vs) { if (!$public) { $n = '<a href="' . BASE_URL . '?view=persons&personid=' . $personid . '" title="Assigned by ' . ents($vs['assigner']) . ' on ' . format_datetime($vs['assignedon']) . '">' . nbsp(ents($vs['name'])) . '</a>'; if (empty($vs['email'])) { $n .= ' <img src="' . BASE_URL . 'resources/img/no_email.png" style="display:inline" title="No Email Address" />'; } $names[] = $n; } else { $names[] = nbsp($vs['name']); } } echo implode("<br />", $names); } } else { if (!empty($ddetail['service'][$mdetail['congregationid']])) { if ($public && (!defined('SHOW_SERVICE_NOTES_PUBLICLY') || !SHOW_SERVICE_NOTES_PUBLICLY)) { // no notes in public view unset($ddetail['service'][$mdetail['congregationid']]['notes']); } $dummy_service->populate($ddetail['service'][$mdetail['congregationid']]['id'], $ddetail['service'][$mdetail['congregationid']]); $dummy_service->printFieldvalue($mdetail['service_field']); } } ?> </td> <?php } if (!$public && count($this->_members) > REPEAT_DATE_THRESHOLD) { ?> <td class="nowrap thick-left-border"> <strong><?php echo str_replace(' ', ' ', date('j M y', strtotime($date))); ?> </strong> </td> <?php } ?> </tr> <?php } ?> </tbody> <?php if (!$public && count($to_print) > 6) { $this->_printTableFooter($editing, $public); } ?> </table> <?php if ($editing) { ?> <input type="submit" class="btn" value="Save" accesskey="s" /> </form> <?php } }
private function _handleProgramSave() { // Update and/or create services on existing dates $dummy = new Service(); foreach ($this->_grouped_services as $date => $date_services) { foreach ($this->_congregations as $congid) { if (isset($date_services[$congid])) { // update the existing service $dummy->populate($date_services[$congid]['id'], $date_services[$congid]); if ($dummy->acquireLock()) { $this->_processServiceCell($congid, $date, $dummy); $dummy->save(); $dummy->releaseLock(); } else { trigger_error("Could not acquire lock on individual service for {$congid} on {$date} - didn't save"); } } else { if (!empty($_POST['topic_title'][$congid][$date]) || !empty($_POST['format_title'][$congid][$date]) || !empty($_POST['bible_ref0'][$congid][$date])) { // create a new service $service = new Service(); $service->setValue('date', $date); $service->setValue('congregationid', $congid); $this->_processServiceCell($congid, $date, $service); $service->create(); } } } } // Add services on new dates $i = 0; while (isset($_POST['new_service_date_d'][$i])) { foreach ($this->_congregations as $congid) { if (!empty($_POST['topic_title'][$congid]['new_' . $i]) || !empty($_POST['format_title'][$congid]['new_' . $i]) || !empty($_POST['bible_refs'][$congid]['new_' . $i][0]) || !empty($_POST['bible_refs'][$congid]['new_' . $i][1])) { // we need to create a service here $service = new Service(); $service->setValue('date', process_widget('new_service_date[' . $i . ']', array('type' => 'date'))); $service->setValue('congregationid', $congid); $this->_processServiceCell($congid, 'new_' . $i, $service); $service->create(); } } $i++; } $shifted = FALSE; // Process the "delete" commands if necessary if (!empty($_POST['delete_single'])) { $service = $GLOBALS['system']->getDBOBject('service', (int) $_POST['delete_single']); if ($service) { $service->delete(); if (!empty($_POST['shift_after_delete'])) { Service::shiftServices(array($service->getValue('congregationid')), $service->getValue('date'), '-7'); $shifted = TRUE; } } } if (!empty($_POST['delete_all_date'])) { $services = $GLOBALS['system']->getDBObjectData('service', array('date' => $_POST['delete_all_date'], 'congregationid' => $this->_congregations), 'AND'); $dummy = new Service(); foreach ($services as $id => $details) { $dummy->populate($id, $details); $dummy->delete(); $shifted = TRUE; } if (!empty($_POST['shift_after_delete'])) { Service::shiftServices($this->_congregations, $_POST['delete_all_date'], '-7'); $shifted = TRUE; } } // Process the "insert" commands if necessary if (!empty($_POST['insert_all_date'])) { Service::shiftServices($this->_congregations, $_POST['insert_all_date'], '7'); $shifted = TRUE; } if (!empty($_POST['insert_single_date'])) { foreach ($_POST['insert_single_date'] as $congid => $date) { Service::shiftServices(array($congid), $date, '7'); $shifted = TRUE; } } if (!$shifted) { foreach ($this->_congregations as $id) { $cong = $GLOBALS['system']->getDBObject('congregation', $id); $cong->releaseLock('services'); } add_message("Services saved"); redirect($_REQUEST['view'], array('editing' => NULL)); } $this->_loadServices(); }
function printView($start_date = NULL, $end_date = NULL, $editing = FALSE, $public = FALSE) { if (empty($this->_members)) { return; } if (!$editing && !$public) { $my_email = $GLOBALS['user_system']->getCurrentUser('email'); } $GLOBALS['system']->includeDBClass('service'); $dummy_service = new Service(); if (is_null($start_date)) { $start_date = date('Y-m-d'); } $service_params = array('congregationid' => $this->getCongregations(), '>date' => date('Y-m-d', strtotime($start_date . ' -1 day'))); if (!is_null($end_date)) { $service_params['<date'] = date('Y-m-d', strtotime($end_date . ' +1 day')); } $services = $GLOBALS['system']->getDBObjectData('service', $service_params, 'AND', 'date'); $to_print = array(); foreach ($services as $id => $service_details) { $service_details['id'] = $id; $to_print[$service_details['date']]['service'][$service_details['congregationid']] = $service_details; $to_print[$service_details['date']]['assignments'] = array(); } $haveHidden = FALSE; foreach ($this->getAssignments($start_date, $end_date) as $date => $date_assignments) { $to_print[$date]['assignments'] = $date_assignments; foreach ($date_assignments as $rid => $asns) { foreach ($asns as $pid => $dets) { if ($dets['assigneehidden']) { $haveHidden = TRUE; } break 2; } } } ksort($to_print); $role_objects = array(); $this_sunday = date('Y-m-d', strtotime('Sunday')); if (empty($to_print)) { if ($public) { ?> <div class="alert alert-error">This roster is empty for the current date range.</div> <?php } else { ?> <div class="alert alert-error">There are no services during the date range specified. Please try a different date range, or create some services using the 'Edit service program' page.</div> <?php } return; } if (!$public && $haveHidden) { if ($editing) { print_message("Some allocations can't be edited because they involve persons you do not have permission to view", 'warning'); } else { print_message("This roster includes some persons that you do not have permission to view", 'warning'); } } if ($editing) { $show_lock_fail_msg = false; $show_group_denied_msg = false; foreach ($this->_members as $id => &$details) { if (!empty($details['role_id'])) { $role = $GLOBALS['system']->getDBObject('roster_role', $details['role_id']); if (!($role->canAcquireLock('assignments') && $role->acquireLock('assignments'))) { $details['readonly'] = true; $show_lock_fail_msg = true; } if (!$role->canEditAssignments()) { $details['readonly'] = true; $show_group_denied_msg = true; } } } if ($show_lock_fail_msg) { print_message("Some of the roles in this roster are currently being edited by another user. To edit assignments for these roles, wait until the other user finishes then try again.", 'failure'); } if ($show_group_denied_msg) { print_message("There are some roles in this roster which you are not able to edit because they refer to a volunteer group you do not have access to."); } ?> <form id="roster" method="post" class="warn-unsaved bubble-option-props" data-lock-length="<?php echo LOCK_LENGTH; ?> "> <?php } ?> <div id="choose-assignee-modal" class="modal hide fade" role="dialog" aria-hidden="true"> <div class="modal-header"> <h4>Choose assignee</h4> </div> <div class="modal-body"> <?php Person::printSingleFinder('personid', NULL); ?> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" id="choose-assignee-save">Save</button> <button class="btn" data-dismiss="modal"id="choose-assignee-cancel">Cancel</button> </div> </div> <table class="table roster" border="1" cellspacing="0" cellpadding="1"> <?php $this->_printTableHeader($editing, $public); ?> <tbody> <?php foreach ($to_print as $date => $ddetail) { if ($public && empty($ddetail['assignments'])) { continue; } $class_clause = $date == $this_sunday ? 'class="tblib-hover"' : ''; ?> <tr <?php echo $class_clause; ?> > <td class="nowrap"> <?php echo '<strong>' . str_replace(' ', ' ', date('j M y', strtotime($date))) . '</strong>'; if (!$editing && !$public) { $emails = array(); foreach ($ddetail['assignments'] as $roleid => $assignees) { foreach ($assignees as $pid => $pdetails) { if (!empty($pdetails['email']) && $pdetails['email'] != $my_email) { $emails[] = $pdetails['email']; } } } $emails = array_unique($emails); if (!empty($emails)) { ?> <p class="smallprint no-print"> <a href="<?php echo get_email_href($my_email, NULL, $emails, date('jS F', strtotime($date))); ?> " <?php echo email_link_extras(); ?> >Email All</a> <?php if (defined('SMS_HTTP_URL') && constant('SMS_HTTP_URL') && $GLOBALS['user_system']->havePerm(PERM_SENDSMS)) { ?> | <span class="clickable" onclick="$(this).parent().next('form').toggle(); $(this).parents('tr:first').addClass('tblib-hover')">SMS All</span> <?php } ?> </p> <?php if (defined('SMS_HTTP_URL') && constant('SMS_HTTP_URL') && $GLOBALS['user_system']->havePerm(PERM_SENDSMS)) { $url = build_url(array('view' => '_send_sms_http', 'roster_view' => $this->id, 'start_date' => $date, 'end_date' => $date)); ?> <form method="post" action="<?php echo $url; ?> " style="position: absolute; display: none"> <div class="well well-small"> <h3>Send SMS</h3> <textarea name="message" rows="5" cols="30" maxlength="<?php echo SMS_MAX_LENGTH; ?> "></textarea> <br /> <input class="btn" type="submit" value="Send" /> <input class="btn" type="button" onclick="$(this).parents('form').toggle(); $(this).parents('tr:first').removeClass('tblib-hover')" value="Cancel" /> </div> </form> <?php } } } ?> </td> <?php $last_congid = NULL; foreach ($this->_members as $id => $mdetail) { $td_class = ''; if ($mdetail['congregationid'] != $last_congid) { $td_class = 'thick-left-border'; $last_congid = $mdetail['congregationid']; } ?> <td class="<?php echo $td_class; ?> "> <?php if ($mdetail['role_id']) { $haveHidden = FALSE; foreach (array_get($ddetail['assignments'], $mdetail['role_id'], array()) as $pid => $pdetails) { if ($pdetails['assigneehidden']) { $haveHidden = TRUE; } } if ($editing && empty($mdetail['readonly']) && !$haveHidden) { $currentval = array(); foreach (array_get($ddetail['assignments'], $mdetail['role_id'], array()) as $pid => $pdetails) { $currentval[$pid] = $pdetails['name']; } if (empty($role_objects[$mdetail['role_id']])) { $role_objects[$mdetail['role_id']] =& $GLOBALS['system']->getDBObject('roster_role', $mdetail['role_id']); } if (empty($role_objects[$mdetail['role_id']])) { // must've been a problem continue; } $role_objects[$mdetail['role_id']]->printChooser($date, $currentval); } else { $names = array(); foreach (array_get($ddetail['assignments'], $mdetail['role_id'], array()) as $personid => $vs) { if (!$public && !$vs['assigneehidden']) { $n = '<a href="' . BASE_URL . '?view=persons&personid=' . $personid . '" title="Assigned by ' . ents($vs['assigner']) . ' on ' . format_datetime($vs['assignedon']) . '">' . nbsp(ents($vs['name'])) . '</a>'; if ('' === $vs['email']) { $n .= ' <img src="' . BASE_URL . 'resources/img/no_email.png" style="display:inline" title="No Email Address" />'; } $names[] = $n; } else { $names[] = nbsp($vs['name']); } } echo implode("<br />", $names); } } else { if (!empty($ddetail['service'][$mdetail['congregationid']])) { if ($public && (!defined('SHOW_SERVICE_NOTES_PUBLICLY') || !SHOW_SERVICE_NOTES_PUBLICLY)) { // no notes in public view unset($ddetail['service'][$mdetail['congregationid']]['notes']); } $dummy_service->populate($ddetail['service'][$mdetail['congregationid']]['id'], $ddetail['service'][$mdetail['congregationid']]); $dummy_service->printFieldvalue($mdetail['service_field']); } } ?> </td> <?php } if (!$public && count($this->_members) > REPEAT_DATE_THRESHOLD) { ?> <td class="nowrap thick-left-border"> <strong><?php echo str_replace(' ', ' ', date('j M y', strtotime($date))); ?> </strong> </td> <?php } ?> </tr> <?php } ?> </tbody> <?php if (!$public && count($to_print) > 6) { $this->_printTableFooter($editing, $public); } ?> </table> <?php if ($editing) { ?> <input type="submit" class="btn" value="Save" accesskey="s" /> </form> <?php } }