syncparams.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $cidReset = true;
  4. require_once __DIR__.'/../../../main/inc/global.inc.php';
  5. api_protect_admin_script();
  6. $action = isset($_GET['what']) ? $_GET['what'] : '';
  7. define('CHAMILO_INTERNAL', true);
  8. $plugin = VChamiloPlugin::create();
  9. $thisUrl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php';
  10. if ($action) {
  11. require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/syncparams.controller.php';
  12. }
  13. $settings = api_get_settings();
  14. $table = new HTML_Table(['class' => 'table']);
  15. $column = 0;
  16. $row = 0;
  17. $headers = [
  18. '',
  19. $plugin->get_lang('variable').' ['.$plugin->get_lang('subkey').']',
  20. $plugin->get_lang('category'),
  21. $plugin->get_lang('accessurl'),
  22. $plugin->get_lang('value'),
  23. '',
  24. ];
  25. $attrs = ['center' => 'left'];
  26. $table->addRow($headers, $attrs, 'th');
  27. foreach ($settings as $param) {
  28. if ($param['subkey'] == 'vchamilo') {
  29. continue;
  30. }
  31. $check = '';
  32. $attrs = ['center' => 'left'];
  33. $syncButton = '
  34. <input class="btn btn-default" type="button" name="syncthis"
  35. value="'.$plugin->get_lang('syncthis').'" onclick="ajax_sync_setting(\''.$param['id'].'\')" />
  36. <span id="res_'.$param['id'].'"></span>';
  37. $data = [
  38. $check,
  39. isset($param['subkey']) && !empty($param['subkey']) ? $param['variable'].' ['.$param['subkey'].']' : $param['variable'],
  40. $param['category'],
  41. $param['access_url'],
  42. '<input type="text" disabled name="value_'.$param['id'].'"
  43. value="'.htmlspecialchars($param['selected_value'], ENT_COMPAT, 'UTF-8').'" />'.
  44. '<br />Master value: '.$param['selected_value'],
  45. $syncButton,
  46. ];
  47. $row = $table->addRow($data, $attrs, 'td');
  48. $table->setRowAttributes($row, ['id' => 'row_'.$param['id']], true);
  49. }
  50. $content = '<form name="settingsform" action="'.$thisUrl.'">';
  51. $content .= '<input type="hidden" name="what" value="" />';
  52. $content .= $table->toHtml();
  53. $content .= '</form>';
  54. Display::addFlash(Display::return_message($plugin->get_lang('Sync your master settings to all instances.')));
  55. $interbreadcrumb[] = ['url' => 'manage.php', 'name' => get_lang('VChamilo')];
  56. $htmlHeadXtra[] = "<script>
  57. function ajax_sync_setting(settingid) {
  58. var webUrl = '".api_get_path(WEB_PATH)."';
  59. var spare = $('#row_'+settingid).html();
  60. var formobj = document.forms['settingsform'];
  61. var url = webUrl + 'plugin/vchamilo/ajax/service.php?what=syncthis&settingid='+settingid+'&value='+encodeURIComponent(formobj.elements['value_'+settingid].value);
  62. $('#row_'+settingid).html('<td colspan=\"7\"><img src=\"'+webUrl+'plugin/vchamilo/pix/ajax_waiter.gif\" /></td>');
  63. $.get(url, function (data) {
  64. $('#row_'+settingid).html(spare);
  65. $('#res_'+settingid).html(data);
  66. });
  67. }
  68. </script>";
  69. $tpl = new Template($plugin->get_lang('SyncSettings'), true, true, false, true, false);
  70. $tpl->assign('content', $content);
  71. $tpl->display_one_col_template();