From e3853a648f8fd3a475b5d49b8cb69c6e11402d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 25 Feb 2015 19:44:12 +0100 Subject: [PATCH 01/60] Redundant code --- htdocs/margin/admin/margin.php | 3 --- htdocs/projet/admin/project.php | 7 +------ htdocs/societe/admin/societe.php | 5 +---- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/htdocs/margin/admin/margin.php b/htdocs/margin/admin/margin.php index f8beb7cd1ca..b031a190f44 100644 --- a/htdocs/margin/admin/margin.php +++ b/htdocs/margin/admin/margin.php @@ -72,7 +72,6 @@ if ($action == 'remises') { if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', $_POST['MARGIN_METHODE_FOR_DISCOUNT'], 'chaine', 0, '', $conf->entity) > 0) { - $conf->global->MARGIN_METHODE_FOR_DISCOUNT = $_POST['MARGIN_METHODE_FOR_DISCOUNT']; setEventMessage($langs->trans("RecordModifiedSuccessfully")); } else @@ -85,7 +84,6 @@ if ($action == 'typemarges') { if (dolibarr_set_const($db, 'MARGIN_TYPE', $_POST['MARGIN_TYPE'], 'chaine', 0, '', $conf->entity) > 0) { - $conf->global->MARGIN_METHODE_FOR_DISCOUNT = $_POST['MARGIN_TYPE']; setEventMessage($langs->trans("RecordModifiedSuccessfully")); } else @@ -98,7 +96,6 @@ if ($action == 'contact') { if (dolibarr_set_const($db, 'AGENT_CONTACT_TYPE', $_POST['AGENT_CONTACT_TYPE'], 'chaine', 0, '', $conf->entity) > 0) { - $conf->global->AGENT_CONTACT_TYPE = $_POST['AGENT_CONTACT_TYPE']; setEventMessage($langs->trans("RecordModifiedSuccessfully")); } else diff --git a/htdocs/projet/admin/project.php b/htdocs/projet/admin/project.php index 915d4ef69ef..a29bb9a2d63 100644 --- a/htdocs/projet/admin/project.php +++ b/htdocs/projet/admin/project.php @@ -237,12 +237,7 @@ if ($action == 'deltask') // Set default model else if ($action == 'setdoc') { - if (dolibarr_set_const($db, "PROJECT_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) - { - // La constante qui a ete lue en avant du nouveau set - // on passe donc par une variable pour avoir un affichage coherent - $conf->global->PROJECT_ADDON_PDF = $value; - } + dolibarr_set_const($db, "PROJECT_ADDON_PDF",$value,'chaine',0,'',$conf->entity); // On active le modele $ret = delDocumentModel($value, $type); diff --git a/htdocs/societe/admin/societe.php b/htdocs/societe/admin/societe.php index 8fec81c686c..881946cb1cd 100644 --- a/htdocs/societe/admin/societe.php +++ b/htdocs/societe/admin/societe.php @@ -165,10 +165,7 @@ if ($action == 'setdoc') $db->begin(); - if (dolibarr_set_const($db, "COMPANY_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) - { - $conf->global->COMPANY_ADDON_PDF = $value; - } + dolibarr_set_const($db, "COMPANY_ADDON_PDF",$value,'chaine',0,'',$conf->entity); // On active le modele $type='company'; From f2fededd2c8c6e9d44946d543b086cc3f6763559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 25 Feb 2015 22:48:45 +0100 Subject: [PATCH 02/60] Drop usage of deprecated dol_htmlentities function --- htdocs/admin/security_file.php | 4 ++-- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/lib/admin.lib.php | 2 +- htdocs/core/lib/functions.lib.php | 10 +++++----- htdocs/main.inc.php | 6 +++--- htdocs/opensurvey/card.php | 12 ++++++------ htdocs/opensurvey/list.php | 4 ++-- htdocs/opensurvey/public/studs.php | 10 +++++----- htdocs/opensurvey/results.php | 14 +++++++------- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/htdocs/admin/security_file.php b/htdocs/admin/security_file.php index 4c0dd435634..e70c6116f90 100644 --- a/htdocs/admin/security_file.php +++ b/htdocs/admin/security_file.php @@ -176,7 +176,7 @@ if (ini_get('safe_mode') && ! empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) dol_syslog("safe_mode is on, basedir is ".$basedir.", safe_mode_exec_dir is ".ini_get('safe_mode_exec_dir'), LOG_WARNING); } } -print ''; +print ''; print ""; print ''; @@ -187,7 +187,7 @@ print ''.$langs->trans("AntiVirusParam").'
'; print $langs->trans("AntiVirusParamExample"); print ''; print ''; -print ''; +print ''; print ""; print ''; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 6a6474c8306..edb27913432 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4446,7 +4446,7 @@ class Form $ret.='\n"; + if (! $silent) print '\n"; dol_syslog('Admin.lib::run_sql Request '.($i+1), LOG_DEBUG); $sqlmodified=0; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index cf3b026ed90..5b57c212150 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -517,7 +517,7 @@ function dol_escape_htmltag($stringtoescape,$keepb=0) $tmp=dol_html_entity_decode($stringtoescape,ENT_COMPAT,'UTF-8'); if ($keepb) $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n')); else $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n',""=>'',''=>'')); - return dol_htmlentities($tmp,ENT_COMPAT,'UTF-8'); + return htmlentities($tmp,ENT_COMPAT,'UTF-8'); } @@ -2473,8 +2473,8 @@ function dol_print_error($db='',$error='') } $out.="".$langs->trans("UserAgent").": ".$_SERVER["HTTP_USER_AGENT"]."
\n"; $out.="
\n"; - $out.="".$langs->trans("RequestedUrl").": ".dol_htmlentities($_SERVER["REQUEST_URI"],ENT_COMPAT,'UTF-8')."
\n"; - $out.="".$langs->trans("Referer").": ".(isset($_SERVER["HTTP_REFERER"])?dol_htmlentities($_SERVER["HTTP_REFERER"],ENT_COMPAT,'UTF-8'):'')."
\n"; + $out.="".$langs->trans("RequestedUrl").": ".htmlentities($_SERVER["REQUEST_URI"],ENT_COMPAT,'UTF-8')."
\n"; + $out.="".$langs->trans("Referer").": ".(isset($_SERVER["HTTP_REFERER"])?htmlentities($_SERVER["HTTP_REFERER"],ENT_COMPAT,'UTF-8'):'')."
\n"; $out.="".$langs->trans("MenuManager").": ".(isset($conf->standard_menu)?$conf->standard_menu:'')."
\n"; $out.="
\n"; $syslog.="url=".$_SERVER["REQUEST_URI"]; @@ -3859,13 +3859,13 @@ function dol_htmlentitiesbr($stringtoencode,$nl2brmode=0,$pagecodefrom='UTF-8',$ $newstring=preg_replace('//i','
',$newstring); // Replace "
" by "
". It's same and avoid pb with FPDF. if ($removelasteolbr) $newstring=preg_replace('/
$/i','',$newstring); // Remove last
(remove only last one) $newstring=strtr($newstring,array('&'=>'__and__','<'=>'__lt__','>'=>'__gt__','"'=>'__dquot__')); - $newstring=dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom); // Make entity encoding + $newstring=htmlentities($newstring,ENT_COMPAT,$pagecodefrom); // Make entity encoding $newstring=strtr($newstring,array('__and__'=>'&','__lt__'=>'<','__gt__'=>'>','__dquot__'=>'"')); } else { if ($removelasteolbr) $newstring=preg_replace('/(\r\n|\r|\n)$/i','',$newstring); // Remove last \n (may remove several) - $newstring=dol_nl2br(dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom),$nl2brmode); + $newstring=dol_nl2br(htmlentities($newstring,ENT_COMPAT,$pagecodefrom),$nl2brmode); } // Other substitutions that htmlentities does not do //$newstring=str_replace(chr(128),'€',$newstring); // 128 = 0x80. Not in html entity table. // Seems useles with TCPDF. Make bug with UTF8 languages diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 7be99f5e278..ca32a823d58 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -988,9 +988,9 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs $appli='Dolibarr'; if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $appli=$conf->global->MAIN_APPLICATION_TITLE; - if ($title && ! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/noapp/',$conf->global->MAIN_HTML_TITLE)) print ''.dol_htmlentities($title).''; - if ($title) print ''.dol_htmlentities($appli.' - '.$title).''; - else print "".dol_htmlentities($appli).""; + if ($title && ! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/noapp/',$conf->global->MAIN_HTML_TITLE)) print ''.htmlentities($title).''; + if ($title) print ''.htmlentities($appli.' - '.$title).''; + else print "".htmlentities($appli).""; print "\n"; $ext=''; diff --git a/htdocs/opensurvey/card.php b/htdocs/opensurvey/card.php index 5d32db24d5c..019f739f5fd 100644 --- a/htdocs/opensurvey/card.php +++ b/htdocs/opensurvey/card.php @@ -212,16 +212,16 @@ $adresseadmin=$object->mail_admin; print $langs->trans("Title") .'
'; // Description print ''; @@ -359,7 +359,7 @@ if ($comments) { print ' '.img_picto('', 'delete.png').' '; } - print dol_htmlentities($comment->usercomment).': '.dol_nl2br(dol_htmlentities($comment->comment))."
"; + print htmlentities($comment->usercomment).': '.dol_nl2br(htmlentities($comment->comment))."
"; } } else diff --git a/htdocs/opensurvey/list.php b/htdocs/opensurvey/list.php index d13c9884e89..ea17965fa9c 100644 --- a/htdocs/opensurvey/list.php +++ b/htdocs/opensurvey/list.php @@ -153,7 +153,7 @@ while ($i < min($num,$limit)) print ''; print ''; diff --git a/htdocs/opensurvey/public/studs.php b/htdocs/opensurvey/public/studs.php index 1b39391b67c..3050bf0ed08 100644 --- a/htdocs/opensurvey/public/studs.php +++ b/htdocs/opensurvey/public/studs.php @@ -258,7 +258,7 @@ print '
'."\n"; //affichage du titre du sondage $titre=str_replace("\\","",$object->titre); -print ''.dol_htmlentities($titre).'

'."\n"; +print ''.htmlentities($titre).'

