<?php
#
# Projeto :  Lucato
# Data : 10/02/2004
#
# ROBO pesquisa
#
		//*******************************************************************
		// INCLUDES nao alterar a ordem dos includes
		//*******************************************************************
		// INCLUDES SEPARADOS PARA TER A OPÇÃO DE MUDAR O WHERE
		// DA PESQUISA DE ACORDO COM O NIVEL DO USUARIO
		include "includes/database.php";
		include "includes/config.php";
		include "includes/functions.php";
		include "includes/htmlMimeMail.php";
		include "includes/permissao.php";
		include "includes/session.php";
		include "includes/modules.php";
		
		//armazernar o link para o botao cancelar das telas
		$last_url = $_SERVER["PHP_SELF"] . "?" .$_SERVER["QUERY_STRING"];
		set_session("LAST_URL", $last_url);

		//recuperar variaveis da tela
		//---------------------------------
		$mod = request("mod");
		$allwords = request("allwords");
		if ( ($allwords == "yes") ){
				$check = "checked";
		} else {
				$check = "";
		}

		$pesqinicial = request("pesqinicial");
		if ( ($pesqinicial == "yes") ){
				$pi = "checked";
		} else {
				$pi = "";
		}
		//fim------------------------------

	//---------------------------------------------
	//SOURCE
	//---------------------------------------------
	$query = request("query");
	$makesearch = request("makesearch");
	if ( $makesearch == "yes" ){
			if ( $modules[$mod]["include"] ) {
					include $modules[$mod]["include"];
			} 

			$navbar["url_default"] = "robo_pesquisa.php?" . show($sid_get) . "&mod=" . show($mod) . "&allwords=$allwords&pesqinicial=$pesqinicial";
			$navbar["max_row"] = 10;
			$navbar["max_page"] = 8;
	        $navbar["page"] = request("page");
			$navbar["action"] = request("action");

			$order = request("order");
			if( empty($order)  ) $order = $modules[$mod]["pesquisa_ordem"];

			$RESULT = get_dataset_search($DATABASE, $modules[$mod], $query , $navbar, request("allwords"), request("pesqinicial"), $order );
	}



		// começa a imprimir a tela
		include("includes/top_comum.php");
 		// Arquivo javascript com as consistencias da tela e o que precisar de java script
		//----------------------------------------------------------------------------------------------
		echo "<script type=\"text/javascript\" src=\"scripts/robo_pesquisa.js\"></script>";
?>
<script language="JavaScript">
		function set_pesquisa( form ) {
				if ( consiste( form ) ){
						if ( form.allwords.checked ) {
								var words = form.allwords.value;
						} else {
								var words = "";
						}
						if ( form.pesqinicial.checked ) {
								var pi = form.pesqinicial.value;
						} else {
								var pi = "";
						}
						document.location = 'robo_pesquisa.php?<?php echo $sid_get?>&mod=' + form.mod.value + '&order=' + form.order.value + '&mult_page_start=' + form.mult_page_start.value + '&rows=' + form.rows.value + '&query=' + form.query.value + '&allwords=' + words + '&pesqinicial=' + pi + '&makesearch=' + form.makesearch.value;
				}
				return false;
		}
</script>
		<!--FORMULARIO DE PESQUISA-->
<div class="row">
		<div class="col-xs-12 col-sm-7 col-md-7 col-lg-7">
			<h1 class="page-title txt-color-blueDark"><i class="fa-fw fa fa-desktop"></i> <?php echo show($modules[$mod]["pesquisa_titulo"]) ?> </h1>
		</div>
</div>
<div id="row">		
<form name="formpesquisa" action="robo_pesquisa.php" method="post" onsubmit="return set_pesquisa(this);" class="form-horizontal" role="form" >
		<?php echo $sid_post?><!--%este pode ser mostrado sem o show pois é um input%-->
		<input type="hidden" name="mod" value="<?php echo show($mod)?>">
		<input type="hidden" name="order" value="<?php echo request("order")?>">
		<input type="hidden" name="makesearch" value="yes">
		<!--<input type="hidden" name="page" value="<?//=request("page")?>">-->
		<input type="hidden" name="mult_page_start" value="<?php echo request("mult_page_start")?>">
		<input type="hidden" name="rows" value="<?php echo request("rows")?>">
		<div class="form-group">
			<div class="col-sm-6">
				<input type="text" name="query" value="<?php echo show(request("query"))?>" size="25" maxlength="30" class="form-control" placeholder="Digite a pesquisa aqui" style='height:45px'><br>
				<input type="checkbox" name="allwords" value="yes" <?php echo show($check)?> > Conter todas as palavras<br/>
				<input type="checkbox" name="pesqinicial" value="yes" <?php echo show($pi)?> > Pesquisa Inicial<br/>
			</div>	
			<div class="col-sm-1">
				<input type="submit" value="Pesquisar" class="btn btn-primary btn-lg" >
			</div>
		</div>
		
</form>
</div>
<div id="row">
<center>
	<div id="wait" >
	<a href="javascript:void(0);" class="btn bg-color-red txt-color-white"><i class="fa fa-gear fa-4x fa-spin"></i></a>
	<br><b>Aguarde enquanto a pesquisa é processada...</b><br>
	</div>
<center>	
</div>
<? include("includes/mensagem_erro.php"); ?>
<br/>
<div id="resultado">
<?
	if ( $makesearch == "yes" ){
?>
			<!-- Resultado da Pesquisa solicitada -->
			<div class="mensagem">Resultado: encontrado(s) <b><?php echo show($navbar["rows"])?></b> registro(s) com a(s) palavra(s) <b><?php echo show($query)?></b></div><br/>


<?php
			echo "<div class=\"text-center\">". $navbar["url_nav"] . "</div>";

			while ( $RESULT->NEXT() ) {
					// aqui vai o  design personalizado
					include $mod . "/pesquisa.php";
			}

			$RESULT->FREE();

			echo "<div class=\"text-center\">". $navbar["url_nav"] . "</div>";
	}
?>
<br/>
<br/>
</div>
<!-- Modal de Alerta -->
<div class="modal fade" id="basicModal_boletim" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
									<h4 class="modal-title" id="myModalLabel">Alerta</h4>
							</div>
							<div class="modal-body" >
								Para disparar o Boletim você deve primeiro ter uma fila de envio do mesmo, siga os passos:<br>
								-Clique em 'Detalhe' <br> 
								-Clique em 'Alterar' <br> 
								-Marque as áreas do Boletim e clique em 'Salvar Registro'	
								<br>
							</div>
							<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
							</div>
						</div>
					</div>
</div>
<!-- Modal de Alerta -->
<? include("includes/bottom_comum.php"); ?>

