PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/webtech/Destination/Destination.php

https://gitlab.com/Zinnurain/destination_finder_beta
PHP | 395 lines | 266 code | 51 blank | 78 comment | 45 complexity | 4f76a9858f01e0e4fac9fbfced0dae79 MD5 | raw file
  1. <?php
  2. namespace App\webtech\Destination;
  3. use App\webtech\Destination\Utility ;
  4. use App\webtech\Destination\Message;
  5. use App\webtech\Destination\Info;
  6. use App\webtech\Destination\Info2;
  7. use PDO;
  8. //session_start();
  9. class Destination{
  10. public $id="";
  11. public $conn;
  12. public $user='root';
  13. public $pass='';
  14. public $search="";
  15. public $area_name="";
  16. public $stand_name="";
  17. public $distance_from="";
  18. public $loc_id="";
  19. public $metere="";
  20. public $uniqid="";
  21. //public $image="";
  22. public function __construct() {
  23. $this->conn = new PDO('mysql:host=localhost;dbname=web_tech_pro', $this->user, $this->pass);
  24. }
  25. public function prepare($data=array()){
  26. if(array_key_exists('id',$data) && !empty($data['id'])){
  27. $this->id=$data['id'];
  28. }
  29. if(array_key_exists('loc_id',$data) && !empty($data['loc_id'])){
  30. $this->loc_id=$data['loc_id'];
  31. }
  32. if(array_key_exists('user_id',$data) && !empty($data['user_id'])){
  33. $this->user_id=$data['user_id'];
  34. }
  35. if(array_key_exists('area_name',$data) && !empty($data['area_name'])){
  36. $this->area_name=$data['area_name'];
  37. }
  38. if(array_key_exists('stand_name',$data) && !empty($data['stand_name'])){
  39. $this->stand_name=$data['stand_name'];
  40. }
  41. if(array_key_exists('distance_from',$data) && !empty($data['distance_from'])){
  42. $this->distance_from=$data['distance_from'];
  43. }
  44. if(array_key_exists('metere',$data) && !empty($data['metere'])){
  45. $this->metere=$data['metere'];
  46. }
  47. if (array_key_exists('search', $data) && !empty($data['search'])) {
  48. $this->search = $data['search'];
  49. }
  50. return $this;
  51. // var_dump($this);
  52. // die();
  53. }
  54. public function destination_find() {
  55. // var_dump($search);
  56. // die();
  57. $query = 'SELECT * FROM `web_tech_pro`.`busstand_list` WHERE `deleted_at` IS NULL';
  58. $result = $this->conn->query($query);
  59. $allData=$result->fetchAll(PDO::FETCH_ASSOC);
  60. return $allData;
  61. // var_dump($allData);
  62. // die();
  63. // if(!empty($allData)){
  64. // foreach ($allData as $value) {
  65. //// var_dump($value['stand_name']);
  66. //// die();
  67. // Info2::info2($value['stand_name']);
  68. // //Info2::info2($_POST['distance_from']);
  69. // Utility::redirect();
  70. // }
  71. //
  72. //
  73. // }
  74. }
  75. public function index() {
  76. // var_dump($search);
  77. // die();
  78. $allData = array();
  79. $whereClause=" 1=1 ";
  80. if(!empty($this->search)){
  81. $whereClause.="AND `stand_name` LIKE '%{$this->search}%'";
  82. // var_dump($_GET);
  83. // die();
  84. }
  85. $query = "SELECT * FROM `web_tech_pro`.`busstand_list` WHERE `deleted_at` IS NULL AND".$whereClause;
  86. $result = $this->conn->query( $query);
  87. $allData=$result->fetchAll(PDO::FETCH_ASSOC);
  88. return $allData;
  89. // var_dump($allData);
  90. // die();
  91. }
  92. public function location_name() {
  93. // var_dump($search);
  94. // die();
  95. $allData = array();
  96. $whereClause=" 1=1 ";
  97. if(!empty($this->search)){
  98. $whereClause.="AND `stand_name` LIKE '%{$this->search}%'";
  99. // var_dump($_GET);
  100. // die();
  101. }
  102. $query = "SELECT `area_name` FROM `web_tech_pro`.`locations` WHERE `deleted_at` IS NULL AND `id`=".loc_id.$whereClause;
  103. $result = $this->conn->query( $query);
  104. $allData=$result->fetchAll(PDO::FETCH_ASSOC);
  105. return $allData;
  106. // var_dump($allData);
  107. // die();
  108. }
  109. public function store() {
  110. // $uid= uniqid();
  111. // $this->uniqid=$uid;
  112. if (!empty($this->area_name)){
  113. $query = "INSERT INTO `web_tech_pro`.`locations` (`area_name`) VALUE (:area_name)";
  114. $result = $this->conn->prepare($query);
  115. $result->execute(array(':area_name'=>$this->area_name));
  116. // var_dump($result);
  117. // die();
  118. if ($result) {
  119. Message::message('Data successfully stored');
  120. if(Info::info()!=NULL){
  121. Utility::redirect6();
  122. }
  123. else{
  124. Utility::redirect();
  125. }
  126. }
  127. } else {
  128. Utility::redirect6();
  129. }
  130. }
  131. public function store2() {
  132. //if (!empty($this->org_name) && !empty($this->org_add) && !empty($this->phone) && !empty($this->summary) ) {
  133. $query = "INSERT INTO `web_tech_pro`.`busstand_list` (`stand_name`,`distance_from`,`metere`) VALUES (:stand_name,:distance_from,:metere)";
  134. // var_dump($query);
  135. // die();
  136. $result = $this->conn->prepare($query);
  137. $result->execute(array(':stand_name'=>$this->stand_name,':distance_from'=>$this->distance_from,':metere'=>$this->metere));
  138. if ($result) {
  139. Message::message('Data successfully stored');
  140. if(Info::info()!=NULL){
  141. Utility::redirect6();
  142. }
  143. else{
  144. Utility::redirect();
  145. }
  146. }
  147. else {
  148. Utility::redirect6();
  149. }
  150. }
  151. //
  152. // public function index2($data='') {//sinlg row mail
  153. //// var_dump($data);
  154. //// die();
  155. // $query = "SELECT * FROM `owncms`.`users` WHERE `users`.`username` = :username";
  156. //
  157. // $result = $this->conn->prepare($query);
  158. //
  159. // $result->execute(array(':username'=>$data));
  160. //
  161. // $allData=$result->fetchAll(PDO::FETCH_ASSOC);
  162. // return $allData;
  163. //// var_dump($allData);
  164. //// die();
  165. // }
  166. public function logout() {
  167. session_destroy();
  168. session_unset(Info::info('id'));
  169. Utility::redirect();
  170. }
  171. public function update2() {
  172. // var_dump($_POST);
  173. // die();
  174. if (!empty($this->user_name) && !empty($this->email) && !empty($this->password) ) {
  175. $query = "UPDATE `web_tech_pro`.`admin_user` SET `email`=:email,`user_name` =:user_name,`password`=:password WHERE `admin_user`.`id` = :id";
  176. //echo $query;
  177. $result = $this->conn->prepare($query);
  178. $result->execute(array(':id'=>$this->id,':email'=>$this->email,':user_name'=>$this->user_name,':password'=>$this->password));
  179. if($result){
  180. Message::message("Data has been updated successfully");
  181. Utility::redirect2();
  182. }
  183. else{
  184. Utility::redirect2();
  185. }
  186. }
  187. elseif(empty($this->password) && !empty($this->user_name) && !empty($this->email)) {
  188. $query = "UPDATE `web_tech_pro`.`admin_user` SET `email`=:email,`user_name` =:user_name WHERE `admin_user`.`id` = :id";
  189. //echo $query;
  190. $result = $this->conn->prepare($query);
  191. $result->execute(array(':id'=>$this->id,':email'=>$this->email,':user_name'=>$this->user_name));
  192. if($result){
  193. Message::message("Data has been updated successfully");
  194. Utility::redirect2();
  195. }
  196. else{
  197. Utility::redirect2();
  198. }
  199. }
  200. else {
  201. Utility::redirect2();
  202. }
  203. }
  204. public function profile_update() {
  205. // var_dump($data);
  206. // die();
  207. $uid=uniqid();
  208. $this->uniqid=$uid;
  209. // var_dump($uid);
  210. // die();
  211. $allData = array();
  212. if(!empty($this->image)){
  213. $query = "UPDATE `owncms`.`profiles` SET `firstname`=:firstname,`lastname`=:lastname,`gender`=:gender,`mobile_no`=:mobile_no,`address`=:address,`country`=:country,`image`=:image WHERE `profiles`.`user_id`=:id";
  214. $result = $this->conn->prepare($query);
  215. $result->execute(array(':id'=>$this->user_id,':firstname'=>$this->firstname,':lastname'=>$this->lastname,':gender'=>$this->gender,':mobile_no'=>$this->mobile_no,':address'=>$this->address,':country'=>$this->country,':image'=>$this->image));
  216. // var_dump($result);
  217. // die();
  218. if($result){
  219. Message::message("Data has been updated successfully");
  220. Utility::redirect5();
  221. }
  222. else{
  223. Utility::redirect5();
  224. }
  225. }
  226. else {
  227. $query = "UPDATE `owncms`.`profiles` SET `firstname`=:firstname,`lastname`=:lastname,`gender=:gender,`mobile_no`=:mobile_no,`address`=:address,`country`=:country WHERE `profiles`.`user_id`=:id";
  228. $result = $this->conn->prepare($query);
  229. $result->execute(array(':id'=>$this->user_id,':firstname'=>$this->firstname,':lastname'=>$this->lastname,':gender'=>$this->gender,':mobile_no'=>$this->mobile_no,':address'=>$this->address,':country'=>$this->country));
  230. // var_dump($result);
  231. // die();
  232. if($result){
  233. Message::message("Data updated successfully");
  234. Utility::redirect5();
  235. }
  236. else{
  237. Utility::redirect5();
  238. }
  239. }
  240. }
  241. public function profile_insert() {//INSERT INTO `profiles` (`id`, `firstname`, `lastname`, `mobile_no`, `address`, `country`, `gender`, `image`, `user_id`) VALUES (NULL, 'fffffff', 'lllllllllll', '05070', ' vdgtb', 'bd', 'Male', NULL, '19');
  242. $uid= uniqid();
  243. //$this->uniqid=$uid;
  244. //if (!empty($this->user_name) && !empty($this->email) && !empty($this->password) ) {
  245. $query = "INSERT INTO `owncms`.`profiles` (`firstname`,`lastname`,`gender`,`address`,`mobile_no`,`country`,`user_id`,`image`) VALUES (:firstname,:lastname,:gender,:address,:mobile_no,:country,:user_id,:image)";
  246. $result = $this->conn->prepare($query);
  247. $result->execute(array(':firstname'=>$this->firstname,':lastname'=>$this->lastname,':gender'=>$this->gender,':address'=>$this->address,':mobile_no'=>$this->mobile_no,':country'=>$this->country,':user_id'=>$this->user_id,':image'=>$this->image));
  248. // var_dump($result);
  249. // die();
  250. if ($result) {
  251. Message::message('Update successful');
  252. Utility::redirect5();
  253. }
  254. // }
  255. else {
  256. Utility::redirect5();
  257. }
  258. }
  259. public function getALLtitle(){
  260. $allData = array();
  261. $query = "SELECT `user_name` FROM `web_tech_pro`.`admin_user` WHERE `deleted_at` IS NULL" ;
  262. $result = $this->conn->query( $query);
  263. $allData=$result->fetchAll(PDO::FETCH_ASSOC);
  264. return $allData;
  265. }
  266. public function view() {
  267. $query="SELECT * FROM `web_tech_pro`.`busstand_list` WHERE `busstand_list`.`id`=".$this->id;
  268. $result = $this->conn->prepare( $query);
  269. $result->execute(array(':id'=>$this->id));
  270. $row = $result->fetch(PDO::FETCH_ASSOC);
  271. // var_dump($row);
  272. // die();
  273. return $row;
  274. }
  275. public function edit() {
  276. $query = "SELECT * FROM `web_tech_pro`.`busstand_list` WHERE `id`=:id";
  277. $result = $this->conn->prepare( $query);
  278. $result->execute(array(':id'=>$this->id));
  279. $row = $result->fetch(PDO::FETCH_ASSOC);
  280. return $row;
  281. }
  282. public function update() {
  283. $query = "UPDATE `web_tech_pro`.`busstand_list` SET `stand_name`=:stand_name,`distance_from` =:distance_from,`metere` =:metere WHERE `busstand_list`.`id` = :id";
  284. //echo $query;
  285. $result = $this->conn->prepare($query);
  286. $result->execute(array(':id'=>$this->id,':stand_name'=>$this->stand_name,':distance_from'=>$this->distance_from,':metere'=>$this->metere));
  287. if($result){
  288. Message::message("Data has been updated successfully");
  289. Utility::redirect6();
  290. }
  291. else{
  292. Utility::redirect6();
  293. }
  294. }
  295. public function trash() {
  296. $this->deleted_at= time();
  297. $query = "UPDATE `web_tech_pro`.`busstand_list` SET `deleted_at`=:deleted_at WHERE `busstand_list`.`id` = :id";
  298. //echo $query;
  299. $result = $this->conn->prepare($query);
  300. $result->execute(array(':id'=>$this->id,':deleted_at'=>$this->deleted_at));
  301. if($result){
  302. Message::message("Data has been trashed successfully");
  303. Utility::redirect6();
  304. }
  305. else {
  306. Utility::redirect6();
  307. }
  308. }
  309. public function trashed() {
  310. $allData = array();
  311. $query = "SELECT * FROM `web_tech_pro`.`busstand_list` WHERE `deleted_at` IS NOT NULL" ;
  312. $result = $this->conn->query( $query);
  313. $allData=$result->fetchAll(PDO::FETCH_ASSOC);
  314. return $allData;
  315. }
  316. public function recover() {
  317. $query = "UPDATE `web_tech_pro`.`busstand_list` SET `deleted_at`=:NULL WHERE `busstand_list`.`id` = :id";
  318. //echo $query;
  319. $result = $this->conn->prepare($query);
  320. $result->execute(array(':id'=>$this->id,':NULL'=>NULL));
  321. if($result){
  322. Message::message("Data has been recovered successfully");
  323. Utility::redirect6();
  324. }
  325. else {
  326. Utility::redirect6();
  327. }
  328. }
  329. public function delete() {
  330. $query = "DELETE FROM `web_tech_pro`.`busstand_list` WHERE `busstand_list`.`id` =:id" ;
  331. //echo $query;
  332. $result = $this->conn->prepare($query);
  333. $result->execute(array(':id'=>$this->id));
  334. //var_dump($result);
  335. //die();
  336. if($result){
  337. Message::message("Data has bee deleted successfully");
  338. Utility::redirect6();
  339. }
  340. else{
  341. Utility::redirect6();
  342. }
  343. }
  344. }