'."\n"; //affichage des commentaires du sondage if ($object->commentaires) @@ -362,7 +362,7 @@ if ($object->format=="D") for ($i=0; isset($toutsujet[$i]); $i++) { $heures=explode('@',$toutsujet[$i]); if (isset($heures[1])) { - print '
'."\n"; + print ''."\n"; } else { print ''."\n"; } @@ -418,7 +418,7 @@ while ($compteur < $num) print ''."\n"; // Name - print ''."\n"; + print ''."\n"; // si la ligne n'est pas a changer, on affiche les données if (! $testligneamodifier) @@ -677,7 +677,7 @@ if ($object->allow_spy) { else { $tmps=explode('@',$toutsujet[$i]); - $meilleursujet .= dol_htmlentities($tmps[0]); + $meilleursujet .= htmlentities($tmps[0]); } $compteursujet++; @@ -717,7 +717,7 @@ if ($comments) foreach ($comments as $obj) { print '
'; if (in_array($obj->usercomment, $listofvoters)) print ' '.img_picto('', 'delete.png').' '; - print dol_htmlentities($obj->usercomment).': '.dol_nl2br(dol_htmlentities($obj->comment))."
"; + print htmlentities($obj->usercomment).':'.dol_nl2br(htmlentities($obj->comment)).""; } } diff --git a/htdocs/opensurvey/results.php b/htdocs/opensurvey/results.php index 226bc0c0465..a543447ffbc 100644 --- a/htdocs/opensurvey/results.php +++ b/htdocs/opensurvey/results.php @@ -451,9 +451,9 @@ $adresseadmin=$object->mail_admin; print $langs->trans("Title") .''; // Expire date @@ -468,7 +468,7 @@ print $langs->trans("Author") .''; @@ -721,7 +721,7 @@ if ($object->format=="D") for ($i = 0; isset($toutsujet[$i]); $i++) { $heures=explode('@', $toutsujet[$i]); if (isset($heures[1])) { - print ''."\n"; + print ''."\n"; } else { print ''."\n"; } @@ -744,7 +744,7 @@ else for ($i = 0; isset($toutsujet[$i]); $i++) { $tmp=explode('@',$toutsujet[$i]); - print ''."\n"; + print ''."\n"; } print ''."\n"; @@ -780,7 +780,7 @@ while ($compteur < $num) } // Name - print ''."\n"; + print ''."\n"; // si la ligne n'est pas a changer, on affiche les données if (! $testligneamodifier) @@ -1047,7 +1047,7 @@ for ($i = 0; $i < $nbcolonnes; $i++) { else { $tmps=explode('@',$toutsujet[$i]); - $meilleursujet .= dol_htmlentities($tmps[0]); + $meilleursujet .= htmlentities($tmps[0]); } $compteursujet++; From f117b65a1773c652fe824182f7534981617f9834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 25 Feb 2015 23:00:43 +0100 Subject: [PATCH 03/60] Removed silent operator for PHP 4 in function dol_html_entity_decode --- htdocs/core/lib/functions.lib.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 5b57c212150..6f21e9d2202 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3911,9 +3911,7 @@ function dol_htmlcleanlastbr($stringtodecode) */ function dol_html_entity_decode($a,$b,$c='UTF-8') { - // We use @ to avoid warning on PHP4 that does not support entity decoding to UTF8; - $ret=@html_entity_decode($a,$b,$c); - return $ret; + return html_entity_decode($a,$b,$c); } /** From e6c8cac3815a89c6731195f9a5fe52ad59e5d270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Mon, 2 Mar 2015 01:16:35 +0100 Subject: [PATCH 04/60] Removed TODO and deprecated tag of dol_htmlentities and revert substitution commit --- htdocs/admin/security_file.php | 4 ++-- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/lib/admin.lib.php | 2 +- htdocs/core/lib/functions.lib.php | 12 +++++------- htdocs/main.inc.php | 6 +++--- htdocs/opensurvey/card.php | 12 ++++++------ htdocs/opensurvey/list.php | 4 ++-- htdocs/opensurvey/public/studs.php | 10 +++++----- htdocs/opensurvey/results.php | 14 +++++++------- 9 files changed, 32 insertions(+), 34 deletions(-) diff --git a/htdocs/admin/security_file.php b/htdocs/admin/security_file.php index e70c6116f90..4c0dd435634 100644 --- a/htdocs/admin/security_file.php +++ b/htdocs/admin/security_file.php @@ -176,7 +176,7 @@ if (ini_get('safe_mode') && ! empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) dol_syslog("safe_mode is on, basedir is ".$basedir.", safe_mode_exec_dir is ".ini_get('safe_mode_exec_dir'), LOG_WARNING); } } -print ''; +print ''; print ""; print ''; @@ -187,7 +187,7 @@ print ''; print '"; print ''; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index edb27913432..6a6474c8306 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4446,7 +4446,7 @@ class Form $ret.='
'; } - $ret.=dol_htmlentities($object->$fieldref); + $ret.=htmlentities($object->$fieldref); if ($morehtmlref) { $ret.=' '.$morehtmlref; diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index a54cb5fcc79..54f2748cfd1 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -249,7 +249,7 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='',$oker $newsql=preg_replace('/__ENTITY__/i',(!empty($entity)?$entity:$conf->entity),$sql); // Ajout trace sur requete (eventuellement a commenter si beaucoup de requetes) - if (! $silent) print '
'.$langs->trans("Request").' '.($i+1)." sql='".dol_htmlentities($newsql,ENT_NOQUOTES)."'
'.$langs->trans("Request").' '.($i+1)." sql='".htmlentities($newsql,ENT_NOQUOTES)."'
'; if ($action == 'edit') { - print ''; + print ''; } -else print dol_htmlentities($object->titre); +else print htmlentities($object->titre); print '
'.$langs->trans("Description") .''; if ($action == 'edit') { - $doleditor=new DolEditor('nouveauxcommentaires', dol_htmlentities($object->commentaires),'',120,'dolibarr_notes','In',1,1,1,ROWS_7,120); + $doleditor=new DolEditor('nouveauxcommentaires', htmlentities($object->commentaires),'',120,'dolibarr_notes','In',1,1,1,ROWS_7,120); $doleditor->Create(0,''); } else @@ -229,7 +229,7 @@ else if (empty($conf->fckeditor->enabled)) print dol_htmlentitiesbr($object->commentaires); else { - $doleditor=new DolEditor('nouveauxcommentaires', dol_htmlentities($object->commentaires),'',120,'dolibarr_notes','In',1,1,1,ROWS_7,120,1); + $doleditor=new DolEditor('nouveauxcommentaires', htmlentities($object->commentaires),'',120,'dolibarr_notes','In',1,1,1,ROWS_7,120,1); $doleditor->Create(0,''); } } @@ -295,7 +295,7 @@ print $langs->trans("Author") .''; if ($object->fk_user_creat) { print $userstatic->getLoginUrl(1); } else { - print dol_htmlentities($object->nom_admin); + print htmlentities($object->nom_admin); } print '
'; print ''.img_picto('','object_opensurvey').' '.$obj->id_sondage.''; - print ''.dol_htmlentities($obj->titre).''; + print ''.htmlentities($obj->titre).''; $type=($obj->format=='A')?'classic':'date'; print img_picto('',dol_buildpath('/opensurvey/img/'.($type == 'classic'?'chart-32.png':'calendar-32.png'),1),'width="16"',1); print ' '.$langs->trans($type=='classic'?"TypeClassic":"TypeDate"); @@ -169,7 +169,7 @@ while ($i < min($num,$limit)) print $userstatic->getLoginUrl(1); } else { - print dol_htmlentities($obj->nom_admin); + print htmlentities($obj->nom_admin); } print ''.dol_htmlentities($heures[1]).''.htmlentities($heures[1]).'
'.dol_htmlentities($obj->name).''.htmlentities($obj->name).' '; if ($action == 'edit') { - print ''; + print ''; } -else print dol_htmlentities($object->titre); +else print htmlentities($object->titre); print '
'; if ($object->fk_user_creat) { print $userstatic->getLoginUrl(1); } else { - print dol_htmlentities($object->nom_admin); + print htmlentities($object->nom_admin); } print '
'.dol_htmlentities($heures[1]).''.htmlentities($heures[1]).''.dol_htmlentities($tmp[0]).''.htmlentities($tmp[0]).''.img_picto('',dol_buildpath('/opensurvey/img/add-16.png',1),'',1).''.dol_htmlentities($obj->name).''.htmlentities($obj->name).'
'.$langs->trans("AntiVirusParam").'
'; print $langs->trans("AntiVirusParamExample"); print '
'; -print ''; +print ''; print "
\n"; + if (! $silent) print '\n"; dol_syslog('Admin.lib::run_sql Request '.($i+1), LOG_DEBUG); $sqlmodified=0; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 6f21e9d2202..fdfb20dd558 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -517,7 +517,7 @@ function dol_escape_htmltag($stringtoescape,$keepb=0) $tmp=dol_html_entity_decode($stringtoescape,ENT_COMPAT,'UTF-8'); if ($keepb) $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n')); else $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n',""=>'',''=>'')); - return htmlentities($tmp,ENT_COMPAT,'UTF-8'); + return dol_htmlentities($tmp,ENT_COMPAT,'UTF-8'); } @@ -2473,8 +2473,8 @@ function dol_print_error($db='',$error='') } $out.="".$langs->trans("UserAgent").": ".$_SERVER["HTTP_USER_AGENT"]."
\n"; $out.="
\n"; - $out.="".$langs->trans("RequestedUrl").": ".htmlentities($_SERVER["REQUEST_URI"],ENT_COMPAT,'UTF-8')."
\n"; - $out.="".$langs->trans("Referer").": ".(isset($_SERVER["HTTP_REFERER"])?htmlentities($_SERVER["HTTP_REFERER"],ENT_COMPAT,'UTF-8'):'')."
\n"; + $out.="".$langs->trans("RequestedUrl").": ".dol_htmlentities($_SERVER["REQUEST_URI"],ENT_COMPAT,'UTF-8')."
\n"; + $out.="".$langs->trans("Referer").": ".(isset($_SERVER["HTTP_REFERER"])?dol_htmlentities($_SERVER["HTTP_REFERER"],ENT_COMPAT,'UTF-8'):'')."
\n"; $out.="".$langs->trans("MenuManager").": ".(isset($conf->standard_menu)?$conf->standard_menu:'')."
\n"; $out.="
\n"; $syslog.="url=".$_SERVER["REQUEST_URI"]; @@ -3859,13 +3859,13 @@ function dol_htmlentitiesbr($stringtoencode,$nl2brmode=0,$pagecodefrom='UTF-8',$ $newstring=preg_replace('//i','
',$newstring); // Replace "
" by "
". It's same and avoid pb with FPDF. if ($removelasteolbr) $newstring=preg_replace('/
$/i','',$newstring); // Remove last
(remove only last one) $newstring=strtr($newstring,array('&'=>'__and__','<'=>'__lt__','>'=>'__gt__','"'=>'__dquot__')); - $newstring=htmlentities($newstring,ENT_COMPAT,$pagecodefrom); // Make entity encoding + $newstring=dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom); // Make entity encoding $newstring=strtr($newstring,array('__and__'=>'&','__lt__'=>'<','__gt__'=>'>','__dquot__'=>'"')); } else { if ($removelasteolbr) $newstring=preg_replace('/(\r\n|\r|\n)$/i','',$newstring); // Remove last \n (may remove several) - $newstring=dol_nl2br(htmlentities($newstring,ENT_COMPAT,$pagecodefrom),$nl2brmode); + $newstring=dol_nl2br(dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom),$nl2brmode); } // Other substitutions that htmlentities does not do //$newstring=str_replace(chr(128),'€',$newstring); // 128 = 0x80. Not in html entity table. // Seems useles with TCPDF. Make bug with UTF8 languages @@ -3917,14 +3917,12 @@ function dol_html_entity_decode($a,$b,$c='UTF-8') /** * Replace htmlentities functions to manage errors * http://php.net/manual/en/function.htmlentities.php - * TODO Remove this function to replace it with direct htmlentities. * * @param string $string The input string. * @param int $flags Flags(see PHP doc above) * @param string $encoding Encoding * @param bool $double_encode When double_encode is turned off PHP will not encode existing html entities * @return string $ret Encoded string - * @deprecated Since PHP4 support is no longer available, this function does not make sense. */ function dol_htmlentities($string, $flags=null, $encoding='UTF-8', $double_encode=false) { diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index ca32a823d58..7be99f5e278 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -988,9 +988,9 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs $appli='Dolibarr'; if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $appli=$conf->global->MAIN_APPLICATION_TITLE; - if ($title && ! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/noapp/',$conf->global->MAIN_HTML_TITLE)) print ''.htmlentities($title).''; - if ($title) print ''.htmlentities($appli.' - '.$title).''; - else print "".htmlentities($appli).""; + if ($title && ! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/noapp/',$conf->global->MAIN_HTML_TITLE)) print ''.dol_htmlentities($title).''; + if ($title) print ''.dol_htmlentities($appli.' - '.$title).''; + else print "".dol_htmlentities($appli).""; print "\n"; $ext=''; diff --git a/htdocs/opensurvey/card.php b/htdocs/opensurvey/card.php index 019f739f5fd..5d32db24d5c 100644 --- a/htdocs/opensurvey/card.php +++ b/htdocs/opensurvey/card.php @@ -212,16 +212,16 @@ $adresseadmin=$object->mail_admin; print $langs->trans("Title") .'
'; // Description print ''; @@ -359,7 +359,7 @@ if ($comments) { print ' '.img_picto('', 'delete.png').' '; } - print htmlentities($comment->usercomment).': '.dol_nl2br(htmlentities($comment->comment))."
"; + print dol_htmlentities($comment->usercomment).': '.dol_nl2br(dol_htmlentities($comment->comment))."
"; } } else diff --git a/htdocs/opensurvey/list.php b/htdocs/opensurvey/list.php index ea17965fa9c..d13c9884e89 100644 --- a/htdocs/opensurvey/list.php +++ b/htdocs/opensurvey/list.php @@ -153,7 +153,7 @@ while ($i < min($num,$limit)) print ''; print ''; diff --git a/htdocs/opensurvey/public/studs.php b/htdocs/opensurvey/public/studs.php index 3050bf0ed08..1b39391b67c 100644 --- a/htdocs/opensurvey/public/studs.php +++ b/htdocs/opensurvey/public/studs.php @@ -258,7 +258,7 @@ print '
'."\n"; //affichage du titre du sondage $titre=str_replace("\\","",$object->titre); -print ''.htmlentities($titre).'

'."\n"; +print ''.dol_htmlentities($titre).'

