add_document.php 3.9 KB

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