diff --git a/.htaccess b/.htaccess index 013cda8..5e16b4a 100644 --- a/.htaccess +++ b/.htaccess @@ -1,5 +1,3 @@ -Options +FollowSymlinks - RewriteEngine on RewriteBase / diff --git a/index.php b/index.php index f87b67c..965d32f 100644 --- a/index.php +++ b/index.php @@ -12,10 +12,10 @@ date_default_timezone_set( 'Europe/Paris' ); setlocale( LC_TIME, "fr_FR.UTF-8" ); error_reporting( E_ALL ); -require( 'src/lib/functions.php' ); -require( 'src/config.php' ); +require( "src/lib/functions.php" ); +require( "src/Config.php" ); -require 'src/Autoloader.php'; +require( "src/Autoloader.php" ); Autoloader::register(); new BDD(); diff --git a/robots.txt b/robots.txt new file mode 100644 index 0000000..14267e9 --- /dev/null +++ b/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Allow: / \ No newline at end of file diff --git a/src/API/APIContact.php b/src/API/APIContact.php index 4722bbd..3c75014 100644 --- a/src/API/APIContact.php +++ b/src/API/APIContact.php @@ -172,7 +172,7 @@ class APIContact extends API { } public function search( array $data ) { - if ( count_chars( $data[ "query" ] ) >= 3 ) { + if ( count_chars( $data[ "query" ] ) >= 2 ) { $result = Contact::search( $data[ "query" ] ); if ( $result !== null ) { $this->returnJson( [ diff --git a/src/Config.php b/src/Config.php index a7137e7..6efd75c 100644 --- a/src/Config.php +++ b/src/Config.php @@ -3,8 +3,8 @@ namespace CAUProject3Contact; class Config { - const SITE_JS_VERSION = '0.01'; - const SITE_CSS_VERSION = '0.01'; + const SITE_JS_VERSION = '0.02'; + const SITE_CSS_VERSION = '0.02'; const TITLE_HEADER = 'Your contact'; const DESCRIPTION_HEADER = 'Manage your contact easly'; diff --git a/src/Controller/site/Index.php b/src/Controller/Site/Index.php similarity index 100% rename from src/Controller/site/Index.php rename to src/Controller/Site/Index.php diff --git a/src/Controller/site/SiteError.php b/src/Controller/Site/SiteError.php similarity index 100% rename from src/Controller/site/SiteError.php rename to src/Controller/Site/SiteError.php diff --git a/src/Controller/site/SiteRouter.php b/src/Controller/Site/SiteRouter.php similarity index 100% rename from src/Controller/site/SiteRouter.php rename to src/Controller/Site/SiteRouter.php diff --git a/src/Model/BDD.php b/src/Model/BDD.php index 27fa205..ec78ac8 100644 --- a/src/Model/BDD.php +++ b/src/Model/BDD.php @@ -8,16 +8,16 @@ use PDO; class BDD { // Server BDD -// const SQL_SERVER = 'sql.sanchez-mathieu.fr'; // BDD Server -// const SQL_LOGIN = 'why7n0_contact'; // BDD Login -// const SQL_PASSWORD = 'fC3c87Gy'; // BDD Password -// const SQL_DB = 'why7n0_contact'; // BDD Name + const SQL_SERVER = 'sql.sanchez-mathieu.fr'; // BDD Server + const SQL_LOGIN = 'why7n0_contact'; // BDD Login + const SQL_PASSWORD = 'fC3c87Gy'; // BDD Password + const SQL_DB = 'why7n0_contact'; // BDD Name // Local BDD - const SQL_SERVER = 'localhost'; // BDD Server - const SQL_LOGIN = 'root'; // BDD Login - const SQL_PASSWORD = ''; // BDD Password - const SQL_DB = 'contact'; // BDD Name +// const SQL_SERVER = 'localhost'; // BDD Server +// const SQL_LOGIN = 'root'; // BDD Login +// const SQL_PASSWORD = ''; // BDD Password +// const SQL_DB = 'contact'; // BDD Name private static $bdd; diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 3bffba0..22ee912 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -93,7 +93,7 @@ class Contact { $lastKey = endKey( $words ); foreach ( $words as $key => $word ) { $normal = self::getQuerySearch( $word, [ "first_name", "last_name", "surname" ] );; - $hard = self::getQuerySearch( $word, [ "email", "address", "phone_number" ] ); + $hard = self::getQuerySearch( $word, [ "email", "address", "phone_number", "birthday" ] ); $q1 .= $normal; $q2 .= $normal; $q3 .= $hard; diff --git a/src/View/Site/Index.php b/src/View/Site/Index.php index 891b5a4..7abeb8c 100644 --- a/src/View/Site/Index.php +++ b/src/View/Site/Index.php @@ -2,7 +2,7 @@
- +
@@ -12,12 +12,13 @@ + "; + echo ""; echo " "; echo " "; echo " "; @@ -25,6 +26,8 @@ echo " "; echo " "; echo " "; + echo " "; + echo " "; echo ""; } ?> diff --git a/src/View/Site/tpl/footer.php b/src/View/Site/tpl/footer.php index 0fbdf1b..6732fe2 100644 --- a/src/View/Site/tpl/footer.php +++ b/src/View/Site/tpl/footer.php @@ -1,16 +1,55 @@ - + @@ -14,6 +14,8 @@ let displayContacts = (contacts) => { + + `); } @@ -26,7 +28,7 @@ $(document).ready(() => { modal.modal(); let search = (query) => { - if (query.length >= 3) { + if (query.length >= 2) { working = true; $.ajax({ url: "/api/contact/search", @@ -60,15 +62,85 @@ $(document).ready(() => { if (!working) { search(query); - } else { lastQuery = query; + } else { + let i = setInterval(() => { + let newQuery = $("#search").val(); + + if (newQuery !== query) { + clearInterval(i); + } else { + if (!working) { + search(query); + lastQuery = query; + clearInterval(i); + } + } + }, 50); } }); $(document).on("click", ".add-contacts", () => { - modal.open(); + $("#modal").addClass("md-show"); }); - $("[data-tooltip]").tooltip(); + $(document).on("click", "#md-cancel", () => { + $("#modal").removeClass("md-show"); + }); + + $(document).on("click", "#md-validate", () => { + let firstName = $("#first_name").val(); + let lastName = $("#last_name").val(); + let surname = $("#surname").val(); + let email = $("#email").val(); + let address = $("#address").val(); + let phoneNumber = $("#phone_number").val(); + let birthday = $("#birthday").val(); + + if (firstName !== "" && lastName !== "") { + let data = { + firstName, + lastName, + surname: (surname !== "" ? surname : null), + email: (email !== "" ? email : null), + address: (address !== "" ? address : null), + phoneNumber: (phoneNumber !== "" ? phoneNumber : null), + birthday: (birthday !== "" ? birthday : null), + }; + + $.ajax({ + url: "/api/contact/insert", + method: "POST", + data, + success: function (result) { + result = JSON.parse(result); + data["id"] = parseInt(result.data["id"], 10); + contacts.push(data); + + $("table tbody").empty(); + displayContacts(contacts); + $("#modal").removeClass("md-show"); + }, error: function () { + } + }); + } + }); + + $(document).on("click", ".delete", function () { + let $contact = $(this).closest("tr"); + let id = parseInt($contact.attr("data-id"), 10); + + $.ajax({ + url: "/api/contact/delete", + method: "POST", + data: { + id + }, + success: function () { + contacts = contacts.filter((c) => c.id !== id); + $contact.remove(); + } + }) + }); });
First NameAddress Phone Number Birthday
" . $contact->getFirstName() . "" . $contact->getLastName() . "" . ( $contact->getSurname() ? $contact->getSurname() : "" ) . "" . ( $contact->getAddress() ? $contact->getAddress() : "" ) . "" . ( $contact->getPhoneNumber() ? $contact->getPhoneNumber() : "" ) . "" . ( $contact->getBirthday() ? date( "Y-m-d", strtotime( $contact->getBirthday() ) ) : "" ) . "createdelete
${(contact["first_name"] ? contact["first_name"] : (contact["firstName"] ? contact["firstName"] : ""))} ${(contact["last_name"] ? contact["last_name"] : (contact["lastName"] ? contact["lastName"] : ""))} ${(contact["surname"] ? contact["surname"] : "")}${(contact["address"] ? contact["address"] : "")} ${(contact["phone_number"] ? contact["phone_number"] : (contact["phoneNumber"] ? contact["phoneNumber"] : ""))} ${(contact["birthday"] ? new Date(contact["birthday"]).toLocaleDateString() : "")}createdelete