Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-type: application/json; charset=utf-8');
- class ArendiWebServices {
- private $db;
- // Constructor - open DB connection
- function __construct() {
- $this->db = new mysqli('localhost', 'root', '47yk2d8r6c', 'arendi');
- $this->db->autocommit(FALSE);
- $stmt1 = $this->db->prepare("SET NAMES 'utf8'");
- $stmt1->execute();
- $stmt2 = $this->db->prepare('SET CHARACTER SET "utf8"');
- $stmt2->execute();
- }
- // Destructor - close DB connection
- function __destruct() {
- $this->db->close();
- }
- // Main method to redeem a code
- function getProjects() {
- error_log("getProjects: giriş\n", 3, "/php.log");
- $stmt = $this->db->prepare('SELECT * FROM projects');
- $stmt->bind_result($id, $no, $title, $subject, $description, $attachment, $status);
- if ($stmt->execute()) {
- error_log("getProjects: if\n", 3, "/php.log");
- //$result = "{\"success\":1";
- $result = array();
- while ($stmt->fetch()) {
- $row = array("id" => $id, "no" => $no, "title" => $title, "subject" => $subject, "description" => $description, "attachment" => $attachment, "status" => $status);
- $result[] = $row;
- }
- echo json_encode($result);
- }
- $stmt->close();
- error_log("getProjects: çıkış\n", 3, "/php.log");
- }
- function getUser($email, $password) {
- error_log("in service\n", 3, "/php.log");
- $stmt = $this->db->prepare("SELECT * FROM users WHERE email=? && password=?");
- $stmt->bind_param("ss", $email, $password);
- $id = 0;
- $companyid = 0;
- $name = "";
- $surname = "";
- $email2 = "";
- $password2 = "";
- $stmt->bind_result($id, $companyid, $name, $surname, $email2, $password2);
- if ($stmt->execute()) {
- if ($stmt->fetch()) {
- $stmt->close();
- error_log($id . " - " . $companyid . " - " . $name . " - " . $surname . " - " . $email2 . " - " . $password2 . "\n", 3, "/php.log");
- $stmt2 = $this->db->prepare("SELECT * FROM companies WHERE id=?");
- $stmt2->bind_param("i", $companyid);
- $cid = 0;
- $cname = "";
- $caddress = "";
- $cphone = "";
- $cwebpage = "";
- $stmt2->bind_result($cid, $cname, $caddress, $cphone, $cwebpage);
- $result = "{\"success\":1,";
- $result = $result . "\"id\":\"" . $id . "\",";
- $result = $result . "\"companyid\":\"" . $cid . "\",";
- $result = $result . "\"companyname\":\"" . $cname . "\",";
- $result = $result . "\"name\":\"" . $name . "\",";
- $result = $result . "\"surname\":\"" . $surname . "\",";
- $result = $result . "\"email\":\"" . $email2 . "\",";
- $result = $result . "\"password\":\"" . $password2 . "\"}";
- $stmt2->close();
- //echo "{\"success\":1,\"id\":\"".$id."\",\"companyid\":\"".$cid."\",\"companyname\":\"".$cname."\",\"name\":\"".$name."\",\"surname\":\"".$surname."\",\"email\":\"".$email2."\",\"password\":\"".$password2."\"}";
- echo $result;
- error_log($cid . " - " . $cname . " - " . $caddress . " - " . $cphone . " - " . $cwebpage . "\n", 3, "/php.log");
- } else {
- echo "{\"success\":0,\"error_message\":\"Kullanıcı adı ya da" . "şifre hatalı.1\",\"email\":\"" . $email . "\",\"password\":\"" . $password . "\"}";
- }
- } else {
- echo "{\"success\":0,\"error_message\":\"Kullanıcı adı ya da " . "şifre hatalı.2\"}";
- }
- }
- function getFoods() {
- error_log("getFoods: giriş\n", 3, "/php.log");
- $stmt = $this->db->prepare("SELECT * FROM yiyecekler");
- $stmt->bind_result($id, $name, $imageUrl, $price, $ingredient, $cookingTime, $star, $videoUrl, $category, $recipe);
- if ($stmt->execute()) {
- error_log("getFoods: if\n", 3, "/php.log");
- //$result = "{\"success\":1";
- $result = array();
- while ($stmt->fetch()) {
- $row = array("id" => $id, "name" => $name, "imageUrl" => $imageUrl, "price" => $price, "ingredient" => $ingredient, "cookingTime" => $cookingTime, "star" => $star, "videoUrl" => $videoUrl, "category" => $category, "recipe" => $recipe);
- $result[] = $row;
- }
- echo json_encode($result);
- }
- $stmt->close();
- error_log("getFoods: çıkış\n", 3, "/php.log");
- }
- function getCategories() {
- error_log("getCategory: giriş\n", 3, "/php.log");
- $stmt = $this->db->prepare('SELECT * FROM category');
- $stmt->bind_result($id, $categoryName);
- if ($stmt->execute()) {
- $result = array();
- while ($stmt->fetch()) {
- $row = array("id" => $id, "category" => $categoryName);
- $result[] = $row;
- }
- echo json_encode($result);
- }
- $stmt->close();
- error_log("getCatergory: çıkış\n", 3, "/php.log");
- }
- function getCookbyName($name) {
- //statement
- $stmt = $this->db->prepare("SELECT * FROM restoran WHERE name=? ");
- $stmt->bind_param("s", $name);
- $stmt->bind_result($id, $name2, $imageurl, $price, $ingredient, $cookingTime, $star, $videoUrl, $category, $recipe);
- if ($stmt->execute()) {
- if ($stmt->fetch()) {
- //printf("Kullanıcı adı şifre veri tabanında mevcut: %s %s\n",
- //$email, $password);
- //echo '{"success":1,"email":"' . $email2 . '","password":"' .
- //$password2 . '"}';
- echo '{"success":1,"name":"' . $name2 . '","imageUrl":"' . $imageurl . '","price":"' . $price . '"}';
- } else {
- echo "{\"success\":0,\"error_message\":\"Yemek adı hatalı.1\"," . "\"email\":\"" . $name . '"}';
- }
- } else {
- echo '{"success":0,"error_message":"Yemek adi hatali.2"}';
- }
- $stmt->close();
- }
- function getMenu() {
- $menu = array("İmam Bayıldı", "Kuru Fasulye", "Pilav", "Mercimek Çorbası", "Bamya");
- echo json_encode($menu);
- }
- }
- $post = filter_input_array(INPUT_POST);
- if (isset($post['username']) && isset($post['password'])) {
- error_log("Arendi Web Services\n", 3, "/php.log");
- error_log("Post data loaded.\n", 3, "/php.log");
- $arendiService = new ArendiWebServices();
- error_log("Service instance created\n", 3, "/php.log");
- error_log("servis: login\n", 3, "php.log");
- error_log($post['username'] . " - " . $post['password'] . "\n", 3, "php.log");
- if ($arendiService)
- $arendiService->getUser($post['username'], $post['password']);
- else
- error_log("servis: failed to create service instane\n", 3, "php.log");
- }
- // else if (isset($post['request'])) {
- // error_log("servis: getprojects\n", 3, "/php.log");
- // if ($post['request'] == "getprojects") {
- // error_log("servis: request - getprojects\n", 3, "/php.log");
- // $arendiService->getProjects();
- // } else if ($post['request'] == "getMenu") {
- // error_log("servis: request - getMenu", 3, "/php.log");
- // $arendiService->getMenu();
- // } else if ($post['request'] == "getCategories") {
- // error_log("servis: request - getMenu", 3, "/php.log");
- // $arendiService->getCategories();
- // } else {
- // error_log("servis: tanımsız servis\n", 3, "/php.log");
- // echo '{"success":0,"error_message":"Tanımsız istek!"}';
- // }
- // } else {
- // error_log("servis: son\n", 3, "/php.log");
- // echo '{"success":0,"error_message":"Kullanıcı adı ya da şifre hatalı."}';
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement