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,80 +1,55 @@
<?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 Module:Group
*/
class group
{
# Open the constructor for this mod
function group()
{
# name of this module:
$this->module = "group";
# location of the construct XML file:
$this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
/**
* The main AgileBill Group Class
*
* @package AgileBill
* @subpackage Module:Group
*/
class group extends OSB_module {
/**
* Add a record
*/
public function add($VAR) {
$group_id = parent::add($VAR);
# open the construct file for parsing
$C_xml = new CORE_xml;
$construct = $C_xml->xml_to_array($this->xml_construct);
if ($group_id) {
# Add the new group to the account_group table:
$db = &DB();
$result = $db->Execute(sqlInsert($db,'account_group',array('date_orig'=>time(),'group_id'=>$group_id,'account_id'=>SESS_ACCOUNT,'acive'=>1)));
if ($result === false) {
global $C_debug;
$this->method = $construct["construct"]["method"];
$this->trigger = $construct["construct"]["trigger"];
$this->field = $construct["construct"]["field"];
$this->table = $construct["construct"]["table"];
$this->module = $construct["construct"]["module"];
$this->cache = $construct["construct"]["cache"];
$this->order_by = $construct["construct"]["order_by"];
$this->limit = $construct["construct"]["limit"];
}
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
return;
}
} else
return false;
##############################
## ADD ##
##############################
function add($VAR)
{
$type = "add";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$group_id = $db->add($VAR, $this, $type);
# add the new group to the account_group table:
$db = &DB();
$record_id = $db->GenID(AGILE_DB_PREFIX . 'account_group_id');
$sql= "INSERT INTO ". AGILE_DB_PREFIX ."account_group SET
id = ".$db->qstr($record_id).",
site_id = ".$db->qstr(DEFAULT_SITE).",
date_orig = ".$db->qstr(time()).",
date_expire = ".$db->qstr('0').",
group_id = ".$db->qstr($group_id).",
account_id = ".$db->qstr(SESS_ACCOUNT).",
active = ".$db->qstr(1);
$result = $db->Execute($sql);
if ($result === false)
{
global $C_debug;
$C_debug->error('list.inc.php','select_groups', $db->ErrorMsg());
return;
}
# update the current user's authentication so the newly added group appears
# Update the current user's authentication so the newly added group appears
# as available to them
global $C_auth;
$C_auth->auth_update();
@@ -82,248 +57,105 @@ class group
return;
}
##############################
## VIEW ##
##############################
function view($VAR)
{
$type = "view";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->view($VAR, $this, $type);
}
private function isAuthorised($VAR) {
# Remove any group ids <= 1001 from the VAR array:
global $C_debug,$C_auth;
##############################
## UPDATE ##
##############################
function update($VAR)
{
#remove any group ids <= 1001 from the VAR array:
global $C_debug, $C_auth;
$id_list = '';
if(isset($VAR["delete_id"]))
$id = explode(',',$VAR["delete_id"]);
elseif (isset($VAR["id"]))
$id = explode(',',$VAR["id"]);
$id = array();
for($i=0; $i<count($id); $i++)
{
if(!empty($id[$i]) && $id[$i] > 1001 )
{
if($i == 0)
$id_list .= $id[$i];
else
$id_list .= ','.$id[$i];
if (isset($VAR['id']))
$id = explode(',',$VAR['id']);
for ($i=0; $i<count($id); $i++) {
if (! empty($id[$i]) && $id[$i] > 1001) {
# Check if group allowed:
if(!$C_auth->auth_group_by_id($id[$i])) {
if (! $C_auth->auth_group_by_id($id[$i])) {
$C_debug->alert('The selected group cannot be modified as your account is not authorized for it.');
return;
}
} else {
$C_debug->alert('The selected group is part of the CORE and cannot be edited.');
return;
}
}
$type = "update";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->update($VAR, $this, $type);
}
##############################
## DELETE ##
##############################
function delete($VAR)
{
global $C_auth;
$this->associated_DELETE[] = Array ('table' => 'account_group', 'field' => 'group_id');
$this->associated_DELETE[] = Array ('table' => 'group_method', 'field' => 'group_id');
#remove any group ids <= 1001 from the mass delete array:
global $C_debug;
$id_list = '';
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(!empty($id[$i]) && $id[$i] > 1001 )
{
if($i == 0)
$id_list .= $id[$i];
else
$id_list .= ','.$id[$i];
# Check if group allowed:
if(!$C_auth->auth_group_by_id(1001) && !$C_auth->auth_group_by_id($id[$i])) {
$C_debug->alert('The selected group cannot be modified as your account is not authorized for it.');
return;
return true;
}
} else {
$C_debug->alert('One or more of the groups selected to be deleted are part of the core and cannot be removed.');
$C_debug->alert('The selected group is part of the CORE and cannot be edited or deleted.');
return true;
}
}
$VAR['id'] = $id_list;
$db = new CORE_database;
$db->mass_delete($VAR, $this, "");
}
##############################
## SEARCH FORM ##
##############################
function search_form($VAR)
{
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->search_form($VAR, $this, $type);
}
##############################
## SEARCH ##
##############################
function search($VAR)
{
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->search($VAR, $this, $type);
/**
* Update an entry
*/
public function update($VAR) {
if (! $this->isAuthorised($VAR))
return parent::update($VAR);
}
##############################
## SEARCH SHOW ##
##############################
/**
* Delete a record
*/
public function delete($VAR) {
$this->associated_DELETE = array();
function search_show($VAR)
{
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->search_show($VAR, $this, $type);
}
array_push($this->associated_DELETE,array('table'=>'account_group','field'=>'group_id'));
array_push($this->associated_DELETE,array('table'=>'group_method','field'=>'group_id'));
if (! $this->isAuthorised($VAR))
return parent::delete($VAR);
}
##############################
## VISUAL LAYOUT ##
##############################
function visual_layout()
{
/**
* Draw the group layout
*/
public function tpl_visual_layout() {
$class = 'form_field';
# get the default group
if(!isset($default)) $default = unserialize(DEFAULT_GROUP);
for($i=0; $i<count($default); $i++) $checked[$default[$i]] = true;
# Get the default group
if (! isset($default))
$default = unserialize(DEFAULT_GROUP);
# get the currect selected value & display
for ($i=0; $i<count($default); $i++)
$checked[$default[$i]] = true;
# Get the currect selected value & display
$db = &DB();
$sql= "SELECT id,name,parent_id FROM ".AGILE_DB_PREFIX."group WHERE id != '0' AND site_id = '" . DEFAULT_SITE . "' ORDER BY parent_id,name";
$result = $db->Execute($sql);
$result = $db->Execute(sqlSelect($db,'group','id,name,parent_id','id!=0','parent_id,name'));
# error handling
if ($result === false)
{
# Error handling
if (! $result) {
global $C_debug;
$C_debug->error('list.inc.php','select_groups', $db->ErrorMsg());
}
# number of results
if($result->RecordCount() > 0)
{
# set the results to an array:
$arr = $result->GetArray();
# start the list
$ret = '';
#----------------------
# start the parent loop
#----------------------
$group = 0;
$arr_count = count($arr);
for($i=0; $i < $arr_count; $i++)
{
$level = 0;
if($arr[$i]['parent_id'] == $group)
{
$ret .= '&nbsp;&nbsp;'. $arr[$i]['name'];
$ret .= '&nbsp;&nbsp;&nbsp; <a href="?_page=group:view&id='.$arr[$i]['id'].'">edit</a><br>';
#----------------------
# start the child loop
#----------------------
$level++;
$ii_group = $arr[$i]['id'];
$ii_print = 1;
# count the available childs for this group
$count_child[$ii_group]=0;
for($c_child=0; $c_child < $arr_count; $c_child++)
if($arr[$c_child]['parent_id'] == $ii_group) $count_child[$ii_group]++;
for($ii=0; $ii < $arr_count; $ii++)
{
if($arr[$ii]['parent_id'] == $ii_group)
{
$ret .= '&nbsp;&nbsp;|__';
$ret .= '&nbsp;&nbsp;'. $arr[$ii]['name'];
$ret .= '&nbsp;&nbsp;&nbsp; <a href="?_page=group:view&id='.$arr[$ii]['id'].'">edit</a><br>';
$ii_print++;
#--------------------------
# start the sub-child loop
#--------------------------
$level++;
$iii_group = $arr[$ii]['id'];
$iii_print = 0;
for($iii=0; $iii < $arr_count; $iii++)
{
if($arr[$iii]['parent_id'] == $iii_group)
{
if($count_child[$ii_group] < $ii_print)
{
$ret .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|__ ';
}
else
{
$ret .= '&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|__ ';
}
$ret .= '&nbsp;&nbsp;'. $arr[$iii]['name'];
$ret .= '&nbsp;&nbsp;&nbsp; <a href="?_page=group:view&id='.$arr[$iii]['id'].'">edit</a><br>';
$iii_print++;
}
}
$level--;
#-----------------------
# end of sub-child loop
#-----------------------
}
}
$level--;
#-------------------
# end of child loop
#-------------------
}
}
}
else
{
return 'No groups available!'; // translate!
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
echo $ret;
# Number of results
if ($result->RecordCount() > 0)
echo $this->build_nested_list($result->GetArray(),0,0);
else
echo _('No groups available!');
}
/**
* This function will build a nested option list
* showing the heirachy of the groups
*
* @see tpl_visual_layout
*/
private function build_nested_list($arr,$level,$current) {
$ret = '';
for ($i=0; $i < count($arr); $i++) {
if ($arr[$i]['parent_id'] == $current) {
if ($level)
$ret .= sprintf('%s|__ ',str_repeat('&nbsp;&nbsp;&nbsp;',$level));
$ret .= sprintf('&nbsp;&nbsp;%s&nbsp;&nbsp;&nbsp;<a href="?_page=group:view&amp;id=%s">%s</a><br/>',$arr[$i]['name'],$arr[$i]['id'],_('Edit'));
$ret .= $this->build_nested_list($arr,$level+1,$arr[$i]['id']);
}
}
return $ret;
}
}
?>
?>

View File

@@ -1,72 +1,103 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<construct>
<!-- define the module name -->
<module>group</module>
<!-- define the module table name -->
<table>group</table>
<!-- define the module dependancy(s) -->
<dependancy/>
<!-- define the DB cache in seconds -->
<cache>0</cache>
<!-- define the default order_by field for SQL queries -->
<order_by>parent_id,name</order_by>
<!-- define the methods -->
<limit>25</limit>
<!-- define database indexes -->
<index>
<pricing>date_expire</pricing>
<idx>status,parent_id,date_start,date_expire</idx>
</index>
<!-- define the fields -->
<field>
<id>
<type>I4</type>
<unique>1</unique>
</id>
<site_id>
<type>I4</type>
</site_id>
<date_orig>
<type>I8</type>
<convert>date-now</convert>
</date_orig>
<date_start>
<type>I8</type>
<convert>date-time</convert>
</date_start>
<date_expire>
<type>I8</type>
<convert>date-time</convert>
</date_expire>
<parent_id>
<type>I4</type>
</parent_id>
<status>
<type>L</type>
</status>
<pricing>
<type>L</type>
</pricing>
<name>
<type>C(128)</type>
<validate>any</validate>
<min_len>3</min_len>
<max_len>64</max_len>
<unique>1</unique>
</name>
<notes>
<type>X2</type>
</notes>
</field>
<!-- define all the methods for this class, and the fields they have access to, if applicable. -->
<method>
<add>id,site_id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id</add>
<update>id,site_id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id</update>
<delete>id,site_id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id</delete>
<view>id,site_id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id</view>
<search>id,site_id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id</search>
<list>id,site_id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id</list>
</method>
<!-- define the method triggers -->
<trigger>0</trigger>
<!-- Module name -->
<module>group</module>
<!-- Module supporting database table -->
<table>group</table>
<!-- Module dependancy(s) (module wont install if these modules are not yet installed) -->
<dependancy></dependancy>
<!-- DB cache in seconds -->
<cache>0</cache>
<!-- Default order_by field for SQL queries -->
<order_by>parent_id,name</order_by>
<!-- Default SQL limit for SQL queries -->
<limit>25</limit>
<!-- Schema version (used to determine if the schema has change during upgrades) -->
<version>0</version>
<!-- Database indexes -->
<index>
<pricing>date_expire</pricing>
<idx>status,parent_id,date_start,date_expire</idx>
</index>
<!-- Database fields -->
<field>
<!-- Record ID -->
<id>
<index>1</index>
<type>I4</type>
<unique>1</unique>
</id>
<!-- Site ID -->
<site_id>
<index>1</index>
<type>I4</type>
</site_id>
<!-- Date record created -->
<date_orig>
<convert>date-now</convert>
<display>Date Created</display>
<type>I8</type>
</date_orig>
<date_start>
<type>I8</type>
<convert>date-time</convert>
<display>Date Start</display>
</date_start>
<date_expire>
<type>I8</type>
<convert>date-time</convert>
<display>Date End</display>
</date_expire>
<parent_id>
<type>I4</type>
<display>Parent</display>
</parent_id>
<!-- Record active (BOOL)-->
<status>
<display>Active</display>
<type>L</type>
</status>
<pricing>
<type>L</type>
<display>Group Pricing</display>
</pricing>
<name>
<type>C(128)</type>
<validate>any</validate>
<min_len>3</min_len>
<max_len>64</max_len>
<unique>1</unique>
<display>Name</display>
</name>
<notes>
<type>X2</type>
<display>Notes</display>
</notes>
</field>
<!-- Methods for this class, and the fields they have access to, if applicable -->
<method>
<add>date_start,date_expire,name,notes,status,pricing,parent_id</add>
<update>date_start,date_expire,name,notes,status,pricing,parent_id</update>
<delete>id</delete>
<view>id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id</view>
<search>name</search>
</method>
<!-- Method triggers -->
<trigger></trigger>
<!-- Template page display titles -->
<title>
<add>Add Group</add>
<search_show>Groups</search_show>
<tpl_title_visual>Group Layout Visualisation</tpl_title_visual>
<view>Modify Group</view>
</title>
<!-- Template helpers -->
<tpl>
</tpl>
</construct>

View File

@@ -1,40 +1,59 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<install>
<!-- Tree Menu Module Properties -->
<module_properties>
<name>group</name>
<parent>account_admin</parent>
<notes><![CDATA[A list of available groups, and their names]]></notes>
<!-- MODULE Dependancy, this module wont be installed if the dependant modules dont exist -->
<dependancy></dependancy>
<!-- Translated display to use on the tree -->
<display>Groups</display>
<!-- Display a module in the menu tree -->
<menu_display>1</menu_display>
<!-- MODULE Name -->
<name>group</name>
<!-- MODULE Notes, these notes show up in the modules table, as a description of the module -->
<notes><![CDATA[A list of available groups, and their names]]></notes>
<!-- MODULE Parent, the parent node in the tree -->
<parent>setup</parent>
<!-- SUB Modules to install with this one -->
<sub_modules></sub_modules>
<!-- MODULE Type (core|base), core modules cannot be deleted, unrecognised types are ignored. -->
<type>core</type>
</module_properties>
<sql_inserts>
<module_method>
<visual_layout>
<name>visual_layout</name>
<notes><![CDATA[Displays the visual layout of the groups]]></notes>
</visual_layout>
<search>
<name>search</name>
</search>
<view>
<name>view</name>
<notes><![CDATA[Allow users to view records]]></notes>
<page><![CDATA[core:search&module=%%&_escape=1&_next_page_one=view]]></page>
<menu_display>1</menu_display>
</view>
<add>
<name>add</name>
<notes><![CDATA[Allow users to add records]]></notes>
<menu_display>1</menu_display>
</add>
<delete>
<name>delete</name>
</delete>
<update>
<name>update</name>
</update>
<search_show>
<name>search_show</name>
<notes><![CDATA[Allow users to view the search results]]></notes>
</search_show>
</module_method>
</sql_inserts>
</install>
<!-- Tree Menu & Module Methods to load, they will be assigned the group permissions on install time, as selected by the user. -->
<module_method>
<add>
<display>Add</display>
<menu_display>1</menu_display>
<name>add</name>
<notes><![CDATA[Add records]]></notes>
</add>
<delete>
<name>delete</name>
<notes><![CDATA[Delete records]]></notes>
</delete>
<search>
<menu_display>1</menu_display>
<display>List</display>
<name>search</name>
<notes><![CDATA[List records]]></notes>
<page><![CDATA[core:search&module=%%&_next_page_one=view]]></page>
</search>
<search_show>
<name>search_show</name>
<notes><![CDATA[Show the results of a search]]></notes>
</search_show>
<update>
<name>update</name>
<notes><![CDATA[Update a record]]></notes>
</update>
<view>
<name>view</name>
<notes><![CDATA[View a record]]></notes>
</view>
<tpl_visual_layout>
<name>tpl_visual_layout</name>
<notes><![CDATA[Displays the visual layout of the groups]]></notes>
</tpl_visual_layout>
</module_method>
</install>

View File

@@ -1,51 +1,51 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<install>
<group>
<id>0</id>
<site_id>1</site_id>
<date_orig>0</date_orig>
<date_start>0</date_start>
<date_expire>0</date_expire>
<parent_id>0</parent_id>
<status>1</status>
<pricing>1</pricing>
<name>All Users</name>
<notes>All unregistered users will have access to this.</notes>
</group>
<group>
<id>2</id>
<site_id>1</site_id>
<date_orig>0</date_orig>
<date_start>0</date_start>
<date_expire>0</date_expire>
<parent_id>0</parent_id>
<status>1</status>
<pricing>1</pricing>
<name>Registered Users</name>
</group>
<group>
<id>4</id>
<site_id>1</site_id>
<date_orig>0</date_orig>
<date_start>0</date_start>
<date_expire>0</date_expire>
<parent_id>2</parent_id>
<status>1</status>
<pricing>0</pricing>
<name>Staff</name>
</group>
<group>
<id>1001</id>
<site_id>1</site_id>
<date_orig>0</date_orig>
<date_start>0</date_start>
<date_expire>0</date_expire>
<parent_id>2</parent_id>
<status>1</status>
<pricing>0</pricing>
<name>Root</name>
</group>
<group_id>
<id>1016</id>
</group_id>
</install>
<group>
<id>0</id>
<site_id>1</site_id>
<date_orig>0</date_orig>
<date_start>0</date_start>
<date_expire>0</date_expire>
<parent_id>0</parent_id>
<status>1</status>
<pricing>1</pricing>
<name>All Users</name>
<notes>All unregistered users will have access to this.</notes>
</group>
<group>
<id>2</id>
<site_id>1</site_id>
<date_orig>0</date_orig>
<date_start>0</date_start>
<date_expire>0</date_expire>
<parent_id>0</parent_id>
<status>1</status>
<pricing>1</pricing>
<name>Registered Users</name>
</group>
<group>
<id>4</id>
<site_id>1</site_id>
<date_orig>0</date_orig>
<date_start>0</date_start>
<date_expire>0</date_expire>
<parent_id>2</parent_id>
<status>1</status>
<pricing>0</pricing>
<name>Staff</name>
</group>
<group>
<id>1001</id>
<site_id>1</site_id>
<date_orig>0</date_orig>
<date_start>0</date_start>
<date_expire>0</date_expire>
<parent_id>2</parent_id>
<status>1</status>
<pricing>0</pricing>
<name>Root</name>
</group>
<group_id>
<id>1016</id>
</group_id>
</install>