diff --git a/main/auth/profile.php b/main/auth/profile.php index 15b31599eb..da8e73b695 100644 --- a/main/auth/profile.php +++ b/main/auth/profile.php @@ -1,5 +1,5 @@ add_html_editor('competences', get_lang('MyCompetences'), false); - + // MY DIPLOMAS $form->add_html_editor('diplomas', get_lang('MyDiplomas'), false); - + // WHAT I AM ABLE TO TEACH $form->add_html_editor('teach', get_lang('MyTeach'), false); - + // MY PRODUCTIONS $form->addElement('file', 'production', get_lang('MyProductions')); - if ($production_list = build_production_list($_user['user_id'])) - $form->addElement('static', 'productions', null, $production_list); + if ($production_list = UserManager::build_production_list($_user['user_id'],'',true)) + { + $form->addElement('static', 'productions', null, $production_list); + } // MY PERSONAL OPEN AREA $form->add_html_editor('openarea', get_lang('MyPersonalOpenArea'), false); @@ -275,7 +277,7 @@ function is_profile_editable() */ /** - * Deprecated function. Use UserManager::get_user_picture_path_by_id($user_id,'none') instead + * Deprecated function. Use UserManager::get_user_picture_path_by_id($user_id,'none') instead * Get a user's display picture. If the user doesn't have a picture, this * function will return an empty string. * @@ -322,7 +324,7 @@ function upload_user_image($user_id) if (!file_exists($image_repository)) { - //error_log('Making path '.$image_repository,0); + //error_log('Making path '.$image_repository,0); mkpath($image_repository); }else{ //error_log('Path '.$image_repository.' exists',0); @@ -349,7 +351,7 @@ function upload_user_image($user_id) { $picture_filename = (PREFIX_IMAGE_FILENAME_WITH_UID ? $user_id.'_' : '').uniqid('').'.'.$file_extension; } - + $temp = new image($_FILES['picture']['tmp_name']); $picture_infos=getimagesize($_FILES['picture']['tmp_name']); $thumbwidth = IMAGE_THUMBNAIL_WIDTH; @@ -358,10 +360,10 @@ function upload_user_image($user_id) $thumbwidth=100; } $new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]); - + $temp->resize($thumbwidth,$new_height,0); $type=$picture_infos[2]; - + switch ($type) { case 2 : $temp->send_image('JPG',$image_repository.$picture_filename); break; @@ -370,7 +372,7 @@ function upload_user_image($user_id) case 1 : $temp->send_image('GIF',$image_repository.$picture_filename); break; } - + return $picture_filename; } @@ -401,76 +403,6 @@ function remove_user_image($user_id) ----------------------------------------------------------- */ -/** - * Returns an XHTML formatted list of productions for a user, or FALSE if he - * doesn't have any. - * - * If there has been a request to remove a production, the function will return - * without building the list unless forced to do so by the optional second - * parameter. This increases performance by avoiding to read through the - * productions on the filesystem before the removal request has been carried - * out because they'll have to be re-read afterwards anyway. - * - * @param $user_id User id - * @param $force Optional parameter to force building after a removal request - * @return A string containing the XHTML code to dipslay the production list, or FALSE - */ -function build_production_list($user_id, $force = false) -{ - if (!$force && $_POST['remove_production']) - return true; // postpone reading from the filesystem - - $productions = get_user_productions($user_id); - - if (empty($productions)) - return false; - - $production_path = UserManager::get_user_picture_path_by_id($user_id,'web',true); - $production_dir = $production_path['dir']; - $del_image = api_get_path(WEB_CODE_PATH).'img/delete.gif'; - $del_text = get_lang('Delete'); - - $production_list = ''; - - return $production_list; -} - -/** - * Returns an array with the user's productions. - * - * @param $user_id User id - * @return An array containing the user's productions - */ -function get_user_productions($user_id) -{ - $production_path = UserManager::get_user_picture_path_by_id($user_id,'system',true); - $production_repository = $production_path['dir'].$user_id.'/'; - $productions = array(); - - if (is_dir($production_repository)) - { - $handle = opendir($production_repository); - - while ($file = readdir($handle)) - { - if ($file == '.' || $file == '..' || $file == '.htaccess') - continue; // skip current/parent directory and .htaccess - - $productions[] = $file; - } - } - - return $productions; // can be an empty array -} - /** * Upload a submitted user production. * @@ -494,18 +426,6 @@ function upload_user_production($user_id) return false; // this should be returned if anything went wrong with the upload } -/** - * Remove a user production. - * - * @param $user_id User id - * @param $production The production to remove - */ -function remove_user_production($user_id, $production) -{ - $production_path = UserManager::get_user_picture_path_by_id($user_id,'system',true); - unlink($production_path['dir'].$user_id.'/'.$production); -} - /* ============================================================================== MAIN CODE @@ -520,9 +440,11 @@ if ($_SESSION['profile_update']) elseif ($_POST['remove_production']) { foreach (array_keys($_POST['remove_production']) as $production) - remove_user_production($_user['user_id'], urldecode($production)); + { + UserManager::remove_user_production($_user['user_id'], urldecode($production)); + } - if ($production_list = build_production_list($_user['user_id'], true)) + if ($production_list = UserManager::build_production_list($_user['user_id'], true,true)) $form->insertElementBefore($form->createElement('static', null, null, $production_list), 'productions'); $form->removeElement('productions'); @@ -542,7 +464,7 @@ elseif ($form->validate()) { if ($new_picture = upload_user_image($_user['user_id'])) $user_data['picture_uri'] = $new_picture; - + } // remove existing picture if asked elseif ($user_data['remove_picture']) diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 32499c09be..7ebdbd154b 100644 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -390,5 +390,97 @@ class UserManager } return array('dir'=>$dir,'file'=>$path); } + +/* +----------------------------------------------------------- + PRODUCTIONS FUNCTIONS +----------------------------------------------------------- +*/ + +/** + * Returns an XHTML formatted list of productions for a user, or FALSE if he + * doesn't have any. + * + * If there has been a request to remove a production, the function will return + * without building the list unless forced to do so by the optional second + * parameter. This increases performance by avoiding to read through the + * productions on the filesystem before the removal request has been carried + * out because they'll have to be re-read afterwards anyway. + * + * @param $user_id User id + * @param $force Optional parameter to force building after a removal request + * @return A string containing the XHTML code to dipslay the production list, or FALSE + */ +function build_production_list($user_id, $force = false, $showdelete=false) +{ + if (!$force && $_POST['remove_production']) + return true; // postpone reading from the filesystem + + $productions = UserManager::get_user_productions($user_id); + + if (empty($productions)) + return false; + + $production_path = UserManager::get_user_picture_path_by_id($user_id,'web',true); + $production_dir = $production_path['dir']; + $del_image = api_get_path(WEB_CODE_PATH).'img/delete.gif'; + $del_text = get_lang('Delete'); + + $production_list = ''; + + return $production_list; +} + +/** + * Returns an array with the user's productions. + * + * @param $user_id User id + * @return An array containing the user's productions + */ +function get_user_productions($user_id) +{ + $production_path = UserManager::get_user_picture_path_by_id($user_id,'system',true); + $production_repository = $production_path['dir'].$user_id.'/'; + $productions = array(); + + if (is_dir($production_repository)) + { + $handle = opendir($production_repository); + + while ($file = readdir($handle)) + { + if ($file == '.' || $file == '..' || $file == '.htaccess') + continue; // skip current/parent directory and .htaccess + + $productions[] = $file; + } + } + + return $productions; // can be an empty array +} + +} + +/** + * Remove a user production. + * + * @param $user_id User id + * @param $production The production to remove + */ +function remove_user_production($user_id, $production) +{ + $production_path = UserManager::get_user_picture_path_by_id($user_id,'system',true); + unlink($production_path['dir'].$user_id.'/'.$production); } ?> \ No newline at end of file diff --git a/main/user/userInfo.php b/main/user/userInfo.php index 1c846738fc..698a8189bd 100644 --- a/main/user/userInfo.php +++ b/main/user/userInfo.php @@ -48,6 +48,7 @@ $language_file = array ('registration', 'userInfo'); include ("../inc/global.inc.php"); require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); +require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php'); $this_section = SECTION_COURSES; $nameTools = get_lang("Users"); @@ -352,6 +353,15 @@ elseif ($displayMode == "viewMainInfoEdit") echo "\n", "", "", "\n"; echo "

