/** * 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>"; } }