This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/core/list.inc.php

518 lines
15 KiB
PHP
Raw Normal View History

<?php
/**
* AgileBill - Open Billing Software
*
* This body of work is free software; you can redistribute it and/or
* modify it under the terms of the Open AgileBill License
* License as published at http://www.agileco.com/agilebill/license1-4.txt
2009-08-03 04:10:16 +00:00
*
* Originally authored by Tony Landis, AgileBill LLC
*
* Recent modifications by Deon George
*
* @author Deon George <deonATleenooksDOTnet>
* @copyright 2009 Deon George
* @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
2009-08-03 04:10:16 +00:00
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @subpackage Core
*/
/**
* The main AgileBill CORE List Class
*
* @package AgileBill
2009-08-03 04:10:16 +00:00
* @subpackage Core
*/
2009-08-03 04:10:16 +00:00
class CORE_list {
private $id = 100;
/**
* @todo deprecite this function - replace with mmenu()
*/
public function menu($input_id,$name,$table,$field,$default,$class,$all=false) {
$this->mmenu($input_id,$name,$table,$field,$default,'',$class,$all);
}
/**
* Generate a select list, using the values in a table
*
* @param string $input_id HTML id="" value.
* + If 'no', then a hot click img wont be included
* + If 'all', then a blank item will be included
* @param string $name HTML name="" value.
* @param string $table Table to query for a list of items.
* @param string $field Column to query for a list of items.
* @param string $default Default Value to pre-select (if it exists)
* + If 'all', then a blank item will be included
* @param string|array $where SQL where conditions
* @param string $class CSS class for the select list
* @param bool $all If true, then a blank item will be included.
*
* @todo Remove the many ways of selecting all
*/
public function mmenu($input_id,$name,$table,$field,$default,$where,$class,$all=false) {
global $C_translate;
2009-08-03 04:10:16 +00:00
$noicon = false;
if ($input_id == 'no') {
$input_id = '';
$noicon = true;
}
if (! $input_id)
$input_id = sprintf('%s_%s_%s',$table,$field,$this->id++);
$db = &DB();
2009-08-03 04:10:16 +00:00
$result = $db->Execute(sqlSelect($db,$table,sprintf('id,%s',$field),$where,$field));
if ($result === false) {
global $C_debug;
2009-08-03 04:10:16 +00:00
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
} else {
2009-08-03 04:10:16 +00:00
$return = sprintf('<select id="%s" name="%s" class="%s">',$input_id,$name,$class);
if ($all)
$return .= '<option value="">&nbsp;</option>';
$i = 0;
2009-08-03 04:10:16 +00:00
while (! $result->EOF) {
2010-11-29 22:41:08 +00:00
$return .= sprintf('<option value="%s"%s>%s</option>',
$result->fields['id'],($default == $result->fields['id']) ? ' selected="selected"' : '',$result->fields[$field]);
$result->MoveNext();
2009-08-03 04:10:16 +00:00
$i++;
}
2009-08-03 04:10:16 +00:00
$return .= '</select>';
2009-08-03 04:10:16 +00:00
if ($i==0)
$return = $C_translate->translate('lists_none_defined');
if ($i > 0 && ! $noicon)
2010-11-29 22:41:08 +00:00
$return .= sprintf('&nbsp;<img src="themes/%s/images/icons/zoomi_16.gif" alt="Zoom" width="16" height="16" style="border: 0px;" onclick="menu_item_view(\'%s\',\'%s\');"/>',THEME_NAME,$table,$input_id);
2009-08-03 04:10:16 +00:00
echo $return;
}
}
function decrypt($data) {
include_once(PATH_CORE.'crypt.inc.php');
2010-11-29 22:41:08 +00:00
return CORE_decrypt($data);
}
2010-11-29 22:41:08 +00:00
function menu_cc_admin($field,$account,$default,$class,$user=false) {
include_once(PATH_MODULES.'account_billing/account_billing.inc.php');
$abo = new account_billing;
echo $abo->menu_admin($field,$account,$default,$class,$user);
2009-08-03 04:10:16 +00:00
}
2010-11-29 22:41:08 +00:00
function menu_multi($default,$name,$table,$field,$id,$max,$class) {
2009-08-03 04:10:16 +00:00
include_once(PATH_CORE.'list_menu_multi.inc.php');
2010-11-29 22:41:08 +00:00
echo list_menu_multi($default,$name,$table,$field,$id,$max,$class);
}
2010-11-29 22:41:08 +00:00
function menu_files($id,$name,$default,$path,$pre,$ext,$class) {
2009-08-03 04:10:16 +00:00
include_once(PATH_CORE.'list_menu_files.inc.php');
2010-11-29 22:41:08 +00:00
echo list_menu_files($id,$name,$default,$path,$pre,$ext,$class);
}
2009-08-03 04:10:16 +00:00
/**
* Generate a list of frequently used selections in OSB
*
* @param string $type List type
* @param string $input_id HTML id="" value.
* @param string $name HTML name="" value.
* @param string $default Default Value to pre-select (if it exists)
* @param string $class CSS class for the select list
* @param bool $all If true, then a blank item will be included.
*/
public function menu_staticlist($type,$input_id,$name,$default,$class,$all=false) {
2010-11-29 22:41:08 +00:00
include_once(PATH_CORE.'list_staticlist.inc.php');
return list_menu_staticlist($type,$input_id,$name,$default,$class,$all);
}
2009-08-03 04:10:16 +00:00
2010-11-29 22:41:08 +00:00
public function format_currency($number,$currency_id=DEFAULT_CURRENCY) {
$number = $this->format_currency_decimal($number,$currency_id);
2009-08-03 04:10:16 +00:00
2010-11-29 22:41:08 +00:00
if (! $currency_id)
$currency_id = DEFAULT_CURRENCY;
2009-08-03 04:10:16 +00:00
2010-11-29 22:41:08 +00:00
return sprintf('%s%s %s',
$this->format_currency[$currency_id]['symbol'],
($number > .05 || $number == 0 || $number < -1 || DEFAULT_DECIMAL_PLACE == 2)
? number_format($number,DEFAULT_DECIMAL_PLACE)
: number_format($this->format_currency_decimal($number,$currency_id,2)),
$this->currency_iso($currency_id));
}
2009-08-03 04:10:16 +00:00
2010-11-29 22:41:08 +00:00
public function format_currency_num($number,$currency_id=DEFAULT_CURRENCY) {
$number = $this->format_currency_decimal($number,$currency_id);
2009-08-03 04:10:16 +00:00
2010-11-29 22:41:08 +00:00
if (! $currency_id)
$currency_id = DEFAULT_CURRENCY;
2009-08-03 04:10:16 +00:00
2010-11-29 22:41:08 +00:00
return sprintf('%s%s',
$this->format_currency[$currency_id]['symbol'],
($number > .05 || $number == 0 || $number < -1 || DEFAULT_DECIMAL_PLACE == 2)
? number_format($number,DEFAULT_DECIMAL_PLACE)
: number_format($this->format_currency_decimal($number,$currency_id),2));
2009-08-03 04:10:16 +00:00
}
2010-11-29 22:41:08 +00:00
public function format_currency_decimal($number,$currency_id,$decimals=DEFAULT_DECIMAL_PLACE) {
if (empty($number))
return 0;
if (empty($currency_id))
$currency_id = DEFAULT_CURRENCY;
if (! isset($this->format_currency[$currency_id]))
$this->currency($currency_id);
if (! isset($this->format_currency[DEFAULT_CURRENCY]))
$this->currency(DEFAULT_CURRENCY);
return round($number*=$this->format_currency[DEFAULT_CURRENCY]['convert'][$currency_id]['rate'],$decimals);
2009-08-03 04:10:16 +00:00
}
2010-11-29 22:41:08 +00:00
public function currency_list($ret,$currency_id=DEFAULT_CURRENCY) {
global $smarty;
2010-11-29 22:41:08 +00:00
if (! isset($this->format_currency[$currency_id]))
$this->currency(DEFAULT_CURRENCY);
$smarty->assign($ret,$this->format_currency[DEFAULT_CURRENCY]['convert']);
}
2010-11-29 22:41:08 +00:00
public function currency_iso($currency_id=DEFAULT_CURRENCY) {
if (! isset($this->format_currency[$currency_id]))
$this->currency(DEFAULT_CURRENCY);
return $this->format_currency[$currency_id]['iso'];
}
2010-11-29 22:41:08 +00:00
public function currency($currency_id) {
static $CACHE = array();
$db = &DB();
2010-11-29 22:41:08 +00:00
if (! isset($CACHE[$currency_id])) {
$rs = $db->Execute(sqlSelect('currency','*',array('where'=>array('id'=>$currency_id))));
if ($rs && $rs->RecordCount())
$this->format_currency[$currency_id] = array(
'symbol' => $rs->fields['symbol'],
'convert' => unserialize($rs->fields['convert_array']),
'iso' => $rs->fields['three_digit']);
else
return false;
}
2010-11-29 22:41:08 +00:00
return true;
}
2010-11-29 22:41:08 +00:00
public function radio($input_id,$name,$table,$field,$id,$class) {
include_once(PATH_CORE.'list_radio.inc.php');
echo list_radio($input_id,$name,$table,$field,$id,$class);
2009-08-03 04:10:16 +00:00
}
2010-11-29 22:41:08 +00:00
public function check($input_id,$name,$table,$field,$default,$class) {
include_once(PATH_CORE.'list_check.inc.php');
echo list_check($input_id,$name,$table,$field,$default,$class);
2009-08-03 04:10:16 +00:00
}
2010-11-29 22:41:08 +00:00
public function select_groups($default,$field_name,$class,$size,$own_account) {
include_once(PATH_CORE.'list_select_groups.inc.php');
return list_select_groups($default,$field_name,$class,$size,$own_account);
}
2010-11-29 22:41:08 +00:00
public function calender_view($field,$default,$css,$id) {
include_once(PATH_CORE.'list_calendar.inc.php');
2010-11-29 22:41:08 +00:00
if (isset($default) && $default != '' && $default != '0')
$default = date(UNIX_DATE_FORMAT,$default);
else
$default = '';
echo list_calender_add($field,$default,$css,$id);
2009-08-03 04:10:16 +00:00
}
public function calender_add($field,$default,$css,$id='') {
if ($default == 'now')
$default = date(UNIX_DATE_FORMAT,time());
include_once(PATH_CORE.'list_calendar.inc.php');
2009-08-03 04:10:16 +00:00
echo list_calender_add($field,$default,$css,$id);
}
2009-08-03 04:10:16 +00:00
# @todo Remove?
2010-11-29 22:41:08 +00:00
public function calender_add_static_var($field,$default,$css) {
include_once(PATH_CORE.'list_calendar.inc.php');
2010-11-29 22:41:08 +00:00
if ($default == 'now')
$default = date(UNIX_DATE_FORMAT,time());
echo list_calender_add_static($field,$default,$css);
}
2010-11-29 22:41:08 +00:00
public function calender_search($field,$default,$css) {
2009-08-03 04:10:16 +00:00
if ($default == 'now')
2010-11-29 22:41:08 +00:00
$default = date(UNIX_DATE_FORMAT,time());
foreach (array(0,1) as $id) {
printf('<select name="field_option[%s][%s]"><option value=">">></option><option value="<"><</option><option value="<="><=</option><option value=">=">>=</option><option value="!=">!=</option></select>&nbsp;&nbsp;',$field,$id);
$this->calender_view($field,$default,$css,$id);
echo '<br/>';
}
}
2009-08-03 04:10:16 +00:00
2010-11-29 22:41:08 +00:00
public function setup_default_date($default,$css) {
include_once(PATH_CORE.'list_setup_default_date.inc.php');
2009-08-03 04:10:16 +00:00
2010-11-29 22:41:08 +00:00
echo list_setup_default_date($default,$css);
}
2010-11-29 22:41:08 +00:00
public function card_type_menu($default_selected,$checkout_id,$field='checkout_plugin_data[card_type]',$class,$all=false) {
include_once(PATH_CORE.'list_card_type_menu.inc.php');
echo list_card_type_menu($default_selected,$checkout_id,$field,$class,$all);
}
2010-11-29 22:41:08 +00:00
public function time($date) {
if ($date == '')
$date = time();
return date(DEFAULT_TIME_FORMAT,$date);
2009-08-03 04:10:16 +00:00
}
2010-11-29 22:41:08 +00:00
public function date($date) {
if ($date == '')
$date = time();
return date(UNIX_DATE_FORMAT,$date);
2009-08-03 04:10:16 +00:00
}
2010-11-29 22:41:08 +00:00
public function date_time($date) {
if ($date == '')
return 'UNKNOWN';
return sprintf('%s %s',$this->date($date),$this->time($date));
}
2010-11-29 22:41:08 +00:00
public function unserial($data,$var) {
global $smarty;
2010-11-29 22:41:08 +00:00
if (is_string($data))
$array = unserialize($data);
if (is_array($array))
$smarty->assign($var,$array);
}
2010-11-29 22:41:08 +00:00
public function smarty_array($table,$field,$sql,$return) { return $this->tmSmartyArray($table,$field,$sql,$return); }
public function tmSmartyArray($table,$field,$sql,$return) {
$db = &DB();
2010-11-29 22:41:08 +00:00
$smart = array();
# @todo this sqlSelect() is using a call for DEFAULT_SITE until all calls to smarty_array() dont start $sql with 'AND'
$result = $db->Execute($s=sqlSelect($table,sprintf('id,%s',$field),array('where'=>sprintf('site_id=%s %s',DEFAULT_SITE,$sql),'orderby'=>$field)));
if (! $result) {
global $C_debug;
2009-08-03 04:10:16 +00:00
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
2010-11-29 22:41:08 +00:00
return false;
2009-08-03 04:10:16 +00:00
}
2010-11-29 22:41:08 +00:00
while (! $result->EOF) {
array_push($smart,$result->fields);
$result->MoveNext();
2009-08-03 04:10:16 +00:00
}
2010-11-29 22:41:08 +00:00
global $smarty;
2010-11-29 22:41:08 +00:00
$smarty->assign($return,$smart);
return true;
}
2010-11-29 22:41:08 +00:00
function translate($table,$field1,$field2,$id,$var) {
global $smarty;
$db = &DB();
$sql= "SELECT id, $field1 FROM ".AGILE_DB_PREFIX."$table
WHERE site_id = " . $db->qstr(DEFAULT_SITE) . " AND
language_id = " . $db->qstr(SESS_LANGUAGE). " AND " .
$field2 . " = " . $db->qstr($id);
2009-08-03 04:10:16 +00:00
$result = $db->Execute($sql);
if ($result === false)
{
global $C_debug;
2009-08-03 04:10:16 +00:00
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
return false;
} else if($result->RecordCount() > 0) {
2010-11-29 22:41:08 +00:00
$smarty->assign("$var",$result->fields);
return $result->fields;
} else {
if (SESS_LANGUAGE == DEFAULT_LANGUAGE) {
return false;
} else {
$sql= "SELECT id, $field1 FROM ".AGILE_DB_PREFIX."$table
WHERE site_id = " . $db->qstr(DEFAULT_SITE) . " AND
language_id = " . $db->qstr(DEFAULT_LANGUAGE). " AND " .
$field2 . " = " . $db->qstr($id);
2009-08-03 04:10:16 +00:00
$result = $db->Execute($sql);
if ($result === false) {
global $C_debug;
2009-08-03 04:10:16 +00:00
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
return false;
} else if($result->RecordCount() > 0) {
2010-11-29 22:41:08 +00:00
$smarty->assign("$var",$result->fields);
return $result->fields;
} else {
return false;
}
}
}
}
2009-08-03 04:10:16 +00:00
public function bool($field,$curr_value,$class='form_menu',$extra='') {
# If the field is blank, we'll just return true/false
if (! $field)
2010-11-29 22:41:08 +00:00
return $curr_value ? _('Yes') : _('No');
2009-08-03 04:10:16 +00:00
if ($curr_value == 'all') {
$true = '';
$false= '';
2009-08-03 04:10:16 +00:00
} elseif($curr_value == '1') {
$true = ' selected="selected"';
$false= '';
2009-08-03 04:10:16 +00:00
} else {
$true = '';
2009-08-03 04:10:16 +00:00
$false= ' selected="selected"';
}
2010-11-29 22:41:08 +00:00
$return = sprintf('<select id="%s" name="%s" class="%s" %s>',preg_replace('/[\[\]]/','_',$field),$field,$class,$extra);
2009-08-03 04:10:16 +00:00
if ($curr_value == 'all')
$return .= '<option value="" selected="selected">&nbsp;</option>';
2010-11-29 22:41:08 +00:00
$return .= sprintf('<option value="1"%s>%s</option>',$true,_('Yes'));
$return .= sprintf('<option value="0"%s>%s</option>',$false,_('No'));
2009-08-03 04:10:16 +00:00
$return .= '</select>';
echo $return;
}
function graphview() {
2010-11-29 22:41:08 +00:00
global $VAR,$C_method;
$auth = Array('product:top','account_admin:top','affiliate:top','invoice:compare');
for($i=0; $i<count($auth); $i++) {
if($auth[$i] == $VAR['graph']) {
2010-11-29 22:41:08 +00:00
$m = explode(':',$VAR['graph']);
$C_method->exe_noauth($m[0],$m[1]);
exit;
}
}
}
function bar_graph() {
global $VAR;
require_once(PATH_CORE . 'graph.inc.php');
$graph = new CORE_graph;
@$module = $VAR['graph_module'];
@$range = $VAR['graph_range'];
@$start = $VAR['graph_start'];
@$extra = $VAR['graph_extra'];
2010-11-29 22:41:08 +00:00
$graph->BAR_graph($module,$range,$start,$extra);
}
function pie_graph() {
global $VAR;
require_once(PATH_CORE . 'graph.inc.php');
$graph = new CORE_graph;
@$module = $VAR['graph_module'];
@$method = $VAR['graph_method'];
@$range = $VAR['graph_range'];
@$start = $VAR['graph_start'];
@$extra = $VAR['graph_extra'];
2010-11-29 22:41:08 +00:00
$graph->PIE_graph($module,$method,$range,$start,$extra);
}
2009-08-03 04:10:16 +00:00
# @todo consider changing this so that it returns the .inc file if the module is installed
# so that $a = x->is_installed('y'); require_once $a can be used
2010-11-29 22:41:08 +00:00
/**
* Check if a module is installed
*
* @param string Name of Module to check
* @return string include path to module, if installed, otherwise false
*/
public function is_installed($module) {
$file = sprintf('%s%s/%s.inc.php',PATH_MODULES,$module,$module);
# If we have already checked, then return the file.
if (isset($this->is_installed[$module]) && $this->is_installed[$module])
return $file;
if (file_exists($file) && $this->auth_method_by_name($module,'search')) {
$this->is_installed[$module] = true;
2010-11-29 22:41:08 +00:00
return $file;
}
2010-11-29 22:41:08 +00:00
$db = &DB();
2010-11-29 22:41:08 +00:00
$result = $db->Execute(sqlSelect('module','id',array('where'=>array('name'=>$module,'status'=>1))));
if ($result && $result->RecordCount() && file_exists($file)) {
$this->is_installed[$module] = true;
2010-11-29 22:41:08 +00:00
return $file;
} else {
return false;
}
}
2010-11-29 22:41:08 +00:00
# @todo this should probably be private?
public function auth_method_by_name($module,$method) {
2009-08-03 04:10:16 +00:00
global $C_auth;
2010-11-29 22:41:08 +00:00
if (! is_object($C_auth))
2009-08-03 04:10:16 +00:00
return false;
return $C_auth->auth_method_by_name($module,$method);
}
2009-08-03 04:10:16 +00:00
/**
* Generate the admin menu
*/
public function generate_admin_menu() {
global $C_auth;
2009-08-03 04:10:16 +00:00
echo $C_auth->generate_admin_menu();
2009-08-03 04:10:16 +00:00
}
2010-11-29 22:41:08 +00:00
# @todo to deprecate
private function account($field) {
if (empty($this->account) && SESS_LOGGED) {
$db = &DB();
$sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'account WHERE
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
id = ' . $db->qstr(SESS_ACCOUNT);
$result = $db->Execute($sql);
$this->account = $result->fields;
}
echo $this->account[$field];
2009-08-03 04:10:16 +00:00
}
# Get the AgileBill version info
2010-11-29 22:41:08 +00:00
# @todo to deprecate
private function version() {
die();
require_once(PATH_CORE.'version.inc.php');
}
}
2009-08-03 04:10:16 +00:00
?>