pearweb_election
[ class tree: pearweb_election ] [ index: pearweb_election ] [ all elements ]

Source for file new.php

Documentation is available at new.php

  1. <?php
  2. auth_require('pear.election', 'pear.admin');
  3. $new = 'new';
  4. $year = date('Y') + 1;
  5. $years = array($year--, $year);
  6. if (!isset($_POST['step'])) {
  7.     $error = '';
  8.     $info = array(
  9.         'purpose' => '',
  10.         'detail' => '',
  11.         'choices' => 2,
  12.         'year' => date('Y', strtotime('+30 days')),
  13.         'month' => date('m', strtotime('+30 days')),
  14.         'day' => date('d', strtotime('+30 days')),
  15.         'length' => 7,
  16.         'minimum' => 1,
  17.         'maximum' => 1,
  18.         'eligiblevoters' => 1,
  19.     );
  20.     require PEARWEB_TEMPLATEDIR . '/election/new-step1.tpl.php';
  21. } elseif ($_POST['step'] == 2) {
  22.     require 'election/pear-election.php';
  23.     $election = new PEAR_Election;
  24.     $error = $election->validateStep1();
  25.     $info['purpose'] = $_POST['purpose'];
  26.     $info['detail'] = $_POST['detail'];
  27.     $info['choices'] = (int) $_POST['choices'];
  28.     $info['year'] = (int) $_POST['year'];
  29.     $info['month'] = $_POST['month'];
  30.     $info['day'] = $_POST['day'];
  31.     $info['length'] = (int) $_POST['length'];
  32.     $info['minimum'] = (int) $_POST['minimum'];
  33.     $info['maximum'] = (int) $_POST['maximum'];
  34.     $info['eligiblevoters'] = (int) $_POST['eligiblevoters'];
  35.     if ($error) {
  36.         require PEARWEB_TEMPLATEDIR . '/election/new-step1.tpl.php';
  37.         exit;
  38.     }
  39.     for ($i = 1; $i <= $info['choices']; $i++) {
  40.         $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i];
  41.         $info['summary_link' . $i] =
  42.             empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i];
  43.     }
  44.     require PEARWEB_TEMPLATEDIR . '/election/new-step2.tpl.php';
  45. } elseif ($_POST['step'] == 3) {
  46.     require 'election/pear-election.php';
  47.     $election = new PEAR_Election;
  48.     $error = $election->validateStep1();
  49.     $info['purpose'] = $_POST['purpose'];
  50.     $info['detail'] = $_POST['detail'];
  51.     $info['choices'] = (int) $_POST['choices'];
  52.     $info['year'] = (int) $_POST['year'];
  53.     $info['month'] = $_POST['month'];
  54.     $info['day'] = $_POST['day'];
  55.     $info['length'] = (int) $_POST['length'];
  56.     $info['minimum'] = (int) $_POST['minimum'];
  57.     $info['maximum'] = (int) $_POST['maximum'];
  58.     $info['eligiblevoters'] = (int) $_POST['eligiblevoters'];
  59.     if ($error) {
  60.         // this should never happen.  It will only occur
  61.         // if the user manually fills POST data without going
  62.         // through the official form, and makes a mistake.
  63.         require PEARWEB_TEMPLATEDIR . '/election/new-step1.tpl.php';
  64.         exit;
  65.     }
  66.     $error = $election->validateStep2();
  67.     $info['choices'] = (int) $_POST['choices'];
  68.     for ($i = 1; $i <= $info['choices']; $i++) {
  69.         $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i];
  70.         $info['summary_link' . $i] =
  71.             empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i];
  72.     }
  73.     if ($error) {
  74.         require PEARWEB_TEMPLATEDIR . '/election/new-step2.tpl.php';
  75.         exit;
  76.     }
  77.     require PEARWEB_TEMPLATEDIR . '/election/new-step3.tpl.php';
  78. } elseif ($_POST['step'] == 4) {
  79.     if (isset($_POST['cancel'])) {
  80.         require 'election/pear-voter.php';
  81.         $voter = new PEAR_Voter;
  82.         $currentelections = $voter->listCurrentElections();
  83.         $completedelections = $voter->listCompletedElections();
  84.         $allelections = $voter->listAllElections();
  85.         $error = 'Election creation cancelled';
  86.         $retrieval = false;
  87.         $old = false;
  88.         require PEARWEB_TEMPLATEDIR . '/election/vote.tpl.php';
  89.         exit;
  90.     }
  91.     require 'election/pear-election.php';
  92.     $election = new PEAR_Election;
  93.     $error = $election->validateStep1();
  94.     $info['purpose'] = $_POST['purpose'];
  95.     $info['detail'] = $_POST['detail'];
  96.     $info['choices'] = (int) $_POST['choices'];
  97.     $info['year'] = (int) $_POST['year'];
  98.     $info['month'] = $_POST['month'];
  99.     $info['day'] = $_POST['day'];
  100.     $info['length'] = (int) $_POST['length'];
  101.     $info['minimum'] = (int) $_POST['minimum'];
  102.     $info['maximum'] = (int) $_POST['maximum'];
  103.     $info['eligiblevoters'] = (int) $_POST['eligiblevoters'];
  104.     if ($error) {
  105.         // this should never happen.  It will only occur
  106.         // if the user manually fills POST data without going
  107.         // through the official form, and makes a mistake.
  108.         require PEARWEB_TEMPLATEDIR . '/election/new-step1.tpl.php';
  109.         exit;
  110.     }
  111.     for ($i = 1; $i <= $info['choices']; $i++) {
  112.         $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i];
  113.         $info['summary_link' . $i] =
  114.             empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i];
  115.     }
  116.     $error = $election->validateStep2();
  117.     if ($error) {
  118.         // this should never happen.  It will only occur
  119.         // if the user manually fills POST data without going
  120.         // through the official form, and makes a mistake.
  121.         require PEARWEB_TEMPLATEDIR . '/election/new-step2.tpl.php';
  122.         exit;
  123.     }
  124.     $election->saveNewElection();
  125.     $error = '';
  126.     require 'election/pear-voter.php';
  127.     $voter = new PEAR_Voter;
  128.     $currentelections = $voter->listCurrentElections();
  129.     $completedelections = $voter->listCompletedElections();
  130.     $allelections = $voter->listAllElections();
  131.     $info = 'Election saved';
  132.     $retrieval = false;
  133.     $old = false;
  134.     require PEARWEB_TEMPLATEDIR . '/election/vote.tpl.php';
  135. }

Documentation generated on Mon, 11 Mar 2019 15:34:35 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.