mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 09:38:23 +01:00
Move function colorIsLight into functions.lib.php
Fix scrutinizer bugs.
This commit is contained in:
@@ -1079,8 +1079,12 @@ class BookKeeping extends CommonObject
|
||||
* @param string $mode Mode
|
||||
* @return number <0 if KO, >0 if OK
|
||||
*/
|
||||
public function updateByMvt($piece_num='', $field='', $value='', $mode='') {
|
||||
public function updateByMvt($piece_num='', $field='', $value='', $mode='')
|
||||
{
|
||||
$error=0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element . $mode . " as ab";
|
||||
$sql .= ' SET ab.' . $field . '=' . (is_numeric($value)?$value:"'".$value."'");
|
||||
$sql .= ' WHERE ab.piece_num=' . $piece_num ;
|
||||
@@ -1521,11 +1525,16 @@ class BookKeeping extends CommonObject
|
||||
* @param string $piece_num Piece num
|
||||
* @return void
|
||||
*/
|
||||
public function transformTransaction($direction=0,$piece_num='') {
|
||||
public function transformTransaction($direction=0,$piece_num='')
|
||||
{
|
||||
$error = 0;
|
||||
|
||||
$this->db->begin();
|
||||
if ($direction==0) {
|
||||
|
||||
if ($direction==0)
|
||||
{
|
||||
$next_piecenum=$this->getNextNumMvt();
|
||||
if ($result < 0) {
|
||||
if ($next_piecenum < 0) {
|
||||
$error++;
|
||||
}
|
||||
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element.'(doc_date, doc_type,';
|
||||
|
||||
@@ -1563,7 +1563,7 @@ class Adherent extends CommonObject
|
||||
* @param int $withpictoimg 0=No picto, 1=Include picto into link, 2=Only picto, -1=Include photo into link, -2=Only picto photo, -3=Only photo very small)
|
||||
* @param int $maxlen length max label
|
||||
* @param string $option Page for link ('card', 'category', 'subscription', ...)
|
||||
* @param string $mode ''=Show firstname and lastname, 'firstname'=Show only firstname, 'login'=Show login, 'ref'=Show ref
|
||||
* @param string $mode ''=Show firstname+lastname as label (using default order), 'firstname'=Show only firstname, 'login'=Show login, 'ref'=Show ref
|
||||
* @param string $morecss Add more css on link
|
||||
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
|
||||
* @return string Chaine avec URL
|
||||
@@ -1574,6 +1574,8 @@ class Adherent extends CommonObject
|
||||
|
||||
if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) $withpictoimg=0;
|
||||
|
||||
$notooltip=0;
|
||||
|
||||
$result=''; $label='';
|
||||
$link=''; $linkstart=''; $linkend='';
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ class AdherentType extends CommonObject
|
||||
$sql.= "libelle = '".$this->db->escape($this->label) ."',";
|
||||
$sql.= "subscription = '".$this->db->escape($this->subscription)."',";
|
||||
$sql.= "note = '".$this->db->escape($this->note)."',";
|
||||
$sql.= "vote = '".$this->db->escape($this->vote)."',";
|
||||
$sql.= "vote = ".(integer) $this->db->escape($this->vote).",";
|
||||
$sql.= "mail_valid = '".$this->db->escape($this->mail_valid)."'";
|
||||
$sql.= " WHERE rowid =".$this->id;
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ if ($action == 'add' && $user->rights->adherent->configurer)
|
||||
$object->subscription = (int) trim($subscription);
|
||||
$object->note = trim($comment);
|
||||
$object->mail_valid = trim($mail_valid);
|
||||
$object->vote = (boolean) trim($vote);
|
||||
$object->vote = trim($vote);
|
||||
|
||||
// Fill array 'array_options' with data from add form
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||
@@ -160,7 +160,7 @@ if ($action == 'update' && $user->rights->adherent->configurer)
|
||||
$object->subscription = (int) trim($subscription);
|
||||
$object->note = trim($comment);
|
||||
$object->mail_valid = trim($mail_valid);
|
||||
$object->vote = (boolean) trim($vote);
|
||||
$object->vote = trim($vote);
|
||||
|
||||
// Fill array 'array_options' with data from add form
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||
|
||||
@@ -1019,9 +1019,9 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='')
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
elseif ($context == 'add' & in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue;
|
||||
elseif ($context == 'edit' & in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue;
|
||||
elseif ($context == 'hide' & in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue;
|
||||
elseif ($context == 'add' && in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue;
|
||||
elseif ($context == 'edit' && in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue;
|
||||
elseif ($context == 'hide' && in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue;
|
||||
else
|
||||
{
|
||||
$size=''; $class=''; $classtd='';
|
||||
|
||||
@@ -83,10 +83,10 @@ class DolibarrApiAccess implements iAuthenticate
|
||||
|
||||
// api key can be provided in url with parameter api_key=xxx or ni header with header DOLAPIKEY:xxx
|
||||
$api_key = '';
|
||||
if (isset($_GET['api_key']))
|
||||
if (isset($_GET['api_key'])) // For backward compatibility
|
||||
{
|
||||
// TODO Add option to disable use of api key on url. Return errors if used.
|
||||
$api_key = $_GET['api_key']; // For backward compatibility
|
||||
$api_key = $_GET['api_key'];
|
||||
}
|
||||
if (isset($_GET['DOLAPIKEY']))
|
||||
{
|
||||
|
||||
@@ -256,9 +256,11 @@ class Documents extends DolibarrApi
|
||||
|
||||
// Define $uploadir
|
||||
$object = null;
|
||||
$entity = $user->entity;
|
||||
$entity = DolibarrApiAccess::$user->entity;
|
||||
if ($ref)
|
||||
{
|
||||
$tmpreldir='';
|
||||
|
||||
if ($modulepart == 'facture' || $modulepart == 'invoice')
|
||||
{
|
||||
$modulepart='facture';
|
||||
|
||||
@@ -117,7 +117,7 @@ class Facturation
|
||||
}
|
||||
|
||||
// Define part of HT, VAT, TTC
|
||||
$resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $txtva, -1, -1, 0, 'HT', $use_npr, $product->type, $mysoc, $localtaxarray);
|
||||
$resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $txtva, -1, -1, 0, 'HT', $vat_npr, $product->type, $mysoc, $localtaxarray);
|
||||
|
||||
// Calcul du total ht sans remise
|
||||
$total_ht = $resultarray[0];
|
||||
@@ -207,6 +207,9 @@ class Facturation
|
||||
|
||||
$total_ht=0;
|
||||
$total_ttc=0;
|
||||
$total_vat = 0;
|
||||
$total_localtax1 = 0;
|
||||
$total_localtax2 = 0;
|
||||
|
||||
$tab=array();
|
||||
$tab = $_SESSION['poscart'];
|
||||
@@ -309,7 +312,7 @@ class Facturation
|
||||
public function ref($aRef=null)
|
||||
{
|
||||
|
||||
if ( !$aRef )
|
||||
if (is_null($aRef))
|
||||
{
|
||||
return $this->ref;
|
||||
}
|
||||
@@ -332,7 +335,7 @@ class Facturation
|
||||
*/
|
||||
public function qte($aQte=null)
|
||||
{
|
||||
if ( !$aQte )
|
||||
if (is_null($aQte))
|
||||
{
|
||||
return $this->qte;
|
||||
}
|
||||
@@ -357,7 +360,7 @@ class Facturation
|
||||
public function stock($aStock=null)
|
||||
{
|
||||
|
||||
if ( !$aStock )
|
||||
if (is_null($aStock))
|
||||
{
|
||||
return $this->stock;
|
||||
}
|
||||
@@ -381,7 +384,7 @@ class Facturation
|
||||
public function remisePercent($aRemisePercent=null)
|
||||
{
|
||||
|
||||
if ( !$aRemisePercent )
|
||||
if (is_null($aRemisePercent))
|
||||
{
|
||||
return $this->remise_percent;
|
||||
}
|
||||
@@ -405,7 +408,7 @@ class Facturation
|
||||
public function montantRemise($aMontantRemise=null)
|
||||
{
|
||||
|
||||
if ( !$aMontantRemise ) {
|
||||
if (is_null($aMontantRemise)) {
|
||||
|
||||
return $this->montant_remise;
|
||||
|
||||
@@ -430,7 +433,7 @@ class Facturation
|
||||
public function prix($aPrix=null)
|
||||
{
|
||||
|
||||
if ( !$aPrix ) {
|
||||
if (is_null($aPrix)) {
|
||||
|
||||
return $this->prix;
|
||||
|
||||
@@ -454,7 +457,7 @@ class Facturation
|
||||
*/
|
||||
public function tva($aTva=null)
|
||||
{
|
||||
if ( !$aTva ) {
|
||||
if (is_null($aTva)) {
|
||||
|
||||
return $this->tva;
|
||||
|
||||
@@ -478,7 +481,7 @@ class Facturation
|
||||
*/
|
||||
public function numInvoice($aNumFacture=null)
|
||||
{
|
||||
if ( !$aNumFacture ) {
|
||||
if (is_null($aNumFacture)) {
|
||||
|
||||
return $this->num_facture;
|
||||
|
||||
@@ -502,7 +505,7 @@ class Facturation
|
||||
public function getSetPaymentMode($aModeReglement=null)
|
||||
{
|
||||
|
||||
if ( !$aModeReglement ) {
|
||||
if (is_null($aModeReglement)) {
|
||||
|
||||
return $this->mode_reglement;
|
||||
|
||||
@@ -527,7 +530,7 @@ class Facturation
|
||||
public function montantEncaisse($aMontantEncaisse=null)
|
||||
{
|
||||
|
||||
if ( !$aMontantEncaisse ) {
|
||||
if (is_null($aMontantEncaisse)) {
|
||||
|
||||
return $this->montant_encaisse;
|
||||
|
||||
@@ -552,7 +555,7 @@ class Facturation
|
||||
public function montantRendu($aMontantRendu=null)
|
||||
{
|
||||
|
||||
if ( !$aMontantRendu ) {
|
||||
if (is_null($aMontantRendu)) {
|
||||
|
||||
return $this->montant_rendu;
|
||||
} else if ( $aMontantRendu == 'RESET' ) {
|
||||
@@ -575,7 +578,7 @@ class Facturation
|
||||
*/
|
||||
public function paiementLe($aPaiementLe=null)
|
||||
{
|
||||
if ( !$aPaiementLe ) {
|
||||
if (is_null($aPaiementLe)) {
|
||||
|
||||
return $this->paiement_le;
|
||||
|
||||
@@ -598,7 +601,7 @@ class Facturation
|
||||
*/
|
||||
public function prixTotalHt($aTotalHt=null)
|
||||
{
|
||||
if ( !$aTotalHt ) {
|
||||
if (is_null($aTotalHt)) {
|
||||
|
||||
return $this->prix_total_ht;
|
||||
|
||||
@@ -621,7 +624,7 @@ class Facturation
|
||||
*/
|
||||
public function montantTva($aMontantTva=null)
|
||||
{
|
||||
if ( !$aMontantTva ) {
|
||||
if (is_null($aMontantTva)) {
|
||||
|
||||
return $this->montant_tva;
|
||||
|
||||
@@ -645,7 +648,7 @@ class Facturation
|
||||
*/
|
||||
public function prixTotalTtc($aTotalTtc=null)
|
||||
{
|
||||
if ( !$aTotalTtc )
|
||||
if (is_null($aTotalTtc))
|
||||
{
|
||||
return $this->prix_total_ttc;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ class Categorie extends CommonObject
|
||||
*/
|
||||
public $socid;
|
||||
/**
|
||||
* @var int Category type
|
||||
* @var string Category type
|
||||
*
|
||||
* @see Categorie::TYPE_PRODUCT
|
||||
* @see Categorie::TYPE_SUPPLIER
|
||||
@@ -1327,6 +1327,7 @@ class Categorie extends CommonObject
|
||||
{
|
||||
$w = array();
|
||||
$i = 0;
|
||||
$forced_color='';
|
||||
foreach ($way as $cat)
|
||||
{
|
||||
$i++;
|
||||
@@ -1340,12 +1341,7 @@ class Categorie extends CommonObject
|
||||
$forced_color='categtextwhite';
|
||||
if ($cat->color)
|
||||
{
|
||||
$hex=$cat->color;
|
||||
$r = hexdec($hex[0].$hex[1]);
|
||||
$g = hexdec($hex[2].$hex[3]);
|
||||
$b = hexdec($hex[4].$hex[5]);
|
||||
$bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
|
||||
if ($bright >= 0.5) $forced_color='categtextblack'; // Higher than 60%
|
||||
if (colorIsLight($cat->color)) $forced_color='categtextblack';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1602,12 +1598,7 @@ class Categorie extends CommonObject
|
||||
$forced_color='categtextwhite';
|
||||
if ($this->color)
|
||||
{
|
||||
$hex=$this->color;
|
||||
$r = hexdec($hex[0].$hex[1]);
|
||||
$g = hexdec($hex[2].$hex[3]);
|
||||
$b = hexdec($hex[4].$hex[5]);
|
||||
$bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
|
||||
if ($bright >= 0.5) $forced_color='categtextblack'; // Higher than 60%
|
||||
if (colorIsLight($this->color)) $forced_color='categtextblack';
|
||||
}
|
||||
|
||||
$link = '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$this->id.'&type='.$this->type.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip '.$forced_color .'">';
|
||||
|
||||
@@ -59,7 +59,7 @@ abstract class DoliDB implements Database
|
||||
public $lastqueryerror;
|
||||
/** @var string Last error message */
|
||||
public $lasterror;
|
||||
/** @var int Last error number */
|
||||
/** @var string Last error number. For example: 'DB_ERROR_RECORD_ALREADY_EXISTS', '12345', ... */
|
||||
public $lasterrno;
|
||||
|
||||
/** @var bool Status */
|
||||
|
||||
@@ -6791,3 +6791,37 @@ function getDictvalue($tablename, $field, $id, $checkentity=false, $rowidfield='
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the color is light
|
||||
*
|
||||
* @param string $stringcolor String with hex (FFFFFF) or comma RGB ('255,255,255')
|
||||
* @return int -1 : Error with argument passed |0 : color is dark | 1 : color is light
|
||||
*/
|
||||
function colorIsLight($stringcolor)
|
||||
{
|
||||
$res = -1;
|
||||
if (!empty($stringcolor))
|
||||
{
|
||||
$res = 0;
|
||||
$tmp=explode(',', $stringcolor);
|
||||
if (count($tmp) > 1) // This is a comma RGB ('255','255','255')
|
||||
{
|
||||
$r = $tmp[0];
|
||||
$g = $tmp[1];
|
||||
$b = $tmp[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
$hexr=$stringcolor[0].$stringcolor[1];
|
||||
$hexg=$stringcolor[2].$stringcolor[3];
|
||||
$hexb=$stringcolor[4].$stringcolor[5];
|
||||
$r = hexdec($hexr);
|
||||
$g = hexdec($hexg);
|
||||
$b = hexdec($hexb);
|
||||
}
|
||||
$bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
|
||||
if ($bright > 0.6) $res = 1;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
@@ -2153,40 +2153,6 @@ function colorStringToArray($stringcolor,$colorifnotfound=array(88,88,88))
|
||||
return array(hexdec($reg[1]),hexdec($reg[2]),hexdec($reg[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the color is light
|
||||
*
|
||||
* @param string $stringcolor String with hex (FFFFFF) or comma RGB ('255,255,255')
|
||||
* @return int -1 : Error with argument passed |0 : color is dark | 1 : color is light
|
||||
*/
|
||||
function colorIsLight($stringcolor)
|
||||
{
|
||||
$res = -1;
|
||||
if (!empty($stringcolor))
|
||||
{
|
||||
$res = 0;
|
||||
$tmp=explode(',', $stringcolor);
|
||||
if (count($tmp) > 1) // This is a comma RGB ('255','255','255')
|
||||
{
|
||||
$r = $tmp[0];
|
||||
$g = $tmp[1];
|
||||
$b = $tmp[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
$hexr=$stringcolor[0].$stringcolor[1];
|
||||
$hexg=$stringcolor[2].$stringcolor[3];
|
||||
$hexb=$stringcolor[4].$stringcolor[5];
|
||||
$r = hexdec($hexr);
|
||||
$g = hexdec($hexg);
|
||||
$b = hexdec($hexb);
|
||||
}
|
||||
$bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
|
||||
if ($bright > 0.6) $res = 1;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the Cartesian product algorithm to an array
|
||||
* Source: http://stackoverflow.com/a/15973172
|
||||
|
||||
Reference in New Issue
Block a user