예제 #1
0
 /**
  * Function to return instance of dbAccess class
  * @return dbAccess singleton object
  */
 public static final function getInstance()
 {
     if (is_null(dbAccess::$dbInstance)) {
         dbAccess::$dbInstance = new dbAccess(dbAccess::$dParams['host'], dbAccess::$dParams['user'], dbAccess::$dParams['password'], dbAccess::$dParams['database']);
     }
     return dbAccess::$dbInstance;
 }
예제 #2
0
function emember_handle_level_cancelled_action($args)
{
    $member_id = $args['member_id'];
    $level = $args['level'];
    //Find record for this user
    eMember_log_debug('emember_membership_cancelled action hook handler. Retrieving membership level record for member ID: ' . $member_id, true);
    $ml_resultset = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, " id='" . $level . "'");
    $list_name = trim($ml_resultset->campaign_name);
    eMember_log_debug('List name for this membership level: ' . $list_name, true);
    if (!empty($list_name)) {
        //This level has a list name associated so need to do autoresponder cancellation.
        //TODO
    }
}
예제 #3
0
function getCount($where)
{
    $db = new dbAccess();
    $count = 0;
    $db->query("SELECT count FROM `visitcounter` WHERE  module = '{$where}';");
    if ($db->numrows()) {
        $count = $db->fetchfield('count', 0);
    }
    $db->freeresult();
    $db->destroy();
    return $count;
}
function eStore_aff_award_commission($payment_data, $cart_items, $customReferrer = '')
{
    eStore_payment_debug('===> Start of Affiliate Commission Calculation <===', true);
    eStore_payment_debug('Checking if the WP Affiliate Platform Plugin is installed.', true);
    if (eStore_affiliate_capability_exists()) {
        global $wpdb;
        $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
        $affiliates_table_name = WP_AFFILIATE_TABLE_NAME;
        $aff_sales_table = WP_AFFILIATE_SALES_TABLE_NAME;
        eStore_payment_debug('WP Affiliate Platform is installed, checking commission related details...', true);
        $customvariables = get_custom_var($payment_data['custom']);
        if (!empty($customReferrer)) {
            $referrer = $customReferrer;
            eStore_payment_debug('Revenue sharing feature is being used', true);
        } else {
            $referrer = $customvariables['ap_id'];
        }
        // Check affiliate leads table for referrer if enabled
        if (WP_ESTORE_CHECK_LEADS_TABLE_FOR_AFFILIATE_REFERRAL_CHECK === '1') {
            if (function_exists('wp_aff_get_referrer_from_leads_table_for_buyer')) {
                $buyer_email = $payment_data['payer_email'];
                $referrer = wp_aff_get_referrer_from_leads_table_for_buyer($buyer_email);
                eStore_payment_debug('Referrer value returned from the leads table check is:' . $referrer, true);
            } else {
                eStore_payment_debug('You need to update the affiliate plugin to use this feature', false);
            }
        }
        // Check if an eMember user with a referrer has purchased
        $eMember_member_id = $customvariables['eMember_id'];
        if (WP_ESTORE_CHECK_EMEMBER_REFERRER_FOR_AFFILIATE_ID === '1' && !empty($eMember_member_id)) {
            eStore_payment_debug('This purchase was made by a member with eMember ID: ' . $eMember_member_id . ' Looking to see if a referrer value exists in this member profile...', true);
            $eMember_resultset = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=' . esc_sql($eMember_member_id));
            $member_referrer = trim($eMember_resultset->referrer);
            eStore_payment_debug('Attached referrer value with this member profile is: ' . $member_referrer, true);
            if (!empty($member_referrer)) {
                $referrer = $member_referrer;
                eStore_payment_debug('Setting the referrer value of this sale to Affiliate ID: ' . $referrer, true);
            }
        }
        if (!empty($referrer)) {
            eStore_payment_debug('The referrer for this sale is:' . $referrer, true);
            $c_id = $customvariables['c_id'];
            //campaign id (if any)
            $txn_id = $payment_data['txn_id'];
            $buyer_email = $payment_data['payer_email'];
            $clientip = $customvariables['ip'];
            eStore_payment_debug('Additional debug data. Txn ID: ' . $txn_id . ' Campign ID: ' . $c_id . ' Buyer Email: ' . $buyer_email, true);
            //Check if no commission is to be awarded for self purchase
            if (WP_ESTORE_NO_COMMISSION_FOR_SELF_PURCHASE == '1') {
                //check if the referrer is the buyer
                if (function_exists('wp_aff_check_if_buyer_is_referrer')) {
                    if (wp_aff_check_if_buyer_is_referrer($referrer, $buyer_email)) {
                        eStore_payment_debug('The buyer (' . $buyer_email . ') is the referrer (' . $referrer . ') so this sale is NOT ELIGIBLE for generating any commission.', true);
                        return true;
                    } else {
                        eStore_payment_debug('The buyer is not the referrer so this sale is eligible for generating commission.', true);
                    }
                } else {
                    eStore_payment_debug('You need to update your affiliate plugin before you can use the No commission on self purchase feature.', false);
                }
            }
            $resultset = $wpdb->get_results("SELECT * FROM {$aff_sales_table} WHERE txn_id = '{$txn_id}'", OBJECT);
            if ($resultset) {
                //Commission for this transaction has already been awarded so no need to do anything.
                eStore_payment_debug('The database record shows that the commission for this transaction has already been awarded so no need to do anything.', true);
                eStore_payment_debug('===> End Affiliate Commission Check <===', true);
                return;
            }
            //Check if the "DO not award commission if coupon is used" feature is in use
            if (get_option('eStore_aff_no_commission_if_coupon_used') != '') {
                $coupon = $customvariables['coupon'];
                if (!empty($coupon)) {
                    eStore_payment_debug('Do Not Award Commission if Coupon Used feature is enabled. Commission will not be awarded for this transaction since a coupon code has been used. Coupon: ' . $coupon, true);
                    eStore_payment_debug('===> End Affiliate Commission Check <===', true);
                    return;
                }
                eStore_payment_debug('No coupon used for this transaction', true);
            }
            $wp_aff_affiliates_db = $wpdb->get_row("SELECT * FROM {$affiliates_table_name} WHERE refid = '{$referrer}'", OBJECT);
            $commission_level = $wp_aff_affiliates_db->commissionlevel;
            $second_tier_referrer = $wp_aff_affiliates_db->referrer;
            $second_tier_commission_level = 0;
            if (!empty($second_tier_referrer)) {
                //This affiliate has a 2nd tier referrer
                eStore_payment_debug('Retrieving the 2nd tier affiliate profile.', true);
                $second_tier_aff = $wpdb->get_row("SELECT * FROM {$affiliates_table_name} WHERE refid = '{$second_tier_referrer}'", OBJECT);
                if (!empty($second_tier_aff->sec_tier_commissionlevel)) {
                    $second_tier_commission_level = $second_tier_aff->sec_tier_commissionlevel;
                    eStore_payment_debug('The 2nd tier affiliate (' . $second_tier_referrer . ') has a profile specific 2nd tier commission level. Commission level is: ' . $second_tier_commission_level, true);
                } else {
                    $second_tier_commission_level = get_option('wp_aff_2nd_tier_commission_level');
                }
            }
            $counter = 1;
            $commission_amount = 0;
            $product_comm_amount = 0;
            $second_tier_commission_amount = 0;
            $purchased_items = '';
            global $eStore_affiliate_individual_product_commisions;
            foreach ($cart_items as $current_cart_item) {
                eStore_payment_debug('Processing Commission for : ' . $current_cart_item['item_name'], true);
                $cart_item_number = $current_cart_item['item_number'];
                //The total item price includes the (individual item price * quantity)
                $total_item_price = $current_cart_item['mc_gross'] - $current_cart_item['mc_shipping'];
                $item_qty = $current_cart_item['quantity'];
                eStore_payment_debug('Total Price of the currently processing item : ' . $total_item_price, true);
                $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$cart_item_number}'", OBJECT);
                if (!empty($retrieved_product->commission)) {
                    eStore_payment_debug('Using product specific commission specified in eStore', true);
                    if (get_option('wp_aff_use_fixed_commission')) {
                        eStore_payment_debug('Using fixed commission rate for this product specific commission', true);
                        //Give fixed commission from the product's specified level
                        $product_comm_amount = $item_qty * $retrieved_product->commission;
                        //Award fixed commission for 2nd tier from the product's specified level
                        if (!empty($retrieved_product->tier2_commission)) {
                            $product_second_tier_comm_amt = $item_qty * $retrieved_product->tier2_commission;
                        }
                    } else {
                        eStore_payment_debug('Using % based commission rate for this product specific commission', true);
                        //Award % commission from the product's specified level
                        //The total item price includes the (individual item price * quantity)
                        $product_comm_amount = $total_item_price * $retrieved_product->commission / 100;
                        //Award % commission for 2nd tier from the product's specified level
                        if (!empty($retrieved_product->tier2_commission)) {
                            $product_second_tier_comm_amt = $total_item_price * $retrieved_product->tier2_commission / 100;
                        }
                    }
                } else {
                    if ($retrieved_product->commission == "0") {
                        $product_comm_amount = 0;
                        $product_second_tier_comm_amt = 0;
                        eStore_payment_debug('This product will not generate any commission as the product specific commission for this product has been specified as 0', true);
                    } else {
                        eStore_payment_debug('Using commission rate from affiliate profile', true);
                        if (get_option('wp_aff_use_fixed_commission')) {
                            eStore_payment_debug('Using fixed commission rate for this commission. Qty:' . $item_qty . ', Fixed commission level:' . $commission_level, true);
                            //Give fixed commission from the affiliate's specified level
                            $product_comm_amount = $item_qty * $commission_level;
                            //Award fixed commission for 2nd tier from the affiliate's specified level
                            $product_second_tier_comm_amt = $item_qty * $second_tier_commission_level;
                        } else {
                            eStore_payment_debug('Using % based commission rate for this commission. Qty:' . $item_qty . ', Total price:' . $total_item_price . ', Commission level:' . $commission_level, true);
                            //The total item price includes the (individual item price * quantity)
                            $product_comm_amount = $total_item_price * ($commission_level / 100);
                            //Award fixed commission for 2nd tier from the affiliate's specified level
                            $product_second_tier_comm_amt = $total_item_price * ($second_tier_commission_level / 100);
                        }
                    }
                }
                $commission_amount = $commission_amount + $product_comm_amount;
                $second_tier_commission_amount = $second_tier_commission_amount + $product_second_tier_comm_amt;
                //Save the individual product commission details for later use
                $current_cart_item['product_commission'] = $product_comm_amount;
                $current_cart_item['product_commission_2nd_tier'] = $product_second_tier_comm_amt;
                $current_cart_item['product_commission_total'] = $product_comm_amount + $product_second_tier_comm_amt;
                array_push($eStore_affiliate_individual_product_commisions, $current_cart_item);
                if ($counter > 1) {
                    $purchased_items .= ", ";
                }
                $purchased_items .= $cart_item_number;
                $counter++;
            }
            $commission_amount = round($commission_amount, 2);
            $second_tier_commission_amount = round($second_tier_commission_amount, 2);
            $sale_amount = $payment_data['mc_gross'];
            $clientdate = date("Y-m-d");
            $clienttime = date("H:i:s");
            $txn_id = $payment_data['txn_id'];
            $item_id = $purchased_items;
            $buyer_name = $payment_data['first_name'] . " " . $payment_data['last_name'];
            $aff_version = get_option('wp_aff_platform_version');
            //Check if using the satellite affiliate plugin is being used then direct commision there
            if (defined('SATELLITE_WP_AFFILIATE_PLATFORM_VERSION')) {
                //WP_ESTORE_REDIRECT_COMMISSION_USING_SATELLITE_AFFILIATE_PLUGIN
                eStore_payment_debug('Satellite affiliate plugin is installed. Redirecting commission using the satellite affiliate plugin.', true);
                if (function_exists('satellite_aff_perform_remote_sale_tracking_eStore')) {
                    eStore_payment_debug('Redirecting commission using the direct commission awarding method. Commission amount: ' . $commission_amount, true);
                    satellite_aff_perform_remote_sale_tracking_eStore($commission_amount, $sale_amount, $referrer, $txn_id, $item_id, $buyer_email, $clientip, $buyer_name);
                } else {
                    if (function_exists('satellite_aff_perform_remote_sale_tracking')) {
                        satellite_aff_perform_remote_sale_tracking($sale_amount, $referrer, $txn_id, '', $buyer_email, $clientip);
                    }
                }
                return true;
            }
            eStore_payment_debug("WP Affiliate plugin version is: " . $aff_version, true);
            // Check if the commission per transaction option is enabled
            if (get_option('eStore_aff_enable_commission_per_transaction') != '') {
                eStore_payment_debug('Commission per transaction option is enabled so the commission will be awarded for the full transaction rather than on a per item basis', true);
                if (get_option('wp_aff_use_fixed_commission')) {
                    eStore_payment_debug('Using fixed commission model... Awarding fixed affiliate commission', true);
                    $updatedb = "INSERT INTO {$aff_sales_table} (refid,date,time,browser,ipaddress,payment,sale_amount,txn_id,item_id,buyer_email,campaign_id,buyer_name) VALUES ('{$referrer}','{$clientdate}','{$clienttime}','','{$clientip}','{$commission_amount}','{$sale_amount}','{$txn_id}','{$item_id}','{$buyer_email}','{$c_id}','{$buyer_name}')";
                    $results = $wpdb->query($updatedb);
                    eStore_payment_debug('===> End Affiliate Commission Check <===', true);
                    return;
                } else {
                    //For percentage based commission there is no difference between per transaction commission amount and the per item commission amount
                }
            }
            //% based commission
            $updatedb = "INSERT INTO {$aff_sales_table} (refid,date,time,browser,ipaddress,payment,sale_amount,txn_id,item_id,buyer_email,campaign_id,buyer_name) VALUES ('{$referrer}','{$clientdate}','{$clienttime}','','{$clientip}','{$commission_amount}','{$sale_amount}','{$txn_id}','{$item_id}','{$buyer_email}','{$c_id}','{$buyer_name}')";
            $results = $wpdb->query($updatedb);
            //Send commission notification email if enabled
            if (function_exists('wp_aff_send_commission_notification')) {
                if ($commission_amount > 0) {
                    eStore_payment_debug("Sending commission email notification request to the affiliate plugin", true);
                    wp_aff_send_commission_notification($wp_aff_affiliates_db->email, $txn_id);
                    eStore_payment_debug("Commission email notification request sending complete.", true);
                } else {
                    eStore_payment_debug("The commission amount is 0. No need to notify the affiliate", true);
                }
            }
            $message = 'The sale has been registered in the WP Affiliate Platform Database for referrer: ' . $referrer . ' with amount: ' . $commission_amount;
            eStore_payment_debug($message, true);
            //2nd tier affiliate commission
            eStore_payment_debug('Awarding 2nd tier commission if applicable', true);
            //$result = wp_aff_award_second_tier_commission($wp_aff_affiliates_db,$sale_amount,$txn_id,$item_id,$buyer_email);
            if (get_option('wp_aff_use_2tier') && !empty($wp_aff_affiliates_db->referrer)) {
                $award_tier_commission = true;
                $duration = get_option('wp_aff_2nd_tier_duration');
                if (!empty($duration)) {
                    $join_date = $wp_aff_affiliates_db->date;
                    $days_since_joined = round((strtotime(date("Y-m-d")) - strtotime($join_date)) / (60 * 60 * 24));
                    if ($days_since_joined > $duration) {
                        eStore_payment_debug('Tier commission award duration expried', true);
                        $award_tier_commission = false;
                    }
                }
                if ($award_tier_commission) {
                    $updatedb = "INSERT INTO {$aff_sales_table} (refid,date,time,browser,ipaddress,payment,sale_amount,txn_id,item_id,buyer_email) VALUES ('{$wp_aff_affiliates_db->referrer}','{$clientdate}','{$clienttime}','','','{$second_tier_commission_amount}','{$sale_amount}','{$txn_id}','{$item_id}','{$buyer_email}')";
                    //$updatedb = "INSERT INTO $aff_sales_table VALUES ('$wp_aff_affiliates_db->referrer','$clientdate','$clienttime','','','$second_tier_commission_amount','$sale_amount','$txn_id','$item_id','$buyer_email')";
                    $results = $wpdb->query($updatedb);
                    eStore_payment_debug('Tier commission awarded to: ' . $wp_aff_affiliates_db->referrer . '. Commission amount: ' . $second_tier_commission_amount, true);
                }
            }
            eStore_payment_debug('End of tier commission check', true);
        } else {
            eStore_payment_debug('No Referrer Found. This is not an affiliate referred sale.', true);
        }
    } else {
        eStore_payment_debug('WP Affiliate Platform capability is not present.', true);
    }
    eStore_payment_debug('===> End Affiliate Commission Check <===', true);
}
예제 #5
0
function emember_update_membership_level($member_id, $target_membership_level)
{
    $emember_auth = Emember_Auth::getInstance();
    $emember_config = Emember_Config::getInstance();
    global $wpdb;
    $resultset = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=' . esc_sql($member_id));
    $target_level_info = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, ' id=' . esc_sql($target_membership_level));
    if ($resultset->membership_level != $target_membership_level) {
        if ($emember_config->getValue('eMember_enable_secondary_membership')) {
            $additional_levels = $resultset->more_membership_levels;
            $active_membership_level = $resultset->membership_level;
            $additional_levels = array_filter(explode(',', $additional_levels));
            $additional_levels[] = $active_membership_level;
            $additional_levels = array_unique($additional_levels);
            $additional_levels = implode(',', $additional_levels);
            $level_info['membership_level'] = trim($target_membership_level);
            $level_info['more_membership_levels'] = $additional_levels;
        } else {
            $level_info['membership_level'] = trim($target_membership_level);
        }
        dbAccess::update(WP_EMEMBER_MEMBERS_TABLE_NAME, 'member_id=' . $member_id, $level_info);
    }
    emember_update_wp_role_for_member($resultset->user_name, $target_level_info->role);
}
예제 #6
0
<?php

require "connection.php";
require "dbAccess.php";
// EventID sent by application needs to be stripped of XSS
$eventid = htmlentities($_POST["eventid"]);
// return array for for JSON responses
$resultArray = array();
// create db connection
$access = new dbAccess();
$access->openConnection();
// query database for all events in events table
$result = $access->getInvited($eventid);
// if query returned successfully
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
    $rowArray = $row;
    array_push($resultArray, $rowArray);
}
if (!empty($resultArray)) {
    echo json_encode($resultArray);
}
$access->closeConnection();
예제 #7
0
파일: wp_eMember1.php 프로젝트: phupx/genco
function wp_eMember_renew_membership_for_free_handler($atts)
{
    extract(shortcode_atts(array('level' => ''), $atts));
    //TODO - If level parameter is not empty then also offer to upgrade to this level?
    $auth = Emember_Auth::getInstance();
    $user_id = $auth->getUserInfo('member_id');
    if (!empty($user_id)) {
        $output = "";
        $output .= '<div class="free_eMember_renewal_form">';
        if (isset($_POST['eMember_free_renewal'])) {
            $member_id = $_POST['eMember_free_renewal'];
            $curr_date = date("Y-m-d");
            dbAccess::update(WP_EMEMBER_MEMBERS_TABLE_NAME, 'member_id=' . $member_id, array('subscription_starts' => $curr_date, 'account_state' => 'active'));
            $output .= "Membership Renewed!";
        } else {
            $output .= '<form name="free_eMember_renewal" method="post" action="">';
            $output .= '<input type="hidden" name="eMember_free_renewal" value="' . $user_id . '" />';
            $output .= '<input type="submit" name="eMember_free_renew_submit" value="Renew" />';
            $output .= '</form>';
        }
        $output .= '</div>';
        return $output;
    } else {
        return "You must be logged in to renew a membership!";
    }
}
예제 #8
0
function emember_payment_gateway_settings_menu()
{
    echo '<div class="wrap">';
    echo '<div id="poststuff"><div id="post-body">';
    $emember_config = Emember_Config::getInstance();
    $paypal_ipn_url = WP_EMEMBER_URL . "/ipn/eMember_handle_paypal_ipn.php";
    if (isset($_POST['info_update_emem_cb'])) {
        $emember_config->setValue('eMember_cb_secret_key', trim($_POST["eMember_cb_secret_key"]));
        $emember_config->saveConfig();
        echo '<div id="message" class="updated fade"><p><strong>';
        echo 'Clickbank Options Updated!';
        echo '</strong></p></div>';
    }
    if (isset($_POST['emem_generate_av_code'])) {
        $mem_level = trim($_POST['emember_paypal_av_member_level']);
        $membership_level_resultset = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, " id='" . $mem_level . "'");
        if ($membership_level_resultset) {
            $pp_av_code = 'notify_url=' . $paypal_ipn_url . '<br />' . 'custom=subsc_ref=' . $mem_level;
            echo '<div id="message" class="updated fade"><p>';
            echo '<strong>Paste the code below in the "Add advanced variables" field of your PayPal button for membership level ' . $mem_level . '</strong>';
            echo '<br /><code>' . $pp_av_code . '</code>';
            echo '</p></div>';
        } else {
            echo '<div id="message" class="updated fade"><p><strong>';
            echo 'Error! The membership level ID (' . $mem_level . ') you specified is incorrect. Please check this value again.';
            echo '</strong></p></div>';
        }
    }
    ?>
    <div class="postbox">
        <h3><label for="title">WP eStore Integration Settings</label></h3>
        <div class="inside">

            <p><strong>
                    Please read the <a href="http://www.tipsandtricks-hq.com/wordpress-membership/?p=60" target="_blank">WP eStore Integration Instruction</a> to integrate eMember with WP eStore's purchase button.
                </strong></p>

        </div></div>

    <div class="postbox">
        <h3><label for="title">Direct PayPal Integration Settings</label></h3>
        <div class="inside">

            <p><strong>
                    Please read the <a href="http://www.tipsandtricks-hq.com/wordpress-membership/?p=146" target="_blank">Direct PayPal Button Integration Instruction</a> to integrate eMember directly with a PayPal button.
                </strong></p>

            <table width="100%" border="0" cellspacing="0" cellpadding="6">
                <tr valign="top"><td width="25%" align="left">
                        PayPal IPN (Instant Payment Notification) URL Value:
                    </td><td align="left">
                        <code><?php 
    echo $paypal_ipn_url;
    ?>
