diff --git a/.gitignore b/.gitignore index c2b1298..3a8fe70 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ xero-php-master .buildpath .project sample +/vendor/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9c792ef --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..329d0f0 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/ts.iml b/.idea/ts.iml new file mode 100644 index 0000000..7d949be --- /dev/null +++ b/.idea/ts.iml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Storage.php b/Storage.php new file mode 100644 index 0000000..4c196b0 --- /dev/null +++ b/Storage.php @@ -0,0 +1,168 @@ +path = dirname(__FILE__) . "/xero.json"; + // \Carbon_Fields\Carbon_Fields::boot(); + // if( !isset($_SESSION) ){ + // $this->init_session(); + // } + } + + public function read_value() { + $this->oauth2state = carbon_get_theme_option("xero_oauth2state"); + $this->oauth2["token"] = carbon_get_theme_option("xero_token"); + $this->oauth2["refresh_token"] = carbon_get_theme_option("xero_refresh_token"); + $this->oauth2["expires"] = carbon_get_theme_option("xero_expires"); + $this->oauth2["tenant_id"] = carbon_get_theme_option("xero_tenant_id"); + $this->oauth2["id_token"] = carbon_get_theme_option("xero_id_token"); + + $this->oauth2['expires_human'] = $this->getExpiresHuman($this->oauth2["expires"]); + } + + public function init_session(){ + // session_start(); + } + + public function getSession() { + return $this->oauth2; + // return $_SESSION['oauth2']; + } + + private function write_json() { + $serialize = [ + "oauth2state" => $this->getOauth2State(), + "oauth2" => $this->oauth2, + ]; + file_put_contents($this->path , json_encode($serialize)); + } + + public function startSession($token, $secret, $expires = null) + { + // session_start(); + } + + public function setToken($token, $expires = null, $tenantId, $refreshToken, $idToken) + { + // $_SESSION['oauth2'] = [ + // 'token' => $token, + // 'expires' => $expires, + // 'tenant_id' => $tenantId, + // 'refresh_token' => $refreshToken, + // 'id_token' => $idToken + // ]; + + $this->oauth2 = [ + 'token' => $token, + 'expires' => $expires, + 'tenant_id' => $tenantId, + 'refresh_token' => $refreshToken, + 'id_token' => $idToken, + 'expires_human' => $this->getExpiresHuman($expires) + ]; + + carbon_set_theme_option("xero_token", $token); + carbon_set_theme_option("xero_refresh_token", $refreshToken); + carbon_set_theme_option("xero_expires", $expires); + carbon_set_theme_option("xero_tenant_id", $tenantId); + carbon_set_theme_option("xero_id_token", $idToken); + carbon_set_theme_option("xero_expires_human", $this->getExpiresHuman($expires)); + + $this->write_json(); + } + + public function getOauth2State() { + $this->oauth2state = carbon_get_theme_option("xero_oauth2state"); + return $this->oauth2state; + } + + public function setOauth2State($state) { + $this->oauth2state = $state; + carbon_set_theme_option("xero_oauth2state", $state); + $this->write_json(); + } + + + private function getExpiresHuman($time_stamp) { + $expire = date("Y-m-d H:i:s", $time_stamp); + $utc_date = \DateTime::createFromFormat( + "Y-m-d H:i:s", + $expire, + new \DateTimeZone('UTC') + ); + + $sydney_date = $utc_date; + $sydney_date->setTimeZone(new \DateTimeZone('Australia/Sydney')); + $str = $sydney_date->format("Y-m-d H:i:s"); + return $str; + } + + public function getToken() + { + //If it doesn't exist or is expired, return null + // if (empty($this->getSession()) + // || ($_SESSION['oauth2']['expires'] !== null + // && $_SESSION['oauth2']['expires'] <= time()) + // ) { + // return null; + // } + // return $this->getSession(); + + if ( $this->oauth2['expires'] !== null && $this->oauth2['expires'] <= time() ) { + return null; + } + return $this->oauth2; + } + + public function getAccessToken() + { + //return $_SESSION['oauth2']['token']; + return $this->oauth2['token']; + } + + public function getRefreshToken() + { + // return $_SESSION['oauth2']['refresh_token']; + return $this->oauth2['refresh_token']; + } + + public function getExpires() + { + //return $_SESSION['oauth2']['expires']; + return $this->oauth2['expires']; + } + + public function getXeroTenantId() + { + //return $_SESSION['oauth2']['tenant_id']; + return $this->oauth2['tenant_id']; + } + + public function getIdToken() + { + // return $_SESSION['oauth2']['id_token']; + return $this->oauth2['id_token']; + } + + public function getHasExpired() + { + if (!empty($this->getSession())) + { + if(time() > $this->getExpires()) + { + return true; + } else { + return false; + } + } else { + return true; + } + } +} +?> \ No newline at end of file diff --git a/Xero.php b/XeroOauth1.php similarity index 98% rename from Xero.php rename to XeroOauth1.php index bba81b8..2a95584 100644 --- a/Xero.php +++ b/XeroOauth1.php @@ -5,7 +5,7 @@ use \XeroPHP\Application\PrivateApplication; use \XeroPHP\Remote\Exception\RateLimitExceededException; use \XeroPHP\Remote\Exception\NotFoundException; -class Xero { +class XeroOauth1 { private $xero; private $clientgroup="48646f3d-cf5e-4fea-8c8b-5812bd540e1b"; private $minimum_sync_interval_in_seconds = 600; @@ -93,10 +93,10 @@ class Xero { $this->sync_employees(); } }catch(RateLimitExceededException $e){ - $msg= "Xero API rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n"; + $msg= "XeroOauth1 API rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n"; $this->logConsole($msg); }catch(NotFoundException $e){ - $msg= "Xero API resource not found rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n"; + $msg= "XeroOauth1 API resource not found rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n"; $this->logConsole($msg); } } diff --git a/css/bts_office.css b/css/bts_office.css index 667c64e..4bbe15b 100644 --- a/css/bts_office.css +++ b/css/bts_office.css @@ -32,13 +32,23 @@ body { } +.sheettitle h1.today { + margin: 0 auto 0 auto; + color: darkgrey; + display: inline-block; + font-size: 1.1em; +} + .sheettitle h1:hover { text-decoration: underline; font-weight: bolder; cursor: pointer; + color: black; + font-size: 1.3em; /* animation: blinker 1s linear infinite; */ } + .timesheets { width: calc(100vw - 300px); height: 100vh; diff --git a/html/timesheet_canvas_v1.html b/html/timesheet_canvas_v1.html index 6b3fea8..cc13660 100644 --- a/html/timesheet_canvas_v1.html +++ b/html/timesheet_canvas_v1.html @@ -32,7 +32,7 @@
-

