Changeset 2565526
- Timestamp:
- 07/16/2021 12:54:37 AM (5 years ago)
- Location:
- service/trunk
- Files:
-
- 6 edited
-
includes/api.php (modified) (1 diff)
-
includes/function.php (modified) (4 diffs)
-
pages/orders.php (modified) (5 diffs)
-
readme.txt (modified) (2 diffs)
-
service.php (modified) (3 diffs)
-
uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
service/trunk/includes/api.php
r2564723 r2565526 1 1 <?php 2 3 class 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 } 2 38 3 39 add_action('rest_api_init', function (){ -
service/trunk/includes/function.php
r2564723 r2565526 1 1 <?php 2 3 add_action('wp_ajax_imei', function (){ 4 (new imei())->get_data($_GET['imei']); 5 }); 2 6 3 7 add_action('wp_ajax_insert_client_number', function (){ … … 17 21 if (current_user_can('manage_options')) { 18 22 global $wpdb; 19 $data = 0;23 $data[] = 0; 20 24 foreach ($_GET['delete'] as $del_id) { 21 25 $data[] = $del_id; … … 26 30 wp_send_json('Not enough rights to delete an object!'); 27 31 } 32 }); 33 34 add_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'])))) ]); 28 50 }); 29 51 … … 44 66 wp_send_json($res); 45 67 }); 68 69 70 //settings page 71 add_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 77 add_action('wp_ajax_get_api_keys', function (){ 78 wp_send_json( ['imeiApiKey' => get_option('service_imei_api_key')] ); 79 }); 80 81 add_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 39 39 40 40 } 41 42 43 41 </style> 44 42 <div class="wrap"> 45 46 43 47 44 <div class="overlay" id="popup"> … … 139 136 }; 140 137 141 function num status(arr, status){138 function numberToStatus(arr, status){ 142 139 for (let i of Object.keys(arr)) { 143 140 if( arr[i] === status ) return i; … … 146 143 } 147 144 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 148 174 $('#number').mask('+7(999) 999-99-99', { 149 175 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 } 150 196 }); 151 197 … … 177 223 }).done(function(data){ 178 224 if (data.id){ 225 print('service_print_receipt', data.id); 179 226 $("#serial").val(''); $("#model").val(''); $("#malfunction").val(''); $("#client").val(''); $("#number").val(''); $("#cost_total").val(''); $("#manager_notes").val(''); 180 227 $('#popup').fadeOut(1000); … … 371 418 let cost_spare = $(this).closest('tr').find('.cost_spare').val(); 372 419 let cost_total = $(this).closest('tr').find('.cost_total').val(); 373 let status = Number(num status(orderStatus, $(this).find(':selected').text()));420 let status = Number(numberToStatus(orderStatus, $(this).find(':selected').text())); 374 421 let val = this; 375 422 $.post(ajaxurl, {action: 'update_order_info','status':status, 'id':id, 'work':work, 'cost_spare':cost_spare, 'cost_total':cost_total}, function(data){ 376 423 $(val).closest('tr').css('backgroundColor', (data) ? 'green' : 'red'); 424 if(status===7){ 425 print('service_print_warranty', id); 426 } 377 427 table.ajax.reload(); 378 428 }); -
service/trunk/readme.txt
r2564723 r2565526 4 4 Requires at least: 4.7 5 5 Tested up to: 5.7.2 6 Stable tag: 1.0. 06 Stable tag: 1.0.1 7 7 Requires PHP: 7.4 8 8 License: GPLv2 or later … … 13 13 14 14 == 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 15 22 = 1.0.0 = 16 23 Initial release. -
service/trunk/service.php
r2564723 r2565526 5 5 * Plugin URI: https://wordpress.org/plugins/service/ 6 6 * Description: The CRM for service center 7 * Version: 1.0. 07 * Version: 1.0.1 8 8 * Requires at least: 5.7.2 9 9 * Requires PHP: 7.4 … … 49 49 remove_submenu_page('service.php','service.php'); 50 50 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 60 add_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__)); 57 70 } ); 58 71 }); … … 89 102 get_role('administrator' )->add_cap( 'service_user' ); 90 103 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'); 91 116 }); 92 117 -
service/trunk/uninstall.php
r2564723 r2565526 6 6 global $wpdb; 7 7 $wpdb->query("DROP TABLE IF EXISTS ". $wpdb -> prefix.'service_orders'); 8 9 delete_option('service_print_receipt'); 10 delete_option('service_print_warranty'); 11 delete_option( 'service_imei_api_key');
Note: See TracChangeset
for help on using the changeset viewer.