/**
  * Called when a user has been removed : delete rights about this user
  *
  * @param jEvent $event   the event
  */
 function onAuthRemoveUser($event)
 {
     if (jApp::config()->acl2['driver'] == 'db') {
         $login = $event->getParam('login');
         jAcl2DbUserGroup::removeUser($login);
     }
 }
Exemplo n.º 2
0
 /**
  * Called when a user has been removed : delete rights about this user
  *
  * @param jEvent $event   the event
  */
 function onAuthRemoveUser($event)
 {
     if ($GLOBALS['gJConfig']->acl2['driver'] == 'db') {
         $login = $event->getParam('login');
         jAcl2DbUserGroup::removeUser($login);
     }
 }
Exemplo n.º 3
0
 protected function _prepareTpl()
 {
     jClasses::inc('masterAdminMenuItem');
     $menu = array();
     $menu['toplinks'] = new masterAdminMenuItem('toplinks', '', '');
     $dashboard = new masterAdminMenuItem('dashboard', jLocale::get('gui.menu.item.dashboard'), jUrl::get('default:index'));
     $dashboard->icon = $GLOBALS['gJConfig']->urlengine['jelixWWWPath'] . 'design/images/dashboard.png';
     $menu['toplinks']->childItems[] = $dashboard;
     $menu['system'] = new masterAdminMenuItem('system', jLocale::get('gui.menu.item.system'), '', 100);
     $items = jEvent::notify('masteradminGetMenuContent')->getResponse();
     foreach ($items as $item) {
         if ($item->parentId) {
             if (!isset($menu[$item->parentId])) {
                 $menu[$item->parentId] = new masterAdminMenuItem($item->parentId, '', '');
             }
             $menu[$item->parentId]->childItems[] = $item;
         } else {
             if (isset($menu[$item->id])) {
                 $menu[$item->id]->copyFrom($item);
             } else {
                 $menu[$item->id] = $item;
             }
         }
     }
     usort($menu, "masterAdminItemSort");
     foreach ($menu as $topitem) {
         usort($topitem->childItems, "masterAdminItemSort");
     }
     $this->_tpl->assign('menuitems', $menu);
     $this->_tpl->assign('selectedMenuItem', $this->param('selectedMenuItem', ''));
 }
Exemplo n.º 4
0
 protected function _prepareTpl()
 {
     $this->_tpl->assignIfNone('foo', 'bar');
     $widgets = jEvent::notify('masterAdminGetDashboardWidget')->getResponse();
     usort($widgets, 'masterAdminDashboardWidgetSort');
     $this->_tpl->assign('widgets', $widgets);
 }
 /**
  * Displays a list of project for a given repository.
  *
  * @param string $repository. Name of the repository.
  * @return Html page with a list of projects.
  */
 function index()
 {
     if ($this->param('theme')) {
         jApp::config()->theme = $this->param('theme');
     }
     $rep = $this->getResponse('html');
     // Get lizmap services
     $services = lizmap::getServices();
     // only maps
     if ($services->onlyMaps) {
         $repository = lizmap::getRepository($services->defaultRepository);
         if ($repository && jAcl2::check('lizmap.repositories.view', $repository->getKey())) {
             $project = lizmap::getProject($repository->getKey() . '~' . $services->defaultProject);
             if ($project) {
                 // test redirection to an other controller
                 $items = jEvent::notify('mainviewGetMaps')->getResponse();
                 foreach ($items as $item) {
                     if ($item->parentId == $repository->getKey() && $item->id == $services->defaultProject) {
                         $rep = $this->getResponse('redirectUrl');
                         $rep->url = $item->url;
                         return $rep;
                     }
                 }
                 // redirection to default controller
                 $rep = $this->getResponse('redirect');
                 $rep->action = 'view~map:index';
                 return $rep;
             }
         }
     }
     // Get repository data
     $repository = $this->param('repository');
     $repositoryList = array();
     if ($repository) {
         if (!jAcl2::check('lizmap.repositories.view', $repository)) {
             $rep = $this->getResponse('redirect');
             $rep->action = 'view~default:index';
             jMessage::add(jLocale::get('view~default.repository.access.denied'), 'error');
             return $rep;
         }
     }
     $title = jLocale::get("view~default.repository.list.title");
     $rep->body->assign('repositoryLabel', $title);
     $rep->body->assign('isConnected', jAuth::isConnected());
     $rep->body->assign('user', jAuth::getUserSession());
     if ($services->allowUserAccountRequests) {
         $rep->body->assign('allowUserAccountRequests', True);
     }
     if ($repository) {
         $lrep = lizmap::getRepository($repository);
         $title .= ' - ' . $lrep->getData('label');
     }
     $rep->title = $title;
     $rep->body->assignZone('MAIN', 'main_view', array('repository' => $repository));
     $rep->addJSCode("\n      \$(window).load(function() {\n        \$('.liz-project-img').parent().mouseenter(function(){\n          var self = \$(this);\n          self.find('.liz-project-desc').slideDown();\n          self.css('cursor','pointer');\n        }).mouseleave(function(){\n          var self = \$(this);\n          self.find('.liz-project-desc').hide();\n        }).click(function(){\n          var self = \$(this);\n          window.location = self.parent().find('a.liz-project-view').attr('href');\n          return false;\n        });\n      });\n      ");
     // Js hack to normalize the height of the project thumbnails to avoid line breaks with long project titles
     $bp = jApp::config()->urlengine['basePath'];
     $rep->addJSLink($bp . 'js/view.js');
     return $rep;
 }
