Merge pull request #12636 from Dolibarr/scrutinizer-patch-18

Scrutinizer Auto-Fixes
This commit is contained in:
Laurent Destailleur 2019-12-06 16:22:07 +01:00 committed by GitHub
commit a489e7ff8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 207 additions and 207 deletions

View File

@ -923,7 +923,7 @@ else
$cats = $c->containing($object->id, Categorie::TYPE_ACCOUNT); $cats = $c->containing($object->id, Categorie::TYPE_ACCOUNT);
if (is_array($cats)) if (is_array($cats))
{ {
foreach($cats as $cat) { foreach ($cats as $cat) {
$arrayselected[] = $cat->id; $arrayselected[] = $cat->id;
} }
} }

View File

@ -66,41 +66,41 @@ class DolEditor
*/ */
public function __construct($htmlname, $content, $width = '', $height = 200, $toolbarname = 'Basic', $toolbarlocation = 'In', $toolbarstartexpanded = false, $uselocalbrowser = true, $okforextendededitor = true, $rows = 0, $cols = 0, $readonly = 0) public function __construct($htmlname, $content, $width = '', $height = 200, $toolbarname = 'Basic', $toolbarlocation = 'In', $toolbarstartexpanded = false, $uselocalbrowser = true, $okforextendededitor = true, $rows = 0, $cols = 0, $readonly = 0)
{ {
global $conf,$langs; global $conf, $langs;
dol_syslog(get_class($this)."::DolEditor htmlname=".$htmlname." width=".$width." height=".$height." toolbarname=".$toolbarname); dol_syslog(get_class($this)."::DolEditor htmlname=".$htmlname." width=".$width." height=".$height." toolbarname=".$toolbarname);
if (! $rows) $rows=round($height/20); if (!$rows) $rows = round($height / 20);
if (! $cols) $cols=($width?round($width/6):80); if (!$cols) $cols = ($width ?round($width / 6) : 80);
$shorttoolbarname=preg_replace('/_encoded$/', '', $toolbarname); $shorttoolbarname = preg_replace('/_encoded$/', '', $toolbarname);
// Name of extended editor to use (FCKEDITOR_EDITORNAME can be 'ckeditor' or 'fckeditor') // Name of extended editor to use (FCKEDITOR_EDITORNAME can be 'ckeditor' or 'fckeditor')
$defaulteditor='ckeditor'; $defaulteditor = 'ckeditor';
$this->tool=empty($conf->global->FCKEDITOR_EDITORNAME)?$defaulteditor:$conf->global->FCKEDITOR_EDITORNAME; $this->tool = empty($conf->global->FCKEDITOR_EDITORNAME) ? $defaulteditor : $conf->global->FCKEDITOR_EDITORNAME;
$this->uselocalbrowser=$uselocalbrowser; $this->uselocalbrowser = $uselocalbrowser;
$this->readonly=$readonly; $this->readonly = $readonly;
// Check if extended editor is ok. If not we force textarea // Check if extended editor is ok. If not we force textarea
if ((empty($conf->fckeditor->enabled) && $okforextendededitor != 'ace') || empty($okforextendededitor)) $this->tool = 'textarea'; if ((empty($conf->fckeditor->enabled) && $okforextendededitor != 'ace') || empty($okforextendededitor)) $this->tool = 'textarea';
if ($okforextendededitor === 'ace') $this->tool='ace'; if ($okforextendededitor === 'ace') $this->tool = 'ace';
//if ($conf->dol_use_jmobile) $this->tool = 'textarea'; // ckeditor and ace seems ok with mobile //if ($conf->dol_use_jmobile) $this->tool = 'textarea'; // ckeditor and ace seems ok with mobile
// Define content and some properties // Define content and some properties
if ($this->tool == 'ckeditor') if ($this->tool == 'ckeditor')
{ {
$content=dol_htmlentitiesbr($content); // If content is not HTML, we convert to HTML. $content = dol_htmlentitiesbr($content); // If content is not HTML, we convert to HTML.
} }
if ($this->tool == 'fckeditor') if ($this->tool == 'fckeditor')
{ {
require_once DOL_DOCUMENT_ROOT.'/includes/fckeditor/fckeditor.php'; require_once DOL_DOCUMENT_ROOT.'/includes/fckeditor/fckeditor.php';
$content=dol_htmlentitiesbr($content); // If content is not HTML, we convert to HTML. $content = dol_htmlentitiesbr($content); // If content is not HTML, we convert to HTML.
$this->editor = new FCKeditor($htmlname); $this->editor = new FCKeditor($htmlname);
$this->editor->BasePath = DOL_URL_ROOT.'/includes/fckeditor/' ; $this->editor->BasePath = DOL_URL_ROOT.'/includes/fckeditor/';
$this->editor->Value = $content; $this->editor->Value = $content;
$this->editor->Height = $height; $this->editor->Height = $height;
if (! empty($width)) $this->editor->Width = $width; if (!empty($width)) $this->editor->Width = $width;
$this->editor->ToolbarSet = $shorttoolbarname; // Profile of this toolbar set is deinfed into theme/mytheme/ckeditor/config.js $this->editor->ToolbarSet = $shorttoolbarname; // Profile of this toolbar set is deinfed into theme/mytheme/ckeditor/config.js
$this->editor->Config['AutoDetectLanguage'] = 'true'; // Language of user (browser) $this->editor->Config['AutoDetectLanguage'] = 'true'; // Language of user (browser)
$this->editor->Config['ToolbarLocation'] = $toolbarlocation ? $toolbarlocation : 'In'; $this->editor->Config['ToolbarLocation'] = $toolbarlocation ? $toolbarlocation : 'In';
@ -109,12 +109,12 @@ class DolEditor
// Rem: Le forcage de ces 2 parametres ne semble pas fonctionner. // Rem: Le forcage de ces 2 parametres ne semble pas fonctionner.
// Dolibarr utilise toujours liens avec modulepart='fckeditor' quelque soit modulepart. // Dolibarr utilise toujours liens avec modulepart='fckeditor' quelque soit modulepart.
// Ou se trouve donc cette valeur /viewimage.php?modulepart=fckeditor&file=' ? // Ou se trouve donc cette valeur /viewimage.php?modulepart=fckeditor&file=' ?
$modulepart='fckeditor'; $modulepart = 'fckeditor';
$this->editor->Config['UserFilesPath'] = '/viewimage.php?modulepart='.$modulepart.'&entity='.$conf->entity.'&file='; $this->editor->Config['UserFilesPath'] = '/viewimage.php?modulepart='.$modulepart.'&entity='.$conf->entity.'&file=';
$this->editor->Config['UserFilesAbsolutePath'] = DOL_DATA_ROOT.'/'.$modulepart.'/' ; $this->editor->Config['UserFilesAbsolutePath'] = DOL_DATA_ROOT.'/'.$modulepart.'/';
$this->editor->Config['LinkBrowser']=($uselocalbrowser?'true':'false'); $this->editor->Config['LinkBrowser'] = ($uselocalbrowser ? 'true' : 'false');
$this->editor->Config['ImageBrowser']=($uselocalbrowser?'true':'false'); $this->editor->Config['ImageBrowser'] = ($uselocalbrowser ? 'true' : 'false');
if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/fckeditor/fckconfig.js')) if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/fckeditor/fckconfig.js'))
{ {
@ -124,14 +124,14 @@ class DolEditor
} }
// Define some properties // Define some properties
if (in_array($this->tool, array('textarea','ckeditor','ace'))) if (in_array($this->tool, array('textarea', 'ckeditor', 'ace')))
{ {
$this->content = $content; $this->content = $content;
$this->htmlname = $htmlname; $this->htmlname = $htmlname;
$this->toolbarname = $shorttoolbarname; $this->toolbarname = $shorttoolbarname;
$this->toolbarstartexpanded = $toolbarstartexpanded; $this->toolbarstartexpanded = $toolbarstartexpanded;
$this->rows = max(ROWS_3, $rows); $this->rows = max(ROWS_3, $rows);
$this->cols = (preg_match('/%/', $cols)?$cols:max(40, $cols)); // If $cols is a percent, we keep it, otherwise, we take max $this->cols = (preg_match('/%/', $cols) ? $cols : max(40, $cols)); // If $cols is a percent, we keep it, otherwise, we take max
$this->height = $height; $this->height = $height;
$this->width = $width; $this->width = $width;
} }
@ -152,45 +152,45 @@ class DolEditor
public function Create($noprint = 0, $morejs = '', $disallowAnyContent = true, $titlecontent = '', $option = '') public function Create($noprint = 0, $morejs = '', $disallowAnyContent = true, $titlecontent = '', $option = '')
{ {
// phpcs:enable // phpcs:enable
global $conf,$langs; global $conf, $langs;
$fullpage=false; $fullpage = false;
if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT)) if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT))
{ {
$disallowAnyContent=empty($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT); // Only predefined list of html tags are allowed or all $disallowAnyContent = empty($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT); // Only predefined list of html tags are allowed or all
} }
$found=0; $found = 0;
$out=''; $out = '';
if ($this->tool == 'fckeditor') // not used anymore if ($this->tool == 'fckeditor') // not used anymore
{ {
$found=1; $found = 1;
$this->editor->Create(); $this->editor->Create();
} }
if (in_array($this->tool, array('textarea','ckeditor'))) if (in_array($this->tool, array('textarea', 'ckeditor')))
{ {
$found=1; $found = 1;
//$out.= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" '.($this->readonly?' disabled':'').' rows="'.$this->rows.'"'.(preg_match('/%/',$this->cols)?' style="margin-top: 5px; width: '.$this->cols.'"':' cols="'.$this->cols.'"').' class="flat">'; //$out.= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" '.($this->readonly?' disabled':'').' rows="'.$this->rows.'"'.(preg_match('/%/',$this->cols)?' style="margin-top: 5px; width: '.$this->cols.'"':' cols="'.$this->cols.'"').' class="flat">';
// TODO We do not put the disabled tag because on a read form, it change style with grey. // TODO We do not put the disabled tag because on a read form, it change style with grey.
$out.= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" rows="'.$this->rows.'"'.(preg_match('/%/', $this->cols)?' style="margin-top: 5px; width: '.$this->cols.'"':' cols="'.$this->cols.'"').' class="flat">'; $out .= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" rows="'.$this->rows.'"'.(preg_match('/%/', $this->cols) ? ' style="margin-top: 5px; width: '.$this->cols.'"' : ' cols="'.$this->cols.'"').' class="flat">';
$out.= htmlspecialchars($this->content); $out .= htmlspecialchars($this->content);
$out.= '</textarea>'; $out .= '</textarea>';
if ($this->tool == 'ckeditor' && ! empty($conf->use_javascript_ajax) && ! empty($conf->fckeditor->enabled)) if ($this->tool == 'ckeditor' && !empty($conf->use_javascript_ajax) && !empty($conf->fckeditor->enabled))
{ {
if (! defined('REQUIRE_CKEDITOR')) define('REQUIRE_CKEDITOR', '1'); if (!defined('REQUIRE_CKEDITOR')) define('REQUIRE_CKEDITOR', '1');
if (! empty($conf->global->FCKEDITOR_SKIN)) { if (!empty($conf->global->FCKEDITOR_SKIN)) {
$skin = $conf->global->FCKEDITOR_SKIN; $skin = $conf->global->FCKEDITOR_SKIN;
} else { } else {
$skin = 'moono-lisa'; // default with ckeditor 4.6 : moono-lisa $skin = 'moono-lisa'; // default with ckeditor 4.6 : moono-lisa
} }
$htmlencode_force=preg_match('/_encoded$/', $this->toolbarname)?'true':'false'; $htmlencode_force = preg_match('/_encoded$/', $this->toolbarname) ? 'true' : 'false';
$out.= '<!-- Output ckeditor $disallowAnyContent='.$disallowAnyContent.' toolbarname='.$this->toolbarname.' -->'."\n"; $out .= '<!-- Output ckeditor $disallowAnyContent='.$disallowAnyContent.' toolbarname='.$this->toolbarname.' -->'."\n";
$out.= '<script type="text/javascript"> $out .= '<script type="text/javascript">
$(document).ready(function () { $(document).ready(function () {
/* console.log("Run ckeditor"); */ /* console.log("Run ckeditor"); */
/* if (CKEDITOR.loadFullCore) CKEDITOR.loadFullCore(); */ /* if (CKEDITOR.loadFullCore) CKEDITOR.loadFullCore(); */
@ -199,11 +199,11 @@ class DolEditor
{ {
/* property:xxx is same than CKEDITOR.config.property = xxx */ /* property:xxx is same than CKEDITOR.config.property = xxx */
customConfig : ckeditorConfig, customConfig : ckeditorConfig,
readOnly : '.($this->readonly?'true':'false').', readOnly : '.($this->readonly ? 'true' : 'false').',
htmlEncodeOutput :'.$htmlencode_force.', htmlEncodeOutput :'.$htmlencode_force.',
allowedContent :'.($disallowAnyContent?'false':'true').', allowedContent :'.($disallowAnyContent ? 'false' : 'true').',
extraAllowedContent : \'\', extraAllowedContent : \'\',
fullPage : '.($fullpage?'true':'false').', fullPage : '.($fullpage ? 'true' : 'false').',
toolbar: \''.$this->toolbarname.'\', toolbar: \''.$this->toolbarname.'\',
toolbarStartupExpanded: '.($this->toolbarstartexpanded ? 'true' : 'false').', toolbarStartupExpanded: '.($this->toolbarstartexpanded ? 'true' : 'false').',
width: '.($this->width ? '\''.$this->width.'\'' : '\'\'').', width: '.($this->width ? '\''.$this->width.'\'' : '\'\'').',
@ -229,13 +229,13 @@ class DolEditor
if ($this->uselocalbrowser) if ($this->uselocalbrowser)
{ {
$out.= ','."\n"; $out .= ','."\n";
// To use filemanager with old fckeditor (GPL) // To use filemanager with old fckeditor (GPL)
$out.= ' filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,'; $out .= ' filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,';
$out.= ' filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,'; $out .= ' filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,';
//$out.= ' filebrowserUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=File\','; //$out.= ' filebrowserUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=File\',';
//$out.= ' filebrowserImageUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=Image\','; //$out.= ' filebrowserImageUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=Image\',';
$out.= "\n"; $out .= "\n";
// To use filemanager with ckfinder (Non free) and ckfinder directory is inside htdocs/includes // To use filemanager with ckfinder (Non free) and ckfinder directory is inside htdocs/includes
/* $out.= ' filebrowserBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html\', /* $out.= ' filebrowserBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html\',
filebrowserImageBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html?Type=Images\', filebrowserImageBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html?Type=Images\',
@ -244,14 +244,14 @@ class DolEditor
filebrowserImageUploadUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images\', filebrowserImageUploadUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images\',
filebrowserFlashUploadUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash\','."\n"; filebrowserFlashUploadUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash\','."\n";
*/ */
$out.= ' filebrowserWindowWidth : \'900\', $out .= ' filebrowserWindowWidth : \'900\',
filebrowserWindowHeight : \'500\', filebrowserWindowHeight : \'500\',
filebrowserImageWindowWidth : \'900\', filebrowserImageWindowWidth : \'900\',
filebrowserImageWindowHeight : \'500\''; filebrowserImageWindowHeight : \'500\'';
} }
$out.= ' })'.$morejs; $out .= ' })'.$morejs;
$out.= '});'."\n"; $out .= '});'."\n";
$out.= '</script>'."\n"; $out .= '</script>'."\n";
} }
} }
@ -259,19 +259,19 @@ class DolEditor
// Warning: ace.js and ext-statusbar.js must be loaded by the parent page. // Warning: ace.js and ext-statusbar.js must be loaded by the parent page.
if (preg_match('/^ace/', $this->tool)) if (preg_match('/^ace/', $this->tool))
{ {
$found=1; $found = 1;
$format=$option; $format = $option;
$out.= "\n".'<!-- Output Ace editor -->'."\n"; $out .= "\n".'<!-- Output Ace editor -->'."\n";
if ($titlecontent) if ($titlecontent)
{ {
$out.= '<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.'">'.$titlecontent; $out .= '<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.'">'.$titlecontent;
$out.= ' &nbsp; - &nbsp; <a id="morelines" href="#" class="right morelines'.$this->htmlname.' reposition">'.dol_escape_htmltag($langs->trans("ShowMoreLines")).'</a> &nbsp; &nbsp; '; $out .= ' &nbsp; - &nbsp; <a id="morelines" href="#" class="right morelines'.$this->htmlname.' reposition">'.dol_escape_htmltag($langs->trans("ShowMoreLines")).'</a> &nbsp; &nbsp; ';
$out.= '</div>'; $out .= '</div>';
$out.= '<script type="text/javascript" language="javascript">'."\n"; $out .= '<script type="text/javascript" language="javascript">'."\n";
$out.= 'jQuery(document).ready(function() {'."\n"; $out .= 'jQuery(document).ready(function() {'."\n";
$out.= ' var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid"); $out .= ' var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid");
var StatusBar = window.ace.require("ace/ext/statusbar").StatusBar; // Init status bar. Need lib ext-statusbar var StatusBar = window.ace.require("ace/ext/statusbar").StatusBar; // Init status bar. Need lib ext-statusbar
var statusBar = new StatusBar(aceEditor, document.getElementById("statusBar'.$this->htmlname.'")); // Init status bar. Need lib ext-statusbar var statusBar = new StatusBar(aceEditor, document.getElementById("statusBar'.$this->htmlname.'")); // Init status bar. Need lib ext-statusbar
var oldNbOfLines = 0 var oldNbOfLines = 0
@ -293,21 +293,21 @@ class DolEditor
} }
}); });
})'; })';
$out.= '</script>'."\n"; $out .= '</script>'."\n";
} }
$out.= '<pre id="'.$this->htmlname.'aceeditorid" style="'.($this->width?'width: '.$this->width.'px; ':''); $out .= '<pre id="'.$this->htmlname.'aceeditorid" style="'.($this->width ? 'width: '.$this->width.'px; ' : '');
$out.= ($this->height?' height: '.$this->height.'px; ':''); $out .= ($this->height ? ' height: '.$this->height.'px; ' : '');
//$out.=" min-height: 100px;"; //$out.=" min-height: 100px;";
$out.= '">'; $out .= '">';
$out.= htmlspecialchars($this->content); $out .= htmlspecialchars($this->content);
$out.= '</pre>'; $out .= '</pre>';
$out.= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" style="width:0px; height: 0px; display: none;">'; $out .= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" style="width:0px; height: 0px; display: none;">';
$out.= htmlspecialchars($this->content); $out .= htmlspecialchars($this->content);
$out.= '</textarea>'; $out .= '</textarea>';
$out.= '<script type="text/javascript" language="javascript">'."\n"; $out .= '<script type="text/javascript" language="javascript">'."\n";
$out.= 'var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid"); $out .= 'var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid");
aceEditor.session.setMode("ace/mode/'.$format.'"); aceEditor.session.setMode("ace/mode/'.$format.'");
aceEditor.setOptions({ aceEditor.setOptions({
@ -315,7 +315,7 @@ class DolEditor
enableLiveAutocompletion: false, // the editor completes the statement while you are typing. Need lib ext-language_tools.js enableLiveAutocompletion: false, // the editor completes the statement while you are typing. Need lib ext-language_tools.js
showPrintMargin: false, // hides the vertical limiting strip showPrintMargin: false, // hides the vertical limiting strip
minLines: 10, minLines: 10,
maxLines: '.(empty($this->height)?'34':(round($this->height/10))).', maxLines: '.(empty($this->height) ? '34' : (round($this->height / 10))).',
fontSize: "110%" // ensures that the editor fits in the environment fontSize: "110%" // ensures that the editor fits in the environment
}); });
@ -327,7 +327,7 @@ class DolEditor
//aceEditor.getSession().setMode("ace/mode/javascript_expression"); //aceEditor.getSession().setMode("ace/mode/javascript_expression");
'."\n"; '."\n";
$out.= 'jQuery(document).ready(function() { $out .= 'jQuery(document).ready(function() {
jQuery(".buttonforacesave").click(function() { jQuery(".buttonforacesave").click(function() {
console.log("We click on savefile button for component '.$this->htmlname.'"); console.log("We click on savefile button for component '.$this->htmlname.'");
var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid") var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid")
@ -337,12 +337,12 @@ class DolEditor
else return false;*/ else return false;*/
}); });
})'; })';
$out.= '</script>'."\n"; $out .= '</script>'."\n";
} }
if (empty($found)) if (empty($found))
{ {
$out.= 'Error, unknown value for tool '.$this->tool.' in DolEditor Create function.'; $out .= 'Error, unknown value for tool '.$this->tool.' in DolEditor Create function.';
} }
if ($noprint) return $out; if ($noprint) return $out;

