Subversion Repositories Applications.gtt

Rev

Rev 10 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 jpm 1
<?php
2
 
11 jpm 3
class ControlleurFrontal {
10 jpm 4
 
11 jpm 5
	public function getRegistre()
6
	{
7
		return Registre::getRegistre();
8
	}
9
 
10
	public function parserAction($url)
10 jpm 11
    {
11 jpm 12
    	if (preg_match('/^(.+?)(?:_(.+)|)$/', $url, $match)) {
13
	    	$retour['classe_action'] = 'GttCtrlAction'.ucfirst($match[1]);
10 jpm 14
    	}
15
 
11 jpm 16
    	$retour['tab_actions'] = array('');
10 jpm 17
    	if (isset($match[2])) {
18
    		preg_match_all('/(.+)(?:_|$)/', $match[2], $match_actions);
11 jpm 19
    		$retour['tab_actions'] = $match_actions[1];
10 jpm 20
    	}
11 jpm 21
		return $retour;
22
    }
23
 
24
	public function executer($url_action)
25
    {
26
    	$tab_info_url = $this->parserAction($url_action);
27
    	//echo '<pre>'.print_r($tab_info_url, true).'</pre>';
28
    	$classe_action = $tab_info_url['classe_action'];
29
    	$fichier_action = GTT_CHEMIN_ACTION.$classe_action.'.class.php';
10 jpm 30
    	if (file_exists($fichier_action)) {
31
			require_once $fichier_action;
11 jpm 32
			$Action = new $classe_action($this->getRegistre());
33
			foreach ($tab_info_url['tab_actions'] as $action) {
10 jpm 34
				// Vérification des données POST ou GET avant l'appel de l'action
35
				if (isset($_POST) || isset($_GET)) {
11 jpm 36
					$Action->verifier();
10 jpm 37
					$methode_verif = 'verifier'.ucfirst($action);
38
					if (method_exists($Action, $methode_verif)) {
39
						// Méthode "vérifier" spécifique à une action
11 jpm 40
						$Action->$methode_verif();
10 jpm 41
					}
42
				}
43
				// Execution de l'action
44
				$Action->setSuivant(ucfirst($action));
45
			}
46
			$Action->demarrer();
11 jpm 47
			$aso_principal['principal'] = $this->rendre();
48
			//echo '<pre>'.print_r($aso_principal, true).'</pre>';
49
			$Resultats = $this->getRegistre();
10 jpm 50
			$aso_principal['principal']['titre'] = $Resultats->getTitre();
51
			$Resultats->setEspaces(array());
52
			$Resultats->setSquelettes(array());
53
			$Resultats->setDonnees(array());
54
			$Resultats->ajouterEspace('Principal', 'principal');
55
    		$Resultats->ajouterSquelette('principal', 'principal.tpl.html');
56
    		$Resultats->ajouterDonnee('principal', $aso_principal['principal']);
11 jpm 57
    		return $this->rendre();
58
    	} else {
59
    		$m = "Le fichier $fichier_action contenant l'action est introuvable!";
60
    		trigger_error($m, E_USER_ERROR);
10 jpm 61
    	}
62
    }
63
 
11 jpm 64
    public function rendre()
10 jpm 65
    {
11 jpm 66
    	$contenu_principal = null;
67
    	$aso_contenu = array('zone_contenu' => '', 'zone_identification' => '');
68
    	foreach ($this->getRegistre()->getEspaces() as $espace_de_nom) {
10 jpm 69
    		ob_start();
70
    		extract($GLOBALS['_GTT_']['i18n']['general'], EXTR_PREFIX_ALL, 'i18n_general');
11 jpm 71
    		extract($this->getRegistre()->getDonnees($espace_de_nom));
72
			include_once GTT_CHEMIN_PRESENTATION.$this->getRegistre()->getSquelettes($espace_de_nom);
73
			// Répartition dans des zones
74
			switch($espace_de_nom) {
75
    			case 'principal' :
76
    				$contenu_principal .= ob_get_contents();
77
    				break;
78
    			case 'identification' :
79
    				$aso_contenu['zone_identification'] .= ob_get_contents();
80
    				break;
81
    			default:
82
    				$aso_contenu['zone_contenu'] .= ob_get_contents();
83
    		}
84
    		ob_end_clean();
10 jpm 85
    	}
11 jpm 86
    	if (!is_null($contenu_principal)) {
87
    		return $contenu_principal;
88
    	}
89
    	return $aso_contenu;
10 jpm 90
    }
91
}
92
?>