<?
   session_start();
   if (!isset($_SESSION['cod_rentacar']))
      header("location: login.php");
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Tarifas</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META NAME="Generator" CONTENT="NetObjects Fusion 8 for Windows">
<link rel="stylesheet" href="../assets/clases.css" type="text/css" />
<script language="javascript" src="../assets/help_functions.js"></script>
<SCRIPT>
<!--
var F_A,F_B,F_CH,F_CL,F_DB,F_E,F_F,F_L,F_MT,F_MV,F_R,F_SE,F_SU,F_U,F_HR,F_MU,F_MD;
function F_e(){} function F_n(){} function F_onLoaded(){}
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
document.write("<SCRIPT SRC=\"../assets/script.js\"><\/SCRIPT>");
document.write("<SCRIPT SRC=\"../assets/effects.js\"><\/SCRIPT>");
//-->
</SCRIPT>
<SCRIPT>
<!--
function F_doLoaded() {
	document.main = new F_cMain();
	document.objectModel = new Object();
	F_OM('Layout','LayoutLYR', 'doc', '', new Array());
	F_OM('ID_btBack' , '', 'btn', 'Layout',new Array(
	'Clicked',F_functID_btBackAction0,'','',0),'LayoutRegion3FORM',0,'btBack');
	F_pageLoaded('Layout');
}
function F_functID_btBackAction0(params) {
history.back();
}

//-->
</SCRIPT>
<LINK REL=STYLESHEET TYPE="text/css" HREF="../html/style.css">
<LINK REL=STYLESHEET TYPE="text/css" HREF="../html/site.css">
<STYLE>
</STYLE><NOLAYER>
<STYLE ID="NOF_STYLE_SHEET">
<!--
DIV#LayoutLYR { position:relative; top:0; left:0; z-index: 1; visibility:inherit; }
-->
</STYLE>

