api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(), 'name' => get_lang('StudentPublications'));
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq().'&id='.$workId, 'name' => $my_folder_data['title']);
$interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddDocument'));
$error_message = null;
switch ($action) {
case 'delete':
if (!empty($workId) && !empty($docId)) {
deleteDocumentToWork($docId, $workId, api_get_course_int_id());
$url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId;
header('Location: '.$url);
exit;
}
break;
}
Display :: display_header(null);
if (empty($docId)) {
$documents = getAllDocumentToWork($workId, api_get_course_int_id());
if (!empty($documents)) {
echo Display::page_subheader(get_lang('DocumentsAdded'));
echo '
';
foreach ($documents as $doc) {
$documentId = $doc['document_id'];
$docData = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
if ($docData) {
$url = api_get_path(WEB_CODE_PATH).'work/add_document.php?action=delete&id='.$workId.'&document_id='.$documentId;
$link = Display::url(get_lang('Delete'), $url);
echo $docData['title'].' '.$link.'
';
}
}
echo '
';
}
$document_tree = DocumentManager::get_document_preview($courseInfo, null, null, 0, false, '/', api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId);
echo Display::page_subheader(get_lang('Documents'));
echo $document_tree;
echo '
';
} else {
$documentInfo = DocumentManager::get_document_data_by_id($docId, $courseInfo['code']);
$form = new FormValidator('add_doc', 'post', api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&document_id='.$docId);
$form->addElement('header', get_lang('AddDocument'));
$form->addElement('hidden', 'add_doc', '1');
$form->addElement('hidden', 'id', $workId);
$form->addElement('hidden', 'document_id', $docId);
$form->addElement('label', get_lang('File'), $documentInfo['title']);
$form->addElement('style_submit_button', 'submit', get_lang('Add'));
$form->display();
if ($form->validate()) {
$values = $form->exportValues();
$workId = $values['id'];
$docId = $values['document_id'];
$data = getDocumentToWork($docId, $workId, api_get_course_int_id());
if (empty($data)) {
addDocumentToWork($docId, $workId, api_get_course_int_id());
$url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId;
header('Location: '.$url);
exit;
} else {
Display::display_warning_message(get_lang('DocumentAlreadyAdded'));
}
}
}
/*
*
CREATE TABLE IF NOT EXISTS c_student_publication_rel_document (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
work_id INT NOT NULL,
document_id INT NOT NULL,
c_id INT NOT NULL
);
CREATE TABLE IF NOT EXISTS c_student_publication_rel_user (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
work_id INT NOT NULL,
user_id INT NOT NULL,
c_id INT NOT NULL
);
*/