public function actionSetUserEventParticipation()
 {
     $objValidator = new helpers\Validation();
     $params = array('event', 'user_token', 'participation');
     try {
         $isRequestValid = $objValidator->validateRequest($params);
         if ($isRequestValid) {
             $userToken = $this->_request->getPost('user_token', null);
             $objUserMdl = new \models\Users();
             $eventId = $this->_request->getPost('event', null);
             $dataToInsert = array('events_id' => $eventId, 'participation_id' => $this->_request->getPost('participation', null));
             // check if user is valid or not
             $userDetails = $objUserMdl->getUserFromToken($userToken);
             if (!$userDetails) {
                 $this->_request->sendErrorResponse(403, 403, 'User token invalid');
             }
             $objUsersEventParticipation = new \models\UsersEventsParticipation();
             $dataToInsert['users_id'] = $userDetails->id;
             $isStatusSaved = $objUsersEventParticipation->insertUserEventParticipation($dataToInsert, $userDetails);
             if ($isStatusSaved) {
                 // send push notification
                 $objNotifier = new \models\Pushnotifications();
                 $objNotifier->participationNotifications($eventId, $userDetails);
                 $this->_request->sendSuccessResponse('Status Saved');
             } else {
                 $this->_request->sendErrorResponse(404, 404, 'Error saving status');
             }
         } else {
             $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated');
         }
     } catch (\Exception $e) {
         $this->_request->sendErrorResponse(404, 404, $e->getMessage());
     }
 }
Example #2
0
 public function nr($id = null)
 {
     $is_loged = LoginVal::isLogged();
     $http = new Http();
     $this->product_m = new \models\Product($id[0]);
     $name = $this->product_m->getName();
     if (empty($name)) {
         Location::To(URL . 'error');
     }
     $available = $this->product_m->getQuantity();
     $promotions = new Promotions($id[0]);
     $pro = $promotions->getPromotion();
     if (!empty($pro)) {
         $old_price = $this->product_m->getOldPrice($pro->getPercent());
         $discount = $pro->getPercent() * 100;
     }
     $additionals = $this->product_m->getAdditionals();
     $a_images = $this->product_m->getAdditionalImages();
     $comments_m = new Comments($id[0]);
     $pagination = new Pagination(2, $comments_m->getNumberOfComments());
     $avg_rating = $comments_m->getAverageRating();
     $comments = $comments_m->getComments(2, $pagination->page($id[1]));
     $next = $pagination->next();
     $prev = $pagination->prev();
     $num_pages = $pagination->getPages();
     $selected = $pagination->getSelected();
     $comment = $http->post('comment');
     if (!empty($comment) && $is_loged && $http->isActive('send') && !empty($this->product_m)) {
         $comment = new Comment();
         $comment->setComment($http->post('comment'));
         $comment->setDate();
         $comment->setProductId($this->product_m->getId());
         $comment->setUserId(Register::get('id'));
         $comment->setRate($http->post('star'));
         $comment->writeData();
         Location::To(URL . 'product/nr/' . $id[0]);
     }
     $comment_tab = array();
     if (!empty($comments)) {
         foreach ($comments as $key => $comment) {
             if (!empty($comment)) {
                 $comment_tab[$key]['comment'] = $comment->getComment();
                 $comment_tab[$key]['date'] = $comment->getDate();
                 $comment_tab[$key]['rate'] = $comment->getRate();
                 $user = new \models\Users($comment->getUserId());
                 $login = $user->getLogin();
                 $comment_tab[$key]['login'] = empty($login) ? 'anonimowy' : $login;
             }
         }
     }
     $this->render('product', array('categories' => $this->categories, 'd_product' => $this->d_product, 'category' => $this->product_m->getCategory(), 'name' => $this->product_m->getName(), 'description' => $this->product_m->getDescription(), 'image' => $this->product_m->getImage(), 'quantity' => $this->product_m->getQuantity(), 'price' => $this->product_m->getPrice(), 'additionals' => $additionals, 'images' => $a_images, 'comments' => $comment_tab, 'product_nr' => $id[0], 'next' => $next, 'prev' => $prev, 'num_pages' => $num_pages, 'selected' => $selected, 'is_loged' => $is_loged, 'avg_rating' => $avg_rating, 'discount' => $discount, 'old_price' => $old_price, 'available' => $available));
 }
 /**
  * Function to send notification to all clients
  * @param int $userId id of the user for which ipn request is to be sent
  * @return void
  * **/
 public function sendIpnForUser($userId)
 {
     $objUserModel = new \models\Users();
     $userRow = $objUserModel->getUserById($userId);
     if ($userRow) {
         $dataToSend = array('first_name' => $userRow->first_name, 'last_name' => $userRow->last_name, 'email_address' => $userRow->email, 'username' => $userRow->user_name, 'cimba_auth_id' => $userRow->id);
         $this->_parameters = $dataToSend;
         $clientResponse = $this->_request();
         $status = -1;
         //mark synced status as ipn request sent
         $objUserSyncStatusModel = new \models\UserSyncStatus();
         $userSyncStatusRow = $objUserSyncStatusModel->getRowByUserId($userRow->id);
         if ($clientResponse) {
             $status = $clientResponse['data']['status'];
         }
         if ($userSyncStatusRow) {
             $userSyncStatusRow->amt_sync_status = $status;
             $objUserSyncStatusModel->getRedBeans()->store($userSyncStatusRow);
         }
     }
 }
