Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function wp_unexapi_admin_url() {
- echo"
- <style>
- span#ta-ad{font-size:20px;font-weight:bold;color:#009688;}
- span#me1-url{color:gray;font-weight:bold;}
- span#me-url{color:gray;font-weight:bold;}
- input.admin-input{-webkit-border-radius: 5px;
- -moz-border-radius: 5px;
- border-radius: 5px;}
- input.admin-input:focus{border-color: #009688;box-shadow: 0 0 2px rgba(0, 150, 136, 1);}
- input.admin-submit{cursor:pointer;border:none;color:white;background-color:#009688;-webkit-transition:all .3s ;
- -moz-transition:all .3s ;
- -o-transition:all .3s ;
- transition:all .3s ;
- -webkit-border-radius: 5px;
- -moz-border-radius: 5px;
- border-radius: 5px;text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);box-shadow:none;}
- input.admin-submit:hover{background-color:#006a60;-webkit-box-shadow: 0px 0px 10px 2px rgba(0,0,0,0.75);
- -moz-box-shadow: 0px 0px 10px 2px rgba(0,0,0,0.75);
- box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.5);border:none;}
- .b-box{display:inline-block;padding:3px 6px;border:2px solid #009688;-webkit-border-radius: 5px;
- -moz-border-radius: 5px;
- border-radius: 5px;}
- </style>
- ";
- $aa = get_option( "unexapi-url" );
- if(isset($_POST['unexapi-url'])){
- update_option( "unexapi-url", $_POST["unex-url"], "no" );
- $aa = get_option( "unexapi-url" );
- echo '<div class="notice notice-success is-dismissible">
- <p>آدرس جدید ذخیره شد.</p>
- </div>';
- }
- echo '
- <br><br>
- <span id="ta-ad">تغییر آدرس</span>
- <br><hr><br>
- <form name="sea-l-form" class="form-horizontal" method="POST" action="" id="form-l">
- آدرس :
- <input type="text" class="admin-input" name="unex-url" required> <br>
- <input type="hidden" name="unexapi-url" value="1"/>
- <input type="submit" style="margin-right:42px;margin-top:7px;" class="admin-submit" value="اعمال تغییرات"/>
- </form>
- <br>
- <div class="b-box">
- <span id="me1-url">آدرس فعلی :</span><br><hr>
- <span id="me-url">'.$aa.'</span><br>
- </div>
- ';
- }
- function wp_unexapi_admin_auth() {
- echo"
- <style>
- span#ta-ad{font-size:20px;font-weight:bold;color:#009688;}
- span#me1-url{color:gray;font-weight:bold;}
- span#me-url{color:gray;font-weight:bold;}
- input.admin-input{-webkit-border-radius: 5px;
- -moz-border-radius: 5px;
- border-radius: 5px;}
- input.admin-input:focus{border-color: #009688;box-shadow: 0 0 2px rgba(0, 150, 136, 1);}
- input.admin-submit{cursor:pointer;border:none;color:white;background-color:#009688;-webkit-transition:all .3s ;
- -moz-transition:all .3s ;
- -o-transition:all .3s ;
- transition:all .3s ;
- -webkit-border-radius: 5px;
- -moz-border-radius: 5px;
- border-radius: 5px;text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);box-shadow:none;}
- input.admin-submit:hover{background-color:#006a60;-webkit-box-shadow: 0px 0px 10px 2px rgba(0,0,0,0.75);
- -moz-box-shadow: 0px 0px 10px 2px rgba(0,0,0,0.75);
- box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.5);border:none;}
- .b-box{display:inline-block;padding:3px 6px;border:2px solid #009688;-webkit-border-radius: 5px;
- -moz-border-radius: 5px;
- border-radius: 5px;}
- </style>
- ";
- $aa = get_option( "unexapi-username" );
- $bb = get_option( "unexapi-password" );
- if(isset($_POST['unexapi-auth'])){
- update_option( "unexapi-username", $_POST["unex-auth-user"], "no" );
- update_option( "unexapi-password", $_POST["unex-auth-pass"], "no" );
- $aa = get_option( "unexapi-username" );
- $bb = get_option( "unexapi-password" );
- echo '<div class="notice notice-success is-dismissible">
- <p>تنظیمات کاربری ذخیره شد.</p>
- </div>';
- }
- echo '
- <br><br>
- <span id="ta-ad">تغییر کاربری</span>
- <br><hr><br>
- <form name="unex-2-form" method="POST" action="">
- username :
- <input type="text" class="admin-input" name="unex-auth-user" required> <br>
- password :
- <input type="text" class="admin-input" name="unex-auth-pass" required> <br>
- <input type="hidden" name="unexapi-auth" value="1"/>
- <input type="submit" class="admin-submit" style="margin-right:67px;margin-top:7px;" value="اعمال تغییرات"/>
- </form>
- <br>
- <div class="b-box">
- <span id="me1-url">اطلاعات کاربری فعلی :</span><br><hr>
- <span id="me-url">'.$aa.' : username</span><br>
- <span id="me-url">'.$bb.' : password</span>
- </div>
- ';
- }
- function wp_unexapi_admin_sync() {
- echo"
- <style>
- span#ta-ad{font-size:20px;font-weight:bold;color:#009688;}
- span#me1-url{color:gray;font-weight:bold;}
- span#me-url{color:gray;font-weight:bold;text-align:right;}
- input.admin-input{width:50px;-webkit-border-radius: 5px;
- -moz-border-radius: 5px;
- border-radius: 5px;}
- input.admin-input:focus{border-color: #009688;box-shadow: 0 0 2px rgba(0, 150, 136, 1);}
- a#admin-submit{font-size: 14px;text-decoration:none;cursor:pointer;border:none;color:white;background-color:#009688;-webkit-transition:all .3s ;
- -moz-transition:all .3s ;
- -o-transition:all .3s ;
- transition:all .3s ;
- -webkit-border-radius: 5px;
- -moz-border-radius: 5px;
- border-radius: 5px;text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);box-shadow:none;padding:4px 6px;}
- a#admin-submit:hover{background-color:#006a60;-webkit-box-shadow: 0px 0px 10px 2px rgba(0,0,0,0.75);
- -moz-box-shadow: 0px 0px 10px 2px rgba(0,0,0,0.75);
- box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.5);border:none;}
- .b-box{display:inline-block;padding:3px 6px;border:2px solid #009688;-webkit-border-radius: 5px;
- -moz-border-radius: 5px;
- border-radius: 5px;}
- input.admin-submit{display:inline-block;cursor:pointer;border:none;color:white;background-color:#009688;-webkit-transition:all .3s ;
- -moz-transition:all .3s ;
- -o-transition:all .3s ;
- transition:all .3s ;
- -webkit-border-radius: 5px;
- -moz-border-radius: 5px;
- border-radius: 5px;text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);box-shadow:none;}
- input.admin-submit:hover{background-color:#006a60;-webkit-box-shadow: 0px 0px 10px 2px rgba(0,0,0,0.75);
- -moz-box-shadow: 0px 0px 10px 2px rgba(0,0,0,0.75);
- box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.5);border:none;}
- </style>
- ";
- $aa = get_option( "unexapi-sync-hour" );
- if(isset($_POST['unexapi-sync'])){
- if(is_numeric($_POST["unex-sync-hour"])){
- update_option( "unexapi-sync-hour", $_POST["unex-sync-hour"], "no" );
- $aa = get_option( "unexapi-sync-hour" );
- echo '<div class="notice notice-success is-dismissible">
- <p>بازه زمانی ذخیره شد.</p>
- </div>';
- }else{
- echo '<div class="notice notice-error is-dismissible">
- <p>لطفا ساعت را با اعداد انگلیسی وارد کنید.</p>
- </div>';
- }
- }
- if(isset($_POST['unexapi-sync-fast'])){
- cron_job_changeprice_fast();
- echo '<div class="notice notice-success is-dismissible">
- <p>درخواست بروزرسانی با موفقیت ارسال شد.</p>
- </div>';
- }
- echo '
- <br><br>';
- if ( get_option( 'unexapi-sync-enable' ) == '0' ) {
- echo '<span id="ta-ad">بروزرسانی دوره ای</span>
- <form name="unex-88-form" method="POST" action="" style="display: inline;">
- <input type="hidden" name="unexapi-sync-enable0" value="1"/>
- <input type="submit" class="admin-submit" value="فعال کن" id="admin-submit" style="background-color:#383dff!important;"/>
- </form>
- <br><hr><br>
- <div class="notice notice-error">
- <p>بروزرسانی دوره ای غیرفعال میباشد .</p>
- </div>
- ';
- } elseif (get_option( 'unexapi-sync-enable' ) == '1') {
- echo '
- <span id="ta-ad">بروزرسانی دوره ای</span>
- <form name="unex-77-form" method="POST" action="" style="display: inline;">
- <input type="hidden" name="unexapi-sync-enable1" value="1"/>
- <input type="submit" class="admin-submit" value="غیر فعال کن" id="admin-submit" style="background-color:#ff3d4e!important;"/>
- </form>
- <br><hr><br>
- <form name="unex-3-form" method="POST" action="">
- بروزرسانی سیستم هر
- <input type="text" class="admin-input" name="unex-sync-hour" required>
- ساعت انجام می گیرد.
- <input type="hidden" name="unexapi-sync" value="1"/>
- <input type="submit" class="admin-submit" value="اعمال تغییرات"/>
- </form>
- <br>
- <div class="b-box">
- <span id="me1-url">زمانبندی فعلی هر</span> ' . $aa . ' <span id="me1-url">ساعت میباشد.</span>
- </div>';
- }
- echo '<br><br><br>
- <br>
- <br>
- <span id="ta-ad">بروزرسانی سریع</span>
- <br><hr><br>
- جهت بروز رسانی سیستم بدون زمان بندی از این بخش استفاده کنید.<br><br>';
- echo '
- <form name="unex-6-form" method="POST" action="" id="loader">
- ';
- $args = array(
- 'show_option_all' => 'تمامی دسته بندی ها',
- 'show_option_none' => '',
- 'option_none_value' => '-1',
- 'orderby' => 'name',
- 'order' => 'ASC',
- 'show_count' => 0,
- 'hide_empty' => 1,
- 'child_of' => 0,
- 'exclude' => '',
- 'include' => '',
- 'echo' => 1,
- 'selected' => 0,
- 'hierarchical' => 1,
- 'name' => 'unexcat',
- 'id' => '',
- 'class' => 'postform',
- 'depth' => 0,
- 'tab_index' => 0,
- 'taxonomy' => 'product_cat',
- 'hide_if_empty' => false,
- 'value_field' => 'term_id',
- );
- wp_dropdown_categories( $args );
- echo '<input type="hidden" name="unexapi-sync-fast" value="1"/>
- <input type="submit" id="loader" class="admin-submit" value="هم اکنون بروزرسانی کن !"/>
- </form>
- <input type="hidden" name="page_sku" value="1">
- <div class="loading"></div>
- <div class="alert-loader">
- <span id="now"></span> / <span id="all"></span><br>
- موفق <span id="accept"></span><br>
- ناموفق <span id="not-accept"></span><br>
- </div>
- <script>
- jQuery(document).ready(function(){
- function ajax_request(){
- jQuery.ajax({
- url: ajaxurl,
- type: \'POST\',
- cache: false,
- data: {
- \'action\':\'loader_check_sku\',
- \'page\': parseInt(jQuery("input[name=page_sku]").val()),
- \'limit\': 50,
- \'accept\': parseInt(jQuery("div.alert-loader span#accept").text()),
- \'not-accept\': parseInt(jQuery("div.alert-loader span#not-accept").text()),
- },
- dataType : "json",
- success:function(data) {
- if(data.end =="YES") {
- alert("End");
- } else {
- jQuery("div.alert-loader span#now").html(data.now);
- jQuery("div.alert-loader span#accept").html(data.ac);
- jQuery("div.alert-loader span#not-accept").html(data.nac);
- jQuery("input[name=page_sku]").val(data.page);
- ajax_request();
- return false;
- }
- },
- error: function(jqXHR, textStatus, errorThrown){
- alert("error");
- console.log(jqXHR);
- console.log(textStatus);
- console.log(errorThrown);
- }
- });
- }
- jQuery(document).on("submit", "form#loader", function (e) {
- e.preventDefault();
- //show Loadign
- jQuery(".loading").html("لطفا کمی صبر کنید ..").hide().fadeIn(1000);
- var formdata = new FormData($("#loader")[0]);
- formdata.append(\'action\', \'loader_check_sku\');
- formdata.append(\'page\', jQuery("input[name=page_sku]").val());
- formdata.append(\'accept\', \'\');
- formdata.append(\'not-accept\', \'\');
- jQuery.ajax({
- url: ajaxurl,
- type: \'POST\',
- processData: false,
- contentType: false,
- cache: false,
- data: formdata,
- dataType : "json",
- success:function(data) {
- if(data.end =="YES") {
- alert("End");
- } else {
- jQuery("div.alert-loader span#now").html(data.now);
- jQuery("div.alert-loader span#all").html(data.all);
- jQuery("div.alert-loader span#accept").text(data.ac);
- jQuery("div.alert-loader span#not-accept").text(data.nac);
- jQuery("input[name=page_sku]").val(data.page);
- ajax_request();
- }
- },
- error: function(jqXHR, textStatus, errorThrown){
- alert("error");
- }
- });
- // Do stuff
- return false;
- });
- });
- </script>
- ';
- }
- define('P_LIMIT', 20);
- function loader_check_sku(){
- global $wpdb, $post;
- if ( defined('DOING_AJAX') && DOING_AJAX ) {
- $page = $_POST['page'];
- $limit = P_LIMIT;
- $accept = $_POST['accept'];
- $not_accept = $_POST['not-accept'];
- $t['end'] = 'NO';
- if($page =="1") {
- $args = array(
- 'post_type' => array('product', 'product_variation'),
- 'post_status' => 'publish',
- 'meta_query' => array(
- array(
- 'key' => '_sku',
- 'value' => '',
- 'compare' => '!=',
- )
- )
- );
- $my_query = new WP_Query( $args );
- $t['all'] = $my_query->found_posts;
- $t['now'] = P_LIMIT;
- }
- //Query
- $args = array(
- 'post_type' => array('product', 'product_variation'),
- 'post_status' => 'publish',
- 'meta_query' => array(
- array(
- 'key' => '_sku',
- 'value' => '',
- 'compare' => '!=',
- )
- ),
- 'posts_per_page' => $limit,
- 'paged' => $page
- );
- $my_query = new WP_Query( $args );
- if($my_query->post_count >0) {
- while ( $my_query->have_posts() ) {
- $my_query->the_post();
- $client = new SoapClient( get_option( "unexapi-url" ), [ 'encoding' => 'UTF-8' ] );
- $result = $client->FindProductByCode(
- [
- 'userName' => get_option( "unexapi-username" ),
- 'password' => get_option( "unexapi-password" ),
- 'code' => get_post_meta( get_the_ID(), '_sku', true ),
- 'groupName' => "",
- ]
- );
- if ( $result->FindProductByCodeResult->Success == "" ) {
- $not_accept = $not_accept + 1;
- } else {
- $accept = $accept + 1;
- foreach ( $result->FindProductByCodeResult->ProductInfoList as $p ) {
- $toman_price = $p->UnitPrice / 10; // tabdil be toman
- $flag = "p";
- if ( $_POST['unexcat'] != 0 ) { //for all categories
- //$term_list = wp_get_post_terms('16716', 'product_cat', array("fields" => "all"));
- //echo '<pre>';
- //print_r($term_list);
- $taxonomy = "product_cat";
- $args = array( 'fields' => 'all' );
- $p_id = get_the_ID();
- if ( $post->post_parent != 0 ) {
- $p_id = wp_get_post_parent_id( get_the_ID() );
- }
- $terms = wp_get_post_terms( $p_id, $taxonomy, $args );
- //print_r($terms);
- $tr = $terms[0]->term_id;
- //echo $terms[0]->term_id;
- //echo "<br>";
- //exit;
- // echo $tr;
- $term_children = get_term_children( $_POST['unexcat'], 'product_cat' );
- //print_r($term_children);
- $term_children[] = $_POST['unexcat'];
- // print_r($term_children);
- if ( ! in_array( $tr, $term_children ) ) {
- $flag = "n";
- }
- }
- if ( $flag == "p" ) {
- if ( get_post_meta( get_the_ID(), '_sale_price', true ) == "" ) {
- $update_p = update_post_meta( get_the_ID(), '_price', $toman_price );
- $update_rp = update_post_meta( get_the_ID(), '_regular_price', $toman_price );
- if ( ( $update_p == true ) and ( $update_rp == true ) ) {
- if ( function_exists( 'rocket_clean_post' ) ) {
- //echo get_the_ID();
- rocket_clean_post( get_the_ID() );
- }
- }
- } else {
- $update_rp = update_post_meta( get_the_ID(), '_regular_price', $toman_price );
- if ( $update_rp == true ) {
- if ( function_exists( 'rocket_clean_post' ) ) {
- rocket_clean_post( get_the_ID() );
- }
- }
- }
- }
- }
- }
- }
- } else {
- $t['end'] ="YES";
- }
- $t['page'] = $page + 1;
- $t['now'] = $_POST['page'] * P_LIMIT;
- $t['ac'] = $accept;
- $t['nac'] = $not_accept;
- //echo $p->UnitPrice;
- //echo the_ID();
- //echo "<br>";
- wp_send_json($t);
- exit;
- }
- die();
- }
- add_action( 'wp_ajax_loader_check_sku', 'loader_check_sku' );
- function wp_unexapi_admin_archive(){
- global $wpdb;
- echo '
- <style>
- span#ta-ad{font-size:20px;font-weight:bold;color:#009688;}
- table.tmes{margin-top:20px;}
- table.tmes tr th, table.tmes tr td{text-align:center;}
- tr.list { -webkit-transition:all .3s ;
- -moz-transition:all .3s ;
- -o-transition:all .3s ;
- transition:all .3s }
- tr.list:hover { background-color:rgba(204,204,204,0.3); }
- .tablenav .tablenav-pages{float:none;}
- .tablenav{text-align:center!important;}
- #wpbody{margin-left:20px!important;}
- span.nog{color:red;}
- span.yesg{color:green;}
- </style>
- ';
- echo '
- <br><br>
- <span id="ta-ad">آرشیو بروزرسانی ها</span>
- <br><hr><br>';
- //**********************************pagination
- //include pagination
- include_once(dirname(__FILE__) . '/pagination.class.php');
- $items = $wpdb->get_var("SELECT COUNT(*) FROM `".$wpdb->prefix."unexapi_sync_archive");
- // $limit = "";
- //Show List
- if($items > 0) {
- $p = new wppagination;
- $p->items($items);
- $p->limit(PAGINATION_ANY_PAGE);
- $p->target('?page=wp-unexapi4');
- $p->currentPage($_GET[$p->paging]);
- $p->calculate();
- $p->parameterName('paging');
- $p->adjacents(1);
- $p->nextLabel('صفحه بعدی');
- $p->prevLabel('صفحه قبلی');
- if(!isset($_GET['paging'])) { $p->page = 1;} else { $p->page = $_GET['paging'];}
- $limit = "LIMIT " . ($p->page - 1) * $p->limit . ", " . $p->limit;
- }
- if($items >PAGINATION_ANY_PAGE) {
- echo'<div class="tablenav">
- <div class="tablenav-pages">';
- $p->show();
- echo'</div>
- </div>
- <div style="clear:both; margin-bottom:20px;"></div>';
- }
- //**********************************pagination
- echo'
- <table class="tmes widefat">
- <thead>
- <tr>
- <th>تاریخ</th>
- <th>ساعت</th>
- <th>بروزرسانی سریع</th>
- <th>بروزرسانی دوره ای</th>
- <th>وضعیت</th>
- </tr>
- </thead>
- <tbody>';
- $sql = "SELECT * FROM ".$wpdb->prefix."unexapi_sync_archive ORDER BY `id` DESC ".$limit;
- $Query2 = $wpdb->get_results($sql, ARRAY_A);
- $rowcount = count($Query2);
- if ($rowcount >0) {
- $radif = 0;
- foreach ( $Query2 as $row2 ) {
- date_default_timezone_set('Asia/Tehran');
- $date1 = jdate( "j F o" , $row2["date"] );
- //list($gy,$gm,$gd)=explode('-',date('Y-n-d'));
- //$j_date_string=gregorian_to_jalali($gy,$gm,$gd,'/');
- $time1 = jdate( "H:i" , $row2["date"] );
- $fastsync = "";
- $periodsync = "";
- if($row2["fast_sync"] == true){
- $fastsync = "<span class='yesg'><span class='dashicons dashicons-yes'></span></span>";
- }
- if($row2["period_sync"] == true){
- $periodsync = "<span class='yesg'><span class='dashicons dashicons-yes'></span></span>";
- }
- if($row2["status"] == true){
- $status = "<span class='yesg'><span class='dashicons dashicons-yes'></span>موفق</span>";
- } elseif($row2["status"] == false){
- $status = "<span class='nog'><span class='dashicons dashicons-no'></span>ناموفق</span>";
- }
- echo'<tr class="list">
- <th>'.$date1.'</th>
- <th>'.$time1.'</th>
- <th>'.$fastsync.'</th>
- <th>'.$periodsync.'</th>
- <th>'.$status.'</th>
- </tr>';
- }
- } else {
- echo'
- <tr>
- <th colspan="8">موردی یافت نشد !</th>
- </tr> ';
- }
- echo'
- </tbody>
- </table>';
- }
Add Comment
Please, Sign In to add comment