Web Office 2020 - Today: Today (old verion 2019)

+

Web Office 2021 - Today: Today

@@ -195,4 +195,4 @@ Confirm_Schedule
-
\ No newline at end of file +
diff --git a/js/bts_timesheet.js b/js/bts_timesheet.js index 7dda02c..177c5c2 100644 --- a/js/bts_timesheet.js +++ b/js/bts_timesheet.js @@ -711,7 +711,7 @@ return false; } // if (this.get_rate() != this.data.rate){ -// this.set_err_msg_rate('rate@Xero inactive ' + this.data.rate); +// this.set_err_msg_rate('rate@XeroOauth1 inactive ' + this.data.rate); // this.mark_rate_invalid(); // this.mark_dirty(); // return false; diff --git a/js/xeroc.js b/js/xeroc.js index 28fa99b..e7a28fc 100644 --- a/js/xeroc.js +++ b/js/xeroc.js @@ -28,7 +28,7 @@ function on_download_ndis_csv (){} function loading() { - return "

Sync to Xero

"; + return "

Sync to XeroOauth1

"; } function display_hour_lines(response) diff --git a/ts.php b/ts.php index 0bdc532..33d5fb7 100644 --- a/ts.php +++ b/ts.php @@ -30,12 +30,14 @@ class AcareOffice{ private $addr_table; private $ndis_table; private $apiv1; + private $XeroOauth2; private $ndis_price; public function __construct() { $this->setup_db_name(); $this->class_loader(); $this->apiv1 = new Apiv1($this, $this->job_table); + $this->XeroOauth2 = new XeroOauth2($this); //$this->check_csv_download(); add_option( "acare_ts_db_version", "1.0" ); @@ -43,7 +45,8 @@ class AcareOffice{ //add_action('init', array($this, 'class_loader')); add_action('init', array($this, 'check_csv_download')); - + + add_action('wp', array($this, 'check_auth')); add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99); @@ -128,8 +131,8 @@ class AcareOffice{ $loader->addNamespace('\XeroPHP', dirname(__FILE__) . '/xero-php-master/src/XeroPHP'); $loader->addNamespace('\Biukop', dirname(__FILE__) . '/' ); - $this->xero = new Xero(); - $this->xero->init_wp(); + //$this->xero = new XeroOauth2($this); + //$this->xero->init_wp(); //$abc = new AddrMap("01515b52-6936-46b2-a000-9ad4cd7a5b50", "0768db6d-e5f4-4b45-89a2-29f7e8d2953c"); //$abc = new AddrMap("122eb1d0-d8c4-4fc3-8bf8-b7825bee1a01", "0768db6d-e5f4-4b45-89a2-29f7e8d2953c"); @@ -174,6 +177,10 @@ class AcareOffice{ //echo $sql; exit(); } + + public function init_xero_with_wp() { + $this->xero->init_wp(); + } private function get_ndis_price() {//help to ensure ndis_price is only build once per call