Location: PHPKode > projects > Warp.cms - php/mysql content management > warp_121/castvote.php
<?php

// [voting module v.1.2.1]
// xantis.warp.cms - version 1.2
// (c) 2002 xantis - all rights reserved
// this code is registered and protected by international copyrights laws

//####### Register Globals !

extract($HTTP_ENV_VARS);
extract($HTTP_GET_VARS);
extract($HTTP_POST_VARS);
extract($HTTP_COOKIE_VARS);
extract($HTTP_SERVER_VARS);

//#########################

$ysecure = rawurldecode ("$ysec");
$ysecure = base64_decode ("$ysecure");

if ($ysecure == 'xvoteok') {
	$xnt_control_var = 'xnt2002warp.cms';
} //end if

if (empty($yfilename)) {
	$yfilename = 'castvote.php';
} //end if

require("lib_adv.php");

//check session
if (strlen($wpsid) < '32') {
	$hlocal_sess_req_redr = "$ywebsite_addr".'xindex.php';
	header("Location: $hlocal_sess_req_redr");
} //end if


//##################################################


function xcastvote_module () {
//-------------------

//remote and lib vars
global 	$REMOTE_ADDR, $arr_var_result ;

//form vars
global 	$vqsid, $vtyp, $vqid, $yoptmax, $wpqid, $wpsid, $ywarp_max_display_cfg ;

//voting cfg vars
global 	$yvoting_thanks, $yvoting_done, $yvoting_result_title, $yvoting_question ;
global	$yvoting_name, $yvoting_err, $yvoting_show_results, $ybar_menu_color, $ymain_color ;
global	$ywebsite_addr, $y_warp_picts_dir, $ywarp_graph_bar, $yvoting_total_txt, $y_warp_back_text_x ;
global 	$y_warp_xdate, $y_warp_xtime, $y_warp_encode_str, $PHP_AUTH_USER, $PHP_AUTH_PW ;


global	$REQUEST_METHOD, $QUERY_STRING, $y_warp_direct_file_acc_msg_reff, $y_warp_err_data_failure ;



//get and check vote type
xmysql_read_data ("SELECT id, type, acc FROM voting_sections WHERE (id='$vqsid')");
$hx_local_arr_vsection = array ();
$hx_local_arr_vsection = $arr_var_result ;


//---------------------------------------------------------page header

if ($hx_local_arr_vsection[2] == 'y') {
	xheader ("$yvoting_result_title", 'secure');
} //end if
else {
	xheader ("$yvoting_result_title", '');
} //end else

xcenter_start ();
xshow_page_title ("$yvoting_result_title", "$wpsid");
xnewline ();
//---------------------------------------------------------

//check request method
if ( ($REQUEST_METHOD <> 'POST') OR (!empty($QUERY_STRING)) ) {
	xzerr_die_after_header ($y_warp_direct_file_acc_msg_reff);
} //end if


if ( (empty($hx_local_arr_vsection[0])) OR ($hx_local_arr_vsection[1] != $vtyp) ) {
	xzerr_die_after_header ($y_warp_err_data_failure);
} //end if


$ydisplay_width_corrected = $ywarp_max_display_cfg;

$y_voted_date = date("Y-m-d");


if ($vqsid <> '') {

//------------------ write operate

if ($hx_local_arr_vsection[2] == 'y') {
	//restrict by user id
	$WARP_B64_ENC_AUTH_PASSW = base64_encode($PHP_AUTH_PW);
	xmysql_read_data ("SELECT id FROM users WHERE ( (usr_name='$PHP_AUTH_USER') AND (usr_pass='$WARP_B64_ENC_AUTH_PASSW') )");
	$y_vote_usr_id = $arr_var_result[0];
} //end if
else {
	//restrict by session id
	$y_vote_usr_id = $wpsid ;
} //end else

xmysql_read_data ("SELECT id FROM voting_access WHERE ( (voting_id='$y_vote_usr_id') AND (vote_sect_id='$vqsid') ) ");
//$arr_var_result

//check if voted
$y_vote_hasvoted_here = 'no' ;
if (!empty($arr_var_result[0])) {
	$y_vote_hasvoted_here = 'yes';
} //end if

$y_local_voting_status = 'err';

if ($vtyp == 's') {
	if ($vqid <> '') {
		if ($y_vote_hasvoted_here <> 'yes') {
			xmysql_write_data ("INSERT INTO voting_access (voting_id, vote_sect_id) VALUES ('$y_vote_usr_id', '$vqsid') ");
			xmysql_write_data ("UPDATE voting_quest SET cast=cast+1 WHERE (id ='$vqid') ");
			$ythank_you_text = "$yvoting_thanks";
			$y_local_voting_status = 'inf';
		} //end if
		else {
			$ythank_you_text = "$yvoting_done";
			$y_local_voting_status = 'wrn';
		} //end else
	} //end if
} //end if


if ($vtyp == 'm') {
	$ycontrol = '';
	for ($i=0; $i < $yoptmax; $i++) {
		$y_ev_text="if (\$"."vqid[$i]"." == '') {\n"."\$"."vqid_new[$i]"." = 'x'; }";
		eval ($y_ev_text);

		$y_ev_text="if (\$"."vqid[$i]"." <> '') {\n"."\$"."vqid_new[$i]"." = "."\$"."vqid[$i]"."; \n"."\$"."ycontrol = 'ok' ; "." }";
		eval ($y_ev_text);

	} //end for

	if ($ycontrol == 'ok') {
		if ($y_vote_hasvoted_here <> 'yes') {
			xmysql_write_data ("INSERT INTO voting_access (voting_id, vote_sect_id) VALUES ('$y_vote_usr_id', '$vqsid') ");
			for ($i=0; $i < $yoptmax; $i++) {
				if ($vqid_new[$i] <> 'x') {
					xmysql_write_data ("UPDATE voting_quest SET cast=cast+1 WHERE (id ='$vqid_new[$i]') ");
				} // end if
			} //end for
			$ythank_you_text = "$yvoting_thanks";
			$y_local_voting_status = 'inf';
		} //end if
		else {
			$ythank_you_text = "$yvoting_done";
			$y_local_voting_status = 'wrn';
		} //end else
	} //end if
} //end if



//------------------ read operate

xmysql_read_data ("SELECT name FROM voting_sections WHERE (id ='$vqsid') ");

$yvoting_name = $arr_var_result[0];

xmysql_read_data ("SELECT name, cast FROM voting_quest WHERE (block ='$vqsid') ORDER BY id ASC");

$yvoting_sum = '0';

$arr_count = count($arr_var_result);
for ($i=0; $i < $arr_count; $i++) {
	$i_name = $i;
	$i_cast = $i +1;
	$i = $i + 1;

	//calculating sume
	$yvoting_sum = $yvoting_sum + $arr_var_result[$i_cast];

} //end for



//-------------------start show

xshow_display_std_start ($yvoting_question." : "."$yvoting_name", "$ydisplay_width_corrected") ;

xnewline ();

xcenter_start ();
xtable_start ('');

xtable_row_start ();
	xtable_column_start_vcenter ('1', '', "$ymain_color");
		xcenter_right_start ();
			xwriteflash_nobg_var ("$ywebsite_addr"."flagger.swf",
			"&xaction=".rawurlencode("$y_local_voting_status").
			"&"
			, '30', '30');
		xcenter_end ();
	xtable_column_end ();

	xtable_column_start_vcenter ('1', '', "$ymain_color");

		if ($vtyp == 's') {
			if ($vqid == '') {
				xvpix ('10');
				xtext_small ("<b>$yvoting_err</b>");
			} //end if

			if ($vqid <> '') {
				xvpix ('10');
				xtext_small ('<b>'.$ythank_you_text.'</b>');
			} //end if
		} //end if

		if ($vtyp == 'm') {
			if ($ycontrol <> 'ok') {
				xvpix ('10');
				xtext_small ("<b>$yvoting_err</b>");
			} //end if

			if ($ycontrol == 'ok') {
				xvpix ('10');
				xtext_small ('<b>'.$ythank_you_text.'</b>');
			} //end if
		} //end if

	xtable_column_end ();
xtable_row_end ();


xtable_end ();
xcenter_end ();


if ($yvoting_show_results == 'y') {

xvline ('100%');
xnewline ();

xcenter_start ();
xtable_start ('450');
xtable_row_start ();
xtable_column_start ('1', '100%', "$ybar_menu_color");

	xnewline ();

	$arr_count = count($arr_var_result);
	for ($i=0; $i < $arr_count; $i++) {
		$i_name = $i;
		$i_cast = $i +1;
		$i = $i + 1;

		if ($yvoting_sum == '0') {
			$yvoting_percent = '0';
		} //end if
		else {
			$yvoting_percent = round (100*$arr_var_result[$i_cast]/$yvoting_sum);
		} //end else

		$yvoting_bar_len = round ($yvoting_percent * 4) + 10;

		xvpix ('10');
		xtext_small ("$arr_var_result[$i_name]"." [".$arr_var_result[$i_cast]." | ".$yvoting_percent."%]");
		xnewline ();

		xvpix ('10');
		xpict_alt ("$ywebsite_addr"."$y_warp_picts_dir".'/'."$ywarp_graph_bar", "$yvoting_bar_len", '18', "$arr_var_result[$i_name]"." ["."$yvoting_percent"." %]");
		xnewline ();

	} //end for

	xnewline ();

xtable_column_end ();
xtable_row_end ();

xtable_row_start ();
xtable_column_start ('1', '100%', "$ybar_menu_color");
	xcenter_right_start ();
		xtext_small ("<b>"."$yvoting_total_txt"." : "."</b>"."$yvoting_sum");
		xvpix ('10');
		xtext_small (' [ '.$y_warp_xdate.' | '.$y_warp_xtime.' ]');
		xvpix ('10');
		xpict ("$ywebsite_addr"."$y_warp_picts_dir".'/'.'surveys.jpg', '30', '30');
		xvpix ('10');
	xcenter_end ();
xtable_column_end ();
xtable_row_end ();


xtable_end ();
xcenter_end ();

} //end if

	xvline ('100%');
	xcenter_start ();
		xtext_link ("$y_warp_back_text_x", "$ywebsite_addr"."xw_main.php"."?wpqid=$wpqid&wpsid=$wpsid", '_self');
	xcenter_end ();


xshow_display_std_end ();


//---------------------------------------------------------page footer

xcenter_end ();
xfooter ();


} //end if


}//-------------------end function



//-------------------------------

if ($ysecure == 'xvoteok') {
	xcastvote_module ();
} //end if

//-------------------------------


// end of php code
?>
Return current item: Warp.cms - php/mysql content management