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