manage.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $cidReset = true;
  4. require_once __DIR__.'/../../../main/inc/global.inc.php';
  5. // Security
  6. api_protect_admin_script();
  7. Virtual::checkSettings();
  8. $action = isset($_GET['what']) ? $_GET['what'] : '';
  9. define('CHAMILO_INTERNAL', true);
  10. $plugin = VChamiloPlugin::create();
  11. $thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php';
  12. Virtual::requireJs('host_list.js', 'vchamilo', 'head');
  13. if ($action) {
  14. require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/manage.controller.php';
  15. }
  16. $query = "SELECT * FROM vchamilo";
  17. $result = Database::query($query);
  18. $instances = [];
  19. while ($instance = Database::fetch_object($result)) {
  20. $instances[$instance->id] = $instance;
  21. }
  22. $templates = Virtual::getAvailableTemplates();
  23. if (empty($templates)) {
  24. $url = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php?what=snapshotinstance';
  25. $url = Display::url($url, $url);
  26. Display::addFlash(
  27. Display::return_message('You need to create a snapshot of master first here:'.$url, 'info', false)
  28. );
  29. }
  30. $table = new HTML_Table(['class' => 'data_table']);
  31. $column = 0;
  32. $row = 0;
  33. // $table->set_additional_parameters($parameters);
  34. $headers = [
  35. '',
  36. $plugin->get_lang('sitename'),
  37. $plugin->get_lang('dbhost').' - '.get_lang('Database'),
  38. $plugin->get_lang('coursefolder'),
  39. $plugin->get_lang('enabled'),
  40. $plugin->get_lang('lastcron'),
  41. '',
  42. ];
  43. $attrs = ['center' => 'left'];
  44. $table->addRow($headers, $attrs, 'th');
  45. $i = 0;
  46. foreach ($instances as $instance) {
  47. $checkbox = '<input type="checkbox" class="vnodessel" name="vids[]" value="'.$instance->id.'" />';
  48. $sitelink = $instance->sitename;
  49. if ($instance->visible) {
  50. $status = '<a href="'.$thisurl.'?what=disableinstances&vids[]='.$instance->id.'" >
  51. '.Display::returnFontAwesomeIcon('toggle-on', 2).'</a>';
  52. } else {
  53. $status = '<a href="'.$thisurl.'?what=enableinstances&vids[]='.$instance->id.'" >
  54. '.Display::returnFontAwesomeIcon('toggle-off', 2).'</a>';
  55. }
  56. $cmd = '&nbsp;<a href="'.$thisurl.'?what=editinstance&vid='.$instance->id.'" title="'.$plugin->get_lang('edit').'">
  57. '.Display::returnFontAwesomeIcon('pencil', 2).'</a>';
  58. $cmd .= '&nbsp;<a href="'.$thisurl.'?what=snapshotinstance&vid='.$instance->id.'" title="'.$plugin->get_lang('snapshotinstance').'">
  59. '.Display::returnFontAwesomeIcon('camera', 2).'</a>';
  60. $cmd .= '<a href="'.$thisurl.'?what=upgrade&vids[]='.$instance->id.'" title="'.$plugin->get_lang('Upgrade').'">
  61. &nbsp;'.Display::returnFontAwesomeIcon('wrench', 2).' </a>';
  62. if (!$instance->visible) {
  63. $cmd .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="'.$thisurl.'?what=fulldeleteinstances&vids[]='.$instance->id.'" title="'.$plugin->get_lang('destroyinstances').'">
  64. &nbsp;'.Display::returnFontAwesomeIcon('remove', 2).' </a>';
  65. } else {
  66. $cmd .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="'.$thisurl.'?what=deleteinstances&vids[]='.$instance->id.'" title="'.$plugin->get_lang('deleteinstances').'">
  67. &nbsp;'.Display::returnFontAwesomeIcon('remove', 2).' </a>';
  68. }
  69. $crondate = $instance->lastcron ? date('r', $instance->lastcron) : '';
  70. $data = [
  71. $checkbox,
  72. $sitelink.' '.$instance->institution.' ('.Display::url($instance->root_web, $instance->root_web, ['target' => '_blank']).')',
  73. $instance->db_host.' - '.$instance->main_database,
  74. $instance->slug,
  75. $status,
  76. $crondate,
  77. $cmd,
  78. ];
  79. $attrs = ['center' => 'left'];
  80. $table->addRow($data, $attrs, 'td');
  81. $i++;
  82. }
  83. $items = [
  84. [
  85. 'url' => $thisurl.'?what=newinstance',
  86. 'content' => $plugin->get_lang('newinstance'),
  87. ],
  88. [
  89. 'url' => $thisurl.'?what=import',
  90. 'content' => $plugin->get_lang('ImportInstance'),
  91. ],
  92. [
  93. 'url' => $thisurl.'?what=snapshotinstance&vid=0',
  94. 'content' => $plugin->get_lang('snapshotmaster'),
  95. ],
  96. [
  97. 'url' => $thisurl.'?what=clearcache&vid=0',
  98. 'content' => $plugin->get_lang('clearmastercache'),
  99. ],
  100. [
  101. 'url' => api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/syncparams.php',
  102. 'content' => $plugin->get_lang('sync_settings'),
  103. ],
  104. [
  105. 'url' => api_get_path(WEB_CODE_PATH).'admin/configure_plugin.php?name=vchamilo',
  106. 'content' => get_lang('Settings'),
  107. ],
  108. ];
  109. $content = Display::page_header('VChamilo Instances');
  110. $content .= Display::actions($items);
  111. $content .= '<form action="'.$thisurl.'">';
  112. $content .= $table->toHtml();
  113. $selectionoptions = ['<option value="0" selected="selected">'.$plugin->get_lang('choose').'</option>'];
  114. $selectionoptions[] = '<option value="deleteinstances">'.$plugin->get_lang('deleteinstances').'</option>';
  115. $selectionoptions[] = '<option value="enableinstances">'.$plugin->get_lang('enableinstances').'</option>';
  116. $selectionoptions[] = '<option value="fulldeleteinstances">'.$plugin->get_lang(
  117. 'destroyinstances'
  118. ).'</option>';
  119. $selectionoptions[] = '<option value="clearcache">'.$plugin->get_lang('clearcache').'</option>';
  120. $selectionoptions[] = '<option value="setconfigvalue">'.$plugin->get_lang('setconfigvalue').'</option>';
  121. $selectionaction = '<select name="what" onchange="this.form.submit()">'.implode('', $selectionoptions).'</select>';
  122. $content .= '<div class="vchamilo-right"><div></div><div>
  123. <a href="javascript:selectallhosts()">'.$plugin->get_lang('selectall').'</a> -
  124. <a href="javascript:deselectallhosts()">'.$plugin->get_lang('selectnone').'</a> -
  125. &nbsp; - '.$plugin->get_lang('withselection').' '.$selectionaction.'</div></div>';
  126. $content .= '</form>';
  127. if (empty($templates)) {
  128. $content = '';
  129. }
  130. $tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
  131. $tpl->assign('content', $content);
  132. $tpl->display_one_col_template();