Custom code

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
halexoliveira
User
Posts: 8

Custom code

Post by halexoliveira »

I need put a filter in add page. Follow:

public function MySQL($query){
	$this->query = mysql_query($query) or die(mysql_error());
    return $this->query;
}
public function MyNum(){
	return mysql_num_rows($this->query);
}
public function MyArray(){
	return mysql_fetch_array($this->query);
}

public function antes($DataAntes){
	$this->MySQL("SELECT * FROM `reservas` WHERE hora_inicio < '$DataAntes' AND hora_fim > '$DataAntes'");
	return $this->MyNum();
}

public function depois($DataDepois){
	$this->MySQL("SELECT * FROM `reservas` WHERE hora_fim > '$DataDepois' AND hora_fim > '$DataDepois'");
	return $this->MyNum();	
	$DataFilt = new Filtro();
$DataFilt->MySQL("SELECT * FROM `reservas`  hora_inicio = '$DataInicio'");
$totalRows = $DataFilt->MyNum();
$RS_Data = $DataFilt->MyArray();

if($RS_Data['hora_fim'] < $DataTermino){
	//echo 'Ocupado <br /><br />';
}else{
	//echo 'Livre <br /><br />';
}

if($DataFilt->antes($DataInicio)=='1'){
	$RS_Data = $DataFilt->MyArray();
	if($RS_Data['hora_fim']){
	
	}
	
}
if(($DataFilt->antes($DataInicio)=='1') OR ($DataFilt->depois($DataTermino)=='1')){
	echo 'Antes'.$DataFilt->antes($DataInicio).'<br />';
	echo 'Depois'.$DataFilt->depois($DataTermino);
}

//echo $totalRows;
echo '<br />';
if($totalRows > 0){
//echo 'Ocupado de '.$RS_Data['data_inicio'].' at&eacute; '.$RS_Data['data_termino'].'<br />';
}else{
//echo 'Data Livre<br />';
}

echo '<br /><br />';

}

how add script?


mobhar
User
Posts: 11905

Post by mobhar »

Not sure what is the purpose of your code. Can you explain it in more detail?


danielc
User
Posts: 1599

Post by danielc »

You can put your php function in Global->All Pages->Global Code. This will use through the project. See Server event and Client script in help file. There is some examples which you may see where to apply your code. Or you specify what you want to achieve for your code so it will help us to determine which server event is more appropriate.


halexoliveira
User
Posts: 8

Post by halexoliveira »

Thank you!
I got this:

function Row_Inserting($rsold, &$rsnew) {
$inicio = ew_ExecuteScalar("SELECT count() FROM reservas WHERE hora_inicio <= '" . ew_AdjustSql($rsnew["hora_inicio"]) . "' AND hora_fim >= '" . ew_AdjustSql($rsnew["hora_inicio"]) . "'"); // your two fields comparison to prevent duplicate
$fim = ew_ExecuteScalar("SELECT count(
) FROM reservas WHERE hora_fim >= '" . ew_AdjustSql($rsnew["hora_fim"]) . "' AND hora_inicio <= '" . ew_AdjustSql($rsnew["hora_fim"]) . "'"); // your two fields comparison to prevent duplicate
$intervalo = ew_ExecuteScalar("SELECT count(*) FROM reservas WHERE hora_fim BETWEEN '" . ew_AdjustSql($rsnew["hora_inicio"]) . "'AND'" . ew_AdjustSql($rsnew["hora_fim"]) . "'"); // your two fields comparison to prevent duplicate
if ($inicio >= 1 OR $fim >= 1 OR $intervalo>=1)
{
$this->setWarningMessage("Horário ja reservado. Verifique no calendário as datas e horários livres.");
$this->setWarningMessage($inicio);
$this->setWarningMessage($fim);
$this->setWarningMessage($intervalo);
return FALSE;
} else
{
return TRUE;
}
}


Post Reply