public function actionGenerate($id)
 {
     $election = $this->loadModel($id);
     $oldtokens = Tokens::model()->findAll('election_id=:election_id', array(':election_id' => $id));
     foreach ($oldtokens as $oldtoken) {
         Votes::model()->deleteAll('token_id=:token_id', array(':token_id' => $oldtoken->id));
     }
     foreach ($election->seats() as $seat) {
         foreach ($seat->candidates() as $candidate) {
             $candidate->votescount = 0;
             $candidate->save();
         }
     }
     Tokens::model()->deleteAll('election_id=:election_id', array(':election_id' => $id));
     $tokens = array();
     for ($i = 0; $i < $election->voters_count; $i++) {
         $token = new Tokens();
         $token->election_id = $id;
         $token->token = $this->generatePassword();
         $prevtoken = Tokens::model()->findAll('token=:token', array(':token' => $token->token));
         while ($prevtoken) {
             $token->token = $this->generatePassword();
             $prevtoken = Tokens::model()->findAll('token=:token', array(':token' => $token->token));
         }
         $token->done_vote = 0;
         $token->save();
         $tokens[] = $token;
     }
     $this->redirect(array('Tokens/index', 'election_id' => $election->id));
 }
 public function actionGenerate($id)
 {
     $station = $this->loadModel($id);
     $election = Elections::model()->findAll();
     $oldtokens = Tokens::model()->findAll('station_id=:station_id', array(':station_id' => $id));
     foreach ($oldtokens as $oldtoken) {
         Votes::model()->deleteAll('token_id=:token_id', array(':token_id' => $oldtoken->id));
     }
     Tokens::model()->deleteAll('station_id=:station_id', array(':station_id' => $id));
     $tokens = array();
     for ($i = 0; $i < $station->voters_count; $i++) {
         $token = new Tokens();
         $token->election_id = $election[0]->id;
         $token->station_id = $id;
         $token->token = $this->generatePassword();
         $prevtoken = Tokens::model()->findAll('token=:token', array(':token' => $token->token));
         while ($prevtoken) {
             $token->token = $this->generatePassword();
             $prevtoken = Tokens::model()->findAll('token=:token', array(':token' => $token->token));
         }
         $token->done_vote = 0;
         $token->save();
         $tokens[] = $token;
     }
     $this->render('generate', array('election' => $election[0], 'tokens' => $tokens, 'station' => $station));
 }
 /**
  * Checking user authentication.
  *
  * @param  int $id
  * @return int | bool
  */
 private function checkAuth($id)
 {
     if (!Auth::guest()) {
         return Votes::where('image_id', $id)->where('user_id', Auth::user()->id)->count();
     } else {
         return false;
     }
 }
 /**
  * Mark notification as read.
  *
  * @return object Redirect
  */
 public function markNotification()
 {
     if (Input::get('user_id') === Auth::user()->id) {
         Votes::editNotification(Votes::find(Input::get('id')));
         return Redirect::route('notification_user')->with('status', 'alert-success')->with('message', 'Success! Marked notification as read.');
     } else {
         return Redirect::route('notification_user')->withErrors(array('error' => 'Error! Cannot mark notification as read.'));
     }
 }
Beispiel #5
0
 public static function getList()
 {
     $data = array();
     $site = $_SESSION['site'];
     if (Funcs::$uri[0] == ONESSA_DIR) {
         $site = $_SESSION['OneSSA']['site'];
     }
     $sql = 'SELECT id FROM {{votes}} WHERE parent=0 AND site=' . $site . ' ORDER BY num';
     $list = DB::GetAll($sql, 'id');
     foreach ($list as $item) {
         $data[] = Votes::getOne($item);
     }
     return $data;
 }
Beispiel #6
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Votes::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Beispiel #7
0
 public static function insertVote($imageId, $voteChoice)
 {
     return Votes::insert(array('user_id' => Auth::user()->id, 'image_id' => $imageId, 'vote' => $voteChoice, 'notification' => 1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()));
 }
 public static function checkIfVotedAnswer($users_id, $answer_id)
 {
     $vote = Votes::findFirst("users_id = '{$users_id}' AND answers_id = '{$answer_id}'");
     return $vote != false;
 }
Beispiel #9
0
 /**
  * Gets where this album ranks overall, for its year, and for its decade.  This is really just a wrapper.
  * @param int $GroupID GroupID of the album
  * @param int $Year Year it was released
  * @return array ('overall'=><overall rank>, 'year'=><rank for its year>, 'decade'=><rank for its decade>)
  */
 public static function get_ranking($GroupID, $Year)
 {
     $GroupID = (int) $GroupID;
     $Year = (int) $Year;
     if ($GroupID <= 0 || $Year <= 0) {
         return false;
     }
     return array('overall' => Votes::get_rank_all($GroupID), 'year' => Votes::get_rank_year($GroupID, $Year), 'decade' => Votes::get_rank_decade($GroupID, $Year));
 }
Beispiel #10
0
 public function actionVotes()
 {
     if ($_POST['voteType'] == 'like') {
         $model = new Votes();
         $model->question_id = $_POST['qId'];
         $model->user_id = $_POST['id'];
         $model->voter_id = Yii::app()->session['userId'];
         if ($_POST['id'] == Yii::app()->session['userId']) {
             echo "You cannot vote Your own question";
             die;
         }
         $rec = Votes::model()->findByAttributes(array('voter_id' => Yii::app()->session['userId']));
         if ($rec) {
             echo "You already vote this question";
             die;
         }
         if (Yii::app()->session['userId'] == "") {
             echo "You must have login to vote the question";
             die;
         }
         $model->status = 1;
         if ($model->save(false)) {
         }
     } else {
         $rec = Votes::model()->findByAttributes(array('voter_id' => Yii::app()->session['userId']));
         if ($rec) {
             echo "You already vote this question";
             die;
         }
         if ($_POST['id'] == Yii::app()->session['userId']) {
             echo "You cannot vote Your own question";
             die;
         }
         if (Yii::app()->session['userId'] == "") {
             echo "You must have login to vote the question";
             die;
         }
         $model = new Votes();
         $model->question_id = $_POST['qId'];
         $model->user_id = $_POST['id'];
         $model->status = 0;
         if ($model->save(false)) {
             // echo "dislike";
         }
     }
 }
Beispiel #11
0
<?php

$UserVotes = Votes::get_user_votes($LoggedUser['ID']);
$GroupVotes = Votes::get_group_votes($GroupID);
$TotalVotes = $GroupVotes['Total'];
$UpVotes = $GroupVotes['Ups'];
$DownVotes = $TotalVotes - $UpVotes;
$Voted = isset($UserVotes[$GroupID]) ? $UserVotes[$GroupID]['Type'] : false;
$Score = Votes::binomial_score($UpVotes, $TotalVotes);
?>
<div class="box" id="votes">
	<div class="head"><strong>Album Votes</strong></div>
	<div class="album_votes body">
		<span class="favoritecount tooltip" title="<?php 
echo $UpVotes . ($UpVotes == 1 ? ' upvote' : ' upvotes');
?>
"><span id="upvotes"><?php 
echo number_format($UpVotes);
?>
</span> <span class="vote_album_up">&and;</span></span>
		&nbsp; &nbsp;
		<span class="favoritecount tooltip" title="<?php 
echo $DownVotes . ($DownVotes == 1 ? ' downvote' : ' downvotes');
?>
"><span id="downvotes"><?php 
echo number_format($DownVotes);
?>
</span> <span class="vote_album_down">&or;</span></span>
		&nbsp; &nbsp;
		<span class="favoritecount" id="totalvotes"><?php 
echo number_format($TotalVotes);
Beispiel #12
0
 function del()
 {
     Votes::del(Funcs::$uri[3]);
     $this->redirect('/votes/');
 }
 /**
  * Notification query.
  *
  * @param  int $type
  * @return mixed
  */
 private function notification($type)
 {
     return Votes::where('user_id', '<>', Auth::user()->id)->where('notification', $type)->get();
 }
