if (typeof(script_root) == "undefined") { var script_root = ''; } function shop_init() { //.. } /*---- admin functions ----*/ var plugin_shop_admin_item_id = 0; var plugin_shop_images = new Array(); function plugin_shop_admin_item_list() { document.getElementById('plugin_shop_admin').innerHTML = '

Loading Products...

'; var url = script_root+'plugins/shop/ajax.php?action=list'; var http = AJAX_obj(); http.open("GET", url, true) http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { var htmlstr = '', i, j, k, l, items = http.responseText.split("]/*delim_item[*/"), data, subdata, subitem; var relation_field_idx = new Array(7,8,9,10,11); var relation_field_name = new Array('category','price','image','link','review'); htmlstr += '

Products List

'; if (http.responseText!='' && items.length > 0) { htmlstr += ''; htmlstr += ''; htmlstr += ' '; htmlstr += ' '; htmlstr += ' '; htmlstr += ' '; htmlstr += ' '; htmlstr += ' '; htmlstr += ''; for (i=0;i=3) { htmlstr += ''; htmlstr += ' '; htmlstr += ' '; htmlstr += ' '; htmlstr += ' '; htmlstr += ' '; /* //relation fields for (l=0;l[remove]
'; } } } htmlstr += ' add '+relation_field_name[l]+''; } //edit buttons htmlstr += '
'; */ htmlstr += ''; htmlstr += ''; } } htmlstr += '
codenamekeywordsmanufacturerstatusfeatured? 
'+data[1]+''+data[2]+''+data[3]+''+data[4]+''+data[5]+''+data[6]+'edit | delete'; htmlstr += 'categories  '; htmlstr += 'prices  '; htmlstr += 'images  '; htmlstr += 'links  '; htmlstr += 'reviews  '; htmlstr += 'edit  '; htmlstr += 'delete'; htmlstr += '
'; htmlstr += '

Total: '+items.length+'

'; } else { htmlstr += '

no product added yet.

'; } htmlstr += '

add new product

'; document.getElementById('plugin_shop_admin').innerHTML = htmlstr } } http.send(); } function plugin_shop_admin_item_form(id) { plugin_shop_admin_item_id = id; var htmlstr = ''; htmlstr += ''; htmlstr += ''; htmlstr += ''; htmlstr += ''; htmlstr += ''; htmlstr += ''; htmlstr += ''; htmlstr += ''; htmlstr += ''; htmlstr += '
code
name
summary
detail
keywords
manufacturer
status
is_featured?
'; if (id) { htmlstr = '

Editing Product

' + htmlstr htmlstr += '

 

'; document.getElementById('plugin_shop_admin').innerHTML = htmlstr var url = script_root+'plugins/shop/ajax.php?action=info&id='+id; var http = AJAX_obj(); http.open("GET", url, true) http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { var i, data = http.responseText.split("]/*delim_data[*/"); document.getElementById('plugin_shop_input_code').value = data[1]; document.getElementById('plugin_shop_input_name').value = data[2]; document.getElementById('plugin_shop_input_descp').value = data[7]; document.getElementById('plugin_shop_input_detail').value = data[8]; document.getElementById('plugin_shop_input_keywords').value = data[3]; document.getElementById('plugin_shop_input_manufacturer').value = data[4]; document.getElementById('plugin_shop_input_status').value = data[5]; document.getElementById('plugin_shop_input_is_featured').checked = (parseInt(data[6])==1?true:false); } } http.send(); } else { htmlstr = '

Adding New Product

' + htmlstr htmlstr += '

 

'; document.getElementById('plugin_shop_admin').innerHTML = htmlstr } } function plugin_shop_admin_item_add() { plugin_shop_admin_item_save('add'); } function plugin_shop_admin_item_edit() { plugin_shop_admin_item_save('edit'); } function plugin_shop_admin_item_save(action) { var url = script_root+'plugins/shop/ajax.php?action=process'; var params = ''; params += '&form_action='+action; params += '&id='+plugin_shop_admin_item_id; params += '&code='+post_escape(document.getElementById('plugin_shop_input_code').value); params += '&name='+post_escape(document.getElementById('plugin_shop_input_name').value); params += '&descp='+post_escape(document.getElementById('plugin_shop_input_descp').value); params += '&detail='+post_escape(document.getElementById('plugin_shop_input_detail').value); params += '&keywords='+post_escape(document.getElementById('plugin_shop_input_keywords').value); params += '&manufacturer='+post_escape(document.getElementById('plugin_shop_input_manufacturer').value); params += '&status='+document.getElementById('plugin_shop_input_status').value; params += '&is_featured='+(document.getElementById('plugin_shop_input_is_featured').checked?1:0); var http = AJAX_obj(); http.open("POST", url, true) http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange = function() { if(http.readyState == 4) { if (http.status == 200) { if (http.responseText=='success') { alert('Changes successfully saved!'); plugin_shop_admin_item_list(); } else { plugin_shop_admin_item_list(); if (http.responseText) { alert(http.responseText); } else { alert('Something is wrong with the system. Please try again later.'); } plugin_shop_admin_item_list(); } } else { alert('Ajax Status: '+http.status); plugin_shop_admin_item_list(); } } } http.send(params); } function plugin_shop_admin_item_delete(id,descp) { if (confirm("Are you sure you want to delete '"+descp+"'?")) { plugin_shop_admin_item_id = id; var action = 'delete'; var url = script_root+'plugins/shop/ajax.php?action=process'; var params = ''; params += '&form_action='+action; params += '&id='+plugin_shop_admin_item_id; var http = AJAX_obj(); http.open("POST", url, true) http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange = function() { if(http.readyState == 4) { if (http.status == 200) { if (http.responseText=='success') { alert('Item Deleted!'); plugin_shop_admin_item_list(); } else { plugin_shop_admin_item_list(); if (http.responseText) { alert(http.responseText); } else { alert('Something is wrong with the system. Please try again later.'); } plugin_shop_admin_item_list(); } } else { alert('Ajax Status: '+http.status); plugin_shop_admin_item_list(); } } } http.send(params); } } function plugin_shop_admin_item_relation_list(relation_type,item_id,item_name) { plugin_shop_admin_item_id = item_id; document.getElementById('plugin_shop_admin').innerHTML = 'Please wait...'; var url = script_root+'plugins/shop/ajax.php?action=relation_list'; url += '&relation_type='+relation_type; url += '&id='+item_id; var http = AJAX_obj(); http.open("GET", url, true) http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { if (http.responseText.substr(0,6)=='error:') { alert(http.responseText); plugin_shop_admin_item_list(); } else { var i, aray = http.responseText.split(']/*delim_item[*/'), data, htmlstr = ''; if (http.responseText!='') { htmlstr += '

