diff --git a/src/application/controllers/appointments.php b/src/application/controllers/appointments.php
index 529cdb2f..903e4945 100644
--- a/src/application/controllers/appointments.php
+++ b/src/application/controllers/appointments.php
@@ -102,16 +102,18 @@ class Appointments extends CI_Controller {
// Synchronize the appointment with the providers plan, if the
// google sync option is enabled.
- $this->load->library('google_sync');
$google_sync = $this->Providers_Model->get_setting('google_sync',
$appointment_data['id_users_provider']);
if ($google_sync == TRUE) {
$google_token = $this->Providers_Model->get_setting('google_token',
$appointment_data['id_users_provider']);
- // Validate the token. If it isn't valid, the sync operation cannot
+
+ // Authenticate the token. If it isn't valid, the sync operation cannot
// be completed.
- if ($this->google_sync->validate_token($google_token) === TRUE) {
+ $this->load->library('google_sync');
+
+ if ($this->google_sync->authenticate($google_token) === TRUE) {
if ($manage_mode === FALSE) {
// Add appointment to Google Calendar.
$this->google_sync->add_appointment($appointment_data['id']);
@@ -122,7 +124,7 @@ class Appointments extends CI_Controller {
}
}
- // Load the book appointment view.
+ // Load the book success view.
$service_data = $this->Services_Model->get_row($appointment_data['id_services']);
$provider_data = $this->Providers_Model->get_row($appointment_data['id_users_provider']);
$company_name = $this->Settings_Model->get_setting('company_name');
@@ -180,10 +182,22 @@ class Appointments extends CI_Controller {
// Delete the appointment from Google Calendar, if it is synced.
if ($appointment_data['id_google_calendar'] != NULL) {
- $this->load->library('google_sync');
- $this->google_sync->delete_appointment($appointment_data['id']);
+ $google_sync = $this->Providers_Model->get_setting('google_sync',
+ $appointment_data['id_users_provider']);
+
+ if ($google_sync == TRUE) {
+ $this->load->library('google_sync');
+
+ // Get the provider's refresh token and try to authenticate the
+ // Google Calendar API usage.
+ $google_token = $this->Providers_Model->get_setting('google_token',
+ $appointment_data['id_users_provider']);
+
+ if ($this->google_sync->authendicate($google_token) === TRUE) {
+ $this->google_sync->delete_appointment($appointment_data['id']);
+ }
+ }
}
-
} catch(Exception $exc) {
// Display the error message to the customer.
$view_data['error_message'] = $exc->getMessage();
diff --git a/src/application/controllers/backend.php b/src/application/controllers/backend.php
new file mode 100644
index 00000000..897049c5
--- /dev/null
+++ b/src/application/controllers/backend.php
@@ -0,0 +1,48 @@
+load->model('Providers_Model');
+ $this->load->model('Services_Model');
+ $this->load->model('Settings_Model');
+
+ // Display the main backend page.
+ $view_data['base_url'] = $this->config->item('base_url');
+ $view_data['company_name'] = $this->Settings_Model->get_setting('company_name');
+ $view_data['available_providers'] = $this->Providers_Model->get_available_providers();
+ $view_data['available_services'] = $this->Services_Model->get_available_services();
+
+ $this->load->view('backend/header', $view_data);
+ $this->load->view('backend/calendar', $view_data);
+ $this->load->view('backend/footer', $view_data);
+ }
+
+ public function customers() {
+
+ }
+
+ public function services() {
+
+ }
+
+ public function providers() {
+
+ }
+
+ public function settings() {
+
+ }
+}
+
+/* End of file backend.php */
+/* Location: ./application/controllers/backend.php */
\ No newline at end of file
diff --git a/src/application/libraries/google_sync.php b/src/application/libraries/google_sync.php
index a1d3b091..a5f3b364 100644
--- a/src/application/libraries/google_sync.php
+++ b/src/application/libraries/google_sync.php
@@ -37,22 +37,21 @@ class Google_Sync {
}
/**
- * Validate the Google API access token of a provider.
+ * Authenticate the Google API usage.
*
- * In order to manage a Google user's data, one need a valid access token.
- * This token is provided when the user grants the permission to a system
- * to access his Google account data. So before making any action we need
- * to make sure that the available token is still valid.
+ * This method must be executed every time we need to make actions on a
+ * provider's Google Calendar account. A new token is necessary and the
+ * only way to get it is to use the stored refresh token that was provided
+ * when the provider granted consent to Easy!Appointments for use his
+ * Google Calendar account.
*
- * IMPORTANT! Always use this method before anything else
- * in order to make sure that the token is being set and still valid.
- *
- * @param string $access_token This token is normally stored in the database.
- * @return bool Returns the validation result.
+ * @param string $refresh_token The provider's refresh token. This value is
+ * stored in the database and used every time we need to make actions to his
+ * Google Caledar account.
+ * @return bool Returns the authenticate operation result.
*/
- public function validate_token($access_token) {
- $this->client->setAccessToken($access_token);
- return $this->client->isAccessTokenExpired();
+ public function authenticate($refresh_token) {
+
}
/**
diff --git a/src/application/views/appointments/book.php b/src/application/views/appointments/book.php
index 4c8f8317..05956e81 100644
--- a/src/application/views/appointments/book.php
+++ b/src/application/views/appointments/book.php
@@ -26,7 +26,7 @@
+ href="config->base_url(); ?>assets/css/frontend.css">
+ src="config->base_url(); ?>assets/js/libs/jquery/jquery.min.js">
+ src="config->base_url(); ?>assets/js/libs/jquery/jquery-ui.min.js">
+ src="config->base_url(); ?>assets/js/libs/jquery/jquery.qtip.min.js">
+ src="config->base_url(); ?>assets/js/libs/bootstrap/bootstrap.min.js">
+ src="config->base_url(); ?>assets/js/libs/date.js">
+ src="config->base_url(); ?>assets/js/frontend_book.js">
+ src="config->base_url(); ?>assets/js/general_functions.js">
diff --git a/src/application/views/appointments/book_success.php b/src/application/views/appointments/book_success.php
index 9f946617..4c7c6fee 100644
--- a/src/application/views/appointments/book_success.php
+++ b/src/application/views/appointments/book_success.php
@@ -149,16 +149,16 @@
'Your appointment has successfully been added to ' +
'your Google Calendar account.
' +
'' +
- 'Appointment Link' +
+ 'Click here to view your appoinmtent on Google ' +
+ 'Calendar.' +
'' +
'