Example #1
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;
}
        case PowerTrail::STATUS_CLOSED:
            // permannet Closure
            $commentType = 5;
            if (!$commentText) {
                $commentText = tr('pt218') . '!';
            }
            break;
        default:
            $commentType = 1;
            if (!$commentText) {
                $commentText = tr('pt056') . '!';
            }
            break;
    }
    // update geoPatch status
    $updateStatusResult = $powerTrail->setAndStoreStatus($newStatus);
    if ($updateStatusResult['updateStatusResult'] === true) {
        $db = OcDb::instance();
        // add comment
        $query = 'INSERT INTO `PowerTrail_comments`(`userId`, `PowerTrailId`, `commentType`, `commentText`, `logDateTime`, `dbInsertDateTime`, `deleted`) VALUES (:1, :2, :3, :4, NOW(), NOW(), 0 )';
        $db->multiVariableQuery($query, (int) $usr['userid'], $powerTrailId, $commentType, $commentText);
        // add action log
        $logQuery = 'INSERT INTO `PowerTrail_actionsLog`(`PowerTrailId`, `userId`, `actionDateTime`, `actionType`, `description`, `cacheId`) VALUES (:1,:2,NOW(),6,:3,:4)';
        $db->multiVariableQuery($logQuery, $powerTrailId, (int) $usr['userid'], $ptAPI->logActionTypes[6]['type'], 0);
    }
} else {
    $updateStatusResult = array('updateStatusResult' => false, 'message' => tr('pt241'));
}
$updateStatusResult['currentStatus'] = $powerTrail->getStatus();
$updateStatusResult['currentStatusTranslation'] = $powerTrail->getStatusTranslation();
print json_encode($updateStatusResult);