]> Softwares of Agnibho - simpleipd.git/commitdiff
Bugfixes
authorAgnibho Mondal <mondal@agnibho.com>
Sun, 16 May 2021 08:46:28 +0000 (14:16 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Sun, 16 May 2021 08:46:28 +0000 (14:16 +0530)
adduser [new file with mode: 0755]
attachments.php
forms/admission.schema.json
lib/db.php
lib/foot.php
login.php
res/script.js [new file with mode: 0644]
schema.sql

diff --git a/adduser b/adduser
new file mode 100755 (executable)
index 0000000..6259895
--- /dev/null
+++ b/adduser
@@ -0,0 +1,24 @@
+#! /bin/env php
+<?php
+$db=new SQLite3("data/data.db");
+if(!empty($_SERVER["argv"][1]) && !empty($_SERVER["argv"][2]) && !empty($_SERVER["argv"][3])){
+  $stmt=$db->prepare("SELECT * FROM users WHERE user=:user");
+  $stmt->bindValue(":user",$_SERVER["argv"][1]);
+  if($stmt->execute()->fetchArray()){
+    $stmt=$db->prepare("UPDATE users SET usergroup=:usergroup,hash=:hash WHERE user=:user");
+    $stmt->bindValue(":user", $_SERVER["argv"][1]);
+    $stmt->bindValue(":hash", password_hash($_SERVER["argv"][3], PASSWORD_DEFAULT));
+    $stmt->execute();
+  }
+  else{
+    $stmt=$db->prepare("INSERT INTO users (user,usergroup,hash) VALUES (:user,:usergroup,:hash)");
+    $stmt->bindValue(":user", $_SERVER["argv"][1]);
+    $stmt->bindValue(":usergroup", $_SERVER["argv"][2]);
+    $stmt->bindValue(":hash", password_hash($_SERVER["argv"][3], PASSWORD_DEFAULT));
+    $stmt->execute();
+  }
+}
+else{
+  echo "Plese enter an username and password for entry into the DB\n";
+}
+?>
index 6bc4833ebdc4d7f50f1fdb5c40bbe896b7d9c89d..b8ff3d5075743696ad67231b7c5c8cbe2a0d9d78 100644 (file)
@@ -7,22 +7,17 @@ if(empty($_SESSION["user"])){
   exit();
 }
 $error="<p>";
-$imgs="<div class='card mb-3'><div class='card-body'><div class='row'>";
+$imgs="<div class='card mb-3 w-100'><div class='card-body'><div class='row'>";
 $pdfs="<div class='card mb-3'><div class='card-body'>";
 if(!empty($_GET["pid"])){
   $pid=$_GET["pid"];
   if(!empty($_FILES)){
-    if($_FILES["upload"]["size"]<8000000){
-      if(in_array($_FILES["upload"]["type"], ["image/jpeg", "image/jpg", "image/png", "image/gif", "application/pdf"])){
-        $fname=str_replace("/", "", $pid)."-".time()."-".rand(1000,9999).".".pathinfo($_FILES["upload"]["name"], PATHINFO_EXTENSION);
-        move_uploaded_file($_FILES["upload"]["tmp_name"], "data/attachments/".$fname);
-      }
-      else{
-        $error=$error."Only jpg, png, gif, pdf files are supported.";
-      }
+    if(in_array($_FILES["upload"]["type"], ["image/jpeg", "image/jpg", "image/png", "image/gif", "application/pdf"])){
+      $fname=str_replace("/", "", $pid)."-".time()."-".rand(1000,9999).".".pathinfo($_FILES["upload"]["name"], PATHINFO_EXTENSION);
+      move_uploaded_file($_FILES["upload"]["tmp_name"], "data/attachments/".$fname);
     }
     else{
-        $error=$error."Maximum filesize exceeded. File upload failed";
+      $error=$error."Only jpg, png, gif, pdf files are supported.";
     }
   }
 
@@ -32,7 +27,7 @@ if(!empty($_GET["pid"])){
     }
     else{
       preg_match("/-([0-9]+)-/", pathinfo($attach, PATHINFO_FILENAME), $orig);
-      $imgs=$imgs."<div class='col-md-6'><figure><img class='w-100' src='".$attach."'><figcaption>Uploaded on: ".date("M d, Y h:i a", $orig[1])."</figcaption></figure></div>";
+      $imgs=$imgs."<div class='col-md-6'><figure><a href='".$attach."'><img class='w-100' src='".$attach."'></a><figcaption>Uploaded on: ".date("M d, Y h:i a", $orig[1])."</figcaption></figure></div>";
     }
   }
 }
@@ -57,6 +52,7 @@ $error=$error."</p>";
       </div>
       <?php echo $error;?>
       <form method="post" enctype="multipart/form-data">
+        <label for="upload">Select file to upload. JPG, PNG, GIF and PDF files are supported. Size limit: <span id="size-limit"><?php echo str_replace("M", "MB", ini_get("upload_max_filesize"));?></span><span id="upload-error"></span></label>
         <input type="file" name="upload" id="upload" class="form-control">
         <input type="submit" value="Upload" class="mt-2 btn btn-primary">
       </form>
index a87274b5047e062c2c259a059f67dd26780f92af..2a58dd707d3f5042be1d1039f182c10a2091d9a8 100644 (file)
@@ -52,5 +52,5 @@
             "type": "string"
         }
     },
