From 6b55446d12a5c39d5a4a4584bfabc7507c2f9b74 Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 2 Dec 2022 15:29:02 +0100 Subject: date<->timestamp, ===, renommage, latex --- php/Connection.php | 35 +++++++++++++++ php/ConnectionDatabase.php | 35 --------------- php/DateTimestamp.php | 50 +++++++++++++++++++++ php/Latex.php | 84 ++++++++++++++++++++++++++++++++++ php/Model.php | 51 +-------------------- php/Zenity.php | 110 +++++++++++++++++++++++++++++++++++++++++++++ php/ZenityClasses.php | 110 --------------------------------------------- php/compileLatex.php | 30 ------------- php/dependances.php | 26 +++++------ php/functions.php | 2 +- php/latexToPdf.php | 38 ++++++++++++++++ php/main.php | 67 ++++++++++++++++----------- php/saisie.php | 16 ------- php/zenity_setup.php | 22 ++++----- 14 files changed, 384 insertions(+), 292 deletions(-) create mode 100644 php/Connection.php delete mode 100644 php/ConnectionDatabase.php create mode 100644 php/DateTimestamp.php create mode 100644 php/Latex.php create mode 100644 php/Zenity.php delete mode 100644 php/ZenityClasses.php delete mode 100644 php/compileLatex.php create mode 100644 php/latexToPdf.php delete mode 100644 php/saisie.php (limited to 'php') diff --git a/php/Connection.php b/php/Connection.php new file mode 100644 index 0000000..bdc7aa9 --- /dev/null +++ b/php/Connection.php @@ -0,0 +1,35 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // $this pour la méthode du parent PDO + } + catch(PDOException $e) + { + die('Erreur : '.$e->getMessage()); + } + } + + // créer son objet avec: $bdd = Connection::getInstance(); + public static function getInstance(): self + { + if(self::$Instance === null) + { + self::$Instance = new self(); + } + return self::$Instance; + } +} diff --git a/php/ConnectionDatabase.php b/php/ConnectionDatabase.php deleted file mode 100644 index b26d0bd..0000000 --- a/php/ConnectionDatabase.php +++ /dev/null @@ -1,35 +0,0 @@ -setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // $this pour la méthode du parent PDO - } - catch(PDOException $e) - { - die('Erreur : '.$e->getMessage()); - } - } - - // créer son objet avec: $bdd = Connection::getInstance(); - public static function getInstance(): self - { - if(self::$Instance === null) - { - self::$Instance = new self(); - } - return self::$Instance; - } -} diff --git a/php/DateTimestamp.php b/php/DateTimestamp.php new file mode 100644 index 0000000..ca07b0a --- /dev/null +++ b/php/DateTimestamp.php @@ -0,0 +1,50 @@ + timestamp (int) + private function get_timestamp(): int + { + if(self::$date_format === 'EU') + { + // change jj/mm/aaaa en jj-mm-aaaa + $this->date = preg_replace('#/#', '-', $this->date); + } + elseif(self::$date_format === 'US') + { + // change mm-dd.yyyy en mm/dd/yyyy + $this->date = preg_replace('#[-\.]#', '/', $this->date); + } + else + { + echo('Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur "EU" ou "US"'); + die(); // brutal + } + return(strtotime($this->date)); + // strtotime() devine le format en analysant la chaîne en entrée, on l'aide un peu + // avec des /, php considère que la date est américaine + // avec des - ou des ., php considère que la date est européenne + } + + // timestamp (int) -> date jj-mm-aaaa (string) + private function get_date(): string + { + if(self::$date_format === 'EU') + { + return(date("j-m-Y", $this->date)); + } + elseif(self::$date_format === 'US') + { + return(date("m/d/Y", $this->date)); + } + else + { + echo('Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur "EU" ou "US"'); + die(); // brutal + } + } +} diff --git a/php/Latex.php b/php/Latex.php new file mode 100644 index 0000000..e8ed763 --- /dev/null +++ b/php/Latex.php @@ -0,0 +1,84 @@ +fileName = $quoi . '-' . $codePresta . '.tex'; + } +} + +class DevisLatex extends PrestaLatex +{} + +class FactureLatex extends PrestaLatex +{} + +class LocationLatex extends PrestaLatex +{} + +class EnveloppeRectoLatex extends PrestaLatex +{} +class EnveloppeVersoLatex extends PrestaLatex +{} + + +abstract class ComptaLatex extends Latex +{ + public function __construct(string $quoi, , string $annee, int $numeroMois = 0) + { + nameTheFile($quoi, $annee, $numeroMois); + } + + // forme = Recettes-2022-06-Juin.tex ou Recettes-2022.tex + // type de 'annee'? + protected function nameTheFile(string $quoi, string $annee, int $numeroMois = 0) + { + $this->fileName = $quoi . '-' . $annee; + $mois = ['', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre']; + if($numeroMois > 0 && $numeroMois <= 12) + { + $this->fileName .= '-' . $numeroMois . '-' . $mois[$numeroMois]; + } + $this->fileName .= '.tex'; + } +} + +class LivreRecettesLatex extends ComptaLatex +{} + +class RegistreAchatsLatex extends ComptaLatex +{} + +class BilanLatex extends ComptaLatex +{} diff --git a/php/Model.php b/php/Model.php index f3f1fe7..d26b081 100644 --- a/php/Model.php +++ b/php/Model.php @@ -4,18 +4,15 @@ class Model extends Connection { private $db; // instance de connexion - private $date = ''; - static public $date_format; // dates européennes jj-mm-aaaa - // pourquoi ne pas mettre les fonctions concernées dans une interface? + public $date; public function __construct() { $this->db = parent::getInstance(); // connexion - self::create_tables(); } // code SQL - function create_tables() + public function create_tables() { // la table prestations est liée à la table clients // les tables devis_factures, cesu et locations sont liées à la table prestations @@ -42,48 +39,4 @@ class Model extends Connection // pour les dates, on stockera à priori le timestamp } - - - // date jour/mois/année (string) -> timestamp (int) - private function get_timestamp(): int - { - if(self::$date_format == 'EU') - { - // change jj/mm/aaaa en jj-mm-aaaa - $this->date = preg_replace('#/#', '-', $this->date); - } - elseif(self::$date_format == 'US') - { - // change mm-dd.yyyy en mm/dd/yyyy - $this->date = preg_replace('#[-\.]#', '/', $this->date); - } - else - { - echo('Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur "EU" ou "US"'); - die(); // brutal - } - return(strtotime($this->date)); - // strtotime() devine le format en analysant la chaîne en entrée, on l'aide un peu - // avec des /, php considère que la date est américaine - // avec des - ou des ., php considère que la date est européenne - } - - // timestamp (int) -> date jj-mm-aaaa (string) - private function get_date(): string - { - if(self::$date_format == 'EU') - { - return(date("j-m-Y", $this->date)); - } - elseif(self::$date_format == 'US') - { - return(date("m/d/Y", $this->date)); - } - else - { - echo('Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur "EU" ou "US"'); - die(); // brutal - } - } - } diff --git a/php/Zenity.php b/php/Zenity.php new file mode 100644 index 0000000..a04b794 --- /dev/null +++ b/php/Zenity.php @@ -0,0 +1,110 @@ +text = $text; + $this->rows= $rows; + $this->command .= $this->command_type; + $this->command .= ' --title="' . $this->title . '"'; + $this->command .= ' --text="' . $this->text . '"'; + } + + public function get() + { + return($this->command); + } +} + + +class ZenityList extends ZenityCmd +{ + public function __construct($text, array $rows) + { + $this->command_type = ' --list'; + parent::__construct($text, $rows); + $this->height = 80 + count($this->rows) * 25; + $this->command .= ' --width=' . $this->width; + $this->command .= ' --height=' . $this->height; + $this->command .= ' --hide-header'; // ligne inutile, il y a déjà le --text + self::one_column_zenity_list($this->rows); + } + + public function set_entries($rows_set) // variable renseignée après la construction + { + $this->rows = $rows_set; + } + + private function one_column_zenity_list($rows) + { + $output = ' --column=""'; + foreach($rows as $entry) + { + $output .= ' "' . $entry . '"'; // forme: ' "choix 1" "choix 2"' + } + $this->command .= $output; + } +} + +class ZenityQuestion extends ZenityCmd +{ + public function __construct($text) + { + $this->command_type = ' --question'; + parent::__construct($text); + $this->command .= ' && echo $?'; + // la sortie de "zenity --question" est le statut de sortie "$?" + // $? vaut 0 pour oui, 1 pour non, à ceci près que pour non zenity ne renvoie rien + } +} + +class ZenityForms extends ZenityCmd +{ + public function __construct($text, array $rows) + { + $this->command_type = ' --forms'; + parent::__construct($text, $rows); + //$this->height = 80 + count($this->rows) * 25; // à tester, mais devrait produire le rendu attendu + self::entries_zenity_forms($this->rows); + } + + private function entries_zenity_forms($entries) + { + $output = ''; + foreach($entries as $one_entry) + { + $output .= ' --add-entry="' . $one_entry . '"'; // forme: ' "choix 1" "choix 2"' + } + $this->command .= $output; + } +} + +class ZenityCalendar extends ZenityCmd +{ + public function __construct($text) + { + $this->command_type = ' --calendar'; + parent::__construct($text); + } +} + +class ZenityEntry extends ZenityCmd +{ + public function __construct($text) + { + $this->command_type = ' --entry'; + parent::__construct($text); + } +} diff --git a/php/ZenityClasses.php b/php/ZenityClasses.php deleted file mode 100644 index 7965012..0000000 --- a/php/ZenityClasses.php +++ /dev/null @@ -1,110 +0,0 @@ -text = $text; - $this->rows= $rows; - $this->command .= $this->command_type; - $this->command .= ' --title="' . $this->title . '"'; - $this->command .= ' --text="' . $this->text . '"'; - } - - public function get() - { - return($this->command); - } -} - - -class Zenity_list extends Zenity_cmd -{ - public function __construct($text, array $rows) - { - $this->command_type = ' --list'; - parent::__construct($text, $rows); - $this->height = 80 + count($this->rows) * 25; - $this->command .= ' --width=' . $this->width; - $this->command .= ' --height=' . $this->height; - $this->command .= ' --hide-header'; // ligne inutile, il y a déjà le --text - self::one_column_zenity_list($this->rows); - } - - public function set_entries($rows_set) // variable renseignée après la construction - { - $this->rows = $rows_set; - } - - private function one_column_zenity_list($rows) - { - $output = ' --column=""'; - foreach($rows as $entry) - { - $output .= ' "' . $entry . '"'; // forme: ' "choix 1" "choix 2"' - } - $this->command .= $output; - } -} - -class Zenity_question extends Zenity_cmd -{ - public function __construct($text) - { - $this->command_type = ' --question'; - parent::__construct($text); - $this->command .= ' && echo $?'; - // la sortie de "zenity --question" est le statut de sortie "$?" - // $? vaut 0 pour oui, 1 pour non, à ceci près que pour non zenity ne renvoie rien - } -} - -class Zenity_forms extends Zenity_cmd -{ - public function __construct($text, array $rows) - { - $this->command_type = ' --forms'; - parent::__construct($text, $rows); - //$this->height = 80 + count($this->rows) * 25; // à tester, mais devrait produire le rendu attendu - self::entries_zenity_forms($this->rows); - } - - private function entries_zenity_forms($entries) - { - $output = ''; - foreach($entries as $one_entry) - { - $output .= ' --add-entry="' . $one_entry . '"'; // forme: ' "choix 1" "choix 2"' - } - $this->command .= $output; - } -} - -class Zenity_calendar extends Zenity_cmd -{ - public function __construct($text) - { - $this->command_type = ' --calendar'; - parent::__construct($text); - } -} - -class Zenity_entry extends Zenity_cmd -{ - public function __construct($text) - { - $this->command_type = ' --entry'; - parent::__construct($text); - } -} diff --git a/php/compileLatex.php b/php/compileLatex.php deleted file mode 100644 index ccd9dab..0000000 --- a/php/compileLatex.php +++ /dev/null @@ -1,30 +0,0 @@ - /dev/null") == '') // commande qui n'ouvre pas de fenêtre, erreur si la chaine est vide parce que la sortie d'erreur va dans /dev/null +if(exec("zenity --version 2> /dev/null") === '') // commande qui n'ouvre pas de fenêtre, erreur si la chaine est vide parce que la sortie d'erreur va dans /dev/null { printf("Impossible de lancer zenity. Veuillez installer le paquet zenity\n"); exit(); } // compilateur pdflatex disponible -if(exec("pdflatex -version 2> /dev/null") == '') // erreur si la chaine est vide parce que la sortie d'erreur va dans /dev/null +if(exec("pdflatex -version 2> /dev/null") === '') // erreur si la chaine est vide parce que la sortie d'erreur va dans /dev/null { printf("Impossible de lancer pdflatex. Veuillez installer une distribution LaTeX.\n"); exit(); @@ -37,10 +37,10 @@ if(!extension_loaded("pdo_sqlite")) // client sqlite -if($exec_mode == 'gui') +if($exec_mode === 'gui') { // sqlitebrowser disponible - if(exec("which sqlitebrowser 2> /dev/null") != '') // which parcourt les dossiers du PATH et affiche les chemins trouvés, erreur si la chaine est vide parce que la sortie d'erreur va dans /dev/null + if(exec("which sqlitebrowser 2> /dev/null") !== '') // which parcourt les dossiers du PATH et affiche les chemins trouvés, erreur si la chaine est vide parce que la sortie d'erreur va dans /dev/null { $sqlitebrowser_enable = true; } @@ -49,32 +49,32 @@ if($exec_mode == 'gui') { printf("Sqlitebrowser n'est pas disponible. J'espère que vous maîtrisez le SQL.\n"); - if(exec("which xterm 2> /dev/null") != '' && exec("xterm -v 2> /dev/null") != '') + if(exec("which xterm 2> /dev/null") !== '' && exec("xterm -v 2> /dev/null") !== '') { $x_term_ccommand = 'xterm -e'; } - elseif(exec("which urxvt 2> /dev/null") != '') + elseif(exec("which urxvt 2> /dev/null") !== '') { $x_term_ccommand = 'urxvt -e'; } - elseif(exec("which lxterminal 2> /dev/null") != '' && exec("lxterminal -v 2> /dev/null") != '') + elseif(exec("which lxterminal 2> /dev/null") !== '' && exec("lxterminal -v 2> /dev/null") !== '') { $x_term_ccommand = 'lxterminal -e'; } - elseif(exec("which xfce4-terminal 2> /dev/null") != '' && exec("xfce4-terminal -V 2> /dev/null") != '') + elseif(exec("which xfce4-terminal 2> /dev/null") !== '' && exec("xfce4-terminal -V 2> /dev/null") !== '') { $x_term_ccommand = 'xfce4-terminal -x'; } - elseif(exec("which gnome-terminal 2> /dev/null") != '') + elseif(exec("which gnome-terminal 2> /dev/null") !== '') { $x_term_ccommand = 'gnome-terminal --'; } - elseif(exec("which konsole 2> /dev/null") != '' && exec("konsole -v 2> /dev/null") != '') + elseif(exec("which konsole 2> /dev/null") !== '' && exec("konsole -v 2> /dev/null") !== '') { $x_term_ccommand = 'konsole -e'; } // pour MAC - NON TESTÉ !! (possibilité de détecter le système avec uname?) - //~ elseif(exec("which Terminal 2> /dev/null") != '') + //~ elseif(exec("which Terminal 2> /dev/null") !== '') //~ { //~ $x_term_ccommand = 'open -a Terminal -e'; // ne marche probablement pas //~ } @@ -86,11 +86,11 @@ if($exec_mode == 'gui') } // sqlite CLI disponible -if(exec("which sqlite 2> /dev/null") != '' && exec("sqlite --version 2> /dev/null") != '') +if(exec("which sqlite 2> /dev/null") !== '' && exec("sqlite --version 2> /dev/null") !== '') { $sqlite_cli = 'sqlite'; } -elseif(exec("which sqlite3 2> /dev/null") != '' && exec("sqlite3 --version 2> /dev/null") != '') +elseif(exec("which sqlite3 2> /dev/null") !== '' && exec("sqlite3 --version 2> /dev/null") !== '') { $sqlite_cli = 'sqlite3'; } diff --git a/php/functions.php b/php/functions.php index 61bc13e..83ebead 100644 --- a/php/functions.php +++ b/php/functions.php @@ -5,7 +5,7 @@ function window_app_command(string $app, string $path = ''): string { $command = 'nohup ' . $app; // détache l'appli du script PHP - if($path != '') + if($path !== '') { $command .= ' ' . $path; } diff --git a/php/latexToPdf.php b/php/latexToPdf.php new file mode 100644 index 0000000..18ff452 --- /dev/null +++ b/php/latexToPdf.php @@ -0,0 +1,38 @@ +create_tables(); +$Database->date = new DateTimestamp; + +require('Zenity.php'); // commande système zenity require('zenity_setup.php'); // texte dans les fenêtres ET instanciation (un objet = une commande) -// require('php/latex.php'); -// require('php/compileLatex.php'); +require('Latex.php'); // générer le code LaTeX +require('latexToPdf.php'); // compilation // boucle principale @@ -41,10 +45,10 @@ while($boucle) $choix_niv1 = exec($MenuPrincipal->get()); // enregistrement - if($choix_niv1 == 'Nouvelle prestation') + if($choix_niv1 === 'Nouvelle prestation') { // est ce que le client est déjà dans la base? - if(exec($QuestionNouveauClient->get()) == 0) // $? = 0 signifie oui + if(exec($QuestionNouveauClient->get()) === 0) // $? = 0 signifie oui { // saisie du nom du client et recherche $client_saisie = exec($RechercheClient->get()); @@ -52,7 +56,7 @@ while($boucle) // sélection parmi les résultats $ResultatsRechercheClient->set_entries(recherche_client($client_saisie)); $choix_niv2 = exec($ResultatsRechercheClient->get()); - if($choix_niv2 != '') + if($choix_niv2 !== '') { echo "client trouvé\n"; } @@ -77,22 +81,22 @@ while($boucle) } - // infos sur la prestation + // type comptable de prestation $choix_niv2 = exec($MenuEnregistrement->get()); $continuer = true; - if($choix_niv2 == "Devis") + if($choix_niv2 === "Devis") { $type = 'DEVIS'; } - elseif($choix_niv2 == "Facture") + elseif($choix_niv2 === "Facture") { $type = 'FACTURE'; } - elseif($choix_niv2 == "CESU") + elseif($choix_niv2 === "CESU") { $type = 'CESU'; } - elseif($choix_niv2 == "Pas de prestation") + elseif($choix_niv2 === "Pas de prestation") { $type = ''; } @@ -101,6 +105,7 @@ while($boucle) $continuer = false; // retour menu principal } + // détail de la prestation if($continuer) { exec($Calendrier->get()); @@ -108,39 +113,47 @@ while($boucle) // enregistrement date et prestation en BDD exec($CommentairePrestation->get()); // enregistrement commentaire en BDD + // vérification? + + // tableau récaptilatif et demande de confirmation des informations + // création fichiers LaTeX et PDF + + // imprimer? + //~ $imprimer_facture = exec('zenity --question --width=250 --title="Base de données mise à jour" --text="Imprimer la facture?"'); + //~ $imprimer_enveloppe = exec('zenity --question --width=250 --title="Base de données mise à jour" --text="Imprimer l\'adresse sur une enveloppe? (insérer une enveloppe DL sans fenêtre dans l\'imprimante"'); } } - elseif($choix_niv1 == 'Fichier clients') + elseif($choix_niv1 === 'Fichier clients') { // quel affichage? un grand tableau avec zenity? une page web? un document LaTeX? } // documents à imprimer - elseif($choix_niv1 == 'Créer/imprimer un document') + elseif($choix_niv1 === 'Créer/imprimer un document') { $choix_niv2 = exec($MenuDocuments->get()); - if($choix_niv2 == 'Devis') + if($choix_niv2 === 'Devis') { } - elseif($choix_niv2 == 'Facture') + elseif($choix_niv2 === 'Facture') { } - elseif($choix_niv2 == 'Lettre avec adresse') + elseif($choix_niv2 === 'Lettre avec adresse') { } - elseif($choix_niv2 == 'Livre des recettes') + elseif($choix_niv2 === 'Livre des recettes') { } - elseif($choix_niv2 == "Registre des achats") + elseif($choix_niv2 === "Registre des achats") { } - elseif($choix_niv2 == "Bilan annuel") + elseif($choix_niv2 === "Bilan annuel") { } @@ -151,18 +164,18 @@ while($boucle) } // Supports de communication - elseif($choix_niv1 == 'Communication') + elseif($choix_niv1 === 'Communication') { $choix_niv2 = exec($MenuCommunication->get()); - if($choix_niv2 == 'Flyer (nécessite gimp)') + if($choix_niv2 === 'Flyer (nécessite gimp)') { exec(window_app_command('gimp', $flyer)); } - elseif($choix_niv2 == 'Carte de visite (nécessite scribus)') + elseif($choix_niv2 === 'Carte de visite (nécessite scribus)') { exec(window_app_command('scribus', $business_card)); } - elseif($choix_niv2 == 'Explorateur de fichiers') + elseif($choix_niv2 === 'Explorateur de fichiers') { exec(window_app_command($file_explorer, $pub)); } @@ -173,7 +186,7 @@ while($boucle) } // BDD - elseif($choix_niv1 == 'Base de données') + elseif($choix_niv1 === 'Base de données') { if($sqlitebrowser_enable) { diff --git a/php/saisie.php b/php/saisie.php deleted file mode 100644 index 1c6563a..0000000 --- a/php/saisie.php +++ /dev/null @@ -1,16 +0,0 @@ -get()); -$MenuPrincipal = new Zenity_list($menu_principal_text, $menu_principal_entrees); -$QuestionNouveauClient = new Zenity_question($question_nouveau_client_text); -$MenuEnregistrement = new Zenity_list($menu_enregistrement_text, $menu_enregistrement_entrees); -$MenuDocuments = new Zenity_list($menu_documents_text, $menu_documents_entrees); -$MenuCommunication = new Zenity_list($menu_communication_text, $menu_communication_entrees); -$RechercheClient = new zenity_entry($recherche_client_text); -$ResultatsRechercheClient = new zenity_list($resultats_recherche_client_text, []); -$NouveauClient = new Zenity_forms($nouveau_client_text, $nouveau_client_entrees); -$Calendrier = new Zenity_calendar($calendar_text); -$FormulairePrestation = new Zenity_forms($formulaire_text, $formulaire_entrees); -$CommentairePrestation = new Zenity_entry($commentaire_prestation_text); +$MenuPrincipal = new ZenityList($menu_principal_text, $menu_principal_entrees); +$QuestionNouveauClient = new ZenityQuestion($question_nouveau_client_text); +$MenuEnregistrement = new ZenityList($menu_enregistrement_text, $menu_enregistrement_entrees); +$MenuDocuments = new ZenityList($menu_documents_text, $menu_documents_entrees); +$MenuCommunication = new ZenityList($menu_communication_text, $menu_communication_entrees); +$RechercheClient = new zenityEntry($recherche_client_text); +$ResultatsRechercheClient = new zenityList($resultats_recherche_client_text, []); +$NouveauClient = new ZenityForms($nouveau_client_text, $nouveau_client_entrees); +$Calendrier = new ZenityCalendar($calendar_text); +$FormulairePrestation = new ZenityForms($formulaire_text, $formulaire_entrees); +$CommentairePrestation = new ZenityEntry($commentaire_prestation_text); -- cgit v1.2.3