Advertisement
Guest User

Untitled

a guest
Sep 5th, 2010
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. <?php
  2. /**
  3. * phpVMS - Virtual Airline Administration Software
  4. * Copyright (c) 2008 Nabeel Shahzad
  5. * For more information, visit www.phpvms.net
  6. * Forums: http://www.phpvms.net/forum
  7. * Documentation: http://www.phpvms.net/docs
  8. *
  9. * phpVMS is licenced under the following license:
  10. * Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
  11. * View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
  12. *
  13. * @author Nabeel Shahzad
  14. * @copyright Copyright (c) 2008, Nabeel Shahzad
  15. * @link http://www.phpvms.net
  16. * @license http://creativecommons.org/licenses/by-nc-sa/3.0/
  17. */
  18.  
  19. class Schedules extends CodonModule
  20. {
  21. public function index()
  22. {
  23. $this->view();
  24. }
  25.  
  26. public function view()
  27. {
  28. if(isset($this->post->action) && $this->post->action == 'findflight')
  29. {
  30. $this->FindFlight();
  31. return;
  32. }
  33.  
  34. $this->showSchedules();
  35. }
  36.  
  37. public function detail($routeid='')
  38. {
  39. $this->details($routeid);
  40. }
  41.  
  42. public function details($routeid = '')
  43. {
  44. //$routeid = $this->get->id;
  45.  
  46. if(!is_numeric($routeid))
  47. {
  48. preg_match('/^([A-Za-z]{3})(\d*)/', $routeid, $matches);
  49. $code = $matches[1];
  50. $flightnum = $matches[2];
  51.  
  52. $params = array('s.code'=>$code, 's.flightnum'=>$flightnum);
  53. }
  54. else
  55. {
  56. $params = array('s.id' => $routeid);
  57. }
  58.  
  59. $schedule = SchedulesData::getScheduleDetailed($routeid);
  60. $this->set('schedule', $schedule);
  61. $this->render('schedule_details.tpl');
  62. $this->render('route_map.tpl');
  63. }
  64.  
  65. public function brief($routeid = '')
  66. {
  67. if($routeid == '')
  68. {
  69. $this->set('message', 'You must be logged in to access this feature!');
  70. $this->render('core_error.tpl');
  71. return;
  72. }
  73.  
  74. $schedule = SchedulesData::getScheduleDetailed($routeid);
  75. $this->set('schedule', $schedule);
  76. $this->render('schedule_briefing.tpl');
  77. }
  78.  
  79. public function boardingpass($routeid)
  80. {
  81. if($routeid == '')
  82. {
  83. $this->set('message', 'You must be logged in to access this feature!');
  84. $this->render('core_error.tpl');
  85. return;
  86. }
  87.  
  88. $schedule = SchedulesData::getScheduleDetailed($routeid);
  89.  
  90. $this->set('schedule', $schedule);
  91. $this->render('schedule_boarding_pass.tpl');
  92. }
  93.  
  94. public function bids()
  95. {
  96. if(!Auth::LoggedIn()) return;
  97.  
  98. $this->set('bids', SchedulesData::GetBids(Auth::$userinfo->pilotid));
  99. $this->render('schedule_bids.tpl');
  100. }
  101.  
  102. public function addbid()
  103. {
  104. if(!Auth::LoggedIn()) return;
  105.  
  106. $routeid = $this->post->id;
  107.  
  108. if($routeid == '')
  109. {
  110. echo 'No route passed';
  111. return;
  112. }
  113.  
  114. // See if this is a valid route
  115. $route = SchedulesData::findSchedules(array('s.id' => $routeid));
  116.  
  117. if(!is_array($route) && !isset($route[0]))
  118. {
  119. echo 'Invalid Route';
  120. return;
  121. }
  122.  
  123. CodonEvent::Dispatch('bid_preadd', 'Schedules', $routeid);
  124.  
  125. /* Block any other bids if they've already made a bid
  126. */
  127. if(Config::Get('DISABLE_BIDS_ON_BID') == true)
  128. {
  129. $bids = SchedulesData::getBids(Auth::$userinfo->pilotid);
  130.  
  131. # They've got somethin goin on
  132. if(count($bids) > 0)
  133. {
  134. echo 'Bid exists!';
  135. return;
  136. }
  137. }
  138.  
  139. $ret = SchedulesData::AddBid(Auth::$userinfo->pilotid, $routeid);
  140. CodonEvent::Dispatch('bid_added', 'Schedules', $routeid);
  141.  
  142. if($ret == true)
  143. {
  144. echo 'Bid added';
  145. }
  146. else
  147. {
  148. echo 'Already in bids!';
  149. }
  150. }
  151.  
  152. public function removebid()
  153. {
  154. if(!Auth::LoggedIn()) return;
  155.  
  156. SchedulesData::RemoveBid($this->post->id);
  157. }
  158.  
  159. public function showSchedules()
  160. {
  161. $depapts = OperationsData::GetAllAirports();
  162. $equip = OperationsData::GetAllAircraftSearchList(true);
  163.  
  164. $this->set('depairports', $depapts);
  165. $this->set('equipment', $equip);
  166.  
  167. $this->render('schedule_searchform.tpl');
  168.  
  169. # Show the routes. Remote this to not show them.
  170. $this->set('allroutes', SchedulesData::GetSchedules());
  171.  
  172. $this->render('schedule_list.tpl');
  173. }
  174.  
  175. public function findFlight()
  176. {
  177.  
  178. if($this->post->depicao != '')
  179. {
  180. $params = array('s.depicao' => $this->post->depicao);
  181. }
  182.  
  183. if($this->post->arricao != '')
  184. {
  185. $params = array('s.arricao' => $this->post->arricao);
  186. }
  187.  
  188. if($this->post->equipment != '')
  189. {
  190. $params = array('a.name' => $this->post->equipment);
  191. }
  192.  
  193. if($this->post->distance != '')
  194. {
  195. if($this->post->type == 'greater')
  196. $value = '> ';
  197. else
  198. $value = '< ';
  199.  
  200. $value .= $this->post->distance;
  201.  
  202. $params = array('s.distance' => $value);
  203. }
  204.  
  205. $params['s.enabled'] = 1;
  206. $this->set('allroutes', SchedulesData::findSchedules($params));
  207. $this->render('schedule_results.tpl');
  208. }
  209.  
  210. public function statsdaysdata($routeid)
  211. {
  212. $routeinfo = SchedulesData::findSchedules(array('s.id'=>$routeid));
  213. $routeinfo = $routeinfo[0];
  214.  
  215. // Last 30 days stats
  216. $data = PIREPData::getIntervalDataByDays(
  217. array(
  218. 'p.code' => $routeinfo->code,
  219. 'p.flightnum' => $routeinfo->flightnum,
  220. ), 30);
  221.  
  222. $this->create_line_graph('Schedule Flown Counts', $data);
  223. }
  224.  
  225. protected function create_line_graph($title, $data)
  226. {
  227. if(!$data)
  228. {
  229. $data = array();
  230. }
  231.  
  232. $titles = array();
  233. $bar_titles = array();
  234. foreach($data as $val)
  235. {
  236. $titles[] = $val->ym;
  237. $values[] = floatval($val->total);
  238. }
  239.  
  240. OFCharts::add_data_set($titles, $values);
  241. echo OFCharts::create_line_graph($title);
  242. }
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement