diff --git a/Release Notes.txt b/Release Notes.txt index 5e65810e..0e5a5904 100644 --- a/Release Notes.txt +++ b/Release Notes.txt @@ -1,5 +1,8 @@ -Vesrion 0.1 +VERSION 0.2 =========== -Includes an implementation of the basic flow for -the appointment reservation use case and unit testing -for the model classes of the system. \ No newline at end of file +- Use the PHPMailer class for sending HTML emails. +- Includes complete Google Sync protocol. +- Customers can book appointments only for the available hours. +- Generation of code documentation. +- Unit test the controller classes. +- Minor Fixes diff --git a/src/application/controllers/appointments.php b/src/application/controllers/appointments.php index 5882f11a..7a8683f0 100644 --- a/src/application/controllers/appointments.php +++ b/src/application/controllers/appointments.php @@ -10,14 +10,14 @@ class Appointments extends CI_Controller { // Display the appointment booking page to the customer. // Get business name. $this->load->model('Settings_Model'); - $view_data['business_name'] = $this->Settings_Model->get_setting('business_name'); + $view_data['company_name'] = $this->Settings_Model->get_setting('company_name'); // Get the available services and providers. $this->load->model('Services_Model'); $view_data['available_services'] = $this->Services_Model->get_available_services(); $this->load->model('Providers_Model'); - $view_data['available_providers'] = $this->Providers_Model->get_available_providers(); // Provider rows contain an array of which services they can provide. + $view_data['available_providers'] = $this->Providers_Model->get_available_providers(); // Load the book appointment view. $this->load->view('appointments/book', $view_data); @@ -35,8 +35,15 @@ class Appointments extends CI_Controller { // Send an email to the customer with the appointment info. $this->load->library('Notifications'); - $this->notifications->send_book_success($post_data['customer'], $post_data['appointment']); - $this->notifications->send_new_appointment($post_data['customer'], $post_data['appointment']); + try { + $this->notifications->send_book_success($post_data['customer'], $post_data['appointment']); + $this->notifications->send_new_appointment($post_data['customer'], $post_data['appointment']); + } catch (NotificationException $not_exc) { + $view_data['notification_error'] = '

An unexpected error occured while sending  ' 
+                        . 'you an email. Please backup the appointment details so that you can restore them '
+                        . 'later. 

Error:
' . $not_exc->getMessage() . '
'; + } + // Load the book appointment view. $this->load->view('appointments/book_success', $view_data); @@ -100,8 +107,9 @@ class Appointments extends CI_Controller { $view_data['message'] = 'Your appointment has been successfully added to Google Calendar!'; $view_data['image'] = 'success.png'; } catch (Exception $exc) { - $view_data['message'] = 'An unexpected error occured during the sync operation:
' . $exc->getMessage() 
-                    . '
' . $exc->getTraceAsString() . '
'; + $view_data['message'] = 'An unexpected error occured during the sync ' + . 'operation:
' . $exc->getMessage() . '
' + . $exc->getTraceAsString() . '
'; $view_data['image'] = 'error.png'; } diff --git a/src/application/controllers/google.php b/src/application/controllers/google.php index 8fd7058a..6c9d8fe9 100644 --- a/src/application/controllers/google.php +++ b/src/application/controllers/google.php @@ -22,7 +22,8 @@ class Google extends CI_Controller { session_start(); if (isset($_SESSION['sync_appointment_id'])) { - header('Location: ' . $this->config->base_url() . 'appointments/google_sync/' . $_SESSION['sync_appointment_id'] . '?code=' . $_GET['code']); + header('Location: ' . $this->config->base_url() . 'appointments/google_sync/' + . $_SESSION['sync_appointment_id'] . '?code=' . $_GET['code']); } else { echo 'An error occured during the Google Calendar API authorization process.'; } diff --git a/src/application/helpers/custom_exceptions_helper.php b/src/application/helpers/custom_exceptions_helper.php index 482f13a2..d0de816d 100644 --- a/src/application/helpers/custom_exceptions_helper.php +++ b/src/application/helpers/custom_exceptions_helper.php @@ -10,5 +10,10 @@ class DatabaseException extends Exception {} */ class ValidationException extends Exception {} +/** + * Notification Exception Class + */ +class NotificationException extends Exception {} + /* End of file exception_types_helper.php */ /* Location: ./application/helpers/exception_types_helper.php */ \ No newline at end of file diff --git a/src/application/libraries/google-api-php-client/Google_Client.php b/src/application/libraries/external/google-api-php-client/Google_Client.php similarity index 100% rename from src/application/libraries/google-api-php-client/Google_Client.php rename to src/application/libraries/external/google-api-php-client/Google_Client.php diff --git a/src/application/libraries/google-api-php-client/auth/Google_AssertionCredentials.php b/src/application/libraries/external/google-api-php-client/auth/Google_AssertionCredentials.php similarity index 100% rename from src/application/libraries/google-api-php-client/auth/Google_AssertionCredentials.php rename to src/application/libraries/external/google-api-php-client/auth/Google_AssertionCredentials.php diff --git a/src/application/libraries/google-api-php-client/auth/Google_Auth.php b/src/application/libraries/external/google-api-php-client/auth/Google_Auth.php similarity index 100% rename from src/application/libraries/google-api-php-client/auth/Google_Auth.php rename to src/application/libraries/external/google-api-php-client/auth/Google_Auth.php diff --git a/src/application/libraries/google-api-php-client/auth/Google_AuthNone.php b/src/application/libraries/external/google-api-php-client/auth/Google_AuthNone.php similarity index 100% rename from src/application/libraries/google-api-php-client/auth/Google_AuthNone.php rename to src/application/libraries/external/google-api-php-client/auth/Google_AuthNone.php diff --git a/src/application/libraries/google-api-php-client/auth/Google_LoginTicket.php b/src/application/libraries/external/google-api-php-client/auth/Google_LoginTicket.php similarity index 100% rename from src/application/libraries/google-api-php-client/auth/Google_LoginTicket.php rename to src/application/libraries/external/google-api-php-client/auth/Google_LoginTicket.php diff --git a/src/application/libraries/google-api-php-client/auth/Google_OAuth2.php b/src/application/libraries/external/google-api-php-client/auth/Google_OAuth2.php similarity index 100% rename from src/application/libraries/google-api-php-client/auth/Google_OAuth2.php rename to src/application/libraries/external/google-api-php-client/auth/Google_OAuth2.php diff --git a/src/application/libraries/google-api-php-client/auth/Google_P12Signer.php b/src/application/libraries/external/google-api-php-client/auth/Google_P12Signer.php similarity index 100% rename from src/application/libraries/google-api-php-client/auth/Google_P12Signer.php rename to src/application/libraries/external/google-api-php-client/auth/Google_P12Signer.php diff --git a/src/application/libraries/google-api-php-client/auth/Google_PemVerifier.php b/src/application/libraries/external/google-api-php-client/auth/Google_PemVerifier.php similarity index 100% rename from src/application/libraries/google-api-php-client/auth/Google_PemVerifier.php rename to src/application/libraries/external/google-api-php-client/auth/Google_PemVerifier.php diff --git a/src/application/libraries/google-api-php-client/auth/Google_Signer.php b/src/application/libraries/external/google-api-php-client/auth/Google_Signer.php similarity index 100% rename from src/application/libraries/google-api-php-client/auth/Google_Signer.php rename to src/application/libraries/external/google-api-php-client/auth/Google_Signer.php diff --git a/src/application/libraries/google-api-php-client/auth/Google_Verifier.php b/src/application/libraries/external/google-api-php-client/auth/Google_Verifier.php similarity index 100% rename from src/application/libraries/google-api-php-client/auth/Google_Verifier.php rename to src/application/libraries/external/google-api-php-client/auth/Google_Verifier.php diff --git a/src/application/libraries/google-api-php-client/cache/Google_ApcCache.php b/src/application/libraries/external/google-api-php-client/cache/Google_ApcCache.php similarity index 100% rename from src/application/libraries/google-api-php-client/cache/Google_ApcCache.php rename to src/application/libraries/external/google-api-php-client/cache/Google_ApcCache.php diff --git a/src/application/libraries/google-api-php-client/cache/Google_Cache.php b/src/application/libraries/external/google-api-php-client/cache/Google_Cache.php similarity index 100% rename from src/application/libraries/google-api-php-client/cache/Google_Cache.php rename to src/application/libraries/external/google-api-php-client/cache/Google_Cache.php diff --git a/src/application/libraries/google-api-php-client/cache/Google_FileCache.php b/src/application/libraries/external/google-api-php-client/cache/Google_FileCache.php similarity index 100% rename from src/application/libraries/google-api-php-client/cache/Google_FileCache.php rename to src/application/libraries/external/google-api-php-client/cache/Google_FileCache.php diff --git a/src/application/libraries/google-api-php-client/cache/Google_MemcacheCache.php b/src/application/libraries/external/google-api-php-client/cache/Google_MemcacheCache.php similarity index 100% rename from src/application/libraries/google-api-php-client/cache/Google_MemcacheCache.php rename to src/application/libraries/external/google-api-php-client/cache/Google_MemcacheCache.php diff --git a/src/application/libraries/google-api-php-client/config.php b/src/application/libraries/external/google-api-php-client/config.php similarity index 100% rename from src/application/libraries/google-api-php-client/config.php rename to src/application/libraries/external/google-api-php-client/config.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_AdExchangeSellerService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_AdExchangeSellerService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_AdExchangeSellerService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_AdExchangeSellerService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_AdexchangebuyerService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_AdexchangebuyerService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_AdexchangebuyerService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_AdexchangebuyerService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_AdsenseService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_AdsenseService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_AdsenseService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_AdsenseService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_AdsensehostService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_AdsensehostService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_AdsensehostService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_AdsensehostService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_AnalyticsService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_AnalyticsService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_AnalyticsService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_AnalyticsService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_AndroidpublisherService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_AndroidpublisherService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_AndroidpublisherService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_AndroidpublisherService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_AuditService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_AuditService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_AuditService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_AuditService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_BigqueryService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_BigqueryService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_BigqueryService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_BigqueryService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_BloggerService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_BloggerService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_BloggerService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_BloggerService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_BooksService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_BooksService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_BooksService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_BooksService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_CalendarService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_CalendarService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_CalendarService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_CalendarService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_ComputeService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_ComputeService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_ComputeService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_ComputeService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_CustomsearchService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_CustomsearchService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_CustomsearchService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_CustomsearchService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_DfareportingService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_DfareportingService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_DfareportingService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_DfareportingService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_DriveService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_DriveService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_DriveService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_DriveService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_FreebaseService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_FreebaseService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_FreebaseService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_FreebaseService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_FusiontablesService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_FusiontablesService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_FusiontablesService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_FusiontablesService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_GanService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_GanService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_GanService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_GanService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_GroupssettingsService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_GroupssettingsService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_GroupssettingsService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_GroupssettingsService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_LatitudeService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_LatitudeService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_LatitudeService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_LatitudeService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_LicensingService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_LicensingService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_LicensingService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_LicensingService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_ModeratorService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_ModeratorService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_ModeratorService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_ModeratorService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_Oauth2Service.php b/src/application/libraries/external/google-api-php-client/contrib/Google_Oauth2Service.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_Oauth2Service.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_Oauth2Service.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_OrkutService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_OrkutService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_OrkutService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_OrkutService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_PagespeedonlineService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_PagespeedonlineService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_PagespeedonlineService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_PagespeedonlineService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_PlusService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_PlusService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_PlusService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_PlusService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_PredictionService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_PredictionService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_PredictionService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_PredictionService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_ResellerService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_ResellerService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_ResellerService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_ResellerService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_ShoppingService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_ShoppingService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_ShoppingService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_ShoppingService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_SiteVerificationService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_SiteVerificationService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_SiteVerificationService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_SiteVerificationService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_StorageService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_StorageService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_StorageService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_StorageService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_TaskqueueService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_TaskqueueService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_TaskqueueService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_TaskqueueService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_TasksService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_TasksService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_TasksService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_TasksService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_TranslateService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_TranslateService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_TranslateService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_TranslateService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_UrlshortenerService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_UrlshortenerService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_UrlshortenerService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_UrlshortenerService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_WebfontsService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_WebfontsService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_WebfontsService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_WebfontsService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_YouTubeAnalyticsService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_YouTubeAnalyticsService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_YouTubeAnalyticsService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_YouTubeAnalyticsService.php diff --git a/src/application/libraries/google-api-php-client/contrib/Google_YouTubeService.php b/src/application/libraries/external/google-api-php-client/contrib/Google_YouTubeService.php similarity index 100% rename from src/application/libraries/google-api-php-client/contrib/Google_YouTubeService.php rename to src/application/libraries/external/google-api-php-client/contrib/Google_YouTubeService.php diff --git a/src/application/libraries/google-api-php-client/external/URITemplateParser.php b/src/application/libraries/external/google-api-php-client/external/URITemplateParser.php similarity index 100% rename from src/application/libraries/google-api-php-client/external/URITemplateParser.php rename to src/application/libraries/external/google-api-php-client/external/URITemplateParser.php diff --git a/src/application/libraries/google-api-php-client/io/Google_CacheParser.php b/src/application/libraries/external/google-api-php-client/io/Google_CacheParser.php similarity index 100% rename from src/application/libraries/google-api-php-client/io/Google_CacheParser.php rename to src/application/libraries/external/google-api-php-client/io/Google_CacheParser.php diff --git a/src/application/libraries/google-api-php-client/io/Google_CurlIO.php b/src/application/libraries/external/google-api-php-client/io/Google_CurlIO.php similarity index 100% rename from src/application/libraries/google-api-php-client/io/Google_CurlIO.php rename to src/application/libraries/external/google-api-php-client/io/Google_CurlIO.php diff --git a/src/application/libraries/google-api-php-client/io/Google_HttpRequest.php b/src/application/libraries/external/google-api-php-client/io/Google_HttpRequest.php similarity index 100% rename from src/application/libraries/google-api-php-client/io/Google_HttpRequest.php rename to src/application/libraries/external/google-api-php-client/io/Google_HttpRequest.php diff --git a/src/application/libraries/google-api-php-client/io/Google_IO.php b/src/application/libraries/external/google-api-php-client/io/Google_IO.php similarity index 100% rename from src/application/libraries/google-api-php-client/io/Google_IO.php rename to src/application/libraries/external/google-api-php-client/io/Google_IO.php diff --git a/src/application/libraries/google-api-php-client/io/Google_REST.php b/src/application/libraries/external/google-api-php-client/io/Google_REST.php similarity index 100% rename from src/application/libraries/google-api-php-client/io/Google_REST.php rename to src/application/libraries/external/google-api-php-client/io/Google_REST.php diff --git a/src/application/libraries/google-api-php-client/io/cacerts.pem b/src/application/libraries/external/google-api-php-client/io/cacerts.pem similarity index 100% rename from src/application/libraries/google-api-php-client/io/cacerts.pem rename to src/application/libraries/external/google-api-php-client/io/cacerts.pem diff --git a/src/application/libraries/google-api-php-client/service/Google_BatchRequest.php b/src/application/libraries/external/google-api-php-client/service/Google_BatchRequest.php similarity index 100% rename from src/application/libraries/google-api-php-client/service/Google_BatchRequest.php rename to src/application/libraries/external/google-api-php-client/service/Google_BatchRequest.php diff --git a/src/application/libraries/google-api-php-client/service/Google_MediaFileUpload.php b/src/application/libraries/external/google-api-php-client/service/Google_MediaFileUpload.php similarity index 100% rename from src/application/libraries/google-api-php-client/service/Google_MediaFileUpload.php rename to src/application/libraries/external/google-api-php-client/service/Google_MediaFileUpload.php diff --git a/src/application/libraries/google-api-php-client/service/Google_Model.php b/src/application/libraries/external/google-api-php-client/service/Google_Model.php similarity index 100% rename from src/application/libraries/google-api-php-client/service/Google_Model.php rename to src/application/libraries/external/google-api-php-client/service/Google_Model.php diff --git a/src/application/libraries/google-api-php-client/service/Google_Service.php b/src/application/libraries/external/google-api-php-client/service/Google_Service.php similarity index 100% rename from src/application/libraries/google-api-php-client/service/Google_Service.php rename to src/application/libraries/external/google-api-php-client/service/Google_Service.php diff --git a/src/application/libraries/google-api-php-client/service/Google_ServiceResource.php b/src/application/libraries/external/google-api-php-client/service/Google_ServiceResource.php similarity index 100% rename from src/application/libraries/google-api-php-client/service/Google_ServiceResource.php rename to src/application/libraries/external/google-api-php-client/service/Google_ServiceResource.php diff --git a/src/application/libraries/google-api-php-client/service/Google_Utils.php b/src/application/libraries/external/google-api-php-client/service/Google_Utils.php similarity index 100% rename from src/application/libraries/google-api-php-client/service/Google_Utils.php rename to src/application/libraries/external/google-api-php-client/service/Google_Utils.php diff --git a/src/application/libraries/google_sync.php b/src/application/libraries/google_sync.php index c0c7a9ba..e725a89c 100644 --- a/src/application/libraries/google_sync.php +++ b/src/application/libraries/google_sync.php @@ -1,8 +1,8 @@ client->authenticate($_GET['code']); $_SESSION['google_api_token'] = $this->client->getAccessToken(); - header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); // refreshes current url + header('Location: http://' . $_SERVER['HTTP_HOST'] + . $_SERVER['PHP_SELF']); // refreshes current url } // If there is an active token then assign it to the client object. @@ -109,7 +110,7 @@ class Google_Sync { $event = new Google_Event(); $event->setSummary($service['name']); - $event->setLocation($CI->Settings_Model->get_setting('business_name')); + $event->setLocation($CI->Settings_Model->get_setting('company_name')); $start = new Google_EventDateTime(); $start->setDateTime(date3339(strtotime($appointment['start_datetime']))); diff --git a/src/application/libraries/notifications.php b/src/application/libraries/notifications.php index 945b64df..d25ca468 100644 --- a/src/application/libraries/notifications.php +++ b/src/application/libraries/notifications.php @@ -1,7 +1,6 @@ CI =& get_instance(); + } + + /** + * Replace the email template variables. + * + * This method finds and replaces the html variables of an email + * template. It is used to generate dynamic HTML emails that are + * send as notifications to the system users. + * + * @param array $replace_array Array that contains the variables + * to be replaced. + * @param string $email_html The email template hmtl. + * @return string Returns the new email html that contain the variables + * of the $replace_array. + */ + private function replace_template_variables($replace_array, $email_html) { + foreach($replace_array as $var=>$value) { + $email_html = str_replace($var, $value, $email_html); + } + + return $email_html; } /** * Send a success email to the customer that booked * a new appointment. * + * @expectedException NotificationException Raises when an unexpected + * error has occured when the email is send. + * * @param array $customer_data Associative array with the customer's * data. Each key has the same name as the corresponding field in db. * @param array $appointment_data Associative array with the appointment's @@ -29,96 +54,50 @@ class Notifications { * @return bool Returns the operation result. */ public function send_book_success($customer_data, $appointment_data) { - $CI =& get_instance(); - $CI->load->model('Providers_Model'); - $CI->load->model('Services_Model'); + $this->CI->load->model('Providers_Model'); + $this->CI->load->model('Services_Model'); + $this->CI->load->model('Settings_Model'); - $html = ' - - - Appointment Book Success! - - -

Your appointment has been successfully booked!

- Appointment Details - - - - - - - - - - - - - - - - - -
Service: ' . $CI->Services_Model->get_value('name', $appointment_data['id_services']) . '
Provider: ' . $CI->Providers_Model->get_value('last_name', $appointment_data['id_users_provider']) . ' ' . $CI->Providers_Model->get_value('first_name', $appointment_data['id_users_provider']) . '
Start Date: ' . date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])) . '
Duration: ' . $CI->Services_Model->get_value('duration', $appointment_data['id_services']) . ' minutes
-

- Customer Details - - - - - - - - - - - - - - - - - -
Name: ' . $customer_data['last_name'] . ' ' . $customer_data['first_name'] . '
Email: ' . $customer_data['email'] . '
Phone: ' . $customer_data['phone_number'] . '
Address: ' . $customer_data['address'] . ', ' . $customer_data['city'] . ', ' . $customer_data['zip_code'] . '
- - '; + $provider_data = $this->CI->Providers_Model->get_row($appointment_data['id_users_provider']); + $service_data = $this->CI->Services_Model->get_row($appointment_data['id_services']); - // Send email to the customer - $to = $customer_data['email']; + $replace_array = array( + '$appointment_service' => $service_data['name'], + '$appointment_provider' => $provider_data['first_name'] . ' ' . $provider_data['last_name'], + '$appointment_date' => date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])), + '$appointment_duration' => $service_data['duration'] . ' minutes', + '$company_link' => $this->CI->Settings_Model->get_setting('company_link'), + '$company_name' => $this->CI->Settings_Model->get_setting('company_name'), + '$customer_name' => $customer_data['first_name'] . ' ' . $customer_data['last_name'] + ); - $CI->load->model('Settings_Model'); - $from_email = $CI->Settings_Model->get_setting('business_email'); - $from_name = $CI->Settings_Model->get_setting('business_name'); + $email_html = file_get_contents(dirname(dirname(__FILE__)) . '/views/emails/book_success.php'); + $email_html = $this->replace_template_variables($replace_array, $email_html); - $subject = 'Appointment Book Success!'; - $headers = $this->get_email_headers($customer_data['last_name'] . ' ' . $customer_data['first_name'], $customer_data['email'], $from_name, $from_email); + $mail = new PHPMailer(); + $mail->From = $this->CI->Settings_Model->get_setting('company_email'); + $mail->FromName = $this->CI->Settings_Model->get_setting('company_name'); + $mail->AddAddress($customer_data['email']); // Do not use the name argument, phpmailer crushes. + $mail->IsHTML(true); + $mail->CharSet = 'UTF-8'; + $mail->Subject = 'Appointment Book Success!'; + $mail->Body = $email_html; + + if(!$mail->Send()) { + throw new NotificationException('Email could not been sent. ' + . 'Mailer Error (' . __LINE__ . '): ' . $mail->ErrorInfo); + } - return mail($to, $subject, $html, $headers); - } - - /** - * Create the email headers. - * - * This method cretes the email header depending the sender and - * the receiver. - * - * @param type $to_name Receiver's name - * @param type $to_email Receiver's email address - * @param type $from_name Sender's name - * @param type $from_email Sender's email - * @return string Returns the email headers. - */ - private function get_email_headers($to_name, $to_email, $from_name, $from_email) { - $headers = EMAIL_HEADER_MIME_VERSION; - $headers .= EMAIL_HEADER_CONTENT_TYPE; - $headers .= 'To: ' . $to_name . ' <' . $to_email . '>' . "\r\n"; - $headers .= 'From: ' . $from_name . ' <' . $from_email . '>' . "\r\n"; - return $headers; + return TRUE; } /** * Send an email notification to a provider that * a new appointment has been added to his plan. * + * @expectedException NotificationException Raises when an unexpected + * error has occured when the email is send. + * * @param array $customer_data Associative array with the customer's * data. Each key has the same name as the corresponding field in db. * @param array $appointment_data Associative array with the appointment's @@ -126,71 +105,45 @@ class Notifications { * @return bool Returns the operation result. */ public function send_new_appointment($customer_data, $appointment_data) { - $CI =& get_instance(); - $CI->load->model('Providers_Model'); - $CI->load->model('Services_Model'); + $this->CI =& get_instance(); + $this->CI->load->model('Providers_Model'); + $this->CI->load->model('Services_Model'); + $this->CI->load->model('Settings_Model'); - $html = ' - - - A new appointment has been added to your plan. - - -

A new appointment has been added to your plan.

- Appointment Details - - - - - - - - - - - - - - - - - -
Service: ' . $CI->Services_Model->get_value('name', $appointment_data['id_services']) . '
Provider: ' . $CI->Providers_Model->get_value('last_name', $appointment_data['id_users_provider']) . ' ' . $CI->Providers_Model->get_value('first_name', $appointment_data['id_users_provider']) . '
Start Date: ' . date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])) . '
Duration: ' . $CI->Services_Model->get_value('duration', $appointment_data['id_services']) . ' minutes
-

- Customer Details - - - - - - - - - - - - - - - - - -
Name: ' . $customer_data['last_name'] . ' ' . $customer_data['first_name'] . '
Email: ' . $customer_data['email'] . '
Phone: ' . $customer_data['phone_number'] . '
Address: ' . $customer_data['address'] . ', ' . $customer_data['city'] . ', ' . $customer_data['zip_code'] . '
- - '; + $provider_data = $this->CI->Providers_Model->get_row($appointment_data['id_users_provider']); + $service_data = $this->CI->Services_Model->get_row($appointment_data['id_services']); + + $replace_array = array( + '$appointment_service' => $service_data['name'], + '$appointment_provider' => $provider_data['first_name'] . ' ' . $provider_data['last_name'], + '$appointment_date' => date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])), + '$appointment_duration' => $service_data['duration'] . ' minutes', + '$company_link' => $this->CI->Settings_Model->get_setting('company_link'), + '$company_name' => $this->CI->Settings_Model->get_setting('company_name'), + '$customer_name' => $customer_data['first_name'] . ' ' . $customer_data['last_name'], + '$customer_email' => $customer_data['email'], + '$customer_phone' => $customer_data['phone_number'], + '$customer_address' => $customer_data['address'] + ); - // Send email to the customer - $provider_email = $CI->Providers_Model->get_value('email', $appointment_data['id_users_provider']); - $provider_nicename = $CI->Providers_Model->get_value('last_name', $appointment_data['id_users_provider']) . ' ' . $CI->Providers_Model->get_value('first_name', $appointment_data['id_users_provider']); + $email_html = file_get_contents(dirname(dirname(__FILE__)) . '/views/emails/new_appointment.php'); + $email_html = $this->replace_template_variables($replace_array, $email_html); - $CI->load->model('Settings_Model'); - $from_email = $CI->Settings_Model->get_setting('business_email'); - $from_name = $CI->Settings_Model->get_setting('business_name'); + $mail = new PHPMailer(); + $mail->From = $this->CI->Settings_Model->get_setting('company_email'); + $mail->FromName = $this->CI->Settings_Model->get_setting('company_name');; + $mail->AddAddress($provider_data['email']); // Do not use the name argument, phpmailer crushes. + $mail->IsHTML(true); + $mail->CharSet = 'UTF-8'; + $mail->Subject = 'New Appointment'; + $mail->Body = $email_html; + + if(!$mail->Send()) { + throw new NotificationException('Email could not been sent. ' + . 'Mailer Error (Line ' . __LINE__ . '): ' . $mail->ErrorInfo); + } - $subject = 'A new appointment has been added to your plan.'; - $headers = $this->get_email_headers($provider_nicename, $provider_email, $from_name, $from_email); - - return mail($provider_email, $subject, $html, $headers); + return TRUE; } } diff --git a/src/application/models/appointments_model.php b/src/application/models/appointments_model.php index 185cc5e7..f267b99b 100644 --- a/src/application/models/appointments_model.php +++ b/src/application/models/appointments_model.php @@ -212,7 +212,7 @@ class Appointments_Model extends CI_Model { * @return bool Returns the delete operation result. */ public function delete($appointment_id) { - if (!is_int($appointment_id)) { + if (!is_numeric($appointment_id)) { throw new InvalidArgumentException('Invalid argument type $appointment_id : ' . $appointment_id); } @@ -235,7 +235,7 @@ class Appointments_Model extends CI_Model { * field names. */ public function get_row($appointment_id) { - if (!is_int($appointment_id)) { + if (!is_numeric($appointment_id)) { throw new InvalidArgumentException('Invalid argument given. Expected integer for the $appointment_id : ' . $appointment_id); } return $this->db->get_where('ea_appointments', array('id' => $appointment_id))->row_array(); @@ -250,7 +250,7 @@ class Appointments_Model extends CI_Model { * @return string Returns the records value from the database. */ public function get_value($field_name, $appointment_id) { - if (!is_int($appointment_id)) { + if (!is_numeric($appointment_id)) { throw new InvalidArgumentException('Invalid argument given, expected integer for the $appointment_id : ' . $appointment_id); } diff --git a/src/application/models/customers_model.php b/src/application/models/customers_model.php index d89c0be0..e74b7d96 100644 --- a/src/application/models/customers_model.php +++ b/src/application/models/customers_model.php @@ -193,7 +193,7 @@ class Customers_Model extends CI_Model { * @return bool Returns the delete operation result. */ public function delete($customer_id) { - if (!is_int($customer_id)) { + if (!is_numeric($customer_id)) { throw new InvalidArgumentException('Invalid argument type $customer_id : ' . $customer_id); } @@ -215,7 +215,7 @@ class Customers_Model extends CI_Model { * field names. */ public function get_row($customer_id) { - if (!is_int($customer_id)) { + if (!is_numeric($customer_id)) { throw new InvalidArgumentException('Invalid argument provided as $customer_id : ' . $customer_id); } return $this->db->get_where('ea_users', array('id' => $customer_id))->row_array(); @@ -230,7 +230,7 @@ class Customers_Model extends CI_Model { * @return string Returns the records value from the database. */ public function get_value($field_name, $customer_id) { - if (!is_int($customer_id)) { + if (!is_numeric($customer_id)) { throw new InvalidArgumentException('Invalid argument provided as $customer_id : ' . $customer_id); } diff --git a/src/application/models/providers_model.php b/src/application/models/providers_model.php index 06d2f0bf..d967fdfc 100644 --- a/src/application/models/providers_model.php +++ b/src/application/models/providers_model.php @@ -17,7 +17,7 @@ class Providers_Model extends CI_Model { * field names. */ public function get_row($provider_id) { - if (!is_int($provider_id)) { + if (!is_numeric($provider_id)) { throw new InvalidArgumentException('$provider_id argument is not an integer : ' . $provider_id); } return $this->db->get_where('ea_users', array('id' => $provider_id))->row_array(); @@ -32,7 +32,7 @@ class Providers_Model extends CI_Model { * @return string Returns the records value from the database. */ public function get_value($field_name, $provider_id) { - if (!is_int($provider_id)) { + if (!is_numeric($provider_id)) { throw new InvalidArgumentException('Invalid argument provided as $customer_id : ' . $provider_id); } diff --git a/src/application/models/services_model.php b/src/application/models/services_model.php index 51786b91..d97f13b1 100644 --- a/src/application/models/services_model.php +++ b/src/application/models/services_model.php @@ -16,7 +16,7 @@ class Services_Model extends CI_Model { * field names. */ public function get_row($service_id) { - if (!is_int($service_id)) { + if (!is_numeric($service_id)) { throw new InvalidArgumentException('$service_id argument is not an integer : ' . $service_id); } return $this->db->get_where('ea_services', array('id' => $service_id))->row_array(); @@ -31,7 +31,7 @@ class Services_Model extends CI_Model { * @return string Returns the records value from the database. */ public function get_value($field_name, $service_id) { - if (!is_int($service_id)) { + if (!is_numeric($service_id)) { throw new InvalidArgumentException('Invalid argument provided as $service_id : ' . $service_id); } diff --git a/src/application/views/appointments/book.php b/src/application/views/appointments/book.php index 7dcbb18a..b2f63811 100644 --- a/src/application/views/appointments/book.php +++ b/src/application/views/appointments/book.php @@ -4,23 +4,62 @@ - - - - - + + + + + - - - - - - - + + + + + + + - + + - - + + - +