diff --git a/Config/Menu/customUserMenu.default.php b/Config/Menu/customUserMenu.default.php index ab1a19e6a6..08ab85785d 100644 --- a/Config/Menu/customUserMenu.default.php +++ b/Config/Menu/customUserMenu.default.php @@ -1,4 +1,7 @@ '/myprofile.php', 'mnu_myRoutes' => '/myroutes.php', - 'mnu_myCacheNotes' => '/mycache_notes.php', + 'mnu_myCacheNotes' => SimpleRouter::getLink(CacheNotesController::class), 'mnu_watchedCaches' => '/mywatches.php', 'mnu_ignoredCaches' => '/myignores.php', 'mnu_myRecommends' => '/mytop5.php', diff --git a/Controllers/CacheNotesController.php b/Controllers/CacheNotesController.php new file mode 100644 index 0000000000..7a26800a11 --- /dev/null +++ b/Controllers/CacheNotesController.php @@ -0,0 +1,256 @@ +isUserLogged()){ + $this->redirectToLoginPage(); + exit; + } + + $this->view->setTemplate('cacheNotes/cacheNotes'); + $this->view->addLocalCss( + Uri::getLinkWithModificationTime('/tpl/stdstyle/cacheNotes/cacheNotes.css')); + + $this->view->addLocalJs( + Uri::getLinkWithModificationTime('/tpl/stdstyle/cacheNotes/cacheNotes.js')); + + $this->view->addLocalCss('/tpl/stdstyle/css/lightTooltip.css'); + $this->view->loadJQuery(); + + //load lightPopup + $this->view->addLocalCss( + Uri::getLinkWithModificationTime('/tpl/stdstyle/js/lightPopup/lightPopup.css')); + $this->view->addLocalJs( + Uri::getLinkWithModificationTime('/tpl/stdstyle/js/lightPopup/lightPopup.js')); + + + + $rowCount = CacheNote::getCountOfUserNotesAndModCoords($this->loggedUser->getUserId()); + $this->view->setVar('rowCount', $rowCount); + + if($rowCount > 0){ + $model = new ListOfCachesModel(); + + $model->addColumn(new Column_CacheTypeIcon(tr('myNotes_status'), + function($row){ + return [ + 'type' => $row['type'], + 'status' => $row['status'], + 'user_sts' => isset($row['user_sts'])?$row['user_sts']:null, + ]; + })); + $model->addColumn(new Column_CacheName(tr('myNotes_cacheName'))); + $model->addColumn(new Column_CacheLastLog(tr('myNotes_lastLogEntry'), + function($row){ + if(isset($row['llog_id'])){ + return [ + 'logId' => $row['llog_id'], + 'logType' => $row['llog_type'], + 'logText' => $row['llog_text'], + 'logUserName' => $row['llog_userName'], + 'logDate' => $row['llog_date'] + ]; + }else{ + return []; + } + } + )); + + // column with notes (+id of this col.) + $model->addColumn(new Column_EllipsedText(tr('myNotes_note'),function($row){ + return [ + 'text' => isset($row['noteTxt'])?$row['noteTxt']:'-', + 'maxChars' => 10, + 'labelShow' => tr('myNotes_showFullNote'), + 'labelHide' => tr('myNotes_hideFullNote'), + ]; + })); + + $model->addColumn(new Column_OnClickActionIcon(tr('myNotes_removeNote'), + function($row){ + return [ + 'icon' => isset($row['noteTxt'])?'/tpl/stdstyle/images/log/16x16-trash.png':null, + 'onClick' => "removeNote(this, {$row['cache_id']})", + 'title' => tr('myNotes_removeNote') + ]; + } + )); + + $model->addColumn(new Column_SimpleText(tr('myNotes_modCacheCoords'), + function($row){ + if(isset($row['coords'])){ + return ($row['coords'])->getAsText(); + }else{ + return '-'; + } + } + )); + + $model->addColumn(new Column_OnClickActionIcon(tr('myNotes_removeCoords'), + function($row){ + + return [ + 'icon' => isset($row['coords'])?'/tpl/stdstyle/images/log/16x16-trash.png':null, + 'onClick' => "removeCoords(this, {$row['cache_id']})", + 'title' => tr('myNotes_removeCoords') + ]; + } + )); + + $pagination = new PaginationModel(50); //per-page number of caches + $pagination->setRecordsCount($rowCount); + list($queryLimit, $queryOffset) = $pagination->getQueryLimitAndOffset(); + $model->setPaginationModel($pagination); + + $model->addDataRows( self::completeDataRows( + $this->loggedUser->getUserId(), $queryLimit, $queryOffset)); + + $this->view->setVar('listCacheModel', $model); + } + + $this->view->buildView(); + } + + /** + * This is called from AJAX only + * @param int $cacheId + */ + public function removeCoords($cacheId) + { + if(!$this->isUserLogged()){ + $this->ajaxErrorResponse("User not logged", 401); + return; + } + + //check cacheId + if(!is_numeric($cacheId)){ + $this->ajaxErrorResponse("Invalid param", 400); + exit; + } + + UserCacheCoords::deleteCoords($cacheId, $this->loggedUser->getUserId()); + $this->ajaxSuccessResponse(); + } + + /** + * This is called from ajax only + * @param int cacheId + */ + public function removeNote($cacheId) + { + if(!$this->isUserLogged()){ + $this->ajaxErrorResponse("User not logged", 401); + return; + } + + Debug::errorLog($cacheId); + + //check cacheId + if(!is_numeric($cacheId)){ + $this->ajaxErrorResponse("Invalid param", 400); + exit; + } + + CacheNote::deleteNote( $this->loggedUser->getUserId(), $cacheId); + $this->ajaxSuccessResponse(); + + } + + private function completeDataRows($userId, $limit=null, $offset=null) + { + $cacheIds = CacheNote::getCachesIdsForNotesAndModCoords($userId, $limit, $offset); + + $result = array_fill_keys($cacheIds, []); + + // fill notes + foreach (CacheNote::getNotesByCacheIds($cacheIds) as $note){ + $result[ $note['cache_id'] ]['noteTxt'] = $note['desc']; + } + + // fill mod-coords + foreach ( UserCacheCoords::getCoordsByCacheIds($cacheIds) as $coord){ + $result[ $coord['cache_id'] ]['coords'] = + Coordinates::FromCoordsFactory($coord['lat'], $coord['lot']); + + $result[ $coord['cache_id'] ]['coordsDate'] = $coord['date']; + } + + // fill caches data + $cacheFields = ['cache_id', 'name', 'type', 'status', 'wp_oc']; + foreach ( MultiCacheStats::getGeocachesById($cacheIds, $cacheFields) as $c){ + foreach($cacheFields as $col){ + $result[ $c['cache_id'] ][$col] = $c[$col]; + } + } + + // find last logs + $logFields = ['id','text','type','user_id','date']; + foreach( MultiLogStats::getLastLogForEachCache($cacheIds) as $log) { + foreach($logFields as $col){ + $result[ $log['cache_id'] ]['llog_'.$col] = $log[$col]; + } + } + + // find cache status for user (found/not-found) + foreach ( MultiLogStats::getStatusForUser($userId, $cacheIds) as $s){ + $result[ $s['cache_id']] ['user_sts'] = $s['type']; + } + + // find necessary-users + $userIds = []; + foreach ($result as $r){ + if (isset($r['llog_user_id'])){ + $userIds[$r['cache_id']] = $r['llog_user_id']; + } + } + + $userNames = MultiUserQueries::GetUserNamesForListOfIds($userIds); + foreach ($result as &$r){ + if (isset($r['llog_user_id'])){ + $r['llog_userName'] = $userNames[$r['llog_user_id']]; + } + } + + return $result; + } + + + +} + diff --git a/Controllers/UserWatchedCachesController.php b/Controllers/UserWatchedCachesController.php index 85f4e5b4b2..104d129176 100644 --- a/Controllers/UserWatchedCachesController.php +++ b/Controllers/UserWatchedCachesController.php @@ -85,6 +85,9 @@ public function mapOfWatches() $this->view->buildView(); } + /** + * Display paginated list of caches watched by current user + */ public function listOfWatches() { if(!$this->isUserLogged()){ @@ -135,7 +138,7 @@ function($row){ $pagination = new PaginationModel(50); //per-page number of caches $pagination->setRecordsCount($watchedCachesCount); - list($queryLimit, $queryOffset) = $pagination->getQueryLimitAndOffset();; + list($queryLimit, $queryOffset) = $pagination->getQueryLimitAndOffset(); $model->setPaginationModel($pagination); $model->addDataRows( diff --git a/Utils/Database/OcDb.php b/Utils/Database/OcDb.php index 57bcb65b7e..c173f6d99b 100644 --- a/Utils/Database/OcDb.php +++ b/Utils/Database/OcDb.php @@ -123,6 +123,27 @@ public function dbFetchAsKeyValArray(PDOStatement $stmt, $keyCol, $valCol) $this->error('', new PDOException(__METHOD__.': call PDOstatement issue!')); } + /** + * Returns array with values of $keyCol column. + * + * @param PDOStatement $stmt + * @param string $keyCol - column name to use for result key + * @return array + */ + public function dbFetchOneColumnArray(PDOStatement $stmt, $keyCol) + { + $result = []; + if(!is_null($stmt)){ + while($row = $this->dbResultFetch($stmt, OcDb::FETCH_ASSOC)){ + $result[] = $row[$keyCol]; + } + return $result; + } + + $this->error('', new PDOException(__METHOD__.': call PDOstatement issue!')); + } + + /** * This method returns the value from first column of first row in statement * @@ -456,5 +477,20 @@ public function quoteLimitOffset($limit, $offset=null){ return array($limit, $offset); } + /** + * Quote string before use in DB query + * (needs for IN strings etc.) + * + * @param string $str + * @return string + */ + public function quoteString($str) + { + $value = $this->quote($str, self::PARAM_STR); + $value = substr($value, 1, -1); //remove ' char from the begining and end of the string + $value = mb_ereg_replace('&', '\&', $value); //escape '&' char + return $value; + } + } diff --git a/Utils/Debug/StopWatch.php b/Utils/Debug/StopWatch.php new file mode 100644 index 0000000000..ab6dfedd83 --- /dev/null +++ b/Utils/Debug/StopWatch.php @@ -0,0 +1,106 @@ +stages[$name] = microtime(); + } + } + + /** + * Returns the array of saved points in time + * @return void|string[] + */ + public static function getResults() + { + if(! $instance = self::instance()){ + return; + } + + $instance->stages['__now'] = microtime(); + + $result = []; + + $last = null; + $start = null; + foreach ($instance->stages as $stageName => $stageTime){ + $ms = self::microTimeToMs($stageTime); + + if(is_null($start)){ + $start = $ms; + $fromStart = 0; + }else{ + $fromStart = number_format($ms-$start, 4); + } + + if( is_null($last) ){ + $fromLast = '-'; + }else{ + $fromLast = number_format($ms - $last, 4); + } + + $result[$stageName] = "$fromStart s. [$fromLast s.]"; + $last = $ms; + + } + return $result; + } + + /** + * Reset saved measurements + */ + public static function reset() + { + if( $instance = self::instance() ){ + $instance->stages = []; + } + } + + private static function instance() + { + static $instance = null; + if ($instance === null) { + if(isset($_REQUEST[self::SWICH_VAR])){ + $instance = new static(); + return $instance; + }else{ + return null; + } + } + return $instance; + } + + private function __construct() + {} + + private static function microTimeToMs($microtime) + { + list($usec, $sec) = explode(" ", $microtime); + return ((float) $usec + (float) $sec); + } + + + +} diff --git a/Utils/Debug/TimeBenchmark.php b/Utils/Debug/TimeBenchmark.php deleted file mode 100644 index d1135bfcf5..0000000000 --- a/Utils/Debug/TimeBenchmark.php +++ /dev/null @@ -1,48 +0,0 @@ -start = 0; - $this->stop = 0; - } - - private function getmicrotime() - { - list($usec, $sec) = explode(" ", microtime()); - return ((float) $usec + (float) $sec); - } - - public function start() - { - $this->start = $this->getmicrotime(); - } - - public function stop() - { - $this->stop = $this->getmicrotime(); - } - - public function diff() - { - $result = $this->stop - $this->start; - return $result; - } - - public function runTime() - { - $result = $this->getmicrotime() - $this->start; - return $result; - } - -} diff --git a/Utils/Generators/TextGen.php b/Utils/Generators/TextGen.php new file mode 100644 index 0000000000..942d19f171 --- /dev/null +++ b/Utils/Generators/TextGen.php @@ -0,0 +1,27 @@ +dataExtractor = $dataFromRowExtractor; } + if(!empty($additionalClass)){ + $this->additionalClass = ' '.$additionalClass; + } + $this->header = $header; } @@ -64,7 +70,12 @@ public function getHeader(){ } public function getCssClass(){ - return 'center'; + return "center"; + } + + public function getAdditionalClass() + { + return $this->additionalClass; } } diff --git a/lib/Objects/ChunkModels/ListOfCaches/Column_CacheTypeIcon.php b/lib/Objects/ChunkModels/ListOfCaches/Column_CacheTypeIcon.php index 07e90692df..7310eb569e 100644 --- a/lib/Objects/ChunkModels/ListOfCaches/Column_CacheTypeIcon.php +++ b/lib/Objects/ChunkModels/ListOfCaches/Column_CacheTypeIcon.php @@ -2,6 +2,14 @@ namespace lib\Objects\ChunkModels\ListOfCaches; +/** + * This is column with cache icon. + * + * $date arg needs to contains: + * - type - type of the cache (for example multi or virtual) + * - status - status of the cache (for example temp-unavailable or archived + * - user_sts - status for current user - for example found or not found etc. + */ class Column_CacheTypeIcon extends AbstractColumn { protected function getChunkName() diff --git a/lib/Objects/ChunkModels/ListOfCaches/Column_EllipsedText.php b/lib/Objects/ChunkModels/ListOfCaches/Column_EllipsedText.php new file mode 100644 index 0000000000..a300eb62e6 --- /dev/null +++ b/lib/Objects/ChunkModels/ListOfCaches/Column_EllipsedText.php @@ -0,0 +1,41 @@ +addColumn( + * new Column_EllipsedText( + * tr('columnTitle'), + * function($row){ + * return [ + * 'text' => ' '' + * ]; + * } + * ) + * ); + * + */ +class Column_EllipsedText extends AbstractColumn { + + /** + * Returns the name of the chunk template + * {@inheritDoc} + * @see \lib\Objects\ChunkModels\ListOfCaches\AbstractColumn::getChunkName() + */ + protected function getChunkName() + { + return "listOfCaches/ellipsedTextColumn"; + } + + public function getCssClass(){ + return 'center'; + } +} + + diff --git a/lib/Objects/ChunkModels/ListOfCaches/Column_OnClickActionIcon.php b/lib/Objects/ChunkModels/ListOfCaches/Column_OnClickActionIcon.php index d254f48520..2bfd3abd73 100644 --- a/lib/Objects/ChunkModels/ListOfCaches/Column_OnClickActionIcon.php +++ b/lib/Objects/ChunkModels/ListOfCaches/Column_OnClickActionIcon.php @@ -2,6 +2,15 @@ namespace lib\Objects\ChunkModels\ListOfCaches; +/** + * This is column with clickable icon. + * + * DataRowExtractor should return array with columns: + * - icon - src of the icon (if null cell will be empty) + * - onClick - onclick action - for example function name + * - title - title value for title html param of the icon + */ + class Column_OnClickActionIcon extends AbstractColumn { protected function getChunkName() diff --git a/lib/Objects/ChunkModels/ListOfCaches/Column_SimpleText.php b/lib/Objects/ChunkModels/ListOfCaches/Column_SimpleText.php index c19eff1c6f..5792291e19 100644 --- a/lib/Objects/ChunkModels/ListOfCaches/Column_SimpleText.php +++ b/lib/Objects/ChunkModels/ListOfCaches/Column_SimpleText.php @@ -2,8 +2,27 @@ namespace lib\Objects\ChunkModels\ListOfCaches; +/** + * This class just display text returned by dataRowExtractor. + * Example: + * + * $model->addColumn( + * new Column_SimpleText( + * tr('columnTitle'), + * function($row){ + * return Row['value']; + * } + * ) + * ); + * + */ class Column_SimpleText extends AbstractColumn { + /** + * Returns the name of the chunk template + * {@inheritDoc} + * @see \lib\Objects\ChunkModels\ListOfCaches\AbstractColumn::getChunkName() + */ protected function getChunkName() { return "listOfCaches/simpleTextColumn"; diff --git a/lib/Objects/Coordinates/Coordinates.php b/lib/Objects/Coordinates/Coordinates.php index 5075483e8b..9781412dbf 100644 --- a/lib/Objects/Coordinates/Coordinates.php +++ b/lib/Objects/Coordinates/Coordinates.php @@ -127,7 +127,7 @@ public function getLatitudeString($format = false) } - $prefix = $this->getLatitudeHemisphereSymbol() . ' '; + $prefix = $this->getLatitudeHemisphereSymbol() . ' '; switch ($format) { case self::COORDINATES_FORMAT_DECIMAL: return $prefix . $this->convertToDecString(abs($this->latitude)); @@ -164,7 +164,7 @@ public function getLongitudeString($format = false) if ($format === false) { /* pick defaut format */ $format = $this->defaultFormat; } - $prefix = $this->getLongitudeHemisphereSymbol() . ' '; + $prefix = $this->getLongitudeHemisphereSymbol() . ' '; switch ($format) { case self::COORDINATES_FORMAT_DECIMAL: return $prefix . $this->convertToDecString(abs($this->longitude)); @@ -272,7 +272,7 @@ public function setLongitude($longitude) * Returns coordinates string to display */ public function getAsText($format = false){ - return " ". $this->getLatitudeString($format)." ".$this->getLongitudeString($format); + return $this->getLatitudeString($format).' '.$this->getLongitudeString($format); } /** @@ -296,7 +296,7 @@ private function getParts($coordinate) private function convertToDegMin($decimalCoordinate) { - $degMinCoordinate = sprintf("%02d", floor($decimalCoordinate)) . '° '; + $degMinCoordinate = sprintf("%02d", floor($decimalCoordinate)) . '° '; $coordinate = $decimalCoordinate - floor($decimalCoordinate); $degMinCoordinate .= sprintf("%06.3f", round($coordinate * 60, 3)) . '\''; return $degMinCoordinate; @@ -304,10 +304,10 @@ private function convertToDegMin($decimalCoordinate) private function convertToDegMinSec($decimalCoordinate) { - $degMinSecCoordinate = sprintf("%02d", floor($decimalCoordinate)) . '° '; + $degMinSecCoordinate = sprintf("%02d", floor($decimalCoordinate)) . '° '; $coordinate = $decimalCoordinate - floor($decimalCoordinate); $coordinate *= 60; - $degMinSecCoordinate .= sprintf("%02d", floor($coordinate)) . '\' '; + $degMinSecCoordinate .= sprintf("%02d", floor($coordinate)) . '\' '; $latmin = $coordinate - floor($coordinate); $degMinSecCoordinate .= sprintf("%02.02f", $latmin * 60) . '\'\''; return $degMinSecCoordinate; @@ -315,7 +315,7 @@ private function convertToDegMinSec($decimalCoordinate) private function convertToDecString($coordinate, $afterComaPlacesCount = 5) { - return sprintf('%.' . $afterComaPlacesCount . 'f', $coordinate) . '° '; + return sprintf('%.' . $afterComaPlacesCount . 'f', $coordinate) . '° '; } private function getLatitudeHemisphereSymbol() diff --git a/lib/Objects/GeoCache/CacheNote.php b/lib/Objects/GeoCache/CacheNote.php new file mode 100644 index 0000000000..ab0ba27a50 --- /dev/null +++ b/lib/Objects/GeoCache/CacheNote.php @@ -0,0 +1,124 @@ +multiVariableQueryValue( + "SELECT `desc` FROM cache_notes + WHERE cache_id = :1 AND user_id = :2 + LIMIT 1", '', $cacheId, $userId); + } + + /** + * Save given user note to DB + * + * @param int $userId + * @param int $cacheId + * @param string $noteContent + */ + public static function storeNote($userId, $cacheId, $noteContent) + { + //TODO: Table cache_notes should have index on cache_id/user_id instead of autoincrement index! + // Then it could be possible to use INSERT ... ON DUPLICATE KEY UPDATE Syntax + // DELETE old coords to be sure there is no duplicates... + self::deleteNote($userId, $cacheId); + + $noteContent = htmlspecialchars($noteContent, ENT_COMPAT, 'UTF-8'); + + self::db()->multiVariableQuery( + "INSERT INTO cache_notes + (cache_id, user_id, `desc`, date) + VALUES(:1, :2, :3, NOW() );", + $cacheId, $userId, $noteContent); + } + + /** + * Delete selected user note + * + * @param int $userId + * @param int $cacheId + */ + public static function deleteNote($userId, $cacheId) + { + //TODO: add LIMIT 1 after note_id removig + + self::db()->multiVariableQuery( + "DELETE FROM cache_notes + WHERE cache_id = :1 AND user_id = :2", $cacheId, $userId); + } + + /** + * Returns the count of caches which has at least one of: + * - user custom coords (mod_coords) + * - user note + * @param int $userId + * @return int count + */ + public static function getCountOfUserNotesAndModCoords($userId) + { + return self::db()->multiVariableQueryValue( + "SELECT COUNT(*) FROM ( + SELECT cache_id FROM cache_notes WHERE user_id = :1 + UNION + SELECT cache_id FROM cache_mod_cords WHERE user_id = :1 + ) x", 0, $userId); + } + + /** + * Returns array of cache-ids which + * - has custom coords (mod_coords) for current user + * - has note for current user + * ordered by cache name and with limit/offset + * + * @param int $userId + * @param int|null $limit + * @param int|null $offset + * @return array + */ + public static function getCachesIdsForNotesAndModCoords( + $userId, $limit=null, $offset=null) + { + $db = self::db(); + + list($limit, $offset) = $db->quoteLimitOffset($limit, $offset); + + $stmt = $db->multiVariableQuery( + "SELECT cache_id FROM ( + SELECT cache_id FROM cache_notes WHERE user_id = :1 + UNION + SELECT cache_id FROM cache_mod_cords WHERE user_id = :1 + ) x LEFT JOIN caches USING (cache_id) + ORDER BY caches.name + LIMIT $limit OFFSET $offset", $userId); + + return $db->dbFetchOneColumnArray($stmt, 'cache_id'); + } + + public static function getNotesByCacheIds(array $cacheIds) + { + if(empty($cacheIds)){ + return []; + } + $db = self::db(); + + $cacheIdsStr = $db->quoteString( implode(',', $cacheIds) ); + + $rs = $db->simpleQuery( + "SELECT * FROM cache_notes + WHERE cache_id IN ($cacheIdsStr)"); + + return $db->dbResultFetchAll($rs); + } + +} diff --git a/lib/Objects/GeoCache/GeoCache.php b/lib/Objects/GeoCache/GeoCache.php index d1e57eab62..2e02d15b22 100644 --- a/lib/Objects/GeoCache/GeoCache.php +++ b/lib/Objects/GeoCache/GeoCache.php @@ -10,6 +10,7 @@ use lib\Objects\Coordinates\Coordinates; use lib\Objects\GeoCache\CacheLocation; use lib\Objects\Coordinates\Altitude; +use lib\Objects\User\MultiUserQueries; /** * Description of geoCache @@ -203,7 +204,7 @@ public static function fromWayPointFactory($wp){ /** * Factory - creats Geocache object based on geocache UUID - * @param unknown $wp + * @param string $wp * @return GeoCache object or null if no such geocache */ public static function fromUUIDFactory($uuid){ @@ -1137,7 +1138,7 @@ public function getCacheVisits() public function getPrePublicationVisits() { - $result = User::GetUserNamesForListOfIds( + $result = MultiUserQueries::GetUserNamesForListOfIds( CacheVisits::GetPrePublicationVisits($this->id)); if(empty($result)){ @@ -1237,65 +1238,32 @@ public function getCacheDescription($descLang) */ public function getUserCoordinates($userId) { - $s = XDb::xSql( - "SELECT longitude AS lon, latitude AS lat FROM cache_mod_cords - WHERE cache_id = ? AND user_id = ? LIMIT 1", $this->id, $userId); - - if($row = XDb::xFetchArray($s)){ - return Coordinates::FromCoordsFactory($row['lat'], $row['lon']); - }else{ - return null; - } - + return UserCacheCoords::getCoords($userId, $this->getCacheId()); } public function saveUserCoordinates(Coordinates $coords, $userId) { - //TODO: Table cache_mod_cords should have index on cache_id/user_id instead of autoincrement index! - // Then it could be possible to use INSERT ... ON DUPLICATE KEY UPDATE Syntax - // DELETE old coords to be sure there is no duplicates... - $this->deleteUserCoordinates($userId); - - XDb::xSql("INSERT INTO cache_mod_cords - (cache_id, user_id, longitude, latitude, date) - VALUES(?, ?, ?, ?, NOW() );", - $this->id, $userId, $coords->getLongitude(), $coords->getLatitude()); + UserCacheCoords::storeCoords($userId, $this->getCacheId(), $coords); } public function deleteUserCoordinates($userId) { - XDb::xSql("DELETE FROM cache_mod_cords - WHERE cache_id = ? AND user_id = ?", $this->id, $userId); + UserCacheCoords::deleteCoords($this->getCacheId(), $userId); } public function getUserNote($userId) { - return XDb::xMultiVariableQueryValue( - "SELECT `desc` FROM cache_notes WHERE cache_id = :1 AND user_id = :2 LIMIT 1", - '', $this->id, $userId); + return CacheNote::getNote($userId, $this->getCacheId()); } public function saveUserNote($userId, $noteContent) { - //TODO: Table cache_notes should have index on cache_id/user_id instead of autoincrement index! - // Then it could be possible to use INSERT ... ON DUPLICATE KEY UPDATE Syntax - // DELETE old coords to be sure there is no duplicates... - $this->deleteUserNote($userId); - - - $noteContent = htmlspecialchars($noteContent, ENT_COMPAT, 'UTF-8'); - - XDb::xSql("INSERT INTO cache_notes - (cache_id, user_id, `desc`, desc_html, date) - VALUES(?, ?, ?, ?, NOW() );", - $this->id, $userId, $noteContent, '0'); - + CacheNote::storeNote($userId, $this->getCacheId(), $noteContent); } public function deleteUserNote($userId) { - XDb::xSql("DELETE FROM cache_notes - WHERE cache_id = ? AND user_id = ?", $this->id, $userId); + CacheNote::deleteNote($userId, $this->getCacheId()); } public function getGeokretsHosted() diff --git a/lib/Objects/GeoCache/GeoCacheLog.php b/lib/Objects/GeoCache/GeoCacheLog.php index 5b1863370f..9066a31a5d 100644 --- a/lib/Objects/GeoCache/GeoCacheLog.php +++ b/lib/Objects/GeoCache/GeoCacheLog.php @@ -342,4 +342,5 @@ public static function fromLogIdFactory($logId) return null; } } + } diff --git a/lib/Objects/GeoCache/GeoCacheLogCommons.php b/lib/Objects/GeoCache/GeoCacheLogCommons.php index 53a3658365..9331868183 100644 --- a/lib/Objects/GeoCache/GeoCacheLogCommons.php +++ b/lib/Objects/GeoCache/GeoCacheLogCommons.php @@ -24,7 +24,7 @@ class GeoCacheLogCommons extends BaseObject{ const LOGTYPE_TEMPORARYUNAVAILABLE = 11; const LOGTYPE_ADMINNOTE = 12; - const ICON_PATH = 'tpl/stdstyle/images/log/'; //path to the dir with log-type icons + const ICON_PATH = '/tpl/stdstyle/images/log/'; //path to the dir with log-type icons public function __construct() { diff --git a/lib/Objects/GeoCache/MultiCacheStats.php b/lib/Objects/GeoCache/MultiCacheStats.php index 21623d4035..551500bd9c 100644 --- a/lib/Objects/GeoCache/MultiCacheStats.php +++ b/lib/Objects/GeoCache/MultiCacheStats.php @@ -139,5 +139,23 @@ public static function getNewCachesCount($fromLastDays){ )", 0); } + /** + * Return array of Geocaches based on given cache Ids + * @param array $cacheIds + */ + public static function getGeocachesById(array $cacheIds, array $fieldsArr) + { + $db = self::db(); + + $cacheIdsStr = implode(',', $cacheIds); + $fields = implode(',', $fieldsArr); + + $rs = $db->simpleQuery( + "SELECT $fields + FROM caches WHERE cache_id IN ($cacheIdsStr)"); + + return $db->dbResultFetchAll($rs); + } + } diff --git a/lib/Objects/GeoCache/MultiLogStats.php b/lib/Objects/GeoCache/MultiLogStats.php index 781ec776d5..8da4492f16 100644 --- a/lib/Objects/GeoCache/MultiLogStats.php +++ b/lib/Objects/GeoCache/MultiLogStats.php @@ -54,4 +54,69 @@ public static function getLastRecomendationsCount($fromLastDays) AND date_created > DATE_SUB(NOW(), INTERVAL $days day)", 0, GeoCacheLog::LOGTYPE_FOUNDIT); } + + /** + * Returns array with last logs data for each given cacheId + * @param array $cacheIds + * @param array $logFields - optional list of log fields + */ + public static function getLastLogForEachCache(array $cacheIds, array $logFields=null) + { + if(empty($cacheIds)){ + return []; + } + + if( is_null($logFields) ){ + $logFields = ['*']; + } + + $db = self::db(); + + $cacheIdsStr = $db->quoteString(implode(',', $cacheIds)); + $fieldsStr = $db->quoteString(implode(',', $logFields)); + + $rs = $db->multiVariableQuery( + "SELECT $fieldsStr + FROM cache_logs + INNER JOIN ( + SELECT MAX(id) as id + FROM cache_logs + WHERE cache_id IN ($cacheIdsStr) AND deleted = 0 + GROUP BY cache_id) x + USING (id) "); + + return $db->dbResultFetchAll($rs); + } + + /** + * + * @param int $userId + * @param array $cacheIds + */ + public static function getStatusForUser($userId, array $cacheIds) + { + if(empty($cacheIds)){ + return []; + } + + $db = self::db(); + + $cacheIdsStr = $db->quoteString(implode(',', $cacheIds)); + $logTypes = implode(',', + [GeoCacheLog::LOGTYPE_FOUNDIT, GeoCacheLog::LOGTYPE_DIDNOTFIND]); + + $rs = $db->multiVariableQuery( + "SELECT cache_id, type, date + FROM cache_logs + INNE JOIN ( + SELECT MAX(id) as id + FROM cache_logs + WHERE cache_id IN ($cacheIdsStr) AND deleted = 0 + AND user_id = :1 + AND type IN ($logTypes) + GROUP BY cache_id) x + USING (id)", $userId); + + return $db->dbResultFetchAll($rs); + } } diff --git a/lib/Objects/GeoCache/UserCacheCoords.php b/lib/Objects/GeoCache/UserCacheCoords.php new file mode 100644 index 0000000000..29951c218b --- /dev/null +++ b/lib/Objects/GeoCache/UserCacheCoords.php @@ -0,0 +1,64 @@ +multiVariableQuery( + "SELECT longitude AS lon, latitude AS lat FROM cache_mod_cords + WHERE cache_id = :1 AND user_id = :2 LIMIT 1", + $cacheId, $userId); + + if($row = self::db()->dbResultFetchOneRowOnly($rs)){ + return Coordinates::FromCoordsFactory($row['lat'], $row['lon']); + }else{ + return null; + } + } + + public static function storeCoords($userId, $cacheId, Coordinates $coords) + { + //TODO: Table cache_mod_cords should have index on cache_id/user_id instead of autoincrement index! + // Then it could be possible to use INSERT ... ON DUPLICATE KEY UPDATE Syntax + // DELETE old coords to be sure there is no duplicates... + self::deleteCoords($cacheId, $userId); + + self::db()->multiVariableQuery( + "INSERT INTO cache_mod_cords + (cache_id, user_id, longitude, latitude, date) + VALUES(:1, :2, :3, :4, NOW() );", + $cacheId, $userId, $coords->getLongitude(), $coords->getLatitude()); + } + + public static function deleteCoords($cacheId, $userId) + { + self::db()->multiVariableQuery( + "DELETE FROM cache_mod_cords + WHERE cache_id = :1 AND user_id = :2 LIMIT 1", + $cacheId, $userId); + } + + public static function getCoordsByCacheIds(array $cacheIds) + { + if(empty($cacheIds)){ + return []; + } + $db = self::db(); + + $cacheIdsStr = implode(',', $cacheIds); + + $rs = $db->simpleQuery( + "SELECT cache_id, latitude AS lat, longitude AS lot, date + FROM cache_mod_cords + WHERE cache_id IN ($cacheIdsStr)"); + + return $db->dbResultFetchAll($rs); + } + +} diff --git a/lib/Objects/Stats/TotalStats.php b/lib/Objects/Stats/TotalStats.php index 1df502170a..60c98ea884 100644 --- a/lib/Objects/Stats/TotalStats.php +++ b/lib/Objects/Stats/TotalStats.php @@ -5,7 +5,7 @@ use lib\Objects\BaseObject; use lib\Objects\Stats\TotalStats\BasicStats; -use lib\Objects\User\MultiUserStats; +use lib\Objects\User\MultiUserQueries; use Utils\Cache\OcMemCache; use Utils\Text\Formatter; use lib\Objects\CacheSet\CacheSet; @@ -52,9 +52,9 @@ private static function contructBasicTotalStats() $basicStats->activeCacheSets =Formatter::number(CacheSet::getActiveCacheSetsCount()); - $basicStats->totalUsers = Formatter::number(MultiUserStats::getActiveUsersCount()); + $basicStats->totalUsers = Formatter::number(MultiUserQueries::getActiveUsersCount()); - $basicStats->newUsers = MultiUserStats::getUsersRegistratedCount($periodDays); + $basicStats->newUsers = MultiUserQueries::getUsersRegistratedCount($periodDays); $basicStats->totalSearches = Formatter::number(MultiLogStats::getTotalSearchesNumber()); diff --git a/lib/Objects/User/MultiUserStats.php b/lib/Objects/User/MultiUserQueries.php similarity index 65% rename from lib/Objects/User/MultiUserStats.php rename to lib/Objects/User/MultiUserQueries.php index 14533b9252..75b1e0d724 100644 --- a/lib/Objects/User/MultiUserStats.php +++ b/lib/Objects/User/MultiUserQueries.php @@ -3,13 +3,12 @@ use lib\Objects\BaseObject; use lib\Objects\GeoCache\GeoCacheLog; -use Utils\Database\OcDb; /** * This class should contains mostly static, READ-ONLY queries * used to generates statistics etc. around user db table */ -class MultiUserStats extends BaseObject +class MultiUserQueries extends BaseObject { /** @@ -43,4 +42,29 @@ public static function getUsersRegistratedCount($fromLastdays) "SELECT COUNT(*) FROM user WHERE date_created > DATE_SUB(NOW(), INTERVAL $days day) ", 0); } + + /** + * Returns arraywhere row[userId] = username + * + * @param array $userIds - array of userIds + * @return array|mixed[] + */ + public static function GetUserNamesForListOfIds(array $userIds) + { + + if(empty($userIds)){ + return array(); + } + + $db = self::db(); + + $userIdsStr = $db->quoteString(implode($userIds, ',')); + + $s = $db->simpleQuery( + "SELECT user_id, username FROM user + WHERE user_id IN ( $userIdsStr )"); + + return $db->dbFetchAsKeyValArray($s, 'user_id', 'username' ); + } + } \ No newline at end of file diff --git a/lib/Objects/User/User.php b/lib/Objects/User/User.php index 97fc00e357..6ace051321 100644 --- a/lib/Objects/User/User.php +++ b/lib/Objects/User/User.php @@ -783,30 +783,6 @@ public function getGeokretyApiSecid() return $this->geokretyApiSecid; } - /** - * Returns arraywhere row[userId] = username - * - * @param array $userIds - array of userIds - * @return array|mixed[] - */ - public static function GetUserNamesForListOfIds(array $userIds) - { - - if(empty($userIds)){ - return array(); - } - - $db = self::db(); - - $userIdsStr = XDb::xEscape(implode($userIds, ',')); - - $s = $db->simpleQuery( - "SELECT user_id, username FROM user - WHERE user_id IN ( $userIdsStr )"); - - return $db->dbFetchAsKeyValArray($s, 'user_id', 'username' ); - } - public function getCacheWatchEmailSettings(){ return $this->db->dbResultFetchOneRowOnly( diff --git a/lib/Objects/User/UserWatchedCache.php b/lib/Objects/User/UserWatchedCache.php index 9ab2ab9c87..2a1f2ce7ce 100644 --- a/lib/Objects/User/UserWatchedCache.php +++ b/lib/Objects/User/UserWatchedCache.php @@ -58,11 +58,11 @@ public static function getWatchedCachesWithLastLogs( ON (cw.cache_id = c.cache_id) LEFT OUTER JOIN ( SELECT cache_id, - id AS llog_id, - text AS llog_text, - type AS llog_type, - user_id AS llog_user_id, - date as llog_date + id AS llog_id, + text AS llog_text, + type AS llog_type, + user_id AS llog_user_id, + date as llog_date FROM cache_logs AS cl JOIN (SELECT MAX(date), MAX(id) AS id diff --git a/lib/calculation.inc.php b/lib/calculation.inc.php index 2c9c61b103..706672e492 100644 --- a/lib/calculation.inc.php +++ b/lib/calculation.inc.php @@ -1,17 +1,28 @@ 'Zadejte text', 'enter_text_error' => 'Nezadali jste text', 'password_required' => 'Chcete-li tento zápis v deníku, musíte zadat heslo.', - 'last_log_entries' => 'Poslední záznamy v deníku', 'terrain_difficulty' => 'Problém půdy', 'task_difficulty' => 'Úkol nesnázích', 'out_of' => 'z', @@ -866,7 +865,6 @@ 'history_gk' => 'Záznamy GeoKrtků', 'mnu_myStats' => 'Moje statistiky', 'mnu_massLogsSave' => 'Garmin Logfile', - 'mycache_note' => 'Moje poznámky', 'personal_cache_note' => 'Osobní poznámky ke keši', 'cache_note_visible' => 'Tuto poznámku ostatní uživatelé neuvidí. Bude ale součástí stažených GPX souborů.', 'obszary_ochrony_przyrody' => 'Nature preserve areas', @@ -1249,7 +1247,6 @@ 'format_other' => 'Ostatní formáty', 'format_pict' => 'GPX + fotky', 'format_ggz_pict' => 'GGZ + fotky***', - 'mycache_notes' => 'For information about notes, see', 'user_activity01' => 'User activity', 'user_activity02' => 'Aktivita uživatele (nalezeno + nenalezeno + vlastní)', 'type' => 'Typ', @@ -1760,7 +1757,6 @@ 'vl_Record_deleted' => 'Záznam smazán', 'vc_ShowDeletions' => 'Zobrazit smazané', 'vc_HideDeletions' => 'Skrýt smazané', - 'mycache_notes_01' => 'Chcete smazat tuto poznámku?', 'log_score_note_innitial' => 'Tuto keš jste ještě nehodnotili.', 'log_score_note_thanks' => 'Děkujeme za hodnocení!', 'log_score_note_encorage' => 'Prosíme zvažte ohodnocení této keše!', @@ -1805,7 +1801,6 @@ 'coordsmod_main' => 'Zadejte vlastní souřadnice keše', 'coordsmod_lon' => 'Longitude', 'coordsmod_lat' => 'Latitude', - 'coordsmod_info_01' => 'User coordinates (WGS84)', 'coordsmod_info_02' => 'Do you want to restore coordinates?', 'modify_coords' => 'Změnit', 'reset_coords' => 'Resetovat', @@ -2476,4 +2471,9 @@ 'ZW' => 'Zimbabwe', 'SU' => 'Soviet Union', 'XX' => 'None (Not set)', + + + 'myNotes_removeConfirmation' => 'Chcete smazat tuto poznámku?', + 'myNotes_modCacheCoords' => 'User coordinates (WGS84)', + ); diff --git a/lib/languages/de.php b/lib/languages/de.php index 53e4496b8b..b426742fe0 100644 --- a/lib/languages/de.php +++ b/lib/languages/de.php @@ -229,7 +229,6 @@ 'enter_text' => 'Geben Sie Text', 'enter_text_error' => 'Text wurde noch nicht eingetragen', 'password_required' => 'Passwort erforderlich, um ein Log-Eintrag.', - 'last_log_entries' => 'zuletzt gefunden', 'terrain_difficulty' => 'Schwierigkeit', 'task_difficulty' => 'Gelände', 'out_of' => 'aus', @@ -648,7 +647,6 @@ 'users_active' => 'Anzahl der Aktive Benutzer in Cache Suchen', 'show_labels' => 'Etiketten anzeigen', 'history_gk' => 'geoKrety besuchen', - 'mycache_note' => 'Meine Notizen', 'personal_cache_note' => 'Persönliche Notiz', 'cache_note_visible' => 'Notiz ist nicht sichtbar für andere Benutzer. Notiz wird befestig zur GPX Datei.', 'obszary_ochrony_przyrody' => 'Naturschutzgebiete', @@ -1040,7 +1038,6 @@ 'format_other' => 'andere formate', 'format_pict' => 'GPX mit bilder', 'format_ggz_pict' => 'GGZ + photos', - 'mycache_notes' => 'For information about notes, see', 'user_activity01' => 'Benutzeraktivität', 'user_activity02' => 'Anzahl der gefundenen, nicht gefundenen und versteckten Caches', 'type' => 'Type', @@ -2108,7 +2105,6 @@ 'vl_Record_deleted' => 'Record deleted', 'vc_ShowDeletions' => 'Show deletions', 'vc_HideDeletions' => 'Hide deletions', - 'mycache_notes_01' => 'Do you want to delete this note?', 'log_score_note_innitial' => 'You have not rated this cache yet.', 'log_score_note_thanks' => 'Thank you for rating!', 'log_score_note_encorage' => 'Please reconsider rating this cache!', @@ -2154,7 +2150,6 @@ 'coordsmod_main' => 'Enter your own coordinates for the cache location', 'coordsmod_lon' => 'Longitude', 'coordsmod_lat' => 'Latitude', - 'coordsmod_info_01' => 'User coordinates (WGS84)', 'coordsmod_info_02' => 'Do you want to restore coordinates?', 'modify_coords' => 'Modify', 'reset_coords' => 'Restore', @@ -2771,4 +2766,19 @@ 'startPage_latestTitledCaches' => 'Latest awarded', 'startPage_validAt' => 'Valid at', + 'myNotes_title' => 'My notes', /* EN! */ + 'myNotes_removeConfirmation' => 'Do you want to delete this note?', + 'myNotes_modCacheCoords' => 'User coordinates (WGS84)', + 'myNotes_status' => 'Status', /* EN! */ + 'myNotes_cacheName' => 'Geocache', /* EN! */ + 'myNotes_note' => 'Note', /* EN! */ + 'myNotes_removeNote' => 'Del. note', /* EN! */ + 'myNotes_noteRemovingSuccess' => 'Note removed', /* EN! */ + 'myNotes_noteRemovingError' => 'Note removing failed', /* EN! */ + 'myNotes_removeCoords' => 'Del. coordinates', /* EN! */ + 'myNotes_coordsRemovingSuccess' => 'User coordinates removed', /* EN! */ + 'myNotes_coordsRemovingError' => 'User coordinates removing failed', /* EN! */ + 'myNotes_emptyList' => 'No notes found in geocaches', /* EN! */ + 'myNotes_showFullNote' => 'more', /* EN! */ + 'myNotes_removeConfirmation' => 'Vrei să ştergi această notă?', /* EN! */ ); diff --git a/lib/languages/en.php b/lib/languages/en.php index 1270862531..df39a8eaf5 100644 --- a/lib/languages/en.php +++ b/lib/languages/en.php @@ -229,7 +229,6 @@ 'enter_text' => 'Enter text', 'enter_text_error' => 'Text has not been entered', 'password_required' => 'Password required to add a log entry.', - 'last_log_entries' => 'The latest log entries', 'terrain_difficulty' => 'Terrain difficulty', 'task_difficulty' => 'Task difficulty', 'out_of' => 'out of', @@ -649,7 +648,6 @@ 'users_active' => 'Number of active users', 'show_labels' => 'Show labels', 'history_gk' => 'GeoKrety records', - 'mycache_note' => 'My cache notes', 'personal_cache_note' => 'Personal cache note', 'cache_note_visible' => 'The note is not visible to other users. It will however be included in GPX files you download.', 'obszary_ochrony_przyrody' => 'Nature reserve areas', @@ -1041,7 +1039,6 @@ 'format_other' => 'Other formats', 'format_pict' => 'GPX + photos', 'format_ggz_pict' => 'GGZ + photos', - 'mycache_notes' => 'For information about notes, see', 'user_activity01' => 'User activity', 'user_activity02' => 'User activity count (finds + did not finds + owned)', 'type' => 'Type', @@ -2112,7 +2109,6 @@ 'vl_Record_deleted' => 'Record deleted', 'vc_ShowDeletions' => 'Show deletions', 'vc_HideDeletions' => 'Hide deletions', - 'mycache_notes_01' => 'Do you want to delete this note?', 'log_score_note_innitial' => 'You have not rated this cache yet.', 'log_score_note_thanks' => 'Thank you for rating!', 'log_score_note_encorage' => 'Please reconsider rating this cache!', @@ -2158,7 +2154,6 @@ 'coordsmod_main' => 'Enter your own coordinates for the cache location', 'coordsmod_lon' => 'Longitude', 'coordsmod_lat' => 'Latitude', - 'coordsmod_info_01' => 'User coordinates (WGS84)', 'coordsmod_info_02' => 'Do you want to restore coordinates?', 'modify_coords' => 'Modify', 'reset_coords' => 'Restore', @@ -2777,4 +2772,21 @@ 'startPage_latestTitledCaches' => 'Latest awarded geocaches', 'startPage_validAt' => 'Valid at', + + 'myNotes_title' => 'My notes', + 'myNotes_lastLogEntry' => 'Last log entry', + 'myNotes_modCacheCoords' => 'User coordinates', + 'myNotes_status' => 'Status', + 'myNotes_cacheName' => 'Geocache', + 'myNotes_note' => 'Note', + 'myNotes_removeNote' => 'Del. note', + 'myNotes_noteRemovingSuccess' => 'Note removed', + 'myNotes_noteRemovingError' => 'Note removing failed', + 'myNotes_removeCoords' => 'Del. coordinates', + 'myNotes_coordsRemovingSuccess' => 'User coordinates removed', + 'myNotes_coordsRemovingError' => 'User coordinates removing failed', + 'myNotes_emptyList' => 'No notes found in geocaches', + 'myNotes_showFullNote' => 'more', + 'myNotes_removeConfirmation' => 'Do you want to delete this note?', + ); diff --git a/lib/languages/es.php b/lib/languages/es.php index a78cb5cd1a..bf6dccadba 100644 --- a/lib/languages/es.php +++ b/lib/languages/es.php @@ -216,7 +216,6 @@ 'enter_text' => 'Escriba el texto', 'enter_text_error' => 'No ha introducido el texto', 'password_required' => 'Para hacer esta entrada en el registro, debe introducir la contrasena.', - 'last_log_entries' => 'El último entradas en el registro', 'terrain_difficulty' => 'La dificultad de la tierra', 'task_difficulty' => 'Grupo de crisis', 'out_of' => 'z', diff --git a/lib/languages/fr.php b/lib/languages/fr.php index 8bcb9af067..b2f466c849 100644 --- a/lib/languages/fr.php +++ b/lib/languages/fr.php @@ -215,7 +215,6 @@ 'enter_text' => 'Entrez le texte', 'enter_text_error' => 'Vous ne l"avez pas, entrez le texte', 'password_required' => 'Pour ce faire, l"entrée dans le journal, vous devez entrer le mot de passe.', - 'last_log_entries' => 'Les dernieres entrées dans le journal', 'terrain_difficulty' => 'La difficulté de la terre', 'task_difficulty' => 'Task difficulté', 'out_of' => 'z', diff --git a/lib/languages/nl.php b/lib/languages/nl.php index ff21fc67e0..c3fc340f96 100644 --- a/lib/languages/nl.php +++ b/lib/languages/nl.php @@ -229,7 +229,6 @@ 'enter_text' => 'Vul tekst in', 'enter_text_error' => 'Er is geen tekst ingevuld', 'password_required' => 'Wachtwoord is nodig om te loggen.', - 'last_log_entries' => 'De laatste logs', 'terrain_difficulty' => 'Terrein', 'task_difficulty' => 'Moeilijkheid', 'out_of' => 'van', @@ -649,7 +648,6 @@ 'users_active' => 'Aantal actieve gebruikers', 'show_labels' => 'Toon labels', 'history_gk' => 'GeoKrety historie', - 'mycache_note' => 'Mijn cache notities', 'personal_cache_note' => 'Persoonlijke cache notitie', 'cache_note_visible' => 'De notitie is niet zichtbaar voor andere gebruikers. De notitie zit wel in het GPX-bestand.', 'obszary_ochrony_przyrody' => 'Beschermde natuurgebieden', @@ -1041,7 +1039,6 @@ 'format_other' => 'andere formaten', 'format_pict' => 'GPX met afbeeldingen', 'format_ggz_pict' => 'GGZ met afbeeldingen', - 'mycache_notes' => 'Zie voor informatie over cachenotities', 'user_activity01' => 'Gebruikers activiteit', 'user_activity02' => 'Totaal van gevonden, niet gevonden en gemaakte caches', 'type' => 'Soort', @@ -2109,7 +2106,6 @@ 'vl_Record_deleted' => 'Bewerking verwijderd', 'vc_ShowDeletions' => 'Toon verwijderde logs', 'vc_HideDeletions' => 'Verberg verwijderde logs', - 'mycache_notes_01' => 'Moet deze cache notitie werkelijk verwijderd worden?', 'log_score_note_innitial' => 'De cache is nog niet beoordeeld.', 'log_score_note_thanks' => 'Bedankt voor de beoordeling', 'log_score_note_encorage' => 'Overweeg eens om deze cache te beoordelen', @@ -2155,7 +2151,6 @@ 'coordsmod_main' => 'Noteer hier de gecorrigeerde coördinaten', 'coordsmod_lon' => 'Longitude', 'coordsmod_lat' => 'Latitude', - 'coordsmod_info_01' => 'Gecorrigeerde coördinaten', 'coordsmod_info_02' => 'Moeten de coördinaten weer hersteld worden?', 'modify_coords' => 'Veranderen', 'reset_coords' => 'Herstellen', @@ -2774,4 +2769,19 @@ 'startPage_latestTitledCaches' => 'Latest awarded', 'startPage_validAt' => 'Valid at', + 'myNotes_title' => 'Mijn cache notities', + 'myNotes_removeConfirmation' => 'Moet deze cache notitie werkelijk verwijderd worden?', + 'myNotes_modCacheCoords' => 'Gecorrigeerde coördinaten', + 'myNotes_status' => 'Status', /* EN! */ + 'myNotes_cacheName' => 'Geocache', /* EN! */ + 'myNotes_note' => 'Note', /* EN! */ + 'myNotes_removeNote' => 'Del. note', /* EN! */ + 'myNotes_noteRemovingSuccess' => 'Note removed', /* EN! */ + 'myNotes_noteRemovingError' => 'Note removing failed', /* EN! */ + 'myNotes_removeCoords' => 'Del. coordinates', /* EN! */ + 'myNotes_coordsRemovingSuccess' => 'User coordinates removed', /* EN! */ + 'myNotes_coordsRemovingError' => 'User coordinates removing failed', /* EN! */ + 'myNotes_emptyList' => 'No notes found in geocaches', /* EN! */ + 'myNotes_showFullNote' => 'more', /* EN! */ + 'myNotes_removeConfirmation' => 'Vrei să ştergi această notă?', /* EN! */ ); diff --git a/lib/languages/pl.php b/lib/languages/pl.php index 1cfa5a4b19..7f886486db 100644 --- a/lib/languages/pl.php +++ b/lib/languages/pl.php @@ -229,7 +229,6 @@ 'enter_text' => 'Wprowadź tekst', 'enter_text_error' => 'Nie wprowadzono tekstu', 'password_required' => 'Aby zrobić wpis do logu, należy podać hasło.', - 'last_log_entries' => 'Ostatnie wpisy do logu', 'terrain_difficulty' => 'Trudność terenu', 'task_difficulty' => 'Trudność zadań', 'out_of' => 'z', @@ -653,7 +652,6 @@ 'users_active' => 'Liczba aktywnych użytkowników w poszukiwaniach', 'show_labels' => 'Pokaż etykiety', 'history_gk' => 'Wizyty GeoKretów', - 'mycache_note' => 'Moje notatki', 'personal_cache_note' => 'Własna notatka do skrzynki', 'cache_note_visible' => 'Notatka nie jest widziana przez innych użytkowników. Notatka będzie dołączana do pliku GPX.', 'obszary_ochrony_przyrody' => 'Obszary ochrony przyrody', @@ -1045,7 +1043,6 @@ 'format_other' => 'Inne formaty', 'format_pict' => 'GPX + zdjęcia', 'format_ggz_pict' => 'GGZ + zdjęcia', - 'mycache_notes' => 'Zobacz opis o notatkach skrzynki', 'user_activity01' => 'Aktywność użytkownika', 'user_activity02' => 'Suma skrzynek znalezionych, nieznalezionych i założonych', 'type' => 'Typ', @@ -2116,7 +2113,6 @@ 'vl_Record_deleted' => 'Wpis skasowany', 'vc_ShowDeletions' => 'Pokazuj usunięcia', 'vc_HideDeletions' => 'Ukrywaj usunięcia', - 'mycache_notes_01' => 'Czy na pewno chcesz usunąć notatkę?', 'log_score_note_innitial' => 'Jeszcze nie oceniłeś(-aś) tej skrzynki.', 'log_score_note_thanks' => 'Dziękujemy za ocenę!', 'log_score_note_encorage' => 'Prosimy o ocenę!', @@ -2162,7 +2158,6 @@ 'coordsmod_main' => 'Wprowadź własne współrzędne dla skrzynki:', 'coordsmod_lon' => 'Długość geograficzna', 'coordsmod_lat' => 'Szerokość geograficzna', - 'coordsmod_info_01' => 'Własne współrzędne (WGS84)', 'coordsmod_info_02' => 'Czy na pewno chcesz przywrócić współrzędne?', 'modify_coords' => 'Modyfikuj współrzędne', 'reset_coords' => 'Przywróć oryginalne', @@ -2781,4 +2776,20 @@ 'startPage_latestTitledCaches' => 'Ostatnio wyróżnione', 'startPage_validAt' => 'Aktualność', + 'myNotes_title' => 'Moje notatki', + 'myNotes_lastLogEntry' => 'Ostatni wpis w logu', + 'myNotes_modCacheCoords' => 'Własne współrzędne', + 'myNotes_status' => 'Status', + 'myNotes_cacheName' => 'Skrzynka', + 'myNotes_note' => 'Notatka', + 'myNotes_removeNote' => 'Usuń notatkę', + 'myNotes_noteRemovingSuccess' => 'Notatka usunięta', + 'myNotes_noteRemovingError' => 'Nie udało się usunąć notatki', + 'myNotes_removeCoords' => 'Usuń współrz.', + 'myNotes_coordsRemovingSuccess' => 'Zmienione koordynaty usunięte', + 'myNotes_coordsRemovingError' => 'Nie udało się usunąć koordynat', + 'myNotes_emptyList' => 'Nie znaleziono twoich notatek w skrzynkach', + 'myNotes_showFullNote' => 'więcej', + 'myNotes_removeConfirmation' => 'Czy na pewno chcesz usunąć notatkę?', + ); diff --git a/lib/languages/ro.php b/lib/languages/ro.php index 55e344f95b..cc5860439d 100644 --- a/lib/languages/ro.php +++ b/lib/languages/ro.php @@ -229,7 +229,6 @@ 'enter_text' => 'Scrie', 'enter_text_error' => 'Nu ai scris nimic', 'password_required' => 'Adăugarea unei însemnări necesită introducerea parolei.', - 'last_log_entries' => 'Ultimele însemnări', 'terrain_difficulty' => 'Teren', 'task_difficulty' => 'Dificultate', 'out_of' => 'din', @@ -649,7 +648,6 @@ 'users_active' => 'Numărul de utilizatori activi', 'show_labels' => 'Arată etichetele', 'history_gk' => 'Înregistrări de GeoKrety', - 'mycache_note' => 'Notiţele geocutiei mele', 'personal_cache_note' => 'Notiţă personală la geocutie', 'cache_note_visible' => 'Aceste notiţe nu pot fi văzute de ceilalţi utilizatori, dar vor fi incluse în fişierele GPX pe care le descarci tu.', 'obszary_ochrony_przyrody' => 'Nature reserve areas***', @@ -1041,7 +1039,6 @@ 'format_other' => 'alte tipuri', 'format_pict' => 'GPX + poze', 'format_ggz_pict' => 'GGZ + poze', - 'mycache_notes' => 'Pentru informaţii despre notiţe, vezi', 'user_activity01' => 'Activitate utilizator', 'user_activity02' => 'Activitate utilizator - total (găsite + negăsite + proprii)', 'type' => 'Tip', @@ -2112,7 +2109,6 @@ 'vl_Record_deleted' => 'Record deleted***', 'vc_ShowDeletions' => 'Arată înregistrările şterse', 'vc_HideDeletions' => 'Ascunde înregistrările şterse', - 'mycache_notes_01' => 'Vrei să ştergi această notă?', 'log_score_note_innitial' => 'Încă nu ai apreciat această geocutie.', 'log_score_note_thanks' => 'Mulţumim pentru aprecierea acordată!', 'log_score_note_encorage' => 'Te rog mai gândeşte-te dacă să apreciezi sau nu această geocutie!', @@ -2158,7 +2154,6 @@ 'coordsmod_main' => 'Introdu propriile tale coordonate pentru geocutie', 'coordsmod_lon' => 'Longitudine', 'coordsmod_lat' => 'Latitudine', - 'coordsmod_info_01' => 'Coordonatele utilizatorilor (WGS84)', 'coordsmod_info_02' => 'Vrei să revii la coordonatele originale?', 'modify_coords' => 'Modifică', 'reset_coords' => 'Anulează', @@ -2759,8 +2754,8 @@ 'startPage_topRatedCachesDesc' => 'Numărul geocutiilor recomandate ca "EXCELENTE"', 'startPage_newCaches' => 'Geocutii noi', 'startPage_newCachesDesc' => 'Geocutii ascunse recent (ultimele 30 de zile)', - 'startPage_activeCacheSets' => 'Active geopaths***', /* EN! */ - 'startPage_activeCacheSetsDesc' => 'Total number of active geopaths***', /* EN! */ + 'startPage_activeCacheSets' => 'Active geopaths***', + 'startPage_activeCacheSetsDesc' => 'Total number of active geopaths***', 'startPage_totalUsers' => 'Utilizatori activi', 'startPage_totalUsersDesc' => 'Numărul utilizatorilor care au căutat sau au ascuns o geocutie', 'startPage_newUsers' => 'Utilizatori noi', @@ -2771,10 +2766,26 @@ 'startPage_newSearchesDesc' => 'Numărul căutărilor efectuate recent (ultimele 30 de zile)', 'startPage_newoRecom' => 'Recomandări noi', 'startPage_newoRecomDesc' => 'Numărul recomandărilor acordate recent (ultimele 30 de zile)', - 'startPage_showMore' => 'Arată mai mult', /* EN! */ - 'startPage_latestCachesList' => 'Cele mai noi geocutii', /* EN! */ - 'startPage_latestCacheSets' => 'Cele mai noi Geopath***', /* EN! */ - 'startPage_latestTitledCaches' => 'Cele mai noi premiate', /* EN! */ + 'startPage_showMore' => 'Arată mai mult', + 'startPage_latestCachesList' => 'Cele mai noi geocutii', + 'startPage_latestCacheSets' => 'Cele mai noi Geopath***', + 'startPage_latestTitledCaches' => 'Cele mai noi premiate', 'startPage_validAt' => 'Valabil la***', + 'myNotes_title' => 'Notiţele geocutiei mele', + 'myNotes_modCacheCoords' => 'Coordonatele utilizatorilor', + 'myNotes_lastLogEntry' => 'Last log entry', /* EN! */ + 'myNotes_status' => 'Status', /* EN! */ + 'myNotes_cacheName' => 'Geocache', /* EN! */ + 'myNotes_note' => 'Note', /* EN! */ + 'myNotes_removeNote' => 'Del. note', /* EN! */ + 'myNotes_noteRemovingSuccess' => 'Note removed', /* EN! */ + 'myNotes_noteRemovingError' => 'Note removing failed', /* EN! */ + 'myNotes_removeCoords' => 'Del. coordinates', /* EN! */ + 'myNotes_coordsRemovingSuccess' => 'User coordinates removed', /* EN! */ + 'myNotes_coordsRemovingError' => 'User coordinates removing failed', /* EN! */ + 'myNotes_emptyList' => 'No notes found in geocaches', /* EN! */ + 'myNotes_showFullNote' => 'more', /* EN! */ + 'myNotes_removeConfirmation' => 'Vrei să ştergi această notă?', /* EN! */ + ); diff --git a/lib/languages/sv.php b/lib/languages/sv.php index fe68112c72..687b6fa73e 100644 --- a/lib/languages/sv.php +++ b/lib/languages/sv.php @@ -214,7 +214,6 @@ 'enter_text' => 'Ange text', 'enter_text_error' => 'Ingen text har skrivits in', 'password_required' => 'Lösenord krävs för att lägga till en logg.', - 'last_log_entries' => 'De senaste loggarna', 'terrain_difficulty' => 'Terräng', 'task_difficulty' => 'Svårighet', 'out_of' => 'av', diff --git a/lib/phpqrcode/index.php b/lib/phpqrcode/index.php index f47f5c5ec7..152bec10d8 100644 --- a/lib/phpqrcode/index.php +++ b/lib/phpqrcode/index.php @@ -88,6 +88,5 @@ echo '  '; - // benchmark - //QRtools::timeBenchmark(); + diff --git a/lib/search.gpx.inc.php b/lib/search.gpx.inc.php index 350b4130cf..4e1cebb6ee 100644 --- a/lib/search.gpx.inc.php +++ b/lib/search.gpx.inc.php @@ -8,6 +8,7 @@ use Utils\Database\XDb; use Utils\Database\OcDb; use lib\Objects\GeoCache\GeoCacheCommons; +use lib\Objects\GeoCache\CacheNote; global $content, $bUseZip, $usr, $hide_coords, $dbcSearch, $queryFilter; require_once ('lib/common.inc.php'); @@ -367,7 +368,24 @@ function getPictures($cacheid, $picturescount) echo $gpxHead; - $stmt = XDb::xSql('SELECT `gpxcontent`.`cache_id` `cacheid`, `gpxcontent`.`longitude` `longitude`, `gpxcontent`.`latitude` `latitude`, `gpxcontent`.cache_mod_cords_id, `caches`.`wp_oc` `waypoint`, `caches`.`date_hidden` `date_hidden`, `caches`.`picturescount` `picturescount`, `caches`.`name` `name`, `caches`.`country` `country`, `caches`.`terrain` `terrain`, `caches`.`difficulty` `difficulty`, `caches`.`desc_languages` `desc_languages`, `caches`.`size` `size`, `caches`.`type` `type`, `caches`.`status` `status`, `user`.`username` `username`, `gpxcontent`.`user_id` `owner_id`,`cache_desc`.`desc` `desc`, `cache_desc`.`short_desc` `short_desc`, `cache_desc`.`hint` `hint`, `cache_desc`.`rr_comment`, `caches`.`logpw`, `caches`.`votes` `votes`, `caches`.`score` `score`, `caches`.`topratings` `topratings` FROM `gpxcontent`, `caches`, `user`, `cache_desc` WHERE `gpxcontent`.`cache_id`=`caches`.`cache_id` AND `caches`.`cache_id`=`cache_desc`.`cache_id` AND `caches`.`default_desclang`=`cache_desc`.`language` AND `gpxcontent`.`user_id`=`user`.`user_id`'); + $stmt = XDb::xSql( + 'SELECT `gpxcontent`.`cache_id` `cacheid`, `gpxcontent`.`longitude` `longitude`, + `gpxcontent`.`latitude` `latitude`, `gpxcontent`.cache_mod_cords_id, + `caches`.`wp_oc` `waypoint`, `caches`.`date_hidden` `date_hidden`, + `caches`.`picturescount` `picturescount`, `caches`.`name` `name`, + `caches`.`country` `country`, `caches`.`terrain` `terrain`, + `caches`.`difficulty` `difficulty`, `caches`.`desc_languages` `desc_languages`, + `caches`.`size` `size`, `caches`.`type` `type`, `caches`.`status` `status`, + `user`.`username` `username`, `gpxcontent`.`user_id` `owner_id`, + `cache_desc`.`desc` `desc`, `cache_desc`.`short_desc` `short_desc`, + `cache_desc`.`hint` `hint`, `cache_desc`.`rr_comment`, `caches`.`logpw`, + `caches`.`votes` `votes`, `caches`.`score` `score`, `caches`.`topratings` `topratings` + FROM `gpxcontent`, `caches`, `user`, `cache_desc` + WHERE `gpxcontent`.`cache_id`=`caches`.`cache_id` + AND `caches`.`cache_id`=`cache_desc`.`cache_id` + AND `caches`.`default_desclang`=`cache_desc`.`language` + AND `gpxcontent`.`user_id`=`user`.`user_id`'); + while ($r = XDb::xFetchArray($stmt)) { if (@$enable_cache_access_logs) { @@ -428,11 +446,13 @@ function getPictures($cacheid, $picturescount) // add personal cache info if user login to OC if ($usr == true) { - $notes_rs = XDb::xSql("SELECT `cache_notes`.`desc` `desc` FROM `cache_notes` - WHERE `cache_notes` .`user_id`= ? AND `cache_notes`.`cache_id`= ? ", $usr['userid'], $r['cacheid']); - if ($cn = XDb::xFetchArray($notes_rs)) { - $thisline = str_replace('{personal_cache_note}', cleanup_text("

