Initial Commit of AgileBill Open Source
This commit is contained in:
195
modules/product_img/product_img.inc.php
Normal file
195
modules/product_img/product_img.inc.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?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 product_img
|
||||
{
|
||||
|
||||
# Open the constructor for this mod
|
||||
function product_img()
|
||||
{
|
||||
# name of this module:
|
||||
$this->module = "product_img";
|
||||
|
||||
# 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)
|
||||
{
|
||||
global $_FILES, $C_translate, $C_debug;
|
||||
|
||||
$imgarr = Array('jpeg','jpg','gif','bmp','tif','tiff','png');
|
||||
|
||||
if(isset($_FILES['upload_file1']) && $_FILES['upload_file1']['size'] > 0)
|
||||
{
|
||||
for($i=0; $i<count($imgarr); $i++)
|
||||
{
|
||||
if(eregi($imgarr[$i].'$', $_FILES['upload_file1']['name']))
|
||||
{
|
||||
$filename = $imgarr[$i];
|
||||
$i = 10;
|
||||
}
|
||||
}
|
||||
if(empty($filename))
|
||||
{
|
||||
echo 'You must upload a image file (jpg,gif,bmp,tiff,png)';
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$VAR["product_img_name"] = $_FILES['upload_file1']['name'];
|
||||
$VAR["product_img_url"] = $filename;
|
||||
$VAR["product_img_type"] = "0";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(empty($VAR["img_url"]))
|
||||
{
|
||||
echo 'You must either upload a image or specify an image URL!';
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$VAR["product_img_name"] = $VAR["img_url"];
|
||||
$VAR["product_img_url"] = $VAR["img_url"];
|
||||
$VAR["product_img_type"] = "1";
|
||||
}
|
||||
}
|
||||
|
||||
$type = "add";
|
||||
$this->method["$type"] = split(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$result = $db->add($VAR, $this, $type);
|
||||
|
||||
# copy the image
|
||||
if($result && !empty($filename))
|
||||
{
|
||||
$file = 'prod_img_' . $result . '.' . $filename;
|
||||
copy($_FILES['upload_file1']['tmp_name'], PATH_IMAGES . "" . $file);
|
||||
}
|
||||
}
|
||||
|
||||
##############################
|
||||
## VIEW ##
|
||||
##############################
|
||||
function view($VAR)
|
||||
{
|
||||
$type = "view";
|
||||
$this->method["$type"] = split(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->view($VAR, $this, $type);
|
||||
}
|
||||
|
||||
|
||||
##############################
|
||||
## DELETE ##
|
||||
##############################
|
||||
function delete($VAR)
|
||||
{
|
||||
$db = &DB();
|
||||
|
||||
### Delete any saved images:
|
||||
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] != '')
|
||||
{
|
||||
# get the filetype
|
||||
$sql = 'SELECT url,type FROM ' . AGILE_DB_PREFIX . 'product_img WHERE
|
||||
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
|
||||
id = ' . $db->qstr($id[$i]);
|
||||
$result = $db->Execute($sql);
|
||||
if($result->RecordCount() > 0)
|
||||
{
|
||||
if($result->fields['type'] == "0")
|
||||
{
|
||||
unlink(PATH_IMAGES . 'prod_img_' . $id[$i] . '.' . $result->fields['url']);
|
||||
}
|
||||
|
||||
# delete the record
|
||||
$sql = 'DELETE FROM ' . AGILE_DB_PREFIX . 'product_img WHERE
|
||||
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
|
||||
id = ' . $db->qstr($id[$i]);
|
||||
$result = $db->Execute($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# 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 ##
|
||||
##############################
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
53
modules/product_img/product_img_construct.xml
Normal file
53
modules/product_img/product_img_construct.xml
Normal file
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
||||
<construct>
|
||||
<!-- define the module name -->
|
||||
<module>product_img</module>
|
||||
<!-- define the module table name -->
|
||||
<table>product_img</table>
|
||||
<!-- define the module dependancy(s) -->
|
||||
<dependancy>product</dependancy>
|
||||
<!-- define the DB cache in seconds -->
|
||||
<cache>0</cache>
|
||||
<!-- define the default order_by field for SQL queries -->
|
||||
<order_by>product_id</order_by>
|
||||
<!-- define the methods -->
|
||||
<limit>25</limit>
|
||||
<!-- define database indexes -->
|
||||
<index>
|
||||
<product>product_id</product>
|
||||
</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>
|
||||
<product_id>
|
||||
<type>I4</type>
|
||||
</product_id>
|
||||
<type>
|
||||
<type>L</type>
|
||||
</type>
|
||||
<url>
|
||||
<type>C(255)</type>
|
||||
</url>
|
||||
<name>
|
||||
<type>C(128)</type>
|
||||
</name>
|
||||
</field>
|
||||
<!-- define all the methods for this class, and the fields they have access to, if applicable. -->
|
||||
<method>
|
||||
<add>id,site_id,product_id,type,url,name</add>
|
||||
<update>id,site_id,product_id,type,url,name</update>
|
||||
<delete>id,site_id,product_id,type,url,name</delete>
|
||||
<view>id,site_id,product_id,type,url,name</view>
|
||||
<search>id,site_id,product_id,type,url,name</search>
|
||||
</method>
|
||||
<!-- define the method triggers -->
|
||||
<trigger>0</trigger>
|
||||
</construct>
|
30
modules/product_img/product_img_install.xml
Normal file
30
modules/product_img/product_img_install.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<install>
|
||||
<module_properties>
|
||||
<name>product_img</name>
|
||||
<parent>product</parent>
|
||||
<notes><![CDATA[This module maintains the product images and thumbnails.]]></notes>
|
||||
<dependancy>product</dependancy>
|
||||
</module_properties>
|
||||
<sql_inserts>
|
||||
<module_method>
|
||||
<search_show>
|
||||
<name>search_show</name>
|
||||
</search_show>
|
||||
<search>
|
||||
<name>search</name>
|
||||
</search>
|
||||
<view>
|
||||
<name>view</name>
|
||||
</view>
|
||||
<delete>
|
||||
<name>delete</name>
|
||||
</delete>
|
||||
<update>
|
||||
<name>update</name>
|
||||
</update>
|
||||
<add>
|
||||
<name>add</name>
|
||||
</add>
|
||||
</module_method>
|
||||
</sql_inserts>
|
||||
</install>
|
Reference in New Issue
Block a user