course_add.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. use Chamilo\CoreBundle\Framework\Container;
  7. use Chamilo\CoreBundle\Entity\Course;
  8. use Chamilo\CoreBundle\Form\CourseType;
  9. $cidReset = true;
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. api_protect_admin_script();
  12. $tool_name = get_lang('AddCourse');
  13. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  14. $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
  15. /* MAIN CODE */
  16. global $_configuration;
  17. $group = Container::getGroupManager()->findGroupByName('teachers');
  18. $teachers = array();
  19. $users = $group->getUsers();
  20. /** @var Chamilo\UserBundle\Entity\User $user */
  21. foreach ($users as $user) {
  22. $teachers[$user->getId()] = $user->getCompleteName();
  23. }
  24. // Build the form.
  25. $form = new FormValidator('update_course');
  26. $form->addElement('header', $tool_name);
  27. // Title
  28. $form->add_textfield('title', get_lang('Title'), true, array ('class' => 'span6'));
  29. $form->applyFilter('title', 'html_filter');
  30. $form->applyFilter('title', 'trim');
  31. // Code
  32. $form->add_textfield('visual_code', array(get_lang('CourseCode'), get_lang('OnlyLettersAndNumbers')) , false, array('class' => 'span3', 'maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE));
  33. $form->applyFilter('visual_code', 'api_strtoupper');
  34. $form->applyFilter('visual_code', 'html_filter');
  35. $form->addRule('visual_code', get_lang('Max'), 'maxlength', CourseManager::MAX_COURSE_LENGTH_CODE);
  36. $form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, ' id="course_teachers" class="chzn-select" style="width:350px" multiple="multiple" ');
  37. $form->applyFilter('course_teachers', 'html_filter');
  38. //This function fills the category_code select ...
  39. $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
  40. $form->addElement(
  41. 'select_ajax',
  42. 'category_code',
  43. get_lang('CourseFaculty'),
  44. null,
  45. array(
  46. 'url' => $url
  47. // 'formatResult' => 'function(item) { return item.name + "'" +item.code; }'
  48. )
  49. );
  50. // Course department
  51. $form->add_textfield('department_name', get_lang('CourseDepartment'), false, array ('size' => '60'));
  52. $form->applyFilter('department_name', 'html_filter');
  53. $form->applyFilter('department_name', 'trim');
  54. // Department URL
  55. $form->add_textfield('department_url', get_lang('CourseDepartmentURL'), false, array ('size' => '60'));
  56. $form->applyFilter('department_url', 'html_filter');
  57. $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));
  58. $form->applyFilter('select_language', 'html_filter');
  59. $form->addElement('checkbox', 'exemplary_content', '', get_lang('FillWithExemplaryContent'));
  60. $group = array();
  61. $group[]= $form->createElement('radio', 'visibility', get_lang('CourseAccess'), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  62. $group[]= $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  63. $group[]= $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  64. $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  65. $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
  66. $form->addGroup($group,'', get_lang('CourseAccess'), '<br />');
  67. $group = array();
  68. $group[]= $form->createElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  69. $group[]= $form->createElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  70. $form->addGroup($group,'', get_lang('Subscription'), '<br />');
  71. $group = array();
  72. $group[]= $form->createElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  73. $group[]= $form->createElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  74. $form->addGroup($group,'', get_lang('Unsubscription'), '<br />');
  75. $form->addElement('text','disk_quota',array(get_lang('CourseQuota'), null, get_lang('MB')));
  76. $form->addRule('disk_quota', get_lang('ThisFieldShouldBeNumeric'), 'numeric');
  77. $obj = new GradeModel();
  78. $obj->fill_grade_model_select_in_form($form);
  79. $form->add_progress_bar();
  80. $form->addElement('style_submit_button', 'submit', get_lang('CreateCourse'), 'class="add"');
  81. // Set some default values.
  82. $values['course_language'] = Container::getTranslator()->getLocale();
  83. // api_get_setting('platformLanguage');
  84. $values['disk_quota'] = round(api_get_setting('document.default_document_quotum')/1024/1024, 1);
  85. $default_course_visibility = api_get_setting('course.courses_default_creation_visibility');
  86. if (isset($default_course_visibility)) {
  87. $values['visibility'] = api_get_setting('course.courses_default_creation_visibility');
  88. } else {
  89. $values['visibility'] = COURSE_VISIBILITY_OPEN_PLATFORM;
  90. }
  91. $values['subscribe'] = 1;
  92. $values['unsubscribe'] = 0;
  93. $form->setDefaults($values);
  94. /*
  95. // Validate the form
  96. if ($form->validate()) {
  97. $course = $form->exportValues();
  98. //$teacher_id = $course['tutor_id'];
  99. $course_teachers = isset($course['course_teachers']) ? $course['course_teachers'] : array();
  100. $course['disk_quota'] = $course['disk_quota']*1024*1024;
  101. $course['exemplary_content'] = empty($course['exemplary_content']) ? false : true;
  102. $course['teachers'] = $course_teachers;
  103. //$course['user_id'] = $teacher_id;
  104. $course['wanted_code'] = $course['visual_code'];
  105. $course['gradebook_model_id'] = isset($course['gradebook_model_id']) ? $course['gradebook_model_id'] : null;
  106. // Fixing category code
  107. $course['course_category'] = $course['category_code'];
  108. $course_info = CourseManager::create_course($course);
  109. header('Location: course_list.php'.($course_info===false?'?action=show_msg&warn='.api_get_last_failure():''));
  110. exit;
  111. }*/
  112. // Display the form.
  113. $content = $form->return_form();
  114. //echo $content;
  115. $em = Container::getEntityManager();
  116. $request = Container::getRequest();
  117. $course = new Course();
  118. $builder = Container::getFormFactory()->createBuilder(
  119. new CourseType(),
  120. $course
  121. );
  122. $form = $builder->getForm();
  123. $form->handleRequest($request);
  124. if ($form->isValid()) {
  125. $course = $form->getData();
  126. $em->persist($course);
  127. $em->flush();
  128. Container::addFlash(get_lang('Updated'));
  129. $url = Container::getRouter()->generate(
  130. 'main',
  131. array('name' => 'admin/course_list.php')
  132. );
  133. header('Location: '.$url);
  134. exit;
  135. }
  136. echo Container::getTemplate()->render(
  137. 'ChamiloCoreBundle:Legacy:form.html.twig',
  138. array(
  139. 'form' => $form->createView(),
  140. 'url' => api_get_self()
  141. )
  142. );