api.garage.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <?php
  2. /**
  3. * Vehicles management and accounting
  4. */
  5. class Garage {
  6. /**
  7. * Contains system alter config as key=>value
  8. *
  9. * @var array
  10. */
  11. protected $altCfg = array();
  12. /**
  13. * Contains all of available cars as id=>carData
  14. *
  15. * @var array
  16. */
  17. protected $allCars = array();
  18. /**
  19. * Garage cars database abstraction placeholder
  20. *
  21. * @var object
  22. */
  23. protected $cars = '';
  24. /**
  25. * Contains available car drivers as employeeid=>DriverData
  26. *
  27. * @var array
  28. */
  29. protected $allDrivers = array();
  30. /**
  31. * Garage cars drivers database abstraction layer
  32. *
  33. * @var object
  34. */
  35. protected $drivers = '';
  36. /**
  37. * Contains all active employee as id=>name
  38. *
  39. * @var array
  40. */
  41. protected $allActiveEmployee = array();
  42. /**
  43. * Contains all employee as id=>name
  44. *
  45. * @var array
  46. */
  47. protected $allEmployee = array();
  48. /**
  49. * Contains all mileages as carid=>date=>mileage (in meters)
  50. *
  51. * @var array
  52. */
  53. protected $allMileage = array();
  54. /**
  55. * System message helper instance placeholder
  56. *
  57. * @var object
  58. */
  59. protected $messages = '';
  60. /**
  61. * Database abstraction layer placeholder for cars mileage counters
  62. *
  63. * @var array
  64. */
  65. protected $mileage = '';
  66. /**
  67. * Contains available fuel types
  68. *
  69. * @var array
  70. */
  71. protected $fuelTypes = array();
  72. /**
  73. * Mapon service enabled flag
  74. *
  75. * @var bool
  76. */
  77. protected $maponEnabled = false;
  78. /**
  79. * Some static stuff: routes, tables, etc...
  80. */
  81. const TABLE_CARS = 'garage_cars';
  82. const TABLE_DRIVERS = 'garage_drivers';
  83. const TABLE_MILEAGE = 'garage_mileage';
  84. const TABLE_MAPONUNITS = 'garage_mapon';
  85. const URL_ME = '?module=garage';
  86. const PROUTE_NEWDRIVER = 'newdriveremployeeid';
  87. const ROUTE_CARS = 'cars';
  88. const ROUTE_DRIVERS = 'drivers';
  89. const ROUTE_MILEAGE = 'mileage';
  90. const ROUTE_DRIVERDEL = 'deletedriveremployeeid';
  91. const ROUTE_CARDEL = 'deletethiscarid';
  92. const PROUTE_DRIVEREDIT = 'editsomedriver';
  93. const PROUTE_DRIVERCAR = 'driversetcar';
  94. const PROUTE_MILEAGEKM = 'newmileagekmeterscount';
  95. const PROUTE_MILEAGECAR = 'newmileagecarid';
  96. /**
  97. * Basic car parameters here
  98. */
  99. const PROUTE_NEWCAR = 'createnewcarplease';
  100. const PROUTE_CARVENDOR = 'carvendor';
  101. const PROUTE_CARMODEL = 'carmodel';
  102. const PROUTE_CARNUMBER = 'carnumber';
  103. const PROUTE_CARVIN = 'carvin';
  104. const PROUTE_CARYEAR = 'caryear';
  105. const PROUTE_CARPOWER = 'carpower';
  106. const PROUTE_CARENGINE = 'carengine';
  107. const PROUTE_CARCONSUMPTION = 'carfuelconsumption';
  108. const PROUTE_CARFUELTYPE = 'carfueltype';
  109. const PROUTE_CARGASTANK = 'cargastank';
  110. const PROUTE_CARWEIGHT = 'carweight';
  111. /**
  112. * Preloads some required data and sets some props.
  113. * What did you expect here?
  114. */
  115. public function __construct() {
  116. $this->initMessages();
  117. $this->loadConfigs();
  118. $this->setFuelTypes();
  119. $this->initCars();
  120. $this->loadCars();
  121. $this->initDrivers();
  122. $this->loadDrivers();
  123. $this->initMileage();
  124. $this->loadMileage();
  125. $this->loadEmployee();
  126. }
  127. /**
  128. * Inits system message helper
  129. *
  130. * @return void
  131. */
  132. protected function initMessages() {
  133. $this->messages = new UbillingMessageHelper();
  134. }
  135. /**
  136. * Loads required configs for further usage
  137. *
  138. * @return void
  139. */
  140. protected function loadConfigs() {
  141. global $ubillingConfig;
  142. $this->altCfg = $ubillingConfig->getAlter();
  143. }
  144. /**
  145. * Inits cars database abstraction layer
  146. *
  147. * @return void
  148. */
  149. protected function initCars() {
  150. $this->cars = new NyanORM(self::TABLE_CARS);
  151. }
  152. /**
  153. * Loads existing cars from database
  154. *
  155. * @return void
  156. */
  157. protected function loadCars() {
  158. $this->allCars = $this->cars->getAll('id');
  159. }
  160. /**
  161. * Inits drivers database abstraction layer
  162. *
  163. * @return void
  164. */
  165. protected function initDrivers() {
  166. $this->drivers = new NyanORM(self::TABLE_DRIVERS);
  167. }
  168. /**
  169. * Loads available drivers from database
  170. *
  171. * @return void
  172. */
  173. protected function loadDrivers() {
  174. $this->allDrivers = $this->drivers->getAll('employeeid');
  175. }
  176. /**
  177. * Inits mileages database abstraction layer
  178. *
  179. * @return void
  180. */
  181. protected function initMileage() {
  182. $this->mileage = new NyanORM(self::TABLE_MILEAGE);
  183. }
  184. /**
  185. * Loads existing mileage counters from database
  186. *
  187. * @return void
  188. */
  189. protected function loadMileage() {
  190. $mileageTmp = $this->mileage->getAll();
  191. if (!empty($mileageTmp)) {
  192. foreach ($mileageTmp as $io => $each) {
  193. $dateDay = strtotime($each['date']);
  194. $dateDay = date("Y-m-d", $dateDay); //just a day of month
  195. $dayMileage = $each['mileage'];
  196. // TODO: take some decision on this
  197. // //on many records by same date
  198. // if (isset($this->allMileage[$each['carid']][$dateDay])) {
  199. // $dayMileage += $this->allMileage[$each['carid']][$dateDay];
  200. // }
  201. $this->allMileage[$each['carid']][$dateDay] = $dayMileage;
  202. }
  203. }
  204. }
  205. /**
  206. * Renders mileage creation form
  207. *
  208. * @return string
  209. */
  210. public function renderMileageCreateForm() {
  211. $result = '';
  212. $carsTmp = array();
  213. if (!empty($this->allCars)) {
  214. foreach ($this->allCars as $io => $each) {
  215. $driverId = $this->getCarDriver($each['id']);
  216. $driverName = (isset($this->allEmployee[$driverId])) ? $this->allEmployee[$driverId] : '';
  217. $carLabel = $each['vendor'] . ' ' . $each['model'] . ' ' . $each['number'] . ' - ' . $driverName;
  218. $carsTmp[$each['id']] = $carLabel;
  219. }
  220. }
  221. $inputs = wf_Selector(self::PROUTE_MILEAGECAR, $carsTmp, __('Car'), '', true);
  222. $inputs .= wf_TextInput(self::PROUTE_MILEAGEKM, __('Mileage') . ' (' . __('km') . ')', '', true, 8, 'digits');
  223. $inputs .= wf_Submit(__('Save'));
  224. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  225. return($result);
  226. }
  227. /**
  228. * Creates new mileage record in database
  229. *
  230. * @param int $carId
  231. * @param int $mileage
  232. * @param bool $inKilometers
  233. *
  234. * @return void/string on error
  235. */
  236. public function createMileage($carId, $mileage, $inKilometers) {
  237. $result = '';
  238. $newDate = curdatetime();
  239. $mileage = ubRouting::filters($mileage, 'int');
  240. $carId = ubRouting::filters($carId, 'int');
  241. if ($inKilometers) {
  242. $mileage = $mileage * 1000; //omg omg, so much math!
  243. }
  244. if (!empty($mileage) AND ! empty($carId)) {
  245. //TODO: add some new >= old check here
  246. $this->mileage->data('date', $newDate);
  247. $this->mileage->data('carid', $carId);
  248. $this->mileage->data('mileage', $mileage);
  249. $this->mileage->create();
  250. log_register('GARAGE MILEAGE CREATE CAR [' . $carId . '] M `' . $mileage . '`');
  251. } else {
  252. $result .= __('Something went wrong') . ': ' . __('Car') . ' ' . __('or') . ' ' . __('Mileage') . ' ' . __('is empty');
  253. }
  254. return($result);
  255. }
  256. /**
  257. * Sets available fuel types
  258. *
  259. * @return void
  260. */
  261. protected function setFuelTypes() {
  262. $this->fuelTypes['petrol'] = __('Petrol');
  263. $this->fuelTypes['diesel'] = __('Diesel');
  264. $this->fuelTypes['lpg'] = __('Liquefied petroleum gas');
  265. $this->fuelTypes['electric'] = __('Electric');
  266. $this->fuelTypes['wood'] = __('On the wood');
  267. }
  268. /**
  269. * Loads available active employee from database
  270. *
  271. * @return void
  272. */
  273. protected function loadEmployee() {
  274. $employeeRaw = ts_GetAllEmployeeData();
  275. if (!empty($employeeRaw)) {
  276. foreach ($employeeRaw as $employeeId => $employeeData) {
  277. $this->allEmployee[$employeeId] = $employeeData['name'];
  278. if ($employeeData['active']) {
  279. $this->allActiveEmployee[$employeeId] = $employeeData['name'];
  280. }
  281. }
  282. }
  283. }
  284. /**
  285. * Renders new driver creation form
  286. *
  287. * @return string
  288. */
  289. protected function renderDriverCreateForm() {
  290. $result = '';
  291. $params = array();
  292. if (!empty($this->allActiveEmployee)) {
  293. foreach ($this->allActiveEmployee as $employeeId => $employeeName) {
  294. if (!isset($this->allDrivers[$employeeId])) {
  295. $params[$employeeId] = $employeeName;
  296. }
  297. }
  298. }
  299. if (!empty($params)) {
  300. $inputs = wf_Selector(self::PROUTE_NEWDRIVER, $params, __('Worker'), '', true);
  301. $inputs .= wf_Submit(__('Create'));
  302. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  303. } else {
  304. $result .= $this->messages->getStyledMessage(__('No employee to be an drivers'), 'info');
  305. }
  306. return($result);
  307. }
  308. /**
  309. * Creates new employee in database
  310. *
  311. * @param int $employeeId
  312. *
  313. * @return void
  314. */
  315. public function createDriver($employeeId) {
  316. $newEmployeeId = ubRouting::filters($employeeId, 'int');
  317. if (!isset($this->allDrivers[$newEmployeeId])) {
  318. if (isset($this->allActiveEmployee[$newEmployeeId])) {
  319. $this->drivers->data('employeeid', $newEmployeeId);
  320. $this->drivers->data('carid', '');
  321. $this->drivers->create();
  322. $newId = $this->drivers->getLastId();
  323. log_register('GARAGE DRIVER CREATE [' . $newEmployeeId . '] AS [' . $newId . ']');
  324. }
  325. }
  326. }
  327. /**
  328. * Deletes existing driver from database
  329. *
  330. * @param int $employeeId
  331. *
  332. * @return
  333. */
  334. public function deleteDriver($employeeId) {
  335. $employeeId = ubRouting::filters($employeeId, 'int');
  336. if (isset($this->allDrivers)) {
  337. $this->drivers->where('employeeid', '=', $employeeId);
  338. $this->drivers->delete();
  339. log_register('GARAGE DRIVER DELETE [' . $employeeId . ']');
  340. }
  341. }
  342. /**
  343. * Deletes existing car from database
  344. *
  345. * @param int $carId
  346. *
  347. * @return void/string on error
  348. */
  349. public function deleteCar($carId) {
  350. $result = '';
  351. $carId = ubRouting::filters($carId, 'int');
  352. if (isset($this->allCars[$carId])) {
  353. if (!$this->isCarProtected($carId)) {
  354. $this->cars->where('id', '=', $carId);
  355. $this->cars->delete();
  356. log_register('GARAGE CAR DELETE [' . $carId . ']');
  357. } else {
  358. $result .= __('You cant delete a car which have a driver');
  359. log_register('GARAGE CAR DELETE [' . $carId . '] FAIL BUSY');
  360. }
  361. } else {
  362. log_register('GARAGE CAR DELETE [' . $carId . '] FAIL NOT_EXISTS');
  363. }
  364. return($result);
  365. }
  366. /**
  367. * Returns array of cars which not used by another drivers
  368. *
  369. * @return array
  370. */
  371. protected function getFreeCars() {
  372. $result = array();
  373. if (!empty($this->allCars)) {
  374. $carsTmp = $this->allCars;
  375. if (!empty($this->allDrivers)) {
  376. foreach ($this->allDrivers as $io => $eachDriver) {
  377. if (!empty($eachDriver['carid'])) {
  378. if (isset($carsTmp[$eachDriver['carid']])) {
  379. unset($carsTmp[$eachDriver['carid']]);
  380. }
  381. }
  382. }
  383. }
  384. if (!empty($carsTmp)) {
  385. foreach ($carsTmp as $carId => $carData) {
  386. $result[$carId] = $carData['vendor'] . ' ' . $carData['model'] . ' ' . $carData['number'];
  387. }
  388. }
  389. }
  390. return($result);
  391. }
  392. /**
  393. * Renders existing driver editing form
  394. *
  395. * @param int $employeeId
  396. *
  397. * @return string
  398. */
  399. protected function renderDriverEditFrom($employeeId) {
  400. $result = '';
  401. $employeeId = ubRouting::filters($employeeId, 'int');
  402. if (isset($this->allDrivers[$employeeId])) {
  403. $freeCars = array('' => '-');
  404. $freeCars += $this->getFreeCars();
  405. $inputs = wf_HiddenInput(self::PROUTE_DRIVEREDIT, $employeeId);
  406. $inputs .= wf_Selector(self::PROUTE_DRIVERCAR, $freeCars, __('Car'), $this->allDrivers[$employeeId]['carid'], false);
  407. $inputs .= wf_Submit(__('Save'));
  408. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  409. } else {
  410. $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': EX_NO_DRIVER_EXIST [' . $employeeId . ']', 'error');
  411. }
  412. return($result);
  413. }
  414. /**
  415. * Sets some car as occupied by some driver
  416. *
  417. * @param int $employeeId
  418. *
  419. * @return void
  420. */
  421. public function setDriverCar($employeeId, $carId) {
  422. $employeeId = ubRouting::filters($employeeId, 'int');
  423. $carId = ubRouting::filters($carId, 'int');
  424. if (isset($this->allDrivers[$employeeId])) {
  425. $oldCar = $this->allDrivers[$employeeId]['carid'];
  426. if (empty($carId)) {
  427. //drop car from the driver
  428. $this->drivers->where('employeeid', '=', $employeeId);
  429. $this->drivers->data('carid', '0');
  430. $this->drivers->save();
  431. log_register('GARAGE DRIVER CHANGE CAR [' . $oldCar . '] TO [0]');
  432. } else {
  433. //set new car to driver
  434. $freeCars = $this->getFreeCars();
  435. if (isset($freeCars[$carId])) {
  436. $this->drivers->where('employeeid', '=', $employeeId);
  437. $this->drivers->data('carid', $carId);
  438. $this->drivers->save();
  439. log_register('GARAGE DRIVER CHANGE CAR [' . $oldCar . '] TO [' . $carId . ']');
  440. } else {
  441. log_register('GARAGE DRIVER CHANGE CAR [' . $oldCar . '] TO [' . $carId . '] FAIL BUSY');
  442. }
  443. }
  444. }
  445. }
  446. /**
  447. * Renders existing cars drivers
  448. *
  449. * @return string
  450. */
  451. public function renderDriversList() {
  452. $result = '';
  453. if (!empty($this->allDrivers)) {
  454. $cells = wf_TableCell(__('Driver'));
  455. $cells .= wf_TableCell(__('Car'));
  456. $cells .= wf_TableCell(__('Actions'));
  457. $rows = wf_TableRow($cells, 'row1');
  458. foreach ($this->allDrivers as $employeeId => $eachDriverData) {
  459. $cells = wf_TableCell(@$this->allEmployee[$employeeId]);
  460. $carData = @$this->allCars[$eachDriverData['carid']];
  461. $cells .= wf_TableCell(@$carData['vendor'] . ' ' . @$carData['model'] . ' ' . @$carData['number']);
  462. $actControls = wf_JSAlert(self::URL_ME . '&' . self::ROUTE_DRIVERDEL . '=' . $employeeId, web_delete_icon(), $this->messages->getDeleteAlert());
  463. $actControls .= wf_modalAuto(web_edit_icon(), __('Edit'), $this->renderDriverEditFrom($employeeId));
  464. $cells .= wf_TableCell($actControls);
  465. $rows .= wf_TableRow($cells, 'row5');
  466. }
  467. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  468. } else {
  469. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'warning');
  470. }
  471. //new driver creation interface here
  472. $result .= wf_tag('br') . wf_modalAuto(web_icon_create() . ' ' . __('Create'), __('Create'), $this->renderDriverCreateForm(), 'ubButton');
  473. return($result);
  474. }
  475. /**
  476. * Renders new car creation form
  477. *
  478. * @return string
  479. */
  480. protected function renderCarCreateForm() {
  481. $result = '';
  482. $inputs = wf_HiddenInput(self::PROUTE_NEWCAR, 'true'); //just creation flag
  483. $inputs .= wf_TextInput(self::PROUTE_CARVENDOR, __('Vendor'), '', true, 20, '');
  484. $inputs .= wf_TextInput(self::PROUTE_CARMODEL, __('Model'), '', true, 20, '');
  485. $inputs .= wf_TextInput(self::PROUTE_CARNUMBER, __('Number'), '', true, 20, 'alphanumeric');
  486. $inputs .= wf_TextInput(self::PROUTE_CARVIN, __('VIN'), '', true, 20, 'alphanumeric');
  487. $inputs .= wf_TextInput(self::PROUTE_CARYEAR, __('Year'), '', true, 5, 'digits');
  488. $inputs .= wf_TextInput(self::PROUTE_CARPOWER, __('Power') . ' (' . __('hp') . ')', '', true, 5, 'digits');
  489. $inputs .= wf_TextInput(self::PROUTE_CARENGINE, __('Vehicle engine') . ' (' . __('cc') . ')', '', true, 5, 'digits');
  490. $inputs .= wf_TextInput(self::PROUTE_CARCONSUMPTION, __('Fuel consumption') . ' (' . __('litre') . '/100' . __('km') . ')', '', true, 5);
  491. $inputs .= wf_Selector(self::PROUTE_CARFUELTYPE, $this->fuelTypes, __('Fuel type'), '', true);
  492. $inputs .= wf_TextInput(self::PROUTE_CARGASTANK, __('Gas tank') . ' (' . __('litre') . ')', '', true, 4, 'digits');
  493. $inputs .= wf_TextInput(self::PROUTE_CARWEIGHT, __('Weight') . ' (' . __('kg') . ')', '', true, 4, 'digits');
  494. $inputs .= wf_Submit(__('Create'));
  495. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  496. return($result);
  497. }
  498. /**
  499. * Creates new car in database
  500. *
  501. * @return void
  502. */
  503. public function createCar() {
  504. if (ubRouting::checkPost(array(self::PROUTE_NEWCAR, self::PROUTE_CARVENDOR, self::PROUTE_CARMODEL))) {
  505. $newCarVendor = ubRouting::post(self::PROUTE_CARVENDOR, 'mres');
  506. $newCarModel = ubRouting::post(self::PROUTE_CARMODEL, 'mres');
  507. //required fields
  508. if (!empty($newCarVendor) AND ! empty($newCarModel)) {
  509. $this->cars->data('vendor', ubRouting::post(self::PROUTE_CARVENDOR, 'mres'));
  510. $this->cars->data('model', ubRouting::post(self::PROUTE_CARMODEL, 'mres'));
  511. $this->cars->data('number', ubRouting::post(self::PROUTE_CARNUMBER, 'mres'));
  512. $this->cars->data('vin', ubRouting::post(self::PROUTE_CARVIN, 'mres'));
  513. $this->cars->data('year', ubRouting::post(self::PROUTE_CARYEAR, 'int'));
  514. $this->cars->data('power', ubRouting::post(self::PROUTE_CARPOWER, 'int'));
  515. $this->cars->data('engine', ubRouting::post(self::PROUTE_CARENGINE, 'int'));
  516. $this->cars->data('fuelconsumption', ubRouting::post(self::PROUTE_CARCONSUMPTION, 'float'));
  517. $this->cars->data('fueltype', ubRouting::post(self::PROUTE_CARFUELTYPE, 'mres'));
  518. $this->cars->data('gastank', ubRouting::post(self::PROUTE_CARGASTANK, 'int'));
  519. $this->cars->data('weight', ubRouting::post(self::PROUTE_CARWEIGHT, 'int'));
  520. $this->cars->create();
  521. $newCarId = $this->cars->getLastId();
  522. log_register('GARAGE CAR CREATE [' . $newCarId . ']');
  523. }
  524. }
  525. }
  526. /**
  527. * Checks is car used by someone?
  528. *
  529. * @param int $carId
  530. *
  531. * @return bool
  532. */
  533. protected function isCarProtected($carId) {
  534. $result = false;
  535. $carId = ubRouting::filters($carId, 'int');
  536. if (isset($this->allCars[$carId])) {
  537. $freeCars = $this->getFreeCars();
  538. if (!isset($freeCars[$carId])) {
  539. $result = true;
  540. }
  541. }
  542. return($result);
  543. }
  544. /**
  545. * Returns car driver employeeId
  546. *
  547. * @param int $carId
  548. *
  549. * @return int
  550. */
  551. protected function getCarDriver($carId) {
  552. $result = 0;
  553. if (!empty($this->allDrivers)) {
  554. foreach ($this->allDrivers as $employeeId => $driverData) {
  555. if ($driverData['carid'] == $carId) {
  556. $result = $employeeId;
  557. }
  558. }
  559. }
  560. return($result);
  561. }
  562. /**
  563. * Renders available cars list
  564. *
  565. * @return string
  566. */
  567. public function renderCarsList() {
  568. $result = '';
  569. if (!empty($this->allCars)) {
  570. $cells = wf_TableCell(__('Model'));
  571. $cells .= wf_TableCell(__('Number'));
  572. $cells .= wf_TableCell(__('Driver'));
  573. $cells .= wf_TableCell(__('Actions'));
  574. $rows = wf_TableRow($cells, 'row1');
  575. foreach ($this->allCars as $carId => $carData) {
  576. $cells = wf_TableCell($carData['vendor'] . ' ' . $carData['model']);
  577. $cells .= wf_TableCell($carData['number']);
  578. $carDriverId = $this->getCarDriver($carId);
  579. $driverName = ($carDriverId) ? @$this->allEmployee[$carDriverId] : '';
  580. $cells .= wf_TableCell($driverName);
  581. $carControls = wf_JSAlert(self::URL_ME . '&' . self::ROUTE_CARDEL . '=' . $carId, web_delete_icon(), $this->messages->getDeleteAlert());
  582. $cells .= wf_TableCell($carControls);
  583. $rows .= wf_TableRow($cells, 'row5');
  584. }
  585. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  586. } else {
  587. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'warning');
  588. }
  589. //creation interface here
  590. $result .= wf_tag('br') . wf_modalAuto(web_icon_create() . ' ' . __('Create'), __('Create'), $this->renderCarCreateForm(), 'ubButton');
  591. return($result);
  592. }
  593. /**
  594. * Renders basic controls panel
  595. *
  596. * @return string
  597. */
  598. public function renderControls() {
  599. $result = '';
  600. $result .= wf_Link(self::URL_ME . '&' . self::ROUTE_CARS . '=true', wf_img('skins/car_small.png') . ' ' . __('Cars'), false, 'ubButton');
  601. $result .= wf_Link(self::URL_ME . '&' . self::ROUTE_DRIVERS . '=true', wf_img('skins/driver_small.png') . ' ' . __('Drivers'), false, 'ubButton');
  602. $result .= wf_Link(self::URL_ME . '&' . self::ROUTE_MILEAGE . '=true', wf_img('skins/icon_street.gif') . ' ' . __('Mileage'), false, 'ubButton');
  603. return($result);
  604. }
  605. }