Bladeren bron

Merge branch '1.9.x' of github.com:chamilo/chamilo-lms into 1.9.x

Yannick Warnier 10 jaren geleden
bovenliggende
commit
eab9d76382

+ 83 - 73
main/admin/settings.lib.php

@@ -111,18 +111,18 @@ function handle_plugins()
 {
     $plugin_obj = new AppPlugin();
     $token = Security::get_token();
-     if (isset($_POST['submit_plugins'])) {
+    if (isset($_POST['submit_plugins'])) {
         store_plugins();
         // Add event to the system log.
         $user_id = api_get_user_id();
         $category = $_GET['category'];
-         event_system(
-             LOG_CONFIGURATION_SETTINGS_CHANGE,
-             LOG_CONFIGURATION_SETTINGS_CATEGORY,
-             $category,
-             api_get_utc_datetime(),
-             $user_id
-         );
+        event_system(
+            LOG_CONFIGURATION_SETTINGS_CHANGE,
+            LOG_CONFIGURATION_SETTINGS_CATEGORY,
+            $category,
+            api_get_utc_datetime(),
+            $user_id
+        );
         Display :: display_confirmation_message(get_lang('SettingsStored'));
     }
 
@@ -175,12 +175,12 @@ function handle_plugins()
 
             echo '<div class="btn-group">';
             if (in_array($plugin, $installed_plugins)) {
-                 echo Display::url(get_lang('Configure'), 'configure_plugin.php?name='.$plugin, array('class' => 'btn'));
-                 echo Display::url(get_lang('Regions'), 'settings.php?category=Regions&name='.$plugin, array('class' => 'btn'));
+                echo Display::url(get_lang('Configure'), 'configure_plugin.php?name='.$plugin, array('class' => 'btn'));
+                echo Display::url(get_lang('Regions'), 'settings.php?category=Regions&name='.$plugin, array('class' => 'btn'));
             }
 
             if (file_exists(api_get_path(SYS_PLUGIN_PATH).$plugin.'/readme.txt')) {
-                 echo Display::url("readme.txt", api_get_path(WEB_PLUGIN_PATH).$plugin."/readme.txt", array('class' => 'btn ajax', '_target' => '_blank'));
+                echo Display::url("readme.txt", api_get_path(WEB_PLUGIN_PATH).$plugin."/readme.txt", array('class' => 'btn ajax', '_target' => '_blank'));
             }
             echo '</div>';
             echo '</td></tr>';
@@ -198,7 +198,7 @@ function handle_plugins()
  * This function allows the platform admin to choose the default stylesheet
  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  * @author Julio Montoya <gugli100@gmail.com>, Chamilo
-*/
+ */
 function handle_stylesheets()
 {
     global $_configuration;
@@ -219,7 +219,6 @@ function handle_stylesheets()
     }
 
     $form = new FormValidator('stylesheet_upload', 'post', 'settings.php?category=Stylesheets#tabs-2');
-    //$form->addElement('header', get_lang('UploadNewStylesheet'));
     $form->addElement('text', 'name_stylesheet', get_lang('NameStylesheet'), array('size' => '40', 'maxlength' => '40'));
     $form->addRule('name_stylesheet', get_lang('ThisFieldIsRequired'), 'required');
     $form->addElement('file', 'new_stylesheet', get_lang('UploadNewStylesheet'));
@@ -256,7 +255,13 @@ function handle_stylesheets()
             // Add event to the system log.
             $user_id = api_get_user_id();
             $category = $_GET['category'];
-            event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
+            event_system(
+                LOG_CONFIGURATION_SETTINGS_CHANGE,
+                LOG_CONFIGURATION_SETTINGS_CATEGORY,
+                $category,
+                api_get_utc_datetime(),
+                $user_id
+            );
 
             if ($result) {
                 Display::display_confirmation_message(get_lang('StylesheetAdded'));
@@ -467,7 +472,7 @@ function upload_stylesheet($values, $picture)
  */
 function store_regions()
 {
-     $plugin_obj = new AppPlugin();
+    $plugin_obj = new AppPlugin();
 
     // Get a list of all current 'Plugins' settings
     $installed_plugins = $plugin_obj->get_installed_plugins();
@@ -502,7 +507,7 @@ function store_regions()
 /**
  * This function allows easy activating and inactivating of plugins
  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-*/
+ */
 function store_plugins()
 {
     $appPlugin = new AppPlugin();
@@ -533,13 +538,18 @@ function store_plugins()
 /**
  * This function allows the platform admin to choose which should be the default stylesheet
  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-*/
+ */
 function store_stylesheets()
 {
     // Insert the stylesheet.
-    $style = Database::escape_string($_POST['style']);
-    if (is_style($style)) {
-        api_set_setting('stylesheets', $style, null, 'stylesheets', api_get_current_access_url_id());
+    if (is_style($_POST['style'])) {
+        api_set_setting(
+            'stylesheets',
+            $_POST['style'],
+            null,
+            'stylesheets',
+            api_get_current_access_url_id()
+        );
     }
     return true;
 }
@@ -613,7 +623,7 @@ function handle_search()
 
         $sf_values = array();
         foreach ($specific_fields as $sf) {
-           $sf_values[$sf['code']] = $sf['name'];
+            $sf_values[$sf['code']] = $sf['name'];
         }
         $group = array();
         $url =  Display::div(Display::url(get_lang('AddSpecificSearchField'), 'specific_fields.php'), array('class'=>'sectioncomment'));
@@ -970,34 +980,34 @@ function add_edit_template() {
                     }
                     $temp->send_image($upload_dir.$new_file_name);
                 }
-           }
-
-           // Store the information in the database (as insert or as update).
-           $table_system_template = Database :: get_main_table('system_template');
-           if ($_GET['action'] == 'add') {
-               $content_template = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body>'.Database::escape_string($values['template_text']).'</body>';
-               $sql = "INSERT INTO $table_system_template (title, content, image) VALUES ('".Database::escape_string($values['title'])."','".$content_template."','".Database::escape_string($new_file_name)."')";
-               Database::query($sql);
-
-               // Display a feedback message.
-               Display::display_confirmation_message(get_lang('TemplateAdded'));
-               echo '<a href="settings.php?category=Templates&amp;action=add">'.Display::return_icon('new_template.png', get_lang('AddTemplate'),'',ICON_SIZE_MEDIUM).'</a>';
-           } else {
-               $content_template = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body>'.Database::escape_string($values['template_text']).'</body>';
-               $sql = "UPDATE $table_system_template set title = '".Database::escape_string($values['title'])."', content = '".$content_template."'";
-               if (!empty($new_file_name)) {
-                   $sql .= ", image = '".Database::escape_string($new_file_name)."'";
-               }
-               $sql .= " WHERE id = ".intval($_GET['id'])."";
-               Database::query($sql);
-
-               // Display a feedback message.
-               Display::display_confirmation_message(get_lang('TemplateEdited'));
-           }
+            }
+
+            // Store the information in the database (as insert or as update).
+            $table_system_template = Database :: get_main_table('system_template');
+            if ($_GET['action'] == 'add') {
+                $content_template = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body>'.Database::escape_string($values['template_text']).'</body>';
+                $sql = "INSERT INTO $table_system_template (title, content, image) VALUES ('".Database::escape_string($values['title'])."','".$content_template."','".Database::escape_string($new_file_name)."')";
+                Database::query($sql);
+
+                // Display a feedback message.
+                Display::display_confirmation_message(get_lang('TemplateAdded'));
+                echo '<a href="settings.php?category=Templates&amp;action=add">'.Display::return_icon('new_template.png', get_lang('AddTemplate'),'',ICON_SIZE_MEDIUM).'</a>';
+            } else {
+                $content_template = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body>'.Database::escape_string($values['template_text']).'</body>';
+                $sql = "UPDATE $table_system_template set title = '".Database::escape_string($values['title'])."', content = '".$content_template."'";
+                if (!empty($new_file_name)) {
+                    $sql .= ", image = '".Database::escape_string($new_file_name)."'";
+                }
+                $sql .= " WHERE id = ".intval($_GET['id'])."";
+                Database::query($sql);
+
+                // Display a feedback message.
+                Display::display_confirmation_message(get_lang('TemplateEdited'));
+            }
 
         }
-       Security::clear_token();
-       display_templates();
+        Security::clear_token();
+        display_templates();
 
     } else {
 
@@ -1118,7 +1128,7 @@ function generate_settings_form($settings, $settings_by_access_list) {
 
     $i = 0;
     foreach ($settings as $row) {
-    	if (in_array($row['variable'], array_keys($settings_to_avoid))) { continue; }
+        if (in_array($row['variable'], array_keys($settings_to_avoid))) { continue; }
 
         if (!empty($_configuration['multiple_access_urls'])) {
             if (api_is_global_platform_admin()) {
@@ -1126,18 +1136,18 @@ function generate_settings_form($settings, $settings_by_access_list) {
                     if ($url_id == 1) {
                         if ($row['access_url_changeable'] == '1') {
                             $form->addElement('html', '<div style="float: right;"><a class="share_this_setting" data_status = "0"  data_to_send = "'.$row['variable'].'" href="javascript:void(0);">'.
-                                    Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')).'</a></div>');
+                                Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')).'</a></div>');
                         } else {
                             $form->addElement('html', '<div style="float: right;"><a class="share_this_setting" data_status = "1" data_to_send = "'.$row['variable'].'" href="javascript:void(0);">'.
-                                    Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')).'</a></div>');
+                                Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')).'</a></div>');
                         }
                     } else {
                         if ($row['access_url_changeable'] == '1') {
                             $form->addElement('html', '<div style="float: right;">'.
-                                    Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')).'</div>');
+                                Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')).'</div>');
                         } else {
                             $form->addElement('html', '<div style="float: right;">'.
-                                    Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')).'</div>');
+                                Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')).'</div>');
                         }
                     }
                 }
@@ -1216,25 +1226,25 @@ function generate_settings_form($settings, $settings_by_access_list) {
                 break;
             case 'textarea':
                 if ($row['variable'] == 'header_extra_content') {
-      	            $file = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt';
+                    $file = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt';
                     $value = '';
                     if (file_exists($file)) {
                         $value = file_get_contents($file);
                     }
                     $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('class'=>'span6','rows'=>'10'), $hideme);
-            	    $default_values[$row['variable']] = $value;
+                    $default_values[$row['variable']] = $value;
                 } elseif ($row['variable'] == 'footer_extra_content') {
-            		$file = api_get_path(SYS_PATH).api_get_home_path().'footer_extra_content.txt';
-            		$value = '';
-            		if (file_exists($file)) {
-						$value = file_get_contents($file);
-            		}
-            	    $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10', 'class'=>'span6'), $hideme);
-            	    $default_values[$row['variable']] = $value;
-            	} else {
-                	$form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10','class'=>'span6'), $hideme);
-                	$default_values[$row['variable']] = $row['selected_value'];
-            	}
+                    $file = api_get_path(SYS_PATH).api_get_home_path().'footer_extra_content.txt';
+                    $value = '';
+                    if (file_exists($file)) {
+                        $value = file_get_contents($file);
+                    }
+                    $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10', 'class'=>'span6'), $hideme);
+                    $default_values[$row['variable']] = $value;
+                } else {
+                    $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10','class'=>'span6'), $hideme);
+                    $default_values[$row['variable']] = $row['selected_value'];
+                }
                 break;
             case 'radio':
                 $values = api_get_settings_options($row['variable']);
@@ -1258,15 +1268,15 @@ function generate_settings_form($settings, $settings_by_access_list) {
                 $result = Database::query($sql);
                 $group = array ();
                 while ($rowkeys = Database::fetch_array($result)) {
-                     //if ($rowkeys['variable'] == 'course_create_active_tools' && $rowkeys['subkey'] == 'enable_search') { continue; }
+                    //if ($rowkeys['variable'] == 'course_create_active_tools' && $rowkeys['subkey'] == 'enable_search') { continue; }
 
-                     // Profile tab option should be hidden when the social tool is enabled.
-                     if (api_get_setting('allow_social_tool') == 'true') {
-                         if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') { continue; }
-                     }
+                    // Profile tab option should be hidden when the social tool is enabled.
+                    if (api_get_setting('allow_social_tool') == 'true') {
+                        if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') { continue; }
+                    }
 
-                     // Hiding the gradebook option.
-                     if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_gradebook') { continue; }
+                    // Hiding the gradebook option.
+                    if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_gradebook') { continue; }
 
                     $element = & $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext']));
                     if ($row['access_url_changeable'] == 1) {
@@ -1303,7 +1313,7 @@ function generate_settings_form($settings, $settings_by_access_list) {
                 $default_values[$row['variable']] = $row['selected_value'];
                 break;
             case 'custom':
-            	break;
+                break;
         }
 
         switch ($row['variable']) {

+ 138 - 99
main/admin/settings.php

@@ -10,8 +10,6 @@
  * @package chamilo.admin
  */
 
-/* INIT SECTION */
-
 // Language files that need to be included.
 if (isset($_GET['category']) && $_GET['category'] == 'Templates') {
     $language_file = array('admin', 'document');
@@ -45,7 +43,12 @@ $settings_to_avoid = array(
     'example_material_course_creation'  => 'true' // ON by default - now we have this option when  we create a course
 );
 
-$convert_byte_to_mega_list = array('dropbox_max_filesize', 'message_max_upload_filesize', 'default_document_quotum', 'default_group_quotum');
+$convert_byte_to_mega_list = array(
+    'dropbox_max_filesize',
+    'message_max_upload_filesize',
+    'default_document_quotum',
+    'default_group_quotum'
+);
 
 if (isset($_POST['style'])) {
     Display::$preview_style = $_POST['style'];
@@ -68,8 +71,8 @@ if (isset($_GET['delete_watermark'])) {
 }
 
 if (isset($_GET['action']) &&  $_GET['action'] == 'delete_grading') {
-	$id = intval($_GET['id']);
-	api_delete_setting_option($id);
+    $id = intval($_GET['id']);
+    api_delete_setting_option($id);
 }
 
 $form_search = new FormValidator('search_settings', 'get', api_get_self() , null, array('class'=>'well form-inline'));
@@ -119,11 +122,16 @@ function get_settings($category = null) {
             $settings = search_setting($_REQUEST['search_field']);
         }
     }
-    return array('settings' => $settings, 'settings_by_access_list' => $settings_by_access_list);
+    return array(
+        'settings' => $settings,
+        'settings_by_access_list' => $settings_by_access_list
+    );
 }
 
 // Build the form.
-if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search'))) {
+if (!empty($_GET['category']) &&
+    !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search'))
+) {
     $my_category = isset($_GET['category']) ? $_GET['category'] : null;
     $settings_array = get_settings($my_category);
     $settings = $settings_array['settings'];
@@ -139,11 +147,15 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
         $un_mark_all = false;
 
         if (api_is_multiple_url_enabled()) {
-            if (isset($values['buttons_in_action_right']) && isset($values['buttons_in_action_right']['mark_all'])) {
+            if (isset($values['buttons_in_action_right']) &&
+                isset($values['buttons_in_action_right']['mark_all'])
+            ) {
                 $mark_all = true;
             }
 
-            if (isset($values['buttons_in_action_right']) && isset($values['buttons_in_action_right']['unmark_all'])) {
+            if (isset($values['buttons_in_action_right']) &&
+                isset($values['buttons_in_action_right']['unmark_all'])
+            ) {
                 $un_mark_all = true;
             }
         }
@@ -174,7 +186,10 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
                 $settings_array = get_settings($my_category);
                 $settings = $settings_array['settings'];
                 $settings_by_access_list = $settings_array['settings_by_access_list'];
-                $form = generate_settings_form($settings, $settings_by_access_list);
+                $form = generate_settings_form(
+                    $settings,
+                    $settings_by_access_list
+                );
             }
         }
         if (!empty($_FILES['pdf_export_watermark_path'])) {
@@ -182,7 +197,10 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
         }
 
         if (isset($pdf_export_watermark_path) && !empty($pdf_export_watermark_path['name'])) {
-            $pdf_export_watermark_path_result = PDF::upload_watermark($pdf_export_watermark_path['name'], $pdf_export_watermark_path['tmp_name']);
+            $pdf_export_watermark_path_result = PDF::upload_watermark(
+                $pdf_export_watermark_path['name'],
+                $pdf_export_watermark_path['tmp_name']
+            );
             if ($pdf_export_watermark_path_result) {
                 $message['confirmation'][] = get_lang('UplUploadSucceeded');
             } else {
@@ -193,16 +211,15 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
 
         // Set true for allow_message_tool variable if social tool is actived
         foreach ($convert_byte_to_mega_list as $item) {
-			if (isset($values[$item])) {
-				$values[$item]        = round($values[$item]*1024*1024);
-			}
-		}
+            if (isset($values[$item])) {
+                $values[$item]        = round($values[$item]*1024*1024);
+            }
+        }
 
         if (isset($values['allow_social_tool']) && $values['allow_social_tool'] == 'true') {
             $values['allow_message_tool'] = 'true';
         }
 
-
         // The first step is to set all the variables that have type=checkbox of the category
         // to false as the checkbox that is unchecked is not in the $_POST data and can
         // therefore not be set to false.
@@ -225,96 +242,115 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
 
         foreach ($settings as $item) {
             $key = $item['variable'];
-            if (in_array($key, $settings_to_avoid)) { continue; }
-            if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') { continue; }
+            if (in_array($key, $settings_to_avoid)) {
+                continue;
+            }
+            if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') {
+                continue;
+            }
             $key = Database::escape_string($key);
-            $sql = "UPDATE $table_settings_current SET selected_value = 'false' WHERE variable = '".$key."' AND access_url = ".intval($url_id)."  AND type IN ('checkbox', 'radio') ";
+            $sql = "UPDATE $table_settings_current
+                    SET selected_value = 'false'
+                    WHERE variable = '".$key."' AND access_url = ".intval($url_id)."  AND type IN ('checkbox', 'radio') ";
             $res = Database::query($sql);
         }
 
-        /*foreach($settings_to_avoid as $key => $value) {
-            api_set_setting($key, $value, null, null, $_configuration['access_url']);
-        }*/
-
         // Save the settings.
         $keys = array();
 
         foreach ($values as $key => $value) {
-            if (strcmp($key,'MAX_FILE_SIZE')===0) { continue; }
-            if (in_array($key, $settings_to_avoid)) { continue; }
+            if (strcmp($key, 'MAX_FILE_SIZE') === 0) {
+                continue;
+            }
+            if (in_array($key, $settings_to_avoid)) {
+                continue;
+            }
             // Avoid form elements which have nothing to do with settings
-            if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') { continue; }
+            if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') {
+                continue;
+            }
 
             // Treat gradebook values in separate function.
             //if (strpos($key, 'gradebook_score_display_custom_values') === false) {
-                if (!is_array($value)) {
-                    $old_value = api_get_setting($key);
-                    switch ($key) {
-                    	case 'header_extra_content':
-                    		file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/header_extra_content.txt', $value);
-                    		$value = api_get_home_path().'/header_extra_content.txt';
-                    		break;
-                    	case 'footer_extra_content':
-                    		file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/footer_extra_content.txt', $value);
-                    		$value = api_get_home_path().'/footer_extra_content.txt';
-                    		break;
-                        // URL validation for some settings.
-                        case 'InstitutionUrl':
-                        case 'course_validation_terms_and_conditions_url':
-                            $value = trim(Security::remove_XSS($value));
-                            if ($value != '') {
-                                // Here we accept absolute URLs only.
-                                if (strpos($value, '://') === false) {
-                                    $value = 'http://'.$value;
-                                }
-                                if (!api_valid_url($value, true)) {
-                                    // If the new (non-empty) URL value is invalid, then the old URL value stays.
-                                    $value = $old_value;
-                                }
+            if (!is_array($value)) {
+                $old_value = api_get_setting($key);
+                switch ($key) {
+                    case 'header_extra_content':
+                        file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/header_extra_content.txt', $value);
+                        $value = api_get_home_path().'/header_extra_content.txt';
+                        break;
+                    case 'footer_extra_content':
+                        file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/footer_extra_content.txt', $value);
+                        $value = api_get_home_path().'/footer_extra_content.txt';
+                        break;
+                    // URL validation for some settings.
+                    case 'InstitutionUrl':
+                    case 'course_validation_terms_and_conditions_url':
+                        $value = trim(Security::remove_XSS($value));
+                        if ($value != '') {
+                            // Here we accept absolute URLs only.
+                            if (strpos($value, '://') === false) {
+                                $value = 'http://'.$value;
                             }
-                            // If the new URL value is empty, then it will be stored (i.e. the setting will be deleted).
-                            break;
-
-                        // Validation against e-mail address for some settings.
-                        case 'emailAdministrator':
-                            $value = trim(Security::remove_XSS($value));
-                            if ($value != '' && !api_valid_email($value)) {
-                                // If the new (non-empty) e-mail address is invalid, then the old e-mail address stays.
-                                // If the new e-mail address is empty, then it will be stored (i.e. the setting will be deleted).
+                            if (!api_valid_url($value, true)) {
+                                // If the new (non-empty) URL value is invalid, then the old URL value stays.
                                 $value = $old_value;
                             }
-                            break;
-                    }
-                    if ($old_value != $value) $keys[] = $key;
-                    $result = api_set_setting($key, $value, null, null, $url_id);
-                } else {
-                    $sql = "SELECT subkey FROM $table_settings_current WHERE variable = '$key'";
-                    $res = Database::query($sql);
-                    while ($row_subkeys = Database::fetch_array($res)) {
-                        // If subkey is changed:
-                        if ((isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'false') ||
-                            (!isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'true')) {
-                            $keys[] = $key;
-                            break;
                         }
+                        // If the new URL value is empty, then it will be stored (i.e. the setting will be deleted).
+                        break;
+
+                    // Validation against e-mail address for some settings.
+                    case 'emailAdministrator':
+                        $value = trim(Security::remove_XSS($value));
+                        if ($value != '' && !api_valid_email($value)) {
+                            // If the new (non-empty) e-mail address is invalid, then the old e-mail address stays.
+                            // If the new e-mail address is empty, then it will be stored (i.e. the setting will be deleted).
+                            $value = $old_value;
+                        }
+                        break;
+                }
+                if ($old_value != $value) $keys[] = $key;
+                $result = api_set_setting($key, $value, null, null, $url_id);
+            } else {
+                $sql = "SELECT subkey FROM $table_settings_current WHERE variable = '$key'";
+                $res = Database::query($sql);
+                while ($row_subkeys = Database::fetch_array($res)) {
+                    // If subkey is changed:
+                    if ((isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'false') ||
+                        (!isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'true')) {
+                        $keys[] = $key;
+                        break;
                     }
-                    foreach ($value as $subkey => $subvalue) {
-                        $result = api_set_setting($key, 'true', $subkey, null, $url_id);
-                    }
-
                 }
+                foreach ($value as $subkey => $subvalue) {
+                    $result = api_set_setting($key, 'true', $subkey, null, $url_id);
+                }
+            }
         }
 
         // Add event configuration settings category to the system log.
         $user_id = api_get_user_id();
         $category = $_GET['category'];
-        event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
+        event_system(
+            LOG_CONFIGURATION_SETTINGS_CHANGE,
+            LOG_CONFIGURATION_SETTINGS_CATEGORY,
+            $category,
+            api_get_utc_datetime(),
+            $user_id
+        );
 
         // Add event configuration settings variable to the system log.
         if (is_array($keys) && count($keys) > 0) {
             foreach ($keys as $variable) {
                 if (in_array($key, $settings_to_avoid)) { continue; }
-                event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_VARIABLE, $variable, api_get_utc_datetime(), $user_id);
+                event_system(
+                    LOG_CONFIGURATION_SETTINGS_CHANGE,
+                    LOG_CONFIGURATION_SETTINGS_VARIABLE,
+                    $variable,
+                    api_get_utc_datetime(),
+                    $user_id
+                );
             }
         }
     }
@@ -401,7 +437,6 @@ $resultcategories[] = array('category' => 'CAS');
 $resultcategories[] = array('category' => 'Shibboleth');
 $resultcategories[] = array('category' => 'Facebook');
 
-
 foreach ($resultcategories as $row) {
     $url = array();
     $url['url'] = api_get_self()."?category=".$row['category'];
@@ -413,9 +448,7 @@ foreach ($resultcategories as $row) {
 }
 
 echo Display::actions($action_array);
-
 echo '<br />';
-
 echo $form_search_html;
 
 if ($watermark_deleted) {
@@ -451,7 +484,13 @@ if (!empty($_GET['category'])) {
                     // add event to system log
                     $user_id = api_get_user_id();
                     $category = $_GET['category'];
-                    event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
+                    event_system(
+                        LOG_CONFIGURATION_SETTINGS_CHANGE,
+                        LOG_CONFIGURATION_SETTINGS_CATEGORY,
+                        $category,
+                        api_get_utc_datetime(),
+                        $user_id
+                    );
                     Display :: display_confirmation_message(get_lang('DashboardPluginsHaveBeenUpdatedSucesslly'));
                 }
             }
@@ -461,23 +500,23 @@ if (!empty($_GET['category'])) {
                 });
                 </script>';
             echo '<div id="tabs">';
-                echo '<ul>';
-                echo '<li><a href="#tabs-1">'.get_lang('Plugins').'</a></li>';
-                echo '<li><a href="#tabs-2">'.get_lang('DashboardPlugins').'</a></li>';
-                echo '<li><a href="#tabs-3">'.get_lang('ConfigureExtensions').'</a></li>';
-                echo '</ul>';
-
-                echo '<div id="tabs-1">';
-                handle_plugins();
-                echo '</div>';
-
-                echo '<div id="tabs-2">';
-                DashboardManager::handle_dashboard_plugins();
-                echo '</div>';
-
-                echo '<div id="tabs-3">';
-                handle_extensions();
-                echo '</div>';
+            echo '<ul>';
+            echo '<li><a href="#tabs-1">'.get_lang('Plugins').'</a></li>';
+            echo '<li><a href="#tabs-2">'.get_lang('DashboardPlugins').'</a></li>';
+            echo '<li><a href="#tabs-3">'.get_lang('ConfigureExtensions').'</a></li>';
+            echo '</ul>';
+
+            echo '<div id="tabs-1">';
+            handle_plugins();
+            echo '</div>';
+
+            echo '<div id="tabs-2">';
+            DashboardManager::handle_dashboard_plugins();
+            echo '</div>';
+
+            echo '<div id="tabs-3">';
+            handle_extensions();
+            echo '</div>';
             echo '</div>';
             break;
         case 'Stylesheets':

+ 40 - 18
main/attendance/attendance_controller.php

@@ -544,33 +544,55 @@ class AttendanceController
     }
 
     /**
-     * Gets attendace base in the table:
+     * Gets attendance base in the table:
      * TABLE_STATISTIC_TRACK_E_COURSE_ACCESS
+     * @param bool $showForm
      * @throws ViewException
      */
-    public function calendarLogins()
+    public function getAttendanceBaseInLogin($showForm = false, $exportToPdf = true)
     {
-        $form = new FormValidator(
-            'search',
-            'post',
-            api_get_self().'?'.api_get_cidreq().'&action=calendar_logins'
-        );
-        $form->addDateRangePicker('range', get_lang('Range'));
-        $form->add_button('submit', get_lang('submit'));
         $table = null;
+        $formToDisplay = null;
+        $startDate = null;
+        $endDate = null;
+
+        $sessionId = api_get_session_id();
+        if ($showForm) {
+            $form = new FormValidator(
+                'search',
+                'post',
+                api_get_self() . '?' . api_get_cidreq(
+                ) . '&action=calendar_logins'
+            );
+            $form->addDateRangePicker('range', get_lang('Range'));
+            $form->add_button('submit', get_lang('submit'));
+
+            if ($form->validate()) {
+                $values = $form->getSubmitValues();
+
+                $startDate = api_get_utc_datetime($values['range_start']);
+                $endDate = api_get_utc_datetime($values['range_end']);
+            }
+            $formToDisplay = $form->return_form();
+        } else {
+           if (!empty($sessionId)) {
+               $sessionInfo = api_get_session_info($sessionId);
+               $startDate = $sessionInfo['date_start'];
+               $endDate = $sessionInfo['date_end'];
+           }
+        }
 
-        if ($form->validate()) {
-            $values = $form->getSubmitValues();
-
-            $startDate = api_get_utc_datetime($values['range_start']);
-            $endDate = api_get_utc_datetime($values['range_end']);
+        $attendance = new Attendance();
 
-            $attendance = new Attendance();
-            $table = $attendance->getAttendanceLogins($startDate, $endDate);
+        if ($exportToPdf) {
+            $result = $attendance->exportAttendanceLogin($startDate, $endDate);
+            if (empty($result)) {
+                api_not_allowed(true, get_lang('NoDataAvailable'));
+            }
         }
-
+        $table = $attendance->getAttendanceLoginTable($startDate, $endDate);
         $data = array(
-            'form' => $form->return_form(),
+            'form' => $formToDisplay,
             'table' => $table
         );
         $this->view->set_data($data);

+ 2 - 2
main/attendance/attendance_list.php

@@ -19,8 +19,8 @@ if (api_is_allowed_to_edit(null, true)) {
     echo '<a href="index.php?'.api_get_cidreq().$param_gradebook.'&action=attendance_add">'.
         Display::return_icon('new_attendance_list.png',get_lang('CreateANewAttendance'),'',ICON_SIZE_MEDIUM).'</a>';
 
-    echo '<a href="index.php?'.api_get_cidreq().$param_gradebook.'&action=calendar_logins">'.
-        Display::return_icon('attendance_list.png',get_lang('Logins'),'',ICON_SIZE_MEDIUM).'</a>';
+    /*echo '<a href="index.php?'.api_get_cidreq().$param_gradebook.'&action=calendar_logins">'.
+        Display::return_icon('attendance_list.png',get_lang('Logins'),'',ICON_SIZE_MEDIUM).'</a>';*/
 
     echo '</div>';
 }

+ 15 - 15
main/attendance/index.php

@@ -92,7 +92,7 @@ if (isset($_GET['calendar_id'])) {
 $attendance = new Attendance();
 
 // attendance controller object
-$attendance_controller = new AttendanceController();
+$attendanceController = new AttendanceController();
 $attendance_data = array();
 // get attendance data
 if (!empty($attendance_id)) {
@@ -235,53 +235,53 @@ if ($action == 'calendar_add') {
 
 // delete selected attendance
 if (isset($_POST['action']) && $_POST['action'] == 'attendance_delete_select') {
-    $attendance_controller->attendance_delete($_POST['id']);
+    $attendanceController->attendance_delete($_POST['id']);
 }
 // distpacher actions to controller
 switch ($action) {
     case 'attendance_list':
-        $attendance_controller->attendance_list();
+        $attendanceController->attendance_list();
         break;
     case 'attendance_add':
         if (api_is_allowed_to_edit(null, true)) {
-            $attendance_controller->attendance_add();
+            $attendanceController->attendance_add();
         } else {
             api_not_allowed();
         }
         break;
     case 'attendance_edit' :
         if (api_is_allowed_to_edit(null, true)) {
-            $attendance_controller->attendance_edit($attendance_id);
+            $attendanceController->attendance_edit($attendance_id);
         } else {
             api_not_allowed();
         }
         break;
     case 'attendance_delete' :
         if (api_is_allowed_to_edit(null, true)) {
-            $attendance_controller->attendance_delete($attendance_id);
+            $attendanceController->attendance_delete($attendance_id);
         } else {
             api_not_allowed();
         }
         break;
     case 'attendance_restore':
         if (api_is_allowed_to_edit(null, true)) {
-            $attendance_controller->attendance_restore($attendance_id);
+            $attendanceController->attendance_restore($attendance_id);
         } else {
             api_not_allowed();
         }
         break;
     case 'attendance_sheet_list':
-        $attendance_controller->attendance_sheet($action, $attendance_id, $student_id, true);
+        $attendanceController->attendance_sheet($action, $attendance_id, $student_id, true);
         break;
     case 'attendance_sheet_list_no_edit':
-        $attendance_controller->attendance_sheet($action, $attendance_id, $student_id, false);
+        $attendanceController->attendance_sheet($action, $attendance_id, $student_id, false);
         break;
     case 'attendance_sheet_export_to_pdf':
-        $attendance_controller->attendance_sheet_export_to_pdf($action, $attendance_id, $student_id, $course_id);
+        $attendanceController->attendance_sheet_export_to_pdf($action, $attendance_id, $student_id, $course_id);
         break;
     case 'attendance_sheet_add' :
         if (api_is_allowed_to_edit(null, true)) {
-            $attendance_controller->attendance_sheet($action, $attendance_id);
+            $attendanceController->attendance_sheet($action, $attendance_id);
         } else {
             api_not_allowed();
         }
@@ -289,7 +289,7 @@ switch ($action) {
     case 'lock_attendance' :
     case 'unlock_attendance' :
         if (api_is_allowed_to_edit(null, true)) {
-            $attendance_controller->lock_attendance($action, $attendance_id);
+            $attendanceController->lock_attendance($action, $attendance_id);
         } else {
             api_not_allowed();
         }
@@ -302,13 +302,13 @@ switch ($action) {
             api_not_allowed();
         }
     case 'calendar_list' :
-        $attendance_controller->attendance_calendar($action, $attendance_id, $calendar_id);
+        $attendanceController->attendance_calendar($action, $attendance_id, $calendar_id);
         break;
     case 'calendar_logins':
         if (api_is_allowed_to_edit(null, true)) {
-            $attendance_controller->calendarLogins();
+            $attendanceController->getAttendanceBaseInLogin(false, true);
         }
         break;
     default :
-        $attendance_controller->attendance_list();
+        $attendanceController->attendance_list();
 }

+ 10 - 5
main/chat/chat_message.php

@@ -77,13 +77,19 @@ if ($sent) {
         <div class="tabbable">
             <ul class="nav nav-tabs">
                 <li class="active">
-                    <a href="#tab1" data-toggle="tab"><?php echo get_lang('Write'); ?></a>
+                    <a href="#tab1" data-toggle="tab">
+                        <?php echo get_lang('Write'); ?>
+                    </a>
                 </li>
                 <li>
-                    <a href="#tab2" id="preview" data-toggle="tab"><?php echo get_lang('Preview'); ?></a>
+                    <a href="#tab2" id="preview" data-toggle="tab">
+                        <?php echo get_lang('Preview'); ?>
+                    </a>
                 </li>
                 <li>
-                    <a href="#tab3" id="emojis" data-toggle="tab"><?php echo get_lang('Emojis'); ?></a>
+                    <a href="#tab3" id="emojis" data-toggle="tab">
+                        <?php echo Emojione\Emojione::toImage(':smile:'); ?>
+                    </a>
                 </li>
             </ul>
             <div class="tab-content">
@@ -92,8 +98,7 @@ if ($sent) {
                         <tr>
                             <td width="320" valign="middle">
                                 <?php
-                                $talkboxsize=(api_get_course_setting('allow_open_chat_window')) ? 'width: 350px; height: 80px' : 'width: 450px; height: 35px';
-                                //onkeydown="send_message(event);"
+                                $talkboxsize = (api_get_course_setting('allow_open_chat_window')) ? 'width: 350px; height: 80px' : 'width: 450px; height: 35px';
                                 ?>
                                 <textarea id="message" class="message-text" name="message" style=" <?php echo $talkboxsize; ?>"></textarea>
                             </td>

+ 152 - 34
main/inc/lib/attendance.lib.php

@@ -272,12 +272,12 @@ class Attendance
 		$value_calification  = 0;
 		$weight_calification =	floatval($this->attendance_weight);
 		$sql = "INSERT INTO $tbl_attendance SET
-					c_id =  $course_id,
-					name ='".Database::escape_string($this->name)."',
-					description = '".Database::escape_string($this->description)."',
-					attendance_qualify_title = '$title_gradebook',
-					attendance_weight = '$weight_calification',
-					session_id = '$session_id'";
+				c_id =  $course_id,
+				name ='".Database::escape_string($this->name)."',
+				description = '".Database::escape_string($this->description)."',
+				attendance_qualify_title = '$title_gradebook',
+				attendance_weight = '$weight_calification',
+				session_id = '$session_id'";
 		Database::query($sql);
 		$affected_rows = Database::affected_rows();
 		$last_id = 0;
@@ -383,7 +383,8 @@ class Attendance
 		if (is_array($attendance_id)) {
 			foreach ($attendance_id as $id) {
 				$id	= intval($id);
-				$sql = "UPDATE $tbl_attendance SET active = 1 WHERE c_id = $course_id AND id = '$id'";
+				$sql = "UPDATE $tbl_attendance SET active = 1
+						WHERE c_id = $course_id AND id = '$id'";
 				Database::query($sql);
 				$affected_rows = Database::affected_rows();
 				if (!empty($affected_rows)) {
@@ -393,7 +394,8 @@ class Attendance
 			}
 		} else  {
 			$attendance_id	= intval($attendance_id);
-			$sql = "UPDATE $tbl_attendance SET active = 1 WHERE c_id = $course_id AND id = '$attendance_id'";
+			$sql = "UPDATE $tbl_attendance SET active = 1
+					WHERE c_id = $course_id AND id = '$attendance_id'";
 			Database::query($sql);
 			$affected_rows = Database::affected_rows();
 			if (!empty($affected_rows)) {
@@ -419,7 +421,8 @@ class Attendance
 		if (is_array($attendance_id)) {
 			foreach ($attendance_id as $id) {
 				$id	= intval($id);
-				$sql = "UPDATE $tbl_attendance SET active = 0 WHERE c_id = $course_id AND id = '$id'";
+				$sql = "UPDATE $tbl_attendance SET active = 0
+						WHERE c_id = $course_id AND id = '$id'";
 				Database::query($sql);
 				$affected_rows = Database::affected_rows();
 				if (!empty($affected_rows)) {
@@ -429,7 +432,8 @@ class Attendance
 			}
 		} else  {
 			$attendance_id	= intval($attendance_id);
-			$sql = "UPDATE $tbl_attendance SET active = 0 WHERE c_id = $course_id AND id = '$attendance_id'";
+			$sql = "UPDATE $tbl_attendance SET active = 0
+					WHERE c_id = $course_id AND id = '$attendance_id'";
 			Database::query($sql);
 			$affected_rows = Database::affected_rows();
 			if (!empty($affected_rows)) {
@@ -685,13 +689,18 @@ class Attendance
 				if (count($calendar_ids) > 0) {
 					$sql = "SELECT count(presence) as count_presences
 							FROM $tbl_attendance_sheet
-					        WHERE c_id = $course_id AND user_id = '$uid' AND attendance_calendar_id IN(".implode(',',$calendar_ids).") AND presence = 1";
+					        WHERE
+					        	c_id = $course_id AND
+					        	user_id = '$uid' AND
+					        	attendance_calendar_id IN(".implode(',',$calendar_ids).") AND
+					        	presence = 1";
 					$rs_count  = Database::query($sql);
 					$row_count = Database::fetch_array($rs_count);
 					$count_presences = $row_count['count_presences'];
 				}
 				// save results
-				$sql = "SELECT id FROM $tbl_attendance_result WHERE c_id = $course_id AND user_id='$uid' AND attendance_id='$attendance_id'";
+				$sql = "SELECT id FROM $tbl_attendance_result
+						WHERE c_id = $course_id AND user_id='$uid' AND attendance_id='$attendance_id'";
 				$rs_check_result = Database::query($sql);
 				if (Database::num_rows($rs_check_result) > 0) {
 					// update result
@@ -702,10 +711,10 @@ class Attendance
 				} else {
 					// insert new result
 					$sql = "INSERT INTO $tbl_attendance_result SET
-								c_id = $course_id ,
-								user_id			= '$uid',
-								attendance_id 	= '$attendance_id',
-								score			= '$count_presences'";
+							c_id = $course_id ,
+							user_id			= '$uid',
+							attendance_id 	= '$attendance_id',
+							score			= '$count_presences'";
 					Database::query($sql);
 				}
 			}
@@ -746,8 +755,8 @@ class Attendance
 		}
 
 		// save data
-		$ins = "INSERT INTO $tbl_attendance_sheet_log(c_id, attendance_id, lastedit_date, lastedit_type, lastedit_user_id, calendar_date_value)
-                VALUES($course_id, $attendance_id, '$lastedit_date', '$lastedit_type', $lastedit_user_id, '$calendar_date_value')";
+		$ins = "INSERT INTO $tbl_attendance_sheet_log (c_id, attendance_id, lastedit_date, lastedit_type, lastedit_user_id, calendar_date_value)
+                VALUES ($course_id, $attendance_id, '$lastedit_date', '$lastedit_type', $lastedit_user_id, '$calendar_date_value')";
 
 		Database::query($ins);
 
@@ -839,8 +848,12 @@ class Attendance
 			foreach ($attendances_by_course as $attendance) {
 				// get total faults and total weight
 				$total_done_attendance 	= $attendance['attendance_qualify_max'];
-				$sql = "SELECT score FROM $tbl_attendance_result
-                        WHERE c_id = $course_id AND user_id = $user_id AND attendance_id = ".$attendance['id'];
+				$sql = "SELECT score
+						FROM $tbl_attendance_result
+                        WHERE
+                        	c_id = $course_id AND
+                        	user_id = $user_id AND
+                        	attendance_id = ".$attendance['id'];
 				$rs = Database::query($sql);
 				$score = 0;
 				if (Database::num_rows($rs) > 0) {
@@ -884,7 +897,10 @@ class Attendance
 			// Get total faults and total weight
 			$total_done_attendance 	= $attendance['attendance_qualify_max'];
 			$sql = "SELECT score FROM $tbl_attendance_result
-					WHERE c_id = {$course_info['real_id']} AND user_id=$user_id AND attendance_id=".$attendance['id'];
+					WHERE
+						c_id = {$course_info['real_id']} AND
+						user_id = $user_id AND
+						attendance_id=".$attendance['id'];
 			$rs = Database::query($sql);
 			$score = 0;
 			if (Database::num_rows($rs) > 0) {
@@ -957,7 +973,7 @@ class Attendance
 							att.c_id = $course_id AND
 							cal.c_id =  $course_id AND
 							att.user_id = '$user_id' AND
-							att.attendance_calendar_id IN(".implode(',',$calendar_ids).")
+							att.attendance_calendar_id IN (".implode(',',$calendar_ids).")
                         ORDER BY date_time";
 				$res = Database::query($sql);
 				if (Database::num_rows($res) > 0) {
@@ -1014,7 +1030,7 @@ class Attendance
 					attendance_id = '$attendance_id' AND
 					done_attendance = 0
 				ORDER BY date_time
-				limit 1";
+				LIMIT 1";
 		$rs = Database::query($sql);
 		$next_calendar_datetime = 0;
 		if (Database::num_rows($rs) > 0) {
@@ -1331,10 +1347,14 @@ class Attendance
 		$course_id = api_get_course_int_id();
 		// check if datetime already exists inside the table
 		$sql = "SELECT id FROM $tbl_attendance_calendar
-		        WHERE c_id = $course_id AND date_time = '".Database::escape_string($this->date_time)."' AND attendance_id = '$attendance_id'";
+		        WHERE
+		        	c_id = $course_id AND
+		        	date_time = '".Database::escape_string($this->date_time)."' AND
+		        	attendance_id = '$attendance_id'";
 		$rs = Database::query($sql);
 		if (Database::num_rows($rs) == 0) {
-			$sql = "UPDATE $tbl_attendance_calendar SET date_time='".Database::escape_string($this->date_time)."'
+			$sql = "UPDATE $tbl_attendance_calendar
+					SET date_time='".Database::escape_string($this->date_time)."'
 					WHERE c_id = $course_id AND id = '".intval($calendar_id)."'";
 			Database::query($sql);
 			$affected_rows = Database::affected_rows();
@@ -1361,7 +1381,7 @@ class Attendance
 	{
 		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
 		$tbl_attendance_sheet 	 = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
-		$session_id = api_get_session_id();
+
 		$attendance_id = intval($attendance_id);
 		// get all registered users inside current course
 		$users = $this->get_users_rel_course();
@@ -1464,22 +1484,22 @@ class Attendance
 		return $this->date_time;
 	}
 
-	public function get_name($name)
+	public function get_name()
 	{
 		return $this->name;
 	}
 
-	public function get_description($description)
+	public function get_description()
 	{
 		return $this->description;
 	}
 
-	public function get_attendance_qualify_title($attendance_qualify_title)
+	public function get_attendance_qualify_title()
 	{
 		return $this->attendance_qualify_title;
 	}
 
-	public function get_attendance_weight($attendance_weight)
+	public function get_attendance_weight()
 	{
 		return $this->attendance_weight;
 	}
@@ -1488,10 +1508,16 @@ class Attendance
 	 * @param string $startDate in UTC time
 	 * @param string $endDate in UTC time
 	 *
-	 * @return string
+	 * @return array
 	 */
-	public function getAttendanceLogins($startDate, $endDate)
+	public function getAttendanceLogin($startDate, $endDate)
 	{
+		if (empty($startDate) || $startDate == '0000-00-00' ||
+			empty($endDate) || $endDate == '0000-00-00'
+		) {
+			return false;
+		}
+
 		$sessionId = api_get_session_id();
 		$courseCode  = api_get_course_id();
 		if (!empty($sessionId)) {
@@ -1499,14 +1525,16 @@ class Attendance
 				$courseCode,
 				$sessionId,
 				'',
-				'lastname'
+				'lastname',
+				0
 			);
 		} else {
 			$users = CourseManager:: get_user_list_from_course_code(
 				$courseCode,
 				0,
 				'',
-				'lastname'
+				'lastname',
+				STUDENT
 			);
 		}
 
@@ -1544,6 +1572,33 @@ class Attendance
 			}
 		}
 
+		return array(
+			'users' => $users,
+			'dateList' => $dateList,
+			'headers' => $headers,
+			'results' => $results
+		);
+	}
+
+	/**
+	 * @param string $startDate in UTC time
+	 * @param string $endDate in UTC time
+	 *
+	 * @return string
+	 */
+	public function getAttendanceLoginTable($startDate, $endDate)
+	{
+		$data = $this->getAttendanceLogin($startDate, $endDate);
+
+		if (!$data) {
+			return null;
+		}
+
+		$headers = $data['headers'];
+		$dateList = $data['dateList'];
+		$users = $data['users'];
+		$results = $data['results'];
+
 		$table = new HTML_Table(array('class' => 'data_table'));
 		$row = 0;
 		$column = 0;
@@ -1580,4 +1635,67 @@ class Attendance
 
 		return $table->toHtml();
 	}
+
+	/**
+	 * @param string $startDate in UTC time
+	 * @param string $endDate in UTC time
+	 *
+	 * @return string
+	 */
+	public function exportAttendanceLogin($startDate, $endDate)
+	{
+		$data = $this->getAttendanceLogin($startDate, $endDate);
+
+		if (!$data) {
+			return null;
+		}
+		$users = $data['users'];
+		$results = $data['results'];
+
+		$table = new HTML_Table(array('class' => 'data_table'));
+
+		$table->setHeaderContents(0, 0, get_lang('User'));
+		$table->setHeaderContents(0, 1, get_lang('Date'));
+
+		$row = 1;
+		foreach ($users as $user) {
+			$table->setCellContents(
+				$row,
+				0,
+				$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
+			);
+			$row++;
+		}
+		$table->setColAttributes(0, array('style' => 'width:28%'));
+
+		$row = 1;
+		foreach ($users as $user) {
+			if (isset($results[$user['user_id']]) &&
+				!empty($results[$user['user_id']])
+			) {
+				$dates = implode(', ', array_keys($results[$user['user_id']]));
+				$table->setCellContents($row, 1, $dates);
+			}
+			$row++;
+		}
+
+		//$tableToString = null;
+
+		//$sessionInfo = api_get_session_info(api_get_session_id());
+		//if (!empty($sessionInfo)) {
+		/*$tableToString .= '<strong>'.get_lang('PeriodToDisplay').'</strong>: '.
+			sprintf(get_lang('FromDateXToDateY'), $startDate, $endDate);*/
+		//}
+
+		$tableToString = $table->toHtml();
+
+		$params = array(
+			'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(),
+			'pdf_title' => get_lang('Attendance'),
+			'course_code' => api_get_course_id(),
+			'show_real_course_teachers' => true
+		);
+		$pdf = new PDF('A4', null, $params);
+		$pdf->html_to_pdf_with_template($tableToString);
+	}
 }

+ 39 - 17
main/inc/lib/course.lib.php

@@ -3920,7 +3920,8 @@ class CourseManager
      * @param string Original field name
      * @return int Course id
      */
-    public static function get_course_id_from_original_id($original_course_id_value, $original_course_id_name) {
+    public static function get_course_id_from_original_id($original_course_id_value, $original_course_id_name)
+    {
         $t_cfv = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
         $table_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD);
         $sql_course = "SELECT course_code FROM $table_field cf INNER JOIN $t_cfv cfv ON cfv.field_id=cf.id WHERE field_variable='$original_course_id_name' AND field_value='$original_course_id_value'";
@@ -4149,9 +4150,16 @@ class CourseManager
             if (isset($course_info['user_course_cat'])) {
                  $user_course_category = $course_info['user_course_cat'];
             }
-            $output = array ($user_course_category, $html, $course_info['id_session'], $session, 'active' => $active, 'session_category_id' => $session_category_id);
+            $output = array(
+                $user_course_category,
+                $html,
+                $course_info['id_session'],
+                $session,
+                'active' => $active,
+                'session_category_id' => $session_category_id
+            );
         } else {
-            $output = array ($course_info['user_course_cat'], $html);
+            $output = array($course_info['user_course_cat'], $html);
         }
         return $output;
     }
@@ -4164,7 +4172,8 @@ class CourseManager
      * @param     int        destination session id
      * @return  bool
      */
-    public static function copy_course($source_course_code, $source_session_id, $destination_course_code, $destination_session_id, $params = array()) {
+    public static function copy_course($source_course_code, $source_session_id, $destination_course_code, $destination_session_id, $params = array())
+    {
         require_once api_get_path(SYS_CODE_PATH).'coursecopy/classes/CourseBuilder.class.php';
         require_once api_get_path(SYS_CODE_PATH).'coursecopy/classes/CourseRestorer.class.php';
         require_once api_get_path(SYS_CODE_PATH).'coursecopy/classes/CourseSelectForm.class.php';
@@ -4182,7 +4191,6 @@ class CourseManager
         return false;
     }
 
-
     /**
      * A simpler version of the copy_course, the function creates an empty course with an autogenerated course code
      *
@@ -4292,8 +4300,6 @@ class CourseManager
             }
             return false;
         }
-
-        return false;
     }
 
     /**
@@ -4414,9 +4420,9 @@ class CourseManager
             $result['user_vote'] = self::get_user_course_vote(api_get_user_id(), $course_id, $session_id,$url_id);
         }
 
-        $result['point_average']        = $point_average_in_percentage;
-        $result['point_average_star']   = $point_average_in_star;
-        $result['users_who_voted']        = $users_who_voted;
+        $result['point_average'] = $point_average_in_percentage;
+        $result['point_average_star'] = $point_average_in_star;
+        $result['users_who_voted'] = $users_who_voted;
 
         return $result;
     }
@@ -4438,7 +4444,7 @@ class CourseManager
         $add_user = true
     ) {
         // Course catalog stats modifications see #4191
-        $table_course_ranking       = Database::get_main_table(TABLE_STATISTIC_TRACK_COURSE_RANKING);
+        $table_course_ranking = Database::get_main_table(TABLE_STATISTIC_TRACK_COURSE_RANKING);
 
         $now = api_get_utc_datetime();
 
@@ -4536,10 +4542,15 @@ class CourseManager
 
         $action_done = 'nothing';
 
-        $result = Database::select('id, vote', $table_user_course_vote, array('where' => array('user_id = ? AND c_id = ? AND session_id = ? AND url_id = ?' => $params)), 'first');
+        $result = Database::select(
+            'id, vote',
+            $table_user_course_vote,
+            array('where' => array('user_id = ? AND c_id = ? AND session_id = ? AND url_id = ?' => $params)),
+            'first'
+        );
 
         if (empty($result)) {
-            $result = Database::insert($table_user_course_vote, $params);
+            Database::insert($table_user_course_vote, $params);
             $points_to_add = $vote;
             $add_user = true;
             $action_done = 'added';
@@ -4548,13 +4559,24 @@ class CourseManager
             $points_to_add = $vote - $result['vote'];
             $add_user = false;
 
-            $result = Database::update($table_user_course_vote, $my_params, array('user_id = ? AND c_id = ? AND session_id = ? AND url_id = ?' => $params));
+            Database::update(
+                $table_user_course_vote,
+                $my_params,
+                array('user_id = ? AND c_id = ? AND session_id = ? AND url_id = ?' => $params)
+            );
             $action_done = 'updated';
         }
 
-        //Current points
+        // Current points
         if (!empty($points_to_add)) {
-            self::update_course_ranking($course_id, $session_id, $url_id, $points_to_add, false, $add_user);
+            self::update_course_ranking(
+                $course_id,
+                $session_id,
+                $url_id,
+                $points_to_add,
+                false,
+                $add_user
+            );
         }
         return $action_done;
     }
@@ -5157,7 +5179,7 @@ class CourseManager
 
         $sql = "SELECT * FROM $table
                 WHERE
-                    course_code = $courseCode AND
+                    course_code = '$courseCode' AND
                     session_id = $sessionId AND
                     login_course_date BETWEEN '$startDate' AND '$endDate'
                 ";

+ 76 - 78
main/inc/lib/dashboard.lib.php

@@ -19,24 +19,24 @@ class DashboardManager
 	 * contructor
 	 */
 	public function __construct()
-    {
-    }
+	{
+	}
 
-    /**
+	/**
 	 * This function allows easy activating and inactivating of dashboard plugins
 	 * @return void
-	*/
+	 */
 	public static function handle_dashboard_plugins()
-    {
-        $token = Security::get_existing_token();
-        $tokenCondition = '&amp;sec_token='.$token;
+	{
+		$token = Security::get_existing_token();
+		$tokenCondition = '&amp;sec_token='.$token;
 
 		/* We scan the plugin directory. Each folder is a potential plugin. */
 		$dashboard_pluginpath = api_get_path(SYS_PLUGIN_PATH).'dashboard/';
 		$possibleplugins = self::get_posible_dashboard_plugins_path();
 
 		$table_cols = array('name', 'version', 'description');
-        echo Display::page_subheader(get_lang('DashboardPlugins'));
+		echo Display::page_subheader(get_lang('DashboardPlugins'));
 		echo '<form name="plugins" method="post" action="'.api_get_self().'?category='.Security::remove_XSS($_GET['category']).$tokenCondition.'">';
 		echo '<table class="data_table">';
 		echo '<tr>';
@@ -51,28 +51,30 @@ class DashboardManager
 		// We display all the possible enabled or disabled plugins
 		foreach ($possibleplugins as $testplugin) {
 			$plugin_info_file = $dashboard_pluginpath.$testplugin."/$testplugin.info";
-			$plugin_info = array();
 			if (file_exists($plugin_info_file) && is_readable($plugin_info_file)) {
 				$plugin_info = parse_info_file($plugin_info_file);
 
-    			// change index to lower case
-    			$plugin_info = array_change_key_case($plugin_info);
-
-    			echo '<tr>';
-    				self::display_dashboard_plugin_checkboxes($testplugin);
-    				for ($i = 0 ; $i < count($table_cols); $i++) {
-    					if (isset($plugin_info[strtolower($table_cols[$i])])) {
-    			    		echo '<td>';
-    			    			echo $plugin_info[$table_cols[$i]];
-    			    		echo '</td>';
-    			    	} else {
-    			    		echo '<td></td>';
-    			    	}
-    				}
-    			echo '</tr>';
-            } else {
-                echo Display::tag('tr',  Display::tag('td', get_lang('CheckFilePermissions').' '.Security::remove_XSS($plugin_info_file) , array('colspan'=>'3')));
-            }
+				// change index to lower case
+				$plugin_info = array_change_key_case($plugin_info);
+
+				echo '<tr>';
+				self::display_dashboard_plugin_checkboxes($testplugin);
+				for ($i = 0 ; $i < count($table_cols); $i++) {
+					if (isset($plugin_info[strtolower($table_cols[$i])])) {
+						echo '<td>';
+						echo $plugin_info[$table_cols[$i]];
+						echo '</td>';
+					} else {
+						echo '<td></td>';
+					}
+				}
+				echo '</tr>';
+			} else {
+				echo Display::tag(
+					'tr',
+					Display::tag('td', get_lang('CheckFilePermissions').' '.Security::remove_XSS($plugin_info_file) , array('colspan'=>'3'))
+				);
+			}
 		}
 
 		// display all disabled block data
@@ -84,17 +86,17 @@ class DashboardManager
 					if (isset($disabled_block[strtolower($table_cols[$j])])) {
 						if ($j == 2) {
 							echo '<td>';
-			    				echo '<font color="#aaa">'.$disabled_block[$table_cols[$j]].'</font><br />';
-			    				echo '<font color="red">'.get_lang('ThisPluginHasbeenDeletedFromDashboardPluginDirectory').'</font>';
-			    			echo '</td>';
+							echo '<font color="#aaa">'.$disabled_block[$table_cols[$j]].'</font><br />';
+							echo '<font color="red">'.get_lang('ThisPluginHasbeenDeletedFromDashboardPluginDirectory').'</font>';
+							echo '</td>';
 						} else {
 							echo '<td>';
-			    				echo '<font color="#aaa">'.$disabled_block[$table_cols[$j]].'</font>';
-			    			echo '</td>';
+							echo '<font color="#aaa">'.$disabled_block[$table_cols[$j]].'</font>';
+							echo '</td>';
 						}
-			    	} else {
-			    		echo '<td>&nbsp;</td>';
-			    	}
+					} else {
+						echo '<td>&nbsp;</td>';
+					}
 				}
 				echo '</tr>';
 			}
@@ -113,9 +115,9 @@ class DashboardManager
 	public static function display_dashboard_plugin_checkboxes($plugin_path) {
 
 		$tbl_block = Database::get_main_table(TABLE_MAIN_BLOCK);
-		$plugin_path = Database::escape_string($plugin_path);
 
-		$sql = "SELECT * FROM $tbl_block WHERE path = '$plugin_path' AND active = 1";
+		$sql = "SELECT * FROM $tbl_block
+				WHERE path = '".Database::escape_string($plugin_path)."' AND active = 1";
 		$rs  = Database::query($sql);
 
 		$checked = '';
@@ -124,18 +126,18 @@ class DashboardManager
 		}
 
 		echo "<td align=\"center\">";
-			echo '<input type="checkbox" name="'.$plugin_path.'" value="true" '.$checked.'/>';
+		echo '<input type="checkbox" name="'.$plugin_path.'" value="true" '.$checked.'/>';
 		echo "</td>";
 	}
 
 	/**
-	 * This function allows easy activating and inactivating of plugins and save them inside db
-	 * @param array dashboard plugin paths
+	 * This function allows easy activating and inactivating
+	 * of plugins and save them inside db
+	 * @param array $plugin_paths dashboard plugin paths
 	 * return int affected rows
-	*/
+	 */
 	public static function store_dashboard_plugins($plugin_paths)
 	{
-
 		$tbl_block = Database :: get_main_table(TABLE_MAIN_BLOCK);
 		$affected_rows = 0;
 
@@ -145,8 +147,8 @@ class DashboardManager
 
 		if (count($possibleplugins) > 0) {
 
-			$selected_plugins = array_intersect(array_keys($plugin_paths),$possibleplugins);
-			$not_selected_plugins = array_diff($possibleplugins,array_keys($plugin_paths));
+			$selected_plugins = array_intersect(array_keys($plugin_paths), $possibleplugins);
+			$not_selected_plugins = array_diff($possibleplugins, array_keys($plugin_paths));
 
 			// get blocks id from not selected path
 			$not_selected_blocks_id = array();
@@ -183,7 +185,6 @@ class DashboardManager
 
 				// update extra user blocks data
 				$upd_extra_field = self::store_user_blocks($user_id, $user_blocks_id, $columns);
-
 			}
 
 			// clean from block data
@@ -196,7 +197,6 @@ class DashboardManager
 				}
 			}
 
-
 			// store selected plugins
 			foreach ($selected_plugins as $testplugin) {
 				$selected_path = Database::escape_string($testplugin);
@@ -254,18 +254,16 @@ class DashboardManager
 
 		// get all plugins path inside plugin directory
 		/* We scan the plugin directory. Each folder is a potential plugin. */
-		$possibleplugins = array();
+		$possiblePlugins = array();
 		$dashboard_pluginpath = api_get_path(SYS_PLUGIN_PATH).'dashboard/';
 		$handle = @opendir($dashboard_pluginpath);
-		while (false !== ($file = readdir($handle)))
-		{
-			if ($file <> '.' AND $file <> '..' AND is_dir($dashboard_pluginpath.$file))
-			{
-				$possibleplugins[] = $file;
+		while (false !== ($file = readdir($handle))) {
+			if ($file <> '.' AND $file <> '..' AND is_dir($dashboard_pluginpath.$file)) {
+				$possiblePlugins[] = $file;
 			}
 		}
 		@closedir($handle);
-		return $possibleplugins;
+		return $possiblePlugins;
 	}
 
 	/**
@@ -284,9 +282,9 @@ class DashboardManager
 			while ($row = Database::fetch_array($rs)) {
 				$path = $row['path'];
 				if (!in_array($row['path'],$possibleplugins)) {
-						$active = 0;
+					$active = 0;
 				} else {
-						$active = 1;
+					$active = 1;
 				}
 				// update active
 				$upd = "UPDATE $tbl_block SET active = '$active' WHERE path = '".$row['path']."'";
@@ -371,28 +369,28 @@ class DashboardManager
 				$dashboard_plugin_path = api_get_path(SYS_PLUGIN_PATH).'dashboard/'.$path.'/';
 				require_once $dashboard_plugin_path.$filename_controller;
 				if (class_exists($controller_class)) {
-				    $obj_block = new $controller_class($user_id);
-
-    				// check if user is allowed to see the block
-    				if (method_exists($obj_block, 'is_block_visible_for_user')) {
-    					$is_block_visible_for_user = $obj_block->is_block_visible_for_user($user_id);
-    					if (!$is_block_visible_for_user) continue;
-    				}
-
-    				echo '<tr>';
-                    // checkboxes
-                    self::display_user_dashboard_list_checkboxes($user_id, $block['id']);
-                    echo '<td>'.$block['name'].'</td>';
-                    echo '<td>'.$block['description'].'</td>';
-                    echo '<td><center>
+					$obj_block = new $controller_class($user_id);
+
+					// check if user is allowed to see the block
+					if (method_exists($obj_block, 'is_block_visible_for_user')) {
+						$is_block_visible_for_user = $obj_block->is_block_visible_for_user($user_id);
+						if (!$is_block_visible_for_user) continue;
+					}
+
+					echo '<tr>';
+					// checkboxes
+					self::display_user_dashboard_list_checkboxes($user_id, $block['id']);
+					echo '<td>'.$block['name'].'</td>';
+					echo '<td>'.$block['description'].'</td>';
+					echo '<td><center>
                             <select name="columns['.$block['id'].']">
                             <option value="1" '.(isset($user_block_data[$block['id']]) && $user_block_data[$block['id']]['column']==1?'selected':'').' >1</option>
                             <option value="2" '.(isset($user_block_data[$block['id']]) && $user_block_data[$block['id']]['column']==2?'selected':'').' >2</option>
                             </select></center>
                           </td>';
-                    echo '</tr>';
+					echo '</tr>';
 				} else {
-			         echo Display::tag('tr',  Display::tag('td', get_lang('Error').' '.$controller_class, array('colspan'=>'3')));
+					echo Display::tag('tr',  Display::tag('td', get_lang('Error').' '.$controller_class, array('colspan'=>'3')));
 				}
 			}
 
@@ -427,7 +425,7 @@ class DashboardManager
 		}
 
 		echo "<td align=\"center\">";
-			echo '<input type="checkbox" name="enabled_blocks['.$block_id.']" value="true" '.$checked.'/>';
+		echo '<input type="checkbox" name="enabled_blocks['.$block_id.']" value="true" '.$checked.'/>';
 		echo "</td>";
 	}
 
@@ -437,7 +435,7 @@ class DashboardManager
 	 * @param array selected blocks
 	 * @param array columns position
 	 * @return bool
-	*/
+	 */
 	public static function store_user_blocks($user_id, $enabled_blocks, $columns) {
 		$selected_blocks_id  = array();
 		if (is_array($enabled_blocks) && count($enabled_blocks) > 0) {
@@ -469,11 +467,11 @@ class DashboardManager
 		$data = array();
 		foreach ($extra_user_data as $extra) {
 			$split_extra = explode(':',$extra);
-            if (!empty($split_extra)) {
-                $block_id = $split_extra[0];
-                $column = isset($split_extra[1]) ? $split_extra[1] : null;
-                $data[$block_id] = array('block_id' => $block_id, 'column' => $column);
-            }
+			if (!empty($split_extra)) {
+				$block_id = $split_extra[0];
+				$column = isset($split_extra[1]) ? $split_extra[1] : null;
+				$data[$block_id] = array('block_id' => $block_id, 'column' => $column);
+			}
 		}
 		return $data;
 	}

+ 1 - 1
main/inc/lib/database.lib.php

@@ -474,7 +474,7 @@ class Database
         // See #7440 for more info
         /*
         if ($addFix) {
-            $string = "__@$string@__";
+            //$string = "__@$string@__";
         }
         */
         return get_magic_quotes_gpc()

+ 41 - 25
main/inc/lib/link.lib.php

@@ -800,7 +800,8 @@ function makedefaultviewcode($locatie)
  */
 function change_visibility_link($id, $scope)
 {
-    global $_course, $_user;
+    $_course = api_get_course_info();
+    $_user = api_get_user_info();
     if ($scope == TOOL_LINK) {
         api_item_property_update(
             $_course,
@@ -837,43 +838,58 @@ function getLinkCategories($courseId, $sessionId)
     // Condition for the session.
     $sessionCondition = api_get_session_condition($sessionId, true, true);
 
+    // Getting links
     $sql = "SELECT *, linkcat.id
             FROM $tblLinkCategory linkcat
-            INNER JOIN $tblItemProperty itemproperties
-            ON (linkcat.id = itemproperties.ref AND linkcat.c_id = itemproperties.c_id)
             WHERE
-                itemproperties.tool = '" . TOOL_LINK_CATEGORY . "' AND
-                (itemproperties.visibility = '0' OR itemproperties.visibility = '1')
-                $sessionCondition AND
-                linkcat.c_id = " . $courseId . " AND
-                itemproperties.c_id = " . $courseId . "
+                linkcat.c_id = " . $courseId."
+                $sessionCondition
             ORDER BY linkcat.display_order DESC";
 
+    $result = Database::query($sql);
+    $categories = Database::store_result($result);
+
     $sql = "SELECT *, linkcat.id
             FROM $tblLinkCategory linkcat
+            INNER JOIN $tblItemProperty itemproperties
+            ON (linkcat.id = itemproperties.ref AND linkcat.c_id = itemproperties.c_id)
             WHERE
-                linkcat.c_id = " . $courseId."
-                $sessionCondition
+                itemproperties.tool = '" . TOOL_LINK_CATEGORY . "' AND
+                (itemproperties.visibility = '0' OR itemproperties.visibility = '1')
+                $sessionCondition AND
+                linkcat.c_id = " . $courseId . "
             ORDER BY linkcat.display_order DESC";
 
-    return Database::query($sql);
-}
+    $result = Database::query($sql);
 
-/**
- * Get links categories in the current course and
- * session
- * @param  int $courseId
- * @param  int $sessionId
- * @return array
- */
-function getLinkCategoriesResult($courseId, $sessionId)
-{
-    $result = getLinkCategories($courseId, $sessionId);
-    $list = array();
+    $categoryInItemProperty = array();
     if (Database::num_rows($result)) {
-        $list = Database::store_result($result, 'ASSOC');
+        while ($row = Database::fetch_array($result, 'ASSOC')) {
+            $categoryInItemProperty[$row['id']] = $row;
+        }
     }
-    return $list;
+
+    foreach ($categories as & $category) {
+        if (!isset($categoryInItemProperty[$category['id']])) {
+            api_set_default_visibility($category['id'], TOOL_LINK_CATEGORY);
+        }
+    }
+
+    $sql = "SELECT DISTINCT linkcat.*, visibility
+            FROM $tblLinkCategory linkcat
+            INNER JOIN $tblItemProperty itemproperties
+            ON (linkcat.id = itemproperties.ref AND linkcat.c_id = itemproperties.c_id)
+            WHERE
+                itemproperties.tool = '" . TOOL_LINK_CATEGORY . "' AND
+                (itemproperties.visibility = '0' OR itemproperties.visibility = '1')
+                $sessionCondition AND
+                linkcat.c_id = " . $courseId . "
+            GROUP BY c_id, id
+            ORDER BY linkcat.display_order DESC
+            ";
+    $result = Database::query($sql);
+
+    return Database::store_result($result, 'ASSOC');
 }
 
 /**

+ 32 - 11
main/inc/lib/pdf.lib.php

@@ -42,10 +42,10 @@ class PDF
         //$this->pdf = $pdf = new mPDF('UTF-8', $pageFormat, '', '', 30, 20, 27, 25, 16, 13, $orientation);
         //left, right, top, bottom, margin_header, margin footer
 
-        $params['left']     = isset($params['left'])    ? $params['left']   : 15;
-        $params['right']    = isset($params['right'])   ? $params['right']  : 15;
-        $params['top']      = isset($params['top'])     ? $params['top']    : 20;
-        $params['bottom']   = isset($params['bottom'])  ? $params['bottom'] : 15;
+        $params['left'] = isset($params['left']) ? $params['left'] : 15;
+        $params['right'] = isset($params['right']) ? $params['right'] : 15;
+        $params['top'] = isset($params['top']) ? $params['top'] : 20;
+        $params['bottom'] = isset($params['bottom']) ? $params['bottom'] : 15;
 
         $this->params['filename'] = isset($params['filename']) ? $params['filename'] : api_get_local_time();
         $this->params['pdf_title'] = isset($params['pdf_title']) ? $params['pdf_title'] : get_lang('Untitled');
@@ -53,6 +53,7 @@ class PDF
         $this->params['session_info'] = isset($params['session_info']) ? $params['session_info'] : api_get_session_info(api_get_session_id());
         $this->params['course_code'] = isset($params['course_code']) ? $params['course_code'] : api_get_course_id();
         $this->params['add_signatures'] = isset($params['add_signatures']) ? $params['add_signatures'] : false;
+        $this->params['show_real_course_teachers'] = isset($params['show_real_course_teachers']) ? $params['show_real_course_teachers'] : false;
 
         $this->pdf = new mPDF(
             'UTF-8',
@@ -111,10 +112,27 @@ class PDF
         Display::$global_template->assign('organization', $organization);
 
         //Showing only the current teacher/admin instead the all teacher list name see BT#4080
-        //$teacher_list = CourseManager::get_teacher_list_from_course_code_to_string($course_code);
 
-        $user_info = api_get_user_info();
-        $teacher_list = $user_info['complete_name'];
+        if (isset($this->params['show_real_course_teachers']) &&
+            $this->params['show_real_course_teachers']
+        ) {
+            if (isset($this->params['session_info']) &&
+                !empty($this->params['session_info'])
+            ) {
+                $teacher_list = SessionManager::getCoachesByCourseSessionToString(
+                    $this->params['session_info']['id'],
+                    $this->params['course_code']
+
+                );
+            } else {
+                $teacher_list = CourseManager::get_teacher_list_from_course_code_to_string(
+                    $this->params['course_code']
+                );
+            }
+        } else {
+            $user_info = api_get_user_info();
+            $teacher_list = $user_info['complete_name'];
+        }
 
         Display::$global_template->assign('pdf_course', $this->params['course_code']);
         Display::$global_template->assign('pdf_course_info', $this->params['course_info']);
@@ -334,7 +352,8 @@ class PDF
      * @param   string  $document_html valid html
      * @param   string  $css CSS content of a CSS file
      * @param   string  $pdf_name pdf name
-     * @param   string  $course_code course code (if you are using html that are located in the document tool you must provide this)
+     * @param   string  $course_code course code
+     * (if you are using html that are located in the document tool you must provide this)
      * @return  string  Web path
      */
     public function content_to_pdf(
@@ -592,13 +611,15 @@ class PDF
     public function set_header($course_data)
     {
         $this->pdf->defaultheaderfontsize   = 10;   // in pts
-        $this->pdf->defaultheaderfontstyle  = BI;   // blank, B, I, or BI
+        $this->pdf->defaultheaderfontstyle  = 'BI';   // blank, B, I, or BI
         $this->pdf->defaultheaderline       = 1;    // 1 to include line below header/above footer
 
         if (!empty($course_data['code'])) {
             $teacher_list = CourseManager::get_teacher_list_from_course_code($course_data['code']);
+
             $teachers = '';
             if (!empty($teacher_list)) {
+
                 foreach ($teacher_list as $teacher) {
                     $teachers[]= $teacher['firstname'].' '.$teacher['lastname'];
                 }
@@ -690,8 +711,8 @@ class PDF
     /**
      * Pre-formats a PDF to the right size and, if not stated otherwise, with
      * header, footer and watermark (if any)
-     * @param array General course information (to fill headers)
-     * @param bool Whether we want headers, footers and watermark or not
+     * @param array $course_data General course information (to fill headers)
+     * @param bool $complete Whether we want headers, footers and watermark or not
      */
     public function format_pdf($course_data, $complete = true)
     {

+ 87 - 62
main/link/link.php

@@ -106,18 +106,17 @@ event_access_tool(TOOL_LINK);
 Display::display_header($nameTools, 'Links');
 
 ?>
-<script type="text/javascript">
-/* <![CDATA[ */
-function MM_popupMsg(msg) { //v1.0
-  confirm(msg);
-}
-/* ]]> */
-</script>
+    <script type="text/javascript">
+        /* <![CDATA[ */
+        function MM_popupMsg(msg) { //v1.0
+            confirm(msg);
+        }
+        /* ]]> */
+    </script>
 
 <?php
 
 /*	Action Handling */
-
 $nameTools = get_lang('Links');
 
 if (isset($_GET['action'])) {
@@ -126,14 +125,16 @@ if (isset($_GET['action'])) {
         switch ($_GET['action']) {
             case 'addlink':
                 if ($link_submitted) {
-                    if (!addlinkcategory("link")) {	// Here we add a link
+                    // Here we add a link
+                    if (!addlinkcategory("link")) {
                         unset($submit_link);
                     }
                 }
                 break;
             case 'addcategory':
                 if ($category_submitted) {
-                    if (!addlinkcategory('category')) {	// Here we add a category
+                    // Here we add a category
+                    if (!addlinkcategory('category')) {
                         unset($submit_category);
                     }
                 }
@@ -144,22 +145,28 @@ if (isset($_GET['action'])) {
                 }
                 break;
             case 'deletelink':
-                deletelinkcategory($_GET['id'], 'link'); // Here we delete a link
+                // Here we delete a link
+                deletelinkcategory($_GET['id'], 'link');
                 break;
             case 'deletecategory':
-                deletelinkcategory($_GET['id'], 'category'); // Here we delete a category
+                // Here we delete a category
+                deletelinkcategory($_GET['id'], 'category');
                 break;
             case 'editlink':
-                editlinkcategory('link'); // Here we edit a link
+                // Here we edit a link
+                editlinkcategory('link');
                 break;
             case 'editcategory':
-                editlinkcategory('category'); // Here we edit a category
+                // Here we edit a category
+                editlinkcategory('category');
                 break;
             case 'visible':
-                change_visibility_link($_GET['id'], $_GET['scope']); // Here we edit a category
+                // Here we edit a category
+                change_visibility_link($_GET['id'], $_GET['scope']);
                 break;
             case 'invisible':
-                change_visibility_link($_GET['id'], $_GET['scope']); // Here we edit a category
+                // Here we edit a category
+                change_visibility_link($_GET['id'], $_GET['scope']);
                 break;
         }
         Security::clear_token();
@@ -255,7 +262,7 @@ if (api_is_allowed_to_edit(null, true) && isset($_GET['action'])) {
 
         $resultcategories = getLinkCategories($course_id, $session_id);
 
-        if (Database::num_rows($resultcategories)) {
+        if (!empty($resultcategories)) {
             echo '	<div class="control-group category">
                         <label class="control-label">
                             '.get_lang('Category').'
@@ -263,7 +270,7 @@ if (api_is_allowed_to_edit(null, true) && isset($_GET['action'])) {
                         <div class="controls">';
             echo '			<select name="selectcategory">';
             echo '			<option value="0">--</option>';
-            while ($myrow = Database::fetch_array($resultcategories)) {
+            foreach ($resultcategories as $myrow) {
                 echo '		<option value="'.$myrow['id'].'"';
                 if ($myrow['id'] == $category) {
                     echo ' selected';
@@ -403,23 +410,27 @@ if (!empty($up)) {
     movecatlink($up);
 }
 
-if (empty($_GET['action']) || ($_GET['action'] != 'editlink' && $_GET['action'] != 'addcategory' && $_GET['action'] != 'addlink') || $link_submitted || $category_submitted) {
-
+if (empty($_GET['action']) ||
+    ($_GET['action'] != 'editlink' && $_GET['action'] != 'addcategory' && $_GET['action'] != 'addlink') ||
+    $link_submitted ||
+    $category_submitted
+) {
     /*	Action Links */
-
     echo '<div class="actions">';
     if (api_is_allowed_to_edit(null, true)) {
         $urlview = Security::remove_XSS($urlview);
-        echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=addlink&amp;category='.(!empty($category) ? $category : '').'&amp;urlview='.$urlview.'">'.Display::return_icon('new_link.png', get_lang('LinkAdd'),'',ICON_SIZE_MEDIUM).'</a>';
-        echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=addcategory&amp;urlview='.$urlview.'">'.Display::return_icon('new_folder.png', get_lang('CategoryAdd'),'',ICON_SIZE_MEDIUM).'</a>';
+        echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=addlink&amp;category='.(!empty($category) ? $category : '').'&amp;urlview='.$urlview.'">'.
+            Display::return_icon('new_link.png', get_lang('LinkAdd'),'',ICON_SIZE_MEDIUM).'</a>';
+        echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=addcategory&amp;urlview='.$urlview.'">'.
+            Display::return_icon('new_folder.png', get_lang('CategoryAdd'),'',ICON_SIZE_MEDIUM).'</a>';
 
-           /* "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=importcsv&amp;urlview=".$urlview."\">".get_lang('CsvImport')."</a>\n", // RH*/
+        /* "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=importcsv&amp;urlview=".$urlview."\">".get_lang('CsvImport')."</a>\n", // RH*/
     }
     // Making the show none / show all links. Show none means urlview=0000 (number of zeros depending on the
     // number of categories). Show all means urlview=1111 (number of 1 depending on teh number of categories).
     $resultcategories = getLinkCategories($course_id, $session_id);
-    $aantalcategories = Database::num_rows($resultcategories);
-    if ($aantalcategories > 0) {
+    $aantalcategories = count($resultcategories);
+    if (!empty($resultcategories)) {
         echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&urlview=';
         for ($j = 1; $j <= $aantalcategories; $j++) {
             echo '0';
@@ -449,8 +460,8 @@ if (empty($_GET['action']) || ($_GET['action'] != 'editlink' && $_GET['action']
     $catcounter = 1;
     $view = '0';
 
-    while ($myrow = Database::fetch_array($resultcategories)) {
-        // Validacion when belongs to a session
+    foreach ($resultcategories as $myrow) {
+        // Validation when belongs to a session
         $session_img = api_get_session_image($myrow['session_id'], $_user['status']);
 
         //if (!isset($urlview)) {
@@ -465,9 +476,6 @@ if (empty($_GET['action']) || ($_GET['action'] != 'editlink' && $_GET['action']
         // - instead of a +, the category is no longer clickable and all the links of this category are displayed
         $myrow['description'] = text_filter($myrow['description']);
 
-        // Link categories are always visible.
-        $myrow['visibility'] = 1;
-
         $strVisibility = '';
         if ($myrow['visibility'] == '1') {
             $strVisibility =  '<a href="link.php?' . api_get_cidreq() .  '&amp;sec_token='.$token.'&amp;action=invisible&amp;id=' . $myrow['id'] . '&amp;scope=' . TOOL_LINK_CATEGORY . '" title="' . get_lang('Hide') . '">' .
@@ -478,47 +486,57 @@ if (empty($_GET['action']) || ($_GET['action'] != 'editlink' && $_GET['action']
         }
 
         if ($myrow['visibility'] == '1') {
-
             if (isset($urlview[$i]) && $urlview[$i] == '1') {
                 $newurlview = $urlview;
                 $newurlview[$i] = '0';
                 echo '<tr>';
-                    echo '<table class="data_table">';
-                    echo '<tr>';
-                        echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;">';
-                        echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;urlview='.Security::remove_XSS($newurlview).'">';
-                        echo '<img src="../img/icons/22/view_remove.png" />&nbsp;&nbsp;'.Security::remove_XSS($myrow['category_title']).'</a><br />&nbsp;&nbsp;&nbsp;'.$myrow['description'];
+                echo '<table class="data_table">';
+                echo '<tr>';
+                echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;">';
+                echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;urlview='.Security::remove_XSS($newurlview).'">';
+                echo '<img src="../img/icons/22/view_remove.png" />&nbsp;&nbsp;'.Security::remove_XSS($myrow['category_title']).'</a><br />&nbsp;&nbsp;&nbsp;'.$myrow['description'];
+                echo '</th>';
+                if (api_is_allowed_to_edit(null, true)) {
+                    if ($session_id == $myrow['session_id']) {
+                        echo '<th>';
+                        echo $strVisibility;
+                        showcategoryadmintools($myrow['id']);
                         echo '</th>';
-                        if (api_is_allowed_to_edit(null, true)) {
-                            if ($session_id == $myrow['session_id']) {
-                                echo '<th>'; echo $strVisibility; showcategoryadmintools($myrow['id']); echo '</th>';
-                            } else {
-                                echo '<th>'.get_lang('EditionNotAvailableFromSession');
-                            }
-                        }
-                    echo '</tr>';
-                    echo '</table>';
-                    echo showlinksofcategory($myrow['id']);
+                    } else {
+                        echo '<th>'.get_lang('EditionNotAvailableFromSession');
+                    }
+                }
+                echo '</tr>';
+                echo '</table>';
+                echo showlinksofcategory($myrow['id']);
                 echo '</tr>';
             } else {
                 echo '<tr>';
-                    echo '<table class="data_table">';
-                    echo '<tr>';
-                        echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;"><a href="'.api_get_self().'?'.api_get_cidreq().'&amp;urlview=';
-                        echo is_array($view) ? implode('', $view) : $view;
-                        echo '"><img src="../img/icons/22/view_tree.png" />&nbsp;&nbsp;'.Security::remove_XSS($myrow['category_title']).$session_img;
-                        echo'</a><br />&nbsp;&nbsp;&nbsp;';
-                        echo $myrow['description'];
-                        if (api_is_allowed_to_edit(null, true)) {
-                            echo '<th style="text-align:center;">'; echo $strVisibility; showcategoryadmintools($myrow['id']); echo '</th>';
-                        }
+                echo '<table class="data_table">';
+                echo '<tr>';
+                echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;">
+                    <a href="'.api_get_self().'?'.api_get_cidreq().'&amp;urlview=';
+                echo is_array($view) ? implode('', $view) : $view;
+                echo '"><img src="../img/icons/22/view_tree.png" />&nbsp;&nbsp;'.
+                    Security::remove_XSS($myrow['category_title']).$session_img;
+                echo'</a><br />&nbsp;&nbsp;&nbsp;';
+                echo $myrow['description'];
+
+                if (api_is_allowed_to_edit(null, true)) {
+                    if ($session_id == $myrow['session_id']) {
+                        echo '<th style="text-align:center;">';
+                        echo $strVisibility;
+                        showcategoryadmintools($myrow['id']);
                         echo '</th>';
-                    echo '</tr>';
-                    echo '</table>';
+                    }
+                }
+                echo '</th>';
+                echo '</tr>';
+                echo '</table>';
                 echo '</tr>';
             }
-
-        } else { // NO VISIBLES
+        } else {
+            // NO VISIBLE
             if (api_is_allowed_to_edit(null, true)) {
                 if (isset($urlview[$i]) && $urlview[$i] == '1') {
                     $newurlview = $urlview;
@@ -550,9 +568,16 @@ if (empty($_GET['action']) || ($_GET['action'] != 'editlink' && $_GET['action']
                     echo '"><img src="../img/icons/22/view_tree_na.png" />&nbsp;&nbsp;'.Security::remove_XSS($myrow['category_title']).$session_img;
                     echo'</a><br />&nbsp;&nbsp;&nbsp;';
                     echo $myrow['description'];
+
                     if (api_is_allowed_to_edit(null, true)) {
-                        echo '<th style="text-align:center;">'; echo $strVisibility; showcategoryadmintools($myrow['id']); echo '</th>';
+                        if ($session_id == $myrow['session_id']) {
+                            echo '<th style="text-align:center;">';
+                            echo $strVisibility;
+                            showcategoryadmintools($myrow['id']);
+                            echo '</th>';
+                        }
                     }
+
                     echo '</th>';
                     echo '</tr>';
                     echo '</table>';

+ 1 - 1
main/newscorm/learnpath.class.php

@@ -8499,7 +8499,7 @@ class learnpath
         $return .= '</li>';
         $course_info = api_get_course_info();
 
-        $linkCategories = getLinkCategoriesResult($course_id, $session_id);
+        $linkCategories = getLinkCategories($course_id, $session_id);
         $categoryIdList = array();
         if (!empty($linkCategories)) {
             foreach ($linkCategories as $categoryInfo) {

+ 15 - 7
main/template/default/export/table_pdf.tpl

@@ -15,17 +15,25 @@
     </tr>
 
     {% if pdf_session_info %}
-    <tr>
-        <td>
-          <strong>{{ "Session" | get_lang }}:</strong> {{ pdf_session_info.name }}
-        </td>
+        <tr>
+            <td>
+              <strong>{{ "Session" | get_lang }}:</strong> {{ pdf_session_info.name }}
+            </td>
 
-        {% if pdf_session_info.description %}
+            {% if pdf_session_info.description %}
+                <td>
+                    <strong>{{ "Description" | get_lang }}:</strong> {{ pdf_session_info.description }}
+                </td>
+            {% endif %}
+        </tr>
+
+        {% if pdf_session_info.date_start != '0000-00-00' and pdf_session_info.date_end != '0000-00-00' %}
+            <tr>
             <td>
-                <strong>{{ "Description" | get_lang }}:</strong> {{ pdf_session_info.description }}
+                <strong>{{ "PeriodToDisplay" | get_lang }}:</strong> {{ "FromDateXToDateY"| get_lang | format(pdf_session_info.date_start, pdf_session_info.date_end ) }}
             </td>
+            </tr>
         {% endif %}
-    </tr>
     {% endif %}
 
     {% if pdf_course_info %}

+ 31 - 12
main/tracking/courseLog.php

@@ -155,21 +155,23 @@ $htmlHeadXtra[] .= $js;
 
 // Database table definitions.
 //@todo remove this calls
-$TABLETRACK_ACCESS      = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
-$TABLETRACK_LINKS       = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
-$TABLETRACK_DOWNLOADS   = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
-$TABLETRACK_ACCESS_2    = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
-$TABLETRACK_EXERCISES 	= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
+$TABLETRACK_ACCESS      = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
+$TABLETRACK_LINKS       = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LINKS);
+$TABLETRACK_DOWNLOADS   = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
+$TABLETRACK_ACCESS_2    = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
+$TABLETRACK_EXERCISES 	= Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
 $TABLECOURSUSER	        = Database::get_main_table(TABLE_MAIN_COURSE_USER);
 $TABLECOURSE	        = Database::get_main_table(TABLE_MAIN_COURSE);
 $table_user             = Database::get_main_table(TABLE_MAIN_USER);
 $TABLEQUIZ              = Database::get_course_table(TABLE_QUIZ_TEST);
 
+$sessionId = api_get_session_id();
+
 // Breadcrumbs.
 if (isset($_GET['origin']) && $_GET['origin'] == 'resume_session') {
     $interbreadcrumb[] = array('url' => '../admin/index.php','name' => get_lang('PlatformAdmin'));
     $interbreadcrumb[] = array('url' => '../admin/session_list.php','name' => get_lang('SessionList'));
-    $interbreadcrumb[] = array('url' => '../admin/resume_session.php?id_session='.api_get_session_id(), 'name' => get_lang('SessionOverview'));
+    $interbreadcrumb[] = array('url' => '../admin/resume_session.php?id_session='.$sessionId, 'name' => get_lang('SessionOverview'));
 }
 
 $view = isset($_REQUEST['view']) ? $_REQUEST['view'] : '';
@@ -189,7 +191,7 @@ if (empty($session_id)) {
     $a_students = CourseManager::get_student_list_from_course_code(
         api_get_course_id(),
         true,
-        api_get_session_id()
+        $sessionId
     );
 }
 
@@ -220,9 +222,26 @@ if (isset($_GET['additional_profile_field']) &&
 echo '<div class="actions">';
 
 echo Display::return_icon('user_na.png', get_lang('StudentsTracking'), array(), ICON_SIZE_MEDIUM);
-echo Display::url(Display::return_icon('course.png', get_lang('CourseTracking'), array(), ICON_SIZE_MEDIUM), 'course_log_tools.php?'.api_get_cidreq());
-echo Display::url(Display::return_icon('tools.png', get_lang('ResourcesTracking'), array(), ICON_SIZE_MEDIUM), 'course_log_resources.php?'.api_get_cidreq());
-echo Display::url(Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH).'tracking/exams.php?'.api_get_cidreq());
+echo Display::url(
+    Display::return_icon('course.png', get_lang('CourseTracking'), array(), ICON_SIZE_MEDIUM),
+    'course_log_tools.php?'.api_get_cidreq()
+);
+
+echo Display::url(
+    Display::return_icon('tools.png', get_lang('ResourcesTracking'), array(), ICON_SIZE_MEDIUM),
+    'course_log_resources.php?'.api_get_cidreq()
+);
+echo Display::url(
+    Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), ICON_SIZE_MEDIUM),
+    api_get_path(WEB_CODE_PATH).'tracking/exams.php?'.api_get_cidreq()
+);
+
+if (!empty($sessionId)) {
+    echo Display::url(
+        Display::return_icon('attendance_list.png', get_lang('Logins'), '', ICON_SIZE_MEDIUM),
+        api_get_path(WEB_CODE_PATH) . 'attendance/index.php?' . api_get_cidreq() . '&action=calendar_logins'
+    );
+}
 
 echo '<span style="float:right; padding-top:0px;">';
 echo '<a href="javascript: void(0);" onclick="javascript: window.print();">'.
@@ -256,8 +275,8 @@ $form_search = new FormValidator(
 $renderer = $form_search->defaultRenderer();
 $renderer->setElementTemplate('<span>{element}</span>');
 $form_search->addElement('hidden', 'from', Security::remove_XSS($from));
-$form_search->addElement('hidden', 'session_id', api_get_session_id());
-$form_search->addElement('hidden', 'id_session', api_get_session_id());
+$form_search->addElement('hidden', 'session_id', $sessionId);
+$form_search->addElement('hidden', 'id_session', $sessionId);
 $form_search->addElement('text', 'user_keyword');
 $form_search->addElement('style_submit_button', 'submit', get_lang('SearchUsers'), 'class="search"');
 $form_search->display();

+ 45 - 9
main/work/work.lib.php

@@ -5019,6 +5019,8 @@ function exportAllStudentWorkFromPublication(
         return false;
     }
 
+    $assignment = get_work_assignment_by_id($workId);
+
     $courseCode = $courseInfo['code'];
     $header = get_lang('Course').': '.$courseInfo['title'];
     $teachers = CourseManager::get_teacher_list_from_course_code_to_string(
@@ -5042,8 +5044,11 @@ function exportAllStudentWorkFromPublication(
     $header .= '<br />'.get_lang('StudentPublication').': '.$workData['title'].'<br />';
 
     $content = null;
-    if (!empty($workData['expires_on'])) {
-        $content .= '<br /><strong>' . get_lang('ExpiryDate') . '</strong>: ' . api_get_local_time($workData['expires_on']);
+    $expiresOn = null;
+
+    if (!empty($assignment) && isset($assignment['expires_on'])) {
+        $content .= '<br /><strong>' . get_lang('ExpiryDate') . '</strong>: ' . api_get_local_time($assignment['expires_on']);
+        $expiresOn = api_get_local_time($assignment['expires_on']);
     }
 
     if (!empty($workData['description'])) {
@@ -5057,33 +5062,64 @@ function exportAllStudentWorkFromPublication(
             if (!empty($workList)) {
                 require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
 
+                $table = new HTML_Table(array('class' => 'data_table'));
+                $headers = array(
+                    get_lang('Name'),
+                    get_lang('User'),
+                    get_lang('HandOutDateLimit'),
+                    get_lang('SentDate'),
+                    get_lang('Filename'),
+                    get_lang('Score'),
+                    get_lang('Feedback')
+                );
+
+                $column = 0;
+                foreach($headers as $header) {
+                    $table->setHeaderContents(0, $column, $header);
+                    $column++;
+                }
+
+                $row = 1;
+
                 //$pdf->set_custom_header($header);
                 foreach ($workList as $work) {
                     $content .= '<hr />';
                     // getWorkComments need c_id
                     $work['c_id'] = $courseInfo['real_id'];
 
-                    $content .= '<h3>'.strip_tags($work['title']).'</h3>';
-                    $content .= get_lang('Date').': '.api_get_local_time($work['sent_date_from_db']).'<br />';
+                    //$content .= get_lang('Date').': '.api_get_local_time($work['sent_date_from_db']).'<br />';
+                    $score = null;
                     if (!empty($work['qualification_only'])) {
-                        $content .= get_lang('Score').': '.$work['qualification_only'] . '<br />';
+                        $score = $work['qualification_only'];
                     }
-                    $content .= get_lang('Description').': '.$work['description'].'<br />';
+                    //$content .= get_lang('Description').': '.$work['description'].'<br />';
                     $comments = getWorkComments($work);
 
+                    $feedback = null;
                     if (!empty($comments)) {
                         $content .= '<h4>'.get_lang('Feedback').': </h4>';
                         foreach ($comments as $comment) {
-                            $content .= get_lang('User').': '.api_get_person_name(
+                            $feedback .= get_lang('User').': '.api_get_person_name(
                                 $comment['firstname'],
                                 $comment['lastname']
                             ).'<br />';
-                            $content .= $comment['comment'];
-                            $content .= '<hr />';
+                            $feedback .= $comment['comment'].'<br />';
                         }
                     }
+
+                    $table->setCellContents($row, 0, strip_tags($workData['title']));
+                    $table->setCellContents($row, 1, api_get_person_name(strip_tags($work['firstname']), strip_tags($work['lastname'])));
+                    $table->setCellContents($row, 2, $expiresOn);
+                    $table->setCellContents($row, 3, api_get_local_time($work['sent_date_from_db']));
+                    $table->setCellContents($row, 4, strip_tags($work['title']));
+                    $table->setCellContents($row, 5, $score);
+                    $table->setCellContents($row, 6, $feedback);
+
+                    $row++;
                 }
 
+                $content = $table->toHtml();
+
                 if (!empty($content)) {
                     $params = array(
                         'filename' => $workData['title'] . '_' . api_get_local_time(),

+ 8 - 1
main/work/work_list_all.php

@@ -3,7 +3,14 @@
 
 use ChamiloSession as Session;
 
-$language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
+$language_file = array(
+    'exercice',
+    'work',
+    'document',
+    'admin',
+    'gradebook',
+    'tracking'
+);
 
 require_once '../inc/global.inc.php';
 $current_course_tool  = TOOL_STUDENTPUBLICATION;