/mods/_core/themes/theme_install_step_2.php

https://github.com/harriswong/ATutor · PHP · 99 lines · 65 code · 16 blank · 18 comment · 21 complexity · ff057ba9a2ab140f5d22cbcb13111f21 MD5 · raw file

  1. <?php
  2. /************************************************************************/
  3. /* ATutor */
  4. /************************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* Inclusive Design Institute */
  7. /* http://atutor.ca */
  8. /* */
  9. /* This program is free software. You can redistribute it and/or */
  10. /* modify it under the terms of the GNU General Public License */
  11. /* as published by the Free Software Foundation. */
  12. /************************************************************************/
  13. // $Id:
  14. define('AT_INCLUDE_PATH', '../../../include/');
  15. require(AT_INCLUDE_PATH.'vitals.inc.php');
  16. admin_authenticate(AT_ADMIN_PRIV_ADMIN);
  17. require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');
  18. require(AT_INCLUDE_PATH . '../mods/_core/themes/classes/ThemeParser.class.php');
  19. // theme content folder
  20. $theme_content_folder = AT_CONTENT_DIR . "theme/";
  21. if (isset($_GET["theme"])) $theme = str_replace(array('.','..'), '', $_GET['theme']);
  22. else if (isset($_POST["theme"])) $theme = $_POST["theme"];
  23. if (isset($_GET["title"])) $title = $_GET['title'];
  24. else if (isset($_POST["title"])) $title = $_POST["title"];
  25. if (isset($_GET["permission_granted"])) $permission_granted = $_GET["permission_granted"];
  26. else if (isset($_POST["permission_granted"])) $permission_granted = $_POST["permission_granted"];
  27. // copy theme from content folder into themes folder
  28. if (isset($_GET["theme"]))
  29. {
  30. copys($theme_content_folder.$theme, '../../../themes/'.$theme);
  31. $theme_xml = @file_get_contents('../../../themes/'.$theme . '/theme_info.xml');
  32. //Check if XML file exists (if it doesnt send error and clear directory)
  33. if ($theme_xml == false)
  34. {
  35. $version = '1.4.x';
  36. $extra_info = 'unspecified';
  37. }
  38. else
  39. {
  40. //parse information
  41. $xml_parser = new ThemeParser();
  42. $xml_parser->parse($theme_xml);
  43. $version = $xml_parser->theme_rows['version'];
  44. $type = $xml_parser->theme_rows['type'];
  45. $extra_info = $xml_parser->theme_rows['extra_info'];
  46. }
  47. if ($title == '') $title = str_replace('_', ' ', $theme);
  48. $last_updated = date('Y-m-d');
  49. $status = '1';
  50. //if version number is not compatible with current Atutor version, set theme as disabled
  51. if ($version != VERSION) $status = '0';
  52. //save information in database
  53. $sql = "INSERT INTO ".TABLE_PREFIX."themes (title, version, dir_name, type, last_updated, extra_info, status) ".
  54. "VALUES ('$title', '$version', '$theme', '$type', '$last_updated', '$extra_info', '$status')";
  55. $result = mysql_query($sql, $db);
  56. write_to_log(AT_ADMIN_LOG_INSERT, 'themes', mysql_affected_rows($db), $sql);
  57. }
  58. if (!$result) // error occurs
  59. {
  60. clr_dir("../../themes/".$theme);
  61. if ($_GET['permission_granted']==1)
  62. {
  63. header('Location: '.AT_BASE_HREF.'mods/_core/themes/theme_install_step_3.php?error=1');
  64. }
  65. else
  66. {
  67. $msg->addError('IMPORT_FAILED');
  68. header('Location: '.AT_BASE_HREF.'mods/_core/themes/install_themes.php');
  69. }
  70. }
  71. else // successful
  72. {
  73. if ($_GET['permission_granted']==1)
  74. {
  75. header('Location: '.AT_BASE_HREF.'mods/_core/themes/theme_install_step_3.php?installed=1');
  76. }
  77. else
  78. {
  79. $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
  80. header('Location: '.AT_BASE_HREF.'mods/_core/themes/index.php');
  81. }
  82. }
  83. ?>