Initial Commit of AgileBill Open Source

This commit is contained in:
unknown
2008-11-26 14:50:40 -08:00
parent ae5a0fc25e
commit 02306ccc47
2954 changed files with 410976 additions and 0 deletions

11
modules/file/auth.inc.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
### public methods for this module:
$auth_methods = Array
(
Array ('module' => 'file', 'method' => 'download'),
Array ('module' => 'file', 'method' => 'category_list'),
Array ('module' => 'file', 'method' => 'file_list')
);
?>

492
modules/file/file.inc.php Normal file
View File

@@ -0,0 +1,492 @@
<?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 file
{
# Open the constructor for this mod
function file()
{
# name of this module:
$this->module = "file";
# 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"];
}
##############################
## LIST AUTH FILES ##
##############################
function file_list($VAR)
{
global $smarty;
if(!isset($VAR['id']))
{
global $C_debug;
$smarty->assign('file_display', false);
return false;
}
### Check if user is auth for the selected category:
$db = &DB();
$sql = 'SELECT *
FROM ' . AGILE_DB_PREFIX . 'file WHERE
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
file_category_id = ' . $db->qstr($VAR['id']) . ' AND
status = ' . $db->qstr('1') .'
ORDER BY sort_order,date_orig,name';
$result = $db->Execute($sql);
if($result->RecordCount() == 0)
{
$smarty->assign('file_display', false);
return false;
}
global $C_auth;
$ii = 0;
while(!$result->EOF)
{
@$arr = unserialize($result->fields['group_avail']);
$this_show = false;
for($i=0; $i<count($arr); $i++)
{
if($C_auth->auth_group_by_id($arr[$i]))
{
$this_show = true;
$i=count($arr);
}
}
if($this_show)
{
$start = $result->fields['date_start'];
$expire= $result->fields['date_expire'];
### Check that it is not expired
if (( $start == "0" || $start <= time()+2 ) &&
( $expire == "0" || $expire >= time() ) )
{
$arr_smarty[] = Array (
'id' => $result->fields['id'],
'name' => $result->fields['name'],
'description' => $result->fields['description'],
'size' => $result->fields['type'],
'size' => $result->fields['size']
);
$ii++;
}
}
$result->MoveNext();
}
if($ii == "0")
{
$smarty->assign('file_display', false);
return false;
}
else
{
$smarty->assign('file_display', true);
$smarty->assign('file_results', $arr_smarty);
return true;
}
}
##############################
## GET AUTH CATEGORIES ##
##############################
function category_list($VAR)
{
/* check if current session is authorized for any ticket departments..
and return true/false...
*/
global $smarty;
$db = &DB();
$sql = 'SELECT id,name,group_avail FROM ' . AGILE_DB_PREFIX . 'file_category WHERE
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
status = ' . $db->qstr('1') .'
ORDER BY sort_order,name';
$result = $db->Execute($sql);
if($result->RecordCount() == 0)
{
$smarty->assign('file_category_display', false);
return false;
}
global $C_auth;
$ii = 0;
while(!$result->EOF)
{
@$arr = unserialize($result->fields['group_avail']);
for($i=0; $i<count($arr); $i++)
{
if($C_auth->auth_group_by_id($arr[$i]))
{
### Add to the array
$ii++;
$arr_smarty[] = Array( 'name' => $result->fields['name'],
'id' => $result->fields['id']);
$i=count($arr);
}
}
$result->MoveNext();
}
if($ii == "0")
{
$smarty->assign('file_category_display', false);
return false;
}
else
{
$smarty->assign('file_category_display', true);
$smarty->assign('file_category_results', $arr_smarty);
return true;
}
}
##############################
## DOWNLOAD ##
##############################
function download($VAR)
{
$db = &DB();
$sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'file WHERE
site_id = ' . DEFAULT_SITE . ' AND
id = ' . $db->qstr(@$VAR['id']) . ' AND
status = 1';
$result = $db->Execute($sql);
if($result->RecordCount() == 1)
{
$show = true;
### Validate start date
$s = $result->fields['date_start'];
if($s != '' && $s != 0)
if($s > time())
$show = false;
### Validate expire date
$e = $result->fields['date_expire'];
if($e != '' && $e != 0)
if($e < time())
$show = false;
### Validate user group:
if($show) {
global $C_auth;
@$arr = unserialize($result->fields['group_avail']);
$show = false;
for($i=0; $i<count($arr); $i++) {
if($C_auth->auth_group_by_id($arr[$i])) {
$show = true;
break;
}
}
}
### Get the filetype
if($show)
{
$ft = $result->fields['location_type'];
if($ft == 0)
$file = PATH_FILES . 'file_'.$VAR['id'].'.dat';
elseif ($ft == 1)
$file = $result->fields['location'];
elseif ($ft == 2)
$file = $result->fields['location'];
### Open the file
if (@$file=fopen($file, 'r'))
{
### Display the correct headers:
header ("Content-Type: " . $result->fields['type']);
header ("Content-Size: " . $result->fields['size']);
header ("Content-Disposition: inline; filename=" . $result->fields['name']);
fpassthru($file);
exit;
}
}
}
echo 'Sorry, the file does not exist or you are not authorized or your access has expired!';
}
##############################
## ADD ##
##############################
function add($VAR)
{
global $_FILES, $smarty, $C_debug, $C_translate;
if($VAR['file_location_type'] == '') return false;
$lt = $VAR['file_location_type'];
// UPLOADED FILE FROM LOCAL PC
if($lt == 0) {
### Validate the file upoad:
if(!isset($_FILES['upload_file']) || $_FILES['upload_file']['size'] <= 0)
{
global $C_debug;
$C_debug->alert('You must go back and enter a file for upload!');
return;
}
$VAR['file_size'] = $_FILES['upload_file']['size'];
$VAR['file_type'] = $_FILES['upload_file']['type'];
$VAR['file_name'] = $_FILES['upload_file']['name'];
}
// ENTERED URL TO FILE
elseif ($lt == 1) {
### Validate the remote file can be opened and is greater than 0K
$file = $VAR['url_file'];
if(empty($file) || !$fp = fopen ($file, "r")) {
# error
$C_debug->alert( $C_translate->translate('remote_file_err','file','') );
return;
} else {
$VAR['file_location'] = $file;
$fn = explode("/", $file);
$count = count($fn)-1;
$VAR['file_name'] = $fn[$count];
$headers = stream_get_meta_data($fp);
$headers = $headers['wrapper_data'];
for($i=0;$i<count($headers); $i++) {
if(eregi('^Content-Type:', $headers[$i]))
$VAR['file_type'] = eregi_replace('Content-Type: ', '', $headers[$i]);
elseif(eregi('^Content-Length:', $headers[$i]))
$VAR['file_size'] = eregi_replace('Content-Length: ', '', $headers[$i]);
}
}
}
// ENTERED LOCAL FILE
elseif ($lt == 2)
{
@$file = $VAR['local_file'];
if(is_file($file) && is_readable($file))
{
if(ereg("/", $file))
$fn = explode("/", $file);
else if(ereg("\\", $file))
$fn = explode("\\", $file);
else
$fn[0] = $file;
$count = count($fn)-1;
$VAR['file_name'] = $fn[$count];
$VAR['file_size'] = filesize($file);
$VAR['file_location'] = $file;
include_once(PATH_CORE . 'file_extensions.inc.php');
$ext = new file_extensions;
$VAR['file_type'] = $ext->content_type($file);
}
else
{
$C_debug->alert( $C_translate->translate('local_file_err','file','') );
return;
}
}
else { return false; }
### Create the record
$type = "add";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$id = $db->add($VAR, $this, $type);
### Copy the uploaded file, or exit if fail:
if($lt == 0) {
if(isset($id) && $id > 0) {
if(!copy($_FILES['upload_file']['tmp_name'], PATH_FILES . 'file_'.$id.'.dat')) {
$C_debug->alert( $C_translate->translate('copy_file_err','file','') );
}
}
unlink($_FILES['upload_file']['tmp_name']);
}
}
##############################
## 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)
{
$type = "update";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$db->update($VAR, $this, $type);
}
##############################
## DELETE ##
##############################
function delete($VAR)
{
$db = &DB();
$id = $this->table . '_id';
# generate the list of ID's
$id_list = '';
$ii=0;
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($id[$i] != '')
{
if($i == 0)
{
$id_list .= " id = " . $db->qstr($id[$i]) . " ";
$ii++;
}
else
{
$id_list .= " OR id = " . $db->qstr($id[$i]) . " ";
$ii++;
}
}
}
if($ii>0)
{
# generate the full query
$q = "DELETE FROM
".AGILE_DB_PREFIX."$this->table
WHERE
$id_list
AND
site_id = " . DEFAULT_SITE;
$result = $db->Execute($q);
# error reporting
if ($result === false) {
global $C_debug;
$C_debug->error('file.inc.php','delete', $db->ErrorMsg());
} else {
for($i=0; $i<count($id); $i++) {
if($id[$i] != '') {
error_reporting(0);
unlink(PATH_FILES . 'file_'.$id[$i].'.dat');
$error_reporting_eval = 'error_reporting('.ERROR_REPORTING.');';
eval($error_reporting_eval);
}
}
# Alert delete message
global $C_debug, $C_translate;
$C_translate->value["CORE"]["module_name"] = $C_translate->translate('name',$this->module,"");
$message = $C_translate->translate('alert_delete_ids',"CORE","");
$C_debug->alert($message);
}
}
}
##############################
## 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);
}
}
?>