-- " . tr('search_gpxgc_02') . ": --
" . $cn['desc'] . "
"), $thisline); + $cacheNote = CacheNote::getNote($usr['userid'], $r['cacheid']); + + if (!empty($cacheNote)) { + $thisline = str_replace('{personal_cache_note}', + cleanup_text("

-- " . tr('search_gpxgc_02') . + ": --
" . $cacheNote . "
"), $thisline); } else { $thisline = str_replace('{personal_cache_note}', "", $thisline); } diff --git a/lib/search.gpxgc.inc.php b/lib/search.gpxgc.inc.php index 29ac25ab5b..556f390134 100644 --- a/lib/search.gpxgc.inc.php +++ b/lib/search.gpxgc.inc.php @@ -4,6 +4,7 @@ use Utils\Database\XDb; use Utils\Database\OcDb; +use lib\Objects\GeoCache\CacheNote; use lib\Objects\GeoCache\GeoCacheCommons; use lib\Objects\GeoCache\GeoCacheLog; @@ -301,13 +302,13 @@ function getPictures($cacheid, $picturescount) $thisline = str_replace('{shortdesc}', cleanup_text($r['short_desc']), $thisline); $thisline = str_replace('{desc}', xmlencode_text($logpw . $r['desc']), $thisline); if ($usr == true) { - $notes_rs = XDb::xSql( - "SELECT `cache_notes`.`desc` `desc` FROM `cache_notes` - WHERE `cache_notes` .`user_id`= ? AND `cache_notes`.`cache_id`= ? ", - $usr['userid'], $r['cacheid']); - if ($cn = XDb::xFetchArray($notes_rs)) { - $thisline = str_replace('{personal_cache_note}', cleanup_text("

