<?php
if ( !defined( 'SMARTY_DIR' ) ) {
	include_once( '../init.php' );
}

include ( 'sessioninc.php' );

define( 'PAGE_ID', 'section_mgt' );

if ( !checkAdminPermission( PAGE_ID ) ) {

	header( 'location: not_authorize.php' );
	exit;
}

if ($_POST['frm'] !='frmQuestionDetail'){

	$id 	= 	trim( $_POST['txtid'] );

	$answer	= 	$_POST['txtanswer'];

	$enable	= 	$_POST['txtenabled'];


	$err = 0;

	if ( $answer == '' ) {

		$err = FIELDS_BLANK;

	}

	if ( $err != 0 ) {

		header ( 'location: sectionquestiondetail.php?sectionid=' . $_POST['txtsectionid'] . '&edit=' . $_POST['txtid'] . '&errid=' . $err .'&questionid='.$_POST['questionid']);
		exit;

	}

	$osDB->query( 'UPDATE ! SET answer = ?, enabled = ?  WHERE id = ?' , array( OPTIONS_TABLE, $answer, $enable, $id ));

	header ( 'location: sectionquestiondetail.php?sectionid=' . $_POST['txtsectionid'] . '&edit=' . $_POST['txtid'].'&questionid='.$_POST['questionid'] );
} else {

	$arr = $_POST[ 'txtcheck' ];

	if ( $_POST['groupaction'] == get_lang('enable_selected') && count($arr) > 0) {

		foreach ( $arr as $id ) {

			$osDB->query( 'UPDATE ! SET enabled = ? WHERE id = ?', array( OPTIONS_TABLE , 'Y', $id ) );

		}

	} elseif ($_POST['groupaction'] == get_lang('disable_selected') && count($arr) > 0) {

		foreach ( $arr as $id ) {

			$osDB->query( 'UPDATE ! SET enabled = ? WHERE id = ?', array( OPTIONS_TABLE , 'N', $id ) );

		}

	}

	unset($arr);


	header ( "location: sectionquestiondetail.php?sectionid=" . $_POST['txtsectionid'] . "&questionid=" . $_POST['txtquestionid']);
}
?>