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