Edit time limits, for the lose.
Here's another update, feedback is muchly appreciatory.
PHP Code:
<?php
class product_fields{
function __construct(){
}
function __destruct(){
}
function admin_view_edit(){
global $db;
$output = array();
$output[]="<b>Edit this Categories Product's fields</b><form action='' method='POST'><br>Add Fields<br><select name='addfield'>";
$sql = "select pf.name,pfa.id from product_fields_assign pfa, product_fields pf where pfa.category_id=$category_id and pfa.product_fields_id=pf.id group by pf.id";
$p = $db->Execute($sql);
while(!$p->EOF){
$output[]="<option value='".$p->fields['id']."'>".$p->fields['name']."</option>";
$p->MoveNext();
}
$output[]="</select><br><b>Remove Fields</b><br><select name='remove fields'>";
$p->MoveFirst();
while(!$p->EOF){
$output[]="<option value='".$p->fields['id']."'>".$p->fields['name']."</option>";
$p->MoveNext();
}
$output[]="</select></form>";
return $output;
}
function admin_view_admin(){
global $db;
$output = array();
$output[]=<<<SCRIPT
<script type="javascript">
var updateids = Array('fadd','fedit','fdelete','vadd','vedit','vdelete');
var commandurl = 'includes/productfields.php?c=';
function sendCmnd(){
var url = encodeURIComponent(commandurl + this.id);
new Ajax.Request(url, {
method: 'post',
onSuccess: function(transport) {
var notice = $('notice');
notice.update(transport.responseText);
}
});
}
function init(){
for(i in updateids){
updateids[i].onSubmit=sendCmnd;
}
}
onload=init;
</script>
SCRIPT;
$output[] = "<div id='notice'></div>";
$output[]="<b>Admin Product Fields -- Add</b>
<form id='fadd' action='' method='POST'>
Name: <input type='text' name='name'><br>
Type: <select name='type'>
<option value=0>Dropdown</option>
<option value=1>Text</option>
</select><br>
<br><input type='submit' value='Add'>
</form>
";
$output[]="<b>Admin Product Fields -- Edit</b>
<form id='fedit' action='' method='POST'>
Field: <select name='id'>
</select><br>
Type: <select name='type'>
<option value=0>Dropdown</option>
<option value=1>Text</option>
</select><br>
Name: <input type='text' name='name'><br>
<input type='submit' value='Update'><br>
</form>
";
$output[]="<b>Admin Product Fields -- Delete</b>
<form id='fdelete' action='' method='POST'>
Field: <select name='id'>
</select>
<input type='submit' value='Delete'>
</form>
";
$output[]="<b>Admin Product Values -- Add</b>
<form id='vadd' action='' method='POST'>
Field: <select name='id'>
</select><br>
Value to Add: <input type='text' name='value'><br>
<input type='submit' value='Add'>
</form>
";
$output[]="<b>Admin Product Values -- Edit</b>
<form id='vedit' action='' method='POST'>
Field: <select name='id'>
</select><br>
A New Value: <input type='text' name='value'><br>
<input type='submit' value='Edit'>
</form>
";
$output[]="<b>Admin Product Values -- Delete</b>
<form id='vdelete' action='' method='POST'>
Field: <select name='id'>
</select>
Field Value: <select name='id'>
</select>
<input type='submit' value='Delete'>
</form>
";
$sql = "select pf.name,pfa.id,pv.value from product_fields_assign pfa, product_fields pf, product_values pv where pfa.category_id=$category_id and pv.products_fields_id=pf.id and pfa.product_fields_id=pf.id";
$p = $db->Execute($sql);
while(!$p->EOF){
$output[]="<option value='".$p->fields['id']."'>".$p->fields['name']."</option>";
$p->MoveNext();
}
$output[]="<b>Edit Product Fields</b><form action='' method='POST'><br>Add Fields<br><select name='addfield'>";
$output[]="<b>Delete Product Fields</b><form action='' method='POST'><br>Add Fields<br><select name='addfield'>";
$output[]="</select></form>";
return $output;
}
function admin_view_products_edit($products_id){
global $db;
//Select Categories
$sql = "select categories id where products_id=$products_id";
$r = $db->Execute($sql);
$categories = array();
$ouput='';
while(!$r->EOF){
$categories[] = $r->fields('categories_id');
$r->MoveNext();
}
//Select the list of fields applying to this product or category
foreach($categories as $k=>$v){
$sql = "select p.*,v.* from product_fields p, product values v, product_fields_assign where p.id=v.products_fields_id and p.id=pv.products_fields_id and (pv.productsid=$products_id or pv.categories_id=$categories_id)";
$r = $db->Execute($sql);
$type = get_type_input_text($r->fields('type_id'));
while(!$r->EOF){
$sql = "select * product_fields_state where id={$r->fields('id')}";
}
$output.="{$r->fields('name')}: <input type='$type' name='id_{$r->fields('id')}' value='{$r->fields('value')}'><br>";
if($type==0){
$sql = "select * from product_fields p, product";
$e = $db->Execute($sql);
$output.="<select name=''>";
while(!$e->EOF){
$output.="<option value='type'></option>";
}
$output.="</select>";
}
}
$output.="<input type='submit' value='submit'>";
return $output;
}
function get_type_input_text($type_id){
$type='';
switch ($type_id){
case 0:
$type='dropdown';
break;
case 1:
$type='text';
break;
}
return $type;
}
function admin_fields_list($categories_id,$products_id=null){
global $db;
$sql = "select * from product_fields_assign where products_id=$products_id or categories_id=$categories_id'";
$r = $db->Execute($sql);
$output = '';
while(!$r->EOF){
$sql = "select * from product_fields where id=".$r->fields('id');
$e = $db->Execute($sql);
$ouput.="<option value='{$e->fields('id')}'>{$e->fields('name')}</option>";
$r->MoveNext();
}
return $output;
}
function admin_values_list($product_fields_id){
global $db;
$sql = "select * from product_values where products_fields_id=$products_fields_id)";
$r = $db->Execute($sql);
$output = '';
while(!$r->EOF){
$ouput.="<option value='{$r->fields('id')}'>{$r->fields('value')}</option>";
$r->MoveNext();
}
return $output;
}
function admin_fields_add(){
global $db;
$sql = "insert into product_fields values(NULL,$_POST[type_id],'$_POST[name]')";
$r = $db->Execute($sql);
}
function admin_fields_edit(){
global $db;
}
function admin_fields_delete(){
global $db;
}
function admin_values_add(){
global $db;
}
function admin_values_edit(){
global $db;
}
function admin_values_delete(){
global $db;
}
}
?>
PHP Code:
create table product_fields (
id int unsigned not null auto_increment,
type_id int unsigned not null, -- 0 = dropdown 1 = text
name varchar(35) not null,
primary key(id),
index (name)
);
create table product_values (
id int unsigned not null auto_increment,
products_fields_id int unsigned not null,
value varchar(35)
primary key(id),
index (value),
index (products_fields_id,category_id)
);
create table product_fields_state (
id int unsigned not null auto_increment,
products_id int unsigned not null,
product_fields_id int unsigned not null,
product_value_id int unsigned not null default 0,
text_value varchar(255) not null default '',
primary key(id),
index(products_id,product_fields_id,product_value_id),
index(text_value)
)
create table product_fields_assign (
id int unsigned not null auto_increment,
products_id int unsigned not null default 0,
categories_id int unsigned not null default 0,
products_fields_id int unsigned not null,
primary key(id),
index (products_id,category_id,products_fields_id)
);
Bookmarks