Subversion Repositories Applications.gtt

Rev

Rev 121 | Rev 127 | 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 {
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
	}
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());
37 jpm 70
			$this->chargerActionGenerique(&$tab_info_url['tab_actions']);
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
			//header('Pragma: public');
86
			//header('Expires: 0');
87
			//header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
88
			//header('Cache-Control: private', false);
89
    		switch ($this->url_sortie) {
90
    			case 'html' :
91
    				echo $sortie;
92
    				break;
93
    			case 'csv' :
94
					header('Content-Disposition: inline' );
95
					header('Content-Type: text/plain');
96
					header('Content-Length: '.strlen($sortie));
97
    				echo $sortie;
98
    				break;
99
    			case 'csvt' :
100
					header('Content-Type: text/csv');
101
					header('Content-Disposition: attachment; filename="'.str_replace(' ', '_', $this->getRegistre()->getTitre()).'.csv";' );
102
					header('Content-Length: '.strlen($sortie));
103
    				echo $sortie;
104
    				break;
105
    		}
106
    		exit();
11 jpm 107
    	} else {
108
    		$m = "Le fichier $fichier_action contenant l'action est introuvable!";
109
    		trigger_error($m, E_USER_ERROR);
10 jpm 110
    	}
111
    }
37 jpm 112
 
11 jpm 113
    public function rendre()
10 jpm 114
    {
11 jpm 115
    	$contenu_principal = null;
73 jpm 116
    	$aso_contenu = array('zone_contenu' => '', 'zone_menu' => '', 'zone_identification' => '', 'zone_calendrier' => '');
11 jpm 117
    	foreach ($this->getRegistre()->getEspaces() as $espace_de_nom) {
37 jpm 118
    		if (is_array($this->getRegistre()->getDonnees($espace_de_nom))) {
121 jpm 119
    			$squelette = $espace_de_nom;
120
    			if (false != $this->getRegistre()->getSquelettes($espace_de_nom)) {
121
    				$squelette = $this->getRegistre()->getSquelettes($espace_de_nom);
122
    			}
123
    			$fichier_squelette = GTT_CHEMIN_PRESENTATION.$squelette.'.tpl.'.$this->url_format;
124 jpm 124
    			$squelette_erreur = $fichier_squelette;
37 jpm 125
    			if (file_exists($fichier_squelette)) {
124 jpm 126
		    		$bool_squelette_erreur = false;
37 jpm 127
		    		ob_start();
128
		    		extract($GLOBALS['_GTT_']['i18n']['general'], EXTR_PREFIX_ALL, 'i18n_general');
129
		    		extract($this->getRegistre()->getDonnees($espace_de_nom));
130
					include_once $fichier_squelette;
124 jpm 131
					if ($this->url_format == 'html') {
132
						// Répartition dans des zones
133
						switch($espace_de_nom) {
134
			    			case 'principal' :
135
			    				$contenu_principal .= ob_get_contents();
136
			    				break;
137
			    			case 'zone_calendrier' :
138
			    				$aso_contenu['zone_calendrier'] .= ob_get_contents();
139
			    				break;
140
			    			case 'identification' :
141
			    				$aso_contenu['zone_identification'] .= ob_get_contents();
142
			    				break;
143
			    			case 'zone_menu' :
144
			    				$aso_contenu['zone_menu'] .= ob_get_contents();
145
			    				break;
146
			    			default:
147
			    				$aso_contenu['zone_contenu'] .= ob_get_contents();
148
			    		}
149
					} else {
150
						$contenu_principal = ob_get_contents();
151
					}
37 jpm 152
		    		ob_end_clean();
153
    			}
11 jpm 154
    		}
10 jpm 155
    	}
124 jpm 156
    	if ($bool_squelette_erreur) {
157
    		trigger_error("Absence du fichier de squelette : $squelette_erreur", E_USER_ERROR);
158
 		}
11 jpm 159
    	if (!is_null($contenu_principal)) {
160
    		return $contenu_principal;
161
    	}
162
    	return $aso_contenu;
10 jpm 163
    }
164
}
165
?>