Guest User

vms

a guest
Oct 19th, 2010
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.47 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 Maintenance extends CodonModule
  20. {
  21.  
  22. public function HTMLHead()
  23. {
  24. $this->set('sidebar', 'sidebar_maintenance.tpl');
  25. }
  26.  
  27. public function index()
  28. {
  29. $this->options();
  30. }
  31.  
  32. public function options()
  33. {
  34. $this->render('maintenance_options.tpl');
  35. }
  36.  
  37. public function resetdistances()
  38. {
  39. echo '<h3>Updating and Calculating Distances</h3>';
  40.  
  41. # Update all of the schedules
  42. echo '<p><strong>Updating schedules...</strong></p>';
  43.  
  44. //$allschedules = SchedulesData::GetSchedulesNoDistance();
  45. $allschedules = SchedulesData::findSchedules(array());
  46.  
  47. if(!$allschedules)
  48. {
  49. echo 'No schedules to update';
  50. $allschedules = array();
  51. }
  52.  
  53. # Check 'em
  54. foreach($allschedules as $sched)
  55. {
  56. $distance = SchedulesData::distanceBetweenPoints($sched->deplat, $sched->deplng,
  57. $sched->arrlat, $sched->arrlng);
  58.  
  59. $distance = sprintf("%.6f", $distance);
  60. echo "$sched->code$sched->flightnum - $sched->depname to $sched->arrname "
  61. ."is $distance ".Config::Get('UNIT').'<br />';
  62.  
  63. SchedulesData::updateScheduleFields($sched->id, array('distance' => $distance));
  64. }
  65.  
  66. # Update all of the PIREPS
  67.  
  68. echo '<p><strong>Updating PIREPs...</strong></p>';
  69.  
  70. $allpireps = PIREPData::findPIREPS(array());
  71.  
  72. if(!$allpireps)
  73. {
  74. echo 'No PIREPs need updating!';
  75. $allpireps = array();
  76. }
  77.  
  78. foreach($allpireps as $pirep)
  79. {
  80.  
  81. # Find the schedule, and the distance supplied by the schedule:
  82. $distance = SchedulesData::distanceBetweenPoints($pirep->deplat, $pirep->deplng,
  83. $pirep->arrlat, $pirep->arrlng);
  84.  
  85. $distance = sprintf("%.2f", $distance);
  86.  
  87. echo "PIREP Number $pirep->pirepid ($pirep->code$pirep->flightnum) "
  88. ."$pirep->depname to $pirep->arrname is $distance ".Config::Get('UNIT').'<br />';
  89.  
  90. PIREPData::editPIREPFields($pirep->pirepid, array('distance'=>$distance));
  91. }
  92.  
  93. echo '<p>Completed!</p><br />';
  94.  
  95. LogData::addLog(Auth::$userinfo->pilotid, 'Reset distances');
  96. }
  97.  
  98. public static function resetpirepcount()
  99. {
  100. echo '<h3>Reset PIREP Counts</h3>';
  101. $all_pilots = PilotData::findPilots(array());
  102.  
  103. foreach($all_pilots as $pilot)
  104. {
  105. $pireps = PIREPData::getReportsByAcceptStatus($pilot->pilotid, PIREP_ACCEPTED);
  106. $total = count($pireps);
  107. unset($pireps);
  108.  
  109. $code = PilotData::getPilotCode($pilot->code, $pilot->pilotid);
  110.  
  111. echo "{$code} - {$pilot->firstname} {$pilot->lastname} - {$total} pireps<br />";
  112.  
  113. # Update the pireps table
  114. PilotData::updateProfile($pilot->pilotid, array('totalpireps' => $total));
  115. }
  116.  
  117. echo 'Completed!';
  118. }
  119.  
  120. public function changepilotid()
  121. {
  122. echo '<h3>Change Pilot ID</h3>';
  123.  
  124. if(isset($this->post->submit))
  125. {
  126. $error = false;
  127.  
  128. if(!is_numeric($this->post->new_pilotid))
  129. {
  130. $error = true;
  131. $this->set('message', 'The pilot ID isn\'t numeric!');
  132. $this->render('core_error.tpl');
  133. return;
  134. }
  135.  
  136. if($this->post->new_pilotid < 1)
  137. {
  138. $error = true;
  139. $this->set('message', 'You cannot have an ID less than 1');
  140. $this->render('core_error.tpl');
  141. return;
  142. }
  143.  
  144. if(empty($this->post->new_pilotid))
  145. {
  146. $error = true;
  147. $this->set('message', 'The pilot ID is blank!');
  148. $this->render('core_error.tpl');
  149. return;
  150. }
  151.  
  152. if(empty($this->post->old_pilotid) || $this->post->old_pilotid == 0)
  153. {
  154. $error = true;
  155. $this->set('message', 'No pilot selected');
  156. $this->render('core_error.tpl');
  157. return;
  158. }
  159.  
  160. $pilot = PilotData::getPilotData($this->post->new_pilotid);
  161. if(is_object($pilot))
  162. {
  163. $error = true;
  164. $this->set('message', 'This ID is already used!');
  165. $this->render('core_error.tpl');
  166. return;
  167. }
  168.  
  169. if($error === false)
  170. {
  171. PilotData::changePilotID($this->post->old_pilotid, $this->post->new_pilotid);
  172.  
  173. $this->set('message', "Pilot ID changed from {$this->post->old_pilotid} to {$this->post->new_pilotid}");
  174. $this->render('core_success.tpl');
  175. }
  176. }
  177.  
  178. $this->set('allpilots', PilotData::findPilots(array()));
  179. $this->render('maintenance_changepilotid.tpl');
  180. }
  181.  
  182. public function optimizetables()
  183. {
  184. echo '<h3>Optimizing Tables...</h3>';
  185. $results = MaintenanceData::optimizeTables();
  186.  
  187. foreach($results as $row)
  188. {
  189. echo "{$row->Table} - {$row->Msg_text}<br />";
  190. }
  191. }
  192.  
  193. public function resetacars()
  194. {
  195. echo '<h3>ACARS Reset</h3>';
  196.  
  197. ACARSData::resetFlights();
  198.  
  199. }
  200.  
  201. public function clearcache()
  202. {
  203. echo '<h3>Clearing Cache</h3>';
  204.  
  205. $dir_iterator = new RecursiveDirectoryIterator(CACHE_PATH);
  206. $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
  207.  
  208. foreach ($iterator as $file)
  209. {
  210. if($file->getType() != 'file')
  211. {
  212. continue;
  213. }
  214.  
  215. $file_name = $file->getBaseName();
  216. if($file_name === 'index.php')
  217. continue;
  218.  
  219. echo "Removing \"{$file_name}\"<br />";
  220. unlink($file);
  221. }
  222.  
  223. echo 'Cache cleared!';
  224. }
  225.  
  226. public function calculateranks()
  227. {
  228. echo '<h3>Resetting Ranks</h3>';
  229. RanksData::CalculatePilotRanks();
  230. echo 'Done!';
  231.  
  232. LogData::addLog(Auth::$userinfo->pilotid, 'Recalculated ranks');
  233. }
  234.  
  235. public function resetpilotpay()
  236. {
  237. echo '<h3>Resetting Pilot Pay</h3>';
  238. $allpilots = PilotData::GetAllPilots();
  239.  
  240. foreach($allpilots as $p)
  241. {
  242. $total = PilotData::resetPilotPay($p->pilotid);
  243.  
  244. echo "{$p->firstname} {$p->lastname} - total $ {$total}<br />";
  245. }
  246.  
  247. echo 'Done';
  248.  
  249. LogData::addLog(Auth::$userinfo->pilotid, 'Reset pilot pay');
  250. }
  251.  
  252.  
  253. public function resetsignatures()
  254. {
  255. $allpilots = PilotData::GetAllPilots();
  256.  
  257. echo '<h3>Regenerating signatures</h3>
  258. <strong>Generating signatures...</strong><br />';
  259.  
  260. foreach($allpilots as $pilot)
  261. {
  262. echo "Generating signature for $pilot->firstname $pilot->lastname<br />";
  263. PilotData::GenerateSignature($pilot->pilotid);
  264. }
  265.  
  266. echo "Done";
  267.  
  268. LogData::addLog(Auth::$userinfo->pilotid, 'Reset signatures');
  269. }
  270.  
  271. public function resethours()
  272. {
  273. echo '<h3>Updating Total Hours Count</h3>';
  274.  
  275. $total = 0;
  276. echo '<p>Calculating hours for all pilots: <br />';
  277. $allpilots = PilotData::GetAllPilots();
  278.  
  279. foreach($allpilots as $pilot)
  280. {
  281. $hours = PilotData::UpdateFlightHours($pilot->pilotid);
  282. $total = Util::AddTime($total, $hours);
  283. echo PilotData::GetPilotCode($pilot->code, $pilot->pilotid) . " - found {$hours} flight hours for number <br />";
  284. }
  285.  
  286. echo "Pilots have a total of <strong>$total hours</strong><br /><br />";
  287.  
  288. echo "<strong>Now counting from PIREPS</strong><br />";
  289.  
  290. StatsData::UpdateTotalHours();
  291. echo 'Found '.StatsData::TotalHours().' total hours, updated<br /></p>';
  292.  
  293. LogData::addLog(Auth::$userinfo->pilotid, 'Reset hours');
  294. }
  295.  
  296. public function resetpirepfinance()
  297. {
  298. echo '<h3>Reset PIREP Data</h3>
  299. Resetting PIREPs...<br />';
  300.  
  301. //PIREPData::PopulateEmptyPIREPS();
  302.  
  303. echo 'Complete';
  304.  
  305. LogData::addLog(Auth::$userinfo->pilotid, 'Reset PIREP finances');
  306. }
  307.  
  308. public function resetscheduleroute()
  309. {
  310. echo '<h3>Reset cached schedule routes</h3>
  311. Resetting... <br />';
  312.  
  313. SchedulesData::deleteAllScheduleDetails();
  314.  
  315. echo 'Completed!';
  316.  
  317. LogData::addLog(Auth::$userinfo->pilotid, 'Reset cached schedule route details');
  318. }
  319.  
  320. public function resetpireproute()
  321. {
  322. echo '<h3>Reset cached PIREP routes</h3>
  323. Resetting... <br />';
  324.  
  325. PIREPData::deleteAllRouteDetails();
  326.  
  327. echo 'Completed!';
  328.  
  329. LogData::addLog(Auth::$userinfo->pilotid, 'Reset cached pirep route details');
  330. }
  331. /*public function checkPilotGroups()
  332. {
  333. $activeGroup = PilotGroups::getGroupID('Active Pilots');
  334. $inactiveGroup = PilotGroups::getGroupID('Inactive');
  335.  
  336.  
  337. $params = array(
  338. 'retired' => '1',
  339. 'groupid' => $activeGroup
  340. );
  341.  
  342. $sql = 'SELECT p.*,
  343. p.pilotid as pilotid, p.firstname as firstname, p.lastname as lastname, g.groupid as groupid, g.id as id
  344. FROM '.TABLE_PREFIX.'pilots p
  345. LEFT JOIN '.TABLE_PREFIX.'groupmembers g ON g.pilotid = p.pilotid';
  346.  
  347. $sql .= DB::build_where($params);
  348.  
  349. $results = DB::get_results($sql);
  350.  
  351. if($results)
  352. {
  353. foreach($results as $result)
  354. {
  355. PilotGroups::RemoveUserFromGroup($result->pilotid, $activeGroup);
  356. if(!PilotGroups::CheckUserInGroup($result->pilotid, $inactiveGroup)) PilotGroups::AddUsertoGroup($result->pilotid, $inactiveGroup);
  357. echo '<strong>'.$result->firstname.' '.$result->lastname.'</strong> - Removed from Active Group and reassigned to Inactive Group<br/>';
  358. }
  359. }
  360. else
  361. {
  362. echo "No retired pilot in Active Group";
  363. }
  364. echo "<p></p><p></p>";
  365.  
  366. $params = array(
  367. 'retired' => '0',
  368. 'groupid' => $inactiveGroup
  369. );
  370.  
  371. $sql = 'SELECT p.*,
  372. p.pilotid as pilotid, p.firstname as firstname, p.lastname as lastname, g.groupid as groupid, g.id as id
  373. FROM '.TABLE_PREFIX.'pilots p
  374. LEFT JOIN '.TABLE_PREFIX.'groupmembers g ON g.pilotid = p.pilotid';
  375.  
  376. $sql .= DB::build_where($params);
  377.  
  378. $results = DB::get_results($sql);
  379.  
  380. if($results)
  381. {
  382. foreach($results as $result)
  383. {
  384. PilotGroups::RemoveUserFromGroup($result->pilotid, $inactiveGroup);
  385. if(!PilotGroups::CheckUserInGroup($result->pilotid, $activeGroup)) PilotGroups::AddUsertoGroup($result->pilotid, $activeGroup);
  386. echo '<strong>'.$result->firstname.' '.$result->lastname.'</strong> - Removed from Inactive Group and reassigned to Active Group<br/>';
  387. }
  388. }
  389. else
  390. {
  391. echo "No active pilots in Inactive Group";
  392. }
  393. }*/
Advertisement
Add Comment
Please, Sign In to add comment