View File

@ -376,33 +376,33 @@ class FormTicket
} }
$out = '<tr>'; $out = '<tr>';
$out .= '<td>' . $langs->trans("MailFile") . '</td>'; $out .= '<td>'.$langs->trans("MailFile").'</td>';
$out .= '<td>'; $out .= '<td>';
// TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
$out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">' . "\n"; $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
$out .= '<script type="text/javascript" language="javascript">'; $out .= '<script type="text/javascript" language="javascript">';
$out .= 'jQuery(document).ready(function () {'; $out .= 'jQuery(document).ready(function () {';
$out .= ' jQuery(".removedfile").click(function() {'; $out .= ' jQuery(".removedfile").click(function() {';
$out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());'; $out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
$out .= ' });'; $out .= ' });';
$out .= '})'; $out .= '})';
$out .= '</script>' . "\n"; $out .= '</script>'."\n";
if (count($listofpaths)) { if (count($listofpaths)) {
foreach ($listofpaths as $key => $val) { foreach ($listofpaths as $key => $val) {
$out .= '<div id="attachfile_' . $key . '">'; $out .= '<div id="attachfile_'.$key.'">';
$out .= img_mime($listofnames[$key]) . ' ' . $listofnames[$key]; $out .= img_mime($listofnames[$key]).' '.$listofnames[$key];
if (!$this->withfilereadonly) { if (!$this->withfilereadonly) {
$out .= ' <input type="image" style="border: 0px;" src="' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/delete.png" value="' . ($key + 1) . '" class="removedfile" id="removedfile_' . $key . '" name="removedfile_' . $key . '" />'; $out .= ' <input type="image" style="border: 0px;" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/delete.png" value="'.($key + 1).'" class="removedfile" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />';
} }
$out .= '<br></div>'; $out .= '<br></div>';
} }
} else { } else {
$out .= $langs->trans("NoAttachedFiles") . '<br>'; $out .= $langs->trans("NoAttachedFiles").'<br>';
} }
if ($this->withfile == 2) { // Can add other files if ($this->withfile == 2) { // Can add other files
$out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="' . $langs->trans("Upload") . '" />'; $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
$out .= ' '; $out .= ' ';
$out .= '<input type="submit" class="button" id="addfile" name="addfile" value="' . $langs->trans("MailingAddFile") . '" />'; $out .= '<input type="submit" class="button" id="addfile" name="addfile" value="'.$langs->trans("MailingAddFile").'" />';
} }
$out .= "</td></tr>\n"; $out .= "</td></tr>\n";