Exemplo n.º 6
0
 /**
  * function to manage data before assigning to the template of its zone
  */
 protected function _prepareTpl()
 {
     jClasses::inc('havefnubb~hfnuMenuItem');
     $admin = jAcl2::check('hfnu.admin.index');
     $menu = array();
     $items = jEvent::notify('hfnuGetMenuContent', array('admin' => $admin))->getResponse();
     foreach ($items as $item) {
         if ($item->parentId) {
             if (!isset($menu[$item->parentId])) {
                 $menu[$item->parentId] = new hfnuMenuItem($item->parentId, '', '');
             }
             $menu[$item->parentId]->childItems[] = $item;
         } else {
             if (isset($menu[$item->id])) {
                 $menu[$item->id]->copyFrom($item);
             } else {
                 $menu[$item->id] = $item;
             }
         }
     }
     usort($menu, "hfnuItemSort");
     foreach ($menu as $topitem) {
         usort($topitem->childItems, "hfnuItemSort");
     }
     $this->_tpl->assign('menuitems', $menu);
     $this->_tpl->assign('selectedMenuItem', $this->param('selectedMenuItem', ''));
 }
 protected function _prepareTpl()
 {
     jClasses::inc('masterAdminMenuItem');
     $items = jEvent::notify('masteradminGetInfoBoxContent')->getResponse();
     usort($items, "masterAdminItemSort");
     $this->_tpl->assign('infoboxitems', $items);
     $this->_tpl->assign('user', jAuth::getUserSession());
 }
Exemplo n.º 8
0
 protected function _prepareTpl()
 {
     $this->_tpl->assignIfNone('foo', 'bar');
     $widgets = jEvent::notify('masterAdminGetDashboardWidget')->getResponse();
     usort($widgets, function ($itemA, $itemB) {
         return $itemA->order - $itemB->order;
     });
     $this->_tpl->assign('widgets', $widgets);
 }
Exemplo n.º 9
0
/**
 * hook plugin :  
 *
 * @param jTpl $tpl template engine
 * @param string $event the event name to call
 * @param array $params parameters to give to the listener
 */
function jtpl_function_html_hook($tpl, $event, $params = array())
{
    if ($event == '') {
        return;
    }
    $events = jEvent::notify($event, $params)->getResponse();
    foreach ($events as $event) {
        echo $event;
    }
}
Exemplo n.º 10
0
 protected function _prepareTpl()
 {
     $form = jForms::get('registration');
     if ($form == null) {
         $form = jForms::create('registration');
     }
     jForms::destroy('confirmation');
     jEvent::notify('jcommunity_registration_init_form', array('form' => $form, 'tpl' => $this->_tpl));
     $this->_tpl->assign('form', $form);
 }
Exemplo n.º 11
0
 function testEvents()
 {
     $response = jEvent::notify('TestEvent');
     $response = $response->getResponse();
     $response = serialize($response[0]);
     $temoin = serialize(array('module' => 'jelix_tests', 'ok' => true));
     $this->assertTrue($temoin == $response, 'évenement simple');
     $temoin = array('hello' => 'world');
     $response = jEvent::notify('TestEventWithParams', $temoin);
     $response = $response->getResponse();
     $this->assertTrue($response[0]['params'] == 'world', 'évenement avec paramètres');
 }
Exemplo n.º 12
0
 /**
  * function to manage data before assigning to the template of its zone
  */
 protected function _prepareTpl()
 {
     $srvinfos = jClasses::getService("servinfo~serverinfos");
     list($records, $size) = $srvinfos->dbSize();
     $this->_tpl->assign('LOADS_AVG', $srvinfos->loadsAvg());
     $this->_tpl->assign('CACHE_ENGINE', $srvinfos->cacheEngine());
     $this->_tpl->assign('PHP_VERSION', phpversion());
     $this->_tpl->assign('PHP_OS', PHP_OS);
     $this->_tpl->assign('DB_VERSION', $srvinfos->dbVersion());
     $this->_tpl->assign('DB_SIZE', $size);
     $this->_tpl->assign('DB_RECORDS', $records);
     $this->_tpl->assign('otherInfos', jEvent::notify('servinfoGetInfo')->getResponse());
 }
Exemplo n.º 13
0
 /**
  * Search in forums
  * @param string $string the request to search
  * @param integer $id_forum the id forum in which to make the request
  * @return recordset
  */
 function searchInForums($string, $id_forum, $page = 0, $limit)
 {
     $eventresp = jEvent::notify('HfnuSearchEngineRun', array('string' => $string, 'page' => $page, 'limit' => $limit, 'id_forum' => $id_forum));
     $result = array('datas' => array(), 'total' => 0);
     foreach ($eventresp->getResponse() as $rep) {
         if (!isset($rep['SearchEngineResult'])) {
             $result['datas'] = array();
             $result['total'] = 0;
         } else {
             $result['datas'][] = (array) $rep['SearchEngineResult'];
             $result['total'] = (int) $rep['SearchEngineResultTotal'];
         }
     }
     return $result;
 }
