Page 1 of 1

Writing addons for the bank.

Posted: Tue Nov 10, 2009 1:54 pm
by Erik Mortis
The bank can now handle add ons. below is a basic example.

Some of the code is required to be able to interact with the bank.

Code: Select all

<?php

//These are the basic require files. 
require_once '../../require/util.php'; //utility functions (need to connect to the server)
require_once '../../require/config.php'; //config file needed for various constants.
require_once '../../require/bankops.php'; //needed if you want to move money. 

//There are more libraries at your disposal but I don't plan to go into them here. 

error_reporting(E_ALL); //I require this. 

begin_session(); //needed for session to work. Only put it once. and before any HTML. 

$server = bank_server_connect(); //now you have a server connection. 

//From here on what whatever you need/want for your addon.

//If you want to move money you'll need the transfer_funds() function.
//Here is an example of it in use. 
// transfer_funds($instigator, $sender, $receiver, $funds, $reason, $server)

transfer_funds('Admin', 'Admin', 'Erik', '15.9', 'Taxes', $server)
//this will show that Admin initiated a transfer from their account to Erik's for 15.9. When logged by the function it will show the reason. 
//Most of the time $instigator and $sender should be the same person. Unless you are an admin you should not be moving money from OTHER people's accounts. 
//Though in some situation, when the other user authorized it, you might be moving money from their account to yours. 
//But try to make all funds movements based on who hits the buttons. 

//make sure to use proper XHTML and to have you ending tags. htmllib.php has some premade functions for html. 
//Ask and I can send a recent copy of all required files. 
?>
More info on transfer_funds()

Code: Select all

function transfer_funds($instigator, $sender, $receiver, $funds, $reason, $server)
//Take money from one account and put it in another. 
//Returns 0 on success. Returns 1 on failure due to insufficient funds. 
//2 is returned if the account for the reciever did not exist.
//3 if the sender doesn't exist.
//4 if trying to send to yourself.
//5 if funds to move are neg
//6 if the reciever is an Inactive account.
//7 if the instigator is an Inactive account.
//We handle cleaning up the funds.
//handles error messages and logging. 
If you want to make your own require files put them in a directory called 'require'. This will be kept separate from my require and will be in the same directory that your files are kept.

include_once ('require/myfile.php'); this is how you should do your requires. Mine are 2 directories up the tree.

Re: Writing addons for the bank.

Posted: Tue Nov 10, 2009 1:56 pm
by Andreas the Wise
Would you also want the html_lib for bank menu, header, footer etc? Or do you plan to add those onto people's mods after they've done them?

Re: Writing addons for the bank.

Posted: Tue Nov 10, 2009 1:58 pm
by Erik Mortis
I'm still trying to get functions in the right places. So some things are in odd places. but util.php has some html functions.


Just checked. bank_menu is in util.php, but won't work for a mod due to how the links are done. mods are kept in ./mod/modname/ while the bank is in ./ (from the point of view of files). bank_menu references from where it is called. so in a mod it is not called ./ which is where it expects to find files.

header and footer are in htmllib.php.


Most of the 'select' function are in util.php including one that lets you display a list of users to select from.

Re: Writing addons for the bank.

Posted: Tue Nov 10, 2009 2:12 pm
by Erik Mortis
If you want to access session info it's easy.

These are the variables you'll need. There are a few more. but you shouldn't need them, and for security I won't make them public. but if you mess with them I'll know.
$_SESSION['authorized'] //if true they are logged in
$_SESSION['username'] //their username.
$_SESSION['subdivision'] //what subdivision they are in.
$_SESSION['country'] //what country they are in.
$_SESSION['style'] //what style they use for their style sheets. if you make your own html header you will need to access this to get the css right. ../../styles is where you can find the styles from the point of view of the mod files you are making.

Re: Writing addons for the bank.

Posted: Fri Nov 13, 2009 9:30 pm
by vasroe
So does any file containing this stuff have to be on the SC bank's web server account?

If so, whom might I contact to grant me access to upload a few files to that account?

Re: Writing addons for the bank.

Posted: Fri Nov 13, 2009 10:10 pm
by Erik Mortis
Ari, or myself have the access needed. You can send files to either of us. Though ask him first. I can't speak for his willingness to bother with this.

Re: Writing addons for the bank.

Posted: Mon Jan 11, 2010 2:36 pm
by Erik Mortis
I'll be starting a new thread about how to work with transfer_funds(). The info here will be slightly outdated.

http://shireroth.org/forum/viewtopic.php?f=226&t=12580