Example #4
0
 public function actionUpdateUserProfile()
 {
     $objValidator = new helpers\Validation();
     $objImageProcessor = new helpers\ImageProcessor();
     $params = array('user_token');
     try {
         $isRequestValid = $objValidator->validateRequest($params);
         if ($isRequestValid) {
             $objUserAuthMdl = new \models\Users();
             $userToken = $this->_request->getPost('user_token', null);
             $userDetails = $objUserAuthMdl->getUserFromToken($userToken);
             if (!$userDetails) {
                 $this->_request->sendErrorResponse(403, 403, 'User token invalid');
             }
             $profilePhoto = null;
             $profilePostedPic = $this->_request->getPost('profilepic', null);
             $dpPath = __DIR__ . '/../images/' . $userDetails->id . '_pp.jpg';
             if ($profilePostedPic && $objImageProcessor->convertBase64ToImage($profilePostedPic, $dpPath)) {
                 $profilePhoto = $userDetails->id . '_pp.jpg';
             }
             $password = $this->_request->getPost('password', null);
             $dataToUpdate = array('first_name' => $this->_request->getPost('first_name', null), 'last_name' => $this->_request->getPost('last_name', null), 'email' => $this->_request->getPost('email', null), 'password' => $password ? md5($password) : null, 'city' => $this->_request->getPost('city', null), 'country' => $this->_request->getPost('country', null), 'gender' => $this->_request->getPost('gender', null), 'phone' => $this->_request->getPost('phone', null), 'address' => $this->_request->getPost('address', null), 'websiteurl' => $this->_request->getPost('websiteurl', null));
             $fileterdArray = array_filter($dataToUpdate);
             if (empty($fileterdArray)) {
                 $this->_request->sendErrorResponse(404, 404, 'Please pass data to update');
             }
             // check if user is valid or not
             $return = $objUserAuthMdl->updateUser($dataToUpdate, $userDetails);
             if ($return && $return > 0) {
                 $this->_request->sendSuccessResponse('User successfully updated');
             } else {
                 if ($return == -1) {
                     $this->_request->sendErrorResponse(404, 404, 'Email alredy exists');
                 } else {
                     if ($return == -2) {
                         $this->_request->sendErrorResponse(404, 404, 'Invalid email address');
                     } else {
                         $this->_request->sendErrorResponse(404, 404, 'Error updating user please try latere');
                     }
                 }
             }
         } else {
             $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated');
         }
     } catch (\Exception $e) {
         $this->_request->sendErrorResponse(404, 404, $e->getMessage());
     }
 }
Example #5
0
 public function actionUpdate()
 {
     $objValidator = new helpers\Validation();
     $params = array('dog_id', 'name', 'date_of_birth', 'breed', 'gender', 'user_token');
     try {
         $isRequestValid = $objValidator->validateRequest($params);
         if ($isRequestValid) {
             $userToken = $this->_request->getPost('user_token', null);
             $objUserMdl = new \models\Users();
             $objDogMdl = new \models\Dogs();
             $dataToInsert = array('name' => $this->_request->getPost('name', null), 'date_of_birth' => $this->_request->getPost('date_of_birth', null), 'dog_breed_id' => $this->_request->getPost('breed', null), 'gender' => $this->_request->getPost('gender', null), 'dog_pic' => $this->_request->getPost('dogpic', null), 'id' => $this->_request->getPost('dog_id', null));
             // check if user is valid or not
             $userDetails = $objUserMdl->getUserFromToken($userToken);
             if (!$userDetails) {
                 $this->_request->sendErrorResponse(403, 403, 'User token invalid');
             }
             $isDogInserted = $objDogMdl->updateDogProfile($dataToInsert, $userDetails->id);
             if ($isDogInserted) {
                 $this->_request->sendSuccessResponse('Dog Profile updated');
             } else {
                 $this->_request->sendErrorResponse(404, 404, 'Error updating dog profile');
             }
         } else {
             $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated');
         }
     } catch (\Exception $e) {
         echo $e->getMessage();
         $this->_request->sendErrorResponse(404, 404, $e->getMessage());
     }
 }