</code>
                        <br /><br /><i>You will need to use the above URL as the "IPN handling script URL" value in your your PayPal button.</i><br /><br />
                    </td></tr>
            </table>

            <strong>Generate the "Advanced Variables" Code for your PayPal button</strong>
            <br />
            <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
                Enter the Membership Level ID
                <input name="emember_paypal_av_member_level" type="text" size="4" value="" />
                <input type="submit" name="emem_generate_av_code" class="button-primary" value="Generate Code" />
            </form>

        </div></div>

    <div class="postbox">
        <h3><label for="title">ClickBank Integration Settings</label></h3>
        <div class="inside">

            <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
                <input type="hidden" name="info_update_emem_cb" id="info_update_emem_cb" value="true" />

                <p><strong>
                        Please read the <a href="http://www.tipsandtricks-hq.com/wordpress-membership/?p=470" target="_blank">ClickBank Integration Instruction</a> to integrate eMember with a ClickBank button.
                    </strong></p>

                <table width="100%" border="0" cellspacing="0" cellpadding="6">
                    <tr valign="top"><td width="25%" align="left">
                            ClickBank Secret Key:
                        </td><td align="left">
                            <input name="eMember_cb_secret_key" type="text" size="50" value="<?php 
    echo $emember_config->getValue('eMember_cb_secret_key');
    ?>
"/>
                            <br /><i>Enter your ClickBank secret key. You can configure your secret key from the <code>"Account Settings -> My Site -> Advanced Tools"</code> section of your ClickBank account.</i><br /><br />
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            ClickBank Instant Notification URL Value:
                        </td><td align="left">
                            <code><?php 
    echo WP_EMEMBER_URL . "/ipn/eMember_handle_clickbank_ipn.php";
    ?>
</code>
                            <br /><br /><i>Enter the above URL in your your ClickBank account's "Instant Notification URL" field (just below the secret key). You can find it in the <code>"Account Settings -> My Site -> Advanced Tools"</code> section of your ClickBank account.</i><br /><br />
                        </td></tr>
                </table>

                <div class="submit">
                    <input type="submit" name="info_update_emem_cb" class="button-primary" value="<?php 
    _e('Save Clickbank options');
    ?>
 &raquo;" />
                </div>
            </form>
        </div></div>

    <?php 
    echo '</div></div>';
    echo '</div>';
}
예제 #9
0
// prevent XSS
$email = htmlentities($_POST["email"]);
$userid = htmlentities($_POST["userid"]);
// array for JSON error communication
$returnValue = array();
// reject if given missing inputs and return error as JSON
// if(empty($email) || empty($name)){
//
//   $returnValue["status"] = "error";
//   $returnValue["message"] = "Missing required field";
//   echo json_encode($returnValue);
//
//   return;
// }
// create database access object from dbAccess.php
$access = new dbAccess();
$access->openconnection();
// get user details
$userDetails = $access->getUserDetails($userid);
// abort if email already in database
if (!empty($userDetails)) {
    $returnValue["status"] = "error";
    $returnValue["message"] = "User already exists";
    echo json_encode($returnValue);
    return;
}
// encrypt name as password for the database
$secure_password = md5($email);
// register user with secure password
$result = $access->registerUser($userid, $email, $secure_password);
// report success
function wp_eMember_scheduled_membership_upgrade()
{
    global $wpdb;
    $emember_config = Emember_Config::getInstance();
    $wpememmeta = new WPEmemberMeta();
    $membership_tbl = $wpememmeta->get_table('membership_level');
    $members_tbl = $wpememmeta->get_table('member');
    $email_list = array();
    $emails_for_followup_notification = array();
    $query_start = 0;
    $query_limit = 500;
    $iterations = 0;
    $membership_levels = Emember_Level_Collection::get_instance();
    while (1) {
        $query = 'SELECT member_id,membership_level,email,subscription_starts,account_state, ' . 'more_membership_levels, expiry_1st, expiry_2nd FROM ' . $members_tbl . ' WHERE account_state="active"  LIMIT ' . $query_start . ', ' . $query_limit;
        $members = $wpdb->get_results($query, OBJECT);
        if (count($members) < 1) {
            break;
        }
        foreach ($members as $member) {
            if (empty($member->subscription_starts)) {
                continue;
            }
            $should_update_db = false;
            $level_info = array();
            $my_level = $membership_levels->get_levels($member->membership_level);
            $options = unserialize($my_level->get('options'));
            $current_level = $member->membership_level;
            $more_levels = $member->more_membership_levels;
            $more_levels = is_array($more_levels) ? array_filter($more_levels) : $more_levels;
            $sec_levels = explode(',', $more_levels);
            $level_info['membership_level'] = $current_level;
            $level_info['account_state'] = $member->account_state;
            //Initialize the account state with the current data
            $level_data_modified = false;
            if (isset($options['promoted_level_id']) && !empty($options['promoted_level_id']) && $options['promoted_level_id'] != -1) {
                $current_subscription_starts = strtotime($member->subscription_starts);
                $current_time = time();
                while (1) {
                    if ($current_level === $options['promoted_level_id']) {
                        break;
                    }
                    $promoted_after = trim($options['days_after']);
                    if (empty($promoted_after)) {
                        break;
                    }
                    $d = $promoted_after == 1 ? ' day' : ' days';
                    $expires = strtotime(" + " . abs($promoted_after) . $d, $current_subscription_starts);
                    if ($expires > $current_time) {
                        break;
                    }
                    if (!isset($options['promoted_level_id']) || empty($options['promoted_level_id']) || $options['promoted_level_id'] == -1) {
                        break;
                    }
                    $sec_levels[] = $current_level;
                    $current_level = $options['promoted_level_id'];
                    $my_level = $membership_levels->get_levels($current_level);
                    //
                    $options = unserialize($my_level->get('options'));
                }
                if ($current_level != -1 && !empty($current_level) && $member->membership_level != $current_level) {
                    $level_info['membership_level'] = $current_level;
                    $level_data_modified = true;
                    if ($emember_config->getValue('eMember_enable_secondary_membership')) {
                        $level_info['more_membership_levels'] = array_unique($sec_levels);
                    }
                }
            }
            if (wp_emember_is_subscription_expired($member, $my_level)) {
                $level_info['account_state'] = 'expired';
                $level_data_modified = true;
                $sec = $emember_config->getValue('eMember_enable_secondary_membership');
                $migrate = $emember_config->getValue('eMember_secondary_membership_migrate');
                if ($sec && $migrate) {
                    foreach ($sec_levels as $key => $level) {
                        if (empty($level)) {
                            continue;
                        }
                        if (wp_emember_is_subscription_expired($member, $membership_levels->get_levels($level))) {
                            continue;
                        }
                        $sec_levels[$key] = $level_info['membership_level'];
                        $level_info['membership_level'] = $level;
                        $level_info['account_state'] = 'active';
                        $level_info['more_membership_levels'] = array_unique($sec_levels);
                        break;
                    }
                }
            }
            /*** notification after x day of account expiry ***/
            if (isset($level_info['account_state']) && $level_info['account_state'] == 'expired') {
                $is_auto_email = $emember_config->getValue('eMember_email_notification');
                $notification_interval = $emember_config->getValue('eMember_after_expiry_num_days');
                //$is_recurring = $emember_config->getValue('eMember_after_expiry_num_days_recurring');
                if (!empty($is_auto_email) && !empty($notification_interval)) {
                    $current_mem_level = $membership_levels->get_levels($level_info['membership_level']);
                    $days_elapsed = wp_emember_num_days_since_expired($current_mem_level->get('subscription_period'), $current_mem_level->get('subscription_unit'), $member->get('subscription_starts'));
                    if ($days_elapsed == $notification_interval) {
                        $emails_for_followup_notification[] = $member->email;
                    }
                }
            }
            /*** Auto upgrade ***/
            if ($level_data_modified) {
                eMember_log_cronjob_debug('Auto upgrading the member account with member ID: ' . $member->member_id . ' Level: ' . $level_info['membership_level'], true);
                eMember_log_cronjob_debug('Users account state: ' . $level_info['account_state'], true);
                $email_list[] = $member->email;
                if (isset($level_info['more_membership_levels'])) {
                    $level_info['more_membership_levels'] = implode(',', $level_info['more_membership_levels']);
                }
                if (!empty($level_info)) {
                    dbAccess::update(WP_EMEMBER_MEMBERS_TABLE_NAME, 'member_id=' . $member->member_id, $level_info);
                }
                do_action('emember_membership_changed', array('member_id' => $member->member_id, 'from_level' => $member->membership_level, 'to_level' => $level_info['membership_level']));
            }
        }
        $query_start = $query_limit * ++$iterations + 1;
    }
    //Handle auto upgrade notification if needed
    if ($emember_config->getValue('eMember_enable_autoupgrade_notification')) {
        eMember_log_cronjob_debug('Using auto upgrade notification email option.. need to check the email list.', true);
        if (!empty($email_list)) {
            $subject = $emember_config->getValue('eMember_autoupgrade_email_subject');
            eMember_log_cronjob_debug('Sending auto upgrade notification email with subject: ' . $subject, true);
            $body = $emember_config->getValue('eMember_autoupgrade_email_body');
            $headers = 'From: ' . $emember_config->getValue('eMember_autoupgrade_senders_email_address') . "\r\n";
            $headers .= 'bcc: ' . implode(',', $email_list) . "\r\n";
            eMember_log_cronjob_debug($headers, true);
            wp_mail(array(), $subject, $body, $headers);
            eMember_log_cronjob_debug('Auto upgrade notification email sent.', true);
        }
    }
    // Handle notification email after X days if needed
    if (!empty($emails_for_followup_notification)) {
        $subject = $emember_config->getValue('eMember_after_expiry_email_subject_followup');
        eMember_log_cronjob_debug('Sending expiry notification email after X days with subject: ' . $subject, true);
        $body = $emember_config->getValue('eMember_after_expiry_email_body_followup');
        $headers = 'From: ' . $emember_config->getValue('eMember_after_expiry_senders_email_address_followup') . "\r\n";
        $headers .= 'bcc: ' . implode(',', $emails_for_followup_notification) . "\r\n";
        eMember_log_cronjob_debug($headers, true);
        wp_mail(array(), $subject, $body, $headers);
        eMember_log_cronjob_debug('Expiry notification email sent.', true);
    }
    //mail
}
예제 #11
0
<?php

require "connection.php";
require "dbAccess.php";
// strip application sent data of XSS
$eventid = htmlentities($_POST["eventid"]);
$userid = htmlentities($_POST["userid"]);
// return array for for JSON responses
$resultArray = array();
// create db connection
$access = new dbAccess();
$access->openConnection();
// find database for event name in events table to delete
$result = $access->notGoingEvent($eventid, $userid);
// report success if query succeeded
if (!empty($result)) {
    $returnValue["status"] = "Success";
    $returnValue["message"] = "User is no longer attending";
    echo json_encode($returnValue);
} else {
    $returnValue["status"] = "error";
    $returnValue["message"] = "Bad request";
    echo json_encode($returnValue);
}
$access->closeConnection();
예제 #12
0
 public function __construct($userInfo)
 {
     $level_info = array();
     $current_level = $userInfo->membership_level;
     $more_levels = $userInfo->more_membership_levels;
     $more_levels = is_array($more_levels) ? array_filter($more_levels) : $more_levels;
     $userInfo->more_membership_levels = explode(',', $more_levels);
     $this->primary_level = Emember_Permission::get_instance($userInfo->membership_level);
     $this->secondary_levels = array();
     $config = Emember_Config::getInstance();
     $options = $this->primary_level->get_options();
     if (isset($options['promoted_level_id']) && $options['promoted_level_id'] != -1) {
         $current_subscription_starts = strtotime($userInfo->subscription_starts);
         $sec_levels = $userInfo->more_membership_levels;
         $level_before = $userInfo->membership_level;
         $current_time = time();
         while (1) {
             if ($current_level === $options['promoted_level_id']) {
                 break;
             }
             $promoted_after = trim($options['days_after']);
             if (empty($promoted_after)) {
                 break;
             }
             $d = $promoted_after == 1 ? ' day' : ' days';
             $expires = strtotime(" + " . abs($promoted_after) . $d, $current_subscription_starts);
             if ($expires > $current_time) {
                 break;
             }
             if (!isset($options['promoted_level_id']) || $options['promoted_level_id'] == -1) {
                 break;
             }
             //$current_subscription_starts = $expires;
             $sec_levels[] = $current_level;
             $current_level = $options['promoted_level_id'];
             $this->primary_level = Emember_Permission::get_instance($current_level);
             $options = $this->primary_level->get_options();
         }
         if ($current_level != -1) {
             $level_info['membership_level'] = $current_level;
             //$level_info ['current_subscription_starts'] = date('y-m-d', $current_subscription_starts);
             if ($config->getValue('eMember_enable_secondary_membership')) {
                 $sec_levels = array_unique($sec_levels);
                 $level_info['more_membership_levels'] = implode(',', $sec_levels);
                 $userInfo->more_membership_levels = $sec_levels;
             }
             $userInfo->membership_level = $current_level;
             dbAccess::update(WP_EMEMBER_MEMBERS_TABLE_NAME, 'member_id=' . $userInfo->member_id, $level_info);
             if ($level_info['membership_level'] != $level_before) {
                 do_action('emember_membership_changed', array('member_id' => $userInfo->member_id, 'from_level' => $level_before, 'to_level' => $level_info['membership_level']));
             }
         }
     }
     if ($config->getValue('eMember_enable_secondary_membership')) {
         if (!empty($userInfo->more_membership_levels)) {
             foreach ($userInfo->more_membership_levels as $l) {
                 if (empty($l)) {
                     continue;
                 }
                 $this->secondary_levels[] = Emember_Permission::get_instance($l);
             }
         }
     }
     $my_subcript_period = $this->primary_level->get('subscription_period');
     $my_subscript_unit = $this->primary_level->get('subscription_unit');
     if ($my_subcript_period == 0 && empty($my_subscript_unit)) {
         $type = 'noexpire';
     } else {
         if ($my_subcript_period == 0 && !empty($my_subscript_unit)) {
             $type = 'fixeddate';
             $my_subcript_period = $my_subscript_unit;
         } else {
             $type = 'interval';
             switch ($my_subscript_unit) {
                 case 'Days':
                     break;
                 case 'Weeks':
                     $my_subcript_period = $my_subcript_period * 7;
                     break;
                 case 'Months':
                     $my_subcript_period = $my_subcript_period * 30;
                     break;
                 case 'Years':
                     $my_subcript_period = $my_subcript_period * 365;
                     break;
             }
         }
     }
     $this->subscription_duration = array('duration' => $my_subcript_period, 'type' => $type);
 }
