Advertisement
Guest User

Insert Answers from DB

a guest
Dec 19th, 2010
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.41 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. +----------------------------------------------------------------+
  6.  
  7. |                                                                                           |
  8.  
  9. |   WordPress 2.8 Plugin: WP-Polls 2.60                                     |
  10.  
  11. |   Copyright (c) 2009 Lester "GaMerZ" Chan                                 |
  12.  
  13. |                                                                                           |
  14.  
  15. |   File Written By:                                                                    |
  16.  
  17. |   - Lester "GaMerZ" Chan                                                          |
  18.  
  19. |   - http://lesterchan.net                                                         |
  20.  
  21. |                                                                                           |
  22.  
  23. |   File Information:                                                                   |
  24.  
  25. |   - Add Poll                                                                          |
  26.  
  27. |   - wp-content/plugins/wp-polls/polls-add.php                             |
  28.  
  29. |                                                                                           |
  30.  
  31. +----------------------------------------------------------------+
  32.  
  33. */
  34.  
  35.  
  36.  
  37.  
  38.  
  39. ### Check Whether User Can Manage Polls
  40.  
  41. if(!current_user_can('manage_polls')) {
  42.  
  43.     die('Access Denied');
  44.  
  45. }
  46.  
  47.  
  48.  
  49.  
  50.  
  51. ### Poll Manager
  52.  
  53. $base_name = plugin_basename('wp-polls/polls-manager.php');
  54.  
  55. $base_page = 'admin.php?page='.$base_name;
  56.  
  57.  
  58.  
  59.  
  60.  
  61. ### Form Processing
  62.  
  63. if(!empty($_POST['do'])) {
  64.  
  65.     // Decide What To Do
  66.  
  67.     switch($_POST['do']) {
  68.  
  69.         // Add Poll
  70.  
  71.         case __('Add Poll', 'wp-polls'):
  72.  
  73.             check_admin_referer('wp-polls_add-poll');
  74.  
  75.             // Poll Question
  76.  
  77.             $pollq_question = addslashes(trim($_POST['pollq_question']));
  78.  
  79.             // Poll Start Date
  80.  
  81.             $timestamp_sql = '';
  82.  
  83.             $pollq_timestamp_day = intval($_POST['pollq_timestamp_day']);
  84.  
  85.             $pollq_timestamp_month = intval($_POST['pollq_timestamp_month']);
  86.  
  87.             $pollq_timestamp_year = intval($_POST['pollq_timestamp_year']);
  88.  
  89.             $pollq_timestamp_hour = intval($_POST['pollq_timestamp_hour']);
  90.  
  91.             $pollq_timestamp_minute = intval($_POST['pollq_timestamp_minute']);
  92.  
  93.             $pollq_timestamp_second = intval($_POST['pollq_timestamp_second']);
  94.  
  95.             $pollq_timestamp = gmmktime($pollq_timestamp_hour, $pollq_timestamp_minute, $pollq_timestamp_second, $pollq_timestamp_month, $pollq_timestamp_day, $pollq_timestamp_year);
  96.  
  97.             if($pollq_timestamp > current_time('timestamp')) {
  98.  
  99.                 $pollq_active = -1;
  100.  
  101.             } else {
  102.  
  103.                 $pollq_active = 1;
  104.  
  105.             }
  106.  
  107.             // Poll End Date
  108.  
  109.             $pollq_expiry_no = intval($_POST['pollq_expiry_no']);
  110.  
  111.             if($pollq_expiry_no == 1) {
  112.  
  113.                 $pollq_expiry = '';
  114.  
  115.             } else {
  116.  
  117.                 $pollq_expiry_day = intval($_POST['pollq_expiry_day']);
  118.  
  119.                 $pollq_expiry_month = intval($_POST['pollq_expiry_month']);
  120.  
  121.                 $pollq_expiry_year = intval($_POST['pollq_expiry_year']);
  122.  
  123.                 $pollq_expiry_hour = intval($_POST['pollq_expiry_hour']);
  124.  
  125.                 $pollq_expiry_minute = intval($_POST['pollq_expiry_minute']);
  126.  
  127.                 $pollq_expiry_second = intval($_POST['pollq_expiry_second']);
  128.  
  129.                 $pollq_expiry = gmmktime($pollq_expiry_hour, $pollq_expiry_minute, $pollq_expiry_second, $pollq_expiry_month, $pollq_expiry_day, $pollq_expiry_year);
  130.  
  131.                 if($pollq_expiry <= current_time('timestamp')) {
  132.  
  133.                     $pollq_active = 0;
  134.  
  135.                 }
  136.  
  137.             }
  138.  
  139.             // Mutilple Poll
  140.  
  141.             $pollq_multiple_yes = intval($_POST['pollq_multiple_yes']);
  142.  
  143.             $pollq_multiple = 0;
  144.  
  145.             if($pollq_multiple_yes == 1) {
  146.  
  147.                 $pollq_multiple = intval($_POST['pollq_multiple']);
  148.  
  149.             } else {
  150.  
  151.                 $pollq_multiple = 0;
  152.  
  153.             }
  154.  
  155.             // Insert Poll
  156.  
  157.             $add_poll_question = $wpdb->query("INSERT INTO $wpdb->pollsq VALUES (0, '$pollq_question', '$pollq_timestamp', 0, $pollq_active, '$pollq_expiry', $pollq_multiple, 0)");
  158.  
  159.             if(!$add_poll_question) {
  160.  
  161.                 $text .= '<p style="color: red;">'.sprintf(__('Error In Adding Poll \'%s\'.', 'wp-polls'), stripslashes($pollq_question)).'</p>';
  162.  
  163.             }
  164.            
  165.            
  166.             //Check to see if this is a stylist or salon poll
  167.            
  168.             $pos = strpos(trim(strtolower($_POST['pollq_question'])),'stylist');
  169.             $pos2 = strpos(trim(strtolower($_POST['pollq_question'])),'salon');
  170.  
  171.             if($pos === false or $pos2 === false) {
  172.              // strings NOT found in question
  173.              // use the form to get the anwers
  174.                  
  175.                  // Add Poll Answers
  176.                     $polla_answers = $_POST['polla_answers'];
  177.                     $polla_qid = intval($wpdb->insert_id);
  178.                     foreach($polla_answers as $polla_answer) {
  179.                         $polla_answer = addslashes(trim($polla_answer));
  180.                         $add_poll_answers = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0, $polla_qid, '$polla_answer', 0)");
  181.                         if(!$add_poll_answers) {
  182.                             $text .= '<p style="color: red;">'.sprintf(__('Error In Adding Poll\'s Answer \'%s\'.', 'wp-polls'), stripslashes($polla_answer)).'</p>';
  183.                         }
  184.                     }
  185.             }
  186.             else {
  187.                
  188.                 if($pos === false) {
  189.                     //stylist poll
  190.                     $level = 1;
  191.                 }
  192.                 else{
  193.                     //salon poll   
  194.                     $level = 4;
  195.                 }
  196.                  // string found in question
  197.                 // use the db to get the anwers
  198.                
  199.                 $polla_answers = $wpdb->get_results("
  200.                     SELECT user_nicename
  201.                     FROM $wpdb->wp_users  u
  202.                     INNER JOIN $wpdb->wp_m_membership_relationships mr
  203.                     ON u.id = mr.user_id
  204.                     WHERE mr.level_id=$level
  205.                     ");
  206.        
  207.        
  208.                 $polla_qid = intval($wpdb->insert_id);
  209.    
  210.                 foreach($polla_answers as $polla_answer) {
  211.    
  212.                     $polla_answer = addslashes(trim($polla_answer->user_nicename));
  213.    
  214.                     $add_poll_answers = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0, $polla_qid, '$polla_answer', 0)");
  215.    
  216.                     if(!$add_poll_answers) {
  217.    
  218.                         $text .= '<p style="color: red;">'.sprintf(__('Error In Adding Poll\'s Answer \'%s\'.', 'wp-polls'), stripslashes($polla_answer)).'</p>';
  219.    
  220.                     }
  221.    
  222.                 }
  223.              
  224.             }
  225.                
  226.  
  227.             // Update Lastest Poll ID To Poll Options
  228.  
  229.             $latest_pollid = polls_latest_id();
  230.  
  231.             $update_latestpoll = update_option('poll_latestpoll', $latest_pollid);
  232.  
  233.             if(empty($text)) {
  234.  
  235.                 $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>';
  236.  
  237.             }
  238.  
  239.             cron_polls_place();
  240.  
  241.             break;
  242.  
  243.     }
  244.  
  245. }
  246.  
  247.  
  248.  
  249. ### Add Poll Form
  250.  
  251. $poll_noquestion = 2;
  252.  
  253. $count = 0;
  254.  
  255. ?>
  256.  
  257. <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade">'.stripslashes($text).'</div>'; } ?>
  258.  
  259. <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
  260.  
  261. <?php wp_nonce_field('wp-polls_add-poll'); ?>
  262.  
  263. <div class="wrap">
  264.  
  265.     <div id="icon-wp-polls" class="icon32"><br /></div>
  266.  
  267.     <h2><?php _e('Add Poll', 'wp-polls'); ?></h2>
  268.  
  269.     <!-- Poll Question -->
  270.  
  271.     <h3><?php _e('Poll Question', 'wp-polls'); ?></h3>
  272.  
  273.     <table class="form-table">
  274.  
  275.         <tr>
  276.  
  277.             <th width="20%" scope="row" valign="top"><?php _e('Question', 'wp-polls') ?></th>
  278.  
  279.             <td width="80%"><input type="text" size="70" name="pollq_question" value="" /></td>
  280.  
  281.         </tr>
  282.  
  283.     </table>
  284.  
  285.     <!-- Poll Answers -->
  286.  
  287.     <h3><?php _e('Poll Answers', 'wp-polls'); ?></h3>
  288.  
  289.     <table class="form-table">
  290.  
  291.         <tfoot>
  292.  
  293.             <tr>
  294.  
  295.                 <td width="20%">&nbsp;</td>
  296.  
  297.                 <td width="80%"><input type="button" value="<?php _e('Add Answer', 'wp-polls') ?>" onclick="add_poll_answer_add();" class="button" /></td>
  298.  
  299.             </tr>
  300.  
  301.         </tfoot>
  302.  
  303.         <tbody id="poll_answers">
  304.  
  305.         <?php
  306.  
  307.             for($i = 1; $i <= $poll_noquestion; $i++) {
  308.  
  309.                 echo "<tr id=\"poll-answer-$i\">\n";
  310.  
  311.                 echo "<th width=\"20%\" scope=\"row\" valign=\"top\">".sprintf(__('Answer %s', 'wp-polls'), number_format_i18n($i))."</th>\n";
  312.  
  313.                 echo "<td width=\"80%\"><input type=\"text\" size=\"50\" maxlength=\"200\" name=\"polla_answers[]\" />&nbsp;&nbsp;&nbsp;<input type=\"button\" value=\"".__('Remove', 'wp-polls')."\" onclick=\"remove_poll_answer_add(".$i.");\" class=\"button\" /></td>\n";
  314.  
  315.                 echo "</tr>\n";
  316.  
  317.                 $count++;
  318.  
  319.             }
  320.  
  321.         ?>
  322.  
  323.         </tbody>
  324.  
  325.     </table>
  326.  
  327.     <!-- Poll Multiple Answers -->
  328.  
  329.     <h3><?php _e('Poll Multiple Answers', 'wp-polls') ?></h3>
  330.  
  331.     <table class="form-table">
  332.  
  333.         <tr>
  334.  
  335.             <th width="40%" scope="row" valign="top"><?php _e('Allows Users To Select More Than One Answer?', 'wp-polls'); ?></th>
  336.  
  337.             <td width="60%">
  338.  
  339.                 <select name="pollq_multiple_yes" id="pollq_multiple_yes" size="1" onchange="check_pollq_multiple();">
  340.  
  341.                     <option value="0"><?php _e('No', 'wp-polls'); ?></option>
  342.  
  343.                     <option value="1"><?php _e('Yes', 'wp-polls'); ?></option>
  344.  
  345.                 </select>
  346.  
  347.             </td>
  348.  
  349.         </tr>
  350.  
  351.         <tr>
  352.  
  353.             <th width="40%" scope="row" valign="top"><?php _e('Maximum Number Of Selected Answers Allowed?', 'wp-polls') ?></th>
  354.  
  355.             <td width="60%">
  356.  
  357.                 <select name="pollq_multiple" id="pollq_multiple" size="1" disabled="disabled">
  358.  
  359.                     <?php
  360.  
  361.                         for($i = 1; $i <= $poll_noquestion; $i++) {
  362.  
  363.                             echo "<option value=\"$i\">".number_format_i18n($i)."</option>\n";
  364.  
  365.                         }
  366.  
  367.                     ?>
  368.  
  369.                 </select>
  370.  
  371.             </td>
  372.  
  373.         </tr>
  374.  
  375.     </table>
  376.  
  377.     <!-- Poll Start/End Date -->
  378.  
  379.     <h3><?php _e('Poll Start/End Date', 'wp-polls'); ?></h3>
  380.  
  381.     <table class="form-table">
  382.  
  383.         <tr>
  384.  
  385.             <th width="20%" scope="row" valign="top"><?php _e('Start Date/Time', 'wp-polls') ?></th>
  386.  
  387.             <td width="80%"><?php poll_timestamp(current_time('timestamp')); ?></td>
  388.  
  389.         </tr>
  390.  
  391.         <tr>
  392.  
  393.             <th width="20%" scope="row" valign="top"><?php _e('End Date/Time', 'wp-polls') ?></th>
  394.  
  395.             <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>
  396.  
  397.         </tr>
  398.  
  399.     </table>
  400.  
  401.     <p style="text-align: center;"><input type="submit" name="do" value="<?php _e('Add Poll', 'wp-polls'); ?>"  class="button-primary" />&nbsp;&nbsp;<input type="button" name="cancel" value="<?php _e('Cancel', 'wp-polls'); ?>" class="button" onclick="javascript:history.go(-1)" /></p>
  402.  
  403. </div>
  404.  
  405. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement