/** * @package jelix * @subpackage jtpl_plugin * @author Loic Mathaud * @copyright 2008 Loic Mathaud * @link http://www.jelix.org * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html */ function jtpl_function_html_jmessage($tpl, $type = '') { if ($type == '') { $messages = jMessage::getAll(); } else { $messages = jMessage::get($type); } if (!$messages) { return; } if ($type == '') { echo '<ul class="jelix-msg">'; foreach ($messages as $type_msg => $all_msg) { foreach ($all_msg as $msg) { echo '<li class="jelix-msg-item-' . $type_msg . '">' . htmlspecialchars($msg) . '</li>'; } } } else { echo '<ul class="jelix-msg-' . $type . '">'; foreach ($messages as $msg) { echo '<li class="jelix-msg-item-' . $type . '">' . htmlspecialchars($msg) . '</li>'; } } echo '</ul>'; if ($type == '') { jMessage::clearAll(); } else { jMessage::clear($type); } }
/** * function plugin : Display messages from jMessage */ function jtpl_function_html_jmessage_bootstrap($tpl, $type = '') { // Get messages if ($type == '') { $messages = jMessage::getAll(); } else { $messages = jMessage::get($type); } // Not messages, quit if (!$messages) { return; } // Display messages if ($type == '') { foreach ($messages as $type_msg => $all_msg) { if ($type_msg == 'default') { $type_msg = 'info'; } elseif ($type_msg == 'ok') { $type_msg = 'success'; } echo '<div class="alert alert-block alert-' . $type_msg . ' fade in" data-alert="alert"><a class="close" data-dismiss="alert" href="#">×</a>'; foreach ($all_msg as $msg) { echo '<p>' . htmlspecialchars($msg) . '</p>'; } echo '</div>'; } } else { echo '<div class="alert alert-block ' . $type . ' fade in" data-alert="alert"><a class="close" data-dismiss="alert" href="#">×</a>'; foreach ($messages as $msg) { echo '<p>' . htmlspecialchars($msg) . '</p>'; } echo '</div>'; } if ($type == '') { jMessage::clearAll(); } else { jMessage::clear($type); } }
/** * Send an OGC service Exception * @param $SERVICE the OGC service * @return XML OGC Service Exception. */ function serviceException() { $messages = jMessage::getAll(); $rep = $this->getResponse('xml'); $rep->contentTpl = 'lizmap~wms_exception'; $rep->content->assign('messages', $messages); jMessage::clearAll(); foreach ($messages as $code => $msg) { if ($code == 'AuthorizationRequired') { $rep->setHttpStatus(401, $code); } } return $rep; }
/** * Send an OGC service Exception * @param $SERVICE the OGC service * @return XML OGC Service Exception. */ function serviceException() { $messages = jMessage::getAll(); if (!$messages) { $messages = array(); } $rep = $this->getResponse('xml'); $rep->contentTpl = 'lizmap~wms_exception'; $rep->content->assign('messages', $messages); jMessage::clearAll(); foreach ($messages as $code => $msg) { if ($code == 'AuthorizationRequired') { $rep->setHttpStatus(401, $code); } else { if ($code == 'ProjectNotDefined') { $rep->setHttpStatus(404, 'Not Found'); } else { if ($code == 'RepositoryNotDefined') { $rep->setHttpStatus(404, 'Not Found'); } } } } return $rep; }
/** * Save the form controls data to the database * * @param object $form Jelix jForm object * @return Boolean True if the has been saved */ public function saveFormDataToDb($form) { // Set the form from request //$form->initFromRequest(); // Optionnaly query for the feature $cnx = jDb::getConnection($this->layerId); $layerName = $this->layerName; $capabilities = $this->project->getEditionLayers()->{$layerName}->capabilities; // Update or Insert $updateAction = false; $insertAction = false; if ($this->featureId) { $updateAction = true; } else { $insertAction = true; } // Get list of fields which are not primary keys $fields = array(); foreach ($this->dataFields as $fieldName => $prop) { // For update : And get only fields corresponding to edition capabilities if (!$prop->primary and (strtolower($capabilities->modifyAttribute) == 'true' and $fieldName != $this->geometryColumn or strtolower($capabilities->modifyGeometry) == 'true' and $fieldName == $this->geometryColumn or $insertAction)) { $fields[] = $fieldName; } } if (count($fields) == 0) { jLog::log('Not enough capabilities for this layer ! SQL cannot be constructed: no fields available !', 'error'); $form->setErrorOn($this->geometryColumn, 'An error has been raised when saving the form: Not enough capabilities for this layer !'); jMessage::clearAll(); jMessage::add(jLocale::get('view~edition.link.error.sql'), 'error'); return false; } // Loop though the fields and filter the form posted values $update = array(); $insert = array(); $refs = array(); foreach ($fields as $ref) { // Get and filter the posted data foreach form control $value = $form->getData($ref); if (is_array($value)) { $value = '{' . implode(',', $value) . '}'; } switch ($this->formControls[$ref]->fieldDataType) { case 'geometry': $value = "ST_GeomFromText('" . filter_var($value, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES) . "', " . $this->srid . ")"; $rs = $cnx->query('SELECT GeometryType(' . $value . ') as geomtype'); $rs = $rs->fetch(); if (!preg_match('/' . $this->geometryType . '/', strtolower($rs->geomtype))) { if (preg_match('/' . str_replace('multi', '', $this->geometryType) . '/', strtolower($rs->geomtype))) { $value = 'ST_Multi(' . $value . ')'; } else { $form->setErrorOn($this->geometryColumn, "The geometry type doen't match!"); return false; } } break; case 'date': case 'datetime': $value = filter_var($value, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES); if (!$value) { $value = 'NULL'; } else { $value = $cnx->quote($value); } break; case 'integer': $value = filter_var($value, FILTER_SANITIZE_NUMBER_INT); if (!$value) { $value = 'NULL'; } break; case 'float': $value = (double) $value; if (!$value) { $value = 'NULL'; } break; default: $value = $cnx->quote(filter_var($value, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)); break; } if ($form->hasUpload() && array_key_exists($ref, $form->getUploads())) { $value = $form->getData($ref); $choiceValue = $form->getData($ref . '_choice'); $hiddenValue = $form->getData($ref . '_hidden'); $repPath = $this->repository->getPath(); if ($choiceValue == 'update') { $refPath = realpath($repPath . '/media') . '/upload/' . $this->project->getKey() . '/' . $this->tableName . '/' . $ref; $form->saveFile($ref, $refPath); $value = 'media' . '/upload/' . $this->project->getKey() . '/' . $this->tableName . '/' . $ref . '/' . $value; if ($hiddenValue && file_exists(realPath($repPath) . '/' . $hiddenValue)) { unlink(realPath($repPath) . '/' . $hiddenValue); } } else { if ($choiceValue == 'delete') { if ($hiddenValue && file_exists(realPath($repPath) . '/' . $hiddenValue)) { unlink(realPath($repPath) . '/' . $hiddenValue); } $value = 'NULL'; } else { $value = $hiddenValue; } } if (!$value) { $value = 'NULL'; } else { if ($value != 'NULL') { $value = $cnx->quote(filter_var($value, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)); } } } // Build the SQL insert and update query $insert[] = $value; $refs[] = '"' . $ref . '"'; $update[] = '"' . $ref . '"=' . $value; } $sql = ''; // update if ($updateAction) { if (ctype_digit($this->featureId)) { $featureId = array($this->featureId); } // featureId is set // SQL for updating on line in the edition table $sql = " UPDATE " . $this->table . " SET "; $sql .= implode(', ', $update); $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']; } } } // insert if ($insertAction) { // SQL for insertion into the edition this->table function dquote($n) { return '"' . $n . '"'; } $dfields = array_map("dquote", $fields); $sql = " INSERT INTO " . $this->table . " ("; $sql .= implode(', ', $refs); $sql .= " ) VALUES ("; $sql .= implode(', ', $insert); $sql .= " );"; } try { $rs = $cnx->query($sql); //~ jLog::log($sql); } catch (Exception $e) { $form->setErrorOn($this->geometryColumn, 'An error has been raised when saving the form'); jLog::log("SQL = " . $sql); jLog::log("An error has been raised when saving form data edition to db : " . $e->getMessage(), 'error'); return false; } return true; }
function getGeoBookmarks($repository = Null, $project = Null) { $rep = $this->getResponse('htmlfragment'); $tpl = new jTpl(); // Get user $juser = jAuth::getUserSession(); $usr_login = $juser->login; if (!$repository) { $repository = $this->param('repository'); } if (!$project) { $project = $this->param('project'); } // Get user geobookmarks $daogb = jDao::get('lizmap~geobookmark'); $conditions = jDao::createConditions(); $conditions->addCondition('login', '=', $usr_login); $conditions->addCondition('map', '=', $repository . ':' . $project); $gbList = $daogb->findBy($conditions); $gbCount = $daogb->countBy($conditions); // Get html content $tpl->assign('gbCount', $gbCount); $tpl->assign('gbList', $gbList); $html = $tpl->fetch('view~map_geobookmark'); jMessage::clearAll(); $rep->addContent($html); return $rep; }