Skip to content

Commit

Permalink
Add Buy Report
Browse files Browse the repository at this point in the history
  • Loading branch information
adenvt committed Apr 30, 2015
1 parent 5f44bf5 commit 9676e93
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 11 deletions.
1 change: 1 addition & 0 deletions config/route.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ POST /home/admin/seller/deposit=Admin\Seller->Deposit
GET /home/member/server=Member\Server->All
GET /home/member/server/@id=Member\Server->Id
POST /home/member/server/@id=Member\Server->Buy
GET /home/member/server/@id/success=Member\Server->Report

GET /install=Install->install
24 changes: 19 additions & 5 deletions controller/member/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Id($f3) {
}

function Buy($f3) {
/* $server = $this->loadServer();
$server = $this->loadServer();
$account = new \Webmin($server);
if (($saldo = $this->me->saldo)<$server->price) {
$this->flash('Saldo Anda Kurang, Hub Admin utk Deposit');
Expand All @@ -50,14 +50,28 @@ function Buy($f3) {
$active = date("Y/m/d",strtotime("+30 days"));
$account->expire = \Webmin::exp_encode($active);
if( ! $account->save()) {
$this->flash('Gagal... Coba Beberapa Saat Lagi');
$this->flash('Gagal, Coba Beberapa Saat Lagi');
$f3->reroute($f3->get('URI'));
}
$this->me->saldo = $this->me->saldo-$server->price;
$this->me->save();
$this->flash('Pembelian Account Berhasil','success');*/
$f3->set('Anu','value');
$f3->reroute($f3->get('URI'));
$this->flash('Pembelian Account Berhasil','success');
$f3->set('SESSION.uid',$account->uid);
$f3->set('SESSION.pass',$pass);
$f3->reroute($f3->get('URI').'/success');
}

function Report($f3) {
$server = $this->loadServer();
if ( ! $f3->exists('SESSION.uid',$uid))
$f3->reroute('/home/member/server');
$account = new \Webmin($server);
$account->load($uid);
$account->pass = $f3->get('SESSION.pass');
$f3->set('server',$server);
$f3->set('user',$account);
$f3->set('subcontent','member/account.html');
$f3->clear('SESSION.uid');
$f3->clear('SESSION.pass');
}
}
24 changes: 18 additions & 6 deletions model/webmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ class Webmin extends \Magic {
protected
$db,
$old,
$data;
$data,
$sid;

function __construct($server) {
$url = $server->host;
$pass = $server->getPass();
$db = new xmlrpc_client('/xmlrpc.cgi',$url,10000,'http');
$db = new xmlrpc_client('xmlrpc.cgi',$url,10000,'http');
$db->setCredentials('root',$pass);
$db->return_type = 'phpvals';
$this->db = $db;
$this->sid = \Base::instance()->hash($url);
}

static function exp_decode($days) {
Expand All @@ -42,7 +44,11 @@ function exec($method,$params=NULL) {
}

function find() {
$users = $this->exec('useradmin::list_users');
$cache = \Cache::instance();
if (! $cache->exists($this->sid,$users)) {
$users = $this->exec('useradmin::list_users');
$cache->set($this->sid,$users,60);
}
$out = array();
foreach ($users as $user) {
if ($user['gid']!=100) continue;
Expand Down Expand Up @@ -89,7 +95,10 @@ function load($uid) {
}

function save() {
return ($this->old)?$this->update():$this->insert();
$result = ($this->old)?$this->update():$this->insert();
if ($result)
\Cache::instance()->clear($this->sid);
return $result;
}

function insert() {
Expand All @@ -98,8 +107,11 @@ function insert() {
$user['gid'] = 100;
$user['home'] = '/home/'.$user['user'];
$user['shell'] = '/bin/false';
if ($this->check($this->data['user']))
return $this->exec('useradmin::create_user',[$user]);
if ($this->check($this->data['user'])) {
$result = $this->exec('useradmin::create_user',[$user]);
if ($result) $this->data = $user;
return $result;
}
else return FALSE;
}

Expand Down
4 changes: 4 additions & 0 deletions view/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
}
});
});
function print_report() {
window.print();
return false;
}
</script>
</body>
</html>
51 changes: 51 additions & 0 deletions view/member/account.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
SSH Account
</h1>
</div>
</div>
<div class="row">
<check if="{{ @message }}">
<div class="col-lg-12 hidden-print">
<div class="alert alert-{{ @message['type'] }}">{{ @message['data'] }}</div>
</div>
</check>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-user fa-fw"></i> Account Details
</div>
<table class="table table-hover">
<tbody>
<tr>
<td>Username</td><td>{{ @user->user }}</td>
</tr>
<tr>
<td>Password</td><td>{{ @user->pass }}</td>
</tr>
<tr>
<td>Host</td><td>{{ @server->host }}</td>
</tr>
<tr>
<td>Lokasi</td><td>{{ @server->country }}</td>
</tr>
<tr>
<td>Harga</td><td>{{ @server->price }}</td>
</tr>
<tr>
<td>Exp</td><td>{{ \Webmin::exp_decode(@user->expire) }}</td>
</tr>
<tr class="hidden-print">
<td colspan="2">
<a href="#" class="btn btn-primary" onclick="print_report()">Print</a>
<a href="/home/member/server" class="btn btn-default">Kembali</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>

0 comments on commit 9676e93

Please sign in to comment.