timesheet source code
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

167 lines
5.2KB

  1. <?php
  2. /**
  3. * Plugin Name: Acare Advanced Office
  4. * Plugin URI: http://biukop.com.au/acaresydney/timesheets
  5. * Description: Advanced Office system, timesheet, Payroll for AcareSydney
  6. * Version: 2.1
  7. * Author: Biukop Intelligence
  8. * Author URI: http://biukop.com.au/
  9. */
  10. namespace Biukop;
  11. require_once(dirname(__FILE__) . '/autoload.php');
  12. require_once (ABSPATH . 'wp-includes/pluggable.php');
  13. class AcareOffice{
  14. private $nonce; //for ajax verification
  15. private $pages = array('time-sheets', 'user-list');
  16. private $acaresydney_userid = 0;
  17. private $xero ;
  18. public function __construct() {
  19. add_action('init', array($this, 'class_loader'));
  20. add_action('wp', array($this, 'check_auth'));
  21. add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99);
  22. add_filter('show_admin_bar', '__return_false');
  23. add_shortcode( 'ts-sync-users', array($this, 'sync_users'));
  24. add_shortcode( 'bts_people_item', array($this, 'bts_people_item'));
  25. add_action('wp_ajax_list_staff', array($this,'list_staff' ));
  26. }
  27. /**
  28. * Autoload the custom theme classes
  29. */
  30. public function class_loader()
  31. {
  32. // Create a new instance of the autoloader
  33. $loader = new \Psr4AutoloaderClass();
  34. // Register this instance
  35. $loader->register();
  36. // Add our namespace and the folder it maps to
  37. $loader->addNamespace('\XeroPHP', dirname(__FILE__) . '/xero-php-master/src/XeroPHP');
  38. $loader->addNamespace('\Biukop', dirname(__FILE__) . '/' );
  39. $this->xero = new Xero();
  40. }
  41. //
  42. //
  43. ///check auth
  44. public function check_auth(){
  45. global $pagename;
  46. //echo $pagename;
  47. }
  48. ///
  49. // enqueue / register css /js
  50. //
  51. public function register_js_css() {
  52. $this->nonce = wp_create_nonce('acaresydney');
  53. $this->acaresydney_userid = get_query_var( 'acaresydney_userid' ) ;
  54. $this->register_bts_js();
  55. $this->register_timesheet_js_css();
  56. }
  57. private function register_bts_js()
  58. {
  59. wp_enqueue_style( 'bts', plugins_url('css/ts.css', __FILE__));
  60. wp_enqueue_script('bts', plugins_url('js/ts.js', __FILE__), array('jquery', 'jquery-ui-core'));
  61. wp_localize_script( 'bts', 'bts1', array(
  62. 'ajax_url' => admin_url( 'admin-ajax.php' ),
  63. 'nonce' => $this->nonce, // It is common practice to comma after
  64. 'display_name' => wp_get_current_user()->display_name,
  65. 'anonymous' => !is_user_logged_in(),
  66. 'me'=> get_current_user_id(),
  67. 'userid'=> $this->acaresydney_userid,
  68. ) );
  69. }
  70. private function register_timesheet_js_css(){
  71. global $pagename;
  72. if ($pagename != 'time-sheets'){
  73. return;
  74. }
  75. wp_enqueue_style( 'bts_ts', plugins_url('css/bts_timesheet.css', __FILE__));
  76. wp_enqueue_script( 'bts_ts', plugins_url('js/bts_timesheet.js', __FILE__), array( 'jquery' , 'bts' ));
  77. wp_enqueue_script('mustache', plugins_url('js/mustache.min.js', __FILE__), array('jquery'));
  78. }
  79. public function sync_users()
  80. {
  81. //dummy sync
  82. return;
  83. }
  84. // Usage: `wp sync_users --mininterval=123
  85. public function sync_user_cli($args = array(), $assoc_args = array()){
  86. $arguments = wp_parse_args( $assoc_args, array(
  87. 'mininterval' => 600,
  88. ) );
  89. $this->xero->sync_users($arguments['mininterval']);
  90. return;
  91. }
  92. public function bts_people_item($attr){
  93. return $this->template('people_template', 'peopleitem.html');
  94. }
  95. //generate template based on html file
  96. private function template($id, $file)
  97. {
  98. $text = '<script id="' . $id .'" type="text/x-biukop-template">';
  99. $text .= file_get_contents(plugin_dir_path(__FILE__) . "/html/$file");
  100. $text .= '</script>';
  101. return $text;
  102. }
  103. function list_staff(){
  104. check_ajax_referer('acaresydney');
  105. // Handle the ajax request
  106. $response = array(
  107. 'status' =>'error',
  108. 'staff' => [],
  109. );
  110. //search all users that are staff
  111. $staffq = new \WP_User_Query(array('role'=>'staff'));
  112. $staff = $staffq->get_results();
  113. if (! empty($staff)){
  114. $response['status'] = 'success';
  115. foreach( $staff as $s){
  116. $response['staff'][] = array(
  117. 'login' => $s->user_login,
  118. 'firstname'=> $s->first_name,
  119. 'lastname'=> $s->last_name,
  120. 'mobile'=> get_user_meta($s->ID, 'mobile', true),
  121. 'email'=> $s->user_email,
  122. 'wages'=> 0,
  123. 'hour' => 0 ,
  124. 'OT' => 0 ,
  125. 'petrol'=> 0 ,
  126. 'rating'=> 0,
  127. 'unconfirmedjob'=> 0,
  128. );
  129. }
  130. }
  131. wp_send_json($response);
  132. wp_die();
  133. }
  134. }
  135. $bb = new AcareOffice();
  136. if ( defined( 'WP_CLI' ) && WP_CLI ) {
  137. \WP_CLI::add_command( 'sync_users', array($bb, 'sync_user_cli'));
  138. }