Example #1
0
function preparePtCaches(PowerTrail $powerTrail)
{
    $table = '<table ><tr bgcolor="#cccccc">' . ' <td>' . tr('pt036') . '</td>' . ' <td>' . tr('owner_label') . '</td>' . ' <td>' . tr('waypoint') . '</td>' . ' <td align="center">' . tr('cache') . '<br/>' . tr('number_founds') . '</td>' . ' <td>' . tr('pt210') . '</td>' . '</tr>';
    $color = '#eeeeff';
    /* @var $geocache GeoCache */
    foreach ($powerTrail->getGeocaches() as $geocache) {
        if ($color == '#eeffee') {
            $color = '#eeeeff';
        } else {
            $color = '#eeffee';
        }
        if ($geocache->getFounds() > 0) {
            $color = 'ffbbbb';
        }
        $table .= '<tr bgcolor="' . $color . '" id="tr' . $geocache->getCacheId() . '">
            <td>' . $geocache->getCacheName() . '</td>
            <td>' . $geocache->getOwner()->getUserName() . '</td>
            <td><a href="' . $geocache->getWaypointId() . '">' . $geocache->getWaypointId() . '</a></td>
            <td align="center">' . $geocache->getFounds() . '</td>
            <td align="center"><a href="javascript:void(0);" onclick="rmCache(' . $geocache->getCacheId() . ');" class="editPtDataButton">' . tr('pt130') . '</a> <img src="tpl/stdstyle/js/jquery_1.9.2_ocTheme/ptPreloader.gif"  style="display: none" id="rmCacheLoader' . $geocache->getCacheId() . '" /> </td>
        </tr>';
    }
    $table .= '</table>';
    return $table;
}
 /**
  * used to set geoPath status to inactive, when has too small amount of caches,
  * etc.
  */
 public function cleanPowerTrailsCronjob()
 {
     $getPtQuery = 'SELECT * FROM `PowerTrail` WHERE `status` =1';
     $db = OcDb::instance();
     $s = $db->simpleQuery($getPtQuery);
     $ptToClean = $db->dbResultFetchAll($s);
     foreach ($ptToClean as $dbRow) {
         $powerTrail = new PowerTrail(array('dbRow' => $dbRow));
         $powerTrail->setPowerTrailConfiguration($this->config)->checkCacheCount();
         if (!$powerTrail->disableUncompletablePt($this->serverUrl)) {
             $powerTrail->disablePowerTrailBecauseCacheCountTooLow();
         }
     }
     $this->archiveAbandonPowerTrails();
     $this->freeCacheCandidates();
 }