-- " . cleanup_text(tr('search_gpxgc_02')) . ": --
" . $cn['desc'] . "
"), $thisline); + $cacheNote = CacheNote::getNote($usr['userid'], $r['cacheid']); + + if (!empty($cacheNote)) { + $thisline = str_replace('{personal_cache_note}', + cleanup_text("

-- " . cleanup_text(tr('search_gpxgc_02')) . + ": --
" . $cacheNote . "
"), $thisline); } else { $thisline = str_replace('{personal_cache_note}', "", $thisline); } diff --git a/lib/search.txt.inc.php b/lib/search.txt.inc.php index fde7d83cdf..ea7673fdef 100644 --- a/lib/search.txt.inc.php +++ b/lib/search.txt.inc.php @@ -9,6 +9,7 @@ use Utils\Database\OcDb; use Utils\Text\Rot13; use lib\Objects\GeoCache\GeoCacheCommons; +use lib\Objects\GeoCache\CacheNote; global $content, $bUseZip, $hide_coords, $usr, $lang, $dbcSearch; @@ -244,13 +245,13 @@ } if ($usr == true) { - $notes_rs = XDb::xSql( - "SELECT `cache_notes`.`desc` `desc` FROM `cache_notes` - WHERE `cache_notes` .`user_id`= ? AND `cache_notes`.`cache_id`= ? ", - $usr['userid'], $r['cacheid']); - if ( $cn = XDb::xFetchArray($notes_rs) ) { - $thisline = str_replace('{personal_cache_note}', html2txt("

