Subversion Repositories Applications.gtt

Rev

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