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,311 +1,171 @@
<?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:Method
*/
class module_method
{
# Open the constructor for this mod
function module_method()
{
# name of this module:
$this->module = "module_method";
/**
* The main AgileBill Module Method Class
*
* @package AgileBill
* @subpackage Module:Method
*/
class module_method extends OSB_module {
/**
* View methods
*/
public function view_methods($VAR) {
$type = 'search';
$this->method[$type] = explode(',',$this->method[$type]);
$db = new CORE_database;
# location of the construct XML file:
$this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
# open the construct file for parsing
$C_xml = new CORE_xml;
$construct = $C_xml->xml_to_array($this->xml_construct);
$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"];
$this->this_search_show($VAR,$this,$type);
}
##############################
## ADD ##
##############################
function add($VAR)
{
$type = "add";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->add($VAR, $this, $type);
}
##############################
## VIEW ##
##############################
function view($VAR)
{
$type = "view";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->view($VAR, $this, $type);
}
##############################
## UPDATE ##
##############################
function update($VAR)
{
$type = "update";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->update($VAR, $this, $type);
}
##############################
## DELETE ##
##############################
function delete($VAR)
{
$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);
}
##############################
## SEARCH SHOW ##
##############################
function search_show($VAR)
{
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->search_show($VAR, $this, $type);
}
##############################
## VIEW METHODS ##
##############################
function view_methods($VAR)
{
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$this->this_search_show($VAR, $this, $type);
}
##############################
## VIEW METHODS p.2 #####
##############################
function this_search_show($VAR, $construct, $type)
{
function this_search_show($VAR,$construct,$type) {
global $VAR;
# Get the list of parents for this group
$this->group_parent_list($VAR['module_method_group_id']);
# Generate the full query
$db = &DB();
$result = $db->Execute(sqlSelect($db,'module_method','*',array('module_id'=>$VAR['module_method_module_id'])));
# generate the full query
$q = "SELECT * FROM
".AGILE_DB_PREFIX."module_method
WHERE
module_id = ".$VAR['module_method_module_id'];
$db = &DB();
$result = $db->Execute($q);
# Put the results into a smarty accessable array
$i = 0;
$class_name = true;
# put the results into a smarty accessable array
$i=0;
$class_name = TRUE;
while (!$result->EOF) {
$smart[$i] = $result->fields;
while (! $result->EOF) {
$smart[$i] = $result->fields;
$method_id = $smart[$i]['id'];
## Get the auth status for this method & group
$q1 = 'SELECT id FROM '.AGILE_DB_PREFIX.'group_method WHERE
method_id = '.$smart[$i]['id'].' AND
group_id = '.$VAR['module_method_group_id'];
$db1 = &DB();
$resulta = $db1->Execute($q1);
#echo "<BR> $q1";
# Get the auth status for this method & group
$resulta = $db->Execute(sqlSelect($db,'group_method','id',array('method_id'=>$smart[$i]['id'],'group_id'=>$VAR['module_method_group_id'])));
## authorized by current group
if($resulta->RecordCount() >= 1)
{
#echo "<BR>1 - This group matches!";
# Authorized by current group
if ($resulta->RecordCount() >= 1) {
$smart[$i]['checked'] = '1';
}
else
{
# get the parent group id(s) for this group
} else {
# Get the parent group id(s) for this group
$match = false;
for($ii=0; $ii < count($this->group); $ii++)
{
if($match == false && $this->group[$ii] != $VAR['module_method_group_id'])
{
$q2 = 'SELECT id FROM '.AGILE_DB_PREFIX.'group_method
WHERE method_id = '.$method_id.'
AND group_id = '.$this->group[$ii];
for ($ii=0; $ii < count($this->group); $ii++) {
if ($match == false && $this->group[$ii] != $VAR['module_method_group_id']) {
$resultb = $db->Execute(sqlSelect($db,'group_method','id',array('method_id'=>$method_id,'group_id'=>$this->group[$ii])));
$db2 = &DB();
$resultb = $db2->Execute($q2);
#echo "<BR> $q2";
if($resultb->RecordCount() >= 1)
if ($resultb->RecordCount() >= 1)
$match = true;
}
}
## authorized by parent
if($match)
{
#echo "<BR>2 - This Parent Matches!";
# authorized by parent
if ($match)
$smart[$i]['checked'] = '2';
}
else
{
## not authorized
#echo "<BR>3 - NO matches";
$smart[$i]['checked'] = '3';
}
$smart[$i]['checked'] = '3';
}
if($class_name)
{
if ($class_name) {
$smart[$i]['_C'] = 'row2';
$class_name = FALSE;
$class_name = false;
} else {
$smart[$i]['_C'] = 'row1';
$class_name = TRUE;
$class_name = true;
}
$result->MoveNext();
$i++;
}
# get any linked fields
if($i > 0)
{
if ($i > 0) {
$db_join = new CORE_database;
$this->result = $db_join->join_fields($smart, $this->linked);
}
else
{
} else {
$this->result = $smart;
}
# 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, $this->result);
$smarty->assign('page', $VAR['page']);
$smarty->assign('order', 1111);
$smarty->assign('sort', 1111);
$smarty->assign('limit', 1111);
$smarty->assign($construct->table,$this->result);
$smarty->assign('page',$VAR['page']);
$smarty->assign('order',1111);
$smarty->assign('sort',1111);
$smarty->assign('limit',1111);
$smarty->assign('search_id',1111);
$smarty->assign('results', $results);
$smarty->assign('results',$results);
# get the total pages for this search:
$this->pages = 1;
if ($search->results % $search->limit) $this->pages++;
if ($search->results % $search->limit)
$this->pages++;
# total pages
$smarty->assign('pages', $this->pages);
$smarty->assign('pages',$this->pages);
# current page
$smarty->assign('page', $current_page);
$smarty->assign('page',$current_page);
$page_arr = '';
for($i=0; $i <= $this->pages; $i++)
{
if ($this->page != $i) $page_arr[] = $i;
}
for ($i=0; $i <= $this->pages; $i++)
if ($this->page != $i)
$page_arr[] = $i;
# page array for menu
$smarty->assign('page_arr', $page_arr);
$smarty->assign('page_arr',$page_arr);
}
/**
* Get any inherited groups (parent) for a specified group
* @return void
* @since Version 1.0
* @param int Group Id
*/
function group_parent_list($group)
{
function group_parent_list($group) {
# check if this group is a child with an active parent
$db = &DB();
$q = "SELECT id,parent_id FROM " . AGILE_DB_PREFIX . "group
WHERE id = '$group'
AND site_id = '" . DEFAULT_SITE . "'";
$result = $db->Execute($q);
$result = $db->Execute(sqlSelect($db,'group','id,parent_id',array('id'=>$group)));
# error handling
if ($result === false)
{
if ($result === false) {
global $C_debug;
$C_debug->error('auth.inc.php','group_parent_list', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
# loop through the results
while (!$result->EOF)
{
# loop through the results
while (! $result->EOF) {
# add this group to the list
$this->group[] = $result->fields['id'];
# get inherited groups and check that the associated
# group is active before adding to the list of authorized groups.
if($result->fields['parent_id'] != 0)
{
if ($result->fields['parent_id'] != 0)
$this->group_parent_list($result->fields['parent_id']);
}
# move to next record
$result->MoveNext();
@@ -318,49 +178,25 @@ class module_method
* @since Version 1.0
* @param int Group Id
*/
function update_relations()
{
function update_relations() {
global $VAR;
$db = &DB();
if(isset($VAR['id']) && $VAR['id'] != '')
{
$arr = explode(',', $VAR['id']);
if (isset($VAR['id']) && $VAR['id'] != '')
$arr = explode(',',$VAR['id']);
else
return;
for ($i=0; $i<count($arr); $i++) {
# Clear the entries first
if ($i == 0)
$db->Execute(sqlDelete($db,'group_method',array('module_id'=>$VAR['module_method_module_id'],'group_id'=>$VAR['module_method_group_id'])));
if ($arr[$i] == 0)
return;
$db->Execute(sqlInsert($db,'group_method',array('method_id'=>$arr[$i],'module_id'=>$VAR['module_method_module_id'],'group_id'=>$VAR['module_method_group_id'])));
}
else { return;}
for($i=0; $i<count($arr); $i++)
{
if($i == 0)
{
# clear the entries first
$q = "DELETE FROM ".AGILE_DB_PREFIX."group_method
WHERE
site_id = '" . DEFAULT_SITE . "' AND
module_id = '".$VAR['module_method_module_id']."' AND
group_id = '".$VAR['module_method_group_id']."'";
$db = &DB();
$result = $db->Execute($q);
}
if($arr[$i] == 0) return;
# determine the record id:
$this->record_id = $db->GenID(AGILE_DB_PREFIX . 'group_method_id');
# generate the full query
$q = "INSERT INTO ".AGILE_DB_PREFIX."group_method
SET
id = '".$this->record_id."',
site_id = '" . DEFAULT_SITE . "',
method_id = '".$arr[$i]."',
module_id = '".$VAR['module_method_module_id']."',
group_id = '".$VAR['module_method_group_id']."'";
$db = &DB();
$result = $db->Execute($q);
}
}
}
}
?>
?>

View File

@@ -1,66 +1,106 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<construct>
<!-- define the module name -->
<module>module_method</module>
<!-- define the module table name -->
<table>module_method</table>
<!-- define the module dependancy(s) -->
<dependancy>module</dependancy>
<!-- define the DB cache in seconds -->
<cache>0</cache>
<!-- define the default order_by field for SQL queries -->
<order_by>name</order_by>
<!-- define the methods -->
<limit>25</limit>
<!-- define database indexes -->
<index>
<module>module_id</module>
<menu_display>menu_display</menu_display>
</index>
<!-- define the fields -->
<field>
<id>
<type>I4</type>
<unique>1</unique>
<index>1</index>
</id>
<site_id>
<type>I4</type>
<index>1</index>
</site_id>
<module_id>
<type>I4</type>
<asso_table>module</asso_table>
<asso_field>name</asso_field>
<validate>any</validate>
<index>1</index>
</module_id>
<name>
<type>C(64)</type>
<min_len>1</min_len>
<max_len>64</max_len>
<validate>non_numeric</validate>
<convert/>
</name>
<notes>
<type>C2(128)</type>
</notes>
<page>
<type>C(128)</type>
</page>
<menu_display>
<type>L</type>
</menu_display>
</field>
<!-- define all the methods for this class, and the fields they have access to, if applicable. -->
<method>
<add>id,site_id,module_id,name,notes,page,menu_display</add>
<update>id,site_id,module_id,name,notes,page,menu_display</update>
<delete>id,site_id,module_id,name,notes,page,menu_display</delete>
<view>id,site_id,module_id,name,notes,page,menu_display</view>
<search>id,site_id,module_id,name,notes,page,menu_display</search>
<list>id,site_id,module_id,name,notes,page,menu_display</list>
</method>
<!-- define the method triggers -->
<trigger>0</trigger>
<!-- Module name -->
<module>module_method</module>
<!-- Module supporting database table -->
<table>module_method</table>
<!-- Module dependancy(s) (module wont install if these modules are not yet installed) -->
<dependancy>module</dependancy>
<!-- DB cache in seconds -->
<cache>0</cache>
<!-- Default order_by field for SQL queries -->
<order_by>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>1</version>
<!-- Database indexes -->
<index>
<module>module_id</module>
<menu_display>menu_display</menu_display>
</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>
<module_id>
<display>Module</display>
<type>I4</type>
<asso_table>module</asso_table>
<asso_field>name</asso_field>
<validate>any</validate>
<index>1</index>
</module_id>
<name>
<display>Name</display>
<type>C(64)</type>
<min_len>1</min_len>
<max_len>64</max_len>
<validate>non_numeric</validate>
<convert/>
</name>
<notes>
<type>C2(128)</type>
</notes>
<page>
<type>C(128)</type>
</page>
<menu_display>
<display>Menu</display>
<type>L</type>
</menu_display>
</field>
<!-- Methods for this class, and the fields they have access to, if applicable -->
<method>
<add>module_id,name,notes,page,menu_display</add>
<delete>id,site_id,module_id,name,notes,page,menu_display</delete>
<list>id,site_id,module_id,name,notes,page,menu_display</list>
<search>id,site_id,module_id,name,notes,page,menu_display</search>
<update>id,site_id,module_id,name,notes,page,menu_display</update>
<view>id,site_id,module_id,name,notes,page,menu_display</view>
</method>
<!-- Method triggers -->
<trigger></trigger>
<!-- Template page display titles -->
<title>
<add>Add Method</add>
<update_relations>Update Authorisation</update_relations>
<view>Methods</view>
</title>
<!-- Template helpers -->
<tpl>
<search_show>
<checkbox>
<field>id</field>
<type>checkbox</type>
<width>25px</width>
</checkbox>
<name>
<field>name</field>
</name>
<module_id>
<field>module_id</field>
</module_id>
<menu_display>
<field>menu_display</field>
<type>bool</type>
<width>15px</width>
</menu_display>
</search_show>
</tpl>
</construct>

View File

@@ -1,40 +1,62 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<install>
<!-- Tree Menu Module Properties -->
<module_properties>
<!-- MODULE Dependancy, this module wont be installed if the dependant modules dont exist -->
<dependancy></dependancy>
<!-- Translated display to use on the tree -->
<display></display>
<!-- Display a module in the menu tree -->
<menu_display>0</menu_display>
<!-- MODULE Name -->
<name>module_method</name>
<parent>module</parent>
<!-- MODULE Notes, these notes show up in the modules table, as a description of the module -->
<notes><![CDATA[Control the available methods for each module]]></notes>
<!-- MODULE Parent, the parent node in the tree -->
<parent>module</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>
<search>
<name>search</name>
</search>
<view>
<name>view</name>
</view>
<add>
<name>add</name>
</add>
<delete>
<name>delete</name>
</delete>
<update>
<name>update</name>
</update>
<search_form>
<name>search_form</name>
</search_form>
<search_show>
<name>search_show</name>
<notes><![CDATA[Allow users to view the search results]]></notes>
</search_show>
<view_methods>
<name>view_methods</name>
<notes><![CDATA[View the methods relationship form]]></notes>
</view_methods>
<update_relations>
<name>update_relations</name>
</update_relations>
</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>
<name>add</name>
<notes><![CDATA[Add records]]></notes>
</add>
<delete>
<name>delete</name>
<notes><![CDATA[Delete records]]></notes>
</delete>
<search>
<name>search</name>
<notes><![CDATA[List records]]></notes>
<page><![CDATA[core:search&module=%%&_next_page_one=view]]></page>
</search>
<search_form>
<name>search_form</name>
<notes><![CDATA[Search for records]]></notes>
</search_form>
<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>
<view_methods>
<name>view_methods</name>
<notes><![CDATA[View the methods relationship form]]></notes>
</view_methods>
<update_relations>
<name>update_relations</name>
</update_relations>
</module_method>
</install>