PageRenderTime 68ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/class.pos.php

http://pos-tracker-temar.googlecode.com/
PHP | 2519 lines | 1633 code | 462 blank | 424 comment | 218 complexity | 0baf8c46ce2ff040f2348a7ab41b43e1 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. * Pos-Tracker2
  4. *
  5. * Starbase Tracking Page, multiple Tower view
  6. *
  7. * PHP version 5
  8. *
  9. * LICENSE: This file is part of POS-Tracker2.
  10. * POS-Tracker2 is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, version 3 of the License.
  13. *
  14. * POS-Tracker2 is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with POS-Tracker2. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @author Stephen Gulickk <stephenmg12@gmail.com>
  23. * @author DeTox MinRohim <eve@onewayweb.com>
  24. * @author Andy Snowden <forumadmin@eve-razor.com>
  25. * @copyright 2007-2008 (C) Stephen Gulick, DeTox MinRohim, and Andy Snowden
  26. * @copyright 2008-2009 (C) Stephen Gulick and DeTox MinRohim
  27. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL 3.0
  28. * @access public
  29. * @package POS-Tracker2
  30. * @version SVN: $Id: class.pos.php 309 2010-03-08 02:55:24Z stephenmg12@gmail.com $
  31. * @link https://sourceforge.net/projects/pos-tracker2/
  32. * @link http://www.eve-online.com/
  33. */
  34. define('INT_SECOND', 1);
  35. define('INT_MINUTE', 60);
  36. define('INT_HOUR', 3600);
  37. define('INT_6HOUR', 21600);
  38. define('INT_DAY', 86400);
  39. define('INT_WEEK', 604800);
  40. include 'includes/pos_val.php';
  41. require_once('includes/TEAC.php');
  42. class POSMGMT extends TEAC
  43. {
  44. /**
  45. * POSMGMT::get_formatted_timediff()
  46. *
  47. * @param mixed $then
  48. * @param bool $now
  49. * @return return $str
  50. */
  51. function get_formatted_timediff($then, $now = false)
  52. {
  53. $now = (!$now) ? time() : $now;
  54. $timediff = ($now - $then);
  55. $weeks = (int) intval($timediff / INT_WEEK);
  56. $timediff = (int) intval($timediff - (INT_WEEK * $weeks));
  57. $days = (int) intval($timediff / INT_DAY);
  58. $timediff = (int) intval($timediff - (INT_DAY * $days));
  59. $hours = (int) intval($timediff / INT_HOUR);
  60. $timediff = (int) intval($timediff - (INT_HOUR * $hours));
  61. $mins = (int) intval($timediff / INT_MINUTE);
  62. $timediff = (int) intval($timediff - (INT_MINUTE * $mins));
  63. $sec = (int) intval($timediff / INT_SECOND);
  64. $timediff = (int) intval($timediff - ($sec * INT_SECOND));
  65. $str = '';
  66. if ( $weeks ) {
  67. $str .= intval($weeks);
  68. $str .= ($weeks > 1) ? ' weeks' : ' week';
  69. }
  70. if ( $days ) {
  71. $str .= ($str) ? ', ' : '';
  72. $str .= intval($days);
  73. $str .= ($days > 1) ? ' days' : ' day';
  74. }
  75. if ( $hours ) {
  76. $str .= ($str) ? ', ' : '';
  77. $str .= intval($hours);
  78. $str .= ($hours > 1) ? ' hours' : ' hour';
  79. }
  80. if ( $mins ) {
  81. $str .= ($str) ? ', ' : '';
  82. $str .= intval($mins);
  83. $str .= ($mins > 1) ? ' minutes' : ' minute';
  84. }
  85. if ( $sec ) {
  86. $str .= ($str) ? ', ' : '';
  87. $str .= intval($sec);
  88. $str .= ($sec > 1) ? ' seconds' : ' second';
  89. }
  90. if ( !$weeks && !$days && !$hours && !$mins && !$sec ) {
  91. $str .= '0 seconds ago';
  92. } else {
  93. $str .= ' ago';
  94. }
  95. return $str;
  96. }
  97. /**
  98. * POSMGMT::GetLastSystemUpdate()
  99. *
  100. * @return $row['updateTime']
  101. */
  102. function GetLastSystemUpdate()
  103. {
  104. $dbconn =& DBGetConn(true);
  105. $sql = "SELECT *
  106. FROM ".TBL_PREFIX."system_status
  107. WHERE SolarSystemID = '30023410'";
  108. $result = $dbconn->Execute($sql);
  109. if ($dbconn->ErrorNo() != 0) {
  110. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  111. return false;
  112. }
  113. $row = $result->GetRowAssoc(2);
  114. $result->Close();
  115. return $row['updateTime'];
  116. }
  117. /**
  118. * POSMGMT::GetLastAllianceUpdate()
  119. *
  120. * @return $row['updateTime']
  121. */
  122. function GetLastAllianceUpdate()
  123. {
  124. $dbconn =& DBGetConn(true);
  125. $sql = "SELECT *
  126. FROM ".TBL_PREFIX."alliance_info
  127. WHERE AllianceID = '0'";
  128. $result = $dbconn->Execute($sql);
  129. if ($dbconn->ErrorNo() != 0) {
  130. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  131. return false;
  132. }
  133. $row = $result->GetRowAssoc(2);
  134. $result->Close();
  135. return $row['updateTime'];
  136. }
  137. /**
  138. * POSMGMT::GetAllianceByName()
  139. *
  140. * @param mixed $allname
  141. * @return
  142. */
  143. function GetAllianceByName($allname)
  144. {
  145. $dbconn =& DBGetConn(true);
  146. $sql = "SELECT *
  147. FROM ".TBL_PREFIX."alliance_info
  148. WHERE name = '".Eve::VarPrepForStore($allname)."'";
  149. $result = $dbconn->Execute($sql);
  150. if ($dbconn->ErrorNo() != 0) {
  151. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  152. return false;
  153. }
  154. $row = $result->GetRowAssoc(2);
  155. $result->Close();
  156. return $row;
  157. }
  158. /**
  159. * POSMGMT::GetLastAPITimer()
  160. *
  161. * @return
  162. */
  163. function GetLastAPITimer()
  164. {
  165. $dbconn =& DBGetConn(true);
  166. $sql = "SELECT *
  167. FROM ".TBL_PREFIX."eveapi
  168. ORDER BY apitimer DESC LIMIT 1";
  169. $result = $dbconn->Execute($sql);
  170. if ($dbconn->ErrorNo() != 0) {
  171. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  172. return false;
  173. }
  174. $row = $result->GetRowAssoc(2);
  175. $result->Close();
  176. return $row['apitimer'];
  177. }
  178. function GetLastHangerAPITimer()
  179. {
  180. $dbconn =& DBGetConn(true);
  181. $sql = "SELECT *
  182. FROM ".TBL_PREFIX."update_log
  183. WHERE type = '5'
  184. ORDER BY datetime DESC LIMIT 1";
  185. $result = $dbconn->Execute($sql);
  186. if ($dbconn->ErrorNo() != 0) {
  187. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  188. return false;
  189. }
  190. $row = $result->GetRowAssoc(2);
  191. $result->Close();
  192. return $row['datetime'];
  193. }
  194. /**
  195. * POSMGMT::GetLastPosUpdate()
  196. *
  197. * @param mixed $pos_id
  198. * @return
  199. */
  200. function GetLastPosUpdate($pos_id)
  201. {
  202. $dbconn =& DBGetConn(true);
  203. $sql = "SELECT *
  204. FROM ".TBL_PREFIX."update_log
  205. WHERE type_id = '" . $pos_id . "'
  206. AND type = '1'
  207. ORDER BY id DESC LIMIT 1";
  208. $result = $dbconn->Execute($sql);
  209. if ($dbconn->ErrorNo() != 0) {
  210. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  211. return false;
  212. }
  213. $row = $result->GetRowAssoc(2);
  214. $result->Close();
  215. return $row;
  216. }
  217. /**
  218. * POSMGMT::GetAllUsers()
  219. *
  220. * @return
  221. */
  222. function GetAllUsers()
  223. {
  224. $dbconn =& DBGetConn(true);
  225. $sql = "SELECT *
  226. FROM ".TBL_PREFIX."user
  227. ORDER BY name";
  228. $result = $dbconn->Execute($sql);
  229. if ($dbconn->ErrorNo() != 0) {
  230. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  231. return false;
  232. }
  233. if ($result->EOF) {
  234. return false;
  235. }
  236. for(; !$result->EOF; $result->MoveNext()) {
  237. $users[] = $result->GetRowAssoc(2);
  238. }
  239. $result->Close();
  240. return $users;
  241. }
  242. /**
  243. * POSMGMT::GetAllUsersArray()
  244. *
  245. * @return
  246. */
  247. function GetAllUsersArray()
  248. {
  249. $dbconn =& DBGetConn(true);
  250. $sql = "SELECT name, eve_id
  251. FROM ".TBL_PREFIX."user
  252. ORDER BY name";
  253. $result = $dbconn->Execute($sql);
  254. if ($dbconn->ErrorNo() != 0) {
  255. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  256. return false;
  257. }
  258. if ($result->EOF) {
  259. return false;
  260. }
  261. for(; !$result->EOF; $result->MoveNext()) {
  262. $users[] = $result->GetRowAssoc(2);
  263. }
  264. foreach($users as $user) {
  265. $user_array[$user['eve_id']]=$user['name'];
  266. }
  267. $result->Close();
  268. return $user_array;
  269. }
  270. /**
  271. * POSMGMT::GetAllUsersWithAccess()
  272. *
  273. * @param mixed $access
  274. * @return
  275. */
  276. function GetAllUsersWithAccess($access)
  277. {
  278. $dbconn =& DBGetConn(true);
  279. $sql = "SELECT *
  280. FROM ".TBL_PREFIX."user
  281. WHERE access = '".Eve::VarPrepForStore($access)."'";
  282. $result = $dbconn->Execute($sql);
  283. if ($dbconn->ErrorNo() != 0) {
  284. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  285. return false;
  286. }
  287. if ($result->EOF) {
  288. return false;
  289. }
  290. for(; !$result->EOF; $result->MoveNext()) {
  291. $users[] = $result->GetRowAssoc(2);
  292. }
  293. $result->Close();
  294. return $users;
  295. }
  296. /**
  297. * POSMGMT::GetUserInfofromID()
  298. *
  299. * @param mixed $characterID
  300. * @return
  301. */
  302. function GetUserInfofromID($characterID)
  303. {
  304. $dbconn =& DBGetConn(true);
  305. $sql = "SELECT *
  306. FROM ".TBL_PREFIX."user
  307. WHERE eve_id = '".Eve::VarPrepForStore($characterID)."'";
  308. $result = $dbconn->Execute($sql);
  309. if ($dbconn->ErrorNo() != 0) {
  310. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  311. return false;
  312. }
  313. $row = $result->GetRowAssoc(2);
  314. $result->Close();
  315. return $row;
  316. }
  317. /**
  318. * POSMGMT::LogUser()
  319. *
  320. * @param mixed $args
  321. * @return
  322. */
  323. function LogUser($args)
  324. {
  325. if (!isset($args['name']) or empty($args['name'])) {
  326. return false;
  327. }
  328. if (!isset($args['pass']) or empty($args['pass'])) {
  329. return false;
  330. }
  331. $dbconn =& DBGetConn(true);
  332. $sql = "SELECT *
  333. FROM ".TBL_PREFIX."user
  334. WHERE name = '" . Eve::VarPrepForStore($args['name']) . "'";
  335. //AND pass = (PASSWORD('" . Eve::VarPrepForStore($args['pass']) . "'))";
  336. $result = $dbconn->Execute($sql);
  337. if ($dbconn->ErrorNo() != 0) {
  338. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  339. return false;
  340. }
  341. if ($result->EOF) {
  342. return false;
  343. }
  344. $userinfo = $result->GetRowAssoc(2);
  345. //echo '<pre>';print_r($userinfo);echo '</pre>';exit;
  346. $result->Close();
  347. $compare = false;
  348. $password = $args['pass'];
  349. $hash = $userinfo['pass'];
  350. $compare = $this->comparePassword($password, $hash); //New Password Hashing method
  351. if ($compare)
  352. {
  353. Eve::SessionSetVar('name', $userinfo['name']);
  354. Eve::SessionSetVar('eve_id', $userinfo['eve_id']);
  355. Eve::SessionSetVar('access', $userinfo['access']);
  356. Eve::SessionSetVar('corp', $userinfo['corp']);
  357. Eve::SessionSetVar('id', $userinfo['id']);
  358. Eve::SessionSetVar('email', $userinfo['email']);
  359. Eve::SessionSetVar('away', $userinfo['away']);
  360. Eve::SessionSetVar('highly_trusted', $userinfo['highly_trusted']);
  361. Eve::SessionSetVar('delsid', $userinfo['delsid']);
  362. Eve::SessionSetVar('allianceID', $userinfo['alliance_id']);
  363. Eve::SessionSetVar('userlogged', true);
  364. if ($args['cookie'])
  365. {
  366. $cookie = hash('md5', $hash.time().mt_rand());
  367. Eve::SessionSetVar('cookie', $cookie);
  368. $result = $dbconn->Execute("UPDATE ".TBL_PREFIX."user SET cookie = '".$cookie."' WHERE name = '".Eve::VarPrepForStore($args['name'])."'");
  369. setcookie('postrackerLoginN', $userinfo['name'], time() + 31104000, NULL, $_SERVER['SERVER_NAME'], false, true);
  370. setcookie('postrackerLoginP', $cookie, time() + 31104000, NULL, $_SERVER['SERVER_NAME'], false, true);
  371. }
  372. return $userinfo;
  373. }
  374. else
  375. {
  376. return false;
  377. }
  378. }
  379. function CookieLogUser($args)
  380. {
  381. if (empty($args['name']))
  382. return false;
  383. if (empty($args['pass']))
  384. return false;
  385. $dbconn =& DBGetConn(true);
  386. $sql = "SELECT *
  387. FROM ".TBL_PREFIX."user
  388. WHERE name = '" . Eve::VarPrepForStore($args['name']) . "'";
  389. //AND pass = (PASSWORD('" . Eve::VarPrepForStore($args['pass']) . "'))";
  390. $result = $dbconn->Execute($sql);
  391. if ($dbconn->ErrorNo() != 0)
  392. {
  393. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  394. return false;
  395. }
  396. if ($result->EOF)
  397. return false;
  398. $userinfo = $result->GetRowAssoc(2);
  399. //echo '<pre>';print_r($userinfo);echo '</pre>';exit;
  400. $result->Close();
  401. $password = $args['pass'];
  402. if ($password = $userinfo['cookie'])
  403. {
  404. Eve::SessionSetVar('name', $userinfo['name']);
  405. Eve::SessionSetVar('eve_id', $userinfo['eve_id']);
  406. Eve::SessionSetVar('access', $userinfo['access']);
  407. Eve::SessionSetVar('corp', $userinfo['corp']);
  408. Eve::SessionSetVar('id', $userinfo['id']);
  409. Eve::SessionSetVar('email', $userinfo['email']);
  410. Eve::SessionSetVar('away', $userinfo['away']);
  411. Eve::SessionSetVar('highly_trusted', $userinfo['highly_trusted']);
  412. Eve::SessionSetVar('delsid', $userinfo['delsid']);
  413. Eve::SessionSetVar('allianceID', $userinfo['alliance_id']);
  414. Eve::SessionSetVar('userlogged', true);
  415. return $userinfo;
  416. }
  417. else
  418. {
  419. return false;
  420. }
  421. }
  422. /**
  423. * POSMGMT::getPasswordSalt()
  424. *
  425. * @return
  426. */
  427. function getPasswordSalt()
  428. {
  429. return substr( str_pad( dechex( mt_rand() ), 8, '0', STR_PAD_LEFT ), -8 );
  430. }
  431. // calculate the hash from a salt and a password
  432. /**
  433. * POSMGMT::getPasswordHash()
  434. *
  435. * @param mixed $salt
  436. * @param mixed $password
  437. * @return
  438. */
  439. function getPasswordHash($salt, $password )
  440. {
  441. //hash requires php version 5.1.2 to work. It also must be enabled, check with your hosting provider on how to enable/install extentions
  442. return (hash('md5', $salt.$password ) );
  443. //return (md5($salt.$password)); //If you have dificulty with hash, you can uncomment this line and comment the line above
  444. }
  445. // compare a password to a hash
  446. /**
  447. * POSMGMT::comparePassword()
  448. *
  449. * @param mixed $password
  450. * @param mixed $dbhash
  451. * @return
  452. */
  453. function comparePassword($password, $dbhash)
  454. {
  455. $password = Eve::VarCleanFromInput('pass');//$_POST['pass'];
  456. $salt = substr($dbhash, 0, 8);
  457. $hash = $this->getPasswordHash($salt, $password);
  458. $shash = $salt.$hash;
  459. if($shash == $dbhash) {
  460. return true;
  461. } else {
  462. return false;
  463. }
  464. }
  465. /**
  466. * POSMGMT::newpasswordhash()
  467. *
  468. * @param mixed $password
  469. * @return
  470. */
  471. function newpasswordhash($password)
  472. {
  473. $salt = $this->getPasswordSalt();
  474. $hash = $this->getPasswordHash($salt, $password);
  475. $dbhash = $salt.$hash;
  476. return $dbhash;
  477. }
  478. /**
  479. * POSMGMT::GetUserInfo()
  480. *
  481. * @return
  482. */
  483. function GetUserInfo()
  484. {
  485. $userlogged = Eve::SessionGetVar('userlogged');
  486. if (!$userlogged) {
  487. return false;
  488. } else {
  489. $userinfo = array('name' => Eve::SessionGetVar('name'),
  490. 'access' => Eve::SessionGetVar('access'),
  491. 'corp' => Eve::SessionGetVar('corp'),
  492. 'id' => Eve::SessionGetVar('id'),
  493. 'eve_id' => Eve::SessionGetVar('eve_id'),
  494. 'email' => Eve::SessionGetVar('email'),
  495. 'away' => Eve::SessionGetVar('away'),
  496. 'highly_trusted' => Eve::SessionGetVar('highly_trusted'),
  497. 'delsid' => Eve::SessionGetVar('delsid'),
  498. 'allianceID' => Eve::SessionGetVar('allianceID'));
  499. }
  500. return $userinfo;
  501. }
  502. function VerifySessionInfo()
  503. {
  504. $userlogged = Eve::SessionGetVar('userlogged');
  505. if (!$userlogged)
  506. return false;
  507. $session = array('name' => Eve::SessionGetVar('name'),
  508. 'access' => Eve::SessionGetVar('access'),
  509. 'corp' => Eve::SessionGetVar('corp'),
  510. 'id' => Eve::SessionGetVar('id'),
  511. 'eve_id' => Eve::SessionGetVar('eve_id'),
  512. 'email' => Eve::SessionGetVar('email'),
  513. 'away' => Eve::SessionGetVar('away'),
  514. 'highly_trusted' => Eve::SessionGetVar('highly_trusted'),
  515. 'delsid' => Eve::SessionGetVar('delsid'),
  516. 'allianceID' => Eve::SessionGetVar('allianceID'));
  517. $dbconn =& DBGetConn(true);
  518. $sql = "SELECT *
  519. FROM ".TBL_PREFIX."user
  520. WHERE name = '" . Eve::VarPrepForStore($session['name']) . "'";
  521. $result = $dbconn->Execute($sql);
  522. if ($dbconn->ErrorNo() != 0) {
  523. $error = TRUE;
  524. }
  525. if ($result->EOF) {
  526. $error = TRUE;
  527. }
  528. $userinfo = $result->GetRowAssoc(2);
  529. //echo '<pre>';print_r($userinfo);echo '</pre>';exit;
  530. $result->Close();
  531. if($error)
  532. {
  533. Eve::SessionDelVar('name');
  534. Eve::SessionDelVar('access');
  535. Eve::SessionDelVar('corp');
  536. Eve::SessionDelVar('id');
  537. Eve::SessionDelVar('eve_id');
  538. Eve::SessionDelVar('email');
  539. Eve::SessionDelVar('away');
  540. Eve::SessionDelVar('highly_trusted');
  541. Eve::SessionDelVar('delsid');
  542. Eve::SessionDelVar('allianceID');
  543. Eve::SessionDelVar('userlogged');
  544. }
  545. else
  546. {
  547. Eve::SessionSetVar('name', $userinfo['name']);
  548. Eve::SessionSetVar('eve_id', $userinfo['eve_id']);
  549. Eve::SessionSetVar('access', $userinfo['access']);
  550. Eve::SessionSetVar('corp', $userinfo['corp']);
  551. Eve::SessionSetVar('id', $userinfo['id']);
  552. Eve::SessionSetVar('email', $userinfo['email']);
  553. Eve::SessionSetVar('away', $userinfo['away']);
  554. Eve::SessionSetVar('highly_trusted', $userinfo['highly_trusted']);
  555. Eve::SessionSetVar('delsid', $userinfo['delsid']);
  556. Eve::SessionSetVar('allianceID', $userinfo['alliance_id']);
  557. Eve::SessionSetVar('userlogged', true);
  558. }
  559. }
  560. /**
  561. * POSMGMT::LogOutUser()
  562. *
  563. * @return
  564. */
  565. function LogOutUser()
  566. {
  567. $userlogged = Eve::SessionGetVar('userlogged');
  568. if (!$userlogged) {
  569. return true;
  570. } else {
  571. Eve::SessionDelVar('name');
  572. Eve::SessionDelVar('access');
  573. Eve::SessionDelVar('corp');
  574. Eve::SessionDelVar('id');
  575. Eve::SessionDelVar('eve_id');
  576. Eve::SessionDelVar('email');
  577. Eve::SessionDelVar('away');
  578. Eve::SessionDelVar('highly_trusted');
  579. Eve::SessionDelVar('delsid');
  580. Eve::SessionDelVar('allianceID');
  581. Eve::SessionDelVar('userlogged');
  582. }
  583. return true;
  584. }
  585. /**
  586. * POSMGMT::UpdateUserAway()
  587. *
  588. * @param mixed $args
  589. * @return
  590. */
  591. function UpdateUserAway($args)
  592. {
  593. if (!isset($args['id'])) {
  594. Eve::SessionSetVar('errormsg', 'No ID!');
  595. return false;
  596. }
  597. if (!isset($args['newaway'])) {
  598. Eve::SessionSetVar('errormsg', 'No Away Status!');
  599. return false;
  600. }
  601. $dbconn =& DBGetConn(true);
  602. $sql = "UPDATE ".TBL_PREFIX."user
  603. SET away = '".Eve::VarPrepForStore($args['newaway'])."'
  604. WHERE id = '".Eve::VarPrepForStore($args['id'])."'";
  605. $dbconn->Execute($sql);
  606. if ($dbconn->ErrorNo() != 0) {
  607. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  608. return false;
  609. }
  610. Eve::SessionSetVar('away', $newaway);
  611. return true;
  612. }
  613. /**
  614. * POSMGMT::UpdateUserMail()
  615. *
  616. * @param mixed $args
  617. * @return
  618. */
  619. function UpdateUserMail($args)
  620. {
  621. if (!isset($args['id'])) {
  622. Eve::SessionSetVar('errormsg', 'No ID!');
  623. return false;
  624. }
  625. if (!isset($args['newmail'])) {
  626. Eve::SessionSetVar('errormsg', 'No Mail!');
  627. return false;
  628. }
  629. $dbconn =& DBGetConn(true);
  630. $sql = "UPDATE ".TBL_PREFIX."user
  631. SET email = '".Eve::VarPrepForStore($args['newmail'])."'
  632. WHERE id = '".Eve::VarPrepForStore($args['id'])."'";
  633. $dbconn->Execute($sql);
  634. if ($dbconn->ErrorNo() != 0) {
  635. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  636. return false;
  637. }
  638. Eve::SessionSetVar('email', $newmail);
  639. return true;
  640. }
  641. /**
  642. * POSMGMT::UpdateUserPass()
  643. *
  644. * @param mixed $args
  645. * @return
  646. */
  647. function UpdateUserPass($args)
  648. {
  649. if (!isset($args['id'])) {
  650. Eve::SessionSetVar('errormsg', 'No ID!');
  651. return false;
  652. }
  653. if (!isset($args['newpass'])) {
  654. Eve::SessionSetVar('errormsg', 'No Mail!');
  655. return false;
  656. }
  657. $dbconn =& DBGetConn(true);
  658. $sql = "UPDATE ".TBL_PREFIX."user
  659. SET pass = '".Eve::VarPrepForStore($this->newpasswordhash($args['newpass']))."'
  660. WHERE id = '".Eve::VarPrepForStore($args['id'])."'";
  661. $dbconn->Execute($sql);
  662. if ($dbconn->ErrorNo() != 0) {
  663. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  664. return false;
  665. }
  666. Eve::SessionSetVar('email', $newmail);
  667. return true;
  668. }
  669. /**
  670. * POSMGMT::UpdateUserInfo()
  671. *
  672. * @param mixed $args
  673. * @return
  674. */
  675. function UpdateUserInfo($args)
  676. {
  677. if (!isset($args['id'])) {
  678. Eve::SessionSetVar('errormsg', 'No ID!');
  679. return false;
  680. }
  681. $alliance = $this->GetAllianceByName($args['useralliance']);
  682. $dbconn =& DBGetConn(true);
  683. $sql = "UPDATE ".TBL_PREFIX."user
  684. SET corp = '".Eve::VarPrepForStore($args['usercorp'])."',
  685. alliance_id = '".Eve::VarPrepForStore($alliance['allianceID'])."',
  686. datetime = '".Eve::VarPrepForStore(time())."'
  687. WHERE id = '".Eve::VarPrepForStore($args['id'])."'";
  688. $dbconn->Execute($sql);
  689. if ($dbconn->ErrorNo() != 0) {
  690. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  691. return false;
  692. }
  693. Eve::SessionSetVar('corp', $args['usercorp']);
  694. Eve::SessionSetVar('allianceID', $alliance['allianceID']);
  695. return true;
  696. }
  697. /**
  698. * POSMGMT::UpdateUserAccess()
  699. *
  700. * @param mixed $args
  701. * @return
  702. */
  703. function UpdateUserAccess($args)
  704. {
  705. if (!isset($args['id'])) {
  706. Eve::SessionSetVar('errormsg', 'No ID!');
  707. return false;
  708. }
  709. $dbconn =& DBGetConn(true);
  710. $sql = "UPDATE ".TBL_PREFIX."user
  711. SET access = '".Eve::VarPrepForStore($args['access'])."',
  712. highly_trusted = '".Eve::VarPrepForStore($args['highly_trusted'])."'
  713. WHERE id = '".Eve::VarPrepForStore($args['id'])."'";
  714. $dbconn->Execute($sql);
  715. if ($dbconn->ErrorNo() != 0) {
  716. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  717. return false;
  718. }
  719. return true;
  720. }
  721. /**
  722. * POSMGMT::DeleteUser()
  723. *
  724. * @param mixed $id
  725. * @return
  726. */
  727. function DeleteUser($id)
  728. {
  729. if (!$id) {
  730. Eve::SessionSetVar('errormsg', 'No ID!');
  731. return false;
  732. }
  733. $dbconn =& DBGetConn(true);
  734. $sql = "DELETE FROM ".TBL_PREFIX."user
  735. WHERE id = '".Eve::VarPrepForStore($id)."'";
  736. $dbconn->Execute($sql);
  737. if ($dbconn->ErrorNo() != 0) {
  738. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  739. return false;
  740. }
  741. return true;
  742. }
  743. /**
  744. * POSMGMT::DeletePOS()
  745. *
  746. * @param mixed $pos_id
  747. * @return
  748. */
  749. function DeletePOS($pos_id)
  750. {
  751. if (!$pos_id) {
  752. Eve::SessionSetVar('errormsg', 'No ID!');
  753. return false;
  754. }
  755. $dbconn =& DBGetConn(true);
  756. $sql = "DELETE FROM ".TBL_PREFIX."tower_info
  757. WHERE pos_id = '".Eve::VarPrepForStore($pos_id)."'";
  758. $dbconn->Execute($sql);
  759. if ($dbconn->ErrorNo() != 0) {
  760. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  761. return false;
  762. }
  763. $sql = "DELETE FROM ".TBL_PREFIX."pos_hanger
  764. WHERE pos_id = '".Eve::VarPrepForStore($pos_id)."'";
  765. $dbconn->Execute($sql);
  766. if ($dbconn->ErrorNo() != 0) {
  767. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  768. return false;
  769. }
  770. $sql = "DELETE FROM ".TBL_PREFIX."pos_structures
  771. WHERE pos_id = '".Eve::VarPrepForStore($pos_id)."'";
  772. $dbconn->Execute($sql);
  773. if ($dbconn->ErrorNo() != 0) {
  774. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  775. return false;
  776. }
  777. $sql = "DELETE FROM ".TBL_PREFIX."reactor_info
  778. WHERE pos_id = '".Eve::VarPrepForStore($pos_id)."'";
  779. $dbconn->Execute($sql);
  780. if ($dbconn->ErrorNo() != 0) {
  781. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  782. return false;
  783. }
  784. $sql = "DELETE FROM ".TBL_PREFIX."silo_info
  785. WHERE pos_id = '".Eve::VarPrepForStore($pos_id)."'";
  786. $dbconn->Execute($sql);
  787. if ($dbconn->ErrorNo() != 0) {
  788. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  789. return false;
  790. }
  791. $time = time();
  792. $sql = "INSERT INTO ".TBL_PREFIX."update_log (
  793. eve_id,
  794. type_id,
  795. type,
  796. action,
  797. datetime)
  798. VALUES ('0',
  799. '" . Eve::VarPrepForStore($pos_id) . "',
  800. '1',
  801. 'Delete POS',
  802. '" . Eve::VarPrepForStore($time) . "')";
  803. $dbconn->Execute($sql);
  804. if ($dbconn->ErrorNo() != 0) {
  805. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  806. return false;
  807. }
  808. return true;
  809. }
  810. /**
  811. * POSMGMT::GetAllPos2()
  812. *
  813. * @param mixed $args
  814. * @return
  815. */
  816. function GetAllPos2($args)
  817. {
  818. $userinfo = $this->GetUserInfo();
  819. if (!$userinfo) {
  820. Eve::SessionSetVar('errormsg', 'User Not Logged!');
  821. return false;
  822. }
  823. //$limit = false;
  824. if (isset($args['limit']) && is_numeric($args['limit'])) {
  825. $limit = $args['limit'];
  826. $startnum = ((isset($args['startnum'])) ? $args['startnum'] : 0);
  827. $page = ((isset($args['page'])) ? $args['page'] : 1);
  828. $startnum = ($page * $limit) - $limit;
  829. }
  830. //Sorting Code
  831. $orderby='';
  832. if(isset($args['scolumn'])) {
  833. switch($args['scolumn']) {
  834. case 1:
  835. default:
  836. $orderby="ORDER BY MoonName";
  837. $orderstatus=true;
  838. break;
  839. case 2:
  840. $orderby="ORDER BY MoonName";
  841. break;
  842. case 3:
  843. $orderby="ORDER BY region";
  844. break;
  845. case 4:
  846. $orderby="ORDER BY towerName";
  847. break;
  848. case 5:
  849. $orderby="ORDER BY typeID"; //Need to come up with a way to be alphabetically
  850. break;
  851. case 6:
  852. $orderby="ORDER BY u1.name";
  853. break;
  854. case 7:
  855. $orderby="ORDER BY backup";
  856. break;
  857. case 8:
  858. $orderby="ORDER BY outpost_id";
  859. break;
  860. case 9:
  861. $orderby="ORDER BY pos_size, typeID";
  862. break;
  863. case 10:
  864. $orderby="ORDER BY pos_race, pos_size";
  865. break;
  866. case 11:
  867. $orderby="ORDER BY corp";
  868. break;
  869. }
  870. } else {
  871. $orderby="ORDER BY MoonName";
  872. $orderstatus=true;
  873. }
  874. switch($userinfo['access']) {
  875. case 0:
  876. default:
  877. // This should never happen anyways, so we're going to make sure it won't.
  878. $where = "WHERE 0=1";
  879. break;
  880. case 1:
  881. // Access Level 1 = Show Towers User is Fuel Tech
  882. $where = "WHERE ".TBL_PREFIX."tower_info.owner_id = ".$userinfo['eve_id']."
  883. OR ".TBL_PREFIX."tower_info.secondary_owner_id = ".$userinfo['eve_id'];
  884. break;
  885. case 2:
  886. // Access Level 2 = Show Towers User is Fuel Tech or Same Corp but no Fuel Tech yet.
  887. $where = "WHERE ".TBL_PREFIX."tower_info.owner_id = ".$userinfo['eve_id']."
  888. OR ".TBL_PREFIX."tower_info.secondary_owner_id = ".$userinfo['eve_id']."
  889. OR ( ".TBL_PREFIX."tower_info.owner_id = 0
  890. AND ".TBL_PREFIX."tower_info.corp = '".$userinfo['corp']."' )";
  891. break;
  892. case 3:
  893. case 4:
  894. case 5:
  895. // Access Level 3 or Higher Show everything.
  896. $where = "WHERE 1=1";
  897. break;
  898. }
  899. $dbconn =& DBGetConn(true);
  900. $sql = "SELECT ".TBL_PREFIX."tower_info.*,
  901. u1.name,
  902. u1.corp as ucorp,
  903. u2.name AS 'backup',
  904. ".TBL_PREFIX."evemoons.moonName AS 'MoonName',
  905. mr.regionName AS 'region',
  906. ms.solarSystemName AS 'system'
  907. FROM ".TBL_PREFIX."tower_info
  908. LEFT JOIN ".TBL_PREFIX."user u1 ON ".TBL_PREFIX."tower_info.owner_id = u1.eve_id
  909. LEFT JOIN ".TBL_PREFIX."user u2 ON ".TBL_PREFIX."tower_info.secondary_owner_id = u2.eve_id
  910. LEFT JOIN ".TBL_PREFIX."evemoons ON ".TBL_PREFIX."tower_info.moonID = ".TBL_PREFIX."evemoons.moonID
  911. LEFT JOIN ".TBL_PREFIX."mapregions mr ON ".TBL_PREFIX."evemoons.regionID = mr.regionID
  912. LEFT JOIN ".TBL_PREFIX."mapsolarsystems ms ON ".TBL_PREFIX."tower_info.systemID = ms.solarSystemID
  913. ".$where."
  914. ".$orderby;
  915. //$result = $dbconn->SelectLimit($sql, $limit, $startnum);
  916. $result = $dbconn->Execute($sql);
  917. if ($dbconn->ErrorNo() != 0) {
  918. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  919. return false;
  920. }
  921. for (; !$result->EOF; $result->MoveNext()) {
  922. $rows[] = $result->GetRowAssoc(2);
  923. }
  924. $result->Close();
  925. foreach($rows as $key => $row) {
  926. $row2 = $this->GetLastPosUpdate($row['pos_id']);
  927. $row['result_uptimecalc'] = $this->uptimecalc($row['pos_id']);
  928. $row['result_online'] = $this->online($row['result_uptimecalc']);
  929. $row['last_update'] = gmdate("Y-m-d H:i:s", $row2['datetime']);
  930. $row['online'] = $this->daycalc($row['result_online']);
  931. //$row['region'] = $this->getRegionNameFromMoonID($row['MoonName']);
  932. //$row['system'] = $this->getSystemName($row['systemID']);
  933. $sortAarr[] = $row['result_online'];
  934. $rows[$key] = $row;
  935. }
  936. if(isset($orderstatus)) {
  937. array_multisort($sortAarr, SORT_ASC, $rows);
  938. }
  939. if($limit) {
  940. $rows=array_slice($rows, $startnum, $limit);
  941. }
  942. return $rows;
  943. }
  944. /**
  945. * POSMGMT::GetAllPos2Count()
  946. *
  947. * @return
  948. */
  949. function GetAllPos2Count()
  950. {
  951. $userinfo = $this->GetUserInfo();
  952. if (!$userinfo) {
  953. Eve::SessionSetVar('errormsg', 'User Not Logged!');
  954. return false;
  955. }
  956. switch($userinfo['access']) {
  957. case 0:
  958. default:
  959. // This should never happen anyways, so we're going to make sure it won't.
  960. $where = "WHERE 0=1";
  961. break;
  962. case 1:
  963. // Access Level 1 = Show Towers User is Fuel Tech
  964. $where = "WHERE ".TBL_PREFIX."tower_info.owner_id = ".$userinfo['eve_id']."
  965. OR ".TBL_PREFIX."tower_info.secondary_owner_id = ".$userinfo['eve_id'];
  966. break;
  967. case 2:
  968. // Access Level 2 = Show Towers User is Fuel Tech or Same Corp but no Fuel Tech yet.
  969. $where = "WHERE ".TBL_PREFIX."tower_info.owner_id = ".$userinfo['eve_id']."
  970. OR ".TBL_PREFIX."tower_info.secondary_owner_id = ".$userinfo['eve_id']."
  971. OR ( ".TBL_PREFIX."tower_info.owner_id = 0
  972. AND ".TBL_PREFIX."tower_info.corp = '".$userinfo['corp']."' )";
  973. break;
  974. case 3:
  975. case 4:
  976. case 5:
  977. // Access Level 3 or Higher Show everything.
  978. $where = "WHERE 1=1";
  979. break;
  980. }
  981. $dbconn =& DBGetConn(true);
  982. $sql = "SELECT ".TBL_PREFIX."tower_info.*,
  983. (SELECT ".TBL_PREFIX."user.name
  984. FROM ".TBL_PREFIX."user
  985. WHERE ".TBL_PREFIX."tower_info.secondary_owner_id = ".TBL_PREFIX."user.eve_id ) AS 'backup',
  986. (SELECT ".TBL_PREFIX."evemoons.moonName
  987. FROM ".TBL_PREFIX."evemoons
  988. WHERE ".TBL_PREFIX."tower_info.moonID = ".TBL_PREFIX."evemoons.moonID) AS 'MoonName'
  989. FROM ".TBL_PREFIX."tower_info
  990. ".$where."
  991. ORDER BY MoonName";
  992. $result = $dbconn->Execute($sql);
  993. $resultcount = $result->_numOfRows;
  994. $result->Close();
  995. return $resultcount;
  996. }
  997. /**
  998. * POSMGMT::GetAllPoses()
  999. *
  1000. * @return
  1001. */
  1002. function GetAllPoses()
  1003. {
  1004. $userinfo = GetUserInfo();
  1005. if (!$userinfo) {
  1006. Eve::SessionSetVar('errormsg', 'User Not Logged!');
  1007. return false;
  1008. }
  1009. $dbconn =& DBGetConn(true);
  1010. $where_statement = "WHERE user.corp = '" . $userinfo['corp'] . "' AND pos_info.secret_pos = 0" ;
  1011. if (($userinfo['access'] >= "1") && ($userinfo['highly_trusted'] == 1)) {
  1012. $where_statement2 = "WHERE user.corp = '" . $userinfo['corp'] . "'";
  1013. }
  1014. if (($userinfo['access'] >= "3") && ($userinfo['highly_trusted'] == 1)) {
  1015. $where_statement2 = "";
  1016. }
  1017. if (($userinfo['access'] >= "3") && ($userinfo['highly_trusted'] != 1)) {
  1018. $where_statement2 = "WHERE ".TBL_PREFIX."tower_info.secret_pos = 0";
  1019. }
  1020. //Update pos timers
  1021. $sql = "SELECT ".TBL_PREFIX."tower_info.*,
  1022. ".TBL_PREFIX."user.name,
  1023. ".TBL_PREFIX."user.corp,
  1024. (SELECT ".TBL_PREFIX."user.name
  1025. FROM ".TBL_PREFIX."user
  1026. WHERE ".TBL_PREFIX."tower_info.secondary_owner_id = ".TBL_PREFIX."user.eve_id ) AS 'backup',
  1027. (SELECT ".TBL_PREFIX."evemoons.moonName
  1028. FROM ".TBL_PREFIX."evemoons
  1029. WHERE ".TBL_PREFIX."tower_info.moonID = ".TBL_PREFIX."evemoons.moonID) AS 'MoonName'
  1030. FROM ".TBL_PREFIX."tower_info
  1031. LEFT JOIN ".TBL_PREFIX."user ON ".TBL_PREFIX."tower_info.owner_id = ".TBL_PREFIX."user.eve_id " . $where_statement . "
  1032. ORDER BY MoonName";
  1033. $result = $dbconn->Execute($sql);
  1034. if ($dbconn->ErrorNo() != 0) {
  1035. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  1036. return false;
  1037. }
  1038. for (; !$result->EOF; $result->MoveNext()) {
  1039. $row = $result->GetRowAssoc(2);
  1040. $result_uptimecalc = $this->uptimecalc($row['pos_id']);
  1041. $result_online = $this->online($result_uptimecalc, $row['pos_id']);
  1042. $id = $row['pos_id'];
  1043. $this->UpdatePosStatus($id, $result_online);
  1044. }
  1045. $result->Close();
  1046. $sql = "SELECT pos_info.*,
  1047. user.name,
  1048. user.corp ,
  1049. (SELECT user.name
  1050. FROM user
  1051. WHERE pos_info.secondary_owner_id = user.eve_id) AS 'backup'
  1052. FROM pos_info
  1053. LEFT JOIN user ON pos_info.owner_id=user.eve_id " . $where_statement2 . "
  1054. ORDER BY pos_info.status, pos_info.system ASC";
  1055. $result = $dbconn->Execute($sql);
  1056. if ($dbconn->ErrorNo() != 0) {
  1057. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  1058. return false;
  1059. }
  1060. $rows = array();
  1061. for (; !$result->EOF; $result->MoveNext()) {
  1062. $rows[] = $result->GetRowAssoc(2);
  1063. }
  1064. $result->Close();
  1065. return $rows;
  1066. }
  1067. /**
  1068. * POSMGMT::posoptimaluptime()
  1069. *
  1070. * @param mixed $tower
  1071. * @return
  1072. */
  1073. function posoptimaluptime($tower)
  1074. {
  1075. //Setup
  1076. $required_isotope = $tower['required_isotope'];
  1077. $required_oxygen = $tower['required_oxygen'];
  1078. $required_mechanical_parts = $tower['required_mechanical_parts'];
  1079. $required_coolant = $tower['required_coolant'];
  1080. $required_robotics = $tower['required_robotics'];
  1081. $required_uranium = $tower['required_uranium'];
  1082. $required_ozone = $tower['required_ozone'];
  1083. $required_heavy_water = $tower['required_heavy_water'];
  1084. $required_strontium = $tower['required_strontium'];
  1085. $required_charters = $charters_needed?1:0;
  1086. $race_isotope = $result['race_isotope'];
  1087. $total_pg = $tower['total_pg'];
  1088. $total_cpu = $tower['total_cpu'];
  1089. $current_pg = $tower['current_pg'];
  1090. $current_cpu = $tower['current_cpu'];
  1091. //$tower['uptimecalc'] = $posmgmt->uptimecalc($pos_id);
  1092. $strontium_capacity = $tower['strontium_capacity'];
  1093. $pos_capacity = $tower['fuel_hangar'];
  1094. $tower['pos_capacity'] = $pos_capacity;
  1095. //Calculate Optimal cycles
  1096. $volume_per_cycle = 0;
  1097. $volume_per_cycle += ($required_uranium * $GLOBALS["pos_Ura"]);
  1098. $volume_per_cycle += ($required_oxygen * $GLOBALS["pos_Oxy"]);
  1099. $volume_per_cycle += ($required_mechanical_parts * $GLOBALS["pos_Mec"]);
  1100. $volume_per_cycle += ($required_coolant * $GLOBALS["pos_Coo"]);
  1101. $volume_per_cycle += ($required_robotics * $GLOBALS["pos_Rob"]);
  1102. $volume_per_cycle += ($required_isotope * $GLOBALS["pos_Iso"]);
  1103. $volume_per_cycle += ceil(($current_pg / $total_pg) * $required_ozone) * $GLOBALS["pos_Ozo"];
  1104. $volume_per_cycle += ceil(($current_cpu / $total_cpu) * $required_heavy_water) * $GLOBALS["pos_Hea"];
  1105. $volume_per_cycle += ($required_charters * $GLOBALS["pos_Cha"]);
  1106. $optimum_cycles = floor(($pos_capacity)/$volume_per_cycle);
  1107. /*
  1108. echo $pos_capacity;
  1109. echo "<br>";
  1110. echo $volume_per_cycle;
  1111. exit;*/
  1112. //var_dump($tower);
  1113. //calculate optimal (done!, do not touch)
  1114. $optimal['optimum_cycles']=$optimum_cycles;
  1115. $optimal['optimal_strontium_cycles'] = $optimal_strontium_cycles = floor($strontium_capacity/($required_strontium*3));
  1116. $optimal['optimum_uranium'] = $required_uranium * $optimum_cycles;
  1117. $optimal['optimum_oxygen'] = $required_oxygen * $optimum_cycles;
  1118. $optimal['optimum_mechanical_parts'] = $required_mechanical_parts * $optimum_cycles;
  1119. $optimal['optimum_coolant'] = $required_coolant * $optimum_cycles;
  1120. $optimal['optimum_robotics'] = $required_robotics * $optimum_cycles;
  1121. $optimal['optimum_isotope'] = $required_isotope * $optimum_cycles;
  1122. $optimal['optimum_ozone'] = ceil(($current_pg / $total_pg) * $required_ozone) * $optimum_cycles;
  1123. $optimal['optimum_heavy_water'] = ceil(($current_cpu / $total_cpu) * $required_heavy_water) * $optimum_cycles;
  1124. $optimal['optimum_charters'] = $required_charters * $optimum_cycles;
  1125. $optimal['optimum_strontium'] = $required_strontium * $optimal_strontium_cycles;
  1126. return $optimal;
  1127. }
  1128. /**
  1129. * POSMGMT::getOptimalDifference()
  1130. * @param array $optimal
  1131. * @param array $tower
  1132. * @return array $diff
  1133. */
  1134. function getOptimalDifference($optimal, $tower)
  1135. {
  1136. //Diff clear
  1137. $diff=array();
  1138. //Calculate the difference between whats in the tower and optimal
  1139. $diff['uranium']=$optimal['optimum_uranium']-$tower['uranium'];
  1140. $diff['isotopes']=$optimal['optimum_isotope']-$tower['isotope'];
  1141. $diff['oxygen']=$optimal['optimum_oxygen']-$tower['oxygen'];
  1142. $diff['mechanical_parts']=$optimal['optimum_mechanical_parts']-$tower['mechanical_parts'];
  1143. $diff['coolant']=$optimal['optimum_coolant']-$tower['coolant'];
  1144. $diff['robotics']=$optimal['optimum_robotics']-$tower['robotics'];
  1145. $diff['charters']=$optimal['optimum_charters']-$tower['charters'];
  1146. $diff['ozone']=$optimal['optimum_ozone']-$tower['ozone'];
  1147. $diff['heavy_water']=$optimal['optimum_heavy_water']-$tower['heavy_water'];
  1148. $diff['strontium']=$optimal['optimum_strontium']-$tower['strontium'];
  1149. //calculate optimal difference in m3
  1150. $diff['uranium_m3']=$diff['uranium']*$GLOBALS["pos_Ura"];
  1151. $diff['isotopes_m3']=$diff['isotopes']*$GLOBALS["pos_Iso"];
  1152. $diff['oxygen_m3']=$diff['oxygen']*$GLOBALS["pos_Oxy"];
  1153. $diff['mechanical_parts_m3']=$diff['mechanical_parts']*$GLOBALS["pos_Mec"];
  1154. $diff['coolant_m3']=$diff['coolant']*$GLOBALS["pos_Coo"];
  1155. $diff['robotics_m3']=$diff['robotics']*$GLOBALS["pos_Rob"];
  1156. $diff['charters_m3']=$diff['charters']*$GLOBALS["pos_Cha"];
  1157. $diff['ozone_m3']=$diff['ozone']*$GLOBALS["pos_Ozo"];
  1158. $diff['heavy_water_m3']=$diff['heavy_water']*$GLOBALS["pos_Hea"];
  1159. $diff['strontium_m3']=$diff['strontium']*$GLOBALS["pos_Str"];
  1160. if ($diff['uranium_m3']>= 1)
  1161. {
  1162. $diff['totalDiff']=$diff['totalDiff']+$diff['uranium_m3'];
  1163. }
  1164. if ($diff['isotopes_m3']>= 1)
  1165. {
  1166. $diff['totalDiff']=$diff['totalDiff']+$diff['isotopes_m3'];
  1167. }
  1168. if ($diff['oxygen_m3']>= 1)
  1169. {
  1170. $diff['totalDiff']=$diff['totalDiff']+$diff['oxygen_m3'];
  1171. }
  1172. if ($diff['mechanical_parts_m3']>= 1)
  1173. {
  1174. $diff['totalDiff']=$diff['totalDiff']+$diff['mechanical_parts_m3'];
  1175. }
  1176. if ($diff['coolant_m3']>= 1)
  1177. {
  1178. $diff['totalDiff']=$diff['totalDiff']+$diff['coolant_m3'];
  1179. }
  1180. if ($diff['robotics_m3']>= 1)
  1181. {
  1182. $diff['totalDiff']=$diff['totalDiff']+$diff['robotics_m3'];
  1183. }
  1184. if ($diff['charters_m3']>= 1)
  1185. {
  1186. $diff['totalDiff']=$diff['totalDiff']+$diff['charters_m3'];
  1187. }
  1188. if ($diff['ozone_m3']>= 1)
  1189. {
  1190. $diff['totalDiff']=$diff['totalDiff']+$diff['ozone_m3'];
  1191. }
  1192. if ($diff['heavy_water_m3']>= 1)
  1193. {
  1194. $diff['totalDiff']=$diff['totalDiff']+$diff['heavy_water_m3'];
  1195. }
  1196. return $diff;
  1197. }
  1198. /**
  1199. * POSMGMT::getConstellationNameFromMoonID()
  1200. *
  1201. * @param mixed $moon
  1202. * @return
  1203. */
  1204. function getConstellationNameFromMoonID($moon)
  1205. {
  1206. $dbconn =& DBGetConn(true);
  1207. $sql = "SELECT ".TBL_PREFIX."mapconstellations.constellationName,
  1208. moonName
  1209. FROM ".TBL_PREFIX."mapconstellations,
  1210. ".TBL_PREFIX."mapsolarsystems,
  1211. ".TBL_PREFIX."evemoons
  1212. WHERE ".TBL_PREFIX."evemoons.moonName = '".Eve::VarPrepForStore($moon)."'
  1213. AND ".TBL_PREFIX."evemoons.systemID = ".TBL_PREFIX."mapsolarsystems.SolarSystemID
  1214. AND ".TBL_PREFIX."mapsolarsystems.constellationID = ".TBL_PREFIX."mapconstellations.constellationID";
  1215. $result = $dbconn->Execute($sql);
  1216. if ($dbconn->ErrorNo() != 0) {
  1217. Eve::SessionSetVar('errormsg', 'Could not select from getConstellationNameFromMoonID ' . $dbconn->ErrorMsg() . $sql);
  1218. return false;
  1219. }
  1220. $row = $result->GetRowAssoc(2);
  1221. $result->Close();
  1222. //echo '<pre>';print_r($rows);echo '</pre>';exit;
  1223. return $row['constellationName'];
  1224. }
  1225. /**
  1226. * POSMGMT::getRegionNameFromMoonID()
  1227. *
  1228. * @param mixed $moon
  1229. * @return
  1230. */
  1231. function getRegionNameFromMoonID($moon)
  1232. {
  1233. $dbconn =& DBGetConn(true);
  1234. $sql = "SELECT ".TBL_PREFIX."mapregions.regionName,
  1235. moonName
  1236. FROM ".TBL_PREFIX."mapregions,
  1237. ".TBL_PREFIX."evemoons
  1238. WHERE ".TBL_PREFIX."evemoons.moonName = '".Eve::VarPrepForStore($moon)."'
  1239. AND ".TBL_PREFIX."evemoons.regionID = ".TBL_PREFIX."mapregions.regionID";
  1240. $result = $dbconn->Execute($sql);
  1241. if ($dbconn->ErrorNo() != 0) {
  1242. Eve::SessionSetVar('errormsg', 'Could not select from getRegionNameFromMoonID ' . $dbconn->ErrorMsg() . $sql);
  1243. return false;
  1244. }
  1245. $row = $result->GetRowAssoc(2);
  1246. $result->Close();
  1247. //echo '<pre>';print_r($rows);echo '</pre>';exit;
  1248. return $row['regionName'];
  1249. }
  1250. /**
  1251. * POSMGMT::getMoonNameFromMoonID()
  1252. *
  1253. * @param mixed $moonID
  1254. * @return
  1255. */
  1256. function getMoonNameFromMoonID($moonID)
  1257. {
  1258. $dbconn =& DBGetConn(true);
  1259. $sql = "SELECT `moonName` FROM `".TBL_PREFIX."evemoons` WHERE `moonID`=".Eve::VarPrepForStore($moonID)." LIMIT 0, 30 ";
  1260. $result = $dbconn->Execute($sql);
  1261. if ($dbconn->ErrorNo() != 0) {
  1262. Eve::SessionSetVar('errormsg', 'Could not select from getMoonNameFromMoonID ' . $dbconn->ErrorMsg() . $sql);
  1263. return false;
  1264. }
  1265. $row = $result->GetRowAssoc(2);
  1266. $result->Close();
  1267. //echo '<pre>';print_r($rows);echo '</pre>';exit;
  1268. return $row['moonName'];
  1269. }
  1270. /**
  1271. * POSMGMT::GetAllTowers()
  1272. *
  1273. * @param mixed $args
  1274. * @return
  1275. */
  1276. function GetAllTowers($args)
  1277. {
  1278. $dbconn =& DBGetConn(true);
  1279. $where = "";
  1280. $where2 = "";
  1281. if (isset($args['ownerID'])) {
  1282. $where2 = " AND (".TBL_PREFIX."tower_info.owner_id = '".$args['ownerID']."' OR ".TBL_PREFIX."tower_info.secondary_owner_id = '".$args['ownerID']."') ";
  1283. }
  1284. if (isset($args['corp'])) {
  1285. $where2 .= " AND corp = '".$args['corp']."' ";
  1286. }
  1287. if (isset($args['pos_ids']))
  1288. {
  1289. $where = "WHERE ".TBL_PREFIX."tower_info.pos_id IN ('".implode('\',\'', $args['pos_ids'])."') ";
  1290. $sql = "SELECT * FROM `".TBL_PREFIX."tower_info` ".$where . $where2;
  1291. }
  1292. elseif (isset($args['systemID']))
  1293. {
  1294. $where = "WHERE ".TBL_PREFIX."tower_info.systemID = '".$args['systemID']."' ";
  1295. $sql = "SELECT * FROM `".TBL_PREFIX."tower_info` ".$where . $where2;
  1296. }
  1297. elseif (isset($args['constellationID']))
  1298. {
  1299. $sql = "SELECT pos_id,
  1300. typeID,
  1301. evetowerID,
  1302. outpost_id,
  1303. corp,
  1304. allianceid,
  1305. pos_size,
  1306. pos_race,
  1307. isotope,
  1308. oxygen,
  1309. mechanical_parts,
  1310. coolant,
  1311. robotics,
  1312. uranium,
  1313. ozone,
  1314. heavy_water,
  1315. charters,
  1316. strontium,
  1317. towerName,
  1318. systemID,
  1319. charters_needed,
  1320. status,
  1321. owner_id,
  1322. secondary_owner_id,
  1323. pos_status,
  1324. pos_comment,
  1325. secret_pos,
  1326. moonID,
  1327. ".TBL_PREFIX."mapconstellations.constellationID as constellationID,
  1328. ".TBL_PREFIX."mapconstellations.constellationName as constellationName
  1329. FROM ".TBL_PREFIX."tower_info,
  1330. ".TBL_PREFIX."mapsolarsystems,
  1331. ".TBL_PREFIX."mapconstellations
  1332. WHERE ".TBL_PREFIX."tower_info.systemID = ".TBL_PREFIX."mapsolarsystems.solarSystemID
  1333. AND ".TBL_PREFIX."mapsolarsystems.constellationID = ".TBL_PREFIX."mapconstellations.constellationID
  1334. AND ".TBL_PREFIX."mapsolarsystems.constellationID = '".$args['constellationID']."'" . $where2;
  1335. }
  1336. elseif (isset($args['regionID']))
  1337. {
  1338. $sql = "SELECT pos_id,
  1339. typeID,
  1340. evetowerID,
  1341. outpost_id,
  1342. corp,
  1343. allianceid,
  1344. pos_size,
  1345. pos_race,
  1346. isotope,
  1347. oxygen,
  1348. mechanical_parts,
  1349. coolant,
  1350. robotics,
  1351. uranium,
  1352. ozone,
  1353. heavy_water,
  1354. charters,
  1355. strontium,
  1356. towerName,
  1357. systemID,
  1358. charters_needed,
  1359. status,
  1360. owner_id,
  1361. secondary_owner_id,
  1362. pos_status,
  1363. pos_comment,
  1364. secret_pos,
  1365. moonID,
  1366. ".TBL_PREFIX."mapregions.regionID as regionID,
  1367. ".TBL_PREFIX."mapregions.regionName as regionName
  1368. FROM ".TBL_PREFIX."tower_info,
  1369. ".TBL_PREFIX."mapsolarsystems,
  1370. ".TBL_PREFIX."mapregions
  1371. WHERE ".TBL_PREFIX."tower_info.systemID = ".TBL_PREFIX."mapsolarsystems.solarSystemID
  1372. AND ".TBL_PREFIX."mapsolarsystems.regionID = ".TBL_PREFIX."mapregions.regionID
  1373. AND ".TBL_PREFIX."mapsolarsystems.regionID = '".$args['regionID']."'" . $where2;
  1374. }
  1375. elseif (isset($args['ownerID']) || isset($args['corp']))
  1376. {
  1377. $sql = "SELECT * FROM `".TBL_PREFIX."tower_info` WHERE 1=1" . $where2;
  1378. }
  1379. else
  1380. {
  1381. $sql = "SELECT * FROM `".TBL_PREFIX."tower_info`";
  1382. }
  1383. $result = $dbconn->Execute($sql);
  1384. if ($dbconn->ErrorNo() != 0) {
  1385. Eve::SessionSetVar('errormsg', $dbconn->ErrorMsg() . $sql);
  1386. return false;
  1387. }
  1388. $rows = array();
  1389. for (; !$result->EOF; $result->MoveNext()) {
  1390. $rows[] = $result->GetRowAssoc(2);
  1391. }
  1392. $result->Close();
  1393. return $rows;
  1394. }
  1395. /**
  1396. * POSMGMT::GetTowerTypeID()
  1397. *
  1398. * @param mixed $args
  1399. * @return
  1400. */
  1401. function GetTowerTypeID($args)
  1402. {
  1403. if (!isset($args['pos_race']) || !isset($args['pos_size'])) {
  1404. Eve::SessionSetVar('errormsg', 'Missing Information');
  1405. return false;
  1406. }
  1407. $dbconn =& DBGetConn(true);
  1408. $sql = "SELECT *
  1409. FROM ".TBL_PREFIX."tower_static
  1410. WHERE pos_race = '".Eve::VarPrepForStore($args['pos_race'])."'
  1411. AND pos_size = '".Eve::VarPrepForStore($args['pos_size'])."'";
  1412. $result = $dbconn->Execute($sql);
  1413. if ($dbconn->ErrorNo() != 0) {
  1414. Eve::SessionSetVar('errormsg', 'Failed to get Static Tower Info: '.$dbconn->ErrorMsg());
  1415. return false;
  1416. }
  1417. $row = $result->GetRowAssoc(2);
  1418. $result->Close();
  1419. return $row;
  1420. }
  1421. /**
  1422. * POSMGMT::GetTowerType()
  1423. *
  1424. * @param mixed $typeID
  1425. * @return
  1426. */
  1427. function GetTowerType($typeID)
  1428. {
  1429. if (!isset($typeID) && is_numeric($typeID)) {
  1430. Eve::SessionSetVar('errormsg', 'Missing Information');
  1431. return false;
  1432. }
  1433. $dbconn =& DBGetConn(true);
  1434. $sql = "SELECT *
  1435. FROM ".TBL_PREFIX."tower_static
  1436. WHERE typeID = '".Eve::VarPrepForStore($typeID)."';";
  1437. $result = $dbconn->Execute($sql);
  1438. if ($dbconn->ErrorNo() != 0) {
  1439. Eve::SessionSetVar('errormsg', 'Failed to get Static Tower Info: '.$dbconn->ErrorMsg());
  1440. return false;
  1441. }
  1442. $row = $result->GetRowAssoc(2);
  1443. $result->Close();
  1444. return $row;
  1445. }
  1446. /**
  1447. * POSMGMT::AddNewPOS()
  1448. *
  1449. * @param mixed $args
  1450. * @return
  1451. */
  1452. function AddNewPOS($args = array())
  1453. {
  1454. if (!$args) {
  1455. return false;
  1456. }
  1457. $pos_size = Eve::VarPrepForStore($args['pos_size']);
  1458. $corp = Eve::VarPrepForStore($args['corp']);
  1459. $allianceid = Eve::VarPrepForStore($args['allianceid']);
  1460. $typeID = Eve::VarPrepForStore($args['typeID']);
  1461. $pos_race = Eve::VarPrepForStore($args['pos_race']);
  1462. $pos_size = Eve::VarPrepForStore($args['pos_size']);
  1463. $system = Eve::VarPrepForStore($args['system']);
  1464. //$sovereignity = Eve::VarPrepForStore($args['sovereignity']);
  1465. $uranium = Eve::VarPrepForStore($args['uranium']);
  1466. $oxygen = Eve::VarPrepForStore($args['oxygen']);
  1467. $mechanical_parts = Eve::VarPrepForStore($args['mechanical_parts']);
  1468. $coolant = Eve::VarPrepForStore($args['coolant']);
  1469. $robotics = Eve::VarPrepForStore($args['robotics']);
  1470. $isotope = Eve::VarPrepForStore($args['isotope']);
  1471. $ozone = Eve::VarPrepForStore($args['ozone']);
  1472. $heavy_water = Eve::VarPrepForStore($args['heavy_water']);
  1473. $strontium = Eve::VarPrepForStore($args['strontium']);
  1474. $struct_amount = Eve::VarPrepForStore($args['struct_amount']);
  1475. $owner_id = Eve::VarPrepForStore($args['owner_id']);
  1476. $pos_status = Eve::VarPrepForStore($args['pos_status']);
  1477. $systemID = Eve::VarPrepForStore($args['systemID']);
  1478. $moonID = Eve::VarPrepForStore($args['moonID']);
  1479. $towerName = Eve::VarPrepForStore($args['towerName']);
  1480. $security=$this->getSystemSecurity($systemID);
  1481. if($security>=0.35)
  1482. {
  1483. $charters_needed=1;
  1484. }
  1485. else
  1486. {
  1487. $charters_needed=0;
  1488. }
  1489. $dbconn =& DBGetConn(true);
  1490. //$nextId = $dbconn->GenId(TBL_PREFIX.'tower_info');
  1491. $sql = "INSERT INTO ".TBL_PREFIX."tower_info (typeID,
  1492. evetowerID,
  1493. corp,
  1494. allianceid,
  1495. pos_size,
  1496. pos_race,
  1497. isotope,
  1498. oxygen,
  1499. mechanical_parts,
  1500. coolant,
  1501. robotics,
  1502. uranium,
  1503. ozone,
  1504. heavy_water,
  1505. charters,
  1506. strontium,
  1507. towerName,
  1508. systemID,
  1509. charters_needed,
  1510. status,
  1511. owner_id,
  1512. secondary_owner_id,
  1513. pos_status,
  1514. pos_comment,
  1515. secret_pos,
  1516. moonID,
  1517. onlineSince)
  1518. VALUES ('" . $typeID . "',
  1519. '0',
  1520. '" . $corp . "',
  1521. '" . $allianceid . "',
  1522. '" . $pos_size . "',
  1523. '" . $pos_race . "',
  1524. '" . $isotope . "',

Large files files are truncated, but you can click here to view the full file