<?php
// +---------------------------------------------------------------------------------------+
// | TenderSystem                                                                          |
// +---------------------------------------------------------------------------------------+
// | The contents of this file are subject to the TenderSystem Public License Version 1.1  |
// | ("License"); you may not use this file except in compliance with the License. You may |
// | obtain a copy of the License at http://www.tendersystem.com/tpl/                      |
// |                                                                                       |
// | Software distributed under the License is distributed on an "AS IS" basis, WITHOUT    |
// | WARRANTY OF ANY KIND, either express or implied. See the License for the specific     |
// | language governing rights and limitations under the License.                          |
// |                                                                                       |
// | All copies of the Covered Code must include the "Powered by TenderSystem" logo and    |
// | ValueCard copyright notice on every user interface screen and in every outgoing       |
// | email in the same form as they appear in the distribution.                            |
// |                                                                                       |
// | The Original Code is: TenderSystem                                                    |
// | The Initial Developer of the Original Code is ValueCard (Pty) Limited.                |
// | Portions created by ValueCard are Copyright (C) 2002 ValueCard (Pty) Limited.         |
// | All Rights Reserved.                                                                  |
// | Contributor(s): __________________.                                                   |
// +---------------------------------------------------------------------------------------+

/**
* Award tender
* @package TenderSystem
* @subpackage tender
* @copyright Copyright &copy; 2002, ValueCard (Pty) Ltd
* @license http://www.tendersystem.com/tpl/ TenderSystem Public License
* @version 
*/

if(!$cfg['tender']['enable']) {
	// e54 - Tender module is disabled
	xml_generator("tender","error","e54",$params,$cfg);
}
// field request errors and type 
$fields_request = array (
	'submit'	=> array(),	
	'award'		=> array()
);
get_request($fields_request,$action,$error,$cfg);
if ($action['submit']) {
	// field request errors and type 
	$fields_request = array (
		'tender_item'	=> array("e45"),
		'noinstall'		=> array(),
		'nodeliver'		=> array()
	);
	if(get_request($fields_request,$info,$error,$cfg)) {
		// create session for awarding
		$_SESSION['ts_award_item'] = $info['tender_item'];
		// set parameters
		$params = array(
			'module'		=> 'tender',
			'function'		=> 'award',
			'nodeliver'		=> $info['nodeliver'],
			'tender_item'	=> $info['tender_item'],
			'noinstall'		=> $info['noinstall']
		);
		// send the message to app
		send_message($params,$cfg);
	} else {
		// error
		xml_generator("tender","error",$error,"",$cfg);
	}
} elseif($action['award']) {
	if($_SESSION['ts_award_item']) {
		// set parameters
		$params = array(
			'module'	=> 'tender',
			'function'	=> 'award'
		);
		// field request errors and type 
		$fields_request = array (
			'award_item'			=> array(),
			'title'					=> array(),
			'surname'				=> array(),
			'phone_work'			=> array(),
			'phone_mobile'			=> array(),
			'email'					=> array(),
			'address'				=> array(),
			'preference'			=> array(),
			'excess'				=> array(),
			'reason'				=> array(),
			'comment'				=> array(),
			'cashamount'			=> array(),
			'cash'					=> array(),
			'nontendername'			=> array(),
			'nontenderamount'		=> array(),
			'nontender'				=> array(),
			'invalidate'			=> array(),
			'message'				=> array(),
			'usersid'				=> array(),
			'invalidatetender_item'	=> array(),
			'cashtender_item'		=> array(),
			'nontender_item'		=> array(),
			'ccpoclient'			=> array(),
			'collectsalvage'		=> array()
		);
		get_request($fields_request,$params,$error,$cfg);
		// remove session of awarding
		unset($_SESSION['ts_award_item']);
		// send the message to app
		send_message($params,$cfg);
	} else {
		// resubmit
		$errors[] = "e12";
		xml_generator("tender","error",$errors,"",$cfg);
	}
} else {
	$errors[] = "e13";
	// generate error
	xml_generator("tender","error",$errors,"",$cfg);
}
?>