 |
 |
|
 |
|
 |
|
 |
|
Nombre de fichiers: |
Régistre des visiteurs: |
12 |
Anciens Missionnaires: |
11 |
Actuel: |
4 |
Nouvelles: |
4 |
Images: |
1 |
|
|
 |
|
//////////////////////////////////////////////////////////////////////
//
// phpPolls - A voting booth for PHP3
//
// This file is "phpPollUI.php" and is responsible for
// generating all HTML user-interfaces for a poll.
//
// See inc/phpPollConfig.php for configuration options.
//
// Copyright (c) 1999 Till Gerken (tig@skv.org)
//
// This software is released under the GNU Public License.
// Please see the accompanying file gpl.txt for licensing details!
//
//////////////////////////////////////////////////////////////////////
require_once("inc/phpPollDBFunctions.php");
?>
//////////////////////////////////////////////////////////////////////
// Function poll_getTitle($poll_id)
//////////////////////////////////////////////////////////////////////
function poll_getTitle($poll_id, $print_errors=false) {
global $poll_descTableName, $poll_usePersistentConnects;
$strPollTitle = "";
// connect to database
$poll_db_ID = db_connect();
$poll_result = @db_query("SELECT title FROM $poll_descTableName WHERE (pollID=$poll_id)", $poll_db_ID);
if(!$poll_result && $print_errors) {
echo db_error(). " ";
return(0);
}
$poll_object = @db_fetch_object($poll_result);
$strPollTitle .= $poll_object->title;
if (!$poll_usePersistentConnects == 0)
db_close($poll_db_ID);
return stripslashes($strPollTitle);
}
//////////////////////////////////////////////////////////////////////
// Function poll_exists($poll_id)
//////////////////////////////////////////////////////////////////////
function poll_exists($poll_id) {
$title = @poll_getTitle($poll_id, false);
if (!empty($title)) {
return(true);
}
return(false);
}
//////////////////////////////////////////////////////////////////////
// Function poll_generateUI($poll_id, $poll_forwarder)
//////////////////////////////////////////////////////////////////////
// This function generates the HTML code allowing a user to vote
// for a certain poll. The ID of this poll has to be given as function
// parameter, as well as a forwarder.
//////////////////////////////////////////////////////////////////////
// Parameters:
// poll_id -
// ID number of the poll to be used (MUST be valid)
// poll_forwarder -
// URL that will be used as a forwarder in the resulting
// page to forward the user to an application-defined
// target page.
//////////////////////////////////////////////////////////////////////
// Returns:
// strPollBody string for output
//////////////////////////////////////////////////////////////////////
// Calls to:
// none
//////////////////////////////////////////////////////////////////////
// Global references:
// $poll_usePersistentConnects
// $poll_dataTableName, $poll_maxOptions
// (from inc/phpPollConfig.php)
//////////////////////////////////////////////////////////////////////
// Author: dgibby
// Last change: 01/11/28
//////////////////////////////////////////////////////////////////////
function poll_generateUI($poll_id, $poll_forwarder) {
global $poll_dataTableName, $poll_maxOptions;
global $poll_usePersistentConnects, $strLangPoll;
$strPollOptions = "";
// connect to database
$poll_db_ID = db_connect();
// setup a form
$strPollOptions .= "
";
// close link to database
if($poll_usePersistentConnects == 0)
db_close($poll_db_ID);
return($strPollOptions);
}
//////////////////////////////////////////////////////////////////////
//
// Function poll_viewInfo()
//
//////////////////////////////////////////////////////////////////////
//
// This function generates HTML code showing a poll's additional infomation.
// It displays them in a table for which parameters can be adjusted
// in inc/phpPollConfig.php
//
//////////////////////////////////////////////////////////////////////
//
// Parameters:
// $poll_id -
// ID of poll to show results for (MUST be valid)
// $poll_tableHeader, $poll_tableFooter -
// Tags surrounding the output table ()
// $poll_rowHeader, $poll_rowFooter -
// Tags surrounding each row ( |
// $poll_dataHeader, $poll_dataFooter -
// Tags surrounding each data entry ( | )
//
//////////////////////////////////////////////////////////////////////
//
// Returns:
// 0 - error (prints error to output)
// String containing output
//
//////////////////////////////////////////////////////////////////////
//
// Global references:
// $poll_usePersistentConnects;
// $poll_descTableName;
// (from inc/phpPollConfig.php)
// global $strLangSubmittedBy, $strLangStart, $strLangEnd, $strLangComments
//
//////////////////////////////////////////////////////////////////////
//
// Author: dangby
// dangby
//
//////////////////////////////////////////////////////////////////////
function poll_viewInfo($pollID, $poll_tableHeader="", $poll_rowHeader="", $poll_dataHeader="", $poll_dataFooter=" | ", $poll_rowFooter=" ", $poll_tableFooter=" ", $poll_totalHeader="", $poll_totalFooter=" | ", $poll_dataHeaderRight="") {
global $poll_usePersistentConnects;
global $poll_descTableName;
global $strLangSubmittedBy, $strLangStart, $strLangEnd, $strLangComments;
$strPollDisplay = "";
// connect to database
$poll_db_ID = db_connect();
$strPollDisplay .= $poll_tableHeader;
$query_result = db_query("SELECT comments, startdate, enddate, uid FROM $poll_descTableName WHERE pollID=$pollID", $poll_db_ID);
$numrows = db_numrows($query_result);
if(!$query_result) {
$strPollDisplay .= db_error(). " ";
return(0);
}
$poll_object = db_fetch_object($query_result, 0);
$rowSpacer = " | | ";
$startDate = $poll_object->startdate;
$endDate = $poll_object->enddate;
$comments = $poll_object->comments;
if ($startDate != "") {
$startDate = "$strLangStart: $startDate ";
}
if ($endDate != "") {
$endDate = " $strLangEnd: $endDate";
}
if ($comments != "") {
$comments = "$rowSpacer$strLangComments: $comments | ";
}
$strPollDisplay .= "";
if($poll_usePersistentConnects == 0) {
db_close($poll_db_ID);
}
return($strPollDisplay);
}
//////////////////////////////////////////////////////////////////////
//
// Function poll_viewResults()
//
//////////////////////////////////////////////////////////////////////
//
// This function generates HTML code showing a poll's results.
// It displays them in a table for which parameters can be adjusted
//
//////////////////////////////////////////////////////////////////////
//
// Parameters:
// $poll_id -
// ID of poll to show results for (MUST be valid)
// $poll_tableHeader, $poll_tableFooter -
// Tags surrounding the output table ()
// $poll_rowHeader, $poll_rowFooter -
// Tags surrounding each row (
// $poll_dataHeader, $poll_dataFooter -
// Tags surrounding each data entry ( | )
//
//////////////////////////////////////////////////////////////////////
//
// Returns:
// 0 - error (prints error to output)
// String containing output
//
//////////////////////////////////////////////////////////////////////
//
// Calls to:
// none
//
//////////////////////////////////////////////////////////////////////
//
// Global references:
// $poll_usePersistentConnects
// $poll_descTableName, $poll_dataTableName
// $poll_maxOptions, $poll_resultBarScale, $poll_resultBarHeight
// $poll_resultTableBgColor, $poll_resultBarFile
// (from inc/phpPollConfig.php)
//
//////////////////////////////////////////////////////////////////////
//
// Author: tig
// dangby
//
//////////////////////////////////////////////////////////////////////
function poll_viewResults($poll_id, $poll_tableHeader="", $poll_rowHeader="", $poll_dataHeader="", $poll_dataFooter=" | ", $poll_rowFooter=" ", $poll_tableFooter=" ", $poll_totalHeader="", $poll_totalFooter=" | ", $poll_dataHeaderRight="") {
global $poll_usePersistentConnects;
global $poll_descTableName, $poll_dataTableName, $poll_maxOptions;
global $poll_resultBarScale, $poll_resultBarHeight, $poll_resultTableBgColor;
global $poll_resultBarFile, $poll_checkUserVoted;
global $strLangVote, $strLangTotalVotes;
$strPollDisplay = "";
// connect to database
$poll_db_ID = db_connect();
$poll_sum = getTotalVotes($poll_id, $poll_db_ID);
$strPollDisplay .= $poll_tableHeader;
$query_result = db_query("SELECT pollID FROM $poll_dataTableName WHERE pollID=$poll_id", $poll_db_ID);
$numrows = db_numrows($query_result);
// cycle through all options
for($i = 0; $i < $numrows; $i++) {
// select next vote option
$poll_result = db_query("SELECT * FROM $poll_dataTableName WHERE (pollID=$poll_id) AND (voteID=$i)", $poll_db_ID);
if(!$poll_result) {
$strPollDisplay .= db_error(). " ";
return(0);
}
// fetch field
$poll_object = db_fetch_object($poll_result);
if(is_object($poll_object)) {
$poll_optionText = stripslashes($poll_object->optiontext);
$poll_optionCount = $poll_object->optioncount;
$strPollDisplay .= $poll_rowHeader;
if($poll_optionText != "") {
$strPollDisplay .= $poll_dataHeader;
$strPollDisplay .= " $poll_optionText";
$strPollDisplay .= $poll_dataFooter;
if($poll_sum) {
$poll_percent = 100 * $poll_optionCount / $poll_sum;
} else {
$poll_percent = 0;
}
$strPollDisplay .= $poll_dataHeader;
if ($poll_percent > 0) {
$poll_percentScale = (int)($poll_percent * $poll_resultBarScale);
$strPollDisplay .= " ";
}
$strPollDisplay .= $poll_dataFooter . $poll_dataHeader;
$strPollDisplay .= sprintf("(%d)", $poll_optionCount);
$strPollDisplay .= $poll_dataFooter . $poll_dataHeaderRight;
$strPollDisplay .= sprintf(" %.1f %%", $poll_percent);//str_replace("%", " ", sprintf(" %.1f %%", $poll_percent));
$strPollDisplay .= $poll_dataFooter;
}
$strPollDisplay .= $poll_rowFooter;
}
}
$strPollDisplay .= $poll_rowHeader;
$strPollDisplay .= $poll_totalHeader;
$strPollDisplay .= " $strLangTotalVotes: $poll_sum ";
if ($_SESSION['sess_logged_in']) {
$strPollDisplay .= " $strLangVote";
}
$strPollDisplay .= $poll_totalFooter;
$strPollDisplay .= $poll_rowFooter;
$strPollDisplay .= $poll_tableFooter;
// close link to database
if($poll_usePersistentConnects == 0)
db_close($poll_db_ID);
return($strPollDisplay);
}
//////////////////////////////////////////////////////////////////////
//
// Function poll_getResults()
//
//////////////////////////////////////////////////////////////////////
//
// This function gets a poll's result and returns it in an array.
//
//////////////////////////////////////////////////////////////////////
//
// Parameters:
// $poll_id -
// ID of poll to show results for (MUST be valid)
//
//////////////////////////////////////////////////////////////////////
//
// Returns:
// 0 - error (prints error to output)
// array results -
// This is a multi-dimensional array containing various information
// of the poll identified with $poll_id.
// The first element of the array ($result[0]) contains the topic of
// the poll and the number of total votes:
// $result[0]["title"] - topic of the poll
// $result[0]["votes"] - total number of votes for this poll
// The next elemts contain information about the individual poll
// options. If a poll has two options, it would contain two more elements -
// $results[1] and $results[2] - both being an array again with the following
// elements:
// $result[n]["text"] - text of the option
// $result[n]["votes"] - votes for this option
//
//////////////////////////////////////////////////////////////////////
//
// Calls to:
// none
//
//////////////////////////////////////////////////////////////////////
//
// Global references:
// $poll_usePersistentConnects
// $poll_descTableName, $poll_dataTableName
// (from inc/phpPollConfig.php)
//
//////////////////////////////////////////////////////////////////////
//
// Author: tobias
// Last change: 99/06/04
//
//////////////////////////////////////////////////////////////////////
function poll_getResults($poll_id) {
global $poll_usePersistentConnects;
global $poll_descTableName, $poll_dataTableName, $poll_maxOptions;
$ret = array();
// connect to database
$poll_db_ID = db_connect();
$poll_result = db_query("SELECT SUM(optionCount) AS SUM FROM $poll_dataTableName WHERE pollID=$poll_id", $poll_db_ID);
if(!$poll_result) {
echo db_error(). " ";
return(0);
}
$poll_sum = getTotalVotes($poll_id);
$poll_title = stripslashes(db_result($poll_result, 0, "title"));
$ret[0] = array("title"=>$poll_title, "votes"=>$poll_sum);
// select next vote option
$poll_result = db_query("SELECT * FROM $poll_dataTableName WHERE pollID=$poll_id", $poll_db_ID);
if(!$poll_result) {
echo db_error(). " ";
return(0);
}
$counter = 0;
while ($row = db_fetch_array($poll_result, $counter)) {
$ret[] = array("text"=>$row["optionText"], "votes"=>$row["optionCount"]);
$counter++;
}
// close link to database
if($poll_usePersistentConnects == 0)
db_close($poll_db_ID);
return($ret);
}
function getTotalVotes($poll_id) {
global $poll_dataTableName, $strPollDisplay;
$connection = db_connect();
$poll_result = db_query("SELECT SUM(optionCount) AS SUM FROM $poll_dataTableName WHERE pollID=$poll_id", $connection);
if(!$poll_result) {
$strPollDisplay .= db_error(). " ";
return(0);
}
return ((int)db_result($poll_result, 0, "SUM"));
}
//////////////////////////////////////////////////////////////////////
//
// Function poll_listPolls()
//
//////////////////////////////////////////////////////////////////////
//
// This function returns all available polls in a two-dimensional
// array, structured as [pollDescription, pollID]
//
//////////////////////////////////////////////////////////////////////
//
// Parameters:
// none
//
//////////////////////////////////////////////////////////////////////
//
// Returns:
// Array listing all polls along with ID [pollDescription, pollID]
//
//////////////////////////////////////////////////////////////////////
//
// Calls to:
// none
//
//////////////////////////////////////////////////////////////////////
//
// Global references:
// $poll_usePersistentConnects
// $poll_descTableName
// (from inc/phpPollConfig.php)
//
//////////////////////////////////////////////////////////////////////
//
// Author: Daniel Gibby
//
//
//////////////////////////////////////////////////////////////////////
function poll_listPolls() {
global $poll_usePersistentConnects, $poll_descTableName, $cfg_mission_id, $qrAllUsersVw;
// connect to database
$poll_db_ID = db_connect();
// select all descriptions
$poll_result = db_query("SELECT * FROM $poll_descTableName p, auth a WHERE p.pollID = a.pri_key AND live = 't' AND auth_table = 'polls' AND a.mission_id IN ($cfg_mission_id) ORDER BY timeStamp", $poll_db_ID);
if(!$poll_result) {
echo db_error(). " ";
return;
}
// echo "sess_id: $_SESSION['sess_id'], sess_username: $_SESSION['sess_username']";
$num_polls = db_numrows($poll_result);
// echo "number of polls: ".$num_polls;
// cycle through the descriptions until everyone has been fetched
for($counter=0; $counter < $num_polls; $counter++) {
$poll_object = db_fetch_object($poll_result, $counter);
// I set this to always be user_type ADMIN... don't know if that's what we want
$getCreator = runQuery("SELECT id, full_name, user_type FROM ($qrAllUsersVw) AS u WHERE id='$poll_object->uid' AND user_type = 'ADMIN'");
$creator_object = db_fetch_object($getCreator, 0);
$creator_name = $creator_object->full_name;
$creator_id = $creator_object->id;
$creator_type = $creator_object->user_type;
$resultArray[$counter] = array($poll_object->pollid, $poll_object->title, $creator_name, $poll_object->startdate, $poll_object->enddate, $poll_object->comments, $creator_id, $creator_type);
}
if($poll_usePersistentConnects == 0)
db_close($poll_db_ID);
return($resultArray);
}
//////////////////////////////////////////////////////////////////////
?>
|
|
|