diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php
index b0adb2e2ad1..1f38171f199 100644
--- a/htdocs/accountancy/bookkeeping/card.php
+++ b/htdocs/accountancy/bookkeeping/card.php
@@ -641,8 +641,8 @@ if ($action == 'create')
print '
' . $accountingaccount->getNomUrl(0, 1, 1, '', 0) . ' ';
print '' . length_accounta($line->subledger_account) . ' ';
print '' . $line->label_operation. ' ';
- print '' . price($line->debit) . ' ';
- print '' . price($line->credit) . ' ';
+ print '' . price($line->debit) . ' ';
+ print '' . price($line->credit) . ' ';
print '';
print 'id . '&piece_num=' . $line->piece_num . '&mode='.$mode.'">';
@@ -675,7 +675,7 @@ if ($action == 'create')
print $formaccounting->select_account('', 'accountingaccount_number', 1, array (), 1, 1, '');
print ' ';
print '';
- // TODO For the moment we keep a fre input text instead of a combo. The select_auxaccount has problem because it does not
+ // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not
// use setup of keypress to select thirdparty and this hang browser on large database.
if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX))
{
diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php
index 4fc30bb0c30..05561f4a9d5 100644
--- a/htdocs/accountancy/bookkeeping/list.php
+++ b/htdocs/accountancy/bookkeeping/list.php
@@ -763,7 +763,7 @@ if ($num > 0)
// Amount debit
if (! empty($arrayfields['t.debit']['checked']))
{
- print ' ' . ($line->debit ? price($line->debit) : ''). ' ';
+ print '' . ($line->debit ? price($line->debit) : ''). ' ';
if (! $i) $totalarray['nbfield']++;
if (! $i) $totalarray['totaldebitfield']=$totalarray['nbfield'];
$totalarray['totaldebit'] += $line->debit;
@@ -772,7 +772,7 @@ if ($num > 0)
// Amount credit
if (! empty($arrayfields['t.credit']['checked']))
{
- print '' . ($line->credit ? price($line->credit) : '') . ' ';
+ print '' . ($line->credit ? price($line->credit) : '') . ' ';
if (! $i) $totalarray['nbfield']++;
if (! $i) $totalarray['totalcreditfield']=$totalarray['nbfield'];
$totalarray['totalcredit'] += $line->credit;
@@ -843,8 +843,8 @@ if ($num > 0)
if ($num < $limit && empty($offset)) print ''.$langs->trans("Total").' ';
else print ''.$langs->trans("Totalforthispage").' ';
}
- elseif ($totalarray['totaldebitfield'] == $i) print ''.price($totalarray['totaldebit']).' ';
- elseif ($totalarray['totalcreditfield'] == $i) print ''.price($totalarray['totalcredit']).' ';
+ elseif ($totalarray['totaldebitfield'] == $i) print ''.price($totalarray['totaldebit']).' ';
+ elseif ($totalarray['totalcreditfield'] == $i) print ''.price($totalarray['totalcredit']).' ';
else print ' ';
}
print '';
diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php
index 7e7f40ddfbb..8e1f36bbf41 100644
--- a/htdocs/accountancy/class/bookkeeping.class.php
+++ b/htdocs/accountancy/class/bookkeeping.class.php
@@ -469,14 +469,15 @@ class BookKeeping extends CommonObject
*/
public function createStd(User $user, $notrigger = false, $mode = '')
{
- global $conf;
+ global $conf, $langs;
+
+ $langs->loadLangs(array("accountancy", "bills", "compta"));
dol_syslog(__METHOD__, LOG_DEBUG);
$error = 0;
// Clean parameters
-
if (isset($this->doc_type)) {
$this->doc_type = trim($this->doc_type);
}
@@ -540,7 +541,7 @@ class BookKeeping extends CommonObject
$now = dol_now();
// Check parameters
- // Put here code to add control on parameters values
+ $this->journal_label = $langs->trans($this->journal_label);
// Insert request
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . $mode.' (';
diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php
index 33a06e09136..d6dfe78c7d6 100644
--- a/htdocs/compta/charges/index.php
+++ b/htdocs/compta/charges/index.php
@@ -183,7 +183,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
print $socialcontrib->getNomUrl(1, '20');
print '';
// Type
- print ''.$obj->lib.' ';
+ print ''.$obj->lib.' ';
// Expected to pay
print ''.price($obj->total).' ';
// Ref payment
diff --git a/htdocs/compta/sociales/list.php b/htdocs/compta/sociales/list.php
index 7e25d8c3423..baa1f57a307 100644
--- a/htdocs/compta/sociales/list.php
+++ b/htdocs/compta/sociales/list.php
@@ -187,7 +187,7 @@ if ($resql)
if ($year)
{
- $center=($year?"".img_previous()." ".$langs->trans("Year")." $year ".img_next()." ":"");
+ $center=($year?"".img_previous()." ".$langs->trans("Year")." $year ".img_next()." ":"");
print_barre_liste($langs->trans("SocialContributions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $totalnboflines, 'title_accountancy.png', 0, $newcardbutton, '', $limit);
}
else
@@ -281,7 +281,7 @@ if ($resql)
print '';
if ($obj->periode)
{
- print 'jdate($obj->periode)).'">'.dol_print_date($db->jdate($obj->periode), 'day').' ';
+ print 'jdate($obj->periode)).'">'.dol_print_date($db->jdate($obj->periode),'day').' ';
}
else
{
diff --git a/htdocs/compta/sociales/payments.php b/htdocs/compta/sociales/payments.php
index 384601ca989..daecbe581f8 100644
--- a/htdocs/compta/sociales/payments.php
+++ b/htdocs/compta/sociales/payments.php
@@ -90,7 +90,7 @@ print ' ';
if ($mode != 'sconly')
{
- $center=($year?''.img_previous($langs->trans("Previous"), 'class="valignbottom"')." ".$langs->trans("Year").' '.$year.' '.img_next($langs->trans("Next"), 'class="valignbottom"')." ":"");
+ $center=($year?''.img_previous($langs->trans("Previous"), 'class="valignbottom"')." ".$langs->trans("Year").' '.$year.' '.img_next($langs->trans("Next"), 'class="valignbottom"')." ":"");
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $totalnboflines, 'title_accountancy', 0, '', '', $limit, 1);
}
else
@@ -181,7 +181,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
print $socialcontrib->getNomUrl(1, '20');
print ' ';
// Type
- print ''.$obj->lib.' ';
+ print ''.$obj->lib.' ';
// Date
$date=$obj->periode;
if (empty($date)) $date=$obj->date_ech;
diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php
index 1311264f7fb..0a60d9dc0ae 100644
--- a/htdocs/core/modules/import/import_csv.modules.php
+++ b/htdocs/core/modules/import/import_csv.modules.php
@@ -594,16 +594,25 @@ class ImportCsv extends ModeleImports
// Test regexp
if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
{
- // If test is "Must exist in a field@table"
- if (preg_match('/^(.*)@(.*)$/', $objimport->array_import_regex[0][$val], $reg))
+ // If test is "Must exist in a field@table or field@table:..."
+ if (preg_match('/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg))
{
$field=$reg[1];
$table=$reg[2];
+ $filter=!empty($reg[3])?substr($reg[3], 1):'';
+
+ $cachekey = $field.'@'.$table;
+ if(! empty($filter)) $cachekey.= ':'.$filter;
// Load content of field@table into cache array
- if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
+ if (! is_array($this->cachefieldtable[$cachekey])) // If content of field@table not already loaded into cache
{
$sql="SELECT ".$field." as aliasfield FROM ".$table;
+ if(! empty($filter))
+ {
+ $sql.= ' WHERE ' . $filter;
+ }
+
$resql=$this->db->query($sql);
if ($resql)
{
@@ -612,7 +621,7 @@ class ImportCsv extends ModeleImports
while ($i < $num)
{
$obj=$this->db->fetch_object($resql);
- if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
+ if ($obj) $this->cachefieldtable[$cachekey][]=$obj->aliasfield;
$i++;
}
}
@@ -623,9 +632,11 @@ class ImportCsv extends ModeleImports
}
// Now we check cache is not empty (should not) and key is into cache
- if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval, $this->cachefieldtable[$field.'@'.$table]))
+ if (! is_array($this->cachefieldtable[$cachekey]) || ! in_array($newval, $this->cachefieldtable[$cachekey]))
{
- $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn', $key, $newval, $field, $table);
+ $tableforerror = $table;
+ if(! empty($filter)) $tableforerror.= ':'.$filter;
+ $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn', $key, $newval, $field, $tableforerror);
$this->errors[$error]['type']='FOREIGNKEY';
$errorforthistable++;
$error++;
diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php
index 00db9096bca..10b2a5662f3 100644
--- a/htdocs/core/modules/import/import_xlsx.modules.php
+++ b/htdocs/core/modules/import/import_xlsx.modules.php
@@ -621,16 +621,25 @@ class ImportXlsx extends ModeleImports
// Test regexp
if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
{
- // If test is "Must exist in a field@table"
- if (preg_match('/^(.*)@(.*)$/', $objimport->array_import_regex[0][$val], $reg))
+ // If test is "Must exist in a field@table or field@table:..."
+ if (preg_match('/^(.+)@([^:]+)(:.+)?$/',$objimport->array_import_regex[0][$val],$reg))
{
$field=$reg[1];
$table=$reg[2];
+ $filter=!empty($reg[3])?substr($reg[3], 1):'';
+
+ $cachekey = $field.'@'.$table;
+ if(! empty($filter)) $cachekey.= ':'.$filter;
// Load content of field@table into cache array
- if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
+ if (! is_array($this->cachefieldtable[$cachekey])) // If content of field@table not already loaded into cache
{
$sql="SELECT ".$field." as aliasfield FROM ".$table;
+ if(! empty($filter))
+ {
+ $sql.= ' WHERE ' . $filter;
+ }
+
$resql=$this->db->query($sql);
if ($resql)
{
@@ -639,7 +648,7 @@ class ImportXlsx extends ModeleImports
while ($i < $num)
{
$obj=$this->db->fetch_object($resql);
- if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
+ if ($obj) $this->cachefieldtable[$cachekey][]=$obj->aliasfield;
$i++;
}
}
@@ -650,9 +659,11 @@ class ImportXlsx extends ModeleImports
}
// Now we check cache is not empty (should not) and key is into cache
- if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval, $this->cachefieldtable[$field.'@'.$table]))
+ if (! is_array($this->cachefieldtable[$cachekey]) || ! in_array($newval, $this->cachefieldtable[$cachekey]))
{
- $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn', $key, $newval, $field, $table);
+ $tableforerror = $table;
+ if(! empty($filter)) $tableforerror.= ':'.$filter;
+ $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn', $key, $newval, $field, $tableforerror);
$this->errors[$error]['type']='FOREIGNKEY';
$errorforthistable++;
$error++;
diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php
index d8f8b6915f3..200b4170783 100644
--- a/htdocs/core/modules/modCategorie.class.php
+++ b/htdocs/core/modules/modCategorie.class.php
@@ -425,8 +425,8 @@ class modCategorie extends DolibarrModules
$this->import_icon[$r]=$this->picto;
$this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
$this->import_tables_array[$r]=array('cp'=>MAIN_DB_PREFIX.'categorie_product');
- $this->import_fields_array[$r]=array('cp.fk_categorie'=>"Category*",'cp.fk_product'=>"Product*"
- );
+ $this->import_fields_array[$r]=array('cp.fk_categorie'=>"Category*",'cp.fk_product'=>"Product*");
+ $this->import_regex_array[$r]=array('cp.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=0');
$this->import_convertvalue_array[$r]=array(
'cp.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'),
@@ -444,7 +444,10 @@ class modCategorie extends DolibarrModules
$this->import_icon[$r]=$this->picto;
$this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
$this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_societe');
- $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_soc'=>"ThirdParty*"
+ $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_soc'=>"ThirdParty*");
+ $this->import_regex_array[$r]=array(
+ 'cs.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=2',
+ 'cs.fk_soc'=>'rowid@'.MAIN_DB_PREFIX.'societe:client>0'
);
$this->import_convertvalue_array[$r]=array(
@@ -463,7 +466,10 @@ class modCategorie extends DolibarrModules
$this->import_icon[$r]=$this->picto;
$this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
$this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_fournisseur');
- $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_soc'=>"Supplier*"
+ $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_soc'=>"Supplier*");
+ $this->import_regex_array[$r]=array(
+ 'cs.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=1',
+ 'cs.fk_soc'=>'rowid@'.MAIN_DB_PREFIX.'societe:fournisseur>0'
);
$this->import_convertvalue_array[$r]=array(
diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php
index fe3cb32470e..8e5c87db848 100644
--- a/htdocs/expedition/card.php
+++ b/htdocs/expedition/card.php
@@ -1584,9 +1584,9 @@ if ($action == 'create')
print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan), $indiceAsked);
print '';
}
-
- $indiceAsked++;
}
+
+ $indiceAsked++;
}
print "";
diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php
index e03e50eb0dd..66a118c744b 100644
--- a/htdocs/holiday/class/holiday.class.php
+++ b/htdocs/holiday/class/holiday.class.php
@@ -1438,45 +1438,30 @@ class Holiday extends CommonObject
$result = $this->db->query($sql);
$typeleaves=$this->getTypes(1, 1);
- foreach($typeleaves as $key => $val)
- {
- // On ajoute x jours à chaque utilisateurs
- $nb_holiday = $val['newByMonth'];
- if (empty($nb_holiday)) $nb_holiday=0;
- if ($nb_holiday > 0)
+ // Update each user counter
+ foreach ($users as $userCounter) {
+ $nbDaysToAdd = $typeleaves[$userCounter['type']]['newByMonth'];
+ if(empty($nbDaysToAdd)) continue;
+
+ dol_syslog("We update leave type id ".$userCounter['type']." for user id ".$userCounter['rowid'], LOG_DEBUG);
+
+ $nowHoliday = $userCounter['nb_holiday'];
+ $newSolde = $nowHoliday + $nbDaysToAdd;
+
+ // We add a log for each user
+ $this->addLogCP($user->id, $userCounter['rowid'], $langs->trans('HolidaysMonthlyUpdate'), $newSolde, $userCounter['type']);
+
+ $result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type'], $langs->trans('HolidaysMonthlyUpdate'));
+
+ if ($result < 0)
{
- dol_syslog("We update leavefor everybody for type ".$key, LOG_DEBUG);
-
- $i = 0;
- while ($i < $nbUser)
- {
- $now_holiday = $this->getCPforUser($users[$i]['rowid'], $val['rowid']);
- $new_solde = $now_holiday + $nb_holiday;
-
- // We add a log for each user
- $this->addLogCP($user->id, $users[$i]['rowid'], $langs->trans('HolidaysMonthlyUpdate'), $new_solde, $val['rowid']);
-
- $i++;
- }
-
- // Now we update counter for all users at once
- $sql2 = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
- $sql2.= " nb_holiday = nb_holiday + ".$nb_holiday;
- $sql2.= " WHERE fk_type = ".$val['rowid'];
-
- $result= $this->db->query($sql2);
-
- if (! $result)
- {
- dol_print_error($this->db);
- break;
- }
+ $error++;
+ break;
}
- else dol_syslog("No change for leave of type ".$key, LOG_DEBUG);
}
- if ($result)
+ if (! $error)
{
$this->db->commit();
return 1;
@@ -1635,8 +1620,8 @@ class Holiday extends CommonObject
{
$sql = "SELECT nb_holiday";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday_users";
- $sql.= " WHERE fk_user = '".$user_id."'";
- if ($fk_type > 0) $sql.=" AND fk_type = ".$fk_type;
+ $sql.= " WHERE fk_user = ".(int) $user_id;
+ if ($fk_type > 0) $sql.=" AND fk_type = ".(int) $fk_type;
dol_syslog(get_class($this).'::getCPforUser user_id='.$user_id.' type_id='.$fk_type, LOG_DEBUG);
$result = $this->db->query($sql);
@@ -1799,7 +1784,7 @@ class Holiday extends CommonObject
$obj = $this->db->fetch_object($resql);
- $tab_result[$i]['rowid'] = $obj->rowid;
+ $tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
$tab_result[$i]['name'] = $obj->lastname; // deprecated
$tab_result[$i]['lastname'] = $obj->lastname;
$tab_result[$i]['firstname'] = $obj->firstname;
@@ -1807,7 +1792,7 @@ class Holiday extends CommonObject
$tab_result[$i]['status'] = $obj->statut;
$tab_result[$i]['employee'] = $obj->employee;
$tab_result[$i]['photo'] = $obj->photo;
- $tab_result[$i]['fk_user'] = $obj->fk_user;
+ $tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
//$tab_result[$i]['type'] = $obj->type;
//$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
@@ -1845,7 +1830,7 @@ class Holiday extends CommonObject
{
$obj = $this->db->fetch_object($resql);
- $tab_result[$i]['rowid'] = $obj->rowid;
+ $tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
$tab_result[$i]['name'] = $obj->lastname; // deprecated
$tab_result[$i]['lastname'] = $obj->lastname;
$tab_result[$i]['firstname'] = $obj->firstname;
@@ -1853,7 +1838,7 @@ class Holiday extends CommonObject
$tab_result[$i]['status'] = $obj->statut;
$tab_result[$i]['employee'] = $obj->employee;
$tab_result[$i]['photo'] = $obj->photo;
- $tab_result[$i]['fk_user'] = $obj->fk_user;
+ $tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
$tab_result[$i]['type'] = $obj->fk_type;
$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
diff --git a/htdocs/install/step2.php b/htdocs/install/step2.php
index 1a8a4108827..b553166e8bc 100644
--- a/htdocs/install/step2.php
+++ b/htdocs/install/step2.php
@@ -450,6 +450,11 @@ if ($action == "set")
$buffer=trim($buffer);
if ($buffer)
{
+ // Replace the prefix in table names
+ if ($dolibarr_main_db_prefix != 'llx_')
+ {
+ $buffer=preg_replace('/llx_/i',$dolibarr_main_db_prefix,$buffer);
+ }
dolibarr_install_syslog("step2: request: " . $buffer);
print "\n";
$resql=$db->query($buffer, 0, 'dml');
diff --git a/htdocs/viewimage.php b/htdocs/viewimage.php
index 4d13b182fd4..07b69fff2e9 100644
--- a/htdocs/viewimage.php
+++ b/htdocs/viewimage.php
@@ -170,7 +170,9 @@ if (GETPOST('type', 'alpha')) $type=GETPOST('type', 'alpha');
else $type=dol_mimetype($original_file);
// Security: This wrapper is for images. We do not allow type/html
-if (preg_match('/html/', $type)) accessforbidden('Error: Using the image wrapper to output a file with a mime type HTML is not possible.', 0, 0, 1);
+if (preg_match('/html/i', $type)) accessforbidden('Error: Using the image wrapper to output a file with a mime type HTML is not possible.', 0, 0, 1);
+// Security: This wrapper is for images. We do not allow files ending with .noexe
+if (preg_match('/\.noexe$/i', $original_file)) accessforbidden('Error: Using the image wrapper to output a file ending with .noexe is not allowed.', 0, 0, 1);
// Security: Delete string ../ into $original_file
$original_file = str_replace("../", "/", $original_file);