private function updateEvent($user_id, $user_password, $event_id, $searchablekeywords)
 {
     $response = array();
     $response["success"] = 0;
     $jsonView = new JsonViewer();
     $tryLogin = new TryUserLogin($user_id, $user_password);
     if ($tryLogin->isExists()) {
         //update the events
         $database = new Database();
         $sql = "UPDATE " . EventTable::TableName . " set " . EventTable::SeachableKeywords . "=:search_keys WHERE " . EventTable::Id . "=:id";
         $smt = $database->prepare($sql);
         $smt->bindValue(":id", $event_id);
         $smt->bindValue(":search_keys", $searchablekeywords);
         $status = $smt->execute();
         if ($status) {
             $response["success"] = 1;
             $response["message"] = "update searchable keys";
         } else {
             $response["error_message"] = "Invalid event details provided";
         }
     } else {
         $response["error_message"] = "Invalid login details";
     }
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function removeEvent($user_id, $password, $event_id)
 {
     $response = array();
     $response["success"] = 0;
     $tryUser = new TryFetchUser();
     $user = $tryUser->fetch($user_id);
     if ($user != null) {
         //convert to php object
         $json_user = json_encode($user);
         $php_user = json_decode($json_user);
         $email = $php_user->Email;
         $trylogin = new TryUserLogin($email, $password);
         if ($trylogin->isExists()) {
             //now check if the event
             $tryRemove = new TryRemoveEvent();
             if ($tryRemove->remove($event_id)) {
                 $response["success"] = 1;
                 $response["message"] = "Event successfully removed";
             } else {
                 $response["error_message"] = "Invalid event details provided {$event_id} ";
             }
         } else {
             $response["error_message"] = "No such information found with the login information";
         }
     } else {
         $response["error_message"] = "Invalid user login information provided";
     }
     $jsonView = new JsonViewer();
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function tryChangePassword($email, $newPassword, $resetCode)
 {
     $response = array();
     $response["success"] = 0;
     $tryChange = new TryChangePassword($email, $resetCode, $newPassword);
     $changed = $tryChange->update();
     if ($changed) {
         $response["success"] = 1;
         $response["message"] = "password as be changed, new password sent to you";
         $message = "You password as be successfully changed" . "\n" . "Username = {$email}\n" . "New Password = {$newPassword}\n" . "" . "\n" . "Change Date = " . date("jS /M, Y", Validator::Now());
         $from = "*****@*****.**";
         $user = $this->getUser($email);
         //send the email if the user exists which suppose to
         if ($user != null) {
             $subject = " Success changed password";
             $trySend = new TrySendEmail($message, $from, $user->Email, $user->Fullname, $subject);
             $trySend->update();
         }
     } else {
         $response["error_message"] = "invalid authentication details\n";
     }
     $jsonView = new JsonViewer();
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function createNewEvent($email, $password, $title, $venue, $privacy, $fees, $currency_country = "")
 {
     $response = array();
     $response["success"] = 0;
     //verify if the user exists
     $trycheck = new TryUserLogin($email, $password);
     if ($trycheck->isExists()) {
         $tryfetch = new TryFetchUser();
         $user = $tryfetch->fetch($email);
         if ($user != null) {
             $user_json = json_encode($user);
             $user_php = json_decode($user_json);
             $event = new Event($user_php->ID, $title, $venue, $privacy);
             $event->setCreateDate(Validator::Now());
             $event->setDuration("");
             $event->setStartDate("");
             $event->setDescription("");
             $event->setFees($fees);
             $event->setCurrencyCountry($currency_country);
             // $event->setSearchableKeywords($searchable);
             //validate the events
             if ($this->validate($event)) {
                 $response = $this->commit($event);
             } else {
                 $response["error_message"] = $this->__message;
             }
         }
     } else {
         $response["success"] = 0;
         $response["error_message"] = "relogin into your account , user session expired";
     }
     $jsonView = new JsonViewer();
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function uploadEventImage($email, $password, $eventId, $imagebase64)
 {
     $response = array();
     $response["success"] = 0;
     //upload the
     $tryLogin = new TryUserLogin($email, $password);
     if ($tryLogin->isExists()) {
         //check if the event exist
         $event = TryFetchUserEvent::FetchById($eventId);
         if ($event != null) {
             print_r($event);
             $tryUploadEventPicture = new TryUploadEventPicture($eventId, $imagebase64);
             $result = $tryUploadEventPicture->update();
             if ($result) {
                 $response["success"] = 1;
                 $response["message"] = "upload successful";
             } else {
                 $response["error_message"] = "There is no image or file to upload";
             }
         } else {
             $response["error_message"] = "There is no event found with the given {$eventId} id";
         }
     } else {
         $response["error_message"] = "User did not exist , have to login first to be able to upload event image";
     }
     $json = new JsonViewer();
     $json->setContent($response);
     return $json;
 }
 private function upLoad($email, $password, $imagebase64)
 {
     $response = array();
     $response["success"] = 0;
     $jsonView = new JsonViewer();
     $tryLogin = new TryUserLogin($email, $password);
     if ($tryLogin->isExists()) {
         $tryUser = new TryFetchUser();
         $user = $tryUser->fetch($email);
         if ($user != null) {
             //the user exists
             $jsonuser = json_encode($user);
             $phpuser = json_decode($jsonuser);
             $tryuploadImage = new TryUploadUserProfilePhoto($phpuser->ID, $imagebase64);
             $path = $tryuploadImage->update();
             if ($path != null) {
                 $response["success"] = 1;
                 $response["src_img"] = $path;
             } else {
                 $response["error_message"] = "Could not upload file not file given";
             }
         }
     } else {
         $response["error_message"] = "Session expired , please relogin with your devices";
     }
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function updateEventDateVenue($user_id, $password, $event_id, $startDate, $endDate)
 {
     $response = array();
     $response["success"] = 0;
     if ($this->isValidated($startDate, $endDate)) {
         //dates are not in pass and are in the future
         $try = new TryUserLogin($user_id, $password);
         if ($try->isExists()) {
             //The account exist
             $tryUpdateDateEvent = new TryUpdateDateEventModel($event_id, $startDate, $endDate);
             $result = $tryUpdateDateEvent->update();
             if ($result) {
                 $response["success"] = 1;
                 $response["message"] = "Event date updated successfully";
             } else {
                 $response["error_message"] = "Invalid event request on unexisting event";
             }
         } else {
             $response["error_message"] = "No user found";
         }
     } else {
         $response["error_message"] = $this->__message;
     }
     $jsonView = new JsonViewer();
     $jsonView->setContent($response);
     return $jsonView;
 }
 public function Update($email, $password, $fullname, $long, $lat)
 {
     $jsonView = new JsonViewer();
     $response = array();
     $response["success"] = 0;
     $tryLogin = new TryUserLogin($email, $password);
     //if exists
     if ($tryLogin->isExists()) {
         //fetch user
         $tryFectUser = new TryFetchUser();
         $user = $tryFectUser->fetch($email);
         if ($user != null) {
             $user = json_encode($user);
             $user_php = json_decode($user);
             //update the user information
             $tryUpdate = new TryUpdateUser($user_php->ID, $fullname, $long, $lat);
             $returnVal = $tryUpdate->update();
             if ($returnVal) {
                 $response["success"] = 1;
                 $response["message"] = "user information updated";
             } else {
                 $response["error_message"] = "Could not update records contact administrator";
             }
         } else {
             $response["message"] = "user information could not be update";
         }
     } else {
         $response["error_message"] = "Valid email or password information passed for update";
     }
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function getLocationAddress($address, $lat, $long)
 {
     $response = array();
     $response["success"] = 0;
     $tryFetchLocation = null;
     $criterial = "";
     if ($lat != null || $long != null) {
         $tryFetchLocation = new TryFetchLocationBaseOnGeoLocation();
         $criterial = "" + urldecode($lat) . "," . urldecode($long);
         //get the best fit and match address
         //fetch the location base on the latitude of the user
     } else {
         //fetch the location base on the address of the user
         $criterial = urldecode($address);
         $tryFetchLocation = new TryFetchLocationBaseOnAddress();
     }
     $addresses = $tryFetchLocation->fetch($criterial);
     if ($addresses != null) {
         $response["success"] = 1;
         $response["addresses"] = $addresses;
     }
     $jsonView = new JsonViewer();
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function updateEvent($user_id, $user_password, $event_id, $desc)
 {
     $response = array();
     $response["success"] = 0;
     $jsonView = new JsonViewer();
     $tryLogin = new TryUserLogin($user_id, $user_password);
     if ($tryLogin->isExists()) {
         //update the events
         $database = new Database();
         $sql = "UPDATE " . EventTable::TableName . " set " . EventTable::Description . "=:desc WHERE " . EventTable::Id . "=:id";
         $smt = $database->prepare($sql);
         $smt->bindValue(":id", $event_id);
         $smt->bindValue(":desc", $desc);
         $status = $smt->execute();
         if ($status) {
             $response["success"] = 1;
             $response["message"] = "Description updated";
         } else {
             $response["error_message"] = "No event with such information found";
         }
     } else {
         $response["error_message"] = "Invalid user login details";
     }
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function getUserByEventId($event_id)
 {
     $response = array();
     $response["success"] = 0;
     if ($event_id != null) {
         $event = TryFetchUserEvent::FetchById($event_id);
         if ($event != null) {
             //there is an event found
             $json_event = json_encode($event);
             $php_event = json_decode($json_event);
             $user_id = $php_event->CreatorId;
             if ($user_id != null) {
                 $tryfetchUser = new TryFetchUser();
                 $user = $tryfetchUser->fetch($user_id);
                 if ($user != null) {
                     $response["success"] = 1;
                     $response["user"] = $user;
                 }
             }
         } else {
             $response["error_message"] = "No event found ";
         }
     } else {
         $response["error_message"] = "Event id must be provided";
     }
     $jsonView = new JsonViewer();
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function fetchEventOn($query)
 {
     $json = new JsonViewer();
     $response = array();
     $response["success"] = 0;
     $trySearchEvent = new TrySearchEventWithQueryStrings();
     $events = $trySearchEvent->fetch($query);
     if ($events != null) {
         $response["success"] = 1;
         $response["events"] = $events;
     } else {
         $response["error_message"] = "No search found with {$query} ";
     }
     $json->setContent($response);
     return $json;
 }
 public function Index()
 {
     $eventId = HttpResquestHandler::getParam("event_id");
     $response = array();
     $response["success"] = 0;
     $event = TryFetchUserEvent::FetchById($eventId);
     if ($event != null) {
         $response["success"] = 1;
         $response["event"] = $event;
     } else {
         $response["error_message"] = "No event found";
         //should not happen
     }
     $json = new JsonViewer();
     $json->setContent($response);
     return $json;
 }
 public function Create($email, $fullname, $gender)
 {
     $jsonView = new JsonViewer();
     $response = array();
     $response["success"] = 0;
     $user = new User();
     $user->setEmail($email)->setFullname($fullname)->setId(Validator::UniqueKey())->setGender($gender);
     if ($this->validate($user)) {
         //call the mthod to try an create the user if the email did not exists
         $response = $this->tryCreate($user);
     } else {
         $response["error_message"] = $this->message;
     }
     //try to fetch the user with the email address if it return null that means the email does not exist
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function update($eventid, $title, $venue, $privacy, $email, $password)
 {
     $response = array();
     $response["success"] = 0;
     //check if the user is valid
     $tryLoginUser = new TryUserLogin($email, $password);
     if ($tryLoginUser->isExists()) {
         //get the current event if exist
         $event = TryFetchUserEvent::FetchById($eventid);
         if ($event != null) {
             //set the event properties to the new added informations
             $eventObject = $this->parserEventJson(json_encode($event));
             if ($eventObject != null) {
                 $eventObject->setTitle($title);
                 $eventObject->setId($eventid);
                 $eventObject->setVenue($venue);
                 $eventObject->setType($privacy);
                 //validate to match such the date send is current
                 if ($this->validateEvent($eventObject)) {
                     //update the vent
                     $tryUpdateEvent = new TryUpdateUserEvent($eventObject);
                     $status = $tryUpdateEvent->update();
                     if ($status) {
                         $response["success"] = 1;
                         $response["message"] = "Event Updated";
                     } else {
                         $response["message"] = "There was error when trying to update event";
                     }
                 } else {
                     $response["error_message"] = $this->__message;
                 }
             }
         } else {
             $response["error_message"] = "Know event with the given information";
         }
         //exist
     } else {
         $response["error_message"] = "Unknown user request...";
     }
     $jsonView = new JsonViewer();
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function getUpdateEvent($user_id, $event_id)
 {
     $response = array();
     $response["success"] = 0;
     $jsonView = new JsonViewer();
     $events = TryFetchUserEvent::FetchById($event_id);
     if ($events != null) {
         $tryuser = new TryFetchUser(new UserTable());
         $user = $tryuser->fetch($user_id);
         if ($user != null) {
             $response = $this->addNewAttendance($events, $user_id, $event_id);
         } else {
             $response["error_message"] = "User no found [{$user_id}]";
         }
     } else {
         $response["error_message"] = "No event find with the given event id [{$event_id}]";
     }
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function getUserInfo($username, $password)
 {
     $jsonViewer = new JsonViewer();
     $response = array();
     $response["success"] = 0;
     $userlogin = new TryUserLogin($username, $password);
     if ($userlogin->isExists()) {
         $tryUser = new TryFetchUser(new UserTable());
         $user = $tryUser->fetch($username);
         $response["success"] = 1;
         $response["user"] = $user;
     } else {
         //check if the user email exist
         $error = "Invalid username[{$username}] or password";
         $response["message_error"] = $error;
     }
     //set the view content to return to the users phone
     $jsonViewer->setContent($response);
     return $jsonViewer;
 }
 private function getProfileImageUrl($email, $password)
 {
     $response = array();
     $response["success"] = 0;
     $tryLogin = new TryUserLogin($email, $password);
     if ($tryLogin->isExists()) {
         $tryFetchUserPhoto = new TryFetchUserProfilePhoto();
         $url = $tryFetchUserPhoto->fetch($email);
         $response["success"] = 1;
         if ($url == null) {
             $url = DEFAULT_IMAGE_PROFILE_URL;
         }
         $response["img_src"] = $url;
     } else {
         $response["error_message"] = "user authentication fails";
     }
     $json = new JsonViewer();
     $json->setContent($response);
     return $json;
 }
 public function Index()
 {
     $email = HttpResquestHandler::getParam("email");
     $password = HttpResquestHandler::getParam("password");
     $response = array();
     $response["success"] = 0;
     $tryuser = new TryFetchUser();
     $userdb = $tryuser->fetch($email);
     if ($userdb != null) {
         $user = new User(json_encode($userdb));
         $tryLogin = new TryUserLogin($user->getId(), $password);
         if ($tryLogin->isExists()) {
             $response["success"] = 1;
         } else {
             $response["error_message"] = "Login details is not current or you have not yet verify your account.";
         }
     } else {
         $response["error_message"] = "Invalid Username or Password";
     }
     $jsonView = new JsonViewer();
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function getUserEvents($email, $password, $noevents)
 {
     $response = array();
     $response["success"] = 0;
     $tryLogin = new TryUserLogin($email, $password);
     if ($tryLogin->isExists()) {
         $tryfetch = new TryFetchUser(new UserTable());
         $user = $tryfetch->fetch($email);
         if ($user != null) {
             $response["success"] = 1;
             $user_json = json_encode($user);
             $php_user = json_decode($user_json);
             $tryfetchEvents = new TryFetchUserEvent($noevents);
             $events = $tryfetchEvents->fetch($php_user->ID);
             $response["events"] = $events;
         } else {
             $response["error_message"] = "Invalid user request";
         }
         $json = new JsonViewer();
         $json->setContent($response);
         return $json;
     }
 }
 public function Index()
 {
     $jsonView = new JsonViewer();
     $response = array();
     $response["success"] = 0;
     $email = HttpResquestHandler::getParam("email");
     $tryReset = new TryResetPassword($email);
     $code = $tryReset->update();
     if ($code != null) {
         $response["success"] = 1;
         $tryFetchUser = new TryFetchUser();
         $user = $tryFetchUser->fetch($email);
         $phpuser = new User(json_encode($user));
         $status = $this->sendUserResetCode($phpuser);
         if ($status) {
             $response["message"] = "The verification as be sent to the email address {$email}";
         }
     } else {
         //this should not happen
         die("Debugging  Error in update reset code");
     }
     $jsonView->setContent($response);
     return $jsonView;
 }
 private function createLoginDetailsFrom($email, $vcode, $newpassword)
 {
     $response = array();
     $response["success"] = 0;
     $tryFetchUser = new TryFetchUser();
     $dbuser = $tryFetchUser->fetch($email);
     if ($dbuser != null) {
         $php_user = new User(json_encode($dbuser));
         if (trim($php_user->getVerificationCode()) == trim($vcode)) {
             //create the new user login details
             //check if the user login details account already exists or created
             $tryCreateLogin = new TryCreateLoginDetail($php_user->getId(), $newpassword);
             if (!$tryCreateLogin->isExists()) {
                 if ($this->validate($newpassword)) {
                     if ($tryCreateLogin->create()) {
                         $response["success"] = 1;
                     } else {
                         //This should never happen
                         $response["error_message"] = "Error occur during login details creations";
                     }
                 } else {
                     $response["error_message"] = "Password characters must be more than 3";
                 }
             } else {
                 $response["error_message"] = "This account has already be verified";
             }
         } else {
             $response["error_message"] = "Invalid verification code provided";
         }
     } else {
         $response["error_message"] = "No account found with the given details";
     }
     $jsonView = new JsonViewer();
     $jsonView->setContent($response);
     return $jsonView;
 }