@@ -0,0 +1,75 @@
package sahara.sahara;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;

import java.util.ArrayList;

public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.ViewHolder> {

public ArrayList<Product> mProducts;
private LayoutInflater mLayoutInflater;
private ItemClickListener mClickListener;

public ProductAdapter(Context context, ArrayList<Product> p) {
mLayoutInflater = LayoutInflater.from(context);
mProducts = p;
}

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView category;
public TextView productInfo;
public ViewHolder(View v) {
super(v);
category = (TextView) v.findViewById(R.id.category);
productInfo = (TextView) v.findViewById(R.id.product);
v.setOnClickListener(this);
}

@Override
public void onClick(View v) {
if (mClickListener != null) mClickListener.onItemClick(v, getAdapterPosition());
}

}

@Override
public ProductAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// create a new view
View v = mLayoutInflater.inflate(R.layout.product_row, parent, false);
ProductAdapter.ViewHolder vh = new ProductAdapter.ViewHolder(v);
return vh;
}

@Override
public void onBindViewHolder(ProductAdapter.ViewHolder holder, int position) {
holder.category.setText(mProducts.get(position).category);
holder.productInfo.setText(mProducts.get(position).title + " $" +
Float.toString(mProducts.get(position).price));
}

@Override
public int getItemCount() {
return mProducts.size();
}

// allows clicks events to be caught
void setClickListener(ItemClickListener itemClickListener) {
this.mClickListener = itemClickListener;
}

// parent activity will implement this method to respond to click events
public interface ItemClickListener {
void onItemClick(View view, int position);
}

Product getItem(int position) {
return mProducts.get(position);
}
}
@@ -77,7 +77,9 @@ public void onResponse(String response) {
"Registration Successfull!",
Toast.LENGTH_SHORT
).show();
startActivity(new Intent(getApplicationContext(), Login.class));
Intent i = new Intent(getApplicationContext(), UserInfo.class);
i.putExtra("EMAIL", uemail);
startActivity(i);
finish();
} else {
Toast.makeText(
@@ -1,13 +1,193 @@
package sahara.sahara;

import android.support.v7.app.AppCompatActivity;
import android.app.DatePickerDialog;

import android.content.Intent;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.Pair;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class UserInfo extends AppCompatActivity {
import static android.text.TextUtils.isEmpty;

public class UserInfo extends FragmentActivity implements DatePickerDialog.OnDateSetListener {

int y = -1;
int m = -1;
int d = -1;

public void onDateSet(DatePicker view, int year, int month, int day) {
y = year;
m = month;
d = day;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_info);
final Button addInfo = (Button) findViewById(R.id.addinfo);
final Button skip = (Button) findViewById(R.id.skip);
final EditText fname = (EditText) findViewById(R.id.firstname);
final EditText mname = (EditText) findViewById(R.id.middlename);
final EditText lname = (EditText) findViewById(R.id.lastname);
final Button dob = (Button) findViewById(R.id.birthday);
final EditText address = (EditText) findViewById(R.id.address);
final EditText phone = (EditText) findViewById(R.id.phonenumber);
final EditText zipcode = (EditText) findViewById(R.id.zipcode);

skip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), Login.class));
finish();
}
});

