Plugin Directory

Changeset 2565526


Ignore:
Timestamp:
07/16/2021 12:54:37 AM (5 years ago)
Author:
serviceonline
Message:

Update before 1.0.1

Location:
service/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • service/trunk/includes/api.php

    r2564723 r2565526  
    11<?php
     2
     3class imei {
     4
     5    private $ApiKey;
     6    private string $ImeiApiUrl = 'https://imeidb.xyz/api';
     7
     8    public function __construct() {
     9        $this->ApiKey = get_option( 'service_imei_api_key' );
     10    }
     11
     12    public function get_data($imei){
     13        wp_send_json(json_decode(wp_remote_retrieve_body(wp_remote_get($this->ImeiApiUrl . '/imei/'.$imei.'?token=' . $this->ApiKey))));
     14    }
     15
     16    public function get_balance(){
     17        $result = json_decode(wp_remote_retrieve_body(wp_remote_get($this->ImeiApiUrl . '/balance?token=' . $this->ApiKey)));
     18        if ( $result->message != null) {
     19            echo 'Api imei: ';
     20            echo $result->message;
     21        } else {
     22            _e( 'Balance IMEI: ', 'service' );
     23            echo $result->balance.' '.$result->currency;
     24        }
     25    }
     26
     27    public function test_api_key($key): bool {
     28        if(json_decode(wp_remote_retrieve_body(wp_remote_get($this->ImeiApiUrl . '/balance?token='.$key)))->balance == null){
     29            update_option('service_imei_api_key_status', 'false');
     30            return false;
     31        } else {
     32            update_option('service_imei_api_key_status', 'true');
     33            return true;
     34        }
     35    }
     36
     37}
    238
    339add_action('rest_api_init', function (){
  • service/trunk/includes/function.php

    r2564723 r2565526  
    11<?php
     2
     3add_action('wp_ajax_imei', function (){
     4    (new imei())->get_data($_GET['imei']);
     5});
    26
    37add_action('wp_ajax_insert_client_number', function (){
     
    1721    if (current_user_can('manage_options')) {
    1822        global $wpdb;
    19         $data = 0;
     23        $data[] = 0;
    2024        foreach ($_GET['delete'] as $del_id) {
    2125            $data[] = $del_id;
     
    2630        wp_send_json('Not enough rights to delete an object!');
    2731    }
     32});
     33
     34add_action('wp_ajax_print_documents', function (){
     35    global $wpdb;
     36    $row = $wpdb->get_row( "SELECT id_label, serial, client, model, malfunction, number, work, cost_total FROM $wpdb->service_orders WHERE `id`= ".sanitize_text_field($_GET['id']), ARRAY_A );
     37    $replace_data =
     38        [
     39            '{id_label}'    => $row['id_label'],
     40            '{serial}'      => $row['serial'],
     41            '{date}'        => date_create($row['date'])->Format('d-m-Y'),
     42            '{client}'      => $row['client'],
     43            '{model}'       => $row['model'],
     44            '{malfunction}' => $row['malfunction'],
     45            '{number}'      => $row['number'],
     46            '{work}'        => $row['work'],
     47            '{cost_total}'  => $row['cost_total']
     48        ];
     49    wp_send_json([ 'html' => str_replace(array_keys($replace_data),array_values($replace_data),wp_unslash(get_option(sanitize_text_field($_GET['data'])))) ]);
    2850});
    2951
     
    4466    wp_send_json($res);
    4567});
     68
     69
     70//settings page
     71add_action('wp_ajax_save_settings', function (){
     72    update_option('service_print_receipt', $_POST['print_receipt_save'], false);
     73    update_option('service_print_warranty', $_POST['print_warranty_save'], false);
     74    update_option('service_imei_api_key', $_POST['imei_api_key_save'], false );
     75});
     76
     77add_action('wp_ajax_get_api_keys', function (){
     78    wp_send_json( ['imeiApiKey' => get_option('service_imei_api_key')] );
     79});
     80
     81add_action('wp_ajax_test_api_keys', function (){
     82    wp_send_json(['testImeiApiKey' => (new imei())->test_api_key($_GET['test_imei_api_key']) ]);
     83});
  • service/trunk/pages/orders.php

    r2564723 r2565526  
    3939
    4040    }
    41 
    42 
    4341</style>
    4442<div class="wrap">
    45 
    4643
    4744    <div class="overlay" id="popup">
     
    139136            };
    140137
    141             function numstatus(arr, status){
     138            function numberToStatus(arr, status){
    142139                for (let i of Object.keys(arr)) {
    143140                    if( arr[i] === status ) return i;
     
    146143            }
    147144
     145            function checkLuna(value){
     146                if (!/^\d{15}$/.test(value)) return false;
     147                let sum = 0;
     148                for (let i = 0; i < value.length; i++) {
     149                    let cardNum = parseInt(value[i]);
     150                    if ((value.length - i) % 2 === 0) {
     151                        cardNum = cardNum * 2;
     152                        if (cardNum > 9) {
     153                            cardNum = cardNum - 9;
     154                        }
     155                    }
     156                    sum += cardNum;
     157                }
     158                if(sum % 10 === 0){
     159                    return true;
     160                }
     161            }
     162
     163            function print(doc, id){
     164                $.getJSON(ajaxurl,{action: 'print_documents', data:doc, id:id}, function(data){
     165                    $('#print').remove();
     166                    $('<iframe>', {'id': 'print', 'style': 'width:0px; height:0px; border:0px;', 'srcdoc': data.html}).appendTo('body');
     167                    $('#print').load(function(){
     168                        this.contentWindow.print();
     169                        $(this).unbind('load');
     170                    });
     171                });
     172            }
     173
    148174            $('#number').mask('+7(999) 999-99-99', {
    149175                onComplete: function(){ $('#client').focus(); }
     176            });
     177
     178            $("#number").bind("input", function() {
     179                table.ajax.reload();
     180            });
     181
     182            $("#serial").bind("input", function() {
     183                const digits = this.value;
     184                if(checkLuna(digits) && <?php echo get_option('service_imei_api_key_status'); ?>){
     185                    $.getJSON(ajaxurl, {action:'imei', 'imei':$("#serial").val()}, function(data){
     186                        if (data.success === true){
     187                            $('#model').val(data.data.name);
     188                            $("#image").attr('src', data.data.device_image);
     189                            $('#image').show(1000);
     190                        } else {
     191                            $("#model").focus();
     192                            alert("The imei was not found in the database");
     193                        }
     194                    });
     195                }
    150196            });
    151197
     
    177223                }).done(function(data){
    178224                    if (data.id){
     225                        print('service_print_receipt', data.id);
    179226                        $("#serial").val(''); $("#model").val(''); $("#malfunction").val(''); $("#client").val(''); $("#number").val(''); $("#cost_total").val(''); $("#manager_notes").val('');
    180227                        $('#popup').fadeOut(1000);
     
    371418                let cost_spare = $(this).closest('tr').find('.cost_spare').val();
    372419                let cost_total = $(this).closest('tr').find('.cost_total').val();
    373                 let status = Number(numstatus(orderStatus, $(this).find(':selected').text()));
     420                let status = Number(numberToStatus(orderStatus, $(this).find(':selected').text()));
    374421                let val = this;
    375422                $.post(ajaxurl, {action: 'update_order_info','status':status, 'id':id, 'work':work, 'cost_spare':cost_spare, 'cost_total':cost_total}, function(data){
    376423                    $(val).closest('tr').css('backgroundColor', (data) ? 'green' : 'red');
     424                    if(status===7){
     425                        print('service_print_warranty', id);
     426                    }
    377427                    table.ajax.reload();
    378428                });
  • service/trunk/readme.txt

    r2564723 r2565526  
    44Requires at least: 4.7
    55Tested up to: 5.7.2
    6 Stable tag: 1.0.0
     6Stable tag: 1.0.1
    77Requires PHP: 7.4
    88License: GPLv2 or later
     
    1313
    1414== Changelog ==
     15
     16= 1.0.1 =
     17*Release Date - 16 Jul 2021*
     18
     19* Added print function
     20* Added function of receiving data about a device by imei number using an external API service
     21
    1522= 1.0.0 =
    1623Initial release.
  • service/trunk/service.php

    r2564723 r2565526  
    55 * Plugin URI:        https://wordpress.org/plugins/service/
    66 * Description:       The CRM for service center
    7  * Version:           1.0.0
     7 * Version:           1.0.1
    88 * Requires at least: 5.7.2
    99 * Requires PHP:      7.4
     
    4949    remove_submenu_page('service.php','service.php');
    5050    add_action( 'load-' . $page, function (){
    51         wp_enqueue_script( 'mask', plugins_url('/js/jquery.mask.min.js', __FILE__) );
    52         wp_enqueue_script( 'jquery-ui-autocomplete');
    53         wp_enqueue_script( 'datatables', plugins_url('/js/jquery.dataTables.min.js', __FILE__) );
    54         wp_enqueue_script( 'selectdatatables', plugins_url('/js/dataTables.select.min.js', __FILE__) );
    55         wp_enqueue_script( 'buttonsdatatables', plugins_url('/js/dataTables.buttons.min.js', __FILE__) );
    56         wp_enqueue_style( 'datatablescss', plugins_url('/js/jquery.dataTables.min.css', __FILE__) );
     51        wp_enqueue_script('mask', plugins_url('/js/jquery.mask.min.js', __FILE__));
     52        wp_enqueue_script('jquery-ui-autocomplete');
     53        wp_enqueue_script('datatables', plugins_url('/js/jquery.dataTables.min.js', __FILE__) );
     54        wp_enqueue_script('selectdatatables', plugins_url('/js/dataTables.select.min.js', __FILE__) );
     55        wp_enqueue_script('buttonsdatatables', plugins_url('/js/dataTables.buttons.min.js', __FILE__) );
     56        wp_enqueue_style('datatablescss', plugins_url('/js/jquery.dataTables.min.css', __FILE__) );
     57    } );
     58});
     59
     60add_action('admin_menu', function (){
     61    $page = add_submenu_page(
     62        'service.php',
     63        esc_html__('Settings', 'service'),
     64        esc_html__('Settings', 'service'),
     65        'manage_options',
     66        'settings',
     67        function() {include 'pages/settings.php';});
     68    add_action( 'load-' . $page, function (){
     69        wp_enqueue_script('mask', plugins_url('/js/jquery.mask.min.js', __FILE__));
    5770    } );
    5871});
     
    89102    get_role('administrator' )->add_cap( 'service_user' );
    90103
     104    if ( file_exists( __DIR__ . '/receipt.txt' ) ) {
     105        add_option( "service_print_receipt", file_get_contents( __DIR__ . '/receipt.txt', true ), '', false );
     106        wp_delete_file( __DIR__ . '/receipt.txt' );
     107    }
     108    if ( file_exists( __DIR__ . '/warranty.txt' ) ) {
     109        add_option( "service_print_warranty", file_get_contents( __DIR__ . '/warranty.txt', true ), '', false );
     110        wp_delete_file( __DIR__ . '/warranty.txt' );
     111    }
     112
     113    add_option('service_sms_api_key', '');
     114    add_option('service_imei_api_key', '');
     115    add_option('service_imei_api_key_status', 'false');
    91116});
    92117
  • service/trunk/uninstall.php

    r2564723 r2565526  
    66global $wpdb;
    77$wpdb->query("DROP TABLE IF EXISTS ". $wpdb -> prefix.'service_orders');
     8
     9delete_option('service_print_receipt');
     10delete_option('service_print_warranty');
     11delete_option( 'service_imei_api_key');
Note: See TracChangeset for help on using the changeset viewer.