Adding admin configuration for the watermark, supporting multiple urls, adding delete watermark functions and links see BT#1617

skala
Julio Montoya 15 years ago
parent 5d8b1a15df
commit 3a8cbcb15e
  1. 35
      main/admin/settings.php
  2. 8
      main/course_info/infocours.php
  3. 2
      main/inc/lib/database.lib.php
  4. 34
      main/inc/lib/pdf.lib.php

@ -31,6 +31,7 @@ require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH).'dashboard.lib.php';
require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
require_once 'settings.lib.php';
// Setting the section (for the tabs).
@ -94,6 +95,10 @@ $tool_name = get_lang('DokeosConfigSettings');
if (empty($_GET['category'])) {
$_GET['category'] = 'Platform';
}
$watermark_deleted = false;
if (isset($_GET['delete_watermark'])) {
$watermark_deleted = PDF::delete_watermark();
}
// Build the form.
if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search'))) {
@ -363,6 +368,18 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
break;
*/
}
if ($row['variable'] == 'pdf_export_watermark_enable') {
$url = PDF::get_watermark($course_code);
$form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark'));
if ($url != false) {
$delete_url = '<a href="?delete_watermark">'.Display::return_icon('delete.gif',get_lang('DelImage'), get_lang('DelImage')).'</a>';
$form->addElement('html', '<a href="'.$url.'">'.$url.' '.$delete_url.'</a>');
}
$allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
$form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
}
}
$form->addElement('html', '<div style="text-align: right; clear: both;">');
@ -370,8 +387,21 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
$form->addElement('html', '</div>');
$form->setDefaults($default_values);
if ($form->validate()) {
$values = $form->exportValues();
$pdf_export_watermark_path = $_FILES['pdf_export_watermark_path'];
if (!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']);
unset($update_values['pdf_export_watermark_path']);
}
// Set true for allow_message_tool variable if social tool is actived.
if ($values['allow_social_tool'] == 'true') {
@ -488,6 +518,11 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
// Including the header (banner).
Display :: display_header($tool_name);
if ($watermark_deleted) {
Display :: display_normal_message(get_lang('FileDeleted'));
}
//api_display_tool_title($tool_name);
// Displaying the message that the settings have been stored.

@ -147,7 +147,8 @@ if (api_get_setting('pdf_export_watermark_by_course') == 'true') {
$form->add_textfield('pdf_export_watermark_text', get_lang('PDFWaterMarkHeader'), false, array('size' => '60'));
$form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark'));
if ($url != false) {
$form->addElement('html', '<div class="row"><div class="formw"><a href="'.$url.'">'.$url.'</a></div></div>');
$delete_url = '<a href="?delete_watermark">'.Display::return_icon('delete.gif',get_lang('DelImage'), get_lang('DelImage')).'</a>';
$form->addElement('html', '<div class="row"><div class="formw"><a href="'.$url.'">'.$url.' '.$delete_url.'</a></div></div>');
}
$allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
$form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
@ -382,6 +383,11 @@ if ($form->validate() && is_settings_editable()) {
Display :: display_header($nameTools, MODULE_HELP_NAME);
if (isset($_GET['delete_watermark'])) {
PDF::delete_watermark($course_code);
Display :: display_normal_message(get_lang('FileDeleted'));
}
//api_display_tool_title($nameTools);
if (isset($_GET['action']) && $_GET['action'] == 'show_message') {
Display :: display_normal_message(get_lang('ModifDone'));

@ -1326,7 +1326,7 @@ class Database {
foreach($attributes as $key => $value) {
$filtred_attributes[$key] = self::escape_string($value);
}
$params = array_keys($filtred_attributes);
$params = array_keys($filtred_attributes); //@todo check if the field exists in the table we should use a describe of that table
$values = array_values($filtred_attributes);
if (!empty($params) && !empty($values)) {
$sql = 'INSERT INTO '.$table_name.' ('.implode(',',array_keys($params)).') VALUES ('.implode(',',$values).')';

@ -209,18 +209,38 @@ class PDF {
* @param mixed web path of the watermark image, false if there is nothing to return
*/
public function get_watermark($course_code = null) {
$web_path = false;
if (!empty($course_code) && api_get_setting('pdf_export_watermark_by_course') == 'true') {
$web_path = false;
if (!empty($course_code) && api_get_setting('pdf_export_watermark_by_course') == 'true') {
$course_info = api_get_course_info($course_code);
$store_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/pdf_watermark.png'; // course path
if (file_exists($store_path))
$web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/pdf_watermark.png';
} else {
$store_path = api_get_path(SYS_CODE_PATH).'default_course_document/pdf_watermark.png'; // course path
$store_path = api_get_path(SYS_CODE_PATH).'default_course_document/'.api_get_current_access_url_id().'_pdf_watermark.png'; // course path
if (file_exists($store_path))
$web_path = api_get_path(WEB_CODE_PATH).'default_course_document/pdf_watermark.png';
$web_path = api_get_path(WEB_CODE_PATH).'default_course_document/'.api_get_current_access_url_id().'_pdf_watermark.png';
}
return $web_path;
}
/**
* Deletes the watermark from the Platform or Course
* @param string course code (optional)
* @param mixed web path of the watermark image, false if there is nothing to return
*/
public function delete_watermark($course_code = null) {
if (!empty($course_code) && api_get_setting('pdf_export_watermark_by_course') == 'true') {
$course_info = api_get_course_info($course_code);
$store_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/pdf_watermark.png'; // course path
} else {
$store_path = api_get_path(SYS_CODE_PATH).'default_course_document/'.api_get_current_access_url_id().'_pdf_watermark.png'; // course path
}
if (file_exists($store_path)) {
@unlink($store_path);
return true;
}
return $store_path;
return false;
}
/**
@ -233,10 +253,10 @@ class PDF {
$web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'pdf_watermark.png';
} else {
$store_path = api_get_path(SYS_CODE_PATH).'default_course_document'; // course path
$web_path = api_get_path(WEB_CODE_PATH).'default_course_document/pdf_watermark.png';
$web_path = api_get_path(WEB_CODE_PATH).'default_course_document/'.api_get_current_access_url_id().'_pdf_watermark.png';
}
$course_image = $store_path.'/pdf_watermark.png';
$course_image = $store_path.'/'.api_get_current_access_url_id().'_pdf_watermark.png';
$extension = strtolower(substr(strrchr($filename, '.'), 1));
$result = false;
$allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');

Loading…
Cancel
Save