fix image edit template settings

pull/2958/head
Alex Aragón 6 years ago
parent 42f9e96adb
commit 519ff9045f
  1. 26
      main/admin/settings.lib.php

@ -1129,7 +1129,10 @@ function addEditTemplate()
);
// Setting the form elements: the form to upload an image to be used with the template.
if(empty($template->getImage())){
$form->addElement('file', 'template_image', get_lang('Image'), '');
}
// Setting the form elements: a little bit information about the template image.
$form->addElement('static', 'file_comment', '', get_lang('TemplateImageComment100x70'));
@ -1145,6 +1148,7 @@ function addEditTemplate()
$form->addElement('hidden', 'template_id');
// Adding an extra field: a preview of the image that is currently used.
if (!empty($template->getImage())) {
$form->addElement(
'static',
@ -1155,6 +1159,7 @@ function addEditTemplate()
.'" alt="'.get_lang('TemplatePreview')
.'"/>'
);
$form->addCheckBox('delete_image',null, get_lang('DeletePicture'));
} else {
$form->addElement(
'static',
@ -1171,20 +1176,28 @@ function addEditTemplate()
$form->addButtonSave(get_lang('Ok'), 'submit');
// Setting the rules: the required fields.
if(empty($template->getImage())) {
$form->addRule(
'template_image',
get_lang('ThisFieldIsRequired'),
'required'
);
$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
}
// if the form validates (complies to all rules) we save the information,
// else we display the form again (with error message if needed)
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
// Exporting the values.
$values = $form->exportValues();
$isDelete = null;
if(isset($values['delete_image'])){
$isDelete = $values['delete_image'];
}
// Upload the file.
if (!empty($_FILES['template_image']['name'])) {
$upload_ok = process_uploaded_file($_FILES['template_image']);
@ -1213,6 +1226,7 @@ function addEditTemplate()
}
}
// Store the information in the database (as insert or as update).
$bootstrap = api_get_css(api_get_path(WEB_PUBLIC_PATH).'assets/bootstrap/dist/css/bootstrap.min.css');
$viewport = '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
@ -1236,13 +1250,19 @@ function addEditTemplate()
Display::return_icon('new_template.png', get_lang('AddTemplate'), '', ICON_SIZE_MEDIUM).
'</a>';
} else {
$templateContent = '<head>'.$viewport.'<title>'.$values['title'].'</title>'.$bootstrap.'</head>'
.$values['template_text'];
$templateContent = $values['template_text'];
$template
->setTitle($values['title'])
->setContent(Security::remove_XSS($templateContent, COURSEMANAGERLOWSECURITY));
if ($isDelete) {
$filePath = api_get_path(SYS_APP_PATH) . 'home/default_platform_document/template_thumb/' . $template->getImage();
if (file_exists($filePath)) {
unlink($filePath);
}
$template->setImage(null);
}
if (!empty($new_file_name)) {
$template->setImage($new_file_name);
}

Loading…
Cancel
Save