function manage_surveys() { global $table_prefix, $wpdb; $survey_table = $table_prefix . "surveys"; if (isset($_REQUEST["wpsurv_submit"])) { require_once 'functions.php'; if ($_POST["wpsurv_submit"] == __('Edit', 'wp-surveys') || $_POST["wpsurv_submit"] == __('Cancel', 'wp-surveys') || $_POST["wpsurv_submit"] == __('Back to Edit Survey', 'wp-surveys')) { edit($_POST['survey_id']); } elseif ($_POST["wpsurv_submit"] == __('Update', 'wp-surveys')) { update($_POST['survey_id']); } elseif ($_POST["wpsurv_submit"] == __('Update Options', 'wp-surveys')) { update_options($_POST['survey_id'], $_POST['question_id']); } elseif ($_POST["wpsurv_submit"] == __('Activate', 'wp-surveys') || $_POST["wpsurv_submit"] == __('Make Active', 'wp-surveys')) { activate($_POST['survey_id']); } elseif ($_POST["wpsurv_submit"] == __('Retire', 'wp-surveys')) { retire($_POST['survey_id']); } elseif ($_POST["wpsurv_submit"] == __('Update Leaderboard', 'wp-surveys')) { recach_utility($_POST['survey_id']); } elseif ($_POST["wpsurv_submit"] == __('Edit Options', 'wp-surveys') || $_POST["wpsurv_submit"] == __('Add Some Options', 'wp-surveys') || $_POST["wpsurv_submit"] == __('Edit or Add more Options', 'wp-surveys')) { edit_options($_POST['survey_id'], $_POST['question_id']); } elseif ($_POST["wpsurv_submit"] == __('Add More Questions', 'wp-surveys') || $_POST["wpsurv_submit"] == __('Add Some Questions', 'wp-surveys')) { add_question($_POST['survey_id']); } elseif ($_POST["wpsurv_submit"] == __('Step 2', 'wp-surveys')) { step2($_POST['survey_id']); } elseif ($_POST["wpsurv_submit"] == __('Create Question', 'wp-surveys')) { create_quest($_POST['survey_id']); } elseif ($_POST["wpsurv_submit"] == __('Change Survey', 'wp-surveys') || $_POST["wpsurv_submit"] == __('Add Survey', 'wp-surveys')) { survey($_POST['survey_id']); } elseif ($_POST["wpsurv_submit"] == __('Add This Survey', 'wp-surveys')) { add_survey($_POST['survey_id']); } elseif ($_POST["wpsurv_submit"] == __('View Survey Results', 'wp-surveys')) { results($_POST['survey_id']); } //elseif($_POST["wpsurv_submit"] == __('View Survey Results in CSV File', 'wp-surveys')) //results_CSV($_POST['survey_id']); //elseif($_POST["wpsurv_submit"] == __('Delete File', 'wp-surveys')) //delete_file($_POST['survey_id']); } else { $current_plugins = get_option('active_plugins'); if (file_exists(ABSPATH . PLUGINDIR . '/polyglot.php') && in_array('polyglot.php', $current_plugins)) { $polyglot = true; } echo '<div class="wrap">'; $open_surveys = $wpdb->get_results("SELECT * FROM `" . $survey_table . "` WHERE `survey_open`='1' LIMIT 1;", ARRAY_A); echo '<h2>' . __('Survey Management', 'wp-surveys') . '</h2><h3><u>' . __('Active Survey', 'wp-surveys') . '</u>:</h3>'; if ($open_surveys) { echo '<table class="widefat" width="100%" cellpadding="4" cellspacing="4">'; echo '<tr><th align="left">' . __('Title', 'wp-surveys') . '</th><th align="left">' . __('Description', 'wp-surveys') . '</th><th></th><th></th><th></th></tr>'; foreach ($open_surveys as $survey) { echo '<tr class="alternate">'; if ($polyglot) { echo '<td><b>' . polyglot_filter(stripcslashes($survey['survey_name'])) . '</b></td><td>' . polyglot_filter(stripcslashes($survey['survey_describe'])) . '</td>'; } elseif (!$polyglot) { echo '<td><b>' . stripcslashes($survey['survey_name']) . '</b></td><td>' . stripcslashes($survey['survey_describe']) . '</td>'; } echo '<td class="submit" align="center"><form method="post" action=""><input type="hidden" name="survey_id" value="' . $survey['survey_id'] . '" />'; echo '<input type="submit" name="wpsurv_submit" value="' . __('Edit', 'wp-surveys') . '" /></form></td>'; echo '<td class="submit" align="center"><form method="post" action=""><input type="hidden" name="survey_id" value="' . $survey['survey_id'] . '" />'; echo '<input type="submit" name="wpsurv_submit" value="' . __('Retire', 'wp-surveys') . '" /></form></td>'; echo '<td class="submit" align="center"><form method="post" action=""><input type="hidden" name="survey_id" value="' . $survey['survey_id'] . '" />'; echo '<input type="submit" name="wpsurv_submit" value="' . __('View Survey Results', 'wp-surveys') . '" /></form></td>'; //echo '<td align="center"><form method="post" action=""><input type="hidden" name="survey_id" value="'.$survey['survey_id'].'" />'; //echo '<input type="submit" name="wpsurv_submit" value="'.__('View Survey Results in CSV File', 'wp-surveys').'" /></form></td>'; echo '</tr>'; } echo '</table>'; $next = ++$survey['survey_id']; echo '<br /><form method="post" action=""><input type="hidden" name="survey_id" value="' . $next . '" /><input class="button" type="submit" name="wpsurv_submit" value="' . __('Change Survey', 'wp-surveys') . '" title="' . __('Current Survey will be saved as Retired', 'wp-surveys') . '" /></form>'; } else { echo __('There are no open tournaments or contests.', 'wp-surveys') . '.'; //$last = $wpdb->get_var("SELECT COUNT(`survey_id`) FROM `".$survey_table."`;"); $last = $wpdb->get_var("SELECT `survey_id` FROM `" . $survey_table . "` ORDER BY `survey_id` DESC LIMIT 1;"); $next = ++$last; echo '<br /><br /><form method="post" action=""><input type="hidden" name="survey_id" value="' . $next . '" /><input class="button" type="submit" name="wpsurv_submit" value="' . __('Add Survey', 'wp-surveys') . '" /></form>'; } $closed_surveys = $wpdb->get_results("SELECT * FROM `" . $survey_table . "` WHERE `survey_open`='0';", ARRAY_A); echo '<h3><u>' . __('Retired Surveys', 'wp-surveys') . '</u>:</h3>'; if ($closed_surveys) { echo '<table class="widefat" width="100%" cellpadding="4" cellspacing="4">'; echo '<tr><th align="left">' . __('Title', 'wp-surveys') . '</th><th align="left">' . __('Description', 'wp-surveys') . '</th><th></th><th></th><th></th></tr>'; foreach ($closed_surveys as $survey) { echo '<tr class="alternate">'; if ($polyglot) { echo '<td><b>' . polyglot_filter(stripcslashes($survey['survey_name'])) . '</b></td><td>' . polyglot_filter(stripcslashes($survey['survey_describe'])) . '</td>'; } elseif (!$polyglot) { echo '<td><b>' . stripcslashes($survey['survey_name']) . '</b></td><td>' . stripcslashes($survey['survey_describe']) . '</td>'; } echo '<td class="submit" align="center"><form method="post" action=""><input type="hidden" name="survey_id" value="' . $survey['survey_id'] . '" />'; echo '<input type="submit" name="wpsurv_submit" value="' . __('Edit', 'wp-surveys') . '" /></form></td>'; echo '<td class="submit" align="center"><form method="post" action=""><input type="hidden" name="survey_id" value="' . $survey['survey_id'] . '" />'; echo '<input type="submit" name="wpsurv_submit" value="' . __('Make Active', 'wp-surveys') . '" /></form></td>'; echo '<td class="submit" align="center"><form method="post" action=""><input type="hidden" name="survey_id" value="' . $survey['survey_id'] . '" />'; echo '<input type="submit" name="wpsurv_submit" value="' . __('View Survey Results', 'wp-surveys') . '" /></form></td>'; //echo '<td align="center"><form method="post" action=""><input type="hidden" name="survey_id" value="'.$survey['survey_id'].'" />'; //echo '<input type="submit" name="wpsurv_submit" value="'.__('View Survey Results in CSV File', 'wp-surveys').'" /></form></td>'; echo '</tr>'; } echo '</table>'; } else { echo __('There are no retired surveys', 'wp-surveys') . '.'; } echo '</div>'; } }
function update_options($survey_id, $question_id) { global $table_prefix, $wpdb; $question_table = $table_prefix . "surveys_questions"; $fields = 0; for ($i = 0; $i < 16; $i++) { $column = "question_option_" . $i; $current_option = $wpdb->get_var("SELECT `" . $column . "` FROM `" . $question_table . "` WHERE `question_id`=" . $question_id . " LIMIT 1;"); if ($current_option != trim($_POST[$column])) { $wpdb->query("UPDATE `" . $question_table . "` SET `" . $column . "`='" . $wpdb->escape(trim($_POST[$column])) . "' WHERE `question_id`=" . $question_id . " LIMIT 1;"); } else { $fields++; } } $answer_options = array("answer_option_0_1", "answer_option_0_3", "answer_option_2_3", "answer_option_0_7", "answer_option_4_5", "answer_option_4_7", "answer_option_6_7", "answer_option_0_15", "answer_option_8_9", "answer_option_8_11", "answer_option_10_11", "answer_option_8_15", "answer_option_12_13", "answer_option_12_15", "answer_option_14_15"); foreach ($answer_options as $answer_option) { $current_option = $wpdb->get_var("SELECT `" . $answer_option . "` FROM `" . $question_table . "` WHERE `question_id`=" . $question_id . " LIMIT 1;"); if ($current_option != trim($_POST[$answer_option])) { $column_name = trim($_POST[$answer_option]); preg_match("/_(\\d+)/", $column_name, $results); # $array_set = preg_match_batch("/$results[1]/"),$answer_options); # echo 'Results: '.$array_set[1]; $wpdb->query("UPDATE `" . $question_table . "` SET `" . $answer_option . "`='" . $wpdb->escape(trim($_POST[$answer_option])) . "' WHERE `question_id`=" . $question_id . " LIMIT 1;"); } else { $fields++; } //to 15 } //$column = "question_forever"; //$current_option = $wpdb->get_var("SELECT `".$column."` FROM `".$question_table."` WHERE `question_id`=".$question_id." LIMIT 1;"); //if($current_option != $_POST[$column]) //$wpdb->query("UPDATE `".$question_table."` SET `".$column."`='".$wpdb->escape($_POST[$column])."' WHERE `question_id`=".$question_id." LIMIT 1;"); if ($fields == 16 + 15) { echo '<div id="message0" class="updated fade"><p><strong>' . __('No changes had been made', 'wp-surveys') . '</strong></p></div>'; edit_options($_POST['survey_id'], $_POST['question_id']); return; } else { echo '<div id="message" class="updated fade"><h3><strong>' . __('Update Complete!', 'wp-surveys') . '</strong></h3><p class="submit">' . __('Changes have been applied', 'wp-surveys') . '.</p><form method="post" action=""><p class="submit"><input type="hidden" name="survey_id" value="' . $survey_id . '" />'; echo '<input type="submit" name="wpsurv_submit" value="' . __('Back to Edit Survey', 'wp-surveys') . '" /></p></form>'; echo '<p><a href="http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '" >' . __('Continue', 'wp-surveys') . '...</a></p></div>'; } }
function update_options($survey_id, $question_id) { global $table_prefix, $wpdb; $question_table = $table_prefix . "surveys_questions"; $fields = 0; for ($i = 0; $i < 10; $i++) { $column = "question_option_" . $i; $current_option = $wpdb->get_var("SELECT `" . $column . "` FROM `" . $question_table . "` WHERE `question_id`=" . $question_id . " LIMIT 1;"); if ($current_option != trim($_POST[$column])) { $wpdb->query("UPDATE `" . $question_table . "` SET `" . $column . "`='" . $wpdb->escape(trim($_POST[$column])) . "' WHERE `question_id`=" . $question_id . " LIMIT 1;"); } else { $fields++; } } //$column = "question_forever"; //$current_option = $wpdb->get_var("SELECT `".$column."` FROM `".$question_table."` WHERE `question_id`=".$question_id." LIMIT 1;"); //if($current_option != $_POST[$column]) //$wpdb->query("UPDATE `".$question_table."` SET `".$column."`='".$wpdb->escape($_POST[$column])."' WHERE `question_id`=".$question_id." LIMIT 1;"); if ($fields == 10) { echo '<div id="message0" class="updated fade"><p><strong>' . __('No changes had been made', 'wp-surveys') . '</strong></p></div>'; edit_options($_POST['survey_id'], $_POST['question_id']); return; } else { echo '<div id="message" class="updated fade"><h3><strong>' . __('Update Complete!', 'wp-surveys') . '</strong></h3><p class="submit">' . __('Changes have been applied', 'wp-surveys') . '.</p><form method="post" action=""><p class="submit"><input type="hidden" name="survey_id" value="' . $survey_id . '" />'; echo '<input type="submit" name="wpsurv_submit" value="' . __('Back to Edit Survey', 'wp-surveys') . '" /></p></form>'; echo '<p><a href="http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '" >' . __('Continue', 'wp-surveys') . '...</a></p></div>'; } }
case "optionstable": if ($_SESSION['ticket_user_is_admin'] < 2) { print '<FONT CLASS="warn">Not authorized.</FONT><BR><BR>'; } else { switch ($_GET["go"]) { case "": //edit_input_options("nogo"); edit_options("nogo"); break; case "edit": //edit_input_options("edit"); edit_options("edit"); break; case "update": //edit_input_options("update"); edit_options("update"); break; } //print '<HR>'; print '<table cellpadding=8><tr><td>'; print '<FORM METHOD="POST" ACTION="config.php">'; print '<INPUT TYPE="submit" VALUE="Back to <Settings>">'; print '</form>'; if ($_GET["go"]) { print '</td><td>'; print '<FORM METHOD="POST" ACTION="config.php?mode=optionstable">'; print '<INPUT TYPE="submit" VALUE="Cancel / Go Back">'; print '</form>'; } print '</td></tr></table>'; powered();