Exemplo n.º 14
0
 protected function _prepareTpl()
 {
     jClasses::inc('masterAdminMenuItem');
     $menu = array();
     $menu['toplinks'] = new masterAdminMenuItem('toplinks', '', '');
     if (!isset(jApp::config()->master_admin['disable_dashboard_menu']) || !jApp::config()->master_admin['disable_dashboard_menu']) {
         $dashboard = new masterAdminMenuItem('dashboard', jLocale::get('gui.menu.item.dashboard'), jUrl::get('default:index'));
         $dashboard->icon = jApp::config()->urlengine['jelixWWWPath'] . 'design/images/dashboard.png';
         $menu['toplinks']->childItems[] = $dashboard;
     }
     $menu['refdata'] = new masterAdminMenuItem('refdata', jLocale::get('gui.menu.item.refdata'), '', 80);
     $menu['system'] = new masterAdminMenuItem('system', jLocale::get('gui.menu.item.system'), '', 100);
     $items = jEvent::notify('masteradminGetMenuContent')->getResponse();
     foreach ($items as $item) {
         if ($item->parentId) {
             if (!isset($menu[$item->parentId])) {
                 $menu[$item->parentId] = new masterAdminMenuItem($item->parentId, '', '');
             }
             $isRedefining = false;
             foreach ($menu[$item->parentId]->childItems as $child) {
                 if ($child->id == $item->id) {
                     $child->copyFrom($item);
                     $isRedefining = true;
                     break;
                 }
             }
             if (!$isRedefining) {
                 $menu[$item->parentId]->childItems[] = $item;
             }
         } else {
             if (isset($menu[$item->id])) {
                 $menu[$item->id]->copyFrom($item);
             } else {
                 $menu[$item->id] = $item;
             }
         }
     }
     usort($menu, "masterAdminItemSort");
     foreach ($menu as $topitem) {
         usort($topitem->childItems, "masterAdminItemSort");
     }
     $this->_tpl->assign('menuitems', $menu);
     $this->_tpl->assign('selectedMenuItem', $this->param('selectedMenuItem', ''));
 }
 /**
  * Delete Feature (output as html fragment)
  *
  * @param string $repository Lizmap Repository
  * @param string $project Name of the project
  * @param string $layerId Qgis id of the layer
  * @param integer $featureId Id of the feature.
  * @return Redirect to the validation action.
  */
 public function deleteFeature()
 {
     if (!$this->getEditionParameters()) {
         return $this->serviceAnswer();
     }
     // Get editLayer capabilities
     $eLayers = $this->project->getEditionLayers();
     $layerName = $this->layerName;
     $eLayer = $eLayers->{$layerName};
     if ($eLayer->capabilities->deleteFeature != 'True') {
         jMessage::add('Delete feature for this layer is not in the capabilities!', 'LayerNotEditable');
         return $this->serviceAnswer();
     }
     $featureId = $this->param('featureId');
     if (!$featureId) {
         jMessage::add('The featureId is mandatory !', 'error');
         return $this->serviceAnswer();
     }
     // Get fields data from the edition database
     $layerXmlZero = $this->layerXml[0];
     $_datasource = $layerXmlZero->xpath('datasource');
     $datasource = (string) $_datasource[0];
     $s_provider = $layerXmlZero->xpath('provider');
     $this->provider = (string) $s_provider[0];
     $this->getDataFields($datasource);
     $cnx = jDb::getConnection($this->layerId);
     if (ctype_digit($this->featureId)) {
         $featureId = array($this->featureId);
     }
     // featureId is set
     // SQL for deleting on line in the edition table
     $sql = " DELETE FROM " . $this->table;
     $v = '';
     $i = 0;
     $sql .= ' WHERE';
     foreach ($this->primaryKeys as $key) {
         $sql .= $v . ' "' . $key . '" = ' . $featureId[$i];
         $i++;
         $v = " AND ";
     }
     // Add login filter if needed
     if (!$this->loginFilteredOveride) {
         $this->filterDataByLogin($this->layerName);
         if (is_array($this->loginFilteredLayers)) {
             $sql .= ' AND ' . $this->loginFilteredLayers['where'];
         }
     }
     try {
         $rs = $cnx->query($sql);
         jMessage::add(jLocale::get('view~edition.message.success.delete'), 'success');
         // Log
         $eventParams = array('key' => 'editionDeleteFeature', 'content' => "table=" . $this->tableName . ", id=" . $this->featureId, 'repository' => $this->repository->getKey(), 'project' => $this->project->getKey());
         jEvent::notify('LizLogItem', $eventParams);
     } catch (Exception $e) {
         jLog::log("SQL = " . $sql);
         jLog::log("An error has been raised when saving form data edition to db : " . $e->getMessage(), 'error');
         jMessage::add(jLocale::get('view~edition.message.success.delete'), 'error');
     }
     return $this->serviceAnswer();
 }
Exemplo n.º 16
0
 /**
  * GetPrint
  * @param string $repository Lizmap Repository
  * @param string $project Name of the project : mandatory
  * @return Image rendered by the Map Server.
  */
 function GetPrint()
 {
     /*
         foreach($this->params as $key=>$val){
      print $key. "=>". $val."\n";
         }
     */
     // Get parameters
     if (!$this->getServiceParameters()) {
         return $this->serviceException();
     }
     $url = $this->services->wmsServerURL . '?';
     /*
     $bparams = http_build_query($this->params);
     // replace some chars (not needed in php 5.4, use the 4th parameter of http_build_query)
     $a = array('+', '_', '.', '-');
     $b = array('%20', '%5F', '%2E', '%2D');
     $bparams = str_replace($a, $b, $bparams);
     $querystring = $url . $bparams;
     */
     // Filter the parameters of the request
     // for querying GetPrint
     $data = array();
     $paramsBlacklist = array('module', 'action', 'C', 'repository', 'project');
     foreach ($this->params as $key => $val) {
         if (!in_array($key, $paramsBlacklist)) {
             $data[] = strtolower($key) . '=' . urlencode($val);
         }
     }
     $querystring = $url . implode('&', $data);
     // Get remote data from cache
     /*
         $getRemoteData = $this->lizmapCache->getRemoteData(
      $querystring,
      $this->services->proxyMethod,
      $this->services->debugMode
         );
         $data = $getRemoteData[0];
         $mime = $getRemoteData[1];
     */
     // Get data form server
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_URL, $querystring);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     $data = curl_exec($ch);
     $info = curl_getinfo($ch);
     $mime = $info['content_type'];
     curl_close($ch);
     $rep = $this->getResponse('binary');
     $rep->mimeType = $mime;
     $rep->content = $data;
     $rep->doDownload = false;
     $rep->outputFileName = 'getPrint';
     // Log
     $logContent = '
  <a href="' . jUrl::get('lizmap~service:index', jApp::coord()->request->params) . '" target="_blank">' . $this->params['template'] . '<a>
  ';
     $eventParams = array('key' => 'print', 'content' => $logContent, 'repository' => $this->repository->getKey(), 'project' => $this->project->getKey());
     jEvent::notify('LizLogItem', $eventParams);
     return $rep;
 }
Exemplo n.º 17
0
 /**
  * save data of a form in a new record
  */
 function saveupdate()
 {
     $rep = $this->getResponse('redirect');
     $id = $this->param('id');
     $form = jForms::get($this->form, $id);
     $form->initFromRequest();
     if ($form === null || $id === null) {
         $rep->action = 'master_admin~default:index';
         return $rep;
     }
     $evresp = array();
     if ($form->check() && !jEvent::notify('jauthdbAdminCheckUpdateForm', array('form' => $form))->inResponse('check', false, $evresp)) {
         extract($form->prepareDaoFromControls($this->dao, $id, $this->dbProfile), EXTR_PREFIX_ALL, "form");
         // we call jAuth instead of using jDao, to allow jAuth to do
         // all process, events...
         jAuth::updateUser($form_daorec);
         $form->saveAllFiles($this->uploadsDirectory);
         $rep->action = 'user:index';
         jMessage::add(jLocale::get('crud.message.update.ok', $id), 'notice');
         jForms::destroy($this->form, $id);
     } else {
         $rep->action = 'user:editupdate';
     }
     $rep->params['id'] = $id;
     return $rep;
 }
