From 6e75aa56349d6fad7444e1975911cc5ad4794253 Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Wed, 12 Jan 2011 01:19:04 +0200 Subject: [PATCH 1/5] Feature #1915 - Automatic whitespace cleaning for a selected file. --- main/admin/configure_inscription.php | 790 +++++++++++++-------------- 1 file changed, 395 insertions(+), 395 deletions(-) diff --git a/main/admin/configure_inscription.php b/main/admin/configure_inscription.php index 91c9f30c41..a5beeb2eda 100755 --- a/main/admin/configure_inscription.php +++ b/main/admin/configure_inscription.php @@ -18,76 +18,76 @@ require_once api_get_path(INCLUDE_PATH).'lib/legal.lib.php'; // Load terms & conditions from the current lang if (get_setting('allow_terms_conditions') == 'true') { - $get = array_keys($_GET); - if (isset($get)) { - if ($get[0] == 'legal') { - $language = api_get_interface_language(); - $language = api_get_language_id($language); - $term_preview = LegalManager::get_last_condition($language); - if (!$term_preview) { - //look for the default language - $language = api_get_setting('platformLanguage'); - $language = api_get_language_id($language); - $term_preview = LegalManager::get_last_condition($language); - } - $tool_name = get_lang('TermsAndConditions'); - Display :: display_header(''); - echo '
'; - echo $tool_name; - echo '
'; - if (!empty($term_preview['content'])) { - echo $term_preview['content']; - } else { - echo get_lang('ComingSoon'); - } - Display :: display_footer(); - exit; - } - } + $get = array_keys($_GET); + if (isset($get)) { + if ($get[0] == 'legal') { + $language = api_get_interface_language(); + $language = api_get_language_id($language); + $term_preview = LegalManager::get_last_condition($language); + if (!$term_preview) { + //look for the default language + $language = api_get_setting('platformLanguage'); + $language = api_get_language_id($language); + $term_preview = LegalManager::get_last_condition($language); + } + $tool_name = get_lang('TermsAndConditions'); + Display :: display_header(''); + echo '
'; + echo $tool_name; + echo '
'; + if (!empty($term_preview['content'])) { + echo $term_preview['content']; + } else { + echo get_lang('ComingSoon'); + } + Display :: display_footer(); + exit; + } + } } $action = Security::remove_XSS($_GET['action']); $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); $tool_name = get_lang('ConfigureInscription'); if (!empty($action)) { - $interbreadcrumb[] = array('url' => 'configure_inscription.php', 'name' => get_lang('ConfigureInscription')); - switch($action) { - case 'edit_top': - $tool_name = get_lang('EditTopRegister'); - break; - } + $interbreadcrumb[] = array('url' => 'configure_inscription.php', 'name' => get_lang('ConfigureInscription')); + switch($action) { + case 'edit_top': + $tool_name = get_lang('EditTopRegister'); + break; + } } $lang = ''; //el for "Edit Language" if (!empty($_SESSION['user_language_choice'])) { - $lang = $_SESSION['user_language_choice']; + $lang = $_SESSION['user_language_choice']; } elseif (!empty($_SESSION['_user']['language'])) { - $lang = $_SESSION['_user']['language']; + $lang = $_SESSION['_user']['language']; } else { - $lang = get_setting('platformLanguage'); + $lang = get_setting('platformLanguage'); } // ----- Ensuring availability of main files in the corresponding language ----- if ($_configuration['multiple_access_urls']) { - $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1) { - $url_info = api_get_access_url($access_url_id); - $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url'])); - $clean_url = replace_dangerous_char($url); - $clean_url = str_replace('/', '-', $clean_url); - $clean_url .= '/'; - - $homep = api_get_path(SYS_PATH).'home/'; //homep for Home Path - $homep_new = api_get_path(SYS_PATH).'home/'.$clean_url; //homep for Home Path added the url - $new_url_dir = api_get_path(SYS_PATH).'home/'.$clean_url; - //we create the new dir for the new sites - if (!is_dir($new_url_dir)){ - mkdir($new_url_dir, api_get_permissions_for_new_directories()); - } - } + $access_url_id = api_get_current_access_url_id(); + if ($access_url_id != -1) { + $url_info = api_get_access_url($access_url_id); + $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url'])); + $clean_url = replace_dangerous_char($url); + $clean_url = str_replace('/', '-', $clean_url); + $clean_url .= '/'; + + $homep = api_get_path(SYS_PATH).'home/'; //homep for Home Path + $homep_new = api_get_path(SYS_PATH).'home/'.$clean_url; //homep for Home Path added the url + $new_url_dir = api_get_path(SYS_PATH).'home/'.$clean_url; + //we create the new dir for the new sites + if (!is_dir($new_url_dir)){ + mkdir($new_url_dir, api_get_permissions_for_new_directories()); + } + } } else { - $homep_new = ''; - $homep = api_get_path(SYS_PATH).'home/'; //homep for Home Path + $homep_new = ''; + $homep = api_get_path(SYS_PATH).'home/'; //homep for Home Path } $topf = 'register_top'; //topf for Top File @@ -96,65 +96,65 @@ $homef = array($topf); // If language-specific file does not exist, create it by copying default file foreach ($homef as $my_file) { - if ($_configuration['multiple_access_urls']) { - if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) { - copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext); - } - } else { - if (!file_exists($homep.$my_file.'_'.$lang.$ext)) { - copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext); - } - } + if ($_configuration['multiple_access_urls']) { + if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) { + copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext); + } + } else { + if (!file_exists($homep.$my_file.'_'.$lang.$ext)) { + copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext); + } + } } if (!empty($action)) { - if ($_POST['formSent']) { - switch ($action) { - case 'edit_top': - // Filter - $home_top = ''; - if (api_get_setting('wcag_anysurfer_public_pages') == 'true') { - $home_top = WCAG_Rendering::prepareXHTML(); - } else { - $home_top = trim(stripslashes($_POST['register_top'])); - } - // Write - if (file_exists($homep.$topf.'_'.$lang.$ext)) { - if (is_writable($homep.$topf.'_'.$lang.$ext)) { - $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); - fputs($fp, $home_top); - fclose($fp); - } else { - $errorMsg = get_lang('HomePageFilesNotWritable'); - } - } else { - //File does not exist - $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); - fputs($fp, $home_top); - fclose($fp); - } - break; - } - if (empty($errorMsg)) { - header('Location: '.api_get_self()); - exit(); - } - } else { - switch ($action) { - case 'edit_top': - // This request is only the preparation for the update of the home_top - $home_top = ''; - if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) { - $home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext); - } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) { - $home_top = @(string)file_get_contents($homep.$topf.$lang.$ext); - } else { - $errorMsg = get_lang('HomePageFilesNotReadable'); - } - $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top))); - break; - } - } + if ($_POST['formSent']) { + switch ($action) { + case 'edit_top': + // Filter + $home_top = ''; + if (api_get_setting('wcag_anysurfer_public_pages') == 'true') { + $home_top = WCAG_Rendering::prepareXHTML(); + } else { + $home_top = trim(stripslashes($_POST['register_top'])); + } + // Write + if (file_exists($homep.$topf.'_'.$lang.$ext)) { + if (is_writable($homep.$topf.'_'.$lang.$ext)) { + $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); + fputs($fp, $home_top); + fclose($fp); + } else { + $errorMsg = get_lang('HomePageFilesNotWritable'); + } + } else { + //File does not exist + $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); + fputs($fp, $home_top); + fclose($fp); + } + break; + } + if (empty($errorMsg)) { + header('Location: '.api_get_self()); + exit(); + } + } else { + switch ($action) { + case 'edit_top': + // This request is only the preparation for the update of the home_top + $home_top = ''; + if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) { + $home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext); + } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) { + $home_top = @(string)file_get_contents($homep.$topf.$lang.$ext); + } else { + $errorMsg = get_lang('HomePageFilesNotReadable'); + } + $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top))); + break; + } + } } Display :: display_header($tool_name); @@ -165,253 +165,253 @@ echo ''; // Forbidden to self-register if (get_setting('allow_registration') == 'false') { - api_not_allowed(); + api_not_allowed(); } //api_display_tool_title($tool_name); if (get_setting('allow_registration') == 'approval') { - Display::display_normal_message(get_lang('YourAccountHasToBeApproved')); + Display::display_normal_message(get_lang('YourAccountHasToBeApproved')); } //if openid was not found if (!empty($_GET['openid_msg']) && $_GET['openid_msg'] == 'idnotfound') { - Display::display_warning_message(get_lang('OpenIDCouldNotBeFoundPleaseRegister')); + Display::display_warning_message(get_lang('OpenIDCouldNotBeFoundPleaseRegister')); } $form = new FormValidator('registration'); if (get_setting('allow_terms_conditions') == 'true') { - $display_all_form = !isset($_SESSION['update_term_and_condition'][1]); + $display_all_form = !isset($_SESSION['update_term_and_condition'][1]); } else { - $display_all_form = true; + $display_all_form = true; } if ($display_all_form) { - if (api_is_western_name_order()) { - // FIRST NAME and LAST NAME + if (api_is_western_name_order()) { + // FIRST NAME and LAST NAME $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40, 'disabled' => 'disabled')); - $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40, 'disabled' => 'disabled')); - } else { - // LAST NAME and FIRST NAME - $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40, 'disabled' => 'disabled')); - $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40, 'disabled' => 'disabled')); - } - $form->applyFilter('firstname', 'trim'); - $form->applyFilter('lastname', 'trim'); - $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required'); - $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required'); - - // EMAIL - $form->addElement('text', 'email', get_lang('Email'), array('size' => 40, 'disabled' => 'disabled')); - if (api_get_setting('registration', 'email') == 'true') { - $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required'); - } - $form->addRule('email', get_lang('EmailWrong'), 'email'); - if (api_get_setting('openid_authentication') == 'true') { - $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40, 'disabled' => 'disabled')); - } - - // USERNAME - $form->addElement('text', 'username', get_lang('UserName'), array('size' => USERNAME_MAX_LENGTH, 'disabled' => 'disabled')); - $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required'); - $form->addRule('username', get_lang('UsernameWrong'), 'username'); - $form->addRule('username', get_lang('UserTaken'), 'username_available'); - $form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH); - - // PASSWORD - $form->addElement('password', 'pass1', get_lang('Pass'), array('size' => 40, 'disabled' => 'disabled')); - $form->addElement('password', 'pass2', get_lang('Confirmation'), array('size' => 40, 'disabled' => 'disabled')); - $form->addRule('pass1', get_lang('ThisFieldIsRequired'), 'required'); - $form->addRule('pass2', get_lang('ThisFieldIsRequired'), 'required'); - $form->addRule(array('pass1', 'pass2'), get_lang('PassTwo'), 'compare'); - if (CHECK_PASS_EASY_TO_FIND) { - $form->addRule('password1', get_lang('PassTooEasy').': '.api_generate_password(), 'callback', 'api_check_password'); - } - - // PHONE - $form->addElement('text', 'phone', get_lang('Phone'), array('size' => 40, 'disabled' => 'disabled')); - if (api_get_setting('registration', 'phone') == 'true') { - $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required'); - } - - // LANGUAGE - if (get_setting('registration', 'language') == 'true') { - $form->addElement('select_language', 'language', get_lang('Language'), '', array('disabled' => 'disabled')); - } - - // STUDENT/TEACHER - if (get_setting('allow_registration_as_teacher') != 'false') { - $form->addElement('radio', 'status', get_lang('Status'), get_lang('RegStudent'), STUDENT, array('disabled' => 'disabled')); - $form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER, array('disabled' => 'disabled')); - } - - // EXTENDED FIELDS - if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration','mycomptetences') == 'true') { - $form->add_html_editor('competences', get_lang('MyCompetences'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130')); - } - if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration','mydiplomas') == 'true') { - $form->add_html_editor('diplomas', get_lang('MyDiplomas'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130')); - } - if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration','myteach') == 'true') { - $form->add_html_editor('teach', get_lang('MyTeach'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130')); - } - if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration','mypersonalopenarea') == 'true') { - $form->add_html_editor('openarea', get_lang('MyPersonalOpenArea'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130')); - } - if (api_get_setting('extended_profile') == 'true') { - if (api_get_setting('extendedprofile_registrationrequired', 'mycomptetences') == 'true') { - $form->addRule('competences', get_lang('ThisFieldIsRequired'), 'required'); - } - if (api_get_setting('extendedprofile_registrationrequired', 'mydiplomas') == 'true') { - $form->addRule('diplomas', get_lang('ThisFieldIsRequired'), 'required'); - } - if (api_get_setting('extendedprofile_registrationrequired', 'myteach') == 'true') { - $form->addRule('teach', get_lang('ThisFieldIsRequired'), 'required'); - } - if (api_get_setting('extendedprofile_registrationrequired', 'mypersonalopenarea') == 'true') { - $form->addRule('openarea', get_lang('ThisFieldIsRequired'), 'required'); - } - } - - // EXTRA FIELDS - $extra = UserManager::get_extra_fields(0, 50, 5, 'ASC'); - $extra_data = UserManager::get_extra_user_data(api_get_user_id(), true); - foreach ($extra as $id => $field_details) { - if ($field_details[6] == 0) { - continue; - } - switch($field_details[2]) { - case USER_FIELD_TYPE_TEXT: - $form->addElement('text', 'extra_'.$field_details[1], $field_details[3], array('size' => 40)); - $form->applyFilter('extra_'.$field_details[1], 'stripslashes'); - $form->applyFilter('extra_'.$field_details[1], 'trim'); - if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); - break; - case USER_FIELD_TYPE_TEXTAREA: - $form->add_html_editor('extra_'.$field_details[1], $field_details[3], false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130')); - //$form->addElement('textarea', 'extra_'.$field_details[1], $field_details[3], array('size' => 80)); - $form->applyFilter('extra_'.$field_details[1], 'stripslashes'); - $form->applyFilter('extra_'.$field_details[1], 'trim'); - if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); - break; - case USER_FIELD_TYPE_RADIO: - $group = array(); - foreach ($field_details[9] as $option_id => $option_details) { - $options[$option_details[1]] = $option_details[2]; - $group[] =& HTML_QuickForm::createElement('radio', 'extra_'.$field_details[1], $option_details[1],$option_details[2].'
',$option_details[1]); - } - $form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], ''); - if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); - break; - case USER_FIELD_TYPE_SELECT: - $options = array(); - foreach($field_details[9] as $option_id => $option_details) { - $options[$option_details[1]] = $option_details[2]; - } - $form->addElement('select','extra_'.$field_details[1], $field_details[3], $options, ''); - if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); - break; - case USER_FIELD_TYPE_SELECT_MULTIPLE: - $options = array(); - foreach ($field_details[9] as $option_id => $option_details) { - $options[$option_details[1]] = $option_details[2]; - } - $form->addElement('select','extra_'.$field_details[1], $field_details[3], $options, array('multiple' => 'multiple')); - if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); - break; - case USER_FIELD_TYPE_DATE: - $form->addElement('datepickerdate', 'extra_'.$field_details[1], $field_details[3], array('form_name' => 'registration')); - $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900); - $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00'); - $form -> setDefaults($defaults); - if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); - $form->applyFilter('theme', 'trim'); - break; - case USER_FIELD_TYPE_DATETIME: - $form->addElement('datepicker', 'extra_'.$field_details[1], $field_details[3], array('form_name' => 'registration')); - $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900); - $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00'); - $form -> setDefaults($defaults); - if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); - $form->applyFilter('theme', 'trim'); - break; - case USER_FIELD_TYPE_DOUBLE_SELECT: - foreach ($field_details[9] as $key => $element) { - if ($element[2][0] == '*') { - $values['*'][$element[0]] = str_replace('*', '', $element[2]); - } else { - $values[0][$element[0]] = $element[2]; - } - } - - $group = ''; - $group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1], '', $values[0], ''); - $group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1].'*', '', $values['*'], ''); - $form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], ' '); - if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); - - // recoding the selected values for double : if the user has selected certain values, we have to assign them to the correct select form - if (key_exists('extra_'.$field_details[1], $extra_data)) { - // exploding all the selected values (of both select forms) - $selected_values = explode(';', $extra_data['extra_'.$field_details[1]]); - $extra_data['extra_'.$field_details[1]] = array(); - - // looping through the selected values and assigning the selected values to either the first or second select form - foreach ($selected_values as $key => $selected_value) { - if (key_exists($selected_value,$values[0])) { - $extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1]] = $selected_value; - } else { - $extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1].'*'] = $selected_value; - } - } - } - break; - case USER_FIELD_TYPE_DIVIDER: - $form->addElement('static', $field_details[1], '
'.$field_details[3].''); - break; - } - } + $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40, 'disabled' => 'disabled')); + } else { + // LAST NAME and FIRST NAME + $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40, 'disabled' => 'disabled')); + $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40, 'disabled' => 'disabled')); + } + $form->applyFilter('firstname', 'trim'); + $form->applyFilter('lastname', 'trim'); + $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required'); + $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required'); + + // EMAIL + $form->addElement('text', 'email', get_lang('Email'), array('size' => 40, 'disabled' => 'disabled')); + if (api_get_setting('registration', 'email') == 'true') { + $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required'); + } + $form->addRule('email', get_lang('EmailWrong'), 'email'); + if (api_get_setting('openid_authentication') == 'true') { + $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40, 'disabled' => 'disabled')); + } + + // USERNAME + $form->addElement('text', 'username', get_lang('UserName'), array('size' => USERNAME_MAX_LENGTH, 'disabled' => 'disabled')); + $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required'); + $form->addRule('username', get_lang('UsernameWrong'), 'username'); + $form->addRule('username', get_lang('UserTaken'), 'username_available'); + $form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH); + + // PASSWORD + $form->addElement('password', 'pass1', get_lang('Pass'), array('size' => 40, 'disabled' => 'disabled')); + $form->addElement('password', 'pass2', get_lang('Confirmation'), array('size' => 40, 'disabled' => 'disabled')); + $form->addRule('pass1', get_lang('ThisFieldIsRequired'), 'required'); + $form->addRule('pass2', get_lang('ThisFieldIsRequired'), 'required'); + $form->addRule(array('pass1', 'pass2'), get_lang('PassTwo'), 'compare'); + if (CHECK_PASS_EASY_TO_FIND) { + $form->addRule('password1', get_lang('PassTooEasy').': '.api_generate_password(), 'callback', 'api_check_password'); + } + + // PHONE + $form->addElement('text', 'phone', get_lang('Phone'), array('size' => 40, 'disabled' => 'disabled')); + if (api_get_setting('registration', 'phone') == 'true') { + $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required'); + } + + // LANGUAGE + if (get_setting('registration', 'language') == 'true') { + $form->addElement('select_language', 'language', get_lang('Language'), '', array('disabled' => 'disabled')); + } + + // STUDENT/TEACHER + if (get_setting('allow_registration_as_teacher') != 'false') { + $form->addElement('radio', 'status', get_lang('Status'), get_lang('RegStudent'), STUDENT, array('disabled' => 'disabled')); + $form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER, array('disabled' => 'disabled')); + } + + // EXTENDED FIELDS + if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration','mycomptetences') == 'true') { + $form->add_html_editor('competences', get_lang('MyCompetences'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130')); + } + if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration','mydiplomas') == 'true') { + $form->add_html_editor('diplomas', get_lang('MyDiplomas'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130')); + } + if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration','myteach') == 'true') { + $form->add_html_editor('teach', get_lang('MyTeach'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130')); + } + if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration','mypersonalopenarea') == 'true') { + $form->add_html_editor('openarea', get_lang('MyPersonalOpenArea'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130')); + } + if (api_get_setting('extended_profile') == 'true') { + if (api_get_setting('extendedprofile_registrationrequired', 'mycomptetences') == 'true') { + $form->addRule('competences', get_lang('ThisFieldIsRequired'), 'required'); + } + if (api_get_setting('extendedprofile_registrationrequired', 'mydiplomas') == 'true') { + $form->addRule('diplomas', get_lang('ThisFieldIsRequired'), 'required'); + } + if (api_get_setting('extendedprofile_registrationrequired', 'myteach') == 'true') { + $form->addRule('teach', get_lang('ThisFieldIsRequired'), 'required'); + } + if (api_get_setting('extendedprofile_registrationrequired', 'mypersonalopenarea') == 'true') { + $form->addRule('openarea', get_lang('ThisFieldIsRequired'), 'required'); + } + } + + // EXTRA FIELDS + $extra = UserManager::get_extra_fields(0, 50, 5, 'ASC'); + $extra_data = UserManager::get_extra_user_data(api_get_user_id(), true); + foreach ($extra as $id => $field_details) { + if ($field_details[6] == 0) { + continue; + } + switch($field_details[2]) { + case USER_FIELD_TYPE_TEXT: + $form->addElement('text', 'extra_'.$field_details[1], $field_details[3], array('size' => 40)); + $form->applyFilter('extra_'.$field_details[1], 'stripslashes'); + $form->applyFilter('extra_'.$field_details[1], 'trim'); + if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); + break; + case USER_FIELD_TYPE_TEXTAREA: + $form->add_html_editor('extra_'.$field_details[1], $field_details[3], false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130')); + //$form->addElement('textarea', 'extra_'.$field_details[1], $field_details[3], array('size' => 80)); + $form->applyFilter('extra_'.$field_details[1], 'stripslashes'); + $form->applyFilter('extra_'.$field_details[1], 'trim'); + if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); + break; + case USER_FIELD_TYPE_RADIO: + $group = array(); + foreach ($field_details[9] as $option_id => $option_details) { + $options[$option_details[1]] = $option_details[2]; + $group[] =& HTML_QuickForm::createElement('radio', 'extra_'.$field_details[1], $option_details[1],$option_details[2].'
',$option_details[1]); + } + $form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], ''); + if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); + break; + case USER_FIELD_TYPE_SELECT: + $options = array(); + foreach($field_details[9] as $option_id => $option_details) { + $options[$option_details[1]] = $option_details[2]; + } + $form->addElement('select','extra_'.$field_details[1], $field_details[3], $options, ''); + if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); + break; + case USER_FIELD_TYPE_SELECT_MULTIPLE: + $options = array(); + foreach ($field_details[9] as $option_id => $option_details) { + $options[$option_details[1]] = $option_details[2]; + } + $form->addElement('select','extra_'.$field_details[1], $field_details[3], $options, array('multiple' => 'multiple')); + if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); + break; + case USER_FIELD_TYPE_DATE: + $form->addElement('datepickerdate', 'extra_'.$field_details[1], $field_details[3], array('form_name' => 'registration')); + $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900); + $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00'); + $form -> setDefaults($defaults); + if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); + $form->applyFilter('theme', 'trim'); + break; + case USER_FIELD_TYPE_DATETIME: + $form->addElement('datepicker', 'extra_'.$field_details[1], $field_details[3], array('form_name' => 'registration')); + $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900); + $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00'); + $form -> setDefaults($defaults); + if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); + $form->applyFilter('theme', 'trim'); + break; + case USER_FIELD_TYPE_DOUBLE_SELECT: + foreach ($field_details[9] as $key => $element) { + if ($element[2][0] == '*') { + $values['*'][$element[0]] = str_replace('*', '', $element[2]); + } else { + $values[0][$element[0]] = $element[2]; + } + } + + $group = ''; + $group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1], '', $values[0], ''); + $group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1].'*', '', $values['*'], ''); + $form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], ' '); + if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); + + // recoding the selected values for double : if the user has selected certain values, we have to assign them to the correct select form + if (key_exists('extra_'.$field_details[1], $extra_data)) { + // exploding all the selected values (of both select forms) + $selected_values = explode(';', $extra_data['extra_'.$field_details[1]]); + $extra_data['extra_'.$field_details[1]] = array(); + + // looping through the selected values and assigning the selected values to either the first or second select form + foreach ($selected_values as $key => $selected_value) { + if (key_exists($selected_value,$values[0])) { + $extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1]] = $selected_value; + } else { + $extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1].'*'] = $selected_value; + } + } + } + break; + case USER_FIELD_TYPE_DIVIDER: + $form->addElement('static', $field_details[1], '
'.$field_details[3].''); + break; + } + } } // Terms and conditions if (get_setting('allow_terms_conditions') == 'true') { - $language = api_get_interface_language(); - $language = api_get_language_id($language); - $term_preview = LegalManager::get_last_condition($language); - - if (!$term_preview) { - //we load from the platform - $language = api_get_setting('platformLanguage'); - $language = api_get_language_id($language); - $term_preview = LegalManager::get_last_condition($language); - //if is false we load from english - if (!$term_preview) { - $language = api_get_language_id('english'); //this must work - $term_preview = LegalManager::get_last_condition($language); - } - } - // Version and language //password - $form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']); - $form->addElement('hidden', 'legal_info', $term_preview['legal_id'].':'.$term_preview['language_id']); - if (isset($_SESSION['info_current_user'][1]) && isset($_SESSION['info_current_user'][2])) { - $form->addElement('hidden', 'login', $_SESSION['info_current_user'][1]); - $form->addElement('hidden', 'password', $_SESSION['info_current_user'][2]); - } - if ($term_preview['type'] == 1) { - $form->addElement('checkbox', 'legal_accept', null, get_lang('IHaveReadAndAgree').' '.get_lang('TermsAndConditions').''); - $form->addRule('extra_legal_accept', get_lang('ThisFieldIsRequired'), 'required'); - } else { - if (!empty($term_preview['content'])) { - $preview = LegalManager::show_last_condition($term_preview); - $term_preview = '
-
'.get_lang('TermsAndConditions').'
-
- '.$preview.' -
-
-
'; - $form->addElement('html', $term_preview); - } - } + $language = api_get_interface_language(); + $language = api_get_language_id($language); + $term_preview = LegalManager::get_last_condition($language); + + if (!$term_preview) { + //we load from the platform + $language = api_get_setting('platformLanguage'); + $language = api_get_language_id($language); + $term_preview = LegalManager::get_last_condition($language); + //if is false we load from english + if (!$term_preview) { + $language = api_get_language_id('english'); //this must work + $term_preview = LegalManager::get_last_condition($language); + } + } + // Version and language //password + $form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']); + $form->addElement('hidden', 'legal_info', $term_preview['legal_id'].':'.$term_preview['language_id']); + if (isset($_SESSION['info_current_user'][1]) && isset($_SESSION['info_current_user'][2])) { + $form->addElement('hidden', 'login', $_SESSION['info_current_user'][1]); + $form->addElement('hidden', 'password', $_SESSION['info_current_user'][2]); + } + if ($term_preview['type'] == 1) { + $form->addElement('checkbox', 'legal_accept', null, get_lang('IHaveReadAndAgree').' '.get_lang('TermsAndConditions').''); + $form->addRule('extra_legal_accept', get_lang('ThisFieldIsRequired'), 'required'); + } else { + if (!empty($term_preview['content'])) { + $preview = LegalManager::show_last_condition($term_preview); + $term_preview = '
+
'.get_lang('TermsAndConditions').'
+
+ '.$preview.' +
+
+
'; + $form->addElement('html', $term_preview); + } + } } $form->addElement('style_submit_button', 'submit', get_lang('RegisterUser'), array('class' => 'save', 'disabled' => 'disabled')); @@ -419,84 +419,84 @@ $form->addElement('style_submit_button', 'submit', get_lang('RegisterUser'), arr $defaults['status'] = STUDENT; if (isset($_SESSION['user_language_choice']) && $_SESSION['user_language_choice'] != '') { - $defaults['language'] = $_SESSION['user_language_choice']; + $defaults['language'] = $_SESSION['user_language_choice']; } else { - $defaults['language'] = api_get_setting('platformLanguage'); + $defaults['language'] = api_get_setting('platformLanguage'); } if (!empty($_GET['username'])) { - $defaults['username'] = Security::remove_XSS($_GET['username']); + $defaults['username'] = Security::remove_XSS($_GET['username']); } if (!empty($_GET['email'])) { - $defaults['email'] = Security::remove_XSS($_GET['email']); + $defaults['email'] = Security::remove_XSS($_GET['email']); } if (!empty($_GET['phone'])) { - $defaults['phone'] = Security::remove_XSS($_GET['phone']); + $defaults['phone'] = Security::remove_XSS($_GET['phone']); } if (api_get_setting('openid_authentication') == 'true' && !empty($_GET['openid'])) { - $defaults['openid'] = Security::remove_XSS($_GET['openid']); + $defaults['openid'] = Security::remove_XSS($_GET['openid']); } $form->setDefaults($defaults); switch ($action){ - case 'edit_top': - if ($action == 'edit_top') { - $name = $topf; - $open = $home_top; - } else { - $name = $newsf; - $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext); - $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); - } - - if (!empty($errorMsg)) { - Display::display_normal_message($errorMsg); - } - - $default = array(); - $form = new FormValidator('configure_inscription_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;')); - $renderer =& $form->defaultRenderer(); - $renderer->setHeaderTemplate(''); - $renderer->setFormTemplate('{content}
'); - $renderer->setElementTemplate('{element}'); - $renderer->setRequiredNoteTemplate(''); - $form->addElement('hidden', 'formSent', '1'); - if (api_get_setting('wcag_anysurfer_public_pages') == 'true') { - //TODO: review these lines - // Print WCAG-specific HTML editor - $html = ''; - $html .= WCAG_Rendering::create_xhtml($open); - $html .= ''; - $form->addElement('html', $html); - } else { - $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open); - $form->add_html_editor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); - } - $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"'); - $form->setDefaults($default); - $form->display(); - break; - default: - //Form of language - api_display_language_form(); - echo '  '.Display::display_icon('edit.gif', get_lang('Edit')).' '.get_lang('EditNotice').''; - //echo '
'; - echo '
'; - $open = ''; - if (file_exists($homep.$topf.'_'.$lang.$ext)) { - $open = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext); - } else { - $open = @(string)file_get_contents($homep.$topf.$ext); - } - $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); - echo $open; - echo '
'; - $form->display(); - break; + case 'edit_top': + if ($action == 'edit_top') { + $name = $topf; + $open = $home_top; + } else { + $name = $newsf; + $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext); + $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); + } + + if (!empty($errorMsg)) { + Display::display_normal_message($errorMsg); + } + + $default = array(); + $form = new FormValidator('configure_inscription_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;')); + $renderer =& $form->defaultRenderer(); + $renderer->setHeaderTemplate(''); + $renderer->setFormTemplate('{content}
'); + $renderer->setElementTemplate('{element}'); + $renderer->setRequiredNoteTemplate(''); + $form->addElement('hidden', 'formSent', '1'); + if (api_get_setting('wcag_anysurfer_public_pages') == 'true') { + //TODO: review these lines + // Print WCAG-specific HTML editor + $html = ''; + $html .= WCAG_Rendering::create_xhtml($open); + $html .= ''; + $form->addElement('html', $html); + } else { + $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open); + $form->add_html_editor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); + } + $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"'); + $form->setDefaults($default); + $form->display(); + break; + default: + //Form of language + api_display_language_form(); + echo '  '.Display::display_icon('edit.gif', get_lang('Edit')).' '.get_lang('EditNotice').''; + //echo '
'; + echo '
'; + $open = ''; + if (file_exists($homep.$topf.'_'.$lang.$ext)) { + $open = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext); + } else { + $open = @(string)file_get_contents($homep.$topf.$ext); + } + $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); + echo $open; + echo '
'; + $form->display(); + break; } Display :: display_footer(); From bc6f95beb9325110cdd5c5e8f43d758be1a85e39 Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Wed, 12 Jan 2011 01:50:10 +0200 Subject: [PATCH 2/5] Bug 1846 - Platform administration: Removing irrelevant that prevents accessing "Setting the registration page". --- documentation/changelog.html | 3 +++ main/admin/configure_inscription.php | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/documentation/changelog.html b/documentation/changelog.html index d110664264..6ebdc0889b 100755 --- a/documentation/changelog.html +++ b/documentation/changelog.html @@ -89,6 +89,9 @@
  • Wiki: Fixed links with accents and special characters do not work well in utf-8 #2286
  • A student can edit a file through url into documents tool after visit his/her group #2485
  • Social network to run from 1024x768 #1958
  • +
  • Irrelevant check has been removed, it prevented the page "Administration > Setting the registration page" to be accessed + in the case of assigned value "No" to the setting "Administration > Configuration settings > Portal > Registration". + This bug has been reported by Wolfgang in the forum and by Oliver Corre in the Chamilo support site (Bug #1846)
  • Security

    diff --git a/main/admin/configure_inscription.php b/main/admin/configure_inscription.php index a5beeb2eda..ab8cc15a5d 100755 --- a/main/admin/configure_inscription.php +++ b/main/admin/configure_inscription.php @@ -163,10 +163,12 @@ echo '
    '; echo $tool_name; echo '
    '; -// Forbidden to self-register -if (get_setting('allow_registration') == 'false') { - api_not_allowed(); -} +// The following security condition has been removed, because it makes no sense here. See Bug #1846. +//// Forbidden to self-register +//if (get_setting('allow_registration') == 'false') { +// api_not_allowed(); +//} + //api_display_tool_title($tool_name); if (get_setting('allow_registration') == 'approval') { Display::display_normal_message(get_lang('YourAccountHasToBeApproved')); From d92602b96c8d51b5d6cc08b74bca847873beae25 Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Wed, 12 Jan 2011 13:28:50 +0200 Subject: [PATCH 3/5] Automatic whitespace cleaning for some files, a new task is to be opened for further changes on them. --- main/document/document.inc.php | 1082 ++++++++++++------------ main/document/document.php | 1434 ++++++++++++++++---------------- 2 files changed, 1258 insertions(+), 1258 deletions(-) diff --git a/main/document/document.inc.php b/main/document/document.inc.php index e645669a36..c5c972603f 100755 --- a/main/document/document.inc.php +++ b/main/document/document.inc.php @@ -15,76 +15,76 @@ */ function build_directory_selector($folders, $curdirpath, $group_dir = '', $change_renderer = false) { - $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); - $doc_table = Database::get_course_table(TABLE_DOCUMENT); - $sql = "SELECT * FROM $doc_table WHERE filetype='folder' 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); - } - } - } - - require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; - $form = new FormValidator('selector', 'POST', api_get_self()); - - $parent_select = $form->addElement('select', 'curdirpath', get_lang('CurrentDirectory'), '', 'onchange="javascript: document.selector.submit();"'); - - if ($change_renderer) { - $renderer = $form->defaultRenderer(); - $renderer->setElementTemplate('{label} : {element} ','curdirpath'); - } - - // Group documents cannot be uploaded in the root - if (empty($group_dir)) { - $parent_select -> addOption(get_lang('Documents'), '/'); - if (is_array($folders)) { - foreach ($folders as & $folder) { - $selected = ($curdirpath == $folder) ? ' 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); - if ($selected != '') { - $parent_select->setSelected($folder); - } - } - } - } else { - foreach ($folders as & $folder) { - $selected = ($curdirpath==$folder) ? ' 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); - if ($selected != '') { - $parent_select->setSelected($folder); - } - } - } - - $form = $form->toHtml(); - - return $form; + $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); + $doc_table = Database::get_course_table(TABLE_DOCUMENT); + $sql = "SELECT * FROM $doc_table WHERE filetype='folder' 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); + } + } + } + + require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; + $form = new FormValidator('selector', 'POST', api_get_self()); + + $parent_select = $form->addElement('select', 'curdirpath', get_lang('CurrentDirectory'), '', 'onchange="javascript: document.selector.submit();"'); + + if ($change_renderer) { + $renderer = $form->defaultRenderer(); + $renderer->setElementTemplate('{label} : {element} ','curdirpath'); + } + + // Group documents cannot be uploaded in the root + if (empty($group_dir)) { + $parent_select -> addOption(get_lang('Documents'), '/'); + if (is_array($folders)) { + foreach ($folders as & $folder) { + $selected = ($curdirpath == $folder) ? ' 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); + if ($selected != '') { + $parent_select->setSelected($folder); + } + } + } + } else { + foreach ($folders as & $folder) { + $selected = ($curdirpath==$folder) ? ' 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); + if ($selected != '') { + $parent_select->setSelected($folder); + } + } + } + + $form = $form->toHtml(); + + return $form; } /** @@ -99,121 +99,121 @@ function build_directory_selector($folders, $curdirpath, $group_dir = '', $chang * @return string url */ function create_document_link($www, $title, $path, $filetype, $size, $visibility, $show_as_icon = false) { - global $dbl_click_id; - if (isset($_SESSION['_gid'])) { - $req_gid = '&gidReq='.$_SESSION['_gid']; - } else { - $req_gid = ''; - } - $url_path = urlencode($path); - // Add class="invisible" on invisible files - $visibility_class = ($visibility == 0) ? ' class="invisible"' : ''; - - if (!$show_as_icon) { - // Build download link (icon) - $forcedownload_link = ($filetype == 'folder') ? api_get_self().'?'.api_get_cidreq().'&action=downloadfolder&path='.$url_path.$req_gid : api_get_self().'?'.api_get_cidreq().'&action=download&id='.$url_path.$req_gid; - // Folder download or file download? - $forcedownload_icon = ($filetype == 'folder') ? 'folder_zip.gif' : 'filesave.gif'; - // Prevent multiple clicks on zipped folder download - $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'; - if ($filetype == 'file') { - // Check the extension - $ext = explode('.', $path); - $ext = strtolower($ext[sizeof($ext) - 1]); - - // "htmlfiles" are shown in a frameset - if ($ext == 'htm' || $ext == 'html' || $ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'pdf' || $ext == 'swf' || $ext == 'mp3' || $ext == 'mp4' ||(($ext== 'ogg' || $ext== 'ogx' || $ext== 'oga' || $ext== 'ogv') && api_browser_support('ogg')) ||($ext == 'svg' && api_browser_support('svg'))) { - $url = 'showinframes.php?'.api_get_cidreq().'&file='.$url_path.$req_gid; - } else { - // url-encode for problematic characters (we may not call them dangerous characters...) - $path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq(); - $url = $www.$path; - } - // Files that we want opened in a new window - if ($ext == 'txt' || $ext == 'log' || $ext == 'css' || $ext == 'js') { // Add here - $target = '_blank'; - } - } else { - $url = api_get_self().'?'.api_get_cidreq().'&curdirpath='.$url_path.$req_gid; - } - - // The little download icon - //$tooltip_title = str_replace('?cidReq='.$_GET['cidReq'], '', basename($path)); - $tooltip_title = explode('?', basename($path)); - $tooltip_title = $tooltip_title[0]; - - $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($current_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(); - if (!$show_as_icon) { - if ($filetype == 'folder') { - if (api_is_allowed_to_edit() || api_is_platform_admin() || api_get_setting('students_download_folders') == 'true') { - //filter when I am into shared folder, I can show for donwload only my shared folder - if(is_shared_folder($_GET['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) ? '' : ''.Display::return_icon($forcedownload_icon, get_lang('Download'), array('height'=>'16', 'width' => '16')).''; - } - } - elseif(!preg_match('/shared_folder/', urldecode($forcedownload_link)) || api_is_allowed_to_edit() || api_is_platform_admin()) - { - $force_download_html = ($size == 0) ? '' : ''.Display::return_icon($forcedownload_icon, get_lang('Download'), array('height'=>'16', 'width' => '16')).''; - } - } - } else { - $force_download_html = ($size==0)?'':''.Display::return_icon($forcedownload_icon, get_lang('Download'), array('height'=>'16', 'width' => '16')).''; - } - - //copy files to users myfiles - if(api_get_setting('users_copy_files') == 'true' && api_get_user_id() != 0){ - $copy_myfiles_link = ($filetype == 'file') ? api_get_self().'?'.api_get_cidreq().'&curdirpath='.$_GET['curdirpath'].'&action=copytomyfiles&id='.$url_path.$req_gid :api_get_self().'?'.api_get_cidreq(); - - if($filetype == 'file') - { - $copy_to_myfiles=''.Display::return_icon('briefcase_small.png', get_lang('CopyToMyFiles'), array('height'=>'16', 'width' => '16')).'  '; - } - } - return ''.$title.''.$force_download_html.$copy_to_myfiles; - //end copy files to users myfiles - } - 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){ - return ''.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22)).''; - } - else{ - return ''.build_document_icon_tag($filetype, $path).''; - } - } + global $dbl_click_id; + if (isset($_SESSION['_gid'])) { + $req_gid = '&gidReq='.$_SESSION['_gid']; + } else { + $req_gid = ''; + } + $url_path = urlencode($path); + // Add class="invisible" on invisible files + $visibility_class = ($visibility == 0) ? ' class="invisible"' : ''; + + if (!$show_as_icon) { + // Build download link (icon) + $forcedownload_link = ($filetype == 'folder') ? api_get_self().'?'.api_get_cidreq().'&action=downloadfolder&path='.$url_path.$req_gid : api_get_self().'?'.api_get_cidreq().'&action=download&id='.$url_path.$req_gid; + // Folder download or file download? + $forcedownload_icon = ($filetype == 'folder') ? 'folder_zip.gif' : 'filesave.gif'; + // Prevent multiple clicks on zipped folder download + $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'; + if ($filetype == 'file') { + // Check the extension + $ext = explode('.', $path); + $ext = strtolower($ext[sizeof($ext) - 1]); + + // "htmlfiles" are shown in a frameset + if ($ext == 'htm' || $ext == 'html' || $ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'pdf' || $ext == 'swf' || $ext == 'mp3' || $ext == 'mp4' ||(($ext== 'ogg' || $ext== 'ogx' || $ext== 'oga' || $ext== 'ogv') && api_browser_support('ogg')) ||($ext == 'svg' && api_browser_support('svg'))) { + $url = 'showinframes.php?'.api_get_cidreq().'&file='.$url_path.$req_gid; + } else { + // url-encode for problematic characters (we may not call them dangerous characters...) + $path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq(); + $url = $www.$path; + } + // Files that we want opened in a new window + if ($ext == 'txt' || $ext == 'log' || $ext == 'css' || $ext == 'js') { // Add here + $target = '_blank'; + } + } else { + $url = api_get_self().'?'.api_get_cidreq().'&curdirpath='.$url_path.$req_gid; + } + + // The little download icon + //$tooltip_title = str_replace('?cidReq='.$_GET['cidReq'], '', basename($path)); + $tooltip_title = explode('?', basename($path)); + $tooltip_title = $tooltip_title[0]; + + $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($current_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(); + if (!$show_as_icon) { + if ($filetype == 'folder') { + if (api_is_allowed_to_edit() || api_is_platform_admin() || api_get_setting('students_download_folders') == 'true') { + //filter when I am into shared folder, I can show for donwload only my shared folder + if(is_shared_folder($_GET['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) ? '' : ''.Display::return_icon($forcedownload_icon, get_lang('Download'), array('height'=>'16', 'width' => '16')).''; + } + } + elseif(!preg_match('/shared_folder/', urldecode($forcedownload_link)) || api_is_allowed_to_edit() || api_is_platform_admin()) + { + $force_download_html = ($size == 0) ? '' : ''.Display::return_icon($forcedownload_icon, get_lang('Download'), array('height'=>'16', 'width' => '16')).''; + } + } + } else { + $force_download_html = ($size==0)?'':''.Display::return_icon($forcedownload_icon, get_lang('Download'), array('height'=>'16', 'width' => '16')).''; + } + + //copy files to users myfiles + if(api_get_setting('users_copy_files') == 'true' && api_get_user_id() != 0){ + $copy_myfiles_link = ($filetype == 'file') ? api_get_self().'?'.api_get_cidreq().'&curdirpath='.$_GET['curdirpath'].'&action=copytomyfiles&id='.$url_path.$req_gid :api_get_self().'?'.api_get_cidreq(); + + if($filetype == 'file') + { + $copy_to_myfiles=''.Display::return_icon('briefcase_small.png', get_lang('CopyToMyFiles'), array('height'=>'16', 'width' => '16')).'  '; + } + } + return ''.$title.''.$force_download_html.$copy_to_myfiles; + //end copy files to users myfiles + } + 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){ + return ''.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22)).''; + } + else{ + return ''.build_document_icon_tag($filetype, $path).''; + } + } } /** @@ -224,100 +224,100 @@ function create_document_link($www, $title, $path, $filetype, $size, $visibility * @return string img html tag */ 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)); + $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)); } /** @@ -331,193 +331,193 @@ function build_document_icon_tag($type, $path) { * @return string html img tags with hyperlinks */ function build_edit_icons($curdirpath, $type, $path, $visibility, $id, $is_template, $is_read_only = 0, $session_id = 0) { - if (isset($_SESSION['_gid'])) { - $req_gid = '&gidReq='.$_SESSION['_gid']; - } else { - $req_gid = ''; - } - // Build URL-parameters for table-sorting - $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'; - $curdirpath = urlencode($curdirpath); - - $is_certificate_mode = DocumentManager::is_certificate_mode($path); - $modify_icons = ''; - $cur_ses = api_get_session_id(); - $extension = pathinfo($path, PATHINFO_EXTENSION); - // If document is read only *or* we're in a session and the document - // is from a non-session context, hide the edition capabilities - if ($is_read_only /*or ($session_id!=$cur_ses)*/) { - $modify_icons = Display::return_icon('edit_na.gif', get_lang('Modify')); - $modify_icons .= ' '.Display::return_icon('delete_na.gif', get_lang('Delete')); - $modify_icons .= ' '.Display::return_icon('deplacer_fichier_na.gif', get_lang('Move')); - if(api_is_allowed_to_edit() || api_is_platform_admin()){ - $modify_icons .= ' '.Display::return_icon($visibility_icon.'_na.gif', get_lang('VisibilityCannotBeChanged')); - } - } else { - if ($is_certificate_mode) { - $modify_icons = ''; - }else { - if($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true'){ - $modify_icons = ''; - }else{ - $modify_icons = ''; - } - } + if (isset($_SESSION['_gid'])) { + $req_gid = '&gidReq='.$_SESSION['_gid']; + } else { + $req_gid = ''; + } + // Build URL-parameters for table-sorting + $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'; + $curdirpath = urlencode($curdirpath); + + $is_certificate_mode = DocumentManager::is_certificate_mode($path); + $modify_icons = ''; + $cur_ses = api_get_session_id(); + $extension = pathinfo($path, PATHINFO_EXTENSION); + // If document is read only *or* we're in a session and the document + // is from a non-session context, hide the edition capabilities + if ($is_read_only /*or ($session_id!=$cur_ses)*/) { + $modify_icons = Display::return_icon('edit_na.gif', get_lang('Modify')); + $modify_icons .= ' '.Display::return_icon('delete_na.gif', get_lang('Delete')); + $modify_icons .= ' '.Display::return_icon('deplacer_fichier_na.gif', get_lang('Move')); + if(api_is_allowed_to_edit() || api_is_platform_admin()){ + $modify_icons .= ' '.Display::return_icon($visibility_icon.'_na.gif', get_lang('VisibilityCannotBeChanged')); + } + } else { + if ($is_certificate_mode) { + $modify_icons = ''; + }else { + if($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true'){ + $modify_icons = ''; + }else{ + $modify_icons = ''; + } + } if (in_array($path, array('/audio', '/flash', '/images', '/shared_folder', '/video', '/chat_files', '/certificates'))) { - $modify_icons .= ' '.Display::return_icon('delete_na.gif',get_lang('ThisFolderCannotBeDeleted')); + $modify_icons .= ' '.Display::return_icon('delete_na.gif',get_lang('ThisFolderCannotBeDeleted')); } else { - if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates' && DocumentManager::get_default_certificate_id(api_get_course_id())==$id) { + if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates' && DocumentManager::get_default_certificate_id(api_get_course_id())==$id) { - $modify_icons .= ' '; - } else { - if ($is_certificate_mode) { - $modify_icons .= ' '; - } else { - $modify_icons .= ' '; - } - } + $modify_icons .= ' '; + } else { + if ($is_certificate_mode) { + $modify_icons .= ' '; + } else { + $modify_icons .= ' '; + } + } } if ($is_certificate_mode) { - $modify_icons .= ' '; - $modify_icons .= ' '; + $modify_icons .= ' '; + $modify_icons .= ' '; + } else { + $modify_icons .= ' '; + if(api_is_allowed_to_edit() || api_is_platform_admin()){ + $modify_icons .= ' '; + } + } + } + + //$extension = pathinfo($path, PATHINFO_EXTENSION);//already load above + if ($type == 'file' && ($extension == 'html' || $extension == 'htm')) { + if ($is_template == 0) { + if ((isset($_GET['curdirpath']) && $_GET['curdirpath'] != '/certificates') || !isset($_GET['curdirpath'])) { + $modify_icons .= ' '.get_lang('AddAsTemplate').''; + } + if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates') {//allow attach certificate to course + $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 .= ' '; + if ($is_preview) { + $modify_icons .= ' '; + } + } + } } else { - $modify_icons .= ' '; - if(api_is_allowed_to_edit() || api_is_platform_admin()){ - $modify_icons .= ' '; - } + $modify_icons .= ' '; } - } - - //$extension = pathinfo($path, PATHINFO_EXTENSION);//already load above - if ($type == 'file' && ($extension == 'html' || $extension == 'htm')) { - if ($is_template == 0) { - if ((isset($_GET['curdirpath']) && $_GET['curdirpath'] != '/certificates') || !isset($_GET['curdirpath'])) { - $modify_icons .= ' '.get_lang('AddAsTemplate').''; - } - if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates') {//allow attach certificate to course - $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 .= ' '; - if ($is_preview) { - $modify_icons .= ' '; - } - } - } - } else { - $modify_icons .= ' '; - } - $modify_icons .= ' '; - } - - return $modify_icons; + $modify_icons .= ' '; + } + + return $modify_icons; } function build_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') { - $form = '
    '."\n"; - $form .= ''."\n"; - - $form .= '
    '; - $form .= '
    '; - $form .= get_lang('MoveTo'); - $form .= '
    '; - $form .= '
    '; - - $form .= ' '."\n"; - $form .= '
    '; - - $form .= '
    '; - $form .= '
    '; - $form .= '
    '; - $form .= ' '."\n"; - $form .= '
    '; - $form .= '
    '; - - $form .= ''; - - $form .= '
    '; - - return $form; + $form = '
    '."\n"; + $form .= ''."\n"; + + $form .= '
    '; + $form .= '
    '; + $form .= get_lang('MoveTo'); + $form .= '
    '; + $form .= '
    '; + + $form .= ' '."\n"; + $form .= '
    '; + + $form .= '
    '; + $form .= '
    '; + $form .= '
    '; + $form .= ' '."\n"; + $form .= '
    '; + $form .= '
    '; + + $form .= ''; + + $form .= '
    '; + + return $form; } /** @@ -527,34 +527,34 @@ function build_move_to_selector($folders, $curdirpath, $move_file, $group_dir = */ function get_titles_of_path($path) { - global $tmp_folders_titles; - - $nb_slashes = substr_count($path, '/'); - $tmp_path = ''; - $current_slash_pos = 0; - $path_displayed = ''; - for ($i = 0; $i < $nb_slashes; $i++) { - // For each folder of the path, retrieve title. - $current_slash_pos = strpos($path, '/', $current_slash_pos + 1); - $tmp_path = substr($path, strpos($path, '/', 0), $current_slash_pos); - - if (empty($tmp_path)) { - // If empty, then we are in the final part of the path - $tmp_path = $path; - } - - if (!empty($tmp_folders_titles[$tmp_path])) { - // If this path has soon been stored here we don't need a new query - $path_displayed .= $tmp_folders_titles[$tmp_path]; - } else { - $sql = 'SELECT title FROM '.Database::get_course_table(TABLE_DOCUMENT).' WHERE 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; + global $tmp_folders_titles; + + $nb_slashes = substr_count($path, '/'); + $tmp_path = ''; + $current_slash_pos = 0; + $path_displayed = ''; + for ($i = 0; $i < $nb_slashes; $i++) { + // For each folder of the path, retrieve title. + $current_slash_pos = strpos($path, '/', $current_slash_pos + 1); + $tmp_path = substr($path, strpos($path, '/', 0), $current_slash_pos); + + if (empty($tmp_path)) { + // If empty, then we are in the final part of the path + $tmp_path = $path; + } + + if (!empty($tmp_folders_titles[$tmp_path])) { + // If this path has soon been stored here we don't need a new query + $path_displayed .= $tmp_folders_titles[$tmp_path]; + } else { + $sql = 'SELECT title FROM '.Database::get_course_table(TABLE_DOCUMENT).' WHERE 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; } /** @@ -567,11 +567,11 @@ function get_titles_of_path($path) { * @version february 2006, dokeos 1.8 */ function display_user_link_document($user_id, $name) { - if ($user_id != 0) { - return ''.$name.''; - } else { - return get_lang('Anonymous'); - } + if ($user_id != 0) { + return ''.$name.''; + } else { + return get_lang('Anonymous'); + } } /** * Creates form that asks for the directory name. @@ -579,27 +579,27 @@ function display_user_link_document($user_id, $name) { */ function create_dir_form() { - $new_folder_text = '
    '; - $new_folder_text .= ''; + $new_folder_text = ''; + $new_folder_text .= ''; - // Form title - $new_folder_text .= '
    '.get_lang('CreateDir').'
    '; + // Form title + $new_folder_text .= '
    '.get_lang('CreateDir').'
    '; - // Folder field - $new_folder_text .= '
    '; - $new_folder_text .= '
    *'.get_lang('NewDir').'
    '; - $new_folder_text .= '
    '; - $new_folder_text .= '
    '; + // Folder field + $new_folder_text .= '
    '; + $new_folder_text .= '
    *'.get_lang('NewDir').'
    '; + $new_folder_text .= '
    '; + $new_folder_text .= '
    '; - // Submit button - $new_folder_text .= '
    '; - $new_folder_text .= '
     
    '; - $new_folder_text .= '
    '; - $new_folder_text .= '
    '; - $new_folder_text .= '
    '; - $new_folder_text .= '
    '; + // Submit button + $new_folder_text .= '
    '; + $new_folder_text .= '
     
    '; + $new_folder_text .= '
    '; + $new_folder_text .= '
    '; + $new_folder_text .= ''; + $new_folder_text .= '
    '; - return $new_folder_text; + return $new_folder_text; } @@ -608,16 +608,16 @@ function create_dir_form() { * @return return bool Return true when user is into shared folder */ 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; - } + $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; + } } /** @@ -625,16 +625,16 @@ function is_shared_folder($curdirpath, $current_session_id) { * @return return bool Return true when user is in any user shared folder */ 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; - } + $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; + } } /** @@ -642,19 +642,19 @@ function is_any_user_shared_folder($path, $current_session_id) { * @return return bool Return true when user is in his user shared folder or into a subforder */ 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.'\//';//for security does not remove the last slash - $main_user_shared_folder_session='/shared_folder_session_'.$current_session_id.'\/sf_user_'.$user_id.'\//';//for security does not remove the last slash - - 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; - } + $clean_path = Security::remove_XSS($path).'/'; + $main_user_shared_folder = '/shared_folder\/sf_user_'.$user_id.'\//';//for security does not remove the last slash + $main_user_shared_folder_session='/shared_folder_session_'.$current_session_id.'\/sf_user_'.$user_id.'\//';//for security does not remove the last slash + + 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; + } } /** @@ -662,11 +662,11 @@ function is_my_shared_folder($user_id, $path, $current_session_id) { * @return return bool Return true when exist */ function search_keyword($document_name, $keyword) { - if (api_strripos($document_name, $keyword) !== false){ - return true; - } else { - return false; - } + if (api_strripos($document_name, $keyword) !== false){ + return true; + } else { + return false; + } } ?> \ No newline at end of file diff --git a/main/document/document.php b/main/document/document.php index 5d1d1d5b57..fd85ed2c59 100755 --- a/main/document/document.php +++ b/main/document/document.php @@ -52,16 +52,16 @@ api_protect_course_script(true); $htmlHeadXtra[] = ''; // Session if (isset($_GET['id_session'])) { - $_SESSION['id_session'] = intval($_GET['id_session']); + $_SESSION['id_session'] = intval($_GET['id_session']); } // Create directory certificates $course_id = api_get_course_id(); @@ -69,30 +69,30 @@ DocumentManager::create_directory_certificate_in_course($course_id); // Show preview if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_preview']) && $_GET['set_preview'] == strval(intval($_GET['set_preview']))) { - if (isset($_GET['set_preview'])) { - // Generate document HTML - $course_id = api_get_course_id(); - $content_html = DocumentManager::replace_user_info_into_html($course_id); - - $new_content_html = $content_html; - - $path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/images/gallery'; - $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html); - - $path_image_in_default_course = api_get_path(WEB_CODE_PATH).'default_course_document'; - $new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html); - - $new_content_html = str_replace('/main/img/', api_get_path(WEB_IMG_PATH), $new_content_html); - echo ' - '; - echo '' . get_lang('Print') . ' ' . get_lang('Print') . ''; - print_r($new_content_html); - exit; - } + if (isset($_GET['set_preview'])) { + // Generate document HTML + $course_id = api_get_course_id(); + $content_html = DocumentManager::replace_user_info_into_html($course_id); + + $new_content_html = $content_html; + + $path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/images/gallery'; + $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html); + + $path_image_in_default_course = api_get_path(WEB_CODE_PATH).'default_course_document'; + $new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html); + + $new_content_html = str_replace('/main/img/', api_get_path(WEB_IMG_PATH), $new_content_html); + echo ' + '; + echo '' . get_lang('Print') . ' ' . get_lang('Print') . ''; + print_r($new_content_html); + exit; + } } // Is the document tool visible? @@ -103,33 +103,33 @@ $tool_result = Database::query($tool_sql); $tool_row = Database::fetch_array($tool_result); $tool_visibility = $tool_row['visibility']; if ($tool_visibility == '0' && $to_group_id == '0' && !($is_allowed_to_edit || $group_member_with_upload_rights)) { - api_not_allowed(true); + api_not_allowed(true); } $htmlHeadXtra[] = ""; /* - Variables - - some need defining before inclusion of libraries + Variables + - some need defining before inclusion of libraries */ // What's the current path? // We will verify this a bit further down if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') { - $curdirpath = Security::remove_XSS($_GET['curdirpath']); + $curdirpath = Security::remove_XSS($_GET['curdirpath']); } elseif (isset($_POST['curdirpath']) && $_POST['curdirpath'] != '') { - $curdirpath = Security::remove_XSS($_POST['curdirpath']); + $curdirpath = Security::remove_XSS($_POST['curdirpath']); } else { - $curdirpath = '/'; + $curdirpath = '/'; } $curdirpathurl = urlencode($curdirpath); @@ -147,49 +147,49 @@ $group_member_with_upload_rights = false; // If the group id is set, we show them group documents if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') { - // Needed for group related stuff - require_once $lib_path.'groupmanager.lib.php'; - // Get group info - $group_properties = GroupManager::get_group_properties($_SESSION['_gid']); - $noPHP_SELF = true; - // Let's assume the user cannot upload files for the group - $group_member_with_upload_rights = false; - - if ($group_properties['doc_state'] == 2) { // Documents are private - if ($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid'])) { // Only courseadmin or group members (members + tutors) allowed - $to_group_id = $_SESSION['_gid']; - $req_gid = '&gidReq='.$_SESSION['_gid']; - $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups')); - $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['_gid'], 'name' => get_lang('GroupSpace').' '.$group_properties['name']); - //they are allowed to upload - $group_member_with_upload_rights = true; - } else { - $to_group_id = 0; - $req_gid = ''; - } - } elseif ($group_properties['doc_state'] == 1) { // Documents are public - $to_group_id = $_SESSION['_gid']; - $req_gid = '&gidReq='.$_SESSION['_gid']; - $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups')); - $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['_gid'], 'name' => get_lang('GroupSpace').' '.$group_properties['name']); - //allowed to upload? - if ($is_allowed_to_edit || GroupManager::is_subscribed($_user['user_id'], $_SESSION['_gid'])) { // Only courseadmin or group members can upload - $group_member_with_upload_rights = true; - } - } else { // Documents not active for this group - $to_group_id = 0; - $req_gid = ''; - } - $_SESSION['group_member_with_upload_rights'] = $group_member_with_upload_rights; + // Needed for group related stuff + require_once $lib_path.'groupmanager.lib.php'; + // Get group info + $group_properties = GroupManager::get_group_properties($_SESSION['_gid']); + $noPHP_SELF = true; + // Let's assume the user cannot upload files for the group + $group_member_with_upload_rights = false; + + if ($group_properties['doc_state'] == 2) { // Documents are private + if ($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid'])) { // Only courseadmin or group members (members + tutors) allowed + $to_group_id = $_SESSION['_gid']; + $req_gid = '&gidReq='.$_SESSION['_gid']; + $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups')); + $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['_gid'], 'name' => get_lang('GroupSpace').' '.$group_properties['name']); + //they are allowed to upload + $group_member_with_upload_rights = true; + } else { + $to_group_id = 0; + $req_gid = ''; + } + } elseif ($group_properties['doc_state'] == 1) { // Documents are public + $to_group_id = $_SESSION['_gid']; + $req_gid = '&gidReq='.$_SESSION['_gid']; + $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups')); + $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['_gid'], 'name' => get_lang('GroupSpace').' '.$group_properties['name']); + //allowed to upload? + if ($is_allowed_to_edit || GroupManager::is_subscribed($_user['user_id'], $_SESSION['_gid'])) { // Only courseadmin or group members can upload + $group_member_with_upload_rights = true; + } + } else { // Documents not active for this group + $to_group_id = 0; + $req_gid = ''; + } + $_SESSION['group_member_with_upload_rights'] = $group_member_with_upload_rights; } else { - $_SESSION['group_member_with_upload_rights'] = false; - $to_group_id = 0; - $req_gid = ''; + $_SESSION['group_member_with_upload_rights'] = false; + $to_group_id = 0; + $req_gid = ''; } // For sessions we should check the parameters of visibility if (api_get_session_id() != 0) { - $group_member_with_upload_rights = $group_member_with_upload_rights && api_is_allowed_to_session_edit(false, true); + $group_member_with_upload_rights = $group_member_with_upload_rights && api_is_allowed_to_session_edit(false, true); } /* Libraries */ @@ -202,20 +202,20 @@ require_once $lib_path.'fileUpload.lib.php'; // Check the path // If the path is not found (no document id), set the path to / if (!DocumentManager::get_document_id($_course, $curdirpath)) { - $curdirpath = '/'; - // Urlencoded version - $curdirpathurl = '%2F'; + $curdirpath = '/'; + // Urlencoded version + $curdirpathurl = '%2F'; } // If they are looking at group documents they can't see the root if ($to_group_id != 0 && $curdirpath == '/') { - $curdirpath = $group_properties['directory']; - $curdirpathurl = urlencode($group_properties['directory']); + $curdirpath = $group_properties['directory']; + $curdirpathurl = urlencode($group_properties['directory']); } // Check visibility of the current dir path. Don't show anything if not allowed -if (!$is_allowed_to_edit || api_is_coach()) { +if (!$is_allowed_to_edit || api_is_coach()) { if (!(DocumentManager::is_visible($curdirpath, $_course, api_get_session_id()))) { api_not_allowed(); } @@ -230,66 +230,66 @@ $current_session_id = api_get_session_id(); /* Create shared folders */ if($current_session_id==0){ - //Create shared folder. Necessary for courses recycled. Allways session_id should be zero. Allway should be created from a base course, never from a session. - if (!file_exists($base_work_dir.'/shared_folder')) { - $usf_dir_title = get_lang('UserFolders'); - $usf_dir_name = '/shared_folder'; - $to_group_id = 0; - $visibility = 0; - create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility); - } - // Create dynamic user shared folder - if (!file_exists($base_work_dir.'/shared_folder/sf_user_'.api_get_user_id())) { - $usf_dir_title = api_get_person_name($_user['firstName'], $_user['lastName']); - $usf_dir_name = '/shared_folder/sf_user_'.api_get_user_id(); - $to_group_id = 0; - $visibility = 1; - create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility); - } + //Create shared folder. Necessary for courses recycled. Allways session_id should be zero. Allway should be created from a base course, never from a session. + if (!file_exists($base_work_dir.'/shared_folder')) { + $usf_dir_title = get_lang('UserFolders'); + $usf_dir_name = '/shared_folder'; + $to_group_id = 0; + $visibility = 0; + create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility); + } + // Create dynamic user shared folder + if (!file_exists($base_work_dir.'/shared_folder/sf_user_'.api_get_user_id())) { + $usf_dir_title = api_get_person_name($_user['firstName'], $_user['lastName']); + $usf_dir_name = '/shared_folder/sf_user_'.api_get_user_id(); + $to_group_id = 0; + $visibility = 1; + create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility); + } } -else{ - //Create shared folder session - if (!file_exists($base_work_dir.'/shared_folder_session_'.$current_session_id)) { - $usf_dir_title = get_lang('UserFolders').' ('.api_get_session_name($current_session_id).')'; - $usf_dir_name = '/shared_folder_session_'.$current_session_id; - $to_group_id = 0; - $visibility = 0; - create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility); - } - //Create dynamic user shared folder into a shared folder session - if (!file_exists($base_work_dir.'/shared_folder_session_'.$current_session_id.'/sf_user_'.api_get_user_id())) { - $usf_dir_title = api_get_person_name($_user['firstName'], $_user['lastName']).' ('.api_get_session_name($current_session_id).')'; - $usf_dir_name = '/shared_folder_session_'.$current_session_id.'/sf_user_'.api_get_user_id(); - $to_group_id = 0; - $visibility = 1; - create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility); - } +else{ + //Create shared folder session + if (!file_exists($base_work_dir.'/shared_folder_session_'.$current_session_id)) { + $usf_dir_title = get_lang('UserFolders').' ('.api_get_session_name($current_session_id).')'; + $usf_dir_name = '/shared_folder_session_'.$current_session_id; + $to_group_id = 0; + $visibility = 0; + create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility); + } + //Create dynamic user shared folder into a shared folder session + if (!file_exists($base_work_dir.'/shared_folder_session_'.$current_session_id.'/sf_user_'.api_get_user_id())) { + $usf_dir_title = api_get_person_name($_user['firstName'], $_user['lastName']).' ('.api_get_session_name($current_session_id).')'; + $usf_dir_name = '/shared_folder_session_'.$current_session_id.'/sf_user_'.api_get_user_id(); + $to_group_id = 0; + $visibility = 1; + create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility); + } } /* MAIN SECTION */ if (isset($_GET['action']) && $_GET['action'] == 'download') { - $my_get_id = Security::remove_XSS($_GET['id']); - - // Check whether the document is in the database - if (!DocumentManager::get_document_id($_course, $my_get_id)) { - // File not found! - header('HTTP/1.0 404 Not Found'); - $error404 = ''; - $error404 .= ''; - $error404 .= '404 Not Found'; - $error404 .= ''; - $error404 .= '

    Not Found

    '; - $error404 .= '

    The requested URL was not found on this server.

    '; - $error404 .= '
    '; - $error404 .= ''; - echo $error404; - exit; - } - - // Launch event - event_download($my_get_id); + $my_get_id = Security::remove_XSS($_GET['id']); + + // Check whether the document is in the database + if (!DocumentManager::get_document_id($_course, $my_get_id)) { + // File not found! + header('HTTP/1.0 404 Not Found'); + $error404 = ''; + $error404 .= ''; + $error404 .= '404 Not Found'; + $error404 .= ''; + $error404 .= '

    Not Found

    '; + $error404 .= '

    The requested URL was not found on this server.

    '; + $error404 .= '
    '; + $error404 .= ''; + echo $error404; + exit; + } + + // Launch event + event_download($my_get_id); // Check visibility of document and paths if (!($is_allowed_to_edit || $group_member_with_upload_rights) && !DocumentManager::is_visible($my_get_id, $_course)) { @@ -297,32 +297,32 @@ if (isset($_GET['action']) && $_GET['action'] == 'download') { } $doc_url = $my_get_id; - $full_file_name = $base_work_dir.$doc_url; - DocumentManager::file_send_for_download($full_file_name, true); - exit; + $full_file_name = $base_work_dir.$doc_url; + DocumentManager::file_send_for_download($full_file_name, true); + exit; } // Download a folder if (isset($_GET['action']) && $_GET['action'] == 'downloadfolder' && (api_get_setting('students_download_folders') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin())) { - - //filter when I am into shared folder, I can donwload only my shared folder - - if(is_any_user_shared_folder($_GET['path'],$current_session_id)){ - if(is_my_shared_folder($_user['user_id'], $_GET['path'], $current_session_id) || api_is_allowed_to_edit() || api_is_platform_admin()){ - require 'downloadfolder.inc.php'; - } - } - else{ - require 'downloadfolder.inc.php'; - } - + + //filter when I am into shared folder, I can donwload only my shared folder + + if(is_any_user_shared_folder($_GET['path'],$current_session_id)){ + if(is_my_shared_folder($_user['user_id'], $_GET['path'], $current_session_id) || api_is_allowed_to_edit() || api_is_platform_admin()){ + require 'downloadfolder.inc.php'; + } + } + else{ + require 'downloadfolder.inc.php'; + } + } // Export to PDF if (isset($_GET['action']) && $_GET['action'] == 'export_to_pdf' && (api_get_setting('students_export2pdf') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin())) { - DocumentManager::export_to_pdf($_GET['id'],$course_code); -} + DocumentManager::export_to_pdf($_GET['id'],$course_code); +} // Slideshow inititalisation $_SESSION['image_files_only'] = ''; @@ -331,9 +331,9 @@ $image_files_only = ''; /* Header */ if ($is_certificate_mode) { - $interbreadcrumb[]= array('url' => '../gradebook/index.php', 'name' => get_lang('Gradebook')); + $interbreadcrumb[]= array('url' => '../gradebook/index.php', 'name' => get_lang('Gradebook')); } else { - $interbreadcrumb[]= array('url' => '', 'name' => get_lang('Documents')); + $interbreadcrumb[]= array('url' => '', 'name' => get_lang('Documents')); } // Interbreadcrumb for the current directory root path @@ -344,12 +344,12 @@ $array_len = count($dir_array); /* TODO:check and delete this code if (!$is_certificate_mode) { - if ($array_len > 1) { - if (empty($_SESSION['_gid'])) { - $url_dir = 'document.php?&curdirpath=/'; - $interbreadcrumb[] = array('url' => $url_dir, 'name' => get_lang('HomeDirectory')); - } - } + if ($array_len > 1) { + if (empty($_SESSION['_gid'])) { + $url_dir = 'document.php?&curdirpath=/'; + $interbreadcrumb[] = array('url' => $url_dir, 'name' => get_lang('HomeDirectory')); + } + } } */ @@ -357,31 +357,31 @@ $dir_acum = ''; for ($i = 0; $i < $array_len; $i++) { - $url_dir = 'document.php?&curdirpath='.$dir_acum.$dir_array[$i]; - - //Max char 80 - $url_to_who = cut($dir_array[$i],80); - - if ($is_certificate_mode) { - $interbreadcrumb[] = array('url' => $url_dir.'&selectcat='.Security::remove_XSS($_GET['selectcat']), 'name' => $url_to_who); - - } - else{ - $interbreadcrumb[] = array('url' => $url_dir, 'name' => $url_to_who); - } - - //does not repeat the name group in the url - if (!empty($_SESSION['_gid'])) { - unset($dir_array[1]); - } - - $dir_acum .= $dir_array[$i].'/'; + $url_dir = 'document.php?&curdirpath='.$dir_acum.$dir_array[$i]; + + //Max char 80 + $url_to_who = cut($dir_array[$i],80); + + if ($is_certificate_mode) { + $interbreadcrumb[] = array('url' => $url_dir.'&selectcat='.Security::remove_XSS($_GET['selectcat']), 'name' => $url_to_who); + + } + else{ + $interbreadcrumb[] = array('url' => $url_dir, 'name' => $url_to_who); + } + + //does not repeat the name group in the url + if (!empty($_SESSION['_gid'])) { + unset($dir_array[1]); + } + + $dir_acum .= $dir_array[$i].'/'; } -if (isset($_GET['createdir'])) { - $interbreadcrumb[] = array('url' => '', 'name' => get_lang('CreateDir')); +if (isset($_GET['createdir'])) { + $interbreadcrumb[] = array('url' => '', 'name' => get_lang('CreateDir')); } @@ -393,363 +393,363 @@ event_access_tool(TOOL_DOCUMENT); /* DISPLAY */ if ($to_group_id != 0) { // Add group name after for group documents - $add_group_to_title = ' ('.$group_properties['name'].')'; + $add_group_to_title = ' ('.$group_properties['name'].')'; } /* Introduction section (editable by course admins) */ if (!empty($_SESSION['_gid'])) { - Display::display_introduction_section(TOOL_DOCUMENT.$_SESSION['_gid']); + Display::display_introduction_section(TOOL_DOCUMENT.$_SESSION['_gid']); } else { - Display::display_introduction_section(TOOL_DOCUMENT); + Display::display_introduction_section(TOOL_DOCUMENT); } // Copy a file to general my files user's -if (isset($_GET['action']) && $_GET['action'] == 'copytomyfiles' && api_get_setting('users_copy_files') == 'true' && api_get_user_id() != 0) { - - $clean_get_id = Security::remove_XSS($_GET['id']); - $user_folder = api_get_path(SYS_CODE_PATH).'upload/users/'.api_get_user_id().'/my_files/'; - if (!file_exists($user_folder)) { - @mkdir($user_folder, $permissions_for_new_directories, true); - } - - $file = $sys_course_path.$_course['path'].'/document'.$clean_get_id; - $copyfile = $user_folder.basename($clean_get_id); - - if (file_exists($copyfile)) { - $message = get_lang('CopyAlreadyDone').'

    '.''.get_lang("No").'  |  '.get_lang("Yes").'

    '; - if (!isset($_GET['copy'])){ - Display::display_warning_message($message,false); - } - if (Security::remove_XSS($_GET['copy']) == 'yes'){ - if (!copy($file, $copyfile)) { - Display::display_error_message(get_lang('CopyFailed')); - }else{ - Display::display_confirmation_message(get_lang('OverwritenFile')); - } - } - }else{ - - if (!copy($file, $copyfile)) { - Display::display_error_message(get_lang('CopyFailed')); - }else{ - Display::display_confirmation_message(get_lang('CopyMade')); - } - } +if (isset($_GET['action']) && $_GET['action'] == 'copytomyfiles' && api_get_setting('users_copy_files') == 'true' && api_get_user_id() != 0) { + + $clean_get_id = Security::remove_XSS($_GET['id']); + $user_folder = api_get_path(SYS_CODE_PATH).'upload/users/'.api_get_user_id().'/my_files/'; + if (!file_exists($user_folder)) { + @mkdir($user_folder, $permissions_for_new_directories, true); + } + + $file = $sys_course_path.$_course['path'].'/document'.$clean_get_id; + $copyfile = $user_folder.basename($clean_get_id); + + if (file_exists($copyfile)) { + $message = get_lang('CopyAlreadyDone').'

    '.''.get_lang("No").'  |  '.get_lang("Yes").'

    '; + if (!isset($_GET['copy'])){ + Display::display_warning_message($message,false); + } + if (Security::remove_XSS($_GET['copy']) == 'yes'){ + if (!copy($file, $copyfile)) { + Display::display_error_message(get_lang('CopyFailed')); + }else{ + Display::display_confirmation_message(get_lang('OverwritenFile')); + } + } + }else{ + + if (!copy($file, $copyfile)) { + Display::display_error_message(get_lang('CopyFailed')); + }else{ + Display::display_confirmation_message(get_lang('CopyMade')); + } + } } //START ACTION MENU - /* MOVE FILE OR DIRECTORY */ - //Only teacher and all users into their group and each user into his/her shared folder - if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id) || is_my_shared_folder($_user['user_id'], Security::remove_XSS($_POST['move_to']), $current_session_id)){ - $my_get_move = Security::remove_XSS($_GET['move']); - if (isset($_GET['move']) && $_GET['move'] != '') { - - if (api_is_coach()) { - if (!DocumentManager::is_visible_by_id($my_get_move, $_course,api_get_session_id())) { - api_not_allowed(); - } - } - - if (!$is_allowed_to_edit) { - if (DocumentManager::check_readonly($_course, $_user['user_id'], $my_get_move)) { - api_not_allowed(); - } - } - - if (DocumentManager::get_document_id($_course, $my_get_move)) { - $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit || $group_member_with_upload_rights); - - //filter if is my shared folder. TODO: move this code to build_move_to_selector function - if(is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id) && !$is_allowed_to_edit){ - $main_user_shared_folder_main = '/shared_folder/sf_user_'.api_get_user_id();//only main user shared folder - $main_user_shared_folder_sub = '/shared_folder\/sf_user_'.api_get_user_id().'\//';//all subfolders - $user_shared_folders=array(); - - foreach($folders as $fold){ - if($main_user_shared_folder_main==$fold || preg_match($main_user_shared_folder_sub, $fold)){ - $user_shared_folders[]=$fold; - } - } - echo '
    '.get_lang('Move').'
    '; - echo build_move_to_selector($user_shared_folders, Security::remove_XSS($_GET['curdirpath']), $my_get_move, $group_properties['directory']); - } - else{ - echo '
    '.get_lang('Move').'
    '; - echo build_move_to_selector($folders, Security::remove_XSS($_GET['curdirpath']), $my_get_move, $group_properties['directory']); - } - } - } - - if (isset($_POST['move_to']) && isset($_POST['move_file'])) { - if (!$is_allowed_to_edit) { - if (DocumentManager::check_readonly($_course, $_user['user_id'], $my_get_move)) { - api_not_allowed(); - } - } - - if (api_is_coach()) { - if (!DocumentManager::is_visible_by_id($my_get_move, $_course,api_get_session_id())) { - api_not_allowed(); - } - } - - - require_once $lib_path.'fileManage.lib.php'; - // This is needed for the update_db_info function - //$dbTable = $_course['dbNameGlu'].'document'; - $dbTable = Database::get_course_table(TABLE_DOCUMENT); - // Security fix: make sure they can't move files that are not in the document table - if (DocumentManager::get_document_id($_course, $_POST['move_file'])) { - if (move($base_work_dir.$_POST['move_file'], $base_work_dir.$_POST['move_to'])) { - update_db_info('update', $_POST['move_file'], $_POST['move_to'].'/'.basename($_POST['move_file'])); - // Set the current path - $curdirpath = $_POST['move_to']; - $curdirpathurl = urlencode($_POST['move_to']); - Display::display_confirmation_message(get_lang('DirMv')); - } else { - Display::display_error_message(get_lang('Impossible')); - } - } else { - Display::display_error_message(get_lang('Impossible')); - } - } - } - - /* DELETE FILE OR DIRECTORY */ - //Only teacher and all users into their group - if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)){ - if (isset($_GET['delete'])) { - - if (api_is_coach()) { - if (!DocumentManager::is_visible($_GET['delete'], $_course)) { - api_not_allowed(); - } - } - - if (!$is_allowed_to_edit) { - if (DocumentManager::check_readonly($_course, $_user['user_id'], $_GET['delete'], '', true)) { - api_not_allowed(); - } - } - - require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; - - if (DocumentManager::delete_document($_course, $_GET['delete'], $base_work_dir)) { - if ( isset($_GET['delete_certificate_id']) && $_GET['delete_certificate_id'] == strval(intval($_GET['delete_certificate_id']))) { - $course_id = api_get_course_id(); - $default_certificate_id = $_GET['delete_certificate_id']; - DocumentManager::remove_attach_certificate($course_id, $default_certificate_id); - } - Display::display_confirmation_message(get_lang('DocDeleted')); - } else { - Display::display_error_message(get_lang('DocDeleteError')); - } - } - - if (isset($_POST['action'])) { - switch ($_POST['action']) { - case 'delete': - - foreach ($_POST['path'] as $index => & $path) { - if (!$is_allowed_to_edit) { - if (DocumentManager::check_readonly($_course, $_user['user_id'], $path)) { - Display::display_error_message(get_lang('CantDeleteReadonlyFiles')); - break 2; - } - } - } - - foreach ($_POST['path'] as $index => & $path) { - if (in_array($path, array('/audio', '/flash', '/images', '/shared_folder', '/video', '/chat_files', '/certificates'))) { - continue; - } else { - $delete_document = DocumentManager::delete_document($_course, $path, $base_work_dir); - } - } - if (!empty($delete_document)) { - Display::display_confirmation_message(get_lang('DocDeleted')); - } - break; - } - } - } - - /* CREATE DIRECTORY */ - //Only teacher and all users into their group and any user into his/her shared folder - if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)){ - // Create directory with $_POST data - if (isset($_POST['create_dir']) && $_POST['dirname'] != '') { - // Needed for directory creation - require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; - $post_dir_name = Security::remove_XSS($_POST['dirname']); - - if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') { - Display::display_error_message(get_lang('CannotCreateDir')); - } else { - $added_slash = ($curdirpath == '/') ? '' : '/'; - $dir_name = $curdirpath.$added_slash.replace_dangerous_char($post_dir_name); - $dir_name = disable_dangerous_file($dir_name); - $dir_check = $base_work_dir.$dir_name; - if (!is_dir($dir_check)) { - $created_dir = create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name); - if ($created_dir) { - Display::display_confirmation_message(''.get_lang('DirCr').'', false); - // Uncomment if you want to enter the created dir - //$curdirpath = $created_dir; - //$curdirpathurl = urlencode($curdirpath); - } else { - Display::display_error_message(get_lang('CannotCreateDir')); - } - } else { - Display::display_error_message(get_lang('CannotCreateDir')); - } - } - } - - // Show them the form for the directory name - if (isset($_GET['createdir'])) { - echo create_dir_form(); - } - } - - /* VISIBILITY COMMANDS */ - //Only teacher - if($is_allowed_to_edit){ - if ((isset($_GET['set_invisible']) && !empty($_GET['set_invisible'])) || (isset($_GET['set_visible']) && !empty($_GET['set_visible'])) && $_GET['set_visible'] != '*' && $_GET['set_invisible'] != '*') { - // Make visible or invisible? - if (isset($_GET['set_visible'])) { - $update_id = $_GET['set_visible']; - $visibility_command = 'visible'; - } else { - $update_id = $_GET['set_invisible']; - $visibility_command = 'invisible'; - } - - if (api_is_coach()) { - if (!DocumentManager::is_visible_by_id($update_id, $_course)) { - api_not_allowed(); - } - } - - if (!$is_allowed_to_edit) { - if(DocumentManager::check_readonly($_course, $_user['user_id'], '', $update_id)) { - api_not_allowed(); - } - } - - // Update item_property to change visibility - if (api_item_property_update($_course, TOOL_DOCUMENT, $update_id, $visibility_command, $_user['user_id'], null, null, null, null, $current_session_id)) { - Display::display_confirmation_message(get_lang('VisibilityChanged'));//don't use ViMod because firt is load ViMdod (Gradebook). VisibilityChanged (trad4all) - } else { - Display::display_error_message(get_lang('ViModProb')); - } - } - } - - /* TEMPLATE ACTION */ - //Only teacher and all users into their group - if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)){ - if (isset($_GET['add_as_template']) && !isset($_POST['create_template'])) { - - $document_id_for_template = intval($_GET['add_as_template']); - - // Create the form that asks for the directory name - $template_text = '
    '; - $template_text .= ''; - $template_text .= ''; - $template_text .= ''; - //$template_text .= ''; - //$template_text .= ''; - $template_text .= ''; - $template_text .= ''; - $template_text .= '
    '; - $template_text .= get_lang('TemplateName').' :
    '.get_lang('TemplateDescription').' :
    '.get_lang('TemplateImage').' :
    '; - $template_text .= ''; - $template_text .= '
    '; - // Show the form - Display::display_normal_message($template_text, false); - - } elseif (isset($_GET['add_as_template']) && isset($_POST['create_template'])) { - - $document_id_for_template = intval(Database::escape_string($_GET['add_as_template'])); - - $title = Security::remove_XSS($_POST['template_title']); - //$description = Security::remove_XSS($_POST['template_description']); - $course_code = api_get_course_id(); - $user_id = api_get_user_id(); - - // Create the template_thumbnails folder in the upload folder (if needed) - if (!is_dir(api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/')) { - @mkdir(api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/', api_get_permissions_for_new_directories()); - } - // Upload the file - if (!empty($_FILES['template_image']['name'])) { - - require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; - $upload_ok = process_uploaded_file($_FILES['template_image']); - - if ($upload_ok) { - // Try to add an extension to the file if it hasn't one - $new_file_name = $_course['sysCode'].'-'.add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']); - - // Upload dir - $upload_dir = api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/'; - - // Resize image to max default and end upload - require_once (api_get_path(LIBRARY_PATH).'image.lib.php'); - $temp = new image($_FILES['template_image']['tmp_name']); - $picture_infos = @getimagesize($_FILES['template_image']['tmp_name']); - - $max_width_for_picture = 100; - - if ($picture_infos[0] > $max_width_for_picture) { - $thumbwidth = $max_width_for_picture; - if (empty($thumbwidth) || $thumbwidth == 0) { - $thumbwidth = $max_width_for_picture; - } - $new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]); - - $temp->resize($thumbwidth, $new_height, 0); - } - - $type = $picture_infos[2]; - - switch (!empty($type)) { - case 2 : $temp->send_image('JPG', $upload_dir.$new_file_name); - break; - case 3 : $temp->send_image('PNG', $upload_dir.$new_file_name); - break; - case 1 : $temp->send_image('GIF', $upload_dir.$new_file_name); - break; - } - } - } - - DocumentManager::set_document_as_template($title, $description, $document_id_for_template, $course_code, $user_id, $new_file_name); - Display::display_confirmation_message(get_lang('DocumentSetAsTemplate')); - } - - if (isset($_GET['remove_as_template'])) { - $document_id_for_template = intval($_GET['remove_as_template']); - $course_code = api_get_course_id(); - $user_id = api_get_user_id(); - DocumentManager::unset_document_as_template($document_id_for_template, $course_code, $user_id); - Display::display_confirmation_message(get_lang('DocumentUnsetAsTemplate')); - } - } - + /* MOVE FILE OR DIRECTORY */ + //Only teacher and all users into their group and each user into his/her shared folder + if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id) || is_my_shared_folder($_user['user_id'], Security::remove_XSS($_POST['move_to']), $current_session_id)){ + $my_get_move = Security::remove_XSS($_GET['move']); + if (isset($_GET['move']) && $_GET['move'] != '') { + + if (api_is_coach()) { + if (!DocumentManager::is_visible_by_id($my_get_move, $_course,api_get_session_id())) { + api_not_allowed(); + } + } + + if (!$is_allowed_to_edit) { + if (DocumentManager::check_readonly($_course, $_user['user_id'], $my_get_move)) { + api_not_allowed(); + } + } + + if (DocumentManager::get_document_id($_course, $my_get_move)) { + $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit || $group_member_with_upload_rights); + + //filter if is my shared folder. TODO: move this code to build_move_to_selector function + if(is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id) && !$is_allowed_to_edit){ + $main_user_shared_folder_main = '/shared_folder/sf_user_'.api_get_user_id();//only main user shared folder + $main_user_shared_folder_sub = '/shared_folder\/sf_user_'.api_get_user_id().'\//';//all subfolders + $user_shared_folders=array(); + + foreach($folders as $fold){ + if($main_user_shared_folder_main==$fold || preg_match($main_user_shared_folder_sub, $fold)){ + $user_shared_folders[]=$fold; + } + } + echo '
    '.get_lang('Move').'
    '; + echo build_move_to_selector($user_shared_folders, Security::remove_XSS($_GET['curdirpath']), $my_get_move, $group_properties['directory']); + } + else{ + echo '
    '.get_lang('Move').'
    '; + echo build_move_to_selector($folders, Security::remove_XSS($_GET['curdirpath']), $my_get_move, $group_properties['directory']); + } + } + } + + if (isset($_POST['move_to']) && isset($_POST['move_file'])) { + if (!$is_allowed_to_edit) { + if (DocumentManager::check_readonly($_course, $_user['user_id'], $my_get_move)) { + api_not_allowed(); + } + } + + if (api_is_coach()) { + if (!DocumentManager::is_visible_by_id($my_get_move, $_course,api_get_session_id())) { + api_not_allowed(); + } + } + + + require_once $lib_path.'fileManage.lib.php'; + // This is needed for the update_db_info function + //$dbTable = $_course['dbNameGlu'].'document'; + $dbTable = Database::get_course_table(TABLE_DOCUMENT); + // Security fix: make sure they can't move files that are not in the document table + if (DocumentManager::get_document_id($_course, $_POST['move_file'])) { + if (move($base_work_dir.$_POST['move_file'], $base_work_dir.$_POST['move_to'])) { + update_db_info('update', $_POST['move_file'], $_POST['move_to'].'/'.basename($_POST['move_file'])); + // Set the current path + $curdirpath = $_POST['move_to']; + $curdirpathurl = urlencode($_POST['move_to']); + Display::display_confirmation_message(get_lang('DirMv')); + } else { + Display::display_error_message(get_lang('Impossible')); + } + } else { + Display::display_error_message(get_lang('Impossible')); + } + } + } + + /* DELETE FILE OR DIRECTORY */ + //Only teacher and all users into their group + if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)){ + if (isset($_GET['delete'])) { + + if (api_is_coach()) { + if (!DocumentManager::is_visible($_GET['delete'], $_course)) { + api_not_allowed(); + } + } + + if (!$is_allowed_to_edit) { + if (DocumentManager::check_readonly($_course, $_user['user_id'], $_GET['delete'], '', true)) { + api_not_allowed(); + } + } + + require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; + + if (DocumentManager::delete_document($_course, $_GET['delete'], $base_work_dir)) { + if ( isset($_GET['delete_certificate_id']) && $_GET['delete_certificate_id'] == strval(intval($_GET['delete_certificate_id']))) { + $course_id = api_get_course_id(); + $default_certificate_id = $_GET['delete_certificate_id']; + DocumentManager::remove_attach_certificate($course_id, $default_certificate_id); + } + Display::display_confirmation_message(get_lang('DocDeleted')); + } else { + Display::display_error_message(get_lang('DocDeleteError')); + } + } + + if (isset($_POST['action'])) { + switch ($_POST['action']) { + case 'delete': + + foreach ($_POST['path'] as $index => & $path) { + if (!$is_allowed_to_edit) { + if (DocumentManager::check_readonly($_course, $_user['user_id'], $path)) { + Display::display_error_message(get_lang('CantDeleteReadonlyFiles')); + break 2; + } + } + } + + foreach ($_POST['path'] as $index => & $path) { + if (in_array($path, array('/audio', '/flash', '/images', '/shared_folder', '/video', '/chat_files', '/certificates'))) { + continue; + } else { + $delete_document = DocumentManager::delete_document($_course, $path, $base_work_dir); + } + } + if (!empty($delete_document)) { + Display::display_confirmation_message(get_lang('DocDeleted')); + } + break; + } + } + } + + /* CREATE DIRECTORY */ + //Only teacher and all users into their group and any user into his/her shared folder + if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)){ + // Create directory with $_POST data + if (isset($_POST['create_dir']) && $_POST['dirname'] != '') { + // Needed for directory creation + require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; + $post_dir_name = Security::remove_XSS($_POST['dirname']); + + if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') { + Display::display_error_message(get_lang('CannotCreateDir')); + } else { + $added_slash = ($curdirpath == '/') ? '' : '/'; + $dir_name = $curdirpath.$added_slash.replace_dangerous_char($post_dir_name); + $dir_name = disable_dangerous_file($dir_name); + $dir_check = $base_work_dir.$dir_name; + if (!is_dir($dir_check)) { + $created_dir = create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name); + if ($created_dir) { + Display::display_confirmation_message(''.get_lang('DirCr').'', false); + // Uncomment if you want to enter the created dir + //$curdirpath = $created_dir; + //$curdirpathurl = urlencode($curdirpath); + } else { + Display::display_error_message(get_lang('CannotCreateDir')); + } + } else { + Display::display_error_message(get_lang('CannotCreateDir')); + } + } + } + + // Show them the form for the directory name + if (isset($_GET['createdir'])) { + echo create_dir_form(); + } + } + + /* VISIBILITY COMMANDS */ + //Only teacher + if($is_allowed_to_edit){ + if ((isset($_GET['set_invisible']) && !empty($_GET['set_invisible'])) || (isset($_GET['set_visible']) && !empty($_GET['set_visible'])) && $_GET['set_visible'] != '*' && $_GET['set_invisible'] != '*') { + // Make visible or invisible? + if (isset($_GET['set_visible'])) { + $update_id = $_GET['set_visible']; + $visibility_command = 'visible'; + } else { + $update_id = $_GET['set_invisible']; + $visibility_command = 'invisible'; + } + + if (api_is_coach()) { + if (!DocumentManager::is_visible_by_id($update_id, $_course)) { + api_not_allowed(); + } + } + + if (!$is_allowed_to_edit) { + if(DocumentManager::check_readonly($_course, $_user['user_id'], '', $update_id)) { + api_not_allowed(); + } + } + + // Update item_property to change visibility + if (api_item_property_update($_course, TOOL_DOCUMENT, $update_id, $visibility_command, $_user['user_id'], null, null, null, null, $current_session_id)) { + Display::display_confirmation_message(get_lang('VisibilityChanged'));//don't use ViMod because firt is load ViMdod (Gradebook). VisibilityChanged (trad4all) + } else { + Display::display_error_message(get_lang('ViModProb')); + } + } + } + + /* TEMPLATE ACTION */ + //Only teacher and all users into their group + if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)){ + if (isset($_GET['add_as_template']) && !isset($_POST['create_template'])) { + + $document_id_for_template = intval($_GET['add_as_template']); + + // Create the form that asks for the directory name + $template_text = '
    '; + $template_text .= ''; + $template_text .= ''; + $template_text .= ''; + //$template_text .= ''; + //$template_text .= ''; + $template_text .= ''; + $template_text .= ''; + $template_text .= '
    '; + $template_text .= get_lang('TemplateName').' :
    '.get_lang('TemplateDescription').' :
    '.get_lang('TemplateImage').' :
    '; + $template_text .= ''; + $template_text .= '
    '; + // Show the form + Display::display_normal_message($template_text, false); + + } elseif (isset($_GET['add_as_template']) && isset($_POST['create_template'])) { + + $document_id_for_template = intval(Database::escape_string($_GET['add_as_template'])); + + $title = Security::remove_XSS($_POST['template_title']); + //$description = Security::remove_XSS($_POST['template_description']); + $course_code = api_get_course_id(); + $user_id = api_get_user_id(); + + // Create the template_thumbnails folder in the upload folder (if needed) + if (!is_dir(api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/')) { + @mkdir(api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/', api_get_permissions_for_new_directories()); + } + // Upload the file + if (!empty($_FILES['template_image']['name'])) { + + require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; + $upload_ok = process_uploaded_file($_FILES['template_image']); + + if ($upload_ok) { + // Try to add an extension to the file if it hasn't one + $new_file_name = $_course['sysCode'].'-'.add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']); + + // Upload dir + $upload_dir = api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/'; + + // Resize image to max default and end upload + require_once (api_get_path(LIBRARY_PATH).'image.lib.php'); + $temp = new image($_FILES['template_image']['tmp_name']); + $picture_infos = @getimagesize($_FILES['template_image']['tmp_name']); + + $max_width_for_picture = 100; + + if ($picture_infos[0] > $max_width_for_picture) { + $thumbwidth = $max_width_for_picture; + if (empty($thumbwidth) || $thumbwidth == 0) { + $thumbwidth = $max_width_for_picture; + } + $new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]); + + $temp->resize($thumbwidth, $new_height, 0); + } + + $type = $picture_infos[2]; + + switch (!empty($type)) { + case 2 : $temp->send_image('JPG', $upload_dir.$new_file_name); + break; + case 3 : $temp->send_image('PNG', $upload_dir.$new_file_name); + break; + case 1 : $temp->send_image('GIF', $upload_dir.$new_file_name); + break; + } + } + } + + DocumentManager::set_document_as_template($title, $description, $document_id_for_template, $course_code, $user_id, $new_file_name); + Display::display_confirmation_message(get_lang('DocumentSetAsTemplate')); + } + + if (isset($_GET['remove_as_template'])) { + $document_id_for_template = intval($_GET['remove_as_template']); + $course_code = api_get_course_id(); + $user_id = api_get_user_id(); + DocumentManager::unset_document_as_template($document_id_for_template, $course_code, $user_id); + Display::display_confirmation_message(get_lang('DocumentUnsetAsTemplate')); + } + } + // END ACTION MENU // Attach certificate in the gradebook if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_certificate']) && $_GET['set_certificate'] == strval(intval($_GET['set_certificate']))) { - if (isset($_GET['cidReq'])) { - $course_id = Security::remove_XSS($_GET['cidReq']); // course id - $document_id = Security::remove_XSS($_GET['set_certificate']); // document id - DocumentManager::attach_gradebook_certificate ($course_id,$document_id); - Display::display_normal_message(get_lang('IsDefaultCertificate')); - } + if (isset($_GET['cidReq'])) { + $course_id = Security::remove_XSS($_GET['cidReq']); // course id + $document_id = Security::remove_XSS($_GET['set_certificate']); // document id + DocumentManager::attach_gradebook_certificate ($course_id,$document_id); + Display::display_normal_message(get_lang('IsDefaultCertificate')); + } } @@ -762,238 +762,238 @@ if(isset($_GET['keyword']) && !empty($_GET['keyword'])){ $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit || $group_member_with_upload_rights); if ($folders === false) { - $folders = array(); + $folders = array(); } echo '
    '; if ($is_allowed_to_edit || $group_member_with_upload_rights){ /* BUILD SEARCH FORM */ - echo ''; - $form = new FormValidator('search_document', 'get', '', '', null, false); - $renderer = & $form->defaultRenderer(); - $renderer->setElementTemplate('{element} '); - $form->add_textfield('keyword', '', false); - $form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"'); - $form->display(); - echo ''; + echo ''; + $form = new FormValidator('search_document', 'get', '', '', null, false); + $renderer = & $form->defaultRenderer(); + $renderer->setElementTemplate('{element} '); + $form->add_textfield('keyword', '', false); + $form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"'); + $form->display(); + echo ''; } /* GO TO PARENT DIRECTORY */ if ($curdirpath!= '/' && $curdirpath != $group_properties['directory'] && !$is_certificate_mode) { ?> - -   + +   - -   + +   '); - //print_r($docs_and_folders); - //echo(''); - - // Do we need the title field for the document name or not? - // We get the setting here, so we only have to do it once - $use_document_title = api_get_setting('use_document_title'); - // Create a sortable table with our data - $sortable_data = array(); - - //while (list($key, $id) = each($docs_and_folders)) { - foreach($docs_and_folders as $key=>$id) { - $row = array(); - - // If the item is invisible, wrap it in a span with class invisible - $invisibility_span_open = ($id['visibility'] == 0) ? '' : ''; - // Size (or total size of a directory) - $size = $id['filetype'] == 'folder' ? get_total_folder_size($id['path'], $is_allowed_to_edit) : $id['size']; - // Get the title or the basename depending on what we're using - if ($use_document_title == 'true' && $id['title'] != '') { - $document_name = $id['title']; - } else { - $document_name = basename($id['path']); - } - // Data for checkbox - if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) { - $row[] = $id['path']; - } - - // Hide HotPotatoes Certificates and all css folders - if($id['path']=='/HotPotatoes_files' || $id['path']=='/certificates' || basename($id['path'])=='css'){ - continue; - } - - //Admin setting for Hide/Show the folders of all users - if(api_get_setting('show_users_folders') == 'false' && ($id['path']=='/shared_folder' || strstr($id['path'], 'shared_folder_session_'))){ - continue; - } - - //Admin setting for Hide/Show Default folders to all users - if(api_get_setting('show_default_folders') == 'false' && ($id['path']=='/images' || $id['path']=='/flash' || $id['path']=='/audio' || $id['path']=='/video')){ - continue; - } - - //Admin setting for Hide/Show chat history folder - if(api_get_setting('show_chat_folder') == 'false' && $id['path']=='/chat_files'){ - continue; - } - - // Show the owner of the file only in groups - $user_link = ''; - - if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') { - if (!empty($id['insert_user_id'])) { - $user_info = UserManager::get_user_info_by_id($id['insert_user_id']); - $user_name = api_get_person_name($user_info['firstname'], $user_info['lastname']); - $user_link = '
    '.get_lang('Owner').': '.display_user_link_document($id['insert_user_id'], $user_name).'
    '; - } - } - - // Icons (clickable) - //$row[]= build_document_icon_tag($id['filetype'],$id['path']); - $row[] = create_document_link($http_www, $document_name, $id['path'], $id['filetype'], $size, $id['visibility'], true); - - // Validacion when belongs to a session - $session_img = api_get_session_image($id['session_id'], $_user['status']); - - // Document title with hyperlink - $row[] = create_document_link($http_www, $document_name, $id['path'], $id['filetype'], $size, $id['visibility']).$session_img.'
    '.$invisibility_span_open.nl2br(htmlspecialchars($id['comment'],ENT_QUOTES,$charset)).$invisibility_span_close.$user_link; - - // Comments => display comment under the document name - //$row[] = $invisibility_span_open.nl2br(htmlspecialchars($id['comment'])).$invisibility_span_close; - $display_size = format_file_size($size); - $row[] = ''.$size.''.$invisibility_span_open.$display_size.$invisibility_span_close; - - // Last edit date - $last_edit_date = $id['lastedit_date']; - $last_edit_date = api_get_local_time($last_edit_date, null, date_default_timezone_get()); - $display_date = date_to_str_ago($last_edit_date).'
    '.api_format_date($last_edit_date).''; - $row[] = $invisibility_span_open.$display_date.$invisibility_span_close; - // Admins get an edit column - if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)) { - $is_template = isset($id['is_template']) ? $id['is_template'] : false; - // If readonly, check if it the owner of the file or if the user is an admin - if ($id['insert_user_id'] == $_user['user_id'] || api_is_platform_admin()) { - $edit_icons = build_edit_icons($curdirpath, $id['filetype'], $id['path'], $id['visibility'], $key, $is_template, 0); - } else { - $edit_icons = build_edit_icons($curdirpath, $id['filetype'], $id['path'], $id['visibility'], $key, $is_template, $id['readonly']); - } - $row[] = $edit_icons; - } - $row[] = $last_edit_date; - $row[] = $size; - $total_size = $total_size + $size; - if ((isset ($_GET['keyword']) && search_keyword($document_name, $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) { - $sortable_data[] = $row; - } - } + + //echo('
    ');
    +    //print_r($docs_and_folders);
    +    //echo('
    '); + + // Do we need the title field for the document name or not? + // We get the setting here, so we only have to do it once + $use_document_title = api_get_setting('use_document_title'); + // Create a sortable table with our data + $sortable_data = array(); + + //while (list($key, $id) = each($docs_and_folders)) { + foreach($docs_and_folders as $key=>$id) { + $row = array(); + + // If the item is invisible, wrap it in a span with class invisible + $invisibility_span_open = ($id['visibility'] == 0) ? '' : ''; + // Size (or total size of a directory) + $size = $id['filetype'] == 'folder' ? get_total_folder_size($id['path'], $is_allowed_to_edit) : $id['size']; + // Get the title or the basename depending on what we're using + if ($use_document_title == 'true' && $id['title'] != '') { + $document_name = $id['title']; + } else { + $document_name = basename($id['path']); + } + // Data for checkbox + if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) { + $row[] = $id['path']; + } + + // Hide HotPotatoes Certificates and all css folders + if($id['path']=='/HotPotatoes_files' || $id['path']=='/certificates' || basename($id['path'])=='css'){ + continue; + } + + //Admin setting for Hide/Show the folders of all users + if(api_get_setting('show_users_folders') == 'false' && ($id['path']=='/shared_folder' || strstr($id['path'], 'shared_folder_session_'))){ + continue; + } + + //Admin setting for Hide/Show Default folders to all users + if(api_get_setting('show_default_folders') == 'false' && ($id['path']=='/images' || $id['path']=='/flash' || $id['path']=='/audio' || $id['path']=='/video')){ + continue; + } + + //Admin setting for Hide/Show chat history folder + if(api_get_setting('show_chat_folder') == 'false' && $id['path']=='/chat_files'){ + continue; + } + + // Show the owner of the file only in groups + $user_link = ''; + + if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') { + if (!empty($id['insert_user_id'])) { + $user_info = UserManager::get_user_info_by_id($id['insert_user_id']); + $user_name = api_get_person_name($user_info['firstname'], $user_info['lastname']); + $user_link = '
    '.get_lang('Owner').': '.display_user_link_document($id['insert_user_id'], $user_name).'
    '; + } + } + + // Icons (clickable) + //$row[]= build_document_icon_tag($id['filetype'],$id['path']); + $row[] = create_document_link($http_www, $document_name, $id['path'], $id['filetype'], $size, $id['visibility'], true); + + // Validacion when belongs to a session + $session_img = api_get_session_image($id['session_id'], $_user['status']); + + // Document title with hyperlink + $row[] = create_document_link($http_www, $document_name, $id['path'], $id['filetype'], $size, $id['visibility']).$session_img.'
    '.$invisibility_span_open.nl2br(htmlspecialchars($id['comment'],ENT_QUOTES,$charset)).$invisibility_span_close.$user_link; + + // Comments => display comment under the document name + //$row[] = $invisibility_span_open.nl2br(htmlspecialchars($id['comment'])).$invisibility_span_close; + $display_size = format_file_size($size); + $row[] = ''.$size.''.$invisibility_span_open.$display_size.$invisibility_span_close; + + // Last edit date + $last_edit_date = $id['lastedit_date']; + $last_edit_date = api_get_local_time($last_edit_date, null, date_default_timezone_get()); + $display_date = date_to_str_ago($last_edit_date).'
    '.api_format_date($last_edit_date).''; + $row[] = $invisibility_span_open.$display_date.$invisibility_span_close; + // Admins get an edit column + if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)) { + $is_template = isset($id['is_template']) ? $id['is_template'] : false; + // If readonly, check if it the owner of the file or if the user is an admin + if ($id['insert_user_id'] == $_user['user_id'] || api_is_platform_admin()) { + $edit_icons = build_edit_icons($curdirpath, $id['filetype'], $id['path'], $id['visibility'], $key, $is_template, 0); + } else { + $edit_icons = build_edit_icons($curdirpath, $id['filetype'], $id['path'], $id['visibility'], $key, $is_template, $id['readonly']); + } + $row[] = $edit_icons; + } + $row[] = $last_edit_date; + $row[] = $size; + $total_size = $total_size + $size; + if ((isset ($_GET['keyword']) && search_keyword($document_name, $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) { + $sortable_data[] = $row; + } + } } else { - $sortable_data = ''; - $table_footer = '
    '.get_lang('NoDocsInFolder').'
    '; + $sortable_data = ''; + $table_footer = '
    '.get_lang('NoDocsInFolder').'
    '; } $column_show = array(); if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)) { - // TODO:check enable more options for shared folders - /* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */ - - // Create new document - if (!$is_certificate_mode) { - ?> - -   - - -   - - + // TODO:check enable more options for shared folders + /* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */ + + // Create new document + if (!$is_certificate_mode) { + ?> + +   + + +   + +   - - -   + +   - -   + +   - -   + +   -   +   '.Display::display_icon('zip_save.gif', get_lang('Save').' (ZIP)'). get_lang('Save').' (ZIP) '; - } - - } + // Show download zipped folder icon + global $total_size; + if (!$is_certificate_mode && $total_size != 0 && (api_get_setting('students_download_folders') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin())) { + + //for student does not show icon into other shared folder, and does not show into main path (root) + if (is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id) && $curdirpath!='/' || api_is_allowed_to_edit() || api_is_platform_admin()) + { + echo ''.Display::display_icon('zip_save.gif', get_lang('Save').' (ZIP)'). get_lang('Save').' (ZIP) '; + } + + } } // Slideshow by Patrick Cool, May 2004 require 'document_slideshow.inc.php'; if ($image_present && !isset($_GET['keyword']) ) { - echo ''.get_lang('ViewSlideshow').''; + echo ''.get_lang('ViewSlideshow').''; } echo '
    '; if (!$is_certificate_mode) { - echo build_directory_selector($folders, $curdirpath, (isset($group_properties['directory']) ? $group_properties['directory'] : array()), true); + echo build_directory_selector($folders, $curdirpath, (isset($group_properties['directory']) ? $group_properties['directory'] : array()), true); } if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) { - $column_show[] = 1; + $column_show[] = 1; } $column_show[] = 1; @@ -1002,18 +1002,18 @@ $column_show[] = 1; $column_show[] = 1; if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)) { - $column_show[] = 1; + $column_show[] = 1; } $column_show[] = 0; $column_order = array(); if (count($row) == 8) { - $column_order[3] = 7; - $column_order[4] = 6; + $column_order[3] = 7; + $column_order[4] = 6; } elseif (count($row) == 6) { - $column_order[2] = 5; - $column_order[3] = 4; + $column_order[2] = 5; + $column_order[3] = 4; } $default_column = $is_allowed_to_edit ? 2 : 1; @@ -1021,13 +1021,13 @@ $tablename = $is_allowed_to_edit ? 'teacher_table' : 'student_table'; $table = new SortableTableFromArrayConfig($sortable_data, $default_column, 20, $tablename, $column_show, $column_order, 'ASC'); if(isset($_GET['keyword'])){ - $query_vars['keyword'] = Security::remove_XSS($_GET['keyword']); + $query_vars['keyword'] = Security::remove_XSS($_GET['keyword']); }else{ - $query_vars['curdirpath'] = $curdirpath; + $query_vars['curdirpath'] = $curdirpath; } if (isset($_SESSION['_gid'])) { - $query_vars['gidReq'] = $_SESSION['_gid']; + $query_vars['gidReq'] = $_SESSION['_gid']; } $query_vars['cidReq'] = api_get_course_id(); $table->set_additional_parameters($query_vars); @@ -1035,7 +1035,7 @@ $table->set_additional_parameters($query_vars); $column = 0; if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) { - $table->set_header($column++, '', false,array ('style' => 'width:30px;')); + $table->set_header($column++, '', false,array ('style' => 'width:30px;')); } $table->set_header($column++, get_lang('Type'),true,array ('style' => 'width:30px;')); @@ -1046,22 +1046,22 @@ $table->set_header($column++, get_lang('Size'),true,array ('style' => 'width:50p $table->set_header($column++, get_lang('Date'),true,array ('style' => 'width:150px;')); // Admins get an edit column if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)) { - $table->set_header($column++, get_lang('Actions'), false,array ('style' => 'width:150px;')); + $table->set_header($column++, get_lang('Actions'), false,array ('style' => 'width:150px;')); } // Actions on multiple selected documents // TODO: Currently only delete action -> take only DELETE right into account if (count($docs_and_folders) > 1) { - if ($is_allowed_to_edit || $group_member_with_upload_rights) { - $form_actions = array(); - $form_action['delete'] = get_lang('Delete'); - $table->set_form_actions($form_action, 'path'); - } + if ($is_allowed_to_edit || $group_member_with_upload_rights) { + $form_actions = array(); + $form_action['delete'] = get_lang('Delete'); + $table->set_form_actions($form_action, 'path'); + } } $table->display(); if (!empty($table_footer)) { - echo $table_footer; + echo $table_footer; } // Footer From 2fd98c85b9a9c7b1f10b9006059b567f860d3207 Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Wed, 12 Jan 2011 15:16:36 +0200 Subject: [PATCH 4/5] Feature #2512: The "Documents" tool: Adding an icon "Open in a new window". --- main/document/document.inc.php | 46 +++++++++++++++++++++----- main/img/open_in_new_window.png | Bin 0 -> 1292 bytes main/img/open_in_new_window_small.png | Bin 0 -> 1299 bytes main/lang/bulgarian/trad4all.inc.php | 1 + main/lang/english/trad4all.inc.php | 1 + 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 main/img/open_in_new_window.png create mode 100644 main/img/open_in_new_window_small.png diff --git a/main/document/document.inc.php b/main/document/document.inc.php index c5c972603f..276db604a0 100755 --- a/main/document/document.inc.php +++ b/main/document/document.inc.php @@ -124,18 +124,20 @@ function create_document_link($www, $title, $path, $filetype, $size, $visibility $ext = explode('.', $path); $ext = strtolower($ext[sizeof($ext) - 1]); - // "htmlfiles" are shown in a frameset - if ($ext == 'htm' || $ext == 'html' || $ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'pdf' || $ext == 'swf' || $ext == 'mp3' || $ext == 'mp4' ||(($ext== 'ogg' || $ext== 'ogx' || $ext== 'oga' || $ext== 'ogv') && api_browser_support('ogg')) ||($ext == 'svg' && api_browser_support('svg'))) { + // HTML-files an some other types are shown in a frameset by default. + $is_browser_viewable_file = is_browser_viewable($ext); + if ($is_browser_viewable_file) { $url = 'showinframes.php?'.api_get_cidreq().'&file='.$url_path.$req_gid; } else { // url-encode for problematic characters (we may not call them dangerous characters...) $path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq(); $url = $www.$path; } - // Files that we want opened in a new window - if ($ext == 'txt' || $ext == 'log' || $ext == 'css' || $ext == 'js') { // Add here - $target = '_blank'; - } + // Disabled fragment of code, there is a special icon for opening in a new window. + //// Files that we want opened in a new window + //if ($ext == 'txt' || $ext == 'log' || $ext == 'css' || $ext == 'js') { // Add here + // $target = '_blank'; + //} } else { $url = api_get_self().'?'.api_get_cidreq().'&curdirpath='.$url_path.$req_gid; } @@ -200,10 +202,15 @@ function create_document_link($www, $title, $path, $filetype, $size, $visibility if($filetype == 'file') { - $copy_to_myfiles=''.Display::return_icon('briefcase_small.png', get_lang('CopyToMyFiles'), array('height'=>'16', 'width' => '16')).'  '; + $copy_to_myfiles=''.Display::return_icon('briefcase_small.png', get_lang('CopyToMyFiles'), array('height'=>'16', 'width' => '16')).'  '; } } - return ''.$title.''.$force_download_html.$copy_to_myfiles; + + if ($is_browser_viewable_file) { + $open_in_new_window_link = ''.Display::return_icon('open_in_new_window_small.png', get_lang('OpenInANewWindow'), array('height'=>'16', 'width' => '16')).'  '; + } + + return ''.$title.''.$force_download_html.$copy_to_myfiles.$open_in_new_window_link; //end copy files to users myfiles } else{ @@ -669,4 +676,27 @@ function search_keyword($document_name, $keyword) { } } +/** + * Check whether a document can be opened inside a frame. + * @param string $file_extension The filename extension of the document (it must be in lower case). + * @return bool Returns TRUE or FALSE. + */ +function is_browser_viewable($file_extension) { + static $allowed_extensions = array( + 'htm', 'html', 'xhtml', 'gif', 'jpg', 'jpeg', 'png', 'pdf', 'swf', 'mp3', 'mp4', 'ogg', 'ogx', 'oga', 'ogv', 'svg', + 'txt', 'log', 'css', 'js', + 'mpg', 'mpeg' + ); + if (!($result = in_array($file_extension, $allowed_extensions))) { // Assignment + a logical check. + return false; + } + switch ($file_extension) { + case 'ogg': + return api_browser_support('ogg'); + case 'svg': + return api_browser_support('svg'); + } + return $result; +} + ?> \ No newline at end of file diff --git a/main/img/open_in_new_window.png b/main/img/open_in_new_window.png new file mode 100644 index 0000000000000000000000000000000000000000..51a590035d564f2664694281151709e39f2d5387 GIT binary patch literal 1292 zcmeAS@N?(olHy`uVBq!ia0vp^Vj#@H3?x5i&EW)6jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCijSl0AZa85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#N0|PTd zfKP}kP=QnR_n@Bd#Y_J;H8s6^_wN7y|3JY}Fd70QAq3`LXORHrDTb0DzhGd>AIX3r z_&d8QFwP}QTq8+MN+jjWltmFp%A8Wkz-%Xmv`zSomo8#{6SWt@dboFyt=akR{0J>vel>h($ literal 0 HcmV?d00001 diff --git a/main/img/open_in_new_window_small.png b/main/img/open_in_new_window_small.png new file mode 100644 index 0000000000000000000000000000000000000000..1c91130b9f721f93ad14ea17498c211aeee5440a GIT binary patch literal 1299 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%G|oWRD45bDP46hOx7_4S6Fo+k-*%fHRz`)E9 z;1l8sRNz|o-LK(=d&75+#_!%O-=jOC&YK4<5XG_wN7y|3G6$!Dt8! z{t(!7rtJwZPcf7P`2_>h?MMa;!Qa_cfiWgo;u=vBoS#-wo>-L15RjOeSEA?V8lq5U ztY@lccAWLa6yJGwdgAJ13%NGV_w7rv7*b#r|;ZeWs0(t6TJ&GG;bX26<&u||&5XyUB S?qdWf*?7A8xvX \ No newline at end of file diff --git a/main/lang/english/trad4all.inc.php b/main/lang/english/trad4all.inc.php index 46c219ef91..d8f1bf627a 100644 --- a/main/lang/english/trad4all.inc.php +++ b/main/lang/english/trad4all.inc.php @@ -979,4 +979,5 @@ $ChatFiles = "Conversation history in chat"; $Flash = "Flash"; $Video = "Video"; $Images = "Images"; +$OpenInANewWindow = "Open in a new window"; ?> \ No newline at end of file From b5f060855d0667d48f3788d06953ca9c42fd6d95 Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Wed, 12 Jan 2011 15:24:09 +0200 Subject: [PATCH 5/5] Feature #2512: A minor correction. --- main/document/document.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/document/document.inc.php b/main/document/document.inc.php index 276db604a0..7c52088195 100755 --- a/main/document/document.inc.php +++ b/main/document/document.inc.php @@ -677,7 +677,7 @@ function search_keyword($document_name, $keyword) { } /** - * Check whether a document can be opened inside a frame. + * Checks whether a document can be previewed by using the browser. * @param string $file_extension The filename extension of the document (it must be in lower case). * @return bool Returns TRUE or FALSE. */