function load_events_to_db() { global $wpdb; //$events_detail_tbl = get_option ( 'events_detail_tbl' ); $curdate = date("Y-m-j"); $month = date('M'); $day = date('j'); $year = date('Y'); $fieldseparator = ","; $lineseparator = "\n"; $csvfile = "../wp-content/uploads/groupons.csv"; function getCSVValues($string, $separator = ";") { global $wpdb; //$wpdb->show_errors(); $elements = explode($separator, $string); for ($i = 0; $i < count($elements); $i++) { $nquotes = substr_count($elements[$i], '"'); if ($nquotes % 2 == 1) { for ($j = $i + 1; $j < count($elements); $j++) { if (substr_count($elements[$j], '"') > 0) { // Put the quoted string's pieces back together again array_splice($elements, $i, $j - $i + 1, implode($separator, array_slice($elements, $i, $j - $i + 1))); break; } } } if ($nquotes > 0) { // Remove first and last quotes, then merge pairs of quotes $qstr =& $elements[$i]; $qstr = substr_replace($qstr, '', strpos($qstr, '"'), 1); $qstr = substr_replace($qstr, '', strrpos($qstr, '"'), 1); $qstr = str_replace('""', '"', $qstr); } } return $elements; } if (!file_exists($csvfile)) { echo "File not found. Make sure you specified the correct path.\n"; exit; } $file = fopen($csvfile, "r"); if (!$file) { echo "Error opening data file.\n"; exit; } $size = filesize($csvfile); if (!$size) { echo "File is empty.\n"; exit; } $file = file_get_contents($csvfile); $dataStrings = explode("\r", $file); $i = 0; foreach ($dataStrings as $data) { ++$i; for ($j = 0; $j < $i; ++$j) { $strings = getCSVValues($dataStrings[$j]); } print_r($strings); if (array_key_exists('2', $strings)) { //echo "The element is in the array"; //$skip = $strings[0]; //if ($skip >= "1"){ //Add event data $g_sql = "INSERT INTO " . EVENTS_GROUPON_CODES_TABLE . " (groupon_code, groupon_holder)"; $g_sql .= " VALUES ('{$strings['1']}', '{$strings['2']}')"; echo $g_sql; $wpdb->query($wpdb->prepare($g_sql)); $last_g_id = $wpdb->insert_id; print $wpdb->print_error(); //} } } unlink($csvfile); if (!file_exists($csvfile)) { echo "<br>\nUpload file has been deleted.<br>"; } $tot_records = $i - "2"; echo "Added a total of {$tot_records} events to the database.<br>"; }
<?php // (c) 2012 by Fredi Bach header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); session_start(); // Return Array $returnvalues = array(); if (isset($_POST['code']) && isset($_POST['recipient']) && $_POST['code'] == '123456') { // Array mit Feldern, die nicht in der Email angezeigt werden $hiddenElements = array("submit", "recipient", "subject", "jkit-requireds", "sort", "redirect", "env_report", "from", "reply-to", "key-names", "code"); $mailtext = ''; $requiredValues = getCSVValues($_POST['jkit-requireds'], ","); $keynames = array(); if (isset($_POST['key-names'])) { $ks = explode(',', trim($_POST['key-names'])); if (count($ks) > 0) { foreach ($ks as $k) { $s = explode(':', $k); $keynames[$s[0]] = $s[1]; } } } foreach ($_POST as $key => $val) { $val = trim($val); $val = utf8_decode(trim($val)); if (in_array($key, $requiredValues) && $val != '') { if (false !== ($arraykey = array_search($key, $requiredValues))) { if ($key == 'email' || $key == 'mailadresse') { if (reallyValidEmail($val)) {
function load_events_to_db() { global $wpdb, $current_user; $events_detail_tbl = get_option('events_detail_tbl'); $curdate = date("Y-m-j"); $month = date('M'); $day = date('j'); $year = date('Y'); $fieldseparator = ","; $lineseparator = "\n"; $csvfile = "../wp-content/uploads/events.csv"; if (!function_exists('espresso_member_data')) { $current_user->ID = 1; } function getCSVValues($string, $separator = ",") { global $wpdb; //$wpdb->show_errors(); $elements = explode($separator, $string); for ($i = 0; $i < count($elements); $i++) { $nquotes = substr_count($elements[$i], '"'); if ($nquotes % 2 == 1) { for ($j = $i + 1; $j < count($elements); $j++) { if (substr_count($elements[$j], '"') > 0) { // Put the quoted string's pieces back together again array_splice($elements, $i, $j - $i + 1, implode($separator, array_slice($elements, $i, $j - $i + 1))); break; } } } if ($nquotes > 0) { // Remove first and last quotes, then merge pairs of quotes $qstr =& $elements[$i]; $qstr = substr_replace($qstr, '', strpos($qstr, '"'), 1); $qstr = substr_replace($qstr, '', strrpos($qstr, '"'), 1); $qstr = str_replace('""', '"', $qstr); } } return $elements; } if (!file_exists($csvfile)) { echo "File not found. Make sure you specified the correct path.\n"; exit; } $file = fopen($csvfile, "r"); if (!$file) { echo "Error opening data file.\n"; exit; } $size = filesize($csvfile); if (!$size) { echo "File is empty.\n"; exit; } $file = file_get_contents($csvfile); $dataStrings = explode("\r", $file); $i = 0; $question_groups_rs = $wpdb->get_results("select * from " . EVENTS_QST_GROUP_TABLE . " where wp_user = "******" and system_group = 1"); $question_groups_ar = array(); foreach ($question_groups_rs as $question_group) { $question_groups_ar[] = $question_group->id; } $question_groups = serialize($question_groups_ar); foreach ($dataStrings as $data) { ++$i; for ($j = 0; $j < $i; ++$j) { $strings = getCSVValues($dataStrings[$j]); } //echo "valid is :'".$valid."'"; if (array_key_exists('2', $strings)) { //echo "The element is in the array"; $skip = $strings[0]; if ($skip >= "1") { // Event meta info - $event_meta = array(); $event_meta['default_payment_status'] = ""; $event_meta['venue_id'] = ''; $event_meta['additional_attendee_reg_info'] = 1; $event_meta['add_attendee_question_groups'] = unserialize($question_groups); $event_meta['date_submitted'] = date("Y-m-d H:i:s"); $event_meta = serialize($event_meta); //Add event data $events_sql = "INSERT INTO " . EVENTS_DETAIL_TABLE . " (event_name, event_desc, address, city, state, country, zip, phone, display_desc, event_identifier, "; $events_sql .= " start_date, end_date, reg_limit, allow_multiple, additional_limit, send_mail, is_active, conf_mail, registration_start, registration_end, question_groups,event_meta)"; $events_sql .= " VALUES ('{$strings['1']}', '{$strings['2']}', '{$strings['3']}', '{$strings['4']}', '{$strings['5']}', '{$strings['6']}', '{$strings['7']}', '{$strings['8']}', "; $events_sql .= " '{$strings['9']}','{$strings['10']}', '" . event_date_display($strings['11'], 'Y-m-d') . "', '" . event_date_display($strings['12'], 'Y-m-d') . "','{$strings['15']}', "; $events_sql .= " '{$strings['17']}', '{$strings['18']}', '{$strings['19']}', '{$strings['20']}', '{$strings['21']}','" . event_date_display($strings['22'], 'Y-m-d') . "', '" . event_date_display($strings['23'], 'Y-m-d') . "','" . $question_groups . "','" . $event_meta . "')"; // echo $events_sql; if ($wpdb->query($wpdb->prepare($events_sql, NULL)) === false) { print $wpdb->print_error(); } else { $last_event_id = $wpdb->insert_id; } //Add times data $times_sql = "INSERT INTO " . EVENTS_START_END_TABLE . " (event_id, start_time, end_time) VALUES ('" . $last_event_id . "', '" . date("h:i A", strtotime($strings[13])) . "', '" . date("h:i A", strtotime($strings[14])) . "')"; //echo $times_sql; //$wpdb->query ( $wpdb->prepare( $times_sql ) ); if ($wpdb->query($wpdb->prepare($times_sql, NULL)) === false) { print $wpdb->print_error(); } //Add price data $prices_sql = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost) VALUES ('" . $last_event_id . "', '{$strings['16']}')"; //echo $prices_sql; // $wpdb->query ( $wpdb->prepare( $prices_sql ) ); if ($wpdb->query($wpdb->prepare($prices_sql, NULL)) === false) { print $wpdb->print_error(); } } } } unlink($csvfile); if (!file_exists($csvfile)) { echo "<br>\r\nUpload file has been deleted.<br>"; } $tot_records = $i - "2"; echo "Added a total of {$tot_records} events to the database.<br>"; }