</NOLAYER>
</HEAD>
<BODY NOF="(MB=(save, 213, 65, 0, 0), L=(tarifas2Layout, 760, 310))" STYLE="text-align: center;" onLoad="F_onLoaded();">
    <DIV ID="LayoutLYR"><LAYER ID="LayoutLYR" TOP=0 LEFT=0 VISIBILITY=INHERIT WIDTH=760 HEIGHT=588 Z-INDEX=1>
    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 NOF=LY>
        <TR VALIGN=TOP ALIGN=LEFT>
            <TD WIDTH=760>
                <TABLE ID="Table1" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%" HEIGHT=213>
                    <TR HEIGHT=41>
                        <TD WIDTH=760 STYLE="background-color: rgb(255,255,255); background-image: none;">
                            <P>
                                <TABLE WIDTH=760 BORDER=0 CELLSPACING=0 CELLPADDING=0 ALIGN=LEFT NOF=TE>
                                    <TR>
                                        <TD>
                                            <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=760 HEIGHT=41 NOF="LayoutRegion1">
                                                <TR ALIGN=LEFT VALIGN=TOP>
                                                    <TD>
                                                        <TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=735 NOF="LayoutRegion1">
                                                            <TR VALIGN=TOP ALIGN=LEFT>
                                                                <TD>
                                                                    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=425 NOF="LayoutRegion1">
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD WIDTH=409 HEIGHT=16><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=409 HEIGHT=1 BORDER=0 ALT=""></TD>
                                                                            <TD></TD>
                                                                        </TR>
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD HEIGHT=15></TD>
                                                                            <TD WIDTH=16><IMG ID="Picture2" HEIGHT=15 WIDTH=16 SRC="../assets/images/ihhomicon1.jpg" BORDER=0 ALT="ihhomicon" TITLE="ihhomicon"></TD>
                                                                        </TR>
                                                                    </TABLE>
                                                                </TD>
                                                                <TD>
                                                                    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=56 NOF="LayoutRegion1">
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD WIDTH=2 HEIGHT=17><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=2 HEIGHT=1 BORDER=0 ALT=""></TD>
                                                                            <TD WIDTH=54><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=54 HEIGHT=1 BORDER=0 ALT=""></TD>
                                                                        </TR>
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD></TD>
                                                                            <TD WIDTH=54 CLASS="TextObject">
                                                                                <P><B><U><SPAN STYLE="font-size: 10px;">Home</SPAN></U></B></P>
                                                                            </TD>
                                                                        </TR>
                                                                    </TABLE>
                                                                </TD>
                                                                <TD>
                                                                    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=21 NOF="LayoutRegion1">
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD WIDTH=5 HEIGHT=16><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=5 HEIGHT=1 BORDER=0 ALT=""></TD>
                                                                            <TD></TD>
                                                                        </TR>
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD HEIGHT=15></TD>
                                                                            <TD WIDTH=16><IMG ID="Picture3" HEIGHT=15 WIDTH=16 SRC="../assets/images/ihemail1.jpg" BORDER=0 ALT="ihemail" TITLE="ihemail"></TD>
                                                                        </TR>
                                                                    </TABLE>
                                                                </TD>
                                                                <TD>
                                                                    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=84 NOF="LayoutRegion1">
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD WIDTH=2 HEIGHT=17><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=2 HEIGHT=1 BORDER=0 ALT=""></TD>
                                                                            <TD WIDTH=82><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=82 HEIGHT=1 BORDER=0 ALT=""></TD>
                                                                        </TR>
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD></TD>
                                                                            <TD WIDTH=82 CLASS="TextObject">
                                                                                <P><B><U><SPAN STYLE="font-size: 10px;">Contacte-nos</SPAN></U></B></P>
                                                                            </TD>
                                                                        </TR>
                                                                    </TABLE>
                                                                </TD>
                                                                <TD>
                                                                    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=24 NOF="LayoutRegion1">
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD WIDTH=7 HEIGHT=15><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=7 HEIGHT=1 BORDER=0 ALT=""></TD>
                                                                            <TD></TD>
                                                                        </TR>
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD HEIGHT=17></TD>
                                                                            <TD WIDTH=17><IMG ID="Picture7" HEIGHT=17 WIDTH=17 SRC="../assets/images/ihgobutton031.jpg" BORDER=0 ALT="ihgobutton03" TITLE="ihgobutton03"></TD>
                                                                        </TR>
                                                                    </TABLE>
                                                                </TD>
                                                                <TD>
                                                                    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=44 NOF="LayoutRegion1">
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD WIDTH=6 HEIGHT=17><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=6 HEIGHT=1 BORDER=0 ALT=""></TD>
                                                                            <TD WIDTH=38><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=38 HEIGHT=1 BORDER=0 ALT=""></TD>
                                                                        </TR>
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD></TD>
                                                                            <TD WIDTH=38 CLASS="TextObject">
                                                                                <P><B><U><SPAN STYLE="color: rgb(255,102,0);">Ajuda</SPAN></U></B></P>
                                                                            </TD>
                                                                        </TR>
                                                                    </TABLE>
                                                                </TD>
                                                                <TD>
                                                                    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=29 NOF="LayoutRegion1">
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD WIDTH=22 HEIGHT=21><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=22 HEIGHT=1 BORDER=0 ALT=""></TD>
                                                                            <TD></TD>
                                                                        </TR>
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD HEIGHT=5></TD>
                                                                            <TD WIDTH=7><IMG ID="Picture8" HEIGHT=5 WIDTH=7 SRC="../assets/images/ihbullet.jpg" BORDER=0 ALT="ihbullet" TITLE="ihbullet"></TD>
                                                                        </TR>
                                                                    </TABLE>
                                                                </TD>
                                                                <TD>
                                                                    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=52 NOF="LayoutRegion1">
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD WIDTH=3 HEIGHT=17><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=3 HEIGHT=1 BORDER=0 ALT=""></TD>
                                                                            <TD WIDTH=49><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=49 HEIGHT=1 BORDER=0 ALT=""></TD>
                                                                        </TR>
                                                                        <TR VALIGN=TOP ALIGN=LEFT>
                                                                            <TD></TD>
                                                                            <TD WIDTH=49 CLASS="TextObject">
                                                                                <P><B><SPAN STYLE="font-size: 10px;" class="link_azul"><A HREF="./logout.php">Sair</A></SPAN></B>&nbsp;</P>
                                                                            </TD>
                                                                        </TR>
                                                                    </TABLE>
                                                                </TD>
                                                            </TR>
                                                        </TABLE>
                                                    </TD>
                                                </TR>
                                            </TABLE>
                                        </TD>
                                    </TR>
                                </TABLE>
                            </P>
                        </TD>
                    </TR>
                    <TR HEIGHT=137>
                        <TD>
                            <P><IMG ID="Banner2" HEIGHT=137 WIDTH=760 SRC="../assets/images/autogen/Tarifas_NDefault.jpg" VSPACE=0 HSPACE=0 ALIGN="TOP" BORDER=0 ALT="Tarifas" TITLE="Tarifas" NOF=B_H></P>
                        </TD>
                    </TR>
                    <TR HEIGHT=34>
                        <TD STYLE="background-color: rgb(255,255,255); background-image: url('../assets/images/ihnavbg1.jpg');">
                            <H1 STYLE="text-align: center;"><SPAN STYLE="font-size: x-small; font-weight: normal;"></SPAN></TD>
                    </TR>
                    <TR HEIGHT=1>
                        <TD STYLE="background-color: rgb(255,255,255); background-image: url('../assets/images/ihtop31.gif');">
                            <P></P>
                        </TD>
                    </TR>
                </TABLE>
            </TD>
        </TR>
    </TABLE>
    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=760 NOF=LY>
        <TR VALIGN=TOP ALIGN=LEFT>
            <TD HEIGHT=310 WIDTH=760>
                <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=760 HEIGHT=310 STYLE="background-color: rgb(237,237,237);" NOF="LayoutRegion3">
                    <TR ALIGN=LEFT VALIGN=TOP>
                        <TD>
                            <FORM NAME="LayoutRegion3FORM" ACTION="" METHOD=POST>
                                <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=704 NOF="LayoutRegion3">
                                    <TR VALIGN=TOP ALIGN=LEFT>
                                        <TD WIDTH=98 HEIGHT=18><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=98 HEIGHT=1 BORDER=0 ALT=""></TD>
                                        <TD WIDTH=606><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=606 HEIGHT=1 BORDER=0 ALT=""></TD>
                                    </TR>
                                    <TR VALIGN=TOP ALIGN=LEFT>
                                        <TD></TD>
                                        <TD WIDTH=606 CLASS="TextObject">
                                            <P><?
    function FormatarData($Data) 
    { 
        $date_array = explode("/",$Data);
     
        $var_day   = $date_array[0]; 
        $var_month = $date_array[1]; 
        $var_year  = $date_array[2]; 

        $format_data   = date("Y/m/d H:i:s", mktime(0,0,0,$var_month,$var_day,$var_year)); 
        return($format_data);  
    } 

    if ($_SERVER['REQUEST_METHOD'] == "POST") 
    {      
       include('main.php');

       db_connect();
       $sql = "select cod_tarifa from tr_rentacar_tarifas where cod_rentacar=".$_SESSION['cod_rentacar'];
       $result = mysql_query($sql);       
       
       $mensagem1='';
       while($row = mysql_fetch_row($result))
       {      
           $codigo               = $row[0];
           $mod_check            = 'mod_check'.$codigo;
           $del_check            = 'del_check'.$codigo;           
           $text_description     = 'text_description'.$codigo;
           $text_date_from       = 'text_date_from'.$codigo;
           $text_date_to         = 'text_date_to'.$codigo;
           $num_tolerancia       = 'num_tolerancia'.$codigo;
                                        
           $var_text_descricao       = $_POST[$text_description];
           $var_text_data_inicio     = FormatarData($_POST[$text_date_from]);
           $var_text_data_fim        = FormatarData($_POST[$text_date_to]);
           $var_num_horas_tol        = $_POST[$num_tolerancia];
           
           if (isset($_POST[$mod_check]))
           {
              $sql = "update tr_rentacar_tarifas set ";
              $sql = $sql." descricao      ='$var_text_descricao', ";
              $sql = $sql." data_inicio    ='$var_text_data_inicio', ";
              $sql = $sql." data_fim       ='$var_text_data_fim', ";
              $sql = $sql." horas_tol      = $var_num_horas_tol ";

              $sql = $sql." where cod_rentacar = ".$_SESSION['cod_rentacar'];
              $sql = $sql." and cod_tarifa = ".$codigo;
                            
              $result1 = mysql_query($sql);               
              if ($result1=='')
                 $mensagem1=$mensagem1."Ocorreu um erro na actualização da tarifa.<br>";                  
              else
                 $mensagem1=$mensagem1."A tarifa foi actualizada com sucesso<br>";
           }           

           if (isset($_POST[$del_check]))
           {
              $sql = "delete from tr_rentacar_extras_values where cod_rentacar = ".$_SESSION['cod_rentacar'];
              $sql = $sql." and cod_tarifa = ".$codigo;
              $result2 = mysql_query($sql);

              $sql = "delete from tr_rentacar_tarifas_precos where cod_rentacar = ".$_SESSION['cod_rentacar'];
              $sql = $sql." and cod_tarifa = ".$codigo;
              $result2 = mysql_query($sql);

              $sql = "delete from tr_rentacar_tarifas where cod_rentacar = ".$_SESSION['cod_rentacar'];
              $sql = $sql." and cod_tarifa = ".$codigo;
          
              $result2 = mysql_query($sql);
              if ($result2=='')
                 $mensagem1=$mensagem1."Ocorreu um erro eliminando a tarifa<br>";                  
              else
                 $mensagem1=$mensagem1."A tarifa foi eliminada com sucesso<br>";
           }
       }

       if (isset($_POST['new_check']))
       {
          $new_desc_tarifa     = $_POST['new_description'];
          $new_data_inicio     = FormatarData($_POST['new_date_from']);
          $new_data_fim        = FormatarData($_POST['new_date_to']);          
          $new_horas_tol       = $_POST['new_tolerancia'];

          $sql = "insert into tr_rentacar_tarifas (cod_rentacar, descricao, data_inicio, ";
          $sql = $sql." data_fim, horas_tol) ";
          $sql = $sql." values ";
          $sql = $sql." (".$_SESSION['cod_rentacar'].",'$new_desc_tarifa', '$new_data_inicio', ";
          $sql = $sql." '$new_data_fim',$new_horas_tol)";
                    
          $result3 = mysql_query($sql);
          if ($result3=='')
             $mensagem1=$mensagem1."Ocorreu um erro na inserção da tarifa<br>";                  
          else
             $mensagem1=$mensagem1."A inserção da tarifa foi efectuada com sucesso<br>";          
       }

       echo '<B><SPAN STYLE="font-family: Verdana,Tahoma,Arial,Helvetica,Sans-serif; font-size: 

xx-small;">'.$mensagem1.'</SPAN></B>';  
       
       db_disconnect();
    }

