Sid Gifari From Gifari Industries - BD Cyber Security Team
Home
/
home
/
airmobeuag
/
pro
/
commande_v2_del
/
lib
/
✏️
Editing: gestion.lib.php
<?php /* Class pour commande V2 26/11/2019 */ Class ClassCdeV2 { public function __construct() { $this->EtapeParam = [ ['nom'=>'Zero !' ,'titre'=>''], ['nom'=>'offre' ,'titre'=>'Je choisis mon offre'], ['nom'=>'options' ,'titre'=>''], ['nom'=>'mesinfos' ,'titre'=>'Mes informations'], ['nom'=>'infosste' ,'titre'=>"Informations sur l'entreprise"], ['nom'=>'paiement' ,'titre'=>"Je paie et j'ouvre ma ligne"], ]; $this->Operateurs = ['BOU'=>'Bouygues Telecom','ORG'=>'Orange','SFR'=>'SFR',]; } public function CnxDBaseSQL() { if ($_SERVER['REMOTE_ADDR'] == "127.0.0.1") { $connexion = mysqli_connect("127.0.0.1", "root", "") or die ("could not connect to mysql"); mysqli_select_db($connexion, "airmob") or die ("no database"); } else { $connexion = mysqli_connect("airmobeuagweb.mysql.db", "airmobeuagweb", "5345fhjthk875HJzzs112") or die ("could not connect to mysql"); mysqli_select_db($connexion, "airmobeuagweb") or die ("no database"); } return $connexion; } public function AfficheSuiviEtape() { $Etapecourante = $_SESSION['AIRCMDV2']['etape']; include ("./form/step.php"); echo "<div style='text-align:center; color:#245ba5; margin-bottom:50px;'><h1>".$this->EtapeParam[$Etapecourante]['titre']."</h1></div>"; echo "<br>"; } /* Affiche etape */ public function AfficheFormEtape() { $Etapecourante = $_SESSION['AIRCMDV2']['etape']; $NomForm = $this->EtapeParam[$Etapecourante]['nom']; include ("./form/".$NomForm.".php"); } /* Enregistre les choix utilisateurs */ public function PostForm() { $Etapecourante = $_SESSION['AIRCMDV2']['etape']; $Type = $_SESSION['AIRCMDV2']['type']; // DEBUG : affichage // echo "$Etapecourante / <pre>"; print_r($_REQUEST); echo "</pre>"; // Valide ADD + SUIVANT if( $_REQUEST['btn_suivant'] or $_REQUEST['btn_add'] or $_REQUEST['btn_continuer'] ) { // ---------------------------- // Validation de ma 1ere etape // ---------------------------- if( !@$_SESSION['AIRCMDV2']['Cde_debut'] ) { $_SESSION['AIRCMDV2']['idunique'] = uniqid(); $_SESSION['AIRCMDV2']['Cde_debut'] = date("Y-m-d H:i:s", mktime(date("H") + 1, date("i"), date("s"), date("m"), date("d"), date("Y")));; $Q_INSERT = "INSERT INTO commandes_v2 (idunique, creation ) VALUES ('".$_SESSION['AIRCMDV2']['idunique']."','".date('Y-m-d H:i:s')."') "; $QUERY = mysqli_query ($this->CnxDBaseSQL() , $Q_INSERT); } // $NomProduit = $_SESSION['AIRCMDV2']['NomProduits'][$_REQUEST['p']]['nom']; // Si ADD enregistre if( $_REQUEST['btn_add']) { // echo "<h1>ADD</h1>"; $EtapeSave = $Etapecourante ; // Maintient la valeur de l etape $newKey = max(array_keys( $_SESSION['AIRCMDV2']['Commande'][$Type][$EtapeSave] ))+1;; $_SESSION['AIRCMDV2']['Commande'][$Type][$EtapeSave][$newKey]=['id' => $_REQUEST['p'],'confirme'=>'OK'] ; } elseif( $_REQUEST['btn_continuer']) { $EtapeSave = $Etapecourante+1 ; // Maintient la valeur de l etape } // Si SUIVANT else { $EtapeSave = $Etapecourante - 1; // Etape suivante donc enreg. sur l etape precedente } // Enreg. // echo "<h1>POST ($EtapeSave)</h1>"; foreach ($_REQUEST as $NomChamp => $Val) { list($none,$prod,$cde) = explode ('_',$NomChamp); // Conserve les choix de l utilisateur if($none=="Choix") { if($prod=="DATA") $_SESSION['AIRCMDV2']['Commande'][$Type][$EtapeSave][$cde]['id'] = $Val; if($prod=="OPE" ) $_SESSION['AIRCMDV2']['Commande'][$Type][$EtapeSave][$cde]['operateur'] = $Val; if($prod=="TEL" ) $_SESSION['AIRCMDV2']['Commande'][$Type][$EtapeSave][$cde]['tel'] = $Val; if($prod=="OPT1") $_SESSION['AIRCMDV2']['Commande'][$Type][$EtapeSave][$cde]['id'] = $Val; if($prod=="OPT2") $_SESSION['AIRCMDV2']['Commande'][$Type][$EtapeSave][$cde]['id'] = $Val; $_SESSION['AIRCMDV2']['Commande'][$Type][$EtapeSave][$cde]['confirme'] = "OK"; } else if($none=="Porta") { if($prod=="RIO" ) $_SESSION['AIRCMDV2']['Commande'][$Type][$EtapeSave][$cde]['rio'] = $Val; if($prod=="NUM" ) $_SESSION['AIRCMDV2']['Commande'][$Type][$EtapeSave][$cde]['numero'] = $Val; } else if ($none=="form") { $_SESSION['AIRCMDV2']['Commande']['Utilisateur'][$prod] = $Val; } } // Enregistre en MySQL $this->EnregCmd(); if( $_REQUEST['btn_continuer']) { header('Location:http://pro.airmob.net'); } } } // Enregistre les infos au fur et à mesure des étapes public function EnregCmd(){ // Articles $CmdArray = $this->FormatCmd(); // Détail Cmd $CmdJson = json_encode($CmdArray); // Montant Cmd $Ht = $CmdArray['total_rec']+$CmdArray['total_fas']; $Tva = ($Ht*20)/100; $Ttc = $Ht+$Tva; // Ajoute 2 chmaps à la requete $UPDATE[] = "detail_cmd='".$CmdJson."'"; $UPDATE[] = "montant='$Ttc'"; // Creation de la requete foreach ($_SESSION['AIRCMDV2']['Commande']['Utilisateur'] as $Champ => $Valeur) { $UPDATE[] = $Champ."='".$Valeur."'"; } // Enregsitrement permament $Q_UPDATE = "UPDATE commandes_v2 SET ".join(',',$UPDATE) ."WHERE idunique='".$_SESSION['AIRCMDV2']['idunique']."'"; $QUERY = mysqli_query ($this->CnxDBaseSQL() , $Q_UPDATE); } // STRIPE enregistre le paiement OK ou KO public function PaiementCmd($Msg,$RetourAPI) { // Evite l ecrassement if ($_SESSION['AIRCMDV2']['idunique']) { $Q_UPDATE = "UPDATE commandes_v2 SET code_promo='". $RetourAPI->description."',msg='" . $Msg . "',paiement='" . date('Y-m-d H:i:s') . "' WHERE idunique='" . $_SESSION['AIRCMDV2']['idunique'] . "'"; $QUERY = mysqli_query($this->CnxDBaseSQL(), $Q_UPDATE); unset( $_SESSION['AIRCMDV2']); // Vide la commande } } // Format la commande public function FormatCmd() { $ArrType = ['i'=>'Internet','t'=>'Telephonie']; // Internet, Telephonie foreach($ArrType as $TypedeCommande=>$NomType) { $MyCmd =[]; foreach ($_SESSION['AIRCMDV2']['Commande'][$TypedeCommande] as $Etape => $Cmd) { foreach ($Cmd as $K => $Dtl) { if ($Dtl['id']) { $NomProduit = utf8_encode($_SESSION['AIRCMDV2']['NomProduits'][$Dtl['id']]['nom']); $Rec = $_SESSION['AIRCMDV2']['NomProduits'][$Dtl['id']]['rec']; $Total_Rec += $Rec; $Fas = $_SESSION['AIRCMDV2']['NomProduits'][$Dtl['id']]['fas']; $Total_Fas += $Fas; if ($Etape == 1) $MyCmd[] = ['Type' => $NomType, 'ctg'=>'offre' , 'idart' => $Dtl['id'] , 'nom'=>$NomProduit,'rec'=>$Rec,'fas'=>$Fas,'tel' => $Dtl['tel'],'ope' => $Dtl['operateur'], 'num' => $Dtl['numero'], 'rio' => $Dtl['rio']]; if ($Etape == 2) $MyCmd[] = ['Type' => $NomType, 'ctg'=>'option' , 'idart' => $Dtl['id'] , 'nom'=>$NomProduit,'rec'=>$Rec,'fas'=>$Fas ]; } } $MyCmdALL[$TypedeCommande] = $MyCmd; } } return ['dtl_cmd'=>$MyCmdALL,'total_rec'=>$Total_Rec,'total_fas'=>$Total_Fas]; } // Charge les produits public function ListeProduits( $select_arr ) { // Extrait les articles sélectionnés if( is_array($select_arr) ) { foreach($select_arr as $Chp) { $W[] = "offre ='$Chp'"; } $WHERE = join (' or ', $W); } // Query $cnx = $this->CnxDBaseSQL(); $Lst = mysqli_query($cnx, "SELECT * FROM offres WHERE $WHERE ORDER BY id ") or die(mysqli_error()); while ($Detail = mysqli_fetch_array($Lst, MYSQLI_ASSOC)) { $_SESSION['AIRCMDV2']['LstProduits'][$Detail['offre']][$Detail['id']] = $Detail; $_SESSION['AIRCMDV2']['NomProduits'][$Detail['id']] = $Detail; } } public function StepMobile() { $NoEtape = $_SESSION['AIRCMDV2']['etape']; ${'active'.$NoEtape}='is-active' ; ${'bold'.$NoEtape}='bold; border-bottom:2px solid #235BA5' ; if(!$bold1 && !$bold2 && !$bold3 && !$bold4) $bold5="bold; color :#000;"; echo " <div id=\"container\" style=\"border:0px;\"> <div id=\"content\" style=\"width:650px\"> <br /><br /> <ul class=\"list-unstyled multi-steps\" > <li class=\"$active1 \">Mon offre</li> <li class=\"$active2\">Mes options</li> <li class=\"$active3\">Mes informations</li> <li class=\"$active4\">Mon entreprise</li> <li class=\"$active5\">Paiement</li> </ul> </div> </div> "; } // Declenche la ligne etape public function Step() { $NoEtape = $_SESSION['AIRCMDV2']['etape']; ${'active'.$NoEtape}='is-active' ; echo " <div lass='container-fluid col-md-12'> <br /><br /> <ul class=\"list-unstyled multi-steps\" > <li class=\"$active1 \">Mon offre</li> <li class=\"$active2\">Mes options</li> <li class=\"$active3\">Mes informations</li> <li class=\"$active4\">Mon entreprise</li> <li class=\"$active5\">Paiement</li> </ul> </div>"; } // Connexion à l API STRIPE public function APIStripe( $Array ) { $this->action = $Array['action']; $this->data = $Array['data']; //$CodeAPIStripe = "sk_live_jmMEEsrBrru0qcmySOPhViz1"; // AIRMOB Prod $CodeAPIStripe = "sk_test_wtOLZRJRmrRm5va5cDWUKeNl"; // AIRMOB TEST $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => "https://api.stripe.com/v1/".$this->action, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERPWD => $CodeAPIStripe, CURLOPT_HTTPAUTH => CURLAUTH_BASIC ]); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->data)); $response = json_decode(curl_exec($ch)); return $response; curl_close($ch); } } ?>
💾 Save
❌ Cancel