Dinocanid
12-10-2016, 01:02 PM
-Before we start--
If you have a fresh install of the mysidia script or you have unmodified files, you may download the attachments at the bottom. (You still must follow step 0) If you would rather install it manually, follow the instructions below.
-Step 0-
Go to phpMyAdmin, adopts_users, and create a new column with this info:
Name: bank
Type: int
Length/Values: 11
Default: As defined 0
check the null box
-Step 1-
Create a new page for your bank from scratch. If you don't know how to make pages from scratch go here (http://www.mysidiaadoptables.com/forum/showpost.php?p=32248&postcount=2). Do not create a new page from the admincp.
Create a file named bank.php in your root folder and add the following contents:
<?php
class BankController extends AppController{
public function __construct(){
parent::__construct("member");
}
public function index(){
$mysidia = Registry::get("mysidia");
}
}
?>
Next, make a new file called bankview.php in your view folder with the following contents:
<?php
class BankView extends View{
public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle("The Bank");
$balance = $mysidia->user->getbank();
$cash = $mysidia->user->getcash();
if ($balance <= 0){
$document->add(new Comment("<h2>Current Balance: $0</h2>"));
}
else $document->add(new Comment("<h2>Current Balance: $ {$balance}</h2>", FALSE));
$document->add(new paragraph);
if($mysidia->input->post("deposit")){
$amount = $mysidia->input->post("amount");
$balance = $mysidia->db->select("users", array("bank"))->fetchColumn();
if($amount > $cash){$document->add(new Comment("You don't have that much to deposit!")); return TRUE;}
$mysidia->user->changecash(-$amount);
$mysidia->user->changebank(+$amount);
$document->add(new Comment("<h2>You deposited $ {$amount} into your bank account</h2>", FALSE));
$document->add(new Comment("<br><a href='{$path}bank'>Return to Bank</a> ", FALSE));
return TRUE;}
$depositForm = new FormBuilder("depositForm", "", "post");
$depositForm->buildComment("Amount: ", FALSE)
->buildTextField("amount", FALSE)
->buildButton("Deposit", "deposit", "submit");
$document->add($depositForm);
if($mysidia->input->post("withdraw")){
$amount = $mysidia->input->post("amount");
$balance = $mysidia->db->select("users", array("bank"))->fetchColumn();
if($amount > $balance){$document->add(new Comment("You don't have that much to withdraw!")); return TRUE;}
else{$mysidia->user->changecash(+$amount);
$mysidia->user->changebank(-$amount);}
$document->add(new Comment("<h2>You withdrew $ {$amount} from your bank account</h2>", FALSE));
$document->add(new Comment("<br><a href='{$path}bank'>Return to Bank</a> ", FALSE));
return TRUE;}
$withdrawForm = new FormBuilder("withdrawForm", "", "post");
$withdrawForm->buildComment("Amount: ", FALSE)
->buildTextField("amount", FALSE)
->buildButton("Withdraw", "withdraw", "submit");
$document->add($withdrawForm);
}
}
?>
-Step 2-
Now go to class_member.php and add this with the other public items:
public $bank;
Afterwards, add this with the rest of the functions:
public function changebank($amount){
$mysidia = Registry::get("mysidia");
if(!is_numeric($amount)) throw new Exception('Cannot change user money by a non-numeric value!');
$this->bank += $amount;
if($this->bank >= 0){
$mysidia->db->update("users", array("bank" => $this->bank), "username = '{$this->username}'");
return TRUE;
}
///else throw new InvalidActionException("It seems that {$this->username} cannot afford this transaction.");
}
(The else function is commented out for now so the user avoids any errors. I'll clean it up when I find a way)
Next, go to class_user.php and add this with the other public things:
public $bank;
And this with the other functions:
public function getbank(){
return $this->bank;
}
-End-
That should be it. Now users are able to add and withdraw from a bank account that holds their currency.
-Attachment-
The bank.php file goes in your root/public_html folder while bankview.php goes in your view folder. Please do not use the attachments if you have heavily modified files as it can cause errors! Follow the manual tutorial instead.
If you have a fresh install of the mysidia script or you have unmodified files, you may download the attachments at the bottom. (You still must follow step 0) If you would rather install it manually, follow the instructions below.
-Step 0-
Go to phpMyAdmin, adopts_users, and create a new column with this info:
Name: bank
Type: int
Length/Values: 11
Default: As defined 0
check the null box
-Step 1-
Create a new page for your bank from scratch. If you don't know how to make pages from scratch go here (http://www.mysidiaadoptables.com/forum/showpost.php?p=32248&postcount=2). Do not create a new page from the admincp.
Create a file named bank.php in your root folder and add the following contents:
<?php
class BankController extends AppController{
public function __construct(){
parent::__construct("member");
}
public function index(){
$mysidia = Registry::get("mysidia");
}
}
?>
Next, make a new file called bankview.php in your view folder with the following contents:
<?php
class BankView extends View{
public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle("The Bank");
$balance = $mysidia->user->getbank();
$cash = $mysidia->user->getcash();
if ($balance <= 0){
$document->add(new Comment("<h2>Current Balance: $0</h2>"));
}
else $document->add(new Comment("<h2>Current Balance: $ {$balance}</h2>", FALSE));
$document->add(new paragraph);
if($mysidia->input->post("deposit")){
$amount = $mysidia->input->post("amount");
$balance = $mysidia->db->select("users", array("bank"))->fetchColumn();
if($amount > $cash){$document->add(new Comment("You don't have that much to deposit!")); return TRUE;}
$mysidia->user->changecash(-$amount);
$mysidia->user->changebank(+$amount);
$document->add(new Comment("<h2>You deposited $ {$amount} into your bank account</h2>", FALSE));
$document->add(new Comment("<br><a href='{$path}bank'>Return to Bank</a> ", FALSE));
return TRUE;}
$depositForm = new FormBuilder("depositForm", "", "post");
$depositForm->buildComment("Amount: ", FALSE)
->buildTextField("amount", FALSE)
->buildButton("Deposit", "deposit", "submit");
$document->add($depositForm);
if($mysidia->input->post("withdraw")){
$amount = $mysidia->input->post("amount");
$balance = $mysidia->db->select("users", array("bank"))->fetchColumn();
if($amount > $balance){$document->add(new Comment("You don't have that much to withdraw!")); return TRUE;}
else{$mysidia->user->changecash(+$amount);
$mysidia->user->changebank(-$amount);}
$document->add(new Comment("<h2>You withdrew $ {$amount} from your bank account</h2>", FALSE));
$document->add(new Comment("<br><a href='{$path}bank'>Return to Bank</a> ", FALSE));
return TRUE;}
$withdrawForm = new FormBuilder("withdrawForm", "", "post");
$withdrawForm->buildComment("Amount: ", FALSE)
->buildTextField("amount", FALSE)
->buildButton("Withdraw", "withdraw", "submit");
$document->add($withdrawForm);
}
}
?>
-Step 2-
Now go to class_member.php and add this with the other public items:
public $bank;
Afterwards, add this with the rest of the functions:
public function changebank($amount){
$mysidia = Registry::get("mysidia");
if(!is_numeric($amount)) throw new Exception('Cannot change user money by a non-numeric value!');
$this->bank += $amount;
if($this->bank >= 0){
$mysidia->db->update("users", array("bank" => $this->bank), "username = '{$this->username}'");
return TRUE;
}
///else throw new InvalidActionException("It seems that {$this->username} cannot afford this transaction.");
}
(The else function is commented out for now so the user avoids any errors. I'll clean it up when I find a way)
Next, go to class_user.php and add this with the other public things:
public $bank;
And this with the other functions:
public function getbank(){
return $this->bank;
}
-End-
That should be it. Now users are able to add and withdraw from a bank account that holds their currency.
-Attachment-
The bank.php file goes in your root/public_html folder while bankview.php goes in your view folder. Please do not use the attachments if you have heavily modified files as it can cause errors! Follow the manual tutorial instead.