add_document.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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;
  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;
  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($courseInfo, null, null, 0, false, '/', api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId);
  59. echo Display::page_subheader(get_lang('Documents'));
  60. echo $document_tree;
  61. echo '<hr /><div class="clear"></div>';
  62. } else {
  63. $message = null;
  64. $documentInfo = DocumentManager::get_document_data_by_id($docId, $courseInfo['code']);
  65. $form = new FormValidator('add_doc', 'post', api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&document_id='.$docId);
  66. $form->addElement('header', get_lang('AddDocument'));
  67. $form->addElement('hidden', 'add_doc', '1');
  68. $form->addElement('hidden', 'id', $workId);
  69. $form->addElement('hidden', 'document_id', $docId);
  70. $form->addElement('label', get_lang('File'), $documentInfo['title']);
  71. $form->addElement('style_submit_button', 'submit', get_lang('Add'));
  72. if ($form->validate()) {
  73. $values = $form->exportValues();
  74. $workId = $values['id'];
  75. $docId = $values['document_id'];
  76. $data = getDocumentToWork($docId, $workId, api_get_course_int_id());
  77. if (empty($data)) {
  78. addDocumentToWork($docId, $workId, api_get_course_int_id());
  79. $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId;
  80. header('Location: '.$url);
  81. exit;
  82. } else {
  83. $message = Display::return_message(get_lang('DocumentAlreadyAdded'), 'warning');
  84. }
  85. }
  86. Display :: display_header(null);
  87. echo $message;
  88. $form->display();
  89. }
  90. /*
  91. * DB changes needed
  92. *
  93. CREATE TABLE IF NOT EXISTS c_student_publication_rel_document (
  94. id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  95. work_id INT NOT NULL,
  96. document_id INT NOT NULL,
  97. c_id INT NOT NULL
  98. );
  99. CREATE TABLE IF NOT EXISTS c_student_publication_rel_user (
  100. id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  101. work_id INT NOT NULL,
  102. user_id INT NOT NULL,
  103. c_id INT NOT NULL
  104. );
  105. */