function getSaving($source, $destination)
{
    $data = getDistance($source, $destination);
    $fare = calculateFare($data["distance"]);
    $duration = minToHours(calculateDuration($data["distance"]));
    $start_date = "06/03/2015";
    $end_date = "09/03/2015";
    $geoCordinates = get_lat_long($destination);
    $hotelPrice = getStayzillahotel($geoCordinates[0], $geoCordinates[1], $start_date, $end_date);
    $Price = $hotelPrice->hotels[0]->rawPrice;
    $stayzillaSource = $hotelPrice->hotels[0]->address;
    $data_User = array("distance" => $data["distance"], "duration" => $duration, "cabFare" => $fare);
    $stayzillaData = getDistance($stayzillaSource, $destination);
    $stayZillaDistance = number_format((double) $hotelPrice->hotels[0]->distanceFromLatLong / 1000, 2, '.', '');
    $stayzillafare = calculateFare($stayZillaDistance);
    $stayzillaDuration = minToHours(calculateDuration($stayZillaDistance));
    $data_stayzilla = array("distance" => $stayZillaDistance . " km", "duration" => $stayzillaDuration, "cabFare" => $stayzillafare, "hotelFare" => $Price, "hotelData" => $hotelPrice->hotels[0]);
    $responceData = array();
    $responceData["user"] = $data_User;
    $responceData["stayzilla"] = $data_stayzilla;
    return json_encode($responceData);
}
 $period = $shift['period'];
 $employee = $shift['employee'];
 $hourType = $shift['hourType'];
 // This line translates the start date back into our websites standard of Saturday=0, Sunday=1, . . . Friday=6
 // Just for determining duration, the $startDate is used for all other instances
 if ($startDate != '7') {
     $pretendStartDate = $startDate;
 } else {
     $pretendStartDate = '0';
 }
 if ($endDate == '7' && $startDate == '7') {
     $pretendEndDate = '0';
 } else {
     $pretendEndDate = $endDate;
 }
 $hourTotal = calculateDuration('2011-01-1' . $pretendStartDate . ' ' . $startTime . ':00', '2011-01-1' . $pretendEndDate . ' ' . $endTime . ':00');
 try {
     $semestersQuery = $db->prepare("SELECT * FROM scheduleSemesters WHERE ID=:period");
     $semestersQuery->execute(array(':period' => $period));
 } catch (PDOException $e) {
     exit("error in query");
 }
 $semester = $semestersQuery->fetch(PDO::FETCH_ASSOC);
 $periodStart = date('Y-m-d H:i:s', strtotime("today"));
 // This seems a bit strange but we add the day because the entire day is considered part of the current period so the truth is the period ends at the end of the end date (i.e. the start of the next day)
 // Also I didn't just add 86400000 milliseconds (i.e. the duration of the average day in milliseconds) because due to daylight savings some days are longer and some days are shorter.
 $periodEnd = Date('Y-m-d', strtotime('+1 day', strtotime($semester['endDate']))) . ' 00:00:00';
 // Check to see if the period's start date is a future date, if so use that as the period start
 // If not then use today's date as the start of the period for conflict checks.
 if (strtotime($semester['startDate']) > strtotime($periodStart)) {
     $periodStart = $semester['startDate'] . ' 00:00:00';
Example #3
0
function processWorkspace()
{
    try {
        global $sObject;
        global $sLastExecution;
        resendEmails();
        unpauseApplications();
        calculateDuration();
        executeEvents($sLastExecution);
        executeScheduledCases();
        executeUpdateAppTitle();
        executeCaseSelfService();
        executePlugins();
    } catch (Exception $oError) {
        saveLog("main", "error", "Error processing workspace : " . $oError->getMessage() . "\n");
    }
}
Example #4
0
function processWorkspace()

{

    try {

        Bootstrap::LoadClass("plugin");

        $oPluginRegistry =& PMPluginRegistry::getSingleton();

        if (file_exists(PATH_DATA_SITE . 'plugin.singleton')) {

            $oPluginRegistry->unSerializeInstance(file_get_contents(PATH_DATA_SITE . 'plugin.singleton'));

        }

        Bootstrap::LoadClass("case");



        global $sObject;

        global $sLastExecution;



        resendEmails();

        unpauseApplications();

        calculateDuration();

        /*----------------------------------********---------------------------------*/

        executeEvents($sLastExecution);

        executeScheduledCases();

        executeUpdateAppTitle();

        executeCaseSelfService();

        executePlugins();

        /*----------------------------------********---------------------------------*/

    } catch (Exception $oError) {

        saveLog("main", "error", "Error processing workspace : " . $oError->getMessage() . "\n");

    }

}
/**
 * Update an event or recurring series
 */
function updateEvent($event)
{
    global $db, $mappings, $date_format;
    $editMode = $event[$mappings['recur_edit_mode']];
    if ($editMode) {
        // This is a recurring event, so determine how to handle it.
        // First, load the original master event for this instance:
        $master_event = $db->select('events', $event[$mappings['orig_event_id']]);
        // Select by id returns an array of one item, so grab it
        $master_event = $master_event[0];
        $event_id = $master_event[$mappings['event_id']];
        switch ($editMode) {
            // NOTE: Both the "single" and "future" cases currently create new
            // events in order to represent edited versions of recurrence instances.
            // This could more flexibly be handled within a single master
            // event by supporting multiple RRULE and EXRULE definitions per
            // event. This would be a bit more complex to implement and would
            // also require more processing code to arrive at the final event
            // series to return when querying. For this example (which is already
            // complex enough) we're sticking to the simpler edit implementations
            // which can simply go through the existing default event logic, but
            // you are free to implement these however you'd like in real projects.
            case 'single':
                // Create a new event based on the data passed in (the
                // original event does not need to be updated in this case):
                createSingleCopy($event);
                // Add an exception for the original occurrence start date
                // so that the original instance will not be displayed:
                addExceptionDate($event_id, $event[$mappings['recur_instance_start']]);
                break;
            case 'future':
                // In this sample code we're going to split the original event
                // into two: the original up to the edit date and a new event
                // from the edit date to the series end date. Because of this we
                // only end-date the original event, don't update it otherwise.
                // This could be done all within a single event as explained in
                // the comments above, but for this example we're keeping it simple.
                // First update the original event to end at the instance start:
                $endDate = new DateTime($event[$mappings['recur_instance_start']]);
                // We're at the day level of precision, so roll the end date back to the
                // end of the previous day so it will display correctly in the UI.
                $endDate->setTime(0, 0, 0)->modify('-1 second');
                // Save the original end date before changing it so that we can
                // apply it below to the newly-created series:
                $originalEndDate = $master_event[$mappings['end_date']];
                // End-date the master event (including the RRULE) to the instance start:
                $master_event = endDateRecurringSeries($master_event, $endDate);
                // Persist changes:
                $db->update('events', $master_event);
                // Now create the new event for the updated future series.
                // Update the recurrence instance start date to the edited date:
                $event[$mappings['recur_instance_start']] = $event[$mappings['start_date']];
                // Don't reuse the existing instance id since we're creating a new event:
                unset($event[$mappings['event_id']]);
                // Overwrite the instance end date with the master (series) end date:
                $event[$mappings['end_date']] = $originalEndDate;
                // Create the new event (which also persists it). Note that we are NOT calling
                // addEvent() here, which recalculates the end date for recurring events. In this
                // case we always want to keep the existing master event end date.
                $event = $db->insert('events', cleanEvent($event));
                break;
            case 'all':
                // Make sure the id is the original id, not the instance id:
                $event[$mappings['event_id']] = $event_id;
                // Base duration off of the current instance start / end since the end
                // date for the series will be some future date:
                $event[$mappings['duration']] = calculateDuration($event[$mappings['start_date']], $event[$mappings['end_date']]);
                // In case the start date was edited by the user, we need to update the
                // original event to use the new start date
                $instanceStart = new DateTime($event[$mappings['recur_instance_start']]);
                $editedStart = new DateTime($event[$mappings['start_date']]);
                $startDiff = $instanceStart->diff($editedStart);
                // If start date has changed we're going to use the edited start date as the new
                // series start date, so there's nothing else to do. However if start date is
                // unchanged, we'll need to reset the instance start to the original series start
                // so that we don't shift the recurring series on every edit. We'll also have to
                // check whether the start time has changed, and if so, apply the edited offset
                // to the original series start date. Fun!
                if ($startDiff->days === 0) {
                    // Capture any edited time diff before we overwrite the start date
                    $startTimeDiff = calculateDuration($event[$mappings['recur_instance_start']], $event[$mappings['start_date']]);
                    // The start date has not changed, so revert to the
                    // original series start since we are updating the master event
                    $event[$mappings['start_date']] = $master_event[$mappings['start_date']];
                    if ($startTimeDiff !== 0) {
                        // The start time has changed, so even though the day is the same we
                        // still have to update the master event with the new start time
                        $seriesStart = new DateTime($event[$mappings['start_date']]);
                        if ($startTimeDiff > 0) {
                            $interval = new DateInterval('PT' . $startTimeDiff . 'M');
                        } else {
                            // Goofy logic required to handle negative diffs correctly for PHP
                            $interval = new DateInterval('PT' . -1 * $startTimeDiff . 'M');
                            $interval->invert = 1;
                            // Good old PHP
                        }
                        // Apply the time offset to the original start date
                        $event[$mappings['start_date']] = $seriesStart->add($interval)->format($date_format);
                    }
                }
                // Finally, update the end date to the original series end date. This is
                // especially important in the case where this series may have been split
                // previously (e.g. by a "future" edit) so we want to preserve the current
                // end date, and not assume that it should be the default max date.
                $event[$mappings['end_date']] = calculateEndDate($event);
                // Persist changes:
                $event = $db->update('events', cleanEvent($event));
                break;
        }
    } else {
        if ($event[$mappings['rrule']]) {
            // There was no recurrence edit mode, but there is an rrule, so this was
            // an existing non-recurring event that had recurrence added to it. Need
            // to calculate the duration and end date for the series.
            $event[$mappings['duration']] = calculateDuration($event[$mappings['start_date']], $event[$mappings['end_date']]);
            $event[$mappings['end_date']] = calculateEndDate($event);
        } else {
            if ($event[$mappings['orig_event_id']]) {
                // In case the original event was recurring and was made non-recurring
                // we need to reset the original id and clean it up
                $event[$mappings['event_id']] = $event[$mappings['orig_event_id']];
                // Null out the recurrence-specific fields that are left over
                unset($event[$mappings['rrule']]);
                unset($event[$mappings['duration']]);
            }
        }
        $event = $db->update('events', cleanEvent($event));
    }
    return $event;
}