editinstance.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $cidReset = true;
  4. define('CHAMILO_INTERNAL', true);
  5. global $plugin;
  6. require_once '../../../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. $coursePath = Virtual::getConfig('vchamilo', 'course_real_root');
  17. $homePath = Virtual::getConfig('vchamilo', 'home_real_root');
  18. if ($id) {
  19. $mode = 'update';
  20. } else {
  21. $mode = $registeronly ? 'register' : 'add' ;
  22. }
  23. $vhost = (array) Virtual::getInstance($id);
  24. $form = new InstanceForm($plugin, $mode, $vhost);
  25. if ($data = $form->get_data()) {
  26. switch ($data->what) {
  27. case 'addinstance':
  28. case 'registerinstance':
  29. Virtual::addInstance($data);
  30. echo '<a class="btn btn-primary" href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'.'">Continue</a>';
  31. // vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
  32. die;
  33. break;
  34. case 'updateinstance':
  35. unset($data->what);
  36. unset($data->submitbutton);
  37. unset($data->registeronly);
  38. unset($data->template);
  39. $data->lastcron = 0;
  40. $data->lastcrongap = 0;
  41. $data->croncount = 0;
  42. $id = $data->vid;
  43. unset($data->vid);
  44. unset($data->testconnection);
  45. unset($data->testdatapath);
  46. unset($data->vid);
  47. Database::update('vchamilo', (array) $data, array('id = ?' => $id), true);
  48. Display::addFlash(Display::return_message(get_lang('Updated')));
  49. Virtual::redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
  50. break;
  51. }
  52. }
  53. if ($id) {
  54. $vhost['vid'] = $vhost['id'];
  55. unset($vhost['id']);
  56. $form->set_data($vhost);
  57. } else {
  58. $vhost['db_host'] = 'localhost';
  59. $vhost['registeronly'] = $registeronly;
  60. $form->set_data($vhost);
  61. }
  62. $content = $form->return_form();
  63. $interbreadcrumb[] = array('url' => 'manage.php', 'name' => get_lang('VChamilo'));
  64. $tpl = new Template(get_lang('Instance'), true, true, false, true, false);
  65. $tpl->assign('content', $content);
  66. $tpl->display_one_col_template();