-- ".tr('search_text_16')." --
".$cn['desc']."
"), $thisline); + $cacheNote = CacheNote::getNote($usr['userid'], $r['cacheid']); + + if ( !empty($cacheNote) ) { + $thisline = str_replace('{personal_cache_note}', + html2txt("

-- ".tr('search_text_16')." --
". + $cacheNote . "
"), $thisline); } else { $thisline = str_replace('{personal_cache_note}', "", $thisline); } diff --git a/mycache_notes.php b/mycache_notes.php deleted file mode 100644 index 2fbe10dc65..0000000000 --- a/mycache_notes.php +++ /dev/null @@ -1,227 +0,0 @@ -multiVariableQuery($query, $note_id, $userid); - } - if (isset($_REQUEST["delete_coords"])) { - $coords_id = $_REQUEST["delete_coords"]; - //remove - $query = "DELETE FROM `cache_mod_cords` WHERE `id`=:1 AND `user_id`=:2"; - $db->multiVariableQuery($query, $coords_id, $userid); - } - //else - { - $query = " - SELECT `cache_notes`.`cache_id` `cacheid`, - `cache_notes`.`desc` `notes_desc`, - `caches`.`name` `cache_name`, - `cache_type`.`icon_small` `icon_large`, - `caches`.`type` `cache_type`, - `caches`.`cache_id` `cache_id`, - `caches`.`user_id` `user_id`, - note_id, - cl.text AS log_text, - cl.type AS log_type, - cl.user_id AS luser_id, - cl.date AS log_date, - cl.deleted AS log_deleted, - log_types.icon_small AS icon_small, - user.username AS user_name, - cache_mod_cords.id as cache_mod_cords_id, - cache_mod_cords.longitude, - cache_mod_cords.latitude - FROM - `cache_notes` - INNER JOIN `caches` ON (`cache_notes`.`cache_id`=`caches`.`cache_id`) - INNER JOIN cache_type ON (caches.type = cache_type.id) - left outer JOIN cache_logs as cl ON (caches.cache_id = cl.cache_id) - left outer JOIN log_types ON (cl.type = log_types.id) - left outer JOIN user ON (cl.user_id = user.user_id) - left outer JOIN cache_mod_cords ON ( - cache_mod_cords.user_id = cache_notes.user_id - AND cache_mod_cords.cache_id = cache_notes.cache_id - ) - WHERE - `cache_notes`.`user_id`=:1 - AND `cache_type`.`id`=`caches`.`type` - AND - ( cl.id is null or cl.id = - ( SELECT id - FROM cache_logs cl_id - WHERE cl.cache_id = cl_id.cache_id and cl_id.date = - - ( SELECT max( cache_logs.date ) - FROM cache_logs - WHERE cl.cache_id = cache_id - ) - limit 1 - )) - GROUP BY `cacheid` - UNION - SELECT `cache_mod_cords`.`cache_id` `cacheid`, - `cache_notes`.`desc` `notes_desc`, - `caches`.`name` `cache_name`, - `cache_type`.`icon_small` `icon_large`, - `caches`.`type` `cache_type`, - `caches`.`cache_id` `cache_id`, - `caches`.`user_id` `user_id`, - note_id, - cl.text AS log_text, - cl.type AS log_type, - cl.user_id AS luser_id, - cl.date AS log_date, - cl.deleted AS log_deleted, - log_types.icon_small AS icon_small, - user.username AS user_name, - cache_mod_cords.id as cache_mod_cords_id, - cache_mod_cords.longitude, - cache_mod_cords.latitude - FROM - cache_mod_cords - INNER JOIN `caches` ON (`cache_mod_cords`.`cache_id`=`caches`.`cache_id`) - INNER JOIN cache_type ON (caches.type = cache_type.id) - left outer JOIN cache_logs as cl ON (caches.cache_id = cl.cache_id) - left outer JOIN log_types ON (cl.type = log_types.id) - left outer JOIN user ON (cl.user_id = user.user_id) - left outer JOIN cache_notes ON ( - cache_notes.user_id = cache_mod_cords.user_id - AND cache_notes.cache_id = cache_mod_cords.cache_id - ) - WHERE - `cache_mod_cords`.`user_id`=:1 - AND `cache_type`.`id`=`caches`.`type` - AND - ( cl.id is null or cl.id = - ( SELECT id - FROM cache_logs cl_id - WHERE cl.cache_id = cl_id.cache_id and cl_id.date = - - ( SELECT max( cache_logs.date ) - FROM cache_logs - WHERE cl.cache_id = cache_id - ) - limit 1 - )) - GROUP BY `cacheid` - ORDER BY `cache_name`, log_date DESC"; - $s = $db->multiVariableQuery($query, $userid); - - $count = $db->rowCount($s); - if ($count != 0) { - $notes = ""; - $bgcolor1 = '#ffffff'; - $bgcolor2 = '#eeeeee'; - - for ($i = 0; $i < $count; $i++) { - $bgcolor = ( $i % 2 ) ? $bgcolor1 : $bgcolor2; - - $notes_record = $db->dbResultFetch($s); - $cacheicon = myninc::checkCacheStatusByUser($notes_record, $usr['userid']); - - $user_coords = ' '; - if ($notes_record['latitude'] != null && $notes_record['longitude'] != null) { - $user_coords = mb_ereg_replace(" ", " ", htmlspecialchars(help_latToDegreeStr($notes_record['latitude'], 1), ENT_COMPAT, 'UTF-8')) . ' ' . mb_ereg_replace(" ", " ", htmlspecialchars(help_lonToDegreeStr($notes_record['longitude'], 1), ENT_COMPAT, 'UTF-8')); - $user_coords.= ' '; - } - - $delete_user_note = ' '; - if ($notes_record['notes_desc'] != null) { - $delete_user_note = ''; - } - - $notes .= ' - - ' . $notes_record['cache_name'] . ' -   - ' . $user_coords . ' - {lastfound} - {iconimage} - ' . $delete_user_note . ''; - $icon_img = ''; - $notes = mb_ereg_replace('{bgcolor}', $bgcolor, $notes); - $notes = mb_ereg_replace('{cacheid}', $notes_record["cacheid"], $notes); - $notes = mb_ereg_replace('{noteid}', $notes_record["note_id"], $notes); - if ($notes_record['log_date'] == NULL || $notes_record['log_date'] == '0000-00-00 00:00:00') { - $notes = mb_ereg_replace('{lastfound}', htmlspecialchars($no_found_date, ENT_COMPAT, 'UTF-8'), $notes); - } else { - $notes = mb_ereg_replace('{lastfound}', htmlspecialchars(strftime( - $GLOBALS['config']['dateformat'], strtotime($notes_record['log_date'])), ENT_COMPAT, 'UTF-8'), $notes); - }; - - if ($notes_record["log_deleted"] == 1) { // if last record is deleted change icon and text - $log_text = tr('vl_Record_deleted'); - $notes_record['icon_small'] = "log/16x16-trash.png"; - } else { - $log_text = CleanSpecChars($notes_record['log_text'], 1); - }; - - - if ($notes_record['log_type'] == 12 && !$usr['admin']) { - $notes_record['user_id'] = '0'; - $notes_record['user_name'] = $tr_COG; - }; - - - $log_text = "" . $notes_record['user_name'] . ":
" . $log_text; - $notes_text = CleanSpecChars($notes_record['notes_desc'], 1); - $notes = mb_ereg_replace('{notes_text}', $notes_text, $notes); - if ($notes_record['icon_small'] != '') { - $icon_img = mb_ereg_replace('{icon_name}', $notes_record['icon_small'], $icon_img); - $icon_img = mb_ereg_replace('{log_text}', $log_text, $icon_img); - } else { - $icon_img = ' '; - } - $notes = mb_ereg_replace('{iconimage}', $icon_img, $notes); - } - - - tpl_set_var('notes_content', $notes); - } else { - tpl_set_var('notes_content', '
  ' . tr('no_note') . '

