<?php
/**
* XS2:
*
* This file is developed by Solutecs, LLC for the purpose of the company
* and is provided together with XS2 Framework as and inherent part of the
* system. This file can be used on the terms of License Agreement.
*
* +7 (495) 585-0833 / 13 Rusakovskaya street, Moscow 107140 Russia
*
* @link http://www.solutecs.com
* @copyright ©1998-2007 Solutecs, LLC
* @package XS2-MODCOM
* @subpackage proc-photorating
* @version 1.XX
*/
// Опция $cookieVoteLifetime: срок (в секундах), после которого опять можно голосовать
$cookieVoteLifetime = 60*60*24;
$ratingScale = xs2GetNodes(array('NType'=>'score'));
$allPhotos = XSCore_indexArray(xs2GetNodes(array('NType'=>'photo')), 'NodId');
$voted = array_unique(array_filter(explode('.', $_COOKIE['voted'])));
if ($_POST['action']=='voteForm') {
unset($_POST['action']);
foreach($_POST as $option=>$score) {
$nodeId = (int)substr_replace($option, '', 0, 5);
if(!in_array($nodeId, $voted)) {
$allPhotos[$nodeId]['Total'] += $score;
++$allPhotos[$nodeId]['Votes'];
$allPhotos[$nodeId]['Rating'] = $allPhotos[$nodeId]['Total']/$allPhotos[$nodeId]['Votes'];
if(xs2UpdateNode(array('NodId' =>$nodeId,
'NType' =>'photo',
'Total'=>$allPhotos[$nodeId]['Total'],
'Rating'=>$allPhotos[$nodeId]['Rating'],
'Votes'=>$allPhotos[$nodeId]['Votes']))) {
array_push($voted, $nodeId);
}
}
}
}
foreach($voted as $nodeId) {
if($allPhotos[$nodeId])
$allPhotos[$nodeId]['_Voted'] = true;
};
if ($voted) setcookie('voted', join('.', $voted), time()+$cookieVoteLifetime, '/');
$_HTML->assign('ratingScale', $ratingScale);
$_HTML->assign('allPhotos', $allPhotos);
?>
|