addInfo.setOnClickListener(new View.OnClickListener() {
private void updateUserInfo(final String fn, final String mn, final String ln, final String pn, final String addr, final String zc, final long unixTime) {
StringRequest stringRequest = new StringRequest(Request.Method.POST,
Constants.URL_UPDATEUSERINFO,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
if (!jsonObject.getBoolean("error")){
Toast.makeText(
getApplicationContext(),
"Profile Update Successfull",
Toast.LENGTH_SHORT
).show();
if(!PreferenceManager.getInstance(getApplicationContext()).isUserLoggedIn()) {
startActivity(new Intent(getApplicationContext(), Login.class));
finish();
}
else {
startActivity(new Intent(getApplicationContext(), MainActivity.class));
finish();
}
} else {
Toast.makeText(
getApplicationContext(),
jsonObject.getString("message"),
Toast.LENGTH_LONG
).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() { // If listener listens, then we had an error and we will display the msg from db.
@Override
public void onErrorResponse(VolleyError error) {
if(error.getMessage() != null) {
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
}else {
Toast.makeText(
getApplicationContext(),
"Check your connection or contact the administrator.",
Toast.LENGTH_LONG
).show();
}

}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError { // Script returned a message, now we make does variables.
Map<String, String> params = new HashMap<>();
params.put("u_email", getIntent().getStringExtra("EMAIL"));
JSONObject jo = new JSONObject();
try {
jo.put("u_fn", fn);
jo.put("u_mn", mn);
jo.put("u_ln", ln);
jo.put("u_zcode", zc);
jo.put("u_address", addr);
jo.put("u_dob", Long.toString(unixTime));
jo.put("u_phone_number", pn);
} catch(JSONException e) {
e.printStackTrace();
}
params.put("parameters", jo.toString());
return params;
}
};
// This request handler keeps the internet connection until logout... Instead of attempt everytime.
RequestHandler.getInstance(getApplicationContext()).addToRequestQueue(stringRequest);
}
@Override
public void onClick(View v) {
if(isEmpty(fname.getText().toString().trim())) {
Toast.makeText(getApplicationContext(), "First name can't be empty!", Toast.LENGTH_SHORT).show();
return;
}
else if(isEmpty(mname.getText().toString().trim())) {
Toast.makeText(getApplicationContext(), "Middle name can't be empty!", Toast.LENGTH_SHORT).show();
return;
}
else if(isEmpty(lname.getText().toString().trim())) {
Toast.makeText(getApplicationContext(), "Last name can't be empty!", Toast.LENGTH_SHORT).show();
return;
}
else if(isEmpty(address.getText().toString().trim())) {
Toast.makeText(getApplicationContext(), "Address can't be empty!", Toast.LENGTH_SHORT).show();
return;
}
else if(isEmpty(phone.getText().toString().trim())) {
Toast.makeText(getApplicationContext(), "Phone number can't be empty!", Toast.LENGTH_SHORT).show();
return;
}
else if(phone.getText().toString().trim().length() > 10) {
Toast.makeText(getApplicationContext(), "Phone number can't be longer than 10 digits!", Toast.LENGTH_SHORT).show();
return;
}
else if(isEmpty(zipcode.getText().toString().trim())) {
Toast.makeText(getApplicationContext(), "Zipcode can't be empty!", Toast.LENGTH_SHORT).show();
return;
}
else if(zipcode.getText().toString().trim().length() > 5) {
Toast.makeText(getApplicationContext(), "Zipcode can't be greater than 5 digits!", Toast.LENGTH_SHORT).show();
return;
}
else if(y == -1) {
Toast.makeText(getApplicationContext(), "Date of birth can't be empty!", Toast.LENGTH_SHORT).show();
return;
}
updateUserInfo(fname.getText().toString().trim(), mname.getText().toString().trim(), lname.getText().toString().trim(),
phone.getText().toString().trim(), address.getText().toString().trim(), zipcode.getText().toString().trim(), new Date(y-1900,m,d).getTime() / 1000L);
}
});

}

public void showDatePickerDialog(View v) {
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "datePicker");
}

}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -6,4 +6,12 @@
android:layout_height="match_parent"
tools:context="sahara.sahara.MainActivity">

<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView"
android:scrollbars="vertical">

</android.support.v7.widget.RecyclerView>

</android.support.constraint.ConstraintLayout>
@@ -6,4 +6,248 @@
android:layout_height="match_parent"
tools:context="sahara.sahara.UserInfo">

<android.support.design.widget.TextInputLayout
style="@style/Theme.AppCompat.Light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.058"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.116">

<android.support.design.widget.TextInputEditText
android:id="@+id/firstname"
android:layout_width="157dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Firstname"
android:inputType="textEmailAddress"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.215"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.274" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.058"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<android.support.design.widget.TextInputEditText
android:id="@+id/lastname"
android:layout_width="161dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Lastname"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.215"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.44" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.058"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.304">

<android.support.design.widget.TextInputEditText
android:id="@+id/middlename"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Middlename"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.215"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.44" />
</android.support.design.widget.TextInputLayout>

<Button
android:id="@+id/birthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:onClick="showDatePickerDialog"
android:text="Date of Birth"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.844"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.134" />

<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.958"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.304">

<android.support.design.widget.TextInputEditText
android:id="@+id/address"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Address"
android:inputType="textPostalAddress"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.215"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.44" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.958"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<android.support.design.widget.TextInputEditText
android:id="@+id/zipcode"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Zipcode"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.215"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.44" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.669">

<android.support.design.widget.TextInputEditText
android:id="@+id/phonenumber"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Phone Number"
android:inputType="phone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.215"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.44" />
</android.support.design.widget.TextInputLayout>

<Button
android:id="@+id/addinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Add Information"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.159"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.816" />

<Button
android:id="@+id/skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="skip"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.739"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.816" />

</android.support.constraint.ConstraintLayout>
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
cardview:cardCornerRadius="2dp"
cardview:cardElevation="3dp"
cardview:cardUseCompatPadding="true">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:maxLines="3"
android:padding="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textColor="#444"
android:textSize="18dp"
android:textStyle="bold"/>

<TextView
android:id="@+id/category"
android:layout_below="@id/product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:maxLines="3"
android:padding="8dp" />

</RelativeLayout>
</android.support.v7.widget.CardView>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/shopping_cart"
android:title="Shopping Cart" />

