|
Post by Marti-Pair Furxheir S.H. on Jan 6, 2016 4:51:49 GMT -6
I have been talking about 2.0 Online Ballot for a while, and even proposed amendments to allow it. This morning, the first step was laid down, producing Ballot version 1.1 if you will.. Because the ballot is being certified, I will post not just what I did, but how I did it, with full code!!! So, Version 1.1 add a drop down above the Party Field, so it now looks like this: When you select an option in the drop-down, it fills the Party Vote: edit box for you. The values include PRESENT as the first option, and then, the Parties in alphabetical order, first the initial, then the full party name. However, the edit box remains editable! That means that the drop-down is 100% optional, and the value of the drop-down is ignored. This is the code: Party 1: New Javascript: echo '<script>
function SetParty(){
$("#party").val($("#partyselect").val());
}
</script>
' ;
This function basically takes the values of the partyselect, and sets it in the party edit box. Val() is a Jquery property which can accept a new value, and returns the current value. $ is THE Jquery function, and the parameter is the selector you want, in these cases, the element with the ID partyselect, and the element with the ID party. Part 2: preparing the values: $res = mysql_query('SELECT * FROM RegisteredParties WHERE CosaNumber='. $cosa .' ORDER BY PartyInitials ');
if ( $res && mysql_num_rows($res) > 0 ){
$parties[''] = 'Select an option to automatically fill below';
$parties['PRESENT'] = 'PRESENT';
while ( $row = mysql_fetch_assoc($res)){
$parties[$row['PartyInitials']] =$row['PartyInitials'] . ' - '. $row['PartyName'] ;
}
Here we ask from the database the list of all of the RegisteredParties of the Current Cosa, and if we find any, we fill the array $parties with them. But first, we add the empty selector, and the PRESENT. The array key (the part between the [ and the] on the left of the =), will be the value copied in the text field "Party Vote:", while the array value (the part on the right of the = ), will be shown in the select box. There is an unclosed {, because it's further down... Part 3: The drop down $select = GetValueDropDown('partyselect', $parties, '','input span8', false, 'id="partyselect" onChange="SetParty();"');
echo BootstrapField('Parties:', $select);
}
Here, we call my function GetValueDropDown. It has 6 parameters. 1 ) The name of the field. I put 'partyselect', but I don't really use it. 2 ) The array of the options initialized in step 2 3 ) The classes of the select. I put it very large (span8 means 8 out of 12 columns) 4 ) The current value. We don't care about that, so I just put '' 5 ) If we do an automatic output, in this case, we don't want to, since we return to the variable select, so I put false 6 ) The extra parameters. Here I set the ID needed for quick jquery selection, and I put a Javascript event handler: onChance="SetParty();", which will call my function from step 1 when the value changes. Part 4: The Party Vote edit box echo BootstrapTextField('Party Vote:', 'party', $_POST, 'id="party"');
I basically just added a 4th field which is the ID I want to add for jquery fast selection.
|
|
|
Post by Marti-Pair Furxheir S.H. on Jan 7, 2016 4:53:51 GMT -6
Today, I did something that had actually been planned in 2003 before the Halloween Crisis! I then had added a field in the Province table named "SenatorElectionActive", and the plan was to allow to mark which provinces had a Senator election so that the ballot would adjust. I never handled it in the ballot, something which I want to do in the 2.0 Ballot, so that only voters in a province with a Senator election handled by the chancery will actually get asked that question. So, this morning, I modified my Senator Endorsement form to ask at the top which provinces currently have an election. There are 3 choices: - No Election - Election Run by the Chancery - Election Not run by the Chancery I then modified the Senator Endorsement edit to only ask endorsement for either types of election.
|
|
Glüc da Dhi
Secretary of State
Posts: 6,112
Talossan Since: 5-14-2009
|
Post by Glüc da Dhi on Jan 7, 2016 5:03:03 GMT -6
I thought we would be getting an election in Maricopa and not in Florencia?
|
|
|
Post by Marti-Pair Furxheir S.H. on Jan 7, 2016 6:48:58 GMT -6
I thought we would be getting an election in Maricopa and not in Florencia? We are. What are you talking about? (Seriously, I forgot when I took the screenshot that I had debugged and changed the provinces to make sure the system worked, since then, it's back to the right 4 provinces. Sorry if the Screenshots are wrong)
|
|
|
Post by Magniloqueu Épiqeu da Lhiun on Jan 7, 2016 14:04:45 GMT -6
OH LOOK THAT'S MY NAME!
|
|
|
Post by Marti-Pair Furxheir S.H. on Jan 8, 2016 4:36:32 GMT -6
Ok, so this is Ballot 1.2.
It's a TINY, TINY change, but I wanted to still make it explicit.
On like 196, I have:
if ( $_POST['save'] >0 && $ElectionActive){
I changed it to:
if ( $_POST['save'] >0 && $_POST['party'] != '' && $ElectionActive){
What this means is that we used enter the vote storing code ONLY if the form was submitted AND The Election was Active (ElectionActive was true).
Now, we also need a party vote filled. In the past, it was possible to vote in Referendums, Senate and Province without filling a Party, which as far as I know is not legal.
Furthermore, all of the voter information is stored in the party vote (IP address, vote method, Useragent), so if the party isn't filled, we miss that (I have to report it to the Validation thread as a semi-security issue I had not spotted).
Now, when the Party isn't mentioned, the form will appear again to ask again to vote, hopefully with the same values filled in, but that's yet to see.
|
|
|
Post by Marti-Pair Furxheir S.H. on Jan 8, 2016 6:57:15 GMT -6
And this is Ballot 1.3
Now, the Ballot asks you first to enter your citizen number and your PSC, but only that.
Once you have authenticated, it displays the rest of the form and you can then vote, but not change your citizen number or PSC.
So, here is what I added at the top of the Voter form:
$editor_result = mysql_query( "select * from Citizens where number=". intval($_POST['citnumber']));
$voter = mysql_fetch_assoc($editor_result);
if ( $voter['Number'] > 0 && $_POST['psc'] != '' ){
if ( $voter['Number'] > 0 && intval($voter['Active']) == 1 && substr(trim($voter['psc']),0,8) == substr(trim($_POST['psc']),0,8) ){ // we have a voter! $voterloaded = true; } else{ echo '<div class="alert alert-error"><h3>Invalid Citizen number or PSC</h3><p>Please try again or contact the Secretary of State on Wittenberg</p><p>The Database Administrator was emailed of the attempt.</div>'; unset($voter);
$mail = ''; $mail .= nl2br(print_R( $voter, true));
$mail .= nl2br(print_R( $_POST, true)); $mail .= nl2br(print_R( $_SERVER, true));
$cit['Email'] = '[my email]'; $cit['Name'] = 'Marti-Pair Furxhéir';
SendEmail($cit,'There was a failed PSC search in the database from, '. utf8_decode($voter['Name']), $mail );
}
}else{ unset($voter); }
This basically checks if we have a valid citnumber and psc loaded, and if it is the case, we set $voterloaded to true, and put the voter in $voter.
If not, we unset $voter and move on.
However, if there was indeed a voter and PSC entered but the wrong one, I get an email to warn me an attempt. This will tell me if, for example, someone does a brute force attack against the voter form.
Then, I change the title of the first box:
if ( $voterloaded ){ echo '<h3>Part 1: Identification</h3>'; echo '<h3><i>Pärts 1: Identificaziun</i></h3>'; } else{ echo '<h3>Step 1: Identification</h3>'; }
To say "Step 1" instead of "Part 1" if no voter is entered.
And then, I change the top edit:
if ( $voterloaded){ echo BootstrapTextField('Citizen Number / <i>Númerul da Citaxhién</i>:', 'citnumber', $_POST, 'disabled="disabled"'); echo BootstrapTextField('Security Code (PSC) / <i>Coda da Sigürità Perziunal</i>:', 'psc', $_POST, 'disabled="disabled"'); echo BootstrapTextField('Citizen / <i>Citaxhién</i>:', 'Name', $voter, $voterloaded? 'disabled="disabled"': ''); echo '<input type="hidden" name="citnumber" value="'.$_POST['citnumber'].'">'; echo '<input type="hidden" name="psc" value="'.$_POST['psc'].'">';
} else{ echo BootstrapTextField('Citizen Number / <i>Númerul da Citaxhién</i>:', 'citnumber', $_POST); echo BootstrapTextField('Security Code (PSC) / <i>Coda da Sigürità Perziunal</i>:', 'psc', $_POST);
echo Bootstrapfield('', ' <input type="submit" name="Submit" value="Search" class="btn btn-primary">');
}
If we have a voter, we add the name of the voter, and we put the cit number and psc edit as disabled (we then need to put hidden fields with their value as disabled fields do not send their data.
This prevents someone from authenticating as their user, and then as another user once the form is displayed. I know, a little paranoid, but I think it's needed.
I also put a search button if no voter is loaded.
if ( $voterloaded ){
Finally, I do not display the rest of the form unless a voter is loaded.
|
|
|
Post by Marti-Pair Furxheir S.H. on Jan 8, 2016 7:00:20 GMT -6
Advantages of Ballot 1.3:
1 ) The voter knows right away if their PSC is wrong, instead of filling the whole form before finding out
2 ) When the form is finally displayed, we know which voter is voting, but more importantly, from which province he is!
Ballot 1.4 will only display the Senator section if the voter's province is listed, and then, 1.5 will offer a drop down of the citizens of that voter's province.
Once Ballot 1.5 will have been tested, it should in theory become Ballot 2.0.
Then, in the next election, for Ballot 3.0, I will most likely address the provincial votes!
|
|
|
Post by Danihel Txechescu on Jan 8, 2016 8:38:08 GMT -6
Is there a Git repository for this? I'm fluent in PHPese and might help with a few things.
|
|
|
Post by Marti-Pair Furxheir S.H. on Jan 8, 2016 9:07:46 GMT -6
Is there a Git repository for this? I'm fluent in PHPese and might help with a few things. No, it's not open source. But it's good to know I am no longer the only guy who knows PHP!! The Database was officially nationalized, but it's not transferred yet. I still need a lot of work before I will open it in a few months.
|
|
|
Post by Marti-Pair Furxheir S.H. on Jan 9, 2016 5:38:29 GMT -6
So, Ballot 1.4 and 1.5 are done!!!
Here are the details on 1.4:
1 ) Just before Part 6, I add:
$province = mysql_result($province_result,$voter["Province"],"ProvinceName"); $senateelectionactive = mysql_result($province_result,$voter["Province"],"SenatorElectionActive");
So that we know which province the voter is in, and if the Senate Election is active.
2 ) The title is changed to :
echo '<h3>Part 6: Senate Election for '.$province. '</h3>'; echo '<h3><i>Pärts 6: Eleziun per el Senäts ('.$province.')</i></h3>';
So that the title shows that it is specifically for that province.
3 ) Before the Senate part, I added:
if ( $senateelectionactive == 0 ){ echo '<div class="alert alert-info"><h3>Your senator seat is not due for election</h3></div>'; } else{
So that the whole section will be skipped if the senateelectionactive is to 0 (no election), and a warning is shown.
4 ) I only show the Senate Endorsement for the province of the voter:
$res = mysql_query('SELECT * FROM senatorendorsement WHERE cosa='.$cosa.' AND province='.$voter["Province"].' ORDER BY party');
Of course, I got rid of the province column:
echo '<tr><th>Party</th><th>Endorsement</th></tr>'; while ($row = mysql_fetch_assoc($res)){ echo '<tr>'; echo '<td>'. $row['party'] .'</td>'; echo '<td>'. GetCitizenNameLinked($row['candidate']) .'</td>'; echo '</tr>'; }
5 ) If the Senate election is run by the Chancery, the value is set to 1. If not, it's set to -1.
That way, I check if the value is greater than 0 (we already know it's not 0):
if ( $senateelectionactive > 0){
echo BootstrapTextField('Senate Vote<br><i>Vota per el Senäts</i>:', 'senatevote', $_POST); } else{ echo '<div class="alert alert-info"><h3>The '.$province.' Senate election is not run by the Chancery</h3><p>You will need to contact your provincial SoS for information on how to vote.</p></div>'; }
Of course, an additional } was added below to offset the first if...
Ballot 1.5
I simply replaced:
echo BootstrapTextField('Senate Vote<br><i>Vota per el Senäts</i>:', 'senatevote', $_POST);
With:
echo BootstrapField('Senate Vote<br><i>Vota per el Senäts</i>:', GetCitizenSelectize('senatevote', $_POST['senatevote'], false, ' AND Province="'.$voter["Province"].'"'));
GetCitizenSelectize is the function which makes the new dropdown which not only lists the citzens which are active, but which allows you to type part of the name to search in it.
It has 4 parameters:
1 ) 'senatevote': The name of the field. 2 ) $_POST['senatevote']: The current value, so that if the form is resubmitted, it will keep it's value 3 ) false: True if ALL citizens are listed, false if only the Active citizens are listed. 4 ) ' AND Province="'.$voter["Province"].'"': This is an additional search condition. In this case, we only want citizesn from the voter's province
This means that now, we have everything I had planned for Ballot 2.0, except one thing: Validation and Testing.
I will need to make a mock election tomorrow to make sure it works.
|
|
|
Post by Marti-Pair Furxheir S.H. on Jan 9, 2016 6:36:54 GMT -6
Oh right, I also need to update the ballot email.
I'll do so tomorrow.
|
|
|
Post by Marti-Pair Furxheir S.H. on Jan 10, 2016 5:48:09 GMT -6
Oh right, I also need to update the ballot email. I'll do so tomorrow. That is now done.
|
|