2005-10-24 17:59:15 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< ? php  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								require_once  ( " include/election-sql.php " );  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Shamelessly stolen from:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//    http://www.php.net/manual/en/function.mt-rand.php#55013
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Returns a random code of the specified length, containing characters that
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// are equally likely to be any of the digits, uppercase letters, or  lowercase
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// letters.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// The default length of 10 provides 839299365868340224 (62^10) possible codes.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// NOTE: Do not call wt_srand().  It is handled automatically in PHP 4.2.0 and
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//       above and any additional calls are likely to DECREASE the randomness.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								////
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function  randomCode  ( $length = 10 ){  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   $retVal  =  " " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   while ( strlen ( $retVal )  <  $length ){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       $nextChar  =  mt_rand ( 0 ,  61 );  // 10 digits + 26 uppercase + 26 lowercase = 62 chars
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       if (( $nextChar  >= 10 )  &&  ( $nextChar  <  36 )){  // uppercase letters
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           $nextChar  -=  10 ;  // bases the number at 0 instead of 10
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           $nextChar  =  chr ( $nextChar  +  65 );  // ord('A') == 65
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       }  else  if ( $nextChar  >=  36 ){  // lowercase letters
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           $nextChar  -=  36 ;  // bases the number at 0 instead of 36
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           $nextChar  =  chr ( $nextChar  +  97 );  // ord('a') == 97
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       }  else  {  // 0-9
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           $nextChar  =  chr ( $nextChar  +  48 );  // ord('0') == 48
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       $retVal  .=  $nextChar ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return  $retVal ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function  step4_do  ()  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  global  $error ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  global  $handle ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  global  $election_id ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 18:25:43 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  global  $choices_nb ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 17:59:15 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  global  $vote ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  global  $votes_array ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  global  $email ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 18:25:43 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  global  $tmp_token ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 17:59:15 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  $result  =  " " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  $res  =  elec_sql_start_transaction  ( $handle ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if  ( ! $res )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $error  .=  " Can not start a SQL transaction for the vote.<br /> \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  $result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  $i  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  do  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $anon_token  =  randomCode  ( 32 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $anon_token_id  =  elec_insert_new_anon_token  ( $handle ,  $election_id ,  $anon_token ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $i ++ ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }  while  ( $anon_token_id  ===  FALSE  &&  $i  <  10 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if  ( $anon_token_id  ===  FALSE )  { 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-25 21:53:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $error  .=  " Can not create an anonymous token:  " . mysql_error  ( $handle ) . " <br /> \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 17:59:15 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    elec_sql_rollback  ( $handle ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  $result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 18:25:43 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  if  ( $choices_nb  ==  1 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 17:59:15 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $res  =  elec_insert_new_vote  ( $handle ,  $anon_token_id ,  $vote ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! $res )  { 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-25 21:53:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      $error  .=  " Can not insert a vote:  " . mysql_error  ( $handle ) . " <br /> \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 17:59:15 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      elec_sql_rollback  ( $handle ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      return  $result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    foreach  ( $votes_array  as  $vote )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      $res  =  elec_insert_new_vote  ( $handle ,  $anon_token_id ,  $vote ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      if  ( ! $res )  { 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-25 21:53:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $error  .=  " Can not insert a vote:  " . mysql_error  ( $handle ) . " <br /> \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 17:59:15 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        elec_sql_rollback  ( $handle ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  $result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 18:25:43 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  $res  =  elec_sql_remove_tmp_token  ( $handle ,  $election_id ,  $email ,  $tmp_token ); 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 17:59:15 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if  ( ! $res )  { 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-25 21:53:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $error  .=  " Can not remove temporary token:  " . mysql_error  ( $handle ) . " <br /> \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 17:59:15 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    elec_sql_rollback  ( $handle ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  $result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  $res  =  elec_sql_commit  ( $handle ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if  ( ! $res )  { 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-25 21:53:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $error  .=  " Can not commit the vote:  " . mysql_error  ( $handle ) . " <br /> \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 17:59:15 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  $result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  $result  .=  " <h2>Step 4/4 - Keep your anonymous token</h2> \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  $result  .=  " <h3>Your vote has been received.</h3> \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  $result  .=  " <p>Please write this anonymous token somewhere:</p> \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  $result  .=  " <div class= \" votedata \" ><p><strong> " . $anon_token . " </strong></p></div> \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  $result  .=  " <p>This anonymous token will enable you to verify your vote when the preliminary results will be published. Nobody, even the Membership and Elections Committee, except you knows that this token is associated with you and only you will be able to verify your vote. It is not possible to request this anonymous token later.</p> \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return  $result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								?>