View File

@ -23,8 +23,8 @@
*/ */
// Define size of logo small and mini // Define size of logo small and mini
$maxwidthsmall=270;$maxheightsmall=150; $maxwidthsmall = 270; $maxheightsmall = 150;
$maxwidthmini=128;$maxheightmini=72; $maxwidthmini = 128; $maxheightmini = 72;
$quality = 80; $quality = 80;
@ -37,14 +37,14 @@ $quality = 80;
*/ */
function image_format_supported($file) function image_format_supported($file)
{ {
$regeximgext='\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.xpm|\.xbm|\.svg'; // See also into product.class.php $regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.xpm|\.xbm|\.svg'; // See also into product.class.php
// Case filename is not a format image // Case filename is not a format image
$reg = array(); $reg = array();
if (! preg_match('/('.$regeximgext.')$/i', $file, $reg)) return -1; if (!preg_match('/('.$regeximgext.')$/i', $file, $reg)) return -1;
// Case filename is a format image but not supported by this PHP // Case filename is a format image but not supported by this PHP
$imgfonction=''; $imgfonction = '';
if (strtolower($reg[1]) == '.gif') $imgfonction = 'imagecreatefromgif'; if (strtolower($reg[1]) == '.gif') $imgfonction = 'imagecreatefromgif';
if (strtolower($reg[1]) == '.png') $imgfonction = 'imagecreatefrompng'; if (strtolower($reg[1]) == '.png') $imgfonction = 'imagecreatefrompng';
if (strtolower($reg[1]) == '.jpg') $imgfonction = 'imagecreatefromjpeg'; if (strtolower($reg[1]) == '.jpg') $imgfonction = 'imagecreatefromjpeg';
@ -55,7 +55,7 @@ function image_format_supported($file)
if (strtolower($reg[1]) == '.svg') $imgfonction = 'imagecreatefromsvg'; // Never available if (strtolower($reg[1]) == '.svg') $imgfonction = 'imagecreatefromsvg'; // Never available
if ($imgfonction) if ($imgfonction)
{ {
if (! function_exists($imgfonction)) if (!function_exists($imgfonction))
{ {
// Fonctions de conversion non presente dans ce PHP // Fonctions de conversion non presente dans ce PHP
return 0; return 0;
@ -76,7 +76,7 @@ function image_format_supported($file)
*/ */
function dol_getImageSize($file, $url = false) function dol_getImageSize($file, $url = false)
{ {
$ret=array(); $ret = array();
if (image_format_supported($file) < 0) return $ret; if (image_format_supported($file) < 0) return $ret;
@ -89,8 +89,8 @@ function dol_getImageSize($file, $url = false)
if ($filetoread) if ($filetoread)
{ {
$infoImg = getimagesize($filetoread); // Recuperation des infos de l'image $infoImg = getimagesize($filetoread); // Recuperation des infos de l'image
$ret['width']=$infoImg[0]; // Largeur de l'image $ret['width'] = $infoImg[0]; // Largeur de l'image
$ret['height']=$infoImg[1]; // Hauteur de l'image $ret['height'] = $infoImg[1]; // Hauteur de l'image
} }
return $ret; return $ret;
@ -112,29 +112,29 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
global $conf,$langs; global $conf, $langs;
dol_syslog("dol_imageResizeOrCrop file=".$file." mode=".$mode." newWidth=".$newWidth." newHeight=".$newHeight." src_x=".$src_x." src_y=".$src_y); dol_syslog("dol_imageResizeOrCrop file=".$file." mode=".$mode." newWidth=".$newWidth." newHeight=".$newHeight." src_x=".$src_x." src_y=".$src_y);
// Clean parameters // Clean parameters
$file=trim($file); $file = trim($file);
// Check parameters // Check parameters
if (! $file) if (!$file)
{ {
// Si le fichier n'a pas ete indique // Si le fichier n'a pas ete indique
return 'Bad parameter file'; return 'Bad parameter file';
} }
elseif (! file_exists($file)) elseif (!file_exists($file))
{ {
// Si le fichier passe en parametre n'existe pas // Si le fichier passe en parametre n'existe pas
return $langs->trans("ErrorFileNotFound", $file); return $langs->trans("ErrorFileNotFound", $file);
} }
elseif(image_format_supported($file) < 0) elseif (image_format_supported($file) < 0)
{ {
return 'This filename '.$file.' does not seem to be an image filename.'; return 'This filename '.$file.' does not seem to be an image filename.';
} }
elseif(!is_numeric($newWidth) && !is_numeric($newHeight)) elseif (!is_numeric($newWidth) && !is_numeric($newHeight))
{ {
return 'Wrong value for parameter newWidth or newHeight'; return 'Wrong value for parameter newWidth or newHeight';
} }
@ -157,16 +157,16 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
{ {
if ($newWidth <= 0) if ($newWidth <= 0)
{ {
$newWidth=intval(($newHeight / $imgHeight) * $imgWidth); // Keep ratio $newWidth = intval(($newHeight / $imgHeight) * $imgWidth); // Keep ratio
} }
if ($newHeight <= 0) if ($newHeight <= 0)
{ {
$newHeight=intval(($newWidth / $imgWidth) * $imgHeight); // Keep ratio $newHeight = intval(($newWidth / $imgWidth) * $imgHeight); // Keep ratio
} }
} }
$imgfonction=''; $imgfonction = '';
switch($infoImg[2]) switch ($infoImg[2])
{ {
case 1: // IMG_GIF case 1: // IMG_GIF
$imgfonction = 'imagecreatefromgif'; $imgfonction = 'imagecreatefromgif';
@ -183,7 +183,7 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
} }
if ($imgfonction) if ($imgfonction)
{ {
if (! function_exists($imgfonction)) if (!function_exists($imgfonction))
{ {
// Fonctions de conversion non presente dans ce PHP // Fonctions de conversion non presente dans ce PHP
return 'Resize not possible. This PHP does not support GD functions '.$imgfonction; return 'Resize not possible. This PHP does not support GD functions '.$imgfonction;
@ -191,27 +191,27 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
} }
// Initialisation des variables selon l'extension de l'image // Initialisation des variables selon l'extension de l'image
switch($infoImg[2]) switch ($infoImg[2])
{ {
case 1: // Gif case 1: // Gif
$img = imagecreatefromgif($filetoread); $img = imagecreatefromgif($filetoread);
$extImg = '.gif'; // File name extension of image $extImg = '.gif'; // File name extension of image
$newquality='NU'; // Quality is not used for this format $newquality = 'NU'; // Quality is not used for this format
break; break;
case 2: // Jpg case 2: // Jpg
$img = imagecreatefromjpeg($filetoread); $img = imagecreatefromjpeg($filetoread);
$extImg = '.jpg'; $extImg = '.jpg';
$newquality=100; // % quality maximum $newquality = 100; // % quality maximum
break; break;
case 3: // Png case 3: // Png
$img = imagecreatefrompng($filetoread); $img = imagecreatefrompng($filetoread);
$extImg = '.png'; $extImg = '.png';
$newquality=0; // No compression (0-9) $newquality = 0; // No compression (0-9)
break; break;
case 4: // Bmp case 4: // Bmp
$img = imagecreatefromwbmp($filetoread); $img = imagecreatefromwbmp($filetoread);
$extImg = '.bmp'; $extImg = '.bmp';
$newquality='NU'; // Quality is not used for this format $newquality = 'NU'; // Quality is not used for this format
break; break;
} }
@ -239,7 +239,7 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
} }
// Initialisation des variables selon l'extension de l'image // Initialisation des variables selon l'extension de l'image
switch($infoImg[2]) switch ($infoImg[2])
{ {
case 1: // Gif case 1: // Gif
$trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF
@ -260,7 +260,7 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
dol_syslog("dol_imageResizeOrCrop: convert image from ($imgWidth x $imgHeight) at position ($src_x x $src_y) to ($newWidth x $newHeight) as $extImg, newquality=$newquality"); dol_syslog("dol_imageResizeOrCrop: convert image from ($imgWidth x $imgHeight) at position ($src_x x $src_y) to ($newWidth x $newHeight) as $extImg, newquality=$newquality");
//imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee
imagecopyresampled($imgThumb, $img, 0, 0, $src_x, $src_y, $newWidth, $newHeight, ($mode==0?$imgWidth:$newWidth), ($mode==0?$imgHeight:$newHeight)); // Insere l'image de base redimensionnee imagecopyresampled($imgThumb, $img, 0, 0, $src_x, $src_y, $newWidth, $newHeight, ($mode == 0 ? $imgWidth : $newWidth), ($mode == 0 ? $imgHeight : $newHeight)); // Insere l'image de base redimensionnee
$imgThumbName = $file; $imgThumbName = $file;
@ -269,7 +269,7 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
//fclose($fp); //fclose($fp);
// Create image on disk // Create image on disk
switch($infoImg[2]) switch ($infoImg[2])
{ {
case 1: // Gif case 1: // Gif
imagegif($imgThumb, $imgThumbName); imagegif($imgThumb, $imgThumbName);
@ -286,7 +286,7 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
} }
// Set permissions on file // Set permissions on file
if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); if (!empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK));
// Free memory. This does not delete image. // Free memory. This does not delete image.
imagedestroy($img); imagedestroy($img);
@ -343,7 +343,7 @@ function correctExifImageOrientation($fileSource, $fileDest, $quality = 95)
break; break;
} }
if ($deg) { if ($deg) {
if($infoImg[2] === 'IMAGETYPE_PNG') // In fact there is no exif on PNG but just in case if ($infoImg[2] === 'IMAGETYPE_PNG') // In fact there is no exif on PNG but just in case
{ {
imagealphablending($img, false); imagealphablending($img, false);
imagesavealpha($img, true); imagesavealpha($img, true);
@ -351,12 +351,12 @@ function correctExifImageOrientation($fileSource, $fileDest, $quality = 95)
imagealphablending($img, false); imagealphablending($img, false);
imagesavealpha($img, true); imagesavealpha($img, true);
} }
else{ else {
$img = imagerotate($img, $deg, 0); $img = imagerotate($img, $deg, 0);
} }
} }
// then rewrite the rotated image back to the disk as $fileDest // then rewrite the rotated image back to the disk as $fileDest
if($fileDest === false){ if ($fileDest === false) {
return $img; return $img;
} }
else else
@ -365,7 +365,7 @@ function correctExifImageOrientation($fileSource, $fileDest, $quality = 95)
// Create image on disk // Create image on disk
$image = false; $image = false;
switch($infoImg[2]) switch ($infoImg[2])
{ {
case IMAGETYPE_GIF: // 1 case IMAGETYPE_GIF: // 1
$image = imagegif($img, $fileDest); $image = imagegif($img, $fileDest);
@ -473,8 +473,8 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small',
//return 'Le fichier '.$file.' ne necessite pas de creation de vignette'; //return 'Le fichier '.$file.' ne necessite pas de creation de vignette';
} }
$imgfonction=''; $imgfonction = '';
switch($infoImg[2]) switch ($infoImg[2])
{ {
case IMAGETYPE_GIF: // 1 case IMAGETYPE_GIF: // 1
$imgfonction = 'imagecreatefromgif'; $imgfonction = 'imagecreatefromgif';
@ -494,7 +494,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small',
} }
if ($imgfonction) if ($imgfonction)
{ {
if (! function_exists($imgfonction)) if (!function_exists($imgfonction))
{ {
// Fonctions de conversion non presente dans ce PHP // Fonctions de conversion non presente dans ce PHP
return 'Error: Creation of thumbs not possible. This PHP does not support GD function '.$imgfonction; return 'Error: Creation of thumbs not possible. This PHP does not support GD function '.$imgfonction;
@ -502,12 +502,12 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small',
} }
// On cree le repertoire contenant les vignettes // On cree le repertoire contenant les vignettes
$dirthumb = dirname($file).($outdir?'/'.$outdir:''); // Chemin du dossier contenant les vignettes $dirthumb = dirname($file).($outdir ? '/'.$outdir : ''); // Chemin du dossier contenant les vignettes
dol_mkdir($dirthumb); dol_mkdir($dirthumb);
// Initialisation des variables selon l'extension de l'image // Initialisation des variables selon l'extension de l'image
$img=null; $img = null;
switch($infoImg[2]) switch ($infoImg[2])
{ {
case IMAGETYPE_GIF: // 1 case IMAGETYPE_GIF: // 1
$img = imagecreatefromgif($filetoread); $img = imagecreatefromgif($filetoread);
@ -515,7 +515,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small',
break; break;
case IMAGETYPE_JPEG: // 2 case IMAGETYPE_JPEG: // 2
$img = imagecreatefromjpeg($filetoread); $img = imagecreatefromjpeg($filetoread);
$extImg = (preg_match('/\.jpeg$/', $file)?'.jpeg':'.jpg'); // Extension de l'image $extImg = (preg_match('/\.jpeg$/', $file) ? '.jpeg' : '.jpg'); // Extension de l'image
break; break;
case IMAGETYPE_PNG: // 3 case IMAGETYPE_PNG: // 3
$img = imagecreatefrompng($filetoread); $img = imagecreatefrompng($filetoread);
@ -571,12 +571,12 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small',
imagealphablending($rotated, false); imagealphablending($rotated, false);
imagesavealpha($rotated, true); imagesavealpha($rotated, true);
} }
else{ else {
$rotated = imagerotate($img, $exifAngle, 0); $rotated = imagerotate($img, $exifAngle, 0);
} }
// replace image with good orientation // replace image with good orientation
if(!empty($rotated)){ if (!empty($rotated)) {
$img = $rotated; $img = $rotated;
$imgWidth = $trueImgWidth; $imgWidth = $trueImgWidth;
$imgHeight = $trueImgHeight; $imgHeight = $trueImgHeight;
@ -584,14 +584,14 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small',
} }
// Initialisation des dimensions de la vignette si elles sont superieures a l'original // Initialisation des dimensions de la vignette si elles sont superieures a l'original
if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; } if ($maxWidth > $imgWidth) { $maxWidth = $imgWidth; }
if($maxHeight > $imgHeight){ $maxHeight = $imgHeight; } if ($maxHeight > $imgHeight) { $maxHeight = $imgHeight; }
$whFact = $maxWidth/$maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette $whFact = $maxWidth / $maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette
$imgWhFact = $imgWidth/$imgHeight; // Facteur largeur/hauteur de l'original $imgWhFact = $imgWidth / $imgHeight; // Facteur largeur/hauteur de l'original
// Fixe les dimensions de la vignette // Fixe les dimensions de la vignette
if($whFact < $imgWhFact) if ($whFact < $imgWhFact)
{ {
// Si largeur determinante // Si largeur determinante
$thumbWidth = $maxWidth; $thumbWidth = $maxWidth;
@ -603,11 +603,11 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small',
$thumbHeight = $maxHeight; $thumbHeight = $maxHeight;
$thumbWidth = $thumbHeight * $imgWhFact; $thumbWidth = $thumbHeight * $imgWhFact;
} }
$thumbHeight=round($thumbHeight); $thumbHeight = round($thumbHeight);
$thumbWidth=round($thumbWidth); $thumbWidth = round($thumbWidth);
// Define target format // Define target format
if (empty($targetformat)) $targetformat=$infoImg[2]; if (empty($targetformat)) $targetformat = $infoImg[2];
// Create empty image // Create empty image
if ($targetformat == IMAGETYPE_GIF) if ($targetformat == IMAGETYPE_GIF)
@ -634,35 +634,35 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small',
// Initialisation des variables selon l'extension de l'image // Initialisation des variables selon l'extension de l'image
// $targetformat is 0 by default, in such case, we keep original extension // $targetformat is 0 by default, in such case, we keep original extension
switch($targetformat) switch ($targetformat)
{ {
case IMAGETYPE_GIF: // 1 case IMAGETYPE_GIF: // 1
$trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF
imagecolortransparent($imgThumb, $trans_colour); imagecolortransparent($imgThumb, $trans_colour);
$extImgTarget = '.gif'; $extImgTarget = '.gif';
$newquality='NU'; $newquality = 'NU';
break; break;
case IMAGETYPE_JPEG: // 2 case IMAGETYPE_JPEG: // 2
$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
$extImgTarget = (preg_match('/\.jpeg$/i', $file)?'.jpeg':'.jpg'); $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '.jpg');
$newquality=$quality; $newquality = $quality;
break; break;
case IMAGETYPE_PNG: // 3 case IMAGETYPE_PNG: // 3
imagealphablending($imgThumb, false); // Pour compatibilite sur certain systeme imagealphablending($imgThumb, false); // Pour compatibilite sur certain systeme
$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel
$extImgTarget = '.png'; $extImgTarget = '.png';
$newquality=$quality-100; $newquality = $quality - 100;
$newquality=round(abs($quality-100)*9/100); $newquality = round(abs($quality - 100) * 9 / 100);
break; break;
case IMAGETYPE_BMP: // 6 case IMAGETYPE_BMP: // 6
// Not supported by PHP GD // Not supported by PHP GD
$extImgTarget = '.bmp'; $extImgTarget = '.bmp';
$newquality='NU'; $newquality = 'NU';
break; break;
case IMAGETYPE_WBMP: // 15 case IMAGETYPE_WBMP: // 15
$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
$extImgTarget = '.bmp'; $extImgTarget = '.bmp';
$newquality='NU'; $newquality = 'NU';
break; break;
} }
if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour); if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour);
@ -682,7 +682,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small',
//fclose($fp); //fclose($fp);
// Create image on disk // Create image on disk
switch($targetformat) switch ($targetformat)
{ {
case IMAGETYPE_GIF: // 1 case IMAGETYPE_GIF: // 1
imagegif($imgThumb, $imgThumbName); imagegif($imgThumb, $imgThumbName);
@ -702,7 +702,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small',
} }
// Set permissions on file // Set permissions on file
if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); if (!empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK));
// Free memory. This does not delete image. // Free memory. This does not delete image.
imagedestroy($img); imagedestroy($img);

View File

@ -32,24 +32,24 @@
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
// For direct external download link, we don't need to load/check we are into a login session // For direct external download link, we don't need to load/check we are into a login session
if (isset($_GET["hashp"]) && ! defined("NOLOGIN")) if (isset($_GET["hashp"]) && !defined("NOLOGIN"))
{ {
if (! defined("NOLOGIN")) define("NOLOGIN", 1); if (!defined("NOLOGIN")) define("NOLOGIN", 1);
if (! defined("NOCSRFCHECK")) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
if (! defined("NOIPCHECK")) define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip if (!defined("NOIPCHECK")) define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip
} }
// Some value of modulepart can be used to get resources that are public so no login are required. // Some value of modulepart can be used to get resources that are public so no login are required.
if ((isset($_GET["modulepart"]) && $_GET["modulepart"] == 'medias')) if ((isset($_GET["modulepart"]) && $_GET["modulepart"] == 'medias'))
{ {
if (! defined("NOLOGIN")) define("NOLOGIN", 1); if (!defined("NOLOGIN")) define("NOLOGIN", 1);
if (! defined("NOCSRFCHECK")) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
if (! defined("NOIPCHECK")) define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip if (!defined("NOIPCHECK")) define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip
} }
/** /**
@ -76,25 +76,25 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
$encoding = ''; $encoding = '';
$action=GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
$original_file=GETPOST('file', 'alphanohtml'); // Do not use urldecode here ($_GET are already decoded by PHP). $original_file = GETPOST('file', 'alphanohtml'); // Do not use urldecode here ($_GET are already decoded by PHP).
$hashp=GETPOST('hashp', 'aZ09'); $hashp = GETPOST('hashp', 'aZ09');
$modulepart=GETPOST('modulepart', 'alpha'); $modulepart = GETPOST('modulepart', 'alpha');
$urlsource=GETPOST('urlsource', 'alpha'); $urlsource = GETPOST('urlsource', 'alpha');
$entity=GETPOST('entity', 'int')?GETPOST('entity', 'int'):$conf->entity; $entity = GETPOST('entity', 'int') ?GETPOST('entity', 'int') : $conf->entity;
// Security check // Security check
if (empty($modulepart) && empty($hashp)) accessforbidden('Bad link. Bad value for parameter modulepart', 0, 0, 1); if (empty($modulepart) && empty($hashp)) accessforbidden('Bad link. Bad value for parameter modulepart', 0, 0, 1);
if (empty($original_file) && empty($hashp)) accessforbidden('Bad link. Missing identification to find file (original_file or hashp)', 0, 0, 1); if (empty($original_file) && empty($hashp)) accessforbidden('Bad link. Missing identification to find file (original_file or hashp)', 0, 0, 1);
if ($modulepart == 'fckeditor') $modulepart='medias'; // For backward compatibility if ($modulepart == 'fckeditor') $modulepart = 'medias'; // For backward compatibility
$socid=0; $socid = 0;
if ($user->socid > 0) $socid = $user->socid; if ($user->socid > 0) $socid = $user->socid;
// For some module part, dir may be privates // For some module part, dir may be privates
if (in_array($modulepart, array('facture_paiement','unpaid'))) if (in_array($modulepart, array('facture_paiement', 'unpaid')))
{ {
if (! $user->rights->societe->client->voir || $socid) $original_file='private/'.$user->id.'/'.$original_file; // If user has no permission to see all, output dir is specific to user if (!$user->rights->societe->client->voir || $socid) $original_file = 'private/'.$user->id.'/'.$original_file; // If user has no permission to see all, output dir is specific to user
} }
@ -111,10 +111,10 @@ if (in_array($modulepart, array('facture_paiement','unpaid')))
*/ */
// If we have a hash public (hashp), we guess the original_file. // If we have a hash public (hashp), we guess the original_file.
if (! empty($hashp)) if (!empty($hashp))
{ {
include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
$ecmfile=new EcmFiles($db); $ecmfile = new EcmFiles($db);
$result = $ecmfile->fetch(0, '', '', '', $hashp); $result = $ecmfile->fetch(0, '', '', '', $hashp);
if ($result > 0) if ($result > 0)
{ {
@ -131,7 +131,7 @@ if (! empty($hashp))
if ($moduleparttocheck == $modulepart) if ($moduleparttocheck == $modulepart)
{ {
// We remove first level of directory // We remove first level of directory
$original_file = (($tmp[1]?$tmp[1].'/':'').$ecmfile->filename); // this is relative to module dir $original_file = (($tmp[1] ? $tmp[1].'/' : '').$ecmfile->filename); // this is relative to module dir
//var_dump($original_file); exit; //var_dump($original_file); exit;
} }
else else
@ -142,7 +142,7 @@ if (! empty($hashp))
else else
{ {
$modulepart = $moduleparttocheck; $modulepart = $moduleparttocheck;
$original_file = (($tmp[1]?$tmp[1].'/':'').$ecmfile->filename); // this is relative to module dir $original_file = (($tmp[1] ? $tmp[1].'/' : '').$ecmfile->filename); // this is relative to module dir
} }
} }
else else
@ -155,13 +155,13 @@ if (! empty($hashp))
// Define attachment (attachment=true to force choice popup 'open'/'save as') // Define attachment (attachment=true to force choice popup 'open'/'save as')
$attachment = true; $attachment = true;
if (preg_match('/\.(html|htm)$/i', $original_file)) $attachment = false; if (preg_match('/\.(html|htm)$/i', $original_file)) $attachment = false;
if (isset($_GET["attachment"])) $attachment = GETPOST("attachment", 'alpha')?true:false; if (isset($_GET["attachment"])) $attachment = GETPOST("attachment", 'alpha') ?true:false;
if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment = false;
// Define mime type // Define mime type
$type = 'application/octet-stream'; $type = 'application/octet-stream';
if (GETPOST('type', 'alpha')) $type=GETPOST('type', 'alpha'); if (GETPOST('type', 'alpha')) $type = GETPOST('type', 'alpha');
else $type=dol_mimetype($original_file); else $type = dol_mimetype($original_file);
// Security: Force to octet-stream if file is a dangerous file // Security: Force to octet-stream if file is a dangerous file
if (preg_match('/\.noexe$/i', $original_file)) $type = 'application/octet-stream'; if (preg_match('/\.noexe$/i', $original_file)) $type = 'application/octet-stream';
@ -169,7 +169,7 @@ if (preg_match('/\.noexe$/i', $original_file)) $type = 'application/octet-stream
$original_file = str_replace("../", "/", $original_file); $original_file = str_replace("../", "/", $original_file);
// Find the subdirectory name as the reference // Find the subdirectory name as the reference
$refname=basename(dirname($original_file)."/"); $refname = basename(dirname($original_file)."/");
// Security check // Security check
if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart'); if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart');
@ -180,7 +180,7 @@ $accessallowed = $check_access['accessallowed'];
$sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals']; $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
$fullpath_original_file = $check_access['original_file']; // $fullpath_original_file is now a full path name $fullpath_original_file = $check_access['original_file']; // $fullpath_original_file is now a full path name
if (! empty($hashp)) if (!empty($hashp))
{ {
$accessallowed = 1; // When using hashp, link is public so we force $accessallowed $accessallowed = 1; // When using hashp, link is public so we force $accessallowed
$sqlprotectagainstexternals = ''; $sqlprotectagainstexternals = '';
@ -195,14 +195,14 @@ else
$resql = $db->query($sqlprotectagainstexternals); $resql = $db->query($sqlprotectagainstexternals);
if ($resql) if ($resql)
{ {
$num=$db->num_rows($resql); $num = $db->num_rows($resql);
$i=0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if ($user->socid != $obj->fk_soc) if ($user->socid != $obj->fk_soc)
{ {
$accessallowed=0; $accessallowed = 0;
break; break;
} }
$i++; $i++;
@ -214,7 +214,7 @@ else
// Security: // Security:
// Limit access if permissions are wrong // Limit access if permissions are wrong
if (! $accessallowed) if (!$accessallowed)
{ {
accessforbidden(); accessforbidden();
} }
@ -236,10 +236,10 @@ $filename = preg_replace('/\.noexe$/i', '', $filename);
// Output file on browser // Output file on browser
dol_syslog("document.php download $fullpath_original_file filename=$filename content-type=$type"); dol_syslog("document.php download $fullpath_original_file filename=$filename content-type=$type");
$fullpath_original_file_osencoded=dol_osencode($fullpath_original_file); // New file name encoded in OS encoding charset $fullpath_original_file_osencoded = dol_osencode($fullpath_original_file); // New file name encoded in OS encoding charset
// This test if file exists should be useless. We keep it to find bug more easily // This test if file exists should be useless. We keep it to find bug more easily
if (! file_exists($fullpath_original_file_osencoded)) if (!file_exists($fullpath_original_file_osencoded))
{ {
dol_syslog("ErrorFileDoesNotExists: ".$fullpath_original_file); dol_syslog("ErrorFileDoesNotExists: ".$fullpath_original_file);
print "ErrorFileDoesNotExists: ".$original_file; print "ErrorFileDoesNotExists: ".$original_file;
@ -264,8 +264,8 @@ if (!$attachment && !empty($conf->global->MAIN_USE_EXIF_ROTATION) && image_forma
$readfile = !$imgres; $readfile = !$imgres;
} }
if($readfile){ if ($readfile) {
header('Content-Length: ' . dol_filesize($fullpath_original_file)); header('Content-Length: '.dol_filesize($fullpath_original_file));
readfile($fullpath_original_file_osencoded); readfile($fullpath_original_file_osencoded);
} }

View File

@ -488,7 +488,7 @@ if ($resql)
{ {
$oldtype = $type; $oldtype = $type;
$params = array(); $params = array();
if ($type === "") $params['forcenohideoftext']=1; if ($type === "") $params['forcenohideoftext'] = 1;
if ($type === "") { if ($type === "") {
$newcardbutton .= dolGetButtonTitle($langs->trans('NewProduct'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type=0', '', 1, $params); $newcardbutton .= dolGetButtonTitle($langs->trans('NewProduct'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type=0', '', 1, $params);
$type = Product::TYPE_SERVICE; $type = Product::TYPE_SERVICE;