2 /* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3 and is published under the AGPL license. */
5 class IdxController extends Zend_Controller_Action
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/closebtn.js');
14 $this->view->headScript()->appendFile('js/highlight.js');
15 $this->view->headScript()->appendFile('js/deck.js');
16 $this->view->headScript()->appendFile('js/ajaxize.js');
17 $this->view->headScript()->appendFile('js/message.js');
18 $this->view->headScript()->appendFile('js/syj.js');
19 $this->view->headLink()->appendStylesheet('css/openlayers/style.css');
20 $this->view->headLink()->appendStylesheet('css/generic.css');
21 $this->view->headLink()->appendStylesheet('css/syj.css');
24 public function indexAction() {
25 $url = $this->getRequest()->getUserParam('url');
27 $geomform = new Syj_Form_Geom(array('name' => 'geomform', 'action' => 'path'));
28 $loginform = new Syj_Form_Login(array('name' => 'loginform', 'action' => 'login'));
29 $userform = new Syj_Form_User(array('name' => 'userform', 'action' => 'user'));
30 $newpwdform = new Syj_Form_Newpwd(array('name' => 'newpwdform', 'action' => 'newpwd'));
33 $pathMapper = new Syj_Model_PathMapper();
34 $path = new Syj_Model_Path();
35 if (!$pathMapper->findByUrl($url, $path)) {
36 if (is_numeric($url) and $pathMapper->hasexisted($url)) {
37 throw new Syj_Exception_NotFound('Gone', 410);
39 throw new Syj_Exception_NotFound('Not Found', 404);
42 $title = $path->displayTitle;
43 $this->view->path = $path;
44 $geomform->geom_title->setValue($path->title);
45 $geomform->geom_data->setValue((string)$path->geom);
46 $geomform->geom_id->setValue((string)$path->id);
47 $loginform->login_geom_id->setValue((string)$path->id);
49 $extent = new phptojs\JsObject('gMaxExtent', $this->_helper->syjGeoip($this->getRequest()->getClientIp(true)));
50 $this->view->headScript()->prependScript((string) $extent);
51 $title = "Show your journey";
54 $this->_jsLoggedInfo(isset($url) ? $path: null);
55 $this->_jsLocaleStrings();
56 $this->view->headTitle($title);
57 $this->view->geomform = $geomform;
58 $this->view->loginform = $loginform;
59 $this->view->userform = $userform;
60 $this->view->newpwdform = $newpwdform;
63 protected function _jsLoggedInfo(Syj_Model_Path $path = null) {
64 $loggedinfo = new phptojs\JsObject('gLoggedInfo', array('connections' => 0));
66 $sessionStorage = Zend_Auth::getInstance()->getStorage();
67 $sessionData = $sessionStorage->read();
69 if ($sessionStorage->isEmpty()) {
70 $loggedinfo->logged = false;
72 $userMapper = new Syj_Model_UserMapper();
73 $obj = new Syj_Model_User();
74 if ($userMapper->find($sessionData['user'], $obj)) {
75 $loggedinfo->logged = true;
78 Zend_Session::start();
79 Zend_Session::destroy();
80 $loggedinfo->logged = false;
85 if ($path->owner->id == $sessionData['user']) {
86 $loggedinfo->isowner = true;
88 $loggedinfo->isowner = false;
90 $loggedinfo->ownername = $this->view->escape((string)$path->owner->pseudo);
92 $loggedinfo->isowner = true;
95 $this->view->headScript()->prependScript((string) $loggedinfo);
98 protected function _jsLocaleStrings() {
99 $this->view->jslocales = array(
100 'saveSuccess' => __("save took place successfully"),
101 'requestError' => __("server did not understood request. That's probably caused by a bug in SYJ"),
102 'UnreferencedError' => __("path did not exist in the server. May be it has been already deleted"),
103 'uniquePathError' => __("similar path seems to already exist. Please do not create two exactly identical paths"),
104 'notReachedError' => __("server could not be reached"),
105 'serverError' => __("there was a server error"),
106 'unknownError' => __("there was an unknown error"),
107 'userEmptyWarn' => __("you must enter a login name"),
108 'loginSuccess' => __("Login correct"),
109 'loginFailure' => __("Wrong login/password"),
110 'loginNeeded' => __("You need to login before retrying to save"),
111 'cookiesNeeded' => __("You need to have cookies enabled to login to SYJ"),
112 'passwordEmptyWarn' => __("you must enter a password"),
113 'passwordNoMatchWarn' => __("Password do not match"),
114 'acceptTermsofuseWarn' => __("You must accept terms of use"),
115 'emailEmptyWarn' => __("you must enter an email"),
116 'emailInvalidWarn' => __("invalid email"),
117 'invalidPseudo' => __("pseudo must only contain letters, digits, dots or underscores"),
118 'uniqueUserError' => __("unavailable pseudo"),
119 'uniqueEmailError' => __("an user is already registered with this email"),
120 'userSuccess' => __("Account created"),
121 'newpwdSuccess' => __("A link to reset your password has been emailed to you"),
122 'canResubmit' => __("Now, you can retry to save"),
123 'routeBy' => __("route by"),
124 'osmAttribution' => __("Map by <a href='http://openstreetmap.org/'>OpenStreetMap</a>")