$db = \Utils\Database\OcDb::instance(); $projectId = $_REQUEST['projectId']; $userId = $_REQUEST['userId']; if (is_numeric($userId)) { $queryParam = ' user_id = '; } else { $queryParam = ' username LIKE '; } $query = 'SELECT user_id, username FROM user WHERE ' . $queryParam . ' :1 LIMIT 1'; $s = $db->multiVariableQuery($query, $userId); $userResult = $db->dbResultFetchOneRowOnly($s); $addQuery = "INSERT INTO `PowerTrail_owners`(`PowerTrailId`, `userId`, `privileages`) VALUES (:1,:2,:3)"; $db->multiVariableQuery($addQuery, $projectId, $userResult['user_id'], 1); $logQuery = 'INSERT INTO `PowerTrail_actionsLog`(`PowerTrailId`, `userId`, `actionDateTime`, `actionType`, `description`, `cacheId`) VALUES (:1,:2,NOW(),4,:3,:4)'; $db->multiVariableQuery($logQuery, $projectId, $_SESSION['user_id'], $ptAPI->logActionTypes[4]['type'] . ' new owner is: ' . $userResult['user_id'], $userResult['user_id']); $powerTrail = new \lib\Objects\PowerTrail\PowerTrail(array('id' => $projectId)); $ptOwners = displayPtOwnerList($powerTrail->getOwners()); echo $ptOwners; function displayPtOwnerList($ptOwners) { $ownerList = ''; foreach ($ptOwners as $user) { $ownerList .= '<a href="viewprofile.php?userid=' . $user->getUserId() . '">' . $user->getUsername() . '</a>'; if ($user->getUserId() != $_SESSION['user_id']) { $ownerList .= '<span style="display: none" class="removeUserIcon"><img onclick="ajaxRemoveUserFromPt(' . $user->getUserId() . ');" src="tpl/stdstyle/images/free_icons/cross.png" width=10 " /></span>, '; } else { $ownerList .= ', '; } } return substr($ownerList, 0, -2); }
} require_once __DIR__ . '/../lib/ClassPathDictionary.php'; $ptAPI = new powerTrailBase(); $db = \lib\Database\DataBaseSingleton::Instance(); $projectId = $_REQUEST['projectId']; $userId = $_REQUEST['userId']; //check if user is only one owner if (count(powerTrailBase::getPtOwners($projectId)) > 1 && $ptAPI::checkIfUserIsPowerTrailOwner($_SESSION['user_id'], $projectId) == 1) { $addQuery = 'DELETE FROM `PowerTrail_owners` WHERE `userId` = :1 AND `PowerTrailId` = :2'; $db->multiVariableQuery($addQuery, $userId, $projectId); $logQuery = 'INSERT INTO `PowerTrail_actionsLog`(`PowerTrailId`, `userId`, `actionDateTime`, `actionType`, `description`, `cacheId`) VALUES (:1,:2,NOW(),5,:3,:4)'; $db->multiVariableQuery($logQuery, $projectId, $_SESSION['user_id'], $ptAPI->logActionTypes[5]['type'] . ' removed owner is: ' . $userId, $userId); } $pt = new powerTrailController($_SESSION['user_id']); $pt->findPtOwners($projectId); $ptOwners = displayPtOwnerList($pt->getPtOwners()); // $result = json_encode($cacheCountResult); // sleep(5); echo $ptOwners; function displayPtOwnerList($ptOwners) { $ownerList = ''; foreach ($ptOwners as $userId => $user) { $ownerList .= '<a href="viewprofile.php?userid=' . $userId . '">' . $user['username'] . '</a>'; if ($userId != $_SESSION['user_id']) { $ownerList .= '<span style="display: none" class="removeUserIcon"><img onclick="ajaxRemoveUserFromPt(' . $userId . ');" src="tpl/stdstyle/images/free_icons/cross.png" width=10 /></span>, '; } else { $ownerList .= ', '; } } $ownerList = substr($ownerList, 0, -2);
tpl_set_var('removeCacheButtonDisplay', $removeCacheButtonDisplay); tpl_set_var('leadingUserId', $leadingUser['user_id']); tpl_set_var('leadingUserName', $leadingUser['username']); tpl_set_var('fullCountryMap', '0'); tpl_set_var('ptTypeName', tr($ptTypesArr[$powerTrail->getType()]['translate'])); tpl_set_var('displaySelectedPowerTrail', 'block'); tpl_set_var('powerTrailName', $powerTrail->getName()); tpl_set_var('powerTrailDescription', stripslashes(htmlspecialchars_decode($powerTrail->getDescription()))); tpl_set_var('displayPtDescriptionUserAction', displayPtDescriptionUserAction($powerTrail)); tpl_set_var('powerTrailDateCreated', $powerTrail->getDateCreated()->format($dateFormat)); tpl_set_var('powerTrailCacheCount', $powerTrail->getCacheCount()); tpl_set_var('powerTrailActiveCacheCount', $powerTrail->getActiveGeocacheCount()); tpl_set_var('powerTrailUnavailableCacheCount', $powerTrail->getUnavailableGeocacheCount()); tpl_set_var('powerTrailArchivedCacheCount', $powerTrail->getArchivedGeocacheCount()); tpl_set_var('powerTrailCacheLeft', $powerTrail->getCacheCount() - count($foundCachsByUser)); tpl_set_var('powerTrailOwnerList', displayPtOwnerList($powerTrail)); tpl_set_var('date', date($dateFormat)); tpl_set_var('powerTrailDemandPercent', $powerTrail->getPerccentRequired()); tpl_set_var('demandPercentMinimum', lib\Controllers\PowerTrailController::MINIMUM_PERCENT_REQUIRED); tpl_set_var('ptCommentsSelector', displayPtCommentsSelector('commentType', $powerTrail, null, $usr)); tpl_set_var('conquestCount', $powerTrail->getConquestedCount()); tpl_set_var('ptPoints', $powerTrail->getPoints()); tpl_set_var('cacheFound', count($foundCachsByUser)); tpl_set_var('powerTrailLogo', displayPowerTrailLogo($powerTrail->getId(), $powerTrail->getImage())); tpl_set_var('powerTrailserStats', displayPowerTrailserStats($powerTrail, $foundCachsByUser)); //map tpl_set_var('mapInit', 1); tpl_set_var('mapCenterLat', $powerTrail->getCenterCoordinates()->getLatitude()); tpl_set_var('mapCenterLon', $powerTrail->getCenterCoordinates()->getLongitude()); tpl_set_var('mapZoom', 11); tpl_set_var('ptList4map', "[" . $powerTrail->getCenterCoordinates()->getLatitude() . "," . $powerTrail->getCenterCoordinates()->getLongitude() . ",'" . tr('pt136') . "'],");