Ejemplo n.º 1
0
<?php

use Utils\Database\OcDb;
$rootpath = __DIR__ . '/../';
require_once __DIR__ . '/../lib/common.inc.php';
$appContainer = lib\Objects\ApplicationContainer::Instance();
if ($appContainer->getLoggedUser() === false) {
    $loggedUserId = -9999;
} else {
    $loggedUserId = $appContainer->getLoggedUser()->getUserId();
}
$commentsArr = lib\Controllers\PowerTrailController::getEntryTypes();
$ptOwners = powerTrailBase::getPtOwners($_REQUEST['projectId']);
$paginateCount = powerTrailBase::commentsPaginateCount;
foreach ($ptOwners as $owner) {
    $ownersIdArray[] = $owner['user_id'];
}
$nextSearchStart = $_REQUEST['start'] + $_REQUEST['limit'];
$db = OcDb::instance();
$q = 'SELECT count(*) AS `count` FROM  `PowerTrail_comments`
    WHERE  `PowerTrailId` =:1 AND `deleted` = 0 ';
$s = $db->multiVariableQuery($q, $_REQUEST['projectId']);
$count = $db->dbResultFetchOneRowOnly($s);
$count = $count['count'];
$query = 'SELECT * FROM  `PowerTrail_comments`, `user` WHERE  `PowerTrailId` =:variable1 AND `deleted` = 0 AND `PowerTrail_comments`.`userId` = `user`.`user_id` ORDER BY  `logDateTime` DESC LIMIT :variable2 , :variable3   ';
$params['variable1']['value'] = (int) $_REQUEST['projectId'];
$params['variable1']['data_type'] = 'integer';
$params['variable2']['value'] = (int) $_REQUEST['start'];
$params['variable2']['data_type'] = 'integer';
$params['variable3']['value'] = (int) $_REQUEST['limit'];
$params['variable3']['data_type'] = 'integer';
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
 public static function emailOwners($ptId, $commentType, $commentDateTime, $commentText, $action, $commentOwnerId = false, $delReason = '')
 {
     /*ugly, but we need this values from common.inc.php*/
     global $watchlistMailfrom, $usr, $absolute_server_URI, $site_name, $siteDateFormat, $siteDateTimeFormat;
     $siteDateFormat = 'Y-m-d';
     $siteDateTimeFormat = 'Y-m-d H:i';
     $owners = powerTrailBase::getPtOwners($ptId);
     $commentTypes = lib\Controllers\PowerTrailController::getEntryTypes();
     $ptDbRow = powerTrailBase::getPtDbRow($ptId);
     //remove images
     $commentText = preg_replace("/<img[^>]+\\>/i", "", $commentText);
     $headers = 'MIME-Version: 1.0' . "\r\n";
     $headers .= 'Content-type: text/html; charset=UTF-8 ' . "\r\n";
     $headers .= "From: {$site_name} <" . $watchlistMailfrom . ">\r\n";
     $headers .= "Reply-To: " . $watchlistMailfrom . "\r\n";
     $mailbody = file_get_contents(dirname(__FILE__) . '/commentEmail.html');
     switch ($action) {
         case 'delComment':
             $subject = tr('pt131') . ' ' . $ptDbRow['name'];
             $mailbody = mb_ereg_replace('{commentAction}', tr('pt132'), $mailbody);
             $mailbody = mb_ereg_replace('{actionDesc}', tr('pt131'), $mailbody);
             $mailbody = mb_ereg_replace('{delReason}', $delReason, $mailbody);
             $mailbody = mb_ereg_replace('{pt153}', tr('pt153'), $mailbody);
             break;
         case 'newComment':
             $subject = tr('pt128') . ' ' . $ptDbRow['name'];
             $mailbody = mb_ereg_replace('{commentAction}', tr('pt127'), $mailbody);
             $mailbody = mb_ereg_replace('{actionDesc}', tr('pt128'), $mailbody);
             $mailbody = mb_ereg_replace('{delReason}', '', $mailbody);
             $mailbody = mb_ereg_replace('{pt153}', '', $mailbody);
             break;
         case 'editComment':
             $subject = tr('pt146') . ' ' . $ptDbRow['name'];
             $mailbody = mb_ereg_replace('{commentAction}', tr('pt147'), $mailbody);
             $mailbody = mb_ereg_replace('{actionDesc}', tr('pt146'), $mailbody);
             $mailbody = mb_ereg_replace('{delReason}', '', $mailbody);
             $mailbody = mb_ereg_replace('{pt153}', '', $mailbody);
             break;
     }
     if (!isset($usr['userid'])) {
         $usr['userid'] = -1;
     }
     if (!isset($usr['username'])) {
         $usr['username'] = '******';
     }
     $mailbody = mb_ereg_replace('{runwatch14}', tr('runwatch14'), $mailbody);
     $mailbody = mb_ereg_replace('{commentDateTime}', date($siteDateTimeFormat, strtotime($commentDateTime)), $mailbody);
     $mailbody = mb_ereg_replace('{userId}', $usr['userid'], $mailbody);
     $mailbody = mb_ereg_replace('{userName}', $usr['username'], $mailbody);
     $mailbody = mb_ereg_replace('{absolute_server_URI}', $absolute_server_URI, $mailbody);
     if (isset($commentTypes[$commentType]['translate'])) {
         $mailbody = mb_ereg_replace('{commentType}', tr($commentTypes[$commentType]['translate']), $mailbody);
     } else {
         $mailbody = mb_ereg_replace('{commentType}', '&nbsp', $mailbody);
     }
     $mailbody = mb_ereg_replace('{ptName}', $ptDbRow['name'], $mailbody);
     $mailbody = mb_ereg_replace('{ptId}', $ptId, $mailbody);
     $mailbody = mb_ereg_replace('{pt133}', tr('pt133'), $mailbody);
     $mailbody = mb_ereg_replace('{pt134}', tr('pt134'), $mailbody);
     $mailbody = mb_ereg_replace('{commentText}', htmlspecialchars_decode(stripslashes($commentText)), $mailbody);
     $mailbody = mb_ereg_replace('{addingCommentDateTime}', date($siteDateTimeFormat), $mailbody);
     $doNotSendEmailToCommentAuthor = false;
     foreach ($owners as $owner) {
         $to = $owner['email'];
         if ($owner['power_trail_email'] == 1) {
             mb_send_mail($to, $subject, $mailbody, $headers);
         }
         if ($commentOwnerId && $commentOwnerId == $owner["user_id"]) {
             $doNotSendEmailToCommentAuthor = true;
         }
     }
     if ($commentOwnerId && !$doNotSendEmailToCommentAuthor) {
         $userDetails = powerTrailBase::getUserDetails($commentOwnerId);
         if ($userDetails['power_trail_email']) {
             mb_send_mail($userDetails['email'], $subject, $mailbody, $headers);
         }
     }
     //for debug only
     //mb_send_mail('*****@*****.**', $subject, $mailbody, $headers);
 }