Fix PDF logos

This commit is contained in:
Romain Neutron
2012-07-16 18:14:07 +02:00
parent a6306616b4
commit 1a109d0257
3 changed files with 446 additions and 407 deletions

View File

@@ -340,7 +340,7 @@ class PDF
$RIGHT_IMG = NULL; $RIGHT_IMG = NULL;
$LEFT__IMG = $registry->get('GV_RootPath') . "config/minilogos/logopdf_" $LEFT__IMG = $registry->get('GV_RootPath') . "config/minilogos/logopdf_"
. $rec->get_sbas_id() . ".jpg"; . $rec->get_sbas_id() . "";
if ( ! is_file($LEFT__IMG)) { if ( ! is_file($LEFT__IMG)) {
$databox = $rec->get_databox(); $databox = $rec->get_databox();

View File

@@ -96,23 +96,28 @@ class appbox extends base
public function write_collection_pic(collection $collection, SymfoFile $pathfile = null, $pic_type) public function write_collection_pic(collection $collection, SymfoFile $pathfile = null, $pic_type)
{ {
$core = \bootstrap::getCore(); $core = \bootstrap::getCore();
$filename = null;
if ( ! is_null($pathfile)) { if ( ! is_null($pathfile)) {
if ( ! in_array(mb_strtolower($pathfile->getMimeType()), array('image/gif', 'image/png', 'image/jpeg', 'image/jpg', 'image/pjpeg'))) { if ( ! in_array(mb_strtolower($pathfile->getMimeType()), array('image/gif', 'image/png', 'image/jpeg', 'image/jpg', 'image/pjpeg'))) {
throw new \InvalidArgumentException('Invalid file format'); throw new \InvalidArgumentException('Invalid file format');
} }
$filename = $pathfile->getPathname();
//resize collection logo //resize collection logo
$imageSpec = new ImageSpecification(); $imageSpec = new ImageSpecification();
$imageSpec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO); $imageSpec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO);
$imageSpec->setDimensions(120, 24); $imageSpec->setDimensions(120, 24);
$tmp = tempnam(sys_get_temp_dir(), 'tmpdatabox').'.jpg';
try { try {
$core['media-alchemyst'] $core['media-alchemyst']
->open($pathfile->getPathname()) ->open($pathfile->getPathname())
->turninto($pathfile->getPathname(), $imageSpec) ->turninto($tmp, $imageSpec)
->close(); ->close();
$filename = $tmp;
} catch (\MediaAlchemyst\Exception $e) { } catch (\MediaAlchemyst\Exception $e) {
} }
@@ -147,12 +152,12 @@ class appbox extends base
$core['file-system']->remove($target); $core['file-system']->remove($target);
} }
if (null === $target || null === $pathfile) { if (null === $target || null === $filename) {
continue; continue;
} }
$core['file-system']->mkdir(dirname($target), 0750); $core['file-system']->mkdir(dirname($target), 0750);
$core['file-system']->copy($pathfile->getPathname(), $target, true); $core['file-system']->copy($filename, $target, true);
$core['file-system']->chmod($target, 0760); $core['file-system']->chmod($target, 0760);
} }
@@ -162,10 +167,11 @@ class appbox extends base
public function write_databox_pic(databox $databox, SymfoFile $pathfile = null, $pic_type) public function write_databox_pic(databox $databox, SymfoFile $pathfile = null, $pic_type)
{ {
$core = \bootstrap::getCore(); $core = \bootstrap::getCore();
$filename = null;
if ( ! is_null($pathfile)) { if ( ! is_null($pathfile)) {
if ( ! in_array(mb_strtolower($pathfile->getMimeType()), array('image/jpeg', 'image/jpg', 'image/pjpeg'))) { if ( ! in_array(mb_strtolower($pathfile->getMimeType()), array('image/jpeg', 'image/jpg', 'image/pjpeg', 'image/png', 'image/gif'))) {
throw new \InvalidArgumentException('Invalid file format'); throw new \InvalidArgumentException('Invalid file format');
} }
} }
@@ -174,6 +180,27 @@ class appbox extends base
throw new \InvalidArgumentException('unknown pic_type'); throw new \InvalidArgumentException('unknown pic_type');
} }
if($pathfile) {
$filename = $pathfile->getPathname();
$imageSpec = new ImageSpecification();
$imageSpec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO);
$imageSpec->setDimensions(120, 35);
$tmp = tempnam(sys_get_temp_dir(), 'tmpdatabox').'.jpg';
try {
$core['media-alchemyst']
->open($pathfile->getPathname())
->turninto($tmp, $imageSpec)
->close();
$filename = $tmp;
} catch (\MediaAlchemyst\Exception $e) {
}
}
$registry = $databox->get_registry(); $registry = $databox->get_registry();
$file = $registry->get('GV_RootPath') . 'config/minilogos/' . $pic_type . '_' . $databox->get_sbas_id(); $file = $registry->get('GV_RootPath') . 'config/minilogos/' . $pic_type . '_' . $databox->get_sbas_id();
$custom_path = $registry->get('GV_RootPath') . 'www/custom/minilogos/' . $pic_type . '_' . $databox->get_sbas_id(); $custom_path = $registry->get('GV_RootPath') . 'www/custom/minilogos/' . $pic_type . '_' . $databox->get_sbas_id();
@@ -184,12 +211,12 @@ class appbox extends base
$core['file-system']->remove($target); $core['file-system']->remove($target);
} }
if (is_null($pathfile)) { if (is_null($filename)) {
continue; continue;
} }
$core['file-system']->mkdir(dirname($target)); $core['file-system']->mkdir(dirname($target));
$core['file-system']->copy($pathfile->getRealPath(), $target); $core['file-system']->copy($filename, $target);
$core['file-system']->chmod($target, 0760); $core['file-system']->chmod($target, 0760);
} }

