public function upload() { $cfile = new CURLFile('useruploaddata.xls', 'application/vnd.ms-excel', 'useruploaddata.xls'); $webRequest = new WebRequest(); $params = array("action" => 'login', "username" => "admin", "password" => "admin"); $result = $webRequest->post("http://localhost/rozgarmela/admin/", $params); //echo "tried to login, result is " . $result . "\n"; $params = array("user_group_id" => 'JobSeeker', "import_file" => $cfile, "file_type" => 'xls', "csv_delimiter" => 'semicolon', "encodingFromCharset" => 'UTF-8', "action" => 'Import'); $result = $webRequest->post("http://localhost/rozgarmela/admin/import-users/", $params); echo "sent data, result is " . $result . "\n"; return $result; }
private function handleLogin() { global $gLogger; $gLogger->log("Handling login"); // variable to set the status of the login // defaults to false. $success = false; $error = ""; $username = WebRequest::post("lgUsername"); $password = WebRequest::post("lgPassword"); $userAccount = InternalUser::getByName($username); if ($userAccount) { if ($userAccount->authenticate($password)) { // log in $gLogger->log("Login: OK"); $success = true; Session::setLoggedInUser($userAccount->getId()); } else { $error = "bad-password"; $gLogger->log("Login:Bad password"); } } else { $error = "bad-username"; $gLogger->log("Login:Bad username"); } if ($success) { global $cWebPath; $this->mHeaders[] = "HTTP/1.1 303 See Other"; $this->mHeaders[] = "Location: " . $cWebPath . "/management.php"; } else { $this->error($error); $this->showLoginForm(); } }
private function showEditRoomPage() { if (WebRequest::wasPosted()) { try { // get variables $rname = WebRequest::post("rname"); $rtype = WebRequest::postInt("rtype"); $rmin = WebRequest::postInt("rmin"); $rmax = WebRequest::postInt("rmax"); $rprice = WebRequest::postFloat("rprice"); $id = WebRequest::getInt("id"); // data validation if ($rname == "") { throw new CreateRoomException("blank-roomname"); } if ($rtype == 0) { throw new CreateRoomException("blank-roomtype"); } if ($rmax < 1 || $rmin < 0) { throw new CreateRoomException("room-capacity-too-small"); } if ($rmin > $rmax) { throw new CreateRoomException("room-capacity-min-gt-max"); } if ($rprice != abs($rprice)) { throw new CreateRoomException("room-price-negative"); } $room = Room::getById($id); if ($room == null) { throw new Exception("Room does not exist"); } // set values $room->setName($rname); $room->setType($rtype); $room->setMinPeople($rmin); $room->setMaxPeople($rmax); $room->setPrice($rprice); $room->save(); global $cScriptPath; $this->mHeaders[] = "Location: {$cScriptPath}/Rooms"; } catch (CreateRoomException $ex) { $this->mBasePage = "mgmt/roomEdit.tpl"; $this->error($ex->getMessage()); } } else { $this->mBasePage = "mgmt/roomEdit.tpl"; $room = Room::getById(WebRequest::getInt("id")); if ($room == null) { throw new Exception("Room does not exist"); } $this->mSmarty->assign("roomid", $room->getId()); $this->mSmarty->assign("rname", $room->getName()); $this->mSmarty->assign("rmin", $room->getMinPeople()); $this->mSmarty->assign("rmax", $room->getMaxPeople()); $this->mSmarty->assign("rprice", $room->getPrice()); $this->mSmarty->assign("rtype", $room->getType()->getId()); } $this->mSmarty->assign("rtlist", RoomType::$data); }
/** * @covers ByJG\Util\WebRequest::post */ public function testPost5() { $this->object = new WebRequest(self::SERVER_TEST . '?extra=ok'); $response = $this->object->post(['param' => 'value']); $this->assertEquals(200, $this->object->getLastStatus()); $result = json_decode($response, true); $expected = ['content-type' => 'application/x-www-form-urlencoded', 'method' => 'POST', 'query_string' => ['extra' => 'ok'], 'post_string' => ['param' => 'value'], 'payload' => 'param=value']; $this->assertEquals($expected, $result); }
protected function runPage() { if (Session::isCustomerLoggedIn()) { global $cWebPath; // redirect to main page $this->mHeaders[] = "HTTP/1.1 303 See Other"; $this->mHeaders[] = "Location: " . $cWebPath . "/index.php"; return; } if (WebRequest::wasPosted()) { if (WebRequest::get("id") && WebRequest::get("hash")) { // setting password $id = WebRequest::get("id"); $hash = WebRequest::get("hash"); $customer = Customer::getById($id); try { if ($customer->getMailChecksum() != $hash) { throw new InvalidChecksumException(); } $suPassword = WebRequest::post("suPassword"); $suConfirm = WebRequest::post("suConfirm"); // validation if ($suPassword == "") { throw new CreateCustomerException("Password not specified"); } if ($suConfirm == "") { throw new CreateCustomerException("Confirmed password not specified"); } if ($suPassword != $suConfirm) { throw new CreateCustomerException("Password mismatch"); } // validation if ($suPassword != "" && $suPassword == $suConfirm) { $customer->setPassword($suPassword); } $customer->save(); // log them in Session::setLoggedInCustomer($id); // redirect to main page global $cWebPath; $this->mHeaders[] = "HTTP/1.1 303 See Other"; $this->mHeaders[] = "Location: " . $cWebPath . "/index.php"; } catch (CreateCustomerException $ex) { $this->mBasePage = "changePassword.tpl"; $this->error($ex->getMessage()); } catch (InvalidChecksumException $ex) { $this->mBasePage = "changePassword.tpl"; $this->error($ex->getMessage()); } } else { // requesting try { $suEmail = WebRequest::post("suEmail"); // validation if ($suEmail == "") { throw new CreateCustomerException("Email not specified"); } $customer = Customer::getByEmail($suEmail); if ($customer == null) { throw new NonexistantObjectException(); } $customer->sendPasswordReset(); $this->mBasePage = "forgotpassword.tpl"; // TODO: show some confirmation, check email, etc } catch (CreateCustomerException $ex) { $this->mBasePage = "forgottenpassword.tpl"; $this->error($ex->getMessage()); } catch (NonexistantObjectException $ex) { $this->mBasePage = "forgottenpassword.tpl"; $this->error("nonexistant object"); } } } else { if (WebRequest::get("id") && WebRequest::get("hash")) { // show reset password form try { $id = WebRequest::get("id"); $hash = WebRequest::get("hash"); $customer = Customer::getById($id); if ($customer->getMailChecksum() != $hash) { throw new InvalidChecksumException(); } $this->mBasePage = "changePassword.tpl"; $this->mSmarty->assign("cpid", $id); $this->mSmarty->assign("cphash", $hash); } catch (InvalidChecksumException $ex) { $this->mBasePage = "forgottenpassword.tpl"; $this->error("invalid checksum"); } } else { // show request form $this->mBasePage = "forgottenpassword.tpl"; return; } } }
public function showCal() { $this->mBasePage = "cal.tpl"; global $cWebPath; $startdate = new DateTime(WebRequest::post("qbCheckin")); $enddate = new DateTime(WebRequest::post("qbCheckout")); $idlist = Room::getIdList(); $dates = array(); for ($date = $startdate; $date < $enddate; $date->modify("+1 day")) { $dates[] = clone $date; } $availabilityMatrix = array(); $roomlist = array(); foreach ($idlist as $id) { $r = Room::getById($id); $roomlist[$id] = $r; $availabilityMatrix[$id] = array(); foreach ($dates as $d) { $availabilityMatrix[$id][array_search($d, $dates)] = !$r->isAvailable($d); } } $this->mSmarty->assign("availmatrix", $availabilityMatrix); $this->mSmarty->assign("datelist", $dates); $this->mSmarty->assign("roomlist", $roomlist); $this->mSmarty->assign("valQbCheckin", WebRequest::postString("qbCheckin")); $this->mSmarty->assign("valQbCheckout", WebRequest::postString("qbCheckout")); $this->mSmarty->assign("valQbAdults", WebRequest::postInt("qbAdults")); $this->mSmarty->assign("valQbChildren", WebRequest::postInt("qbChildren")); $this->mSmarty->assign("valQbPromoCode", WebRequest::postString("qbPromoCode")); $this->mSmarty->assign("valQbTitle", WebRequest::post("qbTitle")); $this->mSmarty->assign("valQbFirstname", WebRequest::post("qbFirstname")); $this->mSmarty->assign("valQbLastname", WebRequest::post("qbLastname")); $this->mSmarty->assign("valQbAddress", WebRequest::post("qbAddress")); $this->mSmarty->assign("valQbCity", WebRequest::post("qbCity")); $this->mSmarty->assign("valQbPostcode", WebRequest::post("qbPostcode")); $this->mSmarty->assign("valQbCountry", WebRequest::post("qbCountry")); $this->mSmarty->assign("valQbEmail", WebRequest::post("qbEmail")); }
private function showChangePasswordPage() { $userid = WebRequest::getInt("id"); if ($userid < 1) { throw new Exception("UserID too small"); } if (InternalUser::getById($userid) == null) { throw new Exception("User does not exist"); } if (WebRequest::wasPosted()) { try { if (WebRequest::post("newpass") != WebRequest::post("newpass2")) { throw new CreateUserException("Passwords do not match"); } $password = WebRequest::post("newpass"); $user = InternalUser::getById($userid); $user->setPassword($password); $user->save(); global $cScriptPath; $this->mHeaders[] = "Location: {$cScriptPath}/SystemUsers"; } catch (CreateUserException $ex) { $this->error("password-nomatch"); $this->mSmarty->assign("userid", $userid); $this->mBasePage = "mgmt/iuserChangePw.tpl"; } } else { $this->mSmarty->assign("userid", $userid); $this->mBasePage = "mgmt/iuserChangePw.tpl"; } }
private function showAddBillItemPage() { $rt = WebRequest::getInt("id"); if (WebRequest::wasPosted()) { $bi = new Bill_item(); $bi->setBooking(Booking::getById($rt)); $bi->setName(WebRequest::post("billname")); $bi->setPrice(WebRequest::post("billprice")); $bi->save(); global $cScriptPath; $this->mHeaders[] = "Location: {$cScriptPath}/Billing?action=view&id={$rt}"; } else { $this->mSmarty->assign("bid", $rt); $this->mBasePage = "mgmt/billcreate.tpl"; } }
private function showAccount() { if (WebRequest::wasPosted()) { try { // get variables $suTitle = WebRequest::post("suTitle"); $suFirstname = WebRequest::post("suFirstname"); $suLastname = WebRequest::post("suLastname"); $suAddress = WebRequest::post("suAddress"); $suCity = WebRequest::post("suCity"); $suPostcode = WebRequest::post("suPostcode"); $suCountry = WebRequest::post("suCountry"); $suEmail = WebRequest::post("suEmail"); $suPassword = WebRequest::post("suPassword"); $suConfirm = WebRequest::post("suConfirm"); $id = Session::getLoggedInCustomer(); // data validation if ($suTitle == "") { throw new CreateCustomerException("suTitle not specified"); } if ($suFirstname == "") { throw new CreateCustomerException("suFirstname not specified"); } if ($suLastname == "") { throw new CreateCustomerException("suLastname not specified"); } if ($suAddress == "") { throw new CreateCustomerException("suAddress not specified"); } if ($suCity == "") { throw new CreateCustomerException("suCity not specified"); } if ($suPostcode == "") { throw new CreateCustomerException("suPostcode not specified"); } if ($suCountry == "") { throw new CreateCustomerException("suCountry not specified"); } if ($suEmail == "") { throw new CreateCustomerException("suEmail not specified"); } $customer = Customer::getById($id); if ($customer == null) { throw new Exception("Custoemr does not exist"); } if ($suPassword != "" && $suPassword == $suConfirm) { $customer->setPassword($suPassword); } // set values $customer->setTitle($suTitle); $customer->setFirstname($suFirstname); $customer->setSurname($suLastname); $address = $customer->getAddress(); $address->setLine1($suAddress); $address->setCity($suCity); $address->setPostcode($suPostcode); $address->setCountry($suCountry); if ($customer->getEmail() != $suEmail) { $customer->setEmail($suEmail); $customer->sendMailConfirm(); } // save it $address->save(); $customer->save(); global $cScriptPath; $this->mHeaders[] = "Location: {$cScriptPath}/Account"; } catch (CreateCustomerException $ex) { $this->mBasePage = "account.tpl"; $this->error($ex->getMessage()); } } else { $this->mBasePage = "account.tpl"; $customer = Customer::getById(Session::getLoggedInCustomer()); if ($customer == null) { throw new Exception("Customer does not exist"); } $this->mSmarty->assign("custid", $customer->getId()); $this->mSmarty->assign("suTitle", $customer->getTitle()); $this->mSmarty->assign("suFirstname", $customer->getFirstName()); $this->mSmarty->assign("suLastname", $customer->getSurname()); $this->mSmarty->assign("suAddress", $customer->getAddress()->getLine1()); $this->mSmarty->assign("suCity", $customer->getAddress()->getCity()); $this->mSmarty->assign("suPostcode", $customer->getAddress()->getPostcode()); $this->mSmarty->assign("suCountry", $customer->getAddress()->getCountry()); $this->mSmarty->assign("suEmail", $customer->getEmail()); } }
private function save() { $keys = WebRequest::getPostKeys(); foreach ($keys as $k) { // extract id from POST request $id = str_replace("lang", "", $k); $id = str_replace("msg", "", $id); if (!is_numeric($id)) { throw new ArgumentException("{$k}: [{$id}] is not an integer", 0); } // retrieve message object $message = Message::getById($id); if ($message == null) { throw new ArgumentException("Message ID {$id} could not be found"); } $value = WebRequest::post($k); if ($message->getContent != $value) { // write content $message->setContent($value); // save object $message->save(); } } }
private function showEditBookingPage() { if (WebRequest::wasPosted()) { try { // get variables $bcust = WebRequest::postInt("bcust"); $badults = WebRequest::postInt("badults"); $bchildren = WebRequest::postInt("bchildren"); $bstart = WebRequest::post("bstart"); $bend = WebRequest::post("bend"); $bpromo = WebRequest::postInt("bpromo"); $broom = WebRequest::PostInt("broom"); $id = WebRequest::getInt("id"); // data validation if ($badults == 0) { throw new CreateBookingException("no-adults"); } if ($bstart == null) { throw new CreateBookingException("no-start-date"); } if ($bend == null) { throw new CreateBookingException("no-end-date"); } if ($bcust == null) { throw new CreateBookingException("no-customer-for-booking"); } $booking = Booking::getById($id); if ($booking == null) { throw new CreateBookingException("Booking does not exist"); } // set values $booking->setCustomer($bcust); $booking->setAdults($badults); $booking->setChildren($rmin); $booking->setStartDate($rmax); $booking->setEndDate($rprice); $booking->setPromocode($bpromo); $booking->setRoom($broom); $booking->save(); global $cScriptPath; $this->mHeaders[] = "Location: {$cScriptPath}/Bookings"; } catch (CreateBookingException $ex) { $this->mBasePage = "mgmt/bookingEdit.tpl"; $this->error($ex->getMessage()); } } else { try { $this->mBasePage = "mgmt/bookingEdit.tpl"; $booking = Booking::getById(WebRequest::getInt("id")); if ($booking == null) { throw new Exception("Booking does not exist"); } $this->mSmarty->assign("bookingid", $booking->getId()); $this->mSmarty->assign("bcust", $booking->getCustomer()->getId()); $this->mSmarty->assign("badults", $booking->getAdults()); $this->mSmarty->assign("bchildren", $booking->getChildren()); $this->mSmarty->assign("bstart", $booking->getStartDate()); $this->mSmarty->assign("bend", $booking->getEndDate()); $this->mSmarty->assign("bpromo", $booking->getPromocode()); $this->mSmarty->assign("broom", $booking->getRoom()->getId()); } catch (Exception $ex) { $this->mBasePage = "mgmt/bookingEdit.tpl"; $this->error($ex->getMessage()); } } }
protected function runPage() { $showError = ""; $error = ""; global $cWebPath; $this->mBasePage = "signup.tpl"; if (Session::isCustomerLoggedIn()) { // why do you want another account? // redirect to main page $this->mHeaders[] = "HTTP/1.1 303 See Other"; $this->mHeaders[] = "Location: " . $cWebPath . "/index.php"; } if (WebRequest::wasPosted()) { try { $suTitle = WebRequest::post("suTitle"); $suFirstname = WebRequest::post("suFirstname"); $suLastname = WebRequest::post("suLastname"); $suAddress = WebRequest::post("suAddress"); $suCity = WebRequest::post("suCity"); $suPostcode = WebRequest::post("suPostcode"); $suCountry = WebRequest::post("suCountry"); $suEmail = WebRequest::post("suEmail"); $suPassword = WebRequest::post("suPassword"); $suConfirm = WebRequest::post("suConfirm"); // data validation if ($suTitle == "") { throw new CreateCustomerException("Title not specified"); } if ($suFirstname == "") { throw new CreateCustomerException("Firstname not specified"); } if ($suLastname == "") { throw new CreateCustomerException("Lastname not specified"); } if ($suAddress == "") { throw new CreateCustomerException("Address not specified"); } if ($suCity == "") { throw new CreateCustomerException("City not specified"); } if ($suPostcode == "") { throw new CreateCustomerException("Postcode not specified"); } if ($suCountry == "") { throw new CreateCustomerException("Country not specified"); } if ($suEmail == "") { throw new CreateCustomerException("Email not specified"); } if ($suPassword == "") { throw new CreateCustomerException("Password not specified"); } if ($suConfirm == "") { throw new CreateCustomerException("Confirmed password not specified"); } if ($suPassword != $suConfirm) { throw new CreateCustomerException("Password mismatch"); } $customer = new Customer(); if ($suPassword != "" && $suPassword == $suConfirm) { $customer->setPassword($suPassword); } // set values $customer->setTitle($suTitle); $customer->setFirstname($suFirstname); $customer->setSurname($suLastname); $address = new Address(); $address->setLine1($suAddress); $address->setCity($suCity); $address->setPostCode($suPostcode); $address->setCountry($suCountry); $address->save(); $customer->setAddress($address); $customer->setEmail($suEmail); // save it $customer->save(); $customer->sendMailConfirm(); global $cScriptPath; $this->mHeaders[] = "Location: {$cScriptPath}"; } catch (CreateCustomerException $ex) { $this->mBasePage = "signup.tpl"; $this->error($ex->getMessage()); } } else { $this->mBasePage = "signup.tpl"; } }