Comment: | Passage à la syntaxe courte des array() dans PHP 5.4 |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
ee4dfba719864e9dbbaf152a056ba02a |
User & Date: | bohwaz on 2014-03-14 18:28:18 |
Other Links: | manifest | tags |
2014-03-14
| ||
18:43 | teste la syntaxe des fichiers php check-in: d790e59035 user: bohwaz tags: trunk | |
18:28 | Passage à la syntaxe courte des array() dans PHP 5.4 check-in: ee4dfba719 user: bohwaz tags: trunk | |
18:10 | Méthodes listes et comptage des rappels envoyés check-in: 3fcdfaaeb4 user: bohwaz tags: trunk | |
Modified src/include/class.champs_membres.php from [98fbf77687] to [ffdaa633d7].
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 .. 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 ... 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 ... 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
namespace Garradin; class Champs_Membres { protected $champs = null; protected $types = array( 'email' => 'Adresse E-Mail', 'url' => 'Adresse URL', 'checkbox' => 'Case à cocher', 'date' => 'Date', 'datetime' => 'Date et heure', //'file' => 'Fichier', 'password' => 'Mot de passe', ................................................................................ 'number' => 'Numéro', 'tel' => 'Numéro de téléphone', 'select' => 'Sélecteur à choix unique', 'multiple' => 'Sélecteur à choix multiple', 'country' => 'Sélecteur de pays', 'text' => 'Texte', 'textarea' => 'Texte multi-lignes', ); protected $text_types = array( 'email', 'text', 'select', 'textarea', 'url', 'password', 'country' ); protected $config_fields = array( 'type', 'title', 'help', 'editable', 'list_row', 'mandatory', 'private', 'options' ); static protected $presets = null; public function __toString() { return utils::write_ini_string($this->champs); } ................................................................................ */ public function save($enable_copy = true) { $db = DB::getInstance(); $config = Config::getInstance(); // Champs à créer $create = array( 'id INTEGER PRIMARY KEY, -- Numéro attribué automatiquement', 'id_categorie INTEGER NOT NULL, -- Numéro de catégorie', 'date_connexion TEXT NULL, -- Date de dernière connexion', 'date_inscription TEXT NOT NULL DEFAULT CURRENT_DATE, -- Date d\'inscription', ); $create_keys = array( 'FOREIGN KEY (id_categorie) REFERENCES membres_categories (id)' ); // Champs à recopier $copy = array( 'id', 'id_categorie', 'date_connexion', 'date_inscription', ); $anciens_champs = $config->get('champs_membres'); $anciens_champs = is_null($anciens_champs) ? $this->champs : $anciens_champs->getAll(); foreach ($this->champs as $key=>$cfg) { if ($cfg['type'] == 'number') ................................................................................ else $type = 'TEXT'; $line = $key . ' ' . $type . ','; if (!empty($cfg['title'])) { $line .= ' -- ' . str_replace(array("\n", "\r"), '', $cfg['title']); } $create[] = $line; if (array_key_exists($key, $anciens_champs)) { $copy[] = $key; |
| < > | < > | | | < > | < > | | | |
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 .. 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 ... 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 ... 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
namespace Garradin; class Champs_Membres { protected $champs = null; protected $types = [ 'email' => 'Adresse E-Mail', 'url' => 'Adresse URL', 'checkbox' => 'Case à cocher', 'date' => 'Date', 'datetime' => 'Date et heure', //'file' => 'Fichier', 'password' => 'Mot de passe', ................................................................................ 'number' => 'Numéro', 'tel' => 'Numéro de téléphone', 'select' => 'Sélecteur à choix unique', 'multiple' => 'Sélecteur à choix multiple', 'country' => 'Sélecteur de pays', 'text' => 'Texte', 'textarea' => 'Texte multi-lignes', ]; protected $text_types = [ 'email', 'text', 'select', 'textarea', 'url', 'password', 'country' ]; protected $config_fields = [ 'type', 'title', 'help', 'editable', 'list_row', 'mandatory', 'private', 'options' ]; static protected $presets = null; public function __toString() { return utils::write_ini_string($this->champs); } ................................................................................ */ public function save($enable_copy = true) { $db = DB::getInstance(); $config = Config::getInstance(); // Champs à créer $create = [ 'id INTEGER PRIMARY KEY, -- Numéro attribué automatiquement', 'id_categorie INTEGER NOT NULL, -- Numéro de catégorie', 'date_connexion TEXT NULL, -- Date de dernière connexion', 'date_inscription TEXT NOT NULL DEFAULT CURRENT_DATE, -- Date d\'inscription', ]; $create_keys = [ 'FOREIGN KEY (id_categorie) REFERENCES membres_categories (id)' ]; // Champs à recopier $copy = [ 'id', 'id_categorie', 'date_connexion', 'date_inscription', ]; $anciens_champs = $config->get('champs_membres'); $anciens_champs = is_null($anciens_champs) ? $this->champs : $anciens_champs->getAll(); foreach ($this->champs as $key=>$cfg) { if ($cfg['type'] == 'number') ................................................................................ else $type = 'TEXT'; $line = $key . ' ' . $type . ','; if (!empty($cfg['title'])) { $line .= ' -- ' . str_replace(["\n", "\r"], '', $cfg['title']); } $create[] = $line; if (array_key_exists($key, $anciens_champs)) { $copy[] = $key; |
Modified src/include/class.compta_categories.php from [944c6c207d] to [504dbd9b0c].
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
if (!isset($data['type']) || ($data['type'] != self::DEPENSES && $data['type'] != self::RECETTES)) { // Catégories "autres" pas possibles pour le moment throw new UserException('Type de catégorie inconnu.'); } $db->simpleInsert('compta_categories', array( 'intitule' => $data['intitule'], 'description'=> $data['description'], 'compte' => $data['compte'], 'type' => (int)$data['type'], )); return $db->lastInsertRowId(); } public function edit($id, $data) { $this->_checkFields($data); $db = DB::getInstance(); $db->simpleUpdate('compta_categories', array( 'intitule' => $data['intitule'], 'description'=> $data['description'], ), 'id = \''.$db->escapeString(trim($id)).'\''); return true; } public function delete($id) { |
| | < > < > |
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
if (!isset($data['type']) || ($data['type'] != self::DEPENSES && $data['type'] != self::RECETTES)) { // Catégories "autres" pas possibles pour le moment throw new UserException('Type de catégorie inconnu.'); } $db->simpleInsert('compta_categories', [ 'intitule' => $data['intitule'], 'description'=> $data['description'], 'compte' => $data['compte'], 'type' => (int)$data['type'], ]); return $db->lastInsertRowId(); } public function edit($id, $data) { $this->_checkFields($data); $db = DB::getInstance(); $db->simpleUpdate('compta_categories', [ 'intitule' => $data['intitule'], 'description'=> $data['description'], ], 'id = \''.$db->escapeString(trim($id)).'\''); return true; } public function delete($id) { |
Modified src/include/class.compta_comptes.php from [c3b8e65fb8] to [666a1a41ca].
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 .. 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ... 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 ... 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
public function importPlan() { $plan = json_decode(file_get_contents(ROOT . '/include/data/plan_comptable.json'), true); $db = DB::getInstance(); $db->exec('BEGIN;'); $ids = array(); foreach ($plan as $id=>$compte) { $ids[] = $id; if ($db->simpleQuerySingle('SELECT 1 FROM compta_comptes WHERE id = ?;', false, $id)) { $db->simpleUpdate('compta_comptes', array( 'parent' => $compte['parent'], 'libelle' => $compte['nom'], 'position' => $compte['position'], 'plan_comptable' => 1, ), 'id = \''.$db->escapeString($id).'\''); } else { $db->simpleInsert('compta_comptes', array( 'id' => $id, 'parent' => $compte['parent'], 'libelle' => $compte['nom'], 'position' => $compte['position'], 'plan_comptable' => 1, )); } } $db->exec('DELETE FROM compta_comptes WHERE id NOT IN(\''.implode('\', \'', $ids).'\') AND plan_comptable = 1;'); $db->exec('END;'); ................................................................................ $position = (int) $data['position']; } else { $position = $db->simpleQuerySingle('SELECT position FROM compta_comptes WHERE id = ?;', false, $data['parent']); } $db->simpleInsert('compta_comptes', array( 'id' => $new_id, 'libelle' => trim($data['libelle']), 'parent' => $data['parent'], 'plan_comptable' => 0, 'position' => (int)$position, )); return $new_id; } public function edit($id, $data) { $db = DB::getInstance(); ................................................................................ if (isset($data['position']) && empty($data['position'])) { throw new UserException('Aucune position du compte n\'a été indiquée.'); } $this->_checkFields($data); $update = array( 'libelle' => trim($data['libelle']), ); if (isset($data['position'])) { $update['position'] = (int) trim($data['position']); } $db->simpleUpdate('compta_comptes', $update, 'id = \''.$db->escapeString(trim($id)).'\''); ................................................................................ } return true; } public function getPositions() { return array( self::ACTIF => 'Actif', self::PASSIF => 'Passif', self::ACTIF | self::PASSIF => 'Actif ou passif (déterminé automatiquement au bilan selon le solde du compte)', self::CHARGE => 'Charge', self::PRODUIT => 'Produit', self::CHARGE | self::PRODUIT => 'Charge et produit', ); } } ?> |
| | | | | | | | < > | | |
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 .. 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ... 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 ... 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
public function importPlan() { $plan = json_decode(file_get_contents(ROOT . '/include/data/plan_comptable.json'), true); $db = DB::getInstance(); $db->exec('BEGIN;'); $ids = []; foreach ($plan as $id=>$compte) { $ids[] = $id; if ($db->simpleQuerySingle('SELECT 1 FROM compta_comptes WHERE id = ?;', false, $id)) { $db->simpleUpdate('compta_comptes', [ 'parent' => $compte['parent'], 'libelle' => $compte['nom'], 'position' => $compte['position'], 'plan_comptable' => 1, ], 'id = \''.$db->escapeString($id).'\''); } else { $db->simpleInsert('compta_comptes', [ 'id' => $id, 'parent' => $compte['parent'], 'libelle' => $compte['nom'], 'position' => $compte['position'], 'plan_comptable' => 1, ]); } } $db->exec('DELETE FROM compta_comptes WHERE id NOT IN(\''.implode('\', \'', $ids).'\') AND plan_comptable = 1;'); $db->exec('END;'); ................................................................................ $position = (int) $data['position']; } else { $position = $db->simpleQuerySingle('SELECT position FROM compta_comptes WHERE id = ?;', false, $data['parent']); } $db->simpleInsert('compta_comptes', [ 'id' => $new_id, 'libelle' => trim($data['libelle']), 'parent' => $data['parent'], 'plan_comptable' => 0, 'position' => (int)$position, ]); return $new_id; } public function edit($id, $data) { $db = DB::getInstance(); ................................................................................ if (isset($data['position']) && empty($data['position'])) { throw new UserException('Aucune position du compte n\'a été indiquée.'); } $this->_checkFields($data); $update = [ 'libelle' => trim($data['libelle']), ]; if (isset($data['position'])) { $update['position'] = (int) trim($data['position']); } $db->simpleUpdate('compta_comptes', $update, 'id = \''.$db->escapeString(trim($id)).'\''); ................................................................................ } return true; } public function getPositions() { return [ self::ACTIF => 'Actif', self::PASSIF => 'Passif', self::ACTIF | self::PASSIF => 'Actif ou passif (déterminé automatiquement au bilan selon le solde du compte)', self::CHARGE => 'Charge', self::PRODUIT => 'Produit', self::CHARGE | self::PRODUIT => 'Charge et produit', ]; } } ?> |
Modified src/include/class.compta_comptes_bancaires.php from [91b72e58dd] to [53301e3cb2].
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
$data['id'] = null; $this->_checkBankFields($data); $new_id = parent::add($data); $db = DB::getInstance(); $db->simpleInsert('compta_comptes_bancaires', array( 'id' => $new_id, 'banque' => $data['banque'], 'iban' => $data['iban'], 'bic' => $data['bic'], )); return $new_id; } public function edit($id, $data) { $db = DB::getInstance(); ................................................................................ $result = parent::edit($id, $data); if (!$result) { return $result; } $db->simpleUpdate('compta_comptes_bancaires', array( 'banque' => $data['banque'], 'iban' => $data['iban'], 'bic' => $data['bic'], ), 'id = \''.$db->escapeString(trim($id)).'\''); return true; } /** * Supprime un compte bancaire * La suppression sera refusée si le compte est utilisé dans l'exercice en cours |
|
|
|
|
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
$data['id'] = null; $this->_checkBankFields($data); $new_id = parent::add($data); $db = DB::getInstance(); $db->simpleInsert('compta_comptes_bancaires', [ 'id' => $new_id, 'banque' => $data['banque'], 'iban' => $data['iban'], 'bic' => $data['bic'], ]); return $new_id; } public function edit($id, $data) { $db = DB::getInstance(); ................................................................................ $result = parent::edit($id, $data); if (!$result) { return $result; } $db->simpleUpdate('compta_comptes_bancaires', [ 'banque' => $data['banque'], 'iban' => $data['iban'], 'bic' => $data['bic'], ], 'id = \''.$db->escapeString(trim($id)).'\''); return true; } /** * Supprime un compte bancaire * La suppression sera refusée si le compte est utilisé dans l'exercice en cours |
Modified src/include/class.compta_exercices.php from [4ee1b8e858] to [d9eb4897cf].
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 .. 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 .. 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ... 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 ... 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 ... 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 ... 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 ... 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 ... 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 ... 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 ... 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 ... 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 ... 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 ... 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 ... 561 562 563 564 565 566 567 568 569 570 571 572 |
{ $this->_checkFields($data); $db = DB::getInstance(); if ($db->simpleQuerySingle('SELECT 1 FROM compta_exercices WHERE (debut <= :debut AND fin >= :debut) OR (debut <= :fin AND fin >= :fin);', false, array('debut' => $data['debut'], 'fin' => $data['fin']))) { throw new UserException('La date de début ou de fin se recoupe avec un autre exercice.'); } if ($db->querySingle('SELECT 1 FROM compta_exercices WHERE cloture = 0;')) { throw new UserException('Il n\'est pas possible de créer un nouvel exercice tant qu\'il existe un exercice non-clôturé.'); } $db->simpleInsert('compta_exercices', array( 'libelle' => trim($data['libelle']), 'debut' => $data['debut'], 'fin' => $data['fin'], )); return $db->lastInsertRowId(); } public function edit($id, $data) { $db = DB::getInstance(); $this->_checkFields($data); // Evitons que les exercices se croisent if ($db->simpleQuerySingle('SELECT 1 FROM compta_exercices WHERE id != :id AND ((debut <= :debut AND fin >= :debut) OR (debut <= :fin AND fin >= :fin));', false, array('debut' => $data['debut'], 'fin' => $data['fin'], 'id' => (int) $id))) { throw new UserException('La date de début ou de fin se recoupe avec un autre exercice.'); } // On vérifie qu'on ne va pas mettre des opérations en dehors de tout exercice if ($db->simpleQuerySingle('SELECT 1 FROM compta_journal WHERE id_exercice = ? AND date < ? LIMIT 1;', false, (int)$id, $data['debut'])) ................................................................................ if ($db->simpleQuerySingle('SELECT 1 FROM compta_journal WHERE id_exercice = ? AND date > ? LIMIT 1;', false, (int)$id, $data['fin'])) { throw new UserException('Des opérations de cet exercice ont une date postérieure à la date de fin de l\'exercice.'); } $db->simpleUpdate('compta_exercices', array( 'libelle' => trim($data['libelle']), 'debut' => $data['debut'], 'fin' => $data['fin'], ), 'id = \''.(int)$id.'\''); return true; } /** * Clôturer un exercice et en ouvrir un nouveau * Le report à nouveau n'est pas effectué automatiquement par cette fonction, voir doReports pour ça. ................................................................................ { throw new UserException('Date de fin vide ou invalide.'); } $db->exec('BEGIN;'); // Clôture de l'exercice $db->simpleUpdate('compta_exercices', array( 'cloture' => 1, 'fin' => $end, ), 'id = \''.(int)$id.'\''); // Date de début du nouvel exercice : lendemain de la clôture du précédent exercice $new_begin = utils::modifyDate($end, '+1 day'); // Date de fin du nouvel exercice : un an moins un jour après l'ouverture $new_end = utils::modifyDate($new_begin, '+1 year -1 day'); ................................................................................ // Enfin sauf s'il existe déjà des opérations après cette date, auquel cas la date de fin // est fixée à la date de la dernière opération, ceci pour ne pas avoir d'opération // orpheline d'exercice $last = $db->simpleQuerySingle('SELECT date FROM compta_journal WHERE id_exercice = ? AND date >= ? ORDER BY date DESC LIMIT 1;', false, $id, $new_end); $new_end = $last ?: $new_end; // Création du nouvel exercice $new_id = $this->add(array( 'debut' => $new_begin, 'fin' => $new_end, 'libelle' => 'Nouvel exercice' ) ); // Ré-attribution des opérations de l'exercice à clôturer qui ne sont pas dans son // intervale au nouvel exercice $db->simpleExec('UPDATE compta_journal SET id_exercice = ? WHERE id_exercice = ? AND date >= ?;', $new_id, $id, $new_begin); $db->exec('END;'); ................................................................................ $statement = $db->simpleStatement('SELECT compta_comptes.id AS compte, compta_comptes.position AS position, COALESCE((SELECT SUM(montant) FROM compta_journal WHERE compte_debit = compta_comptes.id AND id_exercice = :id), 0) - COALESCE((SELECT SUM(montant) FROM compta_journal WHERE compte_credit = compta_comptes.id AND id_exercice = :id), 0) AS solde FROM compta_comptes INNER JOIN compta_journal ON compta_comptes.id = compta_journal.compte_debit OR compta_comptes.id = compta_journal.compte_credit WHERE id_exercice = :id AND solde != 0 AND CAST(substr(compta_comptes.id, 1, 1) AS INTEGER) <= 5 GROUP BY compta_comptes.id;', array('id' => $old_id)); $diff = 0; $journal = new Compta_Journal; while ($row = $statement->fetchArray(SQLITE3_ASSOC)) { $solde = ($row['position'] & Compta_Comptes::ACTIF) ? abs($row['solde']) : -abs($row['solde']); ................................................................................ if (empty($solde)) { continue; } // Chaque solde de compte est reporté dans le nouvel exercice $journal->add(array( 'libelle' => 'Report à nouveau', 'date' => $date, 'montant' => abs($solde), 'compte_debit' => ($solde < 0 ? NULL : $row['compte']), 'compte_credit' => ($solde > 0 ? NULL : $row['compte']), 'remarques' => 'Report de solde créé automatiquement à la clôture de l\'exercice précédent', )); } // FIXME utiliser $diff pour équilibrer $db->exec('END;'); return true; ................................................................................ $resultat = $this->getCompteResultat($exercice); $resultat = $resultat['resultat']; if ($resultat != 0) { $journal = new Compta_Journal; $journal->add(array( 'libelle' => 'Résultat de l\'exercice précédent', 'date' => $date, 'montant' => $resultat, 'compte_debit' => $resultat < 0 ? 129 : NULL, 'compte_credit' => $resultat > 0 ? 120 : NULL, )); } return true; } public function delete($id) { ................................................................................ WHERE id_exercice = '.(int)$exercice.' ORDER BY date, id;'; return $db->simpleStatementFetch($query); } public function getGrandLivre($exercice) { $db = DB::getInstance(); $livre = array('classes' => array(), 'debit' => 0.0, 'credit' => 0.0); $res = $db->prepare('SELECT compte FROM (SELECT compte_debit AS compte FROM compta_journal WHERE id_exercice = '.(int)$exercice.' GROUP BY compte_debit UNION SELECT compte_credit AS compte FROM compta_journal WHERE id_exercice = '.(int)$exercice.' GROUP BY compte_credit) ................................................................................ continue; $classe = substr($compte, 0, 1); $parent = substr($compte, 0, 2); if (!array_key_exists($classe, $livre['classes'])) { $livre['classes'][$classe] = array(); } if (!array_key_exists($parent, $livre['classes'][$classe])) { $livre['classes'][$classe][$parent] = array( 'total' => 0.0, 'comptes' => array(), ); } $livre['classes'][$classe][$parent]['comptes'][$compte] = array('debit' => 0.0, 'credit' => 0.0, 'journal' => array()); $livre['classes'][$classe][$parent]['comptes'][$compte]['journal'] = $db->simpleStatementFetch( 'SELECT *, strftime(\'%s\', date) AS date FROM ( SELECT * FROM compta_journal WHERE compte_debit = :compte AND id_exercice = '.(int)$exercice.' UNION SELECT * FROM compta_journal WHERE compte_credit = :compte AND id_exercice = '.(int)$exercice.' ) ORDER BY date, numero_piece, id;', SQLITE3_ASSOC, array('compte' => $compte)); $debit = (float) $db->simpleQuerySingle( 'SELECT SUM(montant) FROM compta_journal WHERE compte_debit = ? AND id_exercice = '.(int)$exercice.';', false, $compte); $credit = (float) $db->simpleQuerySingle( 'SELECT SUM(montant) FROM compta_journal WHERE compte_credit = ? AND id_exercice = '.(int)$exercice.';', ................................................................................ return $livre; } public function getCompteResultat($exercice) { $db = DB::getInstance(); $charges = array('comptes' => array(), 'total' => 0.0); $produits = array('comptes' => array(), 'total' => 0.0); $resultat = 0.0; $res = $db->prepare('SELECT compte, SUM(debit), SUM(credit) FROM (SELECT compte_debit AS compte, SUM(montant) AS debit, 0 AS credit FROM compta_journal WHERE id_exercice = '.(int)$exercice.' GROUP BY compte_debit UNION ................................................................................ $classe = substr($compte, 0, 1); $parent = substr($compte, 0, 2); if ($classe == 6) { if (!isset($charges['comptes'][$parent])) { $charges['comptes'][$parent] = array('comptes' => array(), 'solde' => 0.0); } $solde = round($debit - $credit, 2); if (empty($solde)) continue; ................................................................................ $charges['total'] += $solde; $charges['comptes'][$parent]['solde'] += $solde; } elseif ($classe == 7) { if (!isset($produits['comptes'][$parent])) { $produits['comptes'][$parent] = array('comptes' => array(), 'solde' => 0.0); } $solde = round($credit - $debit, 2); if (empty($solde)) continue; ................................................................................ } } $res->finalize(); $resultat = $produits['total'] - $charges['total']; return array('charges' => $charges, 'produits' => $produits, 'resultat' => $resultat); } /** * Calculer le bilan comptable pour l'exercice $exercice * @param integer $exercice ID de l'exercice dont il faut produire le bilan * @param boolean $resultat true s'il faut calculer le résultat de l'exercice (utile pour un exercice en cours) * @return array Un tableau multi-dimensionnel avec deux clés : actif et passif */ public function getBilan($exercice) { $db = DB::getInstance(); $include = array(Compta_Comptes::ACTIF, Compta_Comptes::PASSIF, Compta_Comptes::PASSIF | Compta_Comptes::ACTIF); $actif = array('comptes' => array(), 'total' => 0.0); $passif = array('comptes' => array(), 'total' => 0.0); $resultat = $this->getCompteResultat($exercice); if ($resultat['resultat'] >= 0) { $passif['comptes']['12'] = array( 'comptes' => array('120' => $resultat['resultat']), 'solde' => $resultat['resultat'] ); $passif['total'] = $resultat['resultat']; } else { $passif['comptes']['12'] = array( 'comptes' => array('129' => $resultat['resultat']), 'solde' => $resultat['resultat'] ); $passif['total'] = $resultat['resultat']; } // Y'a sûrement moyen d'améliorer tout ça pour que le maximum de travail // soit fait au niveau du SQL, mais pour le moment ça marche $res = $db->prepare('SELECT compte, debit, credit, (SELECT position FROM compta_comptes WHERE id = compte) AS position ................................................................................ else { continue; } if (!isset(${$position}['comptes'][$parent])) { ${$position}['comptes'][$parent] = array('comptes' => array(), 'solde' => 0); } if (!isset(${$position}['comptes'][$parent]['comptes'][$compte])) { ${$position}['comptes'][$parent]['comptes'][$compte] = 0; } ................................................................................ if (empty($solde)) { unset($actif['comptes'][$parent]['comptes'][$id]); } } } return array('actif' => $actif, 'passif' => $passif); } } ?> |
| | | | | | | | | < | | | | | | | | | | < > | | | | | | | | | | | | | < > | | < > | | |
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 .. 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 .. 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ... 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 ... 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 ... 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 ... 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 ... 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 ... 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 ... 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 ... 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 ... 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 ... 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 ... 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 ... 560 561 562 563 564 565 566 567 568 569 570 571 |
{ $this->_checkFields($data); $db = DB::getInstance(); if ($db->simpleQuerySingle('SELECT 1 FROM compta_exercices WHERE (debut <= :debut AND fin >= :debut) OR (debut <= :fin AND fin >= :fin);', false, ['debut' => $data['debut'], 'fin' => $data['fin']])) { throw new UserException('La date de début ou de fin se recoupe avec un autre exercice.'); } if ($db->querySingle('SELECT 1 FROM compta_exercices WHERE cloture = 0;')) { throw new UserException('Il n\'est pas possible de créer un nouvel exercice tant qu\'il existe un exercice non-clôturé.'); } $db->simpleInsert('compta_exercices', [ 'libelle' => trim($data['libelle']), 'debut' => $data['debut'], 'fin' => $data['fin'], ]); return $db->lastInsertRowId(); } public function edit($id, $data) { $db = DB::getInstance(); $this->_checkFields($data); // Evitons que les exercices se croisent if ($db->simpleQuerySingle('SELECT 1 FROM compta_exercices WHERE id != :id AND ((debut <= :debut AND fin >= :debut) OR (debut <= :fin AND fin >= :fin));', false, ['debut' => $data['debut'], 'fin' => $data['fin'], 'id' => (int) $id])) { throw new UserException('La date de début ou de fin se recoupe avec un autre exercice.'); } // On vérifie qu'on ne va pas mettre des opérations en dehors de tout exercice if ($db->simpleQuerySingle('SELECT 1 FROM compta_journal WHERE id_exercice = ? AND date < ? LIMIT 1;', false, (int)$id, $data['debut'])) ................................................................................ if ($db->simpleQuerySingle('SELECT 1 FROM compta_journal WHERE id_exercice = ? AND date > ? LIMIT 1;', false, (int)$id, $data['fin'])) { throw new UserException('Des opérations de cet exercice ont une date postérieure à la date de fin de l\'exercice.'); } $db->simpleUpdate('compta_exercices', [ 'libelle' => trim($data['libelle']), 'debut' => $data['debut'], 'fin' => $data['fin'], ], 'id = \''.(int)$id.'\''); return true; } /** * Clôturer un exercice et en ouvrir un nouveau * Le report à nouveau n'est pas effectué automatiquement par cette fonction, voir doReports pour ça. ................................................................................ { throw new UserException('Date de fin vide ou invalide.'); } $db->exec('BEGIN;'); // Clôture de l'exercice $db->simpleUpdate('compta_exercices', [ 'cloture' => 1, 'fin' => $end, ], 'id = \''.(int)$id.'\''); // Date de début du nouvel exercice : lendemain de la clôture du précédent exercice $new_begin = utils::modifyDate($end, '+1 day'); // Date de fin du nouvel exercice : un an moins un jour après l'ouverture $new_end = utils::modifyDate($new_begin, '+1 year -1 day'); ................................................................................ // Enfin sauf s'il existe déjà des opérations après cette date, auquel cas la date de fin // est fixée à la date de la dernière opération, ceci pour ne pas avoir d'opération // orpheline d'exercice $last = $db->simpleQuerySingle('SELECT date FROM compta_journal WHERE id_exercice = ? AND date >= ? ORDER BY date DESC LIMIT 1;', false, $id, $new_end); $new_end = $last ?: $new_end; // Création du nouvel exercice $new_id = $this->add([ 'debut' => $new_begin, 'fin' => $new_end, 'libelle' => 'Nouvel exercice' ]); // Ré-attribution des opérations de l'exercice à clôturer qui ne sont pas dans son // intervale au nouvel exercice $db->simpleExec('UPDATE compta_journal SET id_exercice = ? WHERE id_exercice = ? AND date >= ?;', $new_id, $id, $new_begin); $db->exec('END;'); ................................................................................ $statement = $db->simpleStatement('SELECT compta_comptes.id AS compte, compta_comptes.position AS position, COALESCE((SELECT SUM(montant) FROM compta_journal WHERE compte_debit = compta_comptes.id AND id_exercice = :id), 0) - COALESCE((SELECT SUM(montant) FROM compta_journal WHERE compte_credit = compta_comptes.id AND id_exercice = :id), 0) AS solde FROM compta_comptes INNER JOIN compta_journal ON compta_comptes.id = compta_journal.compte_debit OR compta_comptes.id = compta_journal.compte_credit WHERE id_exercice = :id AND solde != 0 AND CAST(substr(compta_comptes.id, 1, 1) AS INTEGER) <= 5 GROUP BY compta_comptes.id;', ['id' => $old_id]); $diff = 0; $journal = new Compta_Journal; while ($row = $statement->fetchArray(SQLITE3_ASSOC)) { $solde = ($row['position'] & Compta_Comptes::ACTIF) ? abs($row['solde']) : -abs($row['solde']); ................................................................................ if (empty($solde)) { continue; } // Chaque solde de compte est reporté dans le nouvel exercice $journal->add([ 'libelle' => 'Report à nouveau', 'date' => $date, 'montant' => abs($solde), 'compte_debit' => ($solde < 0 ? NULL : $row['compte']), 'compte_credit' => ($solde > 0 ? NULL : $row['compte']), 'remarques' => 'Report de solde créé automatiquement à la clôture de l\'exercice précédent', ]); } // FIXME utiliser $diff pour équilibrer $db->exec('END;'); return true; ................................................................................ $resultat = $this->getCompteResultat($exercice); $resultat = $resultat['resultat']; if ($resultat != 0) { $journal = new Compta_Journal; $journal->add([ 'libelle' => 'Résultat de l\'exercice précédent', 'date' => $date, 'montant' => $resultat, 'compte_debit' => $resultat < 0 ? 129 : NULL, 'compte_credit' => $resultat > 0 ? 120 : NULL, ]); } return true; } public function delete($id) { ................................................................................ WHERE id_exercice = '.(int)$exercice.' ORDER BY date, id;'; return $db->simpleStatementFetch($query); } public function getGrandLivre($exercice) { $db = DB::getInstance(); $livre = ['classes' => [], 'debit' => 0.0, 'credit' => 0.0]; $res = $db->prepare('SELECT compte FROM (SELECT compte_debit AS compte FROM compta_journal WHERE id_exercice = '.(int)$exercice.' GROUP BY compte_debit UNION SELECT compte_credit AS compte FROM compta_journal WHERE id_exercice = '.(int)$exercice.' GROUP BY compte_credit) ................................................................................ continue; $classe = substr($compte, 0, 1); $parent = substr($compte, 0, 2); if (!array_key_exists($classe, $livre['classes'])) { $livre['classes'][$classe] = []; } if (!array_key_exists($parent, $livre['classes'][$classe])) { $livre['classes'][$classe][$parent] = [ 'total' => 0.0, 'comptes' => [], ]; } $livre['classes'][$classe][$parent]['comptes'][$compte] = ['debit' => 0.0, 'credit' => 0.0, 'journal' => []]; $livre['classes'][$classe][$parent]['comptes'][$compte]['journal'] = $db->simpleStatementFetch( 'SELECT *, strftime(\'%s\', date) AS date FROM ( SELECT * FROM compta_journal WHERE compte_debit = :compte AND id_exercice = '.(int)$exercice.' UNION SELECT * FROM compta_journal WHERE compte_credit = :compte AND id_exercice = '.(int)$exercice.' ) ORDER BY date, numero_piece, id;', SQLITE3_ASSOC, ['compte' => $compte]); $debit = (float) $db->simpleQuerySingle( 'SELECT SUM(montant) FROM compta_journal WHERE compte_debit = ? AND id_exercice = '.(int)$exercice.';', false, $compte); $credit = (float) $db->simpleQuerySingle( 'SELECT SUM(montant) FROM compta_journal WHERE compte_credit = ? AND id_exercice = '.(int)$exercice.';', ................................................................................ return $livre; } public function getCompteResultat($exercice) { $db = DB::getInstance(); $charges = ['comptes' => [], 'total' => 0.0]; $produits = ['comptes' => [], 'total' => 0.0]; $resultat = 0.0; $res = $db->prepare('SELECT compte, SUM(debit), SUM(credit) FROM (SELECT compte_debit AS compte, SUM(montant) AS debit, 0 AS credit FROM compta_journal WHERE id_exercice = '.(int)$exercice.' GROUP BY compte_debit UNION ................................................................................ $classe = substr($compte, 0, 1); $parent = substr($compte, 0, 2); if ($classe == 6) { if (!isset($charges['comptes'][$parent])) { $charges['comptes'][$parent] = ['comptes' => [], 'solde' => 0.0]; } $solde = round($debit - $credit, 2); if (empty($solde)) continue; ................................................................................ $charges['total'] += $solde; $charges['comptes'][$parent]['solde'] += $solde; } elseif ($classe == 7) { if (!isset($produits['comptes'][$parent])) { $produits['comptes'][$parent] = ['comptes' => [], 'solde' => 0.0]; } $solde = round($credit - $debit, 2); if (empty($solde)) continue; ................................................................................ } } $res->finalize(); $resultat = $produits['total'] - $charges['total']; return ['charges' => $charges, 'produits' => $produits, 'resultat' => $resultat]; } /** * Calculer le bilan comptable pour l'exercice $exercice * @param integer $exercice ID de l'exercice dont il faut produire le bilan * @param boolean $resultat true s'il faut calculer le résultat de l'exercice (utile pour un exercice en cours) * @return array Un tableau multi-dimensionnel avec deux clés : actif et passif */ public function getBilan($exercice) { $db = DB::getInstance(); $include = [Compta_Comptes::ACTIF, Compta_Comptes::PASSIF, Compta_Comptes::PASSIF | Compta_Comptes::ACTIF]; $actif = ['comptes' => [], 'total' => 0.0]; $passif = ['comptes' => [], 'total' => 0.0]; $resultat = $this->getCompteResultat($exercice); if ($resultat['resultat'] >= 0) { $passif['comptes']['12'] = [ 'comptes' => ['120' => $resultat['resultat']], 'solde' => $resultat['resultat'] ]; $passif['total'] = $resultat['resultat']; } else { $passif['comptes']['12'] = [ 'comptes' => ['129' => $resultat['resultat']], 'solde' => $resultat['resultat'] ]; $passif['total'] = $resultat['resultat']; } // Y'a sûrement moyen d'améliorer tout ça pour que le maximum de travail // soit fait au niveau du SQL, mais pour le moment ça marche $res = $db->prepare('SELECT compte, debit, credit, (SELECT position FROM compta_comptes WHERE id = compte) AS position ................................................................................ else { continue; } if (!isset(${$position}['comptes'][$parent])) { ${$position}['comptes'][$parent] = ['comptes' => [], 'solde' => 0]; } if (!isset(${$position}['comptes'][$parent]['comptes'][$compte])) { ${$position}['comptes'][$parent]['comptes'][$compte] = 0; } ................................................................................ if (empty($solde)) { unset($actif['comptes'][$parent]['comptes'][$id]); } } } return ['actif' => $actif, 'passif' => $passif]; } } ?> |
Modified src/include/class.compta_import.php from [1091812b42] to [7e6d1114ca].
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 ... 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 ... 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 ... 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
} if ($cat && !array_key_exists($cat, $liste_cats)) { $cat = $moyen = false; } $data = array( 'libelle' => $col('Libellé'), 'montant' => (float) $col('Montant'), 'date' => $date, 'compte_credit' => $credit, 'compte_debit' => $debit, 'numero_piece' => $col('Numéro de pièce'), 'remarques' => $col('Remarques'), ); if ($cat) { $data['moyen_paiement'] = $moyen; $data['numero_cheque'] = $col('Numéro de chèque'); $data['id_categorie'] = $liste_cats[$cat]; } ................................................................................ $db = DB::getInstance(); $db->exec('BEGIN;'); $comptes = new Compta_Comptes; $banques = new Compta_Comptes_Bancaires; $cats = new Compta_Categories; $journal = new Compta_Journal; $columns = array(); $liste_comptes = $db->simpleStatementFetchAssoc('SELECT id, id FROM compta_comptes;'); $liste_cats = $db->simpleStatementFetchAssoc('SELECT intitule, id FROM compta_categories;'); $liste_moyens = $cats->listMoyensPaiement(); $get_compte = function ($compte, $intitule) use (&$liste_comptes, &$comptes, &$banques) { if (substr($compte, 0, 2) == '51') ................................................................................ } // Création comptes if (!array_key_exists($compte, $liste_comptes)) { if (substr($compte, 0, 3) == '512') { $liste_comptes[$compte] = $banques->add(array( 'libelle' => $intitule, 'banque' => 'Inconnue', )); } else { $liste_comptes[$compte] = $comptes->add(array( 'id' => $compte, 'libelle' => $intitule, 'parent' => substr($compte, 0, -1) )); } } return $compte; }; $col = function($column) use (&$row, &$columns) ................................................................................ { $type = $cats::AUTRES; $cat = false; } if ($type != $cats::AUTRES) { $liste_cats[$cat] = $cats->add(array( 'intitule' => $cat, 'type' => $type, 'compte' => $compte )); } } $data = array( 'libelle' => $col('Libellé'), 'montant' => $col('Montant'), 'date' => $date, 'compte_credit' => $credit, 'compte_debit' => $debit, 'numero_piece' => $col('Numéro de pièce'), 'remarques' => $col('Remarques'), ); if ($cat) { $data['moyen_paiement'] = $moyen; $data['numero_cheque'] = $col('Numéro de chèque'); $data['id_categorie'] = $liste_cats[$cat]; } |
| | | | | | | | | | | |
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 ... 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 ... 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 ... 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
} if ($cat && !array_key_exists($cat, $liste_cats)) { $cat = $moyen = false; } $data = [ 'libelle' => $col('Libellé'), 'montant' => (float) $col('Montant'), 'date' => $date, 'compte_credit' => $credit, 'compte_debit' => $debit, 'numero_piece' => $col('Numéro de pièce'), 'remarques' => $col('Remarques'), ]; if ($cat) { $data['moyen_paiement'] = $moyen; $data['numero_cheque'] = $col('Numéro de chèque'); $data['id_categorie'] = $liste_cats[$cat]; } ................................................................................ $db = DB::getInstance(); $db->exec('BEGIN;'); $comptes = new Compta_Comptes; $banques = new Compta_Comptes_Bancaires; $cats = new Compta_Categories; $journal = new Compta_Journal; $columns = []; $liste_comptes = $db->simpleStatementFetchAssoc('SELECT id, id FROM compta_comptes;'); $liste_cats = $db->simpleStatementFetchAssoc('SELECT intitule, id FROM compta_categories;'); $liste_moyens = $cats->listMoyensPaiement(); $get_compte = function ($compte, $intitule) use (&$liste_comptes, &$comptes, &$banques) { if (substr($compte, 0, 2) == '51') ................................................................................ } // Création comptes if (!array_key_exists($compte, $liste_comptes)) { if (substr($compte, 0, 3) == '512') { $liste_comptes[$compte] = $banques->add([ 'libelle' => $intitule, 'banque' => 'Inconnue', ]); } else { $liste_comptes[$compte] = $comptes->add([ 'id' => $compte, 'libelle' => $intitule, 'parent' => substr($compte, 0, -1) ]); } } return $compte; }; $col = function($column) use (&$row, &$columns) ................................................................................ { $type = $cats::AUTRES; $cat = false; } if ($type != $cats::AUTRES) { $liste_cats[$cat] = $cats->add([ 'intitule' => $cat, 'type' => $type, 'compte' => $compte ]); } } $data = [ 'libelle' => $col('Libellé'), 'montant' => $col('Montant'), 'date' => $date, 'compte_credit' => $credit, 'compte_debit' => $debit, 'numero_piece' => $col('Numéro de pièce'), 'remarques' => $col('Remarques'), ]; if ($cat) { $data['moyen_paiement'] = $moyen; $data['numero_cheque'] = $col('Numéro de chèque'); $data['id_categorie'] = $liste_cats[$cat]; } |
Modified src/include/class.compta_journal.php from [c1f80fd446] to [a5ce496690].
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
if (empty($data['date']) || !utils::checkDate($data['date'])) { throw new UserException('Date vide ou invalide.'); } if (!$db->simpleQuerySingle('SELECT 1 FROM compta_exercices WHERE cloture = 0 AND debut <= :date AND fin >= :date;', false, array('date' => $data['date']))) { throw new UserException('La date ne correspond pas à l\'exercice en cours.'); } if (empty($data['moyen_paiement'])) { $data['moyen_paiement'] = null; ................................................................................ $data['montant'] = (float)$data['montant']; if ($data['montant'] <= 0) { throw new UserException('Le montant ne peut être égal ou inférieur à zéro.'); } foreach (array('remarques', 'numero_piece', 'numero_cheque') as $champ) { if (empty($data[$champ]) || !trim($data[$champ])) { $data[$champ] = ''; } else { |
|
|
|
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
if (empty($data['date']) || !utils::checkDate($data['date'])) { throw new UserException('Date vide ou invalide.'); } if (!$db->simpleQuerySingle('SELECT 1 FROM compta_exercices WHERE cloture = 0 AND debut <= :date AND fin >= :date;', false, ['date' => $data['date']])) { throw new UserException('La date ne correspond pas à l\'exercice en cours.'); } if (empty($data['moyen_paiement'])) { $data['moyen_paiement'] = null; ................................................................................ $data['montant'] = (float)$data['montant']; if ($data['montant'] <= 0) { throw new UserException('Le montant ne peut être égal ou inférieur à zéro.'); } foreach (['remarques', 'numero_piece', 'numero_cheque'] as $champ) { if (empty($data[$champ]) || !trim($data[$champ])) { $data[$champ] = ''; } else { |
Modified src/include/class.config.php from [1c40d3fe5b] to [9f7d60c48f].
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 .. 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 .. 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 .. 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 ... 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 ... 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
namespace Garradin; class Config { protected $fields_types = null; protected $config = null; protected $modified = array(); static protected $_instance = null; static public function getInstance() { return self::$_instance ?: self::$_instance = new Config; } ................................................................................ protected function __construct() { // Définition des types de données stockées $string = ''; $int = 0; $float = 0.0; $array = array(); $bool = false; $object = new \stdClass; $this->fields_types = array( 'nom_asso' => $string, 'adresse_asso' => $string, 'email_asso' => $string, 'site_asso' => $string, 'monnaie' => $string, 'pays' => $string, ................................................................................ 'frequence_sauvegardes' => $int, 'nombre_sauvegardes' => $int, 'champ_identifiant' => $string, 'champ_identite' => $string, 'version' => $string, ); $db = DB::getInstance(); $this->config = $db->simpleStatementFetchAssoc('SELECT cle, valeur FROM config ORDER BY cle;'); foreach ($this->config as $key=>&$value) { ................................................................................ } public function save() { if (empty($this->modified)) return true; $values = array(); $db = DB::getInstance(); $db->exec('BEGIN;'); foreach ($this->modified as $key=>$modified) { $value = $this->config[$key]; ................................................................................ $db->simpleExec('INSERT OR REPLACE INTO config (cle, valeur) VALUES (?, ?);', $key, $value); } $db->exec('END;'); $this->modified = array(); return true; } public function get($key) { if (!array_key_exists($key, $this->fields_types)) ................................................................................ if (!array_key_exists($key, $this->fields_types)) { throw new \OutOfBoundsException('Ce champ est inconnu.'); } if (is_array($this->fields_types[$key])) { $value = !empty($value) ? (array) $value : array(); } elseif (is_int($this->fields_types[$key])) { $value = (int) $value; } elseif (is_float($this->fields_types[$key])) { |
| | | | | | | |
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 .. 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 .. 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 .. 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 ... 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 ... 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
namespace Garradin; class Config { protected $fields_types = null; protected $config = null; protected $modified = []; static protected $_instance = null; static public function getInstance() { return self::$_instance ?: self::$_instance = new Config; } ................................................................................ protected function __construct() { // Définition des types de données stockées $string = ''; $int = 0; $float = 0.0; $array = []; $bool = false; $object = new \stdClass; $this->fields_types = [ 'nom_asso' => $string, 'adresse_asso' => $string, 'email_asso' => $string, 'site_asso' => $string, 'monnaie' => $string, 'pays' => $string, ................................................................................ 'frequence_sauvegardes' => $int, 'nombre_sauvegardes' => $int, 'champ_identifiant' => $string, 'champ_identite' => $string, 'version' => $string, ]; $db = DB::getInstance(); $this->config = $db->simpleStatementFetchAssoc('SELECT cle, valeur FROM config ORDER BY cle;'); foreach ($this->config as $key=>&$value) { ................................................................................ } public function save() { if (empty($this->modified)) return true; $values = []; $db = DB::getInstance(); $db->exec('BEGIN;'); foreach ($this->modified as $key=>$modified) { $value = $this->config[$key]; ................................................................................ $db->simpleExec('INSERT OR REPLACE INTO config (cle, valeur) VALUES (?, ?);', $key, $value); } $db->exec('END;'); $this->modified = []; return true; } public function get($key) { if (!array_key_exists($key, $this->fields_types)) ................................................................................ if (!array_key_exists($key, $this->fields_types)) { throw new \OutOfBoundsException('Ce champ est inconnu.'); } if (is_array($this->fields_types[$key])) { $value = !empty($value) ? (array) $value : []; } elseif (is_int($this->fields_types[$key])) { $value = (int) $value; } elseif (is_float($this->fields_types[$key])) { |
Modified src/include/class.db.php from [70706b161b] to [5025f71f76].
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 ... 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 ... 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 ... 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 ... 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
parent::__construct(DB_FILE, $flags); $this->enableExceptions(true); // Activer les contraintes des foreign keys $this->exec('PRAGMA foreign_keys = ON;'); $this->createFunction('transliterate_to_ascii', array('Garradin\utils', 'transliterateToAscii')); $this->createFunction('base64', 'base64_encode'); $this->createFunction('rank', array($this, 'sql_rank')); $this->createFunction('running_sum', array($this, 'sql_running_sum')); } public function sql_running_sum($data) { // Why is this function called two times for the first row?! // Dunno but here is a workaround if (is_null($this->_running_sum)) ................................................................................ return SQLITE3_NULL; elseif (is_string($arg)) return SQLITE3_TEXT; else throw new \InvalidArgumentException('Argument '.$name.' is of invalid type '.gettype($arg)); } public function simpleStatement($query, $args = array()) { $statement = $this->prepare($query); $nb = $statement->paramCount(); if (!empty($args)) { if (is_array($args) && count($args) == 1 && is_array(current($args))) ................................................................................ public function queryFetchAssocKey($query, $mode = SQLITE3_BOTH) { return $this->_fetchResultAssocKey($this->query($query), $mode); } protected function _fetchResult($result, $mode) { $out = array(); while ($row = $result->fetchArray($mode)) { $out[] = $row; } $result->finalize(); ................................................................................ unset($result, $row); return $out; } protected function _fetchResultAssoc($result) { $out = array(); while ($row = $result->fetchArray(SQLITE3_NUM)) { $out[$row[0]] = $row[1]; } $result->finalize(); ................................................................................ unset($result, $row); return $out; } protected function _fetchResultAssocKey($result, $mode) { $out = array(); while ($row = $result->fetchArray($mode)) { $key = current($row); $out[$key] = $row; } |
| | | | | | | |
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 ... 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 ... 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 ... 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 ... 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
parent::__construct(DB_FILE, $flags); $this->enableExceptions(true); // Activer les contraintes des foreign keys $this->exec('PRAGMA foreign_keys = ON;'); $this->createFunction('transliterate_to_ascii', ['Garradin\utils', 'transliterateToAscii']); $this->createFunction('base64', 'base64_encode'); $this->createFunction('rank', [$this, 'sql_rank']); $this->createFunction('running_sum', [$this, 'sql_running_sum']); } public function sql_running_sum($data) { // Why is this function called two times for the first row?! // Dunno but here is a workaround if (is_null($this->_running_sum)) ................................................................................ return SQLITE3_NULL; elseif (is_string($arg)) return SQLITE3_TEXT; else throw new \InvalidArgumentException('Argument '.$name.' is of invalid type '.gettype($arg)); } public function simpleStatement($query, $args = []) { $statement = $this->prepare($query); $nb = $statement->paramCount(); if (!empty($args)) { if (is_array($args) && count($args) == 1 && is_array(current($args))) ................................................................................ public function queryFetchAssocKey($query, $mode = SQLITE3_BOTH) { return $this->_fetchResultAssocKey($this->query($query), $mode); } protected function _fetchResult($result, $mode) { $out = []; while ($row = $result->fetchArray($mode)) { $out[] = $row; } $result->finalize(); ................................................................................ unset($result, $row); return $out; } protected function _fetchResultAssoc($result) { $out = []; while ($row = $result->fetchArray(SQLITE3_NUM)) { $out[$row[0]] = $row[1]; } $result->finalize(); ................................................................................ unset($result, $row); return $out; } protected function _fetchResultAssocKey($result, $mode) { $out = []; while ($row = $result->fetchArray($mode)) { $key = current($row); $out[$key] = $row; } |
Modified src/include/class.membres.php from [f3f8800d17] to [475706e765].
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ... 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 ... 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 ... 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 ... 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 ... 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 ... 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 ... 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 ... 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 |
if (!$membre || trim($membre['email']) == '') { return false; } $this->_sessionStart(true); $hash = sha1($membre['email'] . $membre['id'] . 'recover' . ROOT . time()); $_SESSION['recover_password'] = array('id' => (int) $membre['id'], 'email' => $membre['email'], 'hash' => $hash); $message = "Bonjour,\n\nVous avez oublié votre mot de passe ? Pas de panique !\n\n"; $message.= "Il vous suffit de cliquer sur le lien ci-dessous pour recevoir un nouveau mot de passe.\n\n"; $message.= WWW_URL . 'admin/password.php?c=' . substr($hash, -10); $message.= "\n\nSi vous n'avez pas demandé à recevoir ce message, ignorez-le, votre mot de passe restera inchangé."; return utils::mail($membre['email'], '['.$config->get('nom_asso').'] Mot de passe perdu ?', $message); ................................................................................ $message = "Bonjour,\n\nVous avez demandé un nouveau mot de passe pour votre compte.\n\n"; $message.= "Votre adresse email : ".$dest."\n"; $message.= "Votre nouveau mot de passe : ".$password."\n\n"; $message.= "Si vous n'avez pas demandé à recevoir ce message, merci de nous le signaler."; $password = $this->_hashPassword($password); $db->simpleUpdate('membres', array('passe' => $password), 'id = '.(int)$id); return utils::mail($dest, '['.$config->get('nom_asso').'] Nouveau mot de passe', $message); } public function updateSessionData($membre = null, $droits = null) { if (is_null($membre)) ................................................................................ return false; return $_SESSION['logged_user']; } public function logout() { $_SESSION = array(); setcookie(session_name(), '', 0, '/'); return true; } public function sessionStore($key, $value) { if (!isset($_SESSION['storage'])) { $_SESSION['storage'] = array(); } if ($value === null) { unset($_SESSION['storage'][$key]); } else ................................................................................ $message .= ", merci de contacter ".$config->get('email_asso')." en cas d'abus."; if ($copie) { utils::mail($from, $sujet, $message); } return utils::mail($dest, $sujet, $message, array('From' => $from)); } // Gestion des données /////////////////////////////////////////////////////// public function _checkFields(&$data, $check_editable = true, $check_password = true) { $champs = Config::getInstance()->get('champs_membres'); ................................................................................ { throw new UserException('Le mot de passe doit faire au moins 5 caractères.'); } return true; } public function add($data = array()) { $this->_checkFields($data); $db = DB::getInstance(); $config = Config::getInstance(); $id = $config->get('champ_identifiant'); if (!empty($data[$id]) ................................................................................ $data['id_categorie'] = Config::getInstance()->get('categorie_membres'); } $db->simpleInsert('membres', $data); return $db->lastInsertRowId(); } public function edit($id, $data = array(), $check_editable = true) { $db = DB::getInstance(); $config = Config::getInstance(); if (isset($data['id']) && ($data['id'] == $id || empty($data['id']))) { unset($data['id']); ................................................................................ FROM membres WHERE id = ? LIMIT 1;', true, (int)$id); } public function delete($ids) { if (!is_array($ids)) { $ids = array((int)$ids); } if ($this->isLogged()) { $user = $this->getLoggedUser(); foreach ($ids as $id) ................................................................................ foreach ($membres as &$id) { $id = (int) $id; } $db = DB::getInstance(); return $db->simpleUpdate('membres', array('id_categorie' => (int)$id_cat), 'id IN ('.implode(',', $membres).')' ); } static protected function _deleteMembres($membres) { foreach ($membres as &$id) ................................................................................ return $db->exec('DELETE FROM membres WHERE id IN ('.$membres.');'); } public function sendMessageToCategory($dest, $sujet, $message, $subscribed_only = false) { $config = Config::getInstance(); $headers = array( 'From' => '"'.$config->get('nom_asso').'" <'.$config->get('email_asso').'>', ); $message .= "\n\n--\n".$config->get('nom_asso')."\n".$config->get('site_asso'); if ($dest == 0) $where = 'id_categorie NOT IN (SELECT id FROM membres_categories WHERE cacher = 1)'; else $where = 'id_categorie = '.(int)$dest; |
| > > > > | | | | | | | | | < > |
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 ... 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 ... 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 ... 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 ... 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 ... 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 ... 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 ... 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 ... 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 |
if (!$membre || trim($membre['email']) == '') { return false; } $this->_sessionStart(true); $hash = sha1($membre['email'] . $membre['id'] . 'recover' . ROOT . time()); $_SESSION['recover_password'] = [ 'id' => (int) $membre['id'], 'email' => $membre['email'], 'hash' => $hash ]; $message = "Bonjour,\n\nVous avez oublié votre mot de passe ? Pas de panique !\n\n"; $message.= "Il vous suffit de cliquer sur le lien ci-dessous pour recevoir un nouveau mot de passe.\n\n"; $message.= WWW_URL . 'admin/password.php?c=' . substr($hash, -10); $message.= "\n\nSi vous n'avez pas demandé à recevoir ce message, ignorez-le, votre mot de passe restera inchangé."; return utils::mail($membre['email'], '['.$config->get('nom_asso').'] Mot de passe perdu ?', $message); ................................................................................ $message = "Bonjour,\n\nVous avez demandé un nouveau mot de passe pour votre compte.\n\n"; $message.= "Votre adresse email : ".$dest."\n"; $message.= "Votre nouveau mot de passe : ".$password."\n\n"; $message.= "Si vous n'avez pas demandé à recevoir ce message, merci de nous le signaler."; $password = $this->_hashPassword($password); $db->simpleUpdate('membres', ['passe' => $password], 'id = '.(int)$id); return utils::mail($dest, '['.$config->get('nom_asso').'] Nouveau mot de passe', $message); } public function updateSessionData($membre = null, $droits = null) { if (is_null($membre)) ................................................................................ return false; return $_SESSION['logged_user']; } public function logout() { $_SESSION = []; setcookie(session_name(), '', 0, '/'); return true; } public function sessionStore($key, $value) { if (!isset($_SESSION['storage'])) { $_SESSION['storage'] = []; } if ($value === null) { unset($_SESSION['storage'][$key]); } else ................................................................................ $message .= ", merci de contacter ".$config->get('email_asso')." en cas d'abus."; if ($copie) { utils::mail($from, $sujet, $message); } return utils::mail($dest, $sujet, $message, ['From' => $from]); } // Gestion des données /////////////////////////////////////////////////////// public function _checkFields(&$data, $check_editable = true, $check_password = true) { $champs = Config::getInstance()->get('champs_membres'); ................................................................................ { throw new UserException('Le mot de passe doit faire au moins 5 caractères.'); } return true; } public function add($data = []) { $this->_checkFields($data); $db = DB::getInstance(); $config = Config::getInstance(); $id = $config->get('champ_identifiant'); if (!empty($data[$id]) ................................................................................ $data['id_categorie'] = Config::getInstance()->get('categorie_membres'); } $db->simpleInsert('membres', $data); return $db->lastInsertRowId(); } public function edit($id, $data = [], $check_editable = true) { $db = DB::getInstance(); $config = Config::getInstance(); if (isset($data['id']) && ($data['id'] == $id || empty($data['id']))) { unset($data['id']); ................................................................................ FROM membres WHERE id = ? LIMIT 1;', true, (int)$id); } public function delete($ids) { if (!is_array($ids)) { $ids = [(int)$ids]; } if ($this->isLogged()) { $user = $this->getLoggedUser(); foreach ($ids as $id) ................................................................................ foreach ($membres as &$id) { $id = (int) $id; } $db = DB::getInstance(); return $db->simpleUpdate('membres', ['id_categorie' => (int)$id_cat], 'id IN ('.implode(',', $membres).')' ); } static protected function _deleteMembres($membres) { foreach ($membres as &$id) ................................................................................ return $db->exec('DELETE FROM membres WHERE id IN ('.$membres.');'); } public function sendMessageToCategory($dest, $sujet, $message, $subscribed_only = false) { $config = Config::getInstance(); $headers = [ 'From' => '"'.$config->get('nom_asso').'" <'.$config->get('email_asso').'>', ]; $message .= "\n\n--\n".$config->get('nom_asso')."\n".$config->get('site_asso'); if ($dest == 0) $where = 'id_categorie NOT IN (SELECT id FROM membres_categories WHERE cacher = 1)'; else $where = 'id_categorie = '.(int)$dest; |
Modified src/include/class.membres_categories.php from [8c232732a2] to [14a663a7ed].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<?php namespace Garradin; class Membres_Categories { protected $droits = array( 'inscription'=> Membres::DROIT_AUCUN, 'connexion' => Membres::DROIT_ACCES, 'membres' => Membres::DROIT_ACCES, 'compta' => Membres::DROIT_ACCES, 'wiki' => Membres::DROIT_ACCES, 'config' => Membres::DROIT_AUCUN, ); static public function getDroitsDefaut() { return $this->droits; } protected function _checkData(&$data) ................................................................................ if ($db->simpleQuerySingle('SELECT 1 FROM membres WHERE id_categorie = ?;', false, (int)$id)) { throw new UserException('La catégorie contient encore des membres, il n\'est pas possible de la supprimer.'); } $db->simpleUpdate( 'wiki_pages', array( 'droit_lecture' => Wiki::LECTURE_NORMAL, 'droit_ecriture' => Wiki::ECRITURE_NORMAL, ), 'droit_lecture = '.(int)$id.' OR droit_ecriture = '.(int)$id ); return $db->simpleExec('DELETE FROM membres_categories WHERE id = ?;', (int) $id); } public function listSimple() |
|
|
<
>
<
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<?php namespace Garradin; class Membres_Categories { protected $droits = [ 'inscription'=> Membres::DROIT_AUCUN, 'connexion' => Membres::DROIT_ACCES, 'membres' => Membres::DROIT_ACCES, 'compta' => Membres::DROIT_ACCES, 'wiki' => Membres::DROIT_ACCES, 'config' => Membres::DROIT_AUCUN, ]; static public function getDroitsDefaut() { return $this->droits; } protected function _checkData(&$data) ................................................................................ if ($db->simpleQuerySingle('SELECT 1 FROM membres WHERE id_categorie = ?;', false, (int)$id)) { throw new UserException('La catégorie contient encore des membres, il n\'est pas possible de la supprimer.'); } $db->simpleUpdate( 'wiki_pages', [ 'droit_lecture' => Wiki::LECTURE_NORMAL, 'droit_ecriture' => Wiki::ECRITURE_NORMAL, ], 'droit_lecture = '.(int)$id.' OR droit_ecriture = '.(int)$id ); return $db->simpleExec('DELETE FROM membres_categories WHERE id = ?;', (int) $id); } public function listSimple() |
Modified src/include/class.sauvegarde.php from [45f67dc004] to [97ec38f183].
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
* @param boolean $auto Si true ne renvoie que la liste des sauvegardes automatiques
* @return array Liste des fichiers
*/
public function getList($auto = false)
{
$ext = $auto ? 'auto\.\d+\.sqlite' : 'sqlite';
$out = array();
$dir = dir(DATA_ROOT);
while ($file = $dir->read())
{
if ($file[0] != '.' && is_file(DATA_ROOT . '/' . $file)
&& preg_match('![\w\d._-]+\.' . $ext . '$!i', $file) && $file != basename(DB_FILE))
{
|
| |
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
* @param boolean $auto Si true ne renvoie que la liste des sauvegardes automatiques
* @return array Liste des fichiers
*/
public function getList($auto = false)
{
$ext = $auto ? 'auto\.\d+\.sqlite' : 'sqlite';
$out = [];
$dir = dir(DATA_ROOT);
while ($file = $dir->read())
{
if ($file[0] != '.' && is_file(DATA_ROOT . '/' . $file)
&& preg_match('![\w\d._-]+\.' . $ext . '$!i', $file) && $file != basename(DB_FILE))
{
|
Modified src/include/class.squelette.php from [e3b0ee8047] to [89735017a9].
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 ... 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 ... 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 ... 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 ... 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 ... 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 ... 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 ... 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
class Squelette_Snippet { const TEXT = 0; const PHP = 1; const GUESS = 2; const OBJ = 3; protected $_content = array(); protected function _getType($type, $value) { if ($type == self::GUESS) { if ($value instanceof Squelette_Snippet) return self::OBJ; ................................................................................ } if ($php && !$in_php) { $out .= ' ?>'; } $this->_content = array(); return $out; } public function __toString() { return $this->output(false); ................................................................................ } } class Squelette extends \miniSkel { private $parent = null; private $current = null; private $_vars = array(); private function _registerDefaultModifiers() { foreach (Squelette_Filtres::$filtres_php as $func=>$name) { if (is_string($func)) $this->register_modifier($name, $func); else $this->register_modifier($name, $name); } foreach (get_class_methods('Garradin\Squelette_Filtres') as $name) { $this->register_modifier($name, array('Garradin\Squelette_Filtres', $name)); } foreach (Squelette_Filtres::$filtres_alias as $name=>$func) { $this->register_modifier($name, array('Garradin\Squelette_Filtres', $func)); } } public function __construct() { $this->_registerDefaultModifiers(); ................................................................................ foreach ($modifiers as &$modifier) { if (!isset($this->modifiers[$modifier['name']])) { throw new \miniSkelMarkupException('Filtre '.$modifier['name'].' inconnu !'); } $out->append(1, '$value = call_user_func_array('.var_export($this->modifiers[$modifier['name']], true).', array($value, '); foreach ($modifier['arguments'] as $arg) { if ($arg == 'debut_liste') { $out->append(1, '$this->getVariable(\'debut_liste\')'); } ................................................................................ //if (preg_match('!getVariable!', $arg)) throw new Exception("lol"); $out->append(1, '"'.str_replace('"', '\\"', $arg).'"'); } $out->append(1, ', '); } $out->append(1, '));'); if (in_array($modifier['name'], Squelette_Filtres::$desactiver_defaut)) { $applyDefault = false; } } ................................................................................ $where .= 'AND (SELECT COUNT(id) FROM wiki_pages WHERE parent = w.id) = 0 '; } elseif ($loopType == 'rubriques') { $where .= 'AND (SELECT COUNT(id) FROM wiki_pages WHERE parent = w.id) > 0 '; } $allowed_fields = array('id', 'uri', 'titre', 'date', 'date_creation', 'date_modification', 'parent', 'rubrique', 'revision', 'points', 'recherche', 'texte'); $search = $search_rank = false; foreach ($loopCriterias as $criteria) { if (isset($criteria['field'])) { if (!in_array($criteria['field'], $allowed_fields)) ................................................................................ $out->append(1, '$nb_rows = $db->countRows($result_'.$hash.'); '); if ($search) { $out->append(1, '} else { $result_'.$hash.' = false; $nb_rows = 0; }'); } $out->append(1, '$this->_vars[\''.$hash.'\'] = array(\'_self_hash\' => \''.$hash.'\', \'_parent_hash\' => $parent_hash, \'total_boucle\' => $nb_rows, \'compteur_boucle\' => 0);'); $out->append(1, '$this->current =& $this->_vars[\''.$hash.'\']; '); $out->append(1, 'if ($nb_rows > 0):'); if ($preContent) { $out->append(2, $this->parse($preContent, $loopName, self::PRE_CONTENT)); } ................................................................................ { if (!file_exists($path)) { throw new \miniSkelMarkupException('Le squelette "'.$tpl_id.'" n\'existe pas.'); } $content = file_get_contents($path); $content = strtr($content, array('<?php' => '<?php', '<?' => '<?php echo \'<?\'; ?>')); $out = new Squelette_Snippet(2, $this->parse($content)); $out->prepend(1, '/* '.$tpl_id.' */ '. 'namespace Garradin; $db = DB::getInstance(); '. 'if ($this->parent) $parent_hash = $this->parent[\'_self_hash\']; '. // For included files 'else $parent_hash = false;'); ................................................................................ } return true; } static public function listSources() { $sources = array(); $dir = dir(ROOT . '/www/squelettes-dist'); while ($file = $dir->read()) { if ($file[0] != '.') $sources[] = $file; |
| | | | | | | | | | | | |
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 ... 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 ... 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 ... 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 ... 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 ... 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 ... 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 ... 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
class Squelette_Snippet { const TEXT = 0; const PHP = 1; const GUESS = 2; const OBJ = 3; protected $_content = []; protected function _getType($type, $value) { if ($type == self::GUESS) { if ($value instanceof Squelette_Snippet) return self::OBJ; ................................................................................ } if ($php && !$in_php) { $out .= ' ?>'; } $this->_content = []; return $out; } public function __toString() { return $this->output(false); ................................................................................ } } class Squelette extends \miniSkel { private $parent = null; private $current = null; private $_vars = []; private function _registerDefaultModifiers() { foreach (Squelette_Filtres::$filtres_php as $func=>$name) { if (is_string($func)) $this->register_modifier($name, $func); else $this->register_modifier($name, $name); } foreach (get_class_methods('Garradin\Squelette_Filtres') as $name) { $this->register_modifier($name, ['Garradin\Squelette_Filtres', $name]); } foreach (Squelette_Filtres::$filtres_alias as $name=>$func) { $this->register_modifier($name, ['Garradin\Squelette_Filtres', $func]); } } public function __construct() { $this->_registerDefaultModifiers(); ................................................................................ foreach ($modifiers as &$modifier) { if (!isset($this->modifiers[$modifier['name']])) { throw new \miniSkelMarkupException('Filtre '.$modifier['name'].' inconnu !'); } $out->append(1, '$value = call_user_func_array('.var_export($this->modifiers[$modifier['name']], true).', [$value, '); foreach ($modifier['arguments'] as $arg) { if ($arg == 'debut_liste') { $out->append(1, '$this->getVariable(\'debut_liste\')'); } ................................................................................ //if (preg_match('!getVariable!', $arg)) throw new Exception("lol"); $out->append(1, '"'.str_replace('"', '\\"', $arg).'"'); } $out->append(1, ', '); } $out->append(1, ']);'); if (in_array($modifier['name'], Squelette_Filtres::$desactiver_defaut)) { $applyDefault = false; } } ................................................................................ $where .= 'AND (SELECT COUNT(id) FROM wiki_pages WHERE parent = w.id) = 0 '; } elseif ($loopType == 'rubriques') { $where .= 'AND (SELECT COUNT(id) FROM wiki_pages WHERE parent = w.id) > 0 '; } $allowed_fields = ['id', 'uri', 'titre', 'date', 'date_creation', 'date_modification', 'parent', 'rubrique', 'revision', 'points', 'recherche', 'texte']; $search = $search_rank = false; foreach ($loopCriterias as $criteria) { if (isset($criteria['field'])) { if (!in_array($criteria['field'], $allowed_fields)) ................................................................................ $out->append(1, '$nb_rows = $db->countRows($result_'.$hash.'); '); if ($search) { $out->append(1, '} else { $result_'.$hash.' = false; $nb_rows = 0; }'); } $out->append(1, '$this->_vars[\''.$hash.'\'] = [\'_self_hash\' => \''.$hash.'\', \'_parent_hash\' => $parent_hash, \'total_boucle\' => $nb_rows, \'compteur_boucle\' => 0];'); $out->append(1, '$this->current =& $this->_vars[\''.$hash.'\']; '); $out->append(1, 'if ($nb_rows > 0):'); if ($preContent) { $out->append(2, $this->parse($preContent, $loopName, self::PRE_CONTENT)); } ................................................................................ { if (!file_exists($path)) { throw new \miniSkelMarkupException('Le squelette "'.$tpl_id.'" n\'existe pas.'); } $content = file_get_contents($path); $content = strtr($content, ['<?php' => '<?php', '<?' => '<?php echo \'<?\'; ?>']); $out = new Squelette_Snippet(2, $this->parse($content)); $out->prepend(1, '/* '.$tpl_id.' */ '. 'namespace Garradin; $db = DB::getInstance(); '. 'if ($this->parent) $parent_hash = $this->parent[\'_self_hash\']; '. // For included files 'else $parent_hash = false;'); ................................................................................ } return true; } static public function listSources() { $sources = []; $dir = dir(ROOT . '/www/squelettes-dist'); while ($file = $dir->read()) { if ($file[0] != '.') $sources[] = $file; |
Modified src/include/class.wiki.php from [beee53698e] to [80444f9637].
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 ... 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 ... 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 ... 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
$data['parent'] = 0; } } return true; } public function create($data = array()) { $this->_checkFields($data); $db = DB::getInstance(); if (!empty($data['uri'])) { $data['uri'] = self::transformTitleToURI($data['uri']); ................................................................................ $db->simpleInsert('wiki_pages', $data); $id = $db->lastInsertRowId(); // On ne peut utiliser un trigger pour insérer dans la recherche // car les tables virtuelles font des opérations qui modifient // last_insert_rowid() et donc résultat incohérent $db->simpleInsert('wiki_recherche', array('id' => $id, 'titre' => $data['titre'])); return $id; } public function edit($id, $data = array()) { $db = DB::getInstance(); $this->_checkFields($data); if (isset($data['uri'])) { $data['uri'] = self::transformTitleToURI($data['uri']); ................................................................................ // Incrémentons le numéro de révision $revision++; $data['id_page'] = $id; $data['revision'] = $revision; $db->simpleInsert('wiki_revisions', $data); $db->simpleUpdate('wiki_pages', array( 'revision' => $revision, 'date_modification' => gmdate('Y-m-d H:i:s'), ), 'id = '.(int)$id); return true; } public function search($query) { $db = DB::getInstance(); ................................................................................ $db = DB::getInstance(); return $db->simpleQuerySingle('SELECT COUNT(*) FROM wiki_pages WHERE '.$this->_getLectureClause().';'); } public function listBackBreadCrumbs($id) { if ($id == 0) return array(); $db = DB::getInstance(); $flat = array(); while ($id > 0) { $res = $db->simpleQuerySingle('SELECT parent, titre, uri FROM wiki_pages WHERE id = ? LIMIT 1;', true, (int)$id); $flat[] = array( 'id' => $id, 'titre' => $res['titre'], 'uri' => $res['uri'], ); $id = (int)$res['parent']; } return array_reverse($flat); } public function listBackParentTree($id) { $db = DB::getInstance(); $flat = array( array( 'id' => 0, 'parent' => null, 'titre' => 'Racine', 'children' => $db->simpleStatementFetchAssocKey('SELECT id, parent, titre FROM wiki_pages WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;', SQLITE3_ASSOC, 0) ) ); do { $parent = $db->simpleQuerySingle('SELECT parent FROM wiki_pages WHERE id = ? LIMIT 1;', false, (int)$id); $flat[$id] = array( 'id' => $id, 'parent' => $id ? (int)$parent : null, 'titre' => $id ? (string)$db->simpleQuerySingle('SELECT titre FROM wiki_pages WHERE id = ? LIMIT 1;', false, (int)$id) : 'Racine', 'children' => $db->simpleStatementFetchAssocKey('SELECT id, parent, titre FROM wiki_pages WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;', SQLITE3_ASSOC, (int)$id) ); $id = (int)$parent; } while ($id != 0); $tree = array(); foreach ($flat as $id=>&$node) { if (is_null($node['parent'])) { $tree[$id] = &$node; } else { if (!isset($flat[$node['parent']]['children'])) { $flat[$node['parent']]['children'] = array(); } $flat[$node['parent']]['children'][$id] = &$node; } } return $tree; } } ?> |
| | | | | | | | | | | | | | | | | |
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 ... 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 ... 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 ... 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
$data['parent'] = 0; } } return true; } public function create($data = []) { $this->_checkFields($data); $db = DB::getInstance(); if (!empty($data['uri'])) { $data['uri'] = self::transformTitleToURI($data['uri']); ................................................................................ $db->simpleInsert('wiki_pages', $data); $id = $db->lastInsertRowId(); // On ne peut utiliser un trigger pour insérer dans la recherche // car les tables virtuelles font des opérations qui modifient // last_insert_rowid() et donc résultat incohérent $db->simpleInsert('wiki_recherche', ['id' => $id, 'titre' => $data['titre']]); return $id; } public function edit($id, $data = []) { $db = DB::getInstance(); $this->_checkFields($data); if (isset($data['uri'])) { $data['uri'] = self::transformTitleToURI($data['uri']); ................................................................................ // Incrémentons le numéro de révision $revision++; $data['id_page'] = $id; $data['revision'] = $revision; $db->simpleInsert('wiki_revisions', $data); $db->simpleUpdate('wiki_pages', [ 'revision' => $revision, 'date_modification' => gmdate('Y-m-d H:i:s'), ], 'id = '.(int)$id); return true; } public function search($query) { $db = DB::getInstance(); ................................................................................ $db = DB::getInstance(); return $db->simpleQuerySingle('SELECT COUNT(*) FROM wiki_pages WHERE '.$this->_getLectureClause().';'); } public function listBackBreadCrumbs($id) { if ($id == 0) return []; $db = DB::getInstance(); $flat = []; while ($id > 0) { $res = $db->simpleQuerySingle('SELECT parent, titre, uri FROM wiki_pages WHERE id = ? LIMIT 1;', true, (int)$id); $flat[] = [ 'id' => $id, 'titre' => $res['titre'], 'uri' => $res['uri'], ]; $id = (int)$res['parent']; } return array_reverse($flat); } public function listBackParentTree($id) { $db = DB::getInstance(); $flat = [ [ 'id' => 0, 'parent' => null, 'titre' => 'Racine', 'children' => $db->simpleStatementFetchAssocKey('SELECT id, parent, titre FROM wiki_pages WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;', SQLITE3_ASSOC, 0) ] ]; do { $parent = $db->simpleQuerySingle('SELECT parent FROM wiki_pages WHERE id = ? LIMIT 1;', false, (int)$id); $flat[$id] = [ 'id' => $id, 'parent' => $id ? (int)$parent : null, 'titre' => $id ? (string)$db->simpleQuerySingle('SELECT titre FROM wiki_pages WHERE id = ? LIMIT 1;', false, (int)$id) : 'Racine', 'children' => $db->simpleStatementFetchAssocKey('SELECT id, parent, titre FROM wiki_pages WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;', SQLITE3_ASSOC, (int)$id) ]; $id = (int)$parent; } while ($id != 0); $tree = []; foreach ($flat as $id=>&$node) { if (is_null($node['parent'])) { $tree[$id] = &$node; } else { if (!isset($flat[$node['parent']]['children'])) { $flat[$node['parent']]['children'] = []; } $flat[$node['parent']]['children'][$id] = &$node; } } return $tree; } } ?> |
Modified src/include/init.php from [3022aaf506] to [5b49b14001].
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
...
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
*/ class Loader { /** * Already loaded filenames * @var array */ static protected $loaded = array(); static protected $libs = array( 'utils', 'squelette_filtres', 'static_cache', 'template' ); /** * Loads a class from the $name * @param stringg $classname * @return bool true */ static public function load($classname) ................................................................................ self::$loaded[$filename] = true; require $filename; } } \spl_autoload_register(array('Garradin\Loader', 'load'), true); $n = new Membres; /* * Inclusion des fichiers de base */ |
|
|
|
|
|
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
...
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
*/ class Loader { /** * Already loaded filenames * @var array */ static protected $loaded = []; static protected $libs = [ 'utils', 'squelette_filtres', 'static_cache', 'template' ]; /** * Loads a class from the $name * @param stringg $classname * @return bool true */ static public function load($classname) ................................................................................ self::$loaded[$filename] = true; require $filename; } } \spl_autoload_register(['Garradin\Loader', 'load'], true); $n = new Membres; /* * Inclusion des fichiers de base */ |
Modified src/include/lib.squelette_filtres.php from [d5a87498f4] to [7a68645339].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
..
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<?php namespace Garradin; class Squelette_Filtres { static private $g2x = null; static private $alt = array(); static public $filtres_php = array( 'strtolower', 'strtoupper', 'ucfirst', 'ucwords', 'str_rot13', 'str_shuffle', 'htmlentities', ................................................................................ 'str_split', 'str_word_count', 'strrev', 'strlen', 'wordwrap', 'strip_tags' => 'supprimer_tags', 'var_dump', ); static public $filtres_alias = array( '!=' => 'different_de', '==' => 'egal_a', '?' => 'choixsivide', '>' => 'superieur_a', '>=' => 'superieur_ou_egal_a', '<' => 'inferieur_a', '<=' => 'inferieur_ou_egal_a', 'yes' => 'oui', 'no' => 'non', 'and' => 'et', 'or' => 'ou', 'xor' => 'xou', ); static public $desactiver_defaut = array( 'formatter_texte', 'entites_html', 'proteger_contact', 'echapper_xml', ); static public function date_en_francais($date) { return ucfirst(strtolower(utils::strftime_fr('%A %e %B %Y', $date))); } static public function heure_en_francais($date) |
|
|
<
>
|
<
>
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
..
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<?php namespace Garradin; class Squelette_Filtres { static private $g2x = null; static private $alt = []; static public $filtres_php = [ 'strtolower', 'strtoupper', 'ucfirst', 'ucwords', 'str_rot13', 'str_shuffle', 'htmlentities', ................................................................................ 'str_split', 'str_word_count', 'strrev', 'strlen', 'wordwrap', 'strip_tags' => 'supprimer_tags', 'var_dump', ]; static public $filtres_alias = [ '!=' => 'different_de', '==' => 'egal_a', '?' => 'choixsivide', '>' => 'superieur_a', '>=' => 'superieur_ou_egal_a', '<' => 'inferieur_a', '<=' => 'inferieur_ou_egal_a', 'yes' => 'oui', 'no' => 'non', 'and' => 'et', 'or' => 'ou', 'xor' => 'xou', ]; static public $desactiver_defaut = [ 'formatter_texte', 'entites_html', 'proteger_contact', 'echapper_xml', ]; static public function date_en_francais($date) { return ucfirst(strtolower(utils::strftime_fr('%A %e %B %Y', $date))); } static public function heure_en_francais($date) |
Modified src/include/lib.template.php from [e37f68648c] to [63482205cb].
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 ... 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 ... 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
return utils::date_fr($format, $ts); } function tpl_format_droits($params) { $droits = $params['droits']; $out = array('connexion' => '', 'inscription' => '', 'membres' => '', 'compta' => '', 'wiki' => '', 'config' => ''); $classes = array( Membres::DROIT_AUCUN => 'aucun', Membres::DROIT_ACCES => 'acces', Membres::DROIT_ECRITURE=> 'ecriture', Membres::DROIT_ADMIN => 'admin', ); foreach ($droits as $cle=>$droit) { $cle = str_replace('droit_', '', $cle); if (array_key_exists($cle, $out)) { ................................................................................ $tpl->register_function('format_droits', 'Garradin\tpl_format_droits'); $tpl->register_function('pagination', 'Garradin\tpl_pagination'); $tpl->register_function('diff', 'Garradin\tpl_diff'); $tpl->register_function('html_champ_membre', 'Garradin\tpl_html_champ_membre'); $tpl->register_modifier('get_country_name', array('Garradin\utils', 'getCountryName')); $tpl->register_modifier('format_tel', 'Garradin\tpl_format_tel'); $tpl->register_modifier('format_wiki', 'Garradin\tpl_format_wiki'); $tpl->register_modifier('liens_wiki', 'Garradin\tpl_liens_wiki'); $tpl->register_modifier('escape_money', 'Garradin\escape_money'); $tpl->register_modifier('html_money', 'Garradin\tpl_html_money'); $tpl->register_modifier('abs', 'abs'); ................................................................................ } elseif ($config['type'] == 'tel') { return '<a href="tel:' . $v . '">' . $v . '</a>'; } elseif ($config['type'] == 'url') { return '<a href="' . $v . '">' . $v . '</a>'; } elseif ($config['type'] == 'country') { return utils::getCountryName($v); } elseif ($config['type'] == 'multiple') { $out = array(); foreach ($config['options'] as $b => $name) { if ($v & (0x01 << $b)) $out[] = $name; } |
| | | | | | |
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 ... 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 ... 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
return utils::date_fr($format, $ts); } function tpl_format_droits($params) { $droits = $params['droits']; $out = ['connexion' => '', 'inscription' => '', 'membres' => '', 'compta' => '', 'wiki' => '', 'config' => '']; $classes = [ Membres::DROIT_AUCUN => 'aucun', Membres::DROIT_ACCES => 'acces', Membres::DROIT_ECRITURE=> 'ecriture', Membres::DROIT_ADMIN => 'admin', ]; foreach ($droits as $cle=>$droit) { $cle = str_replace('droit_', '', $cle); if (array_key_exists($cle, $out)) { ................................................................................ $tpl->register_function('format_droits', 'Garradin\tpl_format_droits'); $tpl->register_function('pagination', 'Garradin\tpl_pagination'); $tpl->register_function('diff', 'Garradin\tpl_diff'); $tpl->register_function('html_champ_membre', 'Garradin\tpl_html_champ_membre'); $tpl->register_modifier('get_country_name', ['Garradin\utils', 'getCountryName']); $tpl->register_modifier('format_tel', 'Garradin\tpl_format_tel'); $tpl->register_modifier('format_wiki', 'Garradin\tpl_format_wiki'); $tpl->register_modifier('liens_wiki', 'Garradin\tpl_liens_wiki'); $tpl->register_modifier('escape_money', 'Garradin\escape_money'); $tpl->register_modifier('html_money', 'Garradin\tpl_html_money'); $tpl->register_modifier('abs', 'abs'); ................................................................................ } elseif ($config['type'] == 'tel') { return '<a href="tel:' . $v . '">' . $v . '</a>'; } elseif ($config['type'] == 'url') { return '<a href="' . $v . '">' . $v . '</a>'; } elseif ($config['type'] == 'country') { return utils::getCountryName($v); } elseif ($config['type'] == 'multiple') { $out = []; foreach ($config['options'] as $b => $name) { if ($v & (0x01 << $b)) $out[] = $name; } |
Modified src/include/lib.utils.php from [42831a0855] to [180cd8e498].
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ... 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 ... 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 ... 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 ... 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 ... 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
class utils { static protected $country_list = null; static protected $g2x = null; static private $french_date_names = array( 'January'=>'Janvier', 'February'=>'Février', 'March'=>'Mars', 'April'=>'Avril', 'May'=>'Mai', 'June'=>'Juin', 'July'=>'Juillet', 'August'=>'Août', 'September'=>'Septembre', 'October'=>'Octobre', 'November'=>'Novembre', 'December'=>'Décembre', 'Monday'=>'Lundi', 'Tuesday'=>'Mardi', 'Wednesday'=>'Mercredi', 'Thursday'=>'Jeudi','Friday'=>'Vendredi','Saturday'=>'Samedi','Sunday'=>'Dimanche', 'Feb'=>'Fév','Apr'=>'Avr','May'=>'Mai','Jun'=>'Juin', 'Jul'=>'Juil','Aug'=>'Aout','Dec'=>'Déc', 'Mon'=>'Lun','Tue'=>'Mar','Wed'=>'Mer','Thu'=>'Jeu','Fri'=>'Ven','Sat'=>'Sam','Sun'=>'Dim'); static public function strftime_fr($format=null, $ts=null) { if (is_null($format)) { $format = '%d/%m/%Y à %H:%M'; } ................................................................................ static public function CSRF_create($key) { self::_sessionStart(true); if (!isset($_SESSION['csrf'])) { $_SESSION['csrf'] = array(); } $_SESSION['csrf'][$key] = sha1($key . uniqid($key, true) . time()); return $_SESSION['csrf'][$key]; } static public function CSRF_check($key, $hash=null) ................................................................................ } if($end==($total-1)) { $end = $total; } if($begin == 2) { $begin = 1; } $out = array(); if ($current > 1) { $out[] = array('id' => $current - 1, 'label' => '« ' . 'Page précédente', 'class' => 'prev', 'accesskey' => 'a'); } if ($begin > 1) { $out[] = array('id' => 1, 'label' => '1 ...', 'class' => 'first'); } for ($i = $begin; $i <= $end; $i++) { $out[] = array('id' => $i, 'label' => $i, 'class' => ($i == $current) ? 'current' : ''); } if ($showLast && $end < $total) { $out[] = array('id' => $total, 'label' => '... ' . $total, 'class' => 'last'); } if ($current < $total) { $out[] = array('id' => $current + 1, 'label' => 'Page suivante' . ' »', 'class' => 'next', 'accesskey' => 'z'); } return $out; } static public function transliterateToAscii($str, $charset='UTF-8') { ................................................................................ static public function htmlGarbage2xhtml($str) { if (!self::$g2x) { require_once ROOT . '/include/libs/garbage2xhtml/lib.garbage2xhtml.php'; self::$g2x = new \garbage2xhtml; self::$g2x->core_attributes = array('class', 'id', 'title'); } return self::$g2x->process($str); } static public function htmlSpip($str, $prefix = '') { ................................................................................ // Adresses email $str = preg_replace('/<a href="((?!http).*@.*)">/iU', '<a href="mailto:$1">', $str); return $str; } static public function mail($to, $subject, $content, $additional_headers = array()) { // Création du contenu du message $content = wordwrap($content); $content = trim($content); $content = preg_replace("#(?<!\r)\n#si", "\r\n", $content); ................................................................................ } return $out; } static public function getMaxUploadSize() { return min(array( self::return_bytes(ini_get('upload_max_filesize')), self::return_bytes(ini_get('post_max_size')), self::return_bytes(ini_get('memory_limit')) )); } static public function return_bytes ($size_str) { switch (substr($size_str, -1)) { |
| | | | | | | | | | | | | |
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ... 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 ... 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 ... 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 ... 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 ... 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
class utils { static protected $country_list = null; static protected $g2x = null; static private $french_date_names = [ 'January'=>'Janvier', 'February'=>'Février', 'March'=>'Mars', 'April'=>'Avril', 'May'=>'Mai', 'June'=>'Juin', 'July'=>'Juillet', 'August'=>'Août', 'September'=>'Septembre', 'October'=>'Octobre', 'November'=>'Novembre', 'December'=>'Décembre', 'Monday'=>'Lundi', 'Tuesday'=>'Mardi', 'Wednesday'=>'Mercredi', 'Thursday'=>'Jeudi','Friday'=>'Vendredi','Saturday'=>'Samedi','Sunday'=>'Dimanche', 'Feb'=>'Fév','Apr'=>'Avr','May'=>'Mai','Jun'=>'Juin', 'Jul'=>'Juil','Aug'=>'Aout','Dec'=>'Déc', 'Mon'=>'Lun','Tue'=>'Mar','Wed'=>'Mer','Thu'=>'Jeu','Fri'=>'Ven','Sat'=>'Sam','Sun'=>'Dim']; static public function strftime_fr($format=null, $ts=null) { if (is_null($format)) { $format = '%d/%m/%Y à %H:%M'; } ................................................................................ static public function CSRF_create($key) { self::_sessionStart(true); if (!isset($_SESSION['csrf'])) { $_SESSION['csrf'] = []; } $_SESSION['csrf'][$key] = sha1($key . uniqid($key, true) . time()); return $_SESSION['csrf'][$key]; } static public function CSRF_check($key, $hash=null) ................................................................................ } if($end==($total-1)) { $end = $total; } if($begin == 2) { $begin = 1; } $out = []; if ($current > 1) { $out[] = ['id' => $current - 1, 'label' => '« ' . 'Page précédente', 'class' => 'prev', 'accesskey' => 'a']; } if ($begin > 1) { $out[] = ['id' => 1, 'label' => '1 ...', 'class' => 'first']; } for ($i = $begin; $i <= $end; $i++) { $out[] = ['id' => $i, 'label' => $i, 'class' => ($i == $current) ? 'current' : '']; } if ($showLast && $end < $total) { $out[] = ['id' => $total, 'label' => '... ' . $total, 'class' => 'last']; } if ($current < $total) { $out[] = ['id' => $current + 1, 'label' => 'Page suivante' . ' »', 'class' => 'next', 'accesskey' => 'z']; } return $out; } static public function transliterateToAscii($str, $charset='UTF-8') { ................................................................................ static public function htmlGarbage2xhtml($str) { if (!self::$g2x) { require_once ROOT . '/include/libs/garbage2xhtml/lib.garbage2xhtml.php'; self::$g2x = new \garbage2xhtml; self::$g2x->core_attributes = ['class', 'id', 'title']; } return self::$g2x->process($str); } static public function htmlSpip($str, $prefix = '') { ................................................................................ // Adresses email $str = preg_replace('/<a href="((?!http).*@.*)">/iU', '<a href="mailto:$1">', $str); return $str; } static public function mail($to, $subject, $content, $additional_headers = []) { // Création du contenu du message $content = wordwrap($content); $content = trim($content); $content = preg_replace("#(?<!\r)\n#si", "\r\n", $content); ................................................................................ } return $out; } static public function getMaxUploadSize() { return min([ self::return_bytes(ini_get('upload_max_filesize')), self::return_bytes(ini_get('post_max_size')), self::return_bytes(ini_get('memory_limit')) ]); } static public function return_bytes ($size_str) { switch (substr($size_str, -1)) { |