Subversion Repositories Applications.gtt

Rev

Rev 127 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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