Example #6
0
 /**
  * Public function action delete event
  * 
  * **/
 public function actionDeleteEvent()
 {
     $objValidator = new helpers\Validation();
     $params = array('user_token', 'eventid');
     try {
         $isRequestValid = $objValidator->validateRequest($params);
         if ($isRequestValid) {
             $userToken = $this->_request->getPost('user_token', null);
             $eventId = $this->_request->getPost('eventid', null);
             $objUserAuthMdl = new \models\Users();
             $objEventsModel = new \models\Events();
             $userDetails = $objUserAuthMdl->getUserFromToken($userToken);
             if (!$userDetails) {
                 $this->_request->sendErrorResponse(403, 403, 'User token invalid');
             }
             //check if event exists or not
             $eventRow = $objEventsModel->findEventById($eventId);
             if (!$eventRow->id) {
                 $this->_request->sendErrorResponse(403, 403, 'Invalid Event');
             }
             // check if event is owned by user
             $isUserEventOwner = $eventRow->users_id == $userDetails->id ? true : false;
             if (!$isUserEventOwner) {
                 $this->_request->sendErrorResponse(403, 403, 'User is not authenticated to delete event');
             }
             try {
                 \R::trash($eventRow);
                 $this->_request->sendSuccessResponse('Event successfully deleted');
             } catch (Exception $ex) {
                 $this->_request->sendErrorResponse(403, 403, 'Error deleting event');
             }
         } else {
             $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated');
         }
     } catch (\Exception $e) {
         $this->_request->sendErrorResponse(404, 404, $e->getMessage());
     }
 }
Example #7
0
 public function actionMigrate()
 {
     $params = array('email', 'username', 'first_name', 'last_name', 'password', 'salt');
     try {
         $isRequestValid = $this->_validator->validateRequest($params);
         if ($isRequestValid) {
             $username = $this->_request->getParam('username', null);
             $email = $this->_request->getParam('email', null);
             $firstName = $this->_request->getParam('first_name', null);
             $lastName = $this->_request->getParam('last_name', null);
             $password = $this->_request->getParam('password', null);
             $salt = $this->_request->getParam('salt', null);
             $objUsersModel = new \models\Users();
             $userData = array('email' => $email, 'username' => $username, 'first_name' => $firstName, 'last_name' => $lastName, 'password' => $password, 'salt' => $salt);
             $userId = $objUsersModel->tempMigrate($userData);
             if ($userId !== -1) {
                 $this->_response->renderJson(array('message' => 'User successfully registered', 'authId' => $userId), 200);
             } else {
                 if ($userId === -1) {
                     $this->_response->renderJson(array('message' => 'This email is already registered'), 404);
                 } else {
                     $this->_response->renderJson(array('message' => 'Error registering user'), 404);
                 }
             }
         } else {
             $this->_response->renderJson(array('message' => 'Request cannot be validated'), 400);
         }
     } catch (\Exception $e) {
         $this->_response->renderJson(array('message' => $e->getMessage()), 500);
     }
 }
Example #8
0
 private function eraseUser()
 {
     $message_m = new \Models\Messages(\lib\Register::get('id'));
     $messages = $message_m->getMessages();
     if (!empty($messages)) {
         foreach ($messages as $message) {
             $message_m->deleteMessages($message->getId());
         }
     }
     $user_e = new \models\User(\lib\Register::get('id'));
     $user_e->delete();
     $user = new \models\Users(\lib\Register::get('id'));
     $user->delete();
     Location::To(URL . 'logout');
 }
Example #9
0
 public function actionSearchExpertsByLocation()
 {
     $objValidator = new helpers\Validation();
     $params = array('user_token', 'query');
     try {
         $isRequestValid = $objValidator->validateRequest($params);
         if ($isRequestValid) {
             $userToken = $this->_request->getPost('user_token', null);
             $objUserMdl = new \models\Users();
             $obUserProfileMdl = new \models\UsersProfiles();
             // check if user is valid or not
             $userDetails = $objUserMdl->getUserFromToken($userToken);
             if (!$userDetails) {
                 $this->_request->sendErrorResponse(403, 403, 'User token invalid');
             }
             $query = $this->_request->getPost('query', null);
             $profiles = $obUserProfileMdl->searchUsersByLocation($query);
             if ($profiles) {
                 $this->_request->sendSuccessResponse('success', $profiles);
             } else {
                 $this->_request->sendErrorResponse(404, 404, 'Profiles not found');
             }
         } else {
             $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated');
         }
     } catch (\Exception $e) {
         echo $e->getMessage();
         $this->_request->sendErrorResponse(404, 404, $e->getMessage());
     }
 }
Example #10
0
<?php

// require necessary files
require_once 'autoload.php';
use libDb\Db;
try {
    // Try to call the class
    $objUsersModel = new \models\Users();
    $objUsersModel->getAllUsers();
} catch (Exception $ex) {
    echo $ex->getMessage();
}