Exemplo n.º 18
0
 /**
  * activate an account. the key should be given as a parameter
  */
 function confirm()
 {
     if (jAuth::isConnected()) {
         return $this->noaccess();
     }
     $rep = $this->getResponse("redirect");
     $rep->action = "registration:confirmform";
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         return $rep;
     }
     $form = jForms::fill('confirmation');
     if ($form == null) {
         return $rep;
     }
     if (!$form->check()) {
         return $rep;
     }
     $login = $form->getData('conf_login');
     $user = jAuth::getUser($login);
     if (!$user) {
         $form->setErrorOn('conf_login', jLocale::get('register.form.confirm.login.doesnt.exist'));
         return $rep;
     }
     if ($user->status != JCOMMUNITY_STATUS_NEW) {
         jForms::destroy('confirmation');
         $rep = $this->getResponse('html');
         $tpl = new jTpl();
         $tpl->assign('already', true);
         $rep->body->assign('MAIN', $tpl->fetch('registration_ok'));
         return $rep;
     }
     if ($form->getData('conf_key') != $user->keyactivate) {
         $form->setErrorOn('conf_key', jLocale::get('register.form.confirm.bad.key'));
         return $rep;
     }
     $user->status = JCOMMUNITY_STATUS_VALID;
     jEvent::notify('jcommunity_registration_confirm', array('user' => $user));
     jAuth::updateUser($user);
     jAuth::changePassword($login, $form->getData('conf_password'));
     jAuth::login($login, $form->getData('conf_password'));
     jForms::destroy('confirmation');
     $rep->action = "registration:confirmok";
     return $rep;
 }
Exemplo n.º 19
0
 protected function _prepareTpl()
 {
     $protocol = jApp::coord()->request->getProtocol();
     $this->_tpl->assign('protocol', $protocol);
     $domain = jApp::coord()->request->getDomainName();
     $this->_tpl->assign('domain', $domain);
     $this->_tpl->assign('auth_url_return', $this->param('auth_url_return'));
     $this->_tpl->assign('isConnected', jAuth::isConnected());
     // Get lizmap services
     $services = lizmap::getServices();
     if ($services->allowUserAccountRequests) {
         $this->_tpl->assign('allowUserAccountRequests', True);
     }
     jClasses::inc('lizmapMainViewItem');
     $maps = array();
     // Get repository data
     $repository = $this->param('repository');
     $repositories = array();
     if ($repository != null && jAcl2::check('lizmap.repositories.view', $repository)) {
         $repositories[] = $repository;
     } else {
         $repositories = lizmap::getRepositoryList();
     }
     // Get excluded project
     $excludedProject = $this->param('excludedProject');
     foreach ($repositories as $r) {
         if (jAcl2::check('lizmap.repositories.view', $r)) {
             $lrep = lizmap::getRepository($r);
             $mrep = new lizmapMainViewItem($r, $lrep->getData('label'));
             $lprojects = $lrep->getProjects();
             // WMS GetCapabilities Url
             $wmsGetCapabilitiesUrl = jAcl2::check('lizmap.tools.displayGetCapabilitiesLinks', $lrep->getKey());
             foreach ($lprojects as $p) {
                 $pOptions = $p->getOptions();
                 if (property_exists($pOptions, 'hideProject') && $pOptions->hideProject == 'True') {
                     continue;
                 }
                 if ($wmsGetCapabilitiesUrl) {
                     $wmsGetCapabilitiesUrl = $p->getData('wmsGetCapabilitiesUrl');
                 }
                 if ($lrep->getKey() . '~' . $p->getData('id') != $excludedProject) {
                     $mrep->childItems[] = new lizmapMainViewItem($p->getData('id'), $p->getData('title'), $p->getData('abstract'), $p->getData('proj'), $p->getData('bbox'), jUrl::get('view~map:index', array("repository" => $p->getData('repository'), "project" => $p->getData('id'))), jUrl::get('view~media:illustration', array("repository" => $p->getData('repository'), "project" => $p->getData('id'))), 0, $r, 'map', $wmsGetCapabilitiesUrl);
                     /*} else {
                       $this->_tpl->assign('auth_url_return', jUrl::get('view~map:index',
                         array(
                           "repository"=>$lrep->getKey(),
                           "project"=>$p->getData('id'),
                         )
                       ) );*/
                 }
             }
             if (count($mrep->childItems) != 0) {
                 usort($mrep->childItems, "mainViewItemSort");
                 $maps[$r] = $mrep;
             }
         }
     }
     $items = jEvent::notify('mainviewGetMaps')->getResponse();
     foreach ($items as $item) {
         if ($item->parentId) {
             if ($item->parentId . '~' . $item->id == $excludedProject) {
                 continue;
             }
             if (!isset($maps[$item->parentId])) {
                 $maps[$item->parentId] = new lizmapMainViewItem($item->parentId, '', '');
             }
             $replaced = false;
             foreach ($maps[$item->parentId]->childItems as $k => $i) {
                 if ($i->id == $item->id) {
                     $maps[$item->parentId]->childItems[$k] = $item;
                     $replaced = true;
                 }
             }
             if (!$replaced) {
                 $maps[$item->parentId]->childItems[] = $item;
                 usort($maps[$item->parentId]->childItems, "mainViewItemSort");
             }
         } else {
             if (isset($maps[$item->id])) {
                 $maps[$item->id]->copyFrom($item);
             } else {
                 $maps[$item->id] = $item;
             }
         }
     }
     usort($maps, "mainViewItemSort");
     foreach ($maps as $topitem) {
         usort($topitem->childItems, "mainViewItemSort");
     }
     $this->_tpl->assign('mapitems', $maps);
     $this->_tpl->assign('onlyMaps', $this->param('onlyMaps', False));
 }
