syncparams.php 3.0 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(array('class' => 'data_table', 'width' => '100%'));
  15. $column = 0;
  16. $row = 0;
  17. $headers = array(
  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 = array('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 = array('center' => 'left');
  33. $syncButton = '
  34. <input class="btn btn-default" type="button" name="syncthis" value="'.$plugin->get_lang('syncthis').'" onclick="ajax_sync_setting(\''.$param['id'].'\')" />
  35. <span id="res_'.$param['id'].'"></span>';
  36. $data = array(
  37. $check,
  38. isset($param['subkey']) && !empty($param['subkey']) ? $param['variable'].' ['.$param['subkey'].']' : $param['variable'],
  39. $param['category'],
  40. $param['access_url'],
  41. '<input type="text" disabled name="value_'.$param['id'].'" value="'.htmlspecialchars($param['selected_value'], ENT_COMPAT, 'UTF-8').'" />'.
  42. '<br />Master value: '.$param['selected_value'],
  43. $syncButton,
  44. );
  45. $row = $table->addRow($data, $attrs, 'td');
  46. $table->setRowAttributes($row, array('id' => 'row_'.$param['id']), true);
  47. }
  48. $content = '<form name="settingsform" action="'.$thisurl.'">';
  49. $content .= '<input type="hidden" name="what" value="" />';
  50. $content .= $table->toHtml();
  51. $content .= '</form>';
  52. Display::addFlash(Display::return_message($plugin->get_lang('Sync your master settings to all instances.')));
  53. $interbreadcrumb[] = array('url' => 'manage.php', 'name' => get_lang('VChamilo'));
  54. $htmlHeadXtra[] = "<script>
  55. function ajax_sync_setting(settingid) {
  56. var webUrl = '".api_get_path(WEB_PATH)."';
  57. var spare = $('#row_'+settingid).html();
  58. var formobj = document.forms['settingsform'];
  59. var url = webUrl + 'plugin/vchamilo/ajax/service.php?what=syncthis&settingid='+settingid+'&value='+encodeURIComponent(formobj.elements['value_'+settingid].value);
  60. $('#row_'+settingid).html('<td colspan=\"7\"><img src=\"'+webUrl+'plugin/vchamilo/pix/ajax_waiter.gif\" /></td>');
  61. $.get(url, function (data) {
  62. $('#row_'+settingid).html(spare);
  63. $('#res_'+settingid).html(data);
  64. });
  65. }
  66. </script>";
  67. $tpl = new Template($plugin->get_lang('SyncSettings'), true, true, false, true, false);
  68. $tpl->assign('content', $content);
  69. $tpl->display_one_col_template();