'); - } - } - unset($db); - } -} - -tpl_BuildTemplate(); diff --git a/mylist.php b/mylist.php index b3acc4cdde..08f2ec8071 100644 --- a/mylist.php +++ b/mylist.php @@ -1,91 +1,74 @@ paramQuery($mod_coord_q, $params); - Unset($params); - - if ($dbc->rowCount($stmt) > 0) { - $tmp_list = str_replace('{mod_suffix}', '[F]', $tmp_list); - } else { - $tmp_list = str_replace('{mod_suffix}', '', $tmp_list); - } - } else { - $tmp_list = str_replace('{mod_suffix}', '', $tmp_list); - }; - - - $tmp_list = mb_ereg_replace('{cachename}', htmlspecialchars($record['name'], ENT_COMPAT, 'UTF-8'), $tmp_list); - if ($record['last_found'] == NULL || $record['last_found'] == '0000-00-00 00:00:00') { - $tmp_list = mb_ereg_replace('{lastfound}', htmlspecialchars($no_found_date, ENT_COMPAT, 'UTF-8'), $tmp_list); - } else { - $tmp_list = mb_ereg_replace('{lastfound}', htmlspecialchars(strftime( - $GLOBALS['config']['dateformat'], strtotime($record['last_found'])), ENT_COMPAT, 'UTF-8'), $tmp_list); - } - - $tmp_list = mb_ereg_replace('{urlencode_cacheid}', htmlspecialchars(urlencode($record['cache_id']), ENT_COMPAT, 'UTF-8'), $tmp_list); - $tmp_list = mb_ereg_replace('{cacheid}', htmlspecialchars($record['cache_id'], ENT_COMPAT, 'UTF-8'), $tmp_list); - - $list .= $tmp_list . "\n"; - } - - unset($dbc); + $tmp_list = mb_ereg_replace('{lastfound}', htmlspecialchars(strftime( + $GLOBALS['config']['dateformat'], strtotime($record['last_found'])), ENT_COMPAT, 'UTF-8'), $tmp_list); + } + $tmp_list = mb_ereg_replace('{urlencode_cacheid}', htmlspecialchars(urlencode($record['cache_id']), ENT_COMPAT, 'UTF-8'), $tmp_list); + $tmp_list = mb_ereg_replace('{cacheid}', htmlspecialchars($record['cache_id'], ENT_COMPAT, 'UTF-8'), $tmp_list); - tpl_set_var('list', $list); - tpl_set_var('print_delete_list', $print_delete_list); - tpl_set_var('export_list', $export_list); - } + $list .= $tmp_list . "\n"; } + + tpl_set_var('list', $list); + tpl_set_var('print_delete_list', $print_delete_list); + tpl_set_var('export_list', $export_list); } //make the template and send it out tpl_BuildTemplate(); -?> + diff --git a/myroutes_search.php b/myroutes_search.php index e8503e12cb..b1043c1c11 100644 --- a/myroutes_search.php +++ b/myroutes_search.php @@ -5,6 +5,7 @@ use lib\Objects\GeoCache\GeoCacheCommons; use okapi\Facade; use okapi\core\Exception\BadRequest; +use lib\Objects\GeoCache\CacheNote; global $rootpath; @@ -772,22 +773,25 @@ // create cache list $caches_list = caches_along_route($route_id, $distance); - $q = ("SELECT - `caches`.`cache_id` `cache_id`, - `caches`.`wp_oc` `cache_wp`, - `caches`.`status` `status`, - `caches`.`type` `type`, - `caches`.`size` `size`, - IFNULL(`cache_mod_cords`.`longitude`, `caches`.`longitude`) `longitude`, - IFNULL(`cache_mod_cords`.`latitude`, `caches`.`latitude`) `latitude`, - IFNULL(cache_mod_cords.id,0) as cache_mod_cords_id, - `caches`.`user_id` `user_id` , - `caches`.`votes` `votes`, - `caches`.`score` `score`, - `caches`.`topratings` `topratings` - FROM `caches` - LEFT JOIN `cache_mod_cords` ON `caches`.`cache_id` = `cache_mod_cords`.`cache_id` AND `cache_mod_cords`.`user_id` = " . $usr['userid'] . " - WHERE `caches`.`wp_oc` IN ('" . implode("', '", $caches_list) . "') AND `caches`.`cache_id` IN (" . $qFilter . ")"); + $q = ( + "SELECT + `caches`.`cache_id` `cache_id`, + `caches`.`wp_oc` `cache_wp`, + `caches`.`status` `status`, + `caches`.`type` `type`, + `caches`.`size` `size`, + IFNULL(`cache_mod_cords`.`longitude`, `caches`.`longitude`) `longitude`, + IFNULL(`cache_mod_cords`.`latitude`, `caches`.`latitude`) `latitude`, + IF(cache_mod_cords.cache_id, 1, 0) AS cache_mod_cords_used, + `caches`.`user_id` `user_id` , + `caches`.`votes` `votes`, + `caches`.`score` `score`, + `caches`.`topratings` `topratings` + FROM `caches` + LEFT JOIN `cache_mod_cords` ON `caches`.`cache_id` = `cache_mod_cords`.`cache_id` + AND `cache_mod_cords`.`user_id` = " . $usr['userid'] . " + WHERE `caches`.`wp_oc` IN ('" . implode("', '", $caches_list) . "') + AND `caches`.`cache_id` IN (" . $qFilter . ")"); // cleanup (old gpxcontent lingers if gpx-download is cancelled by user) XDb::xSql('DROP TEMPORARY TABLE IF EXISTS `gpxcontent`'); @@ -830,7 +834,7 @@ $stmt = XDb::xSql( 'SELECT `gpxcontent`.`cache_id` `cacheid`, `gpxcontent`.`longitude` `longitude`, - `gpxcontent`.`latitude` `latitude`, `gpxcontent`.cache_mod_cords_id, + `gpxcontent`.`latitude` `latitude`, `gpxcontent`.cache_mod_cords_used, `caches`.`wp_oc` `waypoint`, `caches`.`date_hidden` `date_hidden`, `caches`.`picturescount` `picturescount`, `caches`.`name` `name`, `caches`.`country` `country`, `caches`.`terrain` `terrain`, @@ -891,7 +895,7 @@ $thisline = str_replace('{region}', $region, $thisline); // modified coords - if ($r['cache_mod_cords_id'] > 0) { // check if we have user coords + if ($r['cache_mod_cords_used'] > 0) { // check if we have user coords $thisline = str_replace('{mod_suffix}', '(F)', $thisline); } else { $thisline = str_replace('{mod_suffix}', '', $thisline); @@ -907,13 +911,14 @@ $thisline = str_replace('{shortdesc}', cleanup_text($r['short_desc']), $thisline); $thisline = str_replace('{desc}', cleanup_text($logpw . $r['desc']), $thisline); if ($usr == true) { - $notes_rs = XDb::xSql( - "SELECT `cache_notes`.`desc` `desc` FROM `cache_notes` - WHERE `cache_notes` .`user_id`= ? AND `cache_notes`.`cache_id`= ? ", - $usr['userid'], $r['cacheid']); - if ($cn = XDb::xFetchArray($notes_rs)) { - $thisline = str_replace('{personal_cache_note}', cleanup_text("

