cvs: pearweb /public_html/election edit.php index.php info.php new.php

From: Date: Tue, 21 Nov 2006 05:40:27 +0000
Subject: cvs: pearweb /public_html/election edit.php index.php info.php new.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-5215@lists.php.net to get a copy of this message
cellog Tue Nov 21 05:40:27 2006 UTC Added files: /pearweb/public_html/election edit.php index.php info.php new.php Log: as Martin requested, move election into a subdirectory. include/election has pear-voter/pear-election public_html/election has mapped from: election.php -> index.php election-info.php -> info.php election-new.php -> new.php election-edit.php -> edit.php

http://cvs.php.net/viewvc.cgi/pearweb/public_html/election/edit.php?view=markup&rev=1.1 Index: pearweb/public_html/election/edit.php +++ pearweb/public_html/election/edit.php <?php /** * Interface for inputing/editing an election. * * This source file is subject to version 3.01 of the PHP license, * that is bundled with this package in the file LICENSE, and is * available through the world-wide-web at the following URI: * http://www.php.net/license/3_01.txt. * If you did not receive a copy of the PHP license and are unable to * obtain it through the world-wide-web, please send a note to * license@php.net so we can mail you a copy immediately. * * @category pearweb * @package pearweb_election * @author Gregory Beaver <cellog@php.net> * @copyright Copyright (c) 2006 The PHP Group * @license http://www.php.net/license/3_01.txt PHP License * @version $Id: edit.php,v 1.1 2006/11/21 05:40:27 cellog Exp $ */ auth_require('pear.election'); require 'election/pear-election.php'; $new = 'edit'; $year = date('Y'); $years = array($year + 1, $year--, $year--, $year--); $election = new PEAR_Election; if (isset($_GET['election'])) { $info = $election->getInfo($_GET['election']); if (!$info) { $error = 'Unknown election'; $elections = $election->listElections(); require dirname(dirname(dirname(__FILE__))) . '/templates/election-listforedit.tpl.php'; exit; } if (!$election->canEdit($_GET['election'])) { $error = 'Cannot edit that election'; $elections = $election->listElections(); require dirname(dirname(dirname(__FILE__))) . '/templates/election-listforedit.tpl.php'; exit; } $error = array(); $election_id = (int) $_GET['election']; require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step1.tpl.php'; exit; } if (isset($_POST['step'])) { if (!isset($_POST['election_id']) || !$election->electionExists($_POST['election_id'])) { $error = 'Unknown election'; $elections = $election->listElections(); require dirname(dirname(dirname(__FILE__))) . '/templates/election-listforedit.tpl.php'; exit; } $election_id = (int) $_POST['election_id']; if (!$election->canEdit($election_id)) { $error = 'Cannot edit that election'; $elections = $election->listElections(); require dirname(dirname(dirname(__FILE__))) . '/templates/election-listforedit.tpl.php'; exit; } switch ($_POST['step']) { case '2' : $error = $election->validateStep1(false); $info['purpose'] = $_POST['purpose']; $info['detail'] = $_POST['detail']; $info['choices'] = (int) $_POST['choices']; $info['year'] = (int) $_POST['year']; $info['month'] = (int) $_POST['month']; $info['day'] = (int) $_POST['day']; $info['length'] = (int) $_POST['length']; $info['minimum'] = (int) $_POST['minimum']; $info['maximum'] = (int) $_POST['maximum']; $info['eligiblevoters'] = (int) $_POST['eligiblevoters']; if ($error) { require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step1.tpl.php'; exit; } $info = $election->setupChoices($election_id, $info); require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step2.tpl.php'; exit; case '3' : $error = $election->validateStep1(false); $info['purpose'] = $_POST['purpose']; $info['detail'] = $_POST['detail']; $info['choices'] = (int) $_POST['choices']; $info['year'] = (int) $_POST['year']; $info['month'] = (int) $_POST['month']; $info['day'] = (int) $_POST['day']; $info['length'] = (int) $_POST['length']; $info['minimum'] = (int) $_POST['minimum']; $info['maximum'] = (int) $_POST['maximum']; $info['eligiblevoters'] = (int) $_POST['eligiblevoters']; if ($error) { require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step1.tpl.php'; exit; } $error = $election->validateStep2(); $info = $election->setupChoices($election_id, $info); if ($error) { require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step2.tpl.php'; exit; } require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step3.tpl.php'; exit; case '4' : if (isset($_POST['cancel'])) { $error = 'Cancelled edit'; break; } $error = $election->validateStep1(false); $info['purpose'] = $_POST['purpose']; $info['detail'] = $_POST['detail']; $info['choices'] = (int) $_POST['choices']; $info['year'] = (int) $_POST['year']; $info['month'] = (int) $_POST['month']; $info['day'] = (int) $_POST['day']; $info['length'] = (int) $_POST['length']; $info['minimum'] = (int) $_POST['minimum']; $info['maximum'] = (int) $_POST['maximum']; $info['eligiblevoters'] = (int) $_POST['eligiblevoters']; if ($error) { require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step1.tpl.php'; exit; } $error = $election->validateStep2(); for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } if ($error) { require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step2.tpl.php'; exit; } // safe to save $election->saveEditedElection($election_id); $error = 'Election saved'; } } $elections = $election->listElections(); require dirname(dirname(dirname(__FILE__))) . '/templates/election-listforedit.tpl.php'; http://cvs.php.net/viewvc.cgi/pearweb/public_html/election/index.php?view=markup&rev=1.1 Index: pearweb/public_html/election/index.php +++ pearweb/public_html/election/index.php <?php if (!isset($auth_user) || !$auth_user) { if (strlen($_SERVER['QUERY_STRING'])) { $query = '?' . strip_tags($_SERVER['QUERY_STRING']); } else { $query = ''; } require dirname(dirname(dirname(__FILE__))) . '/templates/election-register.tpl.php'; } else { require 'pear-voter.php'; $voter = &new PEAR_Voter; $retrieval = false; if (isset($_POST['salt'])) { if ($vote = $voter->retrieveVote($_POST['election'], $_POST['salt'])) { $info = $voter->electionInfo($_POST['election']); $info['vote'] = $vote; } else { $error = 'No votes found, incorrect salt?'; } $retrieval = true; } $currentelections = $voter->listCurrentElections(); $completedelections = $voter->listCompletedElections(); $allelections = $voter->listAllElections(); require dirname(dirname(dirname(__FILE__))) . '/templates/election-vote.tpl.php'; } ?> http://cvs.php.net/viewvc.cgi/pearweb/public_html/election/info.php?view=markup&rev=1.1 Index: pearweb/public_html/election/info.php +++ pearweb/public_html/election/info.php <?php if (!isset($auth_user) || !$auth_user) { if (isset($_GET['vote'])) { if (strlen($_SERVER['QUERY_STRING'])) { $query = '?' . strip_tags($_SERVER['QUERY_STRING']); } else { $query = ''; } require dirname(dirname(dirname(__FILE__))) . '/templates/election-register.tpl.php'; exit; } } require 'election/pear-voter.php'; $voter = &new PEAR_Voter; if (isset($_POST['confirm'])) { // display vote confirmation page if (!$voter->electionExists($_POST['election'])) { $currentelections = $voter->listCurrentElections(); $completedelections = $voter->listCompletedElections(); $allelections = $voter->listAllElections(); $error = 'No such election id: ' . htmlspecialchars($_GET['election']); $retrieval = false; require dirname(dirname(dirname(__FILE__))) . '/templates/election-vote.tpl.php'; exit; } if ($voter->hasVoted($_POST['election'])) { $currentelections = $voter->listCurrentElections(); $completedelections = $voter->listCompletedElections(); $allelections = $voter->listAllElections(); $error = 'You have already voted in this election'; $retrieval = false; require dirname(dirname(dirname(__FILE__))) . '/templates/election-vote.tpl.php'; exit; } $info = $voter->electionInfo($_POST['election']); if (!isset($_POST['vote'])) { $_POST['vote'] = array(); } if (isset($_POST['abstain'])) { $info['abstain'] = true; $info['vote'] = array(); } else { if (!is_array($_POST['vote'])) { $_POST['vote'] = array($_POST['vote']); } if (count($_POST['vote']) < $info['minimum_choices'] || count($_POST['vote']) > $info['maximum_choices']) { $error = 'You voted for ' . count($_POST['vote']) . ' choices, but must vote ' . 'for at least ' . $info['minimum_choices'] . ' choices, and at most ' . $info['maximum_choices'] . ' choices'; require dirname(dirname(dirname(__FILE__))) . '/templates/election-dovote.tpl.php'; exit; } $info['abstain'] = false; $info['vote'] = $_POST['vote']; } require dirname(dirname(dirname(__FILE__))) . '/templates/election-confirm.tpl.php'; exit; } if (isset($_POST['finalvote'])) { // vote has been confirmed // generate salt for hash if (!$voter->electionExists($_POST['election'])) { $currentelections = $voter->listCurrentElections(); $completedelections = $voter->listCompletedElections(); $allelections = $voter->listAllElections(); $error = 'No such election id: ' . htmlspecialchars($_GET['election']); $retrieval = false; require dirname(dirname(dirname(__FILE__))) . '/templates/election-vote.tpl.php'; exit; } if ($voter->hasVoted($_POST['election'])) { $currentelections = $voter->listCurrentElections(); $completedelections = $voter->listCompletedElections(); $allelections = $voter->listAllElections(); $error = 'You have already voted in this election'; $retrieval = false; require dirname(dirname(dirname(__FILE__))) . '/templates/election-vote.tpl.php'; exit; } if (!isset($_POST['vote']) || !is_array($_POST['vote'])) { $_POST['vote'] = array(); } if (!isset($_POST['abstain'])) { $_POST['abstain'] = false; } $info = $voter->electionInfo($_POST['election']); $info['vote'] = $_POST['vote']; $info['abstain'] = $_POST['abstain']; $salt = $voter->getVoteSalt(); if ($info['abstain']) { $success = $voter->abstain($_POST['election']); } else { $success = $voter->vote($_POST['election'], $_POST['vote']); } require dirname(dirname(dirname(__FILE__))) . '/templates/election-confirmed.tpl.php'; exit; } if (!isset($_GET['election'])) { // display summary $currentelections = $voter->listCurrentElections(); $completedelections = $voter->listCompletedElections(); $allelections = $voter->listAllElections(); $retrieval = false; require dirname(dirname(dirname(__FILE__))) . '/templates/election-vote.tpl.php'; exit; } if (!$voter->electionExists($_GET['election'])) { // display summary $currentelections = $voter->listCurrentElections(); $completedelections = $voter->listCompletedElections(); $allelections = $voter->listAllElections(); $error = 'No such election id: ' . htmlspecialchars($_GET['election']); $retrieval = false; require dirname(dirname(dirname(__FILE__))) . '/templates/election-vote.tpl.php'; exit; } if (isset($_GET['vote'])) { $info = $voter->electionInfo($_GET['election']); if ($voter->hasVoted($_GET['election'])) { $currentelections = $voter->listCurrentElections(); $completedelections = $voter->listCompletedElections(); $allelections = $voter->listAllElections(); $error = 'You cannot vote twice in the same election'; $retrieval = false; require dirname(dirname(dirname(__FILE__))) . '/templates/election-vote.tpl.php'; exit; } elseif ($voter->canVote($_GET['election'])) { require dirname(dirname(dirname(__FILE__))) . '/templates/election-dovote.tpl.php'; } else { $info = $voter->electionInfo($_GET['election']); require dirname(dirname(dirname(__FILE__))) . '/templates/election-showresults.tpl.php'; } } if (isset($_GET['results'])) { $info = $voter->electionInfo($_GET['election']); require dirname(dirname(dirname(__FILE__))) . '/templates/election-showresults.tpl.php'; } response_footer(); ?> http://cvs.php.net/viewvc.cgi/pearweb/public_html/election/new.php?view=markup&rev=1.1 Index: pearweb/public_html/election/new.php +++ pearweb/public_html/election/new.php <?php auth_require('pear.election', 'pear.admin'); $new = 'new'; $year = date('Y') + 1; $years = array($year--, $year); if (!isset($_POST['step'])) { $error = ''; $info = array( 'purpose' => '', 'detail' => '', 'choices' => 2, 'year' => date('Y', strtotime('+30 days')), 'month' => date('m', strtotime('+30 days')), 'day' => date('d', strtotime('+30 days')), 'length' => 7, 'minimum' => 1, 'maximum' => 1, 'eligiblevoters' => 1, ); require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step1.tpl.php'; } elseif ($_POST['step'] == 2) { require 'election/pear-election.php'; $election = new PEAR_Election; $error = $election->validateStep1(); $info['purpose'] = $_POST['purpose']; $info['detail'] = $_POST['detail']; $info['choices'] = (int) $_POST['choices']; $info['year'] = (int) $_POST['year']; $info['month'] = (int) $_POST['month']; $info['day'] = (int) $_POST['day']; $info['length'] = (int) $_POST['length']; $info['minimum'] = (int) $_POST['minimum']; $info['maximum'] = (int) $_POST['maximum']; $info['eligiblevoters'] = (int) $_POST['eligiblevoters']; if ($error) { require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step1.tpl.php'; exit; } for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step2.tpl.php'; } elseif ($_POST['step'] == 3) { require 'election/pear-election.php'; $election = new PEAR_Election; $error = $election->validateStep1(); $info['purpose'] = $_POST['purpose']; $info['detail'] = $_POST['detail']; $info['choices'] = (int) $_POST['choices']; $info['year'] = (int) $_POST['year']; $info['month'] = (int) $_POST['month']; $info['day'] = (int) $_POST['day']; $info['length'] = (int) $_POST['length']; $info['minimum'] = (int) $_POST['minimum']; $info['maximum'] = (int) $_POST['maximum']; $info['eligiblevoters'] = (int) $_POST['eligiblevoters']; if ($error) { // this should never happen. It will only occur // if the user manually fills POST data without going // through the official form, and makes a mistake. require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step1.tpl.php'; exit; } $error = $election->validateStep2(); $info['choices'] = (int) $_POST['choices']; for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } if ($error) { require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step2.tpl.php'; exit; } require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step3.tpl.php'; } elseif ($_POST['step'] == 4) { if (isset($_POST['cancel'])) { require 'election/pear-voter.php'; $voter = new PEAR_Voter; $currentelections = $voter->listCurrentElections(); $completedelections = $voter->listCompletedElections(); $allelections = $voter->listAllElections(); $error = 'Election creation cancelled'; $retrieval = false; require dirname(dirname(dirname(__FILE__))) . '/templates/election-vote.tpl.php'; exit; } require 'election/pear-election.php'; $election = new PEAR_Election; $error = $election->validateStep1(); $info['purpose'] = $_POST['purpose']; $info['detail'] = $_POST['detail']; $info['choices'] = (int) $_POST['choices']; $info['year'] = (int) $_POST['year']; $info['month'] = (int) $_POST['month']; $info['day'] = (int) $_POST['day']; $info['length'] = (int) $_POST['length']; $info['minimum'] = (int) $_POST['minimum']; $info['maximum'] = (int) $_POST['maximum']; $info['eligiblevoters'] = (int) $_POST['eligiblevoters']; if ($error) { // this should never happen. It will only occur // if the user manually fills POST data without going // through the official form, and makes a mistake. require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step1.tpl.php'; exit; } for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } $error = $election->validateStep2(); if ($error) { // this should never happen. It will only occur // if the user manually fills POST data without going // through the official form, and makes a mistake. require dirname(dirname(dirname(__FILE__))) . '/templates/election-new-step2.tpl.php'; exit; } $election->saveNewElection(); $error = ''; require 'election/pear-voter.php'; $voter = new PEAR_Voter; $currentelections = $voter->listCurrentElections(); $completedelections = $voter->listCompletedElections(); $allelections = $voter->listAllElections(); $error = 'Election saved'; $retrieval = false; require dirname(dirname(dirname(__FILE__))) . '/templates/election-vote.tpl.php'; }
« previous php.pear.core (#5215) next »