Guest User

wpgft-loader.php

a guest
Nov 5th, 2012
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.92 KB | None | 0 0
  1. <?php
  2.         global $wpgft_db_version;
  3.         global $wpgft_current_version;
  4.        
  5.         $wpgft_db_version = "1.1";
  6.         $wpgft_current_version = "1.1";
  7.        
  8.         //Register the hook to set everything up on Activation
  9.         register_activation_hook(WP_PLUGIN_DIR . '/wp-gift-cert/wpgft.php', 'wpgft_install');
  10.        
  11.         add_action('plugins_loaded', 'wpgft_update_check');
  12.        
  13.         // Action hook to register our option settings
  14.         add_action( 'admin_init', 'wpgft_register_settings');
  15.        
  16.         //Create Custom Plugin Settings Menu
  17.         add_action('admin_menu', 'wpgft_create_menu');
  18.        
  19.     /**
  20.     *  Function:   wpgft_install
  21.     *
  22.     *  Description:
  23.     *  Sets up the plugin data when installed & activated
  24.     *
  25.     *
  26.     */  
  27.     function wpgft_install() {
  28.         global $wpdb;
  29.         global $wpgft_db_version;
  30.         global $wpgft_current_version;
  31.         //Defines the Custom Table Name
  32.         $table_name = $wpdb->prefix . "wpgft_data";
  33.        
  34.         //Table Structure Version
  35.         $wpgft_db_version = "1.1";
  36.         $wpgft_current_version = "1.0";
  37.        
  38.         //Verify the Database Doesn't Already Exist
  39.         if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
  40.             //Create the Options in the Options Table
  41.             $wpgft_options_arr = array(
  42.                 "current_ver"       => $wpgft_current_version,
  43.                 "paypal_id"         => 'Your Paypal ID',
  44.                 "paypal_url"        => "https://www.sandbox.paypal.com/cgi-bin/webscr",
  45.                 "currency"          => "AUD",
  46.                 "admin_email"       => "[email protected]",
  47.                 "require_address"   => "yes",
  48.                 "disable_css"       => "no",
  49.                 "company"           => "Your Company Name",
  50.                 "company_info"      => "",
  51.                 "custom_return"     => "",
  52.                 "email_message"     => 'Thank You for purchasing a Gift Certificate from us. If you have any questions or problems please contact us at Phone number? or via our <a href="mysite.com/contact/">Contact Page</a>.
  53. <br /><br />
  54. You must be able to receive HTML formatted messages to print this certificate. Make sure you allow images as well. This certificate cannot be redeemed for cash.',
  55.                 "return_page"       => 'This is the return page content displayed when a user is redirected to your site from PayPal. If you enter a Custom Return page in the box above, this box is pretty much just worthless.'
  56.                 );
  57.            
  58.             $wpgft_buttons_arr = array();
  59.            
  60.             //Update the options in the database
  61.             update_option('wpgft_options', $wpgft_options_arr);
  62.             update_option('wpgft_buttons', $wpgft_buttons_arr);
  63.            
  64.             //Build the Query to Create the DatabaseTest
  65.             $sql = "CREATE TABLE {$wpdb->wpgft_data} (
  66.                 `ID` INT(32) NOT NULL auto_increment,
  67.                 `cert_num` varchar(55),
  68.                 `recipient` varchar(55),
  69.                 `cert_amount` varchar(55),
  70.                 `sold_to` varchar(55),
  71.                 `sold_to_email` varchar(55),
  72.                 `sold_to_phone` varchar(55),
  73.                 `sold_to_address` varchar(220),
  74.                 `sale_date` varchar(55),
  75.                 `status` varchar(55),
  76.                 `secret` varchar(220),
  77.                 `button_id` varchar(100),
  78.                 PRIMARY KEY  (ID)
  79.                 );";
  80.                
  81.             include_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  82.             //execute the query creating the table
  83.             dbDelta($sql);
  84.            
  85.             //save the table structure version number
  86.             add_option("wpgft_db_version", $wpgft_db_version);
  87.         } else {
  88.             $wpgft_options_arr = get_option("wpgft_options");
  89.             $wpgft_installed_ver = $wpgft_options_arr['current_ver'];
  90.             $installed_db_version = get_option("wpgft_db_version");
  91.            
  92.             //Check to see if the installed version is different than the current version running, if so add any new options
  93.             if($wpgft_current_version != $wpgft_installed_ver) {
  94.                 $wpgft_options_arr['currency'] = 'USD';
  95.                 $wpgft_options_arr['require_address'] = 'yes';
  96.                 $wpgft_options_arr['disable_css'] = 'no';
  97.                 $wpgft_options_arr['current_ver'] = $wpgft_current_version;
  98.                 $wpgft_options_arr['custom_return'] = '';
  99.                 update_option('wpgft_options', $wpgft_options_arr);
  100.             }
  101.            
  102.             if($installed_db_version <= $wpgft_db_version) {
  103.                
  104.                 $sql = "CREATE TABLE {$wpdb->wpgft_data} (
  105.                 `ID` INT(32) NOT NULL auto_increment,
  106.                 `cert_num` varchar(55),
  107.                 `recipient` varchar(55),
  108.                 `cert_amount` varchar(55),
  109.                 `sold_to` varchar(55),
  110.                 `sold_to_email` varchar(55),
  111.                 `sold_to_phone` varchar(55),
  112.                 `sold_to_address` varchar(220),
  113.                 `sale_date` varchar(55),
  114.                 `status` varchar(55),
  115.                 `secret` varchar(220),
  116.                 `button_id` varchar(100),
  117.                 PRIMARY KEY  (ID)
  118.                 );";
  119.                
  120.                 include_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  121.                 update_option('wpgft_db_version', $wpgft_db_version);
  122.                
  123.                 include_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  124.                 //execute the query creating the table
  125.                 dbDelta($sql);
  126.             }
  127.         }
  128.        
  129.     }
  130.    
  131.     //Checks to see if an upgrade is needed, if so calls the install function
  132.     function wpgft_update_check(){
  133.         global $wpgft_db_version;
  134.         global $wpgft_current_version;
  135.        
  136.         if (get_option('wpgft_db_version') < $wpgft_db_version) {
  137.             wpgft_install();
  138.         }
  139.     }
  140.    
  141.     // Calls to create the admin menus
  142.     function wpgft_create_menu() {
  143.         //Create the new top level menu
  144.         add_menu_page('Gift Certificates', 'Gift Certificates', 'edit_others_pages', 'wpgft-settings', 'wpgft_settings_page' );
  145.         add_submenu_page('wpgft-settings', 'Settings', 'Settings', 'edit_others_pages', 'wpgft-settings', 'wpgft_settings_page' );
  146.         //Create the First SubMenu
  147.         add_submenu_page('wpgft-settings', 'Button Management', 'Create and Edit', 'edit_others_pages', 'certificate_management', 'wpgft_manage_certs' );
  148.         add_submenu_page('wpgft-settings', 'Sold Certicates', 'Sold Certificates', 'edit_others_pages', 'manage_sold', 'wpgft_manage_soldCerts' );
  149.     }
  150.    
  151.     //Setup the settings page on the admin menu
  152.     function wpgft_settings_page() {
  153.         $wpgft_options_arr = get_option('wpgft_options');
  154.         ?>
  155.        
  156.         <div class="wrap">
  157.             <h2><?php _e('Gift Certificates Options', 'wpgft-plugin') ?> <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  158.                 <input type="hidden" name="cmd" value="_s-xclick">
  159.                 <input type="hidden" name="hosted_button_id" value="H7G7STCJR3HU6">
  160.                 <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
  161.                 <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
  162.             </form>
  163. </h2>
  164.            
  165.  
  166.             <form method="post" action="options.php">
  167.                 <?php settings_fields( 'wpgft-settings-group' ); ?>
  168.                 <h3>PayPal Options</h3>
  169.                 <table class="form-table">
  170.                
  171.                     <tr valign="top">
  172.                     <th scope="row"><?php _e('Paypal Email', 'wpgft-plugin'); ?></th>
  173.                     <td> <input type="text" name="wpgft_options[paypal_id]" value="<?php echo $wpgft_options_arr['paypal_id']; ?>" /></td>
  174.                     </tr>
  175.                    
  176.                     <tr valign="top">
  177.                     <th scope="row"><?php _e('Paypal URL', 'wpgft-plugin'); ?></th>
  178.                     <td> <input type="text" name="wpgft_options[paypal_url]" value="<?php echo $wpgft_options_arr['paypal_url']; ?>"/></td>
  179.                     </tr>
  180.                    
  181.                     <tr valign="top">
  182.                     <th scope="row"><?php _e('Require Address', 'wpgft-plugin');    ?></th>
  183.                     <td>
  184.                         <select name="wpgft_options[require_address]">
  185.                             <option value="Yes" <?php if($wpgft_options_arr['require_address'] == "Yes") echo "selected"; ?>>Yes</option>
  186.                             <option value="No" <?php if($wpgft_options_arr['require_address'] == "No") echo "selected"; ?>>No</option>
  187.                         </select></td>
  188.                     </tr>
  189.                    
  190.                     <tr valign="top">
  191.                     <th scope="row"><?php _e('Currency', 'wpgft-plugin');   ?></th>
  192.                     <td>
  193.                         <select name="wpgft_options[currency]">
  194.                             <option value="USD" <?php if($wpgft_options_arr['currency'] == "AUD" || $wpgft_options_arr['currency'] == "") echo "selected"; ?>>AUD</option>
  195.                         </select></td>
  196.                     </tr>
  197.                     <th scope="row"><?php _e('Custom Return Page') ?></th>
  198.                     <td>
  199.                         <input type="text" name="wpgft_options[custom_return]" style="width:300px;" value="<?php echo $wpgft_options_arr['custom_return']; ?>"/>
  200.                         <br />
  201.                         <span class="description">If blank will use the return page content below</span>
  202.                     </td>
  203.                     </tr>
  204.                     <tr>
  205.                     <th scope="row"><?php _e('Return Page Content', 'wpgft-plugin'); ?></th>
  206.                     <td> <textarea cols="50" rows="15" name="wpgft_options[return_page]" ><?php echo $wpgft_options_arr['return_page']; ?></textarea><br />
  207.                         <span class="description"> Text displayed when the user returns from PayPal</span>
  208.                     </td>
  209.                     </tr>
  210.                 </table>
  211.                 <h3>Certificate Display Options</h3>
  212.                 <table class="form-table">
  213.                                    
  214.                     <tr valign="top">
  215.                     <th scope="row"><?php _e('Company Name', 'wpgft-plugin'); ?></th>
  216.                     <td> <input type="text" name="wpgft_options[company]" value="<?php echo $wpgft_options_arr['company']; ?>"/><br />
  217.                         <span class="description">Displayed on Gift Certificate</span></td>
  218.                     </tr>
  219.                    
  220.                     <tr valign="top">
  221.                     <th scope="row"><?php _e('Company Info', 'wpgft-plugin'); ?></th>
  222.                     <td> <textarea name="wpgft_options[company_info]" ><?php echo $wpgft_options_arr['company_info']; ?></textarea><br />
  223.                         <span class="description">Displays below Company Name on Gift Cert</span></td>
  224.                     </tr>
  225.                 </table>
  226.                 <h3>Certificate Email Options</h3>
  227.                 <table class="form-table">
  228.                     <tr valign="top">
  229.                     <th scope="row"><?php _e('Admin E-mail', 'wpgft-plugin'); ?></th>
  230.                     <td> <input type="text" name="wpgft_options[admin_email]" value="<?php echo $wpgft_options_arr['admin_email']; ?>"/><br />
  231.                         <span class="description">"From:" Email used to Issue Certs</span>
  232.                     </td>
  233.                     </tr>
  234.                     <tr valign="top">
  235.                     <th scope="row"><?php _e('E-mail Message', 'wpgft-plugin'); ?></th>
  236.                     <td> <textarea cols="50" rows="15" name="wpgft_options[email_message]" ><?php echo $wpgft_options_arr['email_message']; ?></textarea><br />
  237.                         <span class="description">Message Sent to user after payment is made (displays above the certificate)</span>
  238.                     </td>
  239.                     </tr>
  240.                 </table>
  241.                 <h3>Style Options</h3>
  242.                 <table class="form-table">
  243.                     <tr valign="top">
  244.                         <th scope="row"><?php _e('Disable Included CSS', 'wpgft-plugin'); ?></th>
  245.                         <td>
  246.                         <select name="wpgft_options[disable_css]">
  247.                             <option value="yes" <?php if($wpgft_options_arr['disable_css'] == "yes") echo "selected"; ?>>Yes</option>
  248.                             <option value="no" <?php if($wpgft_options_arr['disable_css'] == "no") echo "selected"; ?>>No</option>
  249.                         </select></td>
  250.                     </tr>
  251.                 </table>
  252.                 <p class="submit">
  253.                 <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'wpgft-plugin'); ?>" />
  254.             </form>
  255.         </div>
  256.         <?php
  257.     }
  258.    
  259.     //Manage the creation of Certificate buttons
  260.     function wpgft_manage_certs() {
  261.         include('wpgft-actions.php');
  262.         if(empty($_GET['insert'])) {
  263.             if(empty($_GET['add'])) {
  264.                 include('editcerts.php');
  265.             } else {
  266.                 include('addcerts.php');
  267.             }
  268.         }
  269.     }
  270.    
  271.     //Manage the sold certificates
  272.     function wpgft_manage_soldCerts() {
  273.        
  274.         global $wpdb;
  275.         $table_name = $wpdb->prefix . "wpgft_data";
  276.         $cert_id = $_GET['cert_id'];
  277.         include('wpgft-actions.php');
  278.        
  279.         //If you requested the e-mail be resent, then resend it.
  280.         if($_GET['resend'] == 'true') {
  281.             $payment_data = $wpdb->get_row($wpdb->prepare("SELECT * from $table_name WHERE ID = $cert_id"), ARRAY_A);
  282.             send_cert_email($payment_data);
  283.         }
  284.         include('showsoldcerts.php');
  285.        
  286.     }
  287.    
  288.     //Define Edit Boxes
  289.     function wpgft_certBtn_amount_meta_box() {
  290.         global $current_button;
  291.         $button_id == -1;
  292.         $wpgft_buttons_arr = get_option('$wpgft_buttons');
  293.        
  294.         if(isset($_GET['id'])) {
  295.             $button_id = $_GET['id']; ?>
  296.             <input type="hidden" name="wpgft_id" value="<?php echo $button_id?>" />
  297.         <?php
  298.         }
  299.         //if($_GET['id'] == 0) $button_id = 0;
  300.         //if($button_id >= 0) $current_button = $wpgft_buttons_arr[$button_id];
  301.         ?>
  302.         <input type="text" name="wpgft_certBtn_amount" value="<?php echo $current_button['amount'];?>" class="regular-text" />
  303.        
  304.         <?php
  305.     }
  306.     function wpgft_certBtn_description_meta_box() {
  307.         global $current_button;
  308.         ?>
  309.         <input type="text" name="wpgft_certBtn_description" value="<?php echo $current_button['description']?>" class="regular-text" />
  310.         <?php
  311.     }
  312.    
  313.     function wpgft_certBtn_company_meta_box() {
  314.         global $current_button;
  315.         ?>
  316.         <input type="text" name="wpgft_certBtn_company" value="<?php echo $current_button['company']?>" class="regular-text" />
  317.         <?php
  318.     }
  319.    
  320.     function wpgft_certBtn_coinfo_meta_box() {
  321.         global $current_button;
  322.         ?>
  323.         <textarea type="text" name="wpgft_certBtn_coinfo"><?php echo $current_button['coinfo']?></textarea>
  324.         <?php
  325.     }
  326.    
  327.     function wpgft_certBtn_button_meta_box() {
  328.         global $current_button;
  329.         $button_option_arr = array(
  330.             "Blue Button"   => "bluebtn1",
  331.             "Orange Button" => "orangebtn1"
  332.         );
  333.         ?>
  334.         <select name="wpgft_certBtn_button">
  335.         <?php
  336.             foreach($button_option_arr as $key => $button_option) {
  337.                 $selected = '';
  338.                 if($button_option == $current_button['button']) $selected = ' selected="selected" ';
  339.                 echo '<option'.$selected.' value="'.$button_option.'">'.$key.'</option>';
  340.             }
  341.             ?>
  342.         </select>
  343.         <?php
  344.     }
  345.    
  346.    
  347.     //Setup the function to show the buttons based on Short Codes.
  348.     function showButton($atts, $content = null) {
  349.         global $wpgft_content_url;
  350.         extract(shortcode_atts(array(
  351.         "id" => FALSE,
  352.         "button_only" => FALSE,), $atts));
  353.         $current_button = get_current_button($id);
  354.         $button_background = $wpgft_content_url ."/plugins/wp-gift-cert/images/".$current_button['button'];
  355.        
  356.         //Make Sure The ID Fed Us actually relates to a record
  357.         if($current_button) {
  358.             if ($current_button['amount'] != 0 && $current_button['amount'] != "") {
  359.                 $box_disabled = 'readonly="true"';
  360.                 $box_class='class="disabled-box"';
  361.             }
  362.            
  363.             $formCode = '<form method="post" action="#" id="wpgft-btn-form-' . $id . '" class="wpgft-btn-form">';
  364.             $formCode .= '<input type="hidden" value="true" name="wpgft_order" />';
  365.             $formCode .= '<input type="hidden" value="'. $id .'" name="button_id" />';
  366.             if ($button_only == TRUE) {
  367.                 $formCode .= '<input type="hidden" value="'.$current_button['amount'].'" name="amount" />';
  368.             } else {
  369.                 $formCode .= '<dl id="wpgft-btn-list-'.$id.'" class="wpgft-table" >';
  370.                 $formCode .= '<dt>Amount</dt>';
  371.                 $formCode .= '<dd><input type="text"'. $box_disabled . ' ' . $box_class .'name="amount" value="'.$current_button['amount'] .'" /></dd>';
  372.                
  373.                 if($current_button['company'] != "") {
  374.                     $formCode .= '<dt>Company</dt>';
  375.                     $formCode .= '<dd>' . $current_button['company'] . '</dd>';
  376.                 }
  377.                
  378.                 $formCode .= '<dt>Description</dt>';
  379.                 $formCode .= '<dd>' . $current_button['description'] . '</dd>';
  380.                 $formCode .= '</dl>';
  381.             }
  382.             $formCode .= '<input class="'. $current_button['button'] .'" type="submit" value="Purchase Cert" name="submit">';
  383.             $nonceID = 'wpgft_nonce_check'.$id;
  384.            
  385.             if( function_exists('wp_nonce_field') ) $formCode .= wp_nonce_field($nonceID);
  386.             $formCode .= '</form>';
  387.             return $formCode;
  388.         }
  389.     }
  390.     add_shortcode('wpgft', 'showButton');
  391.  
  392.     //Intercept to check for submitted data via one of the forms or from PayPal
  393.     function wpgft_eval_PostData() {
  394.         if(isset($_POST['wpgft_order']) || isset($_POST['wpgft_purch'])) {
  395.             $nonceID = 'wpgft_nonce_check'.$_POST['button_id'];
  396.             check_admin_referer($nonceID);
  397.             include("wpgft_processOrder.php");
  398.         }
  399.         if(isset($_GET['ipn_request']) == 'true') {
  400.             include("wpgft_ipnHandler.php");
  401.         }
  402.         if(isset($_GET['verifyGft'])) {
  403.             include("wpgft_verify.php");
  404.         }
  405.         if(isset($_GET['paypal_return'])) {
  406.             include("wpgft_return.php");
  407.         }
  408.     }
  409.     add_action('init', wpgft_eval_PostData);
  410.  
  411. function wpgft_register_settings() {
  412.     //register our Array of settings
  413.     register_setting( 'wpgft-settings-group', 'wpgft_options' );
  414. }
  415.  
  416. /**
  417. *  Function:   get_current_button
  418. *
  419. *  Description:
  420. *  Takes an integer ID and returns the associated button array from the DB
  421. *
  422. *  @int
  423. *
  424. *  @return array
  425. *
  426. */
  427. function get_current_button($id) {
  428.         $wpgft_buttons_arr = get_option('wpgft_buttons');
  429.        
  430.         $current_button = $wpgft_buttons_arr[$id];
  431.         return $current_button;
  432. }
  433.  
  434. function send_cert_email($payment_data) {
  435.         $wpgft_options = get_option("wpgft_options");
  436.         $current_button = get_current_button($payment_data['button_id']);
  437.         if($current_button['company'] != "") {
  438.             $company = $current_button['company'];
  439.             $companyinfo = nl2br($current_button['coinfo']);
  440.         } else {
  441.             $company = $wpgft_options['company'];
  442.             $companyinfo = nl2br($wpgft_options['company_info']);
  443.         }
  444.         $urltoEncode = get_option('siteurl') . "/?verifyGft=true&" . "cert=".$payment_data['cert_num']."&amount=".$payment_data['cert_amount']."&data=".$payment_data['secret'];
  445.         $url = urlencode($urltoEncode);
  446.         $imgCode = '<img src="http://chart.apis.google.com/chart?chs=150x150&cht=qr&chld=|1&chl='.$url.'" alt="QR Code" />';
  447.         $wordAmount = convert_number($payment_data['cert_amount']) . ' and <sup>' . substr($payment_data['cert_amount'], -2) . '/100</sup> ---';
  448.         $currencySymbol = get_currSymbol($payment_data['currency']);
  449.        
  450.         // email stuff (change data below)
  451.         $to = $payment_data['sold_to_email'];
  452.         $from = $wpgft_options['admin_email'];
  453.         $subject = "Your Certificate Order";
  454.        
  455.         //include the user supplied message
  456.         $message = $wpgft_options['email_message'];
  457.         //Build the Certificate out
  458.         $message .= '<br /><br />
  459.         <table style="border: solid 1px #000;width: 600px;">
  460.             <tr>
  461.                 <td style="padding-top:10px; font-weight: bold; padding-right: 10px; text-align: right; padding-bottom: 25px; width:110px;">CERT Num:</td>
  462.                 <td style="padding-top:10px; padding-bottom: 25px; width:310px;">'.$payment_data['cert_num'].'</td>
  463.                 <td style="padding-top:10px; padding-bottom: 25px;">Issued: '.date("m/d/y").'</td>
  464.             </tr>
  465.             <tr>
  466.                 <td style="font-weight: bold;text-align: right; padding-right: 10px; width:110px;">To:</td>
  467.                 <td style="border-bottom: solid 3px #000;">'.$payment_data['recipient'].'</td>
  468.                 <td style="border: solid 1px #000;">'.$currencySymbol.$payment_data['cert_amount'].'</td>
  469.             </tr>
  470.             <tr>
  471.                 <td colspan="3" style="padding-left: 15px; padding-top: 25px; border-bottom: solid 3px #000; font-style: italic;">'.$wordAmount.'</td>
  472.             </tr>
  473.             <tr>
  474.                 <td colspan="2" style="text-align: center;" ><span style="font-size:32px;">'.$company.'</span><br/>'.$companyinfo.'</td>
  475.                 <td>'.$imgCode.'</td>
  476.             </tr>
  477.             </table>
  478.         ';
  479.  
  480.         // a random hash will be necessary to send mixed content
  481.         $separator = md5(time());
  482.  
  483.         // carriage return type (we use a PHP end of line constant)
  484.         $eol = PHP_EOL;
  485.  
  486.         // main header (multipart mandatory)
  487.         $headers  = "From: ". $company . " <" . $from . ">". $eol;
  488.         $headers .= "MIME-Version: 1.0".$eol;
  489.         $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
  490.         $headers .= "Content-Transfer-Encoding: 7bit".$eol;
  491.         $headers .= "This is a MIME encoded message.".$eol.$eol;
  492.  
  493.         // message
  494.         $headers .= "--".$separator.$eol;
  495.         $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
  496.         $headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
  497.         //$headers .= $message.$eol.$eol;
  498.  
  499.         // send message
  500.         $sendit = wp_mail($to, $subject, $message, $headers);
  501.        
  502.         //Code to troubleshoot email problems.
  503.         /*  if(!$sendit) {
  504.                     $tempOptions = get_option('wpgft_options');
  505.                     $tempOptions['admin_email'] = "EMAIL FAILED";
  506.                     update_option('wpgft_options', $tempOptions);
  507.                
  508.                 }
  509.         */
  510.  
  511. }
  512.  
  513. function wpgft_cert_edit_status(){
  514.     global $wpdb;
  515.     $table_name = $wpdb->prefix . "wpgft_data";
  516.    
  517.     $cert_id = $_POST['cert_id'];
  518.     $cert_status = $_POST['cert_status'];
  519.    
  520.     $wpdb->update($table_name, array('Status'  => $cert_status), array('ID' => $cert_id),array('%s'),array('%d'));
  521.    
  522. }
  523. if($_REQUEST['wpgft_admin_action'] == 'cert_edit_status') {
  524.     add_action('admin_init', 'wpgft_cert_edit_status');
  525. }
  526.  
  527. function wpgft_scripts() {
  528.     global $wpgft_content_url;
  529.    
  530.     wp_enqueue_script('wpgft-admin', $wpgft_content_url.'/plugins/wp-gift-cert/js/admin.js', array('jquery', 'jquery-ui-core', 'jquery-ui-sortable'), '1.0');
  531. }
  532.     add_action('admin_init', 'wpgft_scripts');
  533.    
  534. //Look through the posts and see if there are any shortcodes, then include our CSS.
  535.     add_filter('the_posts', 'wpgft_add_scripts_and_styles'); // the_posts gets triggered before wp_head
  536.  
  537. function wpgft_add_scripts_and_styles($posts){
  538.    
  539.     if (empty($posts)) return $posts;
  540.    
  541.     $wpgft_options = get_option("wpgft_options");
  542.     //Check to see if the user has disabled CSS, if they have then don't bother with the css scripts
  543.     if ($wpgft_options['disable_css'] == "yes") return $posts;
  544.    
  545.     $shortcode_found = false; // use this flag to see if styles and scripts need to be enqueued
  546.     foreach ($posts as $post) {
  547.         if (stripos($post->post_content, '[wpgft')  !== false) {
  548.             $shortcode_found = true; // bingo!
  549.             break;
  550.         }
  551.     }
  552.  
  553.     if ($shortcode_found) {
  554.         global $wpgft_content_url;
  555.         // enqueue here
  556.         $fileLoc = $wpgft_content_url."/plugins/wp-gift-cert/css/wpgift.css";
  557.         wp_register_style('wpgft-style', $fileLoc);
  558.         wp_enqueue_style('wpgft-style');
  559.        
  560.     }
  561.  
  562.     return $posts;
  563. }
  564.  
  565. //Function to return the appropriate Symbol for the currency being used
  566.  
  567. function get_currSymbol($currency) {
  568.     switch ($currency) {
  569.             case "AUD":
  570.                 $currSymbol = "$";
  571.                 break;
  572.                
  573.             default:
  574.                 $currSymbol = "$";
  575.     }
  576.    
  577.     return $currSymbol;
  578. }
  579.  
  580. /**
  581. *  Function:   convert_number
  582. *
  583. *  Description:
  584. *  Converts a given integer (in range [0..1T-1], inclusive) into
  585. *  alphabetical format ("one", "two", etc.)
  586. *
  587. *  @int
  588. *
  589. *  @return string
  590. *
  591. */
  592. function convert_number($number)
  593. {
  594.     if (($number < 0) || ($number > 999999999))
  595.     {
  596.     throw new Exception("Number is out of range");
  597.     }
  598.  
  599.     $Gn = floor($number / 1000000);  /* Millions (giga) */
  600.     $number -= $Gn * 1000000;
  601.     $kn = floor($number / 1000);     /* Thousands (kilo) */
  602.     $number -= $kn * 1000;
  603.     $Hn = floor($number / 100);      /* Hundreds (hecto) */
  604.     $number -= $Hn * 100;
  605.     $Dn = floor($number / 10);       /* Tens (deca) */
  606.     $n = $number % 10;               /* Ones */
  607.  
  608.     $res = "";
  609.  
  610.     if ($Gn)
  611.     {
  612.         $res .= convert_number($Gn) . " Million";
  613.     }
  614.  
  615.     if ($kn)
  616.     {
  617.         $res .= (empty($res) ? "" : " ") .
  618.             convert_number($kn) . " Thousand";
  619.     }
  620.  
  621.     if ($Hn)
  622.     {
  623.         $res .= (empty($res) ? "" : " ") .
  624.             convert_number($Hn) . " Hundred";
  625.     }
  626.  
  627.     $ones = array("", "One", "Two", "Three", "Four", "Five", "Six",
  628.         "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen",
  629.         "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen",
  630.         "Nineteen");
  631.     $tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty",
  632.         "Seventy", "Eigthy", "Ninety");
  633.  
  634.     if ($Dn || $n)
  635.     {
  636.         if (!empty($res))
  637.         {
  638.             $res .= " ";
  639.         }
  640.  
  641.         if ($Dn < 2)
  642.         {
  643.             $res .= $ones[$Dn * 10 + $n];
  644.         }
  645.         else
  646.         {
  647.             $res .= $tens[$Dn];
  648.  
  649.             if ($n)
  650.             {
  651.                 $res .= "-" . $ones[$n];
  652.             }
  653.         }
  654.     }
  655.  
  656.     if (empty($res))
  657.     {
  658.         $res = "zero";
  659.     }
  660.  
  661.     return $res;
  662. }
  663.  
  664. ?>
Add Comment
Please, Sign In to add comment