Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Response;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Validator;
  7. use App\DBmodel;
  8.  
  9. class Dataentry extends Controller
  10. {
  11.  
  12. public $vuserid;
  13. public $vusername;
  14. public $vpassword;
  15. public $vuserlevel;
  16. public $status;
  17. public $data;
  18.  
  19. public function __construct(){
  20. $this->vuserid = "";
  21. $this->vusername = "";
  22. $this->vpassword = "";
  23. $this->vuserlevel = "";
  24. $this->vstatus = "";
  25. }
  26.  
  27. function doClear(){
  28. $this->data = array("vuserid"=>$this->vuserid,
  29. "vusername"=>$this->vusername,
  30. "vpassword"=>$this->vpassword,
  31. "vuserlevel"=>$this->vuserlevel,
  32. "vstatus"=>$this->vstatus,
  33. );
  34. }
  35. public function index(){
  36. $this-> doClear();
  37. return view('dataentry')->with($this->data);
  38. }
  39.  
  40. public function doValidate(Request $req){
  41. $validator = Validator::make($req->all(), [
  42. 'txtuserid' => 'required',
  43. 'txtusername' => 'required',
  44. 'txtpassword' => 'required',
  45. 'txtuserlevel' => 'required',
  46. 'txtstatus' => 'required',
  47. ]);
  48. $req->flash();
  49.  
  50. if($validator->passes()){
  51. return true;
  52. } else {
  53. return false;
  54. }
  55. }
  56.  
  57. public function doDM(Request $req){
  58. $vOption = $req->input('btnSubmit');
  59. if($vOption =="Add" || $vOption == "Update"){
  60. $tf = $this->doValidate($req);
  61. }else {
  62. $tf = true;
  63. }
  64.  
  65. if($tf == true){
  66.  
  67. switch($vOption){
  68. case "Add":
  69. $tf = $this->doInsert($req);
  70. break;
  71. case "Delete":
  72. $this->doDelete($req);
  73. break;
  74. case "Update":
  75. $this->doUpdate($req);
  76. break;
  77. case "Show":
  78. $this->data = $this->doShow($req);
  79. break;
  80. }
  81.  
  82. $page ='dataentry';
  83.  
  84. if( $vOption == "Show"){
  85. return view($page)->with($this->data);
  86. } else {
  87. return redirect($page)->with($this->data);
  88. }
  89.  
  90. } else {
  91. return "Validation error!";
  92. }
  93.  
  94. }
  95.  
  96. public function doInsert(Request $req){
  97. $um = new DBmodel();
  98. $um->doInsert($req);
  99. }
  100.  
  101. public function doDelete(Request $req) {
  102. $um = new DBmodel();
  103. $um->doDelete($req);
  104. }
  105.  
  106. public function doUpdate(Request $req) {
  107. $um = new DBmodel();
  108. $um->doUpdate($req);
  109. }
  110. public function doShow(Request $req) {
  111. $um = new DBmodel();
  112. $record = $um->doShow($req);
  113.  
  114. $vShowData ="";
  115. if( sizeof($record) == 1){
  116. foreach ($record as $rec) {
  117. $vShowData = array("vuserid"=>$rec->userid,
  118. "vusername"=>$rec->username,
  119. "vpassword"=>$rec->password,
  120. "vuserlevel"=>$rec->userlevel,
  121. "vstatus"=>$rec->status,
  122. );
  123. }
  124.  
  125. }else {
  126. $vShowData = array("vuserid"=>$this->vuserid,
  127. "vusername"=>$this->vusername,
  128. "vpassword"=>$this->vpassword,
  129. "vuserlevel"=>$this->vuserlevel,
  130. "vstatus"=>$this->vstatus,
  131. );
  132. }
  133. return $vShowData;
  134. }
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement