Skip to content

Commit

Permalink
Merge branch 'develop' into fix/ignored_phpstan_61
Browse files Browse the repository at this point in the history
  • Loading branch information
frederic34 authored Sep 30, 2024
2 parents 2cc6b2f + 2c518be commit 04531a7
Show file tree
Hide file tree
Showing 42 changed files with 212 additions and 118 deletions.
2 changes: 1 addition & 1 deletion dev/tools/phan/baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ return [
'htdocs/adherents/stats/index.php' => ['PhanTypeInvalidDimOffset'],
'htdocs/admin/fckeditor.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'htdocs/api/class/api_access.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanUndeclaredProperty'],
'htdocs/api/class/api_documents.class.php' => ['PhanPluginDuplicateExpressionBinaryOp', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPossiblyUndeclaredVariable'],
'htdocs/api/class/api_documents.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginDuplicateExpressionBinaryOp', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPossiblyUndeclaredVariable'],
'htdocs/api/class/api_login.class.php' => ['PhanPluginUnknownArrayMethodReturnType'],
'htdocs/api/class/api_setup.class.php' => ['PhanPluginUnknownArrayMethodReturnType'],
'htdocs/api/class/api_status.class.php' => ['PhanPluginUnknownArrayMethodReturnType'],
Expand Down
23 changes: 19 additions & 4 deletions htdocs/accountancy/admin/fiscalyear_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}

if ($action == 'confirm_delete' && $confirm == "yes") {
if ($action == 'confirm_delete' && $confirm == "yes" && $permissiontoadd) {
$result = $object->delete($user);
if ($result >= 0) {
header("Location: fiscalyear.php");
exit();
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
} elseif ($action == 'add') {
} elseif ($action == 'add' && $permissiontoadd) {
if (!GETPOST('cancel', 'alpha')) {
$error = 0;

Expand Down Expand Up @@ -144,7 +144,7 @@
header("Location: ./fiscalyear.php");
exit();
}
} elseif ($action == 'update') {
} elseif ($action == 'update' && $permissiontoadd) {
// Update record
if (!GETPOST('cancel', 'alpha')) {
$result = $object->fetch($id);
Expand All @@ -166,8 +166,19 @@
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit();
}
}
} elseif ($action == 'reopen' && $permissiontoadd && getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD')) {
$result = $object->fetch($id);

$object->status = GETPOSTINT('status');
$result = $object->update($user);

if ($result > 0) {
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit();
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}


/*
Expand Down Expand Up @@ -364,6 +375,10 @@
if ($user->hasRight('accounting', 'fiscalyear', 'write')) {
print '<div class="tabsAction">';

if (getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD') && $object->status == $object::STATUS_CLOSED) {
print dolGetButtonAction($langs->trans("ReOpen"), '', 'reopen', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken(), 'reopen', $permissiontoadd);
}

print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';

//print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
Expand Down
7 changes: 2 additions & 5 deletions htdocs/accountancy/bookkeeping/balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
accessforbidden();
}


/*
* Action
*/
Expand Down Expand Up @@ -169,10 +170,6 @@
$filter['t.doc_date<='] = $search_date_end;
$param .= '&date_endmonth=' . GETPOSTINT('date_endmonth') . '&date_endday=' . GETPOSTINT('date_endday') . '&date_endyear=' . GETPOSTINT('date_endyear');
}
if (!empty($search_doc_date)) {
$filter['t.doc_date'] = $search_doc_date;
$param .= '&doc_datemonth=' . GETPOSTINT('doc_datemonth') . '&doc_dateday=' . GETPOSTINT('doc_dateday') . '&doc_dateyear=' . GETPOSTINT('doc_dateyear');
}
if (!empty($search_accountancy_code_start)) {
if ($type == 'sub') {
$filter['t.subledger_account>='] = $search_accountancy_code_start;
Expand Down Expand Up @@ -207,7 +204,7 @@
}
}

if ($action == 'export_csv') {
if ($action == 'export_csv' && $user->hasRight('accounting', 'mouvements', 'lire')) {
$sep = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV');

$filename = 'balance';
Expand Down
2 changes: 1 addition & 1 deletion htdocs/accountancy/class/bookkeeping.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2536,7 +2536,7 @@ public function loadFiscalPeriods($force = false, $mode = 'active')
}

/**
* Get list of fiscal period
* Get list of fiscal period ordered by start date.
*
* @param string $filter Filter
* @return array<array{id:int,label:string,date_start:string,date_end:string,status:int}>|int Return integer <0 if KO, Fiscal periods : [[id, date_start, date_end, label], ...]
Expand Down
55 changes: 38 additions & 17 deletions htdocs/accountancy/closure/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,57 @@
setEventMessages($object->error, $object->errors, 'errors');
}

// Define the arrays of fiscal periods
$active_fiscal_periods = array();
$first_active_fiscal_period = null;
$last_fiscal_period = null;
$current_fiscal_period = null;
$next_fiscal_period = null;
$next_active_fiscal_period = null;
if (is_array($fiscal_periods)) {
foreach ($fiscal_periods as $fiscal_period) {
if (empty($fiscal_period['status'])) {
foreach ($fiscal_periods as $fiscal_period) { // List of fiscal periods sorted by date start
if (empty($first_active_fiscal_period) && empty($fiscal_period['status'])) {
$first_active_fiscal_period = $fiscal_period;
}
if (empty($fiscal_period['status'])) { // if not closed
$active_fiscal_periods[] = $fiscal_period;
}
if (isset($current_fiscal_period)) {
if (isset($current_fiscal_period)) { // If we already reach then current fiscal period, then this one is the next one just after
if (!isset($next_fiscal_period)) {
$next_fiscal_period = $fiscal_period;
}
if (!isset($next_active_fiscal_period) && empty($fiscal_period['status'])) {
$next_active_fiscal_period = $fiscal_period;
}
} else {
} else { // If we did not found the current fiscal period
if ($fiscal_period_id == $fiscal_period['id'] || (empty($fiscal_period_id) && $fiscal_period['date_start'] <= $now && $now <= $fiscal_period['date_end'])) {
$current_fiscal_period = $fiscal_period;
} else {
$last_fiscal_period = $fiscal_period;
$last_fiscal_period = $fiscal_period; // $last_fiscal_period is in fact $previous_fiscal_period
}
}
}
}

// If a current fiscal period open with an end and start date was not found, we autoselect the first one that is open and has a start and end date defined
if (empty($current_fiscal_period) && !empty($first_active_fiscal_period)) {
$current_fiscal_period = $first_active_fiscal_period;
$last_fiscal_period = null;
$foundcurrent = false;
foreach ($fiscal_periods as $fiscal_period) { // List of fiscal periods sorted by date start
if ($foundcurrent) {
$next_fiscal_period = $fiscal_period;
break;
}
if ($fiscal_period['id'] == $current_fiscal_period['id']) {
$foundcurrent = true;
}
if (!$foundcurrent) {
$last_fiscal_period = $fiscal_period;
}
}
}

$accounting_groups_used_for_balance_sheet_account = array_filter(array_map('trim', explode(',', getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))), 'strlen');
$accounting_groups_used_for_income_statement = array_filter(array_map('trim', explode(',', getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))), 'strlen');

Expand All @@ -103,8 +127,8 @@
}

if (empty($reshook)) {
if (isset($current_fiscal_period) && $user->hasRight('accounting', 'fiscalyear', 'write')) {
if ($action == 'confirm_step_1' && $confirm == "yes") {
if (isset($current_fiscal_period)) {
if ($action == 'confirm_step_1' && $confirm == "yes" && $user->hasRight('accounting', 'fiscalyear', 'write')) {
$date_start = dol_mktime(0, 0, 0, GETPOSTINT('date_startmonth'), GETPOSTINT('date_startday'), GETPOSTINT('date_startyear'));
$date_end = dol_mktime(23, 59, 59, GETPOSTINT('date_endmonth'), GETPOSTINT('date_endday'), GETPOSTINT('date_endyear'));

Expand All @@ -119,7 +143,7 @@
setEventMessages($object->error, $object->errors, 'errors');
$action = '';
}
} elseif ($action == 'confirm_step_2' && $confirm == "yes") {
} elseif ($action == 'confirm_step_2' && $confirm == "yes" && $user->hasRight('accounting', 'fiscalyear', 'write')) {
$new_fiscal_period_id = GETPOSTINT('new_fiscal_period_id');
$separate_auxiliary_account = GETPOST('separate_auxiliary_account', 'aZ09');
$generate_bookkeeping_records = GETPOST('generate_bookkeeping_records', 'aZ09');
Expand All @@ -128,11 +152,10 @@
if ($generate_bookkeeping_records) {
if (!getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT')) {
$error++;
setEventMessages($langs->trans("ErrorModuleSetupNotComplete"), null, 'errors');
}
if (!getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
setEventMessages($langs->trans("ErrorAccountingClosureSetupNotComplete"), null, 'errors');
} elseif (!getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
$error++;
setEventMessages($langs->trans("ErrorModuleSetupNotComplete"), null, 'errors');
setEventMessages($langs->trans("ErrorAccountingClosureSetupNotComplete"), null, 'errors');
}
}

Expand All @@ -147,7 +170,7 @@
exit;
}
}
} elseif ($action == 'confirm_step_3' && $confirm == "yes") {
} elseif ($action == 'confirm_step_3' && $confirm == "yes" && $user->hasRight('accounting', 'fiscalyear', 'write')) {
$inventory_journal_id = GETPOSTINT('inventory_journal_id');
$new_fiscal_period_id = GETPOSTINT('new_fiscal_period_id');
$date_start = dol_mktime(0, 0, 0, GETPOSTINT('date_startmonth'), GETPOSTINT('date_startday'), GETPOSTINT('date_startyear'));
Expand Down Expand Up @@ -316,9 +339,7 @@

if (empty($current_fiscal_period)) {
print $langs->trans('ErrorNoFiscalPeriodActiveFound', $langs->transnoentitiesnoconv("Accounting"), $langs->transnoentitiesnoconv("Setup"), $langs->transnoentitiesnoconv("FiscalPeriod"));
}

if (isset($current_fiscal_period)) {
} else {
// Step 1
$head = array();
$head[0][0] = DOL_URL_ROOT . '/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period['id'];
Expand Down Expand Up @@ -384,7 +405,7 @@
if (empty($count_by_month['total']) && empty($current_fiscal_period['status'])) {
$button = '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=step_2&fiscal_period_id=' . $current_fiscal_period['id'] . '">' . $langs->trans("AccountancyClosureClose") . '</a>';
} else {
$button = '<a class="butActionRefused classfortooltip" href="#">' . $langs->trans("AccountancyClosureClose") . '</a>';
$button = '<a class="butActionRefused classfortooltip" href="#" title="This fiscal period already has the status Closed. Feature disabled.">' . $langs->trans("AccountancyClosureClose") . '</a>';
}
print_barre_liste('', '', '', '', '', '', '', -1, '', '', 0, $button, '', 0, 1, 0);

Expand Down
6 changes: 3 additions & 3 deletions htdocs/admin/modulehelp.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@

$text .= '<br><span class="opacitymedium">'.$langs->trans("IdModule").':</span> '.$objMod->numero;

$text .= '<br><span class="opacitymedium">'.$langs->trans("Version").':</span> '.$version;

$textexternal = '';
if ($objMod->isCoreOrExternalModule() == 'external') {
$tmpdirofmoduletoshow = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', (string) $dirofmodule);
Expand Down Expand Up @@ -381,8 +379,10 @@
} elseif (!empty($objMod->enabled_bydefault)) {
$text .= ' &nbsp; <span class="italic opacitymedium">('.$langs->trans("EnabledByDefaultAtInstall").')</span>';
}
$text .= '<br>';
}

$text .= '<br><span class="opacitymedium">'.$langs->trans("Version").':</span> '.$version;

$text .= '<br>';

$moduledesclong = $objMod->getDescLong();
Expand Down
2 changes: 1 addition & 1 deletion htdocs/admin/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@

if ($action == 'checklastversion') {
if ($foundoneexternalmodulewithupdate) {
setEventMessages($langs->trans("ModuleUpdateAvailable"), null, 'warnings');
setEventMessages($langs->trans("ModuleUpdateAvailable"), null, 'warnings', '', 0, 1);
} else {
setEventMessages($langs->trans("NoExternalModuleWithUpdate"), null, 'mesgs');
}
Expand Down
4 changes: 2 additions & 2 deletions htdocs/admin/system/database-tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@
$db->query($sql);
}
if ($action == 'convertutf8') {
$sql = "ALTER TABLE ".$db->sanitize($table)." CHARACTER SET utf8 COLLATE utf8_unicode_ci";
$sql = "ALTER TABLE ".$db->sanitize($table)." CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci";
$db->query($sql);
}
if ($action == 'convertutf8mb4') {
$sql = "ALTER TABLE ".$db->sanitize($table)." CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
$sql = "ALTER TABLE ".$db->sanitize($table)." CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
$db->query($sql);
}
if ($action == 'convertdynamic') {
Expand Down
4 changes: 2 additions & 2 deletions htdocs/admin/system/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@
print '<tr class="oddeven"><td width="300">'.$langs->trans("Password").'</td><td>'.preg_replace('/./i', '*', $dolibarr_main_db_pass).'</td></tr>'."\n";
print '<tr class="oddeven"><td width="300">'.$langs->trans("DBStoringCharset").'</td><td>'.$db->getDefaultCharacterSetDatabase();
if ($db->type == 'mysqli') {
print ' '.$form->textwithpicto('', $langs->transnoentitiesnoconv("HelpMariaDBToGetPossibleValues", "SHOW CHARSET"));
print ' '.$form->textwithpicto('', $langs->transnoentitiesnoconv("HelpMariaDBToGetValue", "SHOW VARIABLES LIKE 'character_set_database'").'<br>'.$langs->transnoentitiesnoconv("HelpMariaDBToGetPossibleValues", "SHOW CHARSET"));
// We can use $db->getDefaultCharacterSetDatabase(), $db->getListOfCharacterSet(),
}
print '</td></tr>'."\n";
print '<tr class="oddeven"><td width="300">'.$langs->trans("DBSortingCharset").'</td><td>'.$db->getDefaultCollationDatabase();
if ($db->type == 'mysqli') {
print ' '.$form->textwithpicto('', $langs->transnoentitiesnoconv("HelpMariaDBToGetPossibleValues", "SHOW COLLATION"));
print ' '.$form->textwithpicto('', $langs->transnoentitiesnoconv("HelpMariaDBToGetValue", "SHOW VARIABLES LIKE 'collation_database'").'<br>'.$langs->transnoentitiesnoconv("HelpMariaDBToGetPossibleValues", "SHOW COLLATION"));
// We can use $db->getDefaultCollationDatabase(), $db->getListOfCollation();
}
print '</td></tr>'."\n";
Expand Down
20 changes: 14 additions & 6 deletions htdocs/api/class/api_documents.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,23 +661,22 @@ public function getDocumentsListByElement($modulepart, $id = 0, $ref = '', $sort
* @param string $fileencoding File encoding (''=no encoding, 'base64'=Base 64)
* @param int $overwriteifexists Overwrite file if exists (1 by default)
* @param int $createdirifnotexists Create subdirectories if the doesn't exists (1 by default)
* @param int $position Position
* @param string $cover Cover info
* @param array $array_options array of options
* @return string
*
* @url POST /upload
*
* @throws RestException 400 Bad Request
* @throws RestException 403 Access denied
* @throws RestException 404 Object not found
* @throws RestException 500 Error on file operationw
* @throws RestException 500 Error on file operation
*/
public function post($filename, $modulepart, $ref = '', $subdir = '', $filecontent = '', $fileencoding = '', $overwriteifexists = 0, $createdirifnotexists = 1)
public function post($filename, $modulepart, $ref = '', $subdir = '', $filecontent = '', $fileencoding = '', $overwriteifexists = 0, $createdirifnotexists = 1, $position = 0, $cover = '', $array_options = [])
{
global $conf;

//var_dump($modulepart);
//var_dump($filename);
//var_dump($filecontent);exit;

$modulepartorig = $modulepart;

if (empty($modulepart)) {
Expand Down Expand Up @@ -938,6 +937,15 @@ public function post($filename, $modulepart, $ref = '', $subdir = '', $fileconte
$moreinfo['src_object_type'] = $object->table_element;
$moreinfo['src_object_id'] = $object->id;
}
if (!empty($array_options)) {
$moreinfo = array_merge($moreinfo, ["array_options" => $array_options]);
}
if (!empty($position)) {
$moreinfo = array_merge($moreinfo, ["position" => $position]);
}
if (!empty($cover)) {
$moreinfo = array_merge($moreinfo, ["cover" => $cover]);
}

// Move the temporary file at its final emplacement
$result = dol_move($destfiletmp, $dest_file, '0', $overwriteifexists, 1, 1, $moreinfo);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/compta/bank/releve.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
* Actions
*/

if ($action == 'confirm_editbankreceipt' && !empty($oldbankreceipt) && !empty($newbankreceipt)) {
if ($action == 'confirm_editbankreceipt' && !empty($oldbankreceipt) && !empty($newbankreceipt) && $user->hasRight('banque', 'consolidate')) {
// Test to check newbankreceipt does not exists yet
$sqltest = "SELECT b.rowid FROM ".MAIN_DB_PREFIX."bank as b, ".MAIN_DB_PREFIX."bank_account as ba";
$sqltest .= " WHERE b.fk_account = ba.rowid AND ba.entity = ".((int) $conf->entity);
Expand Down
5 changes: 3 additions & 2 deletions htdocs/compta/paiement_charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
// Load translation files required by the page
$langs->loadLangs(array("banks", "bills", "compta"));

$chid = GETPOSTINT("id");
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel');

$chid = GETPOSTINT("id");
$amounts = array();

// Security check
Expand All @@ -51,7 +52,7 @@
* Actions
*/

if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) {
if (($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) && $user->hasRight('tax', 'charges', 'creer')) {
$error = 0;

if ($cancel) {
Expand Down
7 changes: 5 additions & 2 deletions htdocs/compta/paiement_vat.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
// Load translation files required by the page
$langs->loadLangs(array("banks", "bills"));

$chid = GETPOSTINT("id");
$action = GETPOST('action', 'alpha');
$confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel');

$chid = GETPOSTINT("id");
$amounts = array();

// Security check
Expand All @@ -45,12 +46,14 @@
$socid = $user->socid;
}

$permissiontoadd = $user->hasRight('tax', 'charges', 'creer');


/*
* Actions
*/

if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) {
if (($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) && $permissiontoadd) {
$error = 0;

if ($cancel) {
Expand Down
Loading

0 comments on commit 04531a7

Please sign in to comment.