Ejemplo n.º 1
0
 public function actionThanks()
 {
     $this->layout = "vote";
     if (isset($_POST['election_id'])) {
         $chosen = Yii::app()->session['chosenones'];
         $donevote = true;
         if (isset($_POST['token_id'])) {
             $token = Tokens::model()->find('id=:token', array(':token' => $_POST['token_id']));
             if (!$token->done_vote) {
                 $token->done_vote = 1;
                 $token->date_vote = date('Y-m-d H:i');
                 $token->save();
                 $donevote = false;
             }
         }
         if (!$donevote) {
             $seats = Seats::model()->findAll(array("condition" => "election_id=" . $_POST['election_id'], "order" => "priority asc"));
             foreach ($seats as $seat) {
                 foreach ($chosen[$seat->id] as $candidate_id) {
                     $vote = new Votes();
                     $vote->token_id = $token->id;
                     $vote->candidate_id = $candidate_id;
                     $vote->save();
                 }
             }
         }
         $this->render('thanks', array('election' => Elections::model()->find('id=:election_id', array(':election_id' => $_POST['election_id']))));
     }
 }
Ejemplo n.º 2
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 = Seats::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Ejemplo n.º 3
0
 public function actionPrint()
 {
     $this->layout = 'blankback';
     if (isset($_GET['election_id'])) {
         $election = Elections::model()->findByPk($_GET['election_id']);
         $seats = Seats::model()->with(array('candidates.votes' => array('order' => 'candidates.name')))->findAll(array('condition' => 't.election_id=' . $_GET['election_id'], 'order' => 'priority asc'));
         $dataProvider = Tokens::model()->findAll(array('condition' => 'election_id=' . $_GET['election_id'], 'order' => 'token asc'));
     } else {
         $this->redirect('Elections/index');
     }
     $mPDF1 = Yii::app()->ePdf->mpdf();
     $mPDF1->WriteHTML($this->render('print', array('tokens' => $dataProvider, 'seats' => $seats, 'election' => $election), true));
     $mPDF1->Output('tokensaudit-' . $election->name . '.pdf', 'I');
 }
Ejemplo n.º 4
0
 public function actionResultform($id)
 {
     $this->layout = 'blankback';
     $seats = Seats::model()->with(array('candidates.votes' => array('order' => 'candidates.votescount desc')))->findAll(array('condition' => 't.election_id=' . $id, 'order' => 'priority asc'));
     $election = Elections::model()->with('tokens')->findByPk($id);
     $usedtokens = Tokens::model()->used($id)->findAll();
     $mPDF1 = Yii::app()->ePdf->mpdf();
     $mPDF1->WriteHTML($this->render('resultform', array('seats' => $seats, 'election' => $election, 'usedtokens' => $usedtokens), true));
     $mPDF1->Output('results-' . $election->name . '.pdf', 'I');
 }
Ejemplo n.º 5
0
<?php 
$form = $this->beginWidget('CActiveForm', array('id' => 'station-seat-form', 'enableAjaxValidation' => false));
?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php 
echo $form->errorSummary($model);
?>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'seat_id');
?>
		<?php 
echo $form->dropDownList($model, 'seat_id', CHtml::listData(Seats::model()->findAll(), 'id', 'name'), array('prompt' => 'Select a seat'));
?>
		<?php 
echo $form->error($model, 'seat_id');
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'station_id');
?>
		<?php 
echo $form->dropDownList($model, 'station_id', CHtml::listData(Stations::model()->findAll(), 'id', 'name'), array('prompt' => 'Select a station'));
?>
		<?php 
echo $form->error($model, 'station_id');
Ejemplo n.º 6
0
 /**
  * Lists all models.
  */
 public function actionIndex()
 {
     if (isset($_GET['seat_id'])) {
         $seat = Seats::model()->findByPk($_GET['seat_id']);
         $dataProvider = new CActiveDataProvider('Candidates', array('criteria' => array('condition' => 'seat_id=' . $_GET['seat_id'])));
     } else {
         $this->redirect('Elections/index');
     }
     $this->render('index', array('dataProvider' => $dataProvider, 'seat' => $seat));
 }