add_document.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. if (empty($workId)) {
  11. api_not_allowed(true);
  12. }
  13. $my_folder_data = get_work_data_by_id($workId);
  14. if (empty($my_folder_data)) {
  15. api_not_allowed(true);
  16. }
  17. $work_data = get_work_assignment_by_id($workId);
  18. if (!api_is_allowed_to_edit()) {
  19. api_not_allowed(true);
  20. }
  21. $courseInfo = api_get_course_info();
  22. $interbreadcrumb[] = array(
  23. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  24. 'name' => get_lang('StudentPublications'),
  25. );
  26. $interbreadcrumb[] = array(
  27. 'url' => api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq().'&id='.$workId,
  28. 'name' => $my_folder_data['title'],
  29. );
  30. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddDocument'));
  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. $documentTree = DocumentManager::get_document_preview(
  59. $courseInfo,
  60. null,
  61. null,
  62. api_get_session_id(),
  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 $documentTree;
  69. echo '<hr /><div class="clear"></div>';
  70. } else {
  71. $documentInfo = DocumentManager::get_document_data_by_id($docId, $courseInfo['code']);
  72. $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&document_id='.$docId.'&'.api_get_cidreq();
  73. $form = new FormValidator('add_doc', 'post', $url);
  74. $form->addElement('header', get_lang('AddDocument'));
  75. $form->addElement('hidden', 'add_doc', '1');
  76. $form->addElement('hidden', 'id', $workId);
  77. $form->addElement('hidden', 'document_id', $docId);
  78. $form->addElement('label', get_lang('File'), $documentInfo['title']);
  79. $form->addButtonCreate(get_lang('Add'));
  80. if ($form->validate()) {
  81. $values = $form->exportValues();
  82. $workId = $values['id'];
  83. $docId = $values['document_id'];
  84. $data = getDocumentToWork($docId, $workId, api_get_course_int_id());
  85. if (empty($data)) {
  86. addDocumentToWork($docId, $workId, api_get_course_int_id());
  87. Display::addFlash(Display::return_message(get_lang('Added'), 'success'));
  88. } else {
  89. Display::addFlash(Display::return_message(get_lang('DocumentAlreadyAdded'), 'warning'));
  90. }
  91. $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&'.api_get_cidreq();
  92. header('Location: '.$url);
  93. exit;
  94. }
  95. Display::display_header(null);
  96. $form->display();
  97. }