// common docs if (!$common_doc_visible and !$is_admin) { // hide links to invisible common docs to non-admins continue; } $path = $real_path; } else { $path = $basedir . $row->path; } if (!$real_path and $row->extra_path) { // external file $size = 0; } else { $size = file_exists($path) ? filesize($path) : 0; } $fileinfo[] = array('is_dir' => $row->format == '.dir', 'size' => $size, 'title' => $row->title, 'filename' => $row->filename, 'format' => $row->format, 'path' => $row->path, 'extra_path' => $row->extra_path, 'visible' => $row->visible == 1, 'public' => $row->public, 'comment' => $row->comment, 'copyrighted' => $row->copyrighted, 'date' => $row->date_modified, 'object' => MediaResourceFactory::initFromDocument($row), 'editable' => $row->editable); } // end of common to teachers and students // ---------------------------------------------- // Display // ---------------------------------------------- $cmdCurDirPath = rawurlencode($curDirPath); $cmdParentDir = rawurlencode($parentDir); if ($can_upload) { // Action result message if (!empty($action_message)) { $tool_content .= $action_message; } // available actions if (!$is_in_tinymce) { if (isset($_GET['rename'])) {
/** * @brief display resource documents * @global type $is_editor * @global type $course_id * @global type $langWasDeleted * @global type $urlServer * @global type $id * @global type $course_code * @param type $title * @param type $comments * @param type $resource_id * @param type $file_id * @return string */ function show_doc($title, $comments, $resource_id, $file_id) { global $is_editor, $course_id, $langWasDeleted, $head_content, $urlServer, $id, $course_code; $file = Database::get()->querySingle("SELECT * FROM document WHERE course_id = ?d AND id = ?d", $course_id, $file_id); if (!$file) { if (!$is_editor) { return ''; } $status = 'del'; $image = 'fa-times'; $link = "<span class='not_visible'>" . q($title) . " ($langWasDeleted)</span>"; } else { $status = $file->visible; if (!$is_editor and ( !resource_access($file->visible, $file->public))) { return ''; } if ($file->format == '.dir') { $image = 'fa-folder-o'; $download_hidden_link = ''; $link = "<a href='{$urlServer}modules/document/index.php?course=$course_code&openDir=$file->path&unit=$id'>$file->filename</a>"; } else { $image = choose_image('.' . $file->format); $download_url = "{$urlServer}modules/document/index.php?course=$course_code&download=$file->path"; $download_hidden_link = "<input type='hidden' value='$download_url'>"; $file_obj = MediaResourceFactory::initFromDocument($file); $file_obj->setAccessURL(file_url($file->path, $file->filename)); $file_obj->setPlayURL(file_playurl($file->path, $file->filename)); $link = MultimediaHelper::chooseMediaAhref($file_obj); } } $class_vis = ($status == '0' or $status == 'del') ? ' class="not_visible"' : ''; if (!empty($comments)) { $comment = '<br />' . $comments; } else { $comment = ''; } return " <tr$class_vis> <td width='1'>" . icon($image, '') . "</a></td> <td align='left'>$download_hidden_link$link$comment</td>" . actions('doc', $resource_id, $status) . '</tr>'; }
/** * list documents while inserting them in course unit * @global type $id * @global type $webDir * @global type $course_code * @global type $tool_content * @global type $group_sql * @global type $langDirectory * @global type $langUp * @global type $langName * @global type $langSize * @global type $langDate * @global type $langType * @global type $langAddModulesButton * @global type $langChoice * @global type $langNoDocuments * @global type $course_code */ function list_docs() { global $id, $webDir, $course_code, $tool_content, $group_sql, $langDirectory, $langUp, $langName, $langSize, $langDate, $langType, $langAddModulesButton, $langChoice, $langNoDocuments, $course_code, $langCommonDocs, $pageName; $basedir = $webDir . '/courses/' . $course_code . '/document'; $path = get_dir_path('path'); $dir_param = get_dir_path('dir'); $dir_setter = $dir_param ? ('&dir=' . $dir_param) : ''; $dir_html = $dir_param ? "<input type='hidden' name='dir' value='$dir_param'>" : ''; if ($id == -1) { $common_docs = true; $pageName = $langCommonDocs; $group_sql = "course_id = -1 AND subsystem = " . COMMON . ""; $basedir = $webDir . '/courses/commondocs'; $visible_sql = 'visible = 1 AND'; } else { $common_docs = false; $visible_sql = ''; } $result = Database::get()->queryArray("SELECT id, course_id, path, filename, format, title, extra_path, date_modified, visible, copyrighted, comment, IF(title = '', filename, title) AS sort_key FROM document WHERE $group_sql AND $visible_sql path LIKE ?s AND path NOT LIKE ?s ORDER BY sort_key COLLATE utf8_unicode_ci", "$path/%", "$path/%/%"); $fileinfo = array(); $urlbase = $_SERVER['SCRIPT_NAME'] . "?course=$course_code$dir_setter&type=doc&id=$id&path="; foreach ($result as $row) { $fullpath = $basedir . $row->path; if ($row->extra_path) { $size = 0; } else { $size = file_exists($fullpath)? filesize($fullpath): 0; } $fileinfo[] = array( 'id' => $row->id, 'is_dir' => is_dir($fullpath), 'size' => $size, 'title' => $row->title, 'name' => htmlspecialchars($row->filename), 'format' => $row->format, 'path' => $row->path, 'visible' => $row->visible, 'comment' => $row->comment, 'copyrighted' => $row->copyrighted, 'date' => $row->date_modified, 'object' => MediaResourceFactory::initFromDocument($row)); } if (count($fileinfo) == 0) { $tool_content .= "<div class='alert alert-warning'>$langNoDocuments</div>"; } else { if (!empty($path)) { $dirname = Database::get()->querySingle("SELECT filename FROM document WHERE $group_sql AND path = ?s", $path); $parentpath = dirname($path); $dirname = htmlspecialchars($dirname->filename); $parentlink = $urlbase . $parentpath; $parenthtml = "<span class='pull-right'><a href='$parentlink'>$langUp " . icon('fa-level-up') . "</a></span>"; $colspan = 4; } $tool_content .= "<form action='insert.php?course=$course_code' method='post'><input type='hidden' name='id' value='$id' />" . "<table class='table-default'>"; if( !empty($path)) { $tool_content .= "<tr>" . "<th colspan='$colspan'><div class='text-left'>$langDirectory: $dirname$parenthtml</div></th>" . "</tr>" ; } $tool_content .= "<tr class='list-header'>" . "<th class='text-left'>$langName</th>" . "<th class='text-center'>$langSize</th>" . "<th class='text-center'>$langDate</th>" . "<th style='width:20px;' class='text-center'>$langChoice</th>" . "</tr>"; $counter = 0; foreach (array(true, false) as $is_dir) { foreach ($fileinfo as $entry) { if ($entry['is_dir'] != $is_dir) { continue; } $dir = $entry['path']; if ($is_dir) { $image = 'fa-folder-o'; $file_url = $urlbase . $dir; $link_text = $entry['name']; $link_href = "<a href='$file_url'>$link_text</a>"; } else { $image = choose_image('.' . $entry['format']); $file_url = file_url($entry['path'], $entry['name'], $common_docs ? 'common' : $course_code); $dObj = $entry['object']; $dObj->setAccessURL($file_url); $dObj->setPlayURL(file_playurl($entry['path'], $entry['name'], $common_docs ? 'common' : $course_code)); $link_href = MultimediaHelper::chooseMediaAhref($dObj); } if ($entry['visible'] == 'i') { $vis = 'invisible'; } else { $vis = ''; } $tool_content .= "<tr class='$vis'>"; $tool_content .= "<td>" . icon($image, '')." $link_href"; /* * * comments ** */ if (!empty($entry['comment'])) { $tool_content .= "<br /><div class='comment'>" . standard_text_escape($entry['comment']) . "</div>"; } $tool_content .= "</td>"; if ($is_dir) { // skip display of date and time for directories $tool_content .= "<td> </td><td> </td>"; } else { $size = format_file_size($entry['size']); $date = nice_format($entry['date'], true, true); $tool_content .= "<td class='text-right'>$size</td><td class='text-center'>$date</td>"; } $tool_content .= "<td class='text-center'><input type='checkbox' name='document[]' value='$entry[id]' /></td>"; $tool_content .= "</tr>"; $counter++; } } $tool_content .= "</table>"; $tool_content .= "<div class='text-right'>"; $tool_content .= "<input class='btn btn-primary' type='submit' name='submit_doc' value='$langAddModulesButton' /></div>$dir_html</form>"; } }
/** * list documents while inserting them in course unit * @global type $id * @global type $webDir * @global type $course_code * @global type $tool_content * @global type $group_sql * @global type $langDirectory * @global type $langUp * @global type $langName * @global type $langSize * @global type $langDate * @global type $langType * @global type $langAddModulesButton * @global type $langChoice * @global type $langNoDocuments * @global type $course_code */ function list_docs() { global $id, $webDir, $course_code, $tool_content, $group_sql, $langDirectory, $langUp, $langName, $langSize, $langDate, $langType, $langAddModulesButton, $langChoice, $langNoDocuments, $course_code, $langCommonDocs, $pageName; $basedir = $webDir . '/courses/' . $course_code . '/document'; $path = get_dir_path('path'); $dir_param = get_dir_path('dir'); $dir_setter = $dir_param ? '&dir=' . $dir_param : ''; $dir_html = $dir_param ? "<input type='hidden' name='dir' value='{$dir_param}'>" : ''; if ($id == -1) { $common_docs = true; $pageName = $langCommonDocs; $group_sql = "course_id = -1 AND subsystem = " . COMMON . ""; $basedir = $webDir . '/courses/commondocs'; $result = Database::get()->queryArray("SELECT * FROM document\n WHERE {$group_sql} AND\n visible = 1 AND\n path LIKE ?s AND\n path NOT LIKE ?s", "{$path}/%", "{$path}/%/%"); } else { $common_docs = false; $result = Database::get()->queryArray("SELECT * FROM document\n WHERE {$group_sql} AND\n path LIKE ?s AND\n path NOT LIKE ?s", "{$path}/%", "{$path}/%/%"); } $fileinfo = array(); $urlbase = $_SERVER['SCRIPT_NAME'] . "?course={$course_code}{$dir_setter}&type=doc&id={$id}&path="; foreach ($result as $row) { $fullpath = $basedir . $row->path; if ($row->extra_path) { $size = 0; } else { $size = file_exists($fullpath) ? filesize($fullpath) : 0; } $fileinfo[] = array('id' => $row->id, 'is_dir' => is_dir($fullpath), 'size' => $size, 'title' => $row->title, 'name' => htmlspecialchars($row->filename), 'format' => $row->format, 'path' => $row->path, 'visible' => $row->visible, 'comment' => $row->comment, 'copyrighted' => $row->copyrighted, 'date' => $row->date_modified, 'object' => MediaResourceFactory::initFromDocument($row)); } if (count($fileinfo) == 0) { $tool_content .= "<div class='alert alert-warning'>{$langNoDocuments}</div>"; } else { if (empty($path)) { $dirname = ''; $parenthtml = ''; $colspan = 5; } else { $dirname = Database::get()->querySingle("SELECT filename FROM document\n WHERE {$group_sql} AND path = ?s", $path); $parentpath = dirname($path); $dirname = "/" . htmlspecialchars($dirname); $parentlink = $urlbase . $parentpath; $parenthtml = "<th class='right'><a href='{$parentlink}'>{$langUp}</a> " . icon('fa-upload', $langUp, $parentlink) . "</th>"; $colspan = 4; } $tool_content .= "<form action='insert.php?course={$course_code}' method='post'><input type='hidden' name='id' value='{$id}' />" . "<table class='table-default'>" . "<tr>" . "<th colspan='{$colspan}'><div align='left'>{$langDirectory}: {$dirname}</div></th>" . $parenthtml . "</tr>" . "<tr>" . "<th>{$langType}</th>" . "<th><div align='left'>{$langName}</div></th>" . "<th width='100'>{$langSize}</th>" . "<th width='80'>{$langDate}</th>" . "<th width='80'>{$langChoice}</th>" . "</tr>"; $counter = 0; foreach (array(true, false) as $is_dir) { foreach ($fileinfo as $entry) { if ($entry['is_dir'] != $is_dir) { continue; } $dir = $entry['path']; if ($is_dir) { $image = 'fa-folder-o'; $file_url = $urlbase . $dir; $link_text = $entry['name']; $link_href = "<a href='{$file_url}'>{$link_text}</a>"; } else { $image = choose_image('.' . $entry['format']); $file_url = file_url($entry['path'], $entry['name'], $common_docs ? 'common' : $course_code); $dObj = $entry['object']; $dObj->setAccessURL($file_url); $dObj->setPlayURL(file_playurl($entry['path'], $entry['name'], $common_docs ? 'common' : $course_code)); $link_href = MultimediaHelper::chooseMediaAhref($dObj); } if ($entry['visible'] == 'i') { $vis = 'invisible'; } else { $vis = ''; } $tool_content .= "<tr class='{$vis}'>"; $tool_content .= "<td width='1' class='center'>" . icon($image, '') . "</td>"; $tool_content .= "<td>{$link_href}"; /* * * comments ** */ if (!empty($entry['comment'])) { $tool_content .= "<br /><div class='comment'>" . standard_text_escape($entry['comment']) . "</div>"; } $tool_content .= "</td>"; if ($is_dir) { // skip display of date and time for directories $tool_content .= "<td> </td><td> </td>"; } else { $size = format_file_size($entry['size']); $date = nice_format($entry['date'], true, true); $tool_content .= "<td class='center'>{$size}</td><td class='center'>{$date}</td>"; } $tool_content .= "<td class='center'><input type='checkbox' name='document[]' value='{$entry['id']}' /></td>"; $tool_content .= "</tr>"; $counter++; } } $tool_content .= "<tr><th colspan={$colspan}><div align='right'>"; $tool_content .= "<input class='btn btn-primary' type='submit' name='submit_doc' value='{$langAddModulesButton}' /></div></th>"; $tool_content .= "</tr></table>{$dir_html}</form>"; } }
$updated = false; } $fileinfo[] = array( 'is_dir' => $is_dir, 'size' => $size, 'title' => $row->title, 'filename' => $row->filename, 'format' => $row->format, 'path' => $row->path, 'extra_path' => $row->extra_path, 'visible' => ($row->visible == 1), 'public' => $row->public, 'comment' => $row->comment, 'copyrighted' => $row->copyrighted, 'date' => $row->date_modified, 'object' => MediaResourceFactory::initFromDocument($row), 'editable' => $row->editable, 'updated' => $updated); } // end of common to teachers and students // ---------------------------------------------- // Display // ---------------------------------------------- $cmdCurDirPath = rawurlencode($curDirPath); $cmdParentDir = rawurlencode($parentDir); if ($can_upload) { // Action result message if (!empty($action_message)) { $tool_content .= $action_message;
/** * @brief get user documents newer than one month * @global type $langNoDocsExist * @param type $param * @return string */ function getUserDocuments($lesson_id) { global $langNoDocsExist, $group_sql; $last_month = strftime('%Y-%m-%d', strtotime('now -1 month')); $found = false; $doc_content = '<table width="100%">'; foreach ($lesson_id as $lid) { $q = Database::get()->queryArray("SELECT document.path, document.course_id, document.filename,\n document.title, document.date_modified,\n document.format, document.visible,\n document.id\n FROM document, course_module\n WHERE document.course_id = ?d AND \n subsystem = " . MAIN . " AND\n document.visible = 1 AND\n date_modified >= '{$last_month}' AND\n format <> '.dir' AND\n course_module.module_id = " . MODULE_ID_DOCS . " AND\n course_module.visible = 1 AND\n course_module.course_id = ?d\n ORDER BY date_modified DESC", $lid, $lid); if ($q) { $found = true; $doc_content .= "<tr><td class='sub_title1'>" . q(ellipsize(course_id_to_title($lid), 70)) . "</td></tr>"; foreach ($q as $course_file) { $group_sql = "course_id = " . $lid . " AND subsystem = " . MAIN; $url = file_url($course_file->path, $course_file->filename, course_id_to_code($lid)); $dObj = MediaResourceFactory::initFromDocument($course_file); $dObj->setAccessURL($url); $dObj->setPlayURL(file_playurl($course_file->path, $course_file->filename, course_id_to_code($lid))); $href = MultimediaHelper::chooseMediaAhref($dObj); $doc_content .= "<tr><td class='smaller'><ul class='custom_list'><li>" . $href . ' - (' . nice_format(date('Y-m-d', strtotime($course_file->date_modified))) . ")</li></ul></td></tr>"; } } } $doc_content .= "</table>"; if ($found) { return $doc_content; } else { return "<div class='alert alert-warning'>{$langNoDocsExist}</div>"; } }