SettingsEditor.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. class SettingsEditor extends Controller {
  3. const KEY_SPLITTER='|';
  4. public function Index() {
  5. $data=parse_ini_file(ApplicationSettings::SETTINGS_PATH,true);
  6. return new View("SettingsEditor/index.view",array("data"=>$data));
  7. }
  8. public function Save($params) {
  9. $newSettings=array();
  10. foreach ($params as $param=>$value){
  11. if (strpos($param, self::KEY_SPLITTER)===false)
  12. continue;
  13. $setting=explode(self::KEY_SPLITTER, $param);
  14. $section=$setting[0];
  15. $key=$setting[1];
  16. if (!isset($newSettings[$section]))
  17. $newSettings[$section]=array();
  18. $newSettings[$section][$key]=$value;
  19. }
  20. $currentSettings=parse_ini_file(ApplicationSettings::SETTINGS_PATH,true);
  21. foreach ($currentSettings as $section=>$setting){
  22. if (!isset($newSettings[$section])){
  23. $newSettings[$section]=$setting;
  24. continue;
  25. }
  26. foreach ($setting as $key=>$value)
  27. if (!isset($newSettings[$section][$key]))
  28. $newSettings[$section][$key]=$value;
  29. }
  30. rename(ApplicationSettings::SETTINGS_PATH, ApplicationSettings::SETTINGS_PATH.(int)microtime(true));
  31. Utils::WriteINIFile($newSettings, ApplicationSettings::SETTINGS_PATH, true);
  32. header("location:/settingseditor");
  33. }
  34. }