PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_configuration/configuration.php

https://github.com/EdwinDW/DwRaidPlanner
PHP | 476 lines | 357 code | 74 blank | 45 comment | 143 complexity | 692bf8e4dc4400fda1b18160e3508772 MD5 | raw file
  1. <?php
  2. // no direct access
  3. defined('_VALID_RAID') or die('Restricted Access');
  4. // load footer?
  5. $load_footer = 1;
  6. // verify permissions
  7. if(!$pMain->checkPerm('edit_configuration')) {
  8. pRedirect('index.php?option=com_login&task=login');
  9. }
  10. if(empty($task) || $task == '') {
  11. // no caching for this
  12. $p->caching = false;
  13. if(empty($_POST)) {
  14. // setup default values
  15. $sql["SELECT"] = "*";
  16. $sql["FROM"] = "config";
  17. $db_raid->set_query('select', $sql, __FILE__, __LINE__);
  18. while($data = $db_raid->fetch()) {
  19. $p->assign('pConfig_'.$data['name'], $data['value']);
  20. }
  21. }
  22. // connect to server to check for updates
  23. if (function_exists('curl_init')) {
  24. // create a new cURL resource
  25. $url = curl_init();
  26. // set URL and other appropriate options
  27. curl_setopt($url, CURLOPT_URL, 'http://www.phpraider.com/updatecheck/1xx.txt');
  28. curl_setopt($url, CURLOPT_RETURNTRANSFER, 1);
  29. // Check if we got a good page back
  30. if (curl_getinfo($url, CURLINFO_HTTP_CODE) == 200) {
  31. // grab URL
  32. $remote = curl_exec($url);
  33. $remote = explode('.', $remote);
  34. }
  35. // close cURL resource, and free up system resources
  36. curl_close($url);
  37. } else {
  38. $url = 'http://www.phpraider.com/updatecheck/1xx.txt';
  39. $remote = @file_get_contents($url);
  40. if ($remote == false) {
  41. unset($remote);
  42. } else {
  43. $remote = explode('.', $remote);
  44. }
  45. }
  46. // check local
  47. include(RAIDER_BASE_PATH.'version.php');
  48. $local = explode('.', $version);
  49. $update = 0;
  50. // do the check
  51. if (isset($remote)) {
  52. if($local[0] < $remote[0]) {
  53. $update = 1;
  54. } else {
  55. if($local[1] < $remote[1]) {
  56. $update = 1;
  57. } else {
  58. if($local[2] < $remote[2]) {
  59. $update = 1;
  60. }
  61. }
  62. }
  63. // setup message
  64. if($update) {
  65. $update = sprintf($pLang['coUpdate'], 'http://www.phpraider.com/index.php?action=tpmod;dl=0',
  66. $remote[0], $remote[1], $remote[2], $local[0], $local[1], $local[2]);
  67. } else {
  68. $update = $pLang['coNoUpdate'];
  69. }
  70. } else {
  71. $update = sprintf($pLang['coUpdateUndetermined'], 'http://www.phpraider.com/index.php?action=tpmod;dl=0');
  72. }
  73. $p->assign('update_check', $update);
  74. // setup game list
  75. if(is_dir(RAIDER_GAME_BASE_PATH)) {
  76. $dh = opendir(RAIDER_GAME_BASE_PATH);
  77. $files = array();
  78. while(false != ($filename = readdir($dh))) {
  79. if (preg_match("/^[0-9a-z]+$/si", $filename) == 1) {
  80. if (is_dir(RAIDER_GAME_BASE_PATH.$filename)) {
  81. $files[] = $filename;
  82. }
  83. }
  84. }
  85. sort($files);
  86. $games = '<option value="">'.$pLang['none'].'</option>';
  87. foreach($files as $value) {
  88. if($value == $pConfig['game'])
  89. $selected = ' selected';
  90. else
  91. $selected = '';
  92. $games .= '<option value="'.$value.'"'.$selected.'>'.$value.'</option>';
  93. }
  94. $p->assign('games', $games);
  95. }
  96. // setup language list
  97. $dh = opendir(RAIDER_LANGUAGE_PATH);
  98. $files = array();
  99. while(false != ($filename = readdir($dh))) {
  100. if (!is_dir(RAIDER_LANGUAGE_PATH.$filename)) {
  101. if (preg_match("/^([0-9a-z]+).php$/si", $filename, $language) == 1) {
  102. $files[] = $language[1];
  103. }
  104. }
  105. }
  106. sort($files);
  107. $language = '';
  108. foreach($files as $value) {
  109. if($value == $pConfig['language'])
  110. $selected = ' selected';
  111. else
  112. $selected = '';
  113. if (!empty($value)) {
  114. $language .= '<option value="'.$value.'"'.$selected.'>'.$value.'</option>';
  115. }
  116. }
  117. $p->assign('language', $language);
  118. // setup template list
  119. $files = array();
  120. $dh = opendir(RAIDER_TEMPLATE_BASE_PATH);
  121. while(false != ($filename = readdir($dh))) {
  122. if (is_dir(RAIDER_TEMPLATE_BASE_PATH.$filename)) {
  123. if (preg_match("/^[^\.]/si", $filename) == 1) {
  124. $files[] = $filename;
  125. }
  126. }
  127. }
  128. sort($files);
  129. $templates = '';
  130. foreach($files as $value) {
  131. if($value == $pConfig['template'])
  132. $selected = ' selected';
  133. else
  134. $selected = '';
  135. $templates .= '<option value="'.$value.'"'.$selected.'>'.$value.'</option>';
  136. }
  137. $p->assign('templates', $templates);
  138. unset($files);
  139. // First Day of the Week
  140. $firstdayofweek = '';
  141. if (empty($pConfig['first_day_of_week']))
  142. $pConfig['first_day_of_week'] = 0;
  143. foreach($pLang['coSiDay'] as $value=>$text){
  144. if($value == $pConfig['first_day_of_week'])
  145. $selected = ' selected';
  146. else
  147. $selected = '';
  148. $firstdayofweek .= '<option value="'.$value.'"'.$selected.'>'.$text.'</option>';
  149. }
  150. $p->assign('firstdayofweek', $firstdayofweek);
  151. // setup auth list
  152. $dh = opendir(RAIDER_BASE_PATH.'authentication');
  153. while(false != ($filename = readdir($dh))) {
  154. $files[] = $filename;
  155. }
  156. sort($files);
  157. array_shift($files);
  158. array_shift($files);
  159. $auth = '';
  160. foreach($files as $value) {
  161. if($value == $pConfig['authentication'])
  162. $selected = ' selected';
  163. else
  164. $selected = '';
  165. $auth .= '<option value="'.$value.'"'.$selected.'>'.$value.'</option>';
  166. }
  167. $p->assign('auth', $auth);
  168. unset($files);
  169. $group = '';
  170. // setup groups
  171. $sql["SELECT"] = "*";
  172. $sql["FROM"] = "groups";
  173. $db_raid->set_query('select', $sql, __FILE__, __LINE__);
  174. $group = '<option value="0"> '.$pLang['coDefault'].'</option>';
  175. while($data = $db_raid->fetch()) {
  176. if($pConfig['default_group'] == $data['group_id'])
  177. $selected = 'selected';
  178. else
  179. $selected = '';
  180. $group .= '<option value="'.$data['group_id'].'"'.$selected.'>'.$data['group_name'].'</option>';
  181. }
  182. $p->assign('group', $group);
  183. // timezones
  184. $timezoneOption = '';
  185. for($i = -12; $i <= 12; $i = $i + 0.5) {
  186. if($i == 12 || $i == 11 || $i == 10 || $i == 9.5 || $i == 9 || $i == 8 || $i == 7 || $i == 6.5 || $i == 6 ||
  187. $i == 5.5 || $i == 5 || $i == 4.5 || $i == 4 || $i == 3.5 || $i == 3 || $i == 2 || $i == 1 || $i == 0 ||
  188. $i == -12 || $i == -11 || $i == -10 || $i == -9 || $i == -8 || $i == -7 || $i == -6 || $i == -5 || $i == -4 ||
  189. $i == -3.5 || $i == -3 || $i == -2|| $i == -1) {
  190. if($i < 0)
  191. $format = '- '.abs($i).' '.$pLang['hours'];
  192. elseif($i > 0)
  193. $format = '+ '.$i.' '.$pLang['hours'];
  194. else
  195. $format = '0';
  196. if($pConfig['timezone'] != ($i * 100))
  197. $timezoneOption .= '<option value="'.($i * 100).'">'.$format.'</option>';
  198. else
  199. $timezoneOption .= '<option value="'.($i * 100).'" SELECTED>'.$format.'</option>';
  200. }
  201. }
  202. $p->assign('timezone', $timezoneOption);
  203. $p->assign('siCurrentTime', newDate($pConfig['time_format'], time(), 0));
  204. $p->assign('siSetTime', newDate($pConfig['time_format'], time(), $pConfig['timezone'] + $pConfig['dst']));
  205. $p->assign('siLocalText', $pLang['coLocal_text']);
  206. // localizations
  207. $p->assign(
  208. array(
  209. // headers
  210. 'database_header' => $pLang['coDB_header'],
  211. 'game_header' => $pLang['coGame_header'],
  212. 'misc_header' => $pLang['coMisc_header'],
  213. 'site_header' => $pLang['coSite_header'],
  214. 'raid_header' => $pLang['coRaid_header'],
  215. 'update_header' => $pLang['coUpdate_header'],
  216. // form text
  217. 'dbServer_text' => $pLang['coServer_text'],
  218. 'dbName_text' => $pLang['coDBName_text'],
  219. 'dbUser_text' => $pLang['coDBUser_text'],
  220. 'dbPass_text' => $pLang['coDBPass_text'],
  221. 'dbPersistent_text' => $pLang['coDBPers_text'],
  222. 'dbPrefix_text' => $pLang['coDBPrefix_text'],
  223. 'gaGame_text' => $pLang['coGame_text'],
  224. 'gaMaxLvl_text' => $pLang['coGAMaxLvL_text'],
  225. 'gaMinLvl_text' => $pLang['coGAMinLvl_text'],
  226. 'gaMinRaiders_text' => $pLang['coGAMinRaiders_text'],
  227. 'gaMaxRaiders_text' => $pLang['coGAMaxRaiders_text'],
  228. 'gaMultiClass_text' => $pLang['coGAMultiClass_text'],
  229. 'siLanguage_text' => $pLang['coSiLanguage_text'],
  230. 'siTemplate_text' => $pLang['coSiTemplate_text'],
  231. 'siAuth_text' => $pLang['coSiAuth_text'],
  232. 'siFirstDayOfWeek_text' => $pLang['coSiFirstDayOfWeek_text'],
  233. 'siDateFormat_text' => $pLang['coSiDateFormat_text'],
  234. 'siTimeFormat_text' => $pLang['coSiTimeFormat_text'],
  235. 'siTimezone_text' => $pLang['coSiTimezone_text'],
  236. 'siDst_text' => $pLang['coSiDst_text'],
  237. 'siRegister_text' => $pLang['coSiRegister_text'],
  238. 'siAdmin_text' => $pLang['coSiAdmin_text'],
  239. 'siAdminEmail_text' => $pLang['coSiAdminEmail_text'],
  240. 'siURL_text' => $pLang['coSiUrl_text'],
  241. 'siConfigureAuth' => $pLang['coSiAuthConfigure_text'],
  242. 'miAnon_text' => $pLang['coMiAnon_text'],
  243. 'miQueue_text' => $pLang['coMiQueue_text'],
  244. 'miDebug_text' => $pLang['coMiDebug_text'],
  245. 'miDefaultGroup_text' => $pLang['coMiDefaultGroup_text'],
  246. 'miDisable_text' => $pLang['coMiDisable_text'],
  247. 'miFreeze_text' => $pLang['coMiFreeze_text'],
  248. 'miReport_text' => $pLang['coMiReport_text'],
  249. // form errors
  250. // buttons
  251. 'reset' => $pLang['reset'],
  252. 'submit' => $pLang['submit']
  253. )
  254. );
  255. if(!defined("DISALLOW_GAME_INSTALL"))
  256. $p->assign('installGame_text','<a href="index.php?option=com_configuration&amp;task=install_game">'.$pLang['coGameInstall_text'].'</a>');
  257. if(empty($_POST)) {
  258. // new form, we (re)set the session data
  259. SmartyValidate::connect($p, true);
  260. // register our validators
  261. SmartyValidate::register_validator('server', 'pConfig_db_server', 'notEmpty', false, false, 'trim');
  262. SmartyValidate::register_validator('name', 'pConfig_db_name', 'notEmpty', false, false, 'trim');
  263. SmartyValidate::register_validator('user', 'pConfig_db_user', 'notEmpty', false, false, 'trim');
  264. SmartyValidate::register_validator('prefix', 'pConfig_db_prefix', 'notEmpty', false, false, 'trim');
  265. SmartyValidate::register_validator('min_level', 'pConfig_min_level', 'notEmpty', false, false, 'trim');
  266. SmartyValidate::register_validator('max_level', 'pConfig_max_level', 'notEmpty', false, false, 'trim');
  267. SmartyValidate::register_validator('min_raiders', 'pConfig_min_raiders', 'notEmpty', false, false, 'trim');
  268. SmartyValidate::register_validator('max_raiders', 'pConfig_max_raiders', 'notEmpty', false, false, 'trim');
  269. SmartyValidate::register_validator('date_format', 'pConfig_date_format', 'notEmpty', false, false, 'trim');
  270. SmartyValidate::register_validator('time_format', 'pConfig_time_format', 'notEmpty', false, false, 'trim');
  271. SmartyValidate::register_validator('timezone', 'pConfig_timezone', 'notEmpty', false, false, 'trim');
  272. SmartyValidate::register_validator('admin', 'pConfig_admin_name', 'notEmpty', false, false, 'trim');
  273. SmartyValidate::register_validator('admin_email', 'pConfig_admin_email', 'notEmpty', false, false, 'trim');
  274. SmartyValidate::register_validator('site_url', 'pConfig_site_url', 'notEmpty', false, false, 'trim');
  275. SmartyValidate::register_validator('report_max', 'pConfig_report_max', 'notEmpty', false, false, 'trim');
  276. // display form
  277. $p->display(RAIDER_TEMPLATE_PATH.'configuration.tpl');
  278. } else {
  279. // give empty checkboxes a value
  280. if(empty($_POST['pConfig_dst'])) $_POST['pConfig_dst'] = 0;
  281. if(empty($_POST['pConfig_allow_anonymous'])) $_POST['pConfig_allow_anonymous'] = 0;
  282. if(empty($_POST['pConfig_auto_queue'])) $_POST['pConfig_auto_queue'] = 0;
  283. if(empty($_POST['pConfig_debug_mode'])) $_POST['pConfig_debug_mode'] = 0;
  284. if(empty($_POST['pConfig_disable_site'])) $_POST['pConfig_disable_site'] = 0;
  285. if(empty($_POST['pConfig_disable_freeze'])) $_POST['pConfig_disable_freeze'] = 0;
  286. if(empty($_POST['pConfig_multi_class'])) $_POST['pConfig_multi_class'] = 0;
  287. foreach($_POST as $key=>$value) {
  288. if (!preg_match("/^pConfig\_db\_/si", $key)) {
  289. $sql["REPLACE"] = "config";
  290. $sql["VALUES"] = array(
  291. 'value'=>$value,
  292. 'name'=>substr($key, 8, strlen($key)-3)
  293. );
  294. $db_raid->set_query('replace', $sql, __FILE__, __LINE__);
  295. }
  296. }
  297. pRedirect("index.php?option=com_configuration");
  298. }
  299. } else if($task == 'install_game') {
  300. if(!defined("DISALLOW_GAME_INSTALL")) {
  301. // no caching for this
  302. $p->caching = false;
  303. if (extension_loaded('zip')) {
  304. $pZipSupport = True;
  305. if(is_writable(RAIDER_GAME_BASE_PATH))
  306. $games = $pLang['coGamesWritable'];
  307. else
  308. $games = $pLang['coGamesNotWritable'];
  309. // localizations
  310. $p->assign(
  311. array(
  312. // text
  313. 'header' => $pLang['coInstallGame_header'],
  314. 'fileName_text' => $pLang['coInstallGameFileName_text'],
  315. 'game' => $games,
  316. // task
  317. 'task' => 'install_game',
  318. // buttons
  319. 'reset' => $pLang['reset'],
  320. 'submit' => $pLang['submit'],
  321. // Zip support
  322. 'zip_support' => True
  323. )
  324. );
  325. if(empty($_FILES)) {
  326. // new form, we (re)set the session data
  327. SmartyValidate::connect($p, true);
  328. // display form
  329. $p->display(RAIDER_TEMPLATE_PATH.'configuration_install_game.tpl');
  330. } else {
  331. if (empty($_FILES['game_file']['error'])) {
  332. $_FILES['game_file']['error'] = 0;
  333. }
  334. if ($_FILES['game_file']['error'] == 0 && empty($_FILES['game_file']['tmp_name'])) {
  335. $_FILES['game_file']['error'] = 6;
  336. }
  337. if ($_FILES['game_file']['error'] == UPLOAD_ERR_OK) {
  338. // unzip file
  339. unzip($_FILES['game_file']['tmp_name'], RAIDER_GAME_BASE_PATH, true, false);
  340. // execute SQL file
  341. $sqlErrors = sqlFromFile(RAIDER_GAME_BASE_PATH.'install.sql', 'index.php?option=com_configuration');
  342. if ($sqlErrors) {
  343. if (is_array($sqlErrors)) {
  344. foreach ($sqlErrors as $sqlError) {
  345. printError($sqlError['error_message'].' with SQL:<strong>'.$sqlError['sql'].'</strong>');
  346. }
  347. } else {
  348. printError($sqlErrors);
  349. }
  350. }
  351. // remove SQL file
  352. unlink(RAIDER_GAME_BASE_PATH.'install.sql');
  353. } else {
  354. // Show error message.
  355. switch($_FILES['game_file']['error']){
  356. case UPLOAD_ERR_INI_SIZE:
  357. $errorMessage = sprintf($pLang['coInstallGame_error_upload'][$_FILES['game_file']['error']],get_cfg_var('upload_max_filesize'));
  358. break;
  359. case UPLOAD_ERR_FORM_SIZE:
  360. $errorMessage = sprintf($pLang['coInstallGame_error_upload'][$_FILES['game_file']['error']],$_POST['MAX_FILE_SIZE']);
  361. break;
  362. case UPLOAD_ERR_PARTIAL:
  363. $errorMessage = $pLang['coInstallGame_error_upload'][$_FILES['game_file']['error']];
  364. break;
  365. case UPLOAD_ERR_NO_FILE:
  366. $errorMessage = $pLang['coInstallGame_error_upload'][$_FILES['game_file']['error']];
  367. break;
  368. case UPLOAD_ERR_NO_TMP_DIR:
  369. case UPLOAD_ERR_CANT_WRITE:
  370. $uploadDir = get_cfg_var('upload_tmp_dir');
  371. $uploadDir = (empty($uploadDir)?getenv('temp'):$$uploadDir);
  372. $errorMessage = sprintf($pLang['coInstallGame_error_upload'][$_FILES['game_file']['error']], $uploadDir);
  373. break;
  374. case UPLOAD_ERR_EXTENSION:
  375. $errorMessage = $pLang['coInstallGame_error_upload'][$_FILES['game_file']['error']];
  376. break;
  377. default:
  378. $errorMessage = $pLang['coInstallGame_error_upload']['unknown'];
  379. } // switch
  380. printError($errorMessage);
  381. }
  382. }
  383. } else {
  384. // localizations
  385. $p->assign(
  386. array(
  387. // text
  388. 'header' => $pLang['coInstallGame_header'],
  389. 'zip_disabled' => $pLang['coGamesZipDisabled'],
  390. 'manual_installation' => sprintf($pLang['coGamesManualInstall'],RAIDER_GAME_BASE_PATH)
  391. )
  392. );
  393. // display form
  394. $p->display(RAIDER_TEMPLATE_PATH.'configuration_install_game.tpl');
  395. }
  396. } else {
  397. pRedirect('index.php?option=com_configuration');
  398. }
  399. } else {
  400. printError($pLang['invalidOption']);
  401. }
  402. ?>