-- " . cleanup_text(tr('search_gpxgc_02')) . ": --
" . $cn['desc'] . "
"), $thisline); + $cacheNote = CacheNote::getNote($usr['userid'], $r['cacheid']); + + if ( !empty($cacheNote) ) { + + $thisline = str_replace('{personal_cache_note}', + cleanup_text("

-- " . cleanup_text(tr('search_gpxgc_02')) . + ": --
" . $cacheNote . "
"), $thisline); } else { $thisline = str_replace('{personal_cache_note}', "", $thisline); } diff --git a/powerTrail/ajaxAddCacheToPt.php b/powerTrail/ajaxAddCacheToPt.php index ef490f5d22..f1f5277557 100644 --- a/powerTrail/ajaxAddCacheToPt.php +++ b/powerTrail/ajaxAddCacheToPt.php @@ -5,6 +5,7 @@ use Utils\Database\XDb; use lib\Objects\Coordinates\Altitude; use lib\Objects\Coordinates\Coordinates; +use Utils\Generators\TextGen; /** * ajaxAddCacheToPt.php @@ -287,7 +288,7 @@ function isCacheCanditate($ptId, $cacheId) function addCacheToCacheCandidate($cacheId, $ptId) { - $linkCode = randomPassword(50); + $linkCode = TextGen::randomText(50); $db = OcDb::instance(); $db->multiVariableQuery( @@ -300,14 +301,4 @@ function addCacheToCacheCandidate($cacheId, $ptId) exit; } -function randomPassword($passLenght) -{ - $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789"; - $pass = array(); - $alphaLength = strlen($alphabet) - 1; - for ($i = 0; $i < $passLenght; $i++) { - $n = rand(0, $alphaLength); - $pass[] = $alphabet[$n]; - } - return implode($pass); //turn the array into a string -} + diff --git a/search.php b/search.php index 1e11271c79..3a44cb65da 100644 --- a/search.php +++ b/search.php @@ -727,16 +727,17 @@ function sanitize(&$array) $max_lon_diff = $distance * 180 / (abs(sin((90 - $lat) * 3.14159 / 180 )) * 6378 * $multiplier[$distance_unit] * 3.14159); $sqlstr = 'CREATE TEMPORARY TABLE result_caches ENGINE=MEMORY - SELECT - (' . getCalcDistanceSqlFormula($usr !== false,$lon, $lat, $distance, $multiplier[$distance_unit]) . ') `distance`, - `caches`.`cache_id` `cache_id` - FROM `caches` FORCE INDEX (`latitude`) - LEFT JOIN `cache_mod_cords` ON `caches`.`cache_id` = `cache_mod_cords`.`cache_id` AND `cache_mod_cords`.`user_id` = :1 - WHERE IFNULL(cache_mod_cords.longitude, `caches`.`longitude`) > :2 - AND IFNULL(cache_mod_cords.longitude, `caches`.`longitude`) < :3 - AND IFNULL(cache_mod_cords.latitude, `caches`.`latitude`) > :4 - AND IFNULL(cache_mod_cords.latitude, `caches`.`latitude`) < :5 - HAVING `distance` < :6'; + SELECT + (' . getCalcDistanceSqlFormula($usr !== false,$lon, $lat, $distance, $multiplier[$distance_unit]) . ') `distance`, + `caches`.`cache_id` `cache_id` + FROM `caches` FORCE INDEX (`latitude`) + LEFT JOIN `cache_mod_cords` ON `caches`.`cache_id` = `cache_mod_cords`.`cache_id` + AND `cache_mod_cords`.`user_id` = :1 + WHERE IFNULL(cache_mod_cords.longitude, `caches`.`longitude`) > :2 + AND IFNULL(cache_mod_cords.longitude, `caches`.`longitude`) < :3 + AND IFNULL(cache_mod_cords.latitude, `caches`.`latitude`) > :4 + AND IFNULL(cache_mod_cords.latitude, `caches`.`latitude`) < :5 + HAVING `distance` < :6'; $dbcSearch->multiVariableQuery( $sqlstr, $usr['userid'], ($lon - $max_lon_diff), ($lon + $max_lon_diff), ($lat - $max_lat_diff), ($lat + $max_lat_diff), $distance ); @@ -838,11 +839,12 @@ function sanitize(&$array) (' . getCalcDistanceSqlFormula($usr !== false,$lon, $lat, $distance, $multiplier[$distance_unit]) . ') `distance`, `caches`.`cache_id` `cache_id` FROM `caches` FORCE INDEX (`latitude`) - LEFT JOIN `cache_mod_cords` ON `caches`.`cache_id` = `cache_mod_cords`.`cache_id` AND `cache_mod_cords`.`user_id` = :1 - WHERE IFNULL(cache_mod_cords.longitude, `caches`.`longitude`) > :2 - AND IFNULL(cache_mod_cords.longitude, `caches`.`longitude`) < :3 - AND IFNULL(cache_mod_cords.latitude, `caches`.`latitude`) > :4 - AND IFNULL(cache_mod_cords.latitude, `caches`.`latitude`) < :5 + LEFT JOIN `cache_mod_cords` ON `caches`.`cache_id` = `cache_mod_cords`.`cache_id` + AND `cache_mod_cords`.`user_id` = :1 + WHERE IFNULL(cache_mod_cords.longitude, `caches`.`longitude`) > :2 + AND IFNULL(cache_mod_cords.longitude, `caches`.`longitude`) < :3 + AND IFNULL(cache_mod_cords.latitude, `caches`.`latitude`) > :4 + AND IFNULL(cache_mod_cords.latitude, `caches`.`latitude`) < :5 HAVING `distance` < :6'; $dbcSearch->multiVariableQuery( $sqlstr, $usr['userid'], ($lon - $max_lon_diff), ($lon + $max_lon_diff), ($lat - $max_lat_diff), ($lat + $max_lat_diff), $distance ); diff --git a/sqlAlters/2018-01-23_myNotes_refactoring.sql b/sqlAlters/2018-01-23_myNotes_refactoring.sql new file mode 100644 index 0000000000..5cd3466c99 --- /dev/null +++ b/sqlAlters/2018-01-23_myNotes_refactoring.sql @@ -0,0 +1,43 @@ +-- 2018-01-23 +-- @author: kojoty + + +-- it is needed to remove all duplicates in cache_notes table +-- (for some number of caches there are more than one note created by user) +DROP TABLE IF EXISTS cache_notes_temp; +CREATE TABLE cache_notes_temp AS + SELECT * FROM cache_notes GROUP BY cache_id, user_id; + +ALTER TABLE `cache_notes_temp` ADD PRIMARY KEY( `cache_id`, `user_id` ); +ALTER TABLE `cache_notes_temp` ADD INDEX( `note_id` ); +ALTER TABLE `cache_notes_temp` ADD INDEX( `user_id` ); + + +ALTER TABLE cache_notes_temp COMMENT = 'User notes for geocaches'; +ALTER TABLE cache_notes_temp CHANGE `desc` `desc` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'User note for geocache'; + +DROP TABLE cache_notes; +RENAME TABLE cache_notes_temp TO cache_notes; + + +-- there should be also drop of note_id and desc_html columns but it needs OKAPI changes +-- I will change it separately + + +-- it is needed to remove all duplicates in cache_mod_cords table +-- (for some number of caches there are more than one note created by user) + +DROP TABLE IF EXISTS cache_mod_cords_temp; +CREATE TABLE cache_mod_cords_temp AS + SELECT `cache_id`,`user_id`,`date`,`longitude`,`latitude` + FROM cache_mod_cords GROUP BY cache_id, user_id; + +ALTER TABLE `cache_mod_cords_temp` ADD PRIMARY KEY( `cache_id`, `user_id`); +ALTER TABLE `cache_mod_cords_temp` CHANGE `user_id` `user_id` INT(11) NOT NULL AFTER `cache_id`; +ALTER TABLE `cache_mod_cords_temp` ADD INDEX( `user_id`); +ALTER TABLE `cache_mod_cords_temp` CHANGE `date` `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; + +ALTER TABLE cache_mod_cords_temp COMMENT = 'Custom coordinates of geocache set by user'; + +DROP TABLE cache_mod_cords; +RENAME TABLE cache_mod_cords_temp TO cache_mod_cords; diff --git a/tpl/stdstyle/cacheNotes/cacheNotes.css b/tpl/stdstyle/cacheNotes/cacheNotes.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tpl/stdstyle/cacheNotes/cacheNotes.js b/tpl/stdstyle/cacheNotes/cacheNotes.js new file mode 100644 index 0000000000..8885ee34e1 --- /dev/null +++ b/tpl/stdstyle/cacheNotes/cacheNotes.js @@ -0,0 +1,54 @@ + +function removeNote(icon, cacheId){ + + var jQueryIcon = $(icon); + + jQueryIcon.attr("src", "tpl/stdstyle/images/loader/spinning-circles.svg"); + jQueryIcon.attr("title", ""); + + $.ajax({ + type: "get", + cache: false, + url: "/cacheNotes/removeNote/"+cacheId, + error: function (xhr) { + + console.log("removeNote resp: " + xhr.responseText); + + jQueryIcon.attr("src", "images/redcross.gif"); + jQueryIcon.attr("title", ""); + }, + success: function (data, status) { + + jQueryIcon.attr("src", "/images/ok.gif"); + jQueryIcon.attr("title", ""); + } + }); + + +} + +function removeCoords(icon, cacheId){ + + var jQueryIcon = $(icon); + + jQueryIcon.attr("src", "tpl/stdstyle/images/loader/spinning-circles.svg"); + jQueryIcon.attr("title", ""); + + $.ajax({ + type: "get", + cache: false, + url: "/cacheNotes/removeCoords/"+cacheId, + error: function (xhr) { + + console.log("removedModCoords: " + xhr.responseText); + + jQueryIcon.attr("src", "images/redcross.gif"); + jQueryIcon.attr("title", ""); + }, + success: function (data, status) { + + jQueryIcon.attr("src", "/images/ok.gif"); + jQueryIcon.attr("title", ""); + } + }); +} diff --git a/tpl/stdstyle/cacheNotes/cacheNotes.tpl.php b/tpl/stdstyle/cacheNotes/cacheNotes.tpl.php new file mode 100644 index 0000000000..28765be8bb --- /dev/null +++ b/tpl/stdstyle/cacheNotes/cacheNotes.tpl.php @@ -0,0 +1,20 @@ + +
+ +
+ +
+ + rowCount > 0) { ?> +
+ callChunk('listOfCaches/listOfCaches', $view->listCacheModel);?> +
+ cachesCount == 0 ?> +
+ +
+ cachesCount == 0 ?> + +
+ + diff --git a/tpl/stdstyle/chunks/listOfCaches/cacheLastLogColumn.tpl.php b/tpl/stdstyle/chunks/listOfCaches/cacheLastLogColumn.tpl.php index 8cadba694f..3e0c35b049 100644 --- a/tpl/stdstyle/chunks/listOfCaches/cacheLastLogColumn.tpl.php +++ b/tpl/stdstyle/chunks/listOfCaches/cacheLastLogColumn.tpl.php @@ -28,18 +28,18 @@ $logTypeName = GeoCacheLogCommons::cleanLogTextForToolTip( tr(GeoCacheLogCommons::typeTranslationKey($data['logType']))); } - ?> - + LogIcon +
+ (): +
+
diff --git a/tpl/stdstyle/chunks/listOfCaches/cacheTypeIconColumn.tpl.php b/tpl/stdstyle/chunks/listOfCaches/cacheTypeIconColumn.tpl.php index 74f4110592..8d530f2e8c 100644 --- a/tpl/stdstyle/chunks/listOfCaches/cacheTypeIconColumn.tpl.php +++ b/tpl/stdstyle/chunks/listOfCaches/cacheTypeIconColumn.tpl.php @@ -3,14 +3,14 @@ use lib\Objects\GeoCache\GeoCacheCommons; use lib\Objects\GeoCache\GeoCacheLogCommons; -/** - This is column with cache icon. - $date arg needs to contains: - - type - type of teh cache (for example multi or virtual) - - status - status of the cache (for example temp-unavailable or archived - - user_sts - status for current user - for example found or not found etc. -*/ - +/** + * This is column with cache icon. + * + * $date arg needs to contains: + * - type - type of the cache (for example multi or virtual) + * - status - status of the cache (for example temp-unavailable or archived + * - user_sts - status for current user - for example found or not found etc. + */ return function (array $data){ diff --git a/tpl/stdstyle/chunks/listOfCaches/ellipsedTextColumn.tpl.php b/tpl/stdstyle/chunks/listOfCaches/ellipsedTextColumn.tpl.php new file mode 100644 index 0000000000..8509a100d1 --- /dev/null +++ b/tpl/stdstyle/chunks/listOfCaches/ellipsedTextColumn.tpl.php @@ -0,0 +1,58 @@ +addColumn( + * new Column_EllipsedText( + * tr('columnTitle'), + * function($row){ + * return [ + * 'text' => ' '' + * ]; + * } + * ) + * ); + * + */ + +return function ($data){ + + if( strlen($data['text']) > $data['maxChars'] ){ + //trim the text + $text = substr($data['text'], 0, $data['maxChars']).'...'; + $fullText = $data['text']; + }else{ + $text = $data['text']; + $fullText = ''; + } + + $popupId = 'elipsed_'.TextGen::randomText(12); +?> + + + +
+ + + +
+ + +
+
+
+
+
+
+ + - - isHeaderEnabled()) { ?> @@ -44,7 +40,7 @@ getRows() as $row){ ?> getColumns() as /** @var AbstractColumn */ $column){ ?> - diff --git a/tpl/stdstyle/chunks/listOfCaches/onClickActionIconColumn.tpl.php b/tpl/stdstyle/chunks/listOfCaches/onClickActionIconColumn.tpl.php index 6a33c7fe45..b10fbd5547 100644 --- a/tpl/stdstyle/chunks/listOfCaches/onClickActionIconColumn.tpl.php +++ b/tpl/stdstyle/chunks/listOfCaches/onClickActionIconColumn.tpl.php @@ -1,15 +1,20 @@ <?=$data['title']?> diff --git a/tpl/stdstyle/chunks/listOfCaches/simpleTextColumn.tpl.php b/tpl/stdstyle/chunks/listOfCaches/simpleTextColumn.tpl.php index ff0effa3ed..a1a6551de3 100644 --- a/tpl/stdstyle/chunks/listOfCaches/simpleTextColumn.tpl.php +++ b/tpl/stdstyle/chunks/listOfCaches/simpleTextColumn.tpl.php @@ -1,7 +1,7 @@
- + +
+ callColumnChunk($row)?>