NEW Can set a squarred icon on your company setup

This commit is contained in:
Laurent Destailleur 2019-10-11 11:27:05 +02:00
parent e7f56b67d8
commit de107fb02e
7 changed files with 182 additions and 72 deletions

View File

@ -105,69 +105,79 @@ if ( ($action == 'update' && ! GETPOST("cancel", 'alpha'))
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOTE", GETPOST("note", 'none'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_GENCOD", GETPOST("barcode", 'alpha'), 'chaine', 0, '', $conf->entity);
$varforimage='logo'; $dirforimage=$conf->mycompany->dir_output.'/logos/';
if ($_FILES[$varforimage]["tmp_name"])
$dirforimage=$conf->mycompany->dir_output.'/logos/';
$arrayofimages = array('logo', 'logo_squarred');
foreach($arrayofimages as $varforimage)
{
if (preg_match('/([^\\/:]+)$/i', $_FILES[$varforimage]["name"], $reg))
if ($_FILES[$varforimage]["tmp_name"])
{
$original_file=$reg[1];
$isimage=image_format_supported($original_file);
if ($isimage >= 0)
$reg = array();
if (preg_match('/([^\\/:]+)$/i', $_FILES[$varforimage]["name"], $reg))
{
dol_syslog("Move file ".$_FILES[$varforimage]["tmp_name"]." to ".$dirforimage.$original_file);
if (! is_dir($dirforimage))
{
dol_mkdir($dirforimage);
}
$result=dol_move_uploaded_file($_FILES[$varforimage]["tmp_name"], $dirforimage.$original_file, 1, 0, $_FILES[$varforimage]['error']);
if ($result > 0)
{
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO", $original_file, 'chaine', 0, '', $conf->entity);
$original_file=$reg[1];
// Create thumbs of logo (Note that PDF use original file and not thumbs)
if ($isimage > 0)
$isimage=image_format_supported($original_file);
if ($isimage >= 0)
{
dol_syslog("Move file ".$_FILES[$varforimage]["tmp_name"]." to ".$dirforimage.$original_file);
if (! is_dir($dirforimage))
{
// Create thumbs
//$object->addThumbs($newfile); // We can't use addThumbs here yet because we need name of generated thumbs to add them into constants. TODO Check if need such constants. We should be able to retreive value with get...
// Create small thumb, Used on logon for example
$imgThumbSmall = vignette($dirforimage.$original_file, $maxwidthsmall, $maxheightsmall, '_small', $quality);
if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i', $imgThumbSmall, $reg))
{
$imgThumbSmall = $reg[1]; // Save only basename
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL", $imgThumbSmall, 'chaine', 0, '', $conf->entity);
}
else dol_syslog($imgThumbSmall);
// Create mini thumb, Used on menu or for setup page for example
$imgThumbMini = vignette($dirforimage.$original_file, $maxwidthmini, $maxheightmini, '_mini', $quality);
if (image_format_supported($imgThumbMini) >= 0 && preg_match('/([^\\/:]+)$/i', $imgThumbMini, $reg))
{
$imgThumbMini = $reg[1]; // Save only basename
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI", $imgThumbMini, 'chaine', 0, '', $conf->entity);
}
else dol_syslog($imgThumbMini);
dol_mkdir($dirforimage);
}
$result=dol_move_uploaded_file($_FILES[$varforimage]["tmp_name"], $dirforimage.$original_file, 1, 0, $_FILES[$varforimage]['error']);
if ($result > 0)
{
$constant = "MAIN_INFO_SOCIETE_LOGO";
if ($varforimage == 'logo_squarred') $constant = "MAIN_INFO_SOCIETE_LOGO_SQUARRED";
dolibarr_set_const($db, $constant, $original_file, 'chaine', 0, '', $conf->entity);
// Create thumbs of logo (Note that PDF use original file and not thumbs)
if ($isimage > 0)
{
// Create thumbs
//$object->addThumbs($newfile); // We can't use addThumbs here yet because we need name of generated thumbs to add them into constants. TODO Check if need such constants. We should be able to retreive value with get...
// Create small thumb, Used on logon for example
$imgThumbSmall = vignette($dirforimage.$original_file, $maxwidthsmall, $maxheightsmall, '_small', $quality);
if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i', $imgThumbSmall, $reg))
{
$imgThumbSmall = $reg[1]; // Save only basename
dolibarr_set_const($db, $constant."_SMALL", $imgThumbSmall, 'chaine', 0, '', $conf->entity);
}
else dol_syslog($imgThumbSmall);
// Create mini thumb, Used on menu or for setup page for example
$imgThumbMini = vignette($dirforimage.$original_file, $maxwidthmini, $maxheightmini, '_mini', $quality);
if (image_format_supported($imgThumbMini) >= 0 && preg_match('/([^\\/:]+)$/i', $imgThumbMini, $reg))
{
$imgThumbMini = $reg[1]; // Save only basename
dolibarr_set_const($db, $constant."_MINI", $imgThumbMini, 'chaine', 0, '', $conf->entity);
}
else dol_syslog($imgThumbMini);
}
else dol_syslog("ErrorImageFormatNotSupported", LOG_WARNING);
} elseif (preg_match('/^ErrorFileIsInfectedWithAVirus/', $result)) {
$error++;
$langs->load("errors");
$tmparray=explode(':', $result);
setEventMessages($langs->trans('ErrorFileIsInfectedWithAVirus', $tmparray[1]), null, 'errors');
}
else
{
$error++;
setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
}
else dol_syslog("ErrorImageFormatNotSupported", LOG_WARNING);
} elseif (preg_match('/^ErrorFileIsInfectedWithAVirus/', $result)) {
$error++;
$langs->load("errors");
$tmparray=explode(':', $result);
setEventMessages($langs->trans('ErrorFileIsInfectedWithAVirus', $tmparray[1]), null, 'errors');
}
else
{
$error++;
setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
$langs->load("errors");
setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors');
}
}
else
{
$error++;
$langs->load("errors");
setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors');
}
}
}
@ -247,7 +257,7 @@ if ( ($action == 'update' && ! GETPOST("cancel", 'alpha'))
}
}
if ($action == 'addthumb') // Regenerate thumbs
if ($action == 'addthumb' || $action == 'addthumbsquarred') // Regenerate thumbs
{
if (file_exists($conf->mycompany->dir_output.'/logos/'.$_GET["file"]))
{
@ -256,15 +266,20 @@ if ($action == 'addthumb') // Regenerate thumbs
// Create thumbs of logo
if ($isimage > 0)
{
$constant = "MAIN_INFO_SOCIETE_LOGO";
if ($action == 'addthumbsquarred') $constant = "MAIN_INFO_SOCIETE_LOGO_SQUARRED";
$reg = array();
// Create thumbs
//$object->addThumbs($newfile); // We can't use addThumbs here yet because we need name of generated thumbs to add them into constants. TODO Check if need such constants. We should be able to retreive value with get...
//$object->addThumbs($newfile); // We can't use addThumbs here yet because we need name of generated thumbs to add them into constants. TODO Check if need such constants. We should be able to retreive value with get...
// Create small thumb. Used on logon for example
$imgThumbSmall = vignette($conf->mycompany->dir_output.'/logos/'.$_GET["file"], $maxwidthsmall, $maxheightsmall, '_small', $quality);
if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i', $imgThumbSmall, $reg))
{
$imgThumbSmall = $reg[1]; // Save only basename
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL", $imgThumbSmall, 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, $constant."_SMALL", $imgThumbSmall, 'chaine', 0, '', $conf->entity);
}
else dol_syslog($imgThumbSmall);
@ -273,7 +288,7 @@ if ($action == 'addthumb') // Regenerate thumbs
if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i', $imgThumbMini, $reg))
{
$imgThumbMini = $reg[1]; // Save only basename
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI", $imgThumbMini, 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, $constant."_MINI", $imgThumbMini, 'chaine', 0, '', $conf->entity);
}
else dol_syslog($imgThumbMini);
@ -297,24 +312,37 @@ if ($action == 'addthumb') // Regenerate thumbs
}
}
if ($action == 'removelogo')
if ($action == 'removelogo' || $action == 'removelogosquarred')
{
$constant = "MAIN_INFO_SOCIETE_LOGO";
if ($action == 'removelogosquarred') $constant = "MAIN_INFO_SOCIETE_LOGO_SQUARRED";
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$logofile=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
if ($mysoc->logo != '') dol_delete_file($logofile);
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO", $conf->entity);
$mysoc->logo='';
$logofilename = $mysoc->logo;
if ($action == 'removelogosquarred') $logofilename = $mysoc->logo_squarred;
$logofile=$conf->mycompany->dir_output.'/logos/'.$logofilename;
if ($logofilename != '') dol_delete_file($logofile);
dolibarr_del_const($db, $constant, $conf->entity);
if ($action == 'removelogosquarred') $mysoc->logo_squarred='';
else $mysoc->logo='';
$logosmallfile=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
if ($mysoc->logo_small != '') dol_delete_file($logosmallfile);
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL", $conf->entity);
$mysoc->logo_small='';
$logofilename = $mysoc->logo_small;
if ($action == 'removelogosquarred') $logofilename = $mysoc->logo_squarred_small;
$logosmallfile=$conf->mycompany->dir_output.'/logos/thumbs/'.$logofilename;
if ($logofilename != '') dol_delete_file($logosmallfile);
dolibarr_del_const($db, $constant."_SMALL", $conf->entity);
if ($action == 'removelogosquarred') $mysoc->logo_squarred_small='';
else $mysoc->logo_small='';
$logominifile=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini;
if ($mysoc->logo_mini != '') dol_delete_file($logominifile);
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI", $conf->entity);
$mysoc->logo_mini='';
$logofilename = $mysoc->logo_mini;
if ($action == 'removelogosquarred') $logofilename = $mysoc->logo_squarred_mini;
$logominifile=$conf->mycompany->dir_output.'/logos/thumbs/'.$logofilename;
if ($logofilename != '') dol_delete_file($logominifile);
dolibarr_del_const($db, $constant."_MINI", $conf->entity);
if ($action == 'removelogosquarred') $mysoc->logo_squarred_mini='';
else $mysoc->logo_mini='';
}
@ -434,7 +462,7 @@ if ($action == 'edit' || $action == 'updateedit')
// Logo
print '<tr class="oddeven"><td><label for="logo">'.$langs->trans("Logo").' (png,jpg)</label></td><td>';
print '<table width="100%" class="nobordernopadding"><tr class="nocellnopadd"><td valign="middle" class="nocellnopadd">';
print '<input type="file" class="flat class=minwidth200" name="logo" id="logo" accept="image/*">';
print '<input type="file" class="flat minwidth200" name="logo" id="logo" accept="image/*">';
print '</td><td class="nocellnopadd right" valign="middle">';
if (! empty($mysoc->logo_mini)) {
print '<a href="'.$_SERVER["PHP_SELF"].'?action=removelogo">'.img_delete($langs->trans("Delete")).'</a>';
@ -448,6 +476,23 @@ if ($action == 'edit' || $action == 'updateedit')
print '</td></tr></table>';
print '</td></tr>';
// Logo (squarred)
print '<tr class="oddeven"><td><label for="logo_squarred">'.$langs->trans("LogoSquarred").' (png,jpg)</label></td><td>';
print '<table width="100%" class="nobordernopadding"><tr class="nocellnopadd"><td valign="middle" class="nocellnopadd">';
print '<input type="file" class="flat minwidth200" name="logo_squarred" id="logo_squarred" accept="image/*">';
print '</td><td class="nocellnopadd right" valign="middle">';
if (! empty($mysoc->logo_squarred_mini)) {
print '<a href="'.$_SERVER["PHP_SELF"].'?action=removelogosquarred">'.img_delete($langs->trans("Delete")).'</a>';
if (file_exists($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_squarred_mini)) {
print ' &nbsp; ';
print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_squarred_mini).'">';
}
} else {
print '<img height="30" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png">';
}
print '</td></tr></table>';
print '</td></tr>';
// Note
print '<tr class="oddeven"><td class="tdtop"><label for="note">'.$langs->trans("Note").'</label></td><td>';
print '<textarea class="flat quatrevingtpercent" name="note" id="note" rows="'.ROWS_5.'">'.(GETPOST('note', 'none') ? GETPOST('note', 'none') : $conf->global->MAIN_INFO_SOCIETE_NOTE).'</textarea></td></tr>';
@ -829,7 +874,7 @@ else
// Logo
print '<tr class="oddeven"><td>'.$langs->trans("Logo").'</td><td>';
print '<tr class="oddeven"><td>'.$form->textwithpicto($langs->trans("Logo"), $langs->trans("LogoDesc")).'</td><td>';
$tagtd='tagtd ';
if ($conf->browser->layout == 'phone') $tagtd='';
@ -854,7 +899,34 @@ else
print '</td></tr>';
// Logo (squarred)
print '<tr class="oddeven"><td>'.$form->textwithpicto($langs->trans("LogoSquarred"), $langs->trans("LogoSquarredDesc")).'</td><td>';
$tagtd='tagtd ';
if ($conf->browser->layout == 'phone') $tagtd='';
print '<div class="tagtable centpercent"><div class="tagtr inline-block centpercent valignmiddle"><div class="'.$tagtd.'inline-block valignmiddle left">';
print $mysoc->logo_squarred;
print '</div><div class="'.$tagtd.'inline-block valignmiddle left">';
// It offers the generation of the thumbnail if it does not exist
if (!is_file($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_squarred_mini) && preg_match('/(\.jpg|\.jpeg|\.png)$/i', $mysoc->logo_squarred))
{
print '<a class="img_logo" href="'.$_SERVER["PHP_SELF"].'?action=addthumbsquarred&amp;file='.urlencode($mysoc->logo_squarred).'">'.img_picto($langs->trans('GenerateThumb'), 'refresh').'</a>&nbsp;&nbsp;';
}
elseif ($mysoc->logo_squarred_mini && is_file($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_squarred_mini))
{
print '<img class="img_logo" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_squarred_mini).'">';
}
else
{
print '<img class="img_logo" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png">';
}
print '</div></div></div>';
print '</td></tr>';
// Note
print '<tr class="oddeven"><td class="tdtop">'.$langs->trans("Note").'</td><td>' . (! empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ? nl2br($conf->global->MAIN_INFO_SOCIETE_NOTE) : '') . '</td></tr>';
print '</table>';

View File

@ -76,6 +76,8 @@ ALTER TABLE llx_holiday_extrafields ADD INDEX idx_holiday_extrafields (fk_object
ALTER TABLE llx_societe_rib MODIFY label varchar(200);
ALTER TABLE llx_societe ADD COLUMN logo_squarred varchar(255);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('USER_SENTBYMAIL','Email sent','Executed when an email is sent from user card','user',300);
create table llx_entrepot_extrafields

View File

@ -107,6 +107,7 @@ create table llx_societe
supplier_order_min_amount double(24,8) DEFAULT NULL, -- min amount for supplier orders
default_lang varchar(6), -- default language
logo varchar(255) DEFAULT NULL,
logo_squarred varchar(255) DEFAULT NULL,
canvas varchar(32) DEFAULT NULL, -- type of canvas if used (null by default)
fk_entrepot integer DEFAULT 0, -- if we need a link between third party and warehouse
webservices_url varchar(255), -- supplier webservice url

View File

@ -1070,6 +1070,9 @@ CompanyCountry=Country
CompanyCurrency=Main currency
CompanyObject=Object of the company
Logo=Logo
LogoDesc=Main logo of company. Will be used into generated documents (PDF, ...)
LogoSquarred=Logo (squarred)
LogoSquarredDesc=Must be a squarred icon (width = height). This logo will be used as the favorite icon or other need like for the top menu bar (if not disabled into disaply setup).
DoNotSuggestPaymentMode=Do not suggest
NoActiveBankAccountDefined=No active bank account defined
OwnerOfBankAccount=Owner of bank account %s

View File

@ -465,6 +465,9 @@ class Societe extends CommonObject
public $logo;
public $logo_small;
public $logo_mini;
public $logo_squarred;
public $logo_squarred_small;
public $logo_squarred_mini;
public $array_options;
@ -1072,6 +1075,7 @@ class Societe extends CommonObject
$sql .= ",barcode = ".(! empty($this->barcode)?"'".$this->db->escape($this->barcode)."'":"null");
$sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->db->escape($this->default_lang)."'":"null");
$sql .= ",logo = ".(! empty($this->logo)?"'".$this->db->escape($this->logo)."'":"null");
$sql .= ",logo_squarred = ".(! empty($this->logo_squarred)?"'".$this->db->escape($this->logo_squarred)."'":"null");
$sql .= ",outstanding_limit= ".($this->outstanding_limit!=''?$this->outstanding_limit:'null');
$sql .= ",order_min_amount= ".($this->order_min_amount!=''?$this->order_min_amount:'null');
$sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount!=''?$this->supplier_order_min_amount:'null');
@ -1266,7 +1270,7 @@ class Societe extends CommonObject
$sql .= ', s.webservices_url, s.webservices_key';
$sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode';
$sql .= ', s.fk_departement as state_id, s.fk_pays as country_id, s.fk_stcomm, s.remise_supplier, s.mode_reglement, s.cond_reglement, s.fk_account, s.tva_assuj';
$sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo';
$sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred';
$sql .= ', s.fk_shipping_method';
$sql .= ', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
$sql .= ', s.order_min_amount, s.supplier_order_min_amount';
@ -1420,6 +1424,7 @@ class Societe extends CommonObject
$this->modelpdf = $obj->model_pdf;
$this->default_lang = $obj->default_lang;
$this->logo = $obj->logo;
$this->logo_squarred = $obj->logo_squarred;
$this->webservices_url = $obj->webservices_url;
$this->webservices_key = $obj->webservices_key;
@ -2110,6 +2115,12 @@ class Societe extends CommonObject
$label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
$label.= '</div><div style="clear: both;"></div>';
}
elseif (! empty($this->logo_squarred) && class_exists('Form'))
{
/*$label.= '<div class="photointooltip">';
$label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
$label.= '</div><div style="clear: both;"></div>';*/
}
$label.= '<div class="centpercent">';
@ -3522,6 +3533,9 @@ class Societe extends CommonObject
$this->logo=empty($conf->global->MAIN_INFO_SOCIETE_LOGO)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO;
$this->logo_small=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
$this->logo_mini=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
$this->logo_squarred=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED;
$this->logo_squarred_small=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL;
$this->logo_squarred_mini=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI;
// Define if company use vat or not
$this->tva_assuj=$conf->global->FACTURE_TVAOPTION;

