Class stockmaniac

Description

StockManiac

This is the base system. It provides access to the output subsystem (templates), the database interface and generic StockManiac data. It implements core logic to handle plugins, settings, users, ... and a few other things.

Use this class to access everything.

Located in /lib/stockmaniac.class.php (line 70)

session
   |
   --gui
      |
      --dbc
         |
         --dbi
            |
            --stockmaniac
Variable Summary
Method Summary
 void __construct ([string $login = FALSE], [string $pass = FALSE], [bool $logout = FALSE], [bool $skip_db_check = FALSE])
 void abort (mixed $msg)
 void abort_access_denied (mixed $msg)
 int add_time_to_day ([int $day = false])
 object analyse_order (object $dao_order, int $date)
 bool check_acl (string $plugin)
 string check_url (string $str)
 array create_bar (array $arr, string $type_filter, [ $baseurl = FALSE], string $url_opt)
 void error (mixed $msg)
 string get_setting (string $name, [string $type = 'plugin'], [string $plugin = false])
 array get_setting_select (string $name, [string $type = 'plugin'], [string $plugin = false])
 void message (mixed $msg)
 void notice (mixed $msg)
 string Pager (int $page, int $lastpage, [int $length = 5])
 int|float percentage (int|float $base, int|float $val, [bool $diff = false])
 void run_plugin (string $name)
 void set_date ([int $timestamp = false])
 bool set_editor ([string $editor = FALSE])
 void set_id_portfolio ([int $id_portfolio = false])
 void set_pnid ([int $pnid = false])
 int set_setting (string $type, string $var, string $val, [string $name = false])
 void set_title ([string $title = FALSE])
 int store_document (array $doc)
 void _add_plugin (string $name, array $arr)
 bool _check_login ([string $user = false], [string $pass = false])
 bool _check_version (string $login)
 void _load_plugins ()
 void _merge_settings ()
 void _message ([string $level = 'message'], mixed $msg)
 int _next_multiple (int $base, int $factor)
 void _plugin_include (string $name)
 void _plugin_redirect (string $name)
 void _set_position_details ([int $pid = false], [int $pnid = false])
 bool _set_user ([string $login = false])
 bool _store_uploaded_file (int $did, array $file)
Variables
int $DATE (line 95)

this day is displayed/processed right now

array $EDITORPLUGIN (line 134)

Editor plugin that is used right now. Attention: do not rely in this!

object $HELPERS (line 159)

{link helpers} object for convenience

int $ID_PORTFOLIO (line 110)

currently selected Portfolio ID

array $MAINPLUGIN (line 142)

Plugin that can handle the current portfolio type

array $PLUGINS (line 79)

array of all plugins known by the core. It is created during the login phase and cached in the session later.

int $PnID (line 118)

currently selected Position inside portfolio

array $PORTFOLIOS (line 126)

list of portfolios of current user

string $RUNNING_PLUGIN (line 87)

name of currently running plugin. Attention: do *not* rely on this!

  • access: public
object dao_user $USER (line 102)

informations about currently logged in user

array $_SETTINGS (line 152)

Active application settings of current user. Use *_setting() methods to access these informations.

Inherited Variables

Inherited from dbc

dbc::$sql_affected_rows
dbc::$sql_error
dbc::$sql_execution_time
dbc::$_db
dbc::$_result

Inherited from gui

gui::$themes
gui::$_smarty

Inherited from session

session::$err
Methods
Constructor __construct (line 172)

Constructor

  • access: public
void __construct ([string $login = FALSE], [string $pass = FALSE], [bool $logout = FALSE], [bool $skip_db_check = FALSE])
  • string $login
  • string $pass
  • bool $logout
  • bool $skip_db_check

Redefinition of:
dbi::__construct()
abort (line 903)

Abort StockManiac properly when something serious went wrong.

This might be called by Plugins if something is really weird. Accepts arguments just like printf() does.

  • access: public
void abort (mixed $msg)
  • mixed $msg
abort_access_denied (line 925)

Abort StockManiac properly with access denied message.

This should be called by external Plugins if the acl check failed. Accepts arguments just like printf() does.

  • access: public
void abort_access_denied (mixed $msg)
  • mixed $msg
add_time_to_day (line 1052)

Return a timestamp for the current day containing:

  • the current day as selected by the user
  • the time as of NOW
Optionaly this can be done to any other $day too. If $day is not given, $DATE is used.

FIXME: this may not make much sense. But what else to use?

  • many brokers mention the day, but not the time in their bills
  • a hardcoded value (such as 1am) would also be bad since it might lead to two orders having *exactly* the same timestamp - now which one is first?

int add_time_to_day ([int $day = false])
  • int $day
analyse_order (line 1124)

Analyse elements of an order and determine it's status. Return the order with status and inactive properties set.

  • access: public
object analyse_order (object $dao_order, int $date)
  • object $dao_order
  • int $date
check_acl (line 1493)