Beispiel #14
0
        ?>
&amp;authkey=<?php 
        echo $LoggedUser['AuthKey'];
        ?>
&amp;torrent_pass=<?php 
        echo $LoggedUser['torrent_pass'];
        ?>
" class="tooltip" title="Download">DL</a>
						| <a href="reportsv2.php?action=report&amp;id=<?php 
        echo $TorrentID;
        ?>
" class="tooltip" title="Report">RP</a> ]
					</span>
					<?php 
        echo "{$DisplayName}\n";
        Votes::vote_link($GroupID, isset($UserVotes[$GroupID]) ? $UserVotes[$GroupID]['Type'] : '');
        ?>
					<div class="tags"><?php 
        echo $TorrentTags->format('torrents.php?type=' . $Action . '&amp;userid=' . $UserID . '&amp;tags=');
        ?>
</div>
				</div>
			</td>
			<td class="nobr"><?php 
        echo time_diff($Time, 1);
        ?>
</td>
			<td class="number_column nobr"><?php 
        echo Format::get_size($Torrent['Size']);
        ?>
</td>
Beispiel #15
0
<?php

error_reporting(E_ALL);
include_once dirname(__FILE__) . '/index.php';
$obj = new Votes();
$title = !empty($_POST['title']) ? $_POST['title'] : '';
if (isset($_POST['type']) && $_POST['type'] == 'sendvote') {
    $num = !empty($_POST['ans']) ? $_POST['ans'] : '';
    if (empty($num) || empty($title)) {
        die('error');
    }
    $res = $obj->saveVote($title, $num);
    echo $res === false ? 'Ошибка' : 'Все ОК';
} else {
    if (empty($title)) {
        die('error');
    }
    $res = $obj->showResult($title);
    echo $res === false ? 'Ошибка' : $res;
}
 public function downAction()
 {
     $response = new ApiResponse();
     $value = -1;
     if ($this->request->isGet()) {
         $questions_id = $this->request->get('questions_id');
         $answers_id = $this->request->get('answers_id');
         $users_id = $this->request->get('users_id');
         if ($questions_id != null && $answers_id == null) {
             $question = Questions::findFirstById($questions_id);
             if ($question == false) {
                 $response->setResponseError('Question not found!');
                 return $response;
             } else {
                 if ($question->users_id != $users_id && !Votes::checkIfVotedQuestion($users_id, $questions_id)) {
                     $question->downvotes += 1;
                     if ($question->save() == false) {
                         $response->setResponseError($question->getMessages());
                         return $response;
                     }
                     $vote = new Votes();
                     $vote->id = uniqid();
                     $vote->questions_id = $questions_id;
                     $vote->users_id = $users_id;
                     $vote->value = $value;
                     if ($vote->save() == false) {
                         $response->setResponseError($vote->getMessages());
                         return $response;
                     } else {
                         $response->setResponseMessage("Create vote down {$vote->id} for question {$questions_id} successfully!");
                     }
                 } else {
                     $response->setResponseError('Cant re-vote or vote for yourself!');
                     return $response;
                 }
             }
         } else {
             if ($questions_id == null && $answers_id != null) {
                 $answer = Answers::findFirstById($answers_id);
                 if ($answer == false) {
                     $response->setResponseError('Answer not found!');
                     return $response;
                 } else {
                     if ($answer->users_id != $users_id && !Votes::checkIfVotedAnswer($users_id, $answers_id)) {
                         var_dump(Votes::checkIfVotedAnswer($users_id, $answers_id));
                         $answer->downvotes += 1;
                         if ($answer->save() == false) {
                             $response->setResponseError($answer->getMessages());
                             return $response;
                         }
                         $vote = new Votes();
                         $vote->id = uniqid();
                         $vote->answers_id = $answers_id;
                         $vote->users_id = $users_id;
                         $vote->value = $value;
                         if ($vote->save() == false) {
                             $response->setResponseError($vote->getMessages());
                             return $response;
                         } else {
                             $response->setResponseMessage("Create vote down {$vote->id} for answer {$answers_id} successfully!");
                         }
                     } else {
                         $response->setResponseError('Cant re-vote or vote for yourself!');
                         return $response;
                     }
                 }
             }
         }
     } else {
         $response->setResponseError('Wrong HTTP Method');
     }
     return $response;
 }
