From 207e42a89083e1a1e5d3812ac236f83300da75b0 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 3 Aug 2012 13:31:47 +0200 Subject: [PATCH] Adding user image when exporting to PDF see BT#2741 --- main/css/print.css | 2 +- main/inc/lib/export.lib.inc.php | 13 +++++------ main/inc/lib/main_api.lib.php | 11 ++++++---- main/user/user.php | 38 ++++++++++++++++++++++----------- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/main/css/print.css b/main/css/print.css index a706c14204..495d91c630 100644 --- a/main/css/print.css +++ b/main/css/print.css @@ -487,6 +487,7 @@ padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;} text-align:left; padding-left:5px; } /* header cell in data table in tools */ + .data_table { border-collapse: collapse; width: 100%; @@ -518,7 +519,6 @@ padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;} text-align: left; } - .data_table_no_border { border-collapse: collapse; border-spacing: 0; diff --git a/main/inc/lib/export.lib.inc.php b/main/inc/lib/export.lib.inc.php index d95d8b3a5a..c90a233d61 100644 --- a/main/inc/lib/export.lib.inc.php +++ b/main/inc/lib/export.lib.inc.php @@ -169,7 +169,7 @@ class Export { return $string; } - public static function export_table_pdf($data, $file_name = 'export', $header, $description, $params = array()) { + public static function export_table_pdf($data, $file_name = 'export', $header = null, $description = null, $params = array(), $header_attributes = array()) { $headers = $data[0]; unset($data[0]); $html = ''; @@ -185,6 +185,8 @@ class Export { $column = 0; foreach ($headers as $header) { $table->setHeaderContents($row, $column, $header); + $attributes = $header_attributes[$column]; + $table->updateCellAttributes($row, $column, $attributes); $column++; } $row++; @@ -193,7 +195,7 @@ class Export { $column = 0; foreach ($printable_data_row as &$printable_data_cell) { $table->setCellContents($row, $column, $printable_data_cell); - //$table->updateCellAttributes($row, $column); + //$table->updateCellAttributes($row, $column, $atributes); $column++; } $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true); @@ -201,15 +203,14 @@ class Export { } $html .= $table->toHtml(); - $html = api_utf8_encode($html); - + $html = api_utf8_encode($html); + $css_file = api_get_path(TO_SYS, WEB_CSS_PATH).'/print.css'; - $css = file_exists($css_file) ? @file_get_contents($css_file) : ''; + $css = file_exists($css_file) ? @file_get_contents($css_file) : ''; $pdf = new PDF('A4', 'P', $params); $pdf->set_custom_header($headers_in_pdf); $pdf->content_to_pdf($html, $css, $file_name, api_get_course_id()); exit; } - } \ No newline at end of file diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 11351754bd..0dc53c4ab4 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -1031,24 +1031,28 @@ function _api_format_user($user, $add_password = false) { //Getting user avatar - $picture_filename = trim($user['picture_uri']); + $picture_filename = trim($user['picture_uri']); $avatar = api_get_path(WEB_CODE_PATH).'img/unknown.jpg'; $avatar_small = api_get_path(WEB_CODE_PATH).'img/unknown_22.jpg'; + $avatar_sys_path = api_get_path(SYS_CODE_PATH).'img/unknown.jpg'; $dir = 'upload/users/'.$user_id.'/'; - if (!empty($picture_filename) && api_is_anonymous() ) { + //if (!empty($picture_filename) && api_is_anonymous() ) { //Why you have to be anonymous? + if (!empty($picture_filename)) { if (api_get_setting('split_users_upload_directory') === 'true') { $dir = 'upload/users/'.substr((string)$user_id, 0, 1).'/'.$user_id.'/'; } } - $image_sys_path = api_get_path(SYS_CODE_PATH).$dir.$picture_filename; + if (file_exists($image_sys_path) && !is_dir($image_sys_path)) { $avatar = api_get_path(WEB_CODE_PATH).$dir.$picture_filename; $avatar_small = api_get_path(WEB_CODE_PATH).$dir.'small_'.$picture_filename; + $avatar_sys_path = api_get_path(SYS_CODE_PATH).$dir.$picture_filename; } $result['avatar'] = $avatar; + $result['avatar_sys_path'] = $avatar_sys_path; $result['avatar_small'] = $avatar_small; if (isset($user['user_is_online'])) { @@ -1058,7 +1062,6 @@ function _api_format_user($user, $add_password = false) { $result['user_is_online_in_chat'] = intval($user['user_is_online_in_chat']); } - if ($add_password) { $result['password'] = $user['password']; } diff --git a/main/user/user.php b/main/user/user.php index 98c1d46318..b6612b2875 100644 --- a/main/user/user.php +++ b/main/user/user.php @@ -23,7 +23,7 @@ * Code */ // name of the language file that needs to be included -$language_file = array('registration', 'admin', 'userInfo'); +$language_file = array('registration', 'admin', 'userInfo', 'registration'); $use_anonymous = true; require_once '../inc/global.inc.php'; $current_course_tool = TOOL_USER; @@ -77,6 +77,8 @@ if (api_is_allowed_to_edit(null, true)) { } } +$user_image_pdf_size = 80; + if (api_is_allowed_to_edit(null, true)) { if (isset($_GET['action'])) { switch ($_GET['action']) { @@ -120,9 +122,9 @@ if (api_is_allowed_to_edit(null, true)) { if ($_GET['type'] == 'pdf') { if ($is_western_name_order) { - $a_users[0] = array('#', get_lang('OfficialCode'), get_lang('FirstName').', '.get_lang('LastName')); + $a_users[0] = array('#', get_lang('UserPicture'), get_lang('OfficialCode'), get_lang('FirstName').', '.get_lang('LastName')); } else { - $a_users[0] = array('#', get_lang('OfficialCode'), get_lang('LastName').', '.get_lang('FirstName')); + $a_users[0] = array('#', get_lang('UserPicture'), get_lang('OfficialCode'), get_lang('LastName').', '.get_lang('FirstName')); } } @@ -168,10 +170,12 @@ if (api_is_allowed_to_edit(null, true)) { } $data[] = $user; if ($_GET['type'] == 'pdf') { + $user_info = api_get_user_info($user['user_id']); + $user_image = Display::img($user_info['avatar'], null, array('width' => $user_image_pdf_size.'px')); if ($is_western_name_order) { - $user_pdf = array($counter, $user['official_code'], $user['firstname'].', '.$user['lastname'] ); + $user_pdf = array($counter, $user_image, $user['official_code'], $user['firstname'].', '.$user['lastname'] ); } else { - $user_pdf = array($counter, $user['official_code'], $user['lastname'].', '.$user['firstname'] ); + $user_pdf = array($counter, $user_image, $user['official_code'], $user['lastname'].', '.$user['firstname'] ); } $a_users[] = $user_pdf; } else { @@ -179,9 +183,8 @@ if (api_is_allowed_to_edit(null, true)) { } $counter++; } - } - - + } + if ($session_id == 0) { // users directly subscribed to the course @@ -220,11 +223,14 @@ if (api_is_allowed_to_edit(null, true)) { } } if ($_GET['type'] == 'pdf') { + $user_info = api_get_user_info($user['user_id']); + $user_image = Display::img($user_info['avatar'], null, array('width' => $user_image_pdf_size.'px')); + if ($is_western_name_order) { - $user_pdf = array($counter, $user['official_code'], $user['firstname'].', '.$user['lastname'] ); + $user_pdf = array($counter, $user_image, $user['official_code'], $user['firstname'].', '.$user['lastname'] ); } else { - $user_pdf = array($counter, $user['official_code'], $user['lastname'].', '.$user['firstname'] ); - } + $user_pdf = array($counter, $user_image, $user['official_code'], $user['lastname'].', '.$user['firstname'] ); + } $a_users[] = $user_pdf; } else { $a_users[] = $user; @@ -268,7 +274,7 @@ if (api_is_allowed_to_edit(null, true)) { if (!empty($session_id)) { //If I'm a coach $coaches = CourseManager::get_coach_list_from_course_code($course_info['code'], $session_id); - + if (isset($coaches) && isset($coaches[$user_id])) { $user_info = api_get_user_info($user_id); $description .= ''.get_lang('Coach').': '.$user_info['complete_name'].''; @@ -284,7 +290,13 @@ if (api_is_allowed_to_edit(null, true)) { $description .= ''.get_lang('Date').': '.api_convert_and_format_date(time(), DATE_TIME_FORMAT_LONG).''; $description .= ''; $params = array(); - Export::export_table_pdf($a_users, get_lang('UserList'), $header, $description, $params); + $header_attributes = array( + array('style' => 'width:10px'), + array('style' => 'width:30px'), + array('style' => 'width:50px'), + array('style' => 'width:500px'), + ); + Export::export_table_pdf($a_users, get_lang('UserList'), $header, $description, $params, $header_attributes); exit; } }