function displayAllCachesOfPowerTrail(\lib\Objects\PowerTrail\PowerTrail $powerTrail, $choseFinalCaches)
{
    isset($_SESSION['user_id']) ? $userId = $_SESSION['user_id'] : ($userId = -9999);
    $powerTrailCachesUserLogsByCache = $powerTrail->getFoundCachsByUser($userId);
    $geocacheFoundArr = array();
    foreach ($powerTrailCachesUserLogsByCache as $geocache) {
        $geocacheFoundArr[$geocache['geocacheId']] = $geocache;
    }
    if (count($powerTrail->getCacheCount()) == 0) {
        return '<br /><br />' . tr('pt082');
    }
    $statusIcons = array(1 => '/tpl/stdstyle/images/log/16x16-published.png', 2 => '/tpl/stdstyle/images/log/16x16-temporary.png', 3 => '/tpl/stdstyle/images/log/16x16-trash.png', 5 => '/tpl/stdstyle/images/log/16x16-need-maintenance.png');
    $statusDesc = array(1 => tr('pt141'), 2 => tr('pt142'), 3 => tr('pt143'), 5 => tr('pt144'));
    $cacheTypesIcons = cache::getCacheIconsSet();
    $cacheRows = '<table class="ptCacheTable" align="center" width="90%"><tr>
        <th>' . tr('pt075') . '</th>
        <th>' . tr('pt076') . '</th>';
    if ($choseFinalCaches) {
        $cacheRows .= '<th></th>';
    }
    $cacheRows .= '   <th>' . tr('pt077') . '</th>
        <th><img src="tpl/stdstyle/images/log/16x16-found.png" /></th>
        <th>' . tr('pt078') . '</th>
        <th><img src="images/rating-star.png" /></th>
    </tr>';
    $totalFounds = 0;
    $totalTopRatings = 0;
    $bgcolor = '#ffffff';
    $cachetypes = array(1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0);
    $cacheSize = array(2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0);
    unset($_SESSION['geoPathCacheList']);
    /* @var $geocache lib\Objects\GeoCache\GeoCache*/
    foreach ($powerTrail->getGeocaches() as $geocache) {
        $_SESSION['geoPathCacheList'][] = $geocache->getCacheId();
        $totalFounds += $geocache->getFounds();
        $totalTopRatings += $geocache->getRecommendations();
        $cachetypes[$geocache->getCacheType()]++;
        $cacheSize[$geocache->getSizeId()]++;
        // powerTrailController::debug($cache); exit;
        if ($bgcolor == '#eeeeff') {
            $bgcolor = '#ffffff';
        } else {
            $bgcolor = '#eeeeff';
        }
        if ($geocache->isIsPowerTrailFinalGeocache()) {
            $bgcolor = '#000000';
            $fontColor = '<font color ="#ffffff">';
        } else {
            $fontColor = '';
        }
        $cacheRows .= '<tr bgcolor="' . $bgcolor . '">';
        //display icon found/not found depend on current user
        if (isset($geocacheFoundArr[$geocache->getCacheId()])) {
            $cacheRows .= '<td align="center"><img src="' . $cacheTypesIcons[$geocache->getCacheType()]['iconSet'][1]['iconSmallFound'] . '" /></td>';
        } elseif ($geocache->getOwner()->getUserId() == $userId) {
            $cacheRows .= '<td align="center"><img src="' . $cacheTypesIcons[$geocache->getCacheType()]['iconSet'][1]['iconSmallOwner'] . '" /></td>';
        } else {
            $cacheRows .= '<td align="center"><img src="' . $cacheTypesIcons[$geocache->getCacheType()]['iconSet'][1]['iconSmall'] . '" /></td>';
        }
        //cachename, username
        $cacheRows .= '<td><b><a href="' . $geocache->getWaypointId() . '">' . $fontColor . $geocache->getCacheName() . '</b></a> (' . $geocache->getOwner()->getUserName() . ') ';
        if ($geocache->isIsPowerTrailFinalGeocache()) {
            $cacheRows .= '<span class="finalCache">' . tr('pt148') . '</span>';
        }
        $cacheRows .= '</td>';
        //chose final caches
        if ($choseFinalCaches) {
            if ($geocache->isIsPowerTrailFinalGeocache()) {
                $checked = 'checked = "checked"';
            } else {
                $checked = '';
            }
            $cacheRows .= '<td><span class="ownerFinalChoice"><input type="checkbox" id="fcCheckbox' . $geocache->getCacheId() . '" onclick="setFinalCache(' . $geocache->getCacheId() . ')" ' . $checked . ' /></span></td>';
        }
        //status
        $cacheRows .= '<td align="center"><img src="' . $statusIcons[$geocache->getStatus()] . '" title="' . $statusDesc[$geocache->getStatus()] . '"/></td>';
        //FoundCount
        $cacheRows .= '<td align="center">' . $fontColor . $geocache->getFounds() . '</td>';
        //score, toprating
        $cacheRows .= '<td align="center">' . ratings($geocache->getScore(), $geocache->getRatingVotes()) . '</td>';
        $cacheRows .= '<td align="center">' . $fontColor . $geocache->getRecommendations() . '</td>';
        '</tr>';
    }
    $cacheRows .= '
    <tr bgcolor="#efefff">
        <td></td>
        <td style="font-size: 9px;">' . tr('pt085') . '</td>
        <td></td>
        <td align="center" style="font-size: 9px;">' . $totalFounds . '</td>
        <td></td>
        <td align="center" style="font-size: 9px;">' . $totalTopRatings . '</td>
    </tr>
    </table>';
    $restCaches = $cachetypes[4] + $cachetypes[5] + $cachetypes[6] + $cachetypes[8] + $cachetypes[9] + $cachetypes[10];
    $countCaches = $powerTrail->getCacheCount();
    $restCachesPercent = round($restCaches * 100 / $countCaches);
    foreach ($cachetypes as $key => $value) {
        $cachePercent[$key] = round($value * 100 / $countCaches);
    }
    foreach ($cacheSize as $key => $value) {
        $cacheSizePercent[$key] = round($value * 100 / $countCaches);
    }
    $img = '<table align="center"><tr><td align=center width="50%">' . tr('pt107') . '<br /><img src="http://chart.apis.google.com/chart?chs=350x100&chd=t:' . $cachetypes[2] . ',' . $cachetypes[3] . ',' . $cachetypes[7] . ',' . $cachetypes[1] . ',' . $restCaches . '&cht=p3&chl=' . $cachetypes[2] . '|' . $cachetypes[3] . '|' . $cachetypes[7] . '|' . $cachetypes[1] . '|' . $restCaches . '&chco=00aa00|FFEB0D|0000cc|cccccc|eeeeee&&chdl=%20' . tr('pt108') . '%20(' . $cachePercent[2] . '%)|' . tr('pt109') . '%20(' . $cachePercent[3] . '%)|' . tr('pt110') . '%20(' . $cachePercent[7] . '%)|' . urlencode(tr('pt111')) . '%20(' . $cachePercent[1] . '%)|' . urlencode(tr('pt112')) . '%20(' . $restCachesPercent . '%)" /></td>';
    $img .= '<td align=center width="50%">' . tr('pt106') . '<br /><img src="http://chart.apis.google.com/chart?chs=350x100&chd=t:' . $cacheSize[2] . ',' . $cacheSize[3] . ',' . $cacheSize[4] . ',' . $cacheSize[5] . ',' . $cacheSize[6] . '&cht=p3&chl=%20' . $cacheSize[2] . '|' . $cacheSize[3] . '|' . $cacheSize[4] . '|' . $cacheSize[5] . '|' . $cacheSize[6] . '&chco=0000aa|00aa00|aa0000|aaaa00|00aaaa&&chdl=' . urlencode(tr('pt113')) . '%20(' . $cacheSizePercent[2] . '%)|' . urlencode(tr('pt114')) . '%20(' . $cacheSizePercent[3] . '%)|' . urlencode(tr('pt115')) . '%20(' . $cacheSizePercent[4] . '%)|' . urlencode(tr('pt116')) . '%20(' . $cacheSizePercent[5] . '%)|' . urlencode(tr('pt117')) . '%20(' . $cacheSizePercent[6] . '%)" /></td></tr></table><br /><br />';
    return $img . $cacheRows;
}
Example #4
0
 /**
  * Function to check if current cache is part of any PowerTrail.
  * On success PowerTrail object is created.
  *
  * @return boolean true if this cache belongs to any PowerTrail;
  */
 public function isPowerTrailPart()
 {
     if (!OcConfig::instance()->getPowerTrailModuleSwitchOn()) {
         return false;
     }
     if (is_null($this->isPowerTrailPart)) {
         $ptArr = PowerTrail::CheckForPowerTrailByCache($this->id);
         if (count($ptArr) > 0) {
             // TODO: ASSUMPTION: cache belongs to ONLY one PT
             $this->isPowerTrailPart = true;
             $this->powerTrail = new PowerTrail(array('dbRow' => $ptArr[0]));
         } else {
             $this->isPowerTrailPart = false;
         }
     }
     return $this->isPowerTrailPart;
 }
