1
0

functions.admin.php 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  1. <?php
  2. /* $Id: functions.admin.php 3325 2008-01-23 14:05:07Z b4rt $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. /**
  16. * updateServerSettings
  17. */
  18. function admin_updateServerSettings() {
  19. global $cfg;
  20. $settings = processSettingsParams(false, false);
  21. saveSettings('tf_settings', $settings);
  22. AuditAction($cfg["constants"]["admin"], " Updating Server Settings");
  23. @header("location: admin.php?op=serverSettings");
  24. exit();
  25. }
  26. /**
  27. * updateTransferSettings
  28. */
  29. function admin_updateTransferSettings() {
  30. global $cfg;
  31. $settings = processSettingsParams(false, false);
  32. saveSettings('tf_settings', $settings);
  33. AuditAction($cfg["constants"]["admin"], " Updating Transfer Settings");
  34. @header("location: admin.php?op=transferSettings");
  35. exit();
  36. }
  37. /**
  38. * updateWebappSettings
  39. */
  40. function admin_updateWebappSettings() {
  41. global $cfg;
  42. $settings = processSettingsParams(false, false);
  43. saveSettings('tf_settings', $settings);
  44. AuditAction($cfg["constants"]["admin"], " Updating WebApp Settings");
  45. @header("location: admin.php?op=webappSettings");
  46. exit();
  47. }
  48. /**
  49. * updateIndexSettings
  50. */
  51. function admin_updateIndexSettings() {
  52. global $cfg;
  53. $settings = processSettingsParams(true, true);
  54. saveSettings('tf_settings', $settings);
  55. AuditAction($cfg["constants"]["admin"], " Updating Index Settings");
  56. @header("location: admin.php?op=indexSettings");
  57. exit();
  58. }
  59. /**
  60. * updateControlSettings
  61. */
  62. function admin_updateControlSettings() {
  63. global $cfg;
  64. $settings = processSettingsParams(false, false);
  65. saveSettings('tf_settings', $settings);
  66. AuditAction($cfg["constants"]["admin"], " Updating Control Settings");
  67. @header("location: admin.php?op=controlSettings");
  68. exit();
  69. }
  70. /**
  71. * updateDirSettings
  72. */
  73. function admin_updateDirSettings() {
  74. global $cfg;
  75. $settings = processSettingsParams(false, false);
  76. saveSettings('tf_settings_dir', $settings);
  77. AuditAction($cfg["constants"]["admin"], " Updating Dir Settings");
  78. @header("location: admin.php?op=dirSettings");
  79. exit();
  80. }
  81. /**
  82. * updateStatsSettings
  83. */
  84. function admin_updateStatsSettings() {
  85. global $cfg;
  86. $settings = processSettingsParams(false, false);
  87. saveSettings('tf_settings_stats', $settings);
  88. AuditAction($cfg["constants"]["admin"], " Updating Stats Settings");
  89. @header("location: admin.php?op=statsSettings");
  90. exit();
  91. }
  92. /**
  93. * updateXferSettings
  94. */
  95. function admin_updateXferSettings() {
  96. global $cfg;
  97. $settings = processSettingsParams(false, false);
  98. saveSettings('tf_settings', $settings);
  99. AuditAction($cfg["constants"]["admin"], " Updating Xfer Settings");
  100. @header("location: admin.php?op=xferSettings");
  101. exit();
  102. }
  103. /**
  104. * updateFluxdSettings
  105. */
  106. function admin_updateFluxdSettings() {
  107. global $cfg;
  108. if ($_POST["fluxd_dbmode"] != $cfg["fluxd_dbmode"] ||
  109. $_POST["fluxd_loglevel"] != $cfg["fluxd_loglevel"] ||
  110. $_POST["fluxd_Qmgr_enabled"] != $cfg["fluxd_Qmgr_enabled"] ||
  111. $_POST["fluxd_Fluxinet_enabled"] != $cfg["fluxd_Fluxinet_enabled"] ||
  112. $_POST["fluxd_Maintenance_enabled"] != $cfg["fluxd_Maintenance_enabled"] ||
  113. $_POST["fluxd_Trigger_enabled"] != $cfg["fluxd_Trigger_enabled"] ||
  114. $_POST["fluxd_Watch_enabled"] != $cfg["fluxd_Watch_enabled"] ||
  115. $_POST["fluxd_Rssad_enabled"] != $cfg["fluxd_Rssad_enabled"] ||
  116. $_POST["fluxd_Qmgr_maxTotalTransfers"] != $cfg["fluxd_Qmgr_maxTotalTransfers"] ||
  117. $_POST["fluxd_Qmgr_maxUserTransfers"] != $cfg["fluxd_Qmgr_maxUserTransfers"] ||
  118. $_POST["fluxd_Qmgr_interval"] != $cfg["fluxd_Qmgr_interval"] ||
  119. $_POST["fluxd_Fluxinet_port"] != $cfg["fluxd_Fluxinet_port"] ||
  120. $_POST["fluxd_Watch_interval"] != $cfg["fluxd_Watch_interval"] ||
  121. $_POST["fluxd_Rssad_interval"] != $cfg["fluxd_Rssad_interval"] ||
  122. $_POST["fluxd_Maintenance_interval"] != $cfg["fluxd_Maintenance_interval"] ||
  123. $_POST["fluxd_Trigger_interval"] != $cfg["fluxd_Trigger_interval"]) {
  124. $message = 'Settings changed. ';
  125. // fluxd Running?
  126. if (Fluxd::isRunning()) {
  127. // restart ?
  128. if ($_POST["fluxd_dbmode"] != $cfg["fluxd_dbmode"]) {
  129. // save settings
  130. $settings = processSettingsParams(false, false);
  131. saveSettings('tf_settings', $settings);
  132. $message .= 'fluxd needs to be restarted to change db-mode.';
  133. } else {
  134. // reload ?
  135. $reloadModules = false;
  136. if ($_POST["fluxd_Qmgr_enabled"] != $cfg["fluxd_Qmgr_enabled"] ||
  137. $_POST["fluxd_Fluxinet_enabled"] != $cfg["fluxd_Fluxinet_enabled"] ||
  138. $_POST["fluxd_Maintenance_enabled"] != $cfg["fluxd_Maintenance_enabled"] ||
  139. $_POST["fluxd_Trigger_enabled"] != $cfg["fluxd_Trigger_enabled"] ||
  140. $_POST["fluxd_Watch_enabled"] != $cfg["fluxd_Watch_enabled"] ||
  141. $_POST["fluxd_Rssad_enabled"] != $cfg["fluxd_Rssad_enabled"]) {
  142. $reloadModules = true;
  143. }
  144. // reconfig of running daemon :
  145. if ($_POST["fluxd_loglevel"] != $cfg["fluxd_loglevel"]) {
  146. Fluxd::setConfig('LOGLEVEL', $_POST["fluxd_loglevel"]);
  147. sleep(2);
  148. }
  149. // save settings
  150. $settings = processSettingsParams(false, false);
  151. saveSettings('tf_settings', $settings);
  152. // reload fluxd-database-cache
  153. Fluxd::reloadDBCache();
  154. // reload fluxd-modules
  155. if ($reloadModules) {
  156. sleep(5);
  157. Fluxd::reloadModules();
  158. $message .= 'modules reloaded.';
  159. } else {
  160. $message .= ' reload module(s) to use new settings.';
  161. }
  162. }
  163. } else {
  164. // save settings
  165. $settings = processSettingsParams(false, false);
  166. saveSettings('tf_settings', $settings);
  167. $message .= 'fluxd is not running.';
  168. }
  169. // log
  170. AuditAction($cfg["constants"]["fluxd"], " Updating fluxd Settings");
  171. // redir
  172. @header("Location: admin.php?op=fluxdSettings&m=".urlencode($message));
  173. } else {
  174. // save settings
  175. $settings = processSettingsParams(false, false);
  176. saveSettings('tf_settings', $settings);
  177. // log
  178. AuditAction($cfg["constants"]["fluxd"], " Updating fluxd Settings");
  179. // redir
  180. @header("Location: admin.php?op=fluxdSettings");
  181. }
  182. exit();
  183. }
  184. /**
  185. * controlFluxd
  186. */
  187. function admin_controlFluxd() {
  188. global $cfg;
  189. $message = "";
  190. $action = tfb_getRequestVar('a');
  191. switch($action) {
  192. case "start":
  193. // start fluxd
  194. if (Fluxd::isReadyToStart()) {
  195. Fluxd::start();
  196. if (Fluxd::isRunning()) {
  197. $message = 'fluxd started';
  198. } else {
  199. $message = 'Error starting fluxd.';
  200. $msgs = Fluxd::getMessages();
  201. Fluxd::logError("Error starting fluxd.".( (!empty($msgs)) ? "\n".implode("\n", $msgs)."\n" : "\n"), true);
  202. array_push($msgs, "please check fluxd-logs");
  203. @error($message, "admin.php?op=fluxdSettings", "fluxd-Settings", $msgs);
  204. }
  205. break;
  206. }
  207. $message = 'fluxd not ready to start';
  208. break;
  209. case "stop":
  210. // kill fluxd
  211. if (Fluxd::isRunning()) {
  212. Fluxd::stop();
  213. $message = (Fluxd::isRunning())
  214. ? 'Stop-Command sent.'
  215. : 'fluxd stopped.';
  216. }
  217. break;
  218. default:
  219. $message = 'Error : no control-operation.';
  220. break;
  221. }
  222. if ($message != "")
  223. @header("Location: admin.php?op=fluxdSettings&m=".urlencode($message));
  224. else
  225. @header("Location: admin.php?op=fluxdSettings");
  226. exit();
  227. }
  228. /**
  229. * updateFluAzuSettings
  230. */
  231. function admin_updateFluAzuSettings() {
  232. global $cfg;
  233. // FluAzu
  234. require_once("inc/classes/FluAzu.php");
  235. $message = "";
  236. if ($_POST["fluazu_host"] != $cfg["fluazu_host"] ||
  237. $_POST["fluazu_port"] != $cfg["fluazu_port"] ||
  238. $_POST["fluazu_secure"] != $cfg["fluazu_secure"] ||
  239. $_POST["fluazu_user"] != $cfg["fluazu_user"] ||
  240. $_POST["fluazu_pw"] != $cfg["fluazu_pw"]) {
  241. // fluazu Running?
  242. if (FluAzu::isRunning()) {
  243. $message = 'fluazu needs to be stopped before settings can be changed.';
  244. } else {
  245. // save settings
  246. $settings = processSettingsParams(false, false);
  247. saveSettings('tf_settings', $settings);
  248. $message = 'Settings changed.';
  249. // log
  250. AuditAction($cfg["constants"]["admin"], " Updating fluazu Settings");
  251. }
  252. }
  253. if ($message != "")
  254. @header("Location: admin.php?op=fluazuSettings&m=".urlencode($message));
  255. else
  256. @header("Location: admin.php?op=fluazuSettings");
  257. exit();
  258. }
  259. /**
  260. * controlFluAzu
  261. */
  262. function admin_controlFluAzu() {
  263. global $cfg;
  264. // FluAzu
  265. require_once("inc/classes/FluAzu.php");
  266. $message = "";
  267. $action = tfb_getRequestVar('a');
  268. switch($action) {
  269. case "start":
  270. // start fluazu
  271. if (!FluAzu::isRunning()) {
  272. if (FluAzu::start()) {
  273. $message = 'fluazu started';
  274. } else {
  275. $message = 'Error starting fluazu.';
  276. $msgs = FluAzu::getMessages();
  277. FluAzu::logMessage("Error starting fluazu.".( (!empty($msgs)) ? "\n".implode("\n", $msgs)."\n" : "\n"), true);
  278. array_push($msgs, "please check fluazu-log");
  279. @error($message, "admin.php?op=fluazuSettings", "fluazu-Settings", $msgs);
  280. }
  281. break;
  282. }
  283. break;
  284. case "stop":
  285. // kill fluazu
  286. if (FluAzu::isRunning()) {
  287. FluAzu::stop();
  288. $message = (FluAzu::isRunning())
  289. ? 'Stop-Command sent.'
  290. : 'fluazu stopped.';
  291. }
  292. break;
  293. default:
  294. $message = 'Error : no control-operation.';
  295. break;
  296. }
  297. if ($message != "")
  298. @header("Location: admin.php?op=fluazuSettings&m=".urlencode($message));
  299. else
  300. @header("Location: admin.php?op=fluazuSettings");
  301. exit();
  302. }
  303. /**
  304. * updateAzureusSettings
  305. */
  306. function admin_updateAzureusSettings() {
  307. global $cfg;
  308. // FluAzu
  309. require_once("inc/classes/FluAzu.php");
  310. $message = "";
  311. // fluazu Running?
  312. if (FluAzu::isRunning()) {
  313. $status = FluAzu::getStatus();
  314. $statusKeys = FluAzu::getStatusKeys();
  315. // current settings
  316. $settingsCurrent = array();
  317. foreach ($statusKeys as $statusKey)
  318. $settingsCurrent[$statusKey] = $status[$statusKey];
  319. // new settings
  320. $settingsNew = array();
  321. foreach ($statusKeys as $statusKey) {
  322. $settingsNew[$statusKey] = tfb_getRequestVar($statusKey);
  323. if ($settingsNew[$statusKey] == "")
  324. $settingsNew[$statusKey] = $settingsCurrent[$statusKey];
  325. }
  326. // customize settings
  327. if ($cfg['transfer_customize_settings'] == 2)
  328. $customize_settings = 1;
  329. elseif ($cfg['transfer_customize_settings'] == 1 && $cfg['isAdmin'])
  330. $customize_settings = 1;
  331. else
  332. $customize_settings = 0;
  333. // get changes
  334. $settingsChanged = array();
  335. foreach ($statusKeys as $statusKey) {
  336. if ($settingsNew[$statusKey] != $settingsCurrent[$statusKey]) {
  337. if ($customize_settings == 1)
  338. array_push($settingsChanged, $statusKey);
  339. }
  340. }
  341. if (empty($settingsChanged)) { /* no changes */
  342. $message = 'no changes.';
  343. } else { /* something changed */
  344. // set
  345. foreach ($settingsChanged as $statusKey)
  346. FluAzu::setAzu($statusKey, $settingsNew[$statusKey], false);
  347. // send
  348. FluAzu::sendCommands();
  349. // give fluazu some time
  350. sleep(2);
  351. $message = 'Settings changed.';
  352. // log
  353. AuditAction($cfg["constants"]["admin"], "Updating azureus Settings");
  354. }
  355. } else {
  356. $message = 'fluazu/azureus not running.';
  357. }
  358. if ($message != "")
  359. @header("Location: admin.php?op=fluazuSettings&m=".urlencode($message));
  360. else
  361. @header("Location: admin.php?op=fluazuSettings");
  362. exit();
  363. }
  364. /**
  365. * updateSearchSettings
  366. */
  367. function admin_updateSearchSettings() {
  368. global $cfg;
  369. $settings = array();
  370. foreach ($_POST as $key => $value) {
  371. if ($key != "searchEngine")
  372. $settings[$key] = $value;
  373. }
  374. if (count($settings) > 0) {
  375. saveSettings('tf_settings', $settings);
  376. AuditAction($cfg["constants"]["admin"], "Updating Search Settings");
  377. }
  378. $searchEngine = tfb_getRequestVar('searchEngine');
  379. if (empty($searchEngine))
  380. $searchEngine = $cfg["searchEngine"];
  381. @header("location: admin.php?op=searchSettings&searchEngine=".$searchEngine);
  382. exit();
  383. }
  384. /**
  385. * addLink
  386. */
  387. function admin_addLink() {
  388. global $cfg;
  389. $newLink = tfb_getRequestVarRaw('newLink');
  390. $newSite = tfb_getRequestVarRaw('newSite');
  391. if (!empty($newLink)){
  392. if (strpos($newLink, "http://" ) !== 0 && strpos($newLink, "https://" ) !== 0 && strpos($newLink, "ftp://" ) !== 0)
  393. $newLink = "http://".$newLink;
  394. empty($newSite) && $newSite = $newLink;
  395. addNewLink($newLink, $newSite);
  396. AuditAction($cfg["constants"]["admin"], "New ".$cfg['_LINKS_MENU'].": ".addslashes($newSite)." [".addslashes($newLink)."]");
  397. }
  398. @header("location: admin.php?op=editLinks");
  399. exit();
  400. }
  401. /**
  402. * editLink
  403. */
  404. function admin_editLink() {
  405. global $cfg;
  406. $lid = tfb_getRequestVar('lid');
  407. $newLink = tfb_getRequestVarRaw('editLink');
  408. $newSite = tfb_getRequestVarRaw('editSite');
  409. if (!empty($newLink)){
  410. if(strpos($newLink, "http://" ) !== 0 && strpos($newLink, "https://" ) !== 0 && strpos($newLink, "ftp://" ) !== 0)
  411. $newLink = "http://".$newLink;
  412. empty($newSite) && $newSite = $newLink;
  413. $oldLink = getLink($lid);
  414. $oldSite = getSite($lid);
  415. alterLink($lid, $newLink, $newSite);
  416. AuditAction($cfg["constants"]["admin"], "Change Link: ".addslashes($oldSite)." [".addslashes($oldLink)."] -> ".addslashes($newSite)." [".addslashes($newLink)."]");
  417. }
  418. @header("location: admin.php?op=editLinks");
  419. exit();
  420. }
  421. /**
  422. * moveLink
  423. */
  424. function admin_moveLink() {
  425. global $db;
  426. $lid = tfb_getRequestVar('lid');
  427. $direction = tfb_getRequestVar('direction');
  428. if (!isset($lid) && !isset($direction) && $direction !== "up" && $direction !== "down") {
  429. @header("location: admin.php?op=editLinks");
  430. exit();
  431. }
  432. $idx = getLinkSortOrder($lid);
  433. $position = array("up"=>-1, "down"=>1);
  434. $new_idx = $idx + $position[$direction];
  435. $sql = "UPDATE tf_links SET sort_order = ".$db->qstr($idx)." WHERE sort_order = ".$db->qstr($new_idx);
  436. $db->Execute($sql);
  437. if ($db->ErrorNo() != 0) dbError($sql);
  438. $sql = "UPDATE tf_links SET sort_order = ".$db->qstr($new_idx)." WHERE lid = ".$db->qstr($lid);
  439. $db->Execute($sql);
  440. if ($db->ErrorNo() != 0) dbError($sql);
  441. // flush session-cache
  442. cacheFlush();
  443. @header("Location: admin.php?op=editLinks");
  444. exit();
  445. }
  446. /**
  447. * deleteLink
  448. */
  449. function admin_deleteLink() {
  450. global $cfg;
  451. $lid = tfb_getRequestVar('lid');
  452. AuditAction($cfg["constants"]["admin"], $cfg['_DELETE']." Link: ".getSite($lid)." [".getLink($lid)."]");
  453. deleteOldLink($lid);
  454. // flush session-cache
  455. cacheFlush();
  456. @header("location: admin.php?op=editLinks");
  457. exit();
  458. }
  459. /**
  460. * addRSS
  461. */
  462. function admin_addRSS() {
  463. global $cfg;
  464. $newRSS = tfb_getRequestVarRaw('newRSS');
  465. if(!empty($newRSS)){
  466. addNewRSS($newRSS);
  467. AuditAction($cfg["constants"]["admin"], "New RSS: ".addslashes($newRSS));
  468. }
  469. @header("location: admin.php?op=editRSS");
  470. exit();
  471. }
  472. /**
  473. * deleteRSS
  474. */
  475. function admin_deleteRSS() {
  476. global $cfg;
  477. $rid = tfb_getRequestVar('rid');
  478. AuditAction($cfg["constants"]["admin"], $cfg['_DELETE']." RSS: ".getRSS($rid));
  479. deleteOldRSS($rid);
  480. @header("location: admin.php?op=editRSS");
  481. exit();
  482. }
  483. /**
  484. * deleteUser
  485. */
  486. function admin_deleteUser() {
  487. global $cfg;
  488. $user_id = tfb_getRequestVar('user_id');
  489. if (!IsSuperAdmin($user_id)) {
  490. DeleteThisUser($user_id);
  491. AuditAction($cfg["constants"]["admin"], $cfg['_DELETE']." ".$cfg['_USER'].": ".$user_id);
  492. }
  493. @header("location: admin.php");
  494. exit();
  495. }
  496. /**
  497. * setUserState
  498. */
  499. function admin_setUserState() {
  500. setUserState();
  501. @header("location: admin.php?op=showUsers");
  502. exit();
  503. }
  504. /**
  505. * admin menu
  506. */
  507. function tmplSetAdminMenu() {
  508. global $cfg, $tmpl;
  509. $tmpl->setvar('_SETTINGS_MENU', $cfg['_SETTINGS_MENU']);
  510. $tmpl->setvar('_FLUXD_MENU', $cfg['_FLUXD_MENU']);
  511. $tmpl->setvar('_SEARCHSETTINGS_MENU', $cfg['_SEARCHSETTINGS_MENU']);
  512. $tmpl->setvar('_LINKS_MENU', $cfg['_LINKS_MENU']);
  513. $tmpl->setvar('_ACTIVITY_MENU', $cfg['_ACTIVITY_MENU']);
  514. $tmpl->setvar('table_admin_border', $cfg["table_admin_border"]);
  515. // superadmin
  516. if (IsSuperAdmin()) {
  517. $tmpl->setvar('is_superadmin', 1);
  518. $tmpl->setvar('adminmenu_superAdminLink', getSuperAdminLink('','<font class="adminlink">superadmin</font></a>'));
  519. }
  520. }
  521. /**
  522. * get Activity
  523. *
  524. * @param $min
  525. * @param $user
  526. * @param $srchFile
  527. * @param $srchAction
  528. */
  529. function tmplSetActivity($min = 0, $user = "", $srchFile = "", $srchAction = "") {
  530. global $cfg, $db, $tmpl;
  531. $sqlForSearch = "";
  532. $userdisplay = $user;
  533. if ($user != "")
  534. $sqlForSearch .= "user_id=".$db->qstr($user)." AND ";
  535. else
  536. $userdisplay = $cfg['_ALLUSERS'];
  537. if ($srchFile != "")
  538. $sqlForSearch .= "file like ".$db->qstr("%".$srchFile."%")." AND ";
  539. if ($srchAction != "")
  540. $sqlForSearch .= "action like ".$db->qstr("%".$srchAction."%")." AND ";
  541. $offset = 50;
  542. $inx = 0;
  543. if (!isset($min))
  544. $min=0;
  545. $max = $min + $offset;
  546. $sql = "SELECT user_id, file, action, ip, ip_resolved, user_agent, time FROM tf_log WHERE ".$sqlForSearch."action!=".$db->qstr($cfg["constants"]["hit"])." ORDER BY time desc";
  547. $result = $db->SelectLimit($sql, $offset, $min);
  548. if ($db->ErrorNo() != 0) dbError($sql);
  549. $act_list = array();
  550. while (list($user_id, $file, $action, $ip, $ip_resolved, $user_agent, $time) = $result->FetchRow()) {
  551. $user_icon = (IsOnline($user_id))
  552. ? "themes/".$cfg['theme']."/images/user.gif"
  553. : "themes/".$cfg['theme']."/images/user_offline.gif";
  554. $is_superuser = (IsUser($user_id)) ? 1 : 0;
  555. array_push($act_list, array(
  556. 'is_superuser' => $is_superuser,
  557. 'user_id' => $user_id,
  558. 'user_icon' => $user_icon,
  559. 'action' => htmlentities($action, ENT_QUOTES),
  560. 'file' => htmlentities($file, ENT_QUOTES),
  561. 'ip_resolved' => htmlentities($ip_resolved, ENT_QUOTES),
  562. 'user_agent' => htmlentities($user_agent, ENT_QUOTES),
  563. 'ip' => htmlentities($ip, ENT_QUOTES),
  564. 'date' => date($cfg['_DATETIMEFORMAT'], $time)
  565. )
  566. );
  567. $inx++;
  568. }
  569. $prev = ($min - $offset);
  570. $selected = "";
  571. $action_list = array();
  572. foreach ($cfg["constants"] as $action) {
  573. if ($action != $cfg["constants"]["hit"]) {
  574. array_push($action_list, array(
  575. 'action' => htmlentities($action, ENT_QUOTES),
  576. 'selected' => ($srchAction == $action) ? "selected" : ""
  577. )
  578. );
  579. }
  580. }
  581. $user_list = array();
  582. $selected = "";
  583. for ($inx2 = 0; $inx2 < sizeof($cfg['users']); $inx2++) {
  584. array_push($user_list, array(
  585. 'user' => htmlentities($cfg['users'][$inx2], ENT_QUOTES),
  586. 'selected' => ($user == $cfg['users'][$inx2]) ? "selected" : ""
  587. )
  588. );
  589. }
  590. // set vars
  591. $tmpl->setvar('_USER', $cfg['_USER']);
  592. $tmpl->setvar('_ACTION', $cfg['_ACTION']);
  593. $tmpl->setvar('_FILE', $cfg['_FILE']);
  594. $tmpl->setvar('_IP', $cfg['_IP']);
  595. $tmpl->setvar('_TIMESTAMP', $cfg['_TIMESTAMP']);
  596. $tmpl->setvar('_NORECORDSFOUND', $cfg['_NORECORDSFOUND']);
  597. $tmpl->setvar('_SENDMESSAGETO', $cfg['_SENDMESSAGETO']);
  598. $tmpl->setvar('_ACTIVITYSEARCH', $cfg['_ACTIVITYSEARCH']);
  599. $tmpl->setvar('_FILE', $cfg['_FILE']);
  600. $tmpl->setvar('_SHOWPREVIOUS', $cfg['_SHOWPREVIOUS']);
  601. $tmpl->setvar('_SHOWMORE', $cfg['_SHOWMORE']);
  602. $tmpl->setvar('_ALL', $cfg['_ALL']);
  603. $tmpl->setvar('_DAYS', $cfg['_DAYS']);
  604. $tmpl->setvar('_SEARCH', $cfg['_SEARCH']);
  605. $tmpl->setvar('_ACTIVITYLOG', $cfg['_ACTIVITYLOG']);
  606. $tmpl->setvar('table_admin_border', $cfg["table_admin_border"]);
  607. $tmpl->setloop('activity_act_list', $act_list);
  608. $tmpl->setloop('activity_action_list', $action_list);
  609. $tmpl->setloop('activity_user_list', $user_list);
  610. $tmpl->setvar('activity_srchFile', $srchFile);
  611. $tmpl->setvar('activity_srchAction', $srchAction);
  612. $tmpl->setvar('activity_prev', $prev);
  613. $tmpl->setvar('activity_user', $user);
  614. $tmpl->setvar('activity_min', $min);
  615. $tmpl->setvar('activity_max', $max);
  616. $tmpl->setvar('activity_days_to_keep', $cfg["days_to_keep"]);
  617. $tmpl->setvar('activity_userdisplay', $userdisplay);
  618. if ($prev >= 0)
  619. $tmpl->setvar('activity_is_prev', 1);
  620. if ($inx>=$offset)
  621. $tmpl->setvar('activity_is_more', 1);
  622. if ($prev >= 0 || $inx>=$offset)
  623. $tmpl->setvar('activity_both_set', 1);
  624. }
  625. /**
  626. * sets vars for the user section
  627. */
  628. function tmplSetUserSection() {
  629. global $cfg, $db, $tmpl;
  630. // xfer-prepare
  631. $tmpl->setvar('enable_xfer', $cfg["enable_xfer"]);
  632. if ($cfg['enable_xfer'] == 1) {
  633. $tmpl->setvar('userSection_colspan', 8);
  634. // getTransferListArray to update xfer-stats
  635. // xfer-init
  636. if ($cfg['xfer_realtime'] == 0) {
  637. $cfg['xfer_realtime'] = 1;
  638. // set xfer-newday
  639. Xfer::setNewday();
  640. }
  641. @getTransferListArray();
  642. } else {
  643. $tmpl->setvar('userSection_colspan', 7);
  644. }
  645. // activity-prepare
  646. $total_activity = GetActivityCount();
  647. $sql = "SELECT user_id, hits, last_visit, time_created, user_level, state FROM tf_users ORDER BY user_id";
  648. $result = $db->Execute($sql);
  649. if ($db->ErrorNo() != 0) dbError($sql);
  650. // user-details
  651. $user_details_list = array();
  652. while (list($user_id, $hits, $last_visit, $time_created, $user_level, $user_state) = $result->FetchRow()) {
  653. // disk-usage
  654. $disk_usage = "0";
  655. $tDir = $cfg["path"].$user_id."/";
  656. if (is_dir($tDir)) {
  657. switch ($cfg["_OS"]) {
  658. case 1: //Linux
  659. $dudir = shell_exec($cfg['bin_du']." -sk -h -D ".tfb_shellencode($tDir));
  660. break;
  661. case 2: //BSD
  662. $dudir = shell_exec($cfg['bin_du']." -sk -h -L ".tfb_shellencode($tDir));
  663. break;
  664. }
  665. $dusize = explode("\t", $dudir);
  666. $disk_usage = array_shift($dusize);
  667. }
  668. // xfer-usage
  669. $xfer_usage = ($cfg['enable_xfer'] == 1)
  670. ? Xfer::getUsage($user_id)
  671. : 0;
  672. // activity
  673. $user_activity = GetActivityCount($user_id);
  674. $user_percent = ($user_activity == 0)
  675. ? 0
  676. : number_format(($user_activity / $total_activity) * 100);
  677. // online
  678. $user_icon = "themes/".$cfg['theme']."/images/user_offline.gif";
  679. if (IsOnline($user_id))
  680. $user_icon = "themes/".$cfg['theme']."/images/user.gif";
  681. // level
  682. $user_image = "themes/".$cfg['theme']."/images/user.gif";
  683. $type_user = $cfg['_NORMALUSER'];
  684. if ($user_level == 1) {
  685. $user_image = "themes/".$cfg['theme']."/images/admin_user.gif";
  686. $type_user = $cfg['_ADMINISTRATOR'];
  687. }
  688. if ($user_level == 2) {
  689. $user_image = "themes/".$cfg['theme']."/images/superadmin.gif";
  690. $type_user = $cfg['_SUPERADMIN'];
  691. }
  692. $is_superadmin = ($user_level <= 1 || IsSuperAdmin()) ? 1 : 0;
  693. // add to list
  694. array_push($user_details_list, array(
  695. 'is_user' => IsUser($user_id),
  696. 'user_id' => $user_id,
  697. 'user_icon' => $user_icon,
  698. 'hits' => $hits,
  699. 'disk_usage' => $disk_usage,
  700. 'xfer_usage' => $xfer_usage,
  701. 'user_percent' => $user_percent,
  702. 'user_percent2' => $user_percent*2,
  703. 'user_percent3' => (200 - ($user_percent*2)),
  704. 'time_created' => date($cfg['_DATEFORMAT'], $time_created),
  705. 'last_visit' => date($cfg['_DATETIMEFORMAT'], $last_visit),
  706. 'user_image' => $user_image,
  707. 'type_user' => $type_user,
  708. 'user_level' => $user_level,
  709. 'user_state' => $user_state,
  710. 'is_superadmin' => $is_superadmin
  711. )
  712. );
  713. }
  714. // set vars
  715. $tmpl->setvar('_USERDETAILS', $cfg['_USERDETAILS']);
  716. $tmpl->setvar('_USER', $cfg['_USER']);
  717. $tmpl->setvar('_HITS', $cfg['_HITS']);
  718. $tmpl->setvar('_UPLOADACTIVITY', $cfg['_UPLOADACTIVITY']);
  719. $tmpl->setvar('_JOINED', $cfg['_JOINED']);
  720. $tmpl->setvar('_LASTVISIT', $cfg['_LASTVISIT']);
  721. $tmpl->setvar('_ADMIN', $cfg['_ADMIN']);
  722. $tmpl->setvar('_DAYS', $cfg['_DAYS']);
  723. $tmpl->setvar('_SENDMESSAGETO', $cfg['_SENDMESSAGETO']);
  724. $tmpl->setvar('_WARNING', $cfg['_WARNING']);
  725. $tmpl->setvar('_ABOUTTODELETE', $cfg['_ABOUTTODELETE']);
  726. $tmpl->setvar('_USERSACTIVITY', $cfg['_USERSACTIVITY']);
  727. $tmpl->setvar('_EDIT', $cfg['_EDIT']);
  728. $tmpl->setvar('_DELETE', $cfg['_DELETE']);
  729. $tmpl->setvar('table_admin_border', $cfg["table_admin_border"]);
  730. $tmpl->setvar('days_to_keep', $cfg["days_to_keep"]);
  731. $tmpl->setloop('user_details_list', $user_details_list);
  732. }
  733. /**
  734. * shell_exec php binary with given command-line,
  735. * taking necessary precautions in case binary
  736. * it is not really a php-cli
  737. *
  738. * @param $php string
  739. * @param $args string
  740. * @return string
  741. */
  742. function safePhpCli($php, $args) {
  743. # Need to be careful in order to avoid problems with cgi-fcgi SAPI php's:
  744. # - they detect whether they are in fcgi mode by testing whether their stdin is
  745. # a socket -- so if this code is run by a fcgi php (whose stdin is a socket),
  746. # child will inherit the same stdin and thus believe it is invoked in fcgi mode
  747. # => '< /dev/null'
  748. # - they detect whether they are in cgi mode by testing the presence of environment
  749. # variables -- so if this code is run by a cgi php (with those env. vars set),
  750. # child will inherit those and thus believe it is invoked in cgi mode
  751. # => 'unset ...'
  752. $cmd = 'unset SERVER_SOFTWARE SERVER_NAME GATEWAY_INTERFACE REQUEST_METHOD ; ';
  753. $cmd .= $php . ' ' . $args . ' < /dev/null';
  754. return shell_exec($cmd);
  755. }
  756. /**
  757. * Returns the status image after a validation
  758. *
  759. * @param $ok bool
  760. * @param $msg string
  761. * @return string
  762. */
  763. function validationMsg($ok, $msg = null) {
  764. global $cfg;
  765. return
  766. '<img src="themes/'.$cfg['theme'].'/images/'.($ok ? 'green.gif' : 'red.gif').
  767. '" align="absmiddle" title="'.(!empty($msg) ? $msg : ($ok ? 'Valid' : 'Invalid')).'">'.
  768. (empty($msg) ? '' : ('<br><font color="'.($ok ? '#008000' : '#ff0000').'">'.$msg.'</font>'));
  769. }
  770. /**
  771. * Validates the existence of a file and returns the status image
  772. *
  773. * @param $the_file
  774. * @return string
  775. */
  776. function validateFile($the_file) {
  777. if (!isFile($the_file))
  778. return validationMsg(false, 'Path is not valid');
  779. return validationMsg(true);
  780. }
  781. /**
  782. * Validates existence + exec of a file and returns the status image
  783. *
  784. * @param $the_file
  785. * @return string
  786. */
  787. function validateBinary($the_file) {
  788. if (!isFile($the_file))
  789. return validationMsg(false, 'Path is not valid');
  790. if (!is_executable($the_file))
  791. return validationMsg(false, 'File exists but is not executable');
  792. return validationMsg(true);
  793. }
  794. /**
  795. * Validates existence + exec + valid version of PHP-cli and returns the status image
  796. *
  797. * @param $the_file
  798. * @return string
  799. */
  800. function validatePhpCli($the_file) {
  801. if (!isFile($the_file))
  802. return validationMsg(false, 'Path is not valid');
  803. if (!is_executable($the_file))
  804. return validationMsg(false, 'File exists but is not executable');
  805. $phpVersion = safePhpCli($the_file, '-v');
  806. if ((strpos($phpVersion, 'PHP')) === false || (strpos($phpVersion, '(cli)')) === false)
  807. return validationMsg(false, 'Executable is not PHP-CLI');
  808. return validationMsg(true);
  809. }
  810. /**
  811. * Validates existence + exec + valid version of transmissioncli and returns the status image
  812. *
  813. * @param $the_file
  814. * @return string
  815. */
  816. function validateTransmissionCli($the_file) {
  817. global $cfg;
  818. if (!isFile($the_file))
  819. return validationMsg(false, 'Path is not valid');
  820. if (!is_executable($the_file))
  821. return validationMsg(false, 'File exists but is not executable');
  822. $transmissionHelp = strtolower(shell_exec("HOME=".tfb_shellencode($cfg["path"])."; export HOME; ".$the_file.' --help'));
  823. return (
  824. strpos($transmissionHelp, 'transmission') === false ||
  825. ((strpos($transmissionHelp, 'tfcli') === false) &&
  826. (strpos($transmissionHelp, 'torrentflux') === false))
  827. )
  828. ? validationMsg(false, 'Executable is not TorrentFlux-bundled transmissioncli')
  829. : validationMsg(true);
  830. }
  831. /**
  832. * setUserState
  833. */
  834. function setUserState() {
  835. global $cfg, $db;
  836. $user_id = tfb_getRequestVar('user_id');
  837. $user_state = tfb_getRequestVar('state');
  838. // check params
  839. if (!(isset($user_id)) && (isset($user_state)))
  840. return false;
  841. // sanity-check, don't allow setting state of superadmin to 0
  842. if (($user_state == 0) && (IsSuperAdmin($user_id))) {
  843. AuditAction($cfg["constants"]["error"], "Invalid try to deactivate superadmin account.");
  844. return false;
  845. }
  846. // set new state
  847. $sql = "SELECT * FROM tf_users WHERE user_id = ".$db->qstr($user_id);
  848. $rs = $db->Execute($sql);
  849. if ($db->ErrorNo() != 0) dbError($sql);
  850. $rec = array('state'=>$user_state);
  851. $sql = $db->GetUpdateSQL($rs, $rec);
  852. $result = $db->Execute($sql);
  853. if ($db->ErrorNo() != 0) dbError($sql);
  854. switch ($user_state) {
  855. case 0:
  856. AuditAction($cfg["constants"]["admin"], "User ".$user_id." deactivated.");
  857. break;
  858. case 1:
  859. AuditAction($cfg["constants"]["admin"], "User ".$user_id." activated.");
  860. break;
  861. }
  862. return true;
  863. }
  864. /**
  865. * Add New Link
  866. *
  867. * @param $newLink
  868. * @param $newSite
  869. */
  870. function addNewLink($newLink,$newSite) {
  871. global $db;
  872. //$rec = array('url'=>$newLink);
  873. // Link sort order index:
  874. $idx = -1;
  875. // Get current highest link index:
  876. $sql = "SELECT sort_order FROM tf_links ORDER BY sort_order DESC";
  877. $result = $db->SelectLimit($sql, 1);
  878. if ($db->ErrorNo() != 0) dbError($sql);
  879. $idx = ($result->fields === false)
  880. ? 0 /* No links currently in db */
  881. : $result->fields["sort_order"] + 1;
  882. $rec = array(
  883. 'url' => $newLink,
  884. 'sitename' => $newSite,
  885. 'sort_order' => $idx
  886. );
  887. $sTable = 'tf_links';
  888. $sql = $db->GetInsertSql($sTable, $rec);
  889. $db->Execute($sql);
  890. if ($db->ErrorNo() != 0) dbError($sql);
  891. // flush session-cache
  892. cacheFlush();
  893. }
  894. /**
  895. * This function updates the database and alters the selected links values
  896. *
  897. * @param $lid
  898. * @param $newLink
  899. * @param $newSite
  900. */
  901. function alterLink($lid,$newLink,$newSite) {
  902. global $cfg, $db;
  903. $sql = "UPDATE tf_links SET url=".$db->qstr($newLink).",sitename=".$db->qstr($newSite)." WHERE lid = ".$db->qstr($lid);
  904. $db->Execute($sql);
  905. if ($db->ErrorNo() != 0) dbError($sql);
  906. // flush session-cache
  907. cacheFlush();
  908. }
  909. /**
  910. * get link
  911. *
  912. * @param $lid
  913. * @return string
  914. */
  915. function getLink($lid) {
  916. global $cfg, $db;
  917. $rtnValue = "";
  918. $sql = "SELECT url FROM tf_links WHERE lid=".$db->qstr($lid);
  919. $rtnValue = $db->GetOne($sql);
  920. return $rtnValue;
  921. }
  922. /**
  923. * Delete Link
  924. *
  925. * @param $lid
  926. */
  927. function deleteOldLink($lid) {
  928. global $db;
  929. // Link Mod
  930. //$sql = "delete from tf_links where lid=".$lid;
  931. // Get Current sort order index of link with this link id:
  932. $idx = getLinkSortOrder($lid);
  933. // Fetch all link ids and their sort orders where the sort order is greater
  934. // than the one we're removing - we need to shuffle each sort order down
  935. // one:
  936. $sql = "SELECT sort_order, lid FROM tf_links ";
  937. $sql .= "WHERE sort_order > ".$db->qstr($idx)." ORDER BY sort_order ASC";
  938. $result = $db->Execute($sql);
  939. if ($db->ErrorNo() != 0) dbError($sql);
  940. $arLinks = $result->GetAssoc();
  941. // Decrement the sort order of each link:
  942. foreach ($arLinks as $sid=>$this_lid) {
  943. $sql = "UPDATE tf_links SET sort_order=sort_order-1 WHERE lid=".$db->qstr($this_lid);
  944. $db->Execute($sql);
  945. if ($db->ErrorNo() != 0) dbError($sql);
  946. }
  947. // Finally delete the link:
  948. $sql = "DELETE FROM tf_links WHERE lid=".$db->qstr($lid);
  949. $result = $db->Execute($sql);
  950. if ($db->ErrorNo() != 0) dbError($sql);
  951. // flush session-cache
  952. cacheFlush();
  953. }
  954. /**
  955. * get Link Sort Order
  956. *
  957. * @param $lid
  958. * @return string
  959. */
  960. function getLinkSortOrder($lid) {
  961. global $db;
  962. // Get Current sort order index of link with this link id:
  963. $sql="SELECT sort_order FROM tf_links WHERE lid=".$db->qstr($lid);
  964. $rtnValue=$db->GetOne($sql);
  965. if ($db->ErrorNo() != 0) dbError($sql);
  966. return $rtnValue;
  967. }
  968. /**
  969. * get Site
  970. *
  971. * @param $lid
  972. * @return string
  973. */
  974. function getSite($lid) {
  975. global $cfg, $db;
  976. $rtnValue = "";
  977. $sql = "SELECT sitename FROM tf_links WHERE lid=".$db->qstr($lid);
  978. $rtnValue = $db->GetOne($sql);
  979. return $rtnValue;
  980. }
  981. /**
  982. * Add New RSS Link
  983. *
  984. * @param $newRSS
  985. */
  986. function addNewRSS($newRSS) {
  987. global $db;
  988. $rec = array('url'=>$newRSS);
  989. $sTable = 'tf_rss';
  990. $sql = $db->GetInsertSql($sTable, $rec);
  991. $db->Execute($sql);
  992. if ($db->ErrorNo() != 0) dbError($sql);
  993. }
  994. /**
  995. * Delete RSS
  996. *
  997. * @param $rid
  998. */
  999. function deleteOldRSS($rid) {
  1000. global $db;
  1001. $sql = "delete from tf_rss where rid=".$db->qstr($rid);
  1002. $result = $db->Execute($sql);
  1003. if ($db->ErrorNo() != 0) dbError($sql);
  1004. }
  1005. /**
  1006. * get RSS
  1007. *
  1008. * @param $rid
  1009. * @return string
  1010. */
  1011. function getRSS($rid) {
  1012. global $cfg, $db;
  1013. $rtnValue = "";
  1014. $sql = "SELECT url FROM tf_rss WHERE rid=".$db->qstr($rid);
  1015. $rtnValue = $db->GetOne($sql);
  1016. return $rtnValue;
  1017. }
  1018. /**
  1019. * Delete User
  1020. *
  1021. * @param $user_id
  1022. */
  1023. function DeleteThisUser($user_id) {
  1024. global $db;
  1025. $sql = "SELECT uid FROM tf_users WHERE user_id = ".$db->qstr($user_id);
  1026. $uid = $db->GetOne( $sql );
  1027. if ($db->ErrorNo() != 0) dbError($sql);
  1028. // delete any cookies this user may have had
  1029. //$sql = "DELETE tf_cookies FROM tf_cookies, tf_users WHERE (tf_users.uid = tf_cookies.uid) AND tf_users.user_id=".$db->qstr($user_id);
  1030. $sql = "DELETE FROM tf_cookies WHERE uid=".$db->qstr($uid);
  1031. $result = $db->Execute($sql);
  1032. if ($db->ErrorNo() != 0) dbError($sql);
  1033. // Now cleanup any message this person may have had
  1034. $sql = "DELETE FROM tf_messages WHERE to_user=".$db->qstr($user_id);
  1035. $result = $db->Execute($sql);
  1036. if ($db->ErrorNo() != 0) dbError($sql);
  1037. // now delete the user from the table
  1038. $sql = "DELETE FROM tf_users WHERE user_id=".$db->qstr($user_id);
  1039. $result = $db->Execute($sql);
  1040. if ($db->ErrorNo() != 0) dbError($sql);
  1041. // flush session-cache
  1042. cacheFlush();
  1043. }
  1044. /**
  1045. * Update User -- used by admin
  1046. *
  1047. * @param $user_id
  1048. * @param $org_user_id
  1049. * @param $pass1
  1050. * @param $userType
  1051. * @param $hideOffline
  1052. */
  1053. function updateThisUser($user_id, $org_user_id, $pass1, $userType, $hideOffline) {
  1054. global $db;
  1055. $user_id = strtolower($user_id);
  1056. if ($hideOffline == "")
  1057. $hideOffline = 0;
  1058. $sql = "select * from tf_users where user_id = ".$db->qstr($org_user_id);
  1059. $rs = $db->Execute($sql);
  1060. if ($db->ErrorNo() != 0) dbError($sql);
  1061. $rec = array();
  1062. $rec['user_id'] = $user_id;
  1063. $rec['user_level'] = $userType;
  1064. $rec['hide_offline'] = $hideOffline;
  1065. if ($pass1 != "")
  1066. $rec['password'] = md5($pass1);
  1067. $sql = $db->GetUpdateSQL($rs, $rec);
  1068. if ($sql != "") {
  1069. $result = $db->Execute($sql);
  1070. if ($db->ErrorNo() != 0) dbError($sql);
  1071. }
  1072. // if the original user id and the new id do not match, we need to update messages and log
  1073. if ($user_id != $org_user_id) {
  1074. $sql = "UPDATE tf_messages SET to_user=".$db->qstr($user_id)." WHERE to_user=".$db->qstr($org_user_id);
  1075. $result = $db->Execute($sql);
  1076. if ($db->ErrorNo() != 0) dbError($sql);
  1077. $sql = "UPDATE tf_messages SET from_user=".$db->qstr($user_id)." WHERE from_user=".$db->qstr($org_user_id);
  1078. $result = $db->Execute($sql);
  1079. if ($db->ErrorNo() != 0) dbError($sql);
  1080. $sql = "UPDATE tf_log SET user_id=".$db->qstr($user_id)." WHERE user_id=".$db->qstr($org_user_id);
  1081. $result = $db->Execute($sql);
  1082. if ($db->ErrorNo() != 0) dbError($sql);
  1083. // flush session-cache
  1084. cacheFlush();
  1085. }
  1086. }
  1087. /**
  1088. * Change User Level
  1089. *
  1090. * @param $user_id
  1091. * @param $level
  1092. */
  1093. function changeUserLevel($user_id, $level) {
  1094. global $db;
  1095. $sql = "select * from tf_users where user_id = ".$db->qstr($user_id);
  1096. $rs = $db->Execute($sql);
  1097. if ($db->ErrorNo() != 0) dbError($sql);
  1098. $rec = array('user_level'=>$level);
  1099. $sql = $db->GetUpdateSQL($rs, $rec);
  1100. $result = $db->Execute($sql);
  1101. if ($db->ErrorNo() != 0) dbError($sql);
  1102. }
  1103. /**
  1104. * sets webapp-lock
  1105. *
  1106. * @param $lock 1|0
  1107. * @return true or function exits with error
  1108. */
  1109. function setWebappLock($lock) {
  1110. global $db;
  1111. $db->Execute("UPDATE tf_settings SET tf_value = ".$db->qstr($lock)." WHERE tf_key = 'webapp_locked'");
  1112. // flush session-cache
  1113. cacheFlush();
  1114. // return
  1115. return ($db->ErrorNo() == 0)
  1116. ? true
  1117. : $db->ErrorMsg();
  1118. }
  1119. /**
  1120. * reset transfer-Totals
  1121. *
  1122. * @return true or function exits with error
  1123. */
  1124. function resetAllTransferTotals() {
  1125. global $db;
  1126. $db->Execute("DELETE FROM tf_transfer_totals");
  1127. // set transfers-cache
  1128. cacheTransfersSet();
  1129. return ($db->ErrorNo() == 0)
  1130. ? true
  1131. : $db->ErrorMsg();
  1132. }
  1133. ?>