View File

@ -902,6 +902,17 @@ table[summary="list_of_modules"] .fa-cog {
font-size: <?php print is_numeric($fontsize) ? ($fontsize+3).'px' : $fontsize; ?> !important;
}
div#login_left, div#login_right {
min-width: 150px !important;
max-width: 200px !important;
padding-left: 5px !important;
padding-right: 5px !important;
}
div.login_block {
height: 64px !important;
}
.divmainbodylarge { margin-left: 20px !important; margin-right: 20px !important; }
.tdoverflowonsmartphone {
@ -923,11 +934,14 @@ table[summary="list_of_modules"] .fa-cog {
padding-bottom: 5px;
}
.login_table .tdinputlogin {
min-width: unset !important;
}
input, input[type=text], input[type=password], select, textarea {
min-width: 20px;
}
.trinputlogin input[type=text], input[type=password] {
max-width: 180px;
max-width: 140px;
}
.vmenu .searchform input {
max-width: 138px; /* length of input text in the quick search box when using a smartphone and without dolidroid */

View File

@ -1061,6 +1061,10 @@ table[summary="list_of_modules"] .fa-cog {
font-size: <?php print $fontsize+3; ?>px !important;
}
.login_vertical_align {
padding-left: 0;
}
.divmainbodylarge { margin-left: 20px; margin-right: 20px; }
.tdoverflowonsmartphone {