Example #5
0
function displayPtCommentsSelector($htmlid, \lib\Objects\PowerTrail\PowerTrail $powerTrail, $selectedId = 0, $usr = null)
{
    $appContainer = lib\Objects\ApplicationContainer::Instance();
    if ($appContainer->getLoggedUser() === false) {
        return '';
    }
    $cachesFoundByUser = $powerTrail->getFoundCachsByUser($appContainer->getLoggedUser()->getUserId());
    $percetDemand = $powerTrail->getPerccentRequired();
    $ptId = $powerTrail->getId();
    if ($powerTrail->getCacheCount() != 0) {
        $percentUserFound = round(count($cachesFoundByUser) * 100 / $powerTrail->getCacheCount(), 2);
    } else {
        $percentUserFound = 0;
    }
    $commentsArr = lib\Controllers\PowerTrailController::getEntryTypes();
    $ptOwners = powerTrailBase::getPtOwners($ptId);
    $selector = '<select id="' . $htmlid . '" name="' . $htmlid . '">';
    foreach ($commentsArr as $id => $type) {
        if ($id == 2) {
            if ($percentUserFound < $percetDemand || powerTrailBase::checkUserConquestedPt($appContainer->getLoggedUser()->getUserId(), $ptId) > 0) {
                continue;
            }
            $selected = 'selected="selected"';
        }
        if (!isset($ptOwners[$appContainer->getLoggedUser()->getUserId()]) && ($id == 3 || $id == 4 || $id == 5)) {
            continue;
        }
        if ($id == 3 && $powerTrail->canBeOpened() === false && $powerTrail->getStatus() != \lib\Objects\PowerTrail\PowerTrail::STATUS_OPEN) {
            /* this PT cannot be opened */
            continue;
        }
        if ($id === \lib\Objects\PowerTrail\Log::TYPE_ADD_WARNING && $appContainer->getLoggedUser()->getIsAdmin() === false) {
            continue;
        }
        if (!isset($selected)) {
            $selected = '';
        }
        if ($selectedId == $id) {
            $selected = 'selected';
        }
        $selector .= '<option value="' . $id . '" ' . $selected . '>' . tr($type['translate']) . '</option>';
        unset($selected);
    }
    $selector .= '</select>';
    return $selector;
}
<?php

