Subversion Repositories Applications.gtt

Rev

Rev 121 | Rev 127 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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