'."\n"; //affichage des commentaires du sondage if ($object->commentaires) @@ -362,7 +362,7 @@ if ($object->format=="D") for ($i=0; isset($toutsujet[$i]); $i++) { $heures=explode('@',$toutsujet[$i]); if (isset($heures[1])) { - print '
'."\n"; + print ''."\n"; } else { print ''."\n"; } @@ -418,7 +418,7 @@ while ($compteur < $num) print ''."\n"; // Name - print ''."\n"; + print ''."\n"; // si la ligne n'est pas a changer, on affiche les données if (! $testligneamodifier) @@ -677,7 +677,7 @@ if ($object->allow_spy) { else { $tmps=explode('@',$toutsujet[$i]); - $meilleursujet .= htmlentities($tmps[0]); + $meilleursujet .= dol_htmlentities($tmps[0]); } $compteursujet++; @@ -717,7 +717,7 @@ if ($comments) foreach ($comments as $obj) { print '
'; if (in_array($obj->usercomment, $listofvoters)) print ' '.img_picto('', 'delete.png').' '; - print htmlentities($obj->usercomment).': '.dol_nl2br(htmlentities($obj->comment))."
"; + print dol_htmlentities($obj->usercomment).':'.dol_nl2br(dol_htmlentities($obj->comment)).""; } } diff --git a/htdocs/opensurvey/results.php b/htdocs/opensurvey/results.php index a543447ffbc..226bc0c0465 100644 --- a/htdocs/opensurvey/results.php +++ b/htdocs/opensurvey/results.php @@ -451,9 +451,9 @@ $adresseadmin=$object->mail_admin; print $langs->trans("Title") .''; // Expire date @@ -468,7 +468,7 @@ print $langs->trans("Author") .''; @@ -721,7 +721,7 @@ if ($object->format=="D") for ($i = 0; isset($toutsujet[$i]); $i++) { $heures=explode('@', $toutsujet[$i]); if (isset($heures[1])) { - print ''."\n"; + print ''."\n"; } else { print ''."\n"; } @@ -744,7 +744,7 @@ else for ($i = 0; isset($toutsujet[$i]); $i++) { $tmp=explode('@',$toutsujet[$i]); - print ''."\n"; + print ''."\n"; } print ''."\n"; @@ -780,7 +780,7 @@ while ($compteur < $num) } // Name - print ''."\n"; + print ''."\n"; // si la ligne n'est pas a changer, on affiche les données if (! $testligneamodifier) @@ -1047,7 +1047,7 @@ for ($i = 0; $i < $nbcolonnes; $i++) { else { $tmps=explode('@',$toutsujet[$i]); - $meilleursujet .= htmlentities($tmps[0]); + $meilleursujet .= dol_htmlentities($tmps[0]); } $compteursujet++; From ad7242529111062f5873b234cba7354555c03863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Mon, 2 Mar 2015 03:27:29 +0100 Subject: [PATCH 05/60] Moved some variables from FactureLigne to CommonInvoiceLine --- htdocs/compta/facture/class/facture.class.php | 35 ------- htdocs/core/class/commoninvoice.class.php | 95 +++++++++++++++++++ 2 files changed, 95 insertions(+), 35 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 4fbdddd5703..d9254df2374 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3586,16 +3586,12 @@ class Facture extends CommonInvoice */ class FactureLigne extends CommonInvoiceLine { - var $db; - var $error; - public $element='facturedet'; public $table_element='facturedet'; var $oldline; //! From llx_facturedet - var $rowid; //! Id facture var $fk_facture; //! Id parent line @@ -3603,17 +3599,9 @@ class FactureLigne extends CommonInvoiceLine var $label; // deprecated //! Description ligne var $desc; - var $fk_product; // Id of predefined product - var $product_type = 0; // Type 0 = product, 1 = Service - var $qty; // Quantity (example 2) - var $tva_tx; // Taux tva produit/service (example 19.6) - var $localtax1_tx; // Local tax 1 - var $localtax2_tx; // Local tax 2 var $localtax1_type; // Local tax 1 type var $localtax2_type; // Local tax 2 type - var $subprice; // P.U. HT (example 100) - var $remise_percent; // % de la remise ligne (example 20%) var $fk_remise_except; // Link to line into llx_remise_except var $rang = 0; @@ -3622,10 +3610,6 @@ class FactureLigne extends CommonInvoiceLine var $marge_tx; var $marque_tx; - var $info_bits = 0; // Liste d'options cumulables: - // Bit 0: 0 si TVA normal - 1 si TVA NPR - // Bit 1: 0 si ligne normal - 1 si bit discount (link to line into llx_remise_except) - var $special_code; // Liste d'options non cumulabels: // 1: frais de port // 2: ecotaxe @@ -3634,15 +3618,6 @@ class FactureLigne extends CommonInvoiceLine var $origin; var $origin_id; - //! Total HT de la ligne toute quantite et incluant la remise ligne - var $total_ht; - //! Total TVA de la ligne toute quantite et incluant la remise ligne - var $total_tva; - var $total_localtax1; //Total Local tax 1 de la ligne - var $total_localtax2; //Total Local tax 2 de la ligne - //! Total TTC de la ligne toute quantite et incluant la remise ligne - var $total_ttc; - var $fk_code_ventilation = 0; var $date_start; @@ -3671,16 +3646,6 @@ class FactureLigne extends CommonInvoiceLine */ public $fk_prev_id; - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - } - /** * Load invoice line from database * diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 6087a5a0adb..1a7ebfc34c8 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -400,5 +400,100 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobjectline.class.php'; */ abstract class CommonInvoiceLine extends CommonObjectLine { + /** + * Quantity + * @var int + */ + public $qty; + + /** + * Unit price before taxes + * @var float + */ + public $subprice; + + /** + * Type of the product. 0 for product 1 for service + * @var int + */ + public $product_type = 0; + + /** + * Id of corresponding product + * @var int + */ + public $fk_product; + + /** + * VAT % + * @var float + */ + public $tva_tx; + + /** + * Local tax 1 % + * @var float + */ + public $localtax1_tx; + + /** + * Local tax 2 % + * @var float + */ + public $localtax2_tx; + + /** + * Percent of discount + * @var float + */ + public $remise_percent; + + /** + * Total amount before taxes + * @var float + */ + public $total_ht; + + /** + * Total VAT amount + * @var float + */ + public $total_tva; + + /** + * Total local tax 1 amount + * @var float + */ + public $total_localtax1; + + /** + * Total local tax 2 amount + * @var float + */ + public $total_localtax2; + + /** + * Total amount with taxes + * @var float + */ + public $total_ttc; + + /** + * Liste d'options cumulables: + * Bit 0: 0 si TVA normal - 1 si TVA NPR + * Bit 1: 0 si ligne normal - 1 si bit discount (link to line into llx_remise_except) + * @var int + */ + public $info_bits = 0; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct(DoliDB $db) + { + $this->db = $db; + } } From c7919a8d08bded53a302c4635ee55de5e4c31c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Mon, 2 Mar 2015 03:27:48 +0100 Subject: [PATCH 06/60] Removed duplicated code --- .../fourn/class/fournisseur.facture.class.php | 33 +++---------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 8283f1cb957..a152b1a2b2c 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -89,37 +89,15 @@ class FactureFournisseur extends CommonInvoice var $mode_reglement_id; var $mode_reglement_code; - var $lines; + /** + * Invoice lines + * @var SupplierInvoiceLine[] + */ + public $lines = array(); var $fournisseur; // deprecated - var $thirdparty; // To store thirdparty var $extraparams=array(); - /** - * Standard invoice - */ - const TYPE_STANDARD = 0; - - /** - * Replacement invoice - */ - const TYPE_REPLACEMENT = 1; - - /** - * Credit note invoice - */ - const TYPE_CREDIT_NOTE = 2; - - /** - * Deposit invoice - */ - const TYPE_DEPOSIT = 3; - - /** - * Proforma invoice - */ - const TYPE_PROFORMA = 4; - /** * Constructor * @@ -140,7 +118,6 @@ class FactureFournisseur extends CommonInvoice $this->propalid = 0; $this->products = array(); - $this->lines = array(); } /** From b0e728251a1ffa5b35b747d929ca4e76be74e40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Mon, 2 Mar 2015 03:28:08 +0100 Subject: [PATCH 07/60] Every line has a $rowid property --- htdocs/core/class/commonobjectline.class.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index c3c8d823a34..7f81c85fa23 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -28,6 +28,12 @@ */ abstract class CommonObjectLine extends CommonObject { + /** + * Id of the line + * @var int + */ + public $rowid; + // TODO // Currently we need function at end of file CommonObject for all object lines. Should find a way to avoid duplicate code. From b69ce21e3e271e6691bc17d163b1295f99744e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Mon, 2 Mar 2015 03:52:59 +0100 Subject: [PATCH 08/60] Removed duplicated code --- htdocs/comm/propal/class/propal.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 189c6101594..4918e331d63 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -107,6 +107,9 @@ class Propal extends CommonObject var $products=array(); var $extraparams=array(); + /** + * @var PropaleLigne[] + */ var $lines = array(); var $line; @@ -2782,9 +2785,6 @@ class Propal extends CommonObject */ class PropaleLigne extends CommonObject { - var $db; - var $error; - public $element='propaldet'; public $table_element='propaldet'; From 4c08d34bb5332d42678a37d482007faa436569d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Mon, 2 Mar 2015 03:53:12 +0100 Subject: [PATCH 09/60] Standardized $rowid as property --- htdocs/commande/class/commande.class.php | 1 + htdocs/compta/facture/class/facture.class.php | 1 + htdocs/core/class/commonobject.class.php | 6 +++--- htdocs/core/class/commonobjectline.class.php | 7 +++++++ htdocs/core/tpl/objectline_edit.tpl.php | 4 ++-- htdocs/core/tpl/objectline_view.tpl.php | 12 ++++++------ htdocs/fichinter/class/fichinter.class.php | 1 - 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index c1c0fa9ec4e..01de7890f9b 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3141,6 +3141,7 @@ class Commande extends CommonOrder $this->lines[$i] = new OrderLine($this->db); $this->lines[$i]->id = $obj->rowid; + $this->lines[$i]->rowid = $obj->rowid; $this->lines[$i]->label = $obj->custom_label; $this->lines[$i]->description = $obj->description; $this->lines[$i]->fk_product = $obj->fk_product; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index d9254df2374..72801b121ff 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3388,6 +3388,7 @@ class Facture extends CommonInvoice $this->lines[$i] = new FactureLigne($this->db); $this->lines[$i]->id = $obj->rowid; + $this->lines[$i]->rowid = $obj->rowid; $this->lines[$i]->label = $obj->custom_label; // deprecated $this->lines[$i]->description = $obj->description; $this->lines[$i]->fk_product = $obj->fk_product; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index c4b2902113a..c08a2b449d7 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2671,7 +2671,7 @@ abstract class CommonObject * TODO Move this into an output class file (htmlline.class.php) * * @param string $action GET/POST action - * @param array $line Selected object line to output + * @param CommonObjectLine $line Selected object line to output * @param string $var Is it a an odd line (true) * @param int $num Number of line (0) * @param int $i I @@ -2699,7 +2699,7 @@ abstract class CommonObject if (! empty($line->date_end)) $type=1; // deprecated // Ligne en mode visu - if ($action != 'editline' || $selected != $line->id) + if ($action != 'editline' || $selected != $line->rowid) { // Product if ($line->fk_product > 0) @@ -2762,7 +2762,7 @@ abstract class CommonObject } // Ligne en mode update - if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) + if ($this->statut == 0 && $action == 'editline' && $selected == $line->rowid) { $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); if (! empty($conf->global->MAIN_HTML5_PLACEHOLDER)) $placeholder=' placeholder="'.$langs->trans("Label").'"'; diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index 7f81c85fa23..b88dfabe83d 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -28,6 +28,13 @@ */ abstract class CommonObjectLine extends CommonObject { + /** + * Id of the line + * @var int + * @deprecated Use $rowid + */ + public $id; + /** * Id of the line * @var int diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index 98f1b842f1a..6148d50f6fc 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -53,9 +53,9 @@ $coldisplay=-1; // We remove first td ?> > global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>global->MAIN_VIEW_LINE_NUMBER))?2:1; ?> -
+
- + diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 0664d471dec..3ae8a8bcaa4 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -44,11 +44,11 @@ if (empty($usemargins)) $usemargins=0; ?> -
> +> global->MAIN_VIEW_LINE_NUMBER)) { ?> - - + @@ -173,7 +173,7 @@ if (empty($usemargins)) $usemargins=0; - statut == 0 && ($user->rights->$element->creer || $permtoedit)) { ?> + statut == 0 && ($object_rights->creer)) { ?> '; +//Help text +$help_text = $langs->trans("PriceExpressionEditorHelp1"); +$help_text.= '

'.$langs->trans("PriceExpressionEditorHelp2"); +$help_text.= '

'.$langs->trans("PriceExpressionEditorHelp3"); +$help_text.= '

'.$langs->trans("PriceExpressionEditorHelp4"); +$help_text.= '

'.$langs->trans("PriceExpressionEditorHelp5"); +foreach ($price_globals->listGlobalVariables() as $entry) { + $help_text.= '
#globals_'.$entry->code.'# '.$entry->description.' = '.$entry->value; +} + //Price expression editor -$help_text = $langs->trans("PriceExpressionEditorHelp1").'

'.$langs->trans("PriceExpressionEditorHelp2").'

'.$langs->trans("PriceExpressionEditorHelp3").'

'.$langs->trans("PriceExpressionEditorHelp4"); print ''; print '
'; } - $ret.=htmlentities($object->$fieldref); + $ret.=dol_htmlentities($object->$fieldref); if ($morehtmlref) { $ret.=' '.$morehtmlref; diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 54f2748cfd1..a54cb5fcc79 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -249,7 +249,7 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='',$oker $newsql=preg_replace('/__ENTITY__/i',(!empty($entity)?$entity:$conf->entity),$sql); // Ajout trace sur requete (eventuellement a commenter si beaucoup de requetes) - if (! $silent) print '
'.$langs->trans("Request").' '.($i+1)." sql='".htmlentities($newsql,ENT_NOQUOTES)."'
'.$langs->trans("Request").' '.($i+1)." sql='".dol_htmlentities($newsql,ENT_NOQUOTES)."'
'; if ($action == 'edit') { - print ''; + print ''; } -else print htmlentities($object->titre); +else print dol_htmlentities($object->titre); print '
'.$langs->trans("Description") .''; if ($action == 'edit') { - $doleditor=new DolEditor('nouveauxcommentaires', htmlentities($object->commentaires),'',120,'dolibarr_notes','In',1,1,1,ROWS_7,120); + $doleditor=new DolEditor('nouveauxcommentaires', dol_htmlentities($object->commentaires),'',120,'dolibarr_notes','In',1,1,1,ROWS_7,120); $doleditor->Create(0,''); } else @@ -229,7 +229,7 @@ else if (empty($conf->fckeditor->enabled)) print dol_htmlentitiesbr($object->commentaires); else { - $doleditor=new DolEditor('nouveauxcommentaires', htmlentities($object->commentaires),'',120,'dolibarr_notes','In',1,1,1,ROWS_7,120,1); + $doleditor=new DolEditor('nouveauxcommentaires', dol_htmlentities($object->commentaires),'',120,'dolibarr_notes','In',1,1,1,ROWS_7,120,1); $doleditor->Create(0,''); } } @@ -295,7 +295,7 @@ print $langs->trans("Author") .''; if ($object->fk_user_creat) { print $userstatic->getLoginUrl(1); } else { - print htmlentities($object->nom_admin); + print dol_htmlentities($object->nom_admin); } print '
'; print ''.img_picto('','object_opensurvey').' '.$obj->id_sondage.''; - print ''.htmlentities($obj->titre).''; + print ''.dol_htmlentities($obj->titre).''; $type=($obj->format=='A')?'classic':'date'; print img_picto('',dol_buildpath('/opensurvey/img/'.($type == 'classic'?'chart-32.png':'calendar-32.png'),1),'width="16"',1); print ' '.$langs->trans($type=='classic'?"TypeClassic":"TypeDate"); @@ -169,7 +169,7 @@ while ($i < min($num,$limit)) print $userstatic->getLoginUrl(1); } else { - print htmlentities($obj->nom_admin); + print dol_htmlentities($obj->nom_admin); } print ''.htmlentities($heures[1]).''.dol_htmlentities($heures[1]).'
'.htmlentities($obj->name).''.dol_htmlentities($obj->name).' '; if ($action == 'edit') { - print ''; + print ''; } -else print htmlentities($object->titre); +else print dol_htmlentities($object->titre); print '
'; if ($object->fk_user_creat) { print $userstatic->getLoginUrl(1); } else { - print htmlentities($object->nom_admin); + print dol_htmlentities($object->nom_admin); } print '
'.htmlentities($heures[1]).''.dol_htmlentities($heures[1]).''.htmlentities($tmp[0]).''.dol_htmlentities($tmp[0]).''.img_picto('',dol_buildpath('/opensurvey/img/add-16.png',1),'',1).''.htmlentities($obj->name).''.dol_htmlentities($obj->name).'
+
info_bits & 2) == 2) { ?> info_bits & 2) == 2) { ?> - id.'#'.$line->id; ?>"> + rowid.'#'.$line->rowid; ?>"> @@ -186,7 +186,7 @@ if (empty($usemargins)) $usemargins=0;
situation_counter == 1 || !$this->situation_cycle_ref) { - print 'id . '">'; + print 'rowid . '">'; print img_delete(); print ''; } @@ -196,12 +196,12 @@ if (empty($usemargins)) $usemargins=0; 1 && empty($conf->browser->phone) && ($this->situation_counter == 1 || !$this->situation_cycle_ref)) { ?> 0) { ?> - id; ?>"> + rowid; ?>"> - id; ?>"> + rowid; ?>"> diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 7be3b0bf3bd..e98852685ad 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -1022,7 +1022,6 @@ class FichinterLigne extends CommonObjectLine var $error; // From llx_fichinterdet - var $rowid; var $fk_fichinter; var $desc; // Description ligne var $datei; // Date intervention From b84cf4afac89ab6c5112c5edf94c3a4f85bcbfcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 4 Mar 2015 10:21:20 +0100 Subject: [PATCH 10/60] Renamed FactureFournisseurLine to SupplierInvoiceLine --- htdocs/core/tpl/objectline_create.tpl.php | 2 +- htdocs/fourn/class/fournisseur.facture.class.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 8a98ac2f613..6481a5961ca 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -281,7 +281,7 @@ else { $newline = new CommandeFournisseurLigne($this->db); } elseif ($this->table_element_line=='facture_fourn_det') { - $newline = new FactureFournisseurLigne($this->db); + $newline = new SupplierInvoiceLine($this->db); } if (is_object($newline)) { print $newline->showOptionals($extrafieldsline, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay+8)); diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index a152b1a2b2c..c6e5cb9d5e6 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -478,7 +478,7 @@ class FactureFournisseur extends CommonInvoice { $obj = $this->db->fetch_object($resql_rows); - $this->lines[$i] = new FactureFournisseurLigne($this->db); + $this->lines[$i] = new SupplierInvoiceLine($this->db); $this->lines[$i]->id = $obj->rowid; $this->lines[$i]->rowid = $obj->rowid; @@ -1274,7 +1274,7 @@ class FactureFournisseur extends CommonInvoice if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { - $linetmp = new FactureFournisseurLigne($this->db); + $linetmp = new SupplierInvoiceLine($this->db); $linetmp->id=$this->rowid; $linetmp->array_options = $array_options; $result=$linetmp->insertExtraFields(); @@ -1826,7 +1826,7 @@ class FactureFournisseur extends CommonInvoice /** * Class to manage line invoices */ -class FactureFournisseurLigne extends CommonInvoice +class SupplierInvoiceLine extends CommonInvoice { var $db; var $error; From 47a151f1572509362b556772520648aa2253e4b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 4 Mar 2015 10:23:18 +0100 Subject: [PATCH 11/60] Created supplier invoice line --- .../fourn/class/fournisseur.facture.class.php | 85 ++++++++++++++++--- 1 file changed, 74 insertions(+), 11 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index c6e5cb9d5e6..22f3c02a5a1 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -457,7 +457,7 @@ class FactureFournisseur extends CommonInvoice */ function fetch_lines() { - $sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx, f.tva'; + $sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx'; $sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 '; $sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line'; $sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc'; @@ -488,6 +488,7 @@ class FactureFournisseur extends CommonInvoice $this->lines[$i]->ref_supplier = $obj->ref_supplier; // Reference product supplier TODO Rename field ref to ref_supplier into table llx_facture_fourn_det and llx_commande_fournisseurdet and update fields it into updateline $this->lines[$i]->libelle = $obj->label; // This field may contains label of product (when invoice create from order) $this->lines[$i]->product_desc = $obj->product_desc; // Description du produit + $this->lines[$i]->subprice = $obj->pu_ht; $this->lines[$i]->pu_ht = $obj->pu_ht; $this->lines[$i]->pu_ttc = $obj->pu_ttc; $this->lines[$i]->tva_tx = $obj->tva_tx; @@ -495,7 +496,7 @@ class FactureFournisseur extends CommonInvoice $this->lines[$i]->localtax2_tx = $obj->localtax2_tx; $this->lines[$i]->qty = $obj->qty; $this->lines[$i]->remise_percent = $obj->remise_percent; - $this->lines[$i]->tva = $obj->tva; + $this->lines[$i]->tva = $obj->total_tva; $this->lines[$i]->total_ht = $obj->total_ht; $this->lines[$i]->total_tva = $obj->total_tva; $this->lines[$i]->total_localtax1 = $obj->total_localtax1; @@ -1819,6 +1820,18 @@ class FactureFournisseur extends CommonInvoice return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } + /** + * Returns the rights used for this class + * @return stdClass + */ + public function getRights() + { + global $user; + + return $user->rights->fournisseur->facture; + } + + } @@ -1828,18 +1841,68 @@ class FactureFournisseur extends CommonInvoice */ class SupplierInvoiceLine extends CommonInvoice { - var $db; - var $error; - - var $pu_ht; - var $pu_ttc; - - public $element='facture_fourn_det'; + public $element='fournisseur->facture'; public $table_element='facture_fourn_det'; - var $oldline; + var $oldline; - /** + public $ref; + public $product_ref; + public $ref_supplier; + public $libelle; + public $product_desc; + + /** + * Unit price before taxes + * @var float + * @deprecated Use $subprice + */ + public $pu_ht; + + /** + * Unit price included taxes + * @var float + */ + public $pu_ttc; + + /** + * Total VAT amount + * @var float + * @deprecated Use $total_tva instead + */ + public $tva; + + /** + * Id of the corresponding supplier invoice + * @var int + */ + var $fk_facture_fourn; + + /** + * Product label + * @var string + */ + var $label; // deprecated + + /** + * Description of the line + * @var string + */ + var $description; + + var $skip_update_total; // Skip update price total for special lines + + /** + * @var int Situation advance percentage + */ + public $situation_percent; + + /** + * @var int Previous situation line id reference + */ + public $fk_prev_id; + + /** * Constructor * * @param DoliDB $db Database handler From 174f1cb5f7607407ff60a8d52898d1ff0b369efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 4 Mar 2015 10:28:37 +0100 Subject: [PATCH 12/60] Refactored supplier invoice line view to fit commonobjectline view --- htdocs/core/class/commonobject.class.php | 16 +++++++++++++++- htdocs/core/tpl/objectline_view.tpl.php | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index c08a2b449d7..523716a8c84 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2686,7 +2686,9 @@ abstract class CommonObject function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0,$permtoedit=0) { global $conf,$langs,$user,$object,$hookmanager; - global $form,$bc,$bcdd; + global $form,$bc,$bcdd, $object_rights; + + $object_rights = $this->getRights(); $element=$this->element; @@ -3727,4 +3729,16 @@ abstract class CommonObject return $out; } + /** + * Returns the rights used for this class + * @return stdClass + */ + public function getRights() + { + global $user; + + return $user->rights->{$this->element}; + } + + } diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 3ae8a8bcaa4..2203642f0dc 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -122,7 +122,7 @@ if (empty($usemargins)) $usemargins=0; tva_tx,'%',$line->info_bits); ?>pu_ht)?price($line->pu_ht):price($line->subprice)); ?>pu_ht); ?> pu_ttc)?price($line->pu_ttc):price($line->subprice)); ?>total_ht); ?> info_bits & 2) == 2) { ?> From f82df1e634e67db455dd21ea722739a6eabd9825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 4 Mar 2015 10:32:09 +0100 Subject: [PATCH 13/60] Refactorred supplier order to match with objectline templates --- htdocs/core/class/commonorder.class.php | 3 +- .../class/fournisseur.commande.class.php | 128 +++++++++++++++--- 2 files changed, 108 insertions(+), 23 deletions(-) diff --git a/htdocs/core/class/commonorder.class.php b/htdocs/core/class/commonorder.class.php index 469e1676a53..3e30b0a9ca6 100644 --- a/htdocs/core/class/commonorder.class.php +++ b/htdocs/core/class/commonorder.class.php @@ -22,6 +22,7 @@ */ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT .'/core/class/commonobjectline.class.php'; /** * \class CommonOrder @@ -36,7 +37,7 @@ abstract class CommonOrder extends CommonObject * \class CommonOrderLine * \brief Superclass for orders classes */ -abstract class CommonOrderLine extends CommonObject +abstract class CommonOrderLine extends CommonObjectLine { } diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index e626760f83e..3d4bfd7fb90 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -88,8 +88,12 @@ class CommandeFournisseur extends CommonOrder var $extraparams=array(); + /** + * @var CommandeFournisseurLigne[] + */ + public $lines = array(); - /** + /** * Constructor * * @param DoliDB $db Database handler @@ -98,7 +102,6 @@ class CommandeFournisseur extends CommonOrder { $this->db = $db; $this->products = array(); - $this->lines = array(); // List of language codes for status $this->statuts[0] = 'StatusOrderDraft'; @@ -237,6 +240,7 @@ class CommandeFournisseur extends CommonOrder $line = new CommandeFournisseurLigne($this->db); $line->id = $objp->rowid; + $line->rowid = $objp->rowid; $line->desc = $objp->description; // Description ligne $line->description = $objp->description; // Description ligne $line->qty = $objp->qty; @@ -2206,6 +2210,18 @@ class CommandeFournisseur extends CommonOrder if ($nb === 0) return $langs->trans('Undefined'); else return $nb.' '.$langs->trans('Days'); } + + /** + * Returns the rights used for this class + * @return stdClass + */ + public function getRights() + { + global $user; + + return $user->rights->fournisseur->commande; + } + } @@ -2221,27 +2237,95 @@ class CommandeFournisseurLigne extends CommonOrderLine public $element='commande_fournisseurdet'; public $table_element='commande_fournisseurdet'; - var $oldline; + /** + * Quantity + * @var int + */ - // From llx_commandedet - var $qty; - var $tva_tx; - var $localtax1_tx; - var $localtax2_tx; - var $localtax1_type; - var $localtax2_type; - var $subprice; - var $remise_percent; - var $desc; // Description ligne - var $fk_product; // Id of predefined product - var $product_type = 0; // Type 0 = product, 1 = Service - var $total_ht; - var $total_tva; - var $total_localtax1; - var $total_localtax2; - var $total_ttc; - var $info_bits; - var $special_code; + /** + * Unit price before taxes + * @var float + */ + public $subprice; + + /** + * Type of the product. 0 for product 1 for service + * @var int + */ + public $product_type = 0; + + /** + * Description of the line + * @var string + */ + var $desc; + + /** + * Id of corresponding product + * @var int + */ + public $fk_product; + + /** + * VAT % + * @var float + */ + public $tva_tx; + + /** + * Local tax 1 % + * @var float + */ + public $localtax1_tx; + + /** + * Local tax 2 % + * @var float + */ + public $localtax2_tx; + + var $localtax1_type; + var $localtax2_type; + + /** + * Total amount before taxes + * @var float + */ + public $total_ht; + + /** + * Total VAT amount + * @var float + */ + public $total_tva; + + /** + * Total local tax 1 amount + * @var float + */ + public $total_localtax1; + + /** + * Total local tax 2 amount + * @var float + */ + public $total_localtax2; + + /** + * Total amount with taxes + * @var float + */ + public $total_ttc; + + /** + * Liste d'options cumulables: + * Bit 0: 0 si TVA normal - 1 si TVA NPR + * Bit 1: 0 si ligne normal - 1 si bit discount (link to line into llx_remise_except) + * @var int + */ + public $info_bits = 0; + + var $special_code; var $date_start; var $date_end; From e1982c54d9cf64b7458717757f4453b4f6b0ec59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 4 Mar 2015 10:34:19 +0100 Subject: [PATCH 14/60] Moved duplicated code to common class --- htdocs/commande/class/commande.class.php | 60 ++++++------ htdocs/core/class/commonorder.class.php | 96 +++++++++++++++++++ .../class/fournisseur.commande.class.php | 92 ------------------ 3 files changed, 125 insertions(+), 123 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 01de7890f9b..cdf73d58c7e 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -104,7 +104,10 @@ class Commande extends CommonOrder var $user_author_id; - var $lines = array(); + /** + * @var OrderLine[] + */ + var $lines = array(); /** @@ -3228,54 +3231,49 @@ class Commande extends CommonOrder */ class OrderLine extends CommonOrderLine { - var $db; - var $error; - public $element='commandedet'; public $table_element='commandedet'; var $oldline; // From llx_commandedet - var $rowid; var $fk_parent_line; var $fk_facture; var $label; - var $desc; // Description ligne - var $fk_product; // Id produit predefini - var $product_type = 0; // Type 0 = product, 1 = Service - - var $qty; // Quantity (example 2) - var $tva_tx; // VAT Rate for product/service (example 19.6) - var $localtax1_tx; // Local tax 1 - var $localtax2_tx; // Local tax 2 - var $localtax1_type; // Local tax 1 type - var $localtax2_type; // Local tax 2 type - var $subprice; // U.P. HT (example 100) - var $remise_percent; // % for line discount (example 20%) var $fk_remise_except; var $rang = 0; var $fk_fournprice; + + /** + * Buy price without taxes + * @var float + */ var $pa_ht; var $marge_tx; var $marque_tx; - var $info_bits = 0; // Bit 0: 0 si TVA normal - 1 si TVA NPR - // Bit 1: 0 ligne normale - 1 si ligne de remise fixe - var $special_code = 0; - var $total_ht; // Total HT de la ligne toute quantite et incluant la remise ligne - var $total_tva; // Total TVA de la ligne toute quantite et incluant la remise ligne - var $total_localtax1; // Total local tax 1 for the line - var $total_localtax2; // Total local tax 2 for the line - var $total_ttc; // Total TTC de la ligne toute quantite et incluant la remise ligne - // Ne plus utiliser - var $remise; - var $price; + /** + * @deprecated + */ + var $remise; + + /** + * @deprecated + */ + var $price; // From llx_product - var $ref; // deprecated - var $libelle; // deprecated - var $product_ref; + /** + * @deprecated Use product_ref + */ + var $ref; + + /** + * @deprecated Use product_label + */ + var $libelle; + + var $product_ref; var $product_label; // Label produit var $product_desc; // Description produit diff --git a/htdocs/core/class/commonorder.class.php b/htdocs/core/class/commonorder.class.php index 3e30b0a9ca6..eadf34d5583 100644 --- a/htdocs/core/class/commonorder.class.php +++ b/htdocs/core/class/commonorder.class.php @@ -39,6 +39,102 @@ abstract class CommonOrder extends CommonObject */ abstract class CommonOrderLine extends CommonObjectLine { + /** + * Quantity + * @var int + */ + public $qty; + + /** + * Unit price before taxes + * @var float + */ + public $subprice; + + /** + * Type of the product. 0 for product 1 for service + * @var int + */ + public $product_type = 0; + + /** + * Description of the line + * @var string + */ + public $desc; + + /** + * Id of corresponding product + * @var int + */ + public $fk_product; + + /** + * Percent line discount + * @var float + */ + public $remise_percent; + + /** + * VAT % + * @var float + */ + public $tva_tx; + + /** + * Local tax 1 % + * @var float + */ + public $localtax1_tx; + + /** + * Local tax 2 % + * @var float + */ + public $localtax2_tx; + + public $localtax1_type; + public $localtax2_type; + + /** + * Total amount before taxes + * @var float + */ + public $total_ht; + + /** + * Total VAT amount + * @var float + */ + public $total_tva; + + /** + * Total local tax 1 amount + * @var float + */ + public $total_localtax1; + + /** + * Total local tax 2 amount + * @var float + */ + public $total_localtax2; + + /** + * Total amount with taxes + * @var float + */ + public $total_ttc; + + /** + * Liste d'options cumulables: + * Bit 0: 0 si TVA normal - 1 si TVA NPR + * Bit 1: 0 si ligne normal - 1 si bit discount (link to line into llx_remise_except) + * @var int + */ + public $info_bits = 0; + + public $special_code = 0; } diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 3d4bfd7fb90..bc2e1e564b2 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2231,101 +2231,9 @@ class CommandeFournisseur extends CommonOrder */ class CommandeFournisseurLigne extends CommonOrderLine { - var $db; - var $error; - public $element='commande_fournisseurdet'; public $table_element='commande_fournisseurdet'; - /** - * Quantity - * @var int - */ - - /** - * Unit price before taxes - * @var float - */ - public $subprice; - - /** - * Type of the product. 0 for product 1 for service - * @var int - */ - public $product_type = 0; - - /** - * Description of the line - * @var string - */ - var $desc; - - /** - * Id of corresponding product - * @var int - */ - public $fk_product; - - /** - * VAT % - * @var float - */ - public $tva_tx; - - /** - * Local tax 1 % - * @var float - */ - public $localtax1_tx; - - /** - * Local tax 2 % - * @var float - */ - public $localtax2_tx; - - var $localtax1_type; - var $localtax2_type; - - /** - * Total amount before taxes - * @var float - */ - public $total_ht; - - /** - * Total VAT amount - * @var float - */ - public $total_tva; - - /** - * Total local tax 1 amount - * @var float - */ - public $total_localtax1; - - /** - * Total local tax 2 amount - * @var float - */ - public $total_localtax2; - - /** - * Total amount with taxes - * @var float - */ - public $total_ttc; - - /** - * Liste d'options cumulables: - * Bit 0: 0 si TVA normal - 1 si TVA NPR - * Bit 1: 0 si ligne normal - 1 si bit discount (link to line into llx_remise_except) - * @var int - */ - public $info_bits = 0; - - var $special_code; var $date_start; var $date_end; From 54b6b199c729bdf61211182e5e8962d12655b3e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 4 Mar 2015 10:03:40 +0100 Subject: [PATCH 15/60] Documented missing properties and removed redundant documentation (cherry picked from commit 6124f6a) --- htdocs/commande/class/commande.class.php | 25 ++++++-- htdocs/core/class/commonorder.class.php | 37 ++++++++++++ .../class/fournisseur.commande.class.php | 58 +++++++++++++------ 3 files changed, 96 insertions(+), 24 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index cdf73d58c7e..a79483bd979 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1604,12 +1604,12 @@ class Commande extends CommonOrder $line = new OrderLine($this->db); - $line->rowid = $objp->rowid; // \deprecated + $line->rowid = $objp->rowid; $line->id = $objp->rowid; $line->fk_commande = $objp->fk_commande; - $line->commande_id = $objp->fk_commande; // \deprecated + $line->commande_id = $objp->fk_commande; $line->label = $objp->custom_label; - $line->desc = $objp->description; // Description ligne + $line->desc = $objp->description; $line->product_type = $objp->product_type; $line->qty = $objp->qty; $line->tva_tx = $objp->tva_tx; @@ -1635,11 +1635,11 @@ class Commande extends CommonOrder $line->special_code = $objp->special_code; $line->fk_parent_line = $objp->fk_parent_line; - $line->ref = $objp->product_ref; // TODO deprecated + $line->ref = $objp->product_ref; $line->product_ref = $objp->product_ref; - $line->libelle = $objp->product_label; // TODO deprecated + $line->libelle = $objp->product_label; $line->product_label = $objp->product_label; - $line->product_desc = $objp->product_desc; // Description produit + $line->product_desc = $objp->product_desc; $line->fk_product_type = $objp->fk_product_type; // Produit ou service $line->date_start = $this->db->jdate($objp->date_start); @@ -3236,6 +3236,19 @@ class OrderLine extends CommonOrderLine var $oldline; + /** + * Id of parent order + * @var int + */ + public $fk_commande; + + /** + * Id of parent order + * @var int + * @deprecated Use fk_commande + */ + public $commande_id; + // From llx_commandedet var $fk_parent_line; var $fk_facture; diff --git a/htdocs/core/class/commonorder.class.php b/htdocs/core/class/commonorder.class.php index eadf34d5583..b4882af8a58 100644 --- a/htdocs/core/class/commonorder.class.php +++ b/htdocs/core/class/commonorder.class.php @@ -39,12 +39,49 @@ abstract class CommonOrder extends CommonObject */ abstract class CommonOrderLine extends CommonObjectLine { + /** + * Product ref + * @var string + * @deprecated Use product_ref + */ + public $ref; + + /** + * Product ref + * @var string + */ + public $product_ref; + + /** + * Product label + * @var string + * @deprecated Use product_label + */ + public $libelle; + + /** + * Product label + * @var string + */ + public $product_label; + + /** + * Product description + * @var string + */ + public $product_desc; + /** * Quantity * @var int */ public $qty; + /** + * @deprecated + */ + var $price; + /** * Unit price before taxes * @var float diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index bc2e1e564b2..f3738fca2b4 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -241,14 +241,14 @@ class CommandeFournisseur extends CommonOrder $line->id = $objp->rowid; $line->rowid = $objp->rowid; - $line->desc = $objp->description; // Description ligne - $line->description = $objp->description; // Description ligne + $line->desc = $objp->description; + $line->description = $objp->description; $line->qty = $objp->qty; $line->tva_tx = $objp->tva_tx; $line->localtax1_tx = $objp->localtax1_tx; $line->localtax2_tx = $objp->localtax2_tx; - $line->subprice = $objp->subprice; // deprecated - $line->pu_ht = $objp->subprice; // Unit price HT + $line->subprice = $objp->subprice; + $line->pu_ht = $objp->subprice; $line->remise_percent = $objp->remise_percent; $line->total_ht = $objp->total_ht; $line->total_tva = $objp->total_tva; @@ -257,16 +257,16 @@ class CommandeFournisseur extends CommonOrder $line->total_ttc = $objp->total_ttc; $line->product_type = $objp->product_type; - $line->fk_product = $objp->fk_product; // Id du produit + $line->fk_product = $objp->fk_product; - $line->libelle = $objp->product_label; // TODO deprecated - $line->product_label = $objp->product_label; // Label produit - $line->product_desc = $objp->product_desc; // Description produit + $line->libelle = $objp->product_label; + $line->product_label = $objp->product_label; + $line->product_desc = $objp->product_desc; - $line->ref = $objp->product_ref; // TODO deprecated - $line->product_ref = $objp->product_ref; // Internal reference - $line->ref_fourn = $objp->ref_supplier; // TODO deprecated - $line->ref_supplier = $objp->ref_supplier; // Reference supplier + $line->ref = $objp->product_ref; + $line->product_ref = $objp->product_ref; + $line->ref_fourn = $objp->ref_supplier; + $line->ref_supplier = $objp->ref_supplier; $line->date_start = $this->db->jdate($objp->date_start); $line->date_end = $this->db->jdate($objp->date_end); @@ -2233,16 +2233,38 @@ class CommandeFournisseurLigne extends CommonOrderLine { public $element='commande_fournisseurdet'; public $table_element='commande_fournisseurdet'; + + /** + * Unit price without taxes + * @var float + */ + public $pu_ht; - var $date_start; + /** + * Unit price without taxes + * @var float + * @deprecated Use pu_ht + */ + public $subprice; + + + var $date_start; var $date_end; - // From llx_product - var $libelle; // Label produit - var $product_desc; // Description produit - // From llx_product_fournisseur_price - var $ref_fourn; // Ref supplier + + /** + * Supplier ref + * @var string + * @deprecated Use ref_supplier + */ + public $ref_fourn; + + /** + * Supplier reference + * @var string + */ + public $ref_supplier; /** From a7741350fe7940b2574adff02d5966569042a794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 4 Mar 2015 10:41:40 +0100 Subject: [PATCH 16/60] Revert unwanted change --- htdocs/fourn/class/fournisseur.facture.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 22f3c02a5a1..3ea6675cc8f 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1841,7 +1841,7 @@ class FactureFournisseur extends CommonInvoice */ class SupplierInvoiceLine extends CommonInvoice { - public $element='fournisseur->facture'; + public $element='facture_fourn_det'; public $table_element='facture_fourn_det'; var $oldline; From 7a2e60bb65c97acaf487669ef85348bcf070373b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 4 Mar 2015 10:45:30 +0100 Subject: [PATCH 17/60] No need to PHP < 5.3.0 compatibility --- htdocs/filefunc.inc.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 7343e65c854..15bee891775 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -83,7 +83,6 @@ if (! empty($dolibarr_strict_mode)) } else { - if (! defined('E_DEPRECATED')) define('E_DEPRECATED',0); // For PHP < 5.3.0 compatibility error_reporting(E_ALL & ~(E_STRICT|E_NOTICE|E_DEPRECATED)); } From 6ec8a38e4a8221677dd08f21dc08323db6cbb689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 4 Mar 2015 10:46:26 +0100 Subject: [PATCH 18/60] Removed duplicated code --- htdocs/commande/class/commande.class.php | 20 ------------------- .../class/fournisseur.commande.class.php | 8 -------- 2 files changed, 28 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index a79483bd979..9c0d4c44aae 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3270,26 +3270,6 @@ class OrderLine extends CommonOrderLine */ var $remise; - /** - * @deprecated - */ - var $price; - - // From llx_product - /** - * @deprecated Use product_ref - */ - var $ref; - - /** - * @deprecated Use product_label - */ - var $libelle; - - var $product_ref; - var $product_label; // Label produit - var $product_desc; // Description produit - // Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) // Start and end date of the line var $date_start; diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index f3738fca2b4..41b9458e006 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2240,14 +2240,6 @@ class CommandeFournisseurLigne extends CommonOrderLine */ public $pu_ht; - /** - * Unit price without taxes - * @var float - * @deprecated Use pu_ht - */ - public $subprice; - - var $date_start; var $date_end; From f94f9d1e577efe74de767441fd3af62465d7feb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 4 Mar 2015 11:19:45 +0100 Subject: [PATCH 19/60] Removed $permtoedit variable --- htdocs/core/class/commonobject.class.php | 7 +++---- htdocs/fourn/commande/card.php | 2 +- htdocs/fourn/facture/card.php | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 523716a8c84..586d5af0171 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2571,7 +2571,7 @@ abstract class CommonObject * @param int $permtoedit Permission to edit line * @return void */ - function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0, $permtoedit=0) + function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) { global $conf, $hookmanager, $inputalsopricewithtax, $usemargins, $langs, $user; @@ -2659,7 +2659,7 @@ abstract class CommonObject } else { - $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline,$permtoedit); + $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); } $i++; @@ -2680,10 +2680,9 @@ abstract class CommonObject * @param string $buyer Object of buyer third party * @param string $selected Object line selected * @param object $extrafieldsline Object of extrafield line attribute - * @param int $permtoedit Permission to edit * @return void */ - function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0,$permtoedit=0) + function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) { global $conf,$langs,$user,$object,$hookmanager; global $form,$bc,$bcdd, $object_rights; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 68724345411..689ac41d2ef 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -1748,7 +1748,7 @@ elseif (! empty($object->id)) // Show object lines $inputalsopricewithtax=0; if (! empty($object->lines)) - $ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, 1, $user->rights->fournisseur->commande->creer); + $ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, 1); $num = count($object->lines); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 01be69f1590..cd1e60a37ed 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2054,7 +2054,7 @@ else // Show object lines if (! empty($object->lines)) - $ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, 1, $user->rights->fournisseur->facture->creer); + $ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, 1); $num=count($object->lines); From ea0964d1ebaba35685c215afe0cc11cdf8a52390 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Tue, 10 Mar 2015 17:17:02 +0100 Subject: [PATCH 20/60] Update export.class.php add specific choice of prefix for export (usefull with many dolibarr exporting data) --- htdocs/exports/class/export.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/exports/class/export.class.php b/htdocs/exports/class/export.class.php index d332592da6d..9ff540a92f2 100644 --- a/htdocs/exports/class/export.class.php +++ b/htdocs/exports/class/export.class.php @@ -524,7 +524,10 @@ class Export if ($resql) { //$this->array_export_label[$indice] - $filename="export_".$datatoexport; + if ($conf->global->EXPORT_PREFIX) + $filename=$conf->global->EXPORT_PREFIX_SPEC."_".$datatoexport; + else + $filename="export_".$datatoexport; $filename.='.'.$objmodel->getDriverExtension(); $dirname=$conf->export->dir_temp.'/'.$user->id; From bf86693dcb05f0e41c819c67df6399c71ec7f3f0 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Tue, 10 Mar 2015 21:47:39 +0100 Subject: [PATCH 21/60] Update sellsjournal.php --- htdocs/accountancy/journal/sellsjournal.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index b3ca7ceae98..c0251291964 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -271,7 +271,11 @@ if ($action == 'export_csv') $sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL; header('Content-Type: text/csv'); - header('Content-Disposition: attachment;filename=journal_ventes.csv'); + if ($conf->global->EXPORT_PREFIX) + $filename=$conf->global->EXPORT_PREFIX_SPEC."_"."journal_ventes.csv"; + else + $filename="journal_ventes.csv"; + header('Content-Disposition: attachment;filename='.$filename); $companystatic = new Client($db); From f91127c92a335b9b281f86b8ed2753239ec616fc Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Tue, 10 Mar 2015 21:48:47 +0100 Subject: [PATCH 22/60] Update purchasesjournal.php --- htdocs/accountancy/journal/purchasesjournal.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 905296358f0..521a1c6a74c 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -249,7 +249,11 @@ if ($action == 'export_csv') $purchase_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL; header('Content-Type: text/csv'); - header('Content-Disposition: attachment;filename=journal_achats.csv'); + if ($conf->global->EXPORT_PREFIX) + $filename=$conf->global->EXPORT_PREFIX_SPEC."_"."journal_achats.csv"; + else + $filename="journal_achats.csv"; + header('Content-Disposition: attachment;filename='.$filename); if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) // Model Cegid Expert Export { From f88646d954664e48a2c2a59b9be3451286268384 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Wed, 11 Mar 2015 10:22:37 +0100 Subject: [PATCH 23/60] Update export.class.php --- htdocs/exports/class/export.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/exports/class/export.class.php b/htdocs/exports/class/export.class.php index 9ff540a92f2..707b38e1ef7 100644 --- a/htdocs/exports/class/export.class.php +++ b/htdocs/exports/class/export.class.php @@ -524,7 +524,7 @@ class Export if ($resql) { //$this->array_export_label[$indice] - if ($conf->global->EXPORT_PREFIX) + if ($conf->global->EXPORT_PREFIX_SPEC) $filename=$conf->global->EXPORT_PREFIX_SPEC."_".$datatoexport; else $filename="export_".$datatoexport; From 9fc83ca011c47be0540989bc6c7160d116d532bc Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Wed, 11 Mar 2015 10:23:13 +0100 Subject: [PATCH 24/60] Update sellsjournal.php --- htdocs/accountancy/journal/sellsjournal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index c0251291964..7605d54825c 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -271,7 +271,7 @@ if ($action == 'export_csv') $sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL; header('Content-Type: text/csv'); - if ($conf->global->EXPORT_PREFIX) + if ($conf->global->EXPORT_PREFIX_SPEC) $filename=$conf->global->EXPORT_PREFIX_SPEC."_"."journal_ventes.csv"; else $filename="journal_ventes.csv"; From e7ed8ce95b6d1754e1c04eaeae2b3499fe801022 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Wed, 11 Mar 2015 10:23:33 +0100 Subject: [PATCH 25/60] Update purchasesjournal.php --- htdocs/accountancy/journal/purchasesjournal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 521a1c6a74c..6d89e8f17a2 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -249,7 +249,7 @@ if ($action == 'export_csv') $purchase_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL; header('Content-Type: text/csv'); - if ($conf->global->EXPORT_PREFIX) + if ($conf->global->EXPORT_PREFIX_SPEC) $filename=$conf->global->EXPORT_PREFIX_SPEC."_"."journal_achats.csv"; else $filename="journal_achats.csv"; From fc5899174be30836c958bda923f43851ec4d919b Mon Sep 17 00:00:00 2001 From: Ion Agorria Date: Sat, 14 Mar 2015 16:48:56 +0100 Subject: [PATCH 26/60] Relocation of expression files --- .../class/price_expression.class.php} | 25 ++--- .../class/price_parser.class.php} | 93 +++++++++++-------- .../editor.php} | 29 ++++-- 3 files changed, 88 insertions(+), 59 deletions(-) rename htdocs/product/{class/priceexpression.class.php => dynamic_price/class/price_expression.class.php} (92%) rename htdocs/product/{class/priceparser.class.php => dynamic_price/class/price_parser.class.php} (78%) rename htdocs/product/{expression.php => dynamic_price/editor.php} (85%) diff --git a/htdocs/product/class/priceexpression.class.php b/htdocs/product/dynamic_price/class/price_expression.class.php similarity index 92% rename from htdocs/product/class/priceexpression.class.php rename to htdocs/product/dynamic_price/class/price_expression.class.php index c5e24d3a228..babf86235c0 100644 --- a/htdocs/product/class/priceexpression.class.php +++ b/htdocs/product/dynamic_price/class/price_expression.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2014 Juanjo Menent -/* Copyright (C) 2014 Ion Agorria +/* Copyright (C) 2015 Ion Agorria * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ */ /** - * \file htdocs/product/class/priceexpression.class.php + * \file htdocs/product/expression/class/price_expression.class.php * \ingroup product * \brief Class for accessing price expression table */ @@ -35,6 +35,7 @@ class PriceExpression var $id; var $title; var $expression; + public $table_element = "c_price_expression"; /** * Constructor @@ -57,14 +58,14 @@ class PriceExpression */ function create($user, $notrigger=0) { - $error=0; + $error=0; // Clean parameters if (isset($this->title)) $this->title=trim($this->title); if (isset($this->expression)) $this->expression=trim($this->expression); // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_price_expression ("; + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; $sql.= "title, expression"; $sql.= ") VALUES ("; $sql.= " ".(isset($this->title)?"'".$this->db->escape($this->title)."'":"''").","; @@ -121,7 +122,7 @@ class PriceExpression function fetch($id) { $sql = "SELECT title, expression"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_price_expression"; + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " WHERE rowid = ".$id; dol_syslog(get_class($this)."::fetch"); @@ -133,8 +134,8 @@ class PriceExpression { $this->id = $id; $this->title = $obj->title; - $this->expression = $obj->expression; - return 1; + $this->expression = $obj->expression; + return 1; } else { @@ -156,10 +157,10 @@ class PriceExpression function list_price_expression() { $sql = "SELECT rowid, title, expression"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_price_expression"; + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " ORDER BY title"; - dol_syslog(get_class($this)."::list_price_expression"); + dol_syslog(get_class($this)."::list_price_expression"); $resql=$this->db->query($sql); if ($resql) { @@ -194,7 +195,7 @@ class PriceExpression function find_title($title) { $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_price_expression"; + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " WHERE title = '".$this->db->escape($title)."'"; dol_syslog(get_class($this)."::find_title"); @@ -235,7 +236,7 @@ class PriceExpression if (isset($this->expression)) $this->expression=trim($this->expression); // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_price_expression SET"; + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; $sql.= " title = ".(isset($this->title)?"'".$this->db->escape($this->title)."'":"''").","; $sql.= " expression = ".(isset($this->expression)?"'".$this->db->escape($this->expression)."'":"''").""; $sql.= " WHERE rowid = ".$this->id; @@ -309,7 +310,7 @@ class PriceExpression if (! $error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_price_expression"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " WHERE rowid = ".$rowid; dol_syslog(get_class($this)."::delete"); diff --git a/htdocs/product/class/priceparser.class.php b/htdocs/product/dynamic_price/class/price_parser.class.php similarity index 78% rename from htdocs/product/class/priceparser.class.php rename to htdocs/product/dynamic_price/class/price_parser.class.php index c2b047a7ae1..68367d8ba5f 100644 --- a/htdocs/product/class/priceparser.class.php +++ b/htdocs/product/dynamic_price/class/price_parser.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2015 Ion Agorria * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,13 +16,15 @@ */ /** - * \file htdocs/product/class/priceparser.class.php + * \file htdocs/product/expression/class/price_parser.class.php * \ingroup product * \brief File of class to calculate prices using expression */ require_once DOL_DOCUMENT_ROOT.'/includes/evalmath/evalmath.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; -require_once DOL_DOCUMENT_ROOT.'/product/class/priceexpression.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_expression.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_global_variable.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_global_variable_updater.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; /** @@ -30,17 +32,17 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; */ class PriceParser { - protected $db; - // Limit of expressions per price - public $limit = 100; - // The error that ocurred when parsing price - public $error; - // The expression that caused the error - public $error_expr; - //The special char - public $special_chr = "#"; - //The separator char - public $separator_chr = ";"; + protected $db; + // Limit of expressions per price + public $limit = 100; + // The error that occurred when parsing price + public $error; + // The expression that caused the error + public $error_expr; + //The special char + public $special_chr = "#"; + //The separator char + public $separator_chr = ";"; /** * Constructor @@ -104,7 +106,7 @@ class PriceParser { return $langs->trans("ErrorPriceExpression".$code, $info); } - else if (in_array($code, array(6))) //Errors which have 2 args + else if (in_array($code, array(6, 23))) //Errors which have 2 args { return $langs->trans("ErrorPriceExpression".$code, $info[0], $info[1]); } @@ -128,6 +130,7 @@ class PriceParser */ public function parseExpression($product, $expression, $values) { + global $user; //Accessible product values by expressions $values = array_merge($values, array( "tva_tx" => $product->tva_tx, @@ -139,13 +142,31 @@ class PriceParser "price_min" => $product->price_min, )); - //Retreive all extrafield for product and add it to values + //Retrieve all extrafield for product and add it to values $extrafields = new ExtraFields($this->db); $extralabels = $extrafields->fetch_name_optionals_label('product', true); $product->fetch_optionals($product->id, $extralabels); foreach ($extrafields->attribute_label as $key=>$label) { - $values['options_'.$key] = $product->array_options['options_'.$key]; + $values["extrafield_".$key] = $product->array_options['options_'.$key]; + } + + //Process any pending updaters + $price_updaters = new PriceGlobalVariableUpdater($this->db); + foreach ($price_updaters->listPendingUpdaters() as $entry) { + //Schedule the next update by adding current timestamp (secs) + interval (mins) + $entry->update_next_update(dol_now() + ($entry->update_interval * 60), $user); + //Do processing + $res = $entry->process(); + //Store any error or clear status if OK + $entry->update_status($res < 1?$entry->error:'', $user); + } + + //Get all global values + $price_globals = new PriceGlobalVariable($this->db); + foreach ($price_globals->listGlobalVariables() as $entry) + { + $values["global_".$entry->code] = $entry->value; } //Check if empty @@ -153,36 +174,32 @@ class PriceParser if (empty($expression)) { $this->error = array(20, null); - return -1; + return -2; } //Prepare the lib, parameters and values $em = new EvalMath(); $em->suppress_errors = true; //Don't print errors on page $this->error_expr = null; - $search = array(); - $replace = array(); - foreach ($values as $key => $value) { - if ($value !== null) { - $search[] = $this->special_chr.$key.$this->special_chr; - $replace[] = $value; - } - } + $last_result = null; //Iterate over each expression splitted by $separator_chr $expression = str_replace("\n", $this->separator_chr, $expression); + foreach ($values as $key => $value) + { + $expression = str_replace($this->special_chr.$key.$this->special_chr, "$value", $expression); + } $expressions = explode($this->separator_chr, $expression); - $expressions = array_slice($expressions, 0, $limit); + $expressions = array_slice($expressions, 0, $this->limit); foreach ($expressions as $expr) { $expr = trim($expr); if (!empty($expr)) { - $expr = str_ireplace($search, $replace, $expr); $last_result = $em->evaluate($expr); $this->error = $em->last_error_code; if ($this->error !== null) { //$em->last_error is null if no error happened, so just check if error is not null $this->error_expr = $expr; - return -2; + return -3; } } } @@ -190,15 +207,15 @@ class PriceParser if (empty($vars["price"])) { $vars["price"] = $last_result; } - if ($vars["price"] === null) + if (!isset($vars["price"])) { $this->error = array(21, $expression); - return -3; + return -4; } if ($vars["price"] < 0) { $this->error = array(22, $expression); - return -4; + return -5; } return $vars["price"]; } @@ -209,13 +226,13 @@ class PriceParser * @param Product $product The Product object to get information * @param string $expression The expression to parse * @param array $extra_values Any aditional values for expression - * @return int > 0 if OK, < 1 if KO + * @return int > 0 if OK, < 1 if KO */ public function parseProductExpression($product, $expression, $extra_values = array()) { //Get the supplier min - $productFournisseur = new ProductFournisseur($this->db); - $supplier_min_price = $productFournisseur->find_min_price_product_fournisseur($product->id); + $productFournisseur = new ProductFournisseur($this->db); + $supplier_min_price = $productFournisseur->find_min_price_product_fournisseur($product->id); //Accessible values by expressions $extra_values = array_merge($extra_values, array( @@ -237,7 +254,7 @@ class PriceParser * * @param Product $product The Product object to get information * @param array $extra_values Any aditional values for expression - * @return int > 0 if OK, < 1 if KO + * @return int > 0 if OK, < 1 if KO */ public function parseProduct($product, $extra_values = array()) { @@ -261,7 +278,7 @@ class PriceParser * @param int $quantity Supplier Min quantity * @param int $tva_tx Supplier VAT rate * @param array $extra_values Any aditional values for expression - * @return int > 0 if OK, < 1 if KO + * @return int > 0 if OK, < 1 if KO */ public function parseProductSupplierExpression($product_id, $expression, $quantity = null, $tva_tx = null, $extra_values = array()) { @@ -285,7 +302,7 @@ class PriceParser * @param int $quantity Min quantity * @param int $tva_tx VAT rate * @param array $extra_values Any aditional values for expression - * @return int > 0 if OK, < 1 if KO + * @return int > 0 if OK, < 1 if KO */ public function parseProductSupplier($product_id, $expression_id, $quantity = null, $tva_tx = null, $extra_values = array()) { diff --git a/htdocs/product/expression.php b/htdocs/product/dynamic_price/editor.php similarity index 85% rename from htdocs/product/expression.php rename to htdocs/product/dynamic_price/editor.php index be3e5401789..1fc7df3b731 100644 --- a/htdocs/product/expression.php +++ b/htdocs/product/dynamic_price/editor.php @@ -16,16 +16,17 @@ */ /** - * \file htdocs/product/expression.php + * \file htdocs/product/expression/editor.php * \ingroup product * \brief Page for editing expression */ -require '../main.inc.php'; +require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; -require_once DOL_DOCUMENT_ROOT.'/product/class/priceexpression.class.php'; -require_once DOL_DOCUMENT_ROOT.'/product/class/priceparser.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_expression.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_global_variable.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; $langs->load("products"); $langs->load("accountancy"); //"Back" translation is on this file @@ -47,6 +48,7 @@ $product = new Product($db); $product->fetch($id, ''); $price_expression = new PriceExpression($db); +$price_globals = new PriceGlobalVariable($db); //Fetch expression data if (empty($eid)) //This also disables fetch when eid == 0 @@ -184,8 +186,17 @@ print '
'.$langs->trans("Name").''; print ''; print '
'.$form->textwithpicto($langs->trans("PriceExpressionEditor"),$help_text,1).''; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('expression',isset($price_expression->expression)?$price_expression->expression:'','',300,'','',false,false,false,4,80); @@ -194,7 +205,7 @@ print '
'; //Buttons -print '
'; +print '
'; print ''; print ''.$langs->trans("Back").''; if ($eid == 0) @@ -205,9 +216,9 @@ else { print ''; } -print '
'; +print ''; -print ''; +print ''; // This code reloads the page depending of selected option, goes to page selected by tab when back is pressed print ''; + print ''; + //Parameters + print ''; + $help = $langs->trans("GlobalVariableUpdaterHelp".$type).'
'.$langs->trans("GlobalVariableUpdaterHelpFormat".$type).''; + print ''.$form->textwithpicto($langs->trans("Parameters"),$help,1).''; + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $doleditor=new DolEditor('parameters',empty($price_updaters->parameters)?'':$price_updaters->parameters,'',300,'','',false,false,false,10,80); + $doleditor->Create(); + print ''; + print ''; + //Interval + print ''; + print ''.$langs->trans("UpdateInterval").''; + print ''; + print ''; + print ''; + + //Form Buttons + print '
'; + print '  '; + print ''; + print '
'; + print ''; +} else { + //Action Buttons + print '
'; + print ''.$langs->trans("Add").''; + print '
'; +} + +llxFooter(); +$db->close(); From 2d09d8196f85e56b970de315e9f5fa686782cc28 Mon Sep 17 00:00:00 2001 From: Ion Agorria Date: Sat, 14 Mar 2015 16:51:50 +0100 Subject: [PATCH 30/60] Language additions --- htdocs/langs/en_US/errors.lang | 6 ++++++ htdocs/langs/en_US/products.lang | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 3d83901194b..37670b7f003 100755 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -161,6 +161,12 @@ ErrorPriceExpressionUnknown=Unknown error '%s' ErrorSrcAndTargetWarehouseMustDiffers=Source and target warehouses must differs ErrorTryToMakeMoveOnProductRequiringBatchData=Error, trying to make a stock movement without batch/serial information, on a product requiring batch/serial information ErrorCantSetReceptionToTotalDoneWithReceptionToApprove=All recorded receptions must first be verified before being allowed to do this action +ErrorGlobalVariableUpdater0=HTTP request failed with error '%s' +ErrorGlobalVariableUpdater1=Invalid JSON format '%s' +ErrorGlobalVariableUpdater2=Missing parameter '%s' +ErrorGlobalVariableUpdater3=The requested data was not found in result +ErrorGlobalVariableUpdater4=SOAP client failed with error '%s' +ErrorGlobalVariableUpdater5=No global variable selected # Warnings WarningMandatorySetupNotComplete=Mandatory setup parameters are not yet defined diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index eb7261ab613..1b9a49b559d 100755 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -245,12 +245,25 @@ MinimumRecommendedPrice=Minimum recommended price is : %s PriceExpressionEditor=Price expression editor PriceExpressionSelected=Selected price expression PriceExpressionEditorHelp1="price = 2 + 2" or "2 + 2" for setting the price. Use ; to separate expressions -PriceExpressionEditorHelp2=You can access ExtraFields with variables like #options_myextrafieldkey# +PriceExpressionEditorHelp2=You can access ExtraFields with variables like #extrafield_myextrafieldkey# and global variables with #global_mycode# PriceExpressionEditorHelp3=In both product/service and supplier prices there are these variables available:
#tva_tx# #localtax1_tx# #localtax2_tx# #weight# #length# #surface# #price_min# PriceExpressionEditorHelp4=In product/service price only: #supplier_min_price#
In supplier prices only: #supplier_quantity# and #supplier_tva_tx# +PriceExpressionEditorHelp5=Available global values: PriceMode=Price mode PriceNumeric=Number DefaultPrice=Default price ComposedProductIncDecStock=Increase/Decrease stock on parent change ComposedProduct=Sub-product -MinSupplierPrice=Minimun supplier price +MinSupplierPrice=Minimum supplier price +DynamicPriceConfiguration=Dynamic price configuration +GlobalVariables=Global variables +GlobalVariableUpdaters=Global variable updaters +GlobalVariableUpdaterType0=JSON data +GlobalVariableUpdaterHelp0=Parses JSON data from specified URL, VALUE specifies the location of relevant value, +GlobalVariableUpdaterHelpFormat0=format is {"URL": "http://example.com/urlofjson", "VALUE": "array1,array2,targetvalue"} +GlobalVariableUpdaterType1=WebService data +GlobalVariableUpdaterHelp1=Parses WebService data from specified URL, NS specifies the namespace, VALUE specifies the location of relevant value, DATA should contain the data to send and METHOD is the calling WS method +GlobalVariableUpdaterHelpFormat1=format is {"URL": "http://example.com/urlofws", "VALUE": "array,targetvalue", "NS": "http://example.com/urlofns", "METHOD": "myWSMethod", "DATA": {"your": "data, "to": "send"}} +UpdateInterval=Update interval (minutes) +LastUpdated=Last updated +CorrectlyUpdated=Correctly updated \ No newline at end of file From e76b6e740f442e865939303134488f821f709c46 Mon Sep 17 00:00:00 2001 From: Ion Agorria Date: Sat, 14 Mar 2015 16:52:01 +0100 Subject: [PATCH 31/60] SQL additions --- .../install/mysql/migration/3.7.0-3.8.0.sql | 20 +++++++++++++ .../tables/llx_c_price_global_variable.sql | 25 ++++++++++++++++ .../llx_c_price_global_variable_updater.sql | 29 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 htdocs/install/mysql/tables/llx_c_price_global_variable.sql create mode 100644 htdocs/install/mysql/tables/llx_c_price_global_variable_updater.sql diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index b7475d88f91..12d6cce2022 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -370,3 +370,23 @@ INSERT INTO llx_c_incoterms (code, libelle, active) VALUES ('DDP', 'Delivered Du -- Extrafields fk_object must be unique (1-1 relation) ALTER TABLE llx_societe_extrafields DROP INDEX idx_societe_extrafields; ALTER TABLE llx_societe_extrafields ADD UNIQUE INDEX uk_societe_extrafields (fk_object); + +create table llx_c_price_global_variable +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + code varchar(20) NOT NULL, + description text DEFAULT NULL, + value double(24,8) DEFAULT 0 +)ENGINE=innodb; + +create table llx_c_price_global_variable_updater +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + type integer NOT NULL, + description text DEFAULT NULL, + parameters text DEFAULT NULL, + fk_variable integer NOT NULL, + update_interval integer DEFAULT 0, + next_update integer DEFAULT 0, + last_status text DEFAULT NULL +)ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_c_price_global_variable.sql b/htdocs/install/mysql/tables/llx_c_price_global_variable.sql new file mode 100644 index 00000000000..0f5630ed193 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_c_price_global_variable.sql @@ -0,0 +1,25 @@ +-- ============================================================================ +-- Copyright (C) 2015 Ion agorria +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- ============================================================================ + +create table llx_c_price_global_variable +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + code varchar(20) NOT NULL, + description text DEFAULT NULL, + value double(24,8) DEFAULT 0 +)ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_c_price_global_variable_updater.sql b/htdocs/install/mysql/tables/llx_c_price_global_variable_updater.sql new file mode 100644 index 00000000000..0c1dcfba701 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_c_price_global_variable_updater.sql @@ -0,0 +1,29 @@ +-- ============================================================================ +-- Copyright (C) 2015 Ion agorria +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- ============================================================================ + +create table llx_c_price_global_variable_updater +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + type integer NOT NULL, + description text DEFAULT NULL, + parameters text DEFAULT NULL, + fk_variable integer NOT NULL, + update_interval integer DEFAULT 0, + next_update integer DEFAULT 0, + last_status text DEFAULT NULL +)ENGINE=innodb; From bcdf3407c7c1d7bbb50090bc2bf3f2215c3d7ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Sun, 15 Mar 2015 18:01:21 +0100 Subject: [PATCH 32/60] Fixed line endings --- htdocs/includes/tcpdi/fpdf_tpl.php | 920 ++++++++++++++--------------- 1 file changed, 460 insertions(+), 460 deletions(-) diff --git a/htdocs/includes/tcpdi/fpdf_tpl.php b/htdocs/includes/tcpdi/fpdf_tpl.php index 86e38b71641..8482ba336ed 100644 --- a/htdocs/includes/tcpdi/fpdf_tpl.php +++ b/htdocs/includes/tcpdi/fpdf_tpl.php @@ -1,460 +1,460 @@ -Error('This method is only usable with FPDF. Use TCPDF methods startTemplate() instead.'); - return; - } - - if ($this->page <= 0) - $this->error("You have to add a page to fpdf first!"); - - if ($x == null) - $x = 0; - if ($y == null) - $y = 0; - if ($w == null) - $w = $this->w; - if ($h == null) - $h = $this->h; - - // Save settings - $this->tpl++; - $tpl =& $this->tpls[$this->tpl]; - $tpl = array( - 'o_x' => $this->x, - 'o_y' => $this->y, - 'o_AutoPageBreak' => $this->AutoPageBreak, - 'o_bMargin' => $this->bMargin, - 'o_tMargin' => $this->tMargin, - 'o_lMargin' => $this->lMargin, - 'o_rMargin' => $this->rMargin, - 'o_h' => $this->h, - 'o_w' => $this->w, - 'o_FontFamily' => $this->FontFamily, - 'o_FontStyle' => $this->FontStyle, - 'o_FontSizePt' => $this->FontSizePt, - 'o_FontSize' => $this->FontSize, - 'buffer' => '', - 'x' => $x, - 'y' => $y, - 'w' => $w, - 'h' => $h - ); - - $this->SetAutoPageBreak(false); - - // Define own high and width to calculate possitions correct - $this->h = $h; - $this->w = $w; - - $this->_intpl = true; - $this->SetXY($x + $this->lMargin, $y + $this->tMargin); - $this->SetRightMargin($this->w - $w + $this->rMargin); - - if ($this->CurrentFont) { - $fontkey = $this->FontFamily . $this->FontStyle; - $this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey]; - - $this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); - } - - return $this->tpl; - } - - /** - * End Template - * - * This method ends a template and reset initiated variables on beginTemplate. - * - * @return mixed If a template is opened, the ID is returned. If not a false is returned. - */ - function endTemplate() { - if (is_subclass_of($this, 'TCPDF')) { - $args = func_get_args(); - return call_user_func_array(array($this, 'TCPDF::endTemplate'), $args); - } - - if ($this->_intpl) { - $this->_intpl = false; - $tpl =& $this->tpls[$this->tpl]; - $this->SetXY($tpl['o_x'], $tpl['o_y']); - $this->tMargin = $tpl['o_tMargin']; - $this->lMargin = $tpl['o_lMargin']; - $this->rMargin = $tpl['o_rMargin']; - $this->h = $tpl['o_h']; - $this->w = $tpl['o_w']; - $this->SetAutoPageBreak($tpl['o_AutoPageBreak'], $tpl['o_bMargin']); - - $this->FontFamily = $tpl['o_FontFamily']; - $this->FontStyle = $tpl['o_FontStyle']; - $this->FontSizePt = $tpl['o_FontSizePt']; - $this->FontSize = $tpl['o_FontSize']; - - $fontkey = $this->FontFamily . $this->FontStyle; - if ($fontkey) - $this->CurrentFont =& $this->fonts[$fontkey]; - - return $this->tpl; - } else { - return false; - } - } - - /** - * Use a Template in current Page or other Template - * - * You can use a template in a page or in another template. - * You can give the used template a new size like you use the Image()-method. - * All parameters are optional. The width or height is calculated automaticaly - * if one is given. If no parameter is given the origin size as defined in - * beginTemplate() is used. - * The calculated or used width and height are returned as an array. - * - * @param int $tplidx A valid template-Id - * @param int $_x The x-position - * @param int $_y The y-position - * @param int $_w The new width of the template - * @param int $_h The new height of the template - * @retrun array The height and width of the template - */ - function useTemplate($tplidx, $_x = null, $_y = null, $_w = 0, $_h = 0) { - if ($this->page <= 0) - $this->error('You have to add a page first!'); - - if (!isset($this->tpls[$tplidx])) - $this->error('Template does not exist!'); - - if ($this->_intpl) { - $this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx]; - } - - $tpl =& $this->tpls[$tplidx]; - $w = $tpl['w']; - $h = $tpl['h']; - - if ($_x == null) - $_x = 0; - if ($_y == null) - $_y = 0; - - $_x += $tpl['x']; - $_y += $tpl['y']; - - $wh = $this->getTemplateSize($tplidx, $_w, $_h); - $_w = $wh['w']; - $_h = $wh['h']; - - $tData = array( - 'x' => $this->x, - 'y' => $this->y, - 'w' => $_w, - 'h' => $_h, - 'scaleX' => ($_w / $w), - 'scaleY' => ($_h / $h), - 'tx' => $_x, - 'ty' => ($this->h - $_y - $_h), - 'lty' => ($this->h - $_y - $_h) - ($this->h - $h) * ($_h / $h) - ); - - $this->_out(sprintf('q %.4F 0 0 %.4F %.4F %.4F cm', $tData['scaleX'], $tData['scaleY'], $tData['tx'] * $this->k, $tData['ty'] * $this->k)); // Translate - $this->_out(sprintf('%s%d Do Q', $this->tplprefix, $tplidx)); - - $this->lastUsedTemplateData = $tData; - - return array('w' => $_w, 'h' => $_h); - } - - /** - * Get The calculated Size of a Template - * - * If one size is given, this method calculates the other one. - * - * @param int $tplidx A valid template-Id - * @param int $_w The width of the template - * @param int $_h The height of the template - * @return array The height and width of the template - */ - function getTemplateSize($tplidx, $_w = 0, $_h = 0) { - if (!isset($this->tpls[$tplidx])) - return false; - - $tpl =& $this->tpls[$tplidx]; - $w = $tpl['w']; - $h = $tpl['h']; - - if ($_w == 0 and $_h == 0) { - $_w = $w; - $_h = $h; - } - - if($_w == 0) - $_w = $_h * $w / $h; - if($_h == 0) - $_h = $_w * $h / $w; - - return array("w" => $_w, "h" => $_h); - } - - /** - * See FPDF/TCPDF-Documentation ;-) - */ - public function SetFont($family, $style = '', $size = 0) { - if (is_subclass_of($this, 'TCPDF')) { - $args = func_get_args(); - return call_user_func_array(array($this, 'TCPDF::SetFont'), $args); - } - - parent::SetFont($family, $style, $size); - - $fontkey = $this->FontFamily . $this->FontStyle; - - if ($this->_intpl) { - $this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey]; - } else { - $this->_res['page'][$this->page]['fonts'][$fontkey] =& $this->fonts[$fontkey]; - } - } - - /** - * See FPDF/TCPDF-Documentation ;-) - */ - function Image( - $file, $x = '', $y = '', $w = 0, $h = 0, $type = '', $link = '', $align = '', $resize = false, - $dpi = 300, $palign = '', $ismask = false, $imgmask = false, $border = 0, $fitbox = false, - $hidden = false, $fitonpage = false, $alt = false, $altimgs = array() - ) { - if (is_subclass_of($this, 'TCPDF')) { - $args = func_get_args(); - return call_user_func_array(array($this, 'TCPDF::Image'), $args); - } - - $ret = parent::Image($file, $x, $y, $w, $h, $type, $link); - if ($this->_intpl) { - $this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file]; - } else { - $this->_res['page'][$this->page]['images'][$file] =& $this->images[$file]; - } - - return $ret; - } - - /** - * See FPDF-Documentation ;-) - * - * AddPage is not available when you're "in" a template. - */ - function AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false) { - if (is_subclass_of($this, 'TCPDF')) { - $args = func_get_args(); - return call_user_func_array(array($this, 'TCPDF::AddPage'), $args); - } - - if ($this->_intpl) - $this->Error('Adding pages in templates isn\'t possible!'); - - parent::AddPage($orientation, $format); - } - - /** - * Preserve adding Links in Templates ...won't work - */ - function Link($x, $y, $w, $h, $link, $spaces = 0) { - if (is_subclass_of($this, 'TCPDF')) { - $args = func_get_args(); - return call_user_func_array(array($this, 'TCPDF::Link'), $args); - } - - if ($this->_intpl) - $this->Error('Using links in templates aren\'t possible!'); - - parent::Link($x, $y, $w, $h, $link); - } - - function AddLink() { - if (is_subclass_of($this, 'TCPDF')) { - $args = func_get_args(); - return call_user_func_array(array($this, 'TCPDF::AddLink'), $args); - } - - if ($this->_intpl) - $this->Error('Adding links in templates aren\'t possible!'); - return parent::AddLink(); - } - - function SetLink($link, $y = 0, $page = -1) { - if (is_subclass_of($this, 'TCPDF')) { - $args = func_get_args(); - return call_user_func_array(array($this, 'TCPDF::SetLink'), $args); - } - - if ($this->_intpl) - $this->Error('Setting links in templates aren\'t possible!'); - parent::SetLink($link, $y, $page); - } - - /** - * Private Method that writes the form xobjects - */ - function _putformxobjects() { - $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; - reset($this->tpls); - foreach($this->tpls AS $tplidx => $tpl) { - - $p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer']; - $this->_newobj(); - $this->tpls[$tplidx]['n'] = $this->n; - $this->_out('<<'.$filter.'/Type /XObject'); - $this->_out('/Subtype /Form'); - $this->_out('/FormType 1'); - $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]', - // llx - $tpl['x'] * $this->k, - // lly - -$tpl['y'] * $this->k, - // urx - ($tpl['w'] + $tpl['x']) * $this->k, - // ury - ($tpl['h'] - $tpl['y']) * $this->k - )); - - if ($tpl['x'] != 0 || $tpl['y'] != 0) { - $this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]', - -$tpl['x'] * $this->k * 2, $tpl['y'] * $this->k * 2 - )); - } - - $this->_out('/Resources '); - - $this->_out('<_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) { - $this->_out('/Font <<'); - foreach($this->_res['tpl'][$tplidx]['fonts'] as $font) - $this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R'); - $this->_out('>>'); - } - if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) || - isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) - { - $this->_out('/XObject <<'); - if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) { - foreach($this->_res['tpl'][$tplidx]['images'] as $image) - $this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R'); - } - if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) { - foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl) - $this->_out($this->tplprefix . $i . ' ' . $tpl['n'] . ' 0 R'); - } - $this->_out('>>'); - } - $this->_out('>>'); - - $this->_out('/Length ' . strlen($p) . ' >>'); - $this->_putstream($p); - $this->_out('endobj'); - } - } - - /** - * Overwritten to add _putformxobjects() after _putimages() - * - */ - function _putimages() { - parent::_putimages(); - $this->_putformxobjects(); - } - - function _putxobjectdict() { - parent::_putxobjectdict(); - - if (count($this->tpls)) { - foreach($this->tpls as $tplidx => $tpl) { - $this->_out(sprintf('%s%d %d 0 R', $this->tplprefix, $tplidx, $tpl['n'])); - } - } - } - - /** - * Private Method - */ - function _out($s) { - if ($this->state == 2 && $this->_intpl) { - $this->tpls[$this->tpl]['buffer'] .= $s . "\n"; - } else { - parent::_out($s); - } - } -} +Error('This method is only usable with FPDF. Use TCPDF methods startTemplate() instead.'); + return; + } + + if ($this->page <= 0) + $this->error("You have to add a page to fpdf first!"); + + if ($x == null) + $x = 0; + if ($y == null) + $y = 0; + if ($w == null) + $w = $this->w; + if ($h == null) + $h = $this->h; + + // Save settings + $this->tpl++; + $tpl =& $this->tpls[$this->tpl]; + $tpl = array( + 'o_x' => $this->x, + 'o_y' => $this->y, + 'o_AutoPageBreak' => $this->AutoPageBreak, + 'o_bMargin' => $this->bMargin, + 'o_tMargin' => $this->tMargin, + 'o_lMargin' => $this->lMargin, + 'o_rMargin' => $this->rMargin, + 'o_h' => $this->h, + 'o_w' => $this->w, + 'o_FontFamily' => $this->FontFamily, + 'o_FontStyle' => $this->FontStyle, + 'o_FontSizePt' => $this->FontSizePt, + 'o_FontSize' => $this->FontSize, + 'buffer' => '', + 'x' => $x, + 'y' => $y, + 'w' => $w, + 'h' => $h + ); + + $this->SetAutoPageBreak(false); + + // Define own high and width to calculate possitions correct + $this->h = $h; + $this->w = $w; + + $this->_intpl = true; + $this->SetXY($x + $this->lMargin, $y + $this->tMargin); + $this->SetRightMargin($this->w - $w + $this->rMargin); + + if ($this->CurrentFont) { + $fontkey = $this->FontFamily . $this->FontStyle; + $this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey]; + + $this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); + } + + return $this->tpl; + } + + /** + * End Template + * + * This method ends a template and reset initiated variables on beginTemplate. + * + * @return mixed If a template is opened, the ID is returned. If not a false is returned. + */ + function endTemplate() { + if (is_subclass_of($this, 'TCPDF')) { + $args = func_get_args(); + return call_user_func_array(array($this, 'TCPDF::endTemplate'), $args); + } + + if ($this->_intpl) { + $this->_intpl = false; + $tpl =& $this->tpls[$this->tpl]; + $this->SetXY($tpl['o_x'], $tpl['o_y']); + $this->tMargin = $tpl['o_tMargin']; + $this->lMargin = $tpl['o_lMargin']; + $this->rMargin = $tpl['o_rMargin']; + $this->h = $tpl['o_h']; + $this->w = $tpl['o_w']; + $this->SetAutoPageBreak($tpl['o_AutoPageBreak'], $tpl['o_bMargin']); + + $this->FontFamily = $tpl['o_FontFamily']; + $this->FontStyle = $tpl['o_FontStyle']; + $this->FontSizePt = $tpl['o_FontSizePt']; + $this->FontSize = $tpl['o_FontSize']; + + $fontkey = $this->FontFamily . $this->FontStyle; + if ($fontkey) + $this->CurrentFont =& $this->fonts[$fontkey]; + + return $this->tpl; + } else { + return false; + } + } + + /** + * Use a Template in current Page or other Template + * + * You can use a template in a page or in another template. + * You can give the used template a new size like you use the Image()-method. + * All parameters are optional. The width or height is calculated automaticaly + * if one is given. If no parameter is given the origin size as defined in + * beginTemplate() is used. + * The calculated or used width and height are returned as an array. + * + * @param int $tplidx A valid template-Id + * @param int $_x The x-position + * @param int $_y The y-position + * @param int $_w The new width of the template + * @param int $_h The new height of the template + * @retrun array The height and width of the template + */ + function useTemplate($tplidx, $_x = null, $_y = null, $_w = 0, $_h = 0) { + if ($this->page <= 0) + $this->error('You have to add a page first!'); + + if (!isset($this->tpls[$tplidx])) + $this->error('Template does not exist!'); + + if ($this->_intpl) { + $this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx]; + } + + $tpl =& $this->tpls[$tplidx]; + $w = $tpl['w']; + $h = $tpl['h']; + + if ($_x == null) + $_x = 0; + if ($_y == null) + $_y = 0; + + $_x += $tpl['x']; + $_y += $tpl['y']; + + $wh = $this->getTemplateSize($tplidx, $_w, $_h); + $_w = $wh['w']; + $_h = $wh['h']; + + $tData = array( + 'x' => $this->x, + 'y' => $this->y, + 'w' => $_w, + 'h' => $_h, + 'scaleX' => ($_w / $w), + 'scaleY' => ($_h / $h), + 'tx' => $_x, + 'ty' => ($this->h - $_y - $_h), + 'lty' => ($this->h - $_y - $_h) - ($this->h - $h) * ($_h / $h) + ); + + $this->_out(sprintf('q %.4F 0 0 %.4F %.4F %.4F cm', $tData['scaleX'], $tData['scaleY'], $tData['tx'] * $this->k, $tData['ty'] * $this->k)); // Translate + $this->_out(sprintf('%s%d Do Q', $this->tplprefix, $tplidx)); + + $this->lastUsedTemplateData = $tData; + + return array('w' => $_w, 'h' => $_h); + } + + /** + * Get The calculated Size of a Template + * + * If one size is given, this method calculates the other one. + * + * @param int $tplidx A valid template-Id + * @param int $_w The width of the template + * @param int $_h The height of the template + * @return array The height and width of the template + */ + function getTemplateSize($tplidx, $_w = 0, $_h = 0) { + if (!isset($this->tpls[$tplidx])) + return false; + + $tpl =& $this->tpls[$tplidx]; + $w = $tpl['w']; + $h = $tpl['h']; + + if ($_w == 0 and $_h == 0) { + $_w = $w; + $_h = $h; + } + + if($_w == 0) + $_w = $_h * $w / $h; + if($_h == 0) + $_h = $_w * $h / $w; + + return array("w" => $_w, "h" => $_h); + } + + /** + * See FPDF/TCPDF-Documentation ;-) + */ + public function SetFont($family, $style = '', $size = 0) { + if (is_subclass_of($this, 'TCPDF')) { + $args = func_get_args(); + return call_user_func_array(array($this, 'TCPDF::SetFont'), $args); + } + + parent::SetFont($family, $style, $size); + + $fontkey = $this->FontFamily . $this->FontStyle; + + if ($this->_intpl) { + $this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey]; + } else { + $this->_res['page'][$this->page]['fonts'][$fontkey] =& $this->fonts[$fontkey]; + } + } + + /** + * See FPDF/TCPDF-Documentation ;-) + */ + function Image( + $file, $x = '', $y = '', $w = 0, $h = 0, $type = '', $link = '', $align = '', $resize = false, + $dpi = 300, $palign = '', $ismask = false, $imgmask = false, $border = 0, $fitbox = false, + $hidden = false, $fitonpage = false, $alt = false, $altimgs = array() + ) { + if (is_subclass_of($this, 'TCPDF')) { + $args = func_get_args(); + return call_user_func_array(array($this, 'TCPDF::Image'), $args); + } + + $ret = parent::Image($file, $x, $y, $w, $h, $type, $link); + if ($this->_intpl) { + $this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file]; + } else { + $this->_res['page'][$this->page]['images'][$file] =& $this->images[$file]; + } + + return $ret; + } + + /** + * See FPDF-Documentation ;-) + * + * AddPage is not available when you're "in" a template. + */ + function AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false) { + if (is_subclass_of($this, 'TCPDF')) { + $args = func_get_args(); + return call_user_func_array(array($this, 'TCPDF::AddPage'), $args); + } + + if ($this->_intpl) + $this->Error('Adding pages in templates isn\'t possible!'); + + parent::AddPage($orientation, $format); + } + + /** + * Preserve adding Links in Templates ...won't work + */ + function Link($x, $y, $w, $h, $link, $spaces = 0) { + if (is_subclass_of($this, 'TCPDF')) { + $args = func_get_args(); + return call_user_func_array(array($this, 'TCPDF::Link'), $args); + } + + if ($this->_intpl) + $this->Error('Using links in templates aren\'t possible!'); + + parent::Link($x, $y, $w, $h, $link); + } + + function AddLink() { + if (is_subclass_of($this, 'TCPDF')) { + $args = func_get_args(); + return call_user_func_array(array($this, 'TCPDF::AddLink'), $args); + } + + if ($this->_intpl) + $this->Error('Adding links in templates aren\'t possible!'); + return parent::AddLink(); + } + + function SetLink($link, $y = 0, $page = -1) { + if (is_subclass_of($this, 'TCPDF')) { + $args = func_get_args(); + return call_user_func_array(array($this, 'TCPDF::SetLink'), $args); + } + + if ($this->_intpl) + $this->Error('Setting links in templates aren\'t possible!'); + parent::SetLink($link, $y, $page); + } + + /** + * Private Method that writes the form xobjects + */ + function _putformxobjects() { + $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; + reset($this->tpls); + foreach($this->tpls AS $tplidx => $tpl) { + + $p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer']; + $this->_newobj(); + $this->tpls[$tplidx]['n'] = $this->n; + $this->_out('<<'.$filter.'/Type /XObject'); + $this->_out('/Subtype /Form'); + $this->_out('/FormType 1'); + $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]', + // llx + $tpl['x'] * $this->k, + // lly + -$tpl['y'] * $this->k, + // urx + ($tpl['w'] + $tpl['x']) * $this->k, + // ury + ($tpl['h'] - $tpl['y']) * $this->k + )); + + if ($tpl['x'] != 0 || $tpl['y'] != 0) { + $this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]', + -$tpl['x'] * $this->k * 2, $tpl['y'] * $this->k * 2 + )); + } + + $this->_out('/Resources '); + + $this->_out('<_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) { + $this->_out('/Font <<'); + foreach($this->_res['tpl'][$tplidx]['fonts'] as $font) + $this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R'); + $this->_out('>>'); + } + if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) || + isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) + { + $this->_out('/XObject <<'); + if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) { + foreach($this->_res['tpl'][$tplidx]['images'] as $image) + $this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R'); + } + if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) { + foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl) + $this->_out($this->tplprefix . $i . ' ' . $tpl['n'] . ' 0 R'); + } + $this->_out('>>'); + } + $this->_out('>>'); + + $this->_out('/Length ' . strlen($p) . ' >>'); + $this->_putstream($p); + $this->_out('endobj'); + } + } + + /** + * Overwritten to add _putformxobjects() after _putimages() + * + */ + function _putimages() { + parent::_putimages(); + $this->_putformxobjects(); + } + + function _putxobjectdict() { + parent::_putxobjectdict(); + + if (count($this->tpls)) { + foreach($this->tpls as $tplidx => $tpl) { + $this->_out(sprintf('%s%d %d 0 R', $this->tplprefix, $tplidx, $tpl['n'])); + } + } + } + + /** + * Private Method + */ + function _out($s) { + if ($this->state == 2 && $this->_intpl) { + $this->tpls[$this->tpl]['buffer'] .= $s . "\n"; + } else { + parent::_out($s); + } + } +} From 6ba3b900b7aed1b8298c4f287b73c694d2a876f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Sun, 15 Mar 2015 23:42:11 +0100 Subject: [PATCH 33/60] PHPCS Fix --- htdocs/core/class/commonobject.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 0a682415b94..e781405344b 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2662,7 +2662,6 @@ abstract class CommonObject * @param string $buyer Object of buyer third party * @param string $selected Object line selected * @param int $dateSelector 1=Show also date range input fields - * @param int $permtoedit Permission to edit line * @return void */ function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) From 9e9a8894ea17c198fee8e3e2d68dd8d81d4de6d8 Mon Sep 17 00:00:00 2001 From: jean Date: Tue, 17 Mar 2015 14:20:08 +0100 Subject: [PATCH 34/60] Add global $langs to method, necessary for triggers to function correctly --- htdocs/fourn/class/fournisseur.product.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 3d12352903f..4db72d48814 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -154,7 +154,7 @@ class ProductFournisseur extends Product */ function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges=0, $remise_percent=0, $remise=0, $newnpr=0) { - global $conf; + global $conf, $langs; // Clean parameter if (empty($qty)) $qty=0; From d5afa1b29f040349eb1b27382ee0e8fa5be4d4d3 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Wed, 18 Mar 2015 13:23:14 +0100 Subject: [PATCH 35/60] Update extrafields.class.php Link object : include only if something to display --- htdocs/core/class/extrafields.class.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 361c14319eb..a1ac0d5b6e3 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1054,6 +1054,7 @@ class ExtraFields elseif ($type == 'link') { $out=''; + $param_list=array_keys($param['options']); // 0 : ObjectName // 1 : classPath @@ -1292,14 +1293,15 @@ class ExtraFields elseif ($type == 'link') { $out=''; - $param_list=array_keys($params['options']); - // 0 : ObjectName - // 1 : classPath - $InfoFieldList = explode(":", $param_list[0]); - dol_include_once($InfoFieldList[1]); - $object = new $InfoFieldList[0]($this->db); + // only if something to display (perf) if ($value) { + $param_list=array_keys($params['options']); + // 0 : ObjectName + // 1 : classPath + $InfoFieldList = explode(":", $param_list[0]); + dol_include_once($InfoFieldList[1]); + $object = new $InfoFieldList[0]($this->db); $object->fetch($value); $value=$object->getNomUrl(3); } From 058042d09df972d3e215236f401c6c9aaa66af58 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 18 Mar 2015 17:52:17 +0100 Subject: [PATCH 36/60] NEW : update skeleton and class builder --- dev/skeletons/build_class_from_table.php | 41 ++++++++++++-- dev/skeletons/skeleton_class.class.php | 72 ++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 4 deletions(-) diff --git a/dev/skeletons/build_class_from_table.php b/dev/skeletons/build_class_from_table.php index 0b2e96daaac..ca10cf49ef0 100755 --- a/dev/skeletons/build_class_from_table.php +++ b/dev/skeletons/build_class_from_table.php @@ -174,7 +174,7 @@ $targetcontent=$sourcecontent; // Substitute class name $targetcontent=preg_replace('/skeleton_class\.class\.php/', $classmin.'.class.php', $targetcontent); $targetcontent=preg_replace('/\$element=\'skeleton\'/', '\$element=\''.$classmin.'\'', $targetcontent); -$targetcontent=preg_replace('/\$table_element=\'skeleton\'/', '\$table_element=\''.$classmin.'\'', $targetcontent); +$targetcontent=preg_replace('/\$table_element=\'skeleton\'/', '\$table_element=\''.$tablenoprefix.'\'', $targetcontent); $targetcontent=preg_replace('/Skeleton_Class/', $classname, $targetcontent); // Substitute comments @@ -252,7 +252,13 @@ foreach($property as $key => $prop) if ($addfield) { $varprop.="\t\t\$sql.= \" "; - if ($prop['istime']) + if ($prop['field']=='datec') + { + $varprop.='"."\'".$this->db->idate(dol_now())."\'"."'; + if ($i < count($property)) $varprop.=","; + $varprop.='";'; + } + elseif ($prop['istime']) { $varprop.='".(! isset($this->'.$prop['field'].') || dol_strlen($this->'.$prop['field'].')==0?\'NULL\':"\'".$this->db->idate('; $varprop.="\$this->".$prop['field'].""; @@ -268,6 +274,12 @@ foreach($property as $key => $prop) if ($i < count($property)) $varprop.=","; $varprop.='";'; } + elseif ($prop['field']=='fk_user_mod' || $prop['field']=='fk_user_author') + { + $varprop.='".$user->id."'; + if ($i < count($property)) $varprop.=","; + $varprop.='";'; + } else { $varprop.='".(! isset($this->'.$prop['field'].')?\'NULL\':"\'".'; @@ -289,11 +301,17 @@ $i=0; foreach($property as $key => $prop) { $i++; - if ($prop['field'] != 'rowid' && $prop['field'] != 'id') + if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && $prop['field'] != 'datec' && $prop['field'] != 'fk_user_author') { $varprop.="\t\t\$sql.= \" "; $varprop.=$prop['field'].'='; - if ($prop['istime']) + if ($prop['field']=='tms') { + $varprop.='".(dol_strlen($this->'.$prop['field'].')!=0 ? "\'".$this->db->idate('; + $varprop.='$this->'.$prop['field']; + $varprop.=')."\'" : "\'".$this->db->idate(dol_now())."\'").'; + $varprop.='"'; + } + elseif ($prop['istime']) { // (dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null') $varprop.='".(dol_strlen($this->'.$prop['field'].')!=0 ? "\'".$this->db->idate('; @@ -301,6 +319,9 @@ foreach($property as $key => $prop) $varprop.=')."\'" : \'null\').'; $varprop.='"'; } + elseif ($prop['field']=='fk_user_mod') { + $varprop.='".$user->id."'; + } else { $varprop.="\"."; @@ -325,6 +346,7 @@ $targetcontent=preg_replace('/\$sql\.= " t\.field2";/', '', $targetcontent); // Substitute select set parameters $varprop="\n"; +$varpropline="\n"; $cleanparam=''; $i=0; foreach($property as $key => $prop) @@ -338,11 +360,22 @@ foreach($property as $key => $prop) if ($prop['istime']) $varprop.=')'; $varprop.=";"; $varprop.="\n"; + + $varpropline.="\t\t\t\t\$line->".$prop['field']." = "; + if ($prop['istime']) $varpropline.='$this->db->jdate('; + $varpropline.='$obj->'.$prop['field']; + if ($prop['istime']) $varpropline.=')'; + $varpropline.=";"; + $varpropline.="\n"; } } $targetcontent=preg_replace('/\$this->prop1 = \$obj->field1;/', $varprop, $targetcontent); $targetcontent=preg_replace('/\$this->prop2 = \$obj->field2;/', '', $targetcontent); +//Substirute fetchAll +$targetcontent=preg_replace('/\$line->prop1 = \$obj->field1;/', $varpropline, $targetcontent); +$targetcontent=preg_replace('/\$line->prop2 = \$obj->field2;/', '', $targetcontent); + // Substitute initasspecimen parameters $varprop="\n"; diff --git a/dev/skeletons/skeleton_class.class.php b/dev/skeletons/skeleton_class.class.php index c1710165066..c9e20317695 100644 --- a/dev/skeletons/skeleton_class.class.php +++ b/dev/skeletons/skeleton_class.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2015 Florian Henry * Copyright (C) ---Put here your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify @@ -41,6 +42,8 @@ class Skeleton_Class extends CommonObject var $element='skeleton'; //!< Id that identify managed objects var $table_element='skeleton'; //!< Name of table without prefix where object is stored + var $lines=array(); + var $id; var $prop1; var $prop2; @@ -175,6 +178,69 @@ class Skeleton_Class extends CommonObject } } + /** + * Load object in memory from the database + * + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit offset limit + * @param int $offset offset limit + * @param array $filter filter array + * @return int <0 if KO, >0 if OK + */ + function fetchAll($sortorder, $sortfield, $limit, $offset, $filter = array()) + { + global $langs; + $sql = "SELECT"; + $sql.= " t.rowid,"; + $sql.= " t.field1,"; + $sql.= " t.field2"; + //... + $sql.= " FROM ".MAIN_DB_PREFIX."mytable as t"; + + // Manage filter + $sqlwhere=array(); + if (count($filter)>0) { + foreach ( $filter as $key => $value ) { + //$sqlwhere []= ' AND '. $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + } + } + if (count($sqlwhere)>0) { + $sql.= ' WHERE '.implode(' AND ', $sqlwhere); + } + $sql .= " ORDER BY " . $sortfield . " " . $sortorder . " " . $this->db->plimit($limit + 1, $offset); + + $this->lines = array (); + + dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + + while ($obj = $this->db->fetch_object($resql)) + { + $line=new Skeleton_ClassLine(); + + $line->id = $obj->rowid; + $line->prop1 = $obj->field1; + $line->prop2 = $obj->field2; + + $this->line[]=$line; + //... + } + $this->db->free($resql); + + return $num; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::fetchAll ".$this->error, LOG_ERR); + return -1; + } + } + /** * Update object into database @@ -368,3 +434,9 @@ class Skeleton_Class extends CommonObject } } + +class Skeleton_ClassLine { + var $id; + var $prop1; + var $prop2; +} From a2676e57684fdea66934291b698199a91204072b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 18 Mar 2015 21:06:55 +0100 Subject: [PATCH 37/60] Fix: the type of notification sent was not filled --- htdocs/core/class/notify.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index db88671f7ff..ac63b3e48c5 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -423,7 +423,7 @@ class Notify if ($mailfile->sendfile()) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)"; - $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$actiondefid.", ".$object->socid.", null, '".$obj->type."', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')"; + $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$actiondefid.", ".$object->socid.", null, 'email', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')"; if (! $this->db->query($sql)) { dol_print_error($this->db); From d442ac328c0a2d4b8ac2bb6d14fb64da1e6b96d2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Mar 2015 12:34:03 +0100 Subject: [PATCH 38/60] Fix: some replacement tags were missing --- htdocs/fourn/commande/card.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index eefd5c961e2..d42c649f044 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -1966,8 +1966,13 @@ elseif (! empty($object->id)) $formmail->withbody=1; $formmail->withdeliveryreceipt=1; $formmail->withcancel=1; + + $object->fetch_projet(); // Tableau des substitutions $formmail->substit['__ORDERREF__']=$object->ref; + $formmail->substit['__ORDERSUPPLIERREF__']=$object->ref_supplier; + $formmail->substit['__THIRPARTY_NAME__'] = $object->thirdparty->name; + $formmail->substit['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:''); $formmail->substit['__SIGNATURE__']=$user->signature; $formmail->substit['__PERSONALIZED__']=''; $formmail->substit['__CONTACTCIVNAME__']=''; From 70f6c3fdbb13134a3f2ead471a8b829e789d60fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 20 Mar 2015 12:59:37 +0100 Subject: [PATCH 39/60] NEW: List of recent modified supplier product prices in Supplier card --- htdocs/fourn/card.php | 46 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index b9957c12134..c88dae2e8f3 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -5,6 +5,7 @@ * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2014 Jean Heimburger + * Copyright (C) 2015 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -313,9 +314,50 @@ if ($object->id > 0) $langs->load("products"); print ''; print ''; - print '
'.$langs->trans("ProductsAndServices").''; + print ''.$langs->trans("ProductsAndServices").''; print ''.$langs->trans("All").' '.$object->nbOfProductRefs().''; - print '
'; + print ''; + + //Query from product/liste.php + $sql = 'SELECT p.rowid, p.ref, p.label, pfp.tms,'; + $sql.= ' p.fk_product_type'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp'; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = pfp.fk_product"; + $sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')'; + $sql.= ' AND pfp.fk_soc = '.$object->id; + $sql .= $db->order('pfp.tms', 'desc'); + $sql.= $db->plimit($MAXLIST); + + $query = $db->query($sql); + + $return = array(); + + if ($db->num_rows($query)) { + + $productstatic = new Product($db); + + while ($objp = $db->fetch_object($query)) { + + $var=!$var; + + $productstatic->id = $objp->rowid; + $productstatic->ref = $objp->ref; + $productstatic->label = $objp->label; + $productstatic->type = $objp->fk_product_type; + + print ""; + print ''; + print $productstatic->getNomUrl(1); + print ''; + print ''; + print dol_trunc(dol_htmlentities($objp->label), 30); + print ''; + print ''.dol_print_date($objp->tms).''; + print ''; + } + } + + print ''; } From b0e928c213ed9cd3715d5fa6d56c0d46b270b1e7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Mar 2015 15:26:00 +0100 Subject: [PATCH 40/60] Disable migration with bugged versions --- htdocs/install/upgrade.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php index 22c18c15fee..1e1ba08b6f9 100644 --- a/htdocs/install/upgrade.php +++ b/htdocs/install/upgrade.php @@ -193,9 +193,9 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) // Test database version is not forbidden for migration $dbversion_disallowed=array( array('type'=>'mysql','version'=>array(5,5,40)), - array('type'=>'mysqli','version'=>array(5,5,40)) - //,array('type'=>'mysql','version'=>array(5,5,41)), - //array('type'=>'mysqli','version'=>array(5,5,41)) + array('type'=>'mysqli','version'=>array(5,5,40)), + array('type'=>'mysql','version'=>array(5,5,41)), + array('type'=>'mysqli','version'=>array(5,5,41)) ); $listofforbiddenversion=''; foreach ($dbversion_disallowed as $dbversion_totest) From 0784e9638a7ab88df303b28d1c3d1b3941f5fff1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Mar 2015 17:57:40 +0100 Subject: [PATCH 41/60] The test on db version must not lock the phpunit --- .travis.yml | 12 +++---- htdocs/install/upgrade.php | 64 +++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/.travis.yml b/.travis.yml index c97b547e499..6c5833ccfdb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -91,13 +91,13 @@ before_script: script: - cd htdocs/install - date -# - php upgrade.php 3.4.0 3.5.0 > upgrade.log -# - php upgrade2.php 3.4.0 3.5.0 > upgrade2.log - - php upgrade.php 3.5.0 3.6.0 >> upgrade.log - - php upgrade2.php 3.5.0 3.6.0 >> upgrade2.log - - php upgrade.php 3.6.0 3.7.0 >> upgrade.log +# - php upgrade.php 3.4.0 3.5.0 ignoredbversion > upgrade.log +# - php upgrade2.php 3.4.0 3.5.0 ignoredbversion > upgrade2.log + - php upgrade.php 3.5.0 3.6.0 ignoredbversion >> upgrade.log + - php upgrade2.php 3.5.0 3.6.0 ignoredbversion >> upgrade2.log + - php upgrade.php 3.6.0 3.7.0 ignoredbversion >> upgrade.log # - cat upgrade360370.log - - php upgrade2.php 3.6.0 3.7.0 >> upgrade2.log + - php upgrade2.php 3.6.0 3.7.0 ignoredbversion >> upgrade2.log # - cat upgrade2.log - cd ../.. - date diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php index 1e1ba08b6f9..126c0896c80 100644 --- a/htdocs/install/upgrade.php +++ b/htdocs/install/upgrade.php @@ -19,9 +19,11 @@ * Upgrade scripts can be ran from command line with syntax: * * cd htdocs/install - * php upgrade.php 3.4.0 3.5.0 + * php upgrade.php 3.4.0 3.5.0 [dirmodule|ignoredbversion] * php upgrade2.php 3.4.0 3.5.0 * + * Option 'dirmodule' allows to provide a path for an external module, so we migrate from command line a script from a module. + * Option 'ignoredbversion' allows to run migration even if database is a bugged database version. * Return code is 0 if OK, >0 if error */ @@ -55,7 +57,8 @@ $setuplang=GETPOST("selectlang",'',3)?GETPOST("selectlang",'',3):'auto'; $langs->setDefaultLang($setuplang); $versionfrom=GETPOST("versionfrom",'',3)?GETPOST("versionfrom",'',3):(empty($argv[1])?'':$argv[1]); $versionto=GETPOST("versionto",'',3)?GETPOST("versionto",'',3):(empty($argv[2])?'':$argv[2]); -$versionmodule=GETPOST("versionmodule",'',3)?GETPOST("versionmodule",'',3):(empty($argv[3])?'':$argv[3]); +$dirmodule=GETPOST("dirmodule",'',3)?GETPOST("dirmodule",'',3):(empty($argv[3])?'':$argv[3]); +$ignoredbversion=GETPOST('ignoredbversion','',3)?GETPOST('ignoredbversion','',3):(empty($argv[3])?'':$argv[3]); $langs->load("admin"); $langs->load("install"); @@ -191,31 +194,34 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) } // Test database version is not forbidden for migration - $dbversion_disallowed=array( - array('type'=>'mysql','version'=>array(5,5,40)), - array('type'=>'mysqli','version'=>array(5,5,40)), - array('type'=>'mysql','version'=>array(5,5,41)), - array('type'=>'mysqli','version'=>array(5,5,41)) - ); - $listofforbiddenversion=''; - foreach ($dbversion_disallowed as $dbversion_totest) - { - if ($dbversion_totest['type'] == $db->type) $listofforbiddenversion.=($listofforbiddenversion?', ':'').join('.',$dbversion_totest['version']); - } - foreach ($dbversion_disallowed as $dbversion_totest) - { - //print $db->type.' - '.join('.',$versionarray).' - '.versioncompare($dbversion_totest['version'],$versionarray)."
\n"; - if ($dbversion_totest['type'] == $db->type - && (versioncompare($dbversion_totest['version'],$versionarray) == 0 || versioncompare($dbversion_totest['version'],$versionarray)<=-4 || versioncompare($dbversion_totest['version'],$versionarray)>=4) - ) - { - // Warning: database version too low. - print '
'.$langs->trans("ErrorDatabaseVersionForbiddenForMigration",join('.',$versionarray),$listofforbiddenversion)."
".$langs->trans("Error")."\n"; - dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ErrorDatabaseVersionForbiddenForMigration",join('.',$versionarray),$listofforbiddenversion)); - $ok=0; - break; - } - } + if (empty($ignoredbversion)) + { + $dbversion_disallowed=array( + array('type'=>'mysql','version'=>array(5,5,40)), + array('type'=>'mysqli','version'=>array(5,5,40)), + array('type'=>'mysql','version'=>array(5,5,41)), + array('type'=>'mysqli','version'=>array(5,5,41)) + ); + $listofforbiddenversion=''; + foreach ($dbversion_disallowed as $dbversion_totest) + { + if ($dbversion_totest['type'] == $db->type) $listofforbiddenversion.=($listofforbiddenversion?', ':'').join('.',$dbversion_totest['version']); + } + foreach ($dbversion_disallowed as $dbversion_totest) + { + //print $db->type.' - '.join('.',$versionarray).' - '.versioncompare($dbversion_totest['version'],$versionarray)."
\n"; + if ($dbversion_totest['type'] == $db->type + && (versioncompare($dbversion_totest['version'],$versionarray) == 0 || versioncompare($dbversion_totest['version'],$versionarray)<=-4 || versioncompare($dbversion_totest['version'],$versionarray)>=4) + ) + { + // Warning: database version too low. + print '
'.$langs->trans("ErrorDatabaseVersionForbiddenForMigration",join('.',$versionarray),$listofforbiddenversion)."
".$langs->trans("Error")."\n"; + dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ErrorDatabaseVersionForbiddenForMigration",join('.',$versionarray),$listofforbiddenversion)); + $ok=0; + break; + } + } + } } // Force l'affichage de la progression @@ -370,7 +376,7 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) if ($ok) { $dir = "mysql/migration/"; // We use mysql migration scripts whatever is database driver - if (! empty($versionmodule)) $dir=dol_buildpath('/'.$versionmodule.'/sql/',0); + if (! empty($dirmodule)) $dir=dol_buildpath('/'.$dirmodule.'/sql/',0); // Clean last part to exclude minor version x.y.z -> x.y $newversionfrom=preg_replace('/(\.[0-9]+)$/i','.0',$versionfrom); @@ -475,7 +481,7 @@ $ret=0; if (! $ok && isset($argv[1])) $ret=1; dol_syslog("Exit ".$ret); -pFooter(((! $ok && empty($_GET["ignoreerrors"])) || $versionmodule),$setuplang); +pFooter(((! $ok && empty($_GET["ignoreerrors"])) || $dirmodule),$setuplang); if ($db->connected) $db->close(); From eeb09b83a10fd4dcb843b3afde336866258ff014 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Mar 2015 20:50:46 +0100 Subject: [PATCH 42/60] The test on db version must not lock the phpunit --- htdocs/install/upgrade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php index 126c0896c80..359980763b0 100644 --- a/htdocs/install/upgrade.php +++ b/htdocs/install/upgrade.php @@ -57,8 +57,8 @@ $setuplang=GETPOST("selectlang",'',3)?GETPOST("selectlang",'',3):'auto'; $langs->setDefaultLang($setuplang); $versionfrom=GETPOST("versionfrom",'',3)?GETPOST("versionfrom",'',3):(empty($argv[1])?'':$argv[1]); $versionto=GETPOST("versionto",'',3)?GETPOST("versionto",'',3):(empty($argv[2])?'':$argv[2]); -$dirmodule=GETPOST("dirmodule",'',3)?GETPOST("dirmodule",'',3):(empty($argv[3])?'':$argv[3]); -$ignoredbversion=GETPOST('ignoredbversion','',3)?GETPOST('ignoredbversion','',3):(empty($argv[3])?'':$argv[3]); +$dirmodule=((GETPOST("dirmodule",'',3) && GETPOST("dirmodule",'',3) != 'ignoredbversion'))?GETPOST("dirmodule",'',3):((empty($argv[3]) || $argv[3] == 'ignoredbversion')?'':$argv[3]); +$ignoredbversion=(GETPOST('ignoredbversion','',3)=='ignoredbversion')?GETPOST('ignoredbversion','',3):((empty($argv[3]) || $argv[3] != 'ignoredbversion')?'':$argv[3]); $langs->load("admin"); $langs->load("install"); From b8ed5533658b83e327faa50b38b694bd7c76ed25 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 21 Mar 2015 01:08:29 +0100 Subject: [PATCH 43/60] We must keep the @, some tools use it to know it is login page. --- htdocs/core/tpl/login.tpl.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index 29eda49a9a9..f9e22ed3812 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -29,7 +29,7 @@ if (GETPOST('dol_use_jmobile')) $conf->dol_use_jmobile=1; if (! empty($conf->dol_use_jmobile)) $conf->use_javascript_ajax=1; $arrayofjs=array('/core/js/dst.js'.(empty($conf->dol_use_jmobile)?'':'?version='.urlencode(DOL_VERSION))); // Javascript code on logon page only to detect user tz, dst_observed, dst_first, dst_second -$titleofloginpage=$langs->trans('Login').' '.$title; // title is defined by dol_loginfunction in security2.lib.php +$titleofloginpage=$langs->trans('Login').' @ '.$title; // title is defined by dol_loginfunction in security2.lib.php. We must keep the @, some tools use it to know it is login page. print top_htmlhead('',$titleofloginpage,0,0,$arrayofjs); ?> @@ -49,7 +49,6 @@ $(document).ready(function () {