2013-04-20 20:20:16 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2015-04-26 15:31:34 +03:00
|
|
|
<meta charset="utf-8" />
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
2015-04-09 22:50:16 +03:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
<meta name="theme-color" content="#35A768">
|
2015-04-26 15:31:34 +03:00
|
|
|
<title><?php echo $this->lang->line('appointment_registered') . ' - ' . $company_name; ?></title>
|
2015-04-09 22:50:16 +03:00
|
|
|
|
2015-04-26 15:31:34 +03:00
|
|
|
<?php
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
// INCLUDE JS FILES
|
|
|
|
// ------------------------------------------------------------ ?>
|
2013-05-17 16:09:10 +03:00
|
|
|
<script
|
|
|
|
type="text/javascript"
|
2015-01-29 00:53:13 +02:00
|
|
|
src="<?php echo $this->config->base_url(); ?>/assets/js/libs/jquery/jquery.min.js"></script>
|
2013-06-10 18:51:23 +03:00
|
|
|
<script
|
|
|
|
type="text/javascript"
|
2015-04-13 21:33:59 +03:00
|
|
|
src="<?php echo $this->config->base_url(); ?>/assets/ext/bootstrap/js/bootstrap.min.js"></script>
|
2013-06-10 18:51:23 +03:00
|
|
|
<script
|
|
|
|
type="text/javascript"
|
2015-01-29 00:53:13 +02:00
|
|
|
src="<?php echo $this->config->base_url(); ?>/assets/js/libs/date.js"></script>
|
2015-04-26 15:31:34 +03:00
|
|
|
|
|
|
|
<script
|
|
|
|
type="text/javascript"
|
|
|
|
src="<?php echo $this->config->base_url(); ?>/assets/js/general_functions.js"></script>
|
|
|
|
|
|
|
|
<script
|
|
|
|
type="text/javascript"
|
|
|
|
src="https://apis.google.com/js/client.js"></script>
|
2013-06-10 18:51:23 +03:00
|
|
|
|
2015-04-26 15:31:34 +03:00
|
|
|
<?php
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
// INCLUDE CSS FILES
|
|
|
|
// ------------------------------------------------------------ ?>
|
2015-04-13 21:33:59 +03:00
|
|
|
<link rel="stylesheet" type="text/css"
|
2015-04-09 22:50:16 +03:00
|
|
|
href="<?php echo $this->config->base_url(); ?>/assets/ext/bootstrap/css/bootstrap.min.css">
|
2015-04-26 15:31:34 +03:00
|
|
|
<link rel="stylesheet" type="text/css"
|
|
|
|
href="<?php echo $this->config->base_url(); ?>/assets/css/frontend.css">
|
|
|
|
|
|
|
|
|
|
|
|
<?php
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
// SET PAGE FAVICON
|
|
|
|
// ------------------------------------------------------------ ?>
|
2015-04-09 22:50:16 +03:00
|
|
|
<link rel="icon" type="image/x-icon"
|
2015-01-29 00:53:13 +02:00
|
|
|
href="<?php echo $this->config->base_url(); ?>/assets/img/favicon.ico">
|
2015-04-13 21:33:59 +03:00
|
|
|
|
2015-04-09 22:50:16 +03:00
|
|
|
<link rel="icon" sizes="192x192"
|
|
|
|
href="<?php echo $this->config->base_url(); ?>/assets/img/logo.png">
|
2013-04-20 20:20:16 +03:00
|
|
|
|
2015-04-26 15:31:34 +03:00
|
|
|
<?php
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
// CUSTOM PAGE JS
|
|
|
|
// ------------------------------------------------------------ ?>
|
2013-06-10 18:51:23 +03:00
|
|
|
<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 . '"'; ?>,
|
2015-04-13 21:01:00 +03:00
|
|
|
'googleApiKey' : <?php echo '"' . Config::GOOGLE_API_KEY . '"'; ?>,
|
|
|
|
'googleClientId' : <?php echo '"' . Config::GOOGLE_CLIENT_ID . '"'; ?>,
|
2013-06-10 18:51:23 +03:00
|
|
|
'googleApiScope' : 'https://www.googleapis.com/auth/calendar'
|
|
|
|
};
|
|
|
|
|
2013-12-19 18:28:19 +02:00
|
|
|
var EALang = <?php echo json_encode($this->lang->language); ?>;
|
2013-12-19 12:28:10 +02:00
|
|
|
|
2013-06-10 18:51:23 +03:00
|
|
|
$(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">' +
|
2013-12-20 19:44:44 +02:00
|
|
|
'<h4>' + EALang['success'] + '</h4>' +
|
2013-06-10 18:51:23 +03:00
|
|
|
'<p>' +
|
2013-12-20 19:44:44 +02:00
|
|
|
EALang['appointment_added_to_google_calendar'] +
|
2013-12-19 12:28:10 +02:00
|
|
|
'<br>' +
|
2013-10-16 18:53:26 +03:00
|
|
|
'<a href="' + response.htmlLink + '" target="_blank">' +
|
2013-12-20 19:44:44 +02:00
|
|
|
EALang['view_appointment_in_google_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>' +
|
2015-04-09 22:50:16 +03:00
|
|
|
'<div class="alert alert-danger">' +
|
2013-12-29 15:57:09 +02:00
|
|
|
'<h4>' + EALang['oops_something_went_wrong'] + '</h4>' +
|
2013-06-10 18:51:23 +03:00
|
|
|
'<p>' +
|
2013-12-29 15:57:09 +02:00
|
|
|
EALang['could_not_add_to_google_calendar'] +
|
2013-06-10 18:51:23 +03:00
|
|
|
'<pre>' + exc + '</pre>' +
|
|
|
|
'</p>' +
|
|
|
|
'</div>');
|
2013-12-29 15:57:09 +02:00
|
|
|
console.log('Add To Google Calendar Exception', exc);
|
2013-06-10 18:51:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2013-04-20 20:20:16 +03:00
|
|
|
</head>
|
|
|
|
<body>
|
2015-04-26 15:31:34 +03:00
|
|
|
<div id="main" class="container">
|
|
|
|
<div class="wrapper row">
|
|
|
|
<div id="success-frame" class="frame-container
|
|
|
|
col-xs-12
|
|
|
|
col-sm-offset-1 col-sm-10
|
|
|
|
col-md-offset-2 col-md-8
|
|
|
|
col-lg-offset-2 col-lg-8">
|
|
|
|
|
|
|
|
<div class="col-xs-12 col-sm-2">
|
|
|
|
<img id="success-icon" class="pull-right" src="<?php echo $this->config->base_url(); ?>/assets/img/success.png" />
|
|
|
|
</div>
|
|
|
|
<div class="col-xs-12 col-sm-10">
|
|
|
|
<?php
|
|
|
|
echo '<h3>' . $this->lang->line('appointment_registered') . '</h3>';
|
|
|
|
echo '<p>' . $this->lang->line('appointment_details_was_sent_to_you') . '</p>';
|
2013-06-10 18:51:23 +03:00
|
|
|
|
2015-04-26 15:31:34 +03:00
|
|
|
if ($this->config->item('ea_google_sync_feature')) {
|
|
|
|
echo '
|
|
|
|
<button id="add-to-google-calendar" class="btn btn-primary">
|
|
|
|
<i class="icon-plus icon-white"></i>
|
|
|
|
' . $this->lang->line('add_to_google_calendar') . '
|
|
|
|
</button>';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display exceptions (if any).
|
|
|
|
if (isset($exceptions)) {
|
|
|
|
echo '<div style="margin:10px">';
|
|
|
|
echo '<h4>Unexpected Errors</h4>';
|
|
|
|
foreach($exceptions as $exc) {
|
|
|
|
echo exceptionToHtml($exc);
|
|
|
|
}
|
|
|
|
echo '</div>';
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2013-04-20 20:20:16 +03:00
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|