View File

@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<construct>
<!-- define the module name -->
<module>file</module>
<!-- define the module table name -->
<table>file</table>
<!-- define the module dependancy(s) -->
<dependancy></dependancy>
<!-- define the DB cache in seconds -->
<cache>0</cache>
<!-- define the default order_by field for SQL queries -->
<order_by>sort_order</order_by>
<!-- define the methods -->
<limit>35</limit>
<!-- 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>
<date_orig>
<type>I8</type>
<convert>date-now</convert>
</date_orig>
<date_last>
<type>I8</type>
<convert>date-now</convert>
</date_last>
<date_start>
<type>I8</type>
<convert>date</convert>
</date_start>
<date_expire>
<type>I8</type>
<convert>date</convert>
</date_expire>
<file_category_id>
<type>I4</type>
<asso_table>file_category</asso_table>
<asso_field>name</asso_field>
<index>1</index>
</file_category_id>
<type>
<type>C(32)</type>
</type>
<size>
<type>I8</type>
</size>
<name>
<type>C(255)</type>
<min_len>1</min_len>
<max_len>255</max_len>
<validate>any</validate>
</name>
<description>
<type>X2</type>
</description>
<status>
<type>L</type>
</status>
<location>
<type>C(255)</type>
</location>
<location_type>
<type>L</type>
</location_type>
<sort_order>
<type>I4</type>
</sort_order>
<group_avail>
<type>C(255)</type>
<convert>array</convert>
<validate>any</validate>
</group_avail>
</field>
<!-- define all the methods for this class, and the fields they have access to, if applicable. -->
<method>
<add>id,site_id,group_avail,date_orig,date_last,date_start,date_expire,file_category_id,type,size,name,description,status,location,location_type,sort_order</add>
<update>id,site_id,group_avail,date_orig,date_last,date_start,date_expire,file_category_id,type,size,name,description,status,location,location_type,sort_order</update>
<delete>id,site_id,group_avail,date_orig,date_last,date_start,date_expire,file_category_id,type,size,name,description,status,location,location_type,sort_order</delete>
<view>id,site_id,group_avail,date_orig,date_last,date_start,date_expire,file_category_id,type,size,name,description,status,location,location_type,sort_order</view>
<search>id,site_id,group_avail,date_orig,date_last,date_start,date_expire,file_category_id,type,size,name,description,status,location,location_type,sort_order</search>
</method>
<!-- define the method triggers -->
<trigger>0</trigger>
</construct>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<install>
<!-- Define the main module properties -->
<module_properties>
<name>file</name>
<parent>file</parent>
<notes>This module allows you to manage your downloadable files and permissions.</notes>
<menu_display>1</menu_display>
<dependancy></dependancy>
<sub_modules>file_category</sub_modules>
</module_properties>
<!-- Define any methods for this module -->
<sql_inserts>
<module_method>
<search>
<name>search</name>
<notes>Allow users to view the search form</notes>
<page>%%:search_form</page>
<menu_display>1</menu_display>
</search>
<view>
<name>view</name>
<notes>Allow users to view records</notes>
<page>core:search&amp;module=%%&amp;_escape=1&amp;_next_page_one=view</page>
<menu_display>1</menu_display>
</view>
<add>
<name>add</name>
<notes>Allow users to add records</notes>
<menu_display>1</menu_display>
</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>Allow users to view the search results</notes>
</search_show>
</module_method>
</sql_inserts>
</install>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<install>
</install>