package com.example.patrice.rerservation01;


import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ajouter_jeu__DB_mysql
{

    JSONParser jsonParser = new JSONParser();

    private static String url_add_jeu = "http://analog-design.net/WORKAREA/WEBSITE/reservation/ajouter_jeu_DB_mysql.php";

    // JSON Node names
    private static final String TAG_SUCCESS = "success";

    public void ajouter_jeu__DB_mysql()
    {
        new CreateNewProduct().execute();
    }


    class CreateNewProduct extends AsyncTask<String, String, String>
    {

        protected String doInBackground(String... args)
        {
            String nom = "gloup";
            String image = "blase.jpeg";
            String description = "que dal ...";

            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("nom", nom));
            params.add(new BasicNameValuePair("image", image));
            params.add(new BasicNameValuePair("description", description));

            // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_add_jeu, "POST", params);

            // check log cat fro response
            Log.d("Create Response", json.toString());

            // check for success tag
            try
            {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1)
                {
                    // successfully created product
 //                   Intent i = new Intent(getApplicationContext(), AllProductsActivity.class);
 //                   startActivity(i);
                    // closing this screen
//                    finish();

                    String aaa= "fff";
                    int j = 5;

                }

                else
                {
                    // failed to create product
                }
            }

            catch (JSONException e)
            {
                e.printStackTrace();
            }

            return null;
        }


        protected void onPostExecute(String file_url)
        {
            // dismiss the dialog once done
            //pDialog.dismiss();
        }

    }
}