/src/webtech/Destination/Destination.php
PHP | 395 lines | 266 code | 51 blank | 78 comment | 45 complexity | 4f76a9858f01e0e4fac9fbfced0dae79 MD5 | raw file
- <?php
- namespace App\webtech\Destination;
- use App\webtech\Destination\Utility ;
- use App\webtech\Destination\Message;
- use App\webtech\Destination\Info;
- use App\webtech\Destination\Info2;
- use PDO;
- //session_start();
- class Destination{
- public $id="";
-
- public $conn;
- public $user='root';
- public $pass='';
- public $search="";
- public $area_name="";
- public $stand_name="";
- public $distance_from="";
- public $loc_id="";
- public $metere="";
- public $uniqid="";
- //public $image="";
-
- public function __construct() {
- $this->conn = new PDO('mysql:host=localhost;dbname=web_tech_pro', $this->user, $this->pass);
-
- }
- public function prepare($data=array()){
-
- if(array_key_exists('id',$data) && !empty($data['id'])){
- $this->id=$data['id'];
- }
- if(array_key_exists('loc_id',$data) && !empty($data['loc_id'])){
- $this->loc_id=$data['loc_id'];
- }
-
- if(array_key_exists('user_id',$data) && !empty($data['user_id'])){
- $this->user_id=$data['user_id'];
- }
- if(array_key_exists('area_name',$data) && !empty($data['area_name'])){
- $this->area_name=$data['area_name'];
- }
- if(array_key_exists('stand_name',$data) && !empty($data['stand_name'])){
- $this->stand_name=$data['stand_name'];
- }
- if(array_key_exists('distance_from',$data) && !empty($data['distance_from'])){
- $this->distance_from=$data['distance_from'];
- }
- if(array_key_exists('metere',$data) && !empty($data['metere'])){
- $this->metere=$data['metere'];
- }
-
- if (array_key_exists('search', $data) && !empty($data['search'])) {
- $this->search = $data['search'];
- }
- return $this;
- // var_dump($this);
- // die();
- }
- public function destination_find() {
- // var_dump($search);
- // die();
-
-
- $query = 'SELECT * FROM `web_tech_pro`.`busstand_list` WHERE `deleted_at` IS NULL';
-
- $result = $this->conn->query($query);
-
- $allData=$result->fetchAll(PDO::FETCH_ASSOC);
- return $allData;
- // var_dump($allData);
- // die();
- // if(!empty($allData)){
- // foreach ($allData as $value) {
- //// var_dump($value['stand_name']);
- //// die();
- // Info2::info2($value['stand_name']);
- // //Info2::info2($_POST['distance_from']);
- // Utility::redirect();
- // }
- //
- //
- // }
- }
- public function index() {
- // var_dump($search);
- // die();
- $allData = array();
- $whereClause=" 1=1 ";
-
- if(!empty($this->search)){
- $whereClause.="AND `stand_name` LIKE '%{$this->search}%'";
- // var_dump($_GET);
- // die();
- }
- $query = "SELECT * FROM `web_tech_pro`.`busstand_list` WHERE `deleted_at` IS NULL AND".$whereClause;
- $result = $this->conn->query( $query);
- $allData=$result->fetchAll(PDO::FETCH_ASSOC);
- return $allData;
- // var_dump($allData);
- // die();
- }
- public function location_name() {
- // var_dump($search);
- // die();
- $allData = array();
- $whereClause=" 1=1 ";
-
- if(!empty($this->search)){
- $whereClause.="AND `stand_name` LIKE '%{$this->search}%'";
- // var_dump($_GET);
- // die();
- }
- $query = "SELECT `area_name` FROM `web_tech_pro`.`locations` WHERE `deleted_at` IS NULL AND `id`=".loc_id.$whereClause;
- $result = $this->conn->query( $query);
- $allData=$result->fetchAll(PDO::FETCH_ASSOC);
- return $allData;
- // var_dump($allData);
- // die();
- }
- public function store() {
- // $uid= uniqid();
- // $this->uniqid=$uid;
- if (!empty($this->area_name)){
- $query = "INSERT INTO `web_tech_pro`.`locations` (`area_name`) VALUE (:area_name)";
- $result = $this->conn->prepare($query);
- $result->execute(array(':area_name'=>$this->area_name));
- // var_dump($result);
- // die();
- if ($result) {
- Message::message('Data successfully stored');
- if(Info::info()!=NULL){
- Utility::redirect6();
- }
- else{
- Utility::redirect();
- }
- }
- } else {
- Utility::redirect6();
- }
-
- }
- public function store2() {
-
- //if (!empty($this->org_name) && !empty($this->org_add) && !empty($this->phone) && !empty($this->summary) ) {
- $query = "INSERT INTO `web_tech_pro`.`busstand_list` (`stand_name`,`distance_from`,`metere`) VALUES (:stand_name,:distance_from,:metere)";
- // var_dump($query);
- // die();
- $result = $this->conn->prepare($query);
- $result->execute(array(':stand_name'=>$this->stand_name,':distance_from'=>$this->distance_from,':metere'=>$this->metere));
- if ($result) {
- Message::message('Data successfully stored');
- if(Info::info()!=NULL){
- Utility::redirect6();
- }
- else{
- Utility::redirect();
- }
- }
- else {
- Utility::redirect6();
- }
-
- }
- //
- // public function index2($data='') {//sinlg row mail
- //// var_dump($data);
- //// die();
- // $query = "SELECT * FROM `owncms`.`users` WHERE `users`.`username` = :username";
- //
- // $result = $this->conn->prepare($query);
- //
- // $result->execute(array(':username'=>$data));
- //
- // $allData=$result->fetchAll(PDO::FETCH_ASSOC);
- // return $allData;
- //// var_dump($allData);
- //// die();
- // }
-
- public function logout() {
- session_destroy();
-
- session_unset(Info::info('id'));
- Utility::redirect();
- }
- public function update2() {
- // var_dump($_POST);
- // die();
- if (!empty($this->user_name) && !empty($this->email) && !empty($this->password) ) {
- $query = "UPDATE `web_tech_pro`.`admin_user` SET `email`=:email,`user_name` =:user_name,`password`=:password WHERE `admin_user`.`id` = :id";
- //echo $query;
- $result = $this->conn->prepare($query);
- $result->execute(array(':id'=>$this->id,':email'=>$this->email,':user_name'=>$this->user_name,':password'=>$this->password));
- if($result){
- Message::message("Data has been updated successfully");
- Utility::redirect2();
- }
- else{
- Utility::redirect2();
- }
- }
- elseif(empty($this->password) && !empty($this->user_name) && !empty($this->email)) {
- $query = "UPDATE `web_tech_pro`.`admin_user` SET `email`=:email,`user_name` =:user_name WHERE `admin_user`.`id` = :id";
- //echo $query;
- $result = $this->conn->prepare($query);
- $result->execute(array(':id'=>$this->id,':email'=>$this->email,':user_name'=>$this->user_name));
- if($result){
- Message::message("Data has been updated successfully");
- Utility::redirect2();
- }
- else{
- Utility::redirect2();
- }
- }
- else {
- Utility::redirect2();
- }
-
- }
- public function profile_update() {
- // var_dump($data);
- // die();
- $uid=uniqid();
- $this->uniqid=$uid;
- // var_dump($uid);
- // die();
-
- $allData = array();
- if(!empty($this->image)){
- $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";
- $result = $this->conn->prepare($query);
- $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));
- // var_dump($result);
- // die();
- if($result){
- Message::message("Data has been updated successfully");
- Utility::redirect5();
- }
- else{
- Utility::redirect5();
- }
- }
- else {
- $query = "UPDATE `owncms`.`profiles` SET `firstname`=:firstname,`lastname`=:lastname,`gender=:gender,`mobile_no`=:mobile_no,`address`=:address,`country`=:country WHERE `profiles`.`user_id`=:id";
- $result = $this->conn->prepare($query);
- $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));
- // var_dump($result);
- // die();
- if($result){
- Message::message("Data updated successfully");
- Utility::redirect5();
- }
- else{
- Utility::redirect5();
- }
- }
-
- }
- 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');
- $uid= uniqid();
- //$this->uniqid=$uid;
- //if (!empty($this->user_name) && !empty($this->email) && !empty($this->password) ) {
- $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)";
- $result = $this->conn->prepare($query);
- $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));
- // var_dump($result);
- // die();
- if ($result) {
- Message::message('Update successful');
- Utility::redirect5();
- }
- // }
- else {
- Utility::redirect5();
- }
-
- }
- public function getALLtitle(){
- $allData = array();
- $query = "SELECT `user_name` FROM `web_tech_pro`.`admin_user` WHERE `deleted_at` IS NULL" ;
- $result = $this->conn->query( $query);
- $allData=$result->fetchAll(PDO::FETCH_ASSOC);
- return $allData;
- }
- public function view() {
- $query="SELECT * FROM `web_tech_pro`.`busstand_list` WHERE `busstand_list`.`id`=".$this->id;
- $result = $this->conn->prepare( $query);
- $result->execute(array(':id'=>$this->id));
- $row = $result->fetch(PDO::FETCH_ASSOC);
- // var_dump($row);
- // die();
- return $row;
- }
- public function edit() {
- $query = "SELECT * FROM `web_tech_pro`.`busstand_list` WHERE `id`=:id";
-
- $result = $this->conn->prepare( $query);
- $result->execute(array(':id'=>$this->id));
- $row = $result->fetch(PDO::FETCH_ASSOC);
- return $row;
-
- }
- public function update() {
-
-
- $query = "UPDATE `web_tech_pro`.`busstand_list` SET `stand_name`=:stand_name,`distance_from` =:distance_from,`metere` =:metere WHERE `busstand_list`.`id` = :id";
- //echo $query;
- $result = $this->conn->prepare($query);
- $result->execute(array(':id'=>$this->id,':stand_name'=>$this->stand_name,':distance_from'=>$this->distance_from,':metere'=>$this->metere));
-
- if($result){
- Message::message("Data has been updated successfully");
- Utility::redirect6();
- }
- else{
- Utility::redirect6();
- }
-
- }
- public function trash() {
- $this->deleted_at= time();
- $query = "UPDATE `web_tech_pro`.`busstand_list` SET `deleted_at`=:deleted_at WHERE `busstand_list`.`id` = :id";
- //echo $query;
- $result = $this->conn->prepare($query);
- $result->execute(array(':id'=>$this->id,':deleted_at'=>$this->deleted_at));
- if($result){
- Message::message("Data has been trashed successfully");
- Utility::redirect6();
- }
- else {
- Utility::redirect6();
- }
- }
- public function trashed() {
- $allData = array();
- $query = "SELECT * FROM `web_tech_pro`.`busstand_list` WHERE `deleted_at` IS NOT NULL" ;
- $result = $this->conn->query( $query);
- $allData=$result->fetchAll(PDO::FETCH_ASSOC);
- return $allData;
- }
- public function recover() {
-
- $query = "UPDATE `web_tech_pro`.`busstand_list` SET `deleted_at`=:NULL WHERE `busstand_list`.`id` = :id";
- //echo $query;
- $result = $this->conn->prepare($query);
- $result->execute(array(':id'=>$this->id,':NULL'=>NULL));
- if($result){
- Message::message("Data has been recovered successfully");
- Utility::redirect6();
- }
-
-
- else {
- Utility::redirect6();
- }
- }
- public function delete() {
- $query = "DELETE FROM `web_tech_pro`.`busstand_list` WHERE `busstand_list`.`id` =:id" ;
- //echo $query;
- $result = $this->conn->prepare($query);
- $result->execute(array(':id'=>$this->id));
- //var_dump($result);
- //die();
- if($result){
- Message::message("Data has bee deleted successfully");
- Utility::redirect6();
- }
- else{
- Utility::redirect6();
- }
-
-
- }
-
- }