Initial Commit of AgileBill Open Source
This commit is contained in:
329
modules/group/group.inc.php
Normal file
329
modules/group/group.inc.php
Normal file
@@ -0,0 +1,329 @@
|
||||
<?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/
|
||||
*
|
||||
* @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
|
||||
* @version 1.4.93
|
||||
*/
|
||||
|
||||
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";
|
||||
|
||||
# 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"];
|
||||
}
|
||||
|
||||
|
||||
|
||||
##############################
|
||||
## ADD ##
|
||||
##############################
|
||||
function add($VAR)
|
||||
{
|
||||
$type = "add";
|
||||
$this->method["$type"] = split(",", $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
|
||||
# as available to them
|
||||
global $C_auth;
|
||||
$C_auth->auth_update();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
##############################
|
||||
## VIEW ##
|
||||
##############################
|
||||
function view($VAR)
|
||||
{
|
||||
$type = "view";
|
||||
$this->method["$type"] = split(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->view($VAR, $this, $type);
|
||||
}
|
||||
|
||||
##############################
|
||||
## 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 = split(',',$VAR["delete_id"]);
|
||||
elseif (isset($VAR["id"]))
|
||||
$id = split(',',$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($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"] = split(",", $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 = split(',',$VAR["delete_id"]);
|
||||
elseif (isset($VAR["id"]))
|
||||
$id = split(',',$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;
|
||||
}
|
||||
|
||||
} else {
|
||||
$C_debug->alert('One or more of the groups selected to be deleted are part of the core and cannot be removed.');
|
||||
}
|
||||
}
|
||||
|
||||
$VAR['id'] = $id_list;
|
||||
$db = new CORE_database;
|
||||
$db->mass_delete($VAR, $this, "");
|
||||
}
|
||||
|
||||
##############################
|
||||
## SEARCH FORM ##
|
||||
##############################
|
||||
function search_form($VAR)
|
||||
{
|
||||
$type = "search";
|
||||
$this->method["$type"] = split(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->search_form($VAR, $this, $type);
|
||||
}
|
||||
|
||||
##############################
|
||||
## SEARCH ##
|
||||
##############################
|
||||
function search($VAR)
|
||||
{
|
||||
$type = "search";
|
||||
$this->method["$type"] = split(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->search($VAR, $this, $type);
|
||||
}
|
||||
|
||||
##############################
|
||||
## SEARCH SHOW ##
|
||||
##############################
|
||||
|
||||
function search_show($VAR)
|
||||
{
|
||||
$type = "search";
|
||||
$this->method["$type"] = split(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->search_show($VAR, $this, $type);
|
||||
}
|
||||
|
||||
|
||||
##############################
|
||||
## VISUAL LAYOUT ##
|
||||
##############################
|
||||
function 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 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);
|
||||
|
||||
# error handling
|
||||
if ($result === false)
|
||||
{
|
||||
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 .= ' '. $arr[$i]['name'];
|
||||
$ret .= ' <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 .= ' |__';
|
||||
$ret .= ' '. $arr[$ii]['name'];
|
||||
$ret .= ' <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 .= ' |__ ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret .= ' | |__ ';
|
||||
}
|
||||
$ret .= ' '. $arr[$iii]['name'];
|
||||
$ret .= ' <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!
|
||||
}
|
||||
echo $ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
72
modules/group/group_construct.xml
Normal file
72
modules/group/group_construct.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<?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>
|
||||
</construct>
|
40
modules/group/group_install.xml
Normal file
40
modules/group/group_install.xml
Normal file
@@ -0,0 +1,40 @@
|
||||
<install>
|
||||
<module_properties>
|
||||
<name>group</name>
|
||||
<parent>account_admin</parent>
|
||||
<notes><![CDATA[A list of available groups, and their names]]></notes>
|
||||
<menu_display>1</menu_display>
|
||||
</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>
|
51
modules/group/group_install_data.xml
Normal file
51
modules/group/group_install_data.xml
Normal file
@@ -0,0 +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>
|
Reference in New Issue
Block a user