timesheet source code
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

131 lignes
4.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. add_shortcode( 'ts-sync-users', array($this, 'sync_users'));
  24. add_shortcode( 'bts_people_item', array($this, 'bts_people_item'));
  25. }
  26. /**
  27. * Autoload the custom theme classes
  28. */
  29. public function class_loader()
  30. {
  31. // Create a new instance of the autoloader
  32. $loader = new \Psr4AutoloaderClass();
  33. // Register this instance
  34. $loader->register();
  35. // Add our namespace and the folder it maps to
  36. $loader->addNamespace('\XeroPHP', dirname(__FILE__) . '/xero-php-master/src/XeroPHP');
  37. $loader->addNamespace('\Biukop', dirname(__FILE__) . '/' );
  38. $this->xero = new Xero();
  39. }
  40. //
  41. //
  42. ///check auth
  43. public function check_auth(){
  44. global $pagename;
  45. //echo $pagename;
  46. }
  47. ///
  48. // enqueue / register css /js
  49. //
  50. public function register_js_css() {
  51. $this->nonce = wp_create_nonce('acaresydney');
  52. $this->acaresydney_userid = get_query_var( 'acaresydney_userid' ) ;
  53. $this->register_bts_js();
  54. $this->register_timesheet_js_css();
  55. }
  56. private function register_bts_js()
  57. {
  58. wp_enqueue_style( 'bts', plugins_url('css/ts.css', __FILE__));
  59. wp_enqueue_script('bts', plugins_url('js/ts.js', __FILE__), array('jquery', 'jquery-ui-core'));
  60. wp_localize_script( 'bts', 'bts1', array(
  61. 'ajax_url' => admin_url( 'admin-ajax.php' ),
  62. 'nonce' => $this->nonce, // It is common practice to comma after
  63. 'display_name' => wp_get_current_user()->display_name,
  64. 'anonymous' => !is_user_logged_in(),
  65. 'me'=> get_current_user_id(),
  66. 'userid'=> $this->acaresydney_userid,
  67. ) );
  68. }
  69. private function register_timesheet_js_css(){
  70. global $pagename;
  71. if ($pagename != 'time-sheets'){
  72. return;
  73. }
  74. wp_enqueue_style( 'bts_ts', plugins_url('css/bts_timesheet.css', __FILE__));
  75. wp_enqueue_script( 'bts_ts', plugins_url('js/bts_timesheet.js', __FILE__), array( 'jquery' , 'bts' ));
  76. wp_enqueue_script('mustache', plugins_url('js/mustache.min.js', __FILE__), array('jquery'));
  77. }
  78. public function sync_users()
  79. {
  80. $a=1;
  81. return;
  82. }
  83. // Usage: `wp sync_users --mininterval=123
  84. public function sync_user_cli($args = array(), $assoc_args = array()){
  85. $arguments = wp_parse_args( $assoc_args, array(
  86. 'mininterval' => 600,
  87. ) );
  88. $this->xero->sync_users($arguments['mininterval']);
  89. return;
  90. }
  91. public function bts_people_item($attr){
  92. return $this->template('people_template', 'peopleitem.html');
  93. }
  94. //generate template based on html file
  95. private function template($id, $file)
  96. {
  97. $text = '<script id="' . $id .'" type="text/x-biukop-template">';
  98. $text .= file_get_contents(plugin_dir_path(__FILE__) . "/html/$file");
  99. $text .= '</script>';
  100. return $text;
  101. }
  102. }
  103. $bb = new AcareOffice();
  104. if ( defined( 'WP_CLI' ) && WP_CLI ) {
  105. \WP_CLI::add_command( 'sync_users', array($bb, 'sync_user_cli'));
  106. }