-
Notifications
You must be signed in to change notification settings - Fork 11
/
getcommunityfundinfo.php
133 lines (121 loc) · 7.01 KB
/
getcommunityfundinfo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
include ("header.php");
include ("pass.php");
$communityfundinfos = $coin->cfundstats();
$proposalvotelist = $coin->proposalvotelist();
$proposalYesVotes = $proposalvotelist['yes'];
$proposalNoVotes = $proposalvotelist['no'];
$proposalNotVoted = $proposalvotelist['null'];
$paymentrequestvotelist = $coin->paymentrequestvotelist();
$paymentRequestYesVotes = $paymentrequestvotelist['yes'];
$paymentRequestNoVotes = $paymentrequestvotelist['no'];
$paymentRequestNotVoted = $paymentrequestvotelist['null'];
?>
<p><b>Community Fund Infos</b></p>
<p>Currently voted on proposals</p>
<div class="panel panel-default">
<div class="table-responsive">
<?php
echo "<table class='table-hover table-condensed table-bordered table'>
<thead>
<tr>
<th>Description</th>
<th>Amount</th>
<th>Your vote</th>
<th>Vote</th>
</tr>";
// at the moment, proposalvotelist() returns a string which would have to be parsed
// it's easier to loop over the result of cfundstats until proposalvotelist returns a json object
// with the json, we could loop over the yes-votes, no-votes, non-votes separately and don't have to check them
foreach ($communityfundinfos['votingPeriod']['votedProposals'] as $row) {
$desc = $row['str'];
$amount = $row['amount'];
$hash = $row['hash'];
$isYesVote = array_filter($proposalYesVotes, function($var) use ($hash) { return preg_match("/\b$hash\b/i", $var); });
$isNoVote = array_filter($proposalNoVotes, function($var) use ($hash) { return preg_match("/\b$hash\b/i", $var); });
$isNotVoted = array_filter($proposalNotVoted, function($var) use ($hash) { return preg_match("/\b$hash\b/i", $var); });
$yourVote = (!empty($isYesVote) ? "Yes" : (!empty($isNoVote) ? "No" : "Not Voted"));
echo "<tr>
<td class='valignmiddle' style='width:70%'>{$desc}</td>
<td class='valignmiddle'>{$amount}</td>
<td class='valignmiddle'>{$yourVote}</td>
<td class='valignmiddle'>
<div class='input-group'>
<span class='input-group-btn'>
<form action='command' method='POST'>
<button style='float:left' class='btn btn-default' type='submit' value='command'>Yes</button>
<input type='hidden' name='order' value='proposalvote' />
<input type='hidden' name='var1' value='{$hash}' />
<input type='hidden' name='var2' value='yes' />
</form>
<form action='command' method='POST'><input type='hidden'>
<button class='btn btn-default' type='submit' value='command'>No</button>
<input type='hidden' name='order' value='proposalvote' />
<input type='hidden' name='var1' value='{$hash}' />
<input type='hidden' name='var2' value='no' />
</form>
</span>
</div>
</td>
</tr>";
} //endforeach
echo "</table>";
?>
</div>
</div>
<p>Currently voted on payment requests</p>
<div class="panel panel-default">
<div class="table-responsive">
<?php
echo "<table class='table-hover table-condensed table-bordered table'>
<thead>
<tr>
<th>Proposal Description</th>
<th>Payment Request Description</th>
<th>Amount</th>
<th>Your vote</th>
<th>Vote</th>
</tr>";
// at the moment, paymentrequestvotelist() returns a string which would have to be parsed
// it's easier to loop over the result of cfundstats until paymentrequestvotelist returns a json object
// with the json, we could loop over the yes-votes, no-votes, non-votes separately and don't have to check them
foreach ($communityfundinfos['votingPeriod']['votedPaymentrequests'] as $row) {
$proposalDesc = $row['proposalDesc'];
$paymentRequestDesc = $row['desc'];
$amount = $row['amount'];
$hash = $row['hash'];
$isYesVote = array_filter($paymentRequestYesVotes, function($var) use ($hash) { return preg_match("/\b$hash\b/i", $var); });
$isNoVote = array_filter($paymentRequestNoVotes, function($var) use ($hash) { return preg_match("/\b$hash\b/i", $var); });
$isNotVoted = array_filter($paymentRequestNotVoted, function($var) use ($hash) { return preg_match("/\b$hash\b/i", $var); });
$yourVote = (!empty($isYesVote) ? "Yes" : (!empty($isNoVote) ? "No" : "Not Voted"));
echo "<tr>
<td class='valignmiddle' style='width:35%'>{$proposalDesc}</td>
<td class='valignmiddle' style='width:35%'>{$paymentRequestDesc}</td>
<td class='valignmiddle'>{$amount}</td>
<td class='valignmiddle'>{$yourVote}</td>
<td class='valignmiddle'>
<div class='input-group'>
<span class='input-group-btn'>
<form action='command' method='POST'><input type='hidden'>
<button style='float:left' class='btn btn-default' type='submit' value='command'>Yes</button>
<input type='hidden' name='order' value='paymentrequestvote' />
<input type='hidden' name='var1' value='{$hash}' />
<input type='hidden' name='var2' value='yes' />
</form>
<form action='command' method='POST'>
<button class='btn btn-default' type='submit' value='command'>No</button>
<input type='hidden' name='order' value='paymentrequestvote' />
<input type='hidden' name='var1' value='{$hash}' />
<input type='hidden' name='var2' value='no' />
</form>
</span>
</div>
</td>
</tr>";
} //endforeach
echo "</table>";
?>
</div>
</div>
</div>
<?php include ("footer.php"); ?>