/** * Allows a user to create an event. * */ public function addEventAction() { $messages = array(); $get = Zend_Registry::get('getFilter'); $event = new Event(); $values = array(); if (isset($get->date)) { $values['date'] = $get->date; } $form = $event->form($values); if ($this->_request->isPost()) { if ($form->isValid($_POST)) { $workshopId = $form->getValue('workshop'); $locationId = $form->getValue('location'); $startTime = $form->getValue('startTime'); $endTime = $form->getValue('endTime'); $date = $form->getValue('date'); $minSize = $form->getValue('minSize'); $maxSize = $form->getValue('maxSize'); $waitlistSize = $form->getValue('waitlistSize'); $instructors = $form->getValue('instructors'); $password = $form->getValue('password'); $evaluationType = $form->getValue('evaluationType'); $formKey = $form->getValue('formKey'); $answerKey = $form->getValue('answerKey'); if (isset($formKey) && $formKey != '') { $regex = '(?<=key\\=)\\w*'; $matches = array(); preg_match_all("/" . $regex . "/is", $form->getValue('formKey'), $matches); $formKey = $matches[0][0]; } if (isset($answerKey) && $answerKey != '') { $regex = '(?<=key\\=)\\w*'; $matches = array(); preg_match_all("/" . $regex . "/is", $form->getValue('answerKey'), $matches); $answerKey = $matches[0][0]; } $date = strtotime($date); $date = strftime('%Y', $date) . "-" . strftime('%m', $date) . "-" . strftime('%d', $date); if (strtolower($startTime['meridian']) == "pm" && $startTime['hour'] < 12) { $startTime['hour'] += 12; } if (strtolower($startTime['meridian']) == "am" && $startTime['hour'] == 12) { $startTime['hour'] = 0; } if (strtolower($endTime['meridian']) == "pm" && $endTime['hour'] < 12) { $endTime['hour'] += 12; } if (strtolower($endTime['meridian']) == "am" && $endTime['hour'] == 12) { $endTime['hour'] = 0; } $timesOk = true; $st = new Zend_Date($date); $st->setHour($startTime['hour'])->setMinute($startTime['minute']); $et = new Zend_Date($date); $et->setHour($endTime['hour'])->setMinute($endTime['minute']); if ($st->isLater($et)) { $timesOk = false; $messages[] = "msg-error-eventStartsAfter"; } else { if ($st->equals($et)) { $timesOk = false; $messages[] = "msg-error-eventTimesEqual"; } } $startTime = $startTime['hour'] . ":" . $startTime['minute'] . ":00"; $endTime = $endTime['hour'] . ":" . $endTime['minute'] . ":00"; $where = $event->getAdapter()->quoteInto('date = ?', $date) . " AND " . $event->getAdapter()->quoteInto('locationId = ?', $locationId) . " AND " . $event->getAdapter()->quoteInto('status = ?', 'open'); $possibleConflicts = $event->fetchAll($where); $conflictFound = false; if ($possibleConflicts->count() > 0) { $startTs = strtotime($startTime); $endTs = strtoTime($endTime); foreach ($possibleConflicts as $pc) { $pcStart = strtotime($pc->startTime); $pcEnd = strtotime($pc->endTime); if ($startTs == $pcStart) { $conflictFound = true; } else { if ($startTs < $pcStart && $endTs > $pcStart) { $conflictFound = true; } else { if ($startTs >= $pcStart && $endTs <= $pcEnd) { $conflictFound = true; } else { if ($startTs < $pcEnd && $endTs >= $pcEnd) { $conflictFound = true; } else { if ($startTs < $pcStart && $endTime > $pcEnd) { $conflictFound = true; } } } } } if ($conflictFound) { $messages[] = "msg-error-eventAlreadyScheduled"; break; } } } $evaluationCheck = true; if ($evaluationType == 'google') { $evaluationCheck = isset($formKey) && isset($answerKey); } else { $evaluationCheck = $evaluationType == 'default'; } if (!$evaluationCheck) { $messages[] = 'msg-error-eventFormKeyMissing'; } if (!$conflictFound && $timesOk && $evaluationCheck) { $data = array('locationId' => $locationId, 'workshopId' => $workshopId, 'startTime' => $startTime, 'endTime' => $endTime, 'date' => $date, 'minSize' => $minSize, 'maxSize' => $maxSize, 'waitlistSize' => $waitlistSize, 'password' => $password, 'evaluationType' => $evaluationType, 'formKey' => $formKey, 'answerKey' => $answerKey); $eventId = $event->insert($data); $instructor = new Event_Instructor(); foreach ($instructors as $i) { $instructor->insert(array('accountId' => $i, 'eventId' => $eventId)); } $this->_helper->flashMessenger->addMessage('msg-info-eventAdded'); $date = explode('-', $date); $this->_helper->redirector->gotoUrl('/workshop/schedule?startYear=' . $date[0] . '&startMonth=' . (int) $date[1]); } } else { $messages[] = "msg-error-formSubmitProblem"; } } $this->view->messages = $messages; $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/jquery.autocomplete.js'); $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/workshop/schedule/help.js'); $this->view->headLink()->appendStylesheet($this->view->baseUrl() . '/css/jquery.autocomplete.css'); $this->view->headLink()->appendStylesheet($this->view->baseUrl() . '/css/workshop/schedule/help.css'); $this->view->form = $form; $this->_helper->pageTitle('workshop-schedule-addEvent:title'); }