'+(relation_type=='category'?'categories':relation_type+'s')+' for '+item_name+'

'; htmlstr += ''; for (i=0;i'; htmlstr += ''; htmlstr += ''; } htmlstr += '
remove
'; } else { htmlstr += '

no '+(relation_type=='category'?'categories':relation_type+'s')+' added yet for '+item_name+'

'; } htmlstr += '

back to list | add new '+relation_type+' for '+item_name+'

'; document.getElementById('plugin_shop_admin').innerHTML = htmlstr; } } } http.send(); } function plugin_shop_admin_item_relation_add(relation_type,item_id,item_name) { plugin_shop_admin_item_id = item_id; var htmlstr = ''; var title = ''; htmlstr += ''; switch (relation_type) { case 'category': title = 'Add Category for '+item_name; htmlstr += ''; htmlstr += ''; var url = script_root+'plugins/shop/ajax.php?action=category_list'; var http = AJAX_obj(); http.open("GET", url, true) http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { var i, aray = http.responseText.split(']/*delim_item[*/'), data; var dropdown = document.getElementById('plugin_shop_admin_input_category'); dropdown.options.length = 0; for (i=0;i'; } htmlstr += '
Select from List:
or Add New Category:
'; document.getElementById('plugin_shop_admin_images').innerHTML = htmlstr; } } else if (http.status == 500) { document.getElementById('plugin_shop_admin_images').innerHTML = 'There seems to be a problem getting the images'; } } } http.send(); break; case 'link': title = 'Add Link for '+item_name; htmlstr += 'URL:'; htmlstr += 'Descp:'; break; case 'review': title = 'Add Review for '+item_name; htmlstr += 'Author:'; htmlstr += 'Message:'; break; default: alert('relation type unknown'); return false; } htmlstr += 'cancel | Add Now'; htmlstr += ''; htmlstr = '

'+title+'

'+htmlstr; document.getElementById('plugin_shop_admin').innerHTML = htmlstr; } function plugin_shop_admin_item_relation_delete(relation_type,relation_id,item_id,item_name) { if (confirm('Are you sure you want to remove this '+relation_type+' from '+item_name+'?')) { document.getElementById('plugin_shop_admin').innerHTML = 'Please wait...'; var url = script_root+'plugins/shop/ajax.php?action=delete_relation'; url += '&relation_type='+relation_type; url += '&relation_id='+relation_id; var http = AJAX_obj(); http.open("GET", url, true) http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { if (http.responseText!='success') { alert(http.responseText); } plugin_shop_admin_item_relation_list(relation_type,item_id,item_name); } } http.send(); } } function plugin_shop_admin_item_relation_process(relation_type) { var url = script_root+'plugins/shop/ajax.php?action=add_relation'; var params = ''; params += '&relation_type='+relation_type; params += '&id='+plugin_shop_admin_item_id; switch (relation_type) { case 'category': params += '&category_id='+escape(document.getElementById('plugin_shop_admin_input_category').value); params += '&category_new='+escape(document.getElementById('plugin_shop_admin_input_category_new').value); break; case 'price': params += '&variant='+escape(document.getElementById('plugin_shop_admin_input_variant').value); params += '&price='+escape(document.getElementById('plugin_shop_admin_input_price').value); break; case 'image': params += '&path='+escape(document.getElementById('plugin_shop_admin_input_path').value); params += '&caption='+escape(document.getElementById('plugin_shop_admin_input_caption').value); break; case 'link': params += '&url='+escape(document.getElementById('plugin_shop_admin_input_url').value); params += '&name='+escape(document.getElementById('plugin_shop_admin_input_name').value); break; case 'review': params += '&author='+escape(document.getElementById('plugin_shop_admin_input_author').value); params += '&message='+escape(document.getElementById('plugin_shop_admin_input_message').value); break; default: alert('releation type unknown'); return false; } var http = AJAX_obj(); http.open("POST", url, true) http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange = function() { if(http.readyState == 4) { if (http.status == 200) { if (http.responseText=='success') { alert(relation_type+' added!'); plugin_shop_admin_item_list(); } else { if (http.responseText) { alert(http.responseText); } else { alert('Something is wrong with the system. Please try again later.'); } plugin_shop_admin_item_list(); } } else { alert('Ajax Status: '+http.status); plugin_shop_admin_item_list(); } } } http.send(params); } function plugin_shop_admin_select_image(idx) { document.getElementById('plugin_shop_admin_input_path').value = plugin_shop_images[idx].replace(/\.\.\/\.\.\/site\/([a-z0-9-.]+)\//g,''); }