break; /** IMPORT COUPONS */ /** IMPORT COUPONS */ case 'import_coupons': if (empty($_POST['id'])) { echo '<div class="a-error">Select coupons that you want to import.</div>'; echo '<a href="#" class="btn" onclick="window.history.go(-1)">Back</a>'; } else { if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['token']) && check_csrf($_POST['token'], 'cjapi_csrf')) { $success = $error = 0; foreach ($_POST['coupon'] as $coupon) { $coupon = json_decode(urldecode($coupon), true); $id = key($coupon); $coupon = current($coupon); if (isset($_POST['id'][$id])) { if (($store = \plugin\CJApi\inc\import::store_imported($coupon['Advertiser'])) && \plugin\CJApi\inc\actions::add_item(array('cjID' => $id, 'store' => $store->ID, 'category' => $store->catID, 'popular' => 0, 'exclusive' => 0, 'name' => $coupon['Title'], 'link' => isset($coupon['Link']) && filter_var($coupon['Link'], FILTER_VALIDATE_URL) ? $coupon['Link'] : '', 'code' => isset($coupon['Code']) ? $coupon['Code'] : '', 'description' => '', 'tags' => '', 'start' => isset($coupon['SD']) ? $coupon['SD'] : '', 'end' => isset($coupon['ED']) ? $coupon['ED'] : date('Y-m-d', strtotime(\query\main::get_option('cj_exp') . ' days')), 'publish' => 1, 'meta_title' => '', 'meta_desc' => ''))) { $success++; } else { $error++; } } } echo '<div class="a-message">Import procedure has been successfully finished.</div>'; echo '<ul class="announce-box"> <li>Imported:<b>' . $success . '</b></li> <li>Errors:<b>' . $error . '</b></li> </ul>'; } echo '<a href="#" class="btn" onclick="window.history.go(-1)">Back</a>'; } break;