Exemplo n.º 20
0
 /**
  * for tests
  * @since 1.5
  */
 public static function clearCache()
 {
     self::$hashListened = array();
     self::$listenersSingleton = array();
     unset($GLOBALS['JELIX_EVENTS']);
 }
Exemplo n.º 21
0
 /**
  *
  */
 protected function _otherthings()
 {
     // overlays
     // browser sniffing, because "&" should be escaped in a xul-overlay PI in gecko 1.9+
     $escape = false;
     if (preg_match('!^Mozilla/5.0 \\(.* rv:(\\d)\\.(\\d).*\\) Gecko/\\d+.*$!', $_SERVER["HTTP_USER_AGENT"], $m)) {
         if (version_compare($m[1] . '.' . $m[2], '1.9') >= 0) {
             $escape = true;
         }
     }
     if ($this->fetchOverlays) {
         $sel = new jSelectorTpl($this->bodyTpl);
         $eventresp = jEvent::notify('FetchXulOverlay', array('tpl' => $sel->toString()));
         foreach ($eventresp->getResponse() as $rep) {
             if (is_array($rep)) {
                 $this->_overlays[jUrl::get($rep[0], $rep[1])] = true;
             } elseif (is_string($rep)) {
                 $this->_overlays[jUrl::get($rep)] = true;
             }
         }
     }
     foreach ($this->_overlays as $src => $ok) {
         echo '<?xul-overlay href="', $escape ? htmlspecialchars($src) : $src, '" ?>', "\n";
     }
     $this->rootAttributes['title'] = $this->title;
 }
Exemplo n.º 22
0
 public static function clearLayerCache($repository, $project, $layer)
 {
     // Storage type
     $ser = lizmap::getServices();
     $cacheStorageType = $ser->cacheStorageType;
     // Cache root directory
     if ($cacheStorageType != 'redis') {
         $cacheRootDirectory = $ser->cacheRootDirectory;
         if (!is_writable($cacheRootDirectory) or !is_dir($cacheRootDirectory)) {
             $cacheRootDirectory = sys_get_temp_dir();
         }
         // Directory where cached files are stored for the project
         $cacheProjectDir = $cacheRootDirectory . '/' . $repository . '/' . $project . '/';
         $results = array();
         if (file_exists($cacheProjectDir)) {
             // Open the directory and walk through the filenames
             $handle = opendir($cacheProjectDir);
             while (false !== ($entry = readdir($handle))) {
                 if ($entry != "." && $entry != "..") {
                     // Get directories and files corresponding to the layer
                     if (preg_match('#(^|_)' . $layer . '($|_)#', $entry)) {
                         $results[] = $cacheProjectDir . $entry;
                     }
                 }
             }
             closedir($handle);
             foreach ($results as $rem) {
                 if (is_dir($rem)) {
                     jFile::removeDir($rem);
                 } else {
                     unlink($rem);
                 }
             }
         }
     } else {
         // FIXME: removing by layer is not supported for the moment. For the moment, we flush all layers of the project.
         $cacheName = 'lizmapCache_' . $repository . '_' . $project;
         self::declareRedisProfile($ser, $cacheName, $repository, $project);
         jCache::flush($cacheName);
     }
     jEvent::notify('lizmapProxyClearLayerCache', array('repository' => $repository, 'project' => $project, 'layer' => $layer));
 }
 /**
  * perform a given event
  * @param jEvent $event the event itself
  * @return void
  */
 function performEvent($event)
 {
     $methodName = 'on' . $event->getName();
     $this->{$methodName}($event);
 }
Exemplo n.º 24
0
 /**
  * Save the data for the services section.
  * @return Redirect to the index.
  */
 function saveAccount()
 {
     // Get lizmap services
     $services = lizmap::getServices();
     $rep = $this->getResponse('redirect');
     $rep->action = 'view~default:index';
     // Redirect if option not active
     if (!$services->allowUserAccountRequests) {
         return $rep;
     }
     // Redirect if already a logged user
     if (jAuth::isConnected()) {
         jMessage::add(jLocale::get("view~user.already.logged"));
         return $rep;
     }
     // Get the form
     $form = jForms::get('view~lizmap_user');
     // token
     $token = $this->param('__JFORMS_TOKEN__');
     if (!$token) {
         $rep->action = "view~user:createAccount";
         return $rep;
     }
     // If the form is not defined, redirection
     if (!$form) {
         $rep->action = "view~user:createAccount";
         return $rep;
     }
     // Set the other form data from the request data
     $form->initFromRequest();
     // Check the form
     $ok = true;
     if (!$form->check()) {
         $ok = false;
     }
     // Check the honey pot. Redirect if filled (means robot)
     $honey = $form->getData('name');
     if ($honey and !empty($honey)) {
         $rep->action = "view~user:createAccount";
         return $rep;
     }
     if (!$ok) {
         // Errors : redirection to the display action
         $rep->action = 'view~user:editAccount';
         return $rep;
     }
     // Save the data
     $evresp = array();
     if (!jEvent::notify('jauthdbAdminCheckCreateForm', array('form' => $form))->inResponse('check', false, $evresp)) {
         // Sanitize some fields
         $sanitize = array('login', 'firstname', 'lastname', 'organization', 'phonenumber', 'street', 'postcode', 'city', 'country', 'comment');
         foreach ($sanitize as $field) {
             $form->setData($field, filter_var($form->getData($field), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES));
         }
         // Add user to database via jAuth methods
         try {
             $props = jDao::createRecord('jauthdb~jelixuser', 'jauth')->getProperties();
             $user = jAuth::createUserObject($form->getData('login'), $form->getData('password'));
             $form->setData('password', $user->password);
             $form->prepareObjectFromControls($user, $props);
             jAuth::saveNewUser($user);
             jMessage::add(jLocale::get("view~user.form.message.saved"));
             $ok = true;
             $rep->action = "view~user:validateAccount";
         } catch (exception $e) {
             $ok = false;
             jMessage::add(jLocale::get("view~user.form.message.not.saved"));
             $rep->action = "view~user:editAccount";
         }
         // Send email to the administrator
         if ($ok) {
             try {
                 $this->sendEmailToAdmin($user);
             } catch (Exception $e) {
                 jLog::log('error while sending email to admin: ' . $e->getMessage());
             }
         }
     }
     return $rep;
 }
