forked from mirrors/easyappointments
Added calendar selection when the user enables the google calendar synchronization for a provider.
This commit is contained in:
parent
05416823f6
commit
de29ef1ef4
10 changed files with 188 additions and 60 deletions
Binary file not shown.
|
@ -100,13 +100,13 @@ class Appointments extends CI_Controller {
|
||||||
$appointment = $post_data['appointment'];
|
$appointment = $post_data['appointment'];
|
||||||
$customer = $post_data['customer'];
|
$customer = $post_data['customer'];
|
||||||
|
|
||||||
if ($this->customers_model->exists($customer))
|
if ($this->customers_model->exists($customer))
|
||||||
$customer['id'] = $this->customers_model->find_record_id($customer);
|
$customer['id'] = $this->customers_model->find_record_id($customer);
|
||||||
|
|
||||||
$customer_id = $this->customers_model->add($customer);
|
$customer_id = $this->customers_model->add($customer);
|
||||||
$appointment['id_users_customer'] = $customer_id;
|
$appointment['id_users_customer'] = $customer_id;
|
||||||
|
|
||||||
$appointment['id'] = $this->appointments_model->add($appointment);
|
$appointment['id'] = $this->appointments_model->add($appointment);
|
||||||
$appointment['hash'] = $this->appointments_model->get_value('hash', $appointment['id']);
|
$appointment['hash'] = $this->appointments_model->get_value('hash', $appointment['id']);
|
||||||
|
|
||||||
$provider = $this->providers_model->get_row($appointment['id_users_provider']);
|
$provider = $this->providers_model->get_row($appointment['id_users_provider']);
|
||||||
|
|
|
@ -332,9 +332,9 @@ class Backend_api extends CI_Controller {
|
||||||
*/
|
*/
|
||||||
public function ajax_disable_provider_sync() {
|
public function ajax_disable_provider_sync() {
|
||||||
try {
|
try {
|
||||||
if (!isset($_POST['provider_id'])) {
|
if (!isset($_POST['provider_id']))
|
||||||
throw new Exception('Provider id not specified.');
|
throw new Exception('Provider id not specified.');
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->privileges[PRIV_USERS]['edit'] == FALSE
|
if ($this->privileges[PRIV_USERS]['edit'] == FALSE
|
||||||
&& $this->session->userdata('user_id') != $_POST['provider_id']) {
|
&& $this->session->userdata('user_id') != $_POST['provider_id']) {
|
||||||
|
@ -1049,25 +1049,25 @@ class Backend_api extends CI_Controller {
|
||||||
*/
|
*/
|
||||||
public function ajax_change_language() {
|
public function ajax_change_language() {
|
||||||
try {
|
try {
|
||||||
// Check if language exists in the available languages.
|
// Check if language exists in the available languages.
|
||||||
$found = false;
|
$found = false;
|
||||||
foreach($this->config->item('available_languages') as $lang) {
|
foreach($this->config->item('available_languages') as $lang) {
|
||||||
if ($lang == $_POST['language']) {
|
if ($lang == $_POST['language']) {
|
||||||
$found = true;
|
$found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$found)
|
if (!$found)
|
||||||
throw new Exception('Translations for the given language does not exist (' . $_POST['language'] . ').');
|
throw new Exception('Translations for the given language does not exist (' . $_POST['language'] . ').');
|
||||||
|
|
||||||
$this->session->set_userdata('language', $_POST['language']);
|
$this->session->set_userdata('language', $_POST['language']);
|
||||||
$this->config->set_item('language', $_POST['language']);
|
$this->config->set_item('language', $_POST['language']);
|
||||||
|
|
||||||
echo json_encode(AJAX_SUCCESS);
|
echo json_encode(AJAX_SUCCESS);
|
||||||
|
|
||||||
} catch(Exception $exc) {
|
} catch(Exception $exc) {
|
||||||
echo json_encode(array(
|
echo json_encode(array(
|
||||||
'exceptions' => array(exceptionToJavaScript($exc))
|
'exceptions' => array(exceptionToJavaScript($exc))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -1084,18 +1084,54 @@ class Backend_api extends CI_Controller {
|
||||||
*/
|
*/
|
||||||
public function ajax_get_google_calendars() {
|
public function ajax_get_google_calendars() {
|
||||||
try {
|
try {
|
||||||
$this->load->library('google_sync');
|
$this->load->library('google_sync');
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
|
|
||||||
$calendars = $this->google_sync->get_google_calendars($_POST['provider_id']);
|
if (!isset($_POST['provider_id']))
|
||||||
echo json_encode($calendars);
|
throw new Exception('Provider id is required in order to fetch the google calendars.');
|
||||||
|
|
||||||
|
// Check if selected provider has sync enabled.
|
||||||
|
$google_sync = $this->providers_model->get_setting('google_sync', $_POST['provider_id']);
|
||||||
|
if ($google_sync) {
|
||||||
|
$google_token = json_decode($this->providers_model->get_setting('google_token', $_POST['provider_id']));
|
||||||
|
$this->google_sync->refresh_token($google_token->refresh_token);
|
||||||
|
$calendars = $this->google_sync->get_google_calendars();
|
||||||
|
echo json_encode($calendars);
|
||||||
|
} else {
|
||||||
|
echo json_encode(AJAX_FAILURE);
|
||||||
|
}
|
||||||
} catch(Exception $exc) {
|
} catch(Exception $exc) {
|
||||||
echo json_encode(array(
|
echo json_encode(array(
|
||||||
'exceptions' => array(exceptionToJavaScript($exc))
|
'exceptions' => array(exceptionToJavaScript($exc))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select a specific google calendar for a provider.
|
||||||
|
*
|
||||||
|
* All the appointments will be synced with this particular calendar.
|
||||||
|
*
|
||||||
|
* @param numeric $_POST['provider_id'] Provider record id.
|
||||||
|
* @param string $_POST['calendar_id'] Google calendar's id.
|
||||||
|
*/
|
||||||
|
public function ajax_select_google_calendar() {
|
||||||
|
try {
|
||||||
|
if ($this->privileges[PRIV_USERS]['edit'] == FALSE
|
||||||
|
&& $this->session->userdata('user_id') != $_POST['provider_id']) {
|
||||||
|
throw new Exception('You do not have the required privileges for this task.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->load->model('providers_model');
|
||||||
|
$result = $this->providers_model->set_setting('google_calendar', $_POST['calendar_id'], $_POST['provider_id']);
|
||||||
|
echo json_encode(($result) ? AJAX_SUCCESS : AJAX_FAILURE);
|
||||||
|
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
echo json_encode(array(
|
||||||
|
'exceptions' => array(exceptionToJavaScript($exc))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End of file backend_api.php */
|
/* End of file backend_api.php */
|
||||||
|
|
|
@ -43,30 +43,27 @@ class Google extends CI_Controller {
|
||||||
*/
|
*/
|
||||||
public function oauth_callback() {
|
public function oauth_callback() {
|
||||||
if (isset($_GET['code'])) {
|
if (isset($_GET['code'])) {
|
||||||
$this->load->library('Google_Sync');
|
$this->load->library('Google_Sync');
|
||||||
$token = $this->google_sync->authenticate($_GET['code']);
|
$token = $this->google_sync->authenticate($_GET['code']);
|
||||||
|
|
||||||
// Store the token into the database for future reference.
|
// Store the token into the database for future reference.
|
||||||
if (!isset($_SESSION)) {
|
if (!isset($_SESSION)) {
|
||||||
@session_start();
|
@session_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_SESSION['oauth_provider_id'])) {
|
if (isset($_SESSION['oauth_provider_id'])) {
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
|
|
||||||
$this->providers_model->set_setting('google_sync', TRUE,
|
$this->providers_model->set_setting('google_sync', TRUE,
|
||||||
$_SESSION['oauth_provider_id']);
|
$_SESSION['oauth_provider_id']);
|
||||||
$this->providers_model->set_setting('google_token', $token,
|
$this->providers_model->set_setting('google_token', $token,
|
||||||
$_SESSION['oauth_provider_id']);
|
$_SESSION['oauth_provider_id']);
|
||||||
$this->providers_model->set_setting('google_calendar', 'primary',
|
$this->providers_model->set_setting('google_calendar', 'primary',
|
||||||
$_SESSION['oath_provider_id']);
|
$_SESSION['oauth_provider_id']);
|
||||||
|
} else {
|
||||||
} else {
|
echo '<h1>Sync provider id not specified!</h1>';
|
||||||
echo '<h1>Sync provider id not specified!</h1>';
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo '<h1>Authorization Failed!</h1>';
|
echo '<h1>Authorization Failed!</h1>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -264,3 +264,6 @@ $lang['hour'] = 'Hour';
|
||||||
$lang['minute'] = 'Minute';
|
$lang['minute'] = 'Minute';
|
||||||
$lang['google_sync_completed'] = 'Google synchronization completed successfully!';
|
$lang['google_sync_completed'] = 'Google synchronization completed successfully!';
|
||||||
$lang['google_sync_failed'] = 'Google synchronization failed: Could not establish server connection.';
|
$lang['google_sync_failed'] = 'Google synchronization failed: Could not establish server connection.';
|
||||||
|
$lang['select_google_calendar'] = 'Select Google Calendar';
|
||||||
|
$lang['select_google_calendar_prompt'] = 'Select the calendar that you want to sync your appointments. If you do not want to select a specific calendar the default one will be used.';
|
||||||
|
$lang['google_calendar_selected'] = 'Google calendar has been successfully selected!';
|
|
@ -263,4 +263,7 @@ $lang['time'] = 'Zeit';
|
||||||
$lang['hour'] = 'Uhr';
|
$lang['hour'] = 'Uhr';
|
||||||
$lang['minute'] = 'Minute';
|
$lang['minute'] = 'Minute';
|
||||||
$lang['google_sync_completed'] = 'Google Synchronisation erfolgreich beendet!';
|
$lang['google_sync_completed'] = 'Google Synchronisation erfolgreich beendet!';
|
||||||
$lang['google_sync_failed'] = 'Google Synchronisation fehlgeschlagen: Serververbindung konnte nicht hergestellt werden.';
|
$lang['google_sync_failed'] = 'Google Synchronisation fehlgeschlagen: Serververbindung konnte nicht hergestellt werden.';
|
||||||
|
$lang['select_google_calendar'] = 'Wählen Sie Google Kalender';
|
||||||
|
$lang['select_google_calendar_prompt'] = 'Wählen Sie den Kalender, den Sie Ihre Termine synchronisieren möchten. Wenn Sie nicht wollen, um einen bestimmten Kalender wählen den Standard, verwendet.';
|
||||||
|
$lang['google_calendar_selected'] = 'Google-Kalender ausgewählt wurde erfolgreich!';
|
|
@ -263,4 +263,7 @@ $lang['time'] = 'Χρόνος';
|
||||||
$lang['hour'] = 'Ώρα';
|
$lang['hour'] = 'Ώρα';
|
||||||
$lang['minute'] = 'Λεπτά';
|
$lang['minute'] = 'Λεπτά';
|
||||||
$lang['google_sync_completed'] = 'Ο συγχρονισμός με την Google ολοκληρώθηκε επιτυχώς!';
|
$lang['google_sync_completed'] = 'Ο συγχρονισμός με την Google ολοκληρώθηκε επιτυχώς!';
|
||||||
$lang['google_sync_failed'] = 'Ο συγχρονισμός με την Google απέτυχε: Δεν μπόρεσε να πραγματοποιηθεί σύνδεση με τον server.';
|
$lang['google_sync_failed'] = 'Ο συγχρονισμός με την Google απέτυχε: Δεν μπόρεσε να πραγματοποιηθεί σύνδεση με τον server.';
|
||||||
|
$lang['select_google_calendar'] = 'Επιλογή Ημερολογίου της Google';
|
||||||
|
$lang['select_google_calendar_prompt'] = 'Επιλέξτε το ημερολόγιο στο οποίο θέλετε να συγχρονίζεται τα ραντεβού σας. Εάν δεν θελήσετε να επιλέξετε ένα συγκεκριμένο ημερολόγιο θα χρησιμοποιηθεί το προεπιλεγμένο.';
|
||||||
|
$lang['google_calendar_selected'] = 'Το ημερολόγιο της Google επιλέχθηκε επιτυχώς!';
|
|
@ -13,7 +13,7 @@ require_once dirname(dirname(dirname(__FILE__))) . '/configuration.php';
|
||||||
* library.
|
* library.
|
||||||
*/
|
*/
|
||||||
class Google_Sync {
|
class Google_Sync {
|
||||||
private $CI;
|
private $CI;
|
||||||
private $client;
|
private $client;
|
||||||
private $service;
|
private $service;
|
||||||
|
|
||||||
|
@ -301,11 +301,19 @@ class Google_Sync {
|
||||||
* The given user's token must already exist in db in order to get access to his
|
* The given user's token must already exist in db in order to get access to his
|
||||||
* Google Calendar account.
|
* Google Calendar account.
|
||||||
*
|
*
|
||||||
* @param numeric $provider_id The provider's record id.
|
* @param string $google_token The user's token will be used to grant access to google calendar.
|
||||||
* @return array Returns an array with the available calendars.
|
* @return array Returns an array with the available calendars.
|
||||||
*/
|
*/
|
||||||
public function get_google_calendars($provider_id) {
|
public function get_google_calendars() {
|
||||||
|
$calendarList = $this->service->calendarList->listCalendarList();
|
||||||
|
$calendars = array();
|
||||||
|
foreach ($calendarList->items as $google_calendar) {
|
||||||
|
$calendars[] = array(
|
||||||
|
'id' => $google_calendar->id,
|
||||||
|
'summary' => $google_calendar->summary
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $calendars;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -315,7 +315,6 @@
|
||||||
<button type="button" class="close" data-dismiss="modal"
|
<button type="button" class="close" data-dismiss="modal"
|
||||||
aria-hidden="true">×</button>
|
aria-hidden="true">×</button>
|
||||||
<h3><?php echo $this->lang->line('new_unavailable_title'); ?></h3>
|
<h3><?php echo $this->lang->line('new_unavailable_title'); ?></h3>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
@ -363,4 +362,36 @@
|
||||||
<?php echo $this->lang->line('cancel'); ?>
|
<?php echo $this->lang->line('cancel'); ?>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// SELECT GOOGLE CALENDAR
|
||||||
|
//
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div id="select-google-calendar" class="modal hide fade">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal"
|
||||||
|
aria-hidden="true">×</button>
|
||||||
|
<h3><?php echo $this->lang->line('select_google_calendar'); ?></h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>
|
||||||
|
<?php echo $this->lang->line('select_google_calendar_prompt'); ?>
|
||||||
|
</p>
|
||||||
|
<select id="google-calendar"></select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button id="select-calendar" class="btn btn-primary">
|
||||||
|
<?php echo $this->lang->line('select'); ?>
|
||||||
|
</button>
|
||||||
|
<button id="close-calendar" class="btn">
|
||||||
|
<?php echo $this->lang->line('close'); ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
|
@ -708,8 +708,29 @@ var BackendCalendar = {
|
||||||
$('#google-sync').prop('disabled', false);
|
$('#google-sync').prop('disabled', false);
|
||||||
$('#select-filter-item option:selected').attr('google-sync', 'true');
|
$('#select-filter-item option:selected').attr('google-sync', 'true');
|
||||||
|
|
||||||
// Display the calendar selection dialog.
|
// Display the calendar selection dialog. First we will get a list
|
||||||
|
// of the available user's calendars and then we will display a selection
|
||||||
|
// modal so the user can select the sync calendar.
|
||||||
|
var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_get_google_calendars';
|
||||||
|
var postData = {
|
||||||
|
'provider_id': $('#select-filter-item').val()
|
||||||
|
};
|
||||||
|
$.post(postUrl, postData, function(response) {
|
||||||
|
///////////////////////////////////////////////////////////////////
|
||||||
|
console.log('Get Available Google Calendars Response', response);
|
||||||
|
///////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
||||||
|
|
||||||
|
$('#google-calendar').empty();
|
||||||
|
$.each(response, function() {
|
||||||
|
var option = '<option value="' + this.id + '">' + this.summary + '</option>';
|
||||||
|
$('#google-calendar').append(option);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#select-google-calendar').modal('show');
|
||||||
|
|
||||||
|
}, 'json');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
@ -922,6 +943,32 @@ var BackendCalendar = {
|
||||||
$('#manage-appointment').find('#customer-id, #first-name, #last-name, #email, '
|
$('#manage-appointment').find('#customer-id, #first-name, #last-name, #email, '
|
||||||
+ '#phone-number, #address, #city, #zip-code, #customer-notes').val('');
|
+ '#phone-number, #address, #city, #zip-code, #customer-notes').val('');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event: Select Google Calendar "Click"
|
||||||
|
*/
|
||||||
|
$('#select-calendar').click(function() {
|
||||||
|
var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_select_google_calendar';
|
||||||
|
var postData = {
|
||||||
|
'provider_id': $('#select-filter-item').val(),
|
||||||
|
'calendar_id': $('#google-calendar').val()
|
||||||
|
};
|
||||||
|
$.post(postUrl, postData, function(response){
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
console.log('Select Google Calendar Response', response);
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
||||||
|
Backend.displayNotification(EALang['google_calendar_selected']);
|
||||||
|
$('#select-google-calendar').modal('hide');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event: Close Google Calendar "Click"
|
||||||
|
*/
|
||||||
|
$('#close-calendar').click(function() {
|
||||||
|
$('#select-google-calendar').modal('hide');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1087,7 +1134,7 @@ var BackendCalendar = {
|
||||||
// on the calendar, even if the provider won't work on that day).
|
// on the calendar, even if the provider won't work on that day).
|
||||||
$.each(response.unavailables, function(index, unavailable) {
|
$.each(response.unavailables, function(index, unavailable) {
|
||||||
if (currDateStart.toString('dd/MM/yyyy')
|
if (currDateStart.toString('dd/MM/yyyy')
|
||||||
=== Date.parse(unavailable.start_datetime).toString('dd/MM/yyyy')) {
|
=== Date.parse(unavailable.start_datetime).toString('dd/MM/yyyy')) {
|
||||||
var unavailablePeriod = {
|
var unavailablePeriod = {
|
||||||
'title': EALang['unavailable'] + ' <br><small>' + ((unavailable.notes.length > 30)
|
'title': EALang['unavailable'] + ' <br><small>' + ((unavailable.notes.length > 30)
|
||||||
? unavailable.notes.substring(0, 30) + '...'
|
? unavailable.notes.substring(0, 30) + '...'
|
||||||
|
@ -1630,14 +1677,14 @@ var BackendCalendar = {
|
||||||
console.log('Drop Unavailable Event Response:', response);
|
console.log('Drop Unavailable Event Response:', response);
|
||||||
|
|
||||||
if (response.exceptions) {
|
if (response.exceptions) {
|
||||||
reponse.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
||||||
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
|
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
|
||||||
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.warnings) {
|
if (response.warnings) {
|
||||||
reponse.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
||||||
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
|
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
|
||||||
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue