/** * Get weather conditions using openweathermap API */ public function getWeather() { $location = LocationController::getLocation(); /*Get content from openweathermap API*/ $weather = file_get_contents('http://api.openweathermap.org/data/2.5/weather?lat=' . $location->latitude . '&lon=' . $location->longitude . '&units=metric'); return $weather; }
/** * Initialize the ConfirmAddController class and their parents */ public function init() { try { parent::init(); } catch (Exception $e) { throw new Exception('Une erreur est survenue durant le chargement du module: ' . $e->getMessage()); } if (file_exists(_CONTROLLERS_DIR_ . '/Tools.php')) { $url = Tools::getInstance()->request_url; $url .= '&id=ukn'; $controller = Tools::getInstance()->getUrl_controller($url); if ($controller == 'ConfirmAddController') { if (file_exists(_LOCATIONS_MODELS_ . '/' . $this->model_name . 'Model.php')) { try { require_once _LOCATIONS_MODELS_ . '/' . $this->model_name . 'Model.php'; Tools::getInstance()->createPost($_POST); if (!empty($_POST['sector']) && !empty($_POST['location'])) { \Location\CreateModel::getInstance()->add_location($_POST['sector'], $_POST['location']); header('Location: /Cas-M-Ping/locations/show/all'); } else { header('Location: /Cas-M-Ping/locations/add'); } } catch (Exception $e) { throw new Exception('Une erreur est survenue durant l\'ajout des données: ' . $e->getMessage()); } } else { throw new Exception('Le modèle "' . $this->model_name . '" n\'existe pas dans "' . _LOCATIONS_MODELS_ . '"!'); } } else { throw new Exception('Une erreur est survenue durant la phase de routage!'); } } else { throw new Exception('L\'URL n\'est pas évaluable!'); } }
/** * Get the location of the client using Google API by searching for the country name and get the first image */ public function getCountryInfo() { $location = LocationController::getLocation(); /*fetch image url from google API ... code can be found at http://stackoverflow.com/a/5694812/2786529 */ $jsrc = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=" . $location->country_name . "%20landmark"; $json = file_get_contents($jsrc); $jset = json_decode($json, true); /*encode to json format*/ $country = json_encode(['country_name' => $location->country_name, 'photourl' => $jset["responseData"]["results"][0]["url"]]); return $country; }
/** * Initialize the DisplayController class and their parents */ public function init() { try { parent::init(); } catch (Exception $e) { throw new Exception('Une erreur est survenue durant le chargement du module: ' . $e->getMessage()); } if (file_exists(_CONTROLLERS_DIR_ . '/Tools.php')) { $url = Tools::getInstance()->request_url; $controller = Tools::getInstance()->getUrl_controller($url); if ($controller == 'DisplayController') { if (file_exists(_LOCATIONS_MODELS_ . '/' . $this->model_name . 'Model.php')) { if (file_exists(_LOCATIONS_VIEWS_ . '/' . $this->view_name . '.tpl')) { try { require_once _LOCATIONS_MODELS_ . '/' . $this->model_name . 'Model.php'; $id = Tools::getInstance()->getUrl_id($url); switch ($id) { case 'all': $data = \Location\DisplayModel::getInstance()->display_locations(); break; default: if (\Location\DisplayModel::getInstance()->has_location($id) == 1) { $data = \Location\DisplayModel::getInstance()->display_location($id); } else { header('Location: /Cas-M-Ping/errors/404'); } break; } echo $this->twig->render($this->view_name . '.tpl', array('locations' => $data, 'bootstrapPath' => _BOOTSTRAP_FILE_)); } catch (Exception $e) { throw new Exception('Une erreur est survenue durant la récupération des données: ' . $e->getMessage()); } } else { throw new Exception('Le template "' . $this->view_name . '" n\'existe pas dans "' . _LOCATIONS_VIEWS_ . '"!'); } } else { throw new Exception('Le modèle "' . $this->model_name . '" n\'existe pas dans "' . _LOCATIONS_MODELS_ . '"!'); } } else { throw new Exception('Une erreur est survenue durant la phase de routage!'); } } else { throw new Exception('L\'URL n\'est pas évaluable!'); } }
/** * Initialize the LocationController class */ public function init() { if (self::$initialized) { return; } self::$initialized = true; if (file_exists(_TWIG_AUTOLOADER_)) { try { require_once _TWIG_AUTOLOADER_; Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem(array(_DEPENDENCIES_DIR_, _LOCATIONS_VIEWS_)); $this->twig = new Twig_Environment($loader, array('cache' => _TWIG_CACHE_)); } catch (Exception $e) { throw new Exception('Le fichier de démarrage Twig ne peut pas s\'executer!'); } } else { throw new Exception('Il n\'existe pas le fichier de démarrage Twig à cet emplacement "' . _TWIG_AUTOLOADER_ . '"!'); } }
/** * Initialize the DeleteController class and their parents */ public function init() { try { parent::init(); } catch (Exception $e) { throw new Exception('Une erreur est survenue durant le chargement du module: ' . $e->getMessage()); } if (file_exists(_CONTROLLERS_DIR_ . '/Tools.php')) { $url = Tools::getInstance()->request_url; $controller = Tools::getInstance()->getUrl_controller($url); if ($controller == 'DeleteController') { if (file_exists(_LOCATIONS_MODELS_ . '/' . $this->model_name . 'Model.php')) { try { require_once _LOCATIONS_MODELS_ . '/' . $this->model_name . 'Model.php'; $id = Tools::getInstance()->getUrl_id($url); switch ($id) { case 'all': \Location\DeleteModel::getInstance()->delete_locations(); break; default: if (\Location\DeleteModel::getInstance()->has_location($id) == 1) { \Location\DeleteModel::getInstance()->delete_location($id); } else { header('Location: /Cas-M-Ping/errors/404'); } break; } header('Location: /Cas-M-Ping/locations/show/all'); } catch (Exception $e) { throw new Exception('Une erreur est survenue durant la modification des données: ' . $e->getMessage()); } } else { throw new Exception('Le modèle "' . $this->model_name . '" n\'existe pas dans "' . _LOCATIONS_MODELS_ . '"!'); } } else { throw new Exception('Une erreur est survenue durant la phase de routage!'); } } else { throw new Exception('L\'URL n\'est pas évaluable!'); } }
/** * Initialize the ModifyController class and their parents */ public function init() { try { parent::init(); } catch (Exception $e) { throw new Exception('Une erreur est survenue durant le chargement du module: ' . $e->getMessage()); } if (file_exists(_CONTROLLERS_DIR_ . '/Tools.php')) { $url = Tools::getInstance()->request_url; $controller = Tools::getInstance()->getUrl_controller($url); if ($controller == 'ModifyController') { if (file_exists(_LOCATIONS_MODELS_ . '/' . $this->model_name . 'Model.php') && file_exists(_SECTORS_MODELS_ . '/' . $this->model_name . 'Model.php')) { if (file_exists(_LOCATIONS_VIEWS_ . '/' . $this->view_name . '.tpl')) { try { require_once _LOCATIONS_MODELS_ . '/' . $this->model_name . 'Model.php'; require_once _SECTORS_MODELS_ . '/' . $this->model_name . 'Model.php'; $id = Tools::getInstance()->getUrl_id($url); $sectors = \Sector\DisplayModel::getInstance()->display_sectors(); $type_locations = \Location\DisplayModel::getInstance()->display_TypeLocationModels(); $data = \Location\DisplayModel::getInstance()->display_location($id); echo $this->twig->render($this->view_name . '.tpl', array('sectors' => $sectors, 'typeLocations' => $type_locations, 'id' => $data[0], 'bootstrapPath' => _BOOTSTRAP_FILE_)); } catch (Exception $e) { throw new Exception('Une erreur est survenue durant l\'affichage des données: ' . $e->getMessage()); } } else { throw new Exception('Le template "' . $this->view_name . '" n\'existe pas dans "' . _LOCATIONS_VIEWS_ . '"!'); } } else { throw new Exception('Le modèle "' . $this->model_name . '" n\'existe pas dans "' . _LOCATIONS_MODELS_ . '" ou "' . _SECTORS_MODELS_ . '"!'); } } else { throw new Exception('Une erreur est survenue durant la phase de routage!'); } } else { throw new Exception('L\'URL n\'est pas évaluable!'); } }
/** * Initialize the ConfirmModifyController class and their parents */ public function init() { try { parent::init(); } catch (Exception $e) { throw new Exception('Une erreur est survenue durant le chargement du module: ' . $e->getMessage()); } if (file_exists(_CONTROLLERS_DIR_ . '/Tools.php')) { $url = Tools::getInstance()->request_url; $controller = Tools::getInstance()->getUrl_controller($url); if ($controller == 'ConfirmModifyController') { if (file_exists(_LOCATIONS_MODELS_ . '/' . $this->model_nameModify . 'Model.php') && file_exists(_LOCATIONS_MODELS_ . '/' . $this->model_nameDisplay . 'Model.php')) { try { require_once _LOCATIONS_MODELS_ . '/' . $this->model_nameModify . 'Model.php'; require_once _LOCATIONS_MODELS_ . '/' . $this->model_nameDisplay . 'Model.php'; $id = Tools::getInstance()->getUrl_id($url); Tools::getInstance()->createPost($_POST); if (!empty($_POST['sector']) && !empty($_POST['location'])) { $data = \Location\DisplayModel::getInstance()->display_location($id); \Location\ModifyModel::getInstance()->modify_location($data[0]['loc_sec_id'], $data[0]['loc_type_id'], $_POST['sector'], $_POST['location']); header('Location: /Cas-M-Ping/locations/show/' . $id); } else { header('Location: /Cas-M-Ping/locations/modify/' . $id); } } catch (Exception $e) { throw new Exception('Une erreur est survenue durant la modification des données: ' . $e->getMessage()); } } else { throw new Exception('Le modèle "' . $this->model_nameModify . '" ou "' . $this->model_nameDisplay . '" n\'existe pas dans "' . _LOCATIONS_MODELS_ . '"!'); } } else { throw new Exception('Une erreur est survenue durant la phase de routage!'); } } else { throw new Exception('L\'URL n\'est pas évaluable!'); } }
<?php include "../LoadClass.php"; /** * Created by PhpStorm. * User: User * Date: 1/21/2016 * Time: 6:07 AM */ $id = $_POST['location']; $locationController = new LocationController(); $locationController->removeLocationById($id); header('Location: ../edit_location.php');
<div class="row"> <div class="col-lg-12"> <div class="ibox float-e-margins"> <div class="ibox-title"> <h5>Remove a location<small> from the system </small></h5> </div> <div class="ibox-content"> <form method="post" class="form-horizontal" action="php/DeleteLocation.php"> <div class="form-group"><label class="col-sm-2 control-label">Select Location</label> <div class="col-sm-10"> <select class="form-control m-b" name="location"> <option selected disabled>- Select a location -</option> <?php $locationController = new LocationController(); $locations = $locationController->selectAll(); foreach ($locations as $location) { echo '<option value="' . $location->getLocationId() . '">' . $location->getLocationName() . ', ' . $location->getLocationCity() . '</option>'; } ?> </select> </div> </div> <div class="form-group"> <div class="col-sm-4 col-sm-offset-2"> <a class="btn btn-white" type="submit">Cancel</a> <input type="submit" class="btn btn-primary" value="Delete"> </div> </div>
public function getPayments() { $to = Input::get('to'); $from = Input::get('from'); if ($from == null || $to == null) { $today = LocationController::getTime(); $todayFrom = $today['date'] . ' 00:00:00'; $todayTo = $today['date'] . ' 23:59:59'; } else { $todayFrom = $from . ' 00:00:00'; $todayTo = $to . ' 23:59:59'; } try { $results = Payment::where('created_at', '>', $todayFrom)->where('created_at', '<', $todayTo)->get()->toArray(); if (!is_null($results)) { foreach ($results as $key => $payment) { $driver = Driver::where('id', '=', $payment['driver_id'])->first()->toArray(); $currency = Currency::find($payment['currency'])->pluck('currency'); $results[$key]['driver_name'] = $driver['first'] . ' ' . $driver['last']; $results[$key]['currency'] = $currency; } } $queries = DB::getQueryLog(); $last_query = end($queries); } catch (Exception $ex) { \Log::error(__METHOD__ . ' | error :' . print_r($ex, 1)); } //\Log::info(__METHOD__.print_r($results, 1)); return json_encode($results); }
} else { header('Route Not Found', true, 404); } break; case 'POST': LocationController::create($_POST); break; case 'GET': if (isset($request) && !empty($request) && $request[0] !== '') { if ($request[0] == 'heatmap') { $id = $request[1]; LocationController::heatmap($id); } else { $id = $request[0]; LocationController::detail($id); } } else { LocationController::read(); } break; case 'DELETE': if (isset($request) && !empty($request) && $request[0] !== '') { $id = $request[0]; LocationController::delete($id); } break; default: return print json_encode('DECISION SUPPORT SYSTEM API v.0.1 developed by: Philip Cesar B. Garay'); break; } exit;
/** * Manages all models. */ public function actionAdmin() { if (isset($_POST['command'], $_POST['id']) && $_POST['command'] === 'delete') { LocationController::loadLocation($_POST['id'])->delete(); // reload the current page to avoid duplicated delete actions $this->refresh(); } $criteria = new CDbCriteria(); $pages = new CPagination(Location::model()->count($criteria)); $pages->pageSize = self::PAGE_SIZE; $pages->applyLimit($criteria); $sort = new CSort('Location'); $sort->applyOrder($criteria); $models = Location::model()->findAll($criteria); $this->render('admin', array('models' => $models, 'pages' => $pages, 'sort' => $sort)); }
<div class="ibox-title"> <h5>Remove a sensor board<small> from an available location </small></h5> </div> <div class="ibox-content"> <form method="post" action="php/DeleteSensorBoard.php" class="form-horizontal"> <div class="form-group"><label class="col-sm-2 control-label">Select Board</label> <div class="col-sm-10"> <select class="form-control m-b" name="sensor_board"> <option disabled selected>- Select a sensor board -</option> <?php $sensorBoardController = new SensorBoardController(); $sensorBoards = $sensorBoardController->selectAll(); foreach ($sensorBoards as $sensorBoard) { $locationController = new LocationController(); $loc = $locationController->getLocationByID($sensorBoard->getLocationId()); echo '<option value="' . $sensorBoard->getIdsensorBoard() . '">' . 'Board ' . $sensorBoard->getIdsensorBoard() . ' - ' . $loc->getLocationName() . ', ' . $loc->getLocationCity() . ' (' . $loc->getLatitude() . ', ' . $loc->getLongitude() . ')' . '</option>'; } ?> </select> </div> </div> <div class="form-group"> <div class="col-sm-4 col-sm-offset-2"> <a class="btn btn-white" type="submit">Cancel</a> <input type="submit" class="btn btn-primary" value="Delete"> </div> </div>
<?php /* * Copyright 2014 Empodex PHP Framework. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @copyright 2014-2015 Empoddy Labs. * @author Prabhat Shankar <prabhat.singh88[at]gmail.com> */ require_once '../init.php'; $controller = new LocationController(); echo $controller->go();
public function showMyTrips() { $userId = Session::get('user_id'); $to = Input::get('to'); $from = Input::get('from'); if ($from == null || $to == null) { $today = LocationController::getTime(); $todayFrom = $today['date'] . ' 00:00:00'; $todayTo = $today['date'] . ' 23:59:59'; } else { $todayFrom = $from . ' 00:00:00'; $todayTo = $to . ' 23:59:59'; } try { $myTrips = DailyTrips::where('user_id', '=', $userId)->where('departure_date_time', '>', $todayFrom)->where('departure_date_time', '<', $todayTo)->orderBy('departure_date_time', 'desc')->get()->toArray(); $carId = Session::get('car_id'); $car = Cars::find($carId); if ($myTrips == null) { $myTrips = array('my_trips' => 'no trips have been recorded for you.'); } $results = array('success' => true, 'my_trips' => $myTrips, 'car' => $car); } catch (Exception $ex) { \Log::error(__METHOD__ . ' | error :' . print_r($ex, 1)); $results = array('success' => false, 'message' => 'an error occurred'); } return $results; }