예제 #13
0
function manage_access_levels()
{
    global $wpdb;
    if (isset($_POST['add_new'])) {
        $alias = esc_sql(stripslashes($_POST['wpm_levels']['new_level']['name']));
        if (empty($alias)) {
            echo '<div id="message" style="color:red;" class="updated fade"><p>Level Name Is Required.</p></div>';
            return;
        }
        $exists = $wpdb->get_col("SELECT id from " . WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE . " WHERE alias = '" . $alias . "'");
        if (count($exists) > 0) {
            echo '<div id="message" style="color:red;" class="updated fade"><p>Membership level name already used. Please use a different name.</p></div>';
            return;
        }
        $role = $_POST['wpm_levels']['new_level']['role'];
        $login_redirect = esc_sql($_POST['wpm_levels']['new_level']['loginredirect']);
        $campaign_name = esc_sql(stripslashes($_POST['wpm_levels']['new_level']['campaign_name']));
        if (isset($_POST['wpm_levels']['new_level']['noexpire']) && $_POST['wpm_levels']['new_level']['noexpire'] == 'noexpire') {
            $subscription_period = 0;
            $subscription_unit = null;
        } else {
            if (isset($_POST['wpm_levels']['new_level']['noexpire']) && $_POST['wpm_levels']['new_level']['noexpire'] == 'fixed_date') {
                $subscription_period = 0;
                $subscription_unit = $_POST['wpm_levels']['new_level']['expire_date'];
            } else {
                $subscription_period = esc_sql($_POST['wpm_levels']['new_level']['expire']);
                $subscription_unit = esc_sql($_POST['wpm_levels']['new_level']['calendar']);
            }
        }
        $permissions = 0;
        $permissions += isset($_POST['wpm_levels']['new_level']['allcustomposts']) ? 32 : 0;
        $permissions += isset($_POST['wpm_levels']['new_level']['allattachments']) ? 16 : 0;
        $permissions += isset($_POST['wpm_levels']['new_level']['allpages']) ? 8 : 0;
        $permissions += isset($_POST['wpm_levels']['new_level']['allposts']) ? 4 : 0;
        $permissions += isset($_POST['wpm_levels']['new_level']['allcomments']) ? 2 : 0;
        $permissions += isset($_POST['wpm_levels']['new_level']['allcategories']) ? 1 : 0;
        $fields['role'] = $role;
        $fields['alias'] = $alias;
        $fields['permissions'] = $permissions;
        $fields['loginredirect_page'] = trim($login_redirect);
        $fields['subscription_period'] = $subscription_period;
        $fields['subscription_unit'] = $subscription_unit;
        $fields['campaign_name '] = $campaign_name;
        $ret = dbAccess::insert(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, $fields);
        if ($ret === false) {
            echo '<div id="message" style="color:red;" class="updated fade"><p>Membership Level &quot;' . $_POST['wpm_levels']['new_level']['name'] . '&quot; couldn\'t be created due to error.</p></div>';
        } else {
            echo '<div id="message" class="updated fade"><p>Membership Level &quot;' . $_POST['wpm_levels']['new_level']['name'] . '&quot; created.</p></div>';
            do_action('eMember_new_membership_level_added', $_POST);
        }
    } else {
        if (isset($_POST['update_info'])) {
            foreach ($_POST['wpm_levels'] as $id => $wp_level) {
                $alias = esc_sql(stripslashes($wp_level['name']));
                $role = $wp_level['role'];
                $login_redirect = esc_sql($wp_level['loginredirect']);
                $campaign_name = esc_sql(stripslashes($wp_level['campaign_name']));
                if (isset($wp_level['noexpire']) && $wp_level['noexpire'] == 'noexpire') {
                    $subscription_period = 0;
                    $subscription_unit = null;
                } else {
                    if (isset($wp_level['noexpire']) && $wp_level['noexpire'] == 'fixed_date') {
                        $subscription_period = 0;
                        $subscription_unit = $wp_level['expire_date'];
                    } else {
                        if (isset($wp_level['noexpire']) && $wp_level['noexpire'] == 'interval') {
                            $subscription_period = esc_sql($wp_level['expire']);
                            $subscription_unit = esc_sql($wp_level['calendar']);
                        }
                    }
                }
                $permissions = 0;
                $permissions += isset($wp_level['allcustomposts']) ? 32 : 0;
                $permissions += isset($wp_level['allattachments']) ? 16 : 0;
                $permissions += isset($wp_level['allpages']) ? 8 : 0;
                $permissions += isset($wp_level['allposts']) ? 4 : 0;
                $permissions += isset($wp_level['allcomments']) ? 2 : 0;
                $permissions += isset($wp_level['allcategories']) ? 1 : 0;
                $fields['role'] = $role;
                $fields['alias'] = $alias;
                $fields['permissions'] = $permissions;
                $fields['loginredirect_page'] = trim($login_redirect);
                $fields['subscription_period'] = $subscription_period;
                $fields['subscription_unit'] = $subscription_unit;
                $fields['campaign_name'] = $campaign_name;
                /**
                 * @todo update role based on flags.
                 * */
                $ret = dbAccess::update(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, ' id = ' . $wp_level['id'], $fields);
                if ($ret === false) {
                    echo '<div id="message" style="color:red;" class="updated fade"><p>Membership Level Update Failed..</p></div>';
                } else {
                    echo '<div id="message" class="updated fade"><p>Membership Level Updated.</p></div>';
                    do_action('eMember_membership_level_updated', $_POST);
                }
            }
        } else {
            if (isset($_GET['delete'])) {
                $ret = dbAccess::delete(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, ' id=' . $_GET['delete']);
                if ($ret === false) {
                    echo '<div id="message" style="color:red;" class="updated fade"><p>Membership Level Couldn\'t be deleted due to error.</p></div>';
                } else {
                    if ($ret === 0) {
                        echo '<div id="message" style="color:red;" class="updated fade"><p>Nothing to delete.</p></div>';
                    } else {
                        echo '<div id="message" class="updated fade"><p>Membership Level Deleted.</p></div>';
                        do_action('eMember_membership_level_deleted', $_POST);
                    }
                }
            }
        }
    }
    $all_levels = dbAccess::findAll(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, ' id != 1 ', ' id DESC ');
    include_once 'views/manage_access_levels_view.php';
}
예제 #14
0
파일: modify.php 프로젝트: phupx/genco
$referee_data = array();
if ($referee_custom_fields) {
    $referee_data = unserialize($referee_custom_fields->meta_value);
    $referee_data['Good_Karma_Referrer'] = $referrer_email;
    //reference to Good Karma Referrer
    $wpdb->query('UPDATE ' . WP_EMEMBER_MEMBERS_META_TABLE . ' SET meta_value =' . '\'' . serialize($referee_data) . '\' WHERE meta_key = \'custom_field\' AND  user_id=' . $referee_id);
    eMember_log_debug('Referee Member data has been updated', true);
} else {
    $referee_data['Good_Karma_Referrer'] = $referrer_email;
    //reference to Good Karma Referrer
    $referee_data['Good_Karma_Referrals'] = '';
    $wpdb->query("INSERT INTO " . WP_EMEMBER_MEMBERS_META_TABLE . '( user_id, meta_key, meta_value ) VALUES(' . $referee_id . ',"custom_field",' . '\'' . serialize($referee_data) . '\')');
    eMember_log_debug('Referee Member data has been inserted', true);
}
// Update the Referrer Member
$referrer_custom_fields = dbAccess::find(WP_EMEMBER_MEMBERS_META_TABLE, ' user_id=\'' . $referrer_id . '\' AND meta_key=\'custom_field\'');
$referrer_data = array();
if ($referrer_custom_fields) {
    $referrer_data = unserialize($referrer_custom_fields->meta_value);
    $referrer_data['Good_Karma_Referrals'] .= ($referrer_data['Good_Karma_Referrals'] != '' ? ', ' : '') . $referee_email;
    //reference to Good Karma Referee
    $wpdb->query('UPDATE ' . WP_EMEMBER_MEMBERS_META_TABLE . ' SET meta_value =' . '\'' . serialize($referrer_data) . '\' WHERE meta_key = \'custom_field\' AND  user_id=' . $referrer_id);
    eMember_log_debug('Referrer Member data has been updated', true);
} else {
    $referrer_data['Good_Karma_Referrer'] = '';
    $referrer_data['Good_Karma_Referrals'] = $referee_email;
    //reference to Good Karma Referee;
    $wpdb->query("INSERT INTO " . WP_EMEMBER_MEMBERS_META_TABLE . '( user_id, meta_key, meta_value ) VALUES(' . $referrer_id . ',"custom_field",' . '\'' . serialize($referrer_data) . '\')');
    eMember_log_debug('Referrer Member data has been inserted', true);
}
echo "Success!\n";
예제 #15
0
function wp_eMember_add_memebers()
{
    $emember_config = Emember_Config::getInstance();
    global $wpdb;
    $d = WP_EMEMBER_URL . '/images/default_image.gif';
    //If being edited, grab current info
    if (isset($_GET['editrecord']) && $_GET['editrecord'] != '') {
        $theid = $_GET['editrecord'];
        $editingrecord = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=' . $theid);
        $edit_custom_fields = dbAccess::find(WP_EMEMBER_MEMBERS_META_TABLE, ' user_id=' . $theid . ' AND meta_key="custom_field"');
        $edit_custom_fields = isset($edit_custom_fields->meta_value) ? unserialize($edit_custom_fields->meta_value) : array();
        $editingrecord->more_membership_levels = explode(',', $editingrecord->more_membership_levels);
        $editingrecord = (array) $editingrecord;
        $image_url = null;
        $image_path = null;
        $upload_dir = wp_upload_dir();
        $upload_url = $upload_dir['baseurl'] . '/emember/';
        $upload_path = $upload_dir['basedir'] . '/emember/';
        $use_gravatar = $emember_config->getValue('eMember_use_gravatar');
        if ($use_gravatar) {
            $image_url = WP_EMEMBER_GRAVATAR_URL . "/" . md5(strtolower($editingrecord['email'])) . "?d=" . urlencode($d) . "&s=" . 96;
        } else {
            if (!empty($editingrecord['profile_image'])) {
                $image_url = $upload_url . $editingrecord['profile_image'];
                $image_path = $theid;
            } else {
                $image_path = "";
                $image_url = WP_EMEMBER_URL . '/images/default_image.gif';
            }
        }
    }
    if (isset($_POST['Submit'])) {
        global $wpdb;
        include_once ABSPATH . WPINC . '/class-phpass.php';
        $wp_hasher = new PasswordHash(8, TRUE);
        $post_editedrecord = esc_sql(isset($_POST['editedrecord']) ? $_POST['editedrecord'] : "");
        $fields = array();
        $fields['flags'] = 0;
        if ($emember_config->getValue('eMember_enable_secondary_membership')) {
            $fields['more_membership_levels'] = implode(',', empty($_POST['more_membership_levels']) ? array() : $_POST['more_membership_levels']);
        }
        $fields["user_name"] = $_POST["user_name"];
        $fields["first_name"] = $_POST["first_name"];
        $fields["last_name"] = $_POST["last_name"];
        $fields["company_name"] = $_POST["company_name"];
        $fields["member_since"] = $_POST["member_since"];
        $fields["membership_level"] = $_POST["membership_level"];
        $fields["account_state"] = $_POST["account_state"];
        $fields["email"] = $_POST["email"];
        $fields["phone"] = $_POST["phone"];
        $fields["address_street"] = $_POST["address_street"];
        $fields["address_city"] = $_POST["address_city"];
        $fields["address_state"] = $_POST["address_state"];
        $fields["address_zipcode"] = $_POST["address_zipcode"];
        $fields["home_page"] = $_POST["home_page"];
        $fields["country"] = $_POST["country"];
        $fields["gender"] = $_POST["gender"];
        $fields["referrer"] = $_POST["referrer"];
        $fields["subscription_starts"] = $_POST["subscription_starts"];
        $fields['last_accessed_from_ip'] = get_real_ip_addr();
        $fields["notes"] = $_POST['notes'];
        $wp_user_info = array();
        $wp_user_info['user_nicename'] = implode('-', explode(' ', $_POST['user_name']));
        $wp_user_info['display_name'] = $_POST['user_name'];
        $wp_user_info['user_email'] = $_POST['email'];
        $wp_user_info['nickname'] = $_POST['user_name'];
        $wp_user_info['first_name'] = $_POST['first_name'];
        $wp_user_info['last_name'] = $_POST['last_name'];
        if ($post_editedrecord == '') {
            $fields['user_name'] = esc_sql($_POST['user_name']);
            $wp_user_info['user_login'] = $_POST['user_name'];
            // Add the record to the DB
            include_once 'emember_validator.php';
            $validator = new Emember_Validator();
            $validator->add(array('value' => $fields['user_name'], 'label' => 'User Name', 'rules' => array('user_required', 'user_name', 'user_unavail', 'user_minlength')));
            $validator->add(array('value' => $_POST['password'], 'repeat' => $_POST['retype_password'], 'label' => 'Password', 'rules' => array('pass_required', 'pass_mismatch')));
            $validator->add(array('value' => $fields['email'], 'label' => 'Email', 'rules' => array('email_required', 'email_unavail')));
            $messages = $validator->validate();
            if (count($messages) > 0) {
                echo '<span class="emember_error">' . implode('<br/>', $messages) . '</span>';
                $editingrecord = $_POST;
            } else {
                $password = $wp_hasher->HashPassword($_POST['password']);
                $fields['password'] = esc_sql($password);
                $ret = dbAccess::insert(WP_EMEMBER_MEMBERS_TABLE_NAME, $fields);
                $lastid = $wpdb->insert_id;
                $should_create_wp_user = $emember_config->getValue('eMember_create_wp_user');
                if ($should_create_wp_user) {
                    $role_names = array(1 => 'Administrator', 2 => 'Editor', 3 => 'Author', 4 => 'Contributor', 5 => 'Subscriber');
                    $membership_level_resultset = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, " id='" . $fields['membership_level'] . "'");
                    $wp_user_info['role'] = $membership_level_resultset->role;
                    $wp_user_info['user_registered'] = date('Y-m-d H:i:s');
                    //$wp_user_id = wp_create_user($_POST['user_name'], $_POST['password'], $_POST['email']);
                    $wp_user_id = eMember_wp_create_user($_POST['user_name'], $_POST['password'], $_POST['email'], $wp_user_info);
                    //do_action( 'set_user_role', $wp_user_id, $membership_level_resultset->role );
                }
                ///custom field insert
                if (isset($_POST['emember_custom'])) {
                    $wpdb->query("INSERT INTO " . WP_EMEMBER_MEMBERS_META_TABLE . '( user_id, meta_key, meta_value ) VALUES(' . $lastid . ',"custom_field",' . '\'' . addslashes(serialize($_POST['emember_custom'])) . '\')');
                }
                if ($ret === false) {
                    $_SESSION['flash_message'] = '<div id="message" style = "color:red;" class="updated fade"><p>Couldn\'t create new member.</p></div>';
                } else {
                    if (isset($_POST['uploaded_profile_img'])) {
                        $upload_dir = wp_upload_dir();
                        $upload_path = $upload_dir['basedir'];
                        $upload_path .= '/emember/';
                        $ext = explode('.', $_POST['uploaded_profile_img']);
                        rename($upload_path . $_POST['uploaded_profile_img'], $upload_path . $lastid . '.' . $ext[1]);
                    }
                    $_SESSION['flash_message'] = '<div id="message" class="updated fade"><p>Member &quot;' . $fields['user_name'] . '&quot; created.</p></div>';
                    //Notify the newly created member if specified in the settings
                    if ($emember_config->getValue('eMember_email_notification_for_manual_member_add')) {
                        $login_link = $emember_config->getValue('login_page_url');
                        $member_email_address = $_POST['email'];
                        $subject_rego_complete = $emember_config->getValue('eMember_email_subject_rego_complete');
                        $body_rego_complete = $emember_config->getValue('eMember_email_body_rego_complete');
                        $from_address = $emember_config->getValue('senders_email_address');
                        $headers = 'From: ' . $from_address . "\r\n";
                        $curr_member_id = $lastid;
                        $additional_params = array('password' => $_POST['password'], 'login_link' => $login_link);
                        $email_body1 = emember_dynamically_replace_member_details_in_message($curr_member_id, $body_rego_complete, $additional_params);
                        wp_mail($member_email_address, $subject_rego_complete, $email_body1, $headers);
                    }
                    //Create the corresponding affliate account if specified in the settings
                    if ($emember_config->getValue('eMember_auto_affiliate_account')) {
                        eMember_handle_affiliate_signup($_POST['user_name'], $_POST['password'], $_POST['first_name'], $_POST['last_name'], $_POST['email'], '');
                    }
                    /*                         * * Signup the member to Autoresponder List (Autoresponder integration) ** */
                    eMember_log_debug("===> Performing autoresponder signup if needed (member was added via admin dashboard) <===", true);
                    $membership_level_id = $_POST["membership_level"];
                    $firstname = $_POST['first_name'];
                    $lastname = $_POST['last_name'];
                    $emailaddress = $_POST['email'];
                    eMember_level_specific_autoresponder_signup($membership_level_id, $firstname, $lastname, $emailaddress);
                    eMember_global_autoresponder_signup($firstname, $lastname, $emailaddress);
                    /*                         * * end of autoresponder integration ** */
                    echo '<script type="text/javascript">window.location = "admin.php?page=wp_eMember_manage";</script>';
                }
            }
        } else {
            if (isset($_POST['emember_custom'])) {
                $custom_fields = dbAccess::find(WP_EMEMBER_MEMBERS_META_TABLE, ' user_id=' . $post_editedrecord . ' AND meta_key=\'custom_field\'');
                if ($custom_fields) {
                    $wpdb->query('UPDATE ' . WP_EMEMBER_MEMBERS_META_TABLE . ' SET meta_value =' . '\'' . addslashes(serialize($_POST['emember_custom'])) . '\' WHERE meta_key = \'custom_field\' AND  user_id=' . $post_editedrecord);
                } else {
                    $wpdb->query("INSERT INTO " . WP_EMEMBER_MEMBERS_META_TABLE . '( user_id, meta_key, meta_value ) VALUES(' . $post_editedrecord . ',"custom_field",' . '\'' . addslashes(serialize($_POST['emember_custom'])) . '\')');
                }
            } else {
                $wpdb->query('DELETE FROM ' . WP_EMEMBER_MEMBERS_META_TABLE . '  WHERE meta_key = \'custom_field\' AND  user_id=' . $post_editedrecord);
            }
            $editingrecord = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=' . $post_editedrecord);
            // Update the member info
            $member_id = esc_sql($_POST['editedrecord']);
            $wp_user_id = username_exists($fields['user_name']);
            $wp_email_owner = email_exists($fields['email']);
            $emember_email_owner = emember_email_exists($fields['email']);
            if (empty($fields['user_name']) || $fields['user_name'] != $editingrecord->user_name) {
                echo '<div id="message" class="updated fade"><p>User Name Cannot Be Changed!</p></div>';
            } else {
                if (empty($fields['email'])) {
                    echo '<div id="message" class="updated fade"><p>Email Field is Empty!</p></div>';
                } else {
                    if ($wp_email_owner && $wp_user_id != $wp_email_owner || $emember_email_owner && $member_id != $emember_email_owner) {
                        echo '<div id="message" class="updated fade"><p>Email ID &quot;' . $fields['email'] . '&quot; is already registered to a user!</p></div>';
                    } else {
                        $update_possible = true;
                        if (!empty($_POST['password'])) {
                            if ($_POST['password'] === $_POST['retype_password']) {
                                $password = $wp_hasher->HashPassword($_POST['password']);
                                $fields['password'] = esc_sql($password);
                                $wp_user_info['user_pass'] = $_POST['password'];
                            } else {
                                $update_possible = false;
                                echo '<div id="message" class="updated fade"><p>Password does\'t match!</p></div>';
                            }
                        }
                        if ($update_possible) {
                            $ret = dbAccess::update(WP_EMEMBER_MEMBERS_TABLE_NAME, 'member_id = ' . $member_id, $fields);
                            if ($fields["membership_level"] != $editingrecord->membership_level) {
                                do_action('emember_membership_changed', array('member_id' => $editingrecord->member_id, 'from_level' => $editingrecord->membership_level, 'to_level' => $fields["membership_level"]));
                            }
                            if ($wp_user_id && !is_wp_error($wp_user_id)) {
                                $wp_user_info['ID'] = $wp_user_id;
                                wp_update_user($wp_user_info);
                                if (($editingrecord->flags & 1) != 1) {
                                    $cond = " id='" . $fields['membership_level'] . "'";
                                    $membership_level_resultset = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, $cond);
                                    update_wp_user_Role($wp_user_id, $membership_level_resultset->role);
                                    //do_action( 'set_user_role', $wp_user_id, $membership_level_resultset->role );
                                }
                            }
                            if ($ret === false) {
                                $_SESSION['flash_message'] = '<div id="message" class="updated fade"><p>' . __('Member', 'wp_eMember') . ' &quot;' . $fields['user_name'] . '&quot; ' . __('Update Failed.', 'wp_eMember') . '</p></div>';
                            } else {
                                $_SESSION['flash_message'] = '<div id="message" class="updated fade"><p>' . __('Member', 'wp_eMember') . ' &quot;' . $fields['user_name'] . '&quot; ' . __('updated.', 'wp_eMember') . '</p></div>';
                                if (isset($_POST['account_status_change'])) {
                                    $from_address = $emember_config->getValue('senders_email_address');
                                    $headers = 'From: ' . $from_address . "\r\n";
                                    $subject = $_POST['notificationmailhead'];
                                    $member_email_address = $_POST['email'];
                                    $login_link = $emember_config->getValue('login_page_url');
                                    $additional_params = array('password' => $_POST['password'], 'login_link' => $login_link);
                                    $curr_member_id = $post_editedrecord;
                                    $email_body = emember_dynamically_replace_member_details_in_message($curr_member_id, $_POST['notificationmailbody'], $additional_params);
                                    wp_mail($member_email_address, $subject, $email_body, $headers);
                                    $emember_config->setValue('eMember_status_change_email_body', $_POST['notificationmailbody']);
                                    $emember_config->setValue('eMember_status_change_email_subject', $_POST['notificationmailhead']);
                                    $emember_config->saveConfig();
                                }
                                echo '<script type="text/javascript">window.location = "admin.php?page=wp_eMember_manage";</script>';
                            }
                        }
                    }
                }
            }
            $editingrecord = (array) $editingrecord;
        }
    }
    $all_levels = dbAccess::findAll(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, ' id != 1 ', ' id DESC ');
    include_once 'views/add_member_view.php';
}
예제 #16
0
<?php

