timesheet source code
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

177 lines
5.5KB

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