Compare commits
2 Commits
474fb451cb
...
843f30d82e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
843f30d82e | ||
|
|
c52ec9ae7a |
53
bin/import_01_collectivites.php
Normal file
53
bin/import_01_collectivites.php
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('smeti_db.inc.php');
|
||||||
|
|
||||||
|
SMETI_db::init();
|
||||||
|
|
||||||
|
$libelle = 'Collectivités';
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'COLL';
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
// Ajouter un lien sur cet item
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/01_COLLECTIVITES.json"), true);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$code = $element['collcod'];
|
||||||
|
SMETI_db::$libelle = $element['collnom'];
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
|
||||||
|
// Ajouter un lien
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
|
||||||
|
// Le rattacher à la racine
|
||||||
|
SMETI_db::$child = SMETI_db::$item;
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
108
bin/import_02_budgets.php
Normal file
108
bin/import_02_budgets.php
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('smeti_db.inc.php');
|
||||||
|
|
||||||
|
SMETI_db::init();
|
||||||
|
|
||||||
|
echo 'Chargement collectivités ';
|
||||||
|
$sql = SMETI_db::$pdo->prepare("SELECT code, item, libelle FROM v_items WHERE plugin = ( SELECT id FROM plugins WHERE libelle = 'Collectivités' )");
|
||||||
|
$sql->execute();
|
||||||
|
$coll = $sql->fetchAll(PDO::FETCH_NUM);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$libelle = 'Budgets';
|
||||||
|
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'BUDG';
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
// Ajouter un lien sur cet item
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = SMETI_db::$code;
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$item;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
echo 'Chargement des données'.PHP_EOL;
|
||||||
|
$counter = 0;
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/02_BUDGETS.json"), true);
|
||||||
|
$nb_shipments = count($shipments);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
progressBar($counter, $nb_shipments);
|
||||||
|
if (5000 == $counter++) break;
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
|
||||||
|
// A-t-on changé de collectivité ?
|
||||||
|
if ($element['collcod'] != $pile_code[$pile_index])
|
||||||
|
{
|
||||||
|
// chercher la collectivité
|
||||||
|
$n = count($coll);
|
||||||
|
for($i=0;$i<$n;$i++)
|
||||||
|
if ($element['collcod'] == $coll[$i][0])
|
||||||
|
break;
|
||||||
|
if ($i == $n) continue;
|
||||||
|
// Revenir au niveau 'plugin' de la pile
|
||||||
|
$pile_index -= 1;
|
||||||
|
|
||||||
|
// Ajout d'un lien (symbolique)
|
||||||
|
SMETI_db::$link = 1;
|
||||||
|
SMETI_db::$item = $coll[$i][1];
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Ajout d'un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
|
||||||
|
// Conserver ce noeud dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['collcod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rajouter le budget
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = $element['colbcodbud'];
|
||||||
|
SMETI_db::$libelle = $element['colbnom'];
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
// Rajouter un lien
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Rajouter un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlever la barre de progression
|
||||||
|
clearLine();
|
||||||
|
// Enlever la barre de progression
|
||||||
|
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
?>
|
||||||
109
bin/import_03_services.php
Normal file
109
bin/import_03_services.php
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('smeti_db.inc.php');
|
||||||
|
|
||||||
|
SMETI_db::init();
|
||||||
|
|
||||||
|
echo 'Chargement collectivités ';
|
||||||
|
$sql = SMETI_db::$pdo->prepare("SELECT code, item, libelle FROM v_items WHERE plugin = ( SELECT id FROM plugins WHERE libelle = 'Collectivités' )");
|
||||||
|
$sql->execute();
|
||||||
|
$coll = $sql->fetchAll(PDO::FETCH_NUM);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$libelle = 'Services';
|
||||||
|
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
die;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'SERV';
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
// Ajouter un lien sur cet item
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = SMETI_db::$code;
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$item;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
echo 'Chargement des données'.PHP_EOL;
|
||||||
|
$counter = 0;
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/03_SERVICES.json"), true);
|
||||||
|
$nb_shipments = count($shipments);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
progressBar($counter, $nb_shipments);
|
||||||
|
if (5000 == $counter++) break;
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
|
||||||
|
// A-t-on changé de collectivité ?
|
||||||
|
if ($element['collcod'] != $pile_code[$pile_index])
|
||||||
|
{
|
||||||
|
// chercher la collectivité
|
||||||
|
$n = count($coll);
|
||||||
|
for($i=0;$i<$n;$i++)
|
||||||
|
if ($element['collcod'] == $coll[$i][0])
|
||||||
|
break;
|
||||||
|
if ($i == $n) continue;
|
||||||
|
// Revenir au niveau 'plugin' de la pile
|
||||||
|
$pile_index -= 1;
|
||||||
|
|
||||||
|
// Ajout d'un lien (symbolique)
|
||||||
|
SMETI_db::$link = 1;
|
||||||
|
SMETI_db::$item = $coll[$i][1];
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Ajout d'un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
|
||||||
|
// Conserver ce noeud dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['collcod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rajouter le service
|
||||||
|
SMETI_db::$code = $element['servcod'];
|
||||||
|
SMETI_db::$libelle = $element['servcod'];
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
// Rajouter un lien
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Rajouter un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlever la barre de progression
|
||||||
|
clearLine();
|
||||||
|
// Enlever la barre de progression
|
||||||
|
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
?>
|
||||||
141
bin/import_10_ncmp.php
Normal file
141
bin/import_10_ncmp.php
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('smeti_db.inc.php');
|
||||||
|
|
||||||
|
SMETI_db::init();
|
||||||
|
|
||||||
|
echo 'Chargement collectivités ';
|
||||||
|
$sql = SMETI_db::$pdo->prepare("SELECT code, item, libelle FROM v_items WHERE plugin = ( SELECT id FROM plugins WHERE libelle = 'Collectivités' )");
|
||||||
|
$sql->execute();
|
||||||
|
$coll = $sql->fetchAll(PDO::FETCH_NUM);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$libelle = 'Familles achats';
|
||||||
|
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'NCMP';
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
// Ajouter un lien sur cet item
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = SMETI_db::$code;
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$item;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
echo 'Chargement des données'.PHP_EOL;
|
||||||
|
$counter = 0;
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/10_NOMCMP.json"), true);
|
||||||
|
$nb_shipments = count($shipments);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
progressBar($counter, $nb_shipments);
|
||||||
|
if (5000 == $counter++) break;
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
|
||||||
|
// A-t-on changé de collectivité ?
|
||||||
|
if ($element['collcod'] != $pile_code[$pile_index-1])
|
||||||
|
{
|
||||||
|
// chercher la collectivité
|
||||||
|
$n = count($coll);
|
||||||
|
for($i=0;$i<$n;$i++)
|
||||||
|
if ($element['collcod'] == $coll[$i][0])
|
||||||
|
break;
|
||||||
|
if ($i == $n) continue;
|
||||||
|
// Revenir au niveau 'plugin' de la pile
|
||||||
|
$pile_index -= 2;
|
||||||
|
|
||||||
|
// Ajout d'un lien (symbolique)
|
||||||
|
SMETI_db::$link = 1;
|
||||||
|
SMETI_db::$item = $coll[$i][1];
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Ajout d'un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
|
||||||
|
// Conserver ce noeud dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['collcod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
|
||||||
|
// Rajouter un élément vide dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-t-on changé de Catégorie de famille ?
|
||||||
|
if ($element['mpcacod'] != $pile_code[$pile_index])
|
||||||
|
{
|
||||||
|
// Dépiler
|
||||||
|
$pile_index -= 1;
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = 'MPCA'.$pile_code[$pile_index].$element['mpcacod'];
|
||||||
|
SMETI_db::$libelle = $element['mpnclib'];
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
// Rajouter un lien
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Rajouter un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
// Empiler
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['mpcacod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
}
|
||||||
|
if ($element['mpnccod'] == "") continue;
|
||||||
|
|
||||||
|
// Rajouter la famille
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = $element['mpnccod'];
|
||||||
|
SMETI_db::$libelle = $element['mpnclib'];
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
// Rajouter un lien
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Rajouter un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlever la barre de progression
|
||||||
|
clearLine();
|
||||||
|
// Enlever la barre de progression
|
||||||
|
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
?>
|
||||||
107
bin/import_10_programmes.php
Normal file
107
bin/import_10_programmes.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('smeti_db.inc.php');
|
||||||
|
|
||||||
|
SMETI_db::init();
|
||||||
|
|
||||||
|
echo 'Chargement collectivités ';
|
||||||
|
$sql = SMETI_db::$pdo->prepare("SELECT code, item, libelle FROM v_items WHERE plugin = ( SELECT id FROM plugins WHERE libelle = 'Collectivités' )");
|
||||||
|
$sql->execute();
|
||||||
|
$coll = $sql->fetchAll(PDO::FETCH_NUM);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$libelle = 'Programmes';
|
||||||
|
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'PROG';
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
// Ajouter un lien sur cet item
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = SMETI_db::$code;
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$item;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
echo 'Chargement des données'.PHP_EOL;
|
||||||
|
$counter = 0;
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/07_PROGRAMMES.json"), true);
|
||||||
|
$nb_shipments = count($shipments);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
progressBar($counter, $nb_shipments);
|
||||||
|
if (5000 == $counter++) break;
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
|
||||||
|
// A-t-on changé de collectivité ?
|
||||||
|
if ($element['collcod'] != $pile_code[$pile_index])
|
||||||
|
{
|
||||||
|
// chercher la collectivité
|
||||||
|
$n = count($coll);
|
||||||
|
for($i=0;$i<$n;$i++)
|
||||||
|
if ($element['collcod'] == $coll[$i][0])
|
||||||
|
break;
|
||||||
|
if ($i == $n) continue;
|
||||||
|
// Revenir au niveau 'plugin' de la pile
|
||||||
|
$pile_index -= 1;
|
||||||
|
|
||||||
|
// Ajout d'un lien (symbolique)
|
||||||
|
SMETI_db::$link = 1;
|
||||||
|
SMETI_db::$item = $coll[$i][1];
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Ajout d'un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
|
||||||
|
// Conserver ce noeud dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['collcod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rajouter le programme
|
||||||
|
SMETI_db::$code = $element['prognum'];
|
||||||
|
SMETI_db::$libelle = $element['proglib'];
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
// Rajouter un lien
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Rajouter un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlever la barre de progression
|
||||||
|
clearLine();
|
||||||
|
// Enlever la barre de progression
|
||||||
|
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
?>
|
||||||
6
bin/init_db.sh
Executable file
6
bin/init_db.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
rm -f ../data/$1
|
||||||
|
sqlite3 ../data/$1 < ../data/SQL/init.sql
|
||||||
|
for script in import_??_*.php
|
||||||
|
do
|
||||||
|
php $script ../data/$1
|
||||||
|
done
|
||||||
110
bin/smeti_db.inc.php
Normal file
110
bin/smeti_db.inc.php
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
function clearLine()
|
||||||
|
{
|
||||||
|
echo "\033[2K\r";
|
||||||
|
}
|
||||||
|
|
||||||
|
function replaceOut($str)
|
||||||
|
{
|
||||||
|
$numNewLines = substr_count($str, "\n");
|
||||||
|
echo chr(27) . "[0G"; // Set cursor to first column
|
||||||
|
echo $str;
|
||||||
|
echo chr(27) . "[" . $numNewLines ."A"; // Set cursor up x lines
|
||||||
|
}
|
||||||
|
|
||||||
|
function progressBar($n, $m)
|
||||||
|
{
|
||||||
|
static $maxsize = 80;
|
||||||
|
static $linesize = 0;
|
||||||
|
static $even = 0;
|
||||||
|
|
||||||
|
if (0 == ($linesize % $maxsize))
|
||||||
|
{
|
||||||
|
$even = 1 - $even;
|
||||||
|
$linesize = 0;
|
||||||
|
echo chr(27) . "[0G";
|
||||||
|
printf('[ %010d / %010d ] ', $n, $m);
|
||||||
|
}
|
||||||
|
|
||||||
|
$linesize += 1;
|
||||||
|
|
||||||
|
if ($even == 1) echo '.';
|
||||||
|
else echo 'X';
|
||||||
|
}
|
||||||
|
|
||||||
|
class SMETI_db
|
||||||
|
{
|
||||||
|
static $plugin = 0;
|
||||||
|
static $libelle = '';
|
||||||
|
static $item = 0;
|
||||||
|
static $code = '';
|
||||||
|
static $link = 0;
|
||||||
|
static $child = 0;
|
||||||
|
static $parent = 0;
|
||||||
|
static $rank = 0;
|
||||||
|
|
||||||
|
static $pdo;
|
||||||
|
static $req0;
|
||||||
|
static $req1;
|
||||||
|
static $req2;
|
||||||
|
static $req3;
|
||||||
|
|
||||||
|
static function init($pdo_cn_string = 'sqlite:../data/base.sqlite')
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
self::$pdo = new PDO($pdo_cn_string);
|
||||||
|
self::$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||||
|
self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // ERRMODE_WARNING | ERRMODE_EXCEPTION | ERRMODE_SILENT
|
||||||
|
} catch(Exception $e) {
|
||||||
|
echo "Impossible d'accéder à la base de données SQLite : ".$e->getMessage();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
self::$req0 = self::$pdo->prepare('INSERT INTO plugins(libelle) VALUES(:libelle)');
|
||||||
|
self::$req0->bindParam('libelle', self::$libelle, PDO::PARAM_STR);
|
||||||
|
|
||||||
|
self::$req1 = self::$pdo->prepare('INSERT INTO items(plugin, code, libelle) VALUES(:plugin, :code, :libelle)');
|
||||||
|
self::$req1->bindParam('plugin', self::$plugin, PDO::PARAM_INT);
|
||||||
|
self::$req1->bindParam('code', self::$code, PDO::PARAM_STR);
|
||||||
|
self::$req1->bindParam('libelle', self::$libelle, PDO::PARAM_STR);
|
||||||
|
|
||||||
|
self::$req2 = self::$pdo->prepare('INSERT INTO links(link, item) VALUES(:link, :item)');
|
||||||
|
self::$req2->bindParam('link', self::$link, PDO::PARAM_INT);
|
||||||
|
self::$req2->bindParam('item', self::$item, PDO::PARAM_INT);
|
||||||
|
|
||||||
|
self::$req3 = self::$pdo->prepare('INSERT INTO nodes(child, parent, rank) VALUES(:child, :parent, :rank)');
|
||||||
|
self::$req3->bindParam('child', self::$child, PDO::PARAM_INT);
|
||||||
|
self::$req3->bindParam('parent', self::$parent, PDO::PARAM_INT);
|
||||||
|
self::$req3->bindParam('rank', self::$rank, PDO::PARAM_INT);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function removePlugin($plugin_name)
|
||||||
|
{
|
||||||
|
$select_clause="SELECT id FROM plugins WHERE libelle = '$plugin_name'";
|
||||||
|
// Parce que je n'ai pas réussi à faire correctement marcher le DELETE CASCADE !
|
||||||
|
self::$pdo->exec("DELETE FROM nodes WHERE parent IN (SELECT DISTINCT id FROM items WHERE plugin IN ( $select_clause ))");
|
||||||
|
self::$pdo->exec("DELETE FROM nodes WHERE child IN (SELECT DISTINCT id FROM items WHERE plugin IN ( $select_clause ))");
|
||||||
|
self::$pdo->exec("DELETE FROM links WHERE item IN (SELECT DISTINCT id FROM items WHERE plugin IN ( $select_clause ))");
|
||||||
|
self::$pdo->exec("DELETE FROM links WHERE link = 1 AND id IN ( SELECT id FROM v_items_tree WHERE parent IS NULL)");
|
||||||
|
self::$pdo->exec("DELETE FROM items WHERE plugin IN ( $select_clause)");
|
||||||
|
self::$pdo->exec("DELETE FROM plugins WHERE libelle = '$plugin_name' ");
|
||||||
|
// Parce que je n'ai pas réussi à faire correctement marcher le DELETE CASCADE !
|
||||||
|
self::$pdo->exec('VACUUM');
|
||||||
|
}
|
||||||
|
|
||||||
|
static function addPlugin($plugin_name)
|
||||||
|
{
|
||||||
|
self::$libelle = $plugin_name;
|
||||||
|
self::$req0->execute();
|
||||||
|
self::$plugin = self::$pdo->lastInsertId();
|
||||||
|
}
|
||||||
|
|
||||||
|
static function setCurPlugin($plugin_name)
|
||||||
|
{
|
||||||
|
$sql = self::$pdo->prepare("SELECT id FROM plugins WHERE libelle = '$plugin_name'");
|
||||||
|
$sql->execute();
|
||||||
|
$row = $sql->fetch(PDO::FETCH_NUM);
|
||||||
|
self::$plugin = $row[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
47
css/carets.css
Normal file
47
css/carets.css
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
.ul_no_list {
|
||||||
|
list-style-type: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.caret {
|
||||||
|
cursor: pointer;
|
||||||
|
-webkit-user-select: none; /* Safari 3.1+ */
|
||||||
|
-moz-user-select: none; /* Firefox 2+ */
|
||||||
|
-ms-user-select: none; /* IE 10+ */
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.caret::before {
|
||||||
|
content: "\25B6";
|
||||||
|
color: black;
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.caret-down::before {
|
||||||
|
-ms-transform: rotate(90deg); /* IE 9 */
|
||||||
|
-webkit-transform: rotate(90deg); /* Safari */'
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.caret_gris {
|
||||||
|
cursor: pointer;
|
||||||
|
-webkit-user-select: none; /* Safari 3.1+ */
|
||||||
|
-moz-user-select: none; /* Firefox 2+ */
|
||||||
|
-ms-user-select: none; /* IE 10+ */
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.caret_gris::before {
|
||||||
|
content: "\25B6";
|
||||||
|
color: grey;
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nested {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
102
css/niveaux.css
Normal file
102
css/niveaux.css
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
.niveau_0 {
|
||||||
|
background-color: #c0392b;
|
||||||
|
font-weight: bold;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_1 {
|
||||||
|
background-color: #e74c3c ;
|
||||||
|
font-weight: normal;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_2 {
|
||||||
|
background-color: #9b59b6;
|
||||||
|
font-weight: normal;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_3 {
|
||||||
|
background-color: #8e44ad;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_4 {
|
||||||
|
background-color: #2980b9;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_5 {
|
||||||
|
background-color: #3498DB;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_6 {
|
||||||
|
background-color: #1ABC9C;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_7 {
|
||||||
|
background-color: #16A085;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_8 {
|
||||||
|
background-color: #27AE60;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_9 {
|
||||||
|
background-color: #2ECC71;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_10 {
|
||||||
|
background-color: #F1C40F;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_11 {
|
||||||
|
background-color: #F39C12;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_12 {
|
||||||
|
background-color: #E67E22;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_13 {
|
||||||
|
background-color: #D35400;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_14 {
|
||||||
|
background-color: #ECF0F1;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_15 {
|
||||||
|
background-color: #BDC3C7;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_16 {
|
||||||
|
background-color: #95A5A6;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_20 {
|
||||||
|
background-color: #7F8C8D;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_21 {
|
||||||
|
background-color: #34495E;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_22 {
|
||||||
|
background-color: #2C3E50;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
35
scripts/main.js
Normal file
35
scripts/main.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
var styles = [ 'niveau_10', 'niveau_9', 'niveau_5', 'niveau_19'];
|
||||||
|
|
||||||
|
$( document ).ready(function() {
|
||||||
|
|
||||||
|
$.getJSON( "api/get.php", function( data ) {
|
||||||
|
|
||||||
|
var div = document.getElementById('TREE');
|
||||||
|
var tbl = document.createElement("table");
|
||||||
|
var tblBody = document.createElement("tbody");
|
||||||
|
|
||||||
|
data.forEach(function(element){
|
||||||
|
var tr = document.createElement('tr');
|
||||||
|
var td = null;
|
||||||
|
|
||||||
|
td = document.createElement('td');
|
||||||
|
td.appendChild(document.createTextNode(element.code));
|
||||||
|
tr.appendChild(td);
|
||||||
|
|
||||||
|
td = document.createElement('td');
|
||||||
|
td.appendChild(document.createTextNode(element.name));
|
||||||
|
tr.appendChild(td);
|
||||||
|
|
||||||
|
tr.setAttribute('class',styles[element.level % styles.length]);
|
||||||
|
tblBody.appendChild(tr);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
tbl.appendChild(tblBody);
|
||||||
|
|
||||||
|
div.appendChild(tbl);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
Reference in New Issue
Block a user