<?php
/*
  $Id: catalog/admin/includes/functions/proforma_data_access.php, 20:57:52 NCB Exp $
 	Proforma v1.0 PLUS (Shareware Version)
 	COPYRIGHT (c) 2008 OPEN SOURCE SERVICES. ALL RIGHTS RESERVED.
  Support and Forum at http://www.open-source-services.com/Forum/Proforma-PF-v1.0-PLUS-Shareware-Version-osCommerce/
  Upgrade at http://www.open-source-services.com/Products/OSS-Premium-Add-Ons/Proforma-v1.0-PLUS.html?flypage=0
*/
function getFormContent($name) {
	
	$pf_query_raw = "select * from 	pf_content where pf_name= '" . $name . "'";
	$pf_query = tep_db_query($pf_query_raw);
	$arr_pf_query = tep_db_fetch_array($pf_query);
	if(!$arr_pf_query) {
		return '';
	} else {
		return $arr_pf_query['content'];
	}
}

function saveUnitContent($name, $content) {
	
	$pf_query_raw = "select * from 	pf_content where pf_name= '" . $name . "'";
	$pf_query = tep_db_query($pf_query_raw);
	$arr_pf_query = tep_db_fetch_array($pf_query);
	if(!$arr_pf_query) {
		tep_db_query("insert into pf_content (pf_name, content) values ('" . tep_db_prepare_input($name) . "', '" . $content . "')");		
	} else {
		tep_db_query("update 	pf_content set pf_name='" . tep_db_prepare_input($name) . "',content='" . $content . "'" . " where pf_name= '" . $name . "'");
	}
	
}

function getAllFormsAndContent() {
	$pf_query_raw = "select * from 	pf_content order by pf_name";
	return tep_db_query($pf_query_raw);
}

function delUnit($name){
	tep_db_query("delete from pf_content where pf_name = '" . $name . "'");
}

function saveUnitSettings($arr_settings){
	$pf_query_raw = "select * from pf_content where pf_name= '" . $arr_settings['pf_name'] . "'";
	$pf_query = tep_db_query($pf_query_raw);
	$arr_pf_query = tep_db_fetch_array($pf_query);

	if(!$arr_pf_query) {
		tep_db_query("insert into	pf_content (pf_name, pf_group, description, position, pages, placement, pf_type, active) values ('" . tep_db_prepare_input($arr_settings['pf_name']) . "', '" . tep_db_prepare_input($arr_settings['pf_group']) . "', '" . tep_db_prepare_input($arr_settings['description']) . "', '" . tep_db_prepare_input($arr_settings['position']) . "', '" . tep_db_prepare_input($arr_settings['pages']) . "', '" . tep_db_prepare_input($arr_settings['placement']) . "', '" . tep_db_prepare_input($arr_settings['pf_type']) . "', '" . tep_db_prepare_input($arr_settings['active']) . "')");		
	} else {
		tep_db_query("update pf_content set pf_name='" . tep_db_prepare_input($arr_settings['pf_name']) . "',pf_group='" . tep_db_prepare_input($arr_settings['pf_group']) . "',description='" . tep_db_prepare_input($arr_settings['description']) . "',position='" . tep_db_prepare_input($arr_settings['position']) . "',pages='" . tep_db_prepare_input($arr_settings['pages']) . "',placement='" . tep_db_prepare_input($arr_settings['placement']) . "',pf_type='" . tep_db_prepare_input($arr_settings['pf_type']) . "',active='" . tep_db_prepare_input($arr_settings['active']) . "'" . " where pf_name= '" . $arr_settings['pf_name'] . "'");
	}
}

function getAllPositions() {
	$pf_query_raw = "select * from pf_positions";
	$pf_query = tep_db_query($pf_query_raw);
	if(!tep_db_fetch_array($pf_query)) {
		return 0;
	} else {
		mysql_data_seek($pf_query,0);
		return $pf_query;
	}
}

function deletePosition($name){
	$pf_query_raw = "delete from pf_positions where pos_name='" . $name . "'";
	tep_db_query($pf_query_raw);
}

function saveNewPosition($name) {
	
	$pf_query_raw = tep_db_query("select * from pf_positions where pos_name='" . $name . "'");  			
	if(!tep_db_fetch_array($pf_query_raw)) {
		tep_db_query("insert into pf_positions (pos_name,deployed,in_use) values ('". $name ."','". PF_NO ."','". PF_NO ."')");
	}
}

function positionInUse($pos_name){
	$pf_query_raw = "select * from 	pf_content where position='" . $pos_name . "'";
	$pf_query = tep_db_query($pf_query_raw);
	if(!tep_db_fetch_array($pf_query)) {
		return false;
	} else {
		return true;
	}
}
?>