Guest User

Untitled

a guest
Mar 16th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.28 KB | None | 0 0
  1. <?php
  2. /**
  3. * AJAX for only backend of the tickets
  4. * @version 1.3.10
  5. */
  6. class evotx_admin_ajax{
  7. public function __construct(){
  8. $ajax_events = array(
  9. 'the_ajax_evotx_a1'=>'evotx_get_attendees',
  10. 'the_ajax_evotx_a3'=>'generate_csv',
  11. 'the_ajax_evotx_a55'=>'admin_resend_confirmation',
  12. 'evoTX_ajax_07'=>'get_ticektinfo_by_ID',
  13. 'the_ajax_evotx_a8'=>'emailing_attendees_admin',
  14. 'evotx_assign_wc_products'=>'assign_wc_products',
  15. 'evotx_save_assign_wc_products'=>'save_assign_wc_products',
  16. 'evotx_sales_insight'=>'evotx_sales_insight',
  17. );
  18. foreach ( $ajax_events as $ajax_event => $class ) {
  19. add_action( 'wp_ajax_'. $ajax_event, array( $this, $class ) );
  20. add_action( 'wp_ajax_nopriv_'. $ajax_event, array( $this, $class ) );
  21. }
  22. }
  23.  
  24. // assign WC Product to event ticket
  25. function assign_wc_products(){
  26. $wc_prods = new WP_Query(array(
  27. 'post_type'=>'product',
  28. 'posts_per_page'=>-1,
  29. 'tax_query' => array(
  30. array(
  31. 'taxonomy' => 'product_cat',
  32. 'field' => 'slug',
  33. 'terms' => 'ticket',
  34. ),
  35. ),
  36. )
  37. );
  38.  
  39. ob_start();
  40.  
  41. ?><div style='text-align:center;padding:15px'><?php
  42.  
  43. if($wc_prods->have_posts()):
  44. ?>
  45. <p><?php _e('Select a WC Product to assign this event ticket, instead of the already assigned WC Product','evotx');?><br/><br/>
  46. <i><?php _e('This event ticket is currently assigned to the below WC Product!','eventon');?></i><br/><code> (ID: <?php echo $_POST['wcid'];?>) <?php echo get_the_title($_POST['wcid']);?></code></p>
  47.  
  48. <select class='field' name='evotx_wcid'><?php
  49.  
  50. while($wc_prods->have_posts()): $wc_prods->the_post();
  51.  
  52. $selected = (!empty($_POST['wcid']) && $wc_prods->post->ID == $_POST['wcid'])? 'selected="selected"':'';
  53.  
  54. ?><option <?php echo $selected;?> value="<?php echo $wc_prods->post->ID;?>">(ID: <?php echo $wc_prods->post->ID;?>) <?php the_title();?></option><?php
  55. endwhile;
  56.  
  57. ?></select>
  58.  
  59. <br/><br/><p><i><?php _e('NOTE: When selecting a new WC Product be sure the product is published and can be assessible on frontend of your website','evotx');?></i></p>
  60. <p style='text-align:center; padding-top:10px;'>
  61. <span class='evo_btn evotx_submit_manual_wc_prod' data-eid="<?php echo $_POST['eid'];?>"><?php _e('Save Changes','eventon');?></span>
  62. </p>
  63. <?php
  64.  
  65. wp_reset_postdata();
  66. else:
  67. ?><p><?php _e('You do not have any items saved! Please add new!','eventon');?></p><?php
  68. endif;
  69.  
  70. echo "</div>";
  71.  
  72. echo json_encode(array('content'=>ob_get_clean(), 'status'=>'good')); exit;
  73.  
  74. }
  75.  
  76. function save_assign_wc_products(){
  77. $wcid = (int)$_POST['wcid'];
  78. $eid = (int)$_POST['eid'];
  79.  
  80. update_post_meta( $eid, 'tx_woocommerce_product_id', $wcid);
  81.  
  82. EVOTX()->functions->save_product_meta_values($wcid, $eid);
  83. EVOTX()->functions->assign_woo_cat($wcid);
  84.  
  85. $msg = __('Successfully Assigned New WC Product to Event Ticket!','evotx');
  86.  
  87. echo json_encode(array('msg'=> $msg, 'status'=>'good')); exit;
  88. }
  89.  
  90. // GET attendee list view for event
  91. function evotx_get_attendees(){
  92. global $evotx;
  93.  
  94. $nonce = $_POST['postnonce'];
  95. $status = 0;
  96. $message = $content = $json = '';
  97.  
  98. if(! wp_verify_nonce( $nonce, 'evotx_nonce' ) ){
  99. $status = 1; $message ='Invalid Nonce';
  100. }else{
  101.  
  102. ob_start();
  103.  
  104. $source = isset($_POST['source'])? $_POST['source']: false;
  105. $ri = (!empty($_POST['ri']) || $_POST['ri']=='0')? $_POST['ri']:'all'; // repeat interval
  106.  
  107. $EA = new EVOTX_Attendees();
  108. $json = $EA->get_tickets_for_event($_POST['eid'], $source);
  109.  
  110.  
  111. if(!count($json)>0){
  112. echo "<div class='evotx'>";
  113. echo "<p class='header nada'>".__('Could not find attendees with completed orders.','evotx')."</p>";
  114. echo "</div>";
  115. }
  116.  
  117. $content = ob_get_clean();
  118. }
  119.  
  120.  
  121. $return_content = array(
  122. 'attendees'=> array(
  123. 'tickets'=>$json,
  124. 'od_gc'=>$EA->_user_can_check(),
  125. 'source' =>$source,
  126. ),
  127. 'temp'=> EVO()->temp->get('evotx_view_attendees'),
  128. 'message'=> $message,
  129. 'status'=>$status,
  130. 'content'=>$content,
  131. );
  132.  
  133. echo json_encode($return_content);
  134. exit;
  135. }
  136.  
  137. // Download csv list of attendees
  138. function generate_csv(){
  139.  
  140. $e_id = (int)$_REQUEST['e_id'];
  141. $EVENT = new EVO_Event($e_id);
  142. $EVENT->get_event_post();
  143.  
  144. header('Content-Encoding: UTF-8');
  145. header("Content-type: text/csv");
  146. header("Content-Disposition: attachment; filename=".$EVENT->post_name."_".date("d-m-y").".csv");
  147. header("Pragma: no-cache");
  148. header("Expires: 0");
  149. echo "xEFxBBxBF"; // UTF-8 BOM
  150.  
  151.  
  152. $EA = new EVOTX_Attendees();
  153. $TN = $EA->get_tickets_for_event($e_id);
  154.  
  155. if($TN){
  156.  
  157. //$fp = fopen('file.csv', 'w');
  158. $csv_header = apply_filters('evotx_csv_headers',array(
  159. 'Name',
  160. //'Ticket Holder Name',
  161. 'Email Address',
  162. 'Company',
  163. 'Address',
  164. 'Phone',
  165. 'Ticket IDs',
  166. 'Seat Number',
  167. 'Quantity',
  168. 'Ticket Type',
  169. 'Event Time',
  170. 'Order Status',
  171. 'Ordered Date'
  172. ), $EVENT);
  173. $csv_head = implode(',', $csv_header);
  174. echo $csv_head."\n";
  175.  
  176. $index = 1;
  177.  
  178. // each customer
  179. foreach($TN as $tn=>$td){
  180.  
  181.  
  182. $evo_tix_id = explode('-', $tn);
  183. $seat_num = '';
  184. $seat_num = get_post_meta($evo_tix_id[0], 'Seat-Number',true);
  185.  
  186. $csv_data = apply_filters('evotx_csv_row',array(
  187. 'name'=> $td['n'],
  188. 'email'=> $td['e'],
  189. 'company'=> '"'. isset($td['company'])? $td['company']:''.'"',
  190. 'address'=> $td['aD'],
  191. 'phone'=> isset($td['phone'])? $td['phone']:'',
  192. 'ticket_number'=> $tn,
  193. 'seats'=>$seat_num,
  194. 'qty'=> '1',
  195. 'ticket_type'=> $td['type'],
  196. 'event_time'=> '"'.$td['oD']['event_time'].'"',
  197. 'order_status'=> $td['oS'],
  198. 'ordered_date'=> '"'. isset($td['oD']['ordered_date'])? $td['oD']['ordered_date']:''.'"',
  199. ), $tn, $td, $EVENT);
  200.  
  201. // process each data row
  202. foreach($csv_data as $field=>$val){ echo $val . ","; }
  203.  
  204. echo "\n";
  205. }
  206. }
  207.  
  208. }
  209.  
  210. // Email attendee list to someone
  211. function emailing_attendees_admin(){
  212. global $evotx, $eventon;
  213.  
  214. $eid = $_POST['eid'];
  215. $wcid = $_POST['wcid'];
  216. $type = $_POST['type'];
  217. $RI = !empty($_POST['repeat_interval'])? $_POST['repeat_interval']:'all'; // repeat interval
  218. $EMAILED = $_message_addition = false;
  219. $emails = array();
  220. $TA = new EVOTX_Attendees();
  221.  
  222. // email attendees list to someone
  223. if($type=='someone'){
  224.  
  225. // get the emails to send the email to
  226. $emails = explode(',', str_replace(' ', '', htmlspecialchars_decode($_POST['emails'])));
  227.  
  228. $TH = $TA->_get_tickets_for_event($eid,'order_status');
  229.  
  230. if(is_array($TH) && isset($TH['completed']) && count($TH['completed'])>0){
  231. ob_start();
  232.  
  233. // get event date time
  234. $datetime = new evo_datetime();
  235. $epmv = get_post_custom($eid);
  236. $eventdate = $datetime->get_correct_formatted_event_repeat_time($epmv, ($RI=='all'?'0':$RI));
  237.  
  238. echo "<p>Confirmed Guests for ".get_the_title($eid)." on ".$eventdate['start']."</p>";
  239. echo "<table style='padding-top:15px; width:100%;text-align:left'><thead><tr>
  240. <th>Ticket Holder</th>
  241. <th>Email Address</th>
  242. <th>Phone</th>
  243. <th>Ticket Number</th>
  244. </tr></thead>
  245. <tbody>";
  246. foreach($TH['completed'] as $tn=>$guest){
  247. echo "<tr><td>".$guest['n'] ."</td><td>".$guest['e']."</td><td>".$guest['phone']. "</td>
  248. <td>".$tn. "</td></tr>";
  249. }
  250. echo "</tbody></table>";
  251. $_message_addition = ob_get_clean();
  252. }else{
  253. ob_start();
  254. echo "<p>".__('There are no completed orders!','evotx')."</p>";
  255. $_message_addition = ob_get_clean();
  256. }
  257.  
  258. //print_r($_message_addition);
  259.  
  260. }elseif($type=='completed'){
  261. $TH = $TA->_get_tickets_for_event($eid,'order_status');
  262. foreach(array('completed') as $order_status){
  263. if(is_array($TH) && isset($TH[$order_status]) && count($TH[$order_status])>0){
  264. foreach($TH[$order_status] as $guest){
  265. $emails[] = $guest['e'];
  266. }
  267. }
  268. }
  269. }elseif($type=='pending'){
  270. $TH = $TA->_get_tickets_for_event($eid,'order_status');
  271. foreach(array('pending','on-hold') as $order_status){
  272. if(is_array($TH) && isset($TH[$order_status]) && count($TH[$order_status])>0){
  273. foreach($TH[$order_status] as $guest){
  274. $emails[] = $guest['e'];
  275. }
  276. }
  277. }
  278. }
  279.  
  280. // emaling
  281. if($emails){
  282. $email = new evotx_email();
  283. $messageBODY = "<div style='padding:15px'>".
  284. (!empty($_POST['message'])? html_entity_decode(stripslashes($_POST['message']) ).'<br/><br/>':'' ).
  285. ($_message_addition?$_message_addition:'') . "</div>";
  286.  
  287. $messageBODY = $email->get_evo_email_body($messageBODY);
  288. $from_email = $email->get_from_email_address();
  289.  
  290. $emails = array_unique($emails);
  291.  
  292. $args = array(
  293. 'html'=>'yes',
  294. 'to'=> $emails,
  295. 'type'=> ($type=='someone'? '':'bcc'),
  296. 'subject'=>$_POST['subject'],
  297. 'from'=>$from_email,
  298. 'from_name'=> $email->get_from_email_name(),
  299. 'from_email'=> $from_email,
  300. 'message'=>$messageBODY,
  301. );
  302.  
  303. //print_r($args);
  304.  
  305. $helper = new evo_helper();
  306. $EMAILED = $helper->send_email($args);
  307.  
  308. }
  309.  
  310. $return_content = array(
  311. 'status'=> ($EMAILED?'0':'did not go'), 'other'=>$args
  312. );
  313. echo json_encode($return_content);
  314. exit;
  315. }
  316.  
  317. // Resend Ticket Email
  318. // Used in both evo-tix and order post page
  319. function admin_resend_confirmation(){
  320. $order_id = false;
  321. $status = 'bad';
  322. $email = '';
  323.  
  324. // get order ID
  325. $order_id = (!empty($_POST['orderid']))? $_POST['orderid']:false;
  326. $ts_mail_errors = array();
  327.  
  328. if($order_id){
  329.  
  330. // use custom email if passed or else get email to send ticket from order information
  331. $email = !empty($_POST['email'])?
  332. $_POST['email']:
  333. get_post_meta($order_id, '_billing_email',true);
  334.  
  335. //print_r($email);
  336.  
  337. if(!empty($email)){
  338. $evoemail = new evotx_email();
  339. $send_mail = $evoemail->send_ticket_email($order_id, false, false, $email);
  340.  
  341. if($send_mail) $status = 'good';
  342.  
  343. if(!$send_mail){
  344. global $ts_mail_errors;
  345. global $phpmailer;
  346.  
  347. if (!isset($ts_mail_errors)) $ts_mail_errors = array();
  348.  
  349. if (isset($phpmailer)) {
  350. $ts_mail_errors[] = $phpmailer->ErrorInfo;
  351. }
  352. }
  353. }
  354. }
  355.  
  356. // return the results
  357. $return_content = array(
  358. 'status'=> $status,
  359. 'email'=>$email,
  360. 'errors'=>$ts_mail_errors,
  361. );
  362.  
  363. echo json_encode($return_content);
  364. exit;
  365. }
  366.  
  367. // get information for a ticket number
  368. function get_ticektinfo_by_ID(){
  369.  
  370. $tickernumber = $_POST['tickernumber'];
  371.  
  372. // decode base 64
  373. if( $this->_is_base64encoded($tickernumber) ){
  374. $tickernumber = base64_decode( $tickernumber );
  375. }
  376.  
  377. $content = $this->get_ticket_info($tickernumber);
  378.  
  379. $return_content = array(
  380. 'content'=>$content,
  381. 'status'=> ($content? 'good':'bad'),
  382. );
  383.  
  384. echo json_encode($return_content);
  385. exit;
  386.  
  387. }
  388.  
  389. function _is_base64encoded($data){
  390. if (preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $data)) {
  391. return TRUE;
  392. } else {
  393. return FALSE;
  394. }
  395. }
  396.  
  397. function get_ticket_info($ticket_number){
  398. if(strpos($ticket_number, '-') === false) return false;
  399.  
  400. $tixNum = explode('-', $ticket_number);
  401.  
  402. if(!get_post_status($tixNum[0])) return false;
  403.  
  404. $tixPMV = get_post_custom($tixNum[0]);
  405.  
  406. ob_start();
  407.  
  408. $evotx_tix = new evotx_tix();
  409. $EA = new EVOTX_Attendees();
  410.  
  411. $tixPOST = get_post($tixNum[0]);
  412. $orderStatus = get_post_status($tixPMV['_orderid'][0]);
  413. $orderStatus = str_replace('wc-', '', $orderStatus);
  414.  
  415. $ticket_holder = $EA->get_attendee_by_ticket_number($ticket_number);
  416. $ticket_status = isset($ticket_holder['s'])? $ticket_holder['s']: 'check-in';
  417.  
  418. echo "<p><em>".__('Ticket Purchased By','evotx').":</em> {$tixPMV['name'][0]}</p>";
  419.  
  420. // additional ticket holder associated names
  421. if(!empty($ticket_holder))
  422. echo "<p><em>".__('Ticket Holder','evotx').":</em> {$ticket_holder['n']}</p>";
  423.  
  424. echo "<p><em>".__('Email Address','evotx').":</em> {$tixPMV['email'][0]}</p>
  425. <p><em>".__('Event','evotx').":</em> ".get_the_title($tixPMV['_eventid'][0])."</p>
  426. <p><em>".__('Purchase Date','evotx').":</em> ".$tixPOST->post_date."</p>
  427. <p><em>".__('Ticket Status','evotx').":</em> <span class='tix_status {$ticket_status}' data-tiid='{$tixNum[0]}' data-tid='{$ticket_number}' data-status='{$ticket_status}'>{$ticket_status}</span></p>
  428. <p><em>".__('Payment Status','evotx').":</em> {$orderStatus}</p>";
  429.  
  430. // other tickets in the same order
  431. $otherTickets = $evotx_tix->get_other_tix_order($ticket_number);
  432.  
  433. if(is_array($otherTickets) && count($otherTickets)>0){
  434. echo "<div class='evotx_other_tickets'>";
  435. echo "<p >".__('Other Tickets in the same Order','evotx')."</p>";
  436. foreach($otherTickets as $num=>$status){
  437. echo "<p><em>".__('Ticekt Number','evotx').":</em> ".$num."</p>";
  438. echo "<p style='padding-bottom:10px;'><em>".__('Ticekt Status','evotx').":</em> <span class='tix_status {$status}' data-tiid='{$tixNum[0]}' data-tid='{$num}' data-status='{$status}'>{$status}</span></p>";
  439. }
  440. echo "</div>";
  441. }
  442.  
  443. return ob_get_clean();
  444. }
  445.  
  446. // Sales Insight
  447. function evotx_sales_insight(){
  448.  
  449. ob_start();
  450.  
  451. $event_id = $_POST['event_id'];
  452.  
  453. date_default_timezone_set('UTC');
  454.  
  455. $EVENT = new evotx_event($event_id);
  456. $curSYM = get_woocommerce_currency_symbol();
  457.  
  458. // event time
  459. if( !$EVENT->is_repeating_event()){
  460. ?>
  461. <div class='evotxsi_row timetoevent'>
  462. <?php if( $EVENT->is_current_event('start')):
  463.  
  464. $timenow = current_time( 'timestamp' );
  465.  
  466. $start = $EVENT->get_prop('evcal_srow');
  467.  
  468. $dif = $start - $timenow;
  469.  
  470. ?>
  471. <p><?php _e('Time left till event start','evotx');?> <span class='static_field'><?php echo $this->get_human_time($dif);?></span></p>
  472. <?php else:?>
  473. <p><?php _e('Event has already started!','evotx');?></p>
  474. <?php endif;?>
  475. </div>
  476. <?php
  477. }
  478.  
  479. // sales by ticekt order
  480. $remainging_tickets = is_bool( $EVENT->has_tickets() )? 0: $EVENT->has_tickets();
  481. $orders = new WP_Query(array(
  482. 'post_type'=>'evo-tix',
  483. 'posts_per_page'=>-1,
  484. 'meta_query'=>array(
  485. array(
  486. 'key'=>'_eventid',
  487. 'value'=>$event_id
  488. )
  489. )
  490. ));
  491.  
  492. $sales_data = array();
  493. $total_tickets_sold = 0;
  494.  
  495. $processed_order_ids = array();
  496.  
  497. if($orders->have_posts()):
  498. while($orders->have_posts()): $orders->the_post();
  499.  
  500. $order_id = get_post_meta($orders->post->ID, '_orderid', true);
  501.  
  502. // check if order post exists
  503. $order_status = get_post_status($order_id);
  504. if(!$order_status) continue;
  505.  
  506. if(in_array($order_id, $processed_order_ids)) continue;
  507.  
  508. $order = new WC_Order( $order_id );
  509.  
  510. if(sizeof( $order->get_items() ) <= 0) continue;
  511.  
  512. // for each ticket item in the order
  513. $_order_qty = $_order_cost = 0;
  514. foreach($order->get_items() as $item_id=>$item){
  515. $_order_event_id = ( isset($item['_event_id']) )? $item['_event_id']:'';
  516. $_order_event_id = !empty($_order_event_id)? $_order_event_id: get_post_meta( $item['product_id'], '_eventid', true);
  517. if(empty($_order_event_id)) continue; // skip non ticket items
  518.  
  519. if($_order_event_id != $event_id) continue;
  520.  
  521.  
  522. $_order_qty += (int)$item['qty'];
  523. $_order_cost += floatval($item['subtotal']);
  524.  
  525. }
  526.  
  527. $total_tickets_sold += $_order_qty;
  528. $processed_order_ids[] = $order_id;
  529.  
  530. $order_time = get_the_date('U', $order_id);
  531. $billing_country = get_post_meta($order_id, '_billing_country',true);
  532.  
  533. $sales_data[$orders->post->ID] = array(
  534. 'qty'=>$_order_qty,
  535. 'cost'=>$_order_cost,
  536. 'status'=>$order->get_status(),
  537. 'country'=>$billing_country,
  538. 'time'=> $order_time
  539. );
  540.  
  541. endwhile;
  542. wp_reset_postdata();
  543. endif;
  544.  
  545. //print_r($sales_data);
  546.  
  547. // sales by order status
  548. if(sizeof($sales_data)>0){
  549.  
  550. ?>
  551. <div class='evotxsi_row sales_by_status'>
  552. <h2 style='margin:10px 0 30px; font-weight:bold'><?php _e('Ticket sales by ticket order status','evotx');?></h2>
  553. <p>
  554. <span>
  555. <b><?php echo $total_tickets_sold + $remainging_tickets ;?></b>
  556. <em><?php echo $remainging_tickets==0? __('No capacity limit','evotx'):'';?></em>
  557. <?php _e('Total Event Capacity','evotx');?>
  558. </span>
  559.  
  560. <?php foreach(array(
  561. 'wc-completed'=> __('Tickets Sold','evotx'),
  562. 'wc-onhold'=> __('Pending','evotx'),
  563. 'wc-cancelled'=> __('Cancelled','evotx'),
  564. 'wc-refunded'=> __('Refunded','evotx'),
  565.  
  566. ) as $type=>$name):?>
  567. <span class='<?php echo $type;?>'>
  568. <?php
  569. $_qty = $_cost = 0;
  570. foreach($sales_data as $oid=>$d){
  571.  
  572. if( $type == 'wc-onhold'){
  573. if(!in_array('wc-'.$d['status'], array('wc-on-hold','wc-pending','wc-processing','wc-failed')) ) continue;
  574. }else{
  575. if('wc-'.$d['status'] != $type) continue;
  576. }
  577.  
  578.  
  579. $_qty += (int)$d['qty'];
  580. $_cost += floatval($d['cost']);
  581. }
  582. ?>
  583. <b><?php echo $_qty;?></b><em><?php echo $curSYM.number_format($_cost,2,'.','');?></em>
  584. <i><?php echo $name;?></i>
  585. </span>
  586. <?php endforeach;?>
  587. </p>
  588. </div>
  589. <div class='evotxsi_row sales_by_time'>
  590. <h2><?php _e('Ticket sales based on the time of ticket sale','evotx');?></h2>
  591. <h3><?php _e('* Time in relation to current time','evotx');?></h3>
  592. <p style='padding:30px 50px'>
  593. <?php
  594.  
  595. // time adjust markup
  596. //$event_start = $EVENT->get_event_time('start');
  597.  
  598. $time_adjust = current_time('timestamp');
  599.  
  600. foreach(array(
  601. array(4838400,10000000,__('2+ Month ago','evotx')),
  602. array(2419200,4838400,__('1-2 Month ago','evotx')),
  603. array(1209600,2419200,__('2-4 Weeks ago','evotx')),
  604. array(604800,1209600,__('1-2 Weeks ago','evotx')),
  605. array(259200,604800,__('3-7 Days Ago','evotx')),
  606. array(86400,259200,__('1-3 Days Ago','evotx')),
  607. array(0,86400,__('Within 1 Day','evotx')),
  608. ) as $val){
  609.  
  610. $_qty = $_cost = 0;
  611.  
  612. $index = 0;
  613. foreach( $sales_data as $oid=>$d){
  614. $order_time = $time_adjust - $d['time'] ;
  615.  
  616.  
  617. // if order start is equal or greater and order end if less than
  618. if( $order_time >= $val[0] && $order_time < $val[1] ){
  619. $_qty += $d['qty'];
  620. $_cost += $d['cost'];
  621. }
  622. $index++;
  623. }
  624.  
  625. $total = $total_tickets_sold + $remainging_tickets;
  626. $width = ($total_tickets_sold==0)? 0: number_format( (($_qty/$total) *100), 2);
  627.  
  628. ?>
  629. <span><b><?php echo $val[2];?></b>
  630. <em><b style='width:<?php echo $width;?>%'></b></em>
  631. <i><b><?php echo $_qty;?></b> <?php echo $curSYM.number_format($_cost,2,'.','');?></i>
  632. </span>
  633. <?php
  634. }
  635. ?>
  636. </p>
  637. </div>
  638. <div class='evotxsi_row sales_by_country'>
  639. <h2><?php _e('Sales by customer location','evotx');?></h2>
  640. <h3><?php _e('Top 3 countries where customers have placed orders from','evotx');?></h3>
  641. <p style='padding-top:10px'>
  642. <?php
  643.  
  644. $_country_data = array();
  645.  
  646. foreach( $sales_data as $oid=>$d){
  647.  
  648. if(!isset($d['country'])) continue;
  649.  
  650. $_country_data[ $d['country']]['qty'] = isset($_country_data[ $d['country']]['qty'])?
  651. $_country_data[ $d['country']]['qty'] + $d['qty'] : $d['qty'];
  652.  
  653. $_country_data[ $d['country']]['cost'] = isset($_country_data[ $d['country']]['cost'])?
  654. $_country_data[ $d['country']]['cost'] + $d['cost'] : $d['cost'];
  655.  
  656. }
  657.  
  658. //$_country_data['CA']= array('qty'=>'3','cost'=>'70');
  659. //$_country_data['SL']= array('qty'=>'12','cost'=>'120');
  660.  
  661. $country_qty = array();
  662. foreach($_country_data as $key=>$row){
  663. $country_qty[ $key] = $row['qty'];
  664. }
  665.  
  666. array_multisort( $country_qty, SORT_DESC,$_country_data );
  667.  
  668. $index = 0;
  669. foreach($_country_data as $country=>$data){
  670. ?>
  671. <span style='opacity:<?php echo 1- ($index*0.3);?>'>
  672. <em><?php echo empty($country)? 'n/a': $country;?></em>
  673. <b><?php echo $data['qty'];?></b>
  674. <i><?php echo $curSYM. number_format($data['cost'], 2, '.','');?></i>
  675. </span>
  676. <?php
  677. $index++;
  678. }
  679.  
  680. ?>
  681. </p>
  682. </div>
  683. <?php
  684. }
  685.  
  686. do_action('evotx_sales_insight_after', $EVENT, $orders);
  687.  
  688. $content = ob_get_clean();
  689.  
  690. echo json_encode(array('content'=> $content, 'status'=>'good')); exit;
  691. }
  692.  
  693. // return time difference in d/h/m
  694. function get_human_time($time){
  695.  
  696. $output = '';
  697. $day = $time/(60*60*24); // in day
  698. $dayFix = floor($day);
  699. $dayPen = $day - $dayFix;
  700. if($dayPen > 0)
  701. {
  702. $hour = $dayPen*(24); // in hour (1 day = 24 hour)
  703. $hourFix = floor($hour);
  704. $hourPen = $hour - $hourFix;
  705. if($hourPen > 0)
  706. {
  707. $min = $hourPen*(60); // in hour (1 hour = 60 min)
  708. $minFix = floor($min);
  709. $minPen = $min - $minFix;
  710. if($minPen > 0)
  711. {
  712. $sec = $minPen*(60); // in sec (1 min = 60 sec)
  713. $secFix = floor($sec);
  714. }
  715. }
  716. }
  717. $str = "";
  718. if($dayFix > 0)
  719. $str.= $dayFix." day ";
  720. if($hourFix > 0)
  721. $str.= $hourFix." hour ";
  722. if($minFix > 0)
  723. $str.= $minFix." min ";
  724. //if($secFix > 0) $str.= $secFix." sec ";
  725. return $str;
  726. }
  727.  
  728. }
  729. new evotx_admin_ajax();
Advertisement
Add Comment
Please, Sign In to add comment