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/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');
20 public function indexAction() {
21 $url = $this->getRequest()->getUserParam('url');
23 $geomform = new Syj_Form_Geom(array('name' => 'geomform', 'action' => 'path'));
24 $loginform = new Syj_Form_Login(array('name' => 'loginform', 'action' => 'login'));
25 $userform = new Syj_Form_User(array('name' => 'userform', 'action' => 'user'));
26 $newpwdform = new Syj_Form_Newpwd(array('name' => 'newpwdform', 'action' => 'newpwd'));
29 $pathMapper = new Syj_Model_PathMapper();
30 $path = new Syj_Model_Path();
31 if (!$pathMapper->findByUrl($url, $path)) {
32 if (is_numeric($url) and $pathMapper->hasexisted($url)) {
33 throw new Syj_Exception_NotFound('Gone', 410);
35 throw new Syj_Exception_NotFound('Not Found', 404);
38 $title = $path->displayTitle;
39 $this->view->path = $path;
40 $geomform->geom_title->setValue($path->title);
41 $geomform->geom_data->setValue((string)$path->geom);
42 $geomform->geom_id->setValue((string)$path->id);
43 $loginform->login_geom_id->setValue((string)$path->id);
45 $extent = new phptojs\JsObject('gMaxExtent', $this->_helper->syjGeoip($this->getRequest()->getClientIp(true)));
46 $this->view->headScript()->prependScript((string) $extent);
47 $title = "Show your journey";
50 $this->_jsLoggedInfo(isset($url) ? $path: null);
51 $this->_jsLocaleStrings();
52 $this->view->headTitle($title);
53 $this->view->geomform = $geomform;
54 $this->view->loginform = $loginform;
55 $this->view->userform = $userform;
56 $this->view->newpwdform = $newpwdform;
59 protected function _jsLoggedInfo(Syj_Model_Path $path = null) {
60 $loggedinfo = new phptojs\JsObject('gLoggedInfo', array('connections' => 0));
62 $sessionStorage = Zend_Auth::getInstance()->getStorage();
63 $sessionData = $sessionStorage->read();
65 if ($sessionStorage->isEmpty()) {
66 $loggedinfo->logged = false;
68 $userMapper = new Syj_Model_UserMapper();
69 $obj = new Syj_Model_User();
70 if ($userMapper->find($sessionData['user'], $obj)) {
71 $loggedinfo->logged = true;
74 Zend_Session::start();
75 Zend_Session::destroy();
76 $loggedinfo->logged = false;
81 if ($path->owner->id == $sessionData['user']) {
82 $loggedinfo->isowner = true;
84 $loggedinfo->isowner = false;
86 $loggedinfo->ownername = $this->view->escape((string)$path->owner->pseudo);
88 $loggedinfo->isowner = true;
91 $this->view->headScript()->prependScript((string) $loggedinfo);
94 protected function _jsLocaleStrings() {
95 $this->view->jslocales = array(
96 'saveSuccess' => __("save took place successfully"),
97 'requestError' => __("server did not understood request. That's probably caused by a bug in SYJ"),
98 'UnreferencedError' => __("path did not exist in the server. May be it has been already deleted"),
99 'uniquePathError' => __("similar path seems to already exist. Please do not create two exactly identical paths"),
100 'notReachedError' => __("server could not be reached"),
101 'serverError' => __("there was a server error"),
102 'unknownError' => __("there was an unknown error"),
103 'userEmptyWarn' => __("you must enter a login name"),
104 'loginSuccess' => __("Login correct"),
105 'loginFailure' => __("Wrong login/password"),
106 'loginNeeded' => __("You need to login before retrying to save"),
107 'cookiesNeeded' => __("You need to have cookies enabled to login to SYJ"),
108 'passwordEmptyWarn' => __("you must enter a password"),
109 'passwordNoMatchWarn' => __("Password do not match"),
110 'acceptTermsofuseWarn' => __("You must accept terms of use"),
111 'emailEmptyWarn' => __("you must enter an email"),
112 'emailInvalidWarn' => __("invalid email"),
113 'invalidPseudo' => __("pseudo must only contain letters, digits, dots or underscores"),
114 'uniqueUserError' => __("unavailable pseudo"),
115 'uniqueEmailError' => __("an user is already registered with this email"),
116 'userSuccess' => __("Account created"),
117 'newpwdSuccess' => __("A link to reset your password has been emailed to you"),
118 'canResubmit' => __("Now, you can retry to save"),
119 'routeBy' => __("route by"),
120 'osmAttribution' => __("Map by <a href='http://openstreetmap.org/'>OpenStreetMap</a>")