root/wp-polls/trunk/polls-add.php

Revision 49932, 10.3 kB (checked in by GamerZ, 1 month ago)

Fixed MYSQL Charset Issue

Line 
1 <?php
2 /*
3 +----------------------------------------------------------------+
4 |                                                                                            |
5 |    WordPress 2.5 Plugin: WP-Polls 2.31                                        |
6 |    Copyright (c) 2008 Lester "GaMerZ" Chan                                    |
7 |                                                                                            |
8 |    File Written By:                                                                    |
9 |    - Lester "GaMerZ" Chan                                                            |
10 |    - http://lesterchan.net                                                            |
11 |                                                                                            |
12 |    File Information:                                                                    |
13 |    - Add Poll                                                                            |
14 |    - wp-content/plugins/wp-polls/polls-add.php                                |
15 |                                                                                            |
16 +----------------------------------------------------------------+
17 */
18
19
20 ### Check Whether User Can Manage Polls
21 if(!current_user_can('manage_polls')) {
22     die('Access Denied');
23 }
24
25
26 ### Poll Manager
27 $base_name = plugin_basename('wp-polls/polls-manager.php');
28 $base_page = 'admin.php?page='.$base_name;
29
30
31 ### Form Processing
32 if(!empty($_POST['do'])) {
33     // Decide What To Do
34     switch($_POST['do']) {
35         // Add Poll
36         case __('Add Poll', 'wp-polls'):
37             // Poll Question
38             $pollq_question = addslashes(trim($_POST['pollq_question']));
39             // Poll Start Date
40             $timestamp_sql = '';
41             $pollq_timestamp_day = intval($_POST['pollq_timestamp_day']);
42             $pollq_timestamp_month = intval($_POST['pollq_timestamp_month']);
43             $pollq_timestamp_year = intval($_POST['pollq_timestamp_year']);
44             $pollq_timestamp_hour = intval($_POST['pollq_timestamp_hour']);
45             $pollq_timestamp_minute = intval($_POST['pollq_timestamp_minute']);
46             $pollq_timestamp_second = intval($_POST['pollq_timestamp_second']);
47             $pollq_timestamp = gmmktime($pollq_timestamp_hour, $pollq_timestamp_minute, $pollq_timestamp_second, $pollq_timestamp_month, $pollq_timestamp_day, $pollq_timestamp_year);
48             if($pollq_timestamp > current_time('timestamp')) {
49                 $pollq_active = -1;
50             } else {
51                 $pollq_active = 1;
52             }
53             // Poll End Date
54             $pollq_expiry_no = intval($_POST['pollq_expiry_no']);
55             if($pollq_expiry_no == 1) {
56                 $pollq_expiry = '';
57             } else {
58                 $pollq_expiry_day = intval($_POST['pollq_expiry_day']);
59                 $pollq_expiry_month = intval($_POST['pollq_expiry_month']);
60                 $pollq_expiry_year = intval($_POST['pollq_expiry_year']);
61                 $pollq_expiry_hour = intval($_POST['pollq_expiry_hour']);
62                 $pollq_expiry_minute = intval($_POST['pollq_expiry_minute']);
63                 $pollq_expiry_second = intval($_POST['pollq_expiry_second']);
64                 $pollq_expiry = gmmktime($pollq_expiry_hour, $pollq_expiry_minute, $pollq_expiry_second, $pollq_expiry_month, $pollq_expiry_day, $pollq_expiry_year);
65                 if($pollq_expiry <= current_time('timestamp')) {
66                     $pollq_active = 0;
67                 }
68             }
69             // Mutilple Poll
70             $pollq_multiple_yes = intval($_POST['pollq_multiple_yes']);
71             $pollq_multiple = 0;
72             if($pollq_multiple_yes == 1) {
73                 $pollq_multiple = intval($_POST['pollq_multiple']);
74             } else {
75                 $pollq_multiple = 0;
76             }
77             // Insert Poll
78             $add_poll_question = $wpdb->query("INSERT INTO $wpdb->pollsq VALUES (0, '$pollq_question', '$pollq_timestamp', 0, $pollq_active, '$pollq_expiry', $pollq_multiple, 0)");
79             if(!$add_poll_question) {
80                 $text .= '<p style="color: red;">'.sprintf(__('Error In Adding Poll \'%s\'.', 'wp-polls'), stripslashes($pollq_question)).'</p>';
81             }
82             // Add Poll Answers
83             $polla_answers = $_POST['polla_answers'];
84             $polla_qid = intval($wpdb->insert_id);
85             foreach($polla_answers as $polla_answer) {
86                 $polla_answer = addslashes(trim($polla_answer));
87                 $add_poll_answers = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0, $polla_qid, '$polla_answer', 0)");
88                 if(!$add_poll_answers) {
89                     $text .= '<p style="color: red;">'.sprintf(__('Error In Adding Poll\'s Answer \'%s\'.', 'wp-polls'), stripslashes($polla_answer)).'</p>';
90                 }
91             }
92             // Update Lastest Poll ID To Poll Options
93             $latest_pollid = polls_latest_id();
94             $update_latestpoll = update_option('poll_latestpoll', $latest_pollid);
95             if(empty($text)) {
96                 $text = '<p style="color: green;">'.sprintf(__('Poll \'%s\' Added Successfully.', 'wp-polls'), stripslashes($pollq_question)).' <a href="'.$base_page.'">'.__('Manage Polls', 'wp-polls').'</a></p>';
97             }
98             cron_polls_place();
99             break;
100     }
101 }
102
103 ### Add Poll Form
104 $poll_noquestion = 2;
105 $count = 0;
106 ?>
107 <script type="text/javascript">
108     /* <![CDATA[*/
109     function check_pollexpiry() {
110         poll_expiry = document.getElementById("pollq_expiry_no").checked;
111         if(poll_expiry) {
112             document.getElementById("pollq_expiry").style.display = 'none';
113         } else {
114             document.getElementById("pollq_expiry").style.display = 'block';
115         }
116     }
117     var count_poll_answer = <?php echo $poll_noquestion; ?>;
118     function create_poll_answer() {
119         // Create Elements
120         var poll_tr = document.createElement("tr");
121         var poll_td1 = document.createElement("th");
122         var poll_td2 = document.createElement("td");
123         var poll_answer = document.createElement("input");
124         var poll_answer_count = document.createTextNode("<?php _e('Answer', 'wp-polls'); ?> " + (count_poll_answer+1));
125         var poll_answer_bold = document.createElement("strong");
126         var poll_option = document.createElement("option");
127         var poll_option_text = document.createTextNode((count_poll_answer+1));
128         count_poll_answer++;
129         // Elements - Input
130         poll_answer.setAttribute('type', "text");
131         poll_answer.setAttribute('name', "polla_answers[]");
132         poll_answer.setAttribute('size', "50");
133         // Elements - Options
134         poll_option.setAttribute('value', count_poll_answer);
135         poll_option.setAttribute('id', "pollq-multiple-" + (count_poll_answer+1));
136         // Elements - TD/TR
137         poll_tr.setAttribute('id', "poll-answer-" + count_poll_answer);
138         poll_td1.setAttribute('width', "20%");
139         poll_td1.setAttribute('scope', "row");
140         poll_td2.setAttribute('width', "80%");
141         // Appending
142         poll_tr.appendChild(poll_td1);
143         poll_tr.appendChild(poll_td2);
144         poll_answer_bold.appendChild(poll_answer_count);
145         poll_td1.appendChild(poll_answer_bold);
146         poll_td2.appendChild(poll_answer);
147         poll_option.appendChild(poll_option_text);
148         document.getElementById("poll_answers").appendChild(poll_tr);
149         document.getElementById("pollq_multiple").appendChild(poll_option);
150     }
151     function remove_poll_answer() {
152         if(count_poll_answer == 2) {
153             alert("<?php _e('You need at least a minimum of 2 poll answers.', 'wp-polls'); ?>");
154         } else {
155             document.getElementById("poll_answers").removeChild(document.getElementById("poll-answer-" + count_poll_answer));
156             document.getElementById("pollq_multiple").removeChild(document.getElementById("pollq-multiple-" + (count_poll_answer+1)));
157             document.getElementById("pollq_multiple").value = count_poll_answer;
158             count_poll_answer--;
159         }
160     }
161     function check_pollq_multiple() {
162         if(parseInt(document.getElementById("pollq_multiple_yes").value) == 1) {
163             document.getElementById("pollq_multiple").disabled = false;
164         } else {
165             document.getElementById("pollq_multiple").value = 1;
166             document.getElementById("pollq_multiple").disabled = true;
167         }
168     }
169     /* ]]> */
170 </script>
171 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade">'.stripslashes($text).'</div>'; } ?>
172 <form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?>" method="post">
173 <div class="wrap">
174     <h2><?php _e('Add Poll', 'wp-polls'); ?></h2>
175     <!-- Poll Question -->
176     <h3><?php _e('Poll Question', 'wp-polls'); ?></h3>
177     <table class="form-table">
178         <tr>
179             <th width="20%" scope="row" valign="top"><?php _e('Question', 'wp-polls') ?></th>
180             <td width="80%"><input type="text" size="70" name="pollq_question" value="" /></td>
181         </tr>
182     </table>
183     <!-- Poll Answers -->
184     <h3><?php _e('Poll Answers', 'wp-polls'); ?></h3>
185     <table class="form-table">
186         <tfoot>
187             <tr>
188                 <td width="20%">&nbsp;</td>
189                 <td width="80%"><input type="button" value="<?php _e('Add Answer', 'wp-polls') ?>" onclick="create_poll_answer();" class="button" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="<?php _e('Remove Answer', 'wp-polls') ?>" onclick="remove_poll_answer();" class="button" /></td>
190             </tr>
191         </tfoot>
192         <tbody id="poll_answers">
193         <?php
194             for($i = 1; $i <= $poll_noquestion; $i++) {
195                 echo "<tr id=\"poll-answer-$i\">\n";
196                 echo "<th width=\"20%\" scope=\"row\" valign=\"top\">".sprintf(__('Answer %s', 'wp-polls'), $i)."</th>\n";
197                 echo "<td width=\"80%\"><input type=\"text\" size=\"50\" name=\"polla_answers[]\" /></td>\n";
198                 echo "</tr>\n";
199                 $count++;
200             }
201         ?>
202         </tbody>
203     </table>
204     <!-- Poll Multiple Answers -->
205     <h3><?php _e('Poll Multiple Answers', 'wp-polls') ?></h3>
206     <table class="form-table">
207         <tr>
208             <th width="40%" scope="row" valign="top"><?php _e('Allows Users To Select More Than One Answer?', 'wp-polls'); ?></th>
209             <td width="60%">
210                 <select name="pollq_multiple_yes" id="pollq_multiple_yes" size="1" onchange="check_pollq_multiple();">
211                     <option value="0"><?php _e('No', 'wp-polls'); ?></option>
212                     <option value="1"><?php _e('Yes', 'wp-polls'); ?></option>
213                 </select>
214             </td>
215         </tr>
216         <tr>
217             <th width="40%" scope="row" valign="top"><?php _e('Maximum Number Of Selected Answers Allowed?', 'wp-polls') ?></th>
218             <td width="60%">
219                 <select name="pollq_multiple" id="pollq_multiple" size="1" disabled="disabled">
220                     <?php
221                         for($i = 1; $i <= $poll_noquestion; $i++) {
222                             echo "<option value=\"$i\">$i</option>\n";
223                         }
224                     ?>
225                 </select>
226             </td>
227         </tr>
228     </table>
229     <!-- Poll Start/End Date -->
230     <h3><?php _e('Poll Start/End Date', 'wp-polls'); ?></h3>
231     <table class="form-table">
232         <tr>
233             <th width="20%" scope="row" valign="top"><?php _e('Start Date/Time', 'wp-polls') ?></th>
234             <td width="80%"><?php poll_timestamp(current_time('timestamp')); ?></td>
235         </tr>
236         <tr>
237             <th width="20%" scope="row" valign="top"><?php _e('End Date/Time', 'wp-polls') ?></th>
238             <td width="80%"><input type="checkbox" name="pollq_expiry_no" id="pollq_expiry_no" value="1" checked="checked" onclick="check_pollexpiry();" />&nbsp;&nbsp;<label for="pollq_expiry_no"><?php _e('Do NOT Expire This Poll', 'wp-polls'); ?></label><?php poll_timestamp(current_time('timestamp'), 'pollq_expiry', 'none'); ?></td>
239         </tr>
240     </table>
241     <p style="text-align: center;"><input type="submit" name="do" value="<?php _e('Add Poll', 'wp-polls'); ?>"  class="button" />&nbsp;&nbsp;<input type="button" name="cancel" value="<?php _e('Cancel', 'wp-polls'); ?>" class="button" onclick="javascript:history.go(-1)" /></p>
242 </div>
243 </form>
Note: See TracBrowser for help on using the browser.