173 lines
5.7 KiB
PHP
173 lines
5.7 KiB
PHP
|
<?php
|
||
|
|
||
|
class ArborescenceController extends Libs_Controller
|
||
|
{
|
||
|
public function init()
|
||
|
{
|
||
|
/* Initialize action controller here */
|
||
|
}
|
||
|
|
||
|
public function indexAction()
|
||
|
{
|
||
|
// action body
|
||
|
}
|
||
|
|
||
|
public function nafAction()
|
||
|
{
|
||
|
$this->_helper->layout()->disableLayout();
|
||
|
$request = $this->getRequest();
|
||
|
$key = $request->getParam('key');
|
||
|
$object = new Object_Naf();
|
||
|
|
||
|
//Récupération des valeurs enregistrées en session
|
||
|
|
||
|
$this->view->key = $key;
|
||
|
$this->view->naf = $object->naf($request->getParam('niveau', 1), $key);
|
||
|
}
|
||
|
|
||
|
public function nafajaxAction()
|
||
|
{
|
||
|
$this->_helper->layout()->disableLayout();
|
||
|
$this->_helper->viewRenderer->setNoRender();
|
||
|
|
||
|
$request = $this->getRequest();
|
||
|
$key = $request->getParam('key');
|
||
|
$object = new Object_Naf();
|
||
|
|
||
|
echo $object->ajax($request->getParam('parent', ''),
|
||
|
$request->getParam('niveau', 1),
|
||
|
$request->getParam('key')
|
||
|
);
|
||
|
}
|
||
|
|
||
|
public function geographiqueAction()
|
||
|
{
|
||
|
$this->_helper->layout()->disableLayout();
|
||
|
$object = new Object_Codepostaux();
|
||
|
$key = $this->getRequest()->getParam('key');
|
||
|
$this->view->assign('key', $key);
|
||
|
$this->view->regions = $object->geographique();
|
||
|
}
|
||
|
|
||
|
public function geographiqueajaxAction()
|
||
|
{
|
||
|
$this->_helper->layout()->disableLayout();
|
||
|
$this->_helper->viewRenderer->setNoRender();
|
||
|
|
||
|
$request = $this->getRequest();
|
||
|
$key = $request->getParam('key');
|
||
|
$id = $request->getParam('id');
|
||
|
|
||
|
if($id[0] == 'R') {
|
||
|
require_once 'Scores/SessionCiblage.php';
|
||
|
$session = new SessionCiblage();
|
||
|
$val = $session->getCritere('adr_cp');
|
||
|
$valuesCheckeds = array();
|
||
|
$valuesUndetermined = array();
|
||
|
|
||
|
if($val != null)
|
||
|
{
|
||
|
$values = explode(',', $val);
|
||
|
foreach($values as $valuesChecked) {
|
||
|
if(strlen($valuesChecked) == 5) {
|
||
|
$valuesUndetermined[] = substr($valuesChecked, 0, 2);
|
||
|
}
|
||
|
if(substr($valuesChecked, 0, 1) == 'D') {
|
||
|
$valuesCheckeds[] = substr($valuesChecked, 1);
|
||
|
} else if (substr($valuesChecked, 0, 1) == 'R') {
|
||
|
$table = new Table_Departements();
|
||
|
$sql = $table->select()->from('departements', array('numdep'))->where('codeRegionInsee = ?', substr($valuesChecked, 1));
|
||
|
$result = $table->fetchAll($sql)->toArray();
|
||
|
foreach($result as $item) {
|
||
|
$valuesCheckeds[] = $item['numdep'];
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$region = substr($request->getParam('id'), 1);
|
||
|
$deps = new Table_Departements();
|
||
|
$sql = $deps->select()
|
||
|
->from('departements')
|
||
|
->where('codeRegionInsee = ?', $region);
|
||
|
$departements = $deps->fetchAll($sql)->toArray();
|
||
|
foreach($departements as $departement) {
|
||
|
$structure = array(
|
||
|
'data' => $departement['libdep'],
|
||
|
'attr' => array('id' => 'D'.$departement['numdep'], 'niveau' => 1),
|
||
|
'state' => 'closed',
|
||
|
'children' => array()
|
||
|
);
|
||
|
if(in_array($departement['numdep'], $valuesCheckeds)) {
|
||
|
$structure['attr']['class'] = 'jstree-checked';
|
||
|
}
|
||
|
if(in_array($departement['numdep'], $valuesUndetermined)) {
|
||
|
$structure['attr']['class'] = 'jstree-undetermined';
|
||
|
}
|
||
|
$departementTab[] = $structure;
|
||
|
}
|
||
|
echo json_encode($departementTab);
|
||
|
} else if ($id[0] == 'D')
|
||
|
{
|
||
|
require_once 'Scores/SessionCiblage.php';
|
||
|
$session = new SessionCiblage();
|
||
|
$val = $session->getCritere('adr_cp');
|
||
|
$valuesCheckeds = array();
|
||
|
if($val != null)
|
||
|
{
|
||
|
$values = explode(',', $val);
|
||
|
foreach($values as $valuesChecked) {
|
||
|
if(strlen($valuesChecked) == 5) {
|
||
|
$valuesCheckeds[] = $valuesChecked;
|
||
|
}
|
||
|
else if(substr($valuesChecked, 0, 1) == 'D') {
|
||
|
$table = new Table_Codepostauxs();
|
||
|
$sql = $table->select()->from('codepostaux', array('Codepos'))->where('Codepos LIKE "'.substr($valuesChecked, 1).'%"');
|
||
|
$results = $table->fetchAll($sql)->toArray();
|
||
|
foreach($results as $result) {
|
||
|
if(!in_array($result['Codepos'], $values))
|
||
|
$valuesCheckeds[] = $result['Codepos'];
|
||
|
}
|
||
|
} else if (substr($valuesChecked, 0, 1) == 'R') {
|
||
|
$Departements = new Table_Departements();
|
||
|
$sql = $Departements->select()->from('departements', array('numdep'))->where('codeRegionInsee = ?', substr($valuesChecked, 1));
|
||
|
$results = $Departements->fetchAll($sql)->toArray();
|
||
|
foreach($results as $result) {
|
||
|
$table = new Table_Codepostauxs();
|
||
|
$sql = $table->select()->from('codepostaux', array('Codepos'))->where('Codepos LIKE "'.$result['numdep'].'%"');
|
||
|
$codes = $table->fetchAll($sql)->toArray();
|
||
|
foreach($codes as $code) {
|
||
|
if(!in_array($result['Codepos'], $values))
|
||
|
$valuesCheckeds[] = $code['Codepos'];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$numdep = substr($request->getParam('id'), 1);
|
||
|
$code = new Table_Codepostauxs();
|
||
|
$sql = $code->select()
|
||
|
->from('codepostaux')
|
||
|
->where('Codepos LIKE "'.$numdep.'%"');
|
||
|
$codePostaux = $code->fetchAll($sql)->toArray();
|
||
|
|
||
|
foreach($codePostaux as $codePostau) {
|
||
|
$structure = array(
|
||
|
'data' => '[ '.$codePostau['Codepos'].' ]'.ucfirst(strtolower($codePostau['Commune'])),
|
||
|
'attr' => array('id' => $codePostau['Codepos'], 'niveau' => 2)
|
||
|
);
|
||
|
if(in_array($codePostau['Codepos'], $valuesCheckeds)) {
|
||
|
$structure['attr']['class'] = 'jstree-checked';
|
||
|
}
|
||
|
$CodePostauxTab[] = $structure;
|
||
|
}
|
||
|
echo json_encode($CodePostauxTab);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|