<?php namespace MotaRaido\Menu\Order; use \MotaRaido\Core\View; use \MotaRaido\Core\Route; if (!defined('MOTAFW')) { echo 'This file can only be called via the main index.php file, and not directly'; exit(); } Route::add('/order/#user/selectdriver', function($user) use ($query) { $view = new View(); $view->assign('title', 'Select Driver'); $view->assign('script', JS . 'selectdriver.js'); $view->assign('user', $user); $view->assign('image', IMG); $pickLoc = $_POST['pick-point']; $dest = $_POST['destination']; $prefDriver = $_POST['pref-driver']; $driverList = $query->select('preferredloc',[]); $ratingDat = $query->select('history',[]); $driverName = $query->select('user', []); $driverPrefLoc = array(); $preferredDriver = ''; $count = 0; foreach($driverList as $driver) { if(!strcasecmp($driver[0],$prefDriver) && $driver[0] !== $user) { $preferredDriver = $driver[0]; } else { if (($driver[1] === $pickLoc || $driver[1] === $dest) && !in_array($driver[0],$driverPrefLoc) && $driver[0] !== $user) { $driverPrefLoc[$count] = $driver[0]; $count++; } } } EmbedJS($driverPrefLoc, $ratingDat, $driverName, $user, $preferredDriver, $pickLoc, $dest); print_r($jsDriverArr); $view->render(__DIR__ . '/SelectDriver.view.php'); }); function EmbedJS($driverArr, $ratingArr, $driverNameArr, $user, $prefDriver, $pickLoc, $dest) { $jsRatingArr = json_encode($ratingArr); $jsDriverArr = json_encode($driverArr); $jsDriverNameArr = json_encode($driverNameArr); $jsUser = json_encode($user); $jsPrefDriver = json_encode($prefDriver); $jsPickLoc = json_encode($pickLoc); $jsDest = json_encode($dest); echo "<script>"; echo "var driverArr = $jsDriverArr;"; echo "var ratingArr = $jsRatingArr;"; echo "var driverNameArr = $jsDriverNameArr;"; echo "var user = $jsUser;"; echo "var preferredDriver = $jsPrefDriver;"; echo "var pickLoc = $jsPickLoc;"; echo "var dest = $jsDest;"; echo "</script>"; }