".Display :: encrypted_mailto_link($mainUserInfo['email'], $mainUserInfo['email'])."

"; + + if (api_get_setting('extended_profile') == 'true') + { + echo '
'.get_lang('MyCompetences').'
'.$mainUserInfo['competences'].'
'; + echo '
'.get_lang('MyDiplomas').'
'.$mainUserInfo['diplomas'].'
'; + echo '
'.get_lang('MyTeach').'
'.$mainUserInfo['teach'].'
'; + echo '
'.get_lang('MyPersonalOpenArea').'
'.$mainUserInfo['openarea'].'
'; + echo '
'.get_lang('MyProductions').'
'.UserManager::build_production_list($mainUserInfo['user_id']).'
'; + } } else{ @@ -442,6 +452,15 @@ elseif ($displayMode == "viewContentList") // default display ""; //"

",$mainUserInfo['email'],"", echo "

". Display::encrypted_mailto_link($mainUserInfo['email'],$mainUserInfo['email']). "

"; + + if (api_get_setting('extended_profile') == 'true') + { + echo '
'.get_lang('MyCompetences').'
'.$mainUserInfo['competences'].'
'; + echo '
'.get_lang('MyDiplomas').'
'.$mainUserInfo['diplomas'].'
'; + echo '
'.get_lang('MyTeach').'
'.$mainUserInfo['teach'].'
'; + echo '
'.get_lang('MyPersonalOpenArea').'
'.$mainUserInfo['openarea'].'
'; + echo '
'.get_lang('MyProductions').'
'.UserManager::build_production_list($mainUserInfo['user_id']).'
'; + } } else{ Display :: display_normal_message(get_lang('ThisStudentIsSubscribeThroughASession')); diff --git a/main/user/userInfoLib.php b/main/user/userInfoLib.php index 22aedbff47..f6f72dc896 100644 --- a/main/user/userInfoLib.php +++ b/main/user/userInfoLib.php @@ -484,7 +484,7 @@ function get_main_user_info($user_id, $courseCode) $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $table_user = Database::get_main_table(TABLE_MAIN_USER); - $sql = "SELECT u.lastname lastName, u.firstname firstName, + $sql = "SELECT u.*, u.lastname lastName, u.firstname firstName, u.email, u.picture_uri picture, cu.role, cu.`status` `status`, cu.tutor_id FROM $table_user u, $table_course_user cu @@ -497,6 +497,7 @@ function get_main_user_info($user_id, $courseCode) if (mysql_num_rows($result) > 0) { $userInfo = mysql_fetch_array($result, MYSQL_ASSOC); + $userInfo['password']=''; return $userInfo; }