Beispiel #17
0
 public function updatecount()
 {
     $votes = Votes::model()->findAll(array("condition" => "candidate_id=" . $this->id));
     $this->votescount = count($votes);
     $duplicates = FixVotes::model()->findAll(array("condition" => "candidate_id=" . $this->id));
     $fixduplicate = 0;
     foreach ($duplicates as $duplicate) {
         $fixduplicate += $duplicate->votecount - 1;
     }
     $this->fixduplicate = $fixduplicate;
     $this->save(false);
 }
Beispiel #18
0
<?php

authorize();
$GroupID = $_REQUEST['groupid'];
if (!is_number($GroupID)) {
    echo 'Invalid Group';
    die;
}
// What groups has this guy voted?
$UserVotes = Votes::get_user_votes($LoggedUser['ID']);
// What are the votes for this group?
$GroupVotes = Votes::get_group_votes($GroupID);
$UserID = $LoggedUser['ID'];
if ($_REQUEST['do'] == 'vote') {
    if (isset($UserVotes[$GroupID]) || !check_perms('site_album_votes')) {
        echo 'noaction';
        die;
    }
    if ($_REQUEST['vote'] != 'up' && $_REQUEST['vote'] != 'down') {
        echo 'badvote';
        die;
    }
    $Type = $_REQUEST['vote'] == 'up' ? 'Up' : 'Down';
    // Update the two votes tables if needed
    $DB->query("\n\t\tINSERT IGNORE INTO users_votes (UserID, GroupID, Type)\n\t\tVALUES ({$UserID}, {$GroupID}, '{$Type}')");
    if ($DB->affected_rows() == 0) {
        echo 'noaction';
        die;
    }
    // Update the group's cache key
    $GroupVotes['Total'] += 1;
Beispiel #19
0
<?php

// Show the "This album is number x overall", etc. box for the "Music" category only
if ($GroupCategoryID == 1) {
    $Rankings = Votes::get_ranking($GroupID, $GroupYear);
    $LIs = '';
    // Display information for the return categories of get_ranking()
    $GroupDecade = $GroupYear - $GroupYear % 10;
    $names = array('overall' => '<a href="top10.php?type=votes">overall</a>', 'decade' => check_perms('site_advanced_top10') ? 'for the <a href="top10.php?advanced=1&amp;type=votes&amp;year1=' . $GroupDecade . '&amp;year2=' . ($GroupDecade + 9) . '">' . $GroupDecade . 's</a>' : 'for the ' . $GroupDecade . 's', 'year' => check_perms('site_advanced_top10') ? 'for <a href="top10.php?advanced=1&amp;type=votes&amp;year1=' . $GroupYear . '&amp;year2=">' . $GroupYear . '</a>' : "for {$GroupYear}");
    foreach ($names as $key => $text) {
        if ($Rank = $Rankings[$key]) {
            if ($Rank <= 10) {
                $Class = 'vr_top_10';
            } elseif ($Rank <= 25) {
                $Class = 'vr_top_25';
            } elseif ($Rank <= 50) {
                $Class = 'vr_top_50';
            }
            $LIs .= "<li id=\"vote_rank_{$key}\" class=\"{$Class}\">No. {$Rank} {$text}</li>";
        }
    }
    if ($LIs != '') {
        ?>
		<div class="box" id="votes_ranks">
			<div class="head"><strong><?php 
        echo SITE_NAME;
        ?>
 Favorites</strong></div>
			<div class="vote_charts body">
				<ul class="stats nobullet" id="vote_rankings">
					<?php 
Beispiel #20
0
            ?>
&amp;usetoken=1" class="tooltip" title="Use a FL Token" onclick="return confirm('Are you sure you want to use a freeleech token here?');">FL</a>
<?php 
        }
        ?>
						| <a href="reportsv2.php?action=report&amp;id=<?php 
        echo $TorrentID;
        ?>
" class="tooltip" title="Report">RP</a>
					</span>
					<strong><?php 
        echo $DisplayName;
        ?>
</strong>
<?php 
        Votes::vote_link($GroupID, $UserVote);
        ?>
					<div class="tags"><?php 
        echo $TorrentTags->format();
        ?>
</div>
				</td>
				<td class="number_column nobr"><?php 
        echo Format::get_size($Torrent['Size']);
        ?>
</td>
				<td class="number_column"><?php 
        echo number_format($Torrent['Snatched']);
        ?>
</td>
				<td class="number_column<?php 
 public function actionRating()
 {
     $this->retVal = new stdClass();
     $request = Yii::app()->request;
     if ($request->isPostRequest && isset($_POST)) {
         $ratingCriteria = new CDbCriteria();
         $ratingCriteria->select = "*";
         $ratingCriteria->condition = "teacher_id = " . StringHelper::filterString($_POST['teacher_id']);
         $rating = Votes::model()->findAll($ratingCriteria);
         $count = count($rating);
         $averageRatingScore = 0;
         $this->retVal->checkRatingStatus = 0;
         foreach ($rating as $rating) {
             $averageRatingScore += $rating["rating_score"];
             if ($rating->user_id == Yii::app()->session['user_id']) {
                 $this->retVal->checkRatingStatus = 1;
             }
         }
         if ($this->retVal->checkRatingStatus === 0) {
             $teacher = Teacher::model()->find(array('select' => '*', 'condition' => 'teacher_id = ' . StringHelper::filterString($_POST['teacher_id'])));
             $ratingScore = ($averageRatingScore + $_POST['rating_score']) / ($count + 1);
             $teacher->teacher_rate = round($ratingScore, 1);
             $teacher->save(FALSE);
             $vote = new Votes();
             $vote->teacher_id = StringHelper::filterString($_POST['teacher_id']);
             $vote->user_id = Yii::app()->session['user_id'];
             $vote->rating_score = StringHelper::filterString($_POST['rating_score']);
             $vote->save(FALSE);
             $this->retVal->count = $count + 1;
             $this->retVal->aver = round($ratingScore, 1);
             $this->retVal->score = round($ratingScore);
         } else {
             $this->retVal->message = "Bạn đã đánh giá thầy/cô này.";
         }
     }
     echo CJSON::encode($this->retVal);
     Yii::app()->end();
 }
Beispiel #22
0
| response will be issued if they are, which you may freely change.
|
*/
Route::filter('guest', function () {
    if (Auth::check()) {
        return Redirect::to('/');
    }
});
/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function () {
    if (Session::token() != Input::get('_token')) {
        throw new Illuminate\Session\TokenMismatchException();
    }
});
/**
 * Composer views
 */
View::composer('layouts.master', function ($view) {
    if (!Auth::guest()) {
        $view->with('notifications', Votes::where('user_id', '<>', Auth::user()->id)->where('notification', 1)->get());
    }
});
Beispiel #23
0
<?php 
    } else {
        ?>
						<span class="add_bookmark float_right">
							<a style="float: right;" href="#" id="bookmarklink_torrent_<?php 
        echo $GroupID;
        ?>
" class="brackets" onclick="Bookmark('torrent', <?php 
        echo $GroupID;
        ?>
, 'Remove bookmark'); return false;">Bookmark</a>
						</span>
<?php 
    }
    $VoteType = isset($UserVotes[$GroupID]['Type']) ? $UserVotes[$GroupID]['Type'] : '';
    Votes::vote_link($GroupID, $VoteType);
    ?>
						<div class="tags"><?php 
    echo $TorrentTags->format('torrents.php?taglist=', $Name);
    ?>
</div>
					</div>
				</td>
			</tr>
<?php 
    $LastRemasterYear = '-';
    $LastRemasterTitle = '';
    $LastRemasterRecordLabel = '';
    $LastRemasterCatalogueNumber = '';
    $LastMedia = '';
    $EditionID = 0;