Update petitions.php
[clinton/MarylandElectronicPetitionSignature.git] / admin / petitions.php
1 <?PHP
2 include_once('../slack.php');
3 include_once('security.php');
4 if ($_COOKIE['level'] == 'user'){
5 slack_general('ADMIN: Redirect User Home ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
6 header('Location: user_home.php');
7 }
8 include_once('header.php');
9 slack_general('ADMIN: petition manager Loaded ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
10 $group_id = $_COOKIE['group_id'];
11
12 if(empty($_POST['petition_id']) && isset($_POST['petition_name']) ){ // new
13 $web_short_name = $petition->real_escape_string($_POST['web_short_name']);
14 $web_color = $petition->real_escape_string($_POST['web_color']);
15 $petition_name = $petition->real_escape_string($_POST['petition_name']);
16 $petition->query("insert into petitions (web_short_name,web_color,group_id,petition_name) values ('$web_short_name','$web_color','$group_id','$petition_name') ");
17 }
18 if(isset($_POST['petition_id']) && isset($_POST['petition_name']) ){ // edit
19 $petition_id = $petition->real_escape_string($_POST['petition_id']);
20 $web_short_name = $petition->real_escape_string($_POST['web_short_name']);
21 $web_color = $petition->real_escape_string($_POST['web_color']);
22 $petition_name = $petition->real_escape_string($_POST['petition_name']);
23 $petition_sign_text_box = $petition->real_escape_string($_POST['petition_sign_text_box']);
24 $petition_circulator_text_box = $petition->real_escape_string($_POST['petition_circulator_text_box']);
25 $eligibleVoterListEnforce = $petition->real_escape_string($_POST['eligibleVoterListEnforce']);
26 $eligibleVoterListField = $petition->real_escape_string($_POST['eligibleVoterListField']);
27 $eligibleVoterListEquals = $petition->real_escape_string($_POST['eligibleVoterListEquals']);
28 $petition->query("update petitions set web_short_name='$web_short_name', web_color='$web_color', petition_name='$petition_name', petition_sign_text_box='$petition_sign_text_box', petition_circulator_text_box='$petition_circulator_text_box', eligibleVoterListEnforce='$eligibleVoterListEnforce', eligibleVoterListField='$eligibleVoterListField', eligibleVoterListEquals='$eligibleVoterListEquals' where petition_id = '$petition_id' ");
29 }
30 ?>
31 <h1>Petitions</h1>
32 <?PHP
33 if($_COOKIE['level'] == 'admin'){
34 $q="SELECT * FROM petitions";
35 }else{
36 $q="SELECT * FROM petitions where group_id = '$group_id'";
37 }
38 $r = $petition->query($q);
39 while($d = mysqli_fetch_array($r)){
40 echo "<li><a href='?edit=$d[petition_id]'>EDIT</a> $d[admin_status] $d[web_short_name] $d[web_color] $d[group_id] $d[petition_name] $d[eligibleVoterListField] $d[eligibleVoterListEquals] $d[eligibleVoterListEnforce]</li>";
41 }
42 ?>
43
44 <?PHP
45 if (isset($_GET['edit'])){
46 $id = intval($_GET['edit']);
47 $q = "SELECT * FROM petitions where petition_id = '$id' ";
48 $r = $petition->query($q);
49 $d = mysqli_fetch_array($r);
50 ?>
51 <h1>Edit Petition Setup</h1>
52 <h3>Please keep whatever text you use in a word or google doc that you control, copy and paste here.</h3>
53 <form method='post'>
54 <input type='hidden' name='petition_id' value='<?PHP echo $id;?>'>
55 <table>
56 <tr><td>Web Short Name*</td><td><input name='web_short_name' value='<?PHP echo $d['web_short_name'];?>' required></td></tr>
57 <tr><td>Web Color</td><td><input name='web_color' value='<?PHP echo $d['web_color'];?>' required></td></tr>
58 <tr><td>Petition Name</td><td><input name='petition_name' value='<?PHP echo $d['petition_name'];?>' required></td></tr>
59 <tr><td>Petition Sign Text Box</td><td><textarea rows='5' cols='50' name='petition_sign_text_box' required><?PHP echo $d['petition_sign_text_box'];?></textarea></td></tr>
60 <tr><td>Petition Circulator Text Box</td><td><textarea rows='5' cols='50' name='petition_circulator_text_box' required><?PHP echo $d['petition_circulator_text_box'];?></textarea></td></tr>
61 <tr><td>eligibleVoterList Enforce</td><td><select name='eligibleVoterListEnforce'><option><?PHP echo $d['eligibleVoterListEnforce'];?></option><option>NO</option><option>YES</option></select></td></tr>
62 <tr><td>eligibleVoterList Field</td><td><input name='eligibleVoterListField' value='<?PHP echo $d['eligibleVoterListField'];?>' required></td></tr>
63 <tr><td>eligibleVoterList Equals</td><td><input name='eligibleVoterListEquals' value='<?PHP echo $d['eligibleVoterListEquals'];?>' required></td></tr>
64 <tr><td></td><td><input type='submit'></td></tr>
65 </table>
66 </form>
67 * changes may break already sent invites!
68
69 <?PHP
70 }
71 ?>
72 <h1>New Petition</h1>
73 <form method='post'>
74 web_short_name <input name='web_short_name' required>
75 web_color <input name='web_color' required>
76 petition_name <input name='petition_name' required>
77 <input type='submit'>
78 </form>
79 <br><br><br>
80 <?PHP
81 include_once('footer.php');
82 ?>