Exemplo n.º 25
0
 /**
  * Load the map page for the given project.
  * @param string $repository Name of the repository.
  * @param string $project Name of the project.
  * @return Page with map and content for the chose Qgis project.
  */
 function index()
 {
     if ($this->param('theme')) {
         jApp::config()->theme = $this->param('theme');
     }
     $rep = $this->getResponse('htmlmap');
     $rep->addJSLink(jUrl::get('view~translate:index'));
     $ok = true;
     // Get the project
     $project = filter_var($this->param('project'), FILTER_SANITIZE_STRING);
     // Get repository data
     $repository = $this->param('repository');
     // Get lizmapRepository class
     // if repository not found get the default
     $lrep = null;
     $lser = lizmap::getServices();
     if (!$repository) {
         $lrep = lizmap::getRepository($lser->defaultRepository);
         $repository = $lser->defaultRepository;
     } else {
         $lrep = lizmap::getRepository($repository);
     }
     if (!$lrep or !jAcl2::check('lizmap.repositories.view', $lrep->getKey())) {
         $rep = $this->getResponse('redirect');
         $rep->action = 'view~default:index';
         jMessage::add(jLocale::get('view~default.repository.access.denied'), 'error');
         return $rep;
     }
     // We must redirect to default repository project list if no project given
     if (!$project) {
         $lproj = lizmap::getProject($lrep->getKey() . '~' . $lser->defaultProject);
         if (!$lproj) {
             jMessage::add('The parameter project is mandatory !', 'error');
             $ok = false;
         } else {
             $project = $lser->defaultProject;
         }
     }
     // Get lizmapProject class
     if ($ok) {
         $lproj = lizmap::getProject($lrep->getKey() . '~' . $project);
         if (!$lproj) {
             jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'error');
             $ok = false;
         }
     }
     // Redirect if project is hidden (lizmap plugin option)
     if ($ok and !$this->forceHiddenProjectVisible) {
         $pOptions = $lproj->getOptions();
         if (property_exists($pOptions, 'hideProject') && $pOptions->hideProject == 'True') {
             jMessage::add(jLocale::get('view~default.project.access.denied'), 'error');
             $ok = false;
         }
     }
     // Redirect if error encountered
     if (!$ok) {
         $rep = $this->getResponse('redirect');
         $rep->params = array('repository' => $lrep->getKey());
         $rep->action = 'view~default:index';
         return $rep;
     }
     // Add js link if google is needed
     if ($lproj->needsGoogle()) {
         $googleKey = $lproj->getGoogleKey();
         if ($googleKey != '') {
             $rep->addJSLink('https://maps.google.com/maps/api/js?v=3.5&sensor=false&key=' . $googleKey);
         } else {
             $rep->addJSLink('https://maps.google.com/maps/api/js?v=3.5&sensor=false');
         }
     }
     // Add the jForms js
     $bp = jApp::config()->urlengine['basePath'];
     $rep->addJSLink($bp . 'jelix/js/jforms_jquery.js');
     $rep->addJSLink($bp . 'jelix/js/jforms/datepickers/default/init.js');
     $rep->addJSLink($bp . 'jelix/js/jforms/datepickers/default/ui.en.js');
     $rep->addJSLink($bp . 'js/fileUpload/jquery.fileupload.js');
     $rep->addJSLink($bp . 'js/bootstrapErrorDecoratorHtml.js');
     // Add botom dock js
     $rep->addJSLink($bp . 'js/bottom-dock.js');
     // Pass some configuration options to the web page through javascript var
     $lizUrls = array("params" => array('repository' => $repository, 'project' => $project), "config" => jUrl::get('lizmap~service:getProjectConfig'), "wms" => jUrl::get('lizmap~service:index'), "media" => jUrl::get('view~media:getMedia'), "nominatim" => jUrl::get('lizmap~osm:nominatim'), "ign" => jUrl::get('lizmap~ign:address'), "edition" => jUrl::get('lizmap~edition:getFeature'), "permalink" => jUrl::getFull('view~map:index'), "dataTableLanguage" => $bp . 'js/dataTables/' . jApp::config()->locale . '.json', "basepath" => $bp, "geobookmark" => jUrl::get('lizmap~geobookmark:index'));
     // Get optionnal WMS public url list
     $lser = lizmap::getServices();
     if ($lser->wmsPublicUrlList) {
         $publicUrlList = $lser->wmsPublicUrlList;
         function f($x)
         {
             return jUrl::getFull('lizmap~service:index', array(), 0, trim($x));
         }
         $pul = array_map('f', explode(',', $publicUrlList));
         $lizUrls['publicUrlList'] = $pul;
     }
     if (jAcl2::check('lizmap.admin.repositories.delete')) {
         $lizUrls['removeCache'] = jUrl::get('admin~config:removeLayerCache');
     }
     $rep->addJSCode("var lizUrls = " . json_encode($lizUrls) . ";");
     $rep->addJSCode("var lizProj4 = " . json_encode($lproj->getAllProj4()) . ";");
     $rep->addStyle('#map', 'background-color:' . $lproj->getCanvasColor() . ';');
     // Get the WMS information
     $wmsInfo = $lproj->getWMSInformation();
     // Set page title from projet title
     if ($wmsInfo['WMSServiceTitle'] != '') {
         $rep->title = $wmsInfo['WMSServiceTitle'];
     } else {
         $rep->title = $repository . ' - ' . $project;
     }
     // Add date.js for timemanager
     if ($lproj->hasTimemanagerLayers()) {
         $rep->addJSLink($bp . 'js/date.js');
     }
     // Assign variables to template
     $assign = array_merge(array('repositoryLabel' => $lrep->getData('label'), 'repository' => $lrep->getKey(), 'project' => $project, 'onlyMaps' => $lser->onlyMaps), $wmsInfo);
     // WMS GetCapabilities Url
     $wmsGetCapabilitiesUrl = jAcl2::check('lizmap.tools.displayGetCapabilitiesLinks', $lrep->getKey());
     if ($wmsGetCapabilitiesUrl) {
         $wmsGetCapabilitiesUrl = $lproj->getData('wmsGetCapabilitiesUrl');
     }
     $assign['wmsGetCapabilitiesUrl'] = $wmsGetCapabilitiesUrl;
     // Get dockable and minidockable element
     $assign['dockable'] = $lproj->getDefaultDockable();
     $items = jEvent::notify('mapDockable', array('repository' => $repository, 'project' => $project))->getResponse();
     $assign['dockable'] = mapDockItemsMerge($assign['dockable'], $items);
     $assign['minidockable'] = $lproj->getDefaultMiniDockable();
     $items = jEvent::notify('mapMiniDockable', array('repository' => $repository, 'project' => $project))->getResponse();
     $assign['minidockable'] = mapDockItemsMerge($assign['minidockable'], $items);
     $assign['bottomdockable'] = $lproj->getDefaultBottomDockable();
     $items = jEvent::notify('mapBottomDockable', array('repository' => $repository, 'project' => $project))->getResponse();
     $assign['bottomdockable'] = mapDockItemsMerge($assign['bottomdockable'], $items);
     // Add dockable js
     foreach (array_merge($assign['dockable'], $assign['minidockable'], $assign['bottomdockable']) as $d) {
         if ($d->js != '') {
             $rep->addJsLink($d->js);
         }
     }
     $themePath = jApp::config()->urlengine['basePath'] . 'themes/' . jApp::config()->theme . '/';
     $rep->addCssLink($themePath . 'css/main.css');
     $rep->addCssLink($themePath . 'css/map.css');
     $rep->addCssLink($themePath . 'css/media.css');
     // Add dockable css
     foreach ($assign['dockable'] as $d) {
         if ($d->css != '') {
             $rep->addCssLink($d->css);
         }
     }
     // Replace default theme by theme found in
     // the repository folder media/themes/default/
     if ($lrep->getData('allowUserDefinedThemes')) {
         $repositoryPath = $lrep->getPath();
         $cssArray = array('main', 'map', 'media');
         $themeArray = array('default', $project);
         foreach ($cssArray as $k) {
             foreach ($themeArray as $theme) {
                 $cssRelPath = 'media/themes/' . $theme . '/css/' . $k . '.css';
                 $cssPath = $lrep->getPath() . '/' . $cssRelPath;
                 if (file_exists($cssPath)) {
                     $cssUrl = jUrl::get('view~media:getCssFile', array('repository' => $lrep->getKey(), 'project' => $project, 'path' => $cssRelPath));
                     //~ $rep->addCssLink( $cssUrl );
                     // Use addHeadContent and not addCssLink to be sure it will be loaded after minified code
                     $rep->addHeadContent('<link type="text/css" href="' . $cssUrl . '" rel="stylesheet" />');
                 }
             }
         }
         // Add JS files found in media/js
         $jsDirArray = array('default', $project);
         foreach ($jsDirArray as $dir) {
             $jsPathRoot = realpath($repositoryPath . '/' . 'media/js/' . $dir);
             if (is_dir($jsPathRoot)) {
                 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($jsPathRoot)) as $filename) {
                     $path_parts = pathinfo($filename);
                     if ($path_parts['extension'] == 'js') {
                         $jsPath = realpath($filename);
                         $jsRelPath = 'media/js/' . $dir . str_replace($jsPathRoot, '', $jsPath);
                         $jsUrl = jUrl::get('view~media:getMedia', array('repository' => $lrep->getKey(), 'project' => $project, 'path' => $jsRelPath));
                         //~ $rep->addJSLink( $jsUrl );
                         // Use addHeadContent and not addJSLink to be sure it will be loaded after minified code
                         $rep->addContent('<script type="text/javascript" src="' . $jsUrl . '" ></script>');
                     }
                 }
             }
         }
     }
     // optionnally hide some tools
     // header
     $jsCode = '';
     $mapMenuCss = '';
     $h = $this->intParam('h', 1);
     if ($h == 0 or property_exists($pOptions, 'hideHeader') && $pOptions->hideHeader == 'True') {
         $h = 0;
         $rep->addStyle('#body', 'padding-top:0px;');
         $rep->addStyle('#header', 'display:none; height:0px;');
     }
     // menu = left vertical menu with icons
     $m = $this->intParam('m', 1);
     if ($m == 0 or property_exists($pOptions, 'hideMenu') && $pOptions->hideMenu == 'True') {
         $m = 0;
         $rep->addStyle('#mapmenu', 'display:none !important; width:0px;');
         $rep->addStyle('#dock', 'left:0px; border-left:none;');
     }
     // legend = legend open at startup
     $l = $this->intParam('l', 1);
     if ($l == 0 or property_exists($pOptions, 'hideLegend') && $pOptions->hideLegend == 'True') {
         $l = 0;
         //~ $rep->addStyle('#dock', 'display:none;');
         $jsCode .= "\n      \$( document ).ready( function() {\n        lizMap.events.on({\n          'uicreated':function(evt){\n            \$('#button-switcher').click();\n          }\n        });\n      });\n      ";
     }
     // navbar
     $n = $this->intParam('n', 1);
     if ($n == 0 or property_exists($pOptions, 'hideNavbar') && $pOptions->hideNavbar == 'True') {
         $rep->addStyle('#navbar', 'display:none !important;');
     }
     // overview-box = scale & overview
     $o = $this->intParam('o', 1);
     if ($o == 0 or property_exists($pOptions, 'hideOverview') && $pOptions->hideOverview == 'True') {
         $rep->addStyle('#overview-box', 'display:none !important;');
     }
     // Apply interface modifications
     if ($jsCode != '') {
         $rep->addJSCode($jsCode);
     }
     // Hide groups checkboxes
     if (property_exists($pOptions, 'hideGroupCheckbox') && $pOptions->hideGroupCheckbox == 'True') {
         $rep->addStyle('#switcher-layers button[name="group"]', 'display:none !important;');
     }
     // Add filter
     $filterParam = $this->param('filter');
     $filter = array();
     if ($filterParam) {
         $fExp = explode(';', $filterParam);
         foreach ($fExp as $item) {
             $iExp = explode(':', $item);
             if (count($iExp) == 2) {
                 $filter[$iExp[0]] = $iExp[1];
             }
         }
         if (count($filter) > 0) {
             $rep->addJSCode("var lizLayerFilter = " . json_encode($filter) . ";");
         }
     }
     // Add styles if needed
     $stylesParam = $this->param('layerStyles');
     $styles = array();
     if ($stylesParam) {
         $fExp = explode(';', $stylesParam);
         foreach ($fExp as $item) {
             $iExp = explode(':', $item);
             if (count($iExp) == 2) {
                 $styles[$iExp[0]] = $iExp[1];
             }
         }
         if (count($styles) > 0) {
             $rep->addJSCode("var lizLayerStyles = " . json_encode($styles) . ";");
         }
     }
     //$assign['auth_url_return'] = jUrl::get('view~default:index');
     // switcher-layers-actions javascript
     $rep->addJSLink($bp . 'js/switcher-layers-actions.js');
     $rep->body->assign($assign);
     // Log
     $eventParams = array('key' => 'viewmap', 'content' => '', 'repository' => $lrep->getKey(), 'project' => $project);
     jEvent::notify('LizLogItem', $eventParams);
     return $rep;
 }
