Adding delete option see BT#9183

1.9.x
Julio Montoya 10 years ago
parent 333f2c2db2
commit 3299491e75
  1. 13
      main/course_info/infocours.php
  2. 34
      main/inc/lib/course.lib.php

@ -114,7 +114,11 @@ if ($form->validate() && is_settings_editable()) {
// update course picture
$picture = $_FILES['picture'];
if (!empty($picture['name'])) {
$picture_uri = CourseManager::update_course_picture($course_code, $picture['name'], $picture['tmp_name']);
$picture_uri = CourseManager::update_course_picture(
$course_code,
$picture['name'],
$picture['tmp_name']
);
}
}
@ -146,6 +150,8 @@ $form->addElement('file', 'picture', get_lang('AddPicture'));
$allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
$form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
$form->addElement('checkbox', 'delete_picture', null, get_lang('DeletePicture'));
if (api_get_setting('pdf_export_watermark_by_course') == 'true') {
$url = PDF::get_watermark($course_code);
$form->add_textfield('pdf_export_watermark_text', get_lang('PDFExportWatermarkTextTitle'), false, array('size' => '60'));
@ -413,6 +419,11 @@ if ($form->validate() && is_settings_editable()) {
$updateValues = $form->exportValues();
$visibility = $updateValues['visibility'];
$deletePicture = $updateValues['delete_picture'];
if ($deletePicture) {
CourseManager::deleteCoursePicture($course_code);
}
global $_configuration;
$urlId = api_get_current_access_url_id();

@ -3379,21 +3379,22 @@ class CourseManager
public static function update_course_picture($course_code, $filename, $source_file = null)
{
$course_info = api_get_course_info($course_code);
$store_path = api_get_path(SYS_COURSE_PATH).$course_info['path']; // course path
$course_image = $store_path.'/course-pic.png'; // image name for courses
// course path
$store_path = api_get_path(SYS_COURSE_PATH).$course_info['path'];
// image name for courses
$course_image = $store_path.'/course-pic.png';
$course_medium_image = $store_path.'/course-pic85x85.png';
//$extension = strtolower(substr(strrchr($filename, '.'), 1));
if (file_exists($course_image)) {
@unlink($course_image);
unlink($course_image);
}
if (file_exists($course_medium_image)) {
@unlink($course_medium_image);
unlink($course_medium_image);
}
$my_course_image = new Image($source_file);
$result = $my_course_image->send_image($course_image, -1, 'png');
//Redimension image to 100x85 (should be 85x85 but 100x85 visually gives
// Redimension image to 100x85 (should be 85x85 but 100x85 visually gives
// better results for most images people put as course icon)
if ($result) {
$medium = new Image($course_image);
@ -3404,6 +3405,27 @@ class CourseManager
return $result;
}
/**
* Deletes the course picture
* @param string $courseCode
*/
public static function deleteCoursePicture($courseCode)
{
$course_info = api_get_course_info($courseCode);
// course path
$storePath = api_get_path(SYS_COURSE_PATH).$course_info['path'];
// image name for courses
$courseImage = $storePath.'/course-pic.png';
$courseMediumImage = $storePath.'/course-pic85x85.png';
if (file_exists($courseImage)) {
unlink($courseImage);
}
if (file_exists($courseMediumImage)) {
unlink($courseMediumImage);
}
}
/**
* @deprecated See CourseManager::course_code_exists()
*/

Loading…
Cancel
Save