<?php
/**
 * File handling the receive bugs
 *
 * @category	Anova
 * @package		BugHandler
 * @author 		senthil_52ag05
 * @copyright 	Copyright (c) 2009 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id: $
 * @since 		2009-01-05
 */
/**
 * File having common configuration variables required for the entire project
 */
require_once('./common/configs/config.inc.php'); //configurations
$CFG['html']['header'] = 'general/html_header.php';
$CFG['html']['footer'] = 'general/html_footer.php';
//compulsory
$CFG['mods']['is_include_only']['html_header'] = false;
$CFG['html']['is_use_header'] = false;
/**
 * To include application top file
 */
require($CFG['site']['project_path'].'common/application_top.inc.php');
//-------------- Class passwordUpdaterFormHandler begins --------------->>>>>//

class receiveBugs extends FormHandler
	{
		public function insertBugs()
			{
				$sql = 'INSERT INTO '.$this->CFG['db']['tbl']['bugs'].' SET'.
						' bug_content = '.$this->dbObj->Param('bug_content').','.
						' parent_id = '.$this->dbObj->Param('parent_id').','.
						' reply_from = '.$this->dbObj->Param('sitename').','.
						' date_added = NOW()';

				$data_ar = array($this->getFormField('bcontent'), $this->getFormField('bid'),  $this->getFormField('sitename'));

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, $data_ar);
				    if (!$rs)
					    trigger_db_error($this->dbObj);
			}

		public function chkIsValidInput()
			{
				if($this->getFormField('bsite') != $this->CFG['site']['url'])
					{
						return false;
					}
				$sql = 'SELECT 1 FROM '.$this->CFG['db']['tbl']['bugs'].' WHERE'.
						' bug_id = '.$this->dbObj->Param('bug_id').' AND'.
						' secret_key = '.$this->dbObj->Param('secret_key');

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->getFormField('bid'), $this->getFormField('skey')));
				    if (!$rs)
					    trigger_db_error($this->dbObj);

				if($rs->PO_RecordCount())
					{
						return true;
					}
				return false;
			}
	}

//<<<<<-------------- Class passwordUpdater FormHandler begins ---------------//
//-------------------- Code begins -------------->>>>>//
$receiveBugs = new receiveBugs();
$receiveBugs->setPageBlockNames(array());
//default form fields and values...
$receiveBugs->setFormField('bid', '');
$receiveBugs->setFormField('bcontent', '');
$receiveBugs->setFormField('bsite', '');
$receiveBugs->setFormField('skey', '');
$receiveBugs->setFormField('sitename', '');

$receiveBugs->sanitizeFormInputs($_REQUEST);
//write_file('test.txt', serialize($_REQUEST));

$receiveBugs->chkIsNotEmpty('bid', $receiveBugs->LANG['err_tip_compulsory']);
$receiveBugs->chkIsNotEmpty('bcontent', $receiveBugs->LANG['err_tip_compulsory']);
$receiveBugs->chkIsNotEmpty('bsite', $receiveBugs->LANG['err_tip_compulsory']);
$receiveBugs->chkIsNotEmpty('skey', $receiveBugs->LANG['err_tip_compulsory']);
$receiveBugs->chkIsNotEmpty('sitename', $receiveBugs->LANG['err_tip_compulsory']);

if ($receiveBugs->isValidFormInputs() and $receiveBugs->chkIsValidInput())
	{
		$receiveBugs->insertBugs();
	}
?>