php_lib . "/common/format_utils.inc";
require_once $dotorg->php_lib . "/base/common/organization.inc";
require_once $dotorg->php_lib . "/base/workgroup/common/wg_traversal_tree.inc";
require_once $dotorg->php_lib . "/base/workgroup/common/evote.inc";
require_once $dotorg->php_lib . "/base/workgroup/common/dbclasses/o_time_zone.inc";
require_once $dotorg->php_lib . "/base/workgroup/common/dbclasses/o_wg_item_share.inc";
//////////////////////////////////////////////////////////////////////
// Ensure user input is clean (base/common/helpers.inc and
// validate registered globals (base/common/validate.inc)
//////////////////////////////////////////////////////////////////////
$_CLEAN['GET'] = clean($_GET);
if (isset($_CLEAN['GET']['id'])) {
$id = validateInteger($_CLEAN['GET']['id']);
}
if (isset($_CLEAN['GET']['voter_id'])) {
$voter_id = validateInteger($_CLEAN['GET']['voter_id']);
}
$_CLEAN['POST'] = clean($_POST);
if (isset($_CLEAN['POST']['id'])) {
$id = validateInteger($_CLEAN['POST']['id']);
}
if (isset($_CLEAN['POST']['voter_id'])) {
$voter_id = validateInteger($_CLEAN['POST']['voter_id']);
}
//////////////////////////////////////////////////////////////////////
// Declare local variables
//////////////////////////////////////////////////////////////////////
$page_error = '';
$action_error = '';
$ballot_name = '';
$is_creator = FALSE;
$is_ballots_manager = FALSE;
//////////////////////////////////////////////////////////////////////
// Declare form variables
//////////////////////////////////////////////////////////////////////
if (!isset($id)) { $id = 0; }
if (!isset($voter_id)) { $voter_id = 0; }
//////////////////////////////////////////////////////////////////////
// END OF VARIABLES
//////////////////////////////////////////////////////////////////////
$wg_item_share = new oWGItemShare();
$vote_tbl = new oVoteTable();
$ballot = new oBallot($id);
if ($ballot->populated) {
$workgroup_id = $ballot->getValue('workgroup_id');
$workgroup = new oWorkGroup($workgroup_id);
}
else {
// Populate workgroup object
$workgroup = new oWorkGroup();
$workgroup_id = $workgroup->populateFromLocation();
}
// Redirect if URL is bad (ex. '/workgroup/filename' instead of '/workgroup//filename')
// Continue only if eVote is 'on' for this workgroup
if (!$workgroup->populated or !$workgroup->isEVoteEnabled()) {
header("location: no_access.php");
exit;
}
$workgroup_name = $workgroup->getValue('name');
$workgroup_location = $workgroup->getValue('location');
$ballot = new oBallot($id);
if (!$ballot->populated) {
$page_error = "Ballot not found.";
}
else {
$time_zone = new oTimeZone();
$ballot_wg_id = $ballot->getValue('workgroup_id');
$ballot_workgroup = getWorkgroup($ballot_wg_id);
// mysql-format datetime for current GMT time
// close_date is GMT, so I need to make sure to compare it
// with the current gmt time
$gmt_today = date('Y-m-d H:i:00', $time_zone->getCurrentGMTTimeStamp());
$close_date = $ballot->getValue('close_date');
$ballot_name = $ballot->getValue('name');
$results_after_closes = ($ballot->getValue('results_open')=='after_closes' ? TRUE : FALSE);
if ($close_date > $gmt_today && $results_after_closes) {
$page_error = "The results of this ballot are not available until it has closed.";
}
}
// Continue only if eVote is 'on' for this workgroup and user is allowed to see
// ballot details
// See if the ballot results are shared with the membership or general public
$shared_viewer_ids = array();
$wg_item_share->getWorkgroupIds($shared_viewer_ids, $ballot->getValue('id'), 'ballot');
$is_shared_with_membership = in_array(0, $shared_viewer_ids);
$is_shared_with_public = in_array(9999, $shared_viewer_ids);
// Here are the rules describing who gets to view ballot details
$allow_results_viewing = ($is_shared_with_membership || $is_shared_with_public);
if (!$workgroup->isEVoteEnabled() || !$allow_results_viewing) {
// redirect to workgroup home page: this workgroup does not have evoting capabilities
header("location: $workgroup_location/no_access.php");
exit;
}
if (!$voter_id) {
$page_error .= "
No voter was specified.";
}
else {
$sql = "select option_id, other_option, comment, document_id from vote where person_id=$voter_id and ballot_id=$id";
$result = $vote_tbl->database->query($sql);
if ($result) {
$num_votes = 0;
while (list($this_option_id, $this_other_option, $this_comment, $this_document_id) = mysql_fetch_array($result)) {
$num_votes++;
if ($this_option_id > 0) {
$vote[] = $this_option_id;
}
else {
$other_text = "Other: ". $this_other_option;
}
if ($this_comment) {
$comment = $this_comment;
}
if ($this_document_id) {
$document_id = $this_document_id;
}
}
mysql_free_result($result);
}
else {
$admin_email_link = $organization->adminEmailLink();
$page_error = "An error occurred while retrieving the details of this vote. If the problem persists, please contact the $admin_email_link";
$page_error .= "$sql
";
$page_error .= "
".mysql_error();
}
}
$page_title = "Vote Details: $ballot_name";
if ($page_error) {
handleFatalError($page_error);
exit;
}
$header = 'file://'. $_SERVER["DOCUMENT_ROOT"] .'/committees/standard_html_header_nobc';
$footer = 'file://'. $_SERVER["DOCUMENT_ROOT"] .'/committees/standard_html_footer';
// Include the standard headers
include_remote_header($header, $page_title, 'workgroup');
$comp_name = getPersonsCompany($voter_id);
$vote_text = '';
if (count($vote) > 0) {
// Standard vote
// Get texts of all standard options
$multiple = FALSE;
$num_options = $ballot->getBallotOptions($option_ids, $option_texts);
for ($i = 0; $i < count($vote); $i++) {
if ($multiple) {
$vote_text .= "
";
}
$vote_text .= $option_texts[$vote[$i]];
$multiple = TRUE;
}
}
if ($num_votes > 1) {
$vote_heading = "Votes";
}
else {
$vote_heading = "Vote";
}
if (!empty($other_text)) {
$vote_text .= "
$other_text";
}
if ($comment) {
$comment = nl2br($comment);
}
else {
$comment = "None";
}
print <<
< Return to Ballot details
Vote Details
Ballot: $ballot_name |
Company:$comp_name |
$vote_heading:$vote_text |
Comment:$comment |
|
HTML;
// This section includes the standard footer
include_remote_footer($footer, 'workgroup');