Check if current user is allowed to access $plugin.

bool check_acl (string $plugin)
  • string $plugin
check_url (line 1291)

Check whether str is a URL. If it is not assume that http:// is meant and prepend it. Empty strings are ignored.

  • access: public
string check_url (string $str)
  • string $str
check_user_is_admin (line 1522)

Check whether the current user is a admin.

  • access: public
bool check_user_is_admin ()
create_bar (line 1085)

Create a array of type BAR (that is display_name, url) from input array. If $baseurl is given it will be prepended to each result url.

Input array must be structured similar to $PORTFOLIOS.

ATTENTION: this does also check ACLs when $a['name'] exists in $PLUGINS. The intended effect is that such lists contain only plugins the user is actually allowed to use. The check is arguably odd at this location.

FIXME: cache bar in session to speed it up?

  • access: public
array create_bar (array $arr, string $type_filter, [ $baseurl = FALSE], string $url_opt)
  • array $arr
  • string $type_filter
  • string $url_opt
  • $baseurl
error (line 996)

Public wrapper around _message()

void error (mixed $msg)
  • mixed $msg
figure_max_upload_size (line 1682)

Figure out what upload size we can handle at maximum. Return number of bytes or 0 on failure of when uploading is disabled in php.ini.

This is what we tell the browser and what we use to detect too large files _before_ PHP does (to the extend we can, otherwise we might end up with broken document records)

  • access: public
  • uses: FILE_UPLOAD_INEFFICIENY
int figure_max_upload_size ()
get_setting (line 1321)

Return a single setting value or false if it was not found.

Locate it by the given option name, type, current editor and current uid. Type is optional, but defaults to plugins. The plugin name defaults to the currently running plugin (see $EDITORPLUGIN).

string get_setting (string $name, [string $type = 'plugin'], [string $plugin = false])
  • string $name
  • string $type
  • string $plugin
get_setting_select (line 1347)

Return values=>labels array for $_SETTINGS data of type 'select' or false if data type is not 'select' or $name does not exist.

Type is optional and defaults to 'plugins'. Plugin is optional and defaults to the currently running plugin.

array get_setting_select (string $name, [string $type = 'plugin'], [string $plugin = false])
  • string $name
  • string $type
  • string $plugin
message (line 970)

Public wrapper around _message()

void message (mixed $msg)
  • mixed $msg
notice (line 983)

Public wrapper around _message()

void notice (mixed $msg)
  • mixed $msg
Pager (line 1226)

Create pager html code.

  • access: public
string Pager (int $page, int $lastpage, [int $length = 5])
  • int $page
  • int $lastpage
  • int $length
percentage (line 1019)

Return the percentage of $val in relation to $base. Optionally return the difference to 100.

  • access: public
int|float percentage (int|float $base, int|float $val, [bool $diff = false])
  • int|float $base
  • int|float $val
  • bool $diff
reload_portfolios (line 603)

Rebuild the list of user portfolios.

bool reload_portfolios ()
run_plugin (line 480)

Run a single plugin. Call it according to its type.

  • access: public
void run_plugin (string $name)
  • string $name
set_date (line 705)

Set date which we gone show now (positions, news, etc...). If no timestamp is given, the current date/time is used.

void set_date ([int $timestamp = false])
  • int $timestamp
set_editor (line 851)

Set current Editor

bool set_editor ([string $editor = FALSE])
  • string $editor
set_id_portfolio (line 729)

Set current Portfolio ID.

void set_id_portfolio ([int $id_portfolio = false])
  • int $id_portfolio
set_pnid (line 741)

Set current Position ID.

void set_pnid ([int $pnid = false])
  • int $pnid
set_setting (line 1386)

Add/change a single setting.

Make sure it's stored in the database and session. Name is optional (and usually the Plugin Name). If name is not given, the curretly running $EDITORPLUGIN is assumed.

Returns 1 when a update was performed, 2 when a insert was performed and

  1. when nothing has been done.

int set_setting (string $type, string $var, string $val, [string $name = false])
  • string $type
  • string $var
  • string $val
  • string $name
set_title (line 884)

Set page title.

  • access: public
  • uses: $TITLE
void set_title ([string $title = FALSE])
  • string $title
store_document (line 1544)

Store a document that was uploaded through PHPs facilities.

$doc is a element from PHPs $_FILES global. Returns the new document ID or false on error.

  • access: public
int store_document (array $doc)
  • array $doc
_add_plugin (line 550)

Add a plugin to the list of known plugins at run time. Take care that it is in the session and that smarty knows about it.

void _add_plugin (string $name, array $arr)
  • string $name
  • array $arr
_check_login (line 302)

Verify username/password against database (when first called) or verify validity flag in session (all subsequent calls).

  • access: private
bool _check_login ([string $user = false], [string $pass = false])
  • string $user
  • string $pass
_check_login_expire (line 335)

Check expiration time of current login.

  • access: private
