<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/

// +----------------------------------------------------------------------+

// | PHP version 4/5                                                      |

// +----------------------------------------------------------------------+

// | Copyright (c) 2004-2010 ARMIA INC                                    |

// +----------------------------------------------------------------------+

// | This source file is a part of iScripts VistaCart                     |

// +----------------------------------------------------------------------+

// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |

// +----------------------------------------------------------------------+

class Customfield extends AppModel



{



   var $name = 'Customfield';



   var $hasMany = array('Productcustomfields'); 



   function delcusnam($nam){



   		$Db = ConnectionManager::getDataSource($this->useDbConfig);



		$cftbl = $Db->fullTableName('customfields');



		$pcfttbl = $Db->fullTableName('productcustomfields');



		$this->query("DELETE c.*, p.* FROM $cftbl c LEFT JOIN $pcfttbl p ON c.id = p.customfield_id WHERE c.custom_name = '$nam'");



		return  true;



   }



   function delcusval($delid){



   		$Db = ConnectionManager::getDataSource($this->useDbConfig);



		$cftbl = $Db->fullTableName('customfields');



		$this->query("DELETE from $cftbl WHERE `id` =".$delid);



		return  true;



   }



      function updatecusval($customname,$editid){



   		$Db = ConnectionManager::getDataSource($this->useDbConfig);



		$cftbl = $Db->fullTableName('customfields');	

                
		$this->query("UPDATE $cftbl SET `custom_name` = '".addslashes($customname)."' WHERE `id` =".$editid);



		return  true;



   }

   

    function checkeditDups($customname,$editid){

   		$Db = ConnectionManager::getDataSource($this->useDbConfig);

		$cftbl = $Db->fullTableName('customfields');	

		$res=$this->query("SELECT count(*)  as dups from $cftbl WHERE `custom_name` ='".addslashes($customname)."' and `id`<>".$editid);

		return $res[0][0]["dups"];

   }



}



?>