Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 63.22 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package Get statistics
  4. * @version 1.0
  5. */
  6. /*
  7. Plugin Name: Get statistics VoIP call
  8. Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page.
  9. Author: Vladimir Tatarnikov
  10. Version: 1.0
  11. Author URI: http://tatarnikovblog.tk/
  12. */
  13.  
  14. if( ! class_exists( 'WP_List_Table' ) ) {
  15. require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
  16. }
  17.  
  18. class Payment_List_Table extends WP_List_Table {
  19.  
  20. var $example_data;
  21. var $found_data;
  22.  
  23. function get_columns(){
  24. $columns = array(
  25. 'cb' => '<input type="checkbox" />',
  26. 'user' => 'Пользователь',
  27. 'log_date' => 'Дата платежа',
  28. 'sum_before' => 'Сумма до',
  29. 'summa' => 'Сумма',
  30. 'sum_after' => 'Сумма после',
  31. 'destination' => 'Назначение платежа'
  32. );
  33. return $columns;
  34. }
  35.  
  36. function column_default($item, $column_name ) {
  37. switch($column_name ) {
  38. case 'user':
  39. case 'sum_before':
  40. case 'summa':
  41. case 'sum_after':
  42. case 'destination':
  43. case 'log_date':
  44. return $item[ $column_name ];
  45. default:
  46. return print_r($item, true ) ; //Мы отображаем целый массив во избежание проблем
  47. }
  48. }
  49.  
  50. function column_cb($item) {
  51. return sprintf(
  52. '<input type="checkbox" name="book[]" value="%s" />', $item['ID']
  53. );
  54. }
  55.  
  56. function column_account_internal($item) {
  57. return sprintf(
  58. '<input type="checkbox" name="account_internal[]" %s />', checked($item['account_internal'], true, false)
  59. );
  60. }
  61.  
  62. function get_sortable_columns() {
  63. $sortable_columns = array(
  64. 'user' => array('user',false)
  65. );
  66. return $sortable_columns;
  67. }
  68.  
  69. function prepare_items() {
  70. $columns = $this->get_columns();
  71. $hidden = array();
  72. $sortable = $this->get_sortable_columns();
  73. $this->_column_headers = array($columns, $hidden, $sortable);
  74. $per_page = 5;
  75. $current_page = $this->get_pagenum();
  76. $total_items = count($this->example_data);
  77. // необходимо только потому, что у нас пример данных
  78. $this->found_data = array_slice($this->example_data,(($current_page-1)*$per_page),$per_page);
  79. $this->set_pagination_args(array(
  80. 'total_items' => $total_items, //Мы должны вычислить общее количество элементов
  81. 'per_page' => $per_page //Мы должны определить, сколько элементов отображается на странице
  82. ) );
  83. $this->items = $this->found_data;
  84. }
  85.  
  86. function get_bulk_actions() {
  87. $actions = array(
  88. 'delete' => 'Удалить'
  89. );
  90. return $actions;
  91. }
  92.  
  93. function process_action(){
  94. $action = $this->current_action();
  95. if ($action=='update'){
  96. if (isset($_GET['account'])){
  97. //update_accounts((int)$_GET['account']);
  98. }
  99. }
  100. }
  101. }
  102.  
  103. class Mountly_Payment_List_Table extends WP_List_Table {
  104.  
  105. var $example_data;
  106. var $found_data;
  107.  
  108. function get_columns(){
  109. $columns = array(
  110. 'cb' => '<input type="checkbox" />',
  111. 'user' => 'Пользователь',
  112. 'summa' => 'Сумма',
  113. 'day' => 'День платежа',
  114. 'destination' => 'Назначение платежа'
  115. );
  116. return $columns;
  117. }
  118.  
  119. function column_default($item, $column_name ) {
  120. switch($column_name ) {
  121. case 'user':
  122. case 'summa':
  123. case 'day':
  124. case 'destination':
  125. return $item[ $column_name ];
  126. default:
  127. return print_r($item, true ) ; //Мы отображаем целый массив во избежание проблем
  128. }
  129. }
  130.  
  131. function column_cb($item) {
  132. return sprintf(
  133. '<input type="checkbox" name="book[]" value="%s" />', $item['ID']
  134. );
  135. }
  136.  
  137. function column_user($item){
  138. $actions = array(
  139. 'edit' => sprintf('<a href="?page=payment_new.php&action=%s&payment=%s">Изменить</a>','edit',$item['id']),
  140. 'delete' => sprintf('<a href="?page=%s&action=%s&payment=%s">Удалить</a>',$_REQUEST['page'],'delete',$item['id']),
  141. );
  142. return sprintf('%1$s %2$s', $item['user'], $this->row_actions($actions));
  143. }
  144.  
  145. function column_account_internal($item) {
  146. return sprintf(
  147. '<input type="checkbox" name="account_internal[]" %s />', checked($item['account_internal'], true, false)
  148. );
  149. }
  150.  
  151. function get_sortable_columns() {
  152. $sortable_columns = array(
  153. 'user' => array('user',false)
  154. );
  155. return $sortable_columns;
  156. }
  157.  
  158. function prepare_items() {
  159. $columns = $this->get_columns();
  160. $hidden = array();
  161. $sortable = $this->get_sortable_columns();
  162. $this->_column_headers = array($columns, $hidden, $sortable);
  163. $per_page = 5;
  164. $current_page = $this->get_pagenum();
  165. $total_items = count($this->example_data);
  166. // необходимо только потому, что у нас пример данных
  167. $this->found_data = array_slice($this->example_data,($current_page-1)*$per_page,$per_page, true);
  168. $this->set_pagination_args(array(
  169. 'total_items' => $total_items, //Мы должны вычислить общее количество элементов
  170. 'per_page' => $per_page //Мы должны определить, сколько элементов отображается на странице
  171. ) );
  172. $this->items = $this->found_data;
  173. }
  174.  
  175. function get_bulk_actions() {
  176. $actions = array(
  177. 'delete' => 'Удалить'
  178. );
  179. return $actions;
  180. }
  181.  
  182. function process_action(){
  183. global $wpdb;
  184. $action = $this->current_action();
  185. if ($action=='update'){
  186. if (isset($_GET['account'])){
  187. update_accounts((int)$_GET['account']);
  188. }
  189. } elseif ($action=='delete'){
  190. if (isset($_GET['payment'])){
  191. $wpdb->delete( $wpdb->prefix.users_payments, array('id' => (int)$_GET['payment']), array( '%d' ));
  192. }
  193. }
  194. }
  195. public function get_pagenum() {
  196. $pagenum = isset( $_REQUEST['paged_mon'] ) ? absint( $_REQUEST['paged_mon'] ) : 0;
  197.  
  198. if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
  199. $pagenum = $this->_pagination_args['total_pages'];
  200.  
  201. return max( 1, $pagenum );
  202. }
  203.  
  204. protected function pagination( $which ) {
  205. if ( empty( $this->_pagination_args ) ) {
  206. return;
  207. }
  208.  
  209. $total_items = $this->_pagination_args['total_items'];
  210. $total_pages = $this->_pagination_args['total_pages'];
  211. $infinite_scroll = false;
  212. if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
  213. $infinite_scroll = $this->_pagination_args['infinite_scroll'];
  214. }
  215.  
  216. if ( 'top' === $which && $total_pages > 1 ) {
  217. $this->screen->render_screen_reader_content( 'heading_pagination' );
  218. }
  219.  
  220. $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
  221.  
  222. $current = $this->get_pagenum();
  223. $removable_query_args = wp_removable_query_args();
  224.  
  225. $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
  226.  
  227. $current_url = remove_query_arg( $removable_query_args, $current_url );
  228.  
  229. $page_links = array();
  230.  
  231. $total_pages_before = '<span class="paging-input">';
  232. $total_pages_after = '</span></span>';
  233.  
  234. $disable_first = $disable_last = $disable_prev = $disable_next = false;
  235.  
  236. if ( $current == 1 ) {
  237. $disable_first = true;
  238. $disable_prev = true;
  239. }
  240. if ( $current == 2 ) {
  241. $disable_first = true;
  242. }
  243. if ( $current == $total_pages ) {
  244. $disable_last = true;
  245. $disable_next = true;
  246. }
  247. if ( $current == $total_pages - 1 ) {
  248. $disable_last = true;
  249. }
  250.  
  251. if ( $disable_first ) {
  252. $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
  253. } else {
  254. $page_links[] = sprintf( "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
  255. esc_url( remove_query_arg( 'paged_mon', $current_url ) ),
  256. __( 'First page' ),
  257. '&laquo;'
  258. );
  259. }
  260.  
  261. if ( $disable_prev ) {
  262. $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
  263. } else {
  264. $page_links[] = sprintf( "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
  265. esc_url( add_query_arg( 'paged_mon', max( 1, $current-1 ), $current_url ) ),
  266. __( 'Previous page' ),
  267. '&lsaquo;'
  268. );
  269. }
  270.  
  271. if ( 'bottom' === $which ) {
  272. $html_current_page = $current;
  273. $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
  274. } else {
  275. $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
  276. '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
  277. $current,
  278. strlen( $total_pages )
  279. );
  280. }
  281. $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
  282. $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
  283.  
  284. if ( $disable_next ) {
  285. $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
  286. } else {
  287. $page_links[] = sprintf( "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
  288. esc_url( add_query_arg( 'paged_mon', min( $total_pages, $current+1 ), $current_url ) ),
  289. __( 'Next page' ),
  290. '&rsaquo;'
  291. );
  292. }
  293.  
  294. if ( $disable_last ) {
  295. $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
  296. } else {
  297. $page_links[] = sprintf( "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
  298. esc_url( add_query_arg( 'paged_mon', $total_pages, $current_url ) ),
  299. __( 'Last page' ),
  300. '&raquo;'
  301. );
  302. }
  303.  
  304. $pagination_links_class = 'pagination-links';
  305. if ( ! empty( $infinite_scroll ) ) {
  306. $pagination_links_class .= ' hide-if-js';
  307. }
  308. $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
  309.  
  310. if ( $total_pages ) {
  311. $page_class = $total_pages < 2 ? ' one-page' : '';
  312. } else {
  313. $page_class = ' no-pages';
  314. }
  315. $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
  316.  
  317. echo $this->_pagination;
  318. }
  319. }
  320.  
  321. class Dayly_Payment_List_Table extends WP_List_Table {
  322.  
  323. var $example_data;
  324. var $found_data;
  325.  
  326. function get_columns(){
  327. $columns = array(
  328. 'cb' => '<input type="checkbox" />',
  329. 'user' => 'Пользователь',
  330. 'summa' => 'Сумма',
  331. 'destination' => 'Назначение платежа'
  332. );
  333. return $columns;
  334. }
  335.  
  336. function column_default($item, $column_name ) {
  337. switch($column_name ) {
  338. case 'user':
  339. case 'summa':
  340. case 'destination':
  341. return $item[ $column_name ];
  342. default:
  343. return print_r($item, true ) ; //Мы отображаем целый массив во избежание проблем
  344. }
  345. }
  346.  
  347. function column_cb($item) {
  348. return sprintf(
  349. '<input type="checkbox" name="book[]" value="%s" />', $item['ID']
  350. );
  351. }
  352.  
  353. function column_user($item){
  354. $actions = array(
  355. 'edit' => sprintf('<a href="?page=payment_new.php&action=%s&payment=%s">Изменить</a>','edit',$item['id']),
  356. 'delete' => sprintf('<a href="?page=%s&action=%s&payment=%s">Удалить</a>',$_REQUEST['page'],'delete',$item['id']),
  357. );
  358. return sprintf('%1$s %2$s', $item['user'], $this->row_actions($actions));
  359. }
  360. function column_account_internal($item) {
  361. return sprintf(
  362. '<input type="checkbox" name="account_internal[]" %s />', checked($item['account_internal'], true, false)
  363. );
  364. }
  365.  
  366. function get_sortable_columns() {
  367. $sortable_columns = array(
  368. 'user' => array('user',false)
  369. );
  370. return $sortable_columns;
  371. }
  372.  
  373. function prepare_items() {
  374. $columns = $this->get_columns();
  375. $hidden = array();
  376. $sortable = $this->get_sortable_columns();
  377. $this->_column_headers = array($columns, $hidden, $sortable);
  378. $per_page = 5;
  379. $current_page = $this->get_pagenum();
  380. $total_items = count($this->example_data);
  381. // необходимо только потому, что у нас пример данных
  382. $this->found_data = array_slice($this->example_data,($current_page-1)*$per_page,$per_page, true);
  383. $this->set_pagination_args(array(
  384. 'total_items' => $total_items, //Мы должны вычислить общее количество элементов
  385. 'per_page' => $per_page //Мы должны определить, сколько элементов отображается на странице
  386. ) );
  387. $this->items = $this->found_data;
  388. }
  389.  
  390. function get_bulk_actions() {
  391. $actions = array(
  392. 'delete' => 'Удалить'
  393. );
  394. return $actions;
  395. }
  396.  
  397. function process_action(){
  398. global $wpdb;
  399. $action = $this->current_action();
  400. if ($action=='update'){
  401. if (isset($_GET['account'])){
  402. update_accounts((int)$_GET['account']);
  403. }
  404. } elseif ($action=='delete'){
  405. if (isset($_GET['payment'])){
  406. $wpdb->delete( $wpdb->prefix.users_payments, array('id' => (int)$_GET['payment']), array( '%d' ));
  407. }
  408. }
  409. }
  410. public function get_pagenum() {
  411. $pagenum = isset( $_REQUEST['paged_day'] ) ? absint( $_REQUEST['paged_day'] ) : 0;
  412.  
  413. if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
  414. $pagenum = $this->_pagination_args['total_pages'];
  415.  
  416. return max( 1, $pagenum );
  417. }
  418.  
  419. protected function pagination( $which ) {
  420. if ( empty( $this->_pagination_args ) ) {
  421. return;
  422. }
  423.  
  424. $total_items = $this->_pagination_args['total_items'];
  425. $total_pages = $this->_pagination_args['total_pages'];
  426. $infinite_scroll = false;
  427. if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
  428. $infinite_scroll = $this->_pagination_args['infinite_scroll'];
  429. }
  430.  
  431. if ( 'top' === $which && $total_pages > 1 ) {
  432. $this->screen->render_screen_reader_content( 'heading_pagination' );
  433. }
  434.  
  435. $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
  436.  
  437. $current = $this->get_pagenum();
  438. $removable_query_args = wp_removable_query_args();
  439.  
  440. $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
  441.  
  442. $current_url = remove_query_arg( $removable_query_args, $current_url );
  443.  
  444. $page_links = array();
  445.  
  446. $total_pages_before = '<span class="paging-input">';
  447. $total_pages_after = '</span></span>';
  448.  
  449. $disable_first = $disable_last = $disable_prev = $disable_next = false;
  450.  
  451. if ( $current == 1 ) {
  452. $disable_first = true;
  453. $disable_prev = true;
  454. }
  455. if ( $current == 2 ) {
  456. $disable_first = true;
  457. }
  458. if ( $current == $total_pages ) {
  459. $disable_last = true;
  460. $disable_next = true;
  461. }
  462. if ( $current == $total_pages - 1 ) {
  463. $disable_last = true;
  464. }
  465.  
  466. if ( $disable_first ) {
  467. $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
  468. } else {
  469. $page_links[] = sprintf( "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
  470. esc_url( remove_query_arg( 'paged_day', $current_url ) ),
  471. __( 'First page' ),
  472. '&laquo;'
  473. );
  474. }
  475.  
  476. if ( $disable_prev ) {
  477. $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
  478. } else {
  479. $page_links[] = sprintf( "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
  480. esc_url( add_query_arg( 'paged_day', max( 1, $current-1 ), $current_url ) ),
  481. __( 'Previous page' ),
  482. '&lsaquo;'
  483. );
  484. }
  485.  
  486. if ( 'bottom' === $which ) {
  487. $html_current_page = $current;
  488. $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
  489. } else {
  490. $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
  491. '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
  492. $current,
  493. strlen( $total_pages )
  494. );
  495. }
  496. $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
  497. $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
  498.  
  499. if ( $disable_next ) {
  500. $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
  501. } else {
  502. $page_links[] = sprintf( "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
  503. esc_url( add_query_arg( 'paged_day', min( $total_pages, $current+1 ), $current_url ) ),
  504. __( 'Next page' ),
  505. '&rsaquo;'
  506. );
  507. }
  508.  
  509. if ( $disable_last ) {
  510. $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
  511. } else {
  512. $page_links[] = sprintf( "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
  513. esc_url( add_query_arg( 'paged_day', $total_pages, $current_url ) ),
  514. __( 'Last page' ),
  515. '&raquo;'
  516. );
  517. }
  518.  
  519. $pagination_links_class = 'pagination-links';
  520. if ( ! empty( $infinite_scroll ) ) {
  521. $pagination_links_class .= ' hide-if-js';
  522. }
  523. $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
  524.  
  525. if ( $total_pages ) {
  526. $page_class = $total_pages < 2 ? ' one-page' : '';
  527. } else {
  528. $page_class = ' no-pages';
  529. }
  530. $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
  531.  
  532. echo $this->_pagination;
  533. }
  534. }
  535.  
  536. class Account_List_Table extends WP_List_Table {
  537.  
  538. var $example_data;
  539. var $found_data;
  540.  
  541. function get_columns(){
  542. $columns = array(
  543. 'cb' => '<input type="checkbox" />',
  544. 'user' => 'Пользователь',
  545. 'account_token' => 'Токен',
  546. 'custom_update' => 'Обновлять вручную'
  547. );
  548. return $columns;
  549. }
  550.  
  551. function column_default($item, $column_name ) {
  552. switch($column_name ) {
  553. case 'user':
  554. case 'account_token':
  555. case 'custom_update':
  556. return $item[ $column_name ];
  557. default:
  558. return print_r($item, true ) ; //Мы отображаем целый массив во избежание проблем
  559. }
  560. }
  561.  
  562. function column_user($item) {
  563. $actions = array(
  564. 'edit' => sprintf('<a href="?page=account_new.php&action=%s&account=%s">Изменить</a>','edit',$item['id']),
  565. 'delete' => sprintf('<a href="?page=%s&action=%s&account=%s">Удалить</a>',$_REQUEST['page'],'delete',$item['id']),
  566. 'update' => sprintf('<a href="?page=%s&action=%s&account=%s">Обновить</a>',$_REQUEST['page'],'update',$item['id']),
  567. );
  568. return sprintf('%1$s %2$s', $item['user'], $this->row_actions($actions));
  569. }
  570.  
  571. function column_cb($item) {
  572. return sprintf(
  573. '<input type="checkbox" name="book[]" value="%s" />', $item['ID']
  574. );
  575. }
  576.  
  577. function column_custom_update($item) {
  578. return sprintf(
  579. '<input type="checkbox" name="account[]" "%s" disabled/>', checked($item['custom_update'], true, false)
  580. );
  581. }
  582.  
  583. function get_sortable_columns() {
  584. $sortable_columns = array(
  585. 'user' => array('user',false)
  586. );
  587. return $sortable_columns;
  588. }
  589.  
  590. function prepare_items() {
  591. $columns = $this->get_columns();
  592. $hidden = array();
  593. $sortable = $this->get_sortable_columns();
  594. $this->_column_headers = array($columns, $hidden, $sortable);
  595. $per_page = 5;
  596. $current_page = $this->get_pagenum();
  597. $total_items = count($this->example_data);
  598. // необходимо только потому, что у нас пример данных
  599. $this->found_data = array_slice($this->example_data,(($current_page-1)*$per_page),$per_page);
  600. $this->set_pagination_args(array(
  601. 'total_items' => $total_items, //Мы должны вычислить общее количество элементов
  602. 'per_page' => $per_page //Мы должны определить, сколько элементов отображается на странице
  603. ) );
  604. $this->items = $this->found_data;
  605. }
  606.  
  607. function get_bulk_actions() {
  608. $actions = array(
  609. 'delete' => 'Удалить'
  610. );
  611. return $actions;
  612. }
  613.  
  614. function process_action(){
  615. global $wpdb;
  616. $action = $this->current_action();
  617. if ($action=='update'){
  618. if (isset($_GET['account'])){
  619. update_accounts((int)$_GET['account']);
  620. }
  621. } elseif ($action=='delete'){
  622. if (isset($_GET['account'])){
  623. $wpdb->delete( $wpdb->prefix.users_accounts, array('id' => (int)$_GET['account']), array( '%d' ));
  624. $wpdb->delete( $wpdb->prefix.users_accounts_sip, array('users_accounts_id' => (int)$_GET['account']), array( '%d' ));
  625. //header("Location: ?page=accounts.php");
  626. }
  627. }
  628. }
  629. }
  630.  
  631. function is_timezone($str){
  632. return in_array($str, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC));
  633. }
  634.  
  635. function set_timezone($date, $timezone){
  636. if (is_timezone($timezone)){
  637. $date->setTimezone(new DateTimeZone($timezone));
  638. $interval = new DateInterval('PT'.$date->getOffset().'S');
  639. return $interval;
  640. } else {
  641. $user_timezone = str_replace('UTC', '', $timezone);
  642. $h_offset = (int)$timezone;
  643. $m_offset = (int)(((float)$timezone - $h_offset)*60);
  644. $interval = new DateInterval('PT'.$h_offset.'H'.$m_offset.'M');
  645. $date->add($interval);
  646. return $interval;
  647. }
  648. }
  649.  
  650. function tatarnikov_add_admin_pages(){
  651. add_menu_page('Аккаунты и токены пользователей', 'Аккаунты', 8, 'accounts.php', 'accounts_menu_page');
  652. add_submenu_page('accounts.php', 'Новый аккаунт пользователя', 'Добавить аккаунт', 8, 'account_new.php', 'account_page');
  653. add_menu_page('история платежей', 'Платежи', 8, 'payments.php', 'payments_menu_page');
  654. add_submenu_page('payments.php', 'Ежедневные платежи', 'Ежедневные платежи', 8, 'dayly_payment_new.php', 'dayly_payment_page');
  655. add_submenu_page('payments.php', 'Ежемесячные платежи', 'Ежемесячные платежи', 8, 'monthly_payment_new.php', 'monthly_payment_page');
  656. add_submenu_page('payments.php', 'Новый платеж', 'Новый платеж', 8, 'payment_new.php', 'payment_page');
  657. }
  658.  
  659. function get_money($duration, $user_id, $calltype){
  660. $tarif_type = get_the_author_meta("tarif_type", $user_id);
  661. $tarif_value = get_the_author_meta("tarif_value", $user_id);
  662. $tarif_delay_sec = get_the_author_meta("tarif_delay_sec", $user_id);
  663. $minutes = (int)($duration / 60);
  664. $seconds = $duration - $minutes*60;
  665. $money = 0;
  666. if ($duration > $tarif_delay_sec && $calltype == "xsi:CallOriginatedEvent"){
  667. if ($tarif_type == 1){
  668. $minutes_full = ($seconds==0?$minutes:$minutes+1);
  669. $money = round($minutes_full * $tarif_value, 2);
  670. } elseif ($tarif_type == 0){
  671. $money = round($duration * $tarif_value/60, 2);
  672. };
  673. }
  674. return $money;
  675. }
  676.  
  677. function is_checked($chkname,$value){
  678. if(!empty($_POST[$chkname])){
  679. foreach($_POST[$chkname] as $chkval){
  680. if($chkval == $value){
  681. return true;
  682. }
  683. }
  684. }
  685. return false;
  686. }
  687.  
  688. function accounts_menu_page(){
  689. global $wpdb;
  690.  
  691. $table_accounts = $wpdb->prefix.users_accounts;
  692. $myListTable = new Account_List_Table();
  693. $myListTable->example_data = $wpdb->get_results(
  694. "
  695. SELECT acc.*, us.user_login as user FROM $table_accounts as acc
  696. left join getstats_wp_users us on us.id = acc.user_id
  697. ",
  698. "ARRAY_A"
  699. );
  700. echo '<div class="wrap"><h1 class="wp-heading-inline">SIP аккаунты пользователей</h1>';
  701. echo "<a class='page-title-action' href='?page=account_new.php'>Добавить</a>";
  702. $myListTable->prepare_items();
  703. echo $myListTable->search_box('Найти', 'search_account');
  704. $myListTable->display();
  705. echo '</div>';
  706.  
  707. }
  708.  
  709. function account_page(){
  710. global $wpdb;
  711. $users = get_users();
  712. $user_id = -1;
  713. $token = '';
  714. $edit = false;
  715. if (isset($_GET['account'])){
  716. $account_id = $_GET['account'];
  717. $table_accounts = $wpdb->prefix.users_accounts;
  718. $account_row = $wpdb->get_row(
  719. "
  720. SELECT * FROM $table_accounts where id = $account_id
  721. "
  722. );
  723. $user_id = $account_row->user_id;
  724. $token = $account_row->account_token;
  725. $custom_update = $account_row->custom_update;
  726. }
  727. if (isset($_GET['action'])){
  728. $edit = $_GET['action']=='edit';
  729. }
  730. if (isset($_POST['action'])){
  731. $table_account = $wpdb->prefix.users_accounts;
  732. $update_data = array(
  733. 'user_id'=>$_POST['user'],
  734. 'account_token'=>$_POST['token'],
  735. 'custom_update'=>$_POST['custom_update']==="on",
  736. );
  737. $sips = array();
  738. $table_sip = $wpdb->prefix.users_accounts_sip;
  739. if ($update_data['account_token'] != ""){
  740. if ($curl = curl_init()){
  741. $headers = array(
  742. "X-MPBX-API-AUTH-TOKEN: ".$update_data['account_token']
  743. );
  744. curl_setopt($curl, CURLOPT_URL,"https://cloudpbx.beeline.ru/apis/portal/abonents");
  745. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  746. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  747. $out = curl_exec($curl);
  748. $abonents = json_decode($out);
  749. foreach ($abonents as $abonent){
  750. $sips[$abonent->userId] = is_checked("sips", $abonent->userId);
  751. }
  752. }
  753. }
  754. print_r($_POST, true);
  755. if ($_POST['action']=='edit'){
  756. $wpdb->update($table_account, $update_data, array('id'=>(int)$_POST['account']));
  757. $user_id = $update_data['user_id'];
  758. $token = $update_data['account_token'];
  759. $custom_update = $update_data['custom_update'];
  760. foreach($sips as $key=>$value){
  761. $current_id = $wpdb->get_var($wpdb->prepare("select id from $table_sip where users_accounts_id = %d and sip = '%s' limit 1", (int)$_POST['account'], $key));
  762. if (!is_null($current_id)){
  763. $updated = $wpdb->update($table_sip, array('select_sip'=>$value), array('id'=>$current_id), array('%d'), array('%d'));
  764. } else {
  765. $wpdb->insert($table_sip, array('users_accounts_id'=>(int)$_POST['account'], 'sip'=>$key, 'select_sip'=>$value), array('%d','%s','%d'));
  766. }
  767. }
  768. } elseif ($_POST['action']=='add'){
  769. $res = $wpdb->insert($table_account, $update_data);
  770. $last_id = $wpdb->insert_id;
  771. if ($res){
  772. update_accounts($last_id);
  773. } else {
  774. }
  775. foreach($sips as $key=>$value){
  776. $wpdb->insert($table_sip, array('users_accounts_id'=>$last_id, 'sip'=>$key, 'select_sip'=>$value), array('%d','%s','%d'));
  777. }
  778. }
  779. }
  780. if ($token != ""){
  781. if ($curl = curl_init()){
  782. $headers = array(
  783. "X-MPBX-API-AUTH-TOKEN: ".$token
  784. );
  785. curl_setopt($curl, CURLOPT_URL,"https://cloudpbx.beeline.ru/apis/portal/abonents");
  786. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  787. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  788. $out = curl_exec($curl);
  789. $abonents = json_decode($out);
  790. }
  791. }
  792. echo "<script type='text/javascript'>
  793. function get_abonents(token){
  794. var request = new XMLHttpRequest();
  795. request.open('GET','https://cloudpbx.beeline.ru/apis/portal/abonents',true);
  796. request.setRequestHeader('X-MPBX-API-AUTH-TOKEN', token);
  797. request.addEventListener('readystatechange', function(){
  798. alert(request.response);
  799. });
  800. request.send();
  801. }
  802. </script>";
  803. echo "<h1 class='wp-heading-inline'>Добавить аккаунт</h1>";
  804. echo "
  805. <form name='getstats_form_settings' method='post' action='".$_SERVER['PHP_SELF']."?page=account_new.php".($edit?'&action=edit&account='.$account_id.'&updated=true':'')."'>".($edit?'<input type="hidden" name="action" value="edit"><input type="hidden" name="account" value="'.$account_id.'"><input type="hidden" name="updated" value="1">':'<input type="hidden" name="action" value="add">')."
  806. <table class='form-table'>
  807. <tr>
  808. <th scope='row'>Пользователь</th>
  809. <td>
  810. <select name='user' required='required'>
  811. <option value=-1></option>";
  812. foreach ($users as $user){
  813. echo sprintf("<option value=%s ".selected($user->ID, $user_id, false).">%s</option>", $user->ID, $user->user_login);
  814. };
  815. echo
  816. "</select>
  817. </td>
  818. </tr>
  819. <tr>
  820. <th scope='row'>Токен</th>
  821. <td>
  822. <!--<input name='token' required='required' value='".$token."' onchange='get_abonents(this.value)'>-->
  823. <input name='token' required='required' value='".$token."'>
  824. </td>
  825. </tr>
  826. <tr>
  827. <th scope='row'>Обновлять вручную</th>
  828. <td>
  829. <input type='checkbox' name='custom_update' '".checked($custom_update, true, false)."'>
  830. </td>
  831. </tr>
  832. </table>
  833. <!--<p class='submit'>
  834. <a class='button' href=''>Обновить список SIP</a>
  835. </p>-->
  836. <table id='sips'>
  837. <th>SIP абонента</th>
  838. <th>Обновлять</th>";
  839. foreach ($abonents as $abonent){
  840. $table_sip = $wpdb->prefix.users_accounts_sip;
  841. $selected = $wpdb->get_var($wpdb->prepare("SELECT select_sip FROM $table_sip where sip='%s' and users_accounts_id = %d limit 1", $abonent->userId, (int)$_GET['account']));
  842. echo "<tr><td>$abonent->userId</td><td><input type='checkbox' name='sips[]' value='$abonent->userId' ".checked($selected, true, false)."></td></tr>";
  843. }
  844. echo "</table>
  845. <p class='submit'>
  846. <input type='submit' value='Сохранить изменения' name='save_new_account' class='button button-primary' id='submit'>
  847. </p>
  848. </form>
  849. ";
  850. }
  851.  
  852. function payments_menu_page(){
  853. global $wpdb;
  854. $users = get_users();
  855.  
  856. $table_payments = $wpdb->prefix.users_payments;
  857. $myListTable = new Payment_List_Table();
  858. $query =
  859. "
  860. SELECT acc.*, us.user_login as user FROM $table_payments as acc
  861. left join getstats_wp_users us on us.id = acc.user_id
  862. where (acc.periodicity = '' or acc.periodicity is null)
  863. ";
  864. if (isset($_GET['user_id']) && $_GET['user_id'] != ''){
  865. $query = $query." and acc.user_id = ".$_GET['user_id'];
  866. }
  867. $myListTable->process_action();
  868. $myListTable->example_data = $wpdb->get_results(
  869. $query, "ARRAY_A"
  870. );
  871. echo '<div class="wrap"><h1 class="wp-heading-inline">История платежей</h1>';
  872. echo "<a class='page-title-action' href='?page=payment_new.php'>Новый платеж</a>";
  873. $myListTable->prepare_items();
  874. echo "
  875. <form method='get'>
  876. <input type='hidden' name='page' value='payments.php'>
  877. <label for='user_id'>Пользователь</label>
  878. <select name='user_id'>
  879. <option value=''></option>";
  880. foreach($users as $user){
  881. echo sprintf("<option value=%s ".selected($user->ID, $_GET['user_id'], false).">%s</option>", $user->ID, $user->user_login);
  882. }
  883. echo "
  884. </select>
  885. <button>Выбрать</button>
  886. </form>
  887. ";
  888. $myListTable->display();
  889. echo '</div>';
  890.  
  891. }
  892.  
  893. function dayly_payment_page(){
  894. global $wpdb;
  895. $users = get_users();
  896.  
  897. $table_payments = $wpdb->prefix.users_payments;
  898. $myListTable = new Dayly_Payment_List_Table();
  899. $query =
  900. "
  901. SELECT acc.*, us.user_login as user FROM $table_payments as acc
  902. left join getstats_wp_users us on us.id = acc.user_id
  903. where acc.periodicity = '1'
  904. ";
  905. if (isset($_GET['user_id']) && $_GET['user_id'] != ''){
  906. $query = $query." and acc.user_id = ".$_GET['user_id'];
  907. }
  908. $myListTable->process_action();
  909. $myListTable->example_data = $wpdb->get_results(
  910. $query, "ARRAY_A"
  911. );
  912. echo '<div class="wrap"><h1 class="wp-heading-inline">Ежедневные платежи</h1>';
  913. echo "<a class='page-title-action' href='?page=payment_new.php'>Новый платеж</a>";
  914. $myListTable->prepare_items();
  915. echo "
  916. <form method='get'>
  917. <input type='hidden' name='page' value='dayly_payment_new.php'>
  918. <label for='user_id'>Пользователь</label>
  919. <select name='user_id'>
  920. <option value=''></option>";
  921. foreach($users as $user){
  922. echo sprintf("<option value=%s ".selected($user->ID, $_GET['user_id'], false).">%s</option>", $user->ID, $user->user_login);
  923. }
  924. echo "
  925. </select>
  926. <button>Выбрать</button>
  927. </form>
  928. ";
  929. $myListTable->display();
  930. echo '</div>';
  931.  
  932. }
  933.  
  934. function monthly_payment_page(){
  935. global $wpdb;
  936. $users = get_users();
  937.  
  938. $table_payments = $wpdb->prefix.users_payments;
  939. $myListTable = new Mountly_Payment_List_Table();
  940. $query =
  941. "
  942. SELECT acc.*, us.user_login as user FROM $table_payments as acc
  943. left join getstats_wp_users us on us.id = acc.user_id
  944. where acc.periodicity = '2'
  945. ";
  946. if (isset($_GET['user_id']) && $_GET['user_id'] != ''){
  947. $query = $query." and acc.user_id = ".$_GET['user_id'];
  948. }
  949. $myListTable->process_action();
  950. $myListTable->example_data = $wpdb->get_results(
  951. $query, "ARRAY_A"
  952. );
  953. echo '<div class="wrap"><h1 class="wp-heading-inline">Ежемесячные платежи</h1>';
  954. echo "<a class='page-title-action' href='?page=payment_new.php'>Новый платеж</a>";
  955. $myListTable->prepare_items();
  956. echo "
  957. <form method='get'>
  958. <input type='hidden' name='page' value='monthly_payment_new.php'>
  959. <label for='user_id'>Пользователь</label>
  960. <select name='user_id'>
  961. <option value=''></option>";
  962. foreach($users as $user){
  963. echo sprintf("<option value=%s ".selected($user->ID, $_GET['user_id'], false).">%s</option>", $user->ID, $user->user_login);
  964. }
  965. echo "
  966. </select>
  967. <button>Выбрать</button>
  968. </form>
  969. ";
  970. $myListTable->display();
  971. echo '</div>';
  972.  
  973. }
  974.  
  975. function payment_page(){
  976. if (current_user_can('administrator', $args)){
  977. global $wpdb;
  978. $users = get_users();
  979. $user_id = -1;
  980. $token = '';
  981. $edit = false;
  982. if (isset($_GET['payment'])){
  983. $payment_id = $_GET['payment'];
  984. $table_accounts = $wpdb->prefix.users_payments;
  985. $account_row = $wpdb->get_row(
  986. "
  987. SELECT * FROM $table_accounts where id = $payment_id
  988. "
  989. );
  990. $user_id = $account_row->user_id;
  991. //$sum_before = $account_row->sum_before;
  992. $summa = $account_row->summa;
  993. $destination = $account_row->destination;
  994. //$sum_after = $account_row->sum_after;
  995. $periodicity = $account_row->periodicity;
  996. $day = $account_row->day;
  997. }
  998. if (isset($_GET['action'])){
  999. $edit = $_GET['action']=='edit';
  1000. }
  1001. if (isset($_POST['action'])){
  1002. $table_payments = $wpdb->prefix.users_payments;
  1003. $balance = get_the_author_meta("balance", $_POST['user']);
  1004. $balance = round((float)$balance, 2);
  1005. $update_data = array(
  1006. 'user_id'=>$_POST['user'],
  1007. //'sum_before'=>$balance,
  1008. 'summa'=>round((float)$_POST['summa'], 2),
  1009. //'sum_after'=>$balance + (float)$_POST['summa'],
  1010. 'destination'=>$_POST['destination'],
  1011. 'periodicity'=>$_POST['periodicity'],
  1012. 'day'=>$_POST['day'],
  1013. );
  1014. if ($_POST['action']=='edit'){
  1015. $wpdb->update($table_payments, $update_data, array('id'=>(int)$_POST['account']));
  1016. $user_id = $update_data['user_id'];
  1017. //$sum_before = $update_data['sum_before'];
  1018. $summa = $update_data['summa'];
  1019. $destination = $update_data['destination'];
  1020. //$sum_after = $update_data['sum_after'];
  1021. $periodicity = $update_data['periodicity'];
  1022. $day = $account_row->day;
  1023. } elseif ($_POST['action']=='add'){
  1024. if ($update_data['periodicity'] == ""){
  1025. $update_data['sum_before'] = $balance;
  1026. $update_data['sum_after'] = $balance + round((float)$_POST['summa'], 2);
  1027. }
  1028. $res = $wpdb->insert($table_payments, $update_data);
  1029. if ($res){
  1030. if ($update_data['periodicity'] == ""){
  1031. update_user_meta($update_data['user_id'], 'balance', $update_data['summa'] + $balance);
  1032. if ($update_data['summa'] + $balance >= 10){
  1033. update_user_meta($update_data['user_id'], 'notify_lt_10', true);
  1034. };
  1035. if ($update_data['summa'] + $balance >= 500){
  1036. update_user_meta($update_data['user_id'], 'notify_lt_500', true);
  1037. };
  1038. if ($update_data['summa'] + $balance >= 1500){
  1039. update_user_meta($update_data['user_id'], 'notify_lt_1500', true);
  1040. };
  1041. }
  1042. } else {
  1043. }
  1044. }
  1045. }
  1046. echo "<h1 class='wp-heading-inline'>Новый платеж</h1>";
  1047. echo "
  1048. <form name='getstats_form_settings' method='post' action='".$_SERVER['PHP_SELF']."?page=payment_new.php".($edit?'&action=edit&payment='.$payment_id.'&updated=true':'')."'>".($edit?'<input type="hidden" name="action" value="edit"><input type="hidden" name="payment" value="'.$payment_id.'"><input type="hidden" name="updated" value="1">':'<input type="hidden" name="action" value="add">')."
  1049. <table class='form-table'>
  1050. <tr>
  1051. <th scope='row'>Пользователь</th>
  1052. <td>
  1053. <select name='user' required='required'>
  1054. <option value=-1></option>";
  1055. foreach ($users as $user){
  1056. echo sprintf("<option value=%s ".selected($user->ID, $user_id, false).">%s</option>", $user->ID, $user->user_login);
  1057. };
  1058. echo
  1059. "</select>
  1060. </td>
  1061. </tr>
  1062. <tr>
  1063. <th scope='row'>Сумма</th>
  1064. <td>
  1065. <input type='number' step='0.01' name='summa' required='required' value='".$summa."'>
  1066. </td>
  1067. </tr>
  1068. <tr>
  1069. <th scope='row'>Назначение платежа</th>
  1070. <td>
  1071. <input name='destination' value='".$destination."'>
  1072. </td>
  1073. </tr>
  1074. <tr>
  1075. <th scope='row'>Периодичность</th>
  1076. <td>
  1077. <select name='periodicity'>
  1078. <option value='' ".selected($periodicity, "", false).">Нет</option>
  1079. <option value='1' ".selected($periodicity, "1", false).">Ежедневно</option>
  1080. <option value='2' ".selected($periodicity, "2", false).">Ежемесячно</option>
  1081. </select>
  1082. </td>
  1083. </tr>
  1084. <tr>
  1085. <th scope='row'>День ежемесячного списания</th>
  1086. <td>
  1087. <select name='day'>";
  1088. for ($i = 1; $i <= 28; $i++) {
  1089. echo sprintf("<option value=%s ".selected($i, $day, false).">%s</option>", $i, $i);
  1090. }
  1091. echo "</select>
  1092. </td>
  1093. </tr>
  1094. </table>
  1095. <p class='submit'>
  1096. <input type='submit' value='Сохранить изменения' name='save_new_payment' class='button button-primary' id='submit'>
  1097. </p>
  1098. </form>
  1099. ";
  1100. } else {
  1101. echo "У Вас недостаточно прав для просмотра данной страницы";
  1102. };
  1103. }
  1104.  
  1105. function update_accounts($account_id, $exclude_sip=array()){
  1106. global $wpdb;
  1107. $table_accounts = $wpdb->prefix.users_accounts;
  1108. $account_row = $wpdb->get_row(
  1109. "
  1110. SELECT * FROM $table_accounts where id = $account_id
  1111. "
  1112. );
  1113. if ($curl = curl_init()){
  1114. $headers = array(
  1115. "X-MPBX-API-AUTH-TOKEN: ".$account_row->account_token
  1116. );
  1117. curl_setopt($curl, CURLOPT_URL,"https://cloudpbx.beeline.ru/apis/portal/abonents");
  1118. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  1119. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  1120. $out = curl_exec($curl);
  1121. $abonents = json_decode($out);
  1122. foreach($abonents as $abonent){
  1123. if (!in_array($abonent->extension, $exclude_sip)){
  1124. $put_headers = array(
  1125. "X-MPBX-API-AUTH-TOKEN: ".$account_row->account_token,
  1126. "Content-Type: application/json"
  1127. );
  1128. $put_data = array(
  1129. 'pattern' => $abonent->extension,
  1130. 'expires' => 720,
  1131. 'subscriptionType' => "ADVANCED_CALL",
  1132. 'url' => plugins_url("getstats/callback.php")
  1133. );
  1134. if ($put_curl = curl_init()){
  1135. curl_setopt($put_curl, CURLOPT_URL,"https://cloudpbx.beeline.ru/apis/portal/subscription");
  1136. curl_setopt($put_curl, CURLOPT_HTTPHEADER, $put_headers);
  1137. curl_setopt($put_curl, CURLOPT_CUSTOMREQUEST, "PUT");
  1138. curl_setopt($put_curl, CURLOPT_POSTFIELDS, json_encode($put_data));
  1139. curl_setopt($put_curl, CURLOPT_RETURNTRANSFER, true);
  1140. $out = curl_exec($put_curl);
  1141. };
  1142. }
  1143. }
  1144. }
  1145. }
  1146.  
  1147. function get_statistics($args){
  1148. ob_start();
  1149. if ( is_user_logged_in() ) {
  1150. global $wpdb;
  1151. $table_accounts = $wpdb->prefix.users_accounts;
  1152. $table_calls = $wpdb->prefix.users_calls;
  1153. $current_user = wp_get_current_user();
  1154. $user_timezone = get_the_author_meta("user_timezone", $current_user->ID);
  1155. $account_row = $wpdb->get_row(
  1156. "
  1157. SELECT * FROM $table_accounts where user_id = $current_user->ID
  1158. "
  1159. );
  1160. $datefrom = date('Y-m-01 00:00:00');
  1161. $dateto = date('Y-m-t 23:59:59');
  1162. if (isset($_GET['datefrom'])){
  1163. if ($_GET['datefrom'] !== ""){
  1164. $datefrom = $_GET['datefrom']." 00:00:00";
  1165. }
  1166. };
  1167. if (isset($_GET['dateto'])){
  1168. if ($_GET['dateto'] !== ""){
  1169. $dateto = $_GET['dateto']." 23:59:59";
  1170. }
  1171. };
  1172. //print_r($user_timezone);
  1173. //echo "<br/>";
  1174. $datefrom_select = new DateTime($datefrom);
  1175. //set_timezone($datefrom_select, $user_timezone);
  1176. $datefrom_date = new DateTime($datefrom);
  1177. //$intervalfrom = $datefrom_date->getTimestamp() - $datefrom_select->getTimestamp();
  1178. $intervalfrom = set_timezone($datefrom_select, $user_timezone);
  1179. //print_r($intervalfrom);
  1180. //echo "<br/>";
  1181. //$datefrom_date = $datefrom_date->modify(sprintf(" %s sec", $intervalfrom));
  1182. $datefrom_date = $datefrom_date->sub($intervalfrom);
  1183. print_r($datefrom_date, true);
  1184. //echo "<br/>";
  1185. //print_r($datefrom_select);
  1186. //echo "<br/>";
  1187.  
  1188. $dateto_select = new DateTime($dateto);
  1189. //set_timezone($dateto_select, $user_timezone);
  1190. $dateto_date = new DateTime($dateto);
  1191. //$intervalto = $dateto_date->getTimestamp() - $dateto_select->getTimestamp();
  1192. $intervalto = set_timezone($dateto_select, $user_timezone);
  1193. //$dateto_date = $dateto_date->modify(sprintf(" %s sec", $intervalto));
  1194. $dateto_date = $dateto_date->sub($intervalto);
  1195. print_r($dateto_date, true);
  1196. //echo "<br/>";
  1197. //print_r($dateto_select);
  1198. //echo "<br/>";
  1199.  
  1200. if ($curl = curl_init()){
  1201. $headers = array(
  1202. "X-MPBX-API-AUTH-TOKEN: ".$account_row->account_token
  1203. );
  1204. curl_setopt($curl, CURLOPT_URL,"https://cloudpbx.beeline.ru/apis/portal/abonents");
  1205. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  1206. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  1207. $out = curl_exec($curl);
  1208. $abonents = json_decode($out);
  1209. echo "
  1210. <form method='get' action='/'>
  1211. <input type='date' name='datefrom' style='width:32%' value=$datefrom>
  1212. -
  1213. <input type='date' name='dateto' style='width:32%' value=$dateto>
  1214. <button type='submit' style='width:33%'>Выбрать</button>
  1215. </form><br/>";
  1216. echo "<table>";
  1217. echo "<thead><tr><td>Абонент</td><td>Дата</td><td>На номер</td><td>Тип вызова</td><td>Длительность</td><td>Сумма</td></tr></thead>";
  1218. $arraySIP = array();
  1219. $arraySIPname = array();
  1220. foreach($abonents as $abonent){
  1221. $userId = $abonent->userId;
  1222. array_push($arraySIP, $userId);
  1223. $arraySIPname[$userId]=($abonent->lastName?$abonent->lastName:$abonent->firstName);
  1224. }
  1225. $arraySIPstr = implode("', '", $arraySIP);
  1226.  
  1227. if ($account_row->custom_update){
  1228. $table_sip = $wpdb->prefix.users_accounts_sip;
  1229. $arraySIPstr = implode("', '", $wpdb->get_col($wpdb->prepare("select sip from $table_sip where users_accounts_id=%d and select_sip=1", $account_row->id)));
  1230. }
  1231.  
  1232. global $wp_query;
  1233. $pages = '';
  1234. $posts_per_page = get_option('posts_per_page');
  1235. $max = ceil($wpdb->get_var(
  1236. "select COUNT(*)
  1237. from $table_calls uc
  1238. left join $table_calls ic on ic.extTrackingId = uc.extTrackingId and
  1239. ic.address is not null and
  1240. ic.startTime = uc.startTime and
  1241. ic.state = 'Alerting' and
  1242. ic.eventData = 'xsi:CallOriginatedEvent'
  1243. where uc.targetId in ('$arraySIPstr') and
  1244. uc.releaseTime is not null and
  1245. uc.answerTime is not null and
  1246. ic.log_datetime is not null and
  1247. ic.log_datetime between '".$datefrom_date->date."' and '".$dateto_date->date."'
  1248. ORDER by 1 desc")/$posts_per_page);
  1249. if (!$current = get_query_var('page')) $current = 1;
  1250. $a['base'] = str_replace(999999999, '%#%', get_pagenum_link(999999999));
  1251. $a['total'] = $max;
  1252. $a['current'] = $current;
  1253.  
  1254. $results = $wpdb->get_results(
  1255. "select ic.log_datetime,
  1256. ic.address as address,
  1257. uc.answerTime,
  1258. uc.releaseTime,
  1259. uc.targetId,
  1260. (select ct.eventData from $table_calls as ct where ct.extTrackingId = uc.extTrackingId and ct.eventData in ('xsi:CallOriginatedEvent', 'xsi:CallReceivedEvent') and ct.startTime = uc.startTime limit 1) as calltype
  1261. from $table_calls uc
  1262. left join $table_calls ic on ic.extTrackingId = uc.extTrackingId and
  1263. ic.address is not null and
  1264. ic.startTime = uc.startTime and
  1265. ic.state = 'Alerting' and
  1266. ic.eventData = 'xsi:CallOriginatedEvent'
  1267. where uc.targetId in ('$arraySIPstr') and
  1268. uc.releaseTime is not null and
  1269. uc.answerTime is not null and
  1270. ic.log_datetime is not null and
  1271. ic.log_datetime between '".$datefrom_date->date."' and '".$dateto_date->date."'
  1272. ORDER by 1 desc limit ".$posts_per_page*($current-1).", ".$posts_per_page
  1273. ,
  1274. "ARRAY_A"
  1275. );
  1276. foreach($results as $res){
  1277. $duration = (int)(((int)$res['releaseTime'] - (int)$res['answerTime'])/1000);
  1278. $minutes = (int)($duration / 60);
  1279. $seconds = $duration - $minutes*60;
  1280. if (strlen($res['address']) == 3) {
  1281. $res['calltype'] = 'inner';
  1282. }
  1283. $money = get_money($duration, $current_user->ID, $res['calltype']);
  1284. $date = new DateTime($res['log_datetime']);
  1285. set_timezone($date, $user_timezone);
  1286. $calltype = "-";
  1287. if ($res['calltype'] == "xsi:CallOriginatedEvent"){
  1288. $calltype = "Исх.";
  1289. } elseif ($res['calltype'] == "xsi:CallReceivedEvent"){
  1290. $calltype = "Вх.";
  1291. } elseif ($res['calltype'] == "inner"){
  1292. $calltype = "Внутр.";
  1293. }
  1294. echo "<tr>";
  1295. echo "<td>".$arraySIPname[$res['targetId']]."</td>", "<td>".$date->format('d.m.Y H:i:s')."</td>", "<td>".$res['address']."</td>", "<td>".$calltype."</td>", "<td>".str_pad($minutes, 2, "0", STR_PAD_LEFT).":".str_pad($seconds, 2, "0", STR_PAD_LEFT)."</td>", "<td>$money, руб.</td>";
  1296. echo "</tr>";
  1297. }
  1298. echo "</table>", "<br>";
  1299.  
  1300. $total = 1; //1 - выводить текст "Страница N из N", 0 - не выводить
  1301. $a['mid_size'] = 3; //сколько ссылок показывать слева и справа от текущей
  1302. $a['end_size'] = 1; //сколько ссылок показывать в начале и в конце
  1303. $a['prev_text'] = '&laquo;'; //текст ссылки "Предыдущая страница"
  1304. $a['next_text'] = '&raquo;'; //текст ссылки "Следующая страница"
  1305.  
  1306. if ($max > 1) echo '<div class="navigation">';
  1307. if ($total == 1 && $max > 1) $pages = '<span class="pages">Страница ' . $current . ' из ' . $max . '</span>'."<br>";
  1308. echo $pages . paginate_links($a);
  1309. if ($max > 1) echo '</div>';
  1310. }
  1311. } else {
  1312. echo "Для просмотра статистики необходимо авторизоваться, нажав кнопку 'Войти'";
  1313. }
  1314. $output_string=ob_get_contents();;
  1315. ob_end_clean();
  1316. return $output_string;
  1317. }
  1318.  
  1319. function show_balance(){
  1320. ob_start();
  1321. if ( is_user_logged_in() ) {
  1322. $user = wp_get_current_user();
  1323. $balance = get_the_author_meta("balance", $user->ID );
  1324. $balance = round((float)$balance, 2);
  1325. echo "Баланс: ", esc_attr($balance), "<br/>", "<hr>";
  1326. }
  1327. $output_string=ob_get_contents();;
  1328. ob_end_clean();
  1329. return $output_string;
  1330. }
  1331.  
  1332. function get_payments(){
  1333. ob_start();
  1334. if ( is_user_logged_in() ) {
  1335. global $wpdb;
  1336. $user = wp_get_current_user();
  1337. $table_payments = $wpdb->prefix.users_payments;
  1338. $user_paymants = $wpdb->get_results(
  1339. "
  1340. SELECT * FROM $table_payments where (periodicity = '' or periodicity is null) and user_id = $user->ID
  1341. ",
  1342. "ARRAY_A"
  1343. );
  1344. echo "<table>";
  1345. echo "<thead><tr><td>Дата платежа</td><td>Сумма</td><td>Назначение платежа</td></tr></thead>";
  1346. foreach ($user_paymants as $user_paymant){
  1347. echo "<tr><td>".$user_paymant["log_date"]."</td><td>".$user_paymant['summa']."</td><td>".$user_paymant['destination']."</td></tr>";
  1348. };
  1349. echo "</table>";
  1350. }
  1351. $output_string=ob_get_contents();;
  1352. ob_end_clean();
  1353. return $output_string;
  1354. }
  1355.  
  1356. function action_update(){
  1357. echo "action update";
  1358. }
  1359.  
  1360. function edit_user_balance($user){
  1361. if (current_user_can('administrator', $args)){
  1362. $user_timezone = get_the_author_meta("user_timezone", $user->ID);
  1363. echo "
  1364. <h3>Баланс пользователя</h3>
  1365. <table class='form-table'>
  1366. <tr>
  1367. <th><label for='balance_profile'>Баланс</label></th>
  1368. <td>";
  1369. echo esc_attr(round((float)get_the_author_meta("balance", $user->ID ), 2));
  1370. echo "</td>
  1371. </tr>
  1372. </table>
  1373. ";
  1374. echo "
  1375. <h3>Тариф пользователя</h3>
  1376. <table class='form-table'>
  1377. <tr>
  1378. <th><label for='tarif_type_profile'>Тариф</label></th>
  1379. <td>
  1380. <select name='tarif_type_profile' required='required'>
  1381. <option value=0 ".selected(get_the_author_meta("tarif_type", $user->ID ), 0, false).">Посекундная</option>
  1382. <option value=1 ".selected(get_the_author_meta("tarif_type", $user->ID ), 1, false).">Поминутная</option>
  1383. </select>
  1384. </td>
  1385. </tr>
  1386. <tr>
  1387. <th><label for='tarif_value_profile'>Цена</label></th>
  1388. <td>
  1389. <input type='number' name='tarif_value_profile' required='required' min='0' step='0.01' value='".get_the_author_meta("tarif_value", $user->ID )."'>
  1390. </td>
  1391. </tr>
  1392. <tr>
  1393. <th><label for='tarif_delay_sec_profile'>Не тарифицировать</label></th>
  1394. <td>
  1395. <input type='number' name='tarif_delay_sec_profile' required='required' min='0' step='1' value='".get_the_author_meta("tarif_delay_sec", $user->ID )."'>
  1396. </td>
  1397. </tr>
  1398. <tr>
  1399. <th><label for='user_timezone'>Часовой пояс</label></th>
  1400. <td>
  1401. <select name='user_timezone'>".wp_timezone_choice($user_timezone)."
  1402. </select>
  1403. </td>
  1404. </tr>
  1405. </table>
  1406. ";
  1407. $bee_login = get_the_author_meta("bee_login", $user->ID );
  1408. $bee_pass = get_the_author_meta("bee_pass", $user->ID );
  1409. echo "
  1410. <h3>Настройка личного кабинета Билайн</h3>
  1411. <table class='form-table'>
  1412. <tr>
  1413. <th><label for='bee_login'>Логин</label></th>
  1414. <td>
  1415. <input name='bee_login' value='".$bee_login."'>
  1416. </td>
  1417. </tr>
  1418. <tr>
  1419. <th><label for='bee_pass'>Цена</label></th>
  1420. <td>
  1421. <input name='bee_pass' value='".$bee_pass."'>
  1422. </td>
  1423. </tr>
  1424. </table>
  1425. ";
  1426. };
  1427. }
  1428.  
  1429. function save_balance($user_id){
  1430. update_user_meta($user_id, 'tarif_type', sanitize_text_field($_POST['tarif_type_profile']));
  1431. update_user_meta($user_id, 'tarif_value', sanitize_text_field($_POST['tarif_value_profile']));
  1432. update_user_meta($user_id, 'tarif_delay_sec', sanitize_text_field($_POST['tarif_delay_sec_profile']));
  1433. update_user_meta($user_id, 'user_timezone', sanitize_text_field($_POST['user_timezone']));
  1434. update_user_meta($user_id, 'bee_login', sanitize_text_field($_POST['bee_login']));
  1435. update_user_meta($user_id, 'bee_pass', sanitize_text_field($_POST['bee_pass']));
  1436. }
  1437.  
  1438. function true_moi_interval( $raspisanie ) {
  1439. // $raspisanie - это массив, состоящий из всех зарегистрированных интервалов
  1440. // наша задача - добавить в него свой собственный интервал, к примеру пусть будет 3 минуты
  1441. $raspisanie['ten_minute'] = array(
  1442. 'interval' => 600, // в одной минуте 60 секунд, в 10 минутах - 600
  1443. 'display' => 'Каждые 10 минут' // отображаемое имя
  1444. );
  1445. return $raspisanie;
  1446. }
  1447.  
  1448. function send_subscription(){
  1449. global $wpdb;
  1450. $table_accounts = $wpdb->prefix.users_accounts;
  1451. $account_ids = $wpdb->get_results("SELECT id, custom_update FROM $table_accounts", "ARRAY_A");
  1452. foreach ($account_ids as $account_id){
  1453. if ($account_id["custom_update"] != 1){
  1454. update_accounts($account_id["id"]);
  1455. } else {
  1456. $table_sips = $wpdb->prefix.users_accounts_sip;
  1457. $array_sip = $wpdb->get_results($wpdb->prepare("SELECT sip FROM $table_sips where select_sip = 1 and users_accounts_id = %d", $account_id["id"]), "ARRAY_N");
  1458. update_accounts($account_id["id"], $array_sip);
  1459. }
  1460. }
  1461. }
  1462.  
  1463. function show_user_info($content){
  1464. if ( is_user_logged_in() ) {
  1465. global $wpdb;
  1466. $user = wp_get_current_user();
  1467. return $user->display_name."<br/>".$user->description."<br/>".$content;
  1468. } else {
  1469. return $content;
  1470. }
  1471. }
  1472.  
  1473. //Действия
  1474. add_action('admin_menu', 'tatarnikov_add_admin_pages');
  1475. add_action('admin_action_update', 'update', 'action_update');
  1476. add_action('show_user_profile', 'edit_user_balance' );
  1477. add_action('edit_user_profile', 'edit_user_balance' );
  1478. add_action('edit_user_profile_update', 'save_balance' );
  1479. add_action('personal_options_update', 'save_balance' );
  1480. //add_action('the_content', 'show_user_info');
  1481.  
  1482. //Шорткоды
  1483. add_shortcode('statistics', 'get_statistics' );
  1484. add_shortcode('balance', 'show_balance' );
  1485. add_shortcode('payments', 'get_payments' );
  1486.  
  1487. //Расписание
  1488. add_filter('cron_schedules', 'true_moi_interval');
  1489. add_action('send_subscription', 'send_subscription');
  1490.  
  1491. if( !wp_next_scheduled('send_subscription'))
  1492. wp_schedule_event(time(), 'ten_minute', 'send_subscription');
  1493.  
  1494. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement