Changes to AgileBill

This commit is contained in:
Deon George
2009-08-03 14:10:16 +10:00
parent 0a22cfe22c
commit 27aee719b0
1051 changed files with 219109 additions and 117219 deletions

View File

@@ -1,283 +1,304 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
class CORE_auth
{
var $auth_modules;
var $auth_methods;
var $account=false;
var $logged=false;
function CORE_auth($force)
{
/**
* The main AgileBill CORE Auth Class
*
* @package AgileBill
* @subpackage Core
*/
class CORE_auth {
private $account = 0;
private $logged = false;
private $group = array();
public function __construct($force) {
global $VAR;
if(!isset( $this->auth_methods ) ) {
#include (PATH_CORE . 'auth_methods.inc');
#$this->auth_methods = $auth_methods;
}
if(defined("SESS_LOGGED")) {
if(SESS_LOGGED == "1") {
$this->logged = TRUE;
$this->account = SESS_ACCOUNT;
if (defined('SESS_LOGGED')) {
if (SESS_LOGGED == '1') {
$this->logged = true;
$this->account = SESS_ACCOUNT;
}
else {
$this->logged = FALSE;
$this->account = 0;
}
} else {
$this->logged = FALSE;
$this->account = 0;
if(!defined('SESS_LOGGED')) define('SESS_LOGGED', false);
if(!defined('SESS')) define('SESS', false);
} else {
if (! defined('SESS_LOGGED'))
define('SESS_LOGGED',false);
if (! defined('SESS'))
define('SESS',false);
}
if($force && defined("FORCE_SESS_ACCOUNT")) {
if ($force && defined('FORCE_SESS_ACCOUNT')) {
$this->account = FORCE_SESS_ACCOUNT;
$this->logged = TRUE;
}
$this->auth_update();
if ( isset($VAR['_logout']) ||
isset($VAR['_login']) ||
isset($VAR['lid']) ||
$force == true ||
CACHE_SESSIONS != "1") {
return;
} else {
if($this->session_auth_cache_retrieve())
{
$this->module_count = count($this->module);
return;
}
$this->logged = true;
}
$this->auth_update();
if (isset($VAR['_logout']) || isset($VAR['_login']) || isset($VAR['lid']) || $force == true || CACHE_SESSIONS != '1') {
return;
} else {
if ($this->session_auth_cache_retrieve()) {
$this->module_count = count($this->module);
return;
}
}
}
function auth_update() {
$this->group = array('0');
public function auth_update() {
$this->group = array('0');
$this->module = array('0');
if($this->account) {
if ($this->account) {
$this->group_list($this->account);
if (!$this->group) {
if (! $this->group)
return;
}
$db = &DB();
$p = AGILE_DB_PREFIX;
$sql="SELECT DISTINCT MM.module_id, GM.method_id, GM.group_id,
M.name AS module_name, M.parent_id AS module_parent_id, M.menu_display AS module_display,
MM.name AS method_name, MM.page AS method_page, MM.menu_display AS method_display
FROM {$p}group_method as GM
LEFT JOIN {$p}module as M on (GM.module_id=M.id and M.site_id=".DEFAULT_SITE.")
LEFT JOIN {$p}module_method as MM on (GM.method_id=MM.id and MM.site_id=".DEFAULT_SITE.") ";
for($i=0; $i<count($this->group); $i++)
if($i==0) $sql .= "WHERE (GM.group_id={$this->group[$i]} ";
else $sql .= "OR GM.group_id={$this->group[$i]} ";
$sql .= ") AND GM.site_id=".DEFAULT_SITE." ORDER BY M.name,MM.name";
$result=$db->Execute($sql);
if($result === false)
{
$db = &DB();
$p = AGILE_DB_PREFIX;
$sql = "
SELECT DISTINCT MM.module_id, GM.method_id, GM.group_id, M.name AS module_name, M.parent_id AS module_parent_id, M.menu_display AS module_display, MM.name AS method_name, MM.page AS method_page, MM.menu_display AS method_display
FROM {$p}group_method as GM
LEFT JOIN {$p}module as M on (GM.module_id=M.id and M.site_id=".DEFAULT_SITE.")
LEFT JOIN {$p}module_method as MM on (GM.method_id=MM.id and MM.site_id=".DEFAULT_SITE.") ";
for ($i=0; $i<count($this->group); $i++)
if ($i==0)
$sql .= sprintf('WHERE (GM.group_id=%s ',$this->group[$i]);
else
$sql .= sprintf('OR GM.group_id=%s ',$this->group[$i]);
$sql .= sprintf(') AND GM.site_id=%s ORDER BY M.name,MM.name',DEFAULT_SITE);
$result=$db->Execute($sql);
if ($result === false) {
global $C_debug;
$C_debug->error('core:auth.inc.php','auth_update', $db->ErrorMsg() . '<br><br>' .$q);
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg().'<br/>'.$q);
return;
}
while (!$result->EOF) {
$module_name = $result->fields["module_name"];
$method_name = $result->fields["method_name"];
$module_name = $result->fields['module_name'];
$method_name = $result->fields['method_name'];
if(empty($this->module[$module_name])) {
$this->module[$module_name] = array($result->fields["module_id"],
$result->fields["module_parent_id"],
$result->fields["module_display"]);
}
if (empty($this->module[$module_name]))
$this->module[$module_name] = array($result->fields['module_id'],$result->fields['module_parent_id'],$result->fields['module_display']);
if (empty($this->module[$module_name][$method_name]))
$this->module[$module_name][$method_name] = array($result->fields['method_id'],$result->fields['method_display'],$result->fields['method_page']);
if(empty($this->module[$module_name][$method_name])) {
$this->module[$module_name][$method_name] = array($result->fields["method_id"],
$result->fields["method_display"],
$result->fields["method_page"]);
}
$result->MoveNext();
}
}
$this->session_auth_cache_update();
}
function session_auth_cache_update() {
private function session_auth_cache_update() {
$db = &DB();
$expire = time() + 7200; // 1 hour
if(isset($this->group) && gettype($this->group) == 'array')
$group = serialize($this->group);
$expire = time()+7200; // 1 hour
if (isset($this->group) && is_array($this->group))
$group = serialize($this->group);
else
$group = 0;
$group = 0;
if(isset($this->module) && gettype($this->module) == 'array')
$module = serialize($this->module);
if (isset($this->module) && is_array($this->module))
$module = serialize($this->module);
else
$module = 0;
$module = 0;
$q = 'DELETE FROM '.AGILE_DB_PREFIX.'session_auth_cache WHERE
session_id = '. $db->qstr(SESS) .' AND
site_id = '. $db->qstr(DEFAULT_SITE);
$db->Execute($q);
$id = $db->GenID(AGILE_DB_PREFIX . "" . 'session_auth_cache_id');
$q = 'INSERT INTO '.AGILE_DB_PREFIX.'session_auth_cache SET
id = '. $db->qstr($id) .',
site_id = '. $db->qstr(DEFAULT_SITE) .',
session_id = '. $db->qstr(SESS) .',
date_expire = '. $db->qstr($expire) .',
group_arr = '. $db->qstr($group) .',
module_arr = '. $db->qstr($module);
$db->Execute($q);
$db->Execute(sqlDelete($db,'session_auth_cache',array('session_id'=>SESS)));
$db->Execute(sqlInsert($db,'session_auth_cache',array('session_id'=>SESS,'date_expire'=>$expire,'group_arr'=>$group,'module_arr'=>$module)));
}
function session_auth_cache_retrieve() {
private function session_auth_cache_retrieve() {
global $C_sess;
if(!empty($C_sess->auth_cache)) {
if ( $C_sess->auth_cache["date_expire"] > time() ) {
$group = $C_sess->auth_cache['group_arr'];
$module = $C_sess->auth_cache['module_arr'];
if($group != '0' && $group != '') $this->group = unserialize($group);
if($module != '0' && $module != '') $this->module = unserialize($module);
if (! empty($C_sess->auth_cache)) {
if ($C_sess->auth_cache['date_expire'] > time()) {
$group = $C_sess->auth_cache['group_arr'];
$module = $C_sess->auth_cache['module_arr'];
if ($group != '0' && $group != '')
$this->group = unserialize($group);
if ($module != '0' && $module != '')
$this->module = unserialize($module);
return true;
}
}
}
$db = &DB();
$q = 'SELECT * FROM '.AGILE_DB_PREFIX.'session_auth_cache WHERE
site_id = '. $db->qstr(DEFAULT_SITE) .' AND
session_id = '. $db->qstr(SESS) .' AND
date_expire >= '. $db->qstr(time());
$result = $db->Execute($q);
if($result->RecordCount() > 0) {
$group = $result->fields['group_arr'];
$module = $result->fields['module_arr'];
if($group != '0' && $group != '') $this->group = unserialize($group);
if($module != '0' && $module != '') $this->module = unserialize($module);
$result = $db->Execute(sqlSelect($db,'session_auth_cache','*',sprintf('session_id=::%s:: AND date_expire >= %s',SESS,time())));
if ($result->RecordCount() > 0) {
$group = $result->fields['group_arr'];
$module = $result->fields['module_arr'];
if ($group != '0' && $group != '')
$this->group = unserialize($group);
if ($module != '0' && $module != '')
$this->module = unserialize($module);
return true;
}
return false;
}
function group_list($account) {
$this->group[0] = "0";
private function group_list($account) {
$this->group[0] = '0';
$time = time();
$db = &DB();
$p = AGILE_DB_PREFIX;
$q="SELECT DISTINCT ag.group_id AS group_id,g.parent_id AS parent_id
FROM {$p}account_group as ag
INNER JOIN {$p}group as g ON (ag.group_id=g.id AND g.status=1 AND g.site_id=".DEFAULT_SITE.")
WHERE ag.account_id = '$account'
AND ( ag.date_start IS NULL OR ag.date_start < $time )
AND ( ag.date_expire IS NULL OR ag.date_expire = 0 OR ag.date_expire > $time )
AND ( g.date_start IS NULL OR g.date_start <= $time )
AND ( g.date_expire IS NULL OR g.date_expire = 0 OR g.date_expire > $time )
AND ag.active=1 AND g.status=1
AND ag.site_id=".DEFAULT_SITE;
$result = $db->Execute($q);
$q = "
SELECT DISTINCT ag.group_id AS group_id,g.parent_id AS parent_id
FROM {$p}account_group as ag
INNER JOIN {$p}group as g ON (ag.group_id=g.id AND g.status=1 AND g.site_id=".DEFAULT_SITE.")
WHERE ag.account_id = '$account'
AND (ag.date_start IS NULL OR ag.date_start < $time)
AND (ag.date_expire IS NULL OR ag.date_expire = 0 OR ag.date_expire > $time)
AND (g.date_start IS NULL OR g.date_start <= $time)
AND (g.date_expire IS NULL OR g.date_expire = 0 OR g.date_expire > $time)
AND ag.active=1 AND g.status=1
AND ag.site_id=".DEFAULT_SITE;
$result = $db->Execute($q);
if ($result === false) {
global $C_debug;
echo $db->ErrorMsg();
$C_debug->error('auth.inc.php','group_list', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
exit;
} elseif($result->RecordCount() == 0) {
} elseif ($result->RecordCount() == 0) {
return;
} else {
} else {
$arr = array();
while (!$result->EOF) {
$arr[] = $result->fields;
array_push($arr,$result->fields);
$result->MoveNext();
}
}
for($i=0; $i<count($arr); $i++) {
for ($i=0; $i<count($arr); $i++) {
$do = true;
for($ii=0; $ii<count($this->group); $ii++)
if($this->group[$ii] == $arr[$i]["group_id"]) $do = false;
if($do) {
$this->group[] = $arr[$i]["group_id"];
for ($ii=0; $ii<count($this->group); $ii++)
if ($this->group[$ii] == $arr[$i]['group_id'])
$do = false;
if(!empty($arr[$i]["parent_id"]) && $arr[$i]["parent_id"] != $arr[$i]["group_id"]) {
if ($do) {
array_push($this->group,$arr[$i]['group_id']);
if (! empty($arr[$i]['parent_id']) && $arr[$i]['parent_id'] != $arr[$i]['group_id']) {
$do = true;
for($ii=0; $ii<count($this->group); $ii++)
if($this->group[$ii] == $arr[$i]["parent_id"]) $do = false;
if($do) $this->group[] = $arr[$i]["parent_id"];
}
for ($ii=0; $ii<count($this->group); $ii++)
if ($this->group[$ii] == $arr[$i]['parent_id'])
$do = false;
if ($do)
array_push($this->group,$arr[$i]['parent_id']);
}
}
}
if($account != SESS_ACCOUNT) return $this->group;
}
function auth_method_by_name($module,$method) {
if ($account != SESS_ACCOUNT)
return $this->group;
}
if(isset($this->module[$module][$method])) return TRUE;
public function auth_method_by_name($module,$method) {
if (isset($this->module[$module][$method]))
return true;
if($module == 'core')
if($method == 'cleanup')
if ($module == 'core')
if ($method == 'cleanup')
return true;
else
return false;
if( is_file(PATH_MODULES.$module.'/auth.inc.php')) {
include (PATH_MODULES.$module.'/auth.inc.php');
$this->auth_methods = $auth_methods;
for($i=0; $i<count($this->auth_methods); $i++)
if ($module == @$this->auth_methods[$i]['module'])
if($method == false || $method == @$this->auth_methods[$i]['method'])
return true;
}
return FALSE;
}
if (is_file(PATH_MODULES.$module.'/auth.inc.php')) {
include(PATH_MODULES.$module.'/auth.inc.php');
$this->auth_methods = $auth_methods;
for ($i=0; $i<count($this->auth_methods); $i++)
if ($module == @$this->auth_methods[$i]['module'])
if ($method == false || $method == @$this->auth_methods[$i]['method'])
return true;
}
function auth_group_by_id($id) {
if(!is_array($id))
$ids[] = $id;
else
$ids = $id;
foreach ( $ids as $group_id )
if(isset($this->group))
foreach ($this->group as $this_group_id)
if($this_group_id == $group_id)
return true;
return false;
}
function auth_group_by_account_id($account, $id) {
if(SESS_LOGGED == true && $account == SESS_ACCOUNT)
return $this->auth_group_by_id($id);
unset($this->group);
$this->group_list($account);
for($i=0; $i < count($this->group); $i++)
if($this->group[$i] == $id) return true;
return FALSE;
public function auth_group_by_id($id) {
$ids = array();
if (! is_array($id))
array_push($ids,$id);
else
$ids = $id;
foreach ($ids as $group_id)
if (isset($this->group))
foreach ($this->group as $this_group_id)
if ($this_group_id == $group_id)
return true;
return false;
}
function generate_admin_menu() {
public function auth_group_by_account_id($account, $id) {
if (SESS_LOGGED == true && $account == SESS_ACCOUNT)
return $this->auth_group_by_id($id);
unset($this->group);
$this->group_list($account);
for ($i=0; $i<count($this->group); $i++)
if ($this->group[$i] == $id)
return true;
return false;
}
/**
* Generate the admin menu
*/
public function generate_admin_menu() {
include_once(PATH_CORE.'auth_generate_admin_menu.inc.php');
return auth_generate_admin_menu($this);
}
}
?>
?>

View File

@@ -1,149 +1,150 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Menu
*/
// generate the admin menu
function auth_generate_admin_menu($menu_obj)
{
$menu_obj->auth_update();
global $C_translate, $smarty, $C_list;
$i=1;
$js='';
$arr = $menu_obj->module;
/**
* The main AgileBill Admin Menu Method
*
* @package AgileBill
* @subpackage Menu
*/
function auth_generate_admin_menu($menu_obj) {
global $C_translate,$smarty,$C_list;
$menu_obj->auth_update();
$i = 1;
$js = '';
$arr = $menu_obj->module;
$arr2 = $menu_obj->module;
// loop through the modules
while (list($module, $val) = each ($arr)) {
if(!empty($val[2])) {
if($val[1] == $val[0] || empty($val[0]) || empty($val[1]))
{
$module_name = $C_translate->translate('menu',$module,'');
# Loop through the modules
while (list($module,$val) = each($arr)) {
if (! empty($val[2])) {
if ($val[1] == $val[0] || empty($val[0]) || empty($val[1])) {
$module_name = $C_translate->translate('menu',$module,'','menutitle');
$parent = $val[0];
$module_id = $val[0];
$module_arr[$i]["name"] = $module_name;
$module_arr[$i]["module"] = $module;
$module_arr[$i]['name'] = $module_name;
$module_arr[$i]['module'] = $module;
# Loop through the methods
while (list($method,$meth_arr) = each($arr[$module])) {
if (gettype($meth_arr) == 'array' && ! empty($meth_arr[1])) {
$method_name = $C_translate->translate($method,$module,'','methodtitle');
// loop through the methods
while (list($method, $meth_arr) = each ($arr[$module])) {
if(gettype($meth_arr) == 'array' && !empty($meth_arr[1])) {
$method_name = $C_translate->translate('menu_'.$method,$module,'');
if(empty($meth_arr[2]))
$page = $module.':'.$method;
else
$page = preg_replace('/%%/', $module, $meth_arr[2]);
$module_arr[$i]["methods"][] = Array('name' => $method_name, 'page' => $page);
$page = htmlspecialchars(str_replace('%%',$module,$meth_arr[2]));
$module_arr[$i]['methods'][] = array('name'=>$method_name,'page'=>$page);
}
}
// Loop through the sub-modules:
# Loop through the sub-modules:
reset($arr2);
$ii=0;
while (list($module, $val) = each ($arr2)) {
if(!empty($val[2])) {
if($val[1] == $parent && $module_id != $val[0])
{
$module_name = $C_translate->translate('menu',$module,'');
$module_arr[$i]["sub_name"][$ii] = $module_name;
$ii = 0;
while (list($module,$val) = each ($arr2)) {
if (! empty($val[2])) {
if ($val[1] == $parent && $module_id != $val[0]) {
$module_name = $C_translate->translate('menu',$module,'','menutitle');
$module_arr[$i]["sub_name"][$ii] = $module_name;
// loop through the methods
while (list($method, $meth_arr) = each ($arr2[$module])) {
if(gettype($meth_arr) == 'array' && !empty($meth_arr[1])) {
$method_name = $C_translate->translate('menu_'.$method,$module,'');
if(empty($meth_arr[2]))
$page = $module.':'.$method;
else
$page = preg_replace('/%%/', $module, $meth_arr[2]);
$module_arr[$i]["sub_methods"][$ii][] = Array('name' => $method_name, 'page' => $page);
}
# Loop through the methods
while (list($method,$meth_arr) = each($arr2[$module])) {
if (gettype($meth_arr) == 'array' && ! empty($meth_arr[1])) {
$method_name = $C_translate->translate($method,$module,'','methodtitle');
if(empty($meth_arr[2]))
$page = $module.':'.$method;
else
$page = htmlspecialchars(str_replace('%%',$module,$meth_arr[2]));
$module_arr[$i]['sub_methods'][$ii][] = array('name'=>$method_name,'page'=>$page);
}
$ii++;
}
$ii++;
}
}
$i++;
}
}
}
$i++;
}
}
}
// Generate the main modules:
# Generate the main modules:
$js = '';
$js .= ".|Overview|javascript:openUrl('?_page=core:admin');\n";
$js .= ".|Exit Administration|javascript:exitAdmin();\n";
$js .= ".|Misc\n";
$js .= "..|Documentation|http://agilebill.com/documentation|||mainFrame\n";
$js .= "..|Agileco News|http://forum.agileco.com/forumdisplay.php?f=26|||mainFrame\n";
$js .= "..|Version Check|?_page=module:upgrade|||mainFrame\n";
for($i=1; $i<=count($module_arr); $i++)
{
for ($i=1; $i<=count($module_arr); $i++) {
$name = $module_arr[$i]['name'];
$js .= ".|{$name}\n";
// Generate the main methods:
for($ii=0; $ii<count($module_arr[$i]['methods']); $ii++) {
# Generate the main methods:
for ($ii=0; $ii<count($module_arr[$i]['methods']); $ii++) {
$name = $module_arr[$i]['methods'][$ii]['name'];
$page = $module_arr[$i]['methods'][$ii]['page'];
$page = $module_arr[$i]['methods'][$ii]['page'];
$js .= "..|{$name}|javascript:openUrl('?_page={$page}')\n";
}
// Generate the sub modules:
for($ii=0; $ii<count(@$module_arr[$i]['sub_name']); $ii++) {
# Generate the sub modules:
for ($ii=0; $ii<count(@$module_arr[$i]['sub_name']); $ii++) {
$name = $module_arr[$i]['sub_name'][$ii];
$js .= "..|{$name}|#\n";
// Generate the sub methods:
for($iii=0; $iii<count($module_arr[$i]['sub_methods'][$ii]); $iii++)
{
# Generate the sub methods:
for ($iii=0; $iii<count($module_arr[$i]['sub_methods'][$ii]); $iii++) {
$name = $module_arr[$i]['sub_methods'][$ii][$iii]['name'];
$page = $module_arr[$i]['sub_methods'][$ii][$iii]['page'];
$js .= "...|{$name}|javascript:openUrl('?_page={$page}')\n";
}
}
}
}
# set the dates for the quicksearch
$smarty->assign('today_start', $C_list->date(mktime(0,0,0,date("m"),date("d"), date("Y"))));
$smarty->assign('week_start', $C_list->date(mktime(0,0,0,date("m"),date("d")-7, date("Y"))));
$smarty->assign('month_start', $C_list->date(mktime(0,0,0,date("m"),1, date("Y"))));
# Set the dates for the quicksearch
$smarty->assign('today_start',$C_list->date(mktime(0,0,0,date('m'),date('d'),date('Y'))));
$smarty->assign('week_start',$C_list->date(mktime(0,0,0,date('m'),date('d')-7,date('Y'))));
$smarty->assign('month_start',$C_list->date(mktime(0,0,0,date('m'),1,date('Y'))));
# Generate the menu
require_once(PATH_INCLUDES."phplayers/PHPLIB.php");
require_once(PATH_INCLUDES."phplayers/layersmenu-common.inc.php");
require_once(PATH_INCLUDES."phplayers/treemenu.inc.php");
require_once(PATH_INCLUDES.'phplayers/PHPLIB.php');
require_once(PATH_INCLUDES.'phplayers/layersmenu-common.inc.php');
require_once(PATH_INCLUDES.'phplayers/treemenu.inc.php');
// unstoppable agileco logo ;)
echo '<img src="http://www.agileco.com/images/poweredby.gif" border="0" style="position: absolute; top: 8px; left: 45px;"/>';
# Unstoppable agileco logo ;)
echo '<img src="themes/default/images/logo-small.png" alt="Logo" style="border: 0; position: absolute; top: 8px; left: 45px;"/>';
$mnu = new TreeMenu();
$mnu->setMenuStructureString($js);
$mnu->setIconsize(16, 16);
$mnu->setIconsize(16,16);
$mnu->parseStructureForMenu('treemenu1');
$mnu->setTreemenuTheme("kde_");
return $mnu->newTreeMenu('treemenu1');
return $js;
$mnu->setTreemenuTheme('kde_');
return $mnu->newTreeMenu('treemenu1');
}
?>

View File

@@ -1,77 +1,119 @@
<?php
class CORE_RSA
{
/**
* 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
*
* 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
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @subpackage Core
*/
var $primes;
var $maxprimes;
if (! defined('LICENSE_KEY'))
define('LICENSE_KEY','47012093-4943-32127707');
function SecurityRSA($show_debug=0) {
mt_srand((double)microtime()*1000000);
$this->primes = array (4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597,
4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751,
4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931,
4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051,
5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227,
5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399,
5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521,
5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683,
5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839,
5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007,
6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151,
6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301,
6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451,
6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637,
6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791,
6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949,
6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103,
7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253,
7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477,
7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589,
7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741,
7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919,
7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093,
8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263,
8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429,
8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609,
8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741,
8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893,
8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059,
9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227,
9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397,
9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533);
$this->maxprimes = count($this->primes) - 1;
/**
* The main AgileBill CORE RSA Class
*
* @package AgileBill
* @subpackage Core
* @todo This Class appears unused.
*/
class CORE_RSA {
private $primes = array();
private $maxprimes = 0;
public function __construct() {
mt_srand((double)microtime()*1000000);
$this->primes = array(
4507,4513,4517,4519,4523,4547,4549,4561,4567,4583,4591,4597,
4603,4621,4637,4639,4643,4649,4651,4657,4663,4673,4679,4691,4703,4721,4723,4729,4733,4751,
4759,4783,4787,4789,4793,4799,4801,4813,4817,4831,4861,4871,4877,4889,4903,4909,4919,4931,
4933,4937,4943,4951,4957,4967,4969,4973,4987,4993,4999,5003,5009,5011,5021,5023,5039,5051,
5059,5077,5081,5087,5099,5101,5107,5113,5119,5147,5153,5167,5171,5179,5189,5197,5209,5227,
5231,5233,5237,5261,5273,5279,5281,5297,5303,5309,5323,5333,5347,5351,5381,5387,5393,5399,
5407,5413,5417,5419,5431,5437,5441,5443,5449,5471,5477,5479,5483,5501,5503,5507,5519,5521,
5527,5531,5557,5563,5569,5573,5581,5591,5623,5639,5641,5647,5651,5653,5657,5659,5669,5683,
5689,5693,5701,5711,5717,5737,5741,5743,5749,5779,5783,5791,5801,5807,5813,5821,5827,5839,
5843,5849,5851,5857,5861,5867,5869,5879,5881,5897,5903,5923,5927,5939,5953,5981,5987,6007,
6011,6029,6037,6043,6047,6053,6067,6073,6079,6089,6091,6101,6113,6121,6131,6133,6143,6151,
6163,6173,6197,6199,6203,6211,6217,6221,6229,6247,6257,6263,6269,6271,6277,6287,6299,6301,
6311,6317,6323,6329,6337,6343,6353,6359,6361,6367,6373,6379,6389,6397,6421,6427,6449,6451,
6469,6473,6481,6491,6521,6529,6547,6551,6553,6563,6569,6571,6577,6581,6599,6607,6619,6637,
6653,6659,6661,6673,6679,6689,6691,6701,6703,6709,6719,6733,6737,6761,6763,6779,6781,6791,
6793,6803,6823,6827,6829,6833,6841,6857,6863,6869,6871,6883,6899,6907,6911,6917,6947,6949,
6959,6961,6967,6971,6977,6983,6991,6997,7001,7013,7019,7027,7039,7043,7057,7069,7079,7103,
7109,7121,7127,7129,7151,7159,7177,7187,7193,7207,7211,7213,7219,7229,7237,7243,7247,7253,
7283,7297,7307,7309,7321,7331,7333,7349,7351,7369,7393,7411,7417,7433,7451,7457,7459,7477,
7481,7487,7489,7499,7507,7517,7523,7529,7537,7541,7547,7549,7559,7561,7573,7577,7583,7589,
7591,7603,7607,7621,7639,7643,7649,7669,7673,7681,7687,7691,7699,7703,7717,7723,7727,7741,
7753,7757,7759,7789,7793,7817,7823,7829,7841,7853,7867,7873,7877,7879,7883,7901,7907,7919,
7927,7933,7937,7949,7951,7963,7993,8009,8011,8017,8039,8053,8059,8069,8081,8087,8089,8093,
8101,8111,8117,8123,8147,8161,8167,8171,8179,8191,8209,8219,8221,8231,8233,8237,8243,8263,
8269,8273,8287,8291,8293,8297,8311,8317,8329,8353,8363,8369,8377,8387,8389,8419,8423,8429,
8431,8443,8447,8461,8467,8501,8513,8521,8527,8537,8539,8543,8563,8573,8581,8597,8599,8609,
8623,8627,8629,8641,8647,8663,8669,8677,8681,8689,8693,8699,8707,8713,8719,8731,8737,8741,
8747,8753,8761,8779,8783,8803,8807,8819,8821,8831,8837,8839,8849,8861,8863,8867,8887,8893,
8923,8929,8933,8941,8951,8963,8969,8971,8999,9001,9007,9011,9013,9029,9041,9043,9049,9059,
9067,9091,9103,9109,9127,9133,9137,9151,9157,9161,9173,9181,9187,9199,9203,9209,9221,9227,
9239,9241,9257,9277,9281,9283,9293,9311,9319,9323,9337,9341,9343,9349,9371,9377,9391,9397,
9403,9413,9419,9421,9431,9433,9437,9439,9461,9463,9467,9473,9479,9491,9497,9511,9521,9533);
$this->maxprimes = count($this->primes)-1;
}
function generate_keys($show_debug=0){
while (empty($e) || empty($d)) {
$p = $this->primes[mt_rand(0, $this->maxprimes)];
while (empty($q) || ($p==$q)) {
$q = $this->primes[mt_rand(0, $this->maxprimes)];
}
$n = $p*$q;
$pi = ($p - 1) * ($q - 1);
$e = $this->tofindE($pi, $p, $q);
$d = $this->extend($e,$pi);
$keys = array ($n, $e, $d);
public function generate_keys(){
$e = false;
$d = false;
$q = false;
while (! $e || ! $d) {
$p = $this->primes[mt_rand(0,$this->maxprimes)];
while (! $q || ($p==$q))
$q = $this->primes[mt_rand(0,$this->maxprimes)];
$n = $p*$q;
$pi = ($p-1)*($q-1);
$e = $this->tofindE($pi,$p,$q);
$d = $this->extend($e,$pi);
$keys = array($n,$e,$d);
}
return $keys;
}
function mo($g, $l) {
return $g - ($l * floor ($g/$l));
}
function extend($Ee,$Epi) {
private function mo($g,$l) {
return $g-($l*floor($g/$l));
}
private function extend($Ee,$Epi) {
$u1 = 1;
$u2 = 0;
$u3 = $Epi;
$v1 = 0;
$v2 = 1;
$v3 = $Ee;
while ($v3 != 0) {
$qq = floor($u3/$v3);
$t1 = $u1 - $qq * $v1;
$t2 = $u2 - $qq * $v2;
$t3 = $u3 - $qq * $v3;
$t1 = $u1-$qq*$v1;
$t2 = $u2-$qq*$v2;
$t3 = $u3-$qq*$v3;
$u1 = $v1;
$u2 = $v2;
$u3 = $v3;
@@ -80,172 +122,212 @@ class CORE_RSA
$v3 = $t3;
$z = 1;
}
$uu = $u1;
$vv = $u2;
if ($vv < 0) {
$inverse = $vv + $Epi;
} else {
if ($vv < 0)
$inverse = $vv+$Epi;
else
$inverse = $vv;
}
return $inverse;
}
function GCD($e,$pi) {
private function GCD($e,$pi) {
$y = $e;
$x = $pi;
while ($y != 0) {
$w = $this->mo($x , $y);
$w = $this->mo($x,$y);
$x = $y;
$y = $w;
}
return $x;
}
function tofindE($pi) {
private function tofindE($pi) {
$great = 0;
$cc = mt_rand (0,$this->maxprimes);
$cc = mt_rand(0,$this->maxprimes);
$startcc = $cc;
while ($cc >= 0) {
$se = $this->primes[$cc];
$great = $this->GCD($se,$pi);
$cc--;
if ($great == 1) break;
if ($great == 1)
break;
}
if ($great == 0) {
$cc = $startcc + 1;
while ($cc <= $this->maxprimes) {
$se = $this->primes[$cc];
$great = $this->GCD($se,$pi);
$cc++;
if ($great == 1) break;
if ($great == 1)
break;
}
}
return $se;
}
function rsa_encrypt($m, $e, $n) {
$asci = array ();
public function rsa_encrypt($m,$e,$n) {
$asci = array();
$coded = '';
for ($i=0; $i<strlen($m); $i+=3) {
$tmpasci="1";
$tmpasci = '1';
for ($h=0; $h<3; $h++) {
if ($i+$h <strlen($m)) {
$tmpstr = ord (substr ($m, $i+$h, 1)) - 30;
if (strlen($tmpstr) < 2) {
$tmpstr ="0".$tmpstr;
}
$tmpstr = ord(substr($m,$i+$h,1))-30;
if (strlen($tmpstr) < 2)
$tmpstr = '0'.$tmpstr;
} else {
break;
}
$tmpasci .=$tmpstr;
$tmpasci .= $tmpstr;
}
array_push($asci, $tmpasci."1");
array_push($asci,$tmpasci.'1');
}
for ($k=0; $k< count ($asci); $k++) {
$resultmod = $this->powmod($asci[$k], $e, $n);
@$coded .= $resultmod." ";
for ($k=0; $k< count($asci); $k++) {
$resultmod = $this->powmod($asci[$k],$e,$n);
$coded .= $resultmod.' ';
}
return trim(@$coded);
return trim($coded);
}
function powmod($base, $exp, $modulus) {
private function powmod($base,$exp,$modulus) {
$accum = 1;
$i = 0;
$basepow2 = $base;
while (($exp >> $i)>0) {
if ((($exp >> $i) & 1) == 1) {
$accum = $this->mo(($accum * $basepow2) , $modulus);
}
$basepow2 = $this->mo(($basepow2 * $basepow2) , $modulus);
if ((($exp >> $i) & 1) == 1)
$accum = $this->mo(($accum*$basepow2),$modulus);
$basepow2 = $this->mo(($basepow2*$basepow2),$modulus);
$i++;
}
return $accum;
}
function rsa_decrypt($c, $d, $n) {
$decryptarray = explode(" ", $c);
for ($u=0; $u<count ($decryptarray); $u++) {
if ($decryptarray[$u] == "") {
array_splice($decryptarray, $u, 1);
}
}
public function rsa_decrypt($c,$d,$n) {
$decryptarray = explode(' ',$c);
$resultd = '';
$deencrypt = '';
for ($u=0; $u<count ($decryptarray); $u++)
if ($decryptarray[$u] == '')
array_splice($decryptarray,$u,1);
for ($u=0; $u< count($decryptarray); $u++) {
$resultmod = $this->powmod($decryptarray[$u], $d, $n);
@$deencrypt.= substr ($resultmod,1,strlen($resultmod)-2);
}
for ($u=0; $u<strlen($deencrypt); $u+=2) {
@$resultd .= chr(substr ($deencrypt, $u, 2) + 30);
$resultmod = $this->powmod($decryptarray[$u],$d,$n);
$deencrypt .= substr($resultmod,1,strlen($resultmod)-2);
}
return @$resultd;
for ($u=0; $u<strlen($deencrypt); $u+=2)
$resultd .= chr(substr($deencrypt,$u,2)+30);
return $resultd;
}
}
}
/**
* Encrypt some data
*/
function CORE_encrypt($data) {
$rsa = new CORE_RSA;
$keys = explode('-',LICENSE_KEY);
$rc4_key = do_rc4(LICENSE_KEY,'en',false);
$rsa_data = $rsa->rsa_encrypt($data,$keys[1],$keys[0]);
$rc4_data = do_rc4($rsa_data,'en',$rc4_key);
function CORE_encrypt($data) {
if(LICENSE_KEY == '') return $data; // provide a license key in the setup area to enable encryption
$rsa = new CORE_RSA;
$keys = explode('-', LICENSE_KEY);
$rsa_data = $rsa->rsa_encrypt($data, $keys[1], $keys[0]);
$rc4_key = do_rc4(LICENSE_KEY, 'en', false);
$rc4_data = do_rc4($rsa_data, 'en', $rc4_key);
return $rc4_data;
}
/**
* Decrypt the data
*/
function CORE_decrypt($data) {
$rsa = new CORE_RSA;
$keys = explode('-',LICENSE_KEY);
$rc4_key = do_rc4(LICENSE_KEY,'en',false);
$rc4_data = do_rc4($data,'de',$rc4_key);
$rsa_data = $rsa->rsa_decrypt($rc4_data,$keys[2],$keys[0]);
function CORE_decrypt($data) {
if(LICENSE_KEY == '') return $data; // provide a license key in the setup area to enable encryption
$rc4_key = do_rc4(LICENSE_KEY, 'en', false);
$rc4_data = do_rc4($data, 'de', $rc4_key);
$rsa = new CORE_RSA;
$keys = explode('-', LICENSE_KEY);
$rsa_data = $rsa->rsa_decrypt($rc4_data, $keys[2], $keys[0]);
return $rsa_data;
}
/**
* Do the encryption/decryption
*/
function do_rc4($data,$case,$pwd) {
if (! $pwd)
$pwd = '21e0*kO-(uV9B0@jFk-er';
function do_rc4($data, $case, $pwd) {
if(!$pwd) $pwd = '21e0*kO-(uV9B0@jFk-er';
if ($case == 'de') {
if ($case == 'de')
$data = urldecode($data);
}
$key[] = "";
$box[] = "";
$temp_swap = "";
$pwd_length = 0;
$pwd_length = strlen($pwd);
$key = array();
$box = array();
$temp_swap = '';
$pwd_length = strlen($pwd);
for ($i = 0; $i <= 255; $i++) {
$key[$i] = ord(substr($pwd, ($i % $pwd_length), 1));
$key[$i] = ord(substr($pwd,($i%$pwd_length),1));
$box[$i] = $i;
}
$x = 0;
for ($i = 0; $i <= 255; $i++) {
$x = ($x + $box[$i] + $key[$i]) % 256;
$x = 0;
for ($i=0; $i<=255; $i++) {
$x = ($x+$box[$i]+$key[$i])%256;
$temp_swap = $box[$i];
$box[$i] = $box[$x];
$box[$x] = $temp_swap;
}
$temp = "";
$k = "";
$cipherby = "";
$cipher = "";
$temp = '';
$k = '';
$cipherby = '';
$cipher = '';
$a = 0;
$j = 0;
for ($i = 0; $i < strlen($data); $i++) {
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
for ($i=0; $i<strlen($data); $i++) {
$a = ($a+1)%256;
$j = ($j+$box[$a])%256;
$temp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $temp;
$k = $box[(($box[$a] + $box[$j]) % 256)];
$cipherby = ord(substr($data, $i, 1)) ^ $k;
$k = $box[(($box[$a]+$box[$j])%256)];
$cipherby = ord(substr($data,$i,1))^$k;
$cipher .= chr($cipherby);
}
if ($case == 'de') {
if ($case == 'de')
$cipher = urldecode(urlencode($cipher));
} else {
else
$cipher = urlencode($cipher);
}
return $cipher;
}
?>
}
?>

View File

@@ -1,262 +1,363 @@
<?php
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
class CORE_database
{
function add($VAR, &$construct, $type)
{
include_once(PATH_CORE . 'database_add.inc.php');
return CORE_database_add($VAR, $construct, $type);
/**
* The main AgileBill CORE Database Class
*
* @package AgileBill
* @subpackage Core
*/
class CORE_database {
public function add($VAR,$construct,$type) {
include_once(PATH_CORE.'database_add.inc.php');
return CORE_database_add($VAR,$construct,$type);
}
function update($VAR, &$construct, $type)
{
include_once(PATH_CORE . 'database_update.inc.php');
return CORE_database_update($VAR, $construct, $type);
public function update($VAR,$construct,$type) {
include_once(PATH_CORE.'database_update.inc.php');
return CORE_database_update($VAR,$construct,$type);
}
function search_form($VAR, &$construct, $type)
{
include_once(PATH_CORE . 'database_search_form.inc.php');
return CORE_database_search_form($VAR, $construct, $type);
public function search_form($VAR,$construct,$type) {
include_once(PATH_CORE.'database_search_form.inc.php');
return CORE_database_search_form($VAR,$construct,$type);
}
function search($VAR, &$construct, $type)
{
include_once(PATH_CORE . 'database_search.inc.php');
return CORE_database_search($VAR, $construct, $type);
public function search($VAR,$construct,$type) {
include_once(PATH_CORE.'database_search.inc.php');
return CORE_database_search($VAR,$construct,$type);
}
function search_show($VAR, &$construct, $type)
{
include_once(PATH_CORE . 'database_search_show.inc.php');
return CORE_database_search_show($VAR, $construct, $type);
}
function view($VAR, &$construct, $type)
{
include_once(PATH_CORE . 'database_view.inc.php');
return CORE_database_view($VAR, $construct, $type);
}
function mass_delete($VAR, &$construct, $type)
{
include_once(PATH_CORE . 'database_mass_delete.inc.php');
return CORE_database_mass_delete($VAR, $construct, $type);
}
function delete($VAR, &$construct, $type)
{
include_once(PATH_CORE . 'database_delete.inc.php');
return CORE_database_delete($VAR, $construct, $type);
public function search_show($VAR,$construct,$type) {
include_once(PATH_CORE.'database_search_show.inc.php');
return CORE_database_search_show($VAR,$construct,$type);
}
function join_fields($result, $linked)
{
include_once(PATH_CORE . 'database_join_fields.inc.php');
return CORE_database_join_fields($result, $linked);
}
public function view($VAR,$construct,$type) {
include_once(PATH_CORE.'database_view.inc.php');
return CORE_database_view($VAR,$construct,$type);
}
public function mass_delete($VAR,$construct,$type) {
include_once(PATH_CORE.'database_mass_delete.inc.php');
return CORE_database_mass_delete($VAR,$construct,$type);
}
public function delete($VAR,$construct,$type) {
include_once(PATH_CORE.'database_delete.inc.php');
return CORE_database_delete($VAR,$construct,$type);
}
public function join_fields($result,$linked) {
include_once(PATH_CORE.'database_join_fields.inc.php');
return CORE_database_join_fields($result,$linked);
}
// replaced in v1.4.91 (use sqlSelect)
function sql_select($TableList, $FieldList, $Conditions, $Order, &$db) {
return sqlSelect( $db, $TableList, $FieldList, $Conditions, $Order);
# @todo To deprecate
public function sql_select($TableList,$FieldList,$Conditions,$Order,&$db) {
return sqlSelect($db,$TableList,$FieldList,$Conditions,$Order);
}
/**
* Remove fields from the standard construct type to ingore insert/select/validation rules set in construct
* Remove fields from the standard construct type to ignore insert/select/validation rules set in construct
*
* @param array $ignore_fields
* @param string $construct_fields
* @return array
*/
function ignore_fields($ignore_fields,$construct_fields) {
if(!is_array($construct_fields)) $fields = explode(",", $construct_fields); else $fields = $construct_fields;
foreach($fields as $id=>$fld) {
if(in_array($fld,$ignore_fields)) {
public function ignore_fields($ignore_fields,$construct_fields) {
if (! is_array($construct_fields))
$fields = explode(',',$construct_fields);
else
$fields = $construct_fields;
foreach ($fields as $id=>$fld)
if (in_array($fld,$ignore_fields))
unset($fields[$id]);
}
}
return $fields;
return $fields;
}
}
class CORE_debugger
{
var $sql_count;
function sql_count() {
if(!isset($this->sql_count)) $this->sql_count = 0;
$this->sql_count++;
/**
* The main AgileBill CORE Debugger Class
*
* @package AgileBill
* @subpackage Core
*/
class CORE_debugger {
public function alert($message) {
$this->alert = array($message);
}
function alert($message) {
$this->alert = Array ($message);
}
public function error($module,$method,$message) {
$this->error = sprintf('%s:%s => %s<br/>',$module,$method,$message);
if (defined('ERROR_REPORTING') && ERROR_REPORTING > 0)
$this->alert($this->error);
function error($module, $method, $message) {
$this->error = $module . ':'. $method . ' => &nbsp;&nbsp ' . $message . '<br>';
if(defined("ERROR_REPORTING") && ERROR_REPORTING > 0) $this->alert($this->error);
$db = &DB();
$this->record_id = $db->GenID(AGILE_DB_PREFIX . "" . 'log_error_id');
$q = "INSERT INTO ".AGILE_DB_PREFIX."log_error
SET
id = ". $db->qstr($this->record_id).",
date_orig = ". $db->qstr(time()).",
account_id = ". @$db->qstr(SESS_ACCOUNT).",
module = ". $db->qstr($module).",
method = ". $db->qstr($method).",
message = ". $db->qstr($message).",
site_id = ". @$db->qstr(DEFAULT_SITE);
$result = $db->Execute($q);
$result = $db->Execute(sqlInsert($db,'log_error',array('date_orig'=>time(),'account_id'=>SESS_ACCOUNT,'module'=>$module,'method'=>$method,'message'=>$message)));
}
}
}
function &DB($debug=false) {
/**
* The main AgileBill CORE Database Function
*/
function DB($debug=false) {
static $saved_db_conn;
if (isset($saved_db_conn) && defined("AGILE_DB_CACHE")) {
#echo '<b>Cached:</b><pre>'.print_r($saved_db_conn,true).'</pre><br>';
if($debug) $saved_db_conn->debug=true; else $saved_db_conn->debug=false;
if (isset($saved_db_conn) && defined('AGILE_DB_CACHE')) {
if ($debug)
$saved_db_conn->debug = true;
else
$saved_db_conn->debug = false;
return $saved_db_conn;
}
$saved_db_conn = NewADOConnection(AGILE_DB_TYPE);
if(defined("AGILE_DB_PCONNECT") && AGILE_DB_PCONNECT == true)
if (defined('AGILE_DB_PCONNECT') && AGILE_DB_PCONNECT == true)
$saved_db_conn->PConnect(AGILE_DB_HOST,AGILE_DB_USERNAME,AGILE_DB_PASSWORD,AGILE_DB_DATABASE);
else
$saved_db_conn->Connect(AGILE_DB_HOST,AGILE_DB_USERNAME,AGILE_DB_PASSWORD,AGILE_DB_DATABASE);
#echo '<b>Original:</b><pre>'.print_r($saved_db_conn,true).'</pre><br>';
if($debug) $saved_db_conn->debug=true; else $saved_db_conn->debug=false;
return $saved_db_conn;
}
if ($debug)
$saved_db_conn->debug = true;
else
$saved_db_conn->debug = false;
function sqlGenID(&$db, $table) {
return $db->GenID( AGILE_DB_PREFIX . $table . '_id' );
$saved_db_conn->SetFetchMode(ADODB_FETCH_ASSOC);
return $saved_db_conn;
}
function sqlConditions( &$db, $Conditions=false, $Tables=false )
{
$where = " WHERE ";
/**
* Get the next SQL index ID for a table
*
* @param $db
* @param $table
* @return int
*/
function sqlGenID($db,$table) {
$id = 0;
if($Conditions) {
if(preg_match('/::/', $Conditions) ) {
$s = explode('::', $Conditions);
$ii=1;
$Conditions = '';
for($i=0; $i<count($s); $i++) {
if($ii==1) {
$Conditions .= " {$s[$i]} ";
$ii++;
} else {
$Conditions .= $db->qstr($s[$i]);
$ii=1;
}
}
# Check if our ID table exists, and if not
static $CACHE = array();
$dbname = md5($db->databaseType.$db->host.$db->database.$db->user);
if (! isset($CACHE[$dbname][$table])) {
$CACHE[$dbname][$table] = true;
$rs = $db->Execute(sprintf('SELECT id FROM %s%s_id WHERE 1=0',AGILE_DB_PREFIX,$table));
if ($rs) {
$rs = $db->Execute(sprintf('SELECT MAX(id) AS max FROM %s%s',AGILE_DB_PREFIX,$table));
if ($rs)
$id = $rs->fields['max']+1;
}
$where .= $Conditions . " AND ";
}
if(!is_array($Tables)) {
$where .= " site_id = ". DEFAULT_SITE;
} else {
$tbarr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S', 'T','U','V');
for($i=0; $i<count($Tables); $i++) {
if( $i > 0 ) $where .= " AND ";
$where .= " {$tbarr[$i]}.site_id = ". DEFAULT_SITE;
}
}
if( $where ) return $where;
return $db->GenID(sprintf('%s%s_id',AGILE_DB_PREFIX,$table),$id);
}
function sqlDelete(&$db, $table, $conditions) {
$conditions = sqlConditions( $db, $conditions);
return "DELETE FROM ".AGILE_DB_PREFIX."$table $conditions";
}
/**
* Generate SQL Conditions for a Query
*/
function sqlConditions($db,$Conditions=false,$Tables=false) {
$db = &DB();
$where = 'WHERE ';
function sqlInsert(&$db, $table, $fields, $id=false) {
if(!$id) $id = sqlGenID( $db,$table);
$fields['id'] = $id;
if(empty($fields['site_id'])) $fields['site_id'] = DEFAULT_SITE;
$tab = AGILE_DB_PREFIX.''.$table;
return $db->GetInsertSQL($tab, $fields, get_magic_quotes_gpc());
}
if ($Conditions) {
if (is_array($Conditions)) {
foreach ($Conditions as $a => $b)
if (is_array($b))
$where .= sprintf("%s IN ('%s') AND ",$a,implode("','",$b));
elseif ($db->qstr($b) == 'NULL')
$where .= sprintf('%s IS NULL AND ',$a);
else
$where .= sprintf('%s=%s AND ',$a,$db->qstr($b));
function sqlUpdate(&$db, $table, $fields, $conditions, $force=false) {
$rs = $db->Execute( sqlSelect( $db, $table, '*', $conditions) );
if(empty($fields['site_id'])) $fields['site_id'] = DEFAULT_SITE;
return $db->GetUpdateSQL( $rs, $fields, false, get_magic_quotes_gpc());
}
} else {
if (preg_match('/::/',$Conditions)) {
$s = explode('::',$Conditions);
$ii = 1;
$Conditions = '';
function sqlSelect(&$db, $TableList, $FieldList, $Conditions, $Order=false, $Limit=false, $DISTINCT='', $GroupBy=false )
{
### Table(s)
if(is_array($TableList)) {
$tbarr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S', 'T','U','V');
$table = '';
$site_id_where = '';
for($i=0;$i<count($TableList); $i++) {
$as = $tbarr[$i];
if($i>0) {
$table .= ",".AGILE_DB_PREFIX.$TableList[$i] . " AS $as";
} else {
$table .= AGILE_DB_PREFIX.$TableList[$i] . " AS $as";
for ($i=0; $i<count($s); $i++) {
if ($ii==1) {
$Conditions .= $s[$i];
$ii++;
} else {
$Conditions .= $db->qstr($s[$i]);
$ii = 1;
}
}
}
$where .= sprintf('%s AND ',$Conditions);
}
}
# Add the SITE ID
if (! is_array($Tables) || count($Tables) == 1) {
$where .= sprintf('site_id=%s',DEFAULT_SITE);
} else {
$tbarr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V');
for ($i=0; $i<count($Tables); $i++) {
if ($i>0)
$where .= ' AND ';
$where .= sprintf(' %s.site_id = %s',$tbarr[$i],DEFAULT_SITE);
}
}
$where = str_replace('{p}',AGILE_DB_PREFIX,$where);
return $where;
}
/**
* Generate SQL to delete from the database
*/
function sqlDelete($db,$table,$where) {
$db = &DB();
$where = sqlConditions($db,$where);
return sprintf('DELETE FROM %s%s %s',AGILE_DB_PREFIX,$table,$where);
}
/**
* Generate SQL to insert into the database
*/
function sqlInsert($db,$table,$FieldList,$id=false) {
$db = &DB();
if (! $id)
$id = sqlGenID($db,$table);
$FieldList['id'] = $id;
if (empty($FieldList['site_id']))
$FieldList['site_id'] = DEFAULT_SITE;
$table = AGILE_DB_PREFIX.$table;
return $db->GetInsertSQL($table,$FieldList,get_magic_quotes_gpc());
}
/**
* Generate SQL to update records in the database
*/
function sqlUpdate($table,$FieldList,$options=array()) {
$sql = array();
$force = false;
$db = &DB();
# Transition until all calls to sqlUpdate() are changed
# @todo To deprecate
if (func_num_args() >= 4) {
$args = func_get_args();
$db = array_shift($args);
$table = array_shift($args);
$FieldList = array_shift($args); if (! is_array($FieldList)) $FieldList=array($FieldList);
$options['where'] = array_shift($args);
$options['force'] = count($args) ? array_shift($args) : false;
}
if (isset($options['force']))
$force = $options['force'];
if (isset($options['where']))
$sql['where'] = $options['where'];
$rs = $db->Execute(sqlSelect($table,'*',$sql));
return $db->GetUpdateSQL($rs,$FieldList,$force,get_magic_quotes_gpc());
}
/**
* Generate SQL to select records from the database
*/
function sqlSelect($TableList,$FieldList,$sql=array()) {
# Transition until all calls to sqlSelect() are changed
# @todo To deprecate
if (func_num_args() >= 4) {
$sql = array();
$args = func_get_args();
$db = array_shift($args);
$TableList = array_shift($args);
$FieldList = array_shift($args);
$sql['where'] = array_shift($args);
$sql['orderby'] = count($args) ? array_shift($args) : '';
$sql['limit'] = count($args) ? array_shift($args) : 0;
$sql['distinct'] = count($args) ? array_shift($args) : false;
$sql['groupby'] = count($args) ? array_shift($args) : '';
}
# Table(s)
if (is_array($TableList)) {
$tbarr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V');
$table = '';
$i = 0;
foreach ($TableList as $index => $value) {
if ($i++>0)
$table .= ',';
$table .= sprintf('%s%s AS %s',AGILE_DB_PREFIX,$value,$tbarr[$index]);
}
} else {
$table = AGILE_DB_PREFIX.$TableList;
}
### Field(s)
if(is_array($FieldList)) {
$fields = '';
for($i=0;$i<count($FieldList); $i++) {
if($i>0)
$fields .= ",".$FieldList[$i];
else
$fields .= $FieldList[$i];
}
} else {
# Field(s)
if (isset($sql['distinct']) && $sql['distinct'])
$fields = 'DISTINCT '.$FieldList;
else
$fields = $FieldList;
}
### Condition(s)
$where = sqlConditions( $db, $Conditions, $TableList);
# Condition(s)
$where = sqlConditions($db,$sql['where'],$TableList);
### Order By
if(!empty($Order)) {
$where .= " ORDER BY $Order ";
}
$line = '';
# Group By
if (isset($sql['groupby']) && $sql['groupby'])
$line .= sprintf(' GROUP BY %s',$sql['groupby']);
### Group By
if(!empty($GroupBy)) {
$where .= " GROUP BY $GroupBy ";
}
# Order By
if (isset($sql['orderby']) && $sql['orderby'])
$line .= sprintf(' ORDER BY %s',$sql['orderby']);
$where = str_replace('{p}', AGILE_DB_PREFIX, $where );
# Limit
if (isset($sql['limit']) && $sql['limit'])
$line .= 'LIMIT '.$sql['limit'];
if(!empty($DISTINCT)) $DISTINCT = 'DISTINCT';
$SQL = sprintf('SELECT %s FROM %s %s %s',$fields,$table,$where,$line);
return "SELECT $DISTINCT $fields FROM $table $where";
if (isset($sql['debug']))
printf('<pre>%s</pre>',$SQL);
return $SQL;
}
?>
?>

View File

@@ -1,216 +1,239 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.94
* @subpackage Core
*/
function CORE_database_add($VAR, $construct, $type)
{
/**
* The main AgileBill CORE Database ADD Method
*
* @uses CORE_validate
* @uses CORE_static_var
* @uses CORE_trigger
*/
function CORE_database_add($VAR,$construct,$type) {
global $C_translate;
# set the field list for this method:
$arr = $construct->method["$type"];
# Temp during code rework
if (! is_array($construct->val_error))
$construct->val_error = array();
# define the validation class
include_once(PATH_CORE . 'validate.inc.php');
$validate = new CORE_validate;
# Set the field list for this method
$arr = $construct->method[$type];
# Define the validation class
include_once(PATH_CORE.'validate.inc.php');
$validate = new CORE_validate($VAR,$construct->module);
$construct->validated = true;
# Quick Validation to see if we have too many variables.
foreach ($VAR as $field_name => $value)
if (preg_match("/^{$construct->module}_/",$field_name))
if (! in_array(preg_replace("/^{$construct->module}_/",'',$field_name),$arr))
array_push($construct->val_error,array(
'field'=>sprintf('%s_%s',$construct->table,$field_name),
'field_trans'=>$field_name,
'error'=>sprintf('WARNING: Variable passed to %s but it will be ignored.',__METHOD__),
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
####################################################################
# loop through the field list to validate the required fields
####################################################################
# Quick Validation to see if we are missing variables.
foreach ($construct->method[$type] as $field_name) {
$field_var = sprintf('%s_%s',$construct->module,$field_name);
while (list ($key, $value) = each ($arr))
{
# get the field value
$field_var = $construct->module . '_' . $value;
$field_name = $value;
$construct->validate = true;
if (! array_key_exists($field_var,$VAR))
array_push($construct->val_error,array(
'field'=>$field_var,
'field_trans'=>$field_name,
'error'=>sprintf('WARNING: Variable NOT passed to %s.',__METHOD__),
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
}
####################################################################
# perform any field validation...
####################################################################
# Perform each field validation
while (list($key,$field_name) = each($arr)) {
# Get the field value
$field_var = sprintf('%s_%s',$construct->module,$field_name);
# check if this value is unique
if(isset($construct->field["$value"]["unique"]) && isset($VAR["$field_var"]))
{
if(!$validate->validate_unique($construct->table, $field_name, "record_id", $VAR["$field_var"]))
{
# Check if this value is unique
if (isset($construct->field[$field_name]['unique']) && isset($VAR[$field_var])) {
if (! $validate->validate_unique($construct->table,$field_name,'record_id',$VAR[$field_var])) {
$construct->validated = false;
$construct->val_error[] = array('field' => $construct->table . '_' . $field_name,
'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""), # translate
'error' => $C_translate->translate('validate_unique',"", ""));
array_push($construct->val_error,array(
'field'=>sprintf('%s_%s',$construct->module,$field_name),
'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
'error'=>$C_translate->translate('validate_unique','',''),
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
}
}
# check if the submitted value meets the specifed requirements
if(isset($construct->field["$value"]["validate"]))
{
if(isset($VAR["$field_var"]))
{
if($VAR["$field_var"] != '')
{
if(!$validate->validate($field_name, $construct->field["$value"], $VAR["$field_var"], $construct->field["$value"]["validate"]))
{
$construct->validated = false;
$construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
'error' => $validate->error["$field_name"] );
}
}
else
{
# Check if the submitted value meets the specifed requirements
if (isset($construct->field[$field_name]['validate'])) {
if (isset($VAR[$field_var]) && ($VAR[$field_var] != '')) {
if (! $validate->validate($field_name,$construct->field[$field_name],$VAR[$field_var],$construct->field[$field_name]['validate'])) {
$construct->validated = false;
$construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
'error' => $C_translate->translate('validate_any',"", ""));
array_push($construct->val_error,array(
'field'=>sprintf('%s_%s',$construct->module,$field_name),
'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
'error'=>$validate->error[$field_name],
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
}
}
else
{
} else {
$construct->validated = false;
$construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
'error' => $C_translate->translate('validate_any',"", ""));
array_push($construct->val_error,array(
'field'=>sprintf('%s_%s',$construct->module,$field_name),
'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
'error'=>$C_translate->translate('validate_any','',''),
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
}
}
}
# Get required static_vars and validate them
require_once(PATH_CORE.'static_var.inc.php');
$static_var = new CORE_static_var;
####################################################################
# If validation was failed, skip the db insert &
# set the errors & origonal fields as Smarty objects,
# and change the page to be loaded.
####################################################################
$all_error = $static_var->validate_form($construct->module,$construct->val_error);
if(!$construct->validated)
{
global $smarty;
if ($all_error != false && gettype($all_error) == 'array')
$construct->validated = false;
else
$construct->validated = true;
# set the errors as a Smarty Object
$smarty->assign('form_validation', $construct->val_error);
/* If validation has failed, skip the db insert & set the errors & original fields as Smarty objects,
and change the page to be loaded.*/
if (! $construct->validated) {
global $smarty;
# set the page to be loaded
if(!defined("FORCE_PAGE"))
{
define('FORCE_PAGE', $VAR['_page_current']);
# Set the errors as a Smarty Object
$smarty->assign('form_validation',$construct->val_error);
# Set the page to be loaded
if (! defined('FORCE_PAGE'))
define('FORCE_PAGE',$VAR['_page_current']);
# Define any triggers
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
# define any triggers
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
}
# strip slashes
# Strip slashes
global $C_vars;
$C_vars->strip_slashes_all();
return false;
}
else
{
# begin the new database class:
} else {
# Begin the new database class
$db = &DB();
# loop through the field list to create the sql queries
$field_list = '';
$i = 0;
# Loop through the field list to create the sql queries
$field_list = array();
reset($arr);
while (list ($key, $value) = each ($arr))
{
# get the field value
$field_var = $construct->module . '_' . $value;
$field_name = $value;
if(isset($VAR["$field_var"]))
{
# check if html allowed:
if(@$construct->field["$value"]["html"] != 1 && !is_array($VAR["$field_var"]))
{
$insert_value = htmlspecialchars($VAR["$field_var"]);
} else {
$insert_value = $VAR["$field_var"];
}
while (list($key,$field_name) = each($arr)) {
# Get the field value
$field_var = sprintf('%s_%s',$construct->module,$field_name);
# perform data conversions
if(isset( $construct->field["$value"]["convert"] ))
$insert_value = $validate->convert($field_name, $insert_value, $construct->field["$value"]["convert"]);
if (isset($VAR[$field_var])) {
# Check if HTML allowed
if (@$construct->field[$field_name]['html'] != 1 && ! is_array($VAR[$field_var]))
$insert_value = htmlspecialchars($VAR[$field_var]);
else
$insert_value = $VAR[$field_var];
# create the sql statement
if(!is_null($insert_value))
$field_list .= ", " . $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
}
}
# Perform data conversions
if (isset($construct->field[$field_name]['convert']))
$insert_value = $validate->convert($field_name,$insert_value,$construct->field[$field_name]['convert']);
# add a comma before the site_id if needed
if($field_list != '')
{
$field_list .= ',';
}
# determine the record id:
$construct->record_id = $db->GenID(AGILE_DB_PREFIX . "" . $construct->table.'_id');
# define the new ID as a constant
define(strtoupper('NEW_RECORD_'.$construct->table.'_ID'), $construct->record_id);
# generate the full query
$q = "INSERT INTO ".AGILE_DB_PREFIX."$construct->table
SET
id = ". $db->qstr($construct->record_id)."
$field_list
site_id = " . $db->qstr(DEFAULT_SITE);
# execute the query
$result = $db->Execute($q);
## echo $q;
# error reporting:
if ($result === false)
{
global $C_debug;
$C_debug->error('database.inc.php','add', $db->ErrorMsg());
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
return false;
# Create the sql statement
if (! is_null($insert_value))
$field_list[$field_name] = $insert_value;
}
}
# define any triggers:
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 1, $VAR);
# Check and see if we have some default fields
foreach (array('date_orig','date_last') as $field_name) {
$field_var = sprintf('%s_%s',$construct->module,$field_name);
if (isset($construct->field[$field_name]) && ! isset($VAR[$field_var]))
if (isset($construct->field[$field_name]['convert']))
$field_list[$field_name] = $validate->convert($field_name,time(),$construct->field[$field_name]['convert']);
else
$field_list[$field_name] = time();
}
global $VAR;
$VAR["id"] = $construct->record_id;
@$redirect_page = $VAR['_page'];
if(isset($VAR["_escape"]) || isset($VAR["_escape_next"])) $_escape = '&_escape=1&_escape_next=1';
define('REDIRECT_PAGE', '?_page=' . $redirect_page . '&id=' . $construct->record_id . '' . @$_escape);
# Determine the record id
$construct->record_id = $db->GenID(AGILE_DB_PREFIX.$construct->table.'_id');
# Define the new ID as a constant
define(strtoupper(sprintf('NEW_RECORD_%s_ID',$construct->table)),$construct->record_id);
# Execute the query
$result = $db->Execute(sqlInsert($db,$construct->table,$field_list,$construct->record_id));
# Error reporting
if ($result === false) {
global $C_debug;
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
return false;
}
# Define any triggers
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],1,$VAR);
}
# Insert the static vars
$static_var->add($VAR,$construct->module,$construct->record_id);
$_escape = '';
if (isset($VAR['_escape']) || isset($VAR['_escape_next']))
$_escape = '&_escape=1&_escape_next=1';
if (! isset($VAR['_noredirect']))
define('REDIRECT_PAGE',sprintf('?_page=%s&id=%s%s',$VAR['_page'],$construct->record_id,$_escape));
return $construct->record_id;
}
}
?>
?>

View File

@@ -1,69 +1,58 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
*/
function CORE_database_delete($VAR, &$construct, $type)
{
global $C_debug, $C_translate;
# set the id
$id = $construct->table . '_id';
/**
* The main AgileBill CORE Database DELETE Method
*
* @package AgileBill
* @subpackage Core:Database
* @uses CORE_Trigger
*/
# generate the full query
$q = "DELETE FROM
".AGILE_DB_PREFIX."$construct->table
WHERE
id = '".$db->qstr($VAR["id"], get_magic_quotes_gpc())."'
AND
site_id = '" . DEFAULT_SITE . "'";
function CORE_database_delete($VAR,$construct,$type) {
global $C_debug,$C_translate;
# execute the query
$db = &DB();
$result = $db->Execute($q);
# Execute the SQL
$result = $db->Execute(sqlDelete($db,$construct->table,array('id'=>$VAR['id'])));
# Alert
$C_debug->value["id"] = $VAR[$id];
$C_debug->value["module_name"] = $C_translate->translate('menu',$construct->module,"");
$alert = $C_translate->translate('alert_delete_id',"","");
$C_debug->alert($alert);
$C_debug->value['id'] = $VAR[$construct->table.'_id'];
$C_debug->value['module_name'] = $C_translate->translate('menu',$construct->module,'');
$C_debug->alert($C_translate->translate('alert_delete_id','',''));
# error reporting
if ($result === false)
{
if ($result === false) {
global $C_debug;
$C_debug->error('database.inc.php','delete', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
}
} else {
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
}
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
}
?>
?>

View File

@@ -1,141 +1,105 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
function CORE_database_mass_delete($VAR, &$construct, $type)
{
/**
* The main AgileBill CORE Database MASS DELETE Method
*
* @uses CORE_trigger
*/
function CORE_database_mass_delete($VAR,$construct,$type) {
global $C_auth,$C_debug;
$db = &DB();
# set the id
$id = $construct->table . '_id';
# generate the list of ID's
$id_list = '';
$ii=0;
if (isset($VAR['delete_id']))
$ids = explode(',',preg_replace('/,$/','',$VAR['delete_id']));
elseif (isset($VAR['id']))
$ids = explode(',',preg_replace('/,$/','',$VAR['id']));
if(isset($VAR["delete_id"]))
{
$id = explode(',',$VAR["delete_id"]);
}
elseif (isset($VAR["id"]))
{
$id = explode(',',$VAR["id"]);
}
for($i=0; $i<count($id); $i++)
{
if($id[$i] != '')
{
if($i == 0)
{
$id_list .= " id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
$ii++;
}
else
{
$id_list .= " OR id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
$ii++;
}
}
}
if($ii>0)
{
# generate the full query
$q = "DELETE FROM
".AGILE_DB_PREFIX."$construct->table
WHERE
$id_list
AND
site_id = '" . DEFAULT_SITE . "'";
# execute the query
$result = $db->Execute($q);
# error reporting
if ($result === false)
{
global $C_debug;
$C_debug->error('database.inc.php','mass_delete', $db->ErrorMsg());
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
}
# Check and see if the user is authorised to delete this records
foreach ($ids as $i => $id) {
$groups = $db->Execute(sqlSelect($db,'account_group','group_id',array('account_id'=>$id),'group_id'));
$group = array();
while (! $groups->EOF) {
array_push($group,$groups->fields['group_id']);
$groups->MoveNext();
}
else
{
# Verify the user has access to view this account
foreach ($group as $gid) {
if (! $C_auth->auth_group_by_id($gid)) {
unset($ids[$i]);
break;
}
}
}
# Nothing to delete
if (! count($ids))
return false;
### Delete any associated records:
if(isset($construct->associated_DELETE))
{
# Execute the query
$result = $db->Execute(sqlDelete($db,$construct->table,array('id'=>$ids)));
for($ii=0; $ii<count($construct->associated_DELETE); $ii++)
{
$id_list = '';
for($i=0; $i<count($id); $i++)
{
if($id[$i] != '')
{
if($i == 0)
{
$id_list .= $construct->associated_DELETE[$ii]["field"] ." = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
}
else
{
$id_list .= " OR " . $construct->associated_DELETE[$ii]["field"] . " = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
}
}
}
# Error reporting
if ($result === false) {
$C_debug->error(__FILE__,__METHOD__, $db->ErrorMsg());
# generate the full query
$q = "DELETE FROM
".AGILE_DB_PREFIX."". $construct->associated_DELETE[$ii]["table"] . "
WHERE
$id_list
AND
site_id = '" . DEFAULT_SITE . "'";
# execute the query
$result = $db->Execute($q);
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
} else {
# Delete any associated records
if (isset($construct->associated_DELETE) && is_array($construct->associated_DELETE) && count($construct->associated_DELETE)) {
foreach ($construct->associated_DELETE as $assoc) {
$db->Execute(sqlDelete($db,$assoc['table'],array($assoc['field']=>$ids)));
# Alert delete message
if (! defined('AJAX')) {
global $C_translate;
$C_translate->value['CORE']['module_name'] = $C_translate->translate('name',$construct->module,'');
$message = $C_translate->translate('alert_delete_ids','CORE','');
$message = str_replace('%%module_name%%','', $message);
$C_debug->alert($message);
}
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],1,$VAR);
}
}
# Alert delete message
if(!defined('AJAX')) {
global $C_debug, $C_translate;
$C_translate->value["CORE"]["module_name"] = $C_translate->translate('name',$construct->module,"");
$message = $C_translate->translate('alert_delete_ids',"CORE","");
$message = ereg_replace('%%module_name%%','', $message);
$C_debug->alert($message);
}
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 1, $VAR);
}
}
}
}
?>
return $result;
}
?>

View File

@@ -1,316 +1,282 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
function CORE_database_search($VAR, &$construct, $type)
{
$db = &DB();
include_once(PATH_CORE . 'validate.inc.php');
/**
* The main AgileBill CORE Database SEARCH Method
*
* @uses CORE_validate
* @uses CORE_trigger
* @uses CORE_search
*/
function CORE_database_search($VAR,$construct,$type) {
global $C_list;
include_once(PATH_CORE.'validate.inc.php');
$validate = new CORE_validate;
# set the search criteria array
$db = &DB();
# Set the search criteria array
$arr = $VAR;
# loop through the submitted field_names to get the WHERE statement
# Loop through the submitted field_names to get the WHERE statement
$where_list = '';
$i=0;
while (list ($key, $value) = each ($arr))
{
if($i == 0)
{
if($value != '')
{
$pat = "^" . $construct->module . "_";
if(eregi($pat, $key))
{
$field = eregi_replace($pat,"",$key);
if(eregi('%',$value))
{
# do any data conversion for this field (date, encrypt, etc...)
if(isset($construct->field["$field"]["convert"]))
{
$value = $validate->convert($field, $value, $construct->field["$field"]["convert"]);
}
$pat = sprintf('/^%s_/',$construct->module);
while (list($key,$value) = each($arr)) {
if ($value != '') {
if (preg_match($pat,$key)) {
$field = preg_replace($pat,'',$key);
$where_list .= " WHERE " . $field . " LIKE " . $db->qstr($value, get_magic_quotes_gpc());
$i++;
}
if (! is_array($value) && preg_match('/%/',$value)) {
# Do any data conversion for this field (date, encrypt, etc...)
if (isset($construct->field[$field]['convert']))
$value = $validate->convert($field,$value,$construct->field[$field]['convert']);
if ($i)
$where_list .= sprintf(' AND %s LIKE %s ',$field,$db->qstr($value,get_magic_quotes_gpc()));
else
{
# check if array
if(is_array($value))
{
for($i_arr=0; $i_arr < count($value); $i_arr++)
{
if($value["$i_arr"] != '')
{
# determine any field options (=, >, <, etc...)
$f_opt = '=';
$pat_field = $construct->module.'_'.$field;
$VAR['field_option']["$pat_field"]["$i_arr"];
if(isset($VAR['field_option']["$pat_field"]["$i_arr"]))
{
$f_opt = $VAR['field_option']["$pat_field"]["$i_arr"];
# error checking, safety precaution
if($f_opt != '=' && $f_opt != '>' && $f_opt != '<' && $f_opt != '>=' && $f_opt != '<=' && $f_opt != '!=')
$f_opt = '=';
}
$where_list .= sprintf(' WHERE %s LIKE %s',$field,$db->qstr($value,get_magic_quotes_gpc()));
# do any data conversion for this field (date, encrypt, etc...)
if(isset($construct->field["$field"]["convert"]))
{
$value["$i_arr"] = $validate->convert($field, $value["$i_arr"], $construct->field["$field"]["convert"]);
}
$i++;
} else {
# Check if array
if (is_array($value)) {
for ($i_arr=0; $i_arr<count($value); $i_arr++) {
if ($value[$i_arr] != '') {
# Determine any field options (=, >, <, etc...)
$f_opt = '=';
$pat_field = sprintf('%s_%s',$construct->module,$field);
if($i_arr == 0)
{
$where_list .= " WHERE " . $field . " $f_opt " . $db->qstr($value["$i_arr"], get_magic_quotes_gpc());
$i++;
}
else
{
$where_list .= " AND " . $field . " $f_opt " . $db->qstr($value["$i_arr"], get_magic_quotes_gpc());
$i++;
}
}
if (isset($VAR['field_option'][$pat_field][$i_arr])) {
$f_opt = $VAR['field_option'][$pat_field][$i_arr];
# Error checking, safety precaution
if (! in_array($f_opt,array('=','>','<','>=','<=','!=')))
$f_opt = '=';
}
# Do any data conversion for this field (date, encrypt, etc...)
if (isset($construct->field[$field]['convert']))
$value[$i_arr] = $validate->convert($field,$value[$i_arr],$construct->field[$field]['convert']);
if (($i_arr == 0) && ($i==0))
$where_list .= sprintf(' WHERE %s %s %s',$field,$f_opt,$db->qstr($value[$i_arr],get_magic_quotes_gpc()));
else
$where_list .= sprintf(' AND %s %s %s',$field,$f_opt,$db->qstr($value[$i_arr],get_magic_quotes_gpc()));
$i++;
}
}
} else {
if ($i)
$where_list .= sprintf(' AND %s=%s ',$field,$db->qstr($value,get_magic_quotes_gpc()));
else
{
$where_list .= " WHERE " . $field . " = " . $db->qstr($value, get_magic_quotes_gpc());
$i++;
}
}
}
}
}
else
{
if($value != '')
{
$pat = "^" . $construct->module . "_";
if(eregi($pat, $key))
{
$field = eregi_replace($pat,"",$key);
if(eregi('%',$value))
{
# do any data conversion for this field (date, encrypt, etc...)
if(isset($construct->field["$field"]["convert"]))
{
$value = $validate->convert($field, $value, $construct->field["$field"]["convert"]);
}
$where_list .= sprintf(' WHERE %s=%s',$field,$db->qstr($value,get_magic_quotes_gpc()));
$where_list .= " AND " . $field . " LIKE " . $db->qstr($value, get_magic_quotes_gpc());
$i++;
}
else
{
# check if array
if(is_array($value))
{
for($i_arr=0; $i_arr < count($value); $i_arr++)
{
if($value["$i_arr"] != '')
{
# determine any field options (=, >, <, etc...)
$f_opt = '=';
$pat_field = $construct->module.'_'.$field;
if(isset($VAR['field_option']["$pat_field"]["$i_arr"]))
{
$f_opt = $VAR['field_option']["$pat_field"]["$i_arr"];
# error checking, safety precaution
if($f_opt != '=' && $f_opt != '>' && $f_opt != '<' && $f_opt != '>=' && $f_opt != '<=' && $f_opt != '!=')
$f_opt = '=';
}
# do any data conversion for this field (date, encrypt, etc...)
if(isset($construct->field["$field"]["convert"]))
{
$value["$i_arr"] = $validate->convert($field, $value["$i_arr"], $construct->field["$field"]["convert"]);
}
$where_list .= " AND " . $field . " $f_opt " . $db->qstr($value["$i_arr"], get_magic_quotes_gpc());
$i++;
}
}
}
else
{
$where_list .= " AND " . $field . " = ". $db->qstr($value, get_magic_quotes_gpc());
$i++;
}
$i++;
}
}
}
}
}
# Some table joins
$join_table = '';
if (isset($VAR['join']) && is_array($VAR['join']))
foreach ($VAR['join'] as $table => $joins)
if ($C_list->is_installed($table)) {
#### finalize the WHERE statement
if($where_list == '')
{
include_once(PATH_MODULES.sprintf('%s/%s.inc.php',$table,$table));
$join = new $table;
if (method_exists($join,'sql_join')) {
foreach ($joins as $jointable => $id)
$q_join .= $join->sql_join($jointable,$id);
$join_table .= sprintf(',%s%s',AGILE_DB_PREFIX,$jointable);
}
if ($where_list)
$where_list .= sprintf(' AND %s',$q_join);
else
$where_list .= sprintf(' WHERE %s',$q_join);
}
# Finalize the WHERE statement
if ($where_list == '')
$where_list .= ' WHERE ';
}
else
{
$where_list .= ' AND ';
}
# get limit type
if(isset($VAR['limit']))
{
# Get limit type
if (isset($VAR['limit']))
$limit = $VAR['limit'];
}
else
{
$limit = $construct->limit;
}
# get order by
if(isset($VAR['order_by']))
{
# Get order by
if (isset($VAR['order_by']))
$order_by = $VAR['order_by'];
}
else
{
$order_by = $construct->order_by;
}
### Get any addition fields to select:
if(isset($construct->custom_EXP))
{
for($ei=0; $ei<count($construct->custom_EXP); $ei++)
{
if($ei == 0)
$field_list = "," . $construct->custom_EXP[$ei]['field'];
# Get any addition fields to select:
if (isset($construct->custom_EXP))
for ($ei=1; $ei<count($construct->custom_EXP); $ei++)
$field_list = sprintf(',%s',$construct->custom_EXP[$ei]['field']);
# Get any static vars to search
$join_list = '';
$pre = AGILE_DB_PREFIX;
if (! empty($VAR['static_relation']) && count($VAR['static_relation']>0)) {
while (list($idx,$value) = each($VAR['static_relation'])) {
if ($value != '') {
$join_list .= sprintf(" INNER JOIN %sstatic_var_record AS s%s ON (s%s.record_id=%s%s.id AND s%s.static_var_relation_id='%s' AND s%s.site_id=%s AND",
$pre,$idx,$idx,$pre,$this->table,$idx,$idx,$idx,$db->qstr(DEFAULT_SITE));
if(preg_match('/%/',$value))
$join_list .= sprintf(' s%s.value LIKE %s',$idx,$db->qstr($VAR['static_relation'][$idx]));
else
$join_list .= sprintf(' s%s.value = %s',$idx,$db->qstr($VAR['static_relation'][$idx]));
$join_list .= ') ';
}
}
}
/*
# standard where list
$q .= $join_list . $where_list ." ".AGILE_DB_PREFIX."account.site_id = " . $db->qstr(DEFAULT_SITE);
# Code for member group
if(!empty($VAR['account_group'])) {
$q .= " AND ".AGILE_DB_PREFIX."account_group.group_id = " . $db->qstr($VAR['account_group'])."
AND ".AGILE_DB_PREFIX."account_group.site_id = " . $db->qstr(DEFAULT_SITE);
}
if(!empty($VAR['account_group'])) {
$q_save .= " LEFT JOIN ".AGILE_DB_PREFIX."account_group ON ".AGILE_DB_PREFIX."account_group.account_id = ".AGILE_DB_PREFIX."account.id ";
if(!empty($join_list))
$q_save .= $join_list;
$q_save .= $where_list ." %%whereList%% ";
$q_save .= AGILE_DB_PREFIX."account_group.group_id = " . $db->qstr($VAR['account_group'])." AND ";
} else {
if(!empty($join_list))
$q_save .= $join_list;
$q_save .= $where_list ." %%whereList%% ";
}
*/
# generate the full query
$q = "SELECT id".$field_list." FROM
".AGILE_DB_PREFIX."$construct->table
$where_list
site_id = '" . DEFAULT_SITE . "'";
$q = sprintf('SELECT %s%s.id AS id%s FROM %s%s %s %s %s%s.site_id=%s',
AGILE_DB_PREFIX,$construct->table,$field_list,
AGILE_DB_PREFIX,$construct->table,$join_table,
$where_list,AGILE_DB_PREFIX,$construct->table,DEFAULT_SITE);
$q_save = "SELECT %%fieldList%% FROM %%tableList%% $join_table".$where_list." %%whereList%% ";
$result = $db->Execute($q);
$q_save = "SELECT %%fieldList%% FROM %%tableList%% ".$where_list." %%whereList%% ";
$result = $db->Execute($q);
//////////////// DEBUG ////
#echo "<PRE>$q</PRE>";
#exit;
# error reporting
if ($result === false)
{
# Error reporting
if ($result === false) {
global $C_debug;
$C_debug->error('database.inc.php','search', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
return;
return;
}
# get the result count:
# Get the result count:
$results = $result->RecordCount();
# get the first record id:
if($results == 1) $record_id = $result->fields['id'];
# Get the first record id:
if ($results == 1)
$record_id = $result->fields['id'];
### Run any custom validation on this result for
### this module
if(isset($construct->custom_EXP))
{
# Run any custom validation on this result for this module
if (isset($construct->custom_EXP)) {
$results = 0;
while(!$result->EOF)
{
for($ei=0; $ei<count($construct->custom_EXP); $ei++)
{
$field = $construct->custom_EXP[$ei]["field"];
$value = $construct->custom_EXP[$ei]["value"];
if($result->fields["$field"] == $value)
{
//$result->MoveNext();
while (! $result->EOF) {
for ($ei=0; $ei<count($construct->custom_EXP); $ei++) {
$field = $construct->custom_EXP[$ei]['field'];
$value = $construct->custom_EXP[$ei]['value'];
if ($result->fields[$field] == $value) {
$ei = count($construct->custom_EXP);
$results++;
}
$results++;
}
}
$result->MoveNext();
}
}
# define the DB vars as a Smarty accessible block
# Define the DB vars as a Smarty accessible block
global $smarty;
# Create the definition for fast-forwarding to a single record:
if ($results == 1 && !isset($construct->fast_forward))
{
$smarty->assign('record_id', $record_id);
}
$smarty->assign('record_id',$record_id);
# create the search record:
if($results > 0)
{
if ($results > 0) {
# create the search record
include_once(PATH_CORE . 'search.inc.php');
include_once(PATH_CORE.'search.inc.php');
$search = new CORE_search;
$arr['module'] = $construct->module;
$arr['module'] = $construct->module;
$arr['sql'] = $q_save;
$arr['limit'] = $limit;
$arr['limit'] = $limit;
$arr['order_by']= $order_by;
$arr['results'] = $results;
$search->add($arr);
# define the search id and other parameters for Smarty
$smarty->assign('search_id', $search->id);
$smarty->assign('search_id',$search->id);
# page:
$smarty->assign('page', '1');
$smarty->assign('page','1');
# limit:
$smarty->assign('limit', $limit);
$smarty->assign('limit',$limit);
# order_by:
$smarty->assign('order_by', $order_by);
$smarty->assign('order_by',$order_by);
}
# define the result count
$smarty->assign('results', $results);
$smarty->assign('results',$results);
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 1, $VAR);
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],1,$VAR);
}
}
?>
?>

View File

@@ -31,18 +31,20 @@ function CORE_database_search_form($VAR, $construct, $type)
while (list ($key, $value) = each ($arr))
{
$field_list["$i"]['translate'] = $C_translate->translate('field_' . $value, $construct->module, "");
if (! $field_list["$i"]['translate'])
$field_list["$i"]['translate'] = sprintf('field_%s',$value);
$field_list["$i"]['field'] = $value;
$i++;
}
# define the field list as a Smarty accessible array
$smarty->assign($construct->module, $field_list);
$smarty->assign('field_list',$field_list);
# define the default ORDER BY field
$smarty->assign($construct->module . '_order_by', $construct->order_by);
$smarty->assign('field_order_by',$construct->order_by);
# define the default LIMIT count
$smarty->assign($construct->module . '_limit', $construct->limit);
$smarty->assign('field_limit',$construct->limit);
# define the recent search menu & javascript
include_once(PATH_CORE . 'search.inc.php');
@@ -66,4 +68,4 @@ function CORE_database_search_form($VAR, $construct, $type)
# send the finished SAVED SEARCH JavaScript to Smarty
$smarty->assign($construct->module . "_saved_js", $search->saved_js);
}
?>
?>

View File

@@ -1,75 +1,72 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
function CORE_database_search_show($VAR, &$construct, $type)
{
# set the field list for this method:
/**
* The main AgileBill CORE Database SEARCH_SHOW Method
*
* @uses CORE_search
* @uses CORE_trigger
*/
function CORE_database_search_show($VAR, &$construct, $type) {
# Set the field list for this method:
$arr = $construct->method[$type];
$field_list = '';
$construct->linked = array();
$i=0;
while (list ($key, $value) = each ($arr))
{
if($i == 0)
{
$field_var = $construct->table . '_' . $value;
$field_list .= AGILE_DB_PREFIX . $construct->table . "." . $value;
while (list($key,$value) = each($arr)) {
$field_var = sprintf('%s_%s',$construct->table,$value);
// determine if this record is linked to another table/field
if($construct->field[$value]["asso_table"] != "")
{
$construct->linked[] = array('field' => $value, 'link_table' => $construct->field[$value]["asso_table"], 'link_field' => $construct->field[$value]["asso_field"]);
}
}
if ($i == 0)
$field_list .= sprintf('%s%s.%s',AGILE_DB_PREFIX,$construct->table,$value);
else
{
$field_var = $construct->table . '_' . $value;
$field_list .= "," . AGILE_DB_PREFIX . $construct->table . "." . $value;
$field_list .= sprintf(',%s%s.%s',AGILE_DB_PREFIX,$construct->table,$value);
# Determine if this record is linked to another table/field
if ($construct->field[$value]['asso_table'] != '')
array_push($construct->linked,array('field'=>$value,'link_table'=>$construct->field[$value]['asso_table'],'link_field'=>$construct->field[$value]['asso_field']));
// determine if this record is linked to another table/field
if($construct->field[$value]["asso_table"] != "")
{
$construct->linked[] = array('field' => $value, 'link_table' => $construct->field[$value]["asso_table"], 'link_field' => $construct->field[$value]["asso_field"]);
}
}
$i++;
}
# get the search details:
if(isset($VAR['search_id']))
{
include_once(PATH_CORE . 'search.inc.php');
# Get the search details:
if (isset($VAR['search_id'])) {
include_once(PATH_CORE.'search.inc.php');
$search = new CORE_search;
$search->get($VAR['search_id']);
}
else
{
# invalid search!
echo '<BR> The search terms submitted were invalid!<BR>'; # translate... # alert
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
$search->get($VAR['search_id']);
} else {
# Invalid search!
echo '<br/>The search terms submitted were invalid!<br/>';
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
}
@@ -77,176 +74,179 @@ function CORE_database_search_show($VAR, &$construct, $type)
if ($search->session != SESS && $search->account != SESS_ACCOUNT) {
global $C_debug;
$C_debug->alert('You are not authorized to view this search!');
return false;
}
# get the sort order details:
if(isset($VAR['order_by']) && $VAR['order_by'] != "")
{
$order_by = ' ORDER BY ' . $VAR['order_by'];
$smarty_order = $VAR['order_by'];
}
else
{
$order_by = ' ORDER BY ' . $construct->order_by;
$smarty_order = $search->order_by;
# Get the sort order details:
if (isset($VAR['order_by']) && $VAR['order_by'] != '') {
$order_by = sprintf(' ORDER BY %s',$VAR['order_by']);
$smarty_order = $VAR['order_by'];
} else {
$order_by = sprintf(' ORDER BY %s',$construct->order_by);
$smarty_order = $search->order_by;
}
# determine the sort order
if(isset($VAR['desc'])) {
# Determine the sort order
if (isset($VAR['desc'])) {
$order_by .= ' DESC';
$smarty_sort = 'desc=';
} else if(isset($VAR['asc'])) {
} elseif (isset($VAR['asc'])) {
$order_by .= ' ASC';
$smarty_sort = 'asc=';
} else {
if (!eregi('date',$smarty_order)) {
if (! preg_match('/date/',$smarty_order)) {
$order_by .= ' ASC';
$smarty_sort = 'asc=';
} else {
} else {
$order_by .= ' DESC';
$smarty_sort = 'desc=';
}
}
}
# Generate the full query
$db = &DB();
# generate the full query
$db = &DB();
$q = eregi_replace("%%fieldList%%", $field_list, $search->sql);
$q = eregi_replace("%%tableList%%", AGILE_DB_PREFIX.$construct->table, $q);
$q = eregi_replace("%%whereList%%", "", $q);
$q .= " site_id = '" . DEFAULT_SITE . "'";
$q = str_replace('%%fieldList%%',$field_list,$search->sql);
$q = str_replace('%%tableList%%',AGILE_DB_PREFIX.$construct->table,$q);
$q = str_replace('%%whereList%%','',$q);
$q .= sprintf(' %s.site_id = %s',AGILE_DB_PREFIX.$construct->table,DEFAULT_SITE);
$q .= $order_by;
///////////////////////
# Determine the offset & limit
$current_page = 1;
$offset = -1;
# determine the offset & limit
$current_page=1;
$offset=-1;
if (!empty($VAR['page'])) $current_page = $VAR['page'];
if (empty($search->limit)) $search->limit=25;
if($current_page>1) $offset = (($current_page * $search->limit) - $search->limit);
$result = $db->SelectLimit($q, $search->limit, $offset);
if (! empty($VAR['page']))
$current_page = $VAR['page'];
if (empty($search->limit))
$search->limit=25;
# error reporting
if ($result === false)
{
if ($current_page>1)
$offset = (($current_page*$search->limit)-$search->limit);
$result = $db->SelectLimit($q,$search->limit,$offset);
# Error reporting
if ($result === false) {
global $C_debug;
$C_debug->error('database.inc.php','search', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
return;
return;
}
# Run any custom validation on this result for this module
$i = 0;
$class_name = true;
if (isset($construct->custom_EXP)) {
while (! $result->EOF) {
for ($ei=0; $ei<count($construct->custom_EXP); $ei++) {
$field = $construct->custom_EXP[$ei]['field'];
$value = $construct->custom_EXP[$ei]['value'];
### Put the results into a smarty accessable array
### Run any custom validation on this result for
### this module
if(isset($construct->custom_EXP))
{
$i=0;
$class_name = TRUE;
$results = 0;
while(!$result->EOF)
{
for($ei=0; $ei<count($construct->custom_EXP); $ei++)
{
$field = $construct->custom_EXP[$ei]["field"];
$value = $construct->custom_EXP[$ei]["value"];
if($result->fields["$field"] == $value)
{
if ($result->fields[$field] == $value) {
$smart[$i] = $result->fields;
if($class_name)
{
if ($class_name) {
$smart[$i]['_C'] = 'row1';
$class_name = FALSE;
$class_name = false;
} else {
$smart[$i]['_C'] = 'row2';
$class_name = TRUE;
}
$i++;
$class_name = true;
}
$i++;
$ei = count($construct->custom_EXP);
$results++;
}
}
}
}
$result->MoveNext();
}
}
else
{
$i=0;
$class_name = TRUE;
while (!$result->EOF) {
} else {
while (! $result->EOF) {
$smart[$i] = $result->fields;
if($class_name)
{
if ($class_name) {
$smart[$i]['_C'] = 'row1';
$class_name = FALSE;
$class_name = false;
} else {
$smart[$i]['_C'] = 'row2';
$class_name = TRUE;
$class_name = true;
}
$result->MoveNext();
$i++;
}
}
# get any linked fields
if($i > 0) {
# Get any linked fields
if ($i > 0) {
$db_join = new CORE_database;
$construct->result = $db_join->join_fields($smart, $construct->linked);
} else {
$construct->result = $smart;
}
}
# get the result count:
# Get the result count:
$results = $result->RecordCount();
# define the DB vars as a Smarty accessible block
global $smarty;
# define the results
$smarty->assign($construct->table, $construct->result);
$smarty->assign('page', $VAR['page']);
$smarty->assign('order', $smarty_order);
$smarty->assign('sort', $smarty_sort);
$smarty->assign('limit', $search->limit);
$smarty->assign('search_show',$construct->result);
$smarty->assign('page',$VAR['page']);
$smarty->assign('order',$smarty_order);
$smarty->assign('sort',$smarty_sort);
$smarty->assign('limit',$search->limit);
$smarty->assign('search_id',$search->id);
$smarty->assign('results', $search->results);
$smarty->assign('results',$search->results);
# get the total pages for this search:
if (empty($search->limit))
$construct->pages = 1;
else
$construct->pages = intval($search->results / $search->limit);
if ($search->results % $search->limit) $construct->pages++;
# total pages
$smarty->assign('pages', $construct->pages);
if ($search->results % $search->limit)
$construct->pages++;
# current page
$smarty->assign('page', $current_page);
$page_arr = '';
for($i=0; $i <= $construct->pages; $i++)
if ($construct->page != $i) $page_arr[] = $i;
# Total pages
$smarty->assign('pages',$construct->pages);
# page array for menu
$smarty->assign('page_arr', $page_arr);
# Current page
$smarty->assign('page',$current_page);
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 1, $VAR);
}
return $construct->result;
$page_arr = array();
for ($i=0; $i<=$construct->pages; $i++)
if ($construct->page != $i)
array_push($page_arr,$i);
# Page array for menu
$smarty->assign('page_arr',$page_arr);
if(isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],1,$VAR);
}
return $construct->result;
}
?>
?>

View File

@@ -1,226 +1,200 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
function CORE_database_update($VAR, &$construct, $type)
{
/**
* The main AgileBill CORE Database UPDATE Method
*
* @uses CORE_validate
* @uses CORE_trigger
*/
function CORE_database_update($VAR,$construct,$type) {
global $C_translate;
# set the field list for this method:
$arr = $construct->method["$type"];
# Temp during code rework
if (! is_array($construct->val_error))
$construct->val_error = array();
# define the validation class
include_once(PATH_CORE . 'validate.inc.php');
$validate = new CORE_validate;
# Set the field list for this method
$arr = $construct->method[$type];
$construct->validated = true;
# Define the validation class
include_once(PATH_CORE.'validate.inc.php');
$validate = new CORE_validate($VAR,$construct->module);
$construct->validated = true;
# define this record id
$id = $VAR[$construct->module . '_id'];
# Quick Validation to see if we have too many variables.
foreach ($VAR as $field_name => $value)
if (preg_match("/^{$construct->module}_/",$field_name))
if (! in_array(preg_replace("/^{$construct->module}_/",'',$field_name),$arr))
array_push($construct->val_error,array(
'field'=>sprintf('%s_%s',$construct->table,$field_name),
'field_trans'=>$field_name,
'error'=>sprintf('WARNING: Variable passed to %s but it will be ignored.',__METHOD__),
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
####################################################################
# loop through the field list to validate the required fields
####################################################################
# Define this record id
$id = $VAR[$construct->module.'_id'];
while (list ($key, $value) = each ($arr))
{
# get the field value
$field_var = $construct->module . '_' . $value;
$field_name = $value;
$construct->validate = true;
# Perform each field validation
while (list($key,$field_name) = each($arr)) {
# Get the field value
$field_var = sprintf('%s_%s',$construct->module,$field_name);
####################################################################
# perform any field validation...
####################################################################
# check if the conversion type required is not one ignored on updates:
# Check if the conversion type required is not one ignored on updates
$ignore_con = false;
$ignore_convert = Array('sha', 'md5','rc5','crypt');
for ($ic=0; $ic < count($ignore_convert); $ic++)
{
if (isset($construct->field["$value"]["convert"]))
if ($construct->field["$value"]["convert"] == $ignore_convert[$ic]) $ignore_con = true;
}
$ignore_convert = array('sha','md5','rc5','crypt');
for ($ic=0; $ic<count($ignore_convert); $ic++)
if (isset($construct->field[$field_name]['convert']))
if ($construct->field[$field_name]['convert'] == $ignore_convert[$ic])
$ignore_con = true;
if(!$ignore_con)
{
if (! $ignore_con) {
# check if this value is unique
if(isset($construct->field["$value"]["unique"]))
{
if(isset($VAR["$field_var"]))
{
if(!$validate->validate_unique($construct->table, $field_name, $id, $VAR["$field_var"]))
{
$construct->validated = false;
$construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""), # translate
'error' => $C_translate->translate('validate_unique',"", ""));
}
}
if (isset($construct->field[$field_name]['unique']) && isset($VAR[$field_var])) {
if (! $validate->validate_unique($construct->table,$field_name,$id,$VAR[$field_var])) {
$construct->validated = false;
array_push($construct->val_error,array(
'field'=>sprintf('%s_%s',$construct->module,$field_name),
'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
'error'=>$C_translate->translate('validate_unique','',''),
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
}
}
# check if the submitted value meets the specifed requirements
if(isset($construct->field["$value"]["validate"]))
{
if(isset($VAR["$field_var"]))
{
if($VAR["$field_var"] != '')
{
if(!$validate->validate($field_name, $construct->field["$value"], $VAR["$field_var"], $construct->field["$value"]["validate"]))
{
$construct->validated = false;
$construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
'error' => $validate->error["$field_name"] );
}
}
else
{
# Check if the submitted value meets the specifed requirements
if (isset($construct->field[$field_name]['validate'])) {
if (isset($VAR[$field_var]) && ($VAR[$field_var] != '')) {
if (! $validate->validate($field_name,$construct->field[$field_name],$VAR[$field_var],$construct->field[$field_name]['validate'])) {
$construct->validated = false;
$construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
'error' => $C_translate->translate('validate_any',"", ""));
array_push($construct->val_error,array(
'field'=>sprintf('%s_%s',$construct->module,$field_name),
'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
'error'=>$validate->error[$field_name],
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
}
}
else
{
} else {
$construct->validated = false;
$construct->val_error[] = array('field' => $construct->module. '_' . $field_name,
'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
'error' => $C_translate->translate('validate_any',"", ""));
array_push($construct->val_error,array(
'field'=>sprintf('%s_%s',$construct->module,$field_name),
'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
'error'=>$C_translate->translate('validate_any','',''),
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
}
}
}
}
/* If validation has failed, skip the db insert & set the errors & original fields as Smarty objects,
and change the page to be loaded.*/
if (! $construct->validated) {
global $smarty;
# Set the errors as a Smarty Object
$smarty->assign('form_validation',$construct->val_error);
# Change the page to be loaded
$VAR['_page'] = $construct->module.':view';
####################################################################
# If validation was failed, skip the db insert &
# set the errors & origonal fields as Smarty objects,
# and change the page to be loaded.
####################################################################
# Define any triggers
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
if(!$construct->validated)
{
global $smarty;
# set the errors as a Smarty Object
$smarty->assign('form_validation', $construct->val_error);
# change the page to be loaded
global $VAR;
$VAR['_page'] = $construct->module . ':view';
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
# strip slashes
# Strip slashes
global $C_vars;
$C_vars->strip_slashes_all();
return false;
}
else
{
return false;
} else {
# Begin the new database class
$db = &DB();
$field_list = '';
$i = 0;
# Loop through the field list to create the sql queries
$field_list = array();
reset($arr);
while (list ($key, $value) = each ($arr))
{
# get the field value
$field_var = $construct->module . '_' . $value;
$field_name = $value;
while (list($key,$field_name) = each($arr)) {
# Get the field value
$field_var = sprintf('%s_%s',$construct->module,$field_name);
if(isset($VAR["$field_var"]) && $VAR["$field_var"] != 'IGNORE-ARRAY-VALUE')
{
# check if html allowed:
if(@$construct->field["$value"]["html"] != 1 && !is_array($VAR["$field_var"]))
$insert_value = htmlspecialchars($VAR["$field_var"]);
if (isset($VAR[$field_var]) && $VAR[$field_var] != 'IGNORE-ARRAY-VALUE') {
# Check if HTML allowed
if (@$construct->field[$field_name]['html'] != 1 && ! is_array($VAR[$field_var]))
$insert_value = htmlspecialchars($VAR[$field_var]);
else
$insert_value = $VAR["$field_var"];
$insert_value = $VAR[$field_var];
# perform data conversions
if(isset($construct->field["$value"]["convert"] ))
$insert_value = $validate->convert($field_name, $insert_value, $construct->field["$value"]["convert"]);
# Perform data conversions
if (isset($construct->field[$field_name]['convert']) && trim($construct->field[$field_name]['convert']))
$insert_value = $validate->convert($field_name,$insert_value,$construct->field[$field_name]['convert']);
if($i == 0)
$field_list .= $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
else
$field_list .= ", " . $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
$i++;
}
elseif ( @$construct->field["$value"]["convert"] == "array" && @$VAR["$field_var"] != 'IGNORE-ARRAY-VALUE')
{
# Handle blank array string...
$insert_value = serialize(Array(""));
if($i == 0)
$field_list .= $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
else
$field_list .= ", " . $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
$i++;
}
$field_list[$field_name] = $insert_value;
} elseif (@$construct->field[$field_name]['convert'] == 'array' && @$VAR[$field_var] != 'IGNORE-ARRAY-VALUE')
# Handle blank array string
$field_list[$field_name] = serialize(array());
}
# generate the full query
$q = "UPDATE " . AGILE_DB_PREFIX . "$construct->table SET
$field_list
WHERE
id = ". $db->qstr($id) ."
AND
site_id = " . $db->qstr(DEFAULT_SITE);
# execute the query
$db = &DB();
$result = $db->Execute($q);
# Execute the query
$result = $db->Execute(sqlUpdate($db,$construct->table,$field_list,array('id'=>$id)));
# echo "<PRE>$q</PRE>";
# error reporting
if ($result === false)
{
# Error reporting
if ($result === false) {
global $C_debug;
$C_debug->error('database.inc.php','update', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
return false;
return false;
}
else
{
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 1, $VAR);
}
return true;
# Define any triggers
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],1,$VAR);
}
}
return true;
}
}
?>
?>

View File

@@ -1,170 +1,111 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
function CORE_database_view($VAR, &$construct, $type)
{
/**
* The main AgileBill CORE Database VIEW Method
*
* This function should only return 1 record.
*
* @uses CORE_trigger
* @uses CORE_static_var
*/
function CORE_database_view($VAR,$construct,$type) {
require_once(PATH_CORE.'static_var.inc.php');
# Some Validaiton
if (! isset($VAR['id']))
return;
# If we have more than 1 entry, then return. Javascript should bring us back with 1 entry to view.
if (count(explode(',',preg_replace('/,$/','',$VAR['id']))) > 1)
return;
# Set our db.
$db = &DB();
# set the field list for this method:
$arr = $construct->method[$type];
$result = $db->Execute(sqlSelect($db,$construct->table,implode(',',$construct->method[$type]),array('id'=>$VAR['id']),$construct->order_by));
# loop through the field list to create the sql queries
$field_list = '';
$i=0;
while (list ($key, $value) = each ($arr))
{
if($i == 0)
{
$field_var = $construct->table . '_' . $value;
$field_list .= $value;
# Error reporting
if ($result === false) {
global $C_debug;
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
else
{
$field_var = $construct->table . '_' . $value;
$field_list .= "," . $value;
}
$i++;
return;
# No results:
} elseif (! $result->RecordCount()) {
global $C_debug;
$C_debug->error(__FILE__,__METHOD__,'The selected record does not exist any longer, or your account is not authorized to view it');
return;
}
if(isset($VAR["id"]))
{
$id = explode(',',$VAR["id"]);
for($i=0; $i<count($id); $i++)
{
if($id[$i] != '')
{
if($i == 0)
{
$id_list .= " id = " .$db->qstr($id[$i])." ";
$ii++;
}
else
{
$id_list .= " OR id = " .$db->qstr($id[$i]). " ";
$ii++;
}
}
}
}
# Get the static vars
$static_var = new CORE_static_var;
$arr = $static_var->update_form($construct->module,'update',$result->fields['id']);
if (is_array($arr))
$smart['static_var'] = $arr;
if($ii>0)
{
# generate the full query
$q = "SELECT
$field_list
FROM
".AGILE_DB_PREFIX."$construct->table
WHERE
$id_list
AND site_id = '" . DEFAULT_SITE . "'
ORDER BY $construct->order_by ";
# Run any custom validation on this result for this module
if (isset($construct->custom_EXP)) {
for ($ei=0; $ei<count($construct->custom_EXP); $ei++) {
$field = $construct->custom_EXP[$ei]['field'];
$value = $construct->custom_EXP[$ei]['value'];
$result = $db->Execute($q);
if ($result->fields[$field] == $value) {
$smart = $result->fields;
///////////////////////
# echo $q;
# echo "<BR>" . $db->ErrorMsg();
# error reporting
if ($result === false)
{
global $C_debug;
$C_debug->error('database.inc.php','view', $db->ErrorMsg());
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
}
return;
}
# put the results into a smarty accessable array
$i=0;
$class_name = TRUE;
while (!$result->EOF)
{
### Run any custom validation on this result for
### this module
if(isset($construct->custom_EXP))
{
for($ei=0; $ei<count($construct->custom_EXP); $ei++)
{
$field = $construct->custom_EXP[$ei]["field"];
$value = $construct->custom_EXP[$ei]["value"];
if($result->fields["$field"] == $value)
{
$smart[$i] = $result->fields;
if($class_name)
{
$smart[$i]["i"] = $i;
} else {
$smart[$i]["i"] = $i;
}
$result->MoveNext();
$ei = count($construct->custom_EXP);
$i++;
}
}
$result->MoveNext();
}
else
{
$smart[$i] = $result->fields;
if($class_name)
{
$smart[$i]["i"] = $i;
} else {
$smart[$i]["i"] = $i;
}
$result->MoveNext();
$i++;
$ei = count($construct->custom_EXP);
}
}
# get the result count:
$results = $i;
### No results:
if($i == 0)
{
global $C_debug;
$C_debug->error("CORE:database.inc.php", "view()", "The selected record does not
exist any longer, or your account is not authorized to view it");
return;
}
# define the results
global $smarty;
$smarty->assign($construct->table, $smart);
$smarty->assign('results', $search->results);
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 1, $VAR);
}
return $smart;
} else {
$smart = $result->fields;
}
# Define the results
global $smarty;
$smarty->assign('record',$smart);
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],1,$VAR);
}
# Return the retrieved records
return $smart;
}
?>
?>

View File

@@ -1,249 +1,217 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
/*
Email Handler Class
This class handles the interface to SMPT and Mail() functions.
$arr = Array(
'from_html' => 'true/false' (so we know whether to stripslashes or not)
'html' => '0/1',
'from_name' => '',
'from_email' => '',
'priority' => '0/1',
'to_email' => 'email@email.com',
'to_name' => '',
'bcc_list' => Array('email@email.com'),
'cc_list' => Array('email@email.com'),
'subject' => '',
'body_text' => '',
'body_html' => '',
'attachments' => Array(Array('file' => 'file.exe',
'data' => 'file data here...'))
'server' => 'mail.domain.com',
'account' => '',
'password' => '');
/**
* The main AgileBill CORE Mail Class
*
* This class handles the interface to SMTP and Mail() functions.
*
* <code>
* $arr = array(
* 'from_html' => 'true/false' (so we know whether to stripslashes or not)
* 'html' => '0/1',
* 'from_name' => '',
* 'from_email' => '',
* 'priority' => '0/1',
* 'to_email' => 'email@email.com',
* 'to_name' => '',
* 'bcc_list' => array('email@email.com'),
* 'cc_list' => array('email@email.com'),
* 'subject' => '',
* 'body_text' => '',
* 'body_html' => '',
* 'attachments' => array(array('file' => 'file.exe',
* 'data' => 'file data here...'))
* 'server' => 'mail.domain.com',
* 'account' => '',
* 'password' => '');
* </code>
*
* @package AgileBill
* @subpackage Core
*/
class CORE_email
{
class CORE_email {
var $debug=false;
function PHP_Mail($arr)
{
### SET THE SMTP SETTINGS
#ini_set('sendmail_from', @$arr['from_email']);
#ini_set('SMTP', @$arr['server']);
public function PHP_Mail($arr) {
# SET THE SMTP SETTINGS
#ini_set('sendmail_from',@$arr['from_email']);
#ini_set('SMTP',@$arr['server']);
### CC LIST
if(isset($arr['cc_list']) == 'array')
{
if(count($arr['cc_list'] > 0))
{
$cc = '';
for($i=0; $i<count($arr['cc_list']); $i++)
{
if($i == 0)
$cc .= $arr['cc_list'][$i];
else
$cc .= ','.$arr['cc_list'][$i].',';
}
}
# CC LIST
$cc = '';
if (isset($arr['cc_list']) && is_array($arr['cc_list']))
$cc = implode(',',$arr['cc_list']);
# BCC LIST
$bcc = '';
if (isset($arr['bcc_list']) && is_array($arr['bcc_list']))
$bcc = implode(',',$arr['bcc_list']);
$headers = '';
# FROM:
$headers .= sprintf('From: "%s" <%s>',$arr['from_name'],$arr['from_email'])."\r\n";
$headers .= sprintf('Reply-To: "%s" <%s>',$arr['from_name'],$arr['from_email'])."\r\n";
# HTML/non-HTML version of body & headers
$headers .= "MIME-Version: 1.0\r\n";
if (isset($arr['html']) && $arr['html'] == '1' && isset($arr['body_html'])) {
# Specify MIME version 1.0
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$body = $arr['body_html'];
} else {
# Specify MIME version 1.0
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$body = $arr['body_text'];
}
### BCC LIST
if(isset($arr['bcc_list']) == 'array')
{
if(count($arr['bcc_list'] > 0))
{
$bcc = '';
for($i=0; $i<count($arr['bcc_list']); $i++)
{
if($i == 0)
$bcc .= $arr['bcc_list'][$i];
else
$bcc .= ','.$arr['bcc_list'][$i];
}
}
}
# CC:
if (trim($cc))
$headers .= sprintf('Cc: %s',$cc)."\r\n";
$headers = '';
### FROM:
$headers .= "From: \"".$arr['from_name']."\" <".$arr['from_email'].">\r \n";
$headers .= "Reply-To: \"".$arr['from_name']."\" <".$arr['from_email'].">\r \n";
# html/non-html version of body & headers
if(isset($arr['html']) && $arr['html'] == '1' && isset($arr['body_html']))
{
### specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r \n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r \n";
$body = $arr['body_html'];
}
else
{
### specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r \n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r \n";
$body = $arr['body_text'];
}
### CC:
if(isset($cc))
$headers .= "Cc: ".$cc."\r \n";
### BCC:
if(isset($bcc))
$headers .= "Bcc: ".$bcc."\r \n";
# BCC:
if (trim($bcc))
$headers .= sprintf('Bcc: %s',$bcc)."\r\n";
### PRIORITY
if(isset($arr['priority']) && $arr['priority'] == '1')
$headers .= "X-Priority: 1";
$headers .= "X-Priority: 1\r\n";
else
$headers .= "X-Priority: 3";
$headers .= "X-Priority: 3\r\n";
/*
echo "<pre>";
echo print_r($arr);
echo $headers;
echo $body;
*/
### Strip Slashes
if (!isset($arr['from_html']) || @$arr['html_form'] == false) {
# from database, we must strip slashes
# Strip Slashes
if (! isset($arr['from_html']) || @$arr['html_form'] == false) {
# From database, we must strip slashes
$arr['subject'] = stripslashes($arr['subject']);
$body = stripslashes($body);
$body = stripslashes($body);
} elseif (@$arr['from_html'] == true && get_magic_quotes_gpc()) {
# straight from html, we must strip slashes
# Straight from html, we must strip slashes
$arr['subject'] = stripslashes($arr['subject']);
$body = stripslashes($body);
$body = stripslashes($body);
}
if($this->debug)
{
if(mail($arr['to_email'], $arr['subject'], $body, $headers)) {
if ($this->debug) {
if (mail($arr['to_email'],$arr['subject'],$body,$headers)) {
global $C_debug;
$message = 'PHP mail() failed to send message "'.$arr['subject'].'" to "'.$arr['to_email'].'"';
$C_debug->alert('CORE:email.inc.php','SMTP_Mail', $message);
return false;
}
}
else
{
if(@mail($arr['to_email'], $arr['subject'], $body, $headers)) {
global $C_debug;
$message = 'PHP mail() failed to send message "'.$arr['subject'].'" to "'.$arr['to_email'].'"';
$C_debug->alert(__FILE__,__METHOD__,sprintf('PHP mail() failed to send message "%s" to "%s"',$arr['subject'],$arr['to_email']));
return false;
}
} else {
if (@mail($arr['to_email'],$arr['subject'],$body,$headers)) {
global $C_debug;
$C_debug->alert(__FILE__,__METHOD__,sprintf('PHP mail() failed to send message "%s" to "%s"',$arr['subject'],$arr['to_email']));
return false;
}
}
return true;
}
function SMTP_Mail($arr)
{
### include the phpmailer class
require_once(PATH_INCLUDES."phpmailer/class.phpmailer.php");
public function SMTP_Mail($arr) {
# Include the phpmailer class
require_once(PATH_INCLUDES.'phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = @$arr['server'];
$mail->Username = @$arr['account'];
$mail->Password = @$arr['password'];
$mail->From = $arr['from_email'];
$mail->FromName = $arr['from_name'];
$mail->AddAddress($arr['to_email'], @$arr['to_name']);
$mail->SMTPAuth = true;
$mail->Host = @$arr['server'];
$mail->Username = @$arr['account'];
$mail->Password = @$arr['password'];
$mail->From = $arr['from_email'];
$mail->FromName = $arr['from_name'];
$mail->AddAddress($arr['to_email'],@$arr['to_name']);
#$mail->AddReplyTo($arr['from_name'], $arr['from_email']);
# CC LIST
if (isset($arr['cc_list']) && is_array($arr['cc_list']))
foreach ($arr['cc_list'] as $email)
$mail->AddCC($email,'');
### CC LIST
if(is_array(@$arr['cc_list']))
for($i=0; $i<count($arr['cc_list']); $i++)
$mail->AddCC($arr['cc_list'][$i], "");
# BCC LIST
if (isset($arr['bcc_list']) && is_array($arr['bcc_list']))
foreach ($arr['bcc_list'] as $email)
$mail->AddBCC($email,'');
### BCC LIST
if(is_array(@$arr['bcc_list']))
for($i=0; $i<count($arr['bcc_list']); $i++)
$mail->AddBCC($arr['bcc_list'][$i], "");
### Strip Slashes
if (empty($arr['from_html']) || @$arr['html_form'] == false) {
# from database, we must strip slashes
$arr['subject'] = stripslashes($arr['subject']);
# Strip Slashes
if (! isset($arr['from_html']) || @$arr['html_form'] == false) {
# From database, we must strip slashes
$arr['subject'] = stripslashes($arr['subject']);
@$arr['body_html'] = stripslashes($arr['body_html']);
@$arr['body_text'] = stripslashes($arr['body_text']);
} elseif (@$arr['from_html'] == true && get_magic_quotes_gpc()) {
# straight from html, we must strip slashes
# Straight from html, we must strip slashes
$arr['subject'] = stripslashes($arr['subject']);
@$arr['body_html'] = stripslashes($arr['body_html']);
@$arr['body_text'] = stripslashes($arr['body_text']);
}
# html/non-html version of body & headers
if(isset($arr['html']) && $arr['html'] == '1' && isset($arr['body_html'])) {
# HTML/non-HTML version of body & headers
if (isset($arr['html']) && $arr['html'] == '1' && isset($arr['body_html'])) {
$mail->IsHTML(true);
$mail->Body = @$arr['body_html'];
$mail->AltBody = @$arr['body_text'];
} else {
$mail->Body = @$arr['body_html'];
$mail->AltBody = @$arr['body_text'];
} else {
$mail->IsHTML(false);
$mail->Body = @$arr['body_text'];
$mail->Body = @$arr['body_text'];
$mail->WordWrap = 50;
}
# subject
$mail->Subject = $arr['subject'];
# Subject
$mail->Subject = $arr['subject'];
# PRIORITY
if(isset($arr['priority']) && $arr['priority'] == '1')
$mail->Priority = 1;
$mail->Priority = 1;
else
$mail->Priority = 3;
$mail->Priority = 3;
/* attachments
/* Attachments
$mail->AddAttachment("/var/tmp/file.tar.gz");
$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
*/
if(!$mail->Send())
{
if($this->debug) {
global $C_debug;
$message = 'SMTP mail() failed to send message "'.$arr['subject'].'" to "'.$arr['to_email'].'" on server "'.$arr['server'].'"';
$C_debug->error('CORE:email.inc.php','SMTP_Mail', $message . ' ---- '.$mail->ErrorInfo);
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
global $C_debug;
$message = 'SMTP mail() failed to send message "'.$arr['subject'].'" to "'.$arr['to_email'].'" on server "'.$arr['server'].'"';
$C_debug->error('CORE:email.inc.php','SMTP_Mail', $message. ' ---- '.$mail->ErrorInfo);
if (! $mail->Send()) {
global $C_debug;
$C_debug->error(__FILE__,__METHOD__,sprintf('SMTP mail() failed to send message "%s" to "%s" on server "%s" (%s)',
$arr['subject'],$arr['to_email'],$arr['server'],$mail->ErrorInfo));
if ($this->debug) {
echo 'Message was not sent <p>';
printf('Mailer Error: %s',$mail->ErrorInfo);
}
return false;
return false;
}
return true;
}
}
?>
?>

View File

@@ -1,58 +1,102 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
class CORE_list
{
var $id;
function menu($input_id, $name, $table, $field, $id, $class, $all=false) {
/**
* The main AgileBill CORE List Class
*
* @package AgileBill
* @subpackage Core
*/
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;
if($all == true || $id == 'all') $all = true;
if(!isset($this->id)) $this->id = 100;
if($input_id <= 0 && $input_id != 'no') $input_id = $this->id++;
$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();
$sql= "SELECT id, $field FROM ".AGILE_DB_PREFIX."$table WHERE site_id = '" . DEFAULT_SITE . "' ORDER BY $field";
$result = $db->Execute($sql);
if ($result === false)
{
$result = $db->Execute(sqlSelect($db,$table,sprintf('id,%s',$field),$where,$field));
if ($result === false) {
global $C_debug;
$C_debug->error('list.inc.php','menu', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
} else {
$return = '<select id="'. $field .'_'. $input_id .'" name="'. $name .'" class="'.$class.'">';
if($all)
$return .= '<option value=""></option>';
$return = sprintf('<select id="%s" name="%s" class="%s">',$input_id,$name,$class);
if ($all)
$return .= '<option value="">&nbsp;</option>';
$i = 0;
while (!$result->EOF) {
$return .= '<option value="' . $result->fields["id"] . '"';
if($id == $result->fields["id"])
$return .= "selected";
$return .= '>' . $result->fields["$field"] . '</option>
';
$i++;
while (! $result->EOF) {
$return .= sprintf('<option value="%s"%s>%s</option>',$result->fields['id'],($default == $result->fields['id']) ? ' selected="selected"' : '',$result->fields[$field]);
$result->MoveNext();
$i++;
}
if($i==0)
$return .= '<option value="">'. $C_translate->translate('lists_none_defined','CORE','').'</option>';
$return .= '</select>';
if($i > 0 && $input_id != 'no')
$return .= '&nbsp;<img src="themes/' . THEME_NAME . '/images/icons/zoomi_16.gif" border="0" width="16" height="16" onclick="menu_item_view(\''.$table.'\',\''.$field .'_'.$input_id.'\');">';
if ($i==0)
$return = $C_translate->translate('lists_none_defined');
if ($i > 0 && ! $noicon)
$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);
echo $return;
}
}
@@ -66,25 +110,190 @@ class CORE_list
include_once(PATH_MODULES . 'account_billing/account_billing.inc.php');
$acct_bill = new account_billing;
echo $acct_bill->menu_admin($field, $account, $default, $class, $user);
}
}
function menu_multi($default, $name, $table, $field, $id, $max, $class) {
include_once(PATH_CORE . 'list_menu_multi.inc.php');
echo list_menu_multi($default, $name, $table, $field, $id, $max, $class);
include_once(PATH_CORE.'list_menu_multi.inc.php');
echo list_menu_multi($default, $name, $table, $field, $id, $max, $class);
}
function menu_files($id, $name, $default, $path, $pre, $ext, $class) {
include_once(PATH_CORE . 'list_menu_files.inc.php');
include_once(PATH_CORE.'list_menu_files.inc.php');
echo list_menu_files($id, $name, $default, $path, $pre, $ext, $class);
}
/**
* 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) {
global $C_list;
# Whether the values are also keys.
$nokeys = false;
$list = array();
switch ($type) {
case 'assoc_grant_type':
$list = array(0=>_('Grant access for specified amount of days'),1=>_('Grant access while associated subscription is active'),2=>_('Grant access forerver'));
break;
case 'assoc_prod_type':
$list = array(0=>_('Require All Selected Products'),1=>_('Require Any One Selected Product'));
break;
case 'charge_sweep':
$list = array(0=>_('Daily'),1=>_('Weekly'),2=>_('Monthly'),3=>_('Quarterly'),4=>_('Semi-Annually'),5=>_('Annually'),6=>_('Service Rebill'));
break;
case 'commissiontype':
$list = array(0=>_('None'),1=>_('Percentage Based'),2=>('Flat Rate'));
break;
# @todo To deprecate this and standardise with commissiontype
case 'discounttype':
$list = array(0=>_('Percentage Based'),1=>('Flat Rate'));
break;
case 'copluginmode':
$list = array(0=>_('Test'),1=>_('Live'));
break;
case 'domaintype':
$list = array(
'register'=>_('Register'),
'transfer'=>_('Transfer'),
'park'=>_('Park')
);
break;
case 'email_piping':
$list = array(0=>'&nbsp;',1=>'POP',2=>'IMAP');
break;
case 'email_piping_action':
$list = array(0=>_('Leave message in mailbox'),1=>_('Delete message from mailbox'));
break;
case 'invoice_delivery':
$list = array(0=>_('None'),1=>_('E-Mail'),2=>_('Print'));
break;
case 'invoice_show_itemized':
$list = array(0=>_('Overview Only'),1=>_('Full Detail'));
break;
case 'nametitle':
$list = array(_('Mr'),_('Ms'),_('Mrs'),_('Miss'),_('Dr'),_('Prof'));
$nokeys = true;
break;
case 'os':
$list = array(0=>'Linux',1=>'Windows');
break;
case 'recur_schedule':
$list = array(0=>_('Weekly'),1=>_('Monthly'),2=>_('Quarterly'),3=>_('Semi-Annually'),4=>_('Annually'),5=>_('Two years'),6=>_('Three Years'));
break;
case 'recur_type':
$list = array(0=>_('Bill on Aniversary Date of Subscription'),1=>_('Bill on Fixed Schedule'));
break;
case 'pricetype':
$list = array(0=>_('One-time Charge'),1=>_('Recurring Membership/Subscription'),2=>_('Trial for Membership/Subscription'));
break;
case 'servicetype':
if ($C_list->is_installed('host_server')) {
$list['host'] = _('Hosting');
$list['host_group'] = _('Hosting & Group Access');
$list['domain'] = _('Domain Name');
}
$list['none'] = _('Recurring Only');
break;
case 'servicequeue':
$list = array(
'new'=>_('Add New'),
'active'=>_('Activate'),
'inactive'=>_('Deactivate'),
'delete'=>_('Delete'),
'edit'=>_('Edit/Update'),
'queue_none'=>_('None')
);
break;
case 'statictype':
$list = array(
'small_text'=>_('Small Text'),
'medium_text'=>_('Medium Text'),
'large_text'=>_('Large Text'),
'dropdown_list'=>_('Dropdown List'),
'calendar'=>_('Calendar'),
'file_upload'=>_('File Upload'),
'status'=>_('Status'),
'checkbox'=>_('Checkbox'),
'hidden'=>_('Hidden')
);
break;
case 'tasktype':
$list = array(0=>_('Internal Method'),1=>_('System Call'));
break;
case 'trial_length':
$list = array(0=>_('Days'),1=>_('Weeks'),2=>_('Months'));
break;
default: return sprintf('Unknown staticlist: %s',$type);
}
# If id is blank, we'll just return the value
if (! $input_id)
return $list[$default];
$return = sprintf('<select id="%s" name="%s" class="%s">',$input_id,$name,$class);
if ($all)
$return .= '<option value="">&nbsp;</option>';
foreach ($list as $element => $details) {
$selected = '';
if ($nokeys) {
if ($default == $details)
$selected = ' selected="selected"';
} else {
if ($default == $element)
$selected = ' selected="selected"';
}
$return .= sprintf('<option value="%s"%s>%s</option>',$nokeys ? $details : $element,$selected,$details);
}
$return .= '</select>';
return $return;
}
function format_currency ($number, $currency_id) {
if(empty($number)) $number = 0;
if(empty($number)) $number = 0;
if(empty($currency_id)) $currency_id = DEFAULT_CURRENCY;
if(!isset($this->format_currency[$currency_id])) $this->currency($currency_id);
if($currency_id != DEFAULT_CURRENCY)
if(!isset($this->format_currency[DEFAULT_CURRENCY]))
$this->currency(DEFAULT_CURRENCY);
if(!isset($this->format_currency[DEFAULT_CURRENCY]))
$this->currency(DEFAULT_CURRENCY);
$number *= $this->format_currency[DEFAULT_CURRENCY]["convert"][$currency_id]["rate"];
if($number > .05 || $number == 0 || $number < -1)
return $this->format_currency[$currency_id]["symbol"]
@@ -93,33 +302,33 @@ class CORE_list
else
return $this->format_currency[$currency_id]["symbol"]
. "" . number_format($number, 3) . " "
. $this->format_currency[$currency_id]["iso"];
. $this->format_currency[$currency_id]["iso"];
}
function format_currency_num ($number, $currency_id) {
if(empty($number)) $number = 0;
if(empty($number)) $number = 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);
if(!isset($this->format_currency[DEFAULT_CURRENCY])) $this->currency(DEFAULT_CURRENCY);
$number *= $this->format_currency[DEFAULT_CURRENCY]["convert"][$currency_id]["rate"];
if($number > .05 || $number == 0 || $number < -1)
return $this->format_currency[$currency_id]["symbol"] . number_format($number, DEFAULT_DECIMAL_PLACE);
else
return $this->format_currency[$currency_id]["symbol"] . number_format($number, 3);
}
return $this->format_currency[$currency_id]["symbol"] . number_format($number, 2);
}
function format_currency_decimal ($number, $currency_id) {
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);
if(!isset($this->format_currency[DEFAULT_CURRENCY])) $this->currency(DEFAULT_CURRENCY);
return round($number *= $this->format_currency[DEFAULT_CURRENCY]["convert"][$currency_id]["rate"], 2);
}
}
function currency_list($ret) {
if(!isset($this->format_currency[$currency_id])) $this->currency(DEFAULT_CURRENCY);
global $smarty;
$smarty->assign("$ret", $this->format_currency[DEFAULT_CURRENCY]["convert"]);
$smarty->assign("$ret", $this->format_currency[DEFAULT_CURRENCY]["convert"]);
}
function currency_iso ($currency_id) {
@@ -147,13 +356,13 @@ class CORE_list
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);
}
echo list_radio($input_id, $name, $table, $field, $id, $class);
}
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);
}
}
function select_groups($default, $field_name, $class, $size, $own_account) {
include_once(PATH_CORE . 'list_select_groups.inc.php');
@@ -161,46 +370,52 @@ class CORE_list
}
function calender_view($field, $default, $css, $id) {
if(isset($default) && $default != '' && $default != '0')
if(isset($default) && $default != '' && $default != '0')
$default = date(UNIX_DATE_FORMAT, $default);
else
$default = '';
include_once(PATH_CORE.'list_calendar.inc.php');
echo list_calender_add($field, $default, $css);
}
function calender_add($field, $default, $css) {
if($default == 'now') $default = date(UNIX_DATE_FORMAT, time());
include_once(PATH_CORE.'list_calendar.inc.php');
echo list_calender_add($field, $default, $css);
echo list_calender_add($field, $default, $css,$id);
}
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');
echo list_calender_add($field,$default,$css,$id);
}
# @todo Remove?
function calender_add_static_var($field, $default, $css) {
if($default == 'now') $default = date(UNIX_DATE_FORMAT, time());
include_once(PATH_CORE.'list_calendar.inc.php');
echo list_calender_add_static($field, $default, $css);
}
function calender_search($field, $default, $css) {
if($default == 'now') $default = date(UNIX_DATE_FORMAT, time());
function calender_search($field, $default, $css) {
if ($default == 'now')
$default = date(UNIX_DATE_FORMAT, time());
echo '
<select name="field_option['.$field.'][0]">
<option value=">">></option>
<option value=">">></option>
<option value="<="><=</option>
<option value=">=">>=</option>
<option value="!=">!=</option>
</select>&nbsp;&nbsp;';
$this->calender_view($field.'[0]', $default, $css, 1);
echo '<BR>
<select name="field_option['.$field.'][1]">
<option value="<"><</option>
<option value="<"><</option>
<option value="<="><=</option>
<option value=">=">>=</option>
<option value="!=">!=</option>
</select>&nbsp;&nbsp;';
$this->calender_view($field.'[1]', $default, $css, 1);
$this->calender_view($field,$default,$css,0);
echo '<br/>
<select name="field_option['.$field.'][1]">
<option value="<"><</option>
<option value=">">></option>
<option value="<="><=</option>
<option value=">=">>=</option>
<option value="!=">!=</option>
</select>&nbsp;&nbsp;';
$this->calender_view($field,$default,$css,1);
}
function setup_default_date($default, $css) {
@@ -208,19 +423,20 @@ class CORE_list
echo list_setup_default_date($default, $css);
}
function card_type_menu($default_selected, $checkout_id, $field='checkout_plugin_data[card_type]', $class) {
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);
}
echo list_card_type_menu($default_selected, $checkout_id, $field, $class,$all);
}
function date($date) {
function date($date) {
if($date == '') $date = time();
return date(UNIX_DATE_FORMAT, $date);
}
return date(UNIX_DATE_FORMAT, $date);
}
function date_time($date) {
if($date == '') $date = time();
$ret = date(UNIX_DATE_FORMAT, $date);
function date_time($date) {
if ($date == '')
return 'UNKNOWN';
$ret = date(UNIX_DATE_FORMAT, $date);
$ret .= " ".date(DEFAULT_TIME_FORMAT, $date);
return $ret;
}
@@ -228,7 +444,7 @@ class CORE_list
function unserial ($data, $var) {
global $smarty;
if(is_string($data)) $array = unserialize($data);
if(is_array($array)) $smarty->assign($var, $array);
if(is_array($array)) $smarty->assign($var, $array);
return;
}
@@ -237,18 +453,18 @@ class CORE_list
$sql= "SELECT id, $field FROM ".AGILE_DB_PREFIX."$table
WHERE site_id = '" . DEFAULT_SITE . "'" . $sql . "
ORDER BY $field";
$result = $db->Execute($sql);
$result = $db->Execute($sql);
if ($result === false)
{
global $C_debug;
$C_debug->error('list.inc.php','smarty_array', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
return false;
}
}
while (!$result->EOF)
{
{
$smart[] = $result->fields;
$result->MoveNext();
}
}
global $smarty;
$smarty->assign("$return", $smart);
return true;
@@ -261,11 +477,11 @@ class CORE_list
WHERE site_id = " . $db->qstr(DEFAULT_SITE) . " AND
language_id = " . $db->qstr(SESS_LANGUAGE). " AND " .
$field2 . " = " . $db->qstr($id);
$result = $db->Execute($sql);
$result = $db->Execute($sql);
if ($result === false)
{
global $C_debug;
$C_debug->error('list.inc.php','translate', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
return false;
} else if($result->RecordCount() > 0) {
$smarty->assign("$var", $result->fields);
@@ -278,10 +494,10 @@ class CORE_list
WHERE site_id = " . $db->qstr(DEFAULT_SITE) . " AND
language_id = " . $db->qstr(DEFAULT_LANGUAGE). " AND " .
$field2 . " = " . $db->qstr($id);
$result = $db->Execute($sql);
$result = $db->Execute($sql);
if ($result === false) {
global $C_debug;
$C_debug->error('list.inc.php','translate', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
return false;
} else if($result->RecordCount() > 0) {
$smarty->assign("$var", $result->fields);
@@ -293,29 +509,39 @@ class CORE_list
}
}
function bool($field, $curr_value, $extra) {
public function bool($field,$curr_value,$class='form_menu',$extra='') {
global $C_translate;
if($curr_value == 'all') {
# If the field is blank, we'll just return true/false
if (! $field)
return $curr_value ? $C_translate->translate('true') : $C_translate->translate('false');
if ($curr_value == 'all') {
$true = '';
$false= '';
} else if($curr_value == "1") {
$true = ' selected';
} elseif($curr_value == '1') {
$true = ' selected="selected"';
$false= '';
} else {
$true = '';
$false= ' selected';
$false= ' selected="selected"';
}
$return = '<select id="'.$field.'" name="'. $field .'" '.$extra.'>';
if($curr_value == 'all')
$return .= '<option value="" selected></option>
';
$return .= '<option value="1"' . $true . '>'. $C_translate->translate('true', 'CORE','') . '</option>';
$return .= '<option value="0"' . $false . '>'. $C_translate->translate('false','CORE','') . '</option>';
$return .= '</select>';
$return = sprintf('<select id="%s" name="%s" class="%s" %s>',$field,$field,$class,$extra);
if ($curr_value == 'all')
$return .= '<option value="" selected="selected">&nbsp;</option>';
$return .= sprintf('<option value="1"%s>%s</option>',$true,$C_translate->translate('true'));
$return .= sprintf('<option value="0"%s>%s</option>',$false,$C_translate->translate('false'));
$return .= '</select>';
echo $return;
}
// @todo this looks the same as bool()
function bool_static_var($field, $curr_value, $class) {
global $C_translate;
if ($curr_value == 'all') {
@@ -328,12 +554,12 @@ class CORE_list
$true = ' selected';
$false= '';
}
$return = '<select id="'.$field.'" name="'. $field .'">';
$return = '<select id="'.$field.'" name="'. $field .'">';
if($curr_value == 'all')
$return .= '<option value="" selected></option>';
$return .= '<option value="" selected>&nbsp;</option>';
$return .= '<option value="1"' . $true . '>'. $C_translate->translate('true', 'CORE','') . '</option>';
$return .= '<option value="0"' . $false . '>'. $C_translate->translate('false','CORE','') . '</option>';
$return .= '</select>';
$return .= '</select>';
return $return;
}
@@ -372,7 +598,9 @@ class CORE_list
$graph->PIE_graph($module, $method, $range, $start, $extra);
}
function is_installed($module) {
# @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
function is_installed($module) {
if(@$this->is_installed[$module] == true) return true;
if($this->auth_method_by_name($module, 'search')) {
$this->is_installed[$module] = true;
@@ -393,15 +621,22 @@ class CORE_list
}
function auth_method_by_name($module, $method) {
global $C_auth;
if(!is_object($C_auth)) return false;
return $C_auth->auth_method_by_name($module, $method);
global $C_auth;
if (!is_object($C_auth))
return false;
return $C_auth->auth_method_by_name($module,$method);
}
function generate_admin_menu() {
/**
* Generate the admin menu
*/
public function generate_admin_menu() {
global $C_auth;
echo $C_auth->generate_admin_menu();
}
}
function account($field) {
if (empty($this->account) && SESS_LOGGED) {
@@ -413,11 +648,11 @@ class CORE_list
$this->account = $result->fields;
}
echo $this->account[$field];
}
}
# Get the AgileBill version info
function version() {
require_once(PATH_CORE.'version.inc.php');
}
}
?>
?>

View File

@@ -1,60 +1,66 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Template:Calendar
*/
function list_calender_add($field, $default, $css)
{
# set the date to current date if 'now' is set as $default
if($default == 'now')
{
$default = date(UNIX_DATE_FORMAT, time());
}
/**
* The main AgileBill Template Calendar Method
*
* @package AgileBill
* @subpackage Template:Calendar
*/
function list_calender_add($field,$default,$css,$fid) {
# Set the date to current date if 'now' is set as $default
if ($default == 'now')
$default = date(UNIX_DATE_FORMAT,time());
$id = rand(9,999);
$ret = '
<input type="text" id="data_'.$field.'_'.$id.'" name="'.$field.'" class="'.$css.'" size="10" value="'.$default.'" />&nbsp;
<input type="button" id="trigger_'.$field.'_'.$id.'" value="+">
<script type="text/javascript">
Calendar.setup(
{
inputField : "data_'.$field.'_'.$id.'",
ifFormat : "'.DEFAULT_DATE_FORMAT.'",
button : "trigger_'.$field.'_'.$id.'"
}
);
</script>
';
$ret = '';
if ($fid)
$ret .= sprintf('<input type="text" id="data_%s_%s_%s" name="%s[%s]" class="%s" size="10" value="%s"/>&nbsp;',$field,$fid,$id,$field,$fid,$css,$default);
else
$ret .= sprintf('<input type="text" id="data_%s_%s_%s" name="%s" class="%s" size="10" value="%s"/>&nbsp;',$field,$fid,$id,$field,$css,$default);
$ret .= sprintf('<input type="button" id="trigger_%s_%s_%s" value="+"/>',$field,$fid,$id);
$ret .= '<script type="text/javascript">Calendar.setup({';
$ret .= sprintf('inputField : "data_%s_%s_%s",',$field,$fid,$id);
$ret .= sprintf('ifFormat : "%s",',DEFAULT_DATE_FORMAT);
$ret .= sprintf('button : "trigger_%s_%s_%s"',$field,$fid,$id);
$ret .= '});</script>';
return $ret;
}
}
# @todo Remove?
function list_calender_add_static($field,$default,$css) {
return list_calender_add($field,$default,$css,'');
function list_calender_add_static($field, $default, $css)
{
# set the date to current date if 'now' is set as $default
if($default == 'now')
{
$default = date(UNIX_DATE_FORMAT);
}
# Set the date to current date if 'now' is set as $default
if ($default == 'now')
$default = date(UNIX_DATE_FORMAT);
$id = rand(9,999);
$ret = '
<input type="text" id="data_'.$field.'_'.$id.'" name="'.$field.'" class="'.$css.'" size="10" value="'.$default.'" />&nbsp;
<input type="text" id="data_'.$field.'_'.$id.'" name="'.$field.'" class="'.$css.'" size="10" value="'.$default.'" />&nbsp;
<input type="button" id="trigger_'.$field.'_'.$id.'" value="+">
<script type="text/javascript">
Calendar.setup(
@@ -68,4 +74,4 @@ function list_calender_add_static($field, $default, $css)
';
return $ret;
}
?>
?>

View File

@@ -1,65 +1,83 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Unknown
*/
function list_card_type_menu($default_selected, $checkout_id, $field, $class)
{
// define default list of accepted CC types
$def_accepted_arr = Array (
0 => 'visa',
1 => 'mc',
2 => 'amex',
3 => 'discover',
4 => 'delta',
5 => 'solo',
6 => 'switch',
7 => 'jcb',
8 => 'diners',
9 => 'carteblanche',
10 => 'enroute' );
$db = &DB();
$q = "SELECT * FROM ".AGILE_DB_PREFIX."checkout WHERE
site_id = ".$db->qstr(DEFAULT_SITE)." AND
id = ".$db->qstr($checkout_id);
$rs = $db->Execute($q);
if($rs == false || $rs->RecordCount() == 0)
$accepted_arr = $def_accepted_arr;
@$cfg = unserialize($rs->fields["plugin_data"]);
$accepted_arr = $cfg['card_type'];
if(count($accepted_arr) <= 0)
$accepted_arr = $def_accepted_arr;
/**
* The main AgileBill List Credit Card Method
*
* @package AgileBill
* @subpackage Unknown
*/
function list_card_type_menu($default_selected,$checkout_id,$field,$class,$all=false) {
global $C_translate;
$data = '<select id="'.$field.'" name="'.$field.'" value="'.$default.'">';
for($i=0; $i<count($accepted_arr); $i++) {
$data .= '<option value="'.$accepted_arr[$i].'"';
if($default_selected == $accepted_arr[$i])
$data .= ' selected';
$data .= '">'.
$C_translate->translate('card_type_'. $accepted_arr[$i],'checkout','');
'</option>
';
}
$data .= '</select>';
return $data;
# Define default list of accepted CC types
$def_accepted_arr = array(
'visa',
'mc',
'amex',
'discover',
'delta',
'solo',
'switch',
'jcb',
'diners',
'carteblanche',
'enroute');
$accepted_arr = array();
$db = &DB();
$rs = $db->Execute($q=sqlSelect($db,'checkout','plugin_data',$checkout_id ? array('id'=>$checkout_id) : ''));
if ($rs == false || $rs->RecordCount() == 0)
$accepted_arr = $def_accepted_arr;
else
while (! $rs->EOF) {
$cfg = unserialize($rs->fields['plugin_data']);
if ($cfg['card_type'])
$accepted_arr = array_merge($accepted_arr,$cfg['card_type']);
$rs->MoveNext();
}
if (! count($accepted_arr))
$accepted_arr = $def_accepted_arr;
else
$accepted_arr = array_values(array_unique($accepted_arr));
asort($accepted_arr);
$data = sprintf('<select id="%s" name="%s">',$field,$field);
if ($all)
$data .= '<option value="" selected>&nbsp;</option>';
foreach ($accepted_arr as $card)
$data .= sprintf('<option value="%s"%s>%s</option>',$card,($default_selected == $card) ? ' selected' : '',$C_translate->translate('card_type_'.$card,'checkout'));
$data .= '</select>';
return $data;
}
?>
?>

View File

@@ -1,79 +1,87 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Smarty
*/
function list_menu_files($id, $name, $default, $path, $pre, $ext, $class)
{
global $C_translate;
if($path == 'product_cat') $path = PATH_THEMES . '' . DEF_THEME_N . '/blocks/product_cat/';
elseif($path == 'whois_plugin') $path = PATH_PLUGINS . '/whois/';
elseif($path == 'product') $path = PATH_PLUGINS . '/product/';
elseif($path == 'e911') $path = PATH_PLUGINS . '/e911/';
elseif($path == 'provision_plugin') $path = PATH_PLUGINS . '/provision/';
elseif($path == 'affiliate_plugin') $path = PATH_PLUGINS . '/affiliate/';
elseif($path == 'checkout_plugin') $path = PATH_PLUGINS . '/checkout/';
elseif($path == 'theme') $path = PATH_THEMES;
elseif($path == 'language') $path = PATH_LANGUAGE . '/core/';
$count = 0;
chdir($path);
$dir = opendir($path);
while ($file_name = readdir($dir))
{
$display = true;
if($file_name != '..' && $file_name != '.')
{
if(!empty($ext))
{
$cute = eregi_replace($ext.'$', "", $file_name);
if(!eregi($ext.'$', $file_name)) $display = false;
}
if(!empty($pre))
{
$cute = eregi_replace('^'.$pre, "", $cute);
if(!eregi('^'.$pre, $file_name)) $display = false;
}
if($display)
{
$arr[] = $cute;
$cute = eregi_replace("_"," ",$cute);
$cute = eregi_replace("-"," ",$cute);
$arrc[] = $cute;
$count++;
}
}
/**
* SMARTY template helper - list files
*/
function list_menu_files($id,$name,$default,$path,$pre,$ext,$class) {
global $C_translate;
switch ($path) {
case 'product_cat': $path = sprintf('%s%s/blocks/product_cat/',PATH_THEMES,DEF_THEME_N); break;
case 'whois_plugin': $path = sprintf('%s/whois/',PATH_PLUGINS); break;
case 'product': $path = sprintf('%s/product/',PATH_PLUGINS); break;
case 'e911': $path = sprintf('%s/e911/',PATH_PLUGINS); break;
case 'provision_plugin': $path = sprintf('%s/provision/',PATH_PLUGINS); break;
case 'affiliate_plugin': $path = sprintf('%s/affiliate/',PATH_PLUGINS); break;
case 'checkout_plugin': $path = sprintf('%s/checkout/',PATH_PLUGINS); break;
case 'theme': $path = PATH_THEMES; break;
case 'language': $path = sprintf('%s/core/',PATH_LANGUAGE); break;
}
$return = '<select id="'.$name.'_'. $id.'" name="'. $name .'" value="'.$default.'">';
if($id == "all" || $default == "all")
$return .= '<option value="" selected></option>';
$i = 0;
for($i=0; $i<$count; $i++)
{
$return .= '<option value="' . $arr[$i] . '"';
if($default == $arr[$i])
$return .= "selected";
$return .= '>' . $arrc[$i] . '</option>
';
}
if($count==0)
$return .= '<option value="">'. $C_translate->translate('lists_none_defined','CORE','').'</option>';
$return .= '</select>';
$dir = opendir($path);
while ($file_name = readdir($dir)) {
$display = true;
if (in_array($file_name,array('.','..')))
continue;
if (! empty($ext)) {
$cute = preg_replace("/{$ext}$/",'',$file_name);
if (! preg_match("/{$ext}$/",$file_name))
$display = false;
}
if (! empty($pre)) {
$cute = preg_replace("/^{$pre}/",'',$cute);
if (! preg_match("/^{$pre}/",$file_name))
$display = false;
}
if ($display)
$arr[$cute] = preg_replace('/_/',' ',$cute);
}
asort($arr);
$return = sprintf('<select id="%s_%s" name="%s">',$name,$id,$name);
if ($id == 'all' || $default == 'all')
$return .= '<option value="" selected="selected">&nbsp;</option>';
if (! count($arr))
$return = $C_translate->translate('lists_none_defined');
else {
foreach ($arr as $key => $value)
$return .= sprintf('<option value="%s"%s>%s</option>',$key,($default == $key) ? ' selected="selected"' : '',$value);
$return .= '</select>';
}
echo $return;
}
?>
?>

View File

@@ -1,67 +1,88 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage List
*/
function list_menu_multi($default, $name, $table, $field, $id, $max, $class)
{
/**
* The main AgileBill Menu List Multiple Method
*
* @package AgileBill
* @subpackage List
* @todo $id seems rendundant
*/
function list_menu_multi($default,$name,$table,$field,$id,$max,$class) {
global $C_translate;
if(!isset($default))
$default = Array('');
else if (gettype($default) == 'array')
$default = $default;
else if (gettype($default) == 'string')
if (! isset($default))
$default = array('');
elseif (gettype($default) == 'array') {}
elseif (gettype($default) == 'string')
$default = unserialize($default);
else
$default = Array('');
$default = array('');
$db = &DB();
$sql= "SELECT id, $field FROM ".AGILE_DB_PREFIX."$table WHERE site_id = '" . DEFAULT_SITE . "' ORDER BY $field";
$result = $db->Execute($sql);
if ($result === false)
{
$result = $db->Execute(sqlSelect($db,$table,sprintf('id,%s',$field),'',$field));
if ($result === false) {
global $C_debug;
$C_debug->error('list.inc.php','menu_list', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__, $db->ErrorMsg());
return;
}
if (@$result->RecordCount() > $max && @$result->RecordCount() != 0)
$size = $max;
if ($result->RecordCount() > $max && $result->RecordCount() != 0)
$size = $max;
else
$size = $result->RecordCount();
$return = '<select id="'.$name.'" name="'. $name .'[]" size="' . $size . '" value="'.$default.'" multiple>';
$size = $result->RecordCount();
$return = sprintf('<select id="%s" name="%s[]" size="%s" multiple="multiple">',$name,$name,$size);
$i = 0;
while (!$result->EOF) {
$return .= '<option value="' . $result->fields["id"] . '"';
for($ii=0; $ii<count($default); $ii++)
{
if($default[$ii] == $result->fields["id"])
{
$return .= " selected";
while (! $result->EOF) {
$return .= sprintf('<option value="%s"',$result->fields['id']);
for ($ii=0; $ii<count($default); $ii++) {
if ($default[$ii] == $result->fields['id']) {
$return .= ' selected="selected"';
$ii = count($default);
}
}
$return .= '>' . $result->fields["$field"] . '</option>
';
$i++;
$return .= sprintf('>%s</option>',$result->fields[$field]);
$result->MoveNext();
}
if($i==0)
$return .= '<option value="">'. $C_translate->translate('lists_none_defined','CORE','').'</option>';
$i++;
}
$return .= '</select>';
if ($i==0) {
$return = $C_translate->translate('lists_none_defined');
if ($name)
$return .= sprintf('<input type="hidden" name="%s" value=""/>',$name);
}
echo $return;
}
?>
?>

View File

@@ -73,7 +73,7 @@ function list_select_groups($default, $field_name, $class, $size, $own_account)
####################
### Is auth?
if(!$C_auth->auth_group_by_id($arr[$i]['id']))
$disabled = ' disabled';
$disabled = ' disabled="disabled"';
else
$disabled = '';
@@ -85,8 +85,8 @@ function list_select_groups($default, $field_name, $class, $size, $own_account)
#if($own_account && $checked[$arr[$i]['id']] == true) $disabled = ' disabled';
$ret .= '<input type="checkbox" name="'.$field_name.''.$id.'[]" value="'.$arr[$i]['id'].'"';
if($checked[$arr[$i]['id']] == true) $ret .= ' checked';
$ret .= $disabled . '>&nbsp;&nbsp;'. $arr[$i]['name'] .'<br>';
if($checked[$arr[$i]['id']] == true) $ret .= ' checked="checked"';
$ret .= $disabled . '/>&nbsp;&nbsp;'. $arr[$i]['name'] .'<br/>';
#----------------------
# start the child loop
@@ -106,7 +106,7 @@ function list_select_groups($default, $field_name, $class, $size, $own_account)
################
### Is auth?
if(!$C_auth->auth_group_by_id($arr[$ii]['id']))
$disabled = ' disabled';
$disabled = ' disabled="disabled"';
else
$disabled = '';
#################
@@ -117,8 +117,8 @@ function list_select_groups($default, $field_name, $class, $size, $own_account)
$ret .= '&nbsp;&nbsp;|__';
$ret .= '<input type="checkbox" name="'.$field_name.''.$id.'[]" value="'.$arr[$ii]['id'].'"';
if($checked[$arr[$ii]['id']] == true) $ret .= ' checked';
$ret .= $disabled . '>&nbsp;&nbsp;'. $arr[$ii]['name'] .'<br>';
if($checked[$arr[$ii]['id']] == true) $ret .= ' checked="checked"';
$ret .= $disabled . '/>&nbsp;&nbsp;'. $arr[$ii]['name'] .'<br/>';
$ii_print++;
@@ -134,7 +134,7 @@ function list_select_groups($default, $field_name, $class, $size, $own_account)
################
### Is auth?
if(!$C_auth->auth_group_by_id($arr[$iii]['id']))
$disabled = ' disabled';
$disabled = ' disabled="disabled"';
else
$disabled = '';
#################
@@ -152,8 +152,8 @@ function list_select_groups($default, $field_name, $class, $size, $own_account)
$ret .= '&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|__ ';
}
$ret .= '<input type="checkbox" name="'.$field_name.''.$id.'[]" value="'.$arr[$iii]['id'].'"';
if($checked[$arr[$iii]['id']] == true) $ret .= ' checked';
$ret .= $disabled . '>&nbsp;&nbsp;'. $arr[$iii]['name'] .'<br>';
if($checked[$arr[$iii]['id']] == true) $ret .= ' checked="checked"';
$ret .= $disabled . '/>&nbsp;&nbsp;'. $arr[$iii]['name'] .'<br/>';
$iii_print++;
}
}
@@ -177,4 +177,4 @@ function list_select_groups($default, $field_name, $class, $size, $own_account)
}
return $ret;
}
?>
?>

View File

@@ -1,82 +1,57 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage List
*/
function list_setup_default_date($default, $css)
{
/**
* The main AgileBill List Default Date Method
*
* @package AgileBill
* @subpackage List
*/
function list_setup_default_date($default,$css) {
global $C_translate;
$arr = unserialize($default);
$ret ='';
# loop through the menus
for($i=0; $i<3; $i++)
{
$ret .= '
<select name="setup_date_format[]" id="setdate1">
<option value=""';
if($arr[$i] == '') $ret .= " selected";
$ret .='>-- '.$C_translate->translate('date_option', 'setup','').' --</option>
<option value="d"';
if($arr[$i] == 'd') $ret .= " selected";
$ret .='>'.$C_translate->translate('date_month_day', 'setup','').'</option>
<option value="m"';
if($arr[$i] == 'm') $ret .= " selected";
$ret .='>'.$C_translate->translate('date_month', 'setup','').'</option>
<option value="Y"';
if($arr[$i] == 'Y') $ret .= " selected";
$ret .='>'.$C_translate->translate('date_year_four', 'setup','').'</option>
</select>
';
# loop through the menus
for ($i=0; $i<3; $i++) {
$ret .= sprintf('<select name="setup_date_format[]" id="setdate%s">',$i);
$ret .= sprintf('<option value=""%s>-- %s --</option>',($arr[$i] == '') ? ' selected="selected"' : '',$C_translate->translate('date_option','setup',''));
$ret .= sprintf('<option value="d"%s>%s</option>',($arr[$i] == 'd') ? ' selected="selected"' : '',$C_translate->translate('date_month_day','setup',''));
$ret .= sprintf('<option value="m"%s>%s</option>',($arr[$i] == 'm') ? ' selected="selected"' : '',$C_translate->translate('date_month','setup',''));
$ret .= sprintf('<option value="Y"%s>%s</option>',($arr[$i] == 'Y') ? ' selected="selected"' : '',$C_translate->translate('date_year_four','setup',''));
$ret .= '</select>';
}
$ret .= '<select name="setup_date_format[]" id="setdate4">';
$ret .= sprintf('<option value=" "%s>-- separator --</option>',($arr[$i] == '') ? ' selected="selected"' : '');
$ret .= sprintf('<option value=" "%s> %s [ ] </option>',($arr[$i] == ' ') ? ' selected="selected"' : '',$C_translate->translate('sep_space','setup',''));
$ret .= sprintf('<option value="-"%s> %s [-] </option>',($arr[$i] == '-') ? ' selected="selected"' : '',$C_translate->translate('sep_dash','setup',''));
$ret .= sprintf('<option value="/"%s> %s [/] </option>',($arr[$i] == '/') ? ' selected="selected"' : '',$C_translate->translate('sep_slash','setup',''));
$ret .= sprintf('<option value="."%s> %s [.] </option>',($arr[$i] == '.') ? ' selected="selected"' : '',$C_translate->translate('sep_period','setup',''));
$ret .= '</select>';
$ret .= '
<select name="setup_date_format[]" id="setdate2">
<option value=" "';
if($arr[$i] == '') $ret .= " selected";
$ret .='>-- separator --</option>
<option value=" "';
if($arr[$i] == ' ') $ret .= " selected";
$ret .='>'.$C_translate->translate('sep_space', 'setup','').' [ ]</option>
<option value="-"';
if($arr[$i] == '-') $ret .= " selected";
$ret .='>'.$C_translate->translate('sep_dash', 'setup','').' [-]</option>
<option value="/"';
if($arr[$i] == '/') $ret .= " selected";
$ret .='>'.$C_translate->translate('sep_slash', 'setup','').' [/]</option>
<option value="."';
if($arr[$i] == '.') $ret .= " selected";
$ret .='>'.$C_translate->translate('sep_period', 'setup','').' [.]</option>
</select>
<br>
';
return $ret;
}
?>
?>

View File

@@ -76,7 +76,7 @@ class CORE_login_handler
$C_debug->alert($C_translate->translate('login_un_pw_failed','',''));
# reload the login page
$VAR["_page"] = 'account:login';
$VAR["_page"] = 'account:user_login';
# log as a failed login
$this->lock_check($VAR,"0",$VAR['_username']);
@@ -175,22 +175,6 @@ class CORE_login_handler
# log the successful login
$this->lock_check($VAR,"1",$id);
####################################################################
### Do any db_mapping
####################################################################
$sql = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'module WHERE
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
name = ' . $db->qstr('db_mapping') . ' AND
status = ' . $db->qstr("1");
$result = $db->Execute($sql);
if($result->RecordCount() > 0)
{
include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
$db_map = new db_mapping;
$db_map->login ( $id );
}
}
@@ -201,13 +185,6 @@ class CORE_login_handler
global $C_debug, $C_translate;
$db = &DB();
# get the account id (for DB mapping):
$q = "SELECT account_id FROM ". AGILE_DB_PREFIX ."session WHERE
id = '" . SESS . "' AND
site_id = '" . DEFAULT_SITE . "'";
$result = $db->Execute($q);
$account_id = $result->fields['account_id'];
# logout the current session by editing the database record
$q = "UPDATE ". AGILE_DB_PREFIX ."session SET logged='0'
WHERE id = '" . SESS . "' AND
@@ -223,20 +200,6 @@ class CORE_login_handler
# logout success:
$C_debug->alert($C_translate->translate('logout_success','',''));
####################################################################
### Do any db_mapping
####################################################################
$sql = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'module WHERE
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
name = ' . $db->qstr('db_mapping') . ' AND
status = ' . $db->qstr("1");
$result = $db->Execute($sql);
if($result->RecordCount() > 0) {
include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
$db_map = new db_mapping;
$db_map->logout ( $account_id );
}
}
@@ -244,6 +207,13 @@ class CORE_login_handler
function locked ($account_id)
{
global $C_list;
include_once(PATH_CORE.'list.inc.php');
$C_list = new CORE_list;
if (! $C_list->is_installed('login_lock'))
return false;
if($account_id != '')
$sql = " OR account_id = '$account_id' AND ";
else
@@ -259,6 +229,7 @@ class CORE_login_handler
$result = $db->Execute($q);
$i = 0;
while (!$result->EOF)
{
$i++;
@@ -354,4 +325,4 @@ class CORE_login_handler
}
}
}
?>
?>

View File

@@ -1,193 +1,147 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
class CORE_method
{
function do_all()
{
global $C_auth, $C_sess, $C_debug, $C_translate, $VAR;
if(empty($VAR['do'])) return;
for($i=0; $i < count($VAR['do']); $i++)
{
if(!empty($VAR['do'][$i]))
{
if(preg_match("/:/", $VAR['do'][$i]))
{
$identifier = explode(':',$VAR['do'][$i]);
$module = $identifier[0];
$method = strtolower($identifier[1]);
$C_translate->value['core']['module_name'] = '<b><u>'. $module.":".$method . '</u></b>';
if (
$module != '' &&
$method != '' &&
gettype($module) == 'string' &&
gettype($method) == 'string'
)
{
if($C_auth->auth_method_by_name($module,$method))
{
if (file_exists(PATH_MODULES . '/' . $module . '/' . $module . '.inc.php'))
{
include_once(PATH_MODULES . '/' . $module . '/' . $module . '.inc.php');
if(class_exists($module))
{
$eval = '$' . $module . ' = new ' . $module . '(); ';
$eval .= '$this_Obj = $' . $module . ';';
$eval .= '$this_Obj->' . $method . '($VAR,$this_Obj);';
eval ($eval);
#call_user_func (array($module, "$method"), $VAR, $this_Obj);
}
else
{
$C_debug->alert($C_translate->translate('method_non_existant','core',''));
}
}
else
{
$C_debug->alert($C_translate->translate('module_non_existant','core',''));
/**
* The main AgileBill Method Class
*
* @package AgileBill
* @subpackage Core
*/
class CORE_method {
public function do_all() {
global $C_auth,$C_sess,$C_debug,$C_translate,$VAR;
# If we dont have anything to do, we'll return
if (empty($VAR['do']))
return;
if (! is_array($VAR['do'])) {
$C_debug->alert(sprintf('VAR[do] is NOT an array (%s), how did you get here?',serialize($VAR['do'])));
return;
}
foreach ($VAR['do'] as $value) {
if (preg_match('/:/',$value)) {
list($module,$method) = explode(':',$value,2);
$C_translate->value['core']['module_name'] = sprintf('<b><u>%s:%s</u></b>',$module,$method);
if ($module && $method) {
if ($C_auth->auth_method_by_name($module,$method)) {
if (file_exists($file = sprintf('%s/%s/%s.inc.php',PATH_MODULES,$module,$module))) {
include_once($file);
if (class_exists($module) && method_exists($module,$method)) {
eval (sprintf('$%s = new %s();$%s->%s($VAR,$%s);',$module,$module,$module,$method,$module));
} else {
$C_debug->alert($C_translate->translate('method_non_existant','core',''));
}
} else {
$C_debug->alert($C_translate->translate('module_non_existant','core',''));
}
else
{
$C_debug->alert($C_translate->translate('module_non_auth','core',''));
}
} else {
$C_debug->alert($C_translate->translate('module_non_auth','core',''));
}
else
{
$C_debug->alert($C_translate->translate('method_invalid','core',''));
}
}
else
{
} else {
$C_debug->alert($C_translate->translate('method_invalid','core',''));
}
} else {
$C_debug->alert($C_translate->translate('method_invalid','core',''));
}
}
}
/**
* Execute a modules method
*/
public function exe($module,$method) {
global $C_auth,$C_sess,$C_debug,$C_translate,$VAR;
function exe($module,$method)
{
global $C_auth, $C_sess, $C_debug, $C_translate, $VAR;
$C_translate->value['core']['module_name'] = $module.":".$method;
if (
$module != '' &&
$method != '' &&
gettype($module) == 'string' &&
gettype($method) == 'string'
)
{
if($C_auth->auth_method_by_name($module,$method))
{
if (file_exists(PATH_MODULES . '/' . $module . '/' . $module . '.inc.php'))
{
include_once(PATH_MODULES . '/' . $module . '/' . $module . '.inc.php');
if(class_exists($module))
{
$eval = '$' . $module . ' = new ' . $module . '; ';
$eval .= '$this_Obj = $' . $module . ';';
$eval .= '$this_Obj->' . $method . '($VAR,$this_Obj);';
eval ($eval);
#call_user_func (array($module, "$method"), $VAR, $this_Obj);
global $smarty;
$smarty->assign_by_ref("return", $account);
$this->result = TRUE;
$this->error = FALSE;
}
else
{
$this->result = FALSE;
$this->error = $C_translate->translate('method_non_existant','core','');
return;
}
}
else
{
$this->result = FALSE;
$this->error = $C_translate->translate('module_non_existant','core','');
return;
}
$C_translate->value['core']['module_name'] = sprintf('%s:%s',$module,$method);
if ($module != '' && $method != '' && gettype($module) == 'string' && gettype($method) == 'string') {
if ($C_auth->auth_method_by_name($module,$method)) {
$this->exe_noauth($module,$method);
} else {
$this->result = false;
$this->error = $C_translate->translate('module_non_auth','core','');
}
else
{
$this->result = FALSE;
$this->error = $C_translate->translate('module_non_auth','core','');
return;
}
}
else
{
$this->result = FALSE;
} else {
$this->result = false;
$this->error = $C_translate->translate('method_invalid','core','');
return;
}
}
}
/**
* Execute a modules method
*/
public function exe_noauth($module,$method) {
global $C_auth,$C_sess,$C_debug,$C_translate,$VAR;
$args = null;
function exe_noauth($module,$method)
{
global $C_auth, $C_sess, $C_debug, $C_translate, $VAR;
if (
$module != '' &&
$method != '' &&
gettype($module) == 'string' &&
gettype($method) == 'string'
)
{
if (file_exists(PATH_MODULES . '/' . $module . '/' . $module . '.inc.php'))
{
include_once(PATH_MODULES . '/' . $module . '/' . $module . '.inc.php');
if(class_exists($module))
{
$eval = '$' . $module . ' = new ' . $module . '; ';
$eval .= '$this_Obj = $' . $module . ';';
$eval .= '$this_Obj->' . $method . '($VAR,$this_Obj);';
eval ($eval);
#call_user_func (array($module, "$method"), $VAR, $this_Obj);
global $smarty;
$smarty->assign_by_ref("return", $account);
$this->result = TRUE;
$this->error = FALSE;
}
else
{
$this->result = FALSE;
$this->error = $C_translate->translate('method_non_existant','','');
return;
}
}
else
{
$this->result = FALSE;
$this->error = $C_translate->translate('module_non_existant','','');
return;
if (count(func_get_args())>2) {
$args = func_get_args();
array_shift($args);
array_shift($args);
}
$C_translate->value['core']['module_name'] = sprintf('%s:%s',$module,$method);
if ($module != '' && $method != '' && gettype($module) == 'string' && gettype($method) == 'string') {
if (file_exists($file = sprintf('%s/%s/%s.inc.php',PATH_MODULES,$module,$module))) {
include_once($file);
if (class_exists($module) && method_exists($module,$method)) {
eval (sprintf('$%s = new %s();$%s->%s($VAR,$%s,$args);',$module,$module,$module,$method,$module));
global $smarty;
$smarty->assign_by_ref('return',$account);
$this->result = true;
$this->error = false;
} else {
$this->result = false;
$this->error = $C_translate->translate('method_non_existant','core','');
}
} else {
$this->result = false;
$this->error = $C_translate->translate('module_non_existant','core','');
}
} else {
$this->result = false;
$this->error = $C_translate->translate('method_invalid','core','');
}
else
{
$this->result = FALSE;
$this->error = $C_translate->translate('method_invalid','','');
return;
}
}
}
}
?>
?>

View File

@@ -1,213 +1,182 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
class CORE_search
{
var $recent_js;
var $recent_menu;
var $saved_js;
var $saved_menu;
/**
* The main AgileBill Search Class
*
* @package AgileBill
* @subpackage Core
*/
class CORE_search {
public $recent_js;
public $recent_menu;
public $saved_js;
public $saved_menu;
/**
* Create a new search record.
*
* @return void
* @since Version 1.0
* @param array Contains the elements of the search query
*/
* Create a new search record.
*
* @param array Contains the elements of the search query
* @return void
* @since Version 1.0
*/
public function add($arr) {
$db = &DB();
function add($arr)
{
$db = &DB();
# determine the search id:
$this->id = $db->GenID(AGILE_DB_PREFIX . 'search_id');
# Determine the search id:
$this->id = $db->GenID(AGILE_DB_PREFIX.'search_id');
# safely store the SQL Query:
$sql = $db->qstr($arr['sql']);
# Create the search record
$result = $db->Execute(sqlInsert($db,'search',array(
'session_id'=>SESS,
'account_id'=>SESS_ACCOUNT,
'module'=>$arr['module'],
'date_orig'=>time(),
'date_expire'=>(time()+(SEARCH_EXPIRE*60)),
'full_sql'=>$arr['sql'],
'order_by'=>$arr['order_by'],
'limit_no'=>$arr['limit'],
'results'=>$arr['results']
),$this->id));
# set the time when this record expires
$date_expire = (time() + (SEARCH_EXPIRE*60));
# create the search record
$q = "INSERT INTO " . AGILE_DB_PREFIX . "search SET
id = '" . $this->id . "',
site_id = '" . DEFAULT_SITE . "',
session_id = '" . SESS . "',
account_id = '" . SESS_ACCOUNT . "',
module = '" . $arr['module'] . "',
date_orig = '" . time() . "',
date_expire = '" . $date_expire . "',
full_sql = $sql,
order_by = '" . $arr['order_by'] . "',
limit_no = '" . $arr['limit'] . "',
results = '" . $arr['results'] . "'";
$result = $db->Execute($q);
# error reporting
if ($result === false)
{
# Error reporting
if ($result === false) {
global $C_debug;
$C_debug->error('search.inc.php','add', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
}
/**
* Retrieves a specific search record, and sets the values to the object.
*
* @return void
* @since Version 1.0
* @todo Complete the search refresh feature
* @param int Contians the Search Id to be retrieved
*/
function get($id)
{
# get the details for this search
* Retrieves a specific search record, and sets the values to the object.
*
* @param int Contians the Search Id to be retrieved
* @return void
* @since Version 1.0
* @todo Complete the search refresh feature
*/
public function get($id) {
# Get the details for this search
$db = &DB();
$q = "SELECT *
FROM " . AGILE_DB_PREFIX . "search
WHERE
id = '" . $id . "'
AND
site_id = '" . DEFAULT_SITE . "'";
$result = $db->Execute($q);
# error reporting
if ($result === false)
{
$result = $db->Execute(sqlSelect($db,'search','*',sprintf('id=%s',$id)));
# Error reporting
if ($result === false) {
global $C_debug;
$C_debug->error('search.inc.php','get', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
# get the search values
$this->id = $id;
$this->account = $result->fields['account_id'];
$this->session = $result->fields['session_id'];
$this->date_orig = $result->fields['date_orig'];
$this->date_expire = $result->fields['date_expire'];
$this->sql = $result->fields['full_sql'];
$this->order_by = $result->fields['order_by'];
$this->limit = $result->fields['limit_no'];
# Get the search values
$this->id = $id;
$this->account = $result->fields['account_id'];
$this->session = $result->fields['session_id'];
$this->date_orig = $result->fields['date_orig'];
$this->date_expire = $result->fields['date_expire'];
$this->sql = $result->fields['full_sql'];
$this->order_by = $result->fields['order_by'];
$this->limit = $result->fields['limit_no'];
# check if this search has expired:
if($this->date_expire <= time())
{
# refresh the search
# $this->results = $this->refresh($id);
# Check if this search has expired:
if($this->date_expire <= time()) {
# Refresh the search
# $this->results = $this->refresh($id);
# echo "<BR> this search has expired! Refreshing.... <BR>";
$this->results = $result->fields['results'];
}
else
{
# use the existing result count
$this->results = $result->fields['results'];
$this->results = $result->fields['results'];
} else {
# Use the existing result count
$this->results = $result->fields['results'];
}
return;
}
/**
* Refreshes the result count of a specific search and stores the new results in the search record,
* and returns the new search result count.
*
* @return int Contains the new search results count
* @since Version 1.0
* @todo Complete the search refresh code
* @param int Contians the Search Id to be refreshed
* @return int The new search results count
* Refreshes the result count of a specific search and stores the new results in the search record,
* and returns the new search result count.
*
* @param int Contians the Search Id to be refreshed
* @return int Contains the new search results count
* @since Version 1.0
* @todo Complete the search refresh code
* @return int The new search results count
*/
function refresh($id)
{
private function refresh($id) {
}
/**
* Saves the current search for later retreival.
*
* @return void
* @since Version 1.0
* @todo Add some error checking for previously used nicknames, identical searches, etc.
* @param int Contians the Search Id to be saved
* @param string Contains the name of the Module this search was for
* @param string Contains search nickname to remember this search as
*/
function save($search_id,$module,$name)
{
# save the search
* Saves the current search for later retreival.
*
* @param string Contains search nickname to remember this search as
* @return void
* @since Version 1.0
* @todo Add some error checking for previously used nicknames, identical searches, etc.
* @param int Contians the Search Id to be saved
* @param string Contains the name of the Module this search was for
*/
public function save($search_id,$module,$name) {
# Save the search
$db = &DB();
# determine the search id:
# Determine the search id:
$this->id = $db->GenID('search_saved');
$n = $db->qstr($name);
$result = $db->Execute(sqlInsert($db,'search_saved',array(
'search_id'=>$search_id,
'account_id'=>SESS_ACCOUNT,
'session_id'=>SESS,
'date_orig'=>time(),
'date_last'=>time(),
'date_expire'=>'',
'module'=>$module,
'name'=>$name
),$this->id));
# generate the insert statement
$q = "INSERT INTO " . AGILE_DB_PREFIX . "search_saved SET
id = '$this->id',
site_id = '" . DEFAULT_SITE . "',
search_id = '$search_id',
account_id = '" . SESS_ACCOUNT . "',
session_id = '" . SESS . "',
date_orig = '" . time() . "',
date_last = '" . time() . "',
date_expire = '',
module = '$module',
name = $n";
$result = $db->Execute($q);
# error reporting
if ($result === false)
{
# Error reporting
if ($result === false) {
global $C_debug;
$C_debug->error('search.inc.php','refresh', $db->ErrorMsg());
}
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
}
/**
* Build the recent search menu and JavaScript
*
* @return void
* @since Version 1.0
* @param string Contains the name of the Module to find recent searches for
*/
function build_recent($module)
{
# disable for now
* Build the recent search menu and JavaScript
*
* @param string Contains the name of the Module to find recent searches for
* @return void
* @since Version 1.0
*/
function build_recent($module) {
# Disable for now
return 0;
if(isset($this->arr)) unset ($this->arr);
# get the recent searches
# Get the recent searches
$db = &DB();
$q = "SELECT id, date_orig, date_expire, full_sql, order_by, limit_no
FROM " . AGILE_DB_PREFIX . "search
@@ -223,11 +192,11 @@ class CORE_search
site_id = '" . DEFAULT_SITE . "'";
$result = $db->Execute($q);
# error reporting
# Error reporting
if ($result === false)
{
global $C_debug;
$C_debug->error('search.inc.php','build_recent', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
$results = $result->RecordCount();
@@ -235,21 +204,21 @@ class CORE_search
$i = 0;
while (!$result->EOF) {
# get the fields for this loop
# Get the fields for this loop
$sql = $result->fields['full_sql'];
# remove the WHERE
# Remove the WHERE
$sql = trim($sql);
$sql = eregi_replace("WHERE","",$sql);
$sql = eregi_replace("AND$","",$sql);
$sql = trim($sql);
# replace any sql statements before we split the string
# Replace any sql statements before we split the string
$sql = ereg_replace(" = ","===",$sql);
$sql = ereg_replace(" LIKE ","===",$sql);
# determine the number of fields
# Determine the number of fields
$ii=0;
if(ereg(" AND ", $sql))
@@ -257,16 +226,16 @@ class CORE_search
$sql = explode(" AND ",$sql);
$this_fields = count($sql);
# loop
# Loop
for($count=0; $count < $this_fields; $count++)
{
# do each field
# Do each field
$sqls = explode("==",$sql[$count]);
$field[$count][name] = $sqls[0];
$field[$count][value] = ereg_replace("'","",$sqls[1]);
$field[$count][value] = ereg_replace("=","",$field[$count][value]);
# check that the name & value are both set...
# Check that the name & value are both set...
if($field[$count][value] != '' && $field[$count][name] != '')
{
if(!isset($this->arr[$i][$ii][limit]))
@@ -282,23 +251,23 @@ class CORE_search
# echo "<BR><BR>Field/Name: " . $this->arr[$i][$ii][0] . " -> " . $this->arr[$i][$ii][1];
$ii++;
# set the menu up for Smarty
# Set the menu up for Smarty
$this->recent_menu[$i] = $result->fields;
}
}
}
else
{
# field count
# Field count
$this_fields = 1;
# do this one field
# Do this one field
$sqls = explode("==",$sql);
$field[name] = $sqls[0];
$field[value] = ereg_replace("'","",$sqls[1]);
$field[value] = ereg_replace("=","",$field[value]);
# check that the name & value are both set...
# Check that the name & value are both set...
if($field[value] != '' && $field[name] != '')
{
if(!isset($this->arr[$i][$ii][limit]))
@@ -314,24 +283,24 @@ class CORE_search
# echo "<BR><BR>Field/Name: " . $field[name] . " -> " . $field[value];
$ii++;
# set the menu up for Smarty
# Set the menu up for Smarty
$this->recent_menu[$i] = $result->fields;
}
}
# continue loop
# Continue loop
$result->MoveNext();
if ($ii > 0) $i++;
}
# finish the JS:
# Finish the JS:
if($i > 0 && $ii > 0)
{
# build the JavaScript
# Build the JavaScript
$this->recent_js = '
<script language="JavaScript">
<script language="JavaScript">
// SEARCH FORM CONTROLLER
function fill_search_recent(mod,fields,field_count,limit,order,s,c)
@@ -339,22 +308,22 @@ class CORE_search
document.search.reset();
var id = document.search_recent.search_id.selectedIndex;
if(id == 0) return "";
var idx = document.search_recent.search_id.options[id].value;
var idx = document.search_recent.search_id.options[id].value;
for(loop=0; loop <= c; loop++)
{
if(s[loop] == idx)
if(s[loop] == idx)
{
var i = loop;
}
}
document.search.limit.value = limit[i];
document.search.order_by.value = order[i];
document.search.order_by.value = order[i];
for(loop=0; loop < field_count[i]; loop++)
{
var fill = "document.search." + mod + "_" + fields[i][loop][0] + ".value = fields[i][loop][1];"
eval(fill);
}
}';
}
}';
$this->recent_js .= "
var mod = '$module';
@@ -366,19 +335,19 @@ class CORE_search
var s = new Array($i);
";
# loop through the searches
# Loop through the searches
for ($ix = 0; $ix <= count($this->arr); $ix++)
{
# loop through the fields
# Loop through the fields
for ($iix = 0; $iix <= count($this->arr[$ix]); $iix++)
{
# check that the name/value is set...
# Check that the name/value is set...
if( $this->arr[$ix][$iix][0] != "" && $this->arr[$ix][$iix][1] != "")
{
$count = count($this->arr[$ix]);
# setup the arrays:
# Setup the arrays:
if($iix==0)
{
$this->recent_js .= "
@@ -390,7 +359,7 @@ class CORE_search
";
}
# set the field settings
# Set the field settings
$this->recent_js .=
"
fields[$ix][$iix] = new Array(2);
@@ -401,7 +370,7 @@ class CORE_search
}
}
# finish the js
# Finish the js
$this->recent_js .= "
</script>
";
@@ -410,28 +379,23 @@ class CORE_search
{
$this->recent_js = FALSE;
}
} # end of functino
} # End of functino
/**
* Build the saved search menu and JavaScript
*
* @return void
* @since Version 1.0
* @param string Contains the name of the Module to find saved searches for
*/
function build_saved($module)
{
# disable for now
* Build the saved search menu and JavaScript
*
* @param string Contains the name of the Module to find saved searches for
* @return void
* @since Version 1.0
*/
function build_saved($module) {
# Disable for now
return 0;
if(isset($this->arr)) unset ($this->arr);
# get the saved searches
# get the recent searches
# Get the saved searches
# Get the recent searches
$db1 = &DB();
$q = "SELECT id, search_id, name
FROM " . AGILE_DB_PREFIX . "search_saved
@@ -446,17 +410,17 @@ class CORE_search
ORDER BY name ASC";
$result1 = $db1->Execute($q);
# error reporting
# Error reporting
if ($result1 === false)
{
global $C_debug;
$C_debug->sql_error($db1->ErrorMsg());
}
$i=0;
while (!$result1->EOF)
{
# get the information for this search
$i=0;
while (!$result1->EOF)
{
# Get the information for this search
$db = &DB();
$q = "SELECT id, full_sql, order_by, limit_no
FROM " . AGILE_DB_PREFIX . "search
@@ -466,28 +430,28 @@ class CORE_search
site_id = '" . DEFAULT_SITE . "'";
$result = $db->Execute($q);
# error reporting
# Error reporting
if ($result === false)
{
global $C_debug;
$C_debug->error('search.inc.php','build_saved', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
# get the fields for this loop
# Get the fields for this loop
$sql = $result->fields['full_sql'];
# remove the WHERE
# Remove the WHERE
$sql = trim($sql);
$sql = eregi_replace("WHERE","",$sql);
$sql = eregi_replace("AND$","",$sql);
$sql = trim($sql);
# replace any sql statements before we split the string
# Replace any sql statements before we split the string
$sql = ereg_replace(" = ","===",$sql);
$sql = ereg_replace(" LIKE ","===",$sql);
# determine the number of fields
# Determine the number of fields
$ii=0;
if(ereg(" AND ", $sql))
@@ -495,16 +459,16 @@ class CORE_search
$sql = explode(" AND ",$sql);
$this_fields = count($sql);
# loop
# Loop
for($count=0; $count < $this_fields; $count++)
{
# do each field
# Do each field
$sqls = explode("==",$sql[$count]);
$field[$count][name] = $sqls[0];
$field[$count][value] = ereg_replace("'","",$sqls[1]);
$field[$count][value] = ereg_replace("=","",$field[$count][value]);
# check that the name & value are both set...
# Check that the name & value are both set...
if($field[$count][value] != '' && $field[$count][name] != '')
{
if(!isset($this->arr[$i][$ii][limit]))
@@ -526,16 +490,16 @@ class CORE_search
}
else
{
# field count
# Field count
$this_fields = 1;
# do this one field
# Do this one field
$sqls = explode("==",$sql);
$field[name] = $sqls[0];
$field[value] = ereg_replace("'","",$sqls[1]);
$field[value] = ereg_replace("=","",$field[value]);
# check that the name & value are both set...
# Check that the name & value are both set...
if($field[value] != '' && $field[name] != '')
{
if(!isset($this->arr[$i][$ii][limit]))
@@ -551,25 +515,25 @@ class CORE_search
# echo "<BR><BR>Field/Name: " . $field[name] . " -> " . $field[value];
$ii++;
# set the menu up for Smarty
# Set the menu up for Smarty
$this->saved_menu[$i] = $result->fields;
$this->saved_menu[$i]["name"] = $result1->fields["name"];
}
}
$result1->MoveNext();
if ($ii > 0) $i++;
$result1->MoveNext();
if ($ii > 0) $i++;
}
# finish the JS:
# Finish the JS:
if($i > 0 && $ii > 0)
{
# build the JavaScript
# Build the JavaScript
$this->saved_js = '
<script language="JavaScript">
<script language="JavaScript">
// SEARCH FORM CONTROLLER
function fill_search_saved(s_mod,s_fields,s_field_count,s_limit,s_order,s_s,s_c)
@@ -577,22 +541,22 @@ class CORE_search
document.search.reset();
var id = document.search_saved.search_id.selectedIndex;
if(id == 0) return "";
var idx = document.search_saved.search_id.options[id].value;
var idx = document.search_saved.search_id.options[id].value;
for(loop=0; loop <= s_c; loop++)
{
if(s_s[loop] == idx)
if(s_s[loop] == idx)
{
var i = loop;
var i = loop;
}
}
document.search.limit.value = s_limit[i];
document.search.order_by.value = s_order[i];
document.search.order_by.value = s_order[i];
for(loop=0; loop < s_field_count[i]; loop++)
{
var fill = "document.search." + s_mod + "_" + s_fields[i][loop][0] + ".value = s_fields[i][loop][1];"
eval(fill);
}
}';
}';
$this->saved_js .= "
var s_mod = '$module';
@@ -604,19 +568,19 @@ class CORE_search
var s_s = new Array($i);
";
# loop through the searches
# Loop through the searches
for ($ix = 0; $ix <= count($this->arr); $ix++)
{
# loop through the fields
# Loop through the fields
for ($iix = 0; $iix <= count($this->arr[$ix]); $iix++)
{
# check that the name/value is set...
# Check that the name/value is set...
if( $this->arr[$ix][$iix][0] != "" && $this->arr[$ix][$iix][1] != "")
{
$count = count($this->arr[$ix]);
# setup the arrays:
# Setup the arrays:
if($iix==0)
{
$this->saved_js .= "
@@ -628,7 +592,7 @@ class CORE_search
";
}
# set the field settings
# Set the field settings
$this->saved_js .=
"
s_fields[$ix][$iix] = new Array(2);
@@ -639,7 +603,7 @@ class CORE_search
}
}
# finish the js
# Finish the js
$this->saved_js .= "
</script>
";
@@ -650,4 +614,4 @@ class CORE_search
}
}
}
?>
?>

View File

@@ -255,14 +255,6 @@ class service_group
include_once(PATH_CORE . 'list.inc.php');
$C_list = new CORE_list;
}
if($C_list->is_installed('db_mapping'))
{
# Update the db_mapping accounts
include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
$db_map = new db_mapping;
$db_map->account_group_sync ( $this->rs['account_id'] );
}
}
}
?>
?>

View File

@@ -325,7 +325,6 @@ class CORE_session
theme_id = ".$db->qstr($this->sess_theme_id).",
campaign_id = ".$db->qstr($this->sess_campaign_id);
$result = $db->Execute($q);
$C_debug->sql_count();
if ($result === false) {
$C_debug->error('session.inc.php','validate', $db->ErrorMsg());
echo 'Unable to start session: Db error<RB><BR>' . $q . '<BR><BR>' . $db->ErrorMsg();
@@ -370,7 +369,6 @@ class CORE_session
$db = &DB();
$q = "DELETE FROM " . AGILE_DB_PREFIX . "session WHERE id = '$sess' AND site_id = '" . DEFAULT_SITE . "'";
$result = $db->Execute($q);
$C_debug->sql_count();
if ($result === false) $C_debug->error('session.inc.php','delete', $db->ErrorMsg());
}
@@ -397,7 +395,6 @@ class CORE_session
AND site_id = " . $db->qstr(DEFAULT_SITE);
$result = $db->Execute($q);
global $C_debug;
$C_debug->sql_count();
if ($result === false) $C_debug->error('session.inc.php','session_constant', $db->ErrorMsg());
if(!defined("SESS_LOGGED"))
define ('SESS_LOGGED', $result->fields['logged']);
@@ -416,4 +413,4 @@ class CORE_session
define ('SESS_EXPIRES', 0);
}
}
?>
?>

View File

@@ -1,169 +1,169 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core:Setup
*/
class CORE_setup
{
function CORE_setup()
{
if(defined('MEMCACHE_ENABLED') && MEMCACHE_ENABLED == true) {
require_once (PATH_INCLUDES. 'cache/cache.php');
/**
* The main AgileBill Core Setup Class
*
* @package AgileBill
* @subpackage Core:Setup
*/
class CORE_setup {
public function __construct() {
if (defined('MEMCACHE_ENABLED') && MEMCACHE_ENABLED == true) {
require_once(PATH_INCLUDES.'cache/cache.php');
$key = md5('keyname1'.__FILE__.DEFAULT_SITE);
$sec = 60*30;
$sec = 60*30;
$timeout = get_value($key.'_exp');
if($timeout == "" || $timeout < time() || !$fields = get_value($key) )
{
if ($timeout == '' || $timeout < time() || ! $fields = get_value($key)) {
$fields = $this->get_setup();
store_value($key, $fields);
store_value($key.'_exp', time()+$sec);
}
store_value($key,$fields);
store_value($key.'_exp',time()+$sec);
}
} else {
$fields = $this->get_setup();
}
define ('DEFAULT_COUNTRY', $fields['country_id']);
define ('DEFAULT_LANGUAGE', $fields['language_id']);
define ('DEFAULT_CURRENCY', $fields['currency_id']);
define ('DEFAULT_WEIGHT', $fields['weight_id']);
define ('DEFAULT_THEME', $fields['theme_id']);
define ('DEFAULT_ADMIN_THEME', $fields['admin_theme_id']);
define ('DEFAULT_GROUP', $fields['group_id']);
define ('DEFAULT_AFFILIATE_TEMPLATE', $fields['affiliate_template_id']);
define ('DEFAULT_AFFILIATE', $fields['affiliate_id']);
define ('DEFAULT_RESELLER', $fields['reseller_id']);
define ('DEFAULT_SETUP_EMAIL', $fields['setup_email_id']);
define ('DEFAULT_TIME_FORMAT', $fields['time_format']);
define ('DEFAULT_ACCOUNT_STATUS',$fields['default_account_status']);
define('DEFAULT_COUNTRY', $fields['country_id']);
define('DEFAULT_LANGUAGE', $fields['language_id']);
define('DEFAULT_CURRENCY', $fields['currency_id']);
define('DEFAULT_WEIGHT', $fields['weight_id']);
define('DEFAULT_THEME', $fields['theme_id']);
define('DEFAULT_ADMIN_THEME', $fields['admin_theme_id']);
define('DEFAULT_GROUP', $fields['group_id']);
define('DEFAULT_AFFILIATE_TEMPLATE', $fields['affiliate_template_id']);
define('DEFAULT_AFFILIATE', $fields['affiliate_id']);
define('DEFAULT_RESELLER', $fields['reseller_id']);
define('DEFAULT_SETUP_EMAIL', $fields['setup_email_id']);
define('DEFAULT_TIME_FORMAT', $fields['time_format']);
define('DEFAULT_ACCOUNT_STATUS',$fields['default_account_status']);
$this->default_date_format($fields['date_format']);
if(!defined("DEFAULT_TIME_FORMAT"))
define ('DEFAULT_TIME_FORMAT', $fields['time_format']);
define ('DEFAULT_DATE_TIME_FORMAT', $fields['date_time_format']);
define ('DEFAULT_DECIMAL_PLACE',$fields['decimal_place']);
define ('COOKIE_NAME', $fields['cookie_name']);
define ('COOKIE_EXPIRE', $fields['cookie_expire']);
define ('SESSION_IP_MATCH', $fields['session_ip_match']);
define ('SESSION_EXPIRE', $fields['login_expire']);
define ('NEWSLETTER_REGISTRATION',$fields['newsletter_registration']);
define ('SEARCH_EXPIRE', $fields['search_expire']);
define ('ERROR_REPORTING', $fields['error_reporting']);
define ('DEBUG', $fields['debug']);
if (! defined('DEFAULT_TIME_FORMAT'))
define('DEFAULT_TIME_FORMAT',$fields['time_format']);
define('DEFAULT_DATE_TIME_FORMAT',$fields['date_time_format']);
define('DEFAULT_DECIMAL_PLACE',$fields['decimal_place']);
define('COOKIE_NAME', $fields['cookie_name']);
define('COOKIE_EXPIRE', $fields['cookie_expire']);
define('SESSION_IP_MATCH', $fields['session_ip_match']);
define('SESSION_EXPIRE', $fields['login_expire']);
define('NEWSLETTER_REGISTRATION',$fields['newsletter_registration']);
define('SEARCH_EXPIRE', $fields['search_expire']);
define('ERROR_REPORTING', $fields['error_reporting']);
define('DEBUG', $fields['debug']);
define ('LOGIN_ATTEMPT_TRY', $fields['login_attempt_try']);
define ('LOGIN_ATTEMPT_TIME', $fields['login_attempt_time']);
define ('LOGIN_ATTEMPT_LOCK', $fields['login_attempt_lock']);
define ('DB_CACHE', $fields['db_cache']);
define ('CACHE_SESSIONS', $fields['cache_sessions']);
define ('WEBLOG', $fields['weblog']);
define ('LICENSE_KEY', $fields['license_key']);
define ('LICENSE_CODE', $fields['license_code']);
define('LOGIN_ATTEMPT_TRY', $fields['login_attempt_try']);
define('LOGIN_ATTEMPT_TIME', $fields['login_attempt_time']);
define('LOGIN_ATTEMPT_LOCK', $fields['login_attempt_lock']);
define('DB_CACHE', $fields['db_cache']);
define('CACHE_SESSIONS', $fields['cache_sessions']);
define('WEBLOG', $fields['weblog']);
if(!defined('SSL_URL')) define ('SSL_URL', $fields['ssl_url']);
if(!defined('URL')) define ('URL', $fields['nonssl_url']);
if(!defined('SITE_NAME')) define ('SITE_NAME', $fields['site_name']);
if(!defined('SITE_EMAIL')) define ('SITE_EMAIL', $fields['site_email']);
if(!defined('SITE_ADDRESS'))define ('SITE_ADDRESS',$fields['site_address']);
if(!defined('SITE_CITY')) define ('SITE_CITY', $fields['site_city']);
if(!defined('SITE_STATE')) define ('SITE_STATE', $fields['site_state']);
if(!defined('SITE_ZIP')) define ('SITE_ZIP', $fields['site_zip']);
if(!defined('SITE_PHONE')) define ('SITE_PHONE', $fields['site_phone']);
if(!defined('SITE_FAX')) define ('SITE_FAX', $fields['site_fax']);
if (! defined('SSL_URL')) define('SSL_URL', $fields['ssl_url']);
if (! defined('URL')) define('URL', $fields['nonssl_url']);
if (! defined('SITE_NAME')) define('SITE_NAME', $fields['site_name']);
if (! defined('SITE_EMAIL')) define('SITE_EMAIL', $fields['site_email']);
if (! defined('SITE_ADDRESS')) define('SITE_ADDRESS', $fields['site_address']);
if (! defined('SITE_CITY')) define('SITE_CITY', $fields['site_city']);
if (! defined('SITE_STATE')) define('SITE_STATE', $fields['site_state']);
if (! defined('SITE_ZIP')) define('SITE_ZIP', $fields['site_zip']);
if (! defined('SITE_PHONE')) define('SITE_PHONE', $fields['site_phone']);
if (! defined('SITE_FAX')) define('SITE_FAX', $fields['site_fax']);
if($fields['os'] == 1)
define ('AGILE_OS', 'WINDOWS');
if ($fields['os'] == 1)
define('AGILE_OS', 'WINDOWS');
else
define ('AGILE_OS', 'LINUX');
define('AGILE_OS', 'LINUX');
define ('PATH_CURL', $fields['path_curl']);
define ('SHOW_AFFILIATE_LINK', $fields['show_affiliate_link']);
define ('AUTO_AFFILIATE', @$fields['auto_affiliate']);
define ('SHOW_TICKET_LINK', $fields['show_ticket_link']);
define ('SHOW_NEWSLETTER_LINK', $fields['show_newsletter_link']);
define ('SHOW_CONTACT_LINK', $fields['show_contact_link']);
define ('SHOW_DOMAIN_LINK', $fields['show_domain_link']);
define ('SHOW_CART_LINK', $fields['show_cart_link']);
define ('SHOW_CHECKOUT_LINK', $fields['show_checkout_link']);
define ('SHOW_PRODUCT_LINK', $fields['show_product_link']);
define ('SHOW_CAT_BLOCK', $fields['show_cat_block']);
define ('SHOW_FILE_BLOCK', $fields['show_file_block']);
define ('SHOW_STATIC_BLOCK', $fields['show_static_block']);
define ('SHOW_AFFILIATE_CODE', $fields['show_affiliate_code']);
define ('SHOW_DISCOUNT_CODE', $fields['show_discount_code']);
define ('BILLING_WEEKDAY', $fields['billing_weekday']);
define ('GRACE_PERIOD', $fields['grace_period']);
define ('MAX_BILLING_NOTICE', $fields['max_billing_notice']);
define ('MAX_INV_GEN_PERIOD', $fields['max_inv_gen_period']);
define('PATH_CURL', $fields['path_curl']);
define('SHOW_AFFILIATE_LINK', $fields['show_affiliate_link']);
define('AUTO_AFFILIATE', @$fields['auto_affiliate']);
define('SHOW_NEWSLETTER_LINK', $fields['show_newsletter_link']);
define('SHOW_CONTACT_LINK', $fields['show_contact_link']);
define('SHOW_DOMAIN_LINK', $fields['show_domain_link']);
define('SHOW_CART_LINK', $fields['show_cart_link']);
define('SHOW_CHECKOUT_LINK', $fields['show_checkout_link']);
define('SHOW_PRODUCT_LINK', $fields['show_product_link']);
define('SHOW_CAT_BLOCK', $fields['show_cat_block']);
define('SHOW_STATIC_BLOCK', $fields['show_static_block']);
define('SHOW_AFFILIATE_CODE', $fields['show_affiliate_code']);
define('SHOW_DISCOUNT_CODE', $fields['show_discount_code']);
define('BILLING_WEEKDAY', $fields['billing_weekday']);
define('GRACE_PERIOD', $fields['grace_period']);
define('MAX_BILLING_NOTICE', $fields['max_billing_notice']);
$error_reporting_eval = 'error_reporting('.ERROR_REPORTING.');';
eval($error_reporting_eval);
error_reporting(ERROR_REPORTING);
}
function get_setup()
{
private function get_setup() {
$db = &DB();
$q = "SELECT * FROM " . AGILE_DB_PREFIX . "setup WHERE site_id = ". DEFAULT_SITE;
$result = $db->Execute($q);
if ($result === false || @$result->RecordCount() == 0) {
if(is_file('install/install.inc'))
$result = $db->Execute(sqlSelect($db,'setup','*',''));
if (! $result || $result->RecordCount() == 0) {
if (is_file('install/install.inc'))
require_once('install/install.inc');
else
$this->handle_failure($db);
exit;
} else {
return $result->fields;
}
}
}
function default_date_format($default)
{
private function default_date_format($default) {
$default = unserialize($default);
$format = '';
$divider = $default[3];
for($i=0; $i<3; $i++)
{
for ($i=0; $i<3; $i++) {
$format .= $default[$i];
if($i != 2)
$format .= $divider;
if ($i != 2)
$format .= $divider;
}
$arr = Array('a','A','b','B','d','j','m','u','y','Y');
for($i=0; $i<count($arr); $i++)
$format = ereg_replace($arr[$i],'%'.$arr[$i],$format);
define ('DEFAULT_DATE_FORMAT', $format);
$UNIX_DATE_FORMAT = ereg_replace('%','', DEFAULT_DATE_FORMAT);
define ('UNIX_DATE_FORMAT', $UNIX_DATE_FORMAT);
define ('DEFAULT_DATE_DIVIDER', $divider);
for ($i=0; $i<count($arr); $i++)
$format = str_replace($arr[$i],'%'.$arr[$i],$format);
define('DEFAULT_DATE_FORMAT',$format);
$UNIX_DATE_FORMAT = str_replace('%','',DEFAULT_DATE_FORMAT);
define('UNIX_DATE_FORMAT',$UNIX_DATE_FORMAT);
define('DEFAULT_DATE_DIVIDER',$divider);
}
/**
* Handle a database connection failure gracefully
*/
function handle_failure(&$db) {
private function handle_failure(&$db) {
# echo error page
include_once(PATH_THEMES.'default/blocks/core/error.tpl');
// echo error page
include_once(PATH_THEMES . 'default/blocks/core/error.tpl');
# log the error
if ($f=fopen(PATH_FILES.'sql_error.txt','a'))
fputs($f,sprintf("%s\t%s\r\n",date('d-m-Y H:i:s a'),$db->_errorMsg));
// log the error
if($f=fopen(PATH_FILES.'sql_error.txt', 'a')) {
$data = date("m-d-Y H:i:s a") . " " . $db->_errorMsg . "\r\n";
fputs($f,$data);
}
exit;
exit;
}
}
?>
?>

View File

@@ -1,4 +1,4 @@
<?
<?php
/* EXAMPLE:
@@ -86,4 +86,4 @@ Class arr_multisort{
return $ret;
}
}
?>
?>

View File

@@ -166,12 +166,12 @@ class CORE_static_var
{
### SMALL TEXT FIELD
$this_html = '<input type="text" size="8" name="'.$static_relation.
'" value="'.$static_value.'">';
'" value="'.$static_value.'"/>';
}
elseif($display == 'search')
{
$this_html = '<input type="text" size="8" name="'.$static_relation.
'" value="'.$static_value.'">' .
'" value="'.$static_value.'"/>' .
$C_translate->translate('search_partial', 'CORE', SESS_LANGUAGE);
}
else
@@ -187,12 +187,12 @@ class CORE_static_var
{
### MEDIUM TEXT FIELD
$this_html = '<input type="text" size="32" name="'.$static_relation.
'" value="'.$static_value.'">';
'" value="'.$static_value.'"/>';
}
elseif($display == 'search')
{
$this_html = '<input type="text" size="32" name="'.$static_relation.
'" value="'.$static_value.'">' .
'" value="'.$static_value.'"/>' .
$C_translate->translate('search_partial', 'CORE', SESS_LANGUAGE);
}
else
@@ -213,7 +213,7 @@ class CORE_static_var
elseif($display == 'search')
{
$this_html = '<input type="text" size="32" name="'.$static_relation.
'" value="'.$static_value.'">' .
'" value="'.$static_value.'"/>' .
$C_translate->translate('search_partial', 'CORE', SESS_LANGUAGE);
}
else
@@ -289,7 +289,7 @@ class CORE_static_var
$id = rand(9,999);
$this_html = '
<input type="text" id="data_'.$field.'_'.$id.'" name="'.$static_relation.'"/>&nbsp;
<input type="button" id="trigger_'.$field.'_'.$id.'" value="+">
<input type="button" id="trigger_'.$field.'_'.$id.'" value="+"/>
<script type="text/javascript">
Calendar.setup(
{
@@ -350,9 +350,9 @@ class CORE_static_var
{
### CHECKBOX
if($static_value == '1')
$this_html = '<input type="checkbox" name="'.$static_relation.'" value="1" checked>';
$this_html = '<input type="checkbox" name="'.$static_relation.'" value="1" checked />';
else
$this_html = '<input type="checkbox" name="'.$static_relation.'" value="1">';
$this_html = '<input type="checkbox" name="'.$static_relation.'" value="1" />';
}
elseif($display == 'search')
{
@@ -369,7 +369,7 @@ class CORE_static_var
else if ($format == 'hidden')
{
### HIDDEN FIELD
$this_html = '<input type="hidden" name="'.$static_relation.'" value="'.$static_value.'">';
$this_html = '<input type="hidden" name="'.$static_relation.'" value="'.$static_value.'"/>';
}
@@ -1445,4 +1445,4 @@ class CORE_static_var
}
}
}
?>
?>

View File

@@ -1,180 +1,204 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
class CORE_theme
{
var $id;
function CORE_theme()
{
global $VAR, $C_debug, $C_translate, $smarty;
/**
* The main AgileBill CORE Theme Class
*
* @package AgileBill
* @subpackage Core
* @uses CORE_block
*/
class CORE_theme {
public $id;
function __construct() {
global $VAR,$C_debug,$C_translate,$smarty;
# Get the cuurent session theme:
if(defined("SESS_THEME") && file_exists(PATH_THEMES . '' . SESS_THEME . '/template.tpl'))
{
if(SESS_THEME == 'default_admin' && SESS_LOGGED != true )
define ('THEME_NAME', DEF_THEME_N);
elseif (defined("ADMIN_FORCE"))
define ('THEME_NAME', 'default_admin');
elseif (!defined("ADMIN_FORCE") && SESS_THEME != 'default_admin')
define ('THEME_NAME', SESS_THEME);
if(defined('SESS_THEME') && file_exists(PATH_THEMES.SESS_THEME.'/template.tpl')) {
if (SESS_THEME == 'default_admin' && SESS_LOGGED != true )
define ('THEME_NAME',DEF_THEME_N);
elseif (defined('ADMIN_FORCE'))
define ('THEME_NAME','default_admin');
elseif (! defined('ADMIN_FORCE') && SESS_THEME != 'default_admin')
define ('THEME_NAME',SESS_THEME);
else
define ('THEME_NAME', DEF_THEME_N);
define ('THEME_NAME',DEF_THEME_N);
} elseif(file_exists(PATH_THEMES.DEFAULT_THEME.'/template.tpl')) {
define ('THEME_NAME',DEFAULT_THEME);
} else {
define ('THEME_NAME',DEF_THEME_N);
}
elseif(file_exists(PATH_THEMES.DEFAULT_THEME.'/template.tpl'))
{
define ('THEME_NAME', DEFAULT_THEME);
}
else
{
define ('THEME_NAME', DEF_THEME_N);
}
# load the block class
$block = new CORE_block;
# set smarty vars
if(isset($smarty->template_dir)) unset($smarty->template_dir);
$smarty->use_sub_dirs = false;
$smarty->template_dir = PATH_THEMES . '' . THEME_NAME . '/';
$smarty->compile_dir = PATH_SMARTY . 'templates/';
$smarty->config_dir = PATH_SMARTY . 'configs/';
$smarty->cache_dir = PATH_SMARTY . 'cache/';
$this->caching = false;
$this->compile_check = true;
$smarty->assign("THEME_NAME", THEME_NAME);
# Set smarty vars
if (isset($smarty->template_dir))
unset($smarty->template_dir);
# Frame Theme Escape
if(THEME_NAME == 'default_admin')
{
if (!empty($VAR['tid']) && empty($VAR['_escape']))
{
// get url string to pass to mainFrame
$url='';
$i=0;
while(list($key,$val) = each($VAR)) {
if($key != 'tid')
{
if($i==0) $url .= '?'; else $url .= '&';
$url .= $key.'='.$val;
$smarty->use_sub_dirs = false;
$smarty->template_dir = PATH_THEMES.THEME_NAME.'/';
$smarty->compile_dir = PATH_SMARTY.'templates/';
$smarty->config_dir = PATH_SMARTY.'configs/';
$smarty->cache_dir = PATH_SMARTY.'cache/';
$this->caching = false;
$this->compile_check = true;
$smarty->assign('THEME_NAME',THEME_NAME);
# Frame Theme Escape
if (THEME_NAME == 'default_admin') {
if (! empty($VAR['tid']) && empty($VAR['_escape'])) {
# Get URL string to pass to mainFrame
$url = '';
$i = 0;
while (list($key,$val) = each($VAR)) {
if ($key != 'tid') {
if ($i==0)
$url .= '?';
else
$url .= '&';
$url .= sprintf('%s=%s',$key,$val);
$i++;
}
}
$url = preg_replace('/tid=default_admin/', '', $url);
$smarty->assign('mainFrameUrl', $url);
$this_template = 'file:'.PATH_THEMES.''.THEME_NAME.'/template.tpl';
$url = preg_replace('/tid=default_admin/','',$url);
$smarty->assign('mainFrameUrl',$url);
$this_template = sprintf('file:%s%s/template.tpl',PATH_THEMES,THEME_NAME);
$smarty->display($this_template);
exit;
}
if (empty($VAR['_escape']))
$block->display('core:top_frame');
# force or define page set?
if(defined("FORCE_PAGE")) {
$block->display(FORCE_PAGE);
exit();
} elseif (@$VAR['_page']) {
$block->display($VAR['_page']);
exit();
} else {
$block->display('core:admin');
exit;
}
if (empty($VAR['_escape']))
$block->display('core:top_frame');
# Force or define page set?
if (defined('FORCE_PAGE')) {
$block->display(FORCE_PAGE);
} elseif (@$VAR['_page']) {
$block->display($VAR['_page']);
} else {
$block->display('core:admin');
}
if (empty($VAR['_escape']))
$block->display('core:bottom_frame');
exit();
}
# Standard themes
if(isset($VAR['_escape']))
{
if(isset($VAR['_print']))
{
# load printer friendly version
if (isset($VAR['_escape'])) {
if (isset($VAR['_print'])) {
# Load printer friendly version
$block->display('core:top_frame');
$block->display($VAR['_page']);
$block->display('core:bottom_print');
exit();
}
else
{
# check for force page:
if(defined("FORCE_PAGE"))
$block->display(FORCE_PAGE);
} else {
# Check for force page:
if(defined('FORCE_PAGE'))
$block->display(FORCE_PAGE);
else
$block->display($VAR['_page']);
$block->display($VAR['_page']);
exit();
}
}
else
{
if(defined("FORCE_PAGE")) {
define('THEME_PAGE', FORCE_PAGE);
} else {
if (defined('FORCE_PAGE')) {
define('THEME_PAGE',FORCE_PAGE);
} else {
if(isset($VAR['_page']))
define('THEME_PAGE', $VAR['_page']);
if (isset($VAR['_page']))
define('THEME_PAGE',$VAR['_page']);
else
define('THEME_PAGE', 'core:main');
define('THEME_PAGE','core:main');
}
# load the block normally
$this_template = 'file:' . PATH_THEMES . '' . THEME_NAME . '/template.tpl';
# Load the block normally
$this_template = sprintf('file:%s%s/template.tpl',PATH_THEMES,THEME_NAME);
$smarty->display($this_template);
}
}
}
class CORE_block {
public function display($block_r) {
global $smarty;
$savedir = '';
# If we are in a module, we need to preserve our template path
if (isset($smarty->_tpl_vars['meth'][0]) && $smarty->_tpl_vars['meth'][0] != 'core')
$savedir = $smarty->template_dir;
class CORE_block
{
function display($block_r)
{
global $smarty;
@$resource = explode(':',$block_r);
@$module = $resource[0];
@$block = $resource[1];
if($module == 'TEMPLATE')
{
$smarty->template_dir = PATH_THEMES . '' . THEME_NAME . '/';
$smarty->display('file:' . $smarty->template_dir . '' . $block . '.tpl');
@$block = $resource[1];
$displayBlock = false;
if ($module == 'TEMPLATE') {
$smarty->template_dir = PATH_THEMES.THEME_NAME.'/';
$displayBlock = true;
} else {
if(is_file(PATH_THEMES . '' . THEME_NAME . '/blocks/' . $module . '/' . $block . '.tpl'))
{
$smarty->template_dir = PATH_THEMES . '' . THEME_NAME . '/blocks/' . $module . '/';
$smarty->display('file:' . $smarty->template_dir . '' . $block . '.tpl');
}
elseif (is_file(PATH_THEMES . '' . DEF_THEME_N . '/blocks/' . $module . '/' . $block . '.tpl'))
{
$smarty->template_dir = PATH_THEMES . '' . DEF_THEME_N . '/blocks/' . $module . '/';
$smarty->display('file:' . $smarty->template_dir . '' . $block . '.tpl');
}
elseif (is_file(PATH_THEMES . 'default/blocks/' . $module . '/' . $block . '.tpl'))
{
$smarty->template_dir = PATH_THEMES . 'default/blocks/' . $module . '/';
$smarty->display('file:' . $smarty->template_dir . '' . $block . '.tpl');
}
else
{
$smarty->display('file:'. PATH_THEMES . '' . DEF_THEME_N . '/blocks/core/invalid_page.tpl');
}
}
if (is_file(sprintf('%s%s/blocks/%s/%s.tpl',PATH_THEMES,THEME_NAME,$module,$block))) {
$smarty->template_dir = sprintf('%s%s/blocks/%s/',PATH_THEMES,THEME_NAME,$module);
$displayBlock = true;
} elseif (is_file(sprintf('%s%s/blocks/%s/%s.tpl',PATH_THEMES,DEF_THEME_N,$module,$block))) {
$smarty->template_dir = sprintf('%s%s/blocks/%s/',PATH_THEMES,DEF_THEME_N,$module);
$displayBlock = true;
} elseif (is_file(sprintf('%s%s/blocks/%s/%s.tpl',PATH_THEMES,'default',$module,$block))) {
$smarty->template_dir = sprintf('%s%s/blocks/%s/',PATH_THEMES,'default',$module);
$displayBlock = true;
} else {
$smarty->display(sprintf('file:%s%s/blocks/core/invalid_page.tpl',PATH_THEMES,DEF_THEME_N));
}
}
if ($displayBlock) {
if (! isset($smarty->_tpl_vars['VAR']['_page']) || ! $smarty->_tpl_vars['VAR']['_page'])
$smarty->_tpl_vars['VAR']['_page'] = $block_r;
$smarty->display(sprintf('file:%s%s.tpl',$smarty->template_dir,$block));
}
if ($savedir)
$smarty->template_dir = $savedir;
}
}
?>
?>

View File

@@ -1,25 +1,41 @@
<?php
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Translation
*/
class CORE_translate
{
/**
* The main AgileBill Translation Class
*
* Translation is controlled by:
* - Templates: Template fields are translated using the {t} macro. This is normal gettext translation
* - Templates - Table Fields: Table fields are translated using {osb f=tt|ft} macro. This uses the <display><description> in the _construct.xml
* - Templates - Page Titles: Table page titles translated using ??? macro. This uses the <title> in the _construct.xml
* - Menu: Fields are translated using the <display> in the _install.xml
* - General: - Gettext translation using _().
*
* @package AgileBill
* @subpackage Translation
*/
class CORE_translate {
function CORE_translate() {
if(defined("SESS_LANGUAGE"))
$language = SESS_LANGUAGE;
@@ -55,12 +71,51 @@ class CORE_translate
}
}
function translate_resource($module, $resource, $language) {
if(!empty($this->value["$module"])) $array = $this->value["$module"];
@$string = $this->lang_pack["$module"]["$language"]["translate"]["$resource"];
if(!empty($array) && is_array($array) && !empty($string))
while(list ($key, $val) = each ($array))
$string = str_replace("%%{$key}%%", $val, $string);
function translate_resource($module, $resource, $language,$type=null) {
if (! empty($this->value[$module]))
$array = $this->value[$module];
@$string = $this->lang_pack[$module][$language]['translate'][$resource];
if (! empty($array) && is_array($array) && ! empty($string))
while (list($key,$val) = each($array))
$string = str_replace("%%{$key}%%",$val,$string);
# Translate menu items
# @todo CACHE this work.
switch ($type) {
case 'menutitle':
$f = sprintf('%s%s/%s_install.xml',PATH_MODULES,$module,$module);
if (is_file($f)) {
# open the XML backup file:
$C_xml = new CORE_xml;
$module_data = $C_xml->xml_to_array($f);
if (isset($module_data['install']['module_properties']['display']))
$string = $module_data['install']['module_properties']['display'];
else
$string = $module;
}
break;
case 'methodtitle':
$f = sprintf('%s%s/%s_install.xml',PATH_MODULES,$module,$module);
if (is_file($f)) {
# open the XML backup file:
$C_xml = new CORE_xml;
$module_data = $C_xml->xml_to_array($f);
if (isset($module_data['install']['module_method'][$resource]['display']))
$string = $module_data['install']['module_method'][$resource]['display'];
else
$string = $resource;
}
break;
}
return $string;
}
@@ -68,7 +123,7 @@ class CORE_translate
$this->value["$module"]["$variable"] = $value;
}
function translate($resource, $module='CORE', $language=SESS_LANGUAGE) {
function translate($resource, $module='CORE', $language=SESS_LANGUAGE,$type=null) {
# determine the language
if(empty($language)) {
if(defined("SESS_LANGUAGE"))
@@ -82,15 +137,173 @@ class CORE_translate
if(!empty($resource)) {
# checks if this is the core
if($module == 'CORE')
return $this->translate_resource('CORE', $resource, $language);
return $this->translate_resource('CORE', $resource, $language,$type);
# load the language pack for the current module if needed:
if(!isset($this->lang_pack["$module"]["$language"]))
$this->get_lang_pack($module,$language);
# translate/return the current resource
return $this->translate_resource($module, $resource, $language);
return $this->translate_resource($module, $resource, $language,$type);
}
}
private function get_module($module) {
if (! file_exists($module_file=sprintf('%s/%s/%s.inc.php',PATH_MODULES,$module,$module))) {
printf('Module DOESNT EXIST (%s):%s',$module,__METHOD__);
return;
}
include_once($module_file);
if (! class_exists($module))
return false;
else
return new $module;
}
/**
* Translate a table title
*/
public function tt($params,$smarty) {
if (! is_array($smarty->_tpl_vars['meth']))
if (! isset($params['module']) || ! isset($params['method'])) {
printf('MISSING module OR method: %s',__METHOD__);
return;
}
$module = isset($params['module']) ? $params['module'] : $smarty->_tpl_vars['meth'][0];
$method = isset($params['method']) ? $params['method'] : $smarty->_tpl_vars['meth'][1];
if (! $mm=$this->get_module($module))
$module = 'core';
if (! isset($mm->title[$method]) || ! trim($mm->title[$method])) {
printf('%s:%s',$module,$method);
return;
}
# See if there is a module specific translation
if (($module != 'core') && $mm->title[$method] != dgettext($module,$mm->title[$method]))
return dgettext($module,$mm->title[$method]);
else
return _($mm->title[$method]);
}
/**
* Translate a table field
*/
public function tf($params,$smarty) {
if ((! is_array($smarty->_tpl_vars['meth']) || ! isset($params['module'])) && ! isset($params['field'])) {
printf('MISSING module OR field: %s',__METHOD__);
return;
}
$module = isset($params['module']) ? $params['module'] : $smarty->_tpl_vars['meth'][0];
$field = $params['field'];
$display = $params['field'];
$description = '';
$mm = '';
if (! $mm=$this->get_module($module))
$module = 'core';
# See if there is a module specific information on the attribute
else {
$display = (isset($mm->field[$field]['display'])) ? $mm->field[$field]['display'] : sprintf('%s:%s',$module,$field);
$description = (isset($mm->field[$field]['description'])) ? $mm->field[$field]['description'] : '';
}
# Translate
if ($description) {
if ($description != dgettext($module,$description))
$description = dgettext($module,$description);
else
$description = _($description);
}
if ($display != dgettext($module,$display))
$display = dgettext($module,$display);
else
$display = _($display);
if ($description)
return sprintf('<a href="#" onmouseover="return overlib(\'%s\');" onmouseout="nd()">%s</a>',$description,$display);
else
return $display;
}
}
?>
/**
* If gettext is not available in PHP, then this will provide compatibility for it.
*/
if (! function_exists('_')) {
function _($msg) {
return $msg;
}
}
/**
* This function will convert the browser two character language into the
* default 5 character language, where the country portion should NOT be
* assumed to be upper case characters of the first two characters.
*/
function auto_lang($lang) {
switch ($lang) {
case 'ja': return 'ja_JP';
case 'cs': return 'cs_CZ';
default: return sprintf('%s_%s',$lang,strtoupper($lang));
}
}
$lang = array();
if (DEF_LANGUAGE == 'auto') {
# Make sure their browser correctly reports language. If not, skip this.
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
# Get the languages which are spetcified in the HTTP header
$lang['lang_http'] = preg_split('/[;,]+/',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($lang['lang_http'] as $key => $value) {
if (substr($value,0,2) == 'q=') {
unset($lang['lang_http'][$key]);
continue;
}
$value = preg_split('/[-]+/',$value);
if (sizeof($value) == 2)
$lang['lang_http'][$key] = strtolower($value[0]).'_'.strtoupper($value[1]);
else
$lang['lang_http'][$key] = auto_lang(strtolower($value[0]));
}
$lang['lang_http'] = array_unique($lang['lang_http']);
foreach ($lang['lang_http'] as $l) {
$lang['language_dir'] = PATH_LANGUAGE.$l;
$lang['language'] = $l;
if ((substr($l,0,2) == 'en') ||
(file_exists($lang['language_dir']) && is_readable($lang['language_dir'])))
break;
}
#todo Generate an error if language doesnt exist.
}
} else {
# Grab the language file configured in config.php
#todo Generate an error if language doesnt exist.
if (DEF_LANGUAGE)
$lang['language'] = DEF_LANGUAGE;
}
# Set language
if (isset($lang['language'])) {
$lang['language'] .= '.UTF-8';
setlocale(LC_ALL,$lang['language']); # set LC_ALL to de_DE
bindtextdomain('core',PATH_LANGUAGE);
bind_textdomain_codeset('core','UTF-8');
textdomain('core');
}
header('Content-type: text/html; charset=UTF-8',true);
?>

View File

@@ -1,58 +1,57 @@
<?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
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* 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
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Core
*/
class CORE_trigger
{
function trigger($trigger, $type, $VAR)
{
if($type)
{
# do success trigger(s)
if(isset($trigger["success"]))
$this->run_triggers($trigger["success"]);
}
else
{
# do failure trigger(s)
if(isset($trigger["failure"]))
$this->run_triggers($trigger["failure"]);
}
}
# run the trigger(s):
function run_triggers($trigger)
{
global $C_method;
$triggers = explode(',', $trigger);
for($i=0; $i<count($triggers); $i++)
{
if(isset($triggers[$i]))
{
$triggerss = explode(':',$triggers[$i]);
# added to remove php error: Undefined offset
if(isset($triggerss) && count($triggerss) > 1)
{
$C_method->exe($triggerss[0], $triggerss[1]);
}
}
}
}
/**
* The main AgileBill CORE Trigger Class
*
* @package AgileBill
* @subpackage Core
*/
class CORE_trigger {
public function trigger($trigger,$type,$VAR) {
if ($type) {
# Do success trigger(s)
if (isset($trigger['success']))
$this->run_triggers($trigger['success']);
} else {
# Do failure trigger(s)
if (isset($trigger['failure']))
$this->run_triggers($trigger['failure']);
}
}
# Run the trigger(s):
private function run_triggers($trigger) {
global $C_method;
foreach (explode(',',$trigger) as $details) {
$tss = explode(':',$details);
if (count($tss)==2)
$C_method->exe($tss[0],$tss[1]);
}
}
}
?>
?>

File diff suppressed because it is too large Load Diff

View File

@@ -46,14 +46,10 @@ else
# get installed optional modules:
$modules = Array ('affiliate' => Array ('affiliate', 'campaign', 'affiliate_commission', 'affiliate_template'),
'charge' => Array ('charge'),
'db_mapping' => Array ('db_mapping'),
'email_queue' => Array ('email_queue'),
'file' => Array ('file', 'file_category'),
'faq' => Array ('faq','faq_translate', 'faq_category'),
'htaccess' => Array ('htaccess', 'htaccess_dir', 'htaccess_exclude'),
'import' => Array ('import'),
'hosting' => Array ('host_server', 'host_registrar_plugin', 'host_tld'),
'ticket' => Array ('ticket', 'ticket_department', 'ticket_message'),
'login_share' => Array ('login_share'),
'static_page' => Array ('static_page', 'static_page_category','static_page_translate') );

View File

@@ -42,6 +42,9 @@ class CORE_xml
if(!is_file($file)) return false;
$xml = simplexml_load_file ($file);
if(is_object($xml)) {
# Comments in the XML field are being translated as comment fields.
if (isset($xml->field->comment))
unset($xml->field->comment);
$dom = dom_import_simplexml ($xml);
$arr["$dom->tagName"] = SimpleXML2Array($xml);
}
@@ -268,4 +271,4 @@ function _xmlFileToArrayClose(& $topTag, & $includeTopTag, & $val, & $lowerCaseT
}
return true;
}
?>
?>