-    "required": ["pid", "name", "age", "sex", "date", "ward", "bed", "status"]
+    "required": ["pid", "name", "age", "sex", "date"]
 }
index 0c91fc2563cb14cc293b4aeb13bb9a5da4830939..67482ab02cd274d4f5efb0cf5be88eda099d89c5 100644 (file)
@@ -7,7 +7,13 @@ class DB extends SQLite3 {
     $stmt=$this->prepare("SELECT hash FROM users WHERE user=:user");
     $stmt->bindValue(":user", $username);
     $result=$stmt->execute();
-    return(password_verify($password, $result->fetchArray()[0]));
+    $hash=$result->fetchArray();
+    if($hash){
+      return(password_verify($password, $hash["hash"]));
+    }
+    else{
+      return(false);
+    }
   }
   function admit($post){
     $quer=$this->prepare("SELECT count(rowid) FROM patients WHERE pid=:pid");
@@ -68,10 +74,10 @@ class DB extends SQLite3 {
     $stmt->bindValue(":data", json_encode($post));
     $stmt->execute();
   }
-  function addDrug($pid, $name, $dose, $route, $frequency, $date, $time, $duration, $addl){
-    $stmt=$this->prepare("INSERT INTO treatment (pid, name, dose, route, frequency, start, duration, omit, addl) VALUES (:pid, :name, :dose, :route, :frequency, :start, :duration, :omit, :addl);");
+  function addDrug($pid, $drug, $dose, $route, $frequency, $date, $time, $duration, $addl){
+    $stmt=$this->prepare("INSERT INTO treatment (pid, drug, dose, route, frequency, start, duration, omit, addl) VALUES (:pid, :drug, :dose, :route, :frequency, :start, :duration, :omit, :addl);");
     $stmt->bindValue(":pid", $pid);
-    $stmt->bindValue(":name", $name);
+    $stmt->bindValue(":drug", $drug);
     $stmt->bindValue(":dose", $dose);
     $stmt->bindValue(":route", $route);
     $stmt->bindValue(":frequency", $frequency);
index c8308cff17ad3cea194524ea7b404ea918666a2d..386e648a80da4d2536298b0088ef0c8cb26facae 100644 (file)
@@ -2,42 +2,4 @@
 <script src="res/moment.js"></script>
 <script src="res/bootstrap/js/bootstrap.bundle.min.js"></script>
 <script src="res/bootstrap-4-autocomplete.min.js"></script>
-
-<script>
-$(document).ready(function(){
-  $("[name='date']").each(function(){
-    if($(this).val()==""){
-      $(this).val(moment().format("YYYY-MM-DD"));
-    }
-  });
-  $("[name='time']").each(function(){
-    if($(this).val()==""){
-      $(this).val(moment().format("HH:MM"));
-    }
-  });
-  if($("[name='drug']").length){
-    $(this).prop("autocomplete","off");
-    $.get("autocomplete/drugs.json", function(data){
-      $("[name='drug']").each(function(){
-        $(this).autocomplete({source:data, highlightClass:'text-danger',treshold:2});
-      });
-    });
-  };
-  if($("[name='route']").length){
-    $(this).prop("autocomplete","off");
-    $.get("autocomplete/route.json", function(data){
-      $("[name='route']").each(function(){
-        $(this).autocomplete({source:data, highlightClass:'text-danger',treshold:1});
-      });
-    });
-  };
-  if($("[name='frequency']").length){
-    $(this).prop("autocomplete","off");
-    $.get("autocomplete/frequency.json", function(data){
-      $("[name='frequency']").each(function(){
-        $(this).autocomplete({source:data, highlightClass:'text-danger',treshold:1});
-      });
-    });
-  };
-});
-</script>
+<script src="res/script.js"></script>
index 9b489f108e55f5fff6b4d7d7f85425adf5179d35..4a4fde56ba2d2daec5ed6528029972ede44ac2fd 100644 (file)
--- a/login.php
+++ b/login.php
@@ -3,7 +3,7 @@ require("lib/db.php");
 require("lib/functions.php");
 session_start();
 $error="";
-if($_GET["action"]=="logout"){
+if(!empty($_GET["action"]) && $_GET["action"]=="logout"){
   $_SESSION["user"]=null;
 }
 if(!empty($_POST["username"]) && !empty($_POST["password"])){
diff --git a/res/script.js b/res/script.js
new file mode 100644 (file)
index 0000000..f7cfddf
--- /dev/null
@@ -0,0 +1,48 @@
+$(document).ready(function(){
+  $("#upload").change(function(){
+    lim=$("#size-limit").text().split("MB")[0]*1000*1000;
+    if(this.files[0]["size"]>lim){
+      $("#upload-error").html(" <span class='text-danger'>[Selected file exceeds size limit]</span>");
+    }
+    else if(["image/jpeg", "image/jpg", "image/png", "image/gif", "application/pdf"].indexOf(this.files[0]["type"])==-1){
+      $("#upload-error").html(" <span class='text-danger'>"+this.files[0]["type"]+" files are not supported</span>");
+    }
+    else{
+      $("#upload-error").text("");
+    }
+  });
+  $("[name='date']").each(function(){
+    if($(this).val()==""){
+      $(this).val(moment().format("YYYY-MM-DD"));
+    }
+  });
+  $("[name='time']").each(function(){
+    if($(this).val()==""){
+      $(this).val(moment().format("HH:MM"));
+    }
+  });
+  if($("[name='drug']").length){
+    $(this).prop("autocomplete","off");
+    $.get("autocomplete/drugs.json", function(data){
+      $("[name='drug']").each(function(){
+        $(this).autocomplete({source:data, highlightClass:'text-danger',treshold:2});
+      });
+    });
+  };
+  if($("[name='route']").length){
+    $(this).prop("autocomplete","off");
+    $.get("autocomplete/route.json", function(data){
+      $("[name='route']").each(function(){
+        $(this).autocomplete({source:data, highlightClass:'text-danger',treshold:1});
+      });
+    });
+  };
+  if($("[name='frequency']").length){
+    $(this).prop("autocomplete","off");
+    $.get("autocomplete/frequency.json", function(data){
+      $("[name='frequency']").each(function(){
+        $(this).autocomplete({source:data, highlightClass:'text-danger',treshold:1});
+      });
+    });
+  };
+});
index be662646f082c0dde09bc961bc157e5391a9f90d..bf3dc2eaf7665b9c8db588f95946770499b5849f 100644 (file)
@@ -40,7 +40,7 @@ data text
 );
 CREATE TABLE treatment(
 pid int,
-name text,
+drug text,
 dose text,
 route text,
 frequency text,
@@ -51,7 +51,7 @@ omit boolean,
 addl text
 );
 CREATE TABLE users(
-user text,
+user text unique,
 usergroup text,
 hash text,
 change boolean,