Subversion Repositories Applications.gtt

Rev

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

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