timesheet source code
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

191 行
6.0KB

  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. //ts-xx for sync single user
  24. add_shortcode( 'ts-sync-users', array($this, 'sync_users'));
  25. //bts-xx for webpage
  26. add_shortcode( 'bts_staff_item', array($this, 'bts_staff_item'));
  27. add_shortcode( 'bts_client_item', array($this, 'bts_client_item'));
  28. add_shortcode( 'bts_job_item', array($this, 'bts_job_item'));
  29. add_action('wp_ajax_list_staff', array($this,'list_staff' ));
  30. add_action('wp_ajax_list_client', array($this,'list_client' ));
  31. }
  32. /**
  33. * Autoload the custom theme classes
  34. */
  35. public function class_loader()
  36. {
  37. // Create a new instance of the autoloader
  38. $loader = new \Psr4AutoloaderClass();
  39. // Register this instance
  40. $loader->register();
  41. // Add our namespace and the folder it maps to
  42. $loader->addNamespace('\XeroPHP', dirname(__FILE__) . '/xero-php-master/src/XeroPHP');
  43. $loader->addNamespace('\Biukop', dirname(__FILE__) . '/' );
  44. $this->xero = new Xero();
  45. }
  46. //
  47. //
  48. ///check auth
  49. public function check_auth(){
  50. global $pagename;
  51. //echo $pagename;
  52. }
  53. ///
  54. // enqueue / register css /js
  55. //
  56. public function register_js_css() {
  57. $this->nonce = wp_create_nonce('acaresydney');
  58. $this->acaresydney_userid = get_query_var( 'acaresydney_userid' ) ;
  59. $this->register_bts_js();
  60. $this->register_timesheet_js_css();
  61. }
  62. private function register_bts_js()
  63. {
  64. wp_enqueue_style( 'bts', plugins_url('css/ts.css', __FILE__));
  65. wp_enqueue_script('bts', plugins_url('js/ts.js', __FILE__), array('jquery', 'jquery-ui-core'));
  66. wp_localize_script( 'bts', 'bts1', array(
  67. 'ajax_url' => admin_url( 'admin-ajax.php' ),
  68. 'nonce' => $this->nonce, // It is common practice to comma after
  69. 'display_name' => wp_get_current_user()->display_name,
  70. 'anonymous' => !is_user_logged_in(),
  71. 'me'=> get_current_user_id(),
  72. 'userid'=> $this->acaresydney_userid,
  73. 'load_user_img'=> plugins_url('img/loading_user.gif', __FILE__),
  74. ) );
  75. }
  76. private function register_timesheet_js_css(){
  77. global $pagename;
  78. if ($pagename != 'time-sheets'){
  79. return;
  80. }
  81. wp_enqueue_style( 'bts_ts', plugins_url('css/bts_timesheet.css', __FILE__));
  82. wp_enqueue_script( 'bts_ts', plugins_url('js/bts_timesheet.js', __FILE__), array( 'jquery' , 'bts' ));
  83. wp_enqueue_script('mustache', plugins_url('js/mustache.min.js', __FILE__), array('jquery'));
  84. }
  85. public function sync_users()
  86. {
  87. //dummy sync
  88. return;
  89. }
  90. // Usage: `wp sync_users --mininterval=123
  91. public function sync_user_cli($args = array(), $assoc_args = array()){
  92. $arguments = wp_parse_args( $assoc_args, array(
  93. 'mininterval' => 600,
  94. ) );
  95. $this->xero->sync_users($arguments['mininterval']);
  96. return;
  97. }
  98. public function bts_staff_item($attr){
  99. return $this->template('staff_item', 'staff.html');
  100. }
  101. public function bts_client_item($attr){
  102. return $this->template('client_item', 'client.html');
  103. }
  104. public function bts_job_item($attr){
  105. return $this->template('job_item', 'job.html');
  106. }
  107. //generate template based on html file
  108. private function template($id, $file)
  109. {
  110. $text = '<script id="' . $id .'" type="text/x-biukop-template">';
  111. $text .= file_get_contents(plugin_dir_path(__FILE__) . "/html/$file");
  112. $text .= '</script>';
  113. return $text;
  114. }
  115. function list_staff(){
  116. check_ajax_referer('acaresydney');
  117. return $this->list_people_by_role('staff');
  118. }
  119. function list_client(){
  120. check_ajax_referer('acaresydney');
  121. return $this->list_people_by_role('client');
  122. }
  123. function list_people_by_role($role){
  124. check_ajax_referer('acaresydney');
  125. // Handle the ajax request
  126. $response = array(
  127. 'status' =>'error',
  128. 'users' => [],
  129. );
  130. //search all users that are staff
  131. $staffq = new \WP_User_Query(array('role'=>$role));
  132. $staff = $staffq->get_results();
  133. if (! empty($staff)){
  134. $response['status'] = 'success';
  135. foreach( $staff as $s){
  136. $response['users'][] = array(
  137. 'login' => $s->user_login,
  138. 'firstname'=> $s->first_name,
  139. 'lastname'=> $s->last_name,
  140. 'mobile'=> get_user_meta($s->ID, 'mobile', true),
  141. 'email'=> $s->user_email,
  142. 'wages'=> 0,
  143. 'hour' => 0 ,
  144. 'OT' => 0 ,
  145. 'petrol'=> 0 ,
  146. 'rating'=> 0,
  147. 'unconfirmedjob'=> 0,
  148. );
  149. }
  150. }
  151. wp_send_json($response);
  152. wp_die();
  153. }
  154. }
  155. $bb = new AcareOffice();
  156. if ( defined( 'WP_CLI' ) && WP_CLI ) {
  157. \WP_CLI::add_command( 'sync_users', array($bb, 'sync_user_cli'));
  158. }