<html>

<head>
  <meta http-equiv='content-type' content='text/html;charset=utf-8'>
  <title>WebBike V1.0</title>
  <link href="style.css" rel="stylesheet" media="screen">
  <?php
  require 'database.inc.php';
  //session_start();
  //session_register("lg_user");
  //session_register("lg_password");
  //session_register("lg_admin");
  //session_register("lg_menu1");
  //session_register("lg_menu2");
  //session_register("lg_menu3");
  //session_register("lg_menu4");
  //session_register("lg_menu5");
  //session_register("lg_menu6");
  ?>
</head>

<body>
  <?php
  if (Test_User($lg_user, $lg_password) == TRUE) {
    if (As_Right_Fonction(6, 34)) {
      if (isset($ok)) {
        $tab_mode = explode(" ", $ModePayement);

        if ($ligne = DBCash::getDBCashByNoCash($NoCash)) {
          $requette2 = "UPDATE commande" . ID_GARAGE . " SET APayer = APayer + (" . $ligne['Somme'] . ") - ( $somme ) WHERE NoCommande = " . $ligne['NoFacture'];
          Connection::executeRawQuery($requette2);
          echo $requette2 . "<br />";
          $requette3 = "UPDATE dbcash" . ID_GARAGE . " SET Somme = $somme, ModePayement = " . $tab_mode[0] . ", NoCaisse = " . $tab_mode[1] . " WHERE NoCash = $NoCash";
          Connection::executeRawQuery($requette3);
          echo $requette3 . "<br />";
          echo "<script language=JavaScript>\n";
          echo "window.opener.window.location.reload();\n";
          echo "window.close();\n";
          echo "</script>\n";
        }
      } else {
        if ($ligne = DBCash::getDBCashByNoCash($NoCash)) {

          echo " <form>\n";
          echo " <INPUT type='hidden' name='ok' value='1'>\n";
          echo " <INPUT type='hidden' name='NoCash' value='$NoCash'>\n";
          echo " <INPUT type='text' name='somme' value='" . $ligne['Somme'] . "'>\n";
          echo " <SELECT name='ModePayement' size='1'>\n";
          if ($resultat2 = $resultat = ModePayement::getModePayment()) {
            foreach ($resultat2 as $ligne2) {
              if (($ligne2['Type'] == 2) && (!Is_Banque())) {
              } else {
                if (As_Right_Groupe(6)) {
                  echo "  <option value='" . $ligne2['NoMode'] . " " . $ligne2['NoCaisse'] . "'";
                  if (($ligne['ModePayement'] == $ligne2['NoMode']) && ($ligne['NoCaisse'] == $ligne2['NoCaisse'])) {
                    echo " selected";
                  }
                  echo ">" . $ligne2['Description'] . " caisse " . $ligne2['NoCaisse'] . "</option>\n";
                } else {
                  echo "  <option value='" . $ligne2['NoMode'] . " " . $ligne2['NoCaisse'] . "'";
                  if (($ligne['ModePayement'] == $ligne2['NoMode']) && ($ligne['NoCaisse'] == $ligne2['NoCaisse'])) {
                    echo " selected";
                  }
                  echo ">" . $ligne2['Description'] . "</option>\n";
                }
              }
            }
          }
          echo " </SELECT>\n";
          echo "<input type='submit' value='valider'>\n";
          echo "</form>";
        }
      }
    } else {
      echo "<script language=JavaScript>\n";
      echo "window.close();\n";
      echo "</script>\n";
    }
  }
  ?>
</body>

</html>