Ejemplo n.º 1
0
function sola_nl_add_single_subscriber($status = 1)
{
    global $wpdb;
    global $sola_nl_subs_tbl;
    $sola_nl_sub_check = '';
    if (sola_cts()) {
        extract($_POST);
        if ($sub_email) {
            $sub_key = wp_hash_password($sub_email);
            $result = $wpdb->get_results('SELECT count(*) as count FROM ' . $sola_nl_subs_tbl . '  WHERE sub_email="' . $sub_email . '" ; ');
            $count = $result[0]->count;
            if ((int) $count === 0) {
                $sola_nl_sub_check = $wpdb->insert($sola_nl_subs_tbl, array('sub_id' => '', 'sub_name' => $sub_name, 'sub_email' => $sub_email, 'sub_key' => $sub_key, "status" => $status));
            }
            if (isset($sub_list)) {
                sola_nl_add_sub_list($sub_list, $wpdb->insert_id);
            }
            if ($sola_nl_sub_check == false) {
                return new WP_Error('db_query_error', __('Could not add subscriber', 'sola'), $wpdb->last_error);
            } else {
                return true;
            }
        } else {
            ?>
           <div class="error">
              <p><?php 
            _e("Please enter an E-mail Address", "sola");
            ?>
</p>
           </div>
           <?php 
        }
    } else {
        echo sola_se();
    }
}
function sola_import_file_subscribers($list)
{
    if (!isset($list)) {
        return new WP_Error('sola_error', __('Please select a list'), "");
    }
    global $wpdb;
    global $sola_nl_subs_tbl;
    global $sola_nl_subs_list_tbl;
    $insert_array = array();
    ini_set("auto_detect_line_endings", true);
    $handle = fopen($_FILES['sub_import_file']['tmp_name'], "r");
    while (!feof($handle)) {
        if (isset($_POST['sub_data_replace_csvreplace']) && $_POST['sub_data_replace_csvreplace'] == "Yes") {
            $wpdb->query("TRUNCATE TABLE {$sola_nl_subs_tbl}");
            $wpdb->query("TRUNCATE TABLE {$sola_nl_subs_list_tbl}");
        }
        while (($data = fgetcsv($handle, 1000, ",", '"')) !== FALSE) {
            set_time_limit(600);
            $email = $data[0];
            if (isset($data[1])) {
                $firstname = $data[1];
            } else {
                $firstname = "";
            }
            if (isset($data[2])) {
                $lastname = $data[2];
            } else {
                $lastname = "";
            }
            $new_subscriber = false;
            $update_subscriber = false;
            /* check if email exists */
            if (isset($_POST['sub_data_replace_csvreplace']) && $_POST['sub_data_replace_csvreplace'] == "Yes") {
                /* no need to check for updates. just insert..! */
                $new_subscriber = true;
                $update_subscriber = false;
            } else {
                if (sola_check_if_subscriber_email_exists($email)) {
                    /* email exists, update db with name */
                    $new_subscriber = false;
                    $update_subscriber = true;
                } else {
                    $new_subscriber = true;
                    $update_subscriber = false;
                }
            }
            /* good to go */
            if ($update_subscriber) {
                $subscriber_data = sola_get_subscriber_data_by_email($email);
                $sub_id = $subscriber_data->sub_id;
                sola_nl_add_sub_list($list, $sub_id);
                if ($wpdb->update($sola_nl_subs_tbl, array('sub_email' => $email, 'sub_name' => $firstname, 'sub_last_name' => $lastname), array('sub_id' => $sub_id), array('%s', '%s', '%s'), array('%d')) === FALSE) {
                    return new WP_Error('db_query_error', __('Could not execute query'), $wpdb->last_error);
                } else {
                }
            }
            if ($new_subscriber) {
                if (sola_cts()) {
                    $sub_key = wp_hash_password($email);
                    $arm_nl_sub_check = $wpdb->insert($sola_nl_subs_tbl, array('sub_id' => '', 'sub_name' => $firstname, 'sub_last_name' => $lastname, 'sub_email' => $email, 'sub_key' => $sub_key, "status" => 1));
                    sola_nl_add_sub_list($list, $wpdb->insert_id);
                } else {
                    return new WP_Error('sola_error', __("Import Error", "sola"), sola_se());
                }
            }
            if (!$new_subscriber && !$update_subscriber) {
                return new WP_Error('sola_error', __('Something went wrong with the upload. Please contact support'), $new_data);
            }
        }
    }
    fclose($handle);
}