View File

@@ -42,9 +42,10 @@ $user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) { if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) {
switch ($parm["act"]) { switch ($parm["act"]) {
case "SENDLOGOPDF": case "SENDLOGOPDF":
try {
if (isset($_FILES['newLogoPdf']) && $_FILES['newLogoPdf']['error'] == UPLOAD_ERR_OK) { if (isset($_FILES['newLogoPdf']) && $_FILES['newLogoPdf']['error'] == UPLOAD_ERR_OK) {
if ($_FILES['newLogoPdf']['size'] < 65536) { if ($_FILES['newLogoPdf']['size'] < 65536) {
$appbox->write_databox_pic($databox, new SymfoFile($_FILES['newLogoPdf']["tmp_name"]), databox::PIC_PDF); $appbox->write_databox_pic($databox, new SymfoFile($_FILES['newLogoPdf']["tmp_name"]), \databox::PIC_PDF);
unlink($_FILES['newLogoPdf']["tmp_name"]); unlink($_FILES['newLogoPdf']["tmp_name"]);
} else { } else {
$printLogoUploadMsg = _('forms::erreur lors de l\'envoi du fichier'); $printLogoUploadMsg = _('forms::erreur lors de l\'envoi du fichier');
@@ -52,6 +53,11 @@ if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) {
} else { } else {
$printLogoUploadMsg = _('forms::erreur lors de l\'envoi du fichier'); $printLogoUploadMsg = _('forms::erreur lors de l\'envoi du fichier');
} }
} catch (\InvalidArgumentException $e) {
$printLogoUploadMsg = _('Invalid file format');
} catch (\Exception $e) {
$printLogoUploadMsg = _('forms::erreur lors de l\'envoi du fichier');
}
break; break;
case 'MOUNT': case 'MOUNT':
$appbox->get_connection()->beginTransaction(); $appbox->get_connection()->beginTransaction();
@@ -358,8 +364,8 @@ $out = "";
<div style='margin:3px 0 3px 10px;'> <div style='margin:3px 0 3px 10px;'>
<?php echo(_('admin::base: Alias')) ?> : <span id="viewname"></span> <?php echo(_('admin::base: Alias')) ?> : <span id="viewname"></span>
<?php <?php
if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) { if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) {
?> ?>
<img src='/skins/icons/edit_0.gif' onclick="chgViewName();return(false);" style='vertical-align:middle'/> <img src='/skins/icons/edit_0.gif' onclick="chgViewName();return(false);" style='vertical-align:middle'/>
<?php <?php
@@ -511,7 +517,7 @@ if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) {
<div id='INDEX_P_BAR'> <div id='INDEX_P_BAR'>
<div style='height:30px;'> <div style='height:30px;'>
<div> <div>
<?php echo(_('admin::base: document indexes en utilisant la fiche xml')); ?> : <?php echo(_('admin::base: document indexes en utilisant la fiche xml')); ?> :
<span id='xml_indexed'></span> <span id='xml_indexed'></span>
</div> </div>
<div id='xml_indexed_bar' style='position:absolute;width:0px;height:15px;background:#d4d0c9;z-index:6;'> <div id='xml_indexed_bar' style='position:absolute;width:0px;height:15px;background:#d4d0c9;z-index:6;'>
@@ -521,7 +527,7 @@ if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) {
</div> </div>
<div style='height:30px;'> <div style='height:30px;'>
<div> <div>
<?php echo(_('admin::base: document indexes en utilisant le thesaurus')); ?> : <?php echo(_('admin::base: document indexes en utilisant le thesaurus')); ?> :
<span id='thesaurus_indexed'></span> <span id='thesaurus_indexed'></span>
</div> </div>
<div id='thesaurus_indexed_bar' style='position:absolute;width:0px;height:15px;background:#d4d0c9;z-index:6;'> <div id='thesaurus_indexed_bar' style='position:absolute;width:0px;height:15px;background:#d4d0c9;z-index:6;'>
@@ -530,8 +536,8 @@ if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) {
</div> </div>
</div> </div>
</div> </div>
<?php <?php
if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) { if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) {
?> ?>
<div style='margin:15px 5px 0px 0px;'> <div style='margin:15px 5px 0px 0px;'>
<input type='checkbox' id='is_indexable' onclick='makeIndexable(this)'/> <input type='checkbox' id='is_indexable' onclick='makeIndexable(this)'/>
@@ -655,8 +661,8 @@ if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) {
</a> </a>
</div> </div>
<?php <?php
} }
?> ?>
<!-- minilogo pour print pdf --> <!-- minilogo pour print pdf -->
<div class='logo_boxes'> <div class='logo_boxes'>
@@ -676,21 +682,27 @@ if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) {
<?php echo(_('admin::base:collection: supprimer le logo')) ?> <?php echo(_('admin::base:collection: supprimer le logo')) ?>
</a> </a>
<?php <?php
} }
?> ?>
</div> </div>
<div id='printLogoDIV_NONE' style='margin:0 0 5px 0; display:none'> <div id='printLogoDIV_NONE' style='margin:0 0 5px 0; display:none'>
<?php echo(_('admin::base:collection: aucun fichier (minilogo, watermark ...)')) ?>
<?php
if ( ! file_exists($registry->get('GV_RootPath') . 'config/minilogos/logopdf_' . $databox->get_sbas_id())) {
echo(_('admin::base:collection: aucun fichier (minilogo, watermark ...)'));
} else {
echo '<img style="margin:5px;" src="/custom/minilogos/logopdf_1"/>';
}
?>
<form method="post" name="flpdf" action="./database.php" target="???" onsubmit="return(false);" ENCTYPE="multipart/form-data"> <form method="post" name="flpdf" action="./database.php" target="???" onsubmit="return(false);" ENCTYPE="multipart/form-data">
<input type="hidden" name="p0" value="<?php echo($parm["p0"]); ?>" /> <input type="hidden" name="p0" value="<?php echo($parm["p0"]); ?>" />
<input type="hidden" name="sta" value="\" /> <input type="hidden" name="sta" value="\" />
<input type="hidden" name="srt" value="" /> <input type="hidden" name="srt" value="" />
<input type="hidden" name="act" value="" /> <input type="hidden" name="act" value="" />
<input type="hidden" name="tid" value="" /> <input type="hidden" name="tid" value="" />
<?php <?php
if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) { if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) {
?> ?>
<input name="newLogoPdf" type="file" /> <input name="newLogoPdf" type="file" />
<input type='button' value='<?php echo(_('boutton::envoyer')); ?>' onclick='sendLogopdf();'/> <input type='button' value='<?php echo(_('boutton::envoyer')); ?>' onclick='sendLogopdf();'/>