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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Preços por Grupo</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=(precosgrupos2Layout, 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><?
    if ($_SERVER['REQUEST_METHOD'] == "POST") 
    {      
       include('main.php');

       db_connect();
       $mensagem1='';

       $sql = "select codigo, cod_tarifa, cod_grupo from tr_rentacar_tarifas_precos ";
       $sql = $sql." where cod_rentacar=".$_SESSION['cod_rentacar'];
       $result = mysql_query($sql);       
              
       while($row = mysql_fetch_row($result))
       {      
           $codigo            = $row[0];
           $cod_tarifa        = $row[1];
           $cod_grupo         = "'".$row[2]."'";
           $cod_grupo_sc      = $row[2]; 
           $mod_check         = 'mod_check'.$codigo;
           $del_check         = 'del_check'.$codigo;           
           $num_day_from      = 'num_day_from'.$codigo;
           $num_day_to        = 'num_day_to'.$codigo;
           $num_preco         = 'num_preco'.$codigo;
                                        
           $var_day_from      = $_POST[$num_day_from];
           $var_day_to        = $_POST[$num_day_to];
           $num_preco         = $_POST[$num_preco];
           
           if (isset($_POST[$mod_check]))
           {
              $sql = "update tr_rentacar_tarifas_precos set ";
              $sql = $sql." day_from       = $var_day_from, ";
              $sql = $sql." day_to         = $var_day_to, ";
              $sql = $sql." preco          = $num_preco ";

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

           if (isset($_POST[$del_check]))
           {
              $sql = "delete from tr_rentacar_tarifas_precos where cod_rentacar = ".$_SESSION['cod_rentacar'];
              $sql = $sql." and codigo = ".$codigo;
          
              $result2 = mysql_query($sql);
              if ($result2=='')
                 $mensagem1=$mensagem1."Ocorreu um erro eliminando a tarifa do grupo<br>";                  
              else
                 $mensagem1=$mensagem1."A tarifa do grupo $cod_grupo_sc foi apagada com sucesso<br>";

              $sql = "select * from tr_rentacar_tarifas_precos where cod_rentacar = ".$_SESSION['cod_rentacar'];
              $sql = $sql." and cod_tarifa = $cod_tarifa and cod_grupo = $cod_grupo";
                
              $result3 = mysql_query($sql) or die("select tr_rentacar_tarifas_precos fails");
              $num_row = mysql_num_rows($result3);
                    
              if ($num_row==0)
              {
                  $new_tarifa     = $_POST['new_tarifa'];
                  $new_grupo1     = "'".$_POST['new_grupo1']."'";
                  $new_grupo2     = "'".$_POST['new_grupo2']."'";
                  $new_grupo3     = "'".$_POST['new_grupo3']."'";
                  $new_grupo4     = "'".$_POST['new_grupo4']."'";
                  $new_grupo5     = "'".$_POST['new_grupo5']."'";
                  $new_grupo6     = "'".$_POST['new_grupo6']."'";
                  $new_grupo7     = "'".$_POST['new_grupo7']."'";
                  $new_grupo8     = "'".$_POST['new_grupo8']."'";
                  $new_grupo9     = "'".$_POST['new_grupo9']."'";
                  $new_grupo10    = "'".$_POST['new_grupo10']."'";
                  
                  $apagar = 1;                   
                  if (isset($_POST['new_check1']) and $new_tarifa == $cod_tarifa and $new_grupo1 == $cod_grupo)
                      $apagar = 0;

                  if (isset($_POST['new_check2']) and $new_tarifa == $cod_tarifa and $new_grupo2 == $cod_grupo)
                      $apagar = 0;

                  if (isset($_POST['new_check3']) and $new_tarifa == $cod_tarifa and $new_grupo3 == $cod_grupo)
                      $apagar = 0;

                  if (isset($_POST['new_check4']) and $new_tarifa == $cod_tarifa and $new_grupo4 == $cod_grupo)
                      $apagar = 0;

                  if (isset($_POST['new_check5']) and $new_tarifa == $cod_tarifa and $new_grupo5 == $cod_grupo)
                      $apagar = 0;

                  if (isset($_POST['new_check6']) and $new_tarifa == $cod_tarifa and $new_grupo6 == $cod_grupo)
                      $apagar = 0;

                  if (isset($_POST['new_check7']) and $new_tarifa == $cod_tarifa and $new_grupo7 == $cod_grupo)
                      $apagar = 0;

                  if (isset($_POST['new_check8']) and $new_tarifa == $cod_tarifa and $new_grupo8 == $cod_grupo)
                      $apagar = 0;

                  if (isset($_POST['new_check9']) and $new_tarifa == $cod_tarifa and $new_grupo9 == $cod_grupo)
                      $apagar = 0;

                  if (isset($_POST['new_check10']) and $new_tarifa == $cod_tarifa and $new_grupo10 == $cod_grupo)
                      $apagar = 0;
                 
                  if ($apagar == 1)
                  {
                      $sql = "delete from tr_rentacar_extras_values where cod_rentacar = ".$_SESSION['cod_rentacar'];
                      $sql = $sql." and cod_tarifa = $cod_tarifa and cod_grupo = $cod_grupo";
                      $result4 = mysql_query($sql);               
                  }
              }        
           }
       }

       $insercao = 0;        
       for ($i=1;$i<=10;$i++)
       {
           $new_check         = 'new_check'.$i;   
           $new_grupo         = 'new_grupo'.$i;        
           $new_day_from      = 'new_day_from'.$i;
           $new_day_to        = 'new_day_to'.$i;
           $new_preco         = 'new_preco'.$i;
                                        
           if (isset($_POST[$new_check]))
           {
               $new_tarifa     = $_POST['new_tarifa'];               
               $new_grupo      = "'".$_POST[$new_grupo]."'";
               $new_day_from   = $_POST[$new_day_from];          
               $new_day_to     = $_POST[$new_day_to];
               $new_preco      = $_POST[$new_preco];

               $sql = "insert into tr_rentacar_tarifas_precos (cod_rentacar, cod_tarifa, cod_grupo, day_from, ";
               $sql = $sql." day_to, preco) ";
               $sql = $sql." values ";
               $sql = $sql." (".$_SESSION['cod_rentacar'].", $new_tarifa, $new_grupo, $new_day_from, ";
               $sql = $sql." $new_day_to, $new_preco)";
                    
               $result3 = mysql_query($sql);         
               $insercao = 1;
           }
       }
      
       if ($insercao==1)
       {
          if ($result3=='')
              $mensagem1=$mensagem1."Ocorreu um erro na inserção das tarifas do grupo<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>
 