| @@ -4,3 +4,4 @@ xero-php-master | |||
| .buildpath | |||
| .project | |||
| sample | |||
| /vendor/ | |||
| @@ -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/ | |||
| @@ -0,0 +1,8 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <project version="4"> | |||
| <component name="ProjectModuleManager"> | |||
| <modules> | |||
| <module fileurl="file://$PROJECT_DIR$/.idea/ts.iml" filepath="$PROJECT_DIR$/.idea/ts.iml" /> | |||
| </modules> | |||
| </component> | |||
| </project> | |||
| @@ -0,0 +1,36 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <project version="4"> | |||
| <component name="PhpIncludePathManager"> | |||
| <include_path> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/version" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/diff" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/recursion-context" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/exporter" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/doctrine/instantiator" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/environment" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/comparator" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/global-state" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/phpspec/prophecy" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/phpunit" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/webmozart/assert" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/symfony/yaml" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/symfony/polyfill-ctype" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/php-code-coverage" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/phpunit-mock-objects" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/php-token-stream" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/composer" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/php-text-template" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/php-file-iterator" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/php-timer" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/phpdocumentor/reflection-docblock" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/phpdocumentor/type-resolver" /> | |||
| <path value="$PROJECT_DIR$/xero-php-master/vendor/phpdocumentor/reflection-common" /> | |||
| </include_path> | |||
| </component> | |||
| <component name="PhpProjectSharedConfiguration" php_language_level="5.5.0" /> | |||
| <component name="PhpUnit"> | |||
| <phpunit_settings> | |||
| <PhpUnitSettings custom_loader_path="$PROJECT_DIR$/xero-php-master/vendor/autoload.php" /> | |||
| </phpunit_settings> | |||
| </component> | |||
| </project> | |||
| @@ -0,0 +1,35 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <module type="WEB_MODULE" version="4"> | |||
| <component name="NewModuleRootManager"> | |||
| <content url="file://$MODULE_DIR$"> | |||
| <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" /> | |||
| <sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" /> | |||
| <sourceFolder url="file://$MODULE_DIR$/xero-php-master/src/XeroPHP" isTestSource="false" packagePrefix="XeroPHP\" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/version" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/diff" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/recursion-context" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/exporter" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/doctrine/instantiator" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/environment" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/comparator" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/global-state" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpspec/prophecy" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/phpunit" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/webmozart/assert" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/symfony/yaml" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/symfony/polyfill-ctype" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/php-code-coverage" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/phpunit-mock-objects" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/php-token-stream" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/composer" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/php-text-template" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/php-file-iterator" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/php-timer" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpdocumentor/reflection-docblock" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpdocumentor/type-resolver" /> | |||
| <excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpdocumentor/reflection-common" /> | |||
| </content> | |||
| <orderEntry type="inheritedJdk" /> | |||
| <orderEntry type="sourceFolder" forTests="false" /> | |||
| </component> | |||
| </module> | |||
| @@ -0,0 +1,6 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <project version="4"> | |||
| <component name="VcsDirectoryMappings"> | |||
| <mapping directory="$PROJECT_DIR$" vcs="Git" /> | |||
| </component> | |||
| </project> | |||
| @@ -0,0 +1,168 @@ | |||
| <?php | |||
| namespace Biukop; | |||
| class StorageClass | |||
| { | |||
| private $path; | |||
| private $oauth2 = []; | |||
| private $oauth2state = ""; | |||
| function __construct() { | |||
| $this->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; | |||
| } | |||
| } | |||
| } | |||
| ?> | |||
| @@ -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); | |||
| } | |||
| } | |||
| @@ -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; | |||
| @@ -32,7 +32,7 @@ | |||
| </div> | |||
| <div class='timesheets'> | |||
| <div class='sheettitle titlebar_gradient'> | |||
| <h1>Web Office 2020 - Today:<span name='today'> Today </span> <a style="float:right;margin-right:20px;" href="/time-sheets/"> (old verion 2019) </a></h1> | |||
| <h1 class="today">Web Office 2021 - Today:<span name='today'> Today </span></h1> | |||
| </div> | |||
| <div class='sheetsheader'> | |||
| <div class='weekly'> | |||
| @@ -195,4 +195,4 @@ | |||
| Confirm_Schedule | |||
| </button> | |||
| </div> | |||
| </div> | |||
| </div> | |||
| @@ -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; | |||
| @@ -28,7 +28,7 @@ function on_download_ndis_csv (){} | |||
| function loading() | |||
| { | |||
| return "<tr class='loading' ><td colspan=4 class='loading'><img src='"+bts().load_job_img +"'><br><h1>Sync to Xero</h1></td></tr>"; | |||
| return "<tr class='loading' ><td colspan=4 class='loading'><img src='"+bts().load_job_img +"'><br><h1>Sync to XeroOauth1</h1></td></tr>"; | |||
| } | |||
| function display_hour_lines(response) | |||
| @@ -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 | |||