diff --git a/src/Controller/StateBalancesController.php b/src/Controller/StateBalancesController.php
index 74f598d19..31febe498 100644
--- a/src/Controller/StateBalancesController.php
+++ b/src/Controller/StateBalancesController.php
@@ -21,7 +21,7 @@ class StateBalancesController extends AppController
{
parent::initialize();
//$this->Auth->allow(['add', 'edit']);
- $this->Auth->allow(['overview', 'overviewGdt', 'ajaxListTransactions', 'ajaxGdtOverview', 'ajaxGetBalance']);
+ $this->Auth->allow(['overview', 'overviewGdt', 'ajaxListTransactions', 'ajaxGdtOverview', 'ajaxGetBalance', 'ajaxGdtTransactions']);
$this->loadComponent('JsonRequestClient');
}
/**
@@ -208,7 +208,6 @@ class StateBalancesController extends AppController
$this->set('timeUsed', microtime(true) - $startTime);
$this->set('gdtSum', $gdtSum);
}
-<<<<<<< HEAD
public function ajaxGetBalance($session_id = 0)
{
@@ -387,148 +386,36 @@ class StateBalancesController extends AppController
public function ajaxListTransactions($page = 0, $count = 20)
{
+
+ return $this->returnJson([
+ 'state' => 'error',
+ 'msg' => 'moved',
+ 'details' => 'moved to state-user-transactions/ajaxListTransactions/'
+ ]);
+ }
+
+ public function ajaxGdtOverview()
+ {
+ $gdtSum = 0;
+ $gdtCount = -1;
$session = $this->getRequest()->getSession();
$user = $session->read('StateUser');
+
if(!$user) {
return $this->returnJson(['state' => 'error', 'msg' => 'user not found', 'details' => 'exist a valid session cookie?']);
}
- $stateUserTransactionsTable = TableRegistry::getTableLocator()->get('StateUserTransactions');
- $paged_state_user_transactions = $stateUserTransactionsTable
- ->find('all')
- ->where(['state_user_id' => $user['id'], 'transaction_type_id IN' => [1,2]])
- ->limit($count)
- ->page($page)
- ->order(['transaction_id'])
- ;
- $all_user_transactions_count = $stateUserTransactionsTable
- ->find('all')
- ->where(['state_user_id' => $user['id'], 'transaction_type_id IN' => [1,2]])
- ->count()
- ;
- $creationTransaction_ids = [];
- $transferTransaction_ids = [];
- $allTransaction_ids = [];
- foreach($paged_state_user_transactions as $state_user_transaction) {
- $allTransaction_ids[] = $state_user_transaction->transaction_id;
- switch($state_user_transaction->transaction_type_id) {
- case 1: $creationTransaction_ids[] = $state_user_transaction->transaction_id; break;
- case 2: $transferTransaction_ids[] = $state_user_transaction->transaction_id; break;
- }
- }
- $transactionsTable = TableRegistry::getTableLocator()->get('Transactions');
- $transactionCreationsTable = TableRegistry::getTableLocator()->get('TransactionCreations');
- $transactionSendCoinsTable = TableRegistry::getTableLocator()->get('TransactionSendCoins');
- $stateUsersTable = TableRegistry::getTableLocator()->get('StateUsers');
- if(count($allTransaction_ids) > 0) {
- $transactionEntries = $transactionsTable->find('all')->where(['id IN' => $allTransaction_ids])->order(['id'])->toArray();
- }
- if(count($creationTransaction_ids) > 0) {
- $transactionCreations = $transactionCreationsTable->find('all')->where(['transaction_id IN' => $creationTransaction_ids]);
- }
- if(count($transferTransaction_ids)) {
- $transactionTransfers = $transactionSendCoinsTable->find('all')->where(['transaction_id IN' => $transferTransaction_ids]);
- }
- //var_dump($transactions->all());
+ $gdtEntries = $this->JsonRequestClient->sendRequestGDT(['email' => $user['email']], 'GdtEntries' . DS . 'sumPerEmailApi');
- $transactions = [];
- // creations
- if(isset($transactionCreations)) {
- foreach ($transactionCreations as $creation) {
- //var_dump($creation);
- $transaction_entries_index = array_search($creation->transaction_id, $allTransaction_ids);
- if(FALSE === $transaction_entries_index) {
- return $this->returnJson(['state' => 'error', 'msg' => 'code error', 'details' => 'creation, transaction_entries_index is FALSE, shouldn\'t occure']);
- }
- $transaction = $transactionEntries[$transaction_entries_index];
- array_push($transactions, [
- 'name' => 'Gradido Akademie',
- 'type' => 'creation',
- 'transaction_id' => $creation->transaction_id,
- 'date' => $transaction->received,
- 'balance' => $creation->amount,
- 'memo' => $transaction->memo
- ]);
+ if('success' == $gdtEntries['state'] && 'success' == $gdtEntries['data']['state']) {
+ $gdtSum = intval($gdtEntries['data']['sum']);
+ if(isset($gdtEntries['data']['count'])) {
+ $gdtCount = intval($gdtEntries['data']['count']);
}
- }
-
- // involved users
- if(isset($transactionTransfers)) {
- $involvedUserIds = [];
-
- foreach ($transactionTransfers as $transfer) {
- //var_dump($sendCoins);
- if ($transfer->state_user_id != $user['id']) {
- array_push($involvedUserIds, intval($transfer->state_user_id));
- } elseif ($transfer->receiver_user_id != $user['id']) {
- array_push($involvedUserIds, intval($transfer->receiver_user_id));
- }
- }
-
- // exchange key with values and drop duplicates
- $involvedUser_temp = array_flip($involvedUserIds);
- // exchange back
- $involvedUserIds = array_flip($involvedUser_temp);
-
- $involvedUser = $stateUsersTable->find('all', [
- 'contain' => false,
- 'where' => ['id IN' => $involvedUserIds],
- 'fields' => ['id', 'first_name', 'last_name', 'email']
- ]);
- //var_dump($involvedUser->toArray());
- $involvedUserIndices = [];
- foreach ($involvedUser as $involvedUser) {
- $involvedUserIndices[$involvedUser->id] = $involvedUser;
- }
-
- // transfers - send coins
- foreach($transactionTransfers as $transfer)
- {
- $transaction_entries_index = array_search($transfer->transaction_id, $allTransaction_ids);
- if(FALSE === $transaction_entries_index) {
-
- return $this->returnJson([
- 'state' => 'error',
- 'msg' => 'code error',
- 'details' => 'transfer, transaction_entries_index is FALSE, shouldn\'t occure',
- 'data' => ['haystack' => $allTransaction_ids, 'needle' => $transfer->transaction_id]
- ]);
- }
- $transaction = $transactionEntries[$transaction_entries_index];
- $type = '';
- $otherUser = null;
- $other_user_public = '';
-
- if ($transfer->state_user_id == $user['id']) {
- $type = 'send';
-
- if(isset($involvedUserIndices[$transfer->receiver_user_id])) {
- $otherUser = $involvedUserIndices[$transfer->receiver_user_id];
- }
- $other_user_public = bin2hex(stream_get_contents($transfer->receiver_public_key));
- } else if ($transfer->receiver_user_id == $user['id']) {
- $type = 'receive';
- if(isset($involvedUserIndices[$transfer->state_user_id])) {
- $otherUser = $involvedUserIndices[$transfer->state_user_id];
- }
- if($transfer->sender_public_key) {
- $other_user_public = bin2hex(stream_get_contents($transfer->sender_public_key));
- }
- }
- if(null == $otherUser) {
- $otherUser = $stateUsersTable->newEntity();
- }
- array_push($transactions, [
- 'name' => $otherUser->first_name . ' ' . $otherUser->last_name,
- 'email' => $otherUser->email,
- 'type' => $type,
- 'transaction_id' => $transfer->transaction_id,
- 'date' => $transaction->received,
- 'balance' => $transfer->amount,
- 'memo' => $transaction->memo,
- 'pubkey' => $other_user_public
- ]);
- //*/
-
+ } else {
+ if($user) {
+ $this->addAdminError('StateBalancesController', 'ajaxGdtOverview', $gdtEntries, $user['id']);
+ } else {
+ $this->addAdminError('StateBalancesController', 'ajaxGdtOverview', $gdtEntries, 0);
}
}
@@ -590,9 +477,9 @@ class StateBalancesController extends AppController
//echo "gdtSum: $gdtSum
";
$this->set('gdtSum', $gdtSum);
$this->set('ownEntries', $ownEntries);
- $this->set('gdtSumPerEmail', $requestResult['data']['gdtSumPerEmail']);
- $this->set('moreEntrysAsShown', $requestResult['data']['moreEntrysAsShown']);
- $this->set('user', $user);
+ $this->set('gdtSumPerEmail', $requestResult['data']['gdtSumPerEmail']);
+ $this->set('moreEntrysAsShown', $requestResult['data']['moreEntrysAsShown']);
+ $this->set('user', $user);
if (isset($requestResult['data']['publishers'])) {
$publishers = $requestResult['data']['publishers'];
@@ -603,6 +490,66 @@ class StateBalancesController extends AppController
$this->Flash->error(__('Fehler beim GDT Server, bitte abwarten oder den Admin benachrichtigen!'));
}
}
+
+ public function ajaxGdtTransactions()
+ {
+ $startTime = microtime(true);
+ $session = $this->getRequest()->getSession();
+ $user = $session->read('StateUser');
+ if(!$user) {
+ return $this->returnJson(['state' => 'error', 'msg' => 'user not found', 'details' => 'exist a valid session cookie?']);
+ }
+
+ $requestResult = $this->JsonRequestClient->sendRequestGDT(['email' => $user['email']], 'GdtEntries' . DS . 'listPerEmailApi');
+ $connectEntries = [];
+ $publishers = [];
+
+ //var_dump($requestResult);
+ if('success' === $requestResult['state'] && 'success' === $requestResult['data']['state']) {
+
+ //var_dump(array_keys($requestResult['data']));
+ $ownEntries = $requestResult['data']['ownEntries'];
+ //$gdtEntries = $requestResult['data']['entries'];
+
+ $gdtSum = 0;
+ foreach ($ownEntries as $i => $gdtEntry) {
+ $gdtSum += $gdtEntry['gdt'];
+ //echo "index: $i
";
+ //var_dump($gdtEntry);
+ }
+ if (isset($requestResult['data']['connectEntrys'])) {
+ $connectEntries = $requestResult['data']['connectEntrys'];
+
+ foreach ($connectEntries as $entry) {
+ //if(!$count) var_dump($entry);
+ //$count++;
+ $gdtSum += $entry['connect']['gdt_entry']['gdt'];
+ }
+ }
+
+ //echo "gdtSum: $gdtSum
";
+
+ if (isset($requestResult['data']['publishers'])) {
+ $publishers = $requestResult['data']['publishers'];
+ }
+ } else {
+ $this->addAdminError('StateBalancesController', 'ajaxGdtTransactions', $requestResult, $user['id']);
+ //$this->Flash->error(__('Fehler beim GDT Server, bitte abwarten oder den Admin benachrichtigen!'));
+ return $this->returnJson(['state' => 'error', 'msg' => 'error from gdt server', 'details' => $requestResult]);
+ }
+
+
+ return $this->returnJson([
+ 'state' => 'success',
+ 'gdtSum' => $gdtSum,
+ 'ownEntries' => $ownEntries,
+ 'connectEntries' => $connectEntries,
+ 'publishers' => $publishers,
+ 'gdtSumPerEmail' => $requestResult['data']['gdtSumPerEmail'],
+ 'moreEntrysAsShown' => $requestResult['data']['moreEntrysAsShown'],
+ 'timeUsed' => microtime(true) - $startTime
+ ]);
+ }
public function sortTransactions($a, $b)
{
diff --git a/webroot/css/grd_styles.css b/webroot/css/grd_styles.css
index 08ecdc3a5..e745ea55e 100644
--- a/webroot/css/grd_styles.css
+++ b/webroot/css/grd_styles.css
@@ -1582,6 +1582,46 @@ To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
*/
+/*
+ Created on : 23.11.2020, 14:04:28
+ Author : einhornimmond
+*/
+/* Style the tab */
+.tab {
+ overflow: hidden;
+ border: 1px solid #ccc;
+ background-color: #f1f1f1;
+}
+/* Style the buttons that are used to open the tab content */
+.tab button {
+ background-color: inherit;
+ float: left;
+ border: none;
+ outline: none;
+ cursor: pointer;
+ padding: 14px 16px;
+ transition: 0.3s;
+}
+/* Change background color of buttons on hover */
+.tab button:hover {
+ background-color: #ddd;
+}
+/* Create an active/current tablink class */
+.tab button.active {
+ background-color: #ccc;
+}
+/* Style the tab content */
+.tabcontent {
+ display: none;
+ padding: 6px 12px;
+ border: 1px solid #ccc;
+ border-top: none;
+}
+/*
+To change this license header, choose License Headers in Project Properties.
+To change this template file, choose Tools | Templates
+and open the template in the editor.
+*/
/* ============================================================
Screen styles for forms.
diff --git a/webroot/js/tabs.js b/webroot/js/tabs.js
new file mode 100644
index 000000000..2db9ab693
--- /dev/null
+++ b/webroot/js/tabs.js
@@ -0,0 +1,27 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+
+function openTab(evt, tabName) {
+ // Declare all variables
+ var i, tabcontent, tablinks;
+
+ // Get all elements with class="tabcontent" and hide them
+ tabcontent = document.getElementsByClassName("tabcontent");
+ for (i = 0; i < tabcontent.length; i++) {
+ tabcontent[i].style.display = "none";
+ }
+
+ // Get all elements with class="tablinks" and remove the class "active"
+ tablinks = document.getElementsByClassName("tablinks");
+ for (i = 0; i < tablinks.length; i++) {
+ tablinks[i].className = tablinks[i].className.replace(" active", "");
+ }
+
+ // Show the current tab, and add an "active" class to the button that opened the tab
+ document.getElementById(tabName).style.display = "block";
+ evt.currentTarget.className += " active";
+}
\ No newline at end of file
diff --git a/websrc/src/less/21-tabs.less b/websrc/src/less/21-tabs.less
new file mode 100644
index 000000000..694dd1dab
--- /dev/null
+++ b/websrc/src/less/21-tabs.less
@@ -0,0 +1,45 @@
+/*
+To change this license header, choose License Headers in Project Properties.
+To change this template file, choose Tools | Templates
+and open the template in the editor.
+*/
+/*
+ Created on : 23.11.2020, 14:04:28
+ Author : einhornimmond
+*/
+
+ /* Style the tab */
+.tab {
+ overflow: hidden;
+ border: 1px solid #ccc;
+ background-color: #f1f1f1;
+}
+
+/* Style the buttons that are used to open the tab content */
+.tab button {
+ background-color: inherit;
+ float: left;
+ border: none;
+ outline: none;
+ cursor: pointer;
+ padding: 14px 16px;
+ transition: 0.3s;
+}
+
+/* Change background color of buttons on hover */
+.tab button:hover {
+ background-color: #ddd;
+}
+
+/* Create an active/current tablink class */
+.tab button.active {
+ background-color: #ccc;
+}
+
+/* Style the tab content */
+.tabcontent {
+ display: none;
+ padding: 6px 12px;
+ border: 1px solid #ccc;
+ border-top: none;
+}
\ No newline at end of file