<item android:id="@+id/shopping_history"
android:title="Purchase History" />

<item android:id="@+id/update_information"
android:title="Update Information" />
</menu>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item android:id="@+id/action_search"
android:title="Search"
android:icon="@drawable/ic_search_black_24dp"
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView" />

</menu>
@@ -30,18 +30,22 @@ public function createUser(&$u_email, &$u_pword){
}
}
// update user profile
public function updateUserProfile(&$parameters, &$u_email){
public function updateUserProfile(&$u_email, &$parameters){
// If user is NOT in the database, then we can't change anything
if($this->doesUserExist($u_email) == 0){
if($this->doesUserExist($u_email) == 0){
return -1;
}else{
// need to get parameters
$parameters = json_decode($parameters);
foreach ($parameters as $key => $value)
{
$attribute = $key;
$attribute_value = $value;
$statement = $this->connection->prepare("UPDATE users SET ? = ? WHERE u_email = ?"); // If the user doesn't exist we will try to create it.
$statement->bind_param("sss",$attribute,$attribute_value,$u_email);
if($key === "u_dob") {
$int = (int)$value;
$value = date("Y-m-d",$int);
}
$query = "UPDATE users SET " . $key . " = " . "\"" . $value . "\"" . " WHERE u_email = " . "\"" . $u_email . "\"";
$statement = $this->connection->prepare($query);
//$statement->bind_param("ss",$attribute_value,$u_email);
// in case query fails
if(!$statement->execute())
{
@@ -53,6 +57,85 @@ public function updateUserProfile(&$parameters, &$u_email){
}
}

public function addToCart(&$u_email, &$p_recid, &$pr_recid) {
if($this->doesUserExist($u_email) == 0){
return -1;
}else {
$u_recid = $this->getu_recid($u_email)['u_recid'];
error_log("u_recid: " . $u_recid, 0);
// get current quantity
$quantity = $this->connection->prepare("SELECT pri_quantity FROM producer_inventory WHERE p_recid = ? AND pr_recid = ?");
$quantity->bind_param("ss", $p_recid, $pr_recid);
if(!$quantity->execute()) {
return 0;
}
$quantity = $quantity->get_result()->fetch_assoc()['pri_quantity']-1;
// update quantity to be quantity-1
$query = "UPDATE producer_inventory SET pri_quantity = ? WHERE p_recid = ? AND pr_recid = ?";
$statement = $this->connection->prepare($query);
$statement->bind_param("sss",$quantity, $p_recid, $pr_recid);
if(!$statement->execute())
{
return 0;
}
// get number currently in shopping cart
$quantity = $this->connection->prepare("SELECT sc_quantity FROM shopping_cart WHERE u_recid = ? AND p_recid = ? AND pr_recid = ?");
$quantity->bind_param("sss", $u_recid, $p_recid, $pr_recid);
if(!$quantity->execute()) {
return 0;
}
$quantity = $quantity->get_result();
error_log("Number of rows: " . $quantity->num_rows, 0);
if($quantity->num_rows > 0) {
$quantity = $quantity->fetch_assoc()['sc_quantity']+1;
// update shopping cart to quantity+1
$query = "UPDATE shopping_cart SET sc_quantity = ? WHERE u_recid = ? AND p_recid = ? AND pr_recid = ?";
$statement = $this->connection->prepare($query);
$statement->bind_param("ssss", $quantity, $u_recid, $p_recid, $pr_recid);
if(!$statement->execute())
{
return 0;
}
}
else {
$query = "INSERT INTO shopping_cart VALUES (?, ?, ?, 1)";
$statement = $this->connection->prepare($query);
$statement->bind_param("sss",$u_recid, $p_recid, $pr_recid);
if(!$statement->execute())
{
return 0;
}
}
// If we got here all queries were successfull.
return 1;
}
}

// get all products and categories
public function getProducts() {
$statement = $this->connection->prepare("SELECT products.p_recid, products.pr_recid, p_name, p_price, c_name FROM products, product_category, producer_inventory WHERE products.c_recid = product_category.c_recid AND products.p_recid = producer_inventory.p_recid AND producer_inventory.pri_quantity > 0 AND products.pr_recid = producer_inventory.pr_recid");
$statement->execute();
$result = $statement->get_result();
$arr = array();
while($row = $result->fetch_assoc()) {
$arr[] = $row;
}
return $arr;
}

// filter products and categories by product name
public function searchProducts(&$search){
$statement = $this->connection->prepare("SELECT products.p_recid, products.pr_recid, p_name, p_price, c_name FROM products, product_category, producer_inventory WHERE products.c_recid = product_category.c_recid AND products.p_name LIKE \"%" . $search . "%\" AND products.p_recid = producer_inventory.p_recid AND producer_inventory.pri_quantity > 0 AND products.pr_recid = producer_inventory.pr_recid");
$statement->execute();
$result = $statement->get_result();
$arr = array();
while($row = $result->fetch_assoc()) {
$arr[] = $row;
}
return $arr;
}


// userLogin function searches for matching parameters (email, password) in the database.
public function userLogin(&$u_email, &$u_pword){
$password = $this->USF_encrypt($u_pword);
@@ -73,7 +156,7 @@ public function getUserByEmail(&$u_email){
}
private function getu_recid(&$u_email){
$statement = $this->connection->prepare("SELECT u_recid FROM users WHERE u_email = ?");
$statement->bind_param("s",$response);
$statement->bind_param("s",$u_email);
$statement->execute();
return $statement->get_result()->fetch_assoc();
}
@@ -0,0 +1,37 @@
<?php
// Script that updates information of an user. -Diego Fabiano

require_once '../includes/DBManipulation.php';


$response = array();

// Making sure that the right method is requested.
if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_POST['u_email']) && isset($_POST['p_recid']) && isset($_POST['pr_recid'])) {
$db = new DBManipulation();
/*
date_default_timezone_set('EST5EDT');
$timestamp = date('Y-m-d G:i:s');
*/
// attempting to create user.
$db_response = $db->addToCart($_POST['u_email'], $_POST['p_recid'], $_POST['pr_recid']);
if($db_response == 1){
$response['error'] = false;
$response['message'] = "Item added to shopping cart!";
} else if($db_response == -1){
$response['error'] = true;
$response['message'] = "Item couldnt be added!";
} else {
$response['error'] = true;
$response['message'] = "Some error occurred while tryng to access the database, please try again";
}
} else {
$response['error'] = true;
$response['message'] = "Make sure to send an email, p_recid, and pr_recid";
}
}else{ // If we got here it means we did not pushed the ewsright method from the app.
$response['error'] = true;
$response['message'] = "Invalid Request";
}
echo json_encode($response);
@@ -0,0 +1,21 @@
<?php
require_once '../includes/DBManipulation.php';
$response = array();

// Making sure that the right method is requested.
if($_SERVER['REQUEST_METHOD']=='GET'){
$db = new DBManipulation();
/*
date_default_timezone_set('EST5EDT');
$timestamp = date('Y-m-d G:i:s');
*/
// attempting to create user.
$db_response = $db->getProducts();
$response['error'] = false;
$response['message'] = "Products fetched successfully!";
$response['products'] = $db_response;
}else{ // If we got here it means we did not pushed the ewsright method from the app.
$response['error'] = true;
$response['message'] = "Invalid Request";
}
echo json_encode($response);
@@ -0,0 +1,27 @@
<?php
require_once '../includes/DBManipulation.php';
$response = array();

// Making sure that the right method is requested.
if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_POST['query'])) {
$db = new DBManipulation();
/*
date_default_timezone_set('EST5EDT');
$timestamp = date('Y-m-d G:i:s');
*/
// attempting to create user.
$query = $_POST['query'];
$db_response = $db->searchProducts($query);
$response['error'] = false;
$response['message'] = "Products fetched successfully!";
$response['products'] = $db_response;
} else {
$response['error'] = true;
$response['message'] = "String must be passed!";
}
}else{ // If we got here it means we did not pushed the ewsright method from the app.
$response['error'] = true;
$response['message'] = "Invalid Request";
}
echo json_encode($response);
@@ -15,21 +15,20 @@
$timestamp = date('Y-m-d G:i:s');
*/
// attempting to create user.
$db_response = $db->updateUserProfile($_POST['u_email'],$_POST['parameters']);
$db_response = $db->updateUserProfile($_POST['u_email'], $_POST['parameters']);
if($db_response == 1){
$response['error'] = false;
$response['message'] = "User: " . $_POST['e_email'] . " updated successfully ";
$response['message'] = "User: " . $_POST['u_email'] . " updated successfully ";
} else if($db_response == -1){
$response['error'] = true;
$response['message'] = "User is not in the database, please register the user";
} else {
$response['error'] = true;
$response['message'] = "Some error occurred while tryng to access the database, please try again";
}
}else{
//we don't have enough parameters
$response['error'] = true;
$response['message'] = "Make sure to provide email";
} else {
$response['error'] = true;
$response['message'] = "Make sure to send an email";
}
}else{ // If we got here it means we did not pushed the ewsright method from the app.
$response['error'] = true;
@@ -14,7 +14,7 @@
$db_response = $db->createUser($_POST['u_email'],$_POST['u_pword']);
if($db_response == 1){
$response['error'] = false;
$response['message'] = "User: " . $_POST['e_email'] . " created successfully ";
$response['message'] = "User: " . $_POST['u_email'] . " created successfully ";
} else if($db_response == -1){
$response['error'] = true;
$response['message'] = "User is already in the database, please login";