You are not logged in. Please log in first to download the report!

// function product_name($id){ // $meta_key = '_accessally_user_contact_id_local'; // global $wpdb; // $c_id = $wpdb->get_results("SELECT meta_value FROM `wp_usermeta` WHERE `user_id` = '$id' AND `meta_key` = '$meta_key'"); // $contact_id = $c_id[0]->meta_value; // if (!empty($contact_id)) { // $tag_ids = $wpdb->get_results("SELECT tag_id FROM `wp_aal_user_tags` WHERE `contact_id` = '$contact_id'"); // $tag = array(); // foreach ($tag_ids as $tag_id) { // $option_name = '_accessally_tagging_ind_tag_' . $tag_id->tag_id; // $option_value = get_option($option_name); // // Check if 'Bioremedy' key exists in the option value, but consider additional words // // if (!empty($option_value['name']) && stripos($option_value['name'], 'Waver Has Access') !== false) { // $tag[] = $option_value['name']; // // } // } // if (empty($tag)) { // $option_value = 'not found'; // } else { // // If there are multiple product names, concatenate them into a comma-separated string // $option_value = implode(",", $tag); // } // } else { // $option_value = 'not found'; // } // return $option_value; // } // if (is_user_logged_in()) { // // Check if the user has the 'manage_options' capability // if (current_user_can('manage_options')) { // $data = array( // array('','Registration Report',''), // array('User ID', 'Order ID', 'Name', 'Email', 'Phone', 'Registration Date', 'Product Name' ,'Address'), // ); // $start_date = '2023-12-01 00:00:00'; // Replace with your desired start date // $end_date = '2023-12-31 23:59:00'; // Current date and time // // Create a new user query // $args = array( // 'role' => 'subscriber', // Set the user role you are interested in // 'date_query' => array( // /* array( // 'after' => '1 months ago', // Set the date range // 'inclusive' => true, // ),*/ // array( // 'column' => 'user_registered', // 'after' => $start_date, // 'before' => $end_date, // 'inclusive' => true, // ), // ), // ); // $user_query = new WP_User_Query($args); // // Get the results // $users = $user_query->get_results(); // // Loop through the users and add data to the array // $counter = 0; // foreach ($users as $user) { // $product_name = product_name($user->id); // // Check if the product name contains "Bioremedy" // // if (stripos($product_name, 'Waver Has Access') !== false) { // $udata = get_userdata($user->id); // //$meta_key = '_accessally_user_contact_id_local'; // $con_id = $wpdb->get_results("SELECT meta_value FROM `wp_usermeta` WHERE `user_id` = '$user->id' AND `meta_key` = '_accessally_user_contact_id_local'"); // $contact_id = $con_id[0]->meta_value; // //echo "SELECT meta_value FROM `wp_usermeta` WHERE `user_id` = '$user->id' AND `meta_key` = '_accessally_user_contact_id_local'"; // $order_id = $wpdb->get_results("SELECT * FROM `wp_aal_crm_field` WHERE `contact_id` = '$contact_id';"); // $first_name = $wpdb->get_results("SELECT * FROM `wp_aal_crm_field` WHERE `contact_id` = '$contact_id' AND `field_id` = 'first_name';"); // $last_name = $wpdb->get_results("SELECT * FROM `wp_aal_crm_field` WHERE `contact_id` = '$contact_id' AND `field_id` = 'last_name';"); // // $email = $wpdb->get_results("SELECT * FROM `wp_aal_crm_field` WHERE `contact_id` = '$contact_id' AND `field_id` = 'email';"); // $phone = $wpdb->get_results("SELECT * FROM `wp_aal_crm_field` WHERE `contact_id` = '$contact_id' AND `field_id` = 'phone';"); // $address1 = $wpdb->get_results("SELECT * FROM `wp_aal_crm_field` WHERE `contact_id` = '$contact_id' AND `field_id` = 'address1';"); // $address2 = $wpdb->get_results("SELECT * FROM `wp_aal_crm_field` WHERE `contact_id` = '$contact_id' AND `field_id` = 'address2';"); // $city = $wpdb->get_results("SELECT * FROM `wp_aal_crm_field` WHERE `contact_id` = '$contact_id' AND `field_id` = 'city';"); // $state = $wpdb->get_results("SELECT * FROM `wp_aal_crm_field` WHERE `contact_id` = '$contact_id' AND `field_id` = 'state';"); // $country = $wpdb->get_results("SELECT * FROM `wp_aal_crm_field` WHERE `contact_id` = '$contact_id' AND `field_id` = 'country';"); // $zip = $wpdb->get_results("SELECT * FROM `wp_aal_crm_field` WHERE `contact_id` = '$contact_id' AND `field_id` = 'zip';"); // $full_address = $address1[0]->field_value.', '.$address2[0]->field_value.', '.$city[0]->field_value.', '.$state[0]->field_value.', '.$country[0]->field_value.', '.$zip[0]->field_value; // $name= $first_name[0]->field_value.' '.$last_name[0]->field_value; // $phone =$phone[0]->field_value; // $registered = $udata->user_registered; // $registered_date = date("Y-m-d", strtotime($registered)); // $user_data = array( // $user->id, // $order_id[0]->field_value, // $name, // $user->user_email, // $phone, // $registered_date, // $product_name, // $full_address, // ); // $data[] = $user_data; // //$kk= count($data1); // // } // } // //$data[] =$data1; // // Sort the data by registration date // usort($data, function ($a, $b) { // return strtotime($a[2]) - strtotime($b[2]); // }); // // Set the CSV filename // $csvFileName = 'report.csv'; // // Set headers to prompt a download // header('Content-Type: text/csv'); // header('Content-Disposition: attachment; filename="' . $csvFileName . '"'); // // Open a temporary file pointer // $tempFile = fopen('php://temp', 'w'); // // Write data to the temporary file // foreach ($data as $row) { // fputcsv($tempFile, $row); // } // // Rewind the temporary file pointer // rewind($tempFile); // // Output the contents of the temporary file to the browser // fpassthru($tempFile); // // Close the temporary file // fclose($tempFile); // // Exit to prevent additional output // //echo 'CSV file created successfully at: ' . $csvFilePath; // exit(); // } else { // // User is not an administrator // echo "

You have not permission to download report. Plaese Login as a admin!

"; // } // } else { // echo "

You are not logedin. Please login first for download report!

"; // }