use Utils\Database\OcDb;
use lib\Objects\PowerTrail\PowerTrail;
$rootpath = __DIR__ . '/../';
require_once __DIR__ . '/../lib/common.inc.php';
if (!isset($usr['userid'])) {
    print 'no hacking please!';
    exit;
}
$ptAPI = new powerTrailBase();
$powerTrailId = (int) $_REQUEST['projectId'];
$powerTrail = new lib\Objects\PowerTrail\PowerTrail(array('id' => $powerTrailId));
$newStatus = (int) $_REQUEST['newStatus'];
if (isset($_REQUEST['commentTxt'])) {
    $commentText = htmlspecialchars($_REQUEST['commentTxt']);
} else {
    $commentText = false;
}
// check if user is owner of selected power Trail
if ($ptAPI::checkIfUserIsPowerTrailOwner($usr['userid'], $powerTrailId) == 1 || isset($usr['admin']) && $usr['admin'] == 1) {
    switch ($newStatus) {
        case PowerTrail::STATUS_OPEN:
            // publish
            $commentType = 3;
            if (!$commentText) {
                $commentText = tr('pt215') . '!';
            }
            break;
        case PowerTrail::STATUS_INSERVICE:
            // in service
function displayPtCommentsSelector($htmlid, \lib\Objects\PowerTrail\PowerTrail $powerTrail, $selectedId = 0, $usr = null)
{
    $cachesFoundByUser = $powerTrail->getFoundCachsByUser($usr['userid']);
    $percetDemand = $powerTrail->getPerccentRequired();
    $ptId = $powerTrail->getId();
    if ($powerTrail->getCacheCount() != 0) {
        $percentUserFound = round(count($cachesFoundByUser) * 100 / $powerTrail->getCacheCount(), 2);
    } else {
        $percentUserFound = 0;
    }
    $commentsArr = powerTrailBase::getPowerTrailComments();
    $ptOwners = powerTrailBase::getPtOwners($ptId);
    $selector = '<select id="' . $htmlid . '" name="' . $htmlid . '">';
    foreach ($commentsArr as $id => $type) {
        if ($id == 2) {
            if ($percentUserFound < $percetDemand || powerTrailBase::checkUserConquestedPt($_SESSION['user_id'], $ptId) > 0) {
                continue;
            }
            $selected = 'selected="selected"';
        }
        if (!isset($ptOwners[$usr['userid']]) && ($id == 3 || $id == 4 || $id == 5)) {
            continue;
        }
        if (!isset($selected)) {
            $selected = '';
        }
        if ($selectedId == $id) {
            $selected = 'selected';
        }
        $selector .= '<option value="' . $id . '" ' . $selected . '>' . tr($type['translate']) . '</option>';
        unset($selected);
    }
    $selector .= '</select>';
    return $selector;
}