Commit c7906147 authored by Tim Steiner's avatar Tim Steiner
Browse files

Merging changes from /branches/redesign up to r690.

parent 8df2eb46
......@@ -45,14 +45,17 @@ class Auth_IndexController extends App_Controller_Action {
public function logoutAction()
{
Zend_Auth::getInstance()->clearIdentity();
$this->_getCasAdapter()->clearIdentity();
$this->_redirect($this->_getCasAdapter()->getLogoutUrl());
}
public function validateAction()
{
$auth = Unl_Auth::getInstance();
$auth->pushAdapter($this->_getCasAdapter());
$auth = Unl_Auth::getInstance();
$casAdapter = $this->_getCasAdapter();
if ($this->_getParam('logoutRequest')) {
$casAdapter->handleLogoutRequest($this->_getParam('logoutRequest'));
}
$auth->pushAdapter($casAdapter);
try {
$result = $auth->authenticate();
......@@ -65,6 +68,9 @@ class Auth_IndexController extends App_Controller_Action {
if (!$user) {
$user = Auth_UserModel::fetchNewFromLdap($auth->getIdentity());
}
} else {
Zend_Auth::getInstance()->clearIdentity();
setcookie('unl_sso', 'fake', time() - 60*60*24, '/', '.unl.edu');
}
$session = new Zend_Session_Namespace(__CLASS__);
......
......@@ -96,7 +96,7 @@ class Auth_UserModel extends Unl_Model {
{
$username = Zend_Auth::getInstance()->getIdentity();
if (!$username) {
throw new Exception('You must be logged in to view this page.');
self::authenticateUser(TRUE);
}
return self::findByUsername($username);
......@@ -405,6 +405,39 @@ class Auth_UserModel extends Unl_Model {
$db->query($sql);
}
/**
* If the user is not currently logged in, calling this will attempt to log them in
* and if $required is TRUE, additionally redirect them to the login page.
* @param bool $required
*/
static public function authenticateUser($required = FALSE)
{
$redirectUri = $_SERVER['REQUEST_URI'];
$baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
$redirectUri = substr($redirectUri, strlen($baseUrl));
$authSession = new Zend_Session_Namespace('Auth_IndexController');
$authSession->referer = $redirectUri;
if ($_SERVER['HTTPS'] == 'on') {
$serviceUrl = 'https://';
} else {
$serviceUrl = 'http://';
}
$serviceUrl .= $_SERVER['SERVER_NAME'] . Zend_Controller_Front::getInstance()->getBaseUrl() . '/auth/index/validate';
$casAdapter = new Unl_Auth_Adapter_Cas($serviceUrl, 'https://login.unl.edu/cas');
if (!$required) {
$casAdapter->setGateway();
}
if ($casAdapter->isTicketExpired() || !Zend_Auth::getInstance()->hasIdentity()) {
header('Location: ' . $casAdapter->getLoginUrl());
exit;
}
}
public function __toString()
{
return $this->getFirstName() . ' ' . $this->getLastName();
......
......@@ -54,8 +54,8 @@ class Courses_PublicViewController extends App_Controller_Action {
if ($crosslisting['courseLetter']) {
$courseCodeNode->appendChild($dom->createElement('courseLetter', $crosslisting['courseLetter']));
}
if ($crosslisting['courseGroup']) {
$courseCodeNode->appendChild($dom->createElement('courseGroup', $crosslisting['courseGroup']));
foreach ($crosslisting['courseGroups'] as $courseGroup) {
$courseCodeNode->appendChild($dom->createElement('courseGroup', $courseGroup));
}
}
} else {
......
......@@ -152,7 +152,8 @@ class Courses_CourseModel extends Unl_Model
$select = new Zend_Db_Select($db);
$select->from(array('x' => 'creqCourseCrosslistings'), array('courseCrosslistingId', 'generation', 'type'));
$select->join(array('c' => 'creqCourseCodes'), 'x.courseCode = c.courseCodeId');
$select->joinLeft(array('u' => 'creqCourseGroups'), 'c.group = u.courseGroupId', array('courseGroup' => 'name'));
$select->joinLeft(array('g' => 'creqCourseCodeGroups'), 'c.courseCodeId = g.courseCode', array('courseCodeGroupId'));
$select->joinLeft(array('u' => 'creqCourseGroups'), 'g.group = u.courseGroupId', array('courseGroup' => 'name'));
$select->join(array('s' => 'creqSubjects'), 'c.subject = s.name', array());
$select->join(array('d' => 'creqDepartments'), 's.department = d.departmentId', array('department' => 'name'));
$select->join(array('cl' => 'creqColleges'), 'd.college = cl.collegeId', array('college' => 'name', 'collegeLong' => 'description'));
......@@ -162,6 +163,12 @@ class Courses_CourseModel extends Unl_Model
foreach($records as $record) {
$courseId = $record['generation'];
$crosslistingId = $record['courseCrosslistingId'];
$groups = (array)$courses[$courseId]['crosslistings'][$crosslistingId]['courseGroups'];
if ($record['courseGroup']) {
$groups[$record['courseCodeGroupId']] = $record['courseGroup'];
}
$record['courseGroups'] = $groups;
unset($record['courseGroup']);
$courses[$courseId]['crosslistings'][$crosslistingId] = $record;
}
......@@ -1717,7 +1724,7 @@ class Courses_CourseModel extends Unl_Model
if ($crosslisting['type'] != 'home listing') {
continue;
}
$homeNumber = str_pad($crosslisting['courseNumber'], 3, '0', STR_PAD_LEFT);
$homeNumber = $crosslisting['courseNumber'];
}
return $homeNumber;
}
......@@ -1769,7 +1776,7 @@ class Courses_CourseModel extends Unl_Model
continue;
}
$homeSubject = $crosslisting['subject'];
$courseNumbers[] = str_pad($crosslisting['courseNumber'], 3, '0', STR_PAD_LEFT) . $crosslisting['courseLetter'];
$courseNumbers[] = $crosslisting['courseNumber'] . $crosslisting['courseLetter'];
}
foreach ($this->_data['crosslistings'] as $crosslisting) {
if ($this->_isEffectiveHomeCrosslisting($crosslisting)) {
......@@ -1778,7 +1785,7 @@ class Courses_CourseModel extends Unl_Model
if ($crosslisting['subject'] != $homeSubject) {
continue;
}
$courseNumbers[] = str_pad($crosslisting['courseNumber'], 3, '0', STR_PAD_LEFT) . $crosslisting['courseLetter'];
$courseNumbers[] = $crosslisting['courseNumber'] . $crosslisting['courseLetter'];
}
sort($courseNumbers);
......@@ -1794,7 +1801,7 @@ class Courses_CourseModel extends Unl_Model
continue;
}
$homeSubject = $crosslisting['subject'];
$courseNumbers[] = str_pad($crosslisting['courseNumber'], 3, '0', STR_PAD_LEFT) . $crosslisting['courseLetter'];
$courseNumbers[] = $crosslisting['courseNumber'] . $crosslisting['courseLetter'];
}
foreach ($this->_data['crosslistings'] as $crosslisting) {
if ($this->_isEffectiveHomeCrosslisting($crosslisting)) {
......@@ -1803,7 +1810,7 @@ class Courses_CourseModel extends Unl_Model
if ($crosslisting['subject'] != $homeSubject) {
continue;
}
$courseNumbers[] = str_pad($crosslisting['courseNumber'], 3, '0', STR_PAD_LEFT) . $crosslisting['courseLetter'] . 'x';
$courseNumbers[] = $crosslisting['courseNumber'] . $crosslisting['courseLetter'] . 'x';
}
sort($courseNumbers);
......
<?php
$proposedCourses = Courses_CourseModel::findLatestOfRequest($this->requests);
$originalCourses = Courses_CourseModel::findParentOfRequest($this->requests);
$requestCourses = array();
foreach ($this->requests as $requset) {
$requestId = $requset->getId();
if ($originalCourses[$requestId]) {
$course = $originalCourses[$requestId];
} else {
$course = $proposedCourses[$requestId];
}
$requestCourses[$requestId] = $course;
}
$this->headLink()->appendStylesheet($this->baseUrl() . '/css/courses/queue-manager/request-table.css', 'all'); ?>
<table class="zentable primary" id="courseRequestTable">
<tr>
<th>Course Code</th>
<?php foreach ($this->users as $user) { ?>
<th><?php echo $user->getFirstName() . ' ' . $user->getLastName(); ?></th>
<?php } ?>
</tr>
<?php foreach ($this->requests as $request) {
$course = $requestCourses[$request->getId()];
$userVotes = $this->requestUserVotes[$request->getId()]; ?>
<tr>
<td><?php echo $course->getCourseCode(); ?></td>
<?php foreach ($this->users as $user) {
$vote = $userVotes[$user->getId()]; ?>
<td><?php echo $vote; ?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
\ No newline at end of file
<h1>Unfortunately an unexpected error has occured.</h1>
<h1>Unfortunately an unexpected error has occurred.</h1>
<h2>Details have been mailed to the administrator for analysis.</h2>
<p>
The error message was: "<?php echo $this->exceptions[0]->getMessage(); ?>"
</p>
<p>
We appologize for the inconvience.
We apologize for the inconvenience.
Please use the back button to return to your previous location
</p>
\ No newline at end of file
</p>
......@@ -9,7 +9,7 @@ if ($_SERVER['HTTPS']) {
$staticBaseUrl = 'http://';
}
$staticBaseUrl .= $_SERVER['HTTP_HOST']
. $baseUrl;
. $baseUrl . '/';
$this->headLink()->appendStylesheet($this->baseUrl() . '/css/index.css', 'all');
$this->headLink()->appendStylesheet($this->baseUrl() . '/css/print.css', 'print');
......
<?php
if (Zend_Auth::getInstance()->getIdentity()) {
$user = Auth_UserModel::findCurrentUser();
$roles = Auth_GroupModel::findByUser($user);
} else {
$user = NULL;
}
?>
<ul>
<?php if (Zend_Auth::getInstance()->getIdentity()) { ?>
<?php if ($user) { ?>
<li><a href="<?php echo $this->baseUrl(); ?>/requests">My Requests</a></li>
<li><a href="<?php echo $this->baseUrl(); ?>/requests/new">New Request</a></li>
<?php } ?>
......@@ -7,7 +16,21 @@
<li><a href="<?php echo $this->baseUrl(); ?>/courses/public-view/search">Curriculum Search</a></li>
<li><a href="<?php echo $this->baseUrl(); ?>/ucc/reports/monthly">UCC Activity</a></li>
<?php if (Zend_Auth::getInstance()->getIdentity()) { ?>
<?php if ($user && in_array(1, $roles->getId())) { ?>
<li>
<a>Admin</a>
<ul>
<li><a href="<?php echo $this->baseUrl(); ?>/auth/user-admin">Users &amp; Groups</a></li>
<li><a href="<?php echo $this->baseUrl(); ?>/requests/approval-body-admin">Approval Bodies</a></li>
<li><a href="<?php echo $this->baseUrl(); ?>/requests/approval-chain-manager">Approval Chains</a></li>
<li><a href="<?php echo $this->baseUrl(); ?>/requests/queue-manager">Queues</a></li>
<li><a href="<?php echo $this->baseUrl(); ?>/requests/withdrawn">Withdrawn Requests</a></li>
<li><a href="<?php echo $this->baseUrl(); ?>/requests/notification" dir="dir ">Notification List</a></li>
</ul>
</li>
<?php } ?>
<?php if ($user) { ?>
<li><a href="<?php echo $this->baseUrl(); ?>/auth/index/logout">Log Out</a></li>
<?php } else { ?>
<li><a href="<?php echo $this->baseUrl(); ?>/auth/index/login">Log In</a></li>
......
......@@ -16,7 +16,6 @@ class Requests_IndexController extends App_Controller_Action
*/
public function indexAction()
{
$this->_authorize->requireLogin();
$in = $this->getRequest()->getParams();
$user = Auth_UserModel::findCurrentUser();
......
......@@ -22,10 +22,58 @@ class Requests_QueueManagerController extends App_Controller_Action
{
$in = $this->_getAllParams();
$queue = Requests_ApprovalActionModel::find($in['id']);
$requests = Requests_RequestModel::findWithCurrentApprovalAction($queue);
$periodId = $in['period'];
if ($periodId > 0) {
$periods = $queue->getPeriods();
$period = $periods[$periodId];
$periodStart = $period['start']->addSecond(1);
$periodEnd = $period['end'];
$allRequests = Requests_ApprovalHistoryModel::findRequestsWithinTimeRangeAndApprovalAction(
$periodStart, $periodEnd, $queue
);
} else {
$allRequests = Requests_RequestModel::findWithCurrentApprovalAction($queue);
$periodEnd = new Zend_Date();
}
$moduleRequests = array();
foreach ($allRequests as $request) {
$module = $request->getModule();
if (!$moduleRequests[$module]) {
$moduleRequests[$module] = new Unl_Model_Collection('Requests_RequestModel');
}
$moduleRequests[$module][$request->getId()] = $request;
}
$periods = $queue->getPeriods();
$periodArray = array();
foreach ($periods as $periodId => $period) {
if ($period['end']) {
$periodArray[$periodId] = $period['end']->toString('YYYY-MM-dd');
} else {
$periodArray[-1] = 'Current';
}
}
$requestVotes = Requests_ApproverVoteModel::findVotesForRequests($allRequests, $periodEnd, $queue);
$requestUserVotes = array();
$userIds = array();
foreach ($requestVotes as $requestId => $votes) {
foreach ($votes as $voteId => $vote) {
$userIds[$vote->getUser()] = $vote->getUser();
$requestUserVotes[$requestId][$vote->getUser()] = $vote->getVote();
}
}
$users = Auth_UserModel::find($userIds);
$users->orderBy('getLastName');
$this->view->queue = $queue;
$this->view->requests = $requests;
$this->view->currentPeriod = $in['period'];
$this->view->periods = $periodArray;
$this->view->moduleRequests = $moduleRequests;
$this->view->requestUserVotes = $requestUserVotes;
$this->view->users = $users;
}
public function editPostAction()
......
......@@ -9,6 +9,9 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
$select = new Zend_Db_Select($db);
$select->from(array('a' => 'creqApprovalActions'));
$select->join(array('q' => 'creqApprovalActionsQueue'), 'a.approvalActionId = q.approvalActionId');
$select->join(array('p' => 'creqApprovalActionsQueuePeriods'),
'a.approvalActionId = p.approvalAction AND p.endTime IS NULL',
array('startTime', 'currentPeriod' => 'approvalActionsQueuePeriodId'));
if (Unl_Util::isArray($id)) {
$select->where('a.approvalActionId IN(?)', $id);
} else {
......@@ -38,6 +41,25 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
$date = $record['date'];
$objects[$objectId]->_data['dates'][] = new Zend_Date($date);
}
$select = new Zend_Db_Select($db);
$select->from(array('p' => 'creqApprovalActionsQueuePeriods'));
$select->order('startTime DESC');
if (Unl_Util::isArray($id)) {
$select->where('p.approvalAction IN(?)', $id);
} else {
$select->where('p.approvalAction = ?', $id);
}
$records = $db->query($select)->fetchAll();
foreach ($records as $record) {
$objectId = $record['approvalAction'];
$periodId = $record['approvalActionsQueuePeriodId'];
$objects[$objectId]->_data['periods'][$periodId] = array('start' => new Zend_Date($record['startTime']),
'end' => ($record['endTime'] ? new Zend_Date($record['endTime']) : NULL),
'id' => $record['approvalActionsQueuePeriodId']);
}
if (Unl_Util::isArray($objects)) {
return $objects;
......@@ -154,7 +176,8 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
static protected function _insert(Unl_Model_Collection $models)
{
$db = Zend_Registry::get('db');
// Insert the queue row
$sql = 'INSERT INTO creqApprovalActionsQueue (approvalActionId, canChangeVote) VALUES ';
$sqlParts = array();
foreach ($models as $model) {
......@@ -163,6 +186,18 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
}
$sql .= implode(', ', $sqlParts);
$db->query($sql);
// Insert the initial queue period starting at the current time.
$sql = 'INSERT INTO creqApprovalActionsQueuePeriods (approvalAction, startTime) VALUES ';
$sqlParts = array();
foreach ($models as $model) {
$sqlParts[] = $db->quoteInto('(?, ', $model->_data['approvalActionId'])
. $db->quoteInto('?)' , time());
}
$sql .= implode(', ', $sqlParts);
$db->query($sql);
}
static protected function _insertDates(array $models)
......@@ -248,6 +283,38 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
Requests_ApprovalChainModel::advance($requests);
Requests_ApprovalChainModel::consider($requests);
$select = new Zend_Db_Select($db);
$select->from(array('q' => 'creqApprovalActionsQueueDates'), array('approvalAction'));
$select->where('q.date <= ?', time());
$queueIds = array();
$records = $select->query()->fetchAll();
if (count($records) == 0) {
return;
}
foreach ($records as $record) {
$queueIds[] = $record['approvalAction'];
}
$sql = 'UPDATE creqApprovalActionsQueuePeriods '
. $db->quoteInto('SET endTime = ? ', time())
. 'WHERE endTime IS NULL '
. $db->quoteInto('AND approvalAction IN (?) ', $queueIds);
$db->query($sql);
$sql = 'INSERT INTO creqApprovalActionsQueuePeriods (approvalAction, startTime) VALUES ';
$sqlParts = array();
foreach ($queueIds as $queueId) {
$sqlParts[] = $db->quoteInto('(?, ', $queueId)
. $db->quoteInto('?)' , time());
}
$sql .= implode(', ', $sqlParts);
$db->query($sql);
$db->query($db->quoteInto('DELETE FROM creqApprovalActionsQueueDates WHERE date <= ?', time()));
}
......@@ -259,21 +326,12 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
public function userMadeDecisions($requests, $requestDecisions)
{
$user = Auth_UserModel::findCurrentUser();
$votes = Requests_ApproverVoteModel::findUsersVotesForRequests($user, $requests, $this);
$requestHistories = Requests_ApprovalHistoryModel::findByRequest($requests);
$votes = Requests_ApproverVoteModel::findUsersVotesForRequests($user, $requests, $this->getCurrentPeriodId());
foreach ($requests as $request) {
$histories = $requestHistories[$request->getId()];
$histories->orderBy('getUnixtime', SORT_DESC);
$lastEndTime = new Zend_Date(0);
foreach ($histories as $history) {
if ($history->getApprovalAction() == $this->getId()) {
$lastEndTime = $history->getTime();
break;
}
}
if ($votes[$request->getId()] && $votes[$request->getId()]->getApprovalAction() == $this->getId()) {
$vote = $votes[$request->getId()];
if (!$this->getCanChangeVote() && $lastEndTime->isEarlier($vote->getTime())) {
if ($votes[$request->getId()]) {
if ($this->getCanChangeVote()) {
$vote = $votes[$request->getId()];
} else {
continue;
}
} else {
......@@ -314,6 +372,11 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
$this->_data['dates'] = $dates;
}
public function getPeriods()
{
return $this->_data['periods'];
}
public function setExtendedData($data)
{
$this->_data['canChangeVote'] = $data['canChangeVote'];
......@@ -324,6 +387,8 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
continue;
}
$date = new Zend_Date();
$date->setDay(1);
$date->setYear($dateParts['year']);
$date->setMonth($dateParts['month']);
$date->setDay($dateParts['day']);
......@@ -336,5 +401,15 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
$this->setDates($dates);
}
public function getCurrentPeriodStartTime()
{
return new Zend_Date($this->_data['startTime']);
}
public function getCurrentPeriodId()
{
return $this->_data['currentPeriod'];
}
}
......@@ -10,6 +10,9 @@ class Requests_ApprovalActionVoteModel extends Requests_ApprovalActionQueueModel
$select->from(array('a' => 'creqApprovalActions'));
$select->join(array('q' => 'creqApprovalActionsQueue'), 'a.approvalActionId = q.approvalActionId');
$select->join(array('v' => 'creqApprovalActionsVote'), 'a.approvalActionId = v.approvalActionId');
$select->join(array('p' => 'creqApprovalActionsQueuePeriods'),
'a.approvalActionId = p.approvalAction AND p.endTime IS NULL',
array('startTime', 'currentPeriod' => 'approvalActionsQueuePeriodId'));
if (Unl_Util::isArray($id)) {
$select->where('a.approvalActionId IN(?)', $id);
} else {
......@@ -24,32 +27,39 @@ class Requests_ApprovalActionVoteModel extends Requests_ApprovalActionQueueModel
$objectId = $object->getId();
$objects[$objectId] = $object;
}
$select = new Zend_Db_Select($db);
$select->from(array('v' => 'creqApproverVotes'));
$select->from(array('d' => 'creqApprovalActionsQueueDates'));
if (Unl_Util::isArray($id)) {
$select->where('v.approvalAction IN(?)', $id);
$select->where('d.approvalAction IN(?)', $id);
} else {
$select->where('v.approvalAction = ?', $id);
$select->where('d.approvalAction = ?', $id);
}
$records = $select->query()->fetchAll();
$records = $db->query($select)->fetchAll();
foreach ($records as $record) {
$objects[$record['approvalAction']]->_data['votes'][$record['request']][$record['approverVoteId']] = $record;
$objectId = $record['approvalAction'];
$date = $record['date'];
$objects[$objectId]->_data['dates'][] = new Zend_Date($date);
}
$select = new Zend_Db_Select($db);
$select->from(array('d' => 'creqApprovalActionsQueueDates'));
$select->from(array('p' => 'creqApprovalActionsQueuePeriods'));
$select->order('startTime DESC');
if (Unl_Util::isArray($id)) {
$select->where('d.approvalAction IN(?)', $id);
$select->where('p.approvalAction IN(?)', $id);
} else {
$select->where('d.approvalAction = ?', $id);
$select->where('p.approvalAction = ?', $id);
}
$records = $db->query($select)->fetchAll();
foreach ($records as $record) {
$objectId = $record['approvalAction'];
$date = $record['date'];
$objects[$objectId]->_data['dates'][] = new Zend_Date($date);
$periodId = $record['approvalActionsQueuePeriodId'];
$objects[$objectId]->_data['periods'][$periodId] = array('start' => new Zend_Date($record['startTime']),
'end' => ($record['endTime'] ? new Zend_Date($record['endTime']) : NULL),
'id' => $record['approvalActionsQueuePeriodId']);
}
if (Unl_Util::isArray($objects)) {
......@@ -174,73 +184,12 @@ class Requests_ApprovalActionVoteModel extends Requests_ApprovalActionQueueModel
}
public function finalize($requests)
{
$requestHistories = Requests_ApprovalHistoryModel::findByRequest($requests);
{
$requestVotes = Requests_ApproverVoteModel::findVotesForRequests($requests, new Zend_Date(), $this);
foreach ($requests as $request) {
$votes = $this->_data['votes'][$request->getId()];