add_document.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
  5. require_once '../inc/global.inc.php';
  6. // Including necessary files
  7. require_once 'work.lib.php';
  8. if (ADD_DOCUMENT_TO_WORK == false) {
  9. exit;
  10. }
  11. $current_course_tool = TOOL_STUDENTPUBLICATION;
  12. $workId = isset($_GET['id']) ? intval($_GET['id']) : null;
  13. $docId = isset($_GET['document_id']) ? intval($_GET['document_id']) : null;
  14. $action = isset($_GET['action']) ? $_GET['action'] : null;
  15. if (empty($workId)) {
  16. api_not_allowed(true);
  17. }
  18. $my_folder_data = get_work_data_by_id($workId);
  19. if (empty($my_folder_data)) {
  20. api_not_allowed(true);
  21. }
  22. $work_data = get_work_assignment_by_id($workId);
  23. if (!api_is_allowed_to_edit()) {
  24. api_not_allowed(true);
  25. }
  26. $courseInfo = api_get_course_info();
  27. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(), 'name' => get_lang('StudentPublications'));
  28. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq().'&id='.$workId, 'name' => $my_folder_data['title']);
  29. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddDocument'));
  30. $error_message = null;
  31. switch ($action) {
  32. case 'delete':
  33. if (!empty($workId) && !empty($docId)) {
  34. deleteDocumentToWork($docId, $workId, api_get_course_int_id());
  35. $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&'.api_get_cidreq();
  36. header('Location: '.$url);
  37. exit;
  38. }
  39. break;
  40. }
  41. if (empty($docId)) {
  42. Display :: display_header(null);
  43. $documents = getAllDocumentToWork($workId, api_get_course_int_id());
  44. if (!empty($documents)) {
  45. echo Display::page_subheader(get_lang('DocumentsAdded'));
  46. echo '<div class="well">';
  47. foreach ($documents as $doc) {
  48. $documentId = $doc['document_id'];
  49. $docData = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
  50. if ($docData) {
  51. $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?action=delete&id='.$workId.'&document_id='.$documentId.'&'.api_get_cidreq();
  52. $link = Display::url(get_lang('Delete'), $url);
  53. echo $docData['title'].' '.$link.'<br />';
  54. }
  55. }
  56. echo '</div>';
  57. }
  58. $document_tree = DocumentManager::get_document_preview(
  59. $courseInfo,
  60. null,
  61. null,
  62. 0,
  63. false,
  64. '/',
  65. api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&'.api_get_cidreq()
  66. );
  67. echo Display::page_subheader(get_lang('Documents'));
  68. echo $document_tree;
  69. echo '<hr /><div class="clear"></div>';
  70. } else {
  71. $message = null;
  72. $documentInfo = DocumentManager::get_document_data_by_id($docId, $courseInfo['code']);
  73. $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&document_id='.$docId.'&'.api_get_cidreq();
  74. $form = new FormValidator('add_doc', 'post', $url);
  75. $form->addElement('header', get_lang('AddDocument'));
  76. $form->addElement('hidden', 'add_doc', '1');
  77. $form->addElement('hidden', 'id', $workId);
  78. $form->addElement('hidden', 'document_id', $docId);
  79. $form->addElement('label', get_lang('File'), $documentInfo['title']);
  80. $form->addElement('style_submit_button', 'submit', get_lang('Add'));
  81. if ($form->validate()) {
  82. $values = $form->exportValues();
  83. $workId = $values['id'];
  84. $docId = $values['document_id'];
  85. $data = getDocumentToWork($docId, $workId, api_get_course_int_id());
  86. if (empty($data)) {
  87. addDocumentToWork($docId, $workId, api_get_course_int_id());
  88. $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&'.api_get_cidreq();
  89. header('Location: '.$url);
  90. exit;
  91. } else {
  92. $message = Display::return_message(get_lang('DocumentAlreadyAdded'), 'warning');
  93. }
  94. }
  95. Display::display_header(null);
  96. echo $message;
  97. $form->display();
  98. }
  99. /**
  100. * DB changes needed for new features in work tool
  101. *
  102. *
  103. * 1. Create tables
  104. *
  105. CREATE TABLE IF NOT EXISTS c_student_publication_rel_document (
  106. id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  107. work_id INT NOT NULL,
  108. document_id INT NOT NULL,
  109. c_id INT NOT NULL
  110. );
  111. CREATE TABLE IF NOT EXISTS c_student_publication_rel_user (
  112. id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  113. work_id INT NOT NULL,
  114. user_id INT NOT NULL,
  115. c_id INT NOT NULL
  116. );
  117. CREATE TABLE IF NOT EXISTS c_student_publication_comment (id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, work_id INT NOT NULL, c_id INT NOT NULL, comment text, user_id int NOT NULL, sent_at datetime NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  118. ALTER TABLE c_student_publication ADD COLUMN document_id int DEFAULT 0;
  119. *
  120. * Update configuration.php:
  121. * $_configuration['add_document_to_work'] = true;
  122. *
  123. */