editinstance.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $cidReset = true;
  4. define('CHAMILO_INTERNAL', true);
  5. global $plugin;
  6. require_once __DIR__.'/../../../main/inc/global.inc.php';
  7. require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/editinstance_form.php';
  8. api_protect_admin_script();
  9. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/js/host_form.js" type="text/javascript" language="javascript"></script>';
  10. // get parameters
  11. $id = isset($_REQUEST['vid']) ? $_REQUEST['vid'] : '';
  12. $action = isset($_REQUEST['what']) ? $_REQUEST['what'] : '';
  13. $registeronly = isset($_REQUEST['registeronly']) ? $_REQUEST['registeronly'] : 0;
  14. $plugin = VChamiloPlugin::create();
  15. $thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php';
  16. if ($id) {
  17. $mode = 'update';
  18. } else {
  19. $mode = $registeronly ? 'register' : 'add';
  20. }
  21. $vhost = (array) Virtual::getInstance($id);
  22. $form = new InstanceForm($plugin, $mode, $vhost);
  23. if ($data = $form->get_data()) {
  24. switch ($data->what) {
  25. case 'addinstance':
  26. case 'registerinstance':
  27. Virtual::addInstance($data);
  28. echo '<a class="btn btn-primary" href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'.'">Continue</a>';
  29. exit;
  30. break;
  31. case 'updateinstance':
  32. unset($data->what);
  33. unset($data->submitbutton);
  34. unset($data->registeronly);
  35. unset($data->template);
  36. $data->lastcron = 0;
  37. $data->lastcrongap = 0;
  38. $data->croncount = 0;
  39. $id = $data->vid;
  40. unset($data->vid);
  41. unset($data->testconnection);
  42. unset($data->testdatapath);
  43. unset($data->vid);
  44. Database::update('vchamilo', (array) $data, ['id = ?' => $id], false);
  45. Display::addFlash(Display::return_message(get_lang('Updated')));
  46. Virtual::redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
  47. break;
  48. }
  49. }
  50. if ($id) {
  51. $vhost['vid'] = $vhost['id'];
  52. unset($vhost['id']);
  53. $form->set_data($vhost);
  54. } else {
  55. $vhost['db_host'] = 'localhost';
  56. $vhost['registeronly'] = $registeronly;
  57. $form->set_data($vhost);
  58. }
  59. $content = $form->return_form();
  60. $interbreadcrumb[] = ['url' => 'manage.php', 'name' => get_lang('VChamilo')];
  61. $tpl = new Template(get_lang('Instance'), true, true, false, true, false);
  62. $tpl->assign('content', $content);
  63. $tpl->display_one_col_template();