}
}
- return class_exists($className, false) || interface_exists($className, false);
+ return false;
}
/**
namespace Galette\Controllers\Crud;
use Galette\Features\BatchList;
-use Galette\Filters\ContributionsList;
-use Throwable;
use Analog\Analog;
use Galette\Controllers\CrudController;
use Slim\Psr7\Request;
);
if (
!$member->hasParent() ||
- $member->hasParent() && $member->parent->id != $this->login->id
+ $member->parent->id != $this->login->id
) {
$value = $this->login->id;
Analog::log(
}
if (isset($post['end_date_filter']) || isset($post['start_date_filter'])) {
- try {
- if (isset($post['start_date_filter'])) {
- $filters->start_date_filter = $post['start_date_filter'];
- }
- if (isset($post['end_date_filter'])) {
- $filters->end_date_filter = $post['end_date_filter'];
- }
- } catch (Throwable $e) {
- $error_detected[] = $e->getMessage();
+ if (isset($post['start_date_filter'])) {
+ $filters->start_date_filter = $post['start_date_filter'];
+ }
+ if (isset($post['end_date_filter'])) {
+ $filters->end_date_filter = $post['end_date_filter'];
}
}
$post = $request->getParsedBody();
if (isset($post['entries_sel'])) {
- $filters = $this->session->$filter_name ?? new ContributionsList();
+ $filter_class = '\\Galette\\Filters\\' . ucwords($type . 'List');
+ $filters = $this->session->$filter_name ?? new $filter_class();
$filters->selected = $post['entries_sel'];
$this->session->$filter_name = $filters;
}
if (isset($post['end_date_filter']) || isset($post['start_date_filter'])) {
- try {
- if (isset($post['start_date_filter'])) {
- $filters->start_date_filter = $post['start_date_filter'];
- }
- if (isset($post['end_date_filter'])) {
- $filters->end_date_filter = $post['end_date_filter'];
- }
- } catch (Throwable $e) {
- $error_detected[] = $e->getMessage();
+ if (isset($post['start_date_filter'])) {
+ $filters->start_date_filter = $post['start_date_filter'];
+ }
+ if (isset($post['end_date_filter'])) {
+ $filters->end_date_filter = $post['end_date_filter'];
}
}
}
if (isset($post['end_date_filter']) || isset($post['start_date_filter'])) {
- try {
- if (isset($post['start_date_filter'])) {
- $filters->start_date_filter = $post['start_date_filter'];
- }
- if (isset($post['end_date_filter'])) {
- $filters->end_date_filter = $post['end_date_filter'];
- }
- } catch (Throwable $e) {
- $error_detected[] = $e->getMessage();
+ if (isset($post['start_date_filter'])) {
+ $filters->start_date_filter = $post['start_date_filter'];
+ }
+ if (isset($post['end_date_filter'])) {
+ $filters->end_date_filter = $post['end_date_filter'];
}
}
$response = $response
->withHeader('Content-type', 'application/pdf')
->withHeader('Content-Disposition', 'attachment;filename="' . $pdf->getFileName() . '"');
- $response->getBody()->write($pdf->download() ?? '');
+ $response->getBody()->write($pdf->download());
return $response;
}
*
* @param Request $request PSR Request
* @param Response $response PSR Response
- * @param integer $id_adh Member id
+ * @param ?integer $id_adh Member id
*
* @return Response
*/
// Fill array $selected with selected ids
$selected = array();
- if (isset($unique) && $unique) {
+ if (isset($unique)) {
$selected[] = $unique;
} else {
$selected = $filters->selected;
$zdb->connection->rollBack();
} catch (\PDOException $e) {
//to avoid php8/mysql autocommit issue
- if ($zdb->isPostgres() || (!$zdb->isPostgres() && !str_contains($e->getMessage(), 'no active transaction'))) {
+ if ($zdb->isPostgres() || !str_contains($e->getMessage(), 'no active transaction')) {
throw $e;
}
}
$zdb->connection->commit();
} catch (\PDOException $e) {
//to avoid php8/mysql autocommit issue
- if ($zdb->isPostgres() || (!$zdb->isPostgres() && !str_contains($e->getMessage(), 'no active transaction'))) {
+ if ($zdb->isPostgres() || !str_contains($e->getMessage(), 'no active transaction')) {
throw $e;
}
}
$conffile = GALETTE_CONFIG_PATH . 'config.inc.php';
if (
is_writable(GALETTE_CONFIG_PATH)
- && (!file_exists($conffile) || file_exists($conffile) && is_writable($conffile))
+ && (!file_exists($conffile) || is_writable($conffile))
&& $fd = @fopen($conffile, 'w')
) {
$data = "<?php
private $sender_address;
private $sent = false;
- private $senders;
-
/**
* Default constructor
*
foreach ($insert_values as $champ => $valeur) {
if (
$login->isSuperAdmin()
- || (!$login->isSuperAdmin()
- && ($champ != 'pref_admin_pass' && $champ != 'pref_admin_login'))
+ || $champ != 'pref_admin_pass' && $champ != 'pref_admin_login'
) {
if (
($champ == "pref_admin_pass" && $_POST['pref_admin_pass'] != '')
}
break;
case 'pref_numrows':
- if (!is_numeric($value) || $value < 0) {
- $this->errors[] = _T("- The numbers and measures have to be integers!");
- }
- break;
case 'pref_etiq_marges_h':
case 'pref_etiq_marges_v':
case 'pref_etiq_hspace':
case 'pref_card_marges_h':
case 'pref_card_hspace':
case 'pref_card_vspace':
- // prevent division by zero
- if ($fieldname == 'pref_numrows' && $value == '0') {
- $value = '10';
- }
if (!is_numeric($value) || $value < 0) {
$this->errors[] = _T("- The numbers and measures have to be integers!");
}
* @property string $stitle Title label
* @property string $company_name
* @property string $name
- * @property string $surname
+ * @property ?string $surname
* @property string $nickname
* @property string $birthdate Localized birthdate
* @property string $rbirthdate Raw birthdate
}
}
- $success = false;
if (empty($this->_id)) {
//we're inserting a new member
unset($values[self::PK]);
$this->sname
);
}
- $success = true;
$event = 'member.add';
} else {
$this->sname
);
}
- $success = true;
$event = 'member.edit';
}
//dynamic fields
- if ($success) {
- $success = $this->dynamicsStore();
- $this->storeSocials($this->id);
- }
+ $this->dynamicsStore();
+ $this->storeSocials($this->id);
//send event at the end of process, once all has been stored
if ($event !== null) {
$emitter->dispatch(new GaletteEvent($event, $this));
}
- return $success;
+ return true;
} catch (Throwable $e) {
Analog::log(
'Something went wrong :\'( | ' . $e->getMessage() . "\n" .
unset($values['date_fin_cotis']);
}
- $success = false;
if (!isset($this->_id) || $this->_id == '') {
//we're inserting a new contribution
unset($values[self::PK]);
_T("Contribution added"),
Adherent::getSName($this->zdb, $this->_member)
);
- $success = true;
$event = 'contribution.add';
} else {
$hist->add(_T("Fail to add new contribution."));
'An error occurred updating contribution # ' . $this->_id . '!'
);
}
- $success = true;
$event = 'contribution.edit';
}
//update deadline
}
//dynamic fields
- if ($success) {
- $success = $this->dynamicsStore(true);
- }
+ $this->dynamicsStore(true);
$this->zdb->connection->commit();
$this->_orig_amount = $this->_amount;
case 'footer':
case 'body':
if ($value === null || trim($value) === '') {
- if ($name !== 'body' && get_class($this) === 'PdfMain') {
+ if ($name !== 'body' && get_class($this) === PdfMain::class) {
throw new \UnexpectedValueException(
_T("header and footer should not be empty!")
);
- } elseif ($name === 'body' && get_class($this) !== 'PdfMain') {
+ } elseif ($name === 'body' && get_class($this) !== PdfMain::class) {
throw new \UnexpectedValueException(
_T("body should not be empty!")
);
case 'type':
case 'date':
return $this->$name;
+ case 'comment':
+ return $this->comment;
default:
Analog::log(
'Unable to get Reminder property ' . $name,
case 'member_id':
case 'type':
case 'date':
+ case 'comment':
return true;
}
return false;
} else {
return $this->$name;
}
- break;
}
}
}
$values[$field] = $this->$prop;
}
- $success = false;
if (!isset($this->_id) || $this->_id == '') {
//we're inserting a new transaction
unset($values[self::PK]);
_T("Transaction added"),
Adherent::getSName($this->zdb, $this->_member)
);
- $success = true;
$event = 'transaction.add';
} else {
$hist->add(_T("Fail to add new transaction."));
Adherent::getSName($this->zdb, $this->_member)
);
}
- $success = true;
$event = 'transaction.edit';
}
//dynamic fields
- if ($success) {
- $this->dynamicsStore(true);
- }
+ $this->dynamicsStore(true);
$this->zdb->connection->commit();
);
return $this->$name;
}
- break;
case 'rstart_date_filter':
case 'rend_date_filter':
//same as above, but raw format
);
return $this->$name;
}
- break;
case 'rstart_date_filter':
case 'rend_date_filter':
//same as above, but raw format
namespace Galette\IO;
use Analog\Analog;
+use Galette\Core\Db;
use Laminas\Db\Sql\Expression;
use Laminas\Db\Sql\Predicate\PredicateSet;
use Galette\Entity\Status;
*/
private function getChartContribsAllTime()
{
+ /** @var Db $zdb */
global $zdb;
$select = $zdb->select(Contribution::TABLE);
);
$groupby = null;
- if (TYPE_DB === 'pgsql') {
+ if ($zdb->isPostgres()) {
$cols['date'] = new Expression('date_trunc(\'month\', date_enreg)');
$groupby = new Expression('date_trunc(\'month\', date_enreg)');
- } elseif (TYPE_DB === 'mysql') {
+ } else {
$cols['date'] = new Expression('date_format(date_enreg, \'%Y-%m\')');
$groupby = new Expression('date_format(date_enreg, \'%Y-%m\')');
}
*
* PHP version 5
*
- * Copyright © 2021 The Galette Team
+ * Copyright © 2021-2023 The Galette Team
*
* This file is part of Galette (http://galette.tuxfamily.org).
*
* @package Galette
*
* @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2019 The Galette Team
+ * @copyright 2021-2023 The Galette Team
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
* @link http://galette.tuxfamily.org
* @since Available since 0.9.6-dev - 2021-11-07
use DateTime;
use Galette\Core\Db;
use Galette\Core\Login;
-use Galette\Core\Authentication;
use Galette\Entity\Adherent;
-use Galette\Entity\Contribution;
use Galette\Entity\ContributionsTypes;
use Galette\Repository\Contributions;
use Galette\Filters\ContributionsList;
* @name Csv
* @package Galette
* @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2021 The Galette Team
+ * @copyright 2021-2023 The Galette Team
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
* @link http://galette.tuxfamily.org
* @since Available since 0.9.6-dev - 2021-11-07
private $path;
private $zdb;
private $login;
- private $members_fields;
- private $fields_config;
- private $filters;
private $type;
/**
{
public const DEFAULT_DIRECTORY = GALETTE_EXPORTS_PATH;
- private $rs;
private $parameted_path;
private $legacy_parameted_file = 'exports.xml';
private $parameted_file = 'exports.yaml';
break;
default:
throw new \RuntimeException('Unknown protocol.');
- break;
}
Analog::log(
private $login;
private $members_fields;
private $fields_config;
- private $filters;
/**
* Default constructor
* Main constructor, set creator and author
*
* @param Preferences $prefs Preferences
- * @param PdfModel $model Related model
+ * @param ?PdfModel $model Related model
*/
- public function __construct(Preferences $prefs, $model = null)
+ public function __construct(Preferences $prefs, ?PdfModel $model = null)
{
global $i18n;
}
if ($model !== null) {
- if ($model instanceof PdfModel) {
- $this->model = $model;
- $this->SetTitle($this->model->htitle);
- } else {
- throw new \UnexpectedValueException(
- 'Provided model must be an instance of PdfModel!'
- );
- }
+ $this->model = $model;
+ $this->SetTitle($this->model->htitle);
}
}
'Location',
$this->routeparser->urlFor('slash')
)->withStatus(302);
- } else {
- //check for ACLs
- $routeContext = RouteContext::fromRequest($request);
- $route = $routeContext->getRoute();
- $cur_route = $route->getName();
- $acl = $this->getAclFor($cur_route);
-
- $go = false;
- switch ($acl) {
- case 'superadmin':
- if ($this->login->isSuperAdmin()) {
- $go = true;
- }
- break;
- case 'admin':
- if (
- $this->login->isSuperAdmin()
- || $this->login->isAdmin()
- ) {
- $go = true;
- }
- break;
- case 'staff':
- if (
- $this->login->isSuperAdmin()
- || $this->login->isAdmin()
- || $this->login->isStaff()
- ) {
- $go = true;
- }
- break;
- case 'groupmanager':
- if (
- $this->login->isSuperAdmin()
- || $this->login->isAdmin()
- || $this->login->isStaff()
- || $this->login->isGroupManager()
- ) {
- $go = true;
- }
- break;
- case 'member':
- if ($this->login->isLogged()) {
- $go = true;
- }
- break;
- default:
- throw new \RuntimeException(
- str_replace(
- '%acl',
- $acl,
- _T("Unknown ACL rule '%acl'!")
- )
- );
- }
- if (!$go) {
- Analog::log(
- 'Permission denied for route ' . $cur_route . ' for user ' . $this->login->login,
- Analog::DEBUG
- );
- $this->flash->addMessage(
- 'error_detected',
- _T("You do not have permission for requested URL.")
+ }
+
+ //check for ACLs
+ $routeContext = RouteContext::fromRequest($request);
+ $route = $routeContext->getRoute();
+ $cur_route = $route->getName();
+ $acl = $this->getAclFor($cur_route);
+
+ $go = false;
+ switch ($acl) {
+ case 'superadmin':
+ if ($this->login->isSuperAdmin()) {
+ $go = true;
+ }
+ break;
+ case 'admin':
+ if (
+ $this->login->isSuperAdmin()
+ || $this->login->isAdmin()
+ ) {
+ $go = true;
+ }
+ break;
+ case 'staff':
+ if (
+ $this->login->isSuperAdmin()
+ || $this->login->isAdmin()
+ || $this->login->isStaff()
+ ) {
+ $go = true;
+ }
+ break;
+ case 'groupmanager':
+ if (
+ $this->login->isSuperAdmin()
+ || $this->login->isAdmin()
+ || $this->login->isStaff()
+ || $this->login->isGroupManager()
+ ) {
+ $go = true;
+ }
+ break;
+ case 'member':
+ $go = true;
+ break;
+ default:
+ throw new \RuntimeException(
+ str_replace(
+ '%acl',
+ $acl,
+ _T("Unknown ACL rule '%acl'!")
+ )
);
- return $response
- ->withHeader('Location', $this->routeparser->urlFor('slash'))
- ->withStatus(302);
- }
+ }
+ if (!$go) {
+ Analog::log(
+ 'Permission denied for route ' . $cur_route . ' for user ' . $this->login->login,
+ Analog::DEBUG
+ );
+ $this->flash->addMessage(
+ 'error_detected',
+ _T("You do not have permission for requested URL.")
+ );
+ return $response
+ ->withHeader('Location', $this->routeparser->urlFor('slash'))
+ ->withStatus(302);
}
return $handler->handle($request);
);
if (
!$member->hasParent() ||
- $member->hasParent() && $member->parent->id != $this->login->id
+ $member->parent->id != $this->login->id
) {
Analog::log(
'Trying to display contributions for member #' . $member->id .
*/
private function buildWhereClause(Select $select)
{
+ /**
+ * @var Db $zdb
+ * @var Login $login
+ */
global $zdb, $login;
try {
);
switch ($this->filters->field_filter) {
case self::FILTER_NAME:
- if (TYPE_DB === 'pgsql') {
+ if ($zdb->isPostgres()) {
$sep = " || ' ' || ";
$pre = '';
$post = '';
* @param bool $count true if we want to count members
* (not applicable from static calls), defaults to false
*
- * @return string SELECT statement
+ * @return Select SELECT statement
*/
private function buildSelect($fields, $count = false)
{
$list = $ids;
}
- if (is_array($list)) {
+ if (count($list)) {
try {
if ($transaction) {
$this->zdb->connection->beginTransaction();
);
if (
!$member->hasParent() ||
- $member->hasParent() && $member->parent->id != $this->login->id
+ $member->parent->id != $this->login->id
) {
Analog::log(
'Trying to display transactions for member #' . $member->id .