require_once 'headbar.php';
require_once 'dbaccess.php';
require_once 'dblogin.php';
$username = "******" . $_SESSION['username'] . "'";
$title = "'" . $_POST['title'] . "'";
$post = "'" . $_POST['forumText'] . "'";
$db = new dbAccess($host, $user, $password, $database);
$fields = ["poster", "title", "comment", "commentid"];
$values = [$username, $title, $post, 0];
$result = $db->insertDB('threads', $values, $fields, '', '');
if ($result) {
    $title = $_POST['title'];
    header("Location: forum.php?title=" . $title);
} else {
}
function wp_estore_add_product_menu()
{
    echo '<div class="wrap">';
    echo "<h2>Add/Edit Products</h2>";
    echo '<div id="poststuff"><div id="post-body">';
    $eStore_products_per_page = get_option('eStore_products_per_page');
    if (empty($eStore_products_per_page)) {
        echo '<div id="message" class="updated fade"><p>';
        echo 'It appears that you have never saved your settings after installing the plugin! Please visit the settings page of this plugin and save it.';
        echo '</p></div>';
    }
    global $wpdb;
    global $products_table_name;
    global $cat_prod_rel_table_name;
    global $cat_table_name;
    $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME;
    //If product is being edited, grab current product info
    if (isset($_GET['editproduct']) && $_GET['editproduct'] != '') {
        $theid = $_GET['editproduct'];
        $editingproduct = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$theid}'", OBJECT);
    }
    if (isset($_POST['Submit'])) {
        if (empty($_POST['productname'])) {
            echo '<div id="message" class="updated fade"><p>' . __('Product name cannot be empty!', 'wp_eStore') . '</p></div>';
        } else {
            $chars_to_replace = array("\r\n", "\n", "\r");
            //Used to replaced hidden chars in various fields
            $curr_symbol = get_option('cart_currency_symbol');
            if (!isset($_POST['editedproduct'])) {
                $_POST['editedproduct'] = "";
            }
            if (!isset($_POST['productid'])) {
                $_POST['productid'] = "";
            }
            if (!isset($_POST['show_qty'])) {
                $_POST['show_qty'] = "";
            }
            if (!isset($_POST['custom_input'])) {
                $_POST['custom_input'] = "";
            }
            if (!isset($_POST['custom_price_option'])) {
                $_POST['custom_price_option'] = "";
            }
            if (!isset($_POST['ppv_content'])) {
                $_POST['ppv_content'] = "";
            }
            if (!isset($_POST['use_pdf_stamper'])) {
                $_POST['use_pdf_stamper'] = "";
            }
            if (!isset($_POST['create_license'])) {
                $_POST['create_license'] = "";
            }
            if (!isset($_POST['sra'])) {
                $_POST['sra'] = "";
            }
            $post_editedproduct = esc_sql($_POST['editedproduct']);
            $post_productid = esc_sql($_POST['productid']);
            //$tmp_name = htmlentities(stripslashes($_POST['productname']) , ENT_COMPAT, "UTF-8");
            $tmp_name = strip_tags(stripslashes($_POST['productname']));
            $post_productname = esc_sql($tmp_name);
            $post_productprice = esc_sql($_POST['productprice']);
            if (empty($_POST['a3'])) {
                //filter the price field value if this is not a subscription product
                $post_productprice = str_replace($curr_symbol, "", $post_productprice);
            }
            $post_producturl = trim(esc_sql($_POST['producturl']));
            $post_product_downloadable = esc_sql($_POST['productdownloadable']);
            $post_product_shipping = esc_sql($_POST['shippingcost']);
            $post_product_available_copies = esc_sql($_POST['availablecopies']);
            $post_product_button_image_url = trim(esc_sql($_POST['buttonimageurl']));
            $post_product_return_url = trim(esc_sql($_POST['returnurl']));
            $paypal_email = esc_sql($_POST['paypal_email']);
            $post_product_sales_count = esc_sql($_POST['salescount']);
            //$post_product_description = $wpdb->escape($_POST['productdesc']);
            $tmpdescription = htmlentities(stripslashes($_POST['productdesc']), ENT_COMPAT, "UTF-8");
            $post_product_description = esc_sql($tmpdescription);
            $post_product_thumbnail = trim(esc_sql($_POST['thumbnail_url']));
            $post_product_variation1 = esc_sql(stripslashes($_POST['variation1']));
            $post_product_variation2 = esc_sql(stripslashes($_POST['variation2']));
            $post_product_variation3 = esc_sql(stripslashes($_POST['variation3']));
            $post_product_variation3 = str_replace($chars_to_replace, "", $post_product_variation3);
            //replace any hidden newlines
            $variation4 = esc_sql(stripslashes($_POST['variation4']));
            $post_product_commission = trim(esc_sql($_POST['productcommission']));
            if ($post_product_downloadable == 'on') {
                $post_product_downloadable = 'yes';
            } else {
                $post_product_downloadable = 'no';
            }
            // Subscription related fields
            $post_a1 = str_replace($curr_symbol, "", $_POST['a1']);
            $a1 = esc_sql($post_a1);
            $p1 = esc_sql($_POST['p1']);
            $t1 = esc_sql($_POST['t1']);
            $post_a3 = str_replace($curr_symbol, "", $_POST['a3']);
            $a3 = esc_sql($post_a3);
            $p3 = esc_sql($_POST['p3']);
            $t3 = esc_sql($_POST['t3']);
            $sra = esc_sql($_POST['sra']);
            $srt = esc_sql($_POST['srt']);
            $ref_text = esc_sql($_POST['ref_text']);
            if ($sra == 'on') {
                $sra = '1';
            } else {
                $sra = '0';
            }
            $custom_input = esc_sql($_POST['custom_input']);
            if ($custom_input == 'on') {
                $custom_input = '1';
            } else {
                $custom_input = '0';
            }
            $custom_input_label = esc_sql($_POST['custom_input_label']);
            $aweber_list = esc_sql(trim(stripslashes($_POST['aweber_list'])));
            $currency_code = esc_sql($_POST['currency_code']);
            $target_thumb_url = trim(esc_sql($_POST['target_thumb_url']));
            $target_button_url = trim(esc_sql($_POST['target_button_url']));
            $weight = esc_sql($_POST['itemweight']);
            $product_url = trim(esc_sql($_POST['product_url']));
            $tmp_item_spec_instruction = stripslashes($_POST['item_spec_instruction']);
            $post_item_spec_instruction = esc_sql($tmp_item_spec_instruction);
            $ppv_content = esc_sql($_POST['ppv_content']);
            if ($ppv_content == 'on') {
                $ppv_content = '1';
            } else {
                $ppv_content = '0';
            }
            $use_pdf_stamper = esc_sql($_POST['use_pdf_stamper']);
            if ($use_pdf_stamper == 'on') {
                $use_pdf_stamper = '1';
            } else {
                $use_pdf_stamper = '0';
            }
            $create_license = esc_sql($_POST['create_license']);
            if ($create_license == 'on') {
                $create_license = '1';
            } else {
                $create_license = '0';
            }
            $post_tax = esc_sql($_POST['tax']);
            $post_author_id = trim(esc_sql($_POST['author_id']));
            $show_qty = esc_sql($_POST['show_qty']);
            if ($show_qty == 'on') {
                $show_qty = '1';
            } else {
                $show_qty = '0';
            }
            $tier2_commission = esc_sql($_POST['tier2_commission']);
            $custom_price_option = esc_sql($_POST['custom_price_option']);
            if ($custom_price_option == 'on') {
                $custom_price_option = '1';
            } else {
                $custom_price_option = '0';
            }
            $post_additional_images = esc_sql($_POST['additional_images']);
            $post_additional_images = str_replace($chars_to_replace, "", $post_additional_images);
            //replace any hidden newlines
            $post_oldprice = esc_sql($_POST['old_price']);
            $post_rev_share_commission = esc_sql($_POST['rev_share_commission']);
            $post_rev_share_commission = str_replace($curr_symbol, "", $post_rev_share_commission);
            $post_rev_share_commission = str_replace("%", "", $post_rev_share_commission);
            $post_per_customer_qty_limit = esc_sql($_POST['per_customer_qty_limit']);
            //----- Some default input values ----------
            if ($post_product_sales_count == '') {
                $post_product_sales_count = 0;
            }
            if ($p1 == '') {
                $p1 = 0;
            }
            if ($p3 == '' || $p3 < 1) {
                $p3 = 1;
            }
            if ($srt == '') {
                $srt = 0;
            }
            if (!isset($_POST['category'])) {
                $_POST['category'] = "";
            }
            //Validate the form URL inputs
            $form_url_fields_validated = true;
            $validation_error_message = "";
            $url_validation_error_msg_ignore = "<p><i>If you know for sure that the URL is correct then ignore this message. You can copy and paste the URL in a browser's address bar to make sure the URL is correct.</i></p>";
            if (!eStore_is_valid_url_if_not_empty($post_product_thumbnail)) {
                $validation_error_message .= "<br /><strong>The URL specified in the \"Thumbnail Image URL\" field does not seem to be a valid URL! Please check this value again:</strong>";
                $validation_error_message .= "<br />" . $post_product_thumbnail . "<br />";
                $form_url_fields_validated = false;
            }
            if (!eStore_is_valid_url_if_not_empty($target_thumb_url)) {
                $validation_error_message .= "<br /><strong>The URL specified in the \"Thumbnail Target URL\" field does not seem to be a valid URL! Please check this value again:</strong>";
                $validation_error_message .= "<br />" . $target_thumb_url . "<br />";
                $form_url_fields_validated = false;
            }
            if (!eStore_is_valid_url_if_not_empty($product_url)) {
                $validation_error_message .= "<br /><strong>The URL specified in the \"Product Page URL\" field does not seem to be a valid URL! Please check this value again:</strong>";
                $validation_error_message .= "<br />" . $product_url . "<br />";
                $form_url_fields_validated = false;
            }
            if (!eStore_is_valid_url_if_not_empty($post_product_button_image_url)) {
                $validation_error_message .= "<br /><strong>The URL specified in the \"Button Image URL\" field does not seem to be a valid URL! Please check this value again:</strong>";
                $validation_error_message .= "<br />" . $post_product_button_image_url . "<br />";
                $form_url_fields_validated = false;
            }
            if (!eStore_is_valid_url_if_not_empty($target_button_url)) {
                $validation_error_message .= "<br /><strong>The URL specified in the \"Button Redirect Target URL\" field does not seem to be a valid URL! Please check this value again:</strong>";
                $validation_error_message .= "<br />" . $target_button_url . "<br />";
                $form_url_fields_validated = false;
            }
            if (!$form_url_fields_validated) {
                //Get the updated product again
                $_GET['editproduct'] = $post_editedproduct;
                $editingproduct = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$post_editedproduct}'", OBJECT);
                echo '<div id="message" class="error fade"><p>';
                echo $validation_error_message;
                echo $url_validation_error_msg_ignore;
                echo '</p></div>';
            }
            //Insert or Update the database
            if ($post_editedproduct == '') {
                $updatedb = "INSERT INTO {$products_table_name} (name, price, product_download_url, downloadable, shipping_cost, available_copies, button_image_url, return_url, sales_count,description,thumbnail_url,variation1,variation2,variation3,commission,a1,p1,t1,a3,p3,t3,sra,srt,ref_text,paypal_email,custom_input,custom_input_label,variation4,aweber_list,currency_code,target_thumb_url,target_button_url,weight,product_url,item_spec_instruction,ppv_content,use_pdf_stamper,create_license,tax,author_id,show_qty,tier2_commission,custom_price_option,additional_images,old_price,rev_share_commission,per_customer_qty_limit) VALUES ('{$post_productname}', '{$post_productprice}','{$post_producturl}','{$post_product_downloadable}','{$post_product_shipping}','{$post_product_available_copies}','{$post_product_button_image_url}','{$post_product_return_url}','{$post_product_sales_count}','{$post_product_description}','{$post_product_thumbnail}','{$post_product_variation1}','{$post_product_variation2}','{$post_product_variation3}','{$post_product_commission}','{$a1}','{$p1}','{$t1}','{$a3}','{$p3}','{$t3}','{$sra}','{$srt}','{$ref_text}','{$paypal_email}','{$custom_input}','{$custom_input_label}','{$variation4}','{$aweber_list}','{$currency_code}','{$target_thumb_url}','{$target_button_url}','{$weight}','{$product_url}','{$post_item_spec_instruction}','{$ppv_content}','{$use_pdf_stamper}','{$create_license}','{$post_tax}','{$post_author_id}','{$show_qty}','{$tier2_commission}','{$custom_price_option}','{$post_additional_images}','{$post_oldprice}','{$post_rev_share_commission}','{$post_per_customer_qty_limit}')";
                $results = $wpdb->query($updatedb);
                $wp_eStore_product_ret = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = LAST_INSERT_ID()", OBJECT);
                $cur_product_id = $wp_eStore_product_ret->id;
                //Add the new category relationship
                $categories = $_POST['category'];
                if (!empty($categories)) {
                    while (list($key, $val) = @each($categories)) {
                        $updatedb = "INSERT INTO {$cat_prod_rel_table_name} (cat_id, prod_id) VALUES ('{$val}', '{$cur_product_id}')";
                        $results = $wpdb->query($updatedb);
                    }
                }
                //Add download meta data
                $download_limit_time = esc_sql($_POST['download_limit_time']);
                if (!empty($download_limit_time)) {
                    $updatedb = "INSERT INTO {$product_meta_table_name} (prod_id, meta_key, meta_value) VALUES ('{$cur_product_id}', 'download_limit_time','{$download_limit_time}')";
                    $results = $wpdb->query($updatedb);
                }
                $download_limit_count = esc_sql($_POST['download_limit_count']);
                if (!empty($download_limit_count)) {
                    $updatedb = "INSERT INTO {$product_meta_table_name} (prod_id, meta_key, meta_value) VALUES ('{$cur_product_id}', 'download_limit_count','{$download_limit_count}')";
                    $results = $wpdb->query($updatedb);
                }
                //Add product meta data
                $available_key_codes = esc_sql($_POST['available_key_codes']);
                if (!empty($available_key_codes)) {
                    $updatedb = "INSERT INTO {$product_meta_table_name} (prod_id, meta_key, meta_value) VALUES ('{$cur_product_id}', 'available_key_codes','{$available_key_codes}')";
                    $results = $wpdb->query($updatedb);
                }
                //Get the handle to the inserted product
                $_GET['editproduct'] = $wp_eStore_product_ret->id;
                $editingproduct = $wp_eStore_product_ret;
                echo '<div id="message" class="updated fade"><p>Product &quot;' . $post_productname . '&quot; created.</p></div>';
                do_action('eStore_new_product_added', $_POST, $_GET['editproduct']);
            } else {
                $updatedb = "UPDATE {$products_table_name} SET name = '{$post_productname}', price = '{$post_productprice}', product_download_url = '{$post_producturl}', downloadable = '{$post_product_downloadable}', shipping_cost = '{$post_product_shipping}', available_copies = '{$post_product_available_copies}', button_image_url='{$post_product_button_image_url}', return_url = '{$post_product_return_url}', sales_count = '{$post_product_sales_count}', description = '{$post_product_description}', thumbnail_url = '{$post_product_thumbnail}', variation1='{$post_product_variation1}', variation2='{$post_product_variation2}',variation3='{$post_product_variation3}',commission='{$post_product_commission}',a1='{$a1}',p1='{$p1}',t1='{$t1}',a3='{$a3}',p3='{$p3}',t3='{$t3}',sra='{$sra}',srt='{$srt}',ref_text='{$ref_text}',paypal_email='{$paypal_email}',custom_input='{$custom_input}',custom_input_label='{$custom_input_label}',variation4='{$variation4}',aweber_list='{$aweber_list}',currency_code='{$currency_code}',target_thumb_url='{$target_thumb_url}',target_button_url='{$target_button_url}',weight='{$weight}',product_url='{$product_url}',item_spec_instruction='{$post_item_spec_instruction}',ppv_content='{$ppv_content}',use_pdf_stamper='{$use_pdf_stamper}',create_license='{$create_license}',tax='{$post_tax}',author_id='{$post_author_id}',show_qty='{$show_qty}',tier2_commission='{$tier2_commission}',custom_price_option='{$custom_price_option}',additional_images='{$post_additional_images}',old_price='{$post_oldprice}',rev_share_commission='{$post_rev_share_commission}',per_customer_qty_limit='{$post_per_customer_qty_limit}' WHERE id='{$post_editedproduct}'";
                $results = $wpdb->query($updatedb);
                //Delete the existing category relationship
                $updatedb = "DELETE FROM {$cat_prod_rel_table_name} WHERE prod_id='{$post_editedproduct}'";
                $results = $wpdb->query($updatedb);
                //Add the new relationship
                $categories = $_POST['category'];
                if (!empty($categories)) {
                    while (list($key, $val) = @each($categories)) {
                        $updatedb = "INSERT INTO {$cat_prod_rel_table_name} (cat_id, prod_id) VALUES ('{$val}', '{$post_editedproduct}')";
                        $results = $wpdb->query($updatedb);
                    }
                }
                //Update product meta data
                $download_limit_time = esc_sql($_POST['download_limit_time']);
                //check if download time is specified
                $editingproductmeta = $wpdb->get_row("SELECT * FROM {$product_meta_table_name} WHERE prod_id = '{$post_editedproduct}' AND meta_key='download_limit_time'", OBJECT);
                if ($editingproductmeta) {
                    //update existing meta record
                    $meta_key_name = "download_limit_time";
                    $updatedb_meta = "UPDATE {$product_meta_table_name} SET meta_value='{$download_limit_time}' WHERE prod_id='{$post_editedproduct}' AND meta_key='{$meta_key_name}'";
                } else {
                    //Add new meta record
                    $updatedb_meta = "INSERT INTO {$product_meta_table_name} (prod_id, meta_key, meta_value) VALUES ('{$post_editedproduct}', 'download_limit_time','{$download_limit_time}')";
                }
                $results = $wpdb->query($updatedb_meta);
                $download_limit_count = esc_sql($_POST['download_limit_count']);
                //check if download count is specified
                $editingproductmeta = $wpdb->get_row("SELECT * FROM {$product_meta_table_name} WHERE prod_id = '{$post_editedproduct}' AND meta_key='download_limit_count'", OBJECT);
                if ($editingproductmeta) {
                    //update existing meta record
                    $meta_key_name = "download_limit_count";
                    $updatedb_meta = "UPDATE {$product_meta_table_name} SET meta_value='{$download_limit_count}' WHERE prod_id='{$post_editedproduct}' AND meta_key='{$meta_key_name}'";
                } else {
                    //Add new meta record
                    $updatedb_meta = "INSERT INTO {$product_meta_table_name} (prod_id, meta_key, meta_value) VALUES ('{$post_editedproduct}', 'download_limit_count','{$download_limit_count}')";
                }
                $results = $wpdb->query($updatedb_meta);
                $available_key_codes = esc_sql($_POST['available_key_codes']);
                //check if a serial key meta value for this product exists
                $editingproductmeta = $wpdb->get_row("SELECT * FROM {$product_meta_table_name} WHERE prod_id = '{$post_editedproduct}' AND meta_key='available_key_codes'", OBJECT);
                if ($editingproductmeta) {
                    //update existing meta record
                    $meta_key_name = "available_key_codes";
                    $updatedb_meta = "UPDATE {$product_meta_table_name} SET meta_value='{$available_key_codes}' WHERE prod_id='{$post_editedproduct}' AND meta_key='{$meta_key_name}'";
                } else {
                    //Add new meta record
                    $updatedb_meta = "INSERT INTO {$product_meta_table_name} (prod_id, meta_key, meta_value) VALUES ('{$post_editedproduct}', 'available_key_codes','{$available_key_codes}')";
                }
                $results = $wpdb->query($updatedb_meta);
                //Get the handle to the updated product
                $_GET['editproduct'] = $post_editedproduct;
                $editingproduct = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$post_editedproduct}'", OBJECT);
                echo '<div id="message" class="updated fade"><p>' . __('Product', 'wp_eStore') . ' &quot;' . $post_productname . '&quot; ' . __('updated.', 'wp_eStore') . '</p></div>';
                do_action('eStore_product_updated', $_POST, $_GET['editproduct']);
            }
        }
    }
    // Copy Product Details
    if (isset($_POST['copy_product'])) {
        $post_orig_product_id = esc_sql($_POST['orig_product_id']);
        $editingproduct = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$post_orig_product_id}'", OBJECT);
        echo '<div id="message" class="updated fade"><p>' . __('Details from Product ID', 'wp_eStore') . ' &quot;' . $post_orig_product_id . '&quot; ' . __('has been copied. Make your changes and save the new product.', 'wp_eStore') . '</p></div>';
    }
    //Delete Product
    if (isset($_POST['deleteproduct']) && isset($_POST['prod_id'])) {
        $theproduct = esc_sql($_POST['prod_id']);
        $updatedb = "DELETE FROM {$products_table_name} WHERE id='{$theproduct}'";
        $results = $wpdb->query($updatedb);
        $updatedb = "DELETE FROM {$cat_prod_rel_table_name} WHERE prod_id='{$theproduct}'";
        $results = $wpdb->query($updatedb);
        $del_meta_db_val = "DELETE FROM {$product_meta_table_name} WHERE prod_id='{$theproduct}' AND meta_key='download_limit_time'";
        $results = $wpdb->query($del_meta_db_val);
        $del_meta_db_val = "DELETE FROM {$product_meta_table_name} WHERE prod_id='{$theproduct}' AND meta_key='download_limit_count'";
        $results = $wpdb->query($del_meta_db_val);
        $del_meta_db_val = "DELETE FROM {$product_meta_table_name} WHERE prod_id='{$theproduct}' AND meta_key='available_key_codes'";
        $results = $wpdb->query($del_meta_db_val);
        echo '<div id="message" class="updated fade"><p>' . __('Product deleted.', 'wp_eStore') . '</p></div>';
        do_action('eStore_product_deleted', $theproduct);
    }
    eStore_admin_css();
    echo eStore_admin_js_scripts();
    ?>
