add_document.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. //require_once '../inc/global.inc.php';
  5. require_once 'work.lib.php';
  6. $current_course_tool = TOOL_STUDENTPUBLICATION;
  7. $workId = isset($_GET['id']) ? intval($_GET['id']) : null;
  8. $docId = isset($_GET['document_id']) ? intval($_GET['document_id']) : null;
  9. $action = isset($_GET['action']) ? $_GET['action'] : null;
  10. $message = Session::read('show_message');
  11. Session::erase('show_message');
  12. if (empty($workId)) {
  13. api_not_allowed(true);
  14. }
  15. $my_folder_data = get_work_data_by_id($workId);
  16. if (empty($my_folder_data)) {
  17. api_not_allowed(true);
  18. }
  19. $work_data = get_work_assignment_by_id($workId);
  20. if (!api_is_allowed_to_edit()) {
  21. api_not_allowed(true);
  22. }
  23. $courseInfo = api_get_course_info();
  24. $interbreadcrumb[] = array(
  25. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  26. 'name' => get_lang('StudentPublications'),
  27. );
  28. $interbreadcrumb[] = array(
  29. 'url' => api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq().'&id='.$workId,
  30. 'name' => $my_folder_data['title'],
  31. );
  32. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddDocument'));
  33. switch ($action) {
  34. case 'delete':
  35. if (!empty($workId) && !empty($docId)) {
  36. deleteDocumentToWork($docId, $workId, api_get_course_int_id());
  37. $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&'.api_get_cidreq();
  38. header('Location: '.$url);
  39. exit;
  40. }
  41. break;
  42. }
  43. if (empty($docId)) {
  44. Display :: display_header(null);
  45. echo $message;
  46. $documents = getAllDocumentToWork($workId, api_get_course_int_id());
  47. if (!empty($documents)) {
  48. echo Display::page_subheader(get_lang('DocumentsAdded'));
  49. echo '<div class="well">';
  50. foreach ($documents as $doc) {
  51. $documentId = $doc['document_id'];
  52. $docData = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
  53. if ($docData) {
  54. $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?action=delete&id='.$workId.'&document_id='.$documentId.'&'.api_get_cidreq();
  55. $link = Display::url(get_lang('Delete'), $url);
  56. echo $docData['title'].' '.$link.'<br />';
  57. }
  58. }
  59. echo '</div>';
  60. }
  61. $documentTree = DocumentManager::get_document_preview(
  62. $courseInfo,
  63. null,
  64. null,
  65. 0,
  66. false,
  67. '/',
  68. api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&'.api_get_cidreq()
  69. );
  70. echo Display::page_subheader(get_lang('Documents'));
  71. echo $documentTree;
  72. echo '<hr /><div class="clear"></div>';
  73. } else {
  74. $documentInfo = DocumentManager::get_document_data_by_id($docId, $courseInfo['code']);
  75. $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&document_id='.$docId.'&'.api_get_cidreq();
  76. $form = new FormValidator('add_doc', 'post', $url);
  77. $form->addElement('header', get_lang('AddDocument'));
  78. $form->addElement('hidden', 'add_doc', '1');
  79. $form->addElement('hidden', 'id', $workId);
  80. $form->addElement('hidden', 'document_id', $docId);
  81. $form->addElement('label', get_lang('File'), $documentInfo['title']);
  82. $form->addButtonCreate(get_lang('Add'));
  83. if ($form->validate()) {
  84. $values = $form->exportValues();
  85. $workId = $values['id'];
  86. $docId = $values['document_id'];
  87. $data = getDocumentToWork($docId, $workId, api_get_course_int_id());
  88. if (empty($data)) {
  89. addDocumentToWork($docId, $workId, api_get_course_int_id());
  90. $message = Display::return_message(get_lang('Added'), 'success');
  91. } else {
  92. $message = Display::return_message(get_lang('DocumentAlreadyAdded'), 'warning');
  93. }
  94. Session::write('show_message', $message);
  95. $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&'.api_get_cidreq();
  96. header('Location: '.$url);
  97. exit;
  98. }
  99. Display::display_header(null);
  100. echo $message;
  101. $form->display();
  102. }