settings2csv.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script generates a CSV file of all settings in the order they appear
  5. * in the platform settings section, in the given language.
  6. * This is meant to speed up the redaction of the admin guide.
  7. * Note: to obtain the default values for all settings, you need to run
  8. * this script on a freshly installed Chamilo setup with all options set
  9. * by default in the installation process.
  10. * @package chamilo.tests.scripts
  11. */
  12. /**
  13. * Init
  14. */
  15. // comment exit statement before executing
  16. exit;
  17. /* Usage doc */
  18. if ($argc <= 1) {
  19. echo 'Usage: php settings2csv.php [language]'.PHP_EOL;
  20. echo ' Where the language name is supported by Chamilo. e.g. french, spanish, ...'.PHP_EOL;
  21. echo ' (defaults to "english").'.PHP_EOL;
  22. echo ' The resulting filepath will appear on the output line'.PHP_EOL.PHP_EOL;
  23. }
  24. $language = 'english';
  25. if (!empty($argv[1])) {
  26. $language = $argv[1];
  27. }
  28. $_GET['language'] = $language;
  29. @require __DIR__ . '/../../main/inc/global.inc.php';
  30. // Categories, in order of appearance in the Chamilo settings page
  31. // Check the end of main/admin/settings.php for the initial list
  32. $categories = [
  33. 'Platform',
  34. 'Course',
  35. 'Session',
  36. 'Languages',
  37. 'User',
  38. 'Tools',
  39. 'Editor',
  40. 'Security',
  41. 'Tuning',
  42. 'Gradebook',
  43. 'Timezones',
  44. 'Tracking',
  45. 'Search',
  46. 'Stylesheets',
  47. 'Templates',
  48. 'Plugins',
  49. 'LDAP',
  50. 'CAS',
  51. 'Shibboleth',
  52. 'Facebook',
  53. 'Crons',
  54. 'WebServices',
  55. ];
  56. $fileName = 'settings'; // will be appended a ".csv" extension
  57. $fileContent = [];
  58. $fileContent[] = [
  59. 'Variable',
  60. 'Subkey',
  61. 'Comment',
  62. 'Current value'
  63. ];
  64. foreach ($categories as $category) {
  65. $fileContent[] = [
  66. '***** '.get_lang('Category', null, $language).': '.$category.' ****',
  67. '',
  68. '',
  69. ''
  70. ];
  71. $settings = api_get_settings($category, 'group');
  72. foreach ($settings as $setting) {
  73. $fileContent[] = [
  74. get_lang($setting['title'], null, $language),
  75. $setting['subkey'],
  76. get_lang($setting['comment'], null, $language),
  77. $setting['selected_value']
  78. ];
  79. }
  80. }
  81. $filePath = Export::arrayToCsv($fileContent, $fileName, true);
  82. echo "File generated and stored in $filePath".PHP_EOL;