From 1449555d15916ff7987e68861b587a920463a9b0 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 27 Jul 2016 15:47:23 +0200 Subject: Edit contact languages --- classes/contact.php | 6 + classes/correspondence.php | 44 ++++--- include/clients-view.php | 80 ++++++------ include/contacts-edit.php | 3 + include/contacts-overview.php | 280 +++++++++++++++++++++--------------------- 5 files changed, 218 insertions(+), 195 deletions(-) diff --git a/classes/contact.php b/classes/contact.php index 989a14f..7741c17 100644 --- a/classes/contact.php +++ b/classes/contact.php @@ -317,13 +317,19 @@ class contact { /** * Set the language of the contact * + * @see correspondence::LANGUAGES The available languages + * * @param string $language The new language for the contact * * @throws PDOException If something went wrong with the database + * @throws Exception If the language is unknown * * @return bool True on succes, false on failure */ public function setLanguage($language) { + if (!in_array($language, correspondence::LANGUAGES)) { + throw new Exception("Language $language not available."); + } $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `language`=? WHERE `id`=?"); $stmt->execute(array($language, $this->id)); if ($stmt->rowCount() == 1) { diff --git a/classes/correspondence.php b/classes/correspondence.php index 7838393..eb18b7d 100644 --- a/classes/correspondence.php +++ b/classes/correspondence.php @@ -38,64 +38,72 @@ class correspondence extends FPDF { const HEAD_GREEN = 0; const HEAD_BLUE = 0; + /** + * Available languages + * + * @see _() Translation function + * @see $translations Translations table + */ + const LANGUAGES = ['en', 'nl']; + /** * Array holding the translations * * @see _() A function to translate */ protected static $translations = array( - 'adres' => array( + 'adres' => array( 'en' => 'Address', 'nl' => 'Adres'), - 'amount' => array( + 'amount' => array( 'en' => 'Amount', 'nl' => 'Subtotaal'), - 'amount-due' => array( + 'amount-due' => array( 'en' => 'Total amount due', 'nl' => 'Te voldoen'), - 'biccode' => array( + 'biccode' => array( 'en' => 'The BIC code of our bank is %%.', 'nl' => 'De BIC-code van de bank is %%.'), - 'btwnr' => array( + 'btwnr' => array( 'en' => 'VAT nr', 'nl' => 'BTW nr'), - 'description' => array( + 'description' => array( 'en' => 'Description', 'nl' => 'Omschrijving'), - 'due-date' => array( + 'due-date' => array( 'en' => 'Due date', 'nl' => 'Vervaldatum'), - 'email' => array( + 'email' => array( 'en' => 'Email', 'nl' => 'Email'), - 'iban' => array( + 'iban' => array( 'en' => 'IBAN', 'nl' => 'IBAN'), - 'invoice' => array( + 'invoice' => array( 'en' => 'Invoice', 'nl' => 'Factuur'), - 'invoice-date' => array( + 'invoice-date' => array( 'en' => 'Invoice date', 'nl' => 'Factuurdatum'), - 'invoice-nr' => array( + 'invoice-nr' => array( 'en' => 'Invoice number', 'nl' => 'Factuurnummer'), - 'price-excl' => array( + 'price-excl' => array( 'en' => 'Price excl.', 'nl' => 'Prijs excl.'), - 'price-incl' => array( + 'price-incl' => array( 'en' => 'Price incl.', 'nl' => 'Prijs incl.'), - 'request' => array( + 'request' => array( 'en' => 'You are kindly requested to transfer the total amount before the due date to the provided IBAN nr.', 'nl' => 'U wordt vriendelijk verzocht het te voldoen bedrag voor de vervaldatum van de factuur over te maken naar opgegeven IBAN-nummer.'), - 'tel-nr' => array( + 'tel-nr' => array( 'en' => 'Tel.', 'nl' => 'Tel.'), - 'total' => array( + 'total' => array( 'en' => 'Total', 'nl' => 'Totaal'), - 'vat' => array( + 'vat' => array( 'en' => 'VAT', 'nl' => 'BTW'), ); diff --git a/include/clients-view.php b/include/clients-view.php index 101d530..514e4e4 100644 --- a/include/clients-view.php +++ b/include/clients-view.php @@ -22,43 +22,45 @@ require_once('./login.php'); $_client = new client($_pdo, $_id); ?>
-
-
Contacts
-
- - - - - - - - - - - getContacts(); - foreach ($contacts as $contact) { - echo " - - - - - "; - } - if (count($contacts) == 0) { - echo ""; - } - ?> - -
#NameAddressTools
{$contact->getId()}{$contact->getName()} - {$contact->getAddress()}
- {$contact->getPostalCode()} - {$contact->getCity()}
- {$contact->getCountry()} -
- - -
There are no contacts in the database. Why not create one?
-
-
+
+
Contacts
+
+ + + + + + + + + + + + getContacts(); + foreach ($contacts as $contact) { + echo " + + + + + + "; + } + if (count($contacts) == 0) { + echo ""; + } + ?> + +
#NameAddressLanguageTools
{$contact->getId()}{$contact->getName()} + {$contact->getAddress()}
+ {$contact->getPostalCode()} + {$contact->getCity()}
+ {$contact->getCountry()} +
{$contact->getLanguage()} + + +
There are no contacts in the database. Why not create one?
+
+
diff --git a/include/contacts-edit.php b/include/contacts-edit.php index a2101b2..a5b3bdd 100644 --- a/include/contacts-edit.php +++ b/include/contacts-edit.php @@ -46,6 +46,9 @@ try { case 'country': $response->success = $contact->setCountry($_REQUEST['value']); break; + case 'language': + $response->success = $contact->setLanguage($_REQUEST['value']); + break; default: $response->http_response_code(404); $response->success = false; diff --git a/include/contacts-overview.php b/include/contacts-overview.php index cd7fc47..c1f282b 100644 --- a/include/contacts-overview.php +++ b/include/contacts-overview.php @@ -2,17 +2,17 @@ /** * BusinessAdmin: administrative software for small companies * Copyright (C) 2015 Camil Staps (ViviSoft) - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -21,144 +21,148 @@ require_once('./login.php'); ?>
-
-
Overview
-
- - - - - - - - - - - getId()}' - data-mixer-order-name='{$contact->getName()}'> - - - - - "; - } - if (count($contacts) == 0) { - echo ""; - } - ?> - -
#NameAddressTools
{$contact->getId()} - {$contact->getName()}
- ({$contact->getClient()->getName()}) -
- {$contact->getEmail()}
-
- {$contact->getAddress()}
- " . ($contact->getAddress_2() != '' ? "{$contact->getAddress_2()}
" : "") . " - {$contact->getPostalCode()} - {$contact->getCity()}
- {$contact->getCountry()} -
- - -
There are no contacts in the database. Why not start with creating one, on the right?
-
-
+
+
Overview
+
+ + + + + + + + + + + + getId()}' + data-mixer-order-name='{$contact->getName()}'> + + + + + + "; + } + if (count($contacts) == 0) { + echo ""; + } + ?> + +
#NameAddressLanguageTools
{$contact->getId()} + {$contact->getName()}
+ ({$contact->getClient()->getName()}) +
+ {$contact->getEmail()}
+
+ {$contact->getAddress()}
+ " . ($contact->getAddress_2() != '' ? "{$contact->getAddress_2()}
" : "") . " + {$contact->getPostalCode()} + {$contact->getCity()}
+ {$contact->getCountry()} +
+ {$contact->getLanguage()} + + + +
There are no contacts in the database. Why not start with creating one, on the right?
+
+
-
-
Create new
-
-
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
-
- -
-
- -
-
- -
- -
- -
-
+ // Callback for when form submission encountered an error + function newContactError() { + $('#newContact .ajaxify-response') + .addClass('alert-danger') + .show() + .find('.ajaxify-response-text') + .html('An unknown error occurred. Please contact support.'); + + $('#newContact input, #newContact button').prop('disabled', false); + $('#newContact').data('bootstrapValidator').resetForm(); + } + +
+ -- cgit v1.2.3