<div class="eStore_grey_box">
You can add a new product or edit an existing product from this interface. When creating a new product you can choose to copy the details from an existing product too (see the option below). This option is helpful when creating multiple products with similar details.
</div>

	<div class="postbox">
	<h3><label for="title">Product Details (Not sure how to add a product? <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=593" target="_blank">Watch the video tutorial</a>)</label></h3>
	<div class="inside">
<form method="post" action="admin.php?page=wp_eStore_addedit">
<table class="form-table">

<?php 
    $current_prod_id = "";
    if (isset($_GET['editproduct']) && $_GET['editproduct'] != '') {
        $current_prod_id = $_GET['editproduct'];
        echo '<input name="editedproduct" type="hidden" value="' . $_GET['editproduct'] . '" />';
        echo '<tr valign="top"><th scope="row">Product ID </th>';
        echo '<td><strong>' . $_GET['editproduct'] . '</strong> (This value is for internal use and cannot be changed)</td>';
        echo '</tr>';
    } else {
        if (isset($editingproduct)) {
            //Copying an existing product
            $current_prod_id = $editingproduct->id;
        } else {
            //New record (initialize with empty data)
            $editingproduct = eStore_get_empty_product_object();
        }
    }
    ?>

<tr valign="top">
<th scope="row">Product Name</th>
<td><input name="productname" type="text" id="productname" value="<?php 
    echo htmlspecialchars($editingproduct->name);
    ?>
" size="40" />
<br /><p class="description">Name of the Product</p></td>
</tr>

<tr valign="top">
<th scope="row">Product Price</th>
<td><input name="productprice" type="text" id="productprice" value="<?php 
    echo $editingproduct->price;
    ?>
" size="20" />
<br/><p class="description">Enter Price to two decimal places. Examples: 10.00 or 6.70 or 1999.95 etc (<strong><i>Do not put currency symbol in the price</i></strong>). See the Subscription payment section below if you are configuring a subscribe button</p></td>
</tr>
</table>

<div class=eStore_blue_box>
<i><strong>Optional Product Details</strong></i> (If any of the following options is not needed for your product you can leave the field empty)
</div>

<div class="msg_head">Additional Product Details (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">Product Description</th>
<td><textarea name="productdesc" cols="83" rows="3"><?php 
    echo $editingproduct->description;
    ?>
</textarea>
<br/><p class="description">This description is used when displaying products using the fancy display option.</p></td>
</tr>

<tr valign="top">
<th scope="row">Thumbnail Image URL</th>
<td><input name="thumbnail_url" type="text" id="thumbnail_url" value="<?php 
    if ($editingproduct->thumbnail_url != '') {
        echo $editingproduct->thumbnail_url;
    } else {
        echo '';
    }
    ?>
" size="100" />
<input type="button" id="thumbnail_url_button" name="thumbnail_url_button" class="button rbutton" value="Upload File" />
<?php 
    wp_eStore_show_file_upload_more_info();
    ?>
<p class="description">This thumbnail image is used when displaying products using the fancy display option.</p></td>
</tr>

<tr valign="top">
<th scope="row">Thumbnail Target URL</th>
<td><input name="target_thumb_url" type="text" id="target_thumb_url" value="<?php 
    if ($editingproduct->target_thumb_url != '') {
        echo $editingproduct->target_thumb_url;
    } else {
        echo '';
    }
    ?>
" size="100" />
<br/><p class="description">If you want to link the thumbnail image to a URL (clicking on this thumbnail will take the visitor to this URL) then specify the target URL in the above field, otherwise leave empty.</p></td>
</tr>

<tr valign="top">
<th scope="row">Old Price</th>
<td><input name="old_price" type="text" id="old_price" value="<?php 
    echo $editingproduct->old_price;
    ?>
" size="10" />
<br/><p class="description">The original price (for display purpose only). This price will be slashed out in some of the fancy displays (not available in all the fancy display options)</p></td>
</tr>

<tr valign="top">
<th scope="row">Additional Product Images</th>
<td><textarea name="additional_images" cols="83" rows="2"><?php 
    echo $editingproduct->additional_images;
    ?>
</textarea>
<br/><p class="description">Enter the image URLs separated by comma. When you display your product using a fancy display with lightbox option, your customers will be able to view these images in the lightbox by clicking the next or previous buttons.</p></td>
</tr>

<tr valign="top">
<th scope="row">Product Page URL</th>
<td><input name="product_url" type="text" id="product_url" value="<?php 
    if ($editingproduct->product_url != '') {
        echo $editingproduct->product_url;
    } else {
        echo '';
    }
    ?>
" size="100" />
<br/><p class="description">If you have a specific page for detailed description of this product then specify the URL here otherwise leave empty. The product name will be linked to this page when using the fancy display option.</p></td>
</tr>

<tr valign="top">
<th scope="row">Product Category</th>
<td>
<?php 
    $wp_eStore_cat_db = $wpdb->get_results("SELECT * FROM {$cat_table_name} ORDER BY cat_name ASC", OBJECT);
    if ($wp_eStore_cat_db) {
        $existing_categories = array();
        if ($_GET['editproduct'] != '') {
            $theid = $_GET['editproduct'];
            $editingproduct_cat_db = $wpdb->get_results("SELECT * FROM {$cat_prod_rel_table_name} WHERE prod_id = '{$theid}'", OBJECT);
            if ($editingproduct_cat_db) {
                foreach ($editingproduct_cat_db as $existing_product_cat) {
                    array_push($existing_categories, $existing_product_cat->cat_id);
                }
            }
        } else {
            if (isset($_POST['copy_product'])) {
                $theid = $_POST['orig_product_id'];
                $editingproduct_cat_db = $wpdb->get_results("SELECT * FROM {$cat_prod_rel_table_name} WHERE prod_id = '{$theid}'", OBJECT);
                if ($editingproduct_cat_db) {
                    foreach ($editingproduct_cat_db as $existing_product_cat) {
                        array_push($existing_categories, $existing_product_cat->cat_id);
                    }
                }
            }
        }
        foreach ($wp_eStore_cat_db as $cat_item) {
            $checked = "";
            if (in_array($cat_item->cat_id, $existing_categories)) {
                $checked = "checked='checked'";
            }
            echo "<input type='checkbox' name='category[]' value='" . $cat_item->cat_id . "' " . $checked . "/> " . $cat_item->cat_name . "<br />";
        }
    } else {
        echo 'No Categories Found! <a href="admin.php?page=wp_eStore_categories"><strong>Add a Category</strong></a>';
    }
    ?>
</td>
</tr>
	
<tr valign="top">
<th scope="row">Button Image URL</th>
<td><input name="buttonimageurl" type="text" id="buttonimageurl" value="<?php 
    if ($editingproduct->button_image_url != '') {
        echo $editingproduct->button_image_url;
    } else {
        echo '';
    }
    ?>
" size="100" />
<input type="button" id="buttonimageurl_button" name="buttonimageurl_button" class="button rbutton" value="Upload File" />
<?php 
    wp_eStore_show_file_upload_more_info();
    ?>
<p class="description">This is useful when you want to customize the look of your payment button using a custom button image for this product.</p></td>
</tr>

<tr valign="top">
<th scope="row">Button Redirect Target URL</th>
<td><input name="target_button_url" type="text" id="target_button_url" value="<?php 
    if ($editingproduct->target_button_url != '') {
        echo $editingproduct->target_button_url;
    } else {
        echo '';
    }
    ?>
" size="100" />
<br/><p class="description">Only use this if you want the Add to Cart button for this product to go to the specified URL above (example: a landing page, sales page) instead of adding the product to the shopping cart. Useful when you are selling/promoting product of others.</p></td>
</tr>

<tr valign="top">
<th scope="row">Display Quantity Field</th>
<td><input type="checkbox" name="show_qty" <?php 
    if ($editingproduct->show_qty == '1') {
        echo 'checked="checked"';
    }
    ?>
 />
<br /><p class="description">When checked, it will display a text box next to the Add to Cart button so the customers can enter a quantity amount for the item.</p></td>
</tr>

<tr valign="top">
<th scope="row">Allow Customers to Specify a Price</th>
<td><input type="checkbox" name="custom_price_option" <?php 
    if ($editingproduct->custom_price_option == '1') {
        echo 'checked="checked"';
    }
    ?>
 />
<br /><p class="description">When checked, it will display a text box next to the Add to Cart button so the customers can specify a price amount for this item. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=994" target="_blank">Read More Here</a></p></td>
</tr>

<tr valign="top">
<th scope="row">Collect Customer Input</th>
<td><input type="checkbox" name="custom_input" <?php 
    if ($editingproduct->custom_input == '1') {
        echo 'checked="checked"';
    }
    ?>
 />
&nbsp;&nbsp;Field Label: <input name="custom_input_label" type="text" id="custom_input_label" value="<?php 
    echo $editingproduct->custom_input_label;
    ?>
" size="40" />
<br /><p class="description">When checked, it will display a text box next to the Add to Cart button where the customer can enter special instruction for that product (eg. a Name if selling Engraving).</p></td>
</tr>

<tr valign="top">
<th scope="row">Product Specific Commission</th>
<td>Primary Commission: <input name="productcommission" type="text" id="productcommission" value="<?php 
    if ($editingproduct->commission != '') {
        echo $editingproduct->commission;
    } else {
        echo '';
    }
    ?>
" size="3" />
&nbsp;&nbsp;2nd Tier Commission: <input name="tier2_commission" type="text" id="tier2_commission" value="<?php 
    if ($editingproduct->tier2_commission != '') {
        echo $editingproduct->tier2_commission;
    } else {
        echo '';
    }
    ?>
" size="3" /> (optional)
<br/><p class="description">Use this option when you want to offer a special affiliate commision rate for this product when using with the <a href="http://www.tipsandtricks-hq.com/?p=1474" target="_blank">WP Affiliate Platform</a> plugin. Only specify the amount (do not include the % or $ sign as it is already specified in the settings menu of the affiliate plugin).</p></td>
</tr>

<tr valign="top">
<th scope="row">Reference Text</th>
<td><input name="ref_text" type="text" id="ref_text" value="<?php 
    echo $editingproduct->ref_text;
    ?>
" size="20" />
<?php 
    if (defined('WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE')) {
        //eMember is installed
        $eMember_levels = array();
        $eMember_levels = dbAccess::findAll(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE);
        $level_details_output = "";
        if ($eMember_levels != null) {
            $level_details_output .= '<table>';
            $level_details_output .= '<tr><th>Membership Level Name</th><th>Level ID</th></tr>';
            foreach ($eMember_levels as $level) {
                if ($level->id == 1) {
                    continue;
                }
                $level_details_output .= '<tr><td>' . $level->alias . '</td><td>' . $level->id . '</td></tr>';
            }
            $level_details_output .= '</table>';
        } else {
            if (empty($eMember_levels)) {
                $level_details_output .= '<p>No membership levels found! Go to membership level menu and create a level.</p>';
            }
        }
        echo '<span class="eStore_more_info_anchor"> [+] See your membership level IDs</span>';
        echo '<div class="eStore_more_info_body" style="color:#666666;">';
        echo $level_details_output;
        echo '</div>';
    }
    ?>
<p class="description">Reference Text field can be useful when integrating with a membership plugin. If you are configuring a payment button for the WP eMember plugin then this is where you specify the membership level ID. <a href="http://www.tipsandtricks-hq.com/wordpress-membership/?p=60" target="_blank">Read More Here</a></p></td>
</tr>
</table>
</div>

<div class="msg_head">Digital Content Details (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">Digital Product URL</th>
<td>
<input id="producturl_button" class="button rbutton" type="button" value="Upload File" />
<span class="eStore_more_info_anchor"> [+] more info<br /></span>
<div class="eStore_more_info_body" style="color:#666666;">
<p>Uploading a file and using it as the digital content of this product is a 3 step process:</p>
<ol>
<li><i>Click the above upload button</i></li> 
<li><i>Choose the file to upload which will upload that file to your media library</i></li> 
<li><i>Finally, click the <strong>Insert into Post</strong> button, this will populate the uploaded file's URL in the following field.</i></li> 
</ol>
</div>
<br />
<input name="producturl" type="text" id="producturl" value="<?php 
    if ($editingproduct->product_download_url != '') {
        echo $editingproduct->product_download_url;
    } else {
        echo '';
    }
    ?>
" size="120" />
<p class="description">The URL of the digital product that you are selling (this content will be given to your customer via an encrypted link), example: <code>http://www.example.com/downloads/ebook/superman.zip</code></p> 
<div class="eStore_more_info_anchor">&nbsp;[+] more info</div>
<div class="eStore_more_info_body">
<li style="margin-left:15px;margin-top:10px;color:#666666;"><i>If you haven't uploaded the file to your server yet then you can do so using the <a href="media-new.php" target="_blank">WordPress's Media Uploader</a> or an FTP software. Simply copy the "File URL" after you upload the file and paste it in the above field.</i></li> 
<li style="margin-left:15px;color:#666666;"><i>If you are making a bundled product then enter the product IDs separated by comma (example: 3,8,18). If the product has multiple files then enter the file URLs separated by comma.</i></li> 
<li style="margin-left:15px;color:#666666;"><i>If you want to integrate with Amazon S3 then read <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=1101" target="_blank">this instruction</a> first.</i></li>
<li style="margin-left:15px;color:#666666;"><i>Please note that the file can be kept on any accessible location on the web (<a href="http://www.tipsandtricks-hq.com/forum/topic/download-directory-protection" target="_blank">more explanation here</a>). The buyer will receive an encrypted link which will let them download this product.</i></li>
</div>
</td></tr>

<tr valign="top">
<th scope="row">Downloadable</th>
<td><input type="checkbox" name="productdownloadable" <?php 
    if ($editingproduct->downloadable != 'no') {
        echo 'checked="checked"';
    }
    ?>
 /> 
<p class="description">If checked the digital content will be delivered via an anonymous encrypted download process (the customer won't know where it is coming from). If unchecked the buyers will be redirected to the above URL when they click on the encrypted link.</p></td>
</tr>
<?php 
    $download_limit_time = "";
    if (isset($_GET['editproduct'])) {
        $theid = $_GET['editproduct'];
        $editingproductmeta = $wpdb->get_row("SELECT * FROM {$product_meta_table_name} WHERE prod_id = '{$theid}' AND meta_key='download_limit_time'", OBJECT);
        if ($editingproductmeta) {
            $download_limit_time = $editingproductmeta->meta_value;
        }
    }
    $download_limit_count = "";
    if (isset($_GET['editproduct'])) {
        $theid = $_GET['editproduct'];
        $editingproductmeta = $wpdb->get_row("SELECT * FROM {$product_meta_table_name} WHERE prod_id = '{$theid}' AND meta_key='download_limit_count'", OBJECT);
        if ($editingproductmeta) {
            $download_limit_count = $editingproductmeta->meta_value;
        }
    }
    ?>
<tr valign="top">
<th scope="row">Selling Pay Per View Content?</th>
<td><p>If you are selling Pay Per View content (example: a streaming video embedded on a page) then <a href="http://www.tipsandtricks-hq.com/ecommerce/using-wordpress-permalinks-as-digital-products-apr-1217" target="_blank">read our pay per view setup documentation</a> to learn how to set it up.</p>
</td>
</tr>

<tr valign="top">
<th scope="row">Duration of Download Link</th>
<td><input name="download_limit_time" type="text" id="download_limit_time" value="<?php 
    echo $download_limit_time;
    ?>
" size="3" /> &nbsp;Hours
<br/><p class="description">This is the duration of time the encrypted links for this product will remain active. If you do not specify a value in this field, it will default to the values set in the settings menu.</p></td>
</tr>

<tr valign="top">
<th scope="row">Download Limit Count</th>
<td><input name="download_limit_count" type="text" id="itemweight" value="<?php 
    echo $download_limit_count;
    ?>
" size="3" /> &nbsp;Times
<br/><p class="description">Number of times an encrypted download link can be used before the link expires. If you do not specify a value in this field, it will default to the values set in the settings menu.</p></td>
</tr>

</table>
</div>

<div class="msg_head">Variations (Click to Expand)</div>
<div class="msg_body">
&nbsp;&nbsp;<strong>Please make sure you have specified a base price for the product in the "Product Price" field above</strong>
<?php 
    $variation_settings = "";
    $variation_settings = apply_filters('eStore_product_variation_settings_filter', $variation_settings, $current_prod_id);
    if (!empty($variation_settings)) {
        //Show the advanced variation UI from the addon
        echo $variation_settings;
    } else {
        //Show the standard variation UI
        ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Product Variation 1</th>
<td><textarea name="variation1" cols="83" rows="3"><?php 
        echo $editingproduct->variation1;
        ?>
</textarea>
<br/><p class="description">Useful if you want to use variation with your product eg. Small, Medium, Large. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=345" target="_blank">Learn How To</a></p></td>
</tr>
<tr valign="top">
<th scope="row">Product Variation 2</th>
<td><textarea name="variation2" cols="83" rows="3"><?php 
        echo $editingproduct->variation2;
        ?>
</textarea>
<br/><p class="description">Useful when adding additional variation with your product eg. Red, Green. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=345" target="_blank">Learn How To</a></p></td>
</tr>
<tr valign="top">
<th scope="row">Product Variation 3</th>
<td><textarea name="variation4" cols="83" rows="3"><?php 
        echo $editingproduct->variation4;
        ?>
</textarea>
<br/><p class="description">Useful when adding additional variation with your product eg. Short, Full. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=345" target="_blank">Learn How To</a></p></td>
</tr>
<tr valign="top">
<th scope="row">Digital Product Variation</th>
<td><textarea name="variation3" cols="83" rows="3"><?php 
        echo $editingproduct->variation3;
        ?>
</textarea>
<br/><p class="description">Can be used for digital delivery of different files depending on the selection (eg. Personal use, Business use). Please note that you need to enter a value (any URL value will do) in the "Digital Product URL" field to trigger the digital variation. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=345" target="_blank">Learn How To Use Digital Product Variation</a></p></td>
</tr>
</table>
<?php 
    }
    ?>

</div>

<div class="msg_head">Shipping &amp; Tax (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">Item Shipping Cost</th>
<td><input name="shippingcost" type="text" id="shippingcost" value="<?php 
    echo $editingproduct->shipping_cost;
    ?>
" size="3" />
<br/><p class="description">Enter the Shipping Cost for this item (eg. 5.00). Leave blank if shipping cost does not apply.</p></td>
</tr>
<tr valign="top">
<th scope="row">Item Weight</th>
<td><input name="itemweight" type="text" id="itemweight" value="<?php 
    echo $editingproduct->weight;
    ?>
" size="3" />
<br/><p class="description">Enter the Weight of the item in lbs. This is only used if you are using <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=50" target="_blank">PayPal profile based shipping</a>.</p></td>
</tr>
<tr valign="top">
<th scope="row">Item Specific Tax</th>
<td><input name="tax" type="text" id="tax" value="<?php 
    echo $editingproduct->tax;
    ?>
" size="3" />%
<br/><p class="description">If you want to charge a different tax for this item than the one specified in the settings menu then enter the tax rate for this item here.</p></td>
</tr>
</table>
</div>

<div class="msg_head">Inventory Control (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">Available Copies</th>
<td><input name="availablecopies" type="text" id="availablecopies" value="<?php 
    echo $editingproduct->available_copies;
    ?>
" size="10" />
<br/><p class="description">Enter the numer of available copies (example: 50). Leave blank if unlimited. This is useful when you only want to sell only 50 copies of a product for example</p></td>
</tr>

<tr valign="top">
<th scope="row">Sales Count</th>
<td><input name="salescount" type="text" id="salescount" value="<?php 
    echo $editingproduct->sales_count;
    ?>
" size="10" />
<br/><p class="description">This is the total sales count. This number gets incremented by the quantity sold when you make a sale</p></td>
</tr>

<tr valign="top">
<th scope="row">Quantity Limit Per Customer</th>
<td><input name="per_customer_qty_limit" type="text" id="per_customer_qty_limit" value="<?php 
    echo $editingproduct->per_customer_qty_limit;
    ?>
" size="10" />
<br/><p class="description">If you want to limit the number of quantity a customer can purchase (example: 1) then enter that number here, otherwise leave this field empty.</p></td>
</tr>
</table>
</div>

<div class="msg_head">Serial Number/License Key Settings (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">Your Codes</th>
<td>
<strong>Read the <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=1618" target="_blank">serial key feature documentation</a> to learn how to use this feature</strong>
<br /><br />
<?php 
    if (isset($_GET['editproduct'])) {
        $theid = $_GET['editproduct'];
        $editingproductmeta = $wpdb->get_row("SELECT * FROM {$product_meta_table_name} WHERE prod_id = '{$theid}' AND meta_key='available_key_codes'", OBJECT);
        $available_key_codes = $editingproductmeta->meta_value;
    } else {
        $available_key_codes = "";
    }
    ?>
<textarea name="available_key_codes" cols="100" rows="7"><?php 
    echo $available_key_codes;
    ?>
</textarea>
<br/><p class="description">Enter your Serial keys/License Keys/Ticket Numbers/Barcodes etc. separated by comma (,) in the above field. One key/number will be given to the customer after the purchase of this product.</p></td>
</tr>
</table>
</div>

<div class="msg_head">AddOn Settings (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row"></th><td><strong><i>Use the following section only if you are using the <a href="http://www.tipsandtricks-hq.com/wp-pdf-stamper-plugin-2332" target="_blank">WP PDF Stamper Plugin</a></i></strong></td>
</tr>
<tr valign="top">
<th scope="row">Stamp the PDF File</th>
<td><input type="checkbox" name="use_pdf_stamper" <?php 
    if ($editingproduct->use_pdf_stamper == '1') {
        echo 'checked="checked"';
    }
    ?>
 />
<p class="description">If this product is an eBook and you want to stamp this PDF file with customer details upon purchase then check this option.</p></td>
</tr>

<tr valign="top">
<th scope="row"></th><td><strong><i>Use the following section only if you are using the <a href="http://www.tipsandtricks-hq.com/?p=1474" target="_blank">WP Affiliate Platform Plugin</a></i></strong></td>
</tr>
<tr valign="top">
<th scope="row">Author ID for Revenue Sharing</th>
<td><input name="author_id" type="text" id="author_id" value="<?php 
    echo $editingproduct->author_id;
    ?>
" size="10" /><br />
If you want to share revenue with the author of this product then enter the affiliate ID of this author in this field. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=930" target="_blnak">Read More Here</a></td>
</tr>

<tr valign="top">
<th scope="row">Revenue Sharing Commission Level</th>
<td><input name="rev_share_commission" type="text" id="rev_share_commission" value="<?php 
    echo $editingproduct->rev_share_commission;
    ?>
" size="4" /><br />
Example Value: 25. By default the commission level specified in the affiliate/author's profile will be used for revenue sharing amount calculation. However, you can choose to override the commission level for this product by specifying a value in the above field. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=930" target="_blnak">Read More Here</a></td>
</tr>

<?php 
    if (function_exists('wp_lic_manager_install')) {
        ?>
<tr valign="top">
<th scope="row"></th><td><strong><i>Use the following section only if you are using the <a href="http://www.tipsandtricks-hq.com" target="_blank">WP License Manager Plugin</a></i></strong></td>
</tr>
<tr valign="top">
<th scope="row">Create License</th>
<td><input type="checkbox" name="create_license" <?php 
        if ($editingproduct->create_license == '1') {
            echo 'checked="checked"';
        }
        ?>
 />
<p class="description">If this product is a piece of software that has been integrated with the WP License Manage plugin then checking this box will create a license for the customer who purchase this product.</p></td>
</tr>
<?php 
    }
    ?>
</table>
</div>

<div class="msg_head">Autoresponder Settings (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">List Name</th>
<td><input name="aweber_list" type="text" id="aweber_list" value="<?php 
    echo $editingproduct->aweber_list;
    ?>
" size="100" /><br/>
<p class="description">The name of the list where the customers of this product will be signed up to (example: "*****@*****.**" if you are using AWeber or "sample_marketing" if you are using GetResponse or "My Customers" if you are using MailChimp). You can find the list/campaign name inside your autoresponder account. Use this if you want the customer of this product to be signed up to a specific list.</p></td>
</tr>
</table>
</div>

<div class="msg_head">Product Specific Instructions for Buyer (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">Instructions for Buyer</th>
<td><textarea name="item_spec_instruction" cols="83" rows="3"><?php 
    echo $editingproduct->item_spec_instruction;
    ?>
</textarea>
<br/><p class="description">This option is useful when you need to give your customer some specific instruction that applies only to this product (e.g. a secret password for the PDF file). This instruction will be added to the buyer's email body when this product is purchased. Use the {product_specific_instructions} tag in the "Buyers Email Body" field in the settings menu to dynamically place this information in the email body.</p></td>
</tr>
</table>
</div>

<div class="msg_head">Buy Now, Subscription or Donation Type Button Specific Settings (Click to Expand)</div>
<div class="msg_body">
<p style="color:red">
<strong>The options in this section are only used for "Buy Now", "Subscription" or "Donation" type buttons. <a href="http://www.tipsandtricks-hq.com/forum/topic/different-types-of-payment-buttons-and-their-behaviour" target="_blank">Explanation on the different types of payment buttons</a></strong>
</p>
<br />This can be useful when you want to use a different setting than the one specified in the Settings menu for this product. For example you might be using USD for your store but you may want to create a subscription button in Euro for one product. 
<br /><br />
<table class="form-table">
<tr valign="top">
<th scope="row">Return URL</th>
<td><input name="returnurl" type="text" id="returnurl" value="<?php 
    if ($editingproduct->return_url != '') {
        echo $editingproduct->return_url;
    } else {
        echo '';
    }
    ?>
" size="50" />
<br/><p class="description">Can be used to redirect customers to a different URL for this item after a successful payment</p></td>
</tr>
<tr valign="top">
<th scope="row">PayPal Email</th>
<td><input name="paypal_email" type="text" id="paypal_email" value="<?php 
    if ($editingproduct->paypal_email != '') {
        echo $editingproduct->paypal_email;
    } else {
        echo '';
    }
    ?>
" size="50" />
<br/><p class="description">This is useful when you want to allow other blog authors to sell their products on your blog and the product owner gets the money directly into his/her PayPal account</p></td>
</tr>
<tr valign="top">
<th scope="row">Currency Code</th>
<td><input name="currency_code" type="text" id="currency_code" value="<?php 
    if ($editingproduct->currency_code != '') {
        echo $editingproduct->currency_code;
    } else {
        echo '';
    }
    ?>
" size="6" />
<br/><p class="description">This is useful when you want to sell a specific product in a different currency than the one specified in the settings menu. (e.g. EUR, GBP, AUD, USD) </p></td>
</tr>
</table>
</div>

<div class="msg_head">Subscription/Recurring Payment Specific Settings (Click to Expand)</div>
<div class="msg_body">
<p>
<strong>Make sure to read the <a href="http://www.tipsandtricks-hq.com/ecommerce/how-to-add-a-subscription-button-for-recurring-payment-400" target="_blank">subscription product creation documentation</a> (there is a video tutorial too)</strong>
</p>

<div class="postbox">
<h3><label for="title">Trial Period (Leave Empty if you are not offfering a Trial Period)</label></h3>
<div class="inside">
<table class="form-table">
<tr valign="top">
<th scope="row">Trial Billing Amount</th>
<td><input name="a1" type="text" id="a1" value="<?php 
    echo $editingproduct->a1;
    ?>
" size="10" />
<br/><p class="description">Amount to be charged for the Trail period. Enter 0 if you want to offer a free trial period</p></td>
</tr>
<tr valign="top">
<th scope="row">Trial Billing Period</th>
<td><input name="p1" type="text" id="p1" value="<?php 
    echo $editingproduct->p1;
    ?>
" size="5" />
		<select name='t1'>
		<option value='D' <?php 
    if ($editingproduct->t1 == 'D') {
        echo 'selected="selected"';
    }
    ?>
>Day</option>
		<option value='M' <?php 
    if ($editingproduct->t1 == 'M') {
        echo 'selected="selected"';
    }
    ?>
>Month</option>
		<option value='Y' <?php 
    if ($editingproduct->t1 == 'Y') {
        echo 'selected="selected"';
    }
    ?>
>Year</option>
		</select>
<br/><p class="description">Length of the Trial Period</p></td>
</tr>
</table>
</div></div>

	<div class="postbox">
	<h3><label for="title">Recurring Billing</label></h3>
	<div class="inside">
<table class="form-table">
<tr valign="top">
<th scope="row">Recurring Billing Amount</th>
<td><input name="a3" type="text" id="a3" value="<?php 
    echo $editingproduct->a3;
    ?>
" size="10" />
<br/><p class="description">Amount to be charged on every billing cycle. If used with a trial period then this amount will be charged after the trial period is over</p></td>
</tr>

<tr valign="top">
<th scope="row">Recurring Billing Cycle</th>
<td><input name="p3" type="text" id="p3" value="<?php 
    echo $editingproduct->p3;
    ?>
" size="5" />
		<select name='t3'>
		<option value='D' <?php 
    if ($editingproduct->t3 == 'D') {
        echo 'selected="selected"';
    }
    ?>
>Day</option>
		<option value='M' <?php 
    if ($editingproduct->t3 == 'M') {
        echo 'selected="selected"';
    }
    ?>
>Month</option>
		<option value='Y' <?php 
    if ($editingproduct->t3 == 'Y') {
        echo 'selected="selected"';
    }
    ?>
>Year</option>
		</select>
</tr>
<tr valign="top">
<th scope="row">Recurring Billing Count</th>
<td><input name="srt" type="text" id="srt" value="<?php 
    echo $editingproduct->srt;
    ?>
" size="5" />
<br/><p class="description">This is the number of payments which will occur at the regular rate. Leave this field empty (or enter 0) if you want the payment to continue to recur at the regular rate until the subscription is canceled. Enter -1 if you want to configure a once off payment.</p></td>
</tr>
<tr valign="top">
<th scope="row">Reattempt on failure</th>
<td><input type="checkbox" name="sra" <?php 
    if ($editingproduct->sra == '1') {
        echo 'checked="checked"';
    }
    ?>
 />
<p class="description">When checked, the payment will be reattempted two more times if the payment fails. After the third failure, the subscription will be cancelled.</p></td>
</tr>
</table>
</div></div>
</div>

<?php 
    if (!isset($_GET['editproduct'])) {
        $_GET['editproduct'] = "";
    }
    $additional_addon_settings = "";
    $additional_addon_settings = apply_filters('eStore_addon_product_settings_filter', $additional_addon_settings, $_GET['editproduct']);
    echo $additional_addon_settings;
    ?>
<p class="submit"><input type="submit" class="button-primary" name="Submit" value="Save Product" /></p>

</form>

<?php 
    if (isset($_GET['editproduct']) && $_GET['editproduct'] != '') {
        //Show delete product link
        echo "<form method=\"post\" action=\"admin.php?page=wp_eStore_addedit\" onSubmit=\"return confirm('Are you sure you want to delete this entry?');\">";
        echo "<input type=\"hidden\" name=\"prod_id\" value=" . $_GET['editproduct'] . " />";
        echo '<input type="submit" style="border: none; background-color:transparent; padding:0; cursor:pointer; color:red;text-decoration:underline" name="deleteproduct" value="Delete Product">';
        echo "</form>";
    }
    ?>

</div></div>

<div class="postbox">
<h3><label for="title">Copy Product Details from an Existing Product</label></h3>
<div class="inside">

To copy the details from an existing product simply enter the ID of the product whose details you wish to copy and hit the "Copy Product Details" button
<br /><br />
<form method="post" action="admin.php?page=wp_eStore_addedit">
Product ID:
<input name="orig_product_id" type="text" id="orig_product_id" value="" size="5" />
<input type="submit" name="copy_product" class="button" value="Copy Product Details" />
</form>
</div>
</div>


<?php 
    echo 'Want to bulk upload product details from CSV file? <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=775" target="_blank">Click Here to Learn More</a><br /><br />';
    echo '<div class="button-group">';
    echo '<a href="admin.php?page=wp-cart-for-digital-products/wp_eStore1.php" class="button">Manage Products</a>&nbsp;&nbsp;';
    echo '<a href="admin.php?page=wp_eStore_addedit" class="button">Create New Product</a>';
    echo '</div>';
    if (!empty($current_prod_id)) {
        $previous_prod = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id < '{$current_prod_id}' ORDER BY id DESC", OBJECT);
        if ($previous_prod) {
            echo '<a href="admin.php?page=wp_eStore_addedit&editproduct=' . $previous_prod->id . '" class="button rbutton">&laquo; Previous Product</a>&nbsp;&nbsp;';
        }
        $next_prod = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id > '{$current_prod_id}' ORDER BY id ASC", OBJECT);
        if ($next_prod) {
            echo '<a href="admin.php?page=wp_eStore_addedit&editproduct=' . $next_prod->id . '" class="button rbutton">Next Product &raquo;</a><br /><br />';
        }
    }
    echo '</div></div>';
    echo '</div>';
    //End of wrap
}
function emember_admin_functions_users_menu()
{
    global $wpdb;
    //$emember_config = Emember_Config::getInstance();
    if (isset($_POST['emember_bulk_user_subs_start_date_change_process'])) {
        $errorMsg = "";
        $level_id = $_POST["emember_bulk_user_subs_start_date_change_level"];
        $new_date = $_POST['emember_bulk_user_subs_start_date_change_date'];
        if ($level_id == 'please_select') {
            $errorMsg = 'Error! Please select a membership level first.';
        }
        if (empty($errorMsg)) {
            //No validation errors so go ahead
            $query = "SELECT * FROM " . WP_EMEMBER_MEMBERS_TABLE_NAME . " WHERE membership_level='{$level_id}'";
            $member_records = $wpdb->get_results($query);
            if ($member_records) {
                foreach ($member_records as $row) {
                    $member_id = $row->member_id;
                    $fields = array();
                    $fields['subscription_starts'] = $new_date;
                    $ret = dbAccess::update(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id = ' . $member_id, $fields);
                    if ($ret === false) {
                        $errorMsg = 'Subscription start date change failed.';
                    }
                }
            }
        }
        $message = "";
        if (!empty($errorMsg)) {
            $message = $errorMsg;
        } else {
            $message = 'Subscription start date change operation successfully completed.';
        }
        echo '<div id="message" class="updated fade"><p><strong>';
        echo $message;
        echo '</strong></p></div>';
    }
    if (isset($_POST['emember_bulk_user_change_level_process'])) {
        $errorMsg = "";
        $from_level_id = $_POST["emember_bulk_user_change_level_from"];
        $to_level_id = $_POST['emember_bulk_user_change_level_to'];
        if ($from_level_id == 'please_select' || $to_level_id == 'please_select') {
            $errorMsg = 'Error! Please select a membership level first.';
        }
        if (empty($errorMsg)) {
            //No validation errors so go ahead
            $query = "SELECT * FROM " . WP_EMEMBER_MEMBERS_TABLE_NAME . " WHERE membership_level='{$from_level_id}'";
            $member_records = $wpdb->get_results($query);
            if ($member_records) {
                foreach ($member_records as $row) {
                    $member_id = $row->member_id;
                    emember_update_membership_level($member_id, $to_level_id);
                }
            }
        }
        $message = "";
        if (!empty($errorMsg)) {
            $message = $errorMsg;
        } else {
            $message = 'Membership level change operation successfully completed.';
        }
        echo '<div id="message" class="updated fade"><p><strong>';
        echo $message;
        echo '</strong></p></div>';
    }
    ?>

    <div class="postbox">
        <h3><label for="title">Bulk Update Subscription Start Date of Members</label></h3>
        <div class="inside">

            <p>The subscription start date of a member is set to the day he/she registers. You can manually set a specific subscription start date of all members who belong to a particular level using the following option.</p>
            <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">

                <table width="100%" border="0" cellspacing="0" cellpadding="6">
                    <tr valign="top">
                        <td width="25%" align="left">
                            <strong>Membership Level: </strong>
                        </td><td align="left">
                            <select name="emember_bulk_user_subs_start_date_change_level">
                                <option value="please_select">Select Level</option>
                                <?php 
    $all_levels = dbAccess::findAll(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, ' id != 1 ', ' id DESC ');
    foreach ($all_levels as $level) {
        ?>
                                    <option value="<?php 
        echo $level->id;
        ?>
"><?php 
        echo $level->alias;
        ?>
</option>
                                <?php 
    }
    ?>
                            </select>
                            <br /><i>Select the Membership level (the subscription start date of all members who are in this level will be updated).</i><br /><br />
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            <strong>Subscription Start Date: </strong>
                        </td><td align="left">
                            <input name="emember_bulk_user_subs_start_date_change_date" id="emember_bulk_user_subs_start_date_change_date" type="text" size="20" value="<?php 
    echo date("Y-m-d");
    ?>
" />
                            <br /><i>Specify the subscription start date.</i><br /><br />
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            <input type="submit" class="button" name="emember_bulk_user_subs_start_date_change_process" value="Bulk Change Subscription Start Date &raquo;" />
                        </td><td align="left"></td>
                    </tr>

                </table>
            </form>
        </div></div>

    <div class="postbox">
        <h3><label for="title">Bulk Update Membership Level of Members</label></h3>
        <div class="inside">

            <p>You can manually change the membership level of any member by editing the record from the members menu. You can use the following option to bulk update the membership level of users who belong to the level you select below.</p>
            <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">

                <table width="100%" border="0" cellspacing="0" cellpadding="6">
                    <tr valign="top">
                        <td width="25%" align="left">
                            <strong>Membership Level: </strong>
                        </td><td align="left">
                            <select name="emember_bulk_user_change_level_from">
                                <option value="please_select">Select Current Level</option>
                                <?php 
    $all_levels = dbAccess::findAll(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, ' id != 1 ', ' id DESC ');
    foreach ($all_levels as $level) {
        ?>
                                    <option value="<?php 
        echo $level->id;
        ?>
"><?php 
        echo $level->alias;
        ?>
</option>
                                <?php 
    }
    ?>
                            </select>
                            <br /><i>Select the current membership level (the membership level of all members who are in this level will be updated).</i><br /><br />
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            <strong>Level to Change to: </strong>
                        </td><td align="left">
                            <select name="emember_bulk_user_change_level_to">
                                <option value="please_select">Select Target Level</option>
                                <?php 
    $all_levels = dbAccess::findAll(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, ' id != 1 ', ' id DESC ');
    foreach ($all_levels as $level) {
        ?>
                                    <option value="<?php 
        echo $level->id;
        ?>
"><?php 
        echo $level->alias;
        ?>
</option>
                                <?php 
    }
    ?>
                            </select>

                            <br /><i>Select the new membership level</i><br /><br />
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            <input type="submit" class="button" name="emember_bulk_user_change_level_process" value="Bulk Change Membership Level &raquo;" />
                        </td><td align="left"></td>
                    </tr>

                </table>
            </form>
        </div></div>

    <script type="text/javascript">
        jQuery(document).ready(function($) {
            $("#emember_bulk_user_subs_start_date_change_date").dateinput({'format': 'yyyy-mm-dd', selectors: true, yearRange: [-100, 100]});
        });
    </script>

    <?php 
}
예제 #19
0
function eMember_level_specific_autoresponder_signup($membership_level_id, $firstname, $lastname, $emailaddress)
{
    eMember_log_debug('Performing membership level specific autoresponder signup if specified.', true);
    $membership_level_resultset = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, " id='" . $membership_level_id . "'");
    $list_name = trim($membership_level_resultset->campaign_name);
    // Autoresponder Sign up
    if (!empty($membership_level_resultset->campaign_name)) {
        $emember_config = Emember_Config::getInstance();
        eMember_log_debug('List name specified for this membership level is: ' . $list_name, true);
        if ($emember_config->getValue('eMember_enable_aweber_int') == 1) {
            $from_address = $emember_config->getValue('senders_email_address');
            $senders_email = eMember_get_string_between($from_address, "<", ">");
            if (empty($senders_email)) {
                $senders_email = $from_address;
            }
            $cust_name = $firstname . ' ' . $lastname;
            if ($emember_config->getValue('eMember_use_new_aweber_integration') == '1') {
                eMember_aweber_new_signup_user($list_name, $firstname, $lastname, $emailaddress);
            } else {
                eMember_log_debug('AWeber list to signup to:' . $list_name, true);
                eMember_send_aweber_mail($list_name, $senders_email, $cust_name, $emailaddress);
                eMember_log_debug('AWeber signup from email address used:' . $senders_email, true);
                eMember_log_debug('AWeber signup operation performed for:' . $emailaddress, true);
            }
        }
        if ($emember_config->getValue('eMember_use_mailchimp') == 1) {
            $api = eMember_get_chimp_api();
            eMember_log_debug('Mailchimp email address to signup:' . $emailaddress, true);
            eMember_log_debug('Mailchimp list to signup to:' . $list_name, true);
            $retval = eMember_mailchimp_subscribe($api, $list_name, $firstname, $lastname, $emailaddress);
            eMember_log_debug('Mailchimp signup operation performed. returned value:' . $retval, true);
        }
        if ($emember_config->getValue('eMember_use_getresponse') == 1) {
            eMember_log_debug('GetResponse email address to signup:' . $emailaddress, true);
            eMember_log_debug('GetResponse campaign to signup to:' . $list_name, true);
            $retval = eMember_getResponse_subscribe($list_name, $firstname, $lastname, $emailaddress);
            eMember_log_debug('GetResponse signup operation performed. returned value:' . $retval, true);
        }
        if ($emember_config->getValue('eMember_use_generic_autoresponder_integration') == '1') {
            eMember_log_debug('Generic autoresponder integration is being used.', true);
            $list_email_address = $list_name;
            $result = eMember_generic_autoresponder_signup($firstname, $lastname, $emailaddress, $list_email_address);
            eMember_log_debug('Generic autoresponder signup result: ' . $result, true);
        }
    }
    // API call for plugins extending the level specific autoresponder signup
    $signup_data = array('firstname' => $firstname, 'lastname' => $lastname, 'email' => $emailaddress, 'list_name' => $list_name);
    do_action('emember_level_specific_autoresponder_signup', $signup_data);
    eMember_log_debug('End of membership level specific autoresponder signup.', true);
}
예제 #20
0
<?php

require "connection.php";
require "dbAccess.php";
$eventid = htmlentities($_POST["eventid"]);
// return array for for JSON responses
$resultArray = array();
// create db connection
$access = new dbAccess();
$access->openConnection();
// find database for event name in events table to delete
$result = $access->deleteEvent($eventid);
// report success if query succeeded
if (!empty($result)) {
    $returnValue["status"] = "Success";
    $returnValue["message"] = "Event deleted";
    echo json_encode($returnValue);
} else {
    $returnValue["status"] = "error";
    $returnValue["message"] = "Event not deleted";
    echo json_encode($returnValue);
}
$access->closeConnection();
예제 #21
0
<?php

require "connection.php";
require "dbAccess.php";
$userid = htmlentities($_POST["userid"]);
// return array for for JSON responses
$resultArray = array();
// create db connection
$access = new dbAccess();
$access->openConnection();
// query database for all events in events table
$result = $access->getInvites($userid);
// if query returned successfully
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
    $rowArray = $row;
    array_push($resultArray, $rowArray);
}
if (!empty($resultArray)) {
    echo json_encode($resultArray);
}
$access->closeConnection();
예제 #22
0
<?php

require "connection.php";
require "dbAccess.php";
// this is internal data, no need to check for XSS
$jsonids = $_POST["ids"];
$ids = json_decode($jsonids, true);
// create db connection
$access = new dbAccess();
$access->openConnection();
// begin sql statement
$sql = "insert into notify (event_id, user_id, inviter_id) values ";
// iterate through $ids array for a single batch sql query
$iter = new ArrayIterator($ids);
// a new caching iterator gives us access to hasNext()
$citer = new CachingIterator($iter);
// loop over the array
foreach ($citer as $value) {
    // add to the query
    $sql .= "('" . $ids[$citer->key()]["event_id"] . "','" . $ids[$citer->key()]["user_id"] . "','" . $ids[$citer->key()]["inviter_id"] . "')";
    // if there is another array member, add a comma
    if ($citer->hasNext()) {
        $sql .= ",";
    }
}
// run query
$result = $access->conn->query($sql);
// report success if query succeeded
if (!empty($result)) {
    $returnValue["status"] = "Success";
    $returnValue["message"] = "Users invited";
예제 #23
0
<?php

require_once 'dblogin.php';
require_once 'dbaccess.php';
$username = $_GET['username'];
$db = new dbAccess($host, $user, $password, $database);
$where = "username = '******'";
$result = $db->selectDB('users', $where, '', '');
$result->data_seek(0);
$row = $result->fetch_array(MYSQLI_ASSOC);
if ($row['username'] == '') {
    if (strlen($username) > 4) {
        echo "<span class=\"validUser\">Username : Valid <span class=\"glyphicon glyphicon-ok\" aria-hidden=\"true\"></span></span>";
    } else {
        echo "Username : "******"<span class=\"invalidUser\">Username : Invalid <span class=\"glyphicon glyphicon-remove\" aria-hidden=\"true\"></span></span>";
}
예제 #24
0
function wp_eMember_admin_functions_general_menu()
{
    $emember_config = Emember_Config::getInstance();
    if (isset($_POST['generate_registration_link'])) {
        $errorMsg = "";
        $eMember_member_id = (string) $_POST["eMember_member_id"];
        $member_record = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=\'' . $eMember_member_id . '\'');
        if ($member_record) {
            $md5_code = md5($member_record->reg_code);
            $separator = '?';
            $url = get_option('eMember_registration_page');
            if (empty($url)) {
                $errorMsg .= "Error! You need to specify the registration URL in the pages/forms settings menu of this plugin.";
            } else {
                if (strpos($url, '?') !== false) {
                    $separator = '&';
                }
                $reg_url = $url . $separator . 'member_id=' . $eMember_member_id . '&code=' . $md5_code;
            }
        } else {
            $errorMsg .= "Error! Could not find the member ID in the database. Please double check the member ID value.";
        }
        $message = "";
        if (!empty($errorMsg)) {
            $message = $errorMsg;
        } else {
            $message = 'Registration Link Generated! Your customer can complete his/her membership registration by going to the generated link.';
        }
        echo '<div id="message" class="updated fade"><p><strong>';
        echo $message;
        echo '</strong></p></div>';
    }
    if (isset($_POST['generate_and_send_registration_link'])) {
        $errorMsg = "";
        $eMember_member_id = (string) $_POST["eMember_member_id"];
        $member_record = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=\'' . $eMember_member_id . '\'');
        if ($member_record) {
            $md5_code = md5($member_record->reg_code);
            $separator = '?';
            $url = get_option('eMember_registration_page');
            if (empty($url)) {
                $errorMsg .= "<br />You need to specify the registration URL in the pages settings menu of this plugin.";
            } else {
                if (strpos($url, '?') !== false) {
                    $separator = '&';
                }
                $reg_url = $url . $separator . 'member_id=' . $eMember_member_id . '&code=' . $md5_code;
            }
            $email = $member_record->email;
            $subject = get_option('eMember_email_subject');
            $body = get_option('eMember_email_body');
            $from_address = get_option('senders_email_address');
            $tags = array("{first_name}", "{last_name}", "{reg_link}");
            $vals = array($member_record->first_name, $member_record->last_name, $reg_url);
            $email_body = str_replace($tags, $vals, $body);
            $headers = 'From: ' . $from_address . "\r\n";
            wp_mail($email, $subject, $email_body, $headers);
        } else {
            $errorMsg .= "<br />Could not find the member ID in the database";
        }
        $message = "";
        if (!empty($errorMsg)) {
            $message = $errorMsg;
        } else {
            $message = "Member registration completion email successfully sent to:" . $email;
        }
        echo '<div id="message" class="updated fade"><p><strong>';
        echo $message;
        echo '</strong></p></div>';
    }
    if (isset($_POST['generate_and_send_registration_link_bulk'])) {
        $errorMsg = "";
        global $wpdb;
        $query = "SELECT member_id,reg_code,first_name,last_name FROM " . WP_EMEMBER_MEMBERS_TABLE_NAME . " WHERE user_name = ''";
        $member_records = $wpdb->get_results($query);
        if ($member_records) {
            foreach ($member_records as $member_record) {
                $md5_code = md5($member_record->reg_code);
                $separator = '?';
                $url = get_option('eMember_registration_page');
                if (empty($url)) {
                    $errorMsg .= "<br />You need to specify the registration URL in the pages settings menu of this plugin.";
                    break;
                } else {
                    if (strpos($url, '?') !== false) {
                        $separator = '&';
                    }
                    $reg_url = $url . $separator . 'member_id=' . $member_record->member_id . '&code=' . $md5_code;
                }
                $email = $member_record->email;
                $subject = get_option('eMember_email_subject');
                $body = get_option('eMember_email_body');
                $from_address = get_option('senders_email_address');
                $tags = array("{first_name}", "{last_name}", "{reg_link}");
                $vals = array($member_record->first_name, $member_record->last_name, $reg_url);
                $email_body = str_replace($tags, $vals, $body);
                $headers = 'From: ' . $from_address . "\r\n";
                wp_mail($email, $subject, $email_body, $headers);
            }
        }
        $message = "";
        if (!empty($errorMsg)) {
            $message = $errorMsg;
        } else {
            $message = "Member registration completion email successfully sent.";
        }
        echo '<div id="message" class="updated fade"><p><strong>';
        echo $message;
        echo '</strong></p></div>';
    }
    if (isset($_POST['emem_to_wp'])) {
        global $wpdb;
        $member_table = WP_EMEMBER_MEMBERS_TABLE_NAME;
        $ret_member_db = $wpdb->get_results("SELECT * FROM {$member_table} ", OBJECT);
        foreach ($ret_member_db as $emember) {
            $emember->user_name = trim($emember->user_name);
            if (empty($emember->user_name)) {
                continue;
            }
            if (strtolower($emember->user_name) === "admin") {
                continue;
            }
            if (!username_exists($emember->user_name)) {
                $role_names = array(1 => 'Administrator', 2 => 'Editor', 3 => 'Author', 4 => 'Contributor', 5 => 'Subscriber');
                $membership_level_resultset = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, " id='" . $emember->membership_level . "'");
                $wp_user_info = array();
                $wp_user_info['user_nicename'] = implode('-', explode(' ', $emember->user_name));
                $wp_user_info['display_name'] = $emember->user_name;
                $wp_user_info['nickname'] = $emember->user_name;
                $wp_user_info['first_name'] = $emember->first_name;
                $wp_user_info['last_name'] = $emember->last_name;
                $wp_user_info['role'] = $role_names[$membership_level_resultset->role];
                $wp_user_info['user_registered'] = date('Y-m-d H:i:s');
                //$wp_user_id = wp_create_user($emember->user_name, 'changeme', $emember->email);
                $wp_user_id = eMember_wp_create_user($emember->user_name, 'changeme', $emember->email);
                $wp_user_info['ID'] = $wp_user_id;
                wp_update_user($wp_user_info);
                //$wpdb->query("UPDATE  $wpdb->users set user_pass = \'" . $emember->password . '\' WHERE ID = ' . $wp_user_id);
                $user_info = get_userdata($wp_user_id);
                $user_cap = is_array($user_info->wp_capabilities) ? array_keys($user_info->wp_capabilities) : array();
                if (!in_array('administrator', $user_cap)) {
                    update_wp_user_Role($wp_user_id, $membership_level_resultset->role);
                }
            }
        }
        echo '<div id="message" class="updated fade"><p>WordPress user account creation complete!</p></div>';
    }
    if (isset($_POST['emem_when_wp'])) {
        $emember_config->setValue('eMember_enable_emem_when_wp', $_POST['eMember_enable_emem_when_wp']);
        $emember_config->setValue('eMember_emem_when_wp_default_level', $_POST['eMember_emem_when_wp_default_level']);
        $emember_config->setValue('eMember_emem_when_wp_default_acstatus', $_POST['eMember_emem_when_wp_default_acstatus']);
        $emember_config->saveConfig();
        echo '<div id="message" class="updated fade"><p>Auto Member Account Creation Settings Saved!</p></div>';
    }
    if (isset($_POST['emember_management_permission_update'])) {
        $emember_config->setValue('emember_management_permission', $_POST['emember_management_permission']);
        $emember_config->saveConfig();
        echo '<div id="message" class="updated fade"><p><strong>';
        echo 'Management permission setting updated!';
        echo '</strong></p></div>';
    }
    ?>

            <div class="postbox">
                <h3><label for="title">Generate a Registration Completion link</label></h3>
                <div class="inside">
                    You can manually generate a registration completion link here and give it to your customer if they have missed the email that was automatically sent out to them after the payment.<br />
                    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">

                        <table width="100%" border="0" cellspacing="0" cellpadding="6">
                            <tr valign="top"><td width="25%" align="right">
                                    <strong>Member ID: </strong>
                                </td><td align="left">
                                    <input name="eMember_member_id" type="text" size="5" value="<?php 
    echo isset($eMember_member_id) ? $eMember_member_id : "";
    ?>
" />
                                    <br /><i>(i) Enter the member ID (you can get the member ID from the members menu).</i><br /><br />
                                </td></tr>

                            <tr valign="top"><td width="25%" align="right">
                                </td><td align="left">
                                    <input type="submit" name="generate_registration_link" value="<?php 
    _e('Generate Link');
    ?>
 &raquo;" />
                                    <br /><i>(ii) Hit the "Generate Link" button.</i><br /><br />
                                </td></tr>
                            <tr valign="top"><td width="25%" align="right">
                                    <strong>Registration Link: </strong>
                                </td><td align="left">
                                    <textarea name="wp_eStore_rego_link" rows="3" cols="80"><?php 
    echo isset($reg_url) ? $reg_url : "";
    ?>
</textarea>
                                    <br /><i>This is the registration completion link.</i><br />
                                </td></tr>
                        </table>
                    </form>
                </div></div>

            <div class="postbox">
                <h3><label for="title">Generate and Email the Registration Completion link</label></h3>
                <div class="inside">
                    You can generate a registration completion link and email it to your customer in one go. This can be useful if they have missed the email that was automatically sent out to them after the payment.<br />
                    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">

                        <table width="100%" border="0" cellspacing="0" cellpadding="6">
                            <tr valign="top"><td width="25%" align="right">
                                    <strong>Member ID: </strong>
                                </td><td align="left">
                                    <input name="eMember_member_id" type="text" size="5" value="<?php 
    echo isset($eMember_member_id) ? $eMember_member_id : "";
    ?>
" />
                                    <br /><i>(i) Enter the member ID (you can get the member ID from the members menu).</i><br /><br />
                                </td></tr>

                            <tr valign="top"><td width="25%" align="right">
                                </td><td align="left">
                                    <input type="submit" name="generate_and_send_registration_link" value="<?php 
    _e('Generate & Email Link');
    ?>
 &raquo;" />
                                    <br /><i>(ii) Hit the "Generate & Email Link" button.</i><br /><br />
                                </td></tr>

                        </table>
                    </form>
                </div></div>

            <div class="postbox">
                <h3><label for="title">Generate and Email the Registration Completion link (Bulk Mode)</label></h3>
                <div class="inside">

                    You can generate registration completion link and email it to all your members that are still waiting to complete the registration. This can be useful if they have missed the email that was automatically sent out to them after the payment.<br />
                    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
                        <input type="submit" name="generate_and_send_registration_link_bulk" value="<?php 
    _e('Generate & Email Link in Bulk');
    ?>
 &raquo;" />
                        <br /><i>Hit the "Generate & Email Link in Bulk" button.</i><br /><br />
                    </form>
                </div></div>



            <div class="postbox">
                <h3><label for="title">Create WordPress User Account for the members that do not have one</label></h3>
                <div class="inside">
                    <strong>If you have a lot of eMember members that do not have a corresponding WordPress user account and for some reason you wanted to create WordPress user account for them then use this option.</strong>
                    <br /><br />
                    &raquo; When you use this option the plugin will create wordpress user accounts for every eMember user that does not have a corresponding WordPress account already.
                    <br />
                    &raquo; The WordPress user accounts will be created with the same details from eMember but the password will be set to "changeme" (The user will have to change the password to their liking).
                    <br />
                    &raquo; Why? The password is kept in the database using an one way encryption so nobody except the member knows what the real password is.
                    <br /><br />
                    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
                        <input type="submit" name="emem_to_wp" value="<?php 
    _e('Create WP account for eMember users');
    ?>
 &raquo;" />
                    </form>
                </div></div>
            <div class="postbox">
                <h3><label for="title">Automatically Create eMember Account When a WordPress User Account is Created.</label></h3>
                <div class="inside">

                    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
                        <table width="100%" border="0" cellspacing="0" cellpadding="6">

                            <tr valign="top"><td width="25%" align="right">
                                    <strong>Enable this Feature: </strong>
                                </td><td align="left">
                                    <input name="eMember_enable_emem_when_wp" type="checkbox" <?php 
    echo $emember_config->getValue('eMember_enable_emem_when_wp');
    ?>
 value="checked='checked'" />
                                    <br /><i>When this feature is enabled, an eMember account will be created for every WP User account that gets created on this site.</i><br />
                                </td></tr>

                            <tr valign="top"><td width="25%" align="right"><strong>Default Membership Level: </strong></td>
                                <td align="left">
                                    <select name="eMember_emem_when_wp_default_level">
                                        <?php 
    $all_levels = dbAccess::findAll(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, ' id != 1 ', ' id DESC ');
    $selected_level = $emember_config->getValue('eMember_emem_when_wp_default_level');
    $selected_acstatus = $emember_config->getValue('eMember_emem_when_wp_default_acstatus');
    foreach ($all_levels as $level) {
        ?>
                                            <option <?php 
        echo $selected_level == $level->id ? "selected='selected'" : "";
        ?>
 value="<?php 
        echo $level->id;
        ?>
"><?php 
        echo $level->alias;
        ?>
</option>
                                        <?php 
    }
    ?>
                                    </select>
                                    <br /><i>When automatically creating a member account in the background, the membership level will be set to the one you specify above.</i>
                                </td></tr>

                            <tr valign="top"><td width="25%" align="right"><strong>Default Account Status: </strong></td>
                                <td align="left">
                                    <select name="eMember_emem_when_wp_default_acstatus">
                                        <option <?php 
    echo $selected_acstatus == 'active' ? "selected='selected'" : "";
    ?>
 value="active">Active</option>
                                        <option <?php 
    echo $selected_acstatus == 'inactive' ? "selected='selected'" : "";
    ?>
 value="inactive">Inactive</option>
                                        <option <?php 
    echo $selected_acstatus == 'pending' ? "selected='selected'" : "";
    ?>
 value="pending">Pending</option>
                                        <option <?php 
    echo $selected_acstatus == 'expired' ? "selected='selected'" : "";
    ?>
 value="expired">Expired</option>
                                    </select>
                                    <br /><i>The account status will be set to the one specified above.</i>
                                </td></tr>
                        </table>
                        <input type="submit" name="emem_when_wp" value="Save Settings &raquo;" />
                    </form>
                </div></div>

            <div class="postbox">
                <h3><label for="title">eMember Admin Dashboard Access Permission</label></h3>
                <div class="inside">
                    <p>
                        eMember's admin dashboard is accessible to admin users only (just like any other plugin).
                        You can allow users with other WP role to access the eMember admin dashboard by selecting a value below.
                        <br /><br />
                        <strong>If don't know what this is for then don't change the following value.</strong>
                    </p>
                    <?php 
    $selected_permission = $emember_config->getValue('emember_management_permission');
    ?>
                    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
                        <select name="emember_management_permission">
                            <option <?php 
    echo $selected_permission == 'edit_themes' ? "selected='selected'" : "";
    ?>
 value="edit_themes">Admin</option>
                            <option <?php 
    echo $selected_permission == 'edit_pages' ? "selected='selected'" : "";
    ?>
 value="edit_pages">Editor</option>
                            <option <?php 
    echo $selected_permission == 'edit_published_posts' ? "selected='selected'" : "";
    ?>
 value="edit_published_posts">Author</option>
                            <option <?php 
    echo $selected_permission == 'edit_posts' ? "selected='selected'" : "";
    ?>
 value="edit_posts">Contributor</option>
                        </select>
                        <input type="submit" name="emember_management_permission_update" value="Save Permission &raquo" />
                    </form>
                </div></div>
            <?php 
}
예제 #25
0
function wp_eMember_dashboard1()
{
    global $wpdb;
    $wp_total_members = dbAccess::findCount(WP_EMEMBER_MEMBERS_TABLE_NAME);
    $fields = array('count(*)' => 'count', 'membership_level' => 'membership_level', 'alias' => 'alias');
    $table = WP_EMEMBER_MEMBERS_TABLE_NAME . ' LEFT JOIN ' . WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE . ' ON (membership_level=id) ';
    $last5members = dbAccess::findAll($table, '', ' member_id DESC LIMIT 0,5');
    $members = dbAccess::findCount($table, $fields, null, null, ' membership_level ');
    $query = "SELECT COUNT(member_id) AS active FROM " . WP_EMEMBER_MEMBERS_TABLE_NAME . " WHERE account_state = 'active'";
    $active_members = $wpdb->get_col($query);
    ?>
    <table>
        <tbody><tr valign="top">
                <td>
                    <table style="width: 800px;" class="widefat">
                        <thead>
                            <tr>
                                <th scope="col">Membership Stats</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>
                                    <table cellspacing="5" cellpadding="3" width="100%">
                                        <tbody><tr valign="top">
                                                <td width="50%" style="border: 1px solid rgb(238, 238, 238); background: rgb(248, 248, 248) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; line-height: 1.5em;">
                                                    <h3 style="margin: 0pt 0pt 5px;">Membership level</h3>
                                                    <?php 
    if ($members) {
        foreach ($members as $member) {
            ?>
                                                            <div style="float: left; width: 130px;"><a href="#">· <?php 
            echo stripslashes($member->alias);
            ?>
</a></div>
                                                            <div style="float: right; width: 35px; text-align: right;"><?php 
            echo $member->count;
            ?>
</div>
                                                            <br clear="all"/>
                                                            <?php 
        }
    } else {
        echo __('Nothing to show.', 'wp_eMember');
    }
    ?>
                                                    <br clear="all"/>
                                                    <hr>
                                                    <div style="float: left; width: 130px;">· Total Members</div>
                                                    <div style="float: right; width: 35px; text-align: right;"><?php 
    echo $wp_total_members[0]->count;
    ?>
</div>
                                                    <br clear="all"/>
                                                    <div style="float: left; width: 130px;">· Active Members</div>
                                                    <div style="float: right; width: 35px; text-align: right;"><?php 
    echo $active_members[0];
    ?>
</div>
                                                </td>
                                                <td width="50%" style="border: 1px solid rgb(238, 238, 238); background: rgb(248, 248, 248) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; line-height: 1.5em;">
                                                    <h3 style="margin: 0pt 0pt 5px;">Recent 5 members</h3>
                                                    <table cellpadding="10px">
                                                        <thead>
                                                            <tr>
                                                                <th>ID</th>
                                                                <th>User</th>
                                                                <th>Level</th>
                                                                <th>Since</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php 
    if ($last5members) {
        foreach ($last5members as $member) {
            ?>
                                                                    <tr>
                                                                        <td>
                                                                            <?php 
            echo $member->member_id;
            ?>
                                                                        </td>
                                                                        <td>
                                                                            <?php 
            echo stripslashes($member->user_name);
            ?>
                                                                        </td>
                                                                        <td>
                                                                            <?php 
            echo stripslashes($member->alias);
            ?>
                                                                        </td>
                                                                        <td>
                                                                            <?php 
            echo date(get_option('date_format'), strtotime($member->member_since));
            ?>
                                                                        </td>
                                                                    </tr>
                                                                    <?php 
        }
    } else {
        echo '<tr> <td colspan="4">' . __('No Members found.', 'wp_eMember') . '</td> </tr>';
    }
    ?>
                                                        </tbody>
                                                    </table>
                                                    <br/>
                                                </td>
                                            </tr>
                                        </tbody></table>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody></table>
    <?php 
}
예제 #26
0
파일: update.php 프로젝트: phupx/genco
        echo "Error!\n";
        echo "Email address entered is blocked.";
        eMember_log_debug("Blocked email address used. This request will fail.", false);
        exit;
    }
}
//Update the corresponding WP User object if needed
$resultset = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=' . $member_id);
$wp_user_id = username_exists($resultset->user_name);
if ($wp_user_id) {
    $wp_user_info = array();
    $wp_user_info['first_name'] = strip_tags(isset($_REQUEST['first_name']) ? $_REQUEST['first_name'] : "");
    $wp_user_info['last_name'] = strip_tags(isset($_REQUEST['last_name']) ? $_REQUEST['last_name'] : "");
    $wp_user_info['user_email'] = strip_tags(isset($_REQUEST['email']) ? $_REQUEST['email'] : "");
    $wp_user_info['ID'] = $wp_user_id;
    if (!empty($_REQUEST['password'])) {
        $wp_user_info['user_pass'] = $_REQUEST['password'];
    }
    wp_update_user($wp_user_info);
}
//Update the emember user profile with the provided data
if (count($fields) > 0) {
    $ret = dbAccess::update(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id =' . $member_id, $fields);
}
//Update the membership level ID
if (!empty($membership_level_id)) {
    emember_update_membership_level($member_id, $membership_level_id);
}
eMember_log_debug("Member profile updated.", true);
echo "Success!\n";
echo "Member profile updated.\n";
예제 #27
0
<?php

require "connection.php";
require "dbAccess.php";
// return array for for JSON responses
$resultArray = array();
// create db connection
$access = new dbAccess();
$access->openConnection();
// query database for all events in events table
$result = $access->getAllEvents();
// if query returned successfully
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
    $rowArray = $row;
    array_push($resultArray, $rowArray);
}
if (!empty($resultArray)) {
    echo json_encode($resultArray);
}
$access->closeConnection();
예제 #28
0
function emember_load_membership_form()
{
    if (!current_user_can('manage_options')) {
        die("Access Forbidden");
    }
    global $wpdb;
    $id = strip_tags($_POST['id']);
    $subscription_period = "";
    $subscription_unit = "";
    $fixed_date = "";
    if (empty($id)) {
        $role = "subscriber";
        $name = "";
        $loginredirect = "";
        $campaign_name = "";
        $expire = 'noexpire';
        $allpages = 'checked="checked"';
        $allcategories = 'checked="checked"';
        $allposts = 'checked="checked"';
        $allcomments = 'checked="checked"';
        $allattachments = 'checked="checked"';
        $allcustomposts = 'checked="checked"';
    } else {
        $level = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, " id = '" . esc_sql($id) . " ' ");
        $role = $level->role;
        $name = htmlspecialchars($level->alias);
        $loginredirect = $level->loginredirect_page;
        $campaign_name = $level->campaign_name;
        if (empty($level->subscription_period) && empty($level->subscription_unit)) {
            $expire = 'noexpire';
        } else {
            if (empty($level->subscription_period)) {
                $expire = 'fixed_date';
                $fixed_date = $level->subscription_unit;
            } else {
                $expire = 'interval';
                $subscription_period = $level->subscription_period;
                $subscription_unit = $level->subscription_unit;
            }
        }
        $allpages = ($level->permissions & 8) === 8 ? 'checked="checked"' : "";
        $allcategories = ($level->permissions & 1) === 1 ? 'checked="checked"' : "";
        $allposts = ($level->permissions & 4) === 4 ? 'checked="checked"' : "";
        $allcomments = ($level->permissions & 2) === 2 ? 'checked="checked"' : "";
        $allattachments = ($level->permissions & 16) === 16 ? 'checked="checked"' : "";
        $allcustomposts = ($level->permissions & 32) === 32 ? 'checked="checked"' : "";
    }
    require_once 'views/add_membership_level_view.php';
    exit(0);
}
예제 #29
0
function send_response($input_raw)
{
    include 'dbAccess.php';
    $swears = array('fuckoff', 'f**k', 'hutto', 'ponnaya', 'pakaya', 'paka', 'fuckyou', 'redda', 'm**********r', 'pimpiya', 'huththa', 'hukahan');
    $sequence_commands = array('/farming', '/addmetofarm', '/removemefromfarm', '/deletefarm', '/setfarmlocation', '/setfarmtime', '/addfarmer', '/removefarmer', '/getfarmlocation', '/icametofarm');
    //This array is used to store the questions to be asked when a user sends a message which would require secondary processing for farm selection.
    //[0] - Farm selection question - this is used in later processing to identify which message the bot should reply to
    // [1] - How many segments should there be other than the request message - this is used for validation.
    // [2] - Response to send if validation on message segments fails.
    $selection_questions = array('/farming' => array('Which farm do you want the details of?', 0), '/addmetofarm' => array('Which farm do you want to be added to?', 0), '/removemefromfarm' => array('Which farm do you want to be removed from?', 0), '/deletefarm' => array('Which farm do you want to delete?', 0), '/setfarmlocation' => array('Which farm do you want to set the location for?', 1, 'You need to specify a location. Use /setfarmlocation LOCATION.'), '/setfarmtime' => array('Which farm do you want to set the time for?', 2, 'You need to specify a date and time. Use /setfarmtime DATE TIME.'), '/addfarmer' => array('Which farm do you want to add to?', 1, 'You need to specify who you need to add. Use /addfarmer FARMER_NAME.'), '/removefarmer' => array('Which farm do you want to remove from?', 1, 'You need to specify who you need to remove. Use /removefarmer FARMER_NAME.'), '/getfarmlocation' => array('Which farm do you want the location of?', 0), '/icametofarm' => array('Which farm did you come to?', 0));
    $db = dbAccess::getInstance();
    //$response = send_curl('https://api.telegram.org/bot112493740:AAHBuoGVyX2_T-qOzl8LgcH-xoFyYUjIsdg/getUpdates');
    /*$input_raw = '{
        "update_id": 89023643,
        "message": {
          "message_id": 9370,
          "from": {
            "id": 387220855,
            "first_name": "Nisal",
            "last_name": "Chandrasekara [LK]",
            "username": "******"
          },
          "chat": {
            "id":-27924249,
            "title": "Bot Devs & BAs"
          },
          "date": 1440704429,
          "reply_to_message": {
            "message_id": 9369,
            "from": {
              "id": 112493740,
              "first_name": "SL ENL Farm Bot",
              "username": "******"
            },
            "chat": {
              "id": -27924249,
              "title": "Bot Devs & BAs"
            },
            "date": 1440704423,
            "text": "@Nisal, Which farm do you want the details of?"
          },
          "text": "/users"
        }
      }';*/
    // let's log the raw JSON message first
    if (DEBUGLVL) {
        $log = new stdClass();
        $log->message_text = $input_raw;
        $db->insertObject('message_log', $log);
    }
    $messageobj = json_decode($input_raw, true);
    $chat_id = $messageobj['message']['chat']['id'];
    $user_id = $messageobj['message']['from']['id'];
    $message_id = $messageobj['message']['message_id'];
    $farmer_name = '@' . $messageobj['message']['from']['username'];
    $reply = '';
    if (array_key_exists('new_chat_participant', $messageobj['message']) & $chat_id == '-111936746' & strpos($messageobj['message']['new_chat_participant']['user_name'], "bot") == false) {
        $newcomer = $messageobj['message']['new_chat_participant']['first_name'] . " " . $messageobj['message']['new_chat_participant']['last_name'];
        $reply = urlencode('Hello ' . $newcomer . ',	
Welcome to SL-ENL L8+ Group.

I can help you to set up farming sessions.
use /farming to check for current farming sessions.

if you are an Android user please install MyTeams App and join our team
http://myteams.website/teams/8qIqaqwnZurf');
        send_curl(build_response($chat_id, $reply));
        return;
    }
    $message_txt_parts = explode(' ', $messageobj['message']['text']);
    $complete_message = $messageobj['message']['text'];
    $request_message = $message_txt_parts[0];
    $request_message = explode('@', $request_message);
    $request_message = $request_message[0];
    //check for swear words
    foreach ($swears as $swear) {
        if (strpos($complete_message, $swear) !== false) {
            $reply = urlencode('යකෝ මේක හදල තියෙන්නෙ ගොන් ආතල් ගන්න නෙවේ. ගොන් ආතල් ගන්න ඕන නම් මෑඩ් හව්ස් එකට පලයන්.');
            send_curl(build_response($chat_id, $reply));
            return;
        }
    }
    if ($chat_id == $user_id) {
        $reply = urlencode('This is not a Group Please add me to a Group to set up your farming session.
https://telegram.me/SlEnlFarmbot?startgroup=addmetogroup');
        send_curl(build_response($chat_id, $reply));
        return;
    }
    if ($request_message == 'Cancel') {
        $markup['hide_keyboard'] = true;
        send_curl('https://api.telegram.org/bot112493740:AAGW9ZOjyfJZh-DJZ-HYW2aJDLuVs2_wwBE/sendMessage?chat_id=' . $chat_id . '&text=👍&reply_markup=' . json_encode($markup));
        return;
    }
    if ($chat_id == '-27924249') {
        if ($request_message == '/activefarms') {
            $db->setQuery('select * from farms where current = 1 ');
            $farms = $db->loadAssocList();
            $reply = urlencode('Active Farms
');
            foreach ($farms as $farm) {
                $reply .= urlencode($farm['id'] . '. ' . $farm['location'] . ' ' . $farm['date_and_time'] . '  by ' . $farm['creator'] . '
');
            }
            send_curl(build_response($chat_id, $reply));
            return;
        }
        if ($request_message == '/users') {
            $db->setQuery("SELECT count( distinct REPLACE(farmer_name,'(Upgraded)','') ) as COUNT FROM farmers");
            $count = $db->loadAssoc();
            $reply = urlencode('@SLEnlFarmbot users 👥 - ' . $count['COUNT']);
            send_curl(build_response($chat_id, $reply));
            return;
        }
    }
    if (in_array($request_message, $sequence_commands)) {
        // This is an initial message in the chain, generate the farm list and send
        $db->setQuery('select * from farms where current=1 and farm_group=' . $chat_id);
        $currentfarms = $db->loadAssocList();
        if (empty($currentfarms)) {
            $reply = urlencode('There are no current farms set up. Use /createfarm LOCATION DATE TIME to set up a new farm.');
            send_curl(build_response($chat_id, $reply));
            return;
        }
        // validate if the message is ready for multifarms
        if (count($message_txt_parts) - 1 < $selection_questions[$request_message][1]) {
            $reply = urlencode($farmer_name . ", " . $selection_questions[$request_message][2]);
            send_curl(build_response($chat_id, $reply));
            return;
        }
        $farmer_name = '@' . $messageobj['message']['from']['username'];
        $keyboard = array('keyboard' => array());
        for ($i = 0; $i < count($currentfarms); $i++) {
            $keyboard['keyboard'][$i][0] = $currentfarms[$i]['id'] . '. ' . $currentfarms[$i]['location'] . ' ' . $currentfarms[$i]['date_and_time'];
        }
        $keyboard['keyboard'][count($currentfarms)][0] = "Cancel";
        if ($request_message == '/setfarmtime') {
            $reply = urlencode($farmer_name . ", " . $selection_questions[$request_message][0] . ' |' . $message_txt_parts[1] . ' ' . $message_txt_parts[2]);
        } else {
            if ($request_message == '/setfarmlocation' || $request_message == '/addfarmer' || $request_message == '/removefarmer') {
                $reply = urlencode($farmer_name . ", " . $selection_questions[$request_message][0] . ' |' . $message_txt_parts[1]);
            } else {
                $reply = urlencode($farmer_name . ", " . $selection_questions[$request_message][0]);
            }
        }
        send_curl(build_response_keyboard($chat_id, $reply, $message_id, $keyboard));
        return;
    }
    if ($request_message == '/createfarm') {
        $time = $location = '';
        $farmer_name = '@' . $messageobj['message']['from']['username'];
        $reply .= easter_eggs($farmer_name);
        if (!empty($message_txt_parts[1])) {
            $location = $message_txt_parts[1];
        } else {
            $reply = urlencode('You cannot set up a farm without specifying a location. Use /createfarm LOCATION DATE TIME.
');
            send_curl(build_response($chat_id, $reply));
            return;
        }
        if (!empty($message_txt_parts[2]) && !empty($message_txt_parts[3])) {
            $time = $message_txt_parts[2] . ' ' . $message_txt_parts[3];
        } else {
            $reply = urlencode('You cannot set up a farm without specifying a date and time for it. Use /createfarm LOCATION DATE TIME.
');
            send_curl(build_response($chat_id, $reply));
            return;
        }
        $farm = new stdClass();
        $farm->date_and_time = $time;
        $farm->location = $location;
        $farm->creator = $farmer_name;
        $farm->farm_group = $chat_id;
        $farm->current = 1;
        $db->insertObject('farms', $farm);
        $db->setQuery('select * from farms where current=1 order by id desc limit 1');
        $currentfarm = $db->loadAssoc();
        $reply .= urlencode($farmer_name . ' created a farm - ' . $currentfarm['location'] . '_' . $currentfarm['date_and_time'] . '
1. ' . $farmer_name);
        $farmer = new stdClass();
        $farmer->farm_id = $currentfarm['id'];
        $farmer->farmer_name = $farmer_name;
        $db->insertObject('farmers', $farmer);
        send_curl(build_response($chat_id, $reply));
        return;
    }
    if (array_key_exists('reply_to_message', $messageobj['message'])) {
        // This is a secondary message on the chain - process it
        $secondary_parts = explode('.', $complete_message);
        $selected_farm_id = $secondary_parts[0];
        $reply_to_message = $messageobj['message']['reply_to_message']['text'];
        $db->setQuery('select * from farms where id=' . $selected_farm_id);
        $currentfarm = $db->loadAssoc();
        if (strpos($reply_to_message, 'details') !== false) {
            // Earlier message was /farming
            $reply .= build_farm_message($currentfarm['id']);
            send_curl(build_response($chat_id, $reply));
            return;
        }
        if (strpos($reply_to_message, 'added') !== false) {
            $db->setQuery("select * from farmers where farmer_name like '{$farmer_name}%' and farm_id=" . $currentfarm['id']);
            $farmeravailable = $db->loadAssoc();
            if (!empty($farmeravailable)) {
                $reply = urlencode('You have already been added to this farm, ' . $farmer_name);
                send_curl(build_response($chat_id, $reply));
                return;
            }
            if ($farmer_name == '@Cyan017') {
                $reply .= urlencode('Yeah right, like that lazy bugger is going to come for a farm. Pigs will fly!');
            }
            $reply .= easter_eggs($farmer_name);
            $farmer = new stdClass();
            $farmer->farm_id = $currentfarm['id'];
            $farmer->farmer_name = $farmer_name;
            $db->insertObject('farmers', $farmer);
            $reply .= build_farm_message($currentfarm['id']);
            send_curl(build_response($chat_id, $reply));
            return;
        }
        if (strpos($reply_to_message, 'removed') !== false) {
            $db->setQuery("select * from farmers where farmer_name like '{$farmer_name}%' and farm_id=" . $currentfarm['id']);
            $farmeravailable = $db->loadAssoc();
            if (empty($farmeravailable)) {
                $reply = urlencode('You were not in this farm anyway, ' . $farmer_name);
                send_curl(build_response($chat_id, $reply));
                return;
            }
            if ($farmer_name == '@Cyan017') {
                $reply .= urlencode('Hahaha I knew that lazy ass @Cyan017 would never come for a farm!');
            }
            $db->setQuery("delete from farmers where farmer_name like '{$farmer_name}%' and farm_id=" . $currentfarm['id'])->loadResult();
            $reply .= build_farm_message($currentfarm['id']);
            send_curl(build_response($chat_id, $reply));
            return;
        }
        if (strpos($reply_to_message, 'delete') !== false) {
            $deleter_name = '@' . $messageobj['message']['from']['username'];
            if ($deleter_name != $currentfarm['creator'] && $deleter_name != '@RamdeshLota' && $deleter_name != '@Nisal') {
                $reply = urlencode($deleter_name . ', you are not my Creator or my Uncle, nor are you my Father. You cannot delete me.');
                send_curl(build_response($chat_id, $reply));
                return;
            }
            $farm = new stdClass();
            $farm->id = $currentfarm['id'];
            $farm->current = 0;
            $db->updateObject('farms', $farm, 'id');
            $reply = urlencode('Deleted ' . $currentfarm['location'] . ' farm.');
            send_curl(build_response($chat_id, $reply));
            return;
        }
        if (strpos($reply_to_message, 'location for') !== false) {
            $location = explode('|', $reply_to_message);
            $location = $location[1];
            $farm = new stdClass();
            $farm->id = $currentfarm['id'];
            $farm->location = $location;
            $db->updateObject('farms', $farm, 'id');
            $reply .= urlencode('Set farm location to ' . $location . '
');
            $reply .= build_farm_message($currentfarm['id']);
            send_curl(build_response($chat_id, $reply));
            return;
        }
        if (strpos($reply_to_message, 'time') !== false) {
            $date_and_time = explode('|', $reply_to_message);
            $date_and_time = $date_and_time[1];
            $farm = new stdClass();
            $farm->id = $currentfarm['id'];
            $farm->date_and_time = $date_and_time;
            $db->updateObject('farms', $farm, 'id');
            $reply .= urlencode('Set farm date and time to ' . $date_and_time . '
');
            $reply .= build_farm_message($currentfarm['id']);
            send_curl(build_response($chat_id, $reply));
            return;
        }
        if (strpos($reply_to_message, 'add to') !== false) {
            $farmer_name = explode('|', $reply_to_message);
            $farmer_name = $farmer_name[1];
            if ($farmer_name == '@Cyan017') {
                $reply .= urlencode('Yeah right, like that lazy bugger is going to come for a farm. Pigs will fly!
');
            }
            $db->setQuery("select * from farmers where farmer_name like '{$farmer_name}%' and farm_id=" . $currentfarm['id']);
            $farmeravailable = $db->loadAssoc();
            if (!empty($farmeravailable)) {
                $reply = urlencode($farmer_name . ' has already been added to this farm.');
                send_curl(build_response($chat_id, $reply));
                return;
            }
            $reply .= easter_eggs($farmer_name);
            $farmer = new stdClass();
            $farmer->farm_id = $currentfarm['id'];
            $farmer->farmer_name = $farmer_name;
            $db->insertObject('farmers', $farmer);
            $reply .= build_farm_message($currentfarm['id']);
            send_curl(build_response($chat_id, $reply));
            return;
        }
        if (strpos($reply_to_message, 'remove from') !== false) {
            $farmer_name = explode('|', $reply_to_message);
            $farmer_name = $farmer_name[1];
            if ($farmer_name == '@Cyan017') {
                $reply .= urlencode('Hahaha I knew that lazy ass @Cyan017 would never come for a farm!');
            }
            $db->setQuery("select * from farmers where farmer_name like '{$farmer_name}%' and farm_id=" . $currentfarm['id']);
            $farmeravailable = $db->loadAssoc();
            if (empty($farmeravailable)) {
                $reply = urlencode($farmer_name . ' is not on this farm anyway.');
                send_curl(build_response($chat_id, $reply));
                return;
            }
            $db->setQuery("delete from farmers where farmer_name like '{$farmer_name}%' and farm_id=" . $currentfarm['id'])->loadResult();
            $reply .= build_farm_message($currentfarm['id']);
            send_curl(build_response($chat_id, $reply));
            return;
        }
        if (strpos($reply_to_message, 'location of') !== false) {
            $farmlocation = $currentfarm['location'];
            if (strripos($farmlocation, 'indi') !== false || strripos($farmlocation, 'inde') !== false) {
                $locationobj = array('longitude' => 79.867644, 'latitude' => 6.904088);
            } else {
                if (strripos($farmlocation, 'dewram') !== false || strripos($farmlocation, 'devram') !== false) {
                    $locationobj = array('longitude' => 79.942516, 'latitude' => 6.853475);
                } else {
                    if (strripos($farmlocation, 'rajagiri') !== false) {
                        $locationobj = array('longitude' => 79.895746, 'latitude' => 6.908751);
                    } else {
                        $reply = $farmlocation . ' farm location is not recognized.';
                        send_curl(build_response($chat_id, $reply));
                    }
                }
            }
            // $location = json_encode($locationobj);
            send_curl(build_location_response($chat_id, $locationobj));
            return;
        }
        if (strpos($reply_to_message, 'come to?') !== false) {
            $upgraded_farmer_name = '@' . $messageobj['message']['from']['username'] . ' (Upgraded)';
            $db->setQuery("select * from farmers where farmer_name='{$upgraded_farmer_name}' and farm_id=" . $currentfarm['id']);
            $upgradedfarmeravailable = $db->loadAssoc();
            if (!empty($upgradedfarmeravailable)) {
                $reply = urlencode('You have already Upgraded this farm,' . $farmer_name);
                send_curl(build_response($chat_id, $reply));
                return;
            }
            $db->setQuery("select * from farmers where farmer_name like '{$farmer_name}%' and farm_id=" . $currentfarm['id']);
            $farmeravailable = $db->loadAssoc();
            if (empty($farmeravailable)) {
                $farmer = new stdClass();
                $farmer->farm_id = $currentfarm['id'];
                $farmer->farmer_name = $upgraded_farmer_name;
                $db->insertObject('farmers', $farmer);
                $reply = urlencode($farmer_name . ' Upgraded ' . $currentfarm['location'] . ' Farm.');
                send_curl(build_response($chat_id, $reply));
                return;
            }
            $db->setQuery("select * from farmers where farmer_name like '{$farmer_name}%' and farm_id=" . $currentfarm['id']);
            $currentfarmer = $db->loadAssoc();
            $farmer = new stdClass();
            $farmer->id = $currentfarmer['id'];
            $farmer->farm_id = $currentfarm['id'];
            $farmer->farmer_name = $upgraded_farmer_name;
            $db->updateObject('farmers', $farmer, 'id');
            //$db->insertObject('farmers', $farmer);
            $reply = urlencode($farmer_name . ' Upgraded ' . $currentfarm['location'] . ' Farm.');
            send_curl(build_response($chat_id, $reply));
        }
    }
    if ($request_message == '/changerequest' || $request_message == '/changerequest@SLEnlFarmBot') {
        $message = strtolower(substr($messageobj['message']['text'], 14));
        if ($message == '' || $message == null) {
            $reply = urlencode('Dear Enlightened LK member,
Bloody say something!
Thank you!');
            send_curl(build_response($chat_id, $reply));
            return;
        }
        if (strpos($message, 'please') == false) {
            $reply = urlencode('Dear Enlightened LK member,
Say please. I am programmed to not accommodate rude people.			
Thank you!');
            send_curl(build_response($chat_id, $reply));
            return;
        }
        $reply = urlencode('Dear Enlightened LK member,
Your suggestion for improvement has been received and will be processed in the distant future (although this is unlikely). 
In the meantime, please be sure to obtain approval from the SL ENL Security Experts Incompetency Group (SESEIG™), 
as there may be unforeseen and unfathomable dangers associated with your change request. 
Thank you!');
        send_curl(build_response($chat_id, $reply));
        $reply = urlencode('New #ChangeRequest
from - @' . $messageobj['message']['from']['username'] . '
' . substr($messageobj['message']['text'], 14));
        send_curl(build_response(-27924249, $reply));
        return;
    }
    if ($request_message == '/help' || $request_message == '/help@SLEnlFarmBot' || $request_message == '/start@SLEnlFarmBot') {
        $reply = urlencode('This is the SL ENL Farming Bot created by @RamdeshLota. Commands:
/createfarm LOCATION DATE TIME - Creates a new farm.
/addmetofarm - Adds you to the current farm.
/removemefromfarm - Removes you from the current farm.
/addfarmer USERNAME - Adds the given username to the farm.
/removefarmer USERNAME - Removes the given username from the farm.
/setfarmlocation LOCATION - Sets the location for the current farm.
/getfarmlocation - Get the location of the current farm.
/setfarmtime DATE TIME - Sets the date and  time for the current farm.(e.g. "Today 6pm")
/deletefarm - Deletes the current farm.
/changerequest - Suggest a change to the bot.        		
/help - Display this help text.');
        send_curl(build_response($chat_id, $reply));
        return;
    }
}
예제 #30
0
}
$username = '';
$password = '';
// keep or reset the form fields
if (isset($_POST['username'])) {
    $username = $_POST['username'];
}
if (isset($_POST['password'])) {
    $password = $_POST['password'];
}
$display = true;
if (isset($_POST['submit'])) {
    unset($_POST['submit']);
    $user_id = "";
    if (validateUserLogin($err_msg)) {
        $conn = new dbAccess($debug);
        if (($rc = $conn->dbLoginUser($username, $password, $user_id)) == GOOD_RC) {
            // we have a valid user
            // Create new session, store the user id
            $_SESSION['user_id'] = $user_id;
            $sess_id = session_id();
            $_SESSION['sess_id'] = $sess_id;
            $dom = new DomDocument();
            $dom->validateOnParse = true;
            $el = $dom->getElementById('sess_id');
            $el->nodeValue = $sess_id;
            $uid = $dom->getElementById('user_id');
            $uid->nodeValue = $user_id;
            // Redirect to user info page
            ob_end_clean();
            header('Location: ' . $baseURL . '/dataAccess/userInfo.php');