123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929 |
- <?php
- function build_directory_selector($folders, $document_id, $group_dir = '', $change_renderer = false) {
- $doc_table = Database::get_course_table(TABLE_DOCUMENT);
- $course_id = api_get_course_int_id();
- $folder_titles = array();
- if (api_get_setting('use_document_title') == 'true') {
- if (is_array($folders)) {
- $escaped_folders = array();
- foreach ($folders as $key => & $val) {
- $escaped_folders[$key] = Database::escape_string($val);
- }
- $folder_sql = implode("','", $escaped_folders);
-
- $sql = "SELECT * FROM $doc_table WHERE filetype = 'folder' AND c_id = $course_id AND path IN ('".$folder_sql."')";
- $res = Database::query($sql);
- $folder_titles = array();
- while ($obj = Database::fetch_object($res)) {
- $folder_titles[$obj->path] = $obj->title;
- }
- }
- } else {
- if (is_array($folders)) {
- foreach ($folders as & $folder) {
- $folder_titles[$folder] = basename($folder);
- }
- }
- }
-
- $form = new FormValidator('selector', 'GET', api_get_self().'?'.api_get_cidreq());
- $form->addElement('hidden', 'cidReq', api_get_course_id());
- $parent_select = $form->addElement('select', 'id', get_lang('CurrentDirectory'), '', 'onchange="javascript: document.selector.submit();"');
- if ($change_renderer) {
- $renderer = $form->defaultRenderer();
- $renderer->setElementTemplate('<span>{label} : {element}</span> ','curdirpath');
- }
-
- if (empty($group_dir)) {
- $parent_select -> addOption(get_lang('Documents'), '/');
-
- if (is_array($folders)) {
- foreach ($folders as $folder_id => & $folder) {
- $selected = ($document_id == $folder_id) ? ' selected="selected"' : '';
- $path_parts = explode('/', $folder);
- $folder_titles[$folder] = cut($folder_titles[$folder], 80);
- $label = str_repeat(' ', count($path_parts) - 2).' — '.$folder_titles[$folder];
- $parent_select -> addOption($label, $folder_id);
- if ($selected != '') {
- $parent_select->setSelected($folder_id);
- }
- }
- }
- } else {
- foreach ($folders as $folder_id => & $folder) {
- $selected = ($document_id == $folder_id) ? ' selected="selected"' : '';
- $label = $folder_titles[$folder];
- if ($folder == $group_dir) {
- $label = get_lang('Documents');
- } else {
- $path_parts = explode('/', str_replace($group_dir, '', $folder));
- $label = cut($label, 80);
- $label = str_repeat(' ', count($path_parts) - 2).' — '.$label;
- }
- $parent_select -> addOption($label, $folder_id);
- if ($selected != '') {
- $parent_select->setSelected($folder_id);
- }
- }
- }
- $form = $form->toHtml();
- return $form;
- }
- function create_document_link($document_data, $show_as_icon = false, $counter = null, $visibility) {
- global $dbl_click_id;
- if (isset($_SESSION['_gid'])) {
- $req_gid = '&gidReq='.$_SESSION['_gid'];
- } else {
- $req_gid = '';
- }
- $course_info = api_get_course_info();
- $www = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document';
- $use_document_title = api_get_setting('use_document_title');
-
-
- if ($use_document_title == 'true' && $document_data['title'] != '') {
- $title = $document_data['title'];
- } else {
- $title = basename($document_data['path']);
- }
-
- $filetype = $document_data['filetype'];
- $size = $filetype == 'folder' ? get_total_folder_size($document_data['path'], api_is_allowed_to_edit(null, true)) : $document_data['size'];
- $path = $document_data['path'];
-
- $url_path = urlencode($document_data['path']);
-
-
- $visibility_class = ($visibility == false) ? ' class="invisible"' : '';
- if (!$show_as_icon) {
-
- $forcedownload_link = ($filetype == 'folder') ? api_get_self().'?'.api_get_cidreq().'&action=downloadfolder&id='.$document_data['id'] : api_get_self().'?'.api_get_cidreq().'&action=download&id='.$document_data['id'];
-
- $forcedownload_icon = ($filetype == 'folder') ? 'save_pack.png' : 'save.png';
-
- $prevent_multiple_click = ($filetype == 'folder') ? " onclick=\"javascript: if(typeof clic_$dbl_click_id == 'undefined' || !clic_$dbl_click_id) { clic_$dbl_click_id=true; window.setTimeout('clic_".($dbl_click_id++)."=false;',10000); } else { return false; }\"":'';
- }
- $target = '_self';
- $is_browser_viewable_file = false;
-
- if ($filetype == 'file') {
-
- $ext = explode('.', $path);
- $ext = strtolower($ext[sizeof($ext) - 1]);
-
- $is_browser_viewable_file = is_browser_viewable($ext);
-
- if ($is_browser_viewable_file) {
-
- $url = 'showinframes.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
- } else {
-
- $path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq();
-
- $url = $www.$path;
- }
-
- $path = str_replace('%2F', '/',$url_path);
- $url = $www.$path;
-
-
-
-
-
-
- } else {
-
- $url = api_get_self().'?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
- }
-
-
- $tooltip_title = explode('?', basename($path));
-
- $tooltip_title = $title;
- $tooltip_title_alt = $tooltip_title;
- if ($path == '/shared_folder') {
- $tooltip_title_alt = get_lang('UserFolders');
- } elseif(strstr($path, 'shared_folder_session_')) {
- $tooltip_title_alt = get_lang('UserFolders').' ('.api_get_session_name(api_get_session_id()).')';
- } elseif(strstr($tooltip_title, 'sf_user_')) {
- $userinfo = Database::get_user_info_from_id(substr($tooltip_title, 8));
- $tooltip_title_alt = get_lang('UserFolder').' '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
- } elseif($path == '/chat_files') {
- $tooltip_title_alt = get_lang('ChatFiles');
- } elseif($path == '/video') {
- $tooltip_title_alt = get_lang('Video');
- } elseif($path == '/audio') {
- $tooltip_title_alt = get_lang('Audio');
- } elseif($path == '/flash') {
- $tooltip_title_alt = get_lang('Flash');
- } elseif($path == '/images') {
- $tooltip_title_alt = get_lang('Images');
- } elseif($path == '/images/gallery') {
- $tooltip_title_alt = get_lang('DefaultCourseImages');
- }
- $current_session_id = api_get_session_id();
- $copy_to_myfiles = $open_in_new_window_link = null;
-
- $curdirpath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null;
-
- if (!$show_as_icon) {
- if ($filetype == 'folder') {
- if (api_is_allowed_to_edit() || api_is_platform_admin() || api_get_setting('students_download_folders') == 'true') {
-
- if (is_shared_folder($curdirpath, $current_session_id)) {
- if (preg_match('/shared_folder\/sf_user_'.api_get_user_id().'$/', urldecode($forcedownload_link))|| preg_match('/shared_folder_session_'.$current_session_id.'\/sf_user_'.api_get_user_id().'$/', urldecode($forcedownload_link)) || api_is_allowed_to_edit() || api_is_platform_admin()) {
- $force_download_html = ($size == 0) ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'), array(),ICON_SIZE_SMALL).'</a>';
- }
- } elseif(!preg_match('/shared_folder/', urldecode($forcedownload_link)) || api_is_allowed_to_edit() || api_is_platform_admin()) {
- $force_download_html = ($size == 0) ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'), array(),ICON_SIZE_SMALL).'</a>';
- }
- }
- } else {
- $force_download_html = ($size==0)?'':'<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'), array(),ICON_SIZE_SMALL).'</a>';
- }
-
-
- if (api_get_setting('users_copy_files') == 'true' && !api_is_anonymous()){
- $copy_myfiles_link = ($filetype == 'file') ? api_get_self().'?'.api_get_cidreq().'&action=copytomyfiles&id='.$document_data['id'].$req_gid :api_get_self().'?'.api_get_cidreq();
- if ($filetype == 'file') {
- $copy_to_myfiles = '<a href="'.$copy_myfiles_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon('briefcase.png', get_lang('CopyToMyFiles'), array(),ICON_SIZE_SMALL).' </a>';
- }
- }
-
- $pdf_icon = '';
- $extension = pathinfo($path, PATHINFO_EXTENSION);
- if (!api_is_allowed_to_edit() && api_get_setting('students_export2pdf') == 'true' && $filetype == 'file' && in_array($extension, array('html','htm'))) {
- $pdf_icon = ' <a style="float:right".'.$prevent_multiple_click.' href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&id='.$document_data['id'].'">'.Display::return_icon('pdf.png', get_lang('Export2PDF'),array(), 22).'</a> ';
- }
-
- if ($is_browser_viewable_file) {
- $open_in_new_window_link = '<a href="'.$www.str_replace('%2F', '/',$url_path).'?'.api_get_cidreq().'" style="float:right"'.$prevent_multiple_click.' target="_blank">'.Display::return_icon('open_in_new_window.png', get_lang('OpenInANewWindow'), array(),ICON_SIZE_SMALL).' </a>';
- }
-
- if ($filetype == 'file') {
-
- if ( preg_match('/mp3$/i', urldecode($url)) ||
- preg_match('/wav$/i', urldecode($url)) ||
- preg_match('/ogg$/i', urldecode($url))) {
- return '<span style="float:left" '.$visibility_class.'>'.$title.'</span>'.$force_download_html.$copy_to_myfiles.$open_in_new_window_link.$pdf_icon;
- } elseif (
-
- preg_match('/swf$/i', urldecode($url)) ||
- preg_match('/png$/i', urldecode($url)) ||
- preg_match('/gif$/i', urldecode($url)) ||
- preg_match('/jpg$/i', urldecode($url)) ||
- preg_match('/jpeg$/i', urldecode($url)) ||
- preg_match('/bmp$/i', urldecode($url)) ||
- preg_match('/svg$/i', urldecode($url))
-
-
-
- ) {
-
-
-
- $url = 'show_content.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid.'&width=700&height=500';
- $class = 'thickbox';
- if ($visibility == false) {
- $class = "thickbox invisible";
- }
- return '<a href="'.$url.'" class="'.$class.'" title="'.$tooltip_title_alt.'" style="float:left">'.$title.'</a>'.$force_download_html.$copy_to_myfiles.$open_in_new_window_link.$pdf_icon;
- } else {
- $url = 'showinframes.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
-
- return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" style="float:left" '.$visibility_class.' >'.$title.'</a>'.$force_download_html.$copy_to_myfiles.$open_in_new_window_link.$pdf_icon;
- }
- } else {
- return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" '.$visibility_class.' style="float:left">'.$title.'</a>'.$force_download_html.$copy_to_myfiles.$open_in_new_window_link.$pdf_icon;
- }
-
- } else {
-
- if (preg_match('/shared_folder/', urldecode($url)) && preg_match('/shared_folder$/', urldecode($url))==false && preg_match('/shared_folder_session_'.$current_session_id.'$/', urldecode($url))==false){
- if ($filetype == 'file') {
-
- if ( preg_match('/mp3$/i', urldecode($url)) ||
- preg_match('/wav$/i', urldecode($url)) ||
- preg_match('/ogg$/i', urldecode($url))) {
- $sound_preview = DocumentManager::generate_media_preview($counter);
- return $sound_preview ;
- } elseif (
-
- preg_match('/swf$/i', urldecode($url)) ||
- preg_match('/html$/i', urldecode($url)) ||
- preg_match('/htm$/i', urldecode($url))
- ) {
- $url = 'showinframesmin.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
- return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" target="yoxview"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22)).'</a>';
- } else {
- return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" target="yoxview"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22)).'</a>';
- }
- } else {
- return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22)).'</a>';
- }
- } else {
- if ($filetype == 'file') {
-
- if ( preg_match('/mp3$/i', urldecode($url)) ||
- preg_match('/wav$/i', urldecode($url)) ||
- preg_match('/ogg$/i', urldecode($url))) {
- $sound_preview = DocumentManager::generate_media_preview($counter);
- return $sound_preview ;
- } elseif (
-
- preg_match('/swf$/i', urldecode($url)) ||
- preg_match('/html$/i', urldecode($url)) ||
- preg_match('/htm$/i', urldecode($url))
- ) {
- $url = 'showinframesmin.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
- return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" target="yoxview"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).'</a>';
- } else {
- return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" target="yoxview"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).'</a>';
- }
- } else {
- return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).'</a>';
- }
- }
- }
- }
- function build_document_icon_tag($type, $path) {
- $basename = basename($path);
- $current_session_id = api_get_session_id();
- $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
- if ($type == 'file') {
- $icon = choose_image($basename);
- } else {
- if ($path == '/shared_folder') {
- $icon = 'folder_users.gif';
- if ($is_allowed_to_edit) {
- $basename = get_lang('HelpUsersFolder');
- } else {
- $basename = get_lang('UserFolders');
- }
- }elseif(strstr($basename, 'sf_user_')) {
- $userinfo = Database::get_user_info_from_id(substr($basename, 8));
- $image_path = UserManager::get_user_picture_path_by_id(substr($basename, 8), 'web', false, true);
- if ($image_path['file'] == 'unknown.jpg') {
- $icon = $image_path['file'];
- } else {
- $icon = '../upload/users/'.substr($basename, 8).'/'.$image_path['file'];
- }
- $basename = get_lang('UserFolder').' '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']);}elseif(strstr($path, 'shared_folder_session_')) {
- if ($is_allowed_to_edit) {
- $basename = '***('.api_get_session_name($current_session_id).')*** '.get_lang('HelpUsersFolder');
- } else {
- $basename = get_lang('UserFolders').' ('.api_get_session_name($current_session_id).')';
- }
- $icon = 'folder_users.gif';
- } else {
- $icon = 'folder_document.gif';
- if($path=='/audio'){
- $icon = 'folder_audio.gif';
- if(api_is_allowed_to_edit()){
- $basename=get_lang('HelpDefaultDirDocuments');
- }
- else{
- $basename=get_lang('Audio');
- }
- }
- elseif($path =='/flash'){
- $icon = 'folder_flash.gif';
- if(api_is_allowed_to_edit()){
- $basename=get_lang('HelpDefaultDirDocuments');
- }
- else{
- $basename=get_lang('Flash');
- }
- }
- elseif($path =='/images'){
- $icon = 'folder_images.gif';
- if(api_is_allowed_to_edit()){
- $basename=get_lang('HelpDefaultDirDocuments');
- }
- else{
- $basename=get_lang('Images');
- }
- }
- elseif($path =='/video'){
- $icon = 'folder_video.gif';
- if(api_is_allowed_to_edit()){
- $basename=get_lang('HelpDefaultDirDocuments');
- }
- else{
- $basename=get_lang('Video');
- }
- }
- elseif($path =='/images/gallery'){
- $icon = 'folder_gallery.gif';
- if(api_is_allowed_to_edit()){
- $basename=get_lang('HelpDefaultDirDocuments');
- }
- else{
- $basename=get_lang('Gallery');
- }
- }
- elseif($path =='/chat_files'){
- $icon = 'folder_chat.gif';
- if(api_is_allowed_to_edit()){
- $basename=get_lang('HelpFolderChat');
- }
- else{
- $basename=get_lang('ChatFiles');
- }
- }
- }
- }
- return Display::return_icon($icon, $basename, array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22));
- }
- function build_edit_icons($document_data, $id, $is_template, $is_read_only = 0, $visibility) {
- if (isset($_SESSION['_gid'])) {
- $req_gid = '&gidReq='.$_SESSION['_gid'];
- } else {
- $req_gid = '';
- }
- $document_id = $document_data['id'];
-
- $type = $document_data['filetype'];
-
- $is_read_only = $document_data['readonly'];
- $path = $document_data['path'];
- $parent_id = DocumentManager::get_document_id(api_get_course_info(), dirname($path));
- $curdirpath = dirname($document_data['path']);
- $is_certificate_mode = DocumentManager::is_certificate_mode($path);
- $curdirpath = urlencode($curdirpath);
- $extension = pathinfo($path, PATHINFO_EXTENSION);
-
-
- $sort_params = array();
- if (isset($_GET['column'])) {
- $sort_params[] = 'column='.Security::remove_XSS($_GET['column']);
- }
- if (isset($_GET['page_nr'])) {
- $sort_params[] = 'page_nr='.Security::remove_XSS($_GET['page_nr']);
- }
- if (isset($_GET['per_page'])) {
- $sort_params[] = 'per_page='.Security::remove_XSS($_GET['per_page']);
- }
- if (isset($_GET['direction'])) {
- $sort_params[] = 'direction='.Security::remove_XSS($_GET['direction']);
- }
- $sort_params = implode('&', $sort_params);
- $visibility_icon = ($visibility == 0) ? 'invisible' : 'visible';
- $visibility_command = ($visibility == 0) ? 'set_visible' : 'set_invisible';
-
- $modify_icons = '';
-
-
-
- if ($is_read_only ) {
- if (api_is_course_admin() || api_is_platform_admin()) {
- if($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true') {
- $modify_icons = '<a href="edit_draw.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
- } elseif($extension=='png' || $extension=='jpg' || $extension=='jpeg' || $extension=='bmp' || $extension=='gif' ||$extension=='pxd' && api_get_setting('enabled_support_pixlr') == 'true'){
- $modify_icons = '<a href="edit_paint.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
- } else {
- $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
- }
- } else {
- $modify_icons = Display::return_icon('edit_na.png', get_lang('Modify'),'',ICON_SIZE_SMALL);
- }
- $modify_icons .= ' '.Display::return_icon('move_na.png', get_lang('Move'),array(), 22);
- if (api_is_allowed_to_edit() || api_is_platform_admin()) {
- $modify_icons .= ' '.Display::return_icon($visibility_icon.'.png', get_lang('VisibilityCannotBeChanged'),'',ICON_SIZE_SMALL);
- }
- $modify_icons .= ' '.Display::return_icon('delete_na.png', get_lang('Delete'),array(), 22);
- } else {
- if ($is_certificate_mode) {
-
-
- $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'&curdirpath=/certificates">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
- } else {
- if (api_get_session_id()) {
- if ($document_data['session_id'] == api_get_session_id()) {
- if ($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true') {
- $modify_icons = '<a href="edit_draw.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
- } elseif($extension=='png' || $extension=='jpg' || $extension=='jpeg' || $extension=='bmp' || $extension=='gif' ||$extension=='pxd' && api_get_setting('enabled_support_pixlr') == 'true'){
- $modify_icons = '<a href="edit_paint.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
- } else {
- $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
- }
- } else {
- $modify_icons .= ' '.Display::return_icon('edit_na.png', get_lang('Edit'),array(), 22).'</a>';
- }
- } else {
- if ($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true') {
- $modify_icons = '<a href="edit_draw.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
- } elseif($extension=='png' || $extension=='jpg' || $extension=='jpeg' || $extension=='bmp' || $extension=='gif' ||$extension=='pxd' && api_get_setting('enabled_support_pixlr') == 'true'){
- $modify_icons = '<a href="edit_paint.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
- } else {
- $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
- }
- }
- }
- if ($is_certificate_mode) {
-
- $modify_icons .= ' '.Display::return_icon('move_na.png', get_lang('Move'),array(), 22).'</a>';
- $modify_icons .= ' '.Display::return_icon($visibility_icon.'.png', get_lang('VisibilityCannotBeChanged'),array(), 22).'</a>';
- Display::return_icon($visibility_icon.'.png', get_lang('VisibilityCannotBeChanged'),array(), 22).'</a>';
- } else {
- if (api_get_session_id()) {
- if ($document_data['session_id'] == api_get_session_id()) {
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'&move='.$document_id.$req_gid.'">'.Display::return_icon('move.png', get_lang('Move'),array(), 22).'</a>';
- } else {
- $modify_icons .= ' '.Display::return_icon('move_na.png', get_lang('Move'),array(), 22).'</a>';
- }
- } else {
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'&move='.$document_id.$req_gid.'">'.Display::return_icon('move.png', get_lang('Move'),array(), 22).'</a>';
- }
- if (api_is_allowed_to_edit() || api_is_platform_admin()) {
- if ($visibility_icon=='invisible'){
- $tip_visibility=get_lang('Show');
- }else{
- $tip_visibility=get_lang('Hide');
- }
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'&'.$visibility_command.'='.$id.$req_gid.'&'.$sort_params.'">'.Display::return_icon($visibility_icon.'.png', $tip_visibility,'',ICON_SIZE_SMALL).'</a>';
- }
- }
- if (in_array($path, array('/audio', '/flash', '/images', '/shared_folder', '/video', '/chat_files', '/certificates'))) {
- $modify_icons .= ' '.Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'),array(), 22);
- } else {
- if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates' && DocumentManager::get_default_certificate_id(api_get_course_id())==$id) {
-
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&delete='.urlencode($path).$req_gid.'&'.$sort_params.'delete_certificate_id='.$id.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), 22).'</a>';
- } else {
- if ($is_certificate_mode) {
-
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&delete='.urlencode($path).$req_gid.'&'.$sort_params.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), 22).'</a>';
- } else {
- if (api_get_session_id()) {
- if ($document_data['session_id'] == api_get_session_id()) {
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&delete='.urlencode($path).$req_gid.'&'.$sort_params.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), 22).'</a>';
- } else {
- $modify_icons .= ' '.Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'),array(), 22);
- }
- } else {
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&delete='.urlencode($path).$req_gid.'&'.$sort_params.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), 22).'</a>';
- }
- }
- }
- }
- }
- if ($type == 'file' && ($extension == 'html' || $extension == 'htm')) {
- if ($is_template == 0) {
- if ((isset($_GET['curdirpath']) && $_GET['curdirpath'] != '/certificates') || !isset($_GET['curdirpath'])) {
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&add_as_template='.$id.$req_gid.'&'.$sort_params.'">'.Display::return_icon('wizard.png', get_lang('AddAsTemplate'),array(), 22).'</a>';
- }
- if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates') {
- $visibility_icon_certificate='nocertificate';
- if (DocumentManager::get_default_certificate_id(api_get_course_id())==$id) {
- $visibility_icon_certificate='certificate';
- $certificate=get_lang('DefaultCertificate');
- $preview=get_lang('PreviewCertificate');
- $is_preview=true;
- } else {
- $is_preview=false;
- $certificate=get_lang('NoDefaultCertificate');
- }
- if (isset($_GET['selectcat'])) {
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&selectcat='.Security::remove_XSS($_GET['selectcat']).'&set_certificate='.$id.$req_gid.'&'.$sort_params.'"><img src="../img/'.$visibility_icon_certificate.'.png" border="0" title="'.$certificate.'" alt="" /></a>';
- if ($is_preview) {
- $modify_icons .= ' <a target="_blank" href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&set_preview='.$id.$req_gid.'&'.$sort_params.'" >'.
- Display::return_icon('preview_view.png', $preview,'',ICON_SIZE_SMALL).'</a>';
- }
- }
- }
- } else {
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&remove_as_template='.$id.$req_gid.'&'.$sort_params.'">'.
- Display::return_icon('wizard_na.png', get_lang('RemoveAsTemplate'),'',ICON_SIZE_SMALL).'</a>';
- }
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&id='.$id.'">'.Display::return_icon('pdf.png', get_lang('Export2PDF'),array(), 22).'</a>';
- }
- return $modify_icons;
- }
- function build_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') {
-
- $form = '<form name="move_to" action="'.api_get_self().'" method="POST">';
- $form .= '<input type="hidden" name="move_file" value="'.$move_file.'" />';
-
- $form .= '<div class="row">';
- $form .= '<div class="label">';
- $form .= get_lang('MoveTo');
- $form .= '</div>';
-
- $form .= '<div class="formw">';
- $form .= '<select name="move_to">';
-
- if ($group_dir == '') {
- if ($curdirpath != '/') {
- $form .= '<option value="/">'.get_lang('Documents').'</option>';
- }
- if (is_array($folders)) {
- foreach ($folders as & $folder) {
-
- if($folder=='/HotPotatoes_files' || $folder=='/certificates' || basename($folder)=='css'){
- continue;
- }
-
- if(api_get_setting('show_users_folders') == 'false' && (strstr($folder, '/shared_folder') || strstr($folder, 'shared_folder_session_'))){
- continue;
- }
-
- if(api_get_setting('show_default_folders') == 'false' && ($folder=='/images' || $folder=='/flash' || $folder=='/audio' || $folder=='/video' || strstr($folder, '/images/gallery') || $folder=='/video/flv')){
- continue;
- }
-
- if(api_get_setting('show_chat_folder') == 'false' && $folder=='/chat_files'){
- continue;
- }
-
-
-
-
- if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) {
- $path_displayed = $folder;
-
- if (api_get_setting('use_document_title')) {
- $path_displayed = get_titles_of_path($folder);
- }
- if (empty($path_displayed)) {
- $path_displayed = get_lang('Untitled');
- }
- $form .= '<option value="'.$folder.'">'.$path_displayed.'</option>';
- }
- }
- }
- } else {
- foreach ($folders as $folder) {
- if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) {
- if (api_get_setting('use_document_title')) {
- $path_displayed = get_titles_of_path($folder);
- }
- $display_folder = substr($path_displayed,strlen($group_dir));
- $display_folder = ($display_folder == '') ? get_lang('Documents') : $display_folder;
- $form .= '<option value="'.$folder.'">'.$display_folder.'</option>';
- }
- }
- }
- $form .= ' </select>';
- $form .= ' </div>';
- $form .= ' </div>';
- $form .= '<div class="row">';
- $form .= ' <div class="label"></div>';
- $form .= ' <div class="formw">';
- $form .= ' <button type="submit" class="next" name="move_file_submit">'.get_lang('MoveElement').'</button>';
- $form .= ' </div>';
- $form .= '</div>';
- $form .= '</form>';
- $form .= '<div style="clear: both; margin-bottom: 10px;"></div>';
- return $form;
- }
- function get_titles_of_path($path) {
- global $tmp_folders_titles;
- $course_id = api_get_course_int_id();
- $nb_slashes = substr_count($path, '/');
- $tmp_path = '';
- $current_slash_pos = 0;
- $path_displayed = '';
- for ($i = 0; $i < $nb_slashes; $i++) {
-
- $current_slash_pos = strpos($path, '/', $current_slash_pos + 1);
- $tmp_path = substr($path, strpos($path, '/', 0), $current_slash_pos);
- if (empty($tmp_path)) {
-
- $tmp_path = $path;
- }
- if (!empty($tmp_folders_titles[$tmp_path])) {
-
- $path_displayed .= $tmp_folders_titles[$tmp_path];
- } else {
- $sql = 'SELECT title FROM '.Database::get_course_table(TABLE_DOCUMENT).'
- WHERE c_id = '.$course_id.' AND path LIKE BINARY "'.$tmp_path.'"';
- $rs = Database::query($sql);
- $tmp_title = '/'.Database::result($rs, 0, 0);
- $path_displayed .= $tmp_title;
- $tmp_folders_titles[$tmp_path] = $tmp_title;
- }
- }
- return $path_displayed;
- }
- function display_user_link_document($user_id, $name) {
- if ($user_id != 0) {
- return '<a href="../user/userInfo.php?uInfo='.$user_id.'">'.$name.'</a>';
- } else {
- return get_lang('Anonymous');
- }
- }
- function create_dir_form($current_dir_id) {
- global $document_id;
- $new_folder_text = '<form action="'.api_get_self().'" method="post">';
- $new_folder_text .= '<input type="hidden" name="dir_id" value="'.intval($document_id).'" />';
- $new_folder_text .= '<input type="hidden" name="id" value="'.intval($current_dir_id).'" />';
-
- $new_folder_text .= '<div class="row"><div class="form_header">'.get_lang('CreateDir').'</div></div>';
-
- $new_folder_text .= '<div class="row">';
- $new_folder_text .= '<div class="label"><span class="form_required">*</span>'.get_lang('NewDir').'</div>';
- $new_folder_text .= '<div class="formw"><input type="text" name="dirname" /></div>';
- $new_folder_text .= '</div>';
-
- $new_folder_text .= '<div class="row">';
- $new_folder_text .= '<div class="label"> </div>';
- $new_folder_text .= '<div class="formw"><button type="submit" class="add" name="create_dir">'.get_lang('CreateFolder').'</button></div>';
- $new_folder_text .= '</div>';
- $new_folder_text .= '</form>';
- $new_folder_text .= '<div style="clear: both; margin-bottom: 10px;"></div>';
- return $new_folder_text;
- }
- function is_shared_folder($curdirpath, $current_session_id) {
- $clean_curdirpath = Security::remove_XSS($curdirpath);
- if($clean_curdirpath== '/shared_folder'){
- return true;
- }
- elseif($clean_curdirpath== '/shared_folder_session_'.$current_session_id){
- return true;
- }
- else{
- return false;
- }
- }
- function is_any_user_shared_folder($path, $current_session_id) {
- $clean_path = Security::remove_XSS($path);
- if(strpos($clean_path,'shared_folder/sf_user_')){
- return true;
- }
- elseif(strpos($clean_path, 'shared_folder_session_'.$current_session_id.'/sf_user_')){
- return true;
- }
- else{
- return false;
- }
- }
- function is_my_shared_folder($user_id, $path, $current_session_id) {
- $clean_path = Security::remove_XSS($path).'/';
- $main_user_shared_folder = '/shared_folder\/sf_user_'.$user_id.'\//';
- $main_user_shared_folder_session='/shared_folder_session_'.$current_session_id.'\/sf_user_'.$user_id.'\//';
- if (preg_match($main_user_shared_folder, $clean_path)){
- return true;
- } elseif(preg_match($main_user_shared_folder_session, $clean_path)) {
- return true;
- } else {
- return false;
- }
- }
- function search_keyword($document_name, $keyword) {
- if (api_strripos($document_name, $keyword) !== false){
- return true;
- } else {
- return false;
- }
- }
- function is_browser_viewable($file_extension) {
- static $allowed_extensions = array(
- 'htm', 'html', 'xhtml',
- 'gif', 'jpg', 'jpeg', 'png', 'tif', 'tiff',
- 'pdf', 'svg', 'swf',
- 'txt', 'log',
- 'mp4', 'ogg', 'ogv', 'ogx', 'mpg', 'mpeg', 'mov', 'avi', 'webm', 'wmv',
- 'mp3', 'oga', 'wav', 'au', 'wma', 'mid', 'kar'
- );
-
-
-
- if (!($result = in_array($file_extension, $allowed_extensions))) {
- return false;
- }
-
-
- if ($file_extension=="pdf"){
- return api_browser_support('pdf');
- }
- elseif ($file_extension=="mp3"){
- return api_browser_support('mp3');
- }
- elseif ($file_extension=="mp4"){
- return api_browser_support('mp4');
- }
- elseif ($file_extension=="ogg" || $file_extension=="ogx" || $file_extension=="ogv" || $file_extension=="oga"){
- return api_browser_support('ogg');
- }
- elseif ($file_extension=="svg"){
- return api_browser_support('svg');
- }
- elseif ($file_extension=="mpg" || $file_extension=="mpeg"){
- return api_browser_support('mpg');
- }
- elseif ($file_extension=="mov"){
- return api_browser_support('mov');
- }
- elseif ($file_extension=="wav"){
- return api_browser_support('wav');
- }
- elseif ($file_extension=="mid" || $file_extension=="kar"){
- return api_browser_support('mid');
- }
- elseif ($file_extension=="avi"){
- return api_browser_support('avi');
- }
- elseif ($file_extension=="wma"){
- return api_browser_support('wma');
- }
- elseif ($file_extension=="wmv"){
- return api_browser_support('wmv');
- }
- elseif ($file_extension=="tif" || $file_extension=="tiff"){
- return api_browser_support('tif');
- }
- elseif ($file_extension=="mov"){
- return api_browser_support('mov');
- }
- elseif ($file_extension=="au"){
- return api_browser_support('au');
- }
- elseif ($file_extension=="webm"){
- return api_browser_support('webm');
- }
- return $result;
- }
|