Subversion Repositories Applications.gtt

Rev

Rev 147 | 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 {
37 jpm 4
 
121 jpm 5
	private $url_action;
6
	private $url_format;
124 jpm 7
	private $url_sortie;
121 jpm 8
 
124 jpm 9
	public function __construct($action, $format, $sortie)
121 jpm 10
	{
11
		$this->url_action = $action;
12
		$this->url_format = $format;
124 jpm 13
		$this->url_sortie = $sortie;
121 jpm 14
	}
154 jpm 15
 
11 jpm 16
	public function getRegistre()
17
	{
18
		return Registre::getRegistre();
19
	}
37 jpm 20
 
11 jpm 21
	public function parserAction($url)
10 jpm 22
    {
11 jpm 23
    	if (preg_match('/^(.+?)(?:_(.+)|)$/', $url, $match)) {
37 jpm 24
    		$aso_compo_classe = explode('-', $match[1]);
25
    		$retour['classe_action'] = 'GttCtrlAction';
26
    		foreach ($aso_compo_classe as $mot) {
27
	    		$retour['classe_action'] .= ucfirst($mot);
28
    		}
10 jpm 29
    	}
37 jpm 30
 
31
    	$retour['tab_actions'] = array('__defaut__');
10 jpm 32
    	if (isset($match[2])) {
33
    		preg_match_all('/(.+)(?:_|$)/', $match[2], $match_actions);
37 jpm 34
    		//echo '<pre>'.print_r($match_actions[1], true).'</pre>';
35
    		foreach ($match_actions[1] as $action) {
36
				$aso_compo_action = explode('-', $action);
37
				$action = '';
38
				foreach ($aso_compo_action as $mot_action) {
39
    				$action .= ucfirst($mot_action);
40
				}
41
				$retour['tab_actions'][] = $action;
42
    		}
10 jpm 43
    	}
11 jpm 44
		return $retour;
45
    }
46
 
37 jpm 47
	private function chargerActionGenerique(&$tab_actions)
48
    {
49
    	// Gestion de l'identification
50
    	$GttCtrlActionIdentification = new GttCtrlActionIdentification($this->getRegistre());
51
    	$GttCtrlActionIdentification->setSuivant('__defaut__');
52
   		array_unshift($tab_actions, $GttCtrlActionIdentification);
53
 
54
    	// Gestion des menus
55
    	$GttCtrlActionMenu = new GttCtrlActionMenu($this->getRegistre());
56
    	$GttCtrlActionMenu->setSuivant('__defaut__');
57
    	$tab_actions[] = $GttCtrlActionMenu;
58
    }
59
 
60
 
121 jpm 61
	public function executer()
11 jpm 62
    {
121 jpm 63
    	$tab_info_url = $this->parserAction($this->url_action);
64
    	//trigger_error(print_r($tab_info_url, true), E_USER_NOTICE);
11 jpm 65
    	$classe_action = $tab_info_url['classe_action'];
66
    	$fichier_action = GTT_CHEMIN_ACTION.$classe_action.'.class.php';
10 jpm 67
    	if (file_exists($fichier_action)) {
68
			require_once $fichier_action;
11 jpm 69
			$Action = new $classe_action($this->getRegistre());
154 jpm 70
			$this->chargerActionGenerique($tab_info_url['tab_actions']);
37 jpm 71
			$Action->setSuivant($tab_info_url['tab_actions']);
10 jpm 72
			$Action->demarrer();
124 jpm 73
			if ($this->url_format == 'html') {
74
				$aso_principal['principal'] = $this->rendre();
75
				//echo '<pre>'.print_r($aso_principal, true).'</pre>';
76
				$aso_principal['principal']['titre'] = $this->getRegistre()->getTitre();
77
				$this->getRegistre()->setEspaces(array());
78
				$this->getRegistre()->setDonnees(array());
79
				$this->getRegistre()->ajouterEspace('Principal', 'principal');
80
    			$this->getRegistre()->ajouterDonnee('principal', $aso_principal['principal']);
81
			}
82
    		$sortie = $this->rendre();
83
 
84
			// Gestion de la sortie
85
    		switch ($this->url_sortie) {
86
    			case 'html' :
87
    				echo $sortie;
88
    				break;
89
    			case 'csv' :
90
					header('Content-Disposition: inline' );
91
					header('Content-Type: text/plain');
92
					header('Content-Length: '.strlen($sortie));
93
    				echo $sortie;
94
    				break;
95
    			case 'csvt' :
96
					header('Content-Type: text/csv');
97
					header('Content-Disposition: attachment; filename="'.str_replace(' ', '_', $this->getRegistre()->getTitre()).'.csv";' );
98
					header('Content-Length: '.strlen($sortie));
99
    				echo $sortie;
100
    				break;
101
    		}
102
    		exit();
11 jpm 103
    	} else {
104
    		$m = "Le fichier $fichier_action contenant l'action est introuvable!";
105
    		trigger_error($m, E_USER_ERROR);
10 jpm 106
    	}
107
    }
37 jpm 108
 
11 jpm 109
    public function rendre()
10 jpm 110
    {
11 jpm 111
    	$contenu_principal = null;
73 jpm 112
    	$aso_contenu = array('zone_contenu' => '', 'zone_menu' => '', 'zone_identification' => '', 'zone_calendrier' => '');
11 jpm 113
    	foreach ($this->getRegistre()->getEspaces() as $espace_de_nom) {
37 jpm 114
    		if (is_array($this->getRegistre()->getDonnees($espace_de_nom))) {
121 jpm 115
    			$squelette = $espace_de_nom;
116
    			if (false != $this->getRegistre()->getSquelettes($espace_de_nom)) {
117
    				$squelette = $this->getRegistre()->getSquelettes($espace_de_nom);
118
    			}
119
    			$fichier_squelette = GTT_CHEMIN_PRESENTATION.$squelette.'.tpl.'.$this->url_format;
124 jpm 120
    			$squelette_erreur = $fichier_squelette;
37 jpm 121
    			if (file_exists($fichier_squelette)) {
124 jpm 122
		    		$bool_squelette_erreur = false;
37 jpm 123
		    		ob_start();
124
		    		extract($GLOBALS['_GTT_']['i18n']['general'], EXTR_PREFIX_ALL, 'i18n_general');
125
		    		extract($this->getRegistre()->getDonnees($espace_de_nom));
126
					include_once $fichier_squelette;
124 jpm 127
					if ($this->url_format == 'html') {
128
						// Répartition dans des zones
129
						switch($espace_de_nom) {
130
			    			case 'principal' :
131
			    				$contenu_principal .= ob_get_contents();
132
			    				break;
133
			    			case 'zone_calendrier' :
134
			    				$aso_contenu['zone_calendrier'] .= ob_get_contents();
135
			    				break;
136
			    			case 'identification' :
137
			    				$aso_contenu['zone_identification'] .= ob_get_contents();
138
			    				break;
139
			    			case 'zone_menu' :
140
			    				$aso_contenu['zone_menu'] .= ob_get_contents();
141
			    				break;
142
			    			default:
143
			    				$aso_contenu['zone_contenu'] .= ob_get_contents();
144
			    		}
145
					} else {
146
						$contenu_principal = ob_get_contents();
147
					}
37 jpm 148
		    		ob_end_clean();
149
    			}
11 jpm 150
    		}
10 jpm 151
    	}
124 jpm 152
    	if ($bool_squelette_erreur) {
153
    		trigger_error("Absence du fichier de squelette : $squelette_erreur", E_USER_ERROR);
154
 		}
11 jpm 155
    	if (!is_null($contenu_principal)) {
156
    		return $contenu_principal;
157
    	}
158
    	return $aso_contenu;
10 jpm 159
    }
160
}
161
?>