?>
&nbsp;</P>
                                        </TD>
                                    </TR>
                                </TABLE>
                                <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 NOF="LayoutRegion3">
                                    <TR VALIGN=TOP ALIGN=LEFT>
                                        <TD WIDTH=98 HEIGHT=10><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=98 HEIGHT=1 BORDER=0 ALT=""></TD>
                                        <TD></TD>
                                    </TR>
                                    <TR VALIGN=TOP ALIGN=LEFT>
                                        <TD></TD>
                                        <TD WIDTH=99>
                                            <TABLE ID="Table5" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%" HEIGHT=31>
                                                <TR>
                                                    <TD>
                                                        <P><INPUT TYPE=BUTTON NAME="btBack" VALUE="Voltar" ID="ID_btBack" class="text_objects" onClick="return(F_e('ID_btBack', F_CL))"></P>
                                                    </TD>
                                                </TR>
                                            </TABLE>
                                        </TD>
                                    </TR>
                                </TABLE>
                            </FORM>
                        </TD>
                    </TR>
                </TABLE>
            </TD>
        </TR>
        <TR VALIGN=TOP ALIGN=LEFT>
            <TD HEIGHT=65 WIDTH=760>
                <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=760 HEIGHT=65 STYLE="background-color: rgb(0,51,102);" NOF="LayoutRegion6">
                    <TR ALIGN=LEFT VALIGN=TOP>
                        <TD>
                            <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=564 NOF="LayoutRegion6">
                                <TR VALIGN=TOP ALIGN=LEFT>
                                    <TD WIDTH=212 HEIGHT=28><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=212 HEIGHT=1 BORDER=0 ALT=""></TD>
                                    <TD WIDTH=352><IMG SRC="../assets/images/autogen/clearpixel.gif" WIDTH=352 HEIGHT=1 BORDER=0 ALT=""></TD>
                                </TR>
                                <TR VALIGN=TOP ALIGN=LEFT>
                                    <TD></TD>
                                    <TD WIDTH=352 CLASS="TextObject">
                                        <P STYLE="text-align: center;"><B><SPAN STYLE="color: rgb(255,255,255);">Copyright Bravacar 2006</SPAN></B></P>
                                    </TD>
                                </TR>
                            </TABLE>
                        </TD>
                    </TR>
                </TABLE>
            </TD>
        </TR>
    </TABLE>
    </LAYER></DIV>
</BODY>
</HTML>
 