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