Exemplo n.º 26
0
 /**
  * logout a user and delete the user in the php session
  */
 public static function logout()
 {
     $config = self::loadConfig();
     jEvent::notify('AuthLogout', array('login' => $_SESSION[$config['session_name']]->login));
     $_SESSION[$config['session_name']] = new jAuthDummyUser();
     if (isset($config['session_destroy']) && $config['session_destroy']) {
         $params = session_get_cookie_params();
         setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]);
         session_destroy();
     }
     if (isset($config['persistant_enable']) && $config['persistant_enable']) {
         if (isset($config['persistant_cookie_name'])) {
             setcookie($config['persistant_cookie_name'] . '[auth]', '', time() - 3600, $config['persistant_cookie_path'], "", false, true);
         } else {
             jLog::log(jLocale::get('jelix~auth.error.persistant.incorrectconfig', 'persistant_cookie_name'), 'error');
         }
     }
 }
Exemplo n.º 27
0
 /**
  * logout a user and delete the user in the php session
  */
 public static function logout()
 {
     $config = self::_getConfig();
     jEvent::notify('AuthLogout', array('login' => $_SESSION[$config['session_name']]->login));
     $_SESSION[$config['session_name']] = new jAuthDummyUser();
     try {
         jAcl::clearCache();
     } catch (Exception $e) {
     }
     try {
         jAcl2::clearCache();
     } catch (Exception $e) {
     }
     if (isset($config['persistant_enable']) && $config['persistant_enable']) {
         if (!isset($config['persistant_cookie_name'])) {
             throw new jException('jelix~auth.error.persistant.incorrectconfig', 'persistant_cookie_name, persistant_crypt_key');
         }
         setcookie($config['persistant_cookie_name'] . '[auth]', '', time() - 3600, $config['persistant_cookie_path']);
     }
 }
