Exemple #1
0
 function testValidate()
 {
     $validDates = array(array('/', '01/01/01', DATE_FORMAT_MMDDYY), array('/', '02/27/05', DATE_FORMAT_MMDDYY), array('/', '02/28/05', DATE_FORMAT_MMDDYY), array('/', '02/29/04', DATE_FORMAT_MMDDYY), array('/', '02/29/00', DATE_FORMAT_MMDDYY), array('/', '12/31/05', DATE_FORMAT_MMDDYY), array('-', '12-31-05', DATE_FORMAT_MMDDYY), array('-', '02-29-00', DATE_FORMAT_MMDDYY), array('-', '22-02-07', DATE_FORMAT_DDMMYY), array('-', '2007-03-25', DATE_FORMAT_YYYYMMDD));
     $invalidDates = array(array('/', '00/00/00', DATE_FORMAT_MMDDYY), array('/', '02/29/05', DATE_FORMAT_MMDDYY), array('/', '02/31/05', DATE_FORMAT_MMDDYY), array('/', '13/01/05', DATE_FORMAT_MMDDYY), array('/', '00/01/05', DATE_FORMAT_MMDDYY), array('/', '12-01-05', DATE_FORMAT_MMDDYY), array('-', '00/01/05', DATE_FORMAT_MMDDYY), array('-', '00-01-05', DATE_FORMAT_MMDDYY), array('/', '00/01/2005', DATE_FORMAT_MMDDYY), array('-', '00/01/2005', DATE_FORMAT_MMDDYY), array('-', '00-01-2005', DATE_FORMAT_MMDDYY), array('-', '000105', DATE_FORMAT_MMDDYY), array('-', 'Test!', DATE_FORMAT_MMDDYY), array('-', '02-29-07', DATE_FORMAT_DDMMYY), array('-', '2007-03-40', DATE_FORMAT_YYYYMMDD), array('-', 'This sentence contains 12-01-05.', DATE_FORMAT_MMDDYY));
     foreach ($validDates as $key => $value) {
         $this->assertTrue(DateUtility::validate($value[0], $value[1], $value[2]), $value[1] . ' (Separator: ' . $value[0] . ')');
     }
     foreach ($invalidDates as $key => $value) {
         $this->assertFalse(DateUtility::validate($value[0], $value[1], $value[2]), $value[1] . ' (Separator: ' . $value[0] . ')');
     }
 }
}
if (!isset($_REQUEST['notes'])) {
    $interface->outputXMLErrorPage(-1, 'Invalid notes.');
    die;
}
$siteID = $interface->getSiteID();
$activityID = $_REQUEST['activityID'];
$type = $_REQUEST['type'];
$jobOrderID = $_REQUEST['jobOrderID'];
/* Decode and trim the activity notes from the company. */
$activityNote = trim(urldecode($_REQUEST['notes']));
$activityDate = trim(urldecode($_REQUEST['date']));
$activityHour = trim(urldecode($_REQUEST['hour']));
$activityMinute = trim(urldecode($_REQUEST['minute']));
$activityAMPM = trim(urldecode($_REQUEST['ampm']));
if (!DateUtility::validate('-', $activityDate, DATE_FORMAT_MMDDYY)) {
    die('Invalid availability date.');
    return;
}
/* Convert formatted time to UNIX timestamp. */
$time = strtotime(sprintf('%s:%s %s', $activityHour, $activityMinute, $activityAMPM));
/* Create MySQL date string w/ 24hr time (YYYY-MM-DD HH:MM:SS). */
$date = sprintf('%s %s', DateUtility::convert('-', $activityDate, DATE_FORMAT_MMDDYY, DATE_FORMAT_YYYYMMDD), date('H:i:00', $time));
/* Highlight what needs highlighting. */
if (strpos($activityNote, 'Status change: ') === 0) {
    $pipelines = new Pipelines($siteID);
    $statusRS = $pipelines->getStatusesForPicking();
    foreach ($statusRS as $data) {
        $activityNote = StringUtility::replaceOnce($data['status'], '<span style="color: #ff6c00;">' . $data['status'] . '</span>', $activityNote);
    }
}
Exemple #3
0
 /**
  * Processes an Add Activity / Schedule Event form and displays
  * contacts/AddActivityScheduleEventModal.tpl. This is factored out
  * for code clarity.
  *
  * @param boolean from joborders module perspective
  * @param integer "regarding" job order ID or -1
  * @param string module directory
  * @return void
  */
 private function _addActivityScheduleEvent($regardingID, $directoryOverride = '')
 {
     /* Module directory override for fatal() calls. */
     if ($directoryOverride != '') {
         $moduleDirectory = $directoryOverride;
     } else {
         $moduleDirectory = $this->_moduleDirectory;
     }
     /* Bail out if we don't have a valid candidate ID. */
     if (!$this->isRequiredIDValid('contactID', $_POST)) {
         CommonErrors::fatalModal(COMMONERROR_BADINDEX, $this, 'Invalid contact ID.');
     }
     $contactID = $_POST['contactID'];
     //if (!eval(Hooks::get('CONTACT_ON_ADD_ACTIVITY_SCHEDULE_EVENT_PRE'))) return;
     if ($this->isChecked('addActivity', $_POST)) {
         /* Bail out if we don't have a valid job order ID. */
         if (!$this->isOptionalIDValid('activityTypeID', $_POST)) {
             CommonErrors::fatalModal(COMMONERROR_BADINDEX, $this, 'Invalid activity type ID.');
         }
         $activityTypeID = $_POST['activityTypeID'];
         $activityNote = $this->getTrimmedInput('activityNote', $_POST);
         $activityNote = htmlspecialchars($activityNote);
         /* Add the activity entry. */
         $activityEntries = new ActivityEntries($this->_siteID);
         $activityID = $activityEntries->add($contactID, DATA_ITEM_CONTACT, $activityTypeID, $activityNote, $this->_userID, $regardingID);
         $activityTypes = $activityEntries->getTypes();
         $activityTypeDescription = ResultSetUtility::getColumnValueByIDValue($activityTypes, 'typeID', $activityTypeID, 'type');
         $activityAdded = true;
     } else {
         $activityAdded = false;
         $activityNote = '';
         $activityTypeDescription = '';
     }
     if ($this->isChecked('scheduleEvent', $_POST)) {
         /* Bail out if we received an invalid date. */
         $trimmedDate = $this->getTrimmedInput('dateAdd', $_POST);
         if (empty($trimmedDate) || !DateUtility::validate('-', $trimmedDate, DATE_FORMAT_MMDDYY)) {
             CommonErrors::fatalModal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid date.');
         }
         /* Bail out if we don't have a valid event type. */
         if (!$this->isRequiredIDValid('eventTypeID', $_POST)) {
             CommonErrors::fatalModal(COMMONERROR_BADINDEX, $this, 'Invalid event type ID.');
         }
         /* Bail out if we don't have a valid time format ID. */
         if (!isset($_POST['allDay']) || $_POST['allDay'] != '0' && $_POST['allDay'] != '1') {
             CommonErrors::fatalModal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid time format ID.');
         }
         $eventTypeID = $_POST['eventTypeID'];
         if ($_POST['allDay'] == 1) {
             $allDay = true;
         } else {
             $allDay = false;
         }
         $publicEntry = $this->isChecked('publicEntry', $_POST);
         $reminderEnabled = $this->isChecked('reminderToggle', $_POST);
         $reminderEmail = $this->getTrimmedInput('sendEmail', $_POST);
         $reminderTime = $this->getTrimmedInput('reminderTime', $_POST);
         $duration = -1;
         /* Is this a scheduled event or an all day event? */
         if ($allDay) {
             $date = DateUtility::convert('-', $trimmedDate, DATE_FORMAT_MMDDYY, DATE_FORMAT_YYYYMMDD);
             $hour = 12;
             $minute = 0;
             $meridiem = 'AM';
         } else {
             /* Bail out if we don't have a valid hour. */
             if (!isset($_POST['hour'])) {
                 CommonErrors::fatalModal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid hour.');
             }
             /* Bail out if we don't have a valid minute. */
             if (!isset($_POST['minute'])) {
                 CommonErrors::fatalModal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid minute.');
             }
             /* Bail out if we don't have a valid meridiem value. */
             if (!isset($_POST['meridiem']) || $_POST['meridiem'] != 'AM' && $_POST['meridiem'] != 'PM') {
                 CommonErrors::fatalModal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid meridiem value.');
             }
             $hour = $_POST['hour'];
             $minute = $_POST['minute'];
             $meridiem = $_POST['meridiem'];
             /* Convert formatted time to UNIX timestamp. */
             $time = strtotime(sprintf('%s:%s %s', $hour, $minute, $meridiem));
             /* Create MySQL date string w/ 24hr time (YYYY-MM-DD HH:MM:SS). */
             $date = sprintf('%s %s', DateUtility::convert('-', $trimmedDate, DATE_FORMAT_MMDDYY, DATE_FORMAT_YYYYMMDD), date('H:i:00', $time));
         }
         $description = $this->getTrimmedInput('description', $_POST);
         $title = $this->getTrimmedInput('title', $_POST);
         /* Bail out if any of the required fields are empty. */
         if (empty($title)) {
             CommonErrors::fatalModal(COMMONERROR_MISSINGFIELDS, $this, 'Required fields are missing.');
         }
         if ($regardingID > 0) {
             $eventJobOrderID = $regardingID;
         } else {
             $eventJobOrderID = -1;
         }
         $calendar = new Calendar($this->_siteID);
         $eventID = $calendar->addEvent($eventTypeID, $date, $description, $allDay, $this->_userID, $contactID, DATA_ITEM_CONTACT, $eventJobOrderID, $title, $duration, $reminderEnabled, $reminderEmail, $reminderTime, $publicEntry, $_SESSION['CATS']->getTimeZoneOffset());
         if ($eventID <= 0) {
             CommonErrors::fatalModal(COMMONERROR_RECORDERROR, $this, 'Failed to add calendar event.');
         }
         /* Extract the date parts from the specified date. */
         $parsedDate = strtotime($date);
         $formattedDate = date('l, F jS, Y', $parsedDate);
         $calendar = new Calendar($this->_siteID);
         $calendarEventTypes = $calendar->getAllEventTypes();
         $eventTypeDescription = ResultSetUtility::getColumnValueByIDValue($calendarEventTypes, 'typeID', $eventTypeID, 'description');
         $eventHTML = sprintf('<p>An event of type <span class="bold">%s</span> has been scheduled on <span class="bold">%s</span>.</p>', htmlspecialchars($eventTypeDescription), htmlspecialchars($formattedDate));
         $eventScheduled = true;
     } else {
         $eventHTML = '<p>No event has been scheduled.</p>';
         $eventScheduled = false;
     }
     if (isset($_GET['onlyScheduleEvent'])) {
         $onlyScheduleEvent = true;
     } else {
         $onlyScheduleEvent = false;
     }
     if (!$activityAdded && !$eventScheduled) {
         $changesMade = false;
     } else {
         $changesMade = true;
     }
     if (!eval(Hooks::get('CANDIDATE_ON_ADD_ACTIVITY_CHANGE_STATUS_POST'))) {
         return;
     }
     $this->_template->assign('contactID', $contactID);
     $this->_template->assign('regardingID', $regardingID);
     $this->_template->assign('activityAdded', $activityAdded);
     $this->_template->assign('activityDescription', $activityNote);
     $this->_template->assign('activityType', $activityTypeDescription);
     $this->_template->assign('eventScheduled', $eventScheduled);
     $this->_template->assign('onlyScheduleEvent', $onlyScheduleEvent);
     $this->_template->assign('eventHTML', $eventHTML);
     $this->_template->assign('changesMade', $changesMade);
     $this->_template->assign('isFinishedMode', true);
     $this->_template->display('./modules/contacts/AddActivityScheduleEventModal.tpl');
 }
