lp_add.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is a learning path creation and player tool in Chamilo - previously learnpath_handler.php
  5. *
  6. * @author Patrick Cool
  7. * @author Denes Nagy
  8. * @author Roan Embrechts, refactoring and code cleaning
  9. * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update for new SCORM tool
  10. * @author Julio Montoya <gugli100@gmail.com> Adding formvalidator support
  11. *
  12. * @package chamilo.learnpath
  13. */
  14. /* INIT SECTION */
  15. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  16. $this_section = SECTION_COURSES;
  17. api_protect_course_script();
  18. /* Libraries */
  19. // The main_api.lib.php, database.lib.php and display.lib.php
  20. // libraries are included by default.
  21. require 'learnpath_functions.inc.php';
  22. //include '../resourcelinker/resourcelinker.inc.php';
  23. require 'resourcelinker.inc.php';
  24. // Rewrite the language file, sadly overwritten by resourcelinker.inc.php.
  25. // Name of the language file that needs to be included.
  26. $language_file = 'learnpath';
  27. /* Header and action code */
  28. $currentstyle = api_get_setting('stylesheets');
  29. //$htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_CODE_PATH).'css/'.$currentstyle.'/learnpath.css"/>';
  30. //$htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="learnpath.css" />'; //will be a merged with original learnpath.css
  31. $htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="dtree.css" />'; //will be moved
  32. $htmlHeadXtra[] = '<script type="text/javascript">
  33. function setFocus(){
  34. $("#learnpath_title").focus();
  35. }
  36. $(document).ready(function () {
  37. setFocus();
  38. });
  39. function timelimit() {
  40. if(document.getElementById(\'options2\').style.display == \'none\')
  41. {
  42. document.getElementById(\'options2\').style.display = \'block\';
  43. } else {
  44. document.getElementById(\'options2\').style.display = \'none\';
  45. }
  46. }
  47. </script>';
  48. /* Constants and variables */
  49. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  50. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  51. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  52. $tbl_lp_view = Database::get_course_table(TABLE_LP_VIEW);
  53. $isStudentView = (int) $_REQUEST['isStudentView'];
  54. $learnpath_id = (int) $_REQUEST['lp_id'];
  55. $submit = $_POST['submit_button'];
  56. /* MAIN CODE */
  57. // Using the resource linker as a tool for adding resources to the learning path.
  58. if ($action == 'add' && $type == 'learnpathitem') {
  59. $htmlHeadXtra[] = "<script language='JavaScript' type='text/javascript'> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
  60. }
  61. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  62. error_log('New LP - User not authorized in lp_add.php');
  63. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  64. }
  65. // From here on, we are admin because of the previous condition, so don't check anymore.
  66. $sql_query = "SELECT * FROM $tbl_lp WHERE id = $learnpath_id";
  67. $result = Database::query($sql_query);
  68. $therow = Database::fetch_array($result);
  69. /*
  70. Course admin section
  71. - all the functions not available for students - always available in this case (page only shown to admin)
  72. */
  73. if (isset($_SESSION['gradebook'])){
  74. $gradebook = $_SESSION['gradebook'];
  75. }
  76. if (!empty($gradebook) && $gradebook=='view') {
  77. $interbreadcrumb[]= array (
  78. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  79. 'name' => get_lang('ToolGradebook')
  80. );
  81. }
  82. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  83. Display::display_header(get_lang('_add_learnpath'), 'Path');
  84. echo '<div class="actions">';
  85. echo '<a href="lp_controller.php?cidReq='.$_course['sysCode'].'">'.Display::return_icon('back.png', get_lang('ReturnToLearningPaths'),'','32').'</a>';
  86. echo '</div>';
  87. Display::display_normal_message(get_lang('AddLpIntro'), false);
  88. if ($_POST AND empty($_REQUEST['lp_name'])) {
  89. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'), false);
  90. }
  91. $form = new FormValidator('lp_add', 'post', 'lp_controller.php');
  92. // Form title
  93. $form->addElement('header', null, get_lang('AddLpToStart'));
  94. // Title
  95. $form->addElement('text', 'lp_name', api_ucfirst(get_lang('LPName')), array('size' => 43));
  96. $form->applyFilter('lp_name', 'html_filter');
  97. $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
  98. $form->addElement('hidden', 'post_time', time());
  99. $form->addElement('hidden', 'action', 'add_lp');
  100. $form->addElement('checkbox', 'enabletimelimit',get_lang('EnableTimeLimits'),null,'onclick = " return timelimit() "');
  101. $form->addElement('html','<div id="options2" style="display:none;">');
  102. $form->addElement('datepicker', 'publicated_on', get_lang('PublicationDate'), array('form_name'=>'exercise_admin'), 5);
  103. $form->addElement('datepicker', 'expired_on', get_lang('ExpirationDate'), array('form_name'=>'exercise_admin'), 5);
  104. $form->addElement('html','</div>');
  105. $defaults['publicated_on'] = date('Y-m-d 12:00:00');
  106. $defaults['expired_on'] = date('Y-m-d 12:00:00',time()+84600);
  107. $form->setDefaults($defaults);
  108. $form->addElement('style_submit_button', 'Submit',get_lang('CreateLearningPath'),'class="save"');
  109. $form->display();
  110. // Footer
  111. Display::display_footer();