bool _check_login_expire ()
_check_version (line 361)

Verify database version information. Call the migration plugin if a discrepancy has been found.

bool _check_version (string $login)
  • string $login
_figure_portfolio_type_handler (line 625)

Figure plugin name which can handle a certain type of portfolio.

  • when the PID changes, the type of the portfolio might also change, so we have to find a plugin that can display this type of portfolio
  • ATTENTION: since Monitors have been dropped in 0.10.1 this code is of no use, therefore I added a shortcut that returns right away. The code is left here to keep the type plumbing intact in case I want special purpose portfolios in the future...
  • FIXME: write a callback for this

  • access: private
bool _figure_portfolio_type_handler ()
_load_account_defaults (line 447)

Load account default settings from file. Fill the 'themes' setting with all values and labels the GUI knows. That way users can choose from all available themes.

FIXME: couldn't we use the 'desc' field somehow? It would be nice.

  • see: gui @ uses PATH_CONFIG
  • access: private
void _load_account_defaults ()
_load_plugins (line 390)

Initialize the $PLUGINS and $_SETTINGS arrays during login phase. Cache both structures in the session.

void _load_plugins ()
_load_portfolios (line 564)

Create list of users' portfolios and cache that.

bool _load_portfolios ()
_merge_settings (line 1430)

Load plugin and account settings from database and merge them into $_SETTINGS.

Both, plugin and account settings are related to the current user. Datatypes are corrected on the fly if necessary.

void _merge_settings ()
_message (line 951)

Collect messages of varios levels and assign them to Smarty.

Collected messages are printed in the header.tpl template at next page reload. Accepts arguments just like printf() does.

void _message ([string $level = 'message'], mixed $msg)
  • string $level
  • mixed $msg
_next_multiple (line 1275)

Return the next multiple of factor, that is larger than base.

  • access: private
int _next_multiple (int $base, int $factor)
  • int $base
  • int $factor
_plugin_include (line 522)

Run a plugin by including the code

void _plugin_include (string $name)
  • string $name
_plugin_redirect (line 535)

Run a plugin by redirecting the browser. Stop immediatelly after the redirect - the plugin *must* take over at this point.

void _plugin_redirect (string $name)
  • string $name
_set_position_details (line 759)

Set Position Details ($PID, $PnID).

Query this information from session and/or database if nothing was given.

void _set_position_details ([int $pid = false], [int $pnid = false])
  • int $pid
  • int $pnid
_set_user (line 665)

Load user account data and ACLs from database and initialize USER array, cache the information in session.

bool _set_user ([string $login = false])
  • string $login
_store_uploaded_file (line 1618)

Store uploaded file in the database.

Take a element of PHPs $_FILES global as $file. Perform acceptance and security checks before storing anything. Returns true on success, false on failure.

bool _store_uploaded_file (int $did, array $file)
  • int $did
  • array $file

Inherited Methods

Inherited From dbi

 dbi::__construct()
 dbi::sql_assign_document()
 dbi::sql_check_version()
 dbi::sql_close_position()
 dbi::sql_delete_broken_document()
 dbi::sql_delete_document()
 dbi::sql_delete_setting()
 dbi::sql_get_user_details()
 dbi::sql_select_acls()
 dbi::sql_select_comments()
 dbi::sql_select_documents()
 dbi::sql_select_document_content()
 dbi::sql_select_first_position()
 dbi::sql_select_last_insert_id()
 dbi::sql_select_order()
 dbi::sql_select_orders()
 dbi::sql_select_portfolios()
 dbi::sql_select_positions()
 dbi::sql_select_position_details()
 dbi::sql_select_position_uid()
 dbi::sql_select_quotes()
 dbi::sql_select_settings()
 dbi::sql_select_split()
 dbi::sql_select_stocks()
 dbi::sql_select_timetags()
 dbi::sql_store_document()
 dbi::sql_store_document_content()
 dbi::sql_store_position()
 dbi::sql_store_setting()
 dbi::sql_update_password()
 dbi::sql_verify_password()

Inherited From dbc

 dbc::__construct()
 dbc::sql()
 dbc::sql_escape_string()
 dbc::sql_get_array_result()
 dbc::sql_get_indexedlist_result()
 dbc::sql_get_objectarray_result()
 dbc::sql_get_object_result()
 dbc::sql_get_result()
 dbc::sql_max_packet_size()
 dbc::sql_script()

Inherited From gui

 gui::__construct()
 gui::append()
 gui::assign()
 gui::debug()
 gui::display()
 gui::get_microtime()
 gui::get_template_vars()
 gui::get_themes()
 gui::register_object()
 gui::set_default_theme()

Inherited From session

 session::__construct()
 session::sess_destroy()
 session::sess_exists()
 session::sess_get_var()
 session::sess_store_var()
 session::sess_unset_var()

Documentation generated on Sun, 22 Aug 2010 11:20:25 +0200 by phpDocumentor 1.4.3