json_decode( $_POST['code'], true ), 'action' => json_decode( $_POST['action'], true ) ]); $data = ''; foreach($_SESSION['history'] as $h=>$entry) $data .= "".$entry['code']." - ".$entry['action']."
"; echo json_encode( [ 'ModuleError' => 0, 'data' => $data ] ); } /* [2] Gestion de la synchronisation =========================================================*/ if( isset($_POST['sync']) ){ $api = new api(); /* (1) On effectue la synchro */ $token = sessionManager::secure_hash( $_COOKIE['mac_password'], $_COOKIE['mac_count'] ); // Renouvellement du TOKEN if( $_COOKIE['mac_count'] == 1 ){ $response = $api->send('sync-renew', [ '@warehouse' => '643405e1004845c2291c244faab192e3ad493b9dec147c8030475794b0f2fa23', '@token' => $token, '@data' => json_encode( $_SESSION['history'] ), '@renew' => sessionManager::secure_hash( $_COOKIE['mac_password'], 10) ]); $_COOKIE['mac_count'] = 9; setcookie('mac_count', $_COOKIE['mac_count'], time()+3600*24*365, '/'); }else{ $response = $api->send('sync', [ '@warehouse' => '643405e1004845c2291c244faab192e3ad493b9dec147c8030475794b0f2fa23', '@token' => $token, '@data' => json_encode( $_SESSION['history'] ) ]); $_COOKIE['mac_count']--; setcookie('mac_count', $_COOKIE['mac_count'], time()+3600*24*365, '/'); } $parsedResponse = json_decode( $response, true ); $toReturn = [ 'response' => $parsedResponse, 'pwd' => $_COOKIE['mac_password'], 'count' => $_COOKIE['mac_count'], 'token' => $token, 'status' => $parsedResponse['ModuleError'], 'data' => ($parsedResponse['ModuleError']==0) ? $parsedResponse['data'] : 'void' ]; echo json_encode($toReturn); } ?>