From 4c814f4b1b0e03a7045768c9066402cd43633761 Mon Sep 17 00:00:00 2001
From: girvandip <girvandip@gmail.com>
Date: Sun, 1 Oct 2017 21:04:01 +0700
Subject: [PATCH] adding more methods into user model

---
 model/user.php                               | 40 ++++++++++++++++++++
 view/{edit-profile.html => edit-profile.php} |  3 ++
 view/{register.html => register.php}         | 15 ++++----
 3 files changed, 51 insertions(+), 7 deletions(-)
 rename view/{edit-profile.html => edit-profile.php} (95%)
 rename view/{register.html => register.php} (89%)

diff --git a/model/user.php b/model/user.php
index 25a33243..af4befe8 100644
--- a/model/user.php
+++ b/model/user.php
@@ -27,4 +27,44 @@ class User {
         mysqli_close($con);
         return $result;
     }
+
+    function saveProfileById($id, $name, $phone, $isDriver, $image) {
+        $con = mysqli_connect('localhost','root','','projekers');
+        mysqli_select_db($con,'projekers');
+        $sql = "update user set name='" . (string)$name . "', phone ='" . (string)$phone . "', isDriver='" .
+            $isDriver ."', image='" . (string)$image . "' where id=" . $id;
+        mysqli_query($con, $sql);
+        mysqli_close($con);
+    }
+
+    function createProfile($name, $username, $email, $password, $phone, $isDriver) {
+        $con = mysqli_connect('localhost','root','','projekers');
+        mysqli_select_db($con, 'projekers');
+        $image = "pikachu.jpg";
+        $sql = "INSERT INTO user(username, name, email, password, phone, isDriver, image) VALUES('" .
+            (string)$username . "', '" . (string)$name . "', '" . (string)$email . "', '" . (string)$password. "', '" .
+            (string)$phone . "', " . $isDriver . ", '" . $image . "')";
+
+        mysqli_query($con,$sql);
+        mysqli_close($con);
+    }
+
+    function getUsername($username) {
+        $con = mysqli_connect('localhost','root','','projekers');
+        mysqli_select_db($con,'projekers');
+        $query = "SELECT id FROM user WHERE username = '" . $username . "'";
+        $result = mysqli_query($con,$query);
+        mysqli_close($con);
+        return $result;
+    }
+
+    function getEmail($email) {
+        $con = mysqli_connect('localhost','root','','projekers');
+        mysqli_select_db($con,'projekers');
+        $query = "SELECT id FROM user WHERE email = '" . $email . "'";
+        $result = mysqli_query($con,$query);
+        mysqli_close($con);
+        return $result;
+    }
+
 }
\ No newline at end of file
diff --git a/view/edit-profile.html b/view/edit-profile.php
similarity index 95%
rename from view/edit-profile.html
rename to view/edit-profile.php
index b5650182..112e8ddc 100644
--- a/view/edit-profile.html
+++ b/view/edit-profile.php
@@ -3,6 +3,9 @@
     <title>Edit-profile</title>
     <link href="../css/primary.css" type="text/css" rel="stylesheet">
     <link href="../css/edit-profile.css" type="text/css" rel="stylesheet">
+    <script>
+        var sessionid = "<?php echo $_GET['id']; ?>";
+    </script>
     <script src="../js/edit-profile.js"></script>
 </head>
 <body onpageshow="getUserProfile();">
diff --git a/view/register.html b/view/register.php
similarity index 89%
rename from view/register.html
rename to view/register.php
index f882b2bd..022d8c5c 100644
--- a/view/register.html
+++ b/view/register.php
@@ -16,34 +16,35 @@
             <br>
             <br>
             <div class="form-input">
-                <form action="register.php" method="post">
+                <form action="../controller/register.php" method="post">
                     <div class="user-input">
                         <div class="label-input">Your Name</label></div>
-                        <div class="text-input"><input type="text" name="full-name" maxlength="20"></div>
+                        <div class="text-input"><input type="text" name="full-name"></div>
                     </div>
                     <div class="user-input">
                         <div class="label-input">Username</label></div>
-                        <div class="text-input-with-check"><input type="text" name="username" maxlength="20"></div>
+                        <div class="text-input-with-check"><input type="text" name="username"></div>
+                        <img id="username-status"></img>
                         <div><img src="../img/check.png" class="check-icon"></div>
                         <div><img src="../img/delete.png" class="delete-icon"></div>
                     </div>
                     <div class="user-input">
                         <div class="label-input">Email</label></div>
-                        <div class="text-input-with-check"><input type="text" name="email" maxlength="20"></div>
+                        <div class="text-input-with-check"><input type="text" name="email"></div>
                         <div><img src="../img/check.png" class="check-icon"></div>
                         <div><img src="../img/delete.png" class="delete-icon"></div>
                     </div>
                     <div class="user-input">
                         <div class="label-input">Password</label></div>
-                        <div class="text-input"><input type="password" name="password" maxlength="20"></div>
+                        <div class="text-input"><input type="password" name="password"></div>
                     </div>
                     <div class="user-input">
                         <div class="label-input">Confirm Password</label></div>
-                        <div class="text-input"><input type="password" name="confirm-password" maxlength="20"></div>
+                        <div class="text-input"><input type="password" name="confirm-password"></div>
                     </div>
                     <div class="user-input">
                         <div class="label-input">Phone Number</label></div>
-                        <div class="text-input"><input type="text" name="phone" maxlength="11"></div>
+                        <div class="text-input"><input type="text" name="phone"></div>
                     </div>
                     <br>
                     <div class="checkbox">
-- 
GitLab