Esempio n. 1
0
 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));
 }
Esempio n. 2
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']))));
     }
 }
Esempio 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');
 }
Esempio n. 4
0
 /**
  * Lists all models.
  */
 public function actionIndex()
 {
     if (isset($_GET['election_id'])) {
         $election = Elections::model()->findByPk($_GET['election_id']);
         $dataProvider = new CActiveDataProvider('Seats', array('criteria' => array('condition' => 'election_id=' . $_GET['election_id'])));
     } else {
         $this->redirect('Elections/index');
     }
     $this->render('index', array('dataProvider' => $dataProvider, 'election' => $election));
 }
Esempio n. 5
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 = Elections::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }