forked from wp-sms/wp-sms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.php
52 lines (40 loc) · 1.46 KB
/
import.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
include_once dirname( __FILE__ ) . "/includes/classes/excel-reader.class.php";
global $wpdb, $table_prefix;
$get_mobile = $wpdb->get_col( "SELECT `mobile` FROM {$table_prefix}sms_subscribes" );
$result = [];
$duplicate = [];
if ( isset( $_POST['wps_import'] ) ) {
if ( ! $_FILES['wps-import-file']['error'] ) {
$data = new Spreadsheet_Excel_Reader( $_FILES["wps-import-file"]["tmp_name"] );
foreach ( $data->sheets[0]['cells'] as $items ) {
// Check and count duplicate items
if ( in_array( $items[2], $get_mobile ) ) {
$duplicate[] = $items[2];
continue;
}
// Count submitted items.
$total_submit[] = $data->sheets[0]['cells'];
$result = $wpdb->insert( "{$table_prefix}sms_subscribes",
array(
'date' => WP_SMS_CURRENT_DATE,
'name' => $items[1],
'mobile' => $items[2],
'status' => '1',
'group_ID' => $_POST['wpsms_group_name']
)
);
}
if ( $result ) {
echo "<div class='updated'><p>" . sprintf( __( '<strong>%s</strong> items was successfully added.', 'wp-sms' ), count( $total_submit ) ) . "</div></p>";
}
if ( $duplicate ) {
echo "<div class='error'><p>" . sprintf( __( '<strong>%s</strong> Mobile numbers Was repeated.', 'wp-sms' ), count( $duplicate ) ) . "</div></p>";
}
} else {
echo "<div class='error'><p>" . __( 'Please complete all fields', 'wp-sms' ) . "</div></p>";
}
}