Exemple #4
0
    public function onEditEvent()
    {
        if ($this->_accessLevel < ACCESS_LEVEL_EDIT)
        {
            CommonErrors::fatal(COMMONERROR_PERMISSION, $this, 'Invalid user level for action.');
        }

        /* Bail out if we don't have a valid event ID. */
        if (!$this->isRequiredIDValid('eventID', $_POST))
        {
            CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid event ID.');
        }

        // FIXME: typeID
        /* Bail out if we don't have a valid event type. */
        if (!$this->isRequiredIDValid('type', $_POST))
        {
            CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid event type ID.');
        }

        /* If we don't have a valid event duration, set duration to 30. */
        if (!$this->isOptionalIDValid('duration', $_POST))
        {
            $duration = 30;
        }
        else
        {
            $duration = $_POST['duration'];
        }

        /* If we have a valid data item type / ID, associate it. */
        if ($this->isRequiredIDValid('dataItemID', $_POST) &&
            $this->isRequiredIDValid('dataItemType', $_POST))
        {
            $dataItemID   = $_POST['dataItemID'];
            $dataItemType = $_POST['dataItemType'];
        }
        else
        {
            $dataItemID   = 'NULL';
            $dataItemType = 'NULL';
        }

        /* If we have a valid job order ID, associate it. */
        if ($this->isRequiredIDValid('jobOrderID', $_POST))
        {
            $jobOrderID   = $_POST['jobOrderID'];
        }
        else
        {
            $jobOrderID   = 'NULL';
        }

        /* Bail out if we received an invalid date. */
        $trimmedDate = $this->getTrimmedInput('dateEdit', $_POST);
        if (empty($trimmedDate) ||
            !DateUtility::validate('-', $trimmedDate, DATE_FORMAT_MMDDYY))
        {
            CommonErrors::fatal(COMMONERROR_BADFIELDS, $this, 'Invalid date.');
        }

        /* Bail out if we don't have a valid time format ID. */
        if (!isset($_POST['allDay']) ||
            ($_POST['allDay'] != '0' && $_POST['allDay'] != '1'))
        {
            CommonErrors::fatal(COMMONERROR_BADFIELDS, $this, 'Invalid time format ID.');
        }

        $eventID  = $_POST['eventID'];
        $type     = $_POST['type'];

        if ($_POST['allDay'] == 1)
        {
            $allDay = true;
        }
        else
        {
            $allDay = false;
        }

        $publicEntry     = $this->isChecked('publicEntry', $_POST);
        $reminderEnabled = $this->isChecked('reminderToggle', $_POST);

        $description   = $this->getTrimmedInput('description', $_POST);
        $title         = $this->getTrimmedInput('title', $_POST);
        $reminderEmail = $this->getTrimmedInput('sendEmail', $_POST);
        $reminderTime  = $this->getTrimmedInput('reminderTime', $_POST);

        // FIXME: Reminder time must be an integer!

        /* Bail out if any of the required fields are empty. */
        if (empty($title))
        {
            CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Required fields are missing.');
        }

        /* Is this a scheduled event or an all day event? */
        if ($allDay)
        {
            $date = DateUtility::convert(
                '-', $trimmedDate, DATE_FORMAT_MMDDYY, DATE_FORMAT_YYYYMMDD
            );

            $hour = 12;
            $minute = 0;
            $meridiem = 'AM';
        }
        else
        {
            /* Bail out if we don't have a valid hour. */
            if (!isset($_POST['hour']))
            {
                CommonErrors::fatal(COMMONERROR_BADFIELDS, $this, 'Invalid hour.');
            }

            /* Bail out if we don't have a valid minute. */
            if (!isset($_POST['minute']))
            {
                CommonErrors::fatal(COMMONERROR_BADFIELDS, $this, 'Invalid minute.');
            }

            /* Bail out if we don't have a valid meridiem value. */
            if (!isset($_POST['meridiem']) ||
                ($_POST['meridiem'] != 'AM' && $_POST['meridiem'] != 'PM'))
            {
                CommonErrors::fatal(COMMONERROR_BADFIELDS, $this, 'Invalid meridiem value.');
            }

            $hour     = $_POST['hour'];
            $minute   = $_POST['minute'];
            $meridiem = $_POST['meridiem'];

            /* Convert formatted time to UNIX timestamp. */
            $time = strtotime(
                sprintf('%s:%s %s', $hour, $minute, $meridiem)
            );

            /* Create MySQL date string w/ 24hr time (YYYY-MM-DD HH:MM:SS). */
            $date = sprintf(
                '%s %s',
                DateUtility::convert(
                    '-', $trimmedDate, DATE_FORMAT_MMDDYY, DATE_FORMAT_YYYYMMDD
                ),
                date('H:i:00', $time)
            );
        }

        if (!eval(Hooks::get('CALENDAR_EDIT_PRE'))) return;

        /* Update the event. */
        $calendar = new Calendar($this->_siteID);
        if (!$calendar->updateEvent($eventID, $type, $date, $description,
            $allDay, $dataItemID, $dataItemType, 'NULL', $title, $duration,
            $reminderEnabled, $reminderEmail, $reminderTime, $publicEntry,
            $_SESSION['CATS']->getTimeZoneOffset()))
        {
            CommonErrors::fatal(COMMONERROR_RECORDERROR, $this, 'Failed to update calendar event.');
        }

        if (!eval(Hooks::get('CALENDAR_EDIT_POST'))) return;

        /* Extract the date parts from the specified date. */
        $parsedDate = strtotime($date);
        $day   = date('j', $parsedDate);
        $month = date('n', $parsedDate);
        $year  = date('Y', $parsedDate);

        /* Transfer to same url without a=editEvent. */
        $newGet = $_GET;
        $newParams = array();

        unset($newGet['a']);
        $newGet['showEvent'] = $eventID;

        foreach ($newGet AS $name => $value)
        {
            $newParams[] = urlencode($name) . '=' . urlencode($value);
        }

        CATSUtility::transferRelativeURI(implode('&', $newParams));
    }
 private function onEdit()
 {
     if ($this->_accessLevel < ACCESS_LEVEL_EDIT) {
         CommonErrors::fatal(COMMONERROR_PERMISSION, $this, 'Invalid user level for action.');
     }
     $jobOrders = new JobOrders($this->_siteID);
     /* Bail out if we don't have a valid job order ID. */
     if (!$this->isRequiredIDValid('jobOrderID', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid job order ID.');
     }
     $jobOrderID = $_POST['jobOrderID'];
     /* Bail out if we don't have a valid company ID. */
     if (!$this->isRequiredIDValid('companyID', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid company ID.');
     }
     /* Bail out if we don't have a valid contact ID. */
     if (!$this->isOptionalIDValid('contactID', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid contact ID.');
     }
     /* Bail out if we don't have a valid recruiter user ID. */
     if (!$this->isRequiredIDValid('recruiter', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid recruiter user ID.');
     }
     /* Bail out if we don't have a valid owner user ID. */
     if (!$this->isOptionalIDValid('owner', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid owner user ID.');
     }
     /* Bail out if we received an invalid start date; if not, go ahead and
      * convert the date to MySQL format.
      */
     $startDate = $this->getTrimmedInput('startDate', $_POST);
     if (!empty($startDate)) {
         if (!DateUtility::validate('-', $startDate, DATE_FORMAT_MMDDYY)) {
             CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid start date.');
             return;
         }
         /* Convert start_date to something MySQL can understand. */
         $startDate = DateUtility::convert('-', $startDate, DATE_FORMAT_MMDDYY, DATE_FORMAT_YYYYMMDD);
     }
     /* Bail out if we received an invalid status. */
     /* FIXME: Check actual status codes. */
     if (!isset($_POST['status']) || empty($_POST['status'])) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid status.');
     }
     if (isset($_POST['openings']) && !empty($_POST['openings']) && !ctype_digit((string) $_POST['openings'])) {
         CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid number of openings.');
     }
     /* Hot job? */
     $isHot = $this->isChecked('isHot', $_POST);
     /* Public Job? */
     $public = $this->isChecked('public', $_POST);
     /* If it is public, is a questionnaire attached? */
     $questionnaireID = isset($_POST['questionnaire']) && !empty($_POST['questionnaire']) && strcmp($_POST['questionnaire'], 'none') && $public ? intval($_POST['questionnaire']) : false;
     $companyID = $_POST['companyID'];
     $contactID = $_POST['contactID'];
     $owner = $_POST['owner'];
     $recruiter = $_POST['recruiter'];
     $openings = $_POST['openings'];
     $openingsAvailable = $_POST['openingsAvailable'];
     /* Change ownership email? */
     if ($this->isChecked('ownershipChange', $_POST) && $owner > 0) {
         $jobOrderDetails = $jobOrders->get($jobOrderID);
         $users = new Users($this->_siteID);
         $ownerDetails = $users->get($_POST['owner']);
         if (!empty($ownerDetails)) {
             $emailAddress = $ownerDetails['email'];
             /* Get the change status email template. */
             $emailTemplates = new EmailTemplates($this->_siteID);
             $statusChangeTemplateRS = $emailTemplates->getByTag('EMAIL_TEMPLATE_OWNERSHIPASSIGNJOBORDER');
             if (empty($statusChangeTemplateRS) || empty($statusChangeTemplateRS['textReplaced'])) {
                 $statusChangeTemplate = '';
             } else {
                 $statusChangeTemplate = $statusChangeTemplateRS['textReplaced'];
             }
             /* Replace e-mail template variables. */
             $stringsToFind = array('%JBODOWNER%', '%JBODTITLE%', '%JBODCLIENT%', '%JBODID%', '%JBODCATSURL%');
             $replacementStrings = array($ownerDetails['fullName'], $jobOrderDetails['title'], $jobOrderDetails['companyName'], $jobOrderID, '<a href="http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=joborders&amp;a=show&amp;jobOrderID=' . $jobOrderID . '">' . 'http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=joborders&amp;a=show&amp;jobOrderID=' . $jobOrderID . '</a>');
             $statusChangeTemplate = str_replace($stringsToFind, $replacementStrings, $statusChangeTemplate);
             $email = $statusChangeTemplate;
         } else {
             $email = '';
             $emailAddress = '';
         }
     } else {
         $email = '';
         $emailAddress = '';
     }
     $title = $this->getTrimmedInput('title', $_POST);
     $companyJobID = $this->getTrimmedInput('companyJobID', $_POST);
     $type = $this->getTrimmedInput('type', $_POST);
     $city = $this->getTrimmedInput('city', $_POST);
     $state = $this->getTrimmedInput('state', $_POST);
     $status = $this->getTrimmedInput('status', $_POST);
     $duration = $this->getTrimmedInput('duration', $_POST);
     $department = $this->getTrimmedInput('department', $_POST);
     $maxRate = $this->getTrimmedInput('maxRate', $_POST);
     $salary = $this->getTrimmedInput('salary', $_POST);
     $description = $this->getTrimmedInput('description', $_POST);
     $notes = $this->getTrimmedInput('notes', $_POST);
     /* Bail out if any of the required fields are empty. */
     if (empty($title) || empty($type) || empty($city) || empty($state)) {
         CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Required fields are missing.');
     }
     if (!eval(Hooks::get('JO_ON_EDIT_PRE'))) {
         return;
     }
     if (!$jobOrders->update($jobOrderID, $title, $companyJobID, $companyID, $contactID, $description, $notes, $duration, $maxRate, $type, $isHot, $openings, $openingsAvailable, $salary, $city, $state, $startDate, $status, $recruiter, $owner, $public, $email, $emailAddress, $department, $questionnaireID)) {
         CommonErrors::fatal(COMMONERROR_RECORDERROR, $this, 'Failed to update job order.');
     }
     /* Update extra fields. */
     $jobOrders->extraFields->setValuesOnEdit($jobOrderID);
     if (!eval(Hooks::get('JO_ON_EDIT_POST'))) {
         return;
     }
     CATSUtility::transferRelativeURI('m=joborders&a=show&jobOrderID=' . $jobOrderID);
 }
 /**
  * Processes an Add Activity / Change Status form and displays
  * candidates/AddActivityChangeStatusModal.tpl. This is factored out
  * for code clarity.
  *
  * @param boolean from joborders module perspective
  * @param integer "regarding" job order ID or -1
  * @param string module directory
  * @return void
  */
 private function _addActivityChangeStatus($isJobOrdersMode, $regardingID, $directoryOverride = '')
 {
     $notificationHTML = '';
     $pipelines = new Pipelines($this->_siteID);
     $statusRS = $pipelines->getStatusesForPicking();
     /* Module directory override for fatal() calls. */
     if ($directoryOverride != '') {
         $moduleDirectory = $directoryOverride;
     } else {
         $moduleDirectory = $this->_moduleDirectory;
     }
     /* Bail out if we don't have a valid candidate ID. */
     if (!$this->isRequiredIDValid('candidateID', $_POST)) {
         CommonErrors::fatalModal(COMMONERROR_BADINDEX, $this, 'Invalid candidate ID.');
     }
     /* Do we have a valid status ID. */
     if (!$this->isOptionalIDValid('statusID', $_POST)) {
         $statusID = -1;
     } else {
         $statusID = $_POST['statusID'];
     }
     $candidateID = $_POST['candidateID'];
     if (!eval(Hooks::get('CANDIDATE_ON_ADD_ACTIVITY_CHANGE_STATUS_PRE'))) {
         return;
     }
     if ($this->isChecked('addActivity', $_POST)) {
         /* Bail out if we don't have a valid job order ID. */
         if (!$this->isOptionalIDValid('activityTypeID', $_POST)) {
             CommonErrors::fatalModal(COMMONERROR_BADINDEX, $this, 'Invalid activity type ID.');
         }
         $activityTypeID = $_POST['activityTypeID'];
         $activityNote = $this->getTrimmedInput('activityNote', $_POST);
         $activityNote = htmlspecialchars($activityNote);
         // FIXME: Move this to a highlighter-method? */
         if (strpos($activityNote, 'Status change: ') === 0) {
             foreach ($statusRS as $data) {
                 $activityNote = StringUtility::replaceOnce($data['status'], '<span style="color: #ff6c00;">' . $data['status'] . '</span>', $activityNote);
             }
         }
         /* Add the activity entry. */
         $activityEntries = new ActivityEntries($this->_siteID);
         $activityID = $activityEntries->add($candidateID, DATA_ITEM_CANDIDATE, $activityTypeID, $activityNote, $this->_userID, $regardingID);
         $activityTypes = $activityEntries->getTypes();
         $activityTypeDescription = ResultSetUtility::getColumnValueByIDValue($activityTypes, 'typeID', $activityTypeID, 'type');
         $activityAdded = true;
     } else {
         $activityAdded = false;
         $activityNote = '';
         $activityTypeDescription = '';
     }
     if ($regardingID <= 0 || $statusID == -1) {
         $statusChanged = false;
         $oldStatusDescription = '';
         $newStatusDescription = '';
     } else {
         $data = $pipelines->get($candidateID, $regardingID);
         /* Bail out if we got an empty result set. */
         if (empty($data)) {
             $this->fatalModal('The specified pipeline entry could not be found.');
         }
         $validStatus = ResultSetUtility::findRowByColumnValue($statusRS, 'statusID', $statusID);
         /* If the status is invalid or unchanged, don't mess with it. */
         if ($validStatus === false || $statusID == $data['status']) {
             $oldStatusDescription = '';
             $newStatusDescription = '';
             $statusChanged = false;
         } else {
             $oldStatusDescription = $data['status'];
             $newStatusDescription = ResultSetUtility::getColumnValueByIDValue($statusRS, 'statusID', $statusID, 'status');
             if ($oldStatusDescription != $newStatusDescription) {
                 $statusChanged = true;
             } else {
                 $statusChanged = false;
             }
         }
         if ($statusChanged && $this->isChecked('triggerEmail', $_POST)) {
             $customMessage = $this->getTrimmedInput('customMessage', $_POST);
             // FIXME: Actually validate the e-mail address?
             if (empty($data['candidateEmail'])) {
                 $email = '';
                 $notificationHTML = '<p><span class="bold">Error:</span> An e-mail notification' . ' could not be sent to the candidate because the candidate' . ' does not have a valid e-mail address.</p>';
             } else {
                 if (empty($customMessage)) {
                     $email = '';
                     $notificationHTML = '<p><span class="bold">Error:</span> An e-mail notification' . ' will not be sent because the message text specified was blank.</p>';
                 } else {
                     if ($this->_accessLevel == ACCESS_LEVEL_DEMO) {
                         $email = '';
                         $notificationHTML = '<p><span class="bold">Error:</span> Demo users can not send' . ' E-Mails.  No E-Mail was sent.</p>';
                     } else {
                         $email = $data['candidateEmail'];
                         $notificationHTML = '<p>An e-mail notification has been sent to the candidate.</p>';
                     }
                 }
             }
         } else {
             $email = '';
             $customMessage = '';
             $notificationHTML = '<p>No e-mail notification has been sent to the candidate.</p>';
         }
         /* Set the pipeline entry's status, but don't send e-mails for now. */
         $pipelines->setStatus($candidateID, $regardingID, $statusID, $email, $customMessage);
         /* If status = placed, and open positions > 0, reduce number of open positions by one. */
         if ($statusID == PIPELINE_STATUS_PLACED && is_numeric($data['openingsAvailable']) && $data['openingsAvailable'] > 0) {
             $jobOrders = new JobOrders($this->_siteID);
             $jobOrders->updateOpeningsAvailable($regardingID, $data['openingsAvailable'] - 1);
         }
     }
     if ($this->isChecked('scheduleEvent', $_POST)) {
         /* Bail out if we received an invalid date. */
         $trimmedDate = $this->getTrimmedInput('dateAdd', $_POST);
         if (empty($trimmedDate) || !DateUtility::validate('-', $trimmedDate, DATE_FORMAT_MMDDYY)) {
             CommonErrors::fatalModal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid date.');
         }
         /* Bail out if we don't have a valid event type. */
         if (!$this->isRequiredIDValid('eventTypeID', $_POST)) {
             CommonErrors::fatalModal(COMMONERROR_BADINDEX, $this, 'Invalid event type ID.');
         }
         /* Bail out if we don't have a valid time format ID. */
         if (!isset($_POST['allDay']) || $_POST['allDay'] != '0' && $_POST['allDay'] != '1') {
             CommonErrors::fatalModal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid time format ID.');
         }
         $eventTypeID = $_POST['eventTypeID'];
         if ($_POST['allDay'] == 1) {
             $allDay = true;
         } else {
             $allDay = false;
         }
         $publicEntry = $this->isChecked('publicEntry', $_POST);
         $reminderEnabled = $this->isChecked('reminderToggle', $_POST);
         $reminderEmail = $this->getTrimmedInput('sendEmail', $_POST);
         $reminderTime = $this->getTrimmedInput('reminderTime', $_POST);
         $duration = $this->getTrimmedInput('duration', $_POST);
         /* Is this a scheduled event or an all day event? */
         if ($allDay) {
             $date = DateUtility::convert('-', $trimmedDate, DATE_FORMAT_MMDDYY, DATE_FORMAT_YYYYMMDD);
             $hour = 12;
             $minute = 0;
             $meridiem = 'AM';
         } else {
             /* Bail out if we don't have a valid hour. */
             if (!isset($_POST['hour'])) {
                 CommonErrors::fatalModal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid hour.');
             }
             /* Bail out if we don't have a valid minute. */
             if (!isset($_POST['minute'])) {
                 CommonErrors::fatalModal(COMMONERROR_MISSINGFIELDS, $this, 'Invalid minute.');
             }
             /* Bail out if we don't have a valid meridiem value. */
             if (!isset($_POST['meridiem']) || $_POST['meridiem'] != 'AM' && $_POST['meridiem'] != 'PM') {
                 $this->fatalModal('Invalid meridiem value.', $moduleDirectory);
             }
             $hour = $_POST['hour'];
             $minute = $_POST['minute'];
             $meridiem = $_POST['meridiem'];
             /* Convert formatted time to UNIX timestamp. */
             $time = strtotime(sprintf('%s:%s %s', $hour, $minute, $meridiem));
             /* Create MySQL date string w/ 24hr time (YYYY-MM-DD HH:MM:SS). */
             $date = sprintf('%s %s', DateUtility::convert('-', $trimmedDate, DATE_FORMAT_MMDDYY, DATE_FORMAT_YYYYMMDD), date('H:i:00', $time));
         }
         $description = $this->getTrimmedInput('description', $_POST);
         $title = $this->getTrimmedInput('title', $_POST);
         /* Bail out if any of the required fields are empty. */
         if (empty($title)) {
             CommonErrors::fatalModal(COMMONERROR_MISSINGFIELDS, $this);
             return;
             /*$this->fatalModal(
                   'Required fields are missing.', $moduleDirectory
               );*/
         }
         if ($regardingID > 0) {
             $eventJobOrderID = $regardingID;
         } else {
             $eventJobOrderID = -1;
         }
         $calendar = new Calendar($this->_siteID);
         $eventID = $calendar->addEvent($eventTypeID, $date, $description, $allDay, $this->_userID, $candidateID, DATA_ITEM_CANDIDATE, $eventJobOrderID, $title, $duration, $reminderEnabled, $reminderEmail, $reminderTime, $publicEntry, $_SESSION['CATS']->getTimeZoneOffset());
         if ($eventID <= 0) {
             $this->fatalModal('Failed to add calendar event.', $moduleDirectory);
         }
         /* Extract the date parts from the specified date. */
         $parsedDate = strtotime($date);
         $formattedDate = date('l, F jS, Y', $parsedDate);
         $calendar = new Calendar($this->_siteID);
         $calendarEventTypes = $calendar->getAllEventTypes();
         $eventTypeDescription = ResultSetUtility::getColumnValueByIDValue($calendarEventTypes, 'typeID', $eventTypeID, 'description');
         $eventHTML = sprintf('<p>An event of type <span class="bold">%s</span> has been scheduled on <span class="bold">%s</span>.</p>', htmlspecialchars($eventTypeDescription), htmlspecialchars($formattedDate));
         $eventScheduled = true;
     } else {
         $eventHTML = '<p>No event has been scheduled.</p>';
         $eventScheduled = false;
     }
     if (isset($_GET['onlyScheduleEvent'])) {
         $onlyScheduleEvent = true;
     } else {
         $onlyScheduleEvent = false;
     }
     if (!$statusChanged && !$activityAdded && !$eventScheduled) {
         $changesMade = false;
     } else {
         $changesMade = true;
     }
     if (!eval(Hooks::get('CANDIDATE_ON_ADD_ACTIVITY_CHANGE_STATUS_POST'))) {
         return;
     }
     $this->_template->assign('candidateID', $candidateID);
     $this->_template->assign('regardingID', $regardingID);
     $this->_template->assign('oldStatusDescription', $oldStatusDescription);
     $this->_template->assign('newStatusDescription', $newStatusDescription);
     $this->_template->assign('statusChanged', $statusChanged);
     $this->_template->assign('activityAdded', $activityAdded);
     $this->_template->assign('activityDescription', $activityNote);
     $this->_template->assign('activityType', $activityTypeDescription);
     $this->_template->assign('eventScheduled', $eventScheduled);
     $this->_template->assign('eventHTML', $eventHTML);
     $this->_template->assign('notificationHTML', $notificationHTML);
     $this->_template->assign('onlyScheduleEvent', $onlyScheduleEvent);
     $this->_template->assign('changesMade', $changesMade);
     $this->_template->assign('isFinishedMode', true);
     $this->_template->assign('isJobOrdersMode', $isJobOrdersMode);
     $this->_template->display('./modules/candidates/AddActivityChangeStatusModal.tpl');
 }