Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Mys v1.3.x Mods (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=42)
-   -   Mys v1.3.4 Bank Mod (http://www.mysidiaadoptables.com/forum/showthread.php?t=5290)

Dinocanid 12-10-2016 01:02 PM

Bank Mod
 
1 Attachment(s)
-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:
Code:

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. 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 Code:

<?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 Code:

 <?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:
PHP Code:

public $bank

Afterwards, add this with the rest of the functions:
PHP Code:

  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:
PHP Code:

public $bank

And this with the other functions:
PHP Code:

      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.

parayna 12-10-2016 02:15 PM

OK, I tinkered with it a bit and made it so that the deposit and withdraw are two separate things for my site... that way the deposit and withdraw parts are hidden when doing one or the other! I basically did it by creating bank_deposit and bank_withdraw.php files as well as their view files. And they work, woo! XD This also let me use the Admin CP to create my bank page as I could just link to those pages from a custom page but I am going to create a PHP one so that it is linked under {url}bank instead of {url}pages/view/bank XD

There was probably an easier way of hiding them so I didn't have to create these files but I'm happy with doing this as then I can add images to each available page and not worry about them showing up wrong. If the text and code isn't in one file, there is no chance of it showing the wrong text/code unless I mess up! XD

Thanks for the code ^_^

Dinocanid 12-10-2016 09:54 PM

Added a pretty important update so users can no longer withdraw more money than they have in the bank and deposit money they don't have.

ffsharriet 01-15-2017 10:16 AM

I can't find where to add a new column?

Name: bank
Type: int
Length/Values: 11
Default: As defined 0
check the null box

I have no where to add this. Could you provide a screen shot to where I can find it please?

Dinocanid 01-15-2017 10:32 AM

You go to phpMyAdmin, find and select adopts_users, and then add a new column under the structure tab with the given information:
http://i.imgur.com/2hTPW1r.gif


All times are GMT -5. The time now is 04:55 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.