]> dev.renevier.net Git - syj.git/blob - application/controllers/IdxController.php
raw mode to display map
[syj.git] / application / controllers / IdxController.php
1 <?php
2 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3     and is published under the AGPL license. */
4
5 class IdxController extends Zend_Controller_Action
6 {
7
8     public function init() {
9         $this->view->headScript()->appendFile('js/OpenLayers.js');
10         $this->view->headScript()->appendFile('js/ModifiablePath.js');
11         $this->view->headScript()->appendFile('js/prototype.js');
12         $this->view->headScript()->appendFile('js/simplebox.js');
13         $this->view->headScript()->appendFile('js/utils.js');
14         $this->view->headScript()->appendFile('js/syj.js');
15         $this->view->headLink()->appendStylesheet('css/openlayers/style.css');
16         $this->view->headLink()->appendStylesheet('css/generic.css');
17         $this->view->headLink()->appendStylesheet('css/syj.css');
18     }
19
20     public function rawmode(Syj_Model_Path $path) {
21         $this->_helper->SyjReset->resetPlaceHolders();
22
23         $this->view->headLink()->appendStylesheet('css/generic.css');
24         $this->view->headLink()->appendStylesheet('css/syjraw.css');
25         $this->view->headScript()->appendFile('js/OpenLayers.js');
26         $this->view->headScript()->appendFile('js/syjraw.js');
27         $this->view->headTitle($path->displayTitle);
28
29         $this->_jsRawLocaleStrings();
30         if ($path->creator) {
31             $this->view->jslocales['geomAttribution'] =
32                         $this->view->translate('route by <strong>%s</strong>', (string)$path->creator->pseudo);
33         }
34         $jsgeom = new phptojs\JsObject('gInitialGeom', array('data' => (string) $path->geom));
35         $this->view->headScript()->prependScript((string) $jsgeom);
36
37         $this->view->rawmode = true;
38         $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/raw.:suffix');
39     }
40
41     public function indexAction() {
42         $url = $this->getRequest()->getUserParam('url');
43
44         $geomform = new Syj_Form_Geom(array('name' => 'geomform'));
45         $loginform = new Syj_Form_Login(array('name' => 'loginform', 'action' => 'login'));
46         $userform = new Syj_Form_User(array('name' => 'userform', 'action' => 'user'));
47         $newpwdform = new Syj_Form_Newpwd(array('name' => 'newpwdform', 'action' => 'newpwd'));
48
49         if (isset($url)) {
50             $pathMapper = new Syj_Model_PathMapper();
51             $path = new Syj_Model_Path();
52             if (!$pathMapper->findByUrl($url, $path)) {
53                 if (is_numeric($url) and $pathMapper->hasexisted($url)) {
54                     throw new Syj_Exception_NotFound('Gone', 410);
55                 } else {
56                     throw new Syj_Exception_NotFound('Not Found', 404);
57                 }
58             }
59
60             if ($this->getRequest()->getQuery('format') == 'raw') {
61                 $this->rawmode($path);
62                 return;
63             }
64
65             $title = $path->displayTitle;
66             $this->view->path = $path;
67             $jsgeom = new phptojs\JsObject('gInitialGeom', array('data' => (string) $path->geom));
68             $this->view->headScript()->prependScript((string) $jsgeom);
69             $loginform->login_geom_id->setValue((string)$path->id);
70             $geomform->geom_title->setValue($path->title);
71         } else {
72             $geomform->setAction('path');
73             $extent = new phptojs\JsObject('gMaxExtent', $this->_helper->syjGeoip($this->getRequest()->getClientIp(true)));
74             $this->view->headScript()->prependScript((string) $extent);
75             $title = "Show your journey";
76         }
77
78         $this->_jsLoggedInfo(isset($url) ? $path: null);
79         $this->_jsLocaleStrings();
80         if (isset ($url) and $path->creator) {
81             $this->view->jslocales['geomAttribution'] =
82                         $this->view->translate('route by <strong>%s</strong>', (string)$path->creator->pseudo);
83         }
84         $this->view->headTitle($title);
85         $this->view->geomform = $geomform;
86         $this->view->loginform = $loginform;
87         $this->view->userform = $userform;
88         $this->view->newpwdform = $newpwdform;
89         $this->view->loggedUser = $this->_helper->SyjSession->user();
90     }
91
92     protected function _jsLoggedInfo(Syj_Model_Path $path = null) {
93         $loggedinfo = new phptojs\JsObject('gLoggedInfo', array('connections' => 0));
94
95         $user = $this->_helper->SyjSession->user();
96         if ($user) {
97             $loggedinfo->logged = true;
98         } else {
99             $loggedinfo->logged = false;
100         }
101
102         if (isset($path)) {
103             $loggedinfo->iscreator = $path->isCreator($user);
104             $loggedinfo->pathid = (string)$path->id;
105         } else {
106             $loggedinfo->iscreator = true;
107         }
108
109         $this->view->headScript()->prependScript((string) $loggedinfo);
110     }
111
112     protected function _jsRawLocaleStrings() {
113         $this->view->jslocales = array(
114             'osmAttribution' => __("Map by <a href='http://openstreetmap.org/'>OpenStreetMap</a>"),
115             );
116     }
117
118     protected function _jsLocaleStrings() {
119         $this->view->jslocales = array(
120             'saveSuccess' => __("save took place successfully"),
121             'requestError' => __("server did not understood request. That's probably caused by a bug in SYJ"),
122             'gonePathError' => __("route not referenced on the server. It has probably been deleted."),
123             'uniquePathError' => __("similar path seems to already exist. Please do not create two exactly identical paths"),
124             'notReachedError' => __("server could not be reached"),
125             'serverError' => __("there was a server error"),
126             'unknownError' => __("there was an unknown error"),
127             'userEmptyWarn' => __("you must enter a login name"),
128             'loginSuccess' => __("Login correct"),
129             'loginFailure' => __("Wrong login/password"),
130             'passwordEmptyWarn' => __("you must enter a password"),
131             'passwordNoMatchWarn' => __("Password do not match"),
132             'acceptTermsofuseWarn' => __("You must accept terms of use"),
133             'emailEmptyWarn' => __("you must enter an email"),
134             'emailInvalidWarn' => __("invalid email"),
135             'uniqueEmailError' => __("an user is already registered with this email"),
136             'userSuccess' => __("Account created"),
137             'newpwdSuccess' => __("A link to reset your password has been emailed to you"),
138             'canResubmit' => __("Now, you can retry to save"),
139             'routeBy' => __("route by"),
140             'osmAttribution' => __("Map by <a href='http://openstreetmap.org/'>OpenStreetMap</a>"),
141             'pseudoChecking' => __("checking availibilty"),
142             'availablePseudo' => __("available pseudo"),
143             'unavailablePseudo' => __("unavailable pseudo"),
144             'editAction' => __("edit"),
145             'createAction' => __("create"),
146             'cloneAction' => __("duplicate"),
147             'unsavedConfirmExit' => __("You have an unsaved route"),
148             );
149     }
150
151 }