2013-04-20 20:20:16 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
|
|
|
2013-05-04 00:26:04 +03:00
|
|
|
<?php // INCLUDE JS FILES ?>
|
2013-05-17 16:09:10 +03:00
|
|
|
<script
|
|
|
|
type="text/javascript"
|
2013-06-10 18:51:23 +03:00
|
|
|
src="<?php echo $this->config->base_url(); ?>assets/js/libs/jquery/jquery.min.js"></script>
|
|
|
|
<script
|
|
|
|
type="text/javascript"
|
|
|
|
src="<?php echo $this->config->base_url(); ?>assets/js/libs/bootstrap/bootstrap.min.js"></script>
|
|
|
|
<script
|
|
|
|
type="text/javascript"
|
|
|
|
src="<?php echo $this->config->base_url(); ?>assets/js/libs/date.js"></script>
|
|
|
|
<script
|
|
|
|
type="text/javascript"
|
|
|
|
src="<?php echo $this->config->base_url(); ?>assets/js/general_functions.js"></script>
|
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
<?php // INCLUDE CSS FILES ?>
|
2013-05-17 16:09:10 +03:00
|
|
|
<link
|
|
|
|
rel="stylesheet"
|
|
|
|
type="text/css"
|
|
|
|
href="<?php echo $this->config->base_url(); ?>assets/css/libs/bootstrap/bootstrap.css">
|
|
|
|
<link
|
|
|
|
rel="stylesheet"
|
|
|
|
type="text/css"
|
|
|
|
href="<?php echo $this->config->base_url(); ?>assets/css/libs/bootstrap/bootstrap-responsive.css">
|
2013-04-20 20:20:16 +03:00
|
|
|
|
|
|
|
<?php // SET FAVICON FOR PAGE ?>
|
2013-05-17 16:09:10 +03:00
|
|
|
<link
|
|
|
|
rel="icon"
|
|
|
|
type="image/x-icon"
|
|
|
|
href="<?php echo $this->config->base_url(); ?>assets/images/favicon.ico">
|
2013-04-20 20:20:16 +03:00
|
|
|
|
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
background-color: #CAEDF3;
|
|
|
|
}
|
|
|
|
|
|
|
|
#success-frame {
|
2013-06-10 18:51:23 +03:00
|
|
|
width: 630px;
|
2013-04-20 20:20:16 +03:00
|
|
|
margin: 150px auto 0 auto;
|
|
|
|
background: #FFF;
|
2013-05-04 00:26:04 +03:00
|
|
|
border: 1px solid #DDDADA;
|
2013-06-10 18:51:23 +03:00
|
|
|
padding: 70px;
|
2013-04-20 20:20:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#success-icon {
|
2013-06-10 18:51:23 +03:00
|
|
|
float: right;
|
|
|
|
margin-top: 17px;
|
2013-04-20 20:20:16 +03:00
|
|
|
}
|
|
|
|
</style>
|
2013-06-10 18:51:23 +03:00
|
|
|
|
|
|
|
<script src="https://apis.google.com/js/client.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var GlobalVariables = {
|
|
|
|
'appointmentData' : <?php echo json_encode($appointment_data); ?>,
|
|
|
|
'providerData' : <?php echo json_encode($provider_data); ?>,
|
|
|
|
'serviceData' : <?php echo json_encode($service_data); ?>,
|
|
|
|
'companyName' : <?php echo '"' . $company_name . '"'; ?>,
|
|
|
|
'googleApiKey' : <?php echo '"' . SystemConfiguration::$google_api_key . '"'; ?>,
|
|
|
|
'googleClientId' : <?php echo '"' . SystemConfiguration::$google_client_id . '"'; ?>,
|
|
|
|
'googleApiScope' : 'https://www.googleapis.com/auth/calendar'
|
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
/**
|
|
|
|
* Event: Add Appointment to Google Calendar "Click"
|
|
|
|
*
|
|
|
|
* This event handler adds the appointment to the users Google
|
|
|
|
* Calendar Account. The event is going to be added to the "primary"
|
|
|
|
* calendar. In order to use the API the javascript client library
|
|
|
|
* provided by Google is necessary.
|
|
|
|
*/
|
|
|
|
$('#add-to-google-calendar').click(function() {
|
|
|
|
gapi.client.setApiKey(GlobalVariables.googleApiKey);
|
|
|
|
gapi.auth.authorize({
|
|
|
|
'client_id' : GlobalVariables.googleClientId,
|
|
|
|
'scope' : GlobalVariables.googleApiScope,
|
|
|
|
'immediate' : false
|
|
|
|
}, handleAuthResult);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method handles the authorization result. If the user granted access
|
|
|
|
* to his data, then the appointment is going to be added to his calendar.
|
|
|
|
*
|
|
|
|
* @param {bool} authResult The user's auth result.
|
|
|
|
*/
|
|
|
|
function handleAuthResult(authResult) {
|
|
|
|
try {
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
console.log('Google Authorization Result: ', authResult);
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
if (authResult.error) {
|
|
|
|
throw 'Could not authorize user.';
|
|
|
|
}
|
|
|
|
|
|
|
|
// The user has granted access, add the appointment to his calendar.
|
|
|
|
// Before making the event.insert request the the event resource data
|
|
|
|
// must be prepared.
|
|
|
|
var appointmentData = GlobalVariables.appointmentData;
|
|
|
|
|
|
|
|
appointmentData['start_datetime'] = GeneralFunctions.ISODateString(
|
|
|
|
Date.parseExact(appointmentData['start_datetime'],
|
|
|
|
'yyyy-MM-dd HH:mm:ss'));
|
|
|
|
appointmentData['end_datetime'] = GeneralFunctions.ISODateString(
|
|
|
|
Date.parseExact(appointmentData['end_datetime'],
|
|
|
|
'yyyy-MM-dd HH:mm:ss'));
|
|
|
|
|
|
|
|
// Create a valid Google Calendar API resource for the new event.
|
|
|
|
var resource = {
|
|
|
|
'summary' : GlobalVariables.serviceData['name'],
|
|
|
|
'location' : GlobalVariables.companyName,
|
|
|
|
'start' : {
|
|
|
|
'dateTime': appointmentData['start_datetime']
|
|
|
|
},
|
|
|
|
'end' : {
|
|
|
|
'dateTime': appointmentData['end_datetime']
|
|
|
|
},
|
|
|
|
'attendees' : [
|
|
|
|
{
|
|
|
|
'email' : GlobalVariables.providerData['email'],
|
|
|
|
'displayName' : GlobalVariables.providerData['first_name'] + ' '
|
|
|
|
+ GlobalVariables.providerData['last_name']
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
gapi.client.load('calendar', 'v3', function() {
|
|
|
|
var request = gapi.client.calendar.events.insert({
|
|
|
|
'calendarId' : 'primary',
|
|
|
|
'resource' : resource
|
|
|
|
});
|
|
|
|
|
|
|
|
request.execute(function(response) {
|
|
|
|
/////////////////////////////////////////////////
|
|
|
|
console.log('Google API Response:', response);
|
|
|
|
/////////////////////////////////////////////////
|
|
|
|
|
|
|
|
if (!response.error) {
|
|
|
|
$('#success-frame').append(
|
|
|
|
'<br><br>' +
|
|
|
|
'<div class="alert alert-success">' +
|
|
|
|
'<h4>Success!</h4>' +
|
|
|
|
'<p>' +
|
2013-11-07 13:25:59 +02:00
|
|
|
'Your appointment has been added to ' +
|
2013-06-10 18:51:23 +03:00
|
|
|
'your Google Calendar account. <br>' +
|
2013-10-16 18:53:26 +03:00
|
|
|
'<a href="' + response.htmlLink + '" target="_blank">' +
|
2013-09-23 18:42:36 +03:00
|
|
|
'Click here to view your appointment on Google ' +
|
2013-06-12 18:31:16 +03:00
|
|
|
'Calendar.' +
|
2013-06-10 18:51:23 +03:00
|
|
|
'</a>' +
|
|
|
|
'</p>' +
|
|
|
|
'</div>'
|
|
|
|
);
|
2013-06-12 18:31:16 +03:00
|
|
|
$('#add-to-google-calendar').hide();
|
2013-06-10 18:51:23 +03:00
|
|
|
} else {
|
|
|
|
throw 'Could not add the event to Google Calendar.';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch(exc) {
|
|
|
|
// The user denied access or something else happened, display
|
|
|
|
// corresponding message on the screen.
|
|
|
|
$('#success-frame').append(
|
|
|
|
'<br><br>' +
|
|
|
|
'<div class="alert alert-error">' +
|
|
|
|
'<h4>Oops! Something Went Wrong!</h4>' +
|
|
|
|
'<p>' +
|
|
|
|
'Your appointment could not be added to your ' +
|
|
|
|
'Google Calendar account.' +
|
|
|
|
'<pre>' + exc + '</pre>' +
|
|
|
|
'</p>' +
|
|
|
|
'</div>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2013-04-20 20:20:16 +03:00
|
|
|
</head>
|
|
|
|
<body>
|
2013-06-03 17:42:19 +03:00
|
|
|
<div id="success-frame" class="frame-container">
|
2013-05-04 00:26:04 +03:00
|
|
|
<img id="success-icon" src="<?php echo $this->config->base_url(); ?>assets/images/success.png" />
|
2013-06-10 18:51:23 +03:00
|
|
|
|
|
|
|
<h3>Your appointment has been successfully registered!</h3>
|
|
|
|
<p>An email with the appointment details has been sent to you.</p>
|
|
|
|
|
2013-10-21 15:36:40 +03:00
|
|
|
<?php if ($this->config->item('ea_google_sync_feature')) { ?>
|
2013-06-10 18:51:23 +03:00
|
|
|
<button id="add-to-google-calendar" class="btn btn-primary">
|
|
|
|
<i class="icon-plus icon-white"></i>
|
|
|
|
Add to Google Calendar
|
|
|
|
</button>
|
2013-10-21 15:36:40 +03:00
|
|
|
<?php } ?>
|
2013-06-26 12:31:57 +03:00
|
|
|
|
2013-05-17 16:09:10 +03:00
|
|
|
<?php
|
2013-07-02 20:18:19 +03:00
|
|
|
// Display exceptions (if any).
|
|
|
|
if (isset($exceptions)) {
|
|
|
|
echo '<div style="margin: 10px">';
|
|
|
|
echo '<h4>Unexpected Errors</h4>';
|
2013-07-15 10:32:19 +03:00
|
|
|
foreach($exceptions as $exc) {
|
|
|
|
echo exceptionToHtml($exc);
|
2013-07-02 20:18:19 +03:00
|
|
|
}
|
|
|
|
echo '</div>';
|
2013-05-17 16:09:10 +03:00
|
|
|
}
|
|
|
|
?>
|
2013-04-20 20:20:16 +03:00
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|