// special request is called when student clicks on the special request button
  // and based on rqid this function is called
  private void getspecialrequest(final String uid) {

    StringRequest strReq =
        new StringRequest(
            Request.Method.POST,
            AppConfig.URL_GETSR,
            new Response.Listener<String>() {

              @Override
              public void onResponse(String response) {

                try {
                  JSONObject jObj = new JSONObject(response);
                  String nofofrequests = jObj.getString("noofrequests");
                  // response from sever
                  if (nofofrequests.equals("0")) {
                    Intent i = new Intent(Student_Dashboard.this, Special_Request.class);
                    startActivity(i);
                    finish();
                  } else {
                    JSONArray reques = jObj.getJSONArray("requez");
                    JSONObject jobj1 = reques.getJSONObject(0);
                    String msg =
                        jobj1.getString(
                            "reqmessage"); // getting the stored msg present which he sent while
                                           // sending special request
                    // rdate is the date on which he sent the request
                    String rdate = jobj1.getString("rdate");
                    // it shows the response of that request whether yet responded or not and what
                    // action taken if responeded
                    String reqresponse = jobj1.getString("reqresponse");

                    // passing all above data to submitted request class and showing the request if
                    // present else
                    // redirected to the screen from where he will send the request
                    Intent i = new Intent(Student_Dashboard.this, Submitted_Request.class);
                    i.putExtra("msg", msg);
                    i.putExtra("rdate", rdate);
                    i.putExtra("response", reqresponse);
                    startActivity(i);
                  }
                } catch (JSONException e) {
                  e.printStackTrace();
                }
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError error) {
                Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG)
                    .show();
              }
            }) {

          @Override // sending getsr and usergroup and student type to see whether
          // any special request is present in databse or not for that student
          protected Map<String, String> getParams() {
            // Posting params to register url
            String usertype = "student";
            String getsr = "numcsa";
            Map<String, String> params = new HashMap<String, String>();
            params.put("getsr", getsr);
            params.put("uid", uid);
            params.put("usertype", usertype);
            return params;
          }
        };

    AppController.getInstance().addToRequestQueue(strReq);
  }
  // checkforn is called when student clicks on wing form button
  private void CheckForm(final String uid) {

    StringRequest strReq =
        new StringRequest(
            Request.Method.POST,
            AppConfig.URl_CHECKFORM,
            new Response.Listener<String>() {

              @Override
              public void onResponse(String response) {

                try {
                  JSONObject jObj =
                      new JSONObject(
                          response); // for storing their response when called checkform api
                  // Response from server
                  String success = jObj.getString("success");
                  String msg =
                      jObj.getString(
                          "message"); // we take response msg and according to redirect the student
                                      // to three different class
                  // if no form present then procedure of wing form details submission
                  // if saved form present then getsaved form function is called else getsubmitted
                  // form function is called

                  // redirecting to the class according to which class is present
                  if (msg.equals("noFormPresent")) {
                    Intent i = new Intent(Student_Dashboard.this, Preference.class);
                    startActivity(i);
                  } else if (msg.equals("savedFormPresent")) {
                    getsavedform();
                  } else if (msg.equals("submittedFormPresent")) {
                    getsubmittedform();
                  }

                } catch (JSONException e) {
                  e.printStackTrace();
                }
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError error) {
                Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG)
                    .show();
              }
            }) {

          @Override // response getting after calling checkform.php link and sending student id and
                    // checkform string to the server
          protected Map<String, String> getParams() {
            // Posting params to register url
            String checkform = "numcsa";
            Map<String, String> params = new HashMap<String, String>();
            params.put("checkform", checkform);
            params.put("uid", uid);
            return params;
          }
        };

    AppController.getInstance().addToRequestQueue(strReq);
  }
  // based in the response of checkform this function is called if submit  form is present of that
  // student in database
  private void getsubmittedform() {
    StringRequest strReq =
        new StringRequest(
            Request.Method.POST,
            AppConfig.URL_GETSUBMITTEDFORM,
            new Response.Listener<String>() {

              @Override
              public void onResponse(String response) {

                String savesid[] = new String[6];
                String hostelid[] = new String[2];
                String floor[] = new String[2];

                try {
                  JSONObject jObj = new JSONObject(response);
                  // Response from server
                  String number = jObj.getString("noofstudent");
                  int n =
                      Integer.parseInt(number); // no of student in the wing from which he filled
                  int m =
                      n
                          / 2; // m will show the no of rooms required for displaying in submitted
                               // form
                  String pref_noofrooms =
                      String.valueOf(
                          m); // convert in string so that we can pass via intent to submitted form
                              // class
                  JSONArray entry =
                      jObj.getJSONArray(
                          "entry"); // json array of above json object to store student id
                  // in string array and then passing to submitted form for diplay
                  for (int i = 0; i < n; i++) {
                    JSONObject jobj1 = entry.getJSONObject(i);
                    savesid[i] = jobj1.getString("sid");
                  }
                  JSONArray pref = jObj.getJSONArray("pref");
                  for (int j = 0; j < 2; j++) {
                    JSONObject jobj2 = pref.getJSONObject(j);
                    hostelid[j] =
                        jobj2.getString(
                            "hostelid"); // storing the preferrred hostel from getsubmittedform.php
                                         // file response
                    floor[j] =
                        jobj2.getString(
                            "floorno"); // storing the preferrred hostel from getsubmittedform.php
                                        // file response
                  }

                  Intent i = new Intent(Student_Dashboard.this, Submitted_Form.class);
                  i.putExtra("sid", savesid); // passing all id
                  i.putExtra("noOfStudents", pref_noofrooms); // passing number of rooms
                  i.putExtra("Hostel_type", hostelid);
                  i.putExtra("Floor_type", floor);
                  startActivity(i);
                  // pfid hostel id and floor id is also passing from this activity to saved form
                  // activity

                } catch (JSONException e) {
                  e.printStackTrace();
                }
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError error) {
                Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG)
                    .show();
              }
            }) {

          @Override // getting response after sending string getsubmittedform and uid of that
                    // student
          // it gives submitted form if present in database
          protected Map<String, String> getParams() {
            // Posting params to register url
            String form = "numcsa";
            String uid = AppController.getString(Student_Dashboard.this, "Student_id");
            Map<String, String> params = new HashMap<String, String>();
            params.put("getsubmittedform", form);
            params.put("uid", uid);
            return params;
          }
        };

    AppController.getInstance().addToRequestQueue(strReq);
  }
  /*  get notification is called when student click on notification button
   * it gives the response by sending student id and usergroup as student and in response it shows all the notification given by warden*/
  private void get_notification(final String uid, final String number) {
    StringRequest strReq =
        new StringRequest(
            Request.Method.POST,
            AppConfig.URL_GET_NOTIFY,
            new Response.Listener<String>() {
              // url is called which is currently stored in appconfig class

              @Override
              public void onResponse(String response) {

                ArrayList<String> data =
                    new ArrayList<>(); // arraylist to store all msg we get in response from server

                try {
                  JSONObject jObj =
                      new JSONObject(
                          response); // make json object jobj to take data from getnotification.php
                                     // file
                  // Response from server
                  JSONArray notify =
                      jObj.getJSONArray(
                          "notiz"); // make json array notify of jobj as data is received in array
                                    // form because there can be many noifications
                  for (int i = 0; i < Integer.parseInt(number); i++) {
                    JSONObject jobj1 =
                        notify.getJSONObject(
                            i); // make json object of that array and take all the msg present in
                                // each notification and who created the notification and
                                // notification type
                    // which gets stored in arraylist
                    data.add(
                        jobj1.getString("nmessage")
                            + " by "
                            + jobj1.getString("creatorid")
                            + " on "
                            + jobj1.getString("ndate")
                            + " ("
                            + jobj1.getString("ntype")
                            + ").");
                  }

                  Intent i =
                      new Intent(
                          Student_Dashboard.this,
                          Student_Notify
                              .class); // notification class is called where the student will see
                                       // the notification present and their creator id
                  // and when notification is created adn type of notification
                  i.putStringArrayListExtra(
                      "msg_list", data); // array list is passed to the notification class
                  startActivity(i);

                } catch (JSONException e) {
                  e.printStackTrace();
                }
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError error) {
                Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG)
                    .show();
              }
            }) {

          @Override
          protected Map<String, String> getParams() {
            // Posting params to register url
            String getnotification = "numcsa";
            String usergroup = "student";
            Map<String, String> params = new HashMap<String, String>();
            params.put("usergroup", usergroup);
            params.put("uid", uid);
            params.put("getnotification", getnotification);
            return params;
          }
        };

    AppController.getInstance().addToRequestQueue(strReq);
  }