<?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 Giftcard extends AppModel

{

   var $name 	= 'Giftcard';

 

  

  ###### Function toget average rating f a product.............

 	function getTableName($tablename)

		 {

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

			$tblnme = $Db->fullTableName($tablename);			

			$tblnme=trim(str_replace('`','',$tblnme));		

			return $tblnme;

		}

	

	function generateCardid()

		 {

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

			$gfdetbl = $Db->fullTableName('giftcard_details');

			$gfdetbl=trim(str_replace('`','',$gfdetbl));	

			$randid=rand(100000,100000000000000); 		

			$res=$this->query("SELECT id FROM $gfdetbl WHERE card_code = '".$randid."'");

			if(isset($res[0][$gfdetbl]["id"]) && $res[0][$gfdetbl]["id"] <> '')

			{

			  generateCardid();

			}

			else

			{

			  return $randid;

			}		

		}	

		

		function updateCardStock($cid,$qty){

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

			$gftbl = $Db->fullTableName('giftcards');

			$this->query("UPDATE $gftbl SET stock = stock - ".$qty." WHERE id = ".$cid);

			return true;

		}	

}

?>