Exemplo n.º 28
0
 /**
  * delete all record corresponding to the conditions stored into the
  * jDaoConditions object.
  * @param jDaoConditions $searchcond
  * @return number of deleted rows
  * @since 1.0beta3
  */
 public final function deleteBy($searchcond)
 {
     if ($searchcond->isEmpty()) {
         return 0;
     }
     $query = 'DELETE FROM ' . $this->_conn->encloseName($this->_tables[$this->_primaryTable]['realname']) . ' WHERE ';
     $query .= $this->_createConditionsClause($searchcond, false);
     if ($this->_deleteByBeforeEvent) {
         jEvent::notify("daoDeleteByBefore", array('dao' => $this->_daoSelector, 'criterias' => $searchcond));
     }
     $result = $this->_conn->exec($query);
     if ($this->_deleteByAfterEvent) {
         jEvent::notify("daoDeleteByAfter", array('dao' => $this->_daoSelector, 'criterias' => $searchcond, 'result' => $result));
     }
     return $result;
 }
Exemplo n.º 29
0
 /**
  * clear all data in the cache.
  *
  * If key_prefix is set, only keys with that prefix will be removed.
  * Note that in that case, it can result in a huge performance issue.
  * See key_prefix_flush_method to configure the best method for your
  * app and your server.
  * @return boolean       false if failure
  */
 public function flush()
 {
     if (!$this->key_prefix) {
         return $this->redis->flushall() == 'OK';
     }
     switch ($this->key_prefix_flush_method) {
         case 'direct':
             $this->redis->flushByPrefix($this->key_prefix);
             return true;
         case 'event':
             jEvent::notify('jCacheRedisFlushKeyPrefix', array('prefix' => $this->key_prefix, 'profile' => $this->profileName));
             return true;
         case 'jcacheredisworker':
             $this->redis->rpush('jcacheredisdelkeys', $this->key_prefix);
             return true;
     }
 }
Exemplo n.º 30
0
 /**
  * remove the censor of current POST
  * To uncensor :
  * 1) get the status of the Father Post
  * 2) apply the Father's status to the Son Post
  * @param integer $thread_id id of the thread
  * @param integer $id_post integer parent id of the thread
  * @param string $status string the status to switch to
  * @param string $censor_msg string of the censored message
  */
 public function uncensor($thread_id, $id_post)
 {
     if ($thread_id < 0 or $id_post < 1) {
         return false;
     }
     $return = false;
     $dao = jDao::get('havefnubb~posts');
     $status = $id_post == $thread_id ? 3 : 5;
     if ($dao->unCensorIt($id_post)) {
         jEvent::notify('HfnuPostAfterStatusChanged', array('id' => $id_post, 'status' => $status));
         $daoThread = jDao::get('havefnubb~threads');
         $rec = $daoThread->get($thread_id);
         $rec->iscensored = 0;
         $daoThread->update($rec);
         $return = $this->getPost($id_post);
     }
     return $return;
 }