commit
599f2fd264
@ -0,0 +1,91 @@
|
||||
image: php
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .composer
|
||||
|
||||
services:
|
||||
- mariadb:10.2
|
||||
|
||||
variables:
|
||||
MYSQL_DATABASE: engelsystem
|
||||
MYSQL_USER: engel
|
||||
MYSQL_PASSWORD: engelsystem
|
||||
MYSQL_HOST: mariadb
|
||||
COMPOSER_HOME: .composer
|
||||
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
|
||||
|
||||
before_script:
|
||||
# Fix permissions after gitlab messed them up
|
||||
- find . -type f -exec chmod 644 {} \;
|
||||
- find . -type d -exec chmod 755 {} \;
|
||||
# Install required Packages
|
||||
- apt update -yqq
|
||||
- apt install -yqq git unzip mariadb-client
|
||||
- docker-php-ext-install pdo pdo_mysql gettext
|
||||
# Install xdebug
|
||||
- pecl install xdebug
|
||||
- docker-php-ext-enable xdebug
|
||||
# MySQL DB
|
||||
- mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" < db/install.sql
|
||||
- mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" < db/update.sql
|
||||
# Install Composer
|
||||
- curl -sS https://getcomposer.org/installer | php -- --no-ansi --install-dir /usr/local/bin/ --filename composer
|
||||
- /usr/local/bin/composer --no-ansi install
|
||||
|
||||
.test_template: &test_definition
|
||||
artifacts:
|
||||
name: "${CI_JOB_NAME}_${CI_PROJECT_ID}_${PHP_VERSION}"
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- ./coverage/
|
||||
coverage: '/^\s*Lines:\s*(\d+(?:\.\d+)?%)/'
|
||||
script: vendor/bin/phpunit --colors=never --coverage-text --coverage-html ./coverage/
|
||||
|
||||
test:7.0:
|
||||
image: php:7.0
|
||||
<<: *test_definition
|
||||
|
||||
test:7.1:
|
||||
image: php:7.1
|
||||
<<: *test_definition
|
||||
|
||||
deploy_staging:
|
||||
stage: deploy
|
||||
only:
|
||||
- master
|
||||
script:
|
||||
- |-
|
||||
if [ -z "${SSH_PRIVATE_KEY}" ] || [ -z "${REMOTE}" ] || [ -z "${REMOTE_PATH}" ]; then
|
||||
echo "Skipping deployment";
|
||||
exit
|
||||
fi
|
||||
- mkdir -p ~/.ssh
|
||||
- echo "$SSH_PRIVATE_KEY" | sed -e 's/\r//g' > ~/.ssh/id_ed25519
|
||||
- chmod 600 ~/.ssh/id_ed25519
|
||||
- apt update && apt install -yqq rsync openssh-client
|
||||
- /usr/local/bin/composer --no-ansi install --no-dev
|
||||
- /usr/local/bin/composer --no-ansi dump-autoload --optimize
|
||||
- echo "syncing ${PWD}/ to ${REMOTE}:${REMOTE_PATH}/${CI_JOB_ID}-${CI_COMMIT_SHA}/"
|
||||
- |-
|
||||
rsync -vAax --exclude '.git*' --exclude .composer/ \
|
||||
-e "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" \
|
||||
./ "${REMOTE}:${REMOTE_PATH}/${CI_JOB_ID}-${CI_COMMIT_SHA}/"
|
||||
- |-
|
||||
ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${REMOTE}" "
|
||||
set -e
|
||||
|
||||
if [[ -f \"${REMOTE_PATH}/current/config/config.php\" ]]; then
|
||||
echo \"Config backup\"
|
||||
cp \"${REMOTE_PATH}/current/config/config.php\" config.php
|
||||
fi
|
||||
|
||||
echo \"Changing symlink\"
|
||||
unlink \"${REMOTE_PATH}/current\"
|
||||
ln -s \"${REMOTE_PATH}/${CI_JOB_ID}-${CI_COMMIT_SHA}\" \"${REMOTE_PATH}/current\"
|
||||
|
||||
if [[ -f config.php ]]; then
|
||||
echo \"Restoring config\"
|
||||
cp config.php \"${REMOTE_PATH}/current/config/config.php\"
|
||||
fi
|
||||
"
|
@ -1,6 +0,0 @@
|
||||
[submodule "vendor/parsedown"]
|
||||
path = vendor/parsedown
|
||||
url = https://github.com/erusev/parsedown.git
|
||||
[submodule "vendor/bootstrap"]
|
||||
path = themes/assets/bootstrap
|
||||
url = https://github.com/twbs/bootstrap.git
|
@ -1,25 +0,0 @@
|
||||
# Installation of Engelsystem
|
||||
|
||||
## Requirements:
|
||||
* PHP 5.4.x (cgi-fcgi)
|
||||
* MySQL-Server 5.5.x
|
||||
* Webserver, i.e. lighttpd, nginx, or Apache
|
||||
|
||||
## Directions:
|
||||
* Clone the master branch with the submodules: `git clone --recursive https://github.com/engelsystem/engelsystem.git`
|
||||
* Webserver must have write access to the 'import' directory and read access for all other directories
|
||||
* Webserver must be public.
|
||||
|
||||
* Recommended: Directory Listing should be disabled.
|
||||
* There must a be MySQL database created with a user who has full rights to that database.
|
||||
* It must be created by the db/install.sql and db/update.sql files.
|
||||
* If necessary, create a config/config.php to override values from config/config.default.php.
|
||||
* In the browser, login with credentials admin:asdfasdf and change the password.
|
||||
|
||||
Engelsystem can now be used.
|
||||
|
||||
## Session Settings:
|
||||
* Make sure the config allows for sessions.
|
||||
* Both Apache and Nginx allow for different VirtualHost configurations.
|
||||
|
||||
Report Bugs: https://github.com/engelsystem/engelsystem/issues
|
@ -1,28 +1,42 @@
|
||||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/20b3b0b4e93344a29da6bec77f329e7a)](https://www.codacy.com/app/engelsystem/engelsystem)
|
||||
[![GPL](https://img.shields.io/github/license/engelsystem/engelsystem.svg?maxAge=2592000)]()
|
||||
|
||||
# Installation eines frischen Engelsystems
|
||||
# Engelsystem
|
||||
|
||||
## Mindestvorrausetzungen (bzw. getestet unter):
|
||||
* PHP 5.4.x (cgi-fcgi)
|
||||
* MySQL-Server 5.5.x
|
||||
* Webserver mit PHP-Anbindung, z.B. lighttpd, nginx oder Apache
|
||||
Please visit https://engelsystem.de for a feature list.
|
||||
|
||||
## Vorgehen:
|
||||
* Klonen des `master` inkl. submodules in lokales Verzeichnis: `git clone --recursive https://github.com/engelsystem/engelsystem.git`
|
||||
* Der Webserver muss Schreibrechte auf das Verzeichnis `import` bekommen, für alle anderen Dateien reichen Leserechte.
|
||||
* Der Webserver muss auf `public` als http-root zeigen.
|
||||
## Installation
|
||||
|
||||
* Empfehlung: Dirlisting sollte deaktiviert sein.
|
||||
* Es muss eine MySQL-Datenbank angelegt werden und ein User existieren, der alle Rechte auf dieser Datenbank besitzt.
|
||||
* Es muss die db/install.sql und die db/update.sql importiert/ausgeführt werden.
|
||||
* Erstelle bei Bedarf eine config/config.php, die die Werte (z.B. DB-Zugang) aus der config/config.default.php überschreibt.
|
||||
* Engelsystem im Browser aufrufen, Anmeldung mit admin:asdfasdf vornehmen und Admin-Passwort ändern.
|
||||
### Requirements:
|
||||
* PHP >= 7.0.0
|
||||
* MySQL-Server >= 5.5.x
|
||||
* Webserver, i.e. lighttpd, nginx, or Apache
|
||||
|
||||
Das Engelsystem ist jetzt einsatzbereit.
|
||||
### Directions:
|
||||
* Clone the master branch: `git clone https://github.com/engelsystem/engelsystem.git`
|
||||
* Install [Composer](https://getcomposer.org/download/)
|
||||
* Install project dependencies: `composer install`
|
||||
* Webserver must have write access to the 'import' directory and read access for all other directories
|
||||
* Webserver must point to the public directory.
|
||||
|
||||
## Session Einstellungen:
|
||||
* Einstellungen für Cookies und Sessions bitte in der PHP Config des Servers vornehmen.
|
||||
* Sowohl Apache als auch nginx bieten Möglichkeiten für verschiedene Konfigurationen pro VirtualHost an
|
||||
* Recommended: Directory Listing should be disabled.
|
||||
* There must a be MySQL database created with a user who has full rights to that database.
|
||||
* It must be created by the db/install.sql and db/update.sql files.
|
||||
* If necessary, create a config/config.php to override values from config/config.default.php.
|
||||
* In the browser, login with credentials admin:asdfasdf and change the password.
|
||||
|
||||
Fehler bitte auf Github melden: https://github.com/engelsystem/engelsystem/issues
|
||||
Engelsystem can now be used.
|
||||
|
||||
### Session Settings:
|
||||
* Make sure the config allows for sessions.
|
||||
* Both Apache and Nginx allow for different VirtualHost configurations.
|
||||
|
||||
Report Bugs: https://github.com/engelsystem/engelsystem/issues
|
||||
|
||||
## Development
|
||||
Since the engelsystem is open source, you can help to improve the system. We really love to get pull requests containing fixes or implementations of our Github issues.
|
||||
|
||||
Please create single pull requests for every feature instead of creating one big monster of pull request containing a complete rewrite.
|
||||
|
||||
### Codestyle
|
||||
Please ensure that your pull requests follow [PSR-2](http://www.php-fig.org/psr/psr-2/) and [PSR-4](http://www.php-fig.org/psr/psr-4/).
|
||||
|
@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "engelsystem/engelsystem",
|
||||
"description": "Shift planning system for chaos events",
|
||||
"type": "project",
|
||||
"license": "GPL-2.0",
|
||||
"authors": [
|
||||
{
|
||||
"name": "msquare",
|
||||
"email": "msquare@notrademark.de"
|
||||
},
|
||||
{
|
||||
"name": "MyIgel",
|
||||
"email": "igor.scheller@igorshp.de"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.0.0",
|
||||
"erusev/parsedown": "^1.6",
|
||||
"illuminate/container": "5.5.*",
|
||||
"psr/container": "^1.0",
|
||||
"psr/log": "^1.0",
|
||||
"symfony/http-foundation": "^3.3",
|
||||
"twbs/bootstrap": "^3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"filp/whoops": "^2.1",
|
||||
"phpunit/phpunit": "^6.3",
|
||||
"symfony/var-dumper": "^3.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Engelsystem\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/helpers.php"
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
// Application config
|
||||
|
||||
return [
|
||||
// Service providers
|
||||
'providers' => [
|
||||
\Engelsystem\Logger\LoggerServiceProvider::class,
|
||||
\Engelsystem\Exceptions\ExceptionsServiceProvider::class,
|
||||
\Engelsystem\Config\ConfigServiceProvider::class,
|
||||
\Engelsystem\Routing\RoutingServiceProvider::class,
|
||||
\Engelsystem\Renderer\RendererServiceProvider::class,
|
||||
\Engelsystem\Database\DatabaseServiceProvider::class,
|
||||
\Engelsystem\Http\RequestServiceProvider::class,
|
||||
\Engelsystem\Http\SessionServiceProvider::class,
|
||||
],
|
||||
];
|
@ -0,0 +1,10 @@
|
||||
update User set Nick=concat('User',UID), Name=concat('Name',UID), Vorname=concat('Prename',UID), `Alter`=0, Telefon='', DECT='', Handy='', email=concat('engel', UID, '@engelsystem.de'), jabber='', Hometown='';
|
||||
update Messages set Text=concat('Message', id);
|
||||
update News set Betreff=concat('Subject', ID), Text=concat('News', ID);
|
||||
update NewsComments set Text=concat('Comment', ID);
|
||||
update Questions set Question=concat('Question', QID), Answer=concat('Answer', QID);
|
||||
update ShiftEntry set Comment='', freeload_comment='';
|
||||
update ShiftTypes set name=concat('Shifttype',id), description='Description';
|
||||
update AngelTypes set name=concat('Angeltype',id), description=concat('Description of angeltype',id);
|
||||
TRUNCATE TABLE LogEntries;
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
// Check for autoloader
|
||||
if (!is_readable(__DIR__ . '/../vendor/autoload.php')) {
|
||||
die('Please run composer.phar install');
|
||||
}
|
||||
|
||||
// Include composer autoloader
|
||||
$loader = require __DIR__ . '/../vendor/autoload.php';
|
@ -1,103 +1,129 @@
|
||||
<?php
|
||||
|
||||
function event_config_title() {
|
||||
return _("Event config");
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function event_config_title()
|
||||
{
|
||||
return _('Event config');
|
||||
}
|
||||
|
||||
function event_config_edit_controller() {
|
||||
global $privileges;
|
||||
|
||||
if (! in_array('admin_event_config', $privileges)) {
|
||||
redirect('?');
|
||||
}
|
||||
|
||||
$event_name = null;
|
||||
$event_welcome_msg = null;
|
||||
$buildup_start_date = null;
|
||||
$event_start_date = null;
|
||||
$event_end_date = null;
|
||||
$teardown_end_date = null;
|
||||
|
||||
$event_config = EventConfig();
|
||||
if ($event_config != null) {
|
||||
$event_name = $event_config['event_name'];
|
||||
$buildup_start_date = $event_config['buildup_start_date'];
|
||||
$event_start_date = $event_config['event_start_date'];
|
||||
$event_end_date = $event_config['event_end_date'];
|
||||
$teardown_end_date = $event_config['teardown_end_date'];
|
||||
$event_welcome_msg = $event_config['event_welcome_msg'];
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['event_name'])) {
|
||||
$event_name = strip_request_item('event_name');
|
||||
}
|
||||
if ($event_name == '') {
|
||||
$event_name = null;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['event_welcome_msg'])) {
|
||||
$event_welcome_msg = strip_request_item_nl('event_welcome_msg');
|
||||
}
|
||||
if ($event_welcome_msg == '') {
|
||||
$event_welcome_msg = null;
|
||||
}
|
||||
|
||||
$result = check_request_date('buildup_start_date', _("Please enter buildup start date."), true);
|
||||
$buildup_start_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
|
||||
$result = check_request_date('event_start_date', _("Please enter event start date."), true);
|
||||
$event_start_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
|
||||
$result = check_request_date('event_end_date', _("Please enter event end date."), true);
|
||||
$event_end_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
|
||||
$result = check_request_date('teardown_end_date', _("Please enter teardown end date."), true);
|
||||
$teardown_end_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
|
||||
if ($buildup_start_date != null && $event_start_date != null && $buildup_start_date > $event_start_date) {
|
||||
$valid = false;
|
||||
error(_("The buildup start date has to be before the event start date."));
|
||||
}
|
||||
|
||||
if ($event_start_date != null && $event_end_date != null && $event_start_date > $event_end_date) {
|
||||
$valid = false;
|
||||
error(_("The event start date has to be before the event end date."));
|
||||
}
|
||||
|
||||
if ($event_end_date != null && $teardown_end_date != null && $event_end_date > $teardown_end_date) {
|
||||
$valid = false;
|
||||
error(_("The event end date has to be before the teardown end date."));
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function event_config_edit_controller()
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
if (!in_array('admin_event_config', $privileges)) {
|
||||
redirect(page_link_to('/'));
|
||||
}
|
||||
|
||||
if ($buildup_start_date != null && $teardown_end_date != null && $buildup_start_date > $teardown_end_date) {
|
||||
$valid = false;
|
||||
error(_("The buildup start date has to be before the teardown end date."));
|
||||
|
||||
$request = request();
|
||||
$event_name = null;
|
||||
$event_welcome_msg = null;
|
||||
$buildup_start_date = null;
|
||||
$event_start_date = null;
|
||||
$event_end_date = null;
|
||||
$teardown_end_date = null;
|
||||
|
||||
$event_config = EventConfig();
|
||||
if ($event_config != null) {
|
||||
$event_name = $event_config['event_name'];
|
||||
$buildup_start_date = $event_config['buildup_start_date'];
|
||||
$event_start_date = $event_config['event_start_date'];
|
||||
$event_end_date = $event_config['event_end_date'];
|
||||
$teardown_end_date = $event_config['teardown_end_date'];
|
||||
$event_welcome_msg = $event_config['event_welcome_msg'];
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$result = EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg);
|
||||
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to update event config.");
|
||||
}
|
||||
|
||||
engelsystem_log("Changed event config: $event_name, $event_welcome_msg, " . date("Y-m-d", $buildup_start_date) . ", " . date("Y-m-d", $event_start_date) . ", " . date("Y-m-d", $event_end_date) . ", " . date("Y-m-d", $teardown_end_date));
|
||||
success(_("Settings saved."));
|
||||
redirect(page_link_to('admin_event_config'));
|
||||
|
||||
if ($request->has('submit')) {
|
||||
$valid = true;
|
||||
|
||||
if ($request->has('event_name')) {
|
||||
$event_name = strip_request_item('event_name');
|
||||
}
|
||||
if ($event_name == '') {
|
||||
$event_name = null;
|
||||
}
|
||||
|
||||
if ($request->has('event_welcome_msg')) {
|
||||
$event_welcome_msg = strip_request_item_nl('event_welcome_msg');
|
||||
}
|
||||
if ($event_welcome_msg == '') {
|
||||
$event_welcome_msg = null;
|
||||
}
|
||||
|
||||
$result = check_request_date('buildup_start_date', _('Please enter buildup start date.'), true);
|
||||
$buildup_start_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
|
||||
$result = check_request_date('event_start_date', _('Please enter event start date.'), true);
|
||||
$event_start_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
|
||||
$result = check_request_date('event_end_date', _('Please enter event end date.'), true);
|
||||
$event_end_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
|
||||
$result = check_request_date('teardown_end_date', _('Please enter teardown end date.'), true);
|
||||
$teardown_end_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
|
||||
if ($buildup_start_date != null && $event_start_date != null && $buildup_start_date > $event_start_date) {
|
||||
$valid = false;
|
||||
error(_('The buildup start date has to be before the event start date.'));
|
||||
}
|
||||
|
||||
if ($event_start_date != null && $event_end_date != null && $event_start_date > $event_end_date) {
|
||||
$valid = false;
|
||||
error(_('The event start date has to be before the event end date.'));
|
||||
}
|
||||
|
||||
if ($event_end_date != null && $teardown_end_date != null && $event_end_date > $teardown_end_date) {
|
||||
$valid = false;
|
||||
error(_('The event end date has to be before the teardown end date.'));
|
||||
}
|
||||
|
||||
if ($buildup_start_date != null && $teardown_end_date != null && $buildup_start_date > $teardown_end_date) {
|
||||
$valid = false;
|
||||
error(_('The buildup start date has to be before the teardown end date.'));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
EventConfig_update(
|
||||
$event_name,
|
||||
$buildup_start_date,
|
||||
$event_start_date,
|
||||
$event_end_date,
|
||||
$teardown_end_date,
|
||||
$event_welcome_msg
|
||||
);
|
||||
|
||||
engelsystem_log(
|
||||
sprintf('Changed event config: %s, %s, %s, %s, %s, %s',
|
||||
$event_name,
|
||||
$event_welcome_msg,
|
||||
date('Y-m-d', $buildup_start_date),
|
||||
date('Y-m-d', $event_start_date),
|
||||
date('Y-m-d', $event_end_date),
|
||||
date('Y-m-d', $teardown_end_date)
|
||||
)
|
||||
);
|
||||
success(_('Settings saved.'));
|
||||
redirect(page_link_to('admin_event_config'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
event_config_title(),
|
||||
EventConfig_edit_view($event_name, $event_welcome_msg, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date)
|
||||
];
|
||||
}
|
||||
|
||||
?>
|
||||
return [
|
||||
event_config_title(),
|
||||
EventConfig_edit_view(
|
||||
$event_name,
|
||||
$event_welcome_msg,
|
||||
$buildup_start_date,
|
||||
$event_start_date,
|
||||
$event_end_date,
|
||||
$teardown_end_date
|
||||
)
|
||||
];
|
||||
}
|
||||
|
@ -1,187 +1,290 @@
|
||||
<?php
|
||||
|
||||
use Engelsystem\Database\DB;
|
||||
|
||||
/**
|
||||
* Sign up for a shift.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function shift_entry_add_controller() {
|
||||
global $privileges, $user;
|
||||
|
||||
if (isset($_REQUEST['shift_id']) && preg_match("/^[0-9]*$/", $_REQUEST['shift_id'])) {
|
||||
$shift_id = $_REQUEST['shift_id'];
|
||||
} else {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
// Locations laden
|
||||
$rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
|
||||
$room_array = [];
|
||||
foreach ($rooms as $room) {
|
||||
$room_array[$room['RID']] = $room['Name'];
|
||||
}
|
||||
|
||||
$shift = Shift($shift_id);
|
||||
$shift['Name'] = $room_array[$shift['RID']];
|
||||
if ($shift == null) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['type_id']) && preg_match("/^[0-9]*$/", $_REQUEST['type_id'])) {
|
||||
$type_id = $_REQUEST['type_id'];
|
||||
} else {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
|
||||
$type = AngelType($type_id);
|
||||
} else {
|
||||
$type = sql_select("SELECT * FROM `UserAngelTypes` JOIN `AngelTypes` ON (`UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`) WHERE `AngelTypes`.`id` = '" . sql_escape($type_id) . "' AND (`AngelTypes`.`restricted` = 0 OR (`UserAngelTypes`.`user_id` = '" . sql_escape($user['UID']) . "' AND NOT `UserAngelTypes`.`confirm_user_id` IS NULL))");
|
||||
$type = $type[0];
|
||||
}
|
||||
|
||||
if ($type == null) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['user_id']) && preg_match("/^[0-9]*$/", $_REQUEST['user_id']) && (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges))) {
|
||||
$user_id = $_REQUEST['user_id'];
|
||||
} else {
|
||||
$user_id = $user['UID'];
|
||||
}
|
||||
|
||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $type);
|
||||
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $type['id']);
|
||||
|
||||
$shift_signup_allowed = Shift_signup_allowed(User($user_id), $shift, $type, null, null, $needed_angeltype, $shift_entries);
|
||||
if (! $shift_signup_allowed->isSignupAllowed()) {
|
||||
error(_("You are not allowed to sign up for this shift. Maybe shift is full or already running."));
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$selected_type_id = $type_id;
|
||||
if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
|
||||
|
||||
if (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1") == 0) {
|
||||
function shift_entry_add_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
|
||||
$request = request();
|
||||
$shift_id = 0;
|
||||
if ($request->has('shift_id') && preg_match('/^\d+$/', $request->input('shift_id'))) {
|
||||
$shift_id = $request->input('shift_id');
|
||||
} else {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['angeltype_id']) && test_request_int('angeltype_id') && sql_num_query("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($_REQUEST['angeltype_id']) . "' LIMIT 1") > 0) {
|
||||
$selected_type_id = $_REQUEST['angeltype_id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `UID` = '" . sql_escape($user_id) . "'")) {
|
||||
return error("This angel does already have an entry for this shift.", true);
|
||||
|
||||
// Locations laden
|
||||
$rooms = Rooms();
|
||||
$room_array = [];
|
||||
foreach ($rooms as $room) {
|
||||
$room_array[$room['RID']] = $room['Name'];
|
||||
}
|
||||
|
||||
$freeloaded = $shift['freeloaded'];
|
||||
$freeload_comment = $shift['freeload_comment'];
|
||||
if (in_array("user_shifts_admin", $privileges)) {
|
||||
$freeloaded = isset($_REQUEST['freeloaded']);
|
||||
$freeload_comment = strip_request_item_nl('freeload_comment');
|
||||
|
||||
$shift = Shift($shift_id);
|
||||
if ($shift == null) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$shift['Name'] = $room_array[$shift['RID']];
|
||||
|
||||
$type_id = null;
|
||||
if ($request->has('type_id') && preg_match('/^\d+$/', $request->input('type_id'))) {
|
||||
$type_id = $request->input('type_id');
|
||||
}
|
||||
|
||||
$comment = strip_request_item_nl('comment');
|
||||
$result = ShiftEntry_create([
|
||||
'SID' => $shift_id,
|
||||
'TID' => $selected_type_id,
|
||||
'UID' => $user_id,
|
||||
'Comment' => $comment,
|
||||
'freeloaded' => $freeloaded,
|
||||
'freeload_comment' => $freeload_comment
|
||||
]);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to create shift entry.');
|
||||
|
||||
if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
|
||||
if($type_id == null) {
|
||||
// If no angeltype id is given, then select first existing angeltype.
|
||||
$needed_angeltypes = NeededAngelTypes_by_shift($shift_id);
|
||||
if(count($needed_angeltypes) > 0) {
|
||||
$type_id = $needed_angeltypes[0]['id'];
|
||||
}
|
||||
}
|
||||
$type = AngelType($type_id);
|
||||
} else {
|
||||
// TODO: Move queries to model
|
||||
$type = DB::selectOne('
|
||||
SELECT *
|
||||
FROM `UserAngelTypes`
|
||||
JOIN `AngelTypes` ON (`UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`)
|
||||
WHERE `AngelTypes`.`id` = ?
|
||||
AND (
|
||||
`AngelTypes`.`restricted` = 0
|
||||
OR (
|
||||
`UserAngelTypes`.`user_id` = ?
|
||||
AND NOT `UserAngelTypes`.`confirm_user_id` IS NULL
|
||||
)
|
||||
)
|
||||
', [$type_id, $user['UID']]);
|
||||
}
|
||||
|
||||
if ($type['restricted'] == 0 && sql_num_query("SELECT * FROM `UserAngelTypes` INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id` WHERE `angeltype_id` = '" . sql_escape($selected_type_id) . "' AND `user_id` = '" . sql_escape($user_id) . "'") == 0) {
|
||||
sql_query("INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`) VALUES ('" . sql_escape($user_id) . "', '" . sql_escape($selected_type_id) . "')");
|
||||
|
||||
if (empty($type)) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
$user_source = User($user_id);
|
||||
engelsystem_log("User " . User_Nick_render($user_source) . " signed up for shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
|
||||
success(_("You are subscribed. Thank you!") . ' <a href="' . page_link_to('user_myshifts') . '">' . _("My shifts") . ' »</a>');
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
$users = sql_select("SELECT *, (SELECT count(*) FROM `ShiftEntry` WHERE `freeloaded`=1 AND `ShiftEntry`.`UID`=`User`.`UID`) AS `freeloaded` FROM `User` ORDER BY `Nick`");
|
||||
$users_select = [];
|
||||
foreach ($users as $usr) {
|
||||
$users_select[$usr['UID']] = $usr['Nick'] . ($usr['freeloaded'] == 0 ? "" : " (" . _("Freeloader") . ")");
|
||||
|
||||
if (
|
||||
$request->has('user_id')
|
||||
&& preg_match('/^\d+$/', $request->input('user_id'))
|
||||
&& (
|
||||
in_array('user_shifts_admin', $privileges)
|
||||
|| in_array('shiftentry_edit_angeltype_supporter', $privileges)
|
||||
)
|
||||
) {
|
||||
$user_id = $request->input('user_id');
|
||||
} else {
|
||||
$user_id = $user['UID'];
|
||||
}
|
||||
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
|
||||
|
||||
$angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
|
||||
$angeltypes = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype['name'];
|
||||
|
||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $type);
|
||||
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $type['id']);
|
||||
|
||||
$shift_signup_allowed = Shift_signup_allowed(
|
||||
User($user_id),
|
||||
$shift,
|
||||
$type,
|
||||
null,
|
||||
null,
|
||||
$needed_angeltype,
|
||||
$shift_entries
|
||||
);
|
||||
if (!$shift_signup_allowed->isSignupAllowed()) {
|
||||
error(_('You are not allowed to sign up for this shift. Maybe shift is full or already running.'));
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
$angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
|
||||
} elseif (in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
|
||||
$users = Users_by_angeltype($type);
|
||||
$users_select = [];
|
||||
foreach ($users as $usr) {
|
||||
if (! $type['restricted'] || $usr['confirm_user_id'] != null) {
|
||||
$users_select[$usr['UID']] = $usr['Nick'];
|
||||
}
|
||||
|
||||
if ($request->has('submit')) {
|
||||
$selected_type_id = $type_id;
|
||||
if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter',
|
||||
$privileges)
|
||||
) {
|
||||
|
||||
if (count(DB::select('SELECT `UID` FROM `User` WHERE `UID`=? LIMIT 1', [$user_id])) == 0) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (
|
||||
$request->has('angeltype_id')
|
||||
&& test_request_int('angeltype_id')
|
||||
&& count(DB::select(
|
||||
'SELECT `id` FROM `AngelTypes` WHERE `id`=? LIMIT 1',
|
||||
[$request->input('angeltype_id')]
|
||||
)) > 0
|
||||
) {
|
||||
$selected_type_id = $request->input('angeltype_id');
|
||||
}
|
||||
}
|
||||
|
||||
if (count(DB::select(
|
||||
'SELECT `id` FROM `ShiftEntry` WHERE `SID`= ? AND `UID` = ?',
|
||||
[$shift['SID'], $user_id]))
|
||||
) {
|
||||
return error('This angel does already have an entry for this shift.', true);
|
||||
}
|
||||
|
||||
$freeloaded = isset($shift['freeloaded']) ? $shift['freeloaded'] : false;
|
||||
$freeload_comment = isset($shift['freeload_comment']) ? $shift['freeload_comment'] : '';
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
$freeloaded = $request->has('freeloaded');
|
||||
$freeload_comment = strip_request_item_nl('freeload_comment');
|
||||
}
|
||||
|
||||
$comment = strip_request_item_nl('comment');
|
||||
ShiftEntry_create([
|
||||
'SID' => $shift_id,
|
||||
'TID' => $selected_type_id,
|
||||
'UID' => $user_id,
|
||||
'Comment' => $comment,
|
||||
'freeloaded' => $freeloaded,
|
||||
'freeload_comment' => $freeload_comment
|
||||
]);
|
||||
|
||||
if (
|
||||
$type['restricted'] == 0
|
||||
&& count(DB::select('
|
||||
SELECT `UserAngelTypes`.`id` FROM `UserAngelTypes`
|
||||
INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id`
|
||||
WHERE `angeltype_id` = ?
|
||||
AND `user_id` = ?
|
||||
', [$selected_type_id, $user_id])) == 0
|
||||
) {
|
||||
DB::insert(
|
||||
'INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`) VALUES (?, ?)',
|
||||
[$user_id, $selected_type_id]
|
||||
);
|
||||
}
|
||||
|
||||
$user_source = User($user_id);
|
||||
engelsystem_log(
|
||||
'User ' . User_Nick_render($user_source)
|
||||
. ' signed up for shift ' . $shift['name']
|
||||
. ' from ' . date('Y-m-d H:i', $shift['start'])
|
||||
. ' to ' . date('Y-m-d H:i', $shift['end'])
|
||||
);
|
||||
success(_('You are subscribed. Thank you!') . ' <a href="' . page_link_to('user_myshifts') . '">' . _('My shifts') . ' »</a>');
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
|
||||
|
||||
$angeltypes_source = User_angeltypes($user);
|
||||
$angeltypes = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
if ($angeltype['supporter']) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
$angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
|
||||
|
||||
$angeltype_select = '';
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
$users = DB::select('
|
||||
SELECT *,
|
||||
(
|
||||
SELECT count(*)
|
||||
FROM `ShiftEntry`
|
||||
WHERE `freeloaded`=1
|
||||
AND `ShiftEntry`.`UID`=`User`.`UID`
|
||||
) AS `freeloaded`
|
||||
FROM `User`
|
||||
ORDER BY `Nick`
|
||||
');
|
||||
$users_select = [];
|
||||
foreach ($users as $usr) {
|
||||
$users_select[$usr['UID']] = $usr['Nick'] . ($usr['freeloaded'] == 0 ? '' : ' (' . _('Freeloader') . ')');
|
||||
}
|
||||
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
|
||||
|
||||
$angeltypes_source = DB::select('SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`');
|
||||
$angeltypes = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
$angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
|
||||
} elseif (in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
|
||||
$users = Users_by_angeltype($type);
|
||||
$users_select = [];
|
||||
foreach ($users as $usr) {
|
||||
if (!$type['restricted'] || $usr['confirm_user_id'] != null) {
|
||||
$users_select[$usr['UID']] = $usr['Nick'];
|
||||
}
|
||||
}
|
||||
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
|
||||
|
||||
$angeltypes_source = User_angeltypes($user);
|
||||
$angeltypes = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
if ($angeltype['supporter']) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
$angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
|
||||
}
|
||||
} else {
|
||||
$user_text = User_Nick_render($user);
|
||||
$angeltype_select = $type['name'];
|
||||
}
|
||||
} else {
|
||||
$user_text = User_Nick_render($user);
|
||||
$angeltype_select = $type['name'];
|
||||
}
|
||||
|
||||
return ShiftEntry_edit_view($user_text, date("Y-m-d H:i", $shift['start']) . ' – ' . date('Y-m-d H:i', $shift['end']) . ' (' . shift_length($shift) . ')', $shift['Name'], $shift['name'], $angeltype_select, "", false, null, in_array('user_shifts_admin', $privileges));
|
||||
|
||||
return ShiftEntry_edit_view(
|
||||
$user_text,
|
||||
date('Y-m-d H:i', $shift['start'])
|
||||
. ' – '
|
||||
. date('Y-m-d H:i', $shift['end'])
|
||||
. ' (' . shift_length($shift) . ')',
|
||||
$shift['Name'],
|
||||
$shift['name'],
|
||||
$angeltype_select, '',
|
||||
false,
|
||||
null,
|
||||
in_array('user_shifts_admin', $privileges)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove somebody from a shift.
|
||||
*/
|
||||
function shift_entry_delete_controller() {
|
||||
global $privileges, $user;
|
||||
|
||||
if (! isset($_REQUEST['entry_id']) || ! test_request_int('entry_id')) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$entry_id = $_REQUEST['entry_id'];
|
||||
|
||||
$shift_entry_source = sql_select("
|
||||
SELECT `User`.`Nick`, `ShiftEntry`.`Comment`, `ShiftEntry`.`UID`, `ShiftTypes`.`name`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`name` as `angel_type`, `AngelTypes`.`id` as `angeltype_id`
|
||||
function shift_entry_delete_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
$request = request();
|
||||
|
||||
if (!$request->has('entry_id') || !test_request_int('entry_id')) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$entry_id = $request->input('entry_id');
|
||||
|
||||
$shift_entry_source = DB::selectOne('
|
||||
SELECT
|
||||
`User`.`Nick`,
|
||||
`User`.`Gekommen`,
|
||||
`ShiftEntry`.`Comment`,
|
||||
`ShiftEntry`.`UID`,
|
||||
`ShiftTypes`.`name`,
|
||||
`Shifts`.*,
|
||||
`Room`.`Name`,
|
||||
`AngelTypes`.`name` AS `angel_type`,
|
||||
`AngelTypes`.`id` AS `angeltype_id`
|
||||
FROM `ShiftEntry`
|
||||
JOIN `User` ON (`User`.`UID`=`ShiftEntry`.`UID`)
|
||||
JOIN `AngelTypes` ON (`ShiftEntry`.`TID` = `AngelTypes`.`id`)
|
||||
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
|
||||
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
|
||||
JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
|
||||
WHERE `ShiftEntry`.`id`='" . sql_escape($entry_id) . "'");
|
||||
if (count($shift_entry_source) > 0) {
|
||||
$shift_entry_source = $shift_entry_source[0];
|
||||
|
||||
if (!in_array('user_shifts_admin', $privileges) && (!in_array('shiftentry_edit_angeltype_supporter', $privileges) || !User_is_AngelType_supporter($user, AngelType($shift_entry_source['angeltype_id'])))) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
$result = ShiftEntry_delete($entry_id);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shift entry.');
|
||||
WHERE `ShiftEntry`.`id`=?',
|
||||
[$entry_id]
|
||||
);
|
||||
if (!empty($shift_entry_source)) {
|
||||
if (!in_array('user_shifts_admin', $privileges) && (!in_array('shiftentry_edit_angeltype_supporter',
|
||||
$privileges) || !User_is_AngelType_supporter($user, AngelType($shift_entry_source['angeltype_id'])))
|
||||
) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
ShiftEntry_delete($entry_id);
|
||||
|
||||
engelsystem_log(
|
||||
'Deleted ' . User_Nick_render($shift_entry_source) . '\'s shift: ' . $shift_entry_source['name']
|
||||
. ' at ' . $shift_entry_source['Name']
|
||||
. ' from ' . date('Y-m-d H:i', $shift_entry_source['start'])
|
||||
. ' to ' . date('Y-m-d H:i', $shift_entry_source['end'])
|
||||
. ' as ' . $shift_entry_source['angel_type']
|
||||
);
|
||||
success(_('Shift entry deleted.'));
|
||||
} else {
|
||||
error(_('Entry not found.'));
|
||||
}
|
||||
|
||||
engelsystem_log("Deleted " . User_Nick_render($shift_entry_source) . "'s shift: " . $shift_entry_source['name'] . " at " . $shift_entry_source['Name'] . " from " . date("Y-m-d H:i", $shift_entry_source['start']) . " to " . date("Y-m-d H:i", $shift_entry_source['end']) . " as " . $shift_entry_source['angel_type']);
|
||||
success(_("Shift entry deleted."));
|
||||
} else {
|
||||
error(_("Entry not found."));
|
||||
}
|
||||
redirect(shift_link($shift_entry_source));
|
||||
}
|
||||
|
||||
?>
|
||||
redirect(shift_link($shift_entry_source));
|
||||
}
|
||||
|
@ -1,324 +1,405 @@
|
||||
<?php
|
||||
|
||||
use Engelsystem\ShiftSignupState;
|
||||
|
||||
function shift_link($shift) {
|
||||
return page_link_to('shifts') . '&action=view&shift_id=' . $shift['SID'];
|
||||
/**
|
||||
* @param array $shift
|
||||
* @return string
|
||||
*/
|
||||
function shift_link($shift)
|
||||
{
|
||||
$parameters = ['action' => 'view'];
|
||||
if (isset($shift['SID'])) {
|
||||
$parameters['shift_id'] = $shift['SID'];
|
||||
}
|
||||
|
||||
$link = page_link_to('shifts', $parameters);
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
function shift_delete_link($shift) {
|
||||
return page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'];
|
||||
/**
|
||||
* @param array $shift
|
||||
* @return string
|
||||
*/
|
||||
function shift_delete_link($shift)
|
||||
{
|
||||
return page_link_to('user_shifts', ['delete_shift' => $shift['SID']]);
|
||||
}
|
||||
|
||||
function shift_edit_link($shift) {
|
||||
return page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'];
|
||||
/**
|
||||
* @param array $shift
|
||||
* @return string
|
||||
*/
|
||||
function shift_edit_link($shift)
|
||||
{
|
||||
return page_link_to('user_shifts', ['edit_shift' => $shift['SID']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a single shift.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function shift_edit_controller() {
|
||||
global $privileges;
|
||||
|
||||
// Schicht bearbeiten
|
||||
$msg = "";
|
||||
$valid = true;
|
||||
|
||||
if (! in_array('admin_shifts', $privileges)) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (! isset($_REQUEST['edit_shift']) || ! test_request_int('edit_shift')) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$shift_id = $_REQUEST['edit_shift'];
|
||||
|
||||
$shift = Shift($shift_id);
|
||||
|
||||
$room = select_array(Rooms(), 'RID', 'Name');
|
||||
$angeltypes = select_array(AngelTypes(), 'id', 'name');
|
||||
$shifttypes = select_array(ShiftTypes(), 'id', 'name');
|
||||
|
||||
$needed_angel_types = select_array(NeededAngelTypes_by_shift($shift_id), 'id', 'count');
|
||||
foreach (array_keys($angeltypes) as $angeltype_id) {
|
||||
if (! isset($needed_angel_types[$angeltype_id])) {
|
||||
$needed_angel_types[$angeltype_id] = 0;
|
||||
function shift_edit_controller()
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
// Schicht bearbeiten
|
||||
$msg = '';
|
||||
$valid = true;
|
||||
$request = request();
|
||||
|
||||
if (!in_array('admin_shifts', $privileges)) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (!$request->has('edit_shift') || !test_request_int('edit_shift')) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
}
|
||||
|
||||
$shifttype_id = $shift['shifttype_id'];
|
||||
$title = $shift['title'];
|
||||
$rid = $shift['RID'];
|
||||
$start = $shift['start'];
|
||||
$end = $shift['end'];
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
// Name/Bezeichnung der Schicht, darf leer sein
|
||||
$title = strip_request_item('title');
|
||||
|
||||
// Auswahl der sichtbaren Locations für die Schichten
|
||||
if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room[$_REQUEST['rid']])) {
|
||||
$rid = $_REQUEST['rid'];
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please select a room."), true);
|
||||
$shift_id = $request->input('edit_shift');
|
||||
|
||||
$shift = Shift($shift_id);
|
||||
|
||||
$room = select_array(Rooms(), 'RID', 'Name');
|
||||
$angeltypes = select_array(AngelTypes(), 'id', 'name');
|
||||
$shifttypes = select_array(ShiftTypes(), 'id', 'name');
|
||||
|
||||
$needed_angel_types = select_array(NeededAngelTypes_by_shift($shift_id), 'angel_type_id', 'count');
|
||||
foreach (array_keys($angeltypes) as $angeltype_id) {
|
||||
if (!isset($needed_angel_types[$angeltype_id])) {
|
||||
$needed_angel_types[$angeltype_id] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
|
||||
$shifttype_id = $_REQUEST['shifttype_id'];
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_('Please select a shifttype.'), true);
|
||||
|
||||
$shifttype_id = $shift['shifttype_id'];
|
||||
$title = $shift['title'];
|
||||
$rid = $shift['RID'];
|
||||
$start = $shift['start'];
|
||||
$end = $shift['end'];
|
||||
|
||||
if ($request->has('submit')) {
|
||||
// Name/Bezeichnung der Schicht, darf leer sein
|
||||
$title = strip_request_item('title');
|
||||
|
||||
// Auswahl der sichtbaren Locations für die Schichten
|
||||
if (
|
||||
$request->has('rid')
|
||||
&& preg_match('/^\d+$/', $request->input('rid'))
|
||||
&& isset($room[$request->input('rid')])
|
||||
) {
|
||||
$rid = $request->input('rid');
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_('Please select a room.'), true);
|
||||
}
|
||||
|
||||
if ($request->has('shifttype_id') && isset($shifttypes[$request->input('shifttype_id')])) {
|
||||
$shifttype_id = $request->input('shifttype_id');
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_('Please select a shifttype.'), true);
|
||||
}
|
||||
|
||||
if ($request->has('start') && $tmp = parse_date('Y-m-d H:i', $request->input('start'))) {
|
||||
$start = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_('Please enter a valid starting time for the shifts.'), true);
|
||||
}
|
||||
|
||||
if ($request->has('end') && $tmp = parse_date('Y-m-d H:i', $request->input('end'))) {
|
||||
$end = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_('Please enter a valid ending time for the shifts.'), true);
|
||||
}
|
||||
|
||||
if ($start >= $end) {
|
||||
$valid = false;
|
||||
$msg .= error(_('The ending time has to be after the starting time.'), true);
|
||||
}
|
||||
|
||||
foreach ($needed_angel_types as $needed_angeltype_id => $count) {
|
||||
$needed_angel_types[$needed_angeltype_id] = 0;
|
||||
|
||||
$queryKey = 'type_' . $needed_angeltype_id;
|
||||
if ($request->has($queryKey)) {
|
||||
if (test_request_int($queryKey)) {
|
||||
$needed_angel_types[$needed_angeltype_id] = trim($request->input($queryKey));
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(
|
||||
_('Please check your input for needed angels of type %s.'),
|
||||
$angeltypes[$needed_angeltype_id]
|
||||
), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$shift['shifttype_id'] = $shifttype_id;
|
||||
$shift['title'] = $title;
|
||||
$shift['RID'] = $rid;
|
||||
$shift['start'] = $start;
|
||||
$shift['end'] = $end;
|
||||
|
||||
Shift_update($shift);
|
||||
NeededAngelTypes_delete_by_shift($shift_id);
|
||||
$needed_angel_types_info = [];
|
||||
foreach ($needed_angel_types as $type_id => $count) {
|
||||
NeededAngelType_add($shift_id, $type_id, null, $count);
|
||||
$needed_angel_types_info[] = $angeltypes[$type_id] . ': ' . $count;
|
||||
}
|
||||
|
||||
engelsystem_log(
|
||||
'Updated shift \'' . $shifttypes[$shifttype_id] . ', ' . $title
|
||||
. '\' from ' . date('Y-m-d H:i', $start)
|
||||
. ' to ' . date('Y-m-d H:i', $end)
|
||||
. ' with angel types ' . join(', ', $needed_angel_types_info)
|
||||
);
|
||||
success(_('Shift updated.'));
|
||||
|
||||
redirect(shift_link([
|
||||
'SID' => $shift_id
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
|
||||
$start = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter a valid starting time for the shifts."), true);
|
||||
|
||||
$angel_types_spinner = '';
|
||||
foreach ($angeltypes as $angeltype_id => $angeltype_name) {
|
||||
$angel_types_spinner .= form_spinner('type_' . $angeltype_id, $angeltype_name,
|
||||
$needed_angel_types[$angeltype_id]);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
|
||||
$end = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter a valid ending time for the shifts."), true);
|
||||
|
||||
return page_with_title(
|
||||
shifts_title(),
|
||||
[
|
||||
msg(),
|
||||
'<noscript>' . info(_('This page is much more comfortable with javascript.'), true) . '</noscript>',
|
||||
form([
|
||||
form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id),
|
||||
form_text('title', _('Title'), $title),
|
||||
form_select('rid', _('Room:'), $room, $rid),
|
||||
form_text('start', _('Start:'), date('Y-m-d H:i', $start)),
|
||||
form_text('end', _('End:'), date('Y-m-d H:i', $end)),
|
||||
'<h2>' . _('Needed angels') . '</h2>',
|
||||
$angel_types_spinner,
|
||||
form_submit('submit', _('Save'))
|
||||
])
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function shift_delete_controller()
|
||||
{
|
||||
global $privileges;
|
||||
$request = request();
|
||||
|
||||
if (!in_array('user_shifts_admin', $privileges)) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if ($start >= $end) {
|
||||
$valid = false;
|
||||
$msg .= error(_("The ending time has to be after the starting time."), true);
|
||||
|
||||
// Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg)
|
||||
if (!$request->has('delete_shift') || !preg_match('/^\d+$/', $request->input('delete_shift'))) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
foreach ($needed_angel_types as $needed_angeltype_id => $needed_angeltype_name) {
|
||||
if (isset($_REQUEST['type_' . $needed_angeltype_id]) && test_request_int('type_' . $needed_angeltype_id)) {
|
||||
$needed_angel_types[$needed_angeltype_id] = trim($_REQUEST['type_' . $needed_angeltype_id]);
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Please check your input for needed angels of type %s."), $needed_angeltype_name), true);
|
||||
}
|
||||
$shift_id = $request->input('delete_shift');
|
||||
|
||||
$shift = Shift($shift_id);
|
||||
if ($shift == null) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$shift['shifttype_id'] = $shifttype_id;
|
||||
$shift['title'] = $title;
|
||||
$shift['RID'] = $rid;
|
||||
$shift['start'] = $start;
|
||||
$shift['end'] = $end;
|
||||
|
||||
$result = Shift_update($shift);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update shift.');
|
||||
}
|
||||
NeededAngelTypes_delete_by_shift($shift_id);
|
||||
$needed_angel_types_info = [];
|
||||
foreach ($needed_angel_types as $type_id => $count) {
|
||||
NeededAngelType_add($shift_id, $type_id, null, $count);
|
||||
$needed_angel_types_info[] = $angeltypes[$type_id] . ": " . $count;
|
||||
}
|
||||
|
||||
engelsystem_log("Updated shift '" . $shifttypes[$shifttype_id] . ", " . $title . "' from " . date("Y-m-d H:i", $start) . " to " . date("Y-m-d H:i", $end) . " with angel types " . join(", ", $needed_angel_types_info));
|
||||
success(_("Shift updated."));
|
||||
|
||||
redirect(shift_link([
|
||||
'SID' => $shift_id
|
||||
]));
|
||||
|
||||
// Schicht löschen bestätigt
|
||||
if ($request->has('delete')) {
|
||||
Shift_delete($shift_id);
|
||||
|
||||
engelsystem_log(
|
||||
'Deleted shift ' . $shift['name']
|
||||
. ' from ' . date('Y-m-d H:i', $shift['start'])
|
||||
. ' to ' . date('Y-m-d H:i', $shift['end'])
|
||||
);
|
||||
success(_('Shift deleted.'));
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
}
|
||||
|
||||
$angel_types_spinner = "";
|
||||
foreach ($angeltypes as $angeltype_id => $angeltype_name) {
|
||||
$angel_types_spinner .= form_spinner('type_' . $angeltype_id, $angeltype_name, $needed_angel_types[$angeltype_id]);
|
||||
}
|
||||
|
||||
return page_with_title(shifts_title(), [
|
||||
msg(),
|
||||
'<noscript>' . info(_("This page is much more comfortable with javascript."), true) . '</noscript>',
|
||||
form([
|
||||
form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id),
|
||||
form_text('title', _("Title"), $title),
|
||||
form_select('rid', _("Room:"), $room, $rid),
|
||||
form_text('start', _("Start:"), date("Y-m-d H:i", $start)),
|
||||
form_text('end', _("End:"), date("Y-m-d H:i", $end)),
|
||||
'<h2>' . _("Needed angels") . '</h2>',
|
||||
$angel_types_spinner,
|
||||
form_submit('submit', _("Save"))
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function shift_delete_controller() {
|
||||
global $privileges;
|
||||
|
||||
if (! in_array('user_shifts_admin', $privileges)) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
// Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg)
|
||||
if (! isset($_REQUEST['delete_shift']) || ! preg_match("/^[0-9]*$/", $_REQUEST['delete_shift'])) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$shift_id = $_REQUEST['delete_shift'];
|
||||
|
||||
$shift = Shift($shift_id);
|
||||
if ($shift == null) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
// Schicht löschen bestätigt
|
||||
if (isset($_REQUEST['delete'])) {
|
||||
Shift_delete($shift_id);
|
||||
|
||||
engelsystem_log("Deleted shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
|
||||
success(_("Shift deleted."));
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
return page_with_title(shifts_title(), [
|
||||
error(sprintf(_("Do you want to delete the shift %s from %s to %s?"), $shift['name'], date("Y-m-d H:i", $shift['start']), date("H:i", $shift['end'])), true),
|
||||
'<a class="button" href="?p=user_shifts&delete_shift=' . $shift_id . '&delete">' . _("delete") . '</a>'
|
||||
]);
|
||||
return page_with_title(shifts_title(), [
|
||||
error(sprintf(
|
||||
_('Do you want to delete the shift %s from %s to %s?'),
|
||||
$shift['name'],
|
||||
date('Y-m-d H:i', $shift['start']),
|
||||
date('H:i', $shift['end'])
|
||||
), true),
|
||||
'<a class="button" href="'
|
||||
. page_link_to('user_shifts', ['delete_shift' => $shift_id, 'delete' => 1]) .
|
||||
'">' . _('delete') . '</a>'
|
||||
]);
|
||||
}
|
||||
|
||||
function shift_controller() {
|
||||
global $user, $privileges;
|
||||
|
||||
if (! in_array('user_shifts', $privileges)) {
|
||||
redirect(page_link_to('?'));
|
||||
}
|
||||
|
||||
if (! isset($_REQUEST['shift_id'])) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
$shift = Shift($_REQUEST['shift_id']);
|
||||
if ($shift == null) {
|
||||
error(_("Shift could not be found."));
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
$shifttype = ShiftType($shift['shifttype_id']);
|
||||
$room = Room($shift['RID']);
|
||||
$angeltypes = AngelTypes();
|
||||
$user_shifts = Shifts_by_user($user);
|
||||
|
||||
$shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0);
|
||||
foreach ($angeltypes as &$angeltype) {
|
||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
|
||||
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
|
||||
|
||||
$angeltype_signup_state = Shift_signup_allowed($user, $shift, $angeltype, null, $user_shifts, $needed_angeltype, $shift_entries);
|
||||
if ($shift_signup_state == null) {
|
||||
$shift_signup_state = $angeltype_signup_state;
|
||||
} else {
|
||||
$shift_signup_state->combineWith($angeltype_signup_state);
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function shift_controller()
|
||||
{
|
||||
global $user, $privileges;
|
||||
$request = request();
|
||||
|
||||
if (!in_array('user_shifts', $privileges)) {
|
||||
redirect(page_link_to('/'));
|
||||
}
|
||||
|
||||
if (!$request->has('shift_id')) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
$shift = Shift($request->input('shift_id'));
|
||||
if ($shift == null) {
|
||||
error(_('Shift could not be found.'));
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
$shifttype = ShiftType($shift['shifttype_id']);
|
||||
$room = Room($shift['RID']);
|
||||
$angeltypes = AngelTypes();
|
||||
$user_shifts = Shifts_by_user($user);
|
||||
|
||||
$shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0);
|
||||
foreach ($angeltypes as &$angeltype) {
|
||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
|
||||
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
|
||||
|
||||
$angeltype_signup_state = Shift_signup_allowed(
|
||||
$user,
|
||||
$shift,
|
||||
$angeltype,
|
||||
null,
|
||||
$user_shifts,
|
||||
$needed_angeltype,
|
||||
$shift_entries
|
||||
);
|
||||
if ($shift_signup_state == null) {
|
||||
$shift_signup_state = $angeltype_signup_state;
|
||||
} else {
|
||||
$shift_signup_state->combineWith($angeltype_signup_state);
|
||||
}
|
||||
$angeltype['shift_signup_state'] = $angeltype_signup_state;
|
||||
}
|
||||
$angeltype['shift_signup_state'] = $angeltype_signup_state;
|
||||
}
|
||||
|
||||
return [
|
||||
$shift['name'],
|
||||
Shift_view($shift, $shifttype, $room, $angeltypes, $shift_signup_state)
|
||||
];
|
||||
|
||||
return [
|
||||
$shift['name'],
|
||||
Shift_view($shift, $shifttype, $room, $angeltypes, $shift_signup_state)
|
||||
];
|
||||
}
|
||||
|
||||
function shifts_controller() {
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
switch ($_REQUEST['action']) {
|
||||
default:
|
||||
redirect(page_link_to('?'));
|
||||
case 'view':
|
||||
return shift_controller();
|
||||
case 'next':
|
||||
return shift_next_controller();
|
||||
}
|
||||
/**
|
||||
* @return array|false
|
||||
*/
|
||||
function shifts_controller()
|
||||
{
|
||||
$request = request();
|
||||
if (!$request->has('action')) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
switch ($request->input('action')) {
|
||||
case 'view':
|
||||
return shift_controller();
|
||||
case 'next':
|
||||
return shift_next_controller();
|
||||
default:
|
||||
redirect(page_link_to('/'));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects the user to his next shift.
|
||||
*/
|
||||
function shift_next_controller() {
|
||||
global $user, $privileges;
|
||||
|
||||
if (! in_array('user_shifts', $privileges)) {
|
||||
redirect(page_link_to('?'));
|
||||
}
|
||||
|
||||
$upcoming_shifts = ShiftEntries_upcoming_for_user($user);
|
||||
if ($upcoming_shifts === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count($upcoming_shifts) > 0) {
|
||||
redirect(shift_link($upcoming_shifts[0]));
|
||||
}
|
||||
|
||||
redirect(page_link_to('user_shifts'));
|
||||
function shift_next_controller()
|
||||
{
|
||||
global $user, $privileges;
|
||||
|
||||
if (!in_array('user_shifts', $privileges)) {
|
||||
redirect(page_link_to('/'));
|
||||
}
|
||||
|
||||
$upcoming_shifts = ShiftEntries_upcoming_for_user($user);
|
||||
|
||||
if (!empty($upcoming_shifts)) {
|
||||
redirect(shift_link($upcoming_shifts[0]));
|
||||
}
|
||||
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Export all shifts using api-key.
|
||||
*/
|
||||
function shifts_json_export_all_controller() {
|
||||
global $api_key;
|
||||
|
||||
if ($api_key == "") {
|
||||
engelsystem_error("Config contains empty apikey.");
|
||||
}
|
||||
|
||||
if (! isset($_REQUEST['api_key'])) {
|
||||
engelsystem_error("Missing parameter api_key.");
|
||||
}
|
||||
|
||||
if ($_REQUEST['api_key'] != $api_key) {
|
||||
engelsystem_error("Invalid api_key.");
|
||||
}
|
||||
|
||||
$shifts_source = Shifts();
|
||||
if ($shifts_source === false) {
|
||||
engelsystem_error("Unable to load shifts.");
|
||||
}
|
||||
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
raw_output(json_encode($shifts_source));
|
||||
function shifts_json_export_all_controller()
|
||||
{
|
||||
$api_key = config('api_key');
|
||||
$request = request();
|
||||
|
||||
if (empty($api_key)) {
|
||||
engelsystem_error('Config contains empty apikey.');
|
||||
}
|
||||
|
||||
if (!$request->has('api_key')) {
|
||||
engelsystem_error('Missing parameter api_key.');
|
||||
}
|
||||
|
||||
if ($request->input('api_key') != $api_key) {
|
||||
engelsystem_error('Invalid api_key.');
|
||||
}
|
||||
|
||||
$shifts_source = Shifts();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
raw_output(json_encode($shifts_source));
|
||||
}
|
||||
|
||||
/**
|
||||
* Export filtered shifts via JSON.
|
||||
* (Like iCal Export or shifts view)
|
||||
*/
|
||||
function shifts_json_export_controller() {
|
||||
global $user;
|
||||
|
||||
if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
|
||||
engelsystem_error("Missing key.");
|
||||
}
|
||||
|
||||
$key = $_REQUEST['key'];
|
||||
|
||||
$user = User_by_api_key($key);
|
||||
if ($user == null) {
|
||||
engelsystem_error("Key invalid.");
|
||||
}
|
||||
if (! in_array('shifts_json_export', privileges_for_user($user['UID']))) {
|
||||
engelsystem_error("No privilege for shifts_json_export.");
|
||||
}
|
||||
|
||||
$shifts = load_ical_shifts();
|
||||
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
raw_output(json_encode($shifts));
|
||||
function shifts_json_export_controller()
|
||||
{
|
||||
global $user;
|
||||
$request = request();
|
||||
|
||||
if (!$request->has('key') || !preg_match('/^[\da-f]{32}$/', $request->input('key'))) {
|
||||
engelsystem_error('Missing key.');
|
||||
}
|
||||
|
||||
$key = $request->input('key');
|
||||
|
||||
$user = User_by_api_key($key);
|
||||
if ($user == null) {
|
||||
engelsystem_error('Key invalid.');
|
||||
}
|
||||
if (!in_array('shifts_json_export', privileges_for_user($user['UID']))) {
|
||||
engelsystem_error('No privilege for shifts_json_export.');
|
||||
}
|
||||
|
||||
$shifts = load_ical_shifts();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
raw_output(json_encode($shifts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns users shifts to export.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function load_ical_shifts() {
|
||||
global $user;
|
||||
|
||||
return Shifts_by_user($user);
|
||||
}
|
||||
function load_ical_shifts()
|
||||
{
|
||||
global $user;
|
||||
|
||||
?>
|
||||
return Shifts_by_user($user);
|
||||
}
|
||||
|
@ -1,179 +1,187 @@
|
||||
<?php
|
||||
|
||||
function shifttype_link($shifttype) {
|
||||
return page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype['id'];
|
||||
/**
|
||||
* @param array $shifttype
|
||||
* @return string
|
||||
*/
|
||||
function shifttype_link($shifttype)
|
||||
{
|
||||
return page_link_to('shifttypes', ['action' => 'view', 'shifttype_id' => $shifttype['id']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a shifttype.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function shifttype_delete_controller() {
|
||||
if (! isset($_REQUEST['shifttype_id'])) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
$shifttype = ShiftType($_REQUEST['shifttype_id']);
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shifttype.');
|
||||
}
|
||||
|
||||
if ($shifttype == null) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
$result = ShiftType_delete($shifttype['id']);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shifttype.');
|
||||
function shifttype_delete_controller()
|
||||
{
|
||||
$request = request();
|
||||
if (!$request->has('shifttype_id')) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
$shifttype = ShiftType($request->input('shifttype_id'));
|
||||
|
||||
if ($shifttype == null) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
engelsystem_log('Deleted shifttype ' . $shifttype['name']);
|
||||
success(sprintf(_('Shifttype %s deleted.'), $shifttype['name']));
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
return [
|
||||
sprintf(_("Delete shifttype %s"), $shifttype['name']),
|
||||
ShiftType_delete_view($shifttype)
|
||||
];
|
||||
|
||||
if ($request->has('confirmed')) {
|
||||
ShiftType_delete($shifttype['id']);
|
||||
|
||||
engelsystem_log('Deleted shifttype ' . $shifttype['name']);
|
||||
success(sprintf(_('Shifttype %s deleted.'), $shifttype['name']));
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
return [
|
||||
sprintf(_('Delete shifttype %s'), $shifttype['name']),
|
||||
ShiftType_delete_view($shifttype)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit or create shift type.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function shifttype_edit_controller() {
|
||||
$shifttype_id = null;
|
||||
$name = "";
|
||||
$angeltype_id = null;
|
||||
$description = "";
|
||||
|
||||
$angeltypes = AngelTypes();
|
||||
|
||||
if (isset($_REQUEST['shifttype_id'])) {
|
||||
$shifttype = ShiftType($_REQUEST['shifttype_id']);
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shifttype.');
|
||||
}
|
||||
if ($shifttype == null) {
|
||||
error(_('Shifttype not found.'));
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
$shifttype_id = $shifttype['id'];
|
||||
$name = $shifttype['name'];
|
||||
$angeltype_id = $shifttype['angeltype_id'];
|
||||
$description = $shifttype['description'];
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') {
|
||||
$name = strip_request_item('name');
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please enter a name.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['angeltype_id']) && preg_match("/^[0-9]+$/", $_REQUEST['angeltype_id'])) {
|
||||
$angeltype_id = $_REQUEST['angeltype_id'];
|
||||
} else {
|
||||
$angeltype_id = null;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['description'])) {
|
||||
$description = strip_request_item_nl('description');
|
||||
function shifttype_edit_controller()
|
||||
{
|
||||
$shifttype_id = null;
|
||||
$name = '';
|
||||
$angeltype_id = null;
|
||||
$description = '';
|
||||
|
||||
$angeltypes = AngelTypes();
|
||||
$request = request();
|
||||
|
||||
if ($request->has('shifttype_id')) {
|
||||
$shifttype = ShiftType($request->input('shifttype_id'));
|
||||
if ($shifttype == null) {
|
||||
error(_('Shifttype not found.'));
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
$shifttype_id = $shifttype['id'];
|
||||
$name = $shifttype['name'];
|
||||
$angeltype_id = $shifttype['angeltype_id'];
|
||||
$description = $shifttype['description'];
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
if ($shifttype_id) {
|
||||
$result = ShiftType_update($shifttype_id, $name, $angeltype_id, $description);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update shifttype.');
|
||||
|
||||
if ($request->has('submit')) {
|
||||
$valid = true;
|
||||
|
||||
if ($request->has('name') && $request->input('name') != '') {
|
||||
$name = strip_request_item('name');
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please enter a name.'));
|
||||
}
|
||||
engelsystem_log('Updated shifttype ' . $name);
|
||||
success(_('Updated shifttype.'));
|
||||
} else {
|
||||
$shifttype_id = ShiftType_create($name, $angeltype_id, $description);
|
||||
if ($shifttype_id === false) {
|
||||
engelsystem_error('Unable to create shifttype.');
|
||||
|
||||
if ($request->has('angeltype_id') && preg_match('/^\d+$/', $request->input('angeltype_id'))) {
|
||||
$angeltype_id = $request->input('angeltype_id');
|
||||
} else {
|
||||
$angeltype_id = null;
|
||||
}
|
||||
|
||||
if ($request->has('description')) {
|
||||
$description = strip_request_item_nl('description');
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
if ($shifttype_id) {
|
||||
ShiftType_update($shifttype_id, $name, $angeltype_id, $description);
|
||||
|
||||
engelsystem_log('Updated shifttype ' . $name);
|
||||
success(_('Updated shifttype.'));
|
||||
} else {
|
||||
$shifttype_id = ShiftType_create($name, $angeltype_id, $description);
|
||||
|
||||
engelsystem_log('Created shifttype ' . $name);
|
||||
success(_('Created shifttype.'));
|
||||
}
|
||||
redirect(page_link_to('shifttypes', ['action' => 'view', 'shifttype_id' => $shifttype_id]));
|
||||
}
|
||||
engelsystem_log('Created shifttype ' . $name);
|
||||
success(_('Created shifttype.'));
|
||||
}
|
||||
redirect(page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype_id);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
shifttypes_title(),
|
||||
ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id)
|
||||
];
|
||||
|
||||
return [
|
||||
shifttypes_title(),
|
||||
ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id)
|
||||
];
|
||||
}
|
||||
|
||||
function shifttype_controller() {
|
||||
if (! isset($_REQUEST['shifttype_id'])) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
$shifttype = ShiftType($_REQUEST['shifttype_id']);
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shifttype.');
|
||||
}
|
||||
if ($shifttype == null) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
$angeltype = null;
|
||||
if ($shifttype['angeltype_id'] != null) {
|
||||
$angeltype = AngelType($shifttype['angeltype_id']);
|
||||
}
|
||||
|
||||
return [
|
||||
$shifttype['name'],
|
||||
ShiftType_view($shifttype, $angeltype)
|
||||
];
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function shifttype_controller()
|
||||
{
|
||||
$request = request();
|
||||
if (!$request->has('shifttype_id')) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
$shifttype = ShiftType($request->input('shifttype_id'));
|
||||
if ($shifttype == null) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
$angeltype = null;
|
||||
if ($shifttype['angeltype_id'] != null) {
|
||||
$angeltype = AngelType($shifttype['angeltype_id']);
|
||||
}
|
||||
|
||||
return [
|
||||
$shifttype['name'],
|
||||
ShiftType_view($shifttype, $angeltype)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* List all shift types.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function shifttypes_list_controller() {
|
||||
$shifttypes = ShiftTypes();
|
||||
if ($shifttypes === false) {
|
||||
engelsystem_error("Unable to load shifttypes.");
|
||||
}
|
||||
|
||||
return [
|
||||
shifttypes_title(),
|
||||
ShiftTypes_list_view($shifttypes)
|
||||
];
|
||||
function shifttypes_list_controller()
|
||||
{
|
||||
$shifttypes = ShiftTypes();
|
||||
|
||||
return [
|
||||
shifttypes_title(),
|
||||
ShiftTypes_list_view($shifttypes)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Text for shift type related links.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function shifttypes_title() {
|
||||
return _("Shifttypes");
|
||||
function shifttypes_title()
|
||||
{
|
||||
return _('Shifttypes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Route shift type actions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function shifttypes_controller() {
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$_REQUEST['action'] = 'list';
|
||||
}
|
||||
|
||||
switch ($_REQUEST['action']) {
|
||||
default:
|
||||
case 'list':
|
||||
return shifttypes_list_controller();
|
||||
case 'view':
|
||||
return shifttype_controller();
|
||||
case 'edit':
|
||||
return shifttype_edit_controller();
|
||||
case 'delete':
|
||||
return shifttype_delete_controller();
|
||||
}
|
||||
}
|
||||
function shifttypes_controller()
|
||||
{
|
||||
$request = request();
|
||||
$action = 'list';
|
||||
if ($request->has('action')) {
|
||||
$action = $request->input('action');
|
||||
}
|
||||
|
||||
?>
|
||||
switch ($action) {
|
||||
case 'view':
|
||||
return shifttype_controller();
|
||||
case 'edit':
|
||||
return shifttype_edit_controller();
|
||||
case 'delete':
|
||||
return shifttype_delete_controller();
|
||||
case 'list':
|
||||
default:
|
||||
return shifttypes_list_controller();
|
||||
}
|
||||
}
|
||||
|
@ -1,132 +1,148 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license information provided.
|
||||
* Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license
|
||||
* information provided.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
function user_driver_license_required_hint() {
|
||||
global $user;
|
||||
|
||||
$angeltypes = User_angeltypes($user);
|
||||
$user_driver_license = UserDriverLicense($user['UID']);
|
||||
|
||||
// User has already entered data, no hint needed.
|
||||
if ($user_driver_license != null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($angeltypes as $angeltype) {
|
||||
if ($angeltype['requires_driver_license']) {
|
||||
return sprintf(_("You joined an angeltype which requires a driving license. Please edit your driving license information here: %s."), '<a href="' . user_driver_license_edit_link() . '">' . _("driving license information") . '</a>');
|
||||
function user_driver_license_required_hint()
|
||||
{
|
||||
global $user;
|
||||
|
||||
$angeltypes = User_angeltypes($user);
|
||||
$user_driver_license = UserDriverLicense($user['UID']);
|
||||
|
||||
// User has already entered data, no hint needed.
|
||||
if ($user_driver_license != null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
foreach ($angeltypes as $angeltype) {
|
||||
if ($angeltype['requires_driver_license']) {
|
||||
return sprintf(
|
||||
_('You joined an angeltype which requires a driving license. Please edit your driving license information here: %s.'),
|
||||
'<a href="' . user_driver_license_edit_link() . '">' . _('driving license information') . '</a>'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Route user driver licenses actions.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function user_driver_licenses_controller() {
|
||||
global $user;
|
||||
|
||||
if (! isset($user)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
$action = strip_request_item('action', 'edit');
|
||||
|
||||
switch ($action) {
|
||||
default:
|
||||
case 'edit':
|
||||
return user_driver_license_edit_controller();
|
||||
}
|
||||
function user_driver_licenses_controller()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (!isset($user)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
$action = strip_request_item('action', 'edit');
|
||||
|
||||
switch ($action) {
|
||||
default:
|
||||
case 'edit':
|
||||
return user_driver_license_edit_controller();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to user driver license edit page for given user.
|
||||
*
|
||||
* @param User $user
|
||||
* @param array $user
|
||||
* @return string
|
||||
*/
|
||||
function user_driver_license_edit_link($user = null) {
|
||||
if ($user == null) {
|
||||
return page_link_to('user_driver_licenses');
|
||||
}
|
||||
return page_link_to('user_driver_licenses') . '&user_id=' . $user['UID'];
|
||||
function user_driver_license_edit_link($user = null)
|
||||
{
|
||||
if ($user == null) {
|
||||
return page_link_to('user_driver_licenses');
|
||||
}
|
||||
return page_link_to('user_driver_licenses', ['user_id' => $user['UID']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the user for the driver license.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function user_driver_license_load_user() {
|
||||
global $user;
|
||||
|
||||
$user_source = $user;
|
||||
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
if ($user_source == null) {
|
||||
redirect(user_driver_license_edit_link());
|
||||
function user_driver_license_load_user()
|
||||
{
|
||||
global $user;
|
||||
$request = request();
|
||||
$user_source = $user;
|
||||
|
||||
if ($request->has('user_id')) {
|
||||
$user_source = User($request->input('user_id'));
|
||||
if ($user_source == null) {
|
||||
redirect(user_driver_license_edit_link());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $user_source;
|
||||
|
||||
return $user_source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a users driver license information.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function user_driver_license_edit_controller() {
|
||||
global $privileges, $user;
|
||||
|
||||
$user_source = user_driver_license_load_user();
|
||||
|
||||
// only privilege admin_user can edit other users driver license information
|
||||
if ($user['UID'] != $user_source['UID'] && ! in_array('admin_user', $privileges)) {
|
||||
redirect(user_driver_license_edit_link());
|
||||
}
|
||||
|
||||
$user_driver_license = UserDriverLicense($user_source['UID']);
|
||||
if ($user_driver_license == null) {
|
||||
$wants_to_drive = false;
|
||||
$user_driver_license = UserDriverLicense_new();
|
||||
} else {
|
||||
$wants_to_drive = true;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$wants_to_drive = isset($_REQUEST['wants_to_drive']);
|
||||
if ($wants_to_drive) {
|
||||
$user_driver_license['has_car'] = isset($_REQUEST['has_car']);
|
||||
$user_driver_license['has_license_car'] = isset($_REQUEST['has_license_car']);
|
||||
$user_driver_license['has_license_3_5t_transporter'] = isset($_REQUEST['has_license_3_5t_transporter']);
|
||||
$user_driver_license['has_license_7_5t_truck'] = isset($_REQUEST['has_license_7_5t_truck']);
|
||||
$user_driver_license['has_license_12_5t_truck'] = isset($_REQUEST['has_license_12_5t_truck']);
|
||||
$user_driver_license['has_license_forklift'] = isset($_REQUEST['has_license_forklift']);
|
||||
|
||||
if (UserDriverLicense_valid($user_driver_license)) {
|
||||
if ($user_driver_license['user_id'] == null) {
|
||||
$user_driver_license = UserDriverLicenses_create($user_driver_license, $user);
|
||||
} else {
|
||||
UserDriverLicenses_update($user_driver_license);
|
||||
function user_driver_license_edit_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
$request = request();
|
||||
$user_source = user_driver_license_load_user();
|
||||
|
||||
// only privilege admin_user can edit other users driver license information
|
||||
if ($user['UID'] != $user_source['UID'] && !in_array('admin_user', $privileges)) {
|
||||
redirect(user_driver_license_edit_link());
|
||||
}
|
||||
|
||||
$user_driver_license = UserDriverLicense($user_source['UID']);
|
||||
if ($user_driver_license == null) {
|
||||
$wants_to_drive = false;
|
||||
$user_driver_license = UserDriverLicense_new();
|
||||
} else {
|
||||
$wants_to_drive = true;
|
||||
}
|
||||
|
||||
if ($request->has('submit')) {
|
||||
$wants_to_drive = $request->has('wants_to_drive');
|
||||
if ($wants_to_drive) {
|
||||
$user_driver_license['has_car'] = $request->has('has_car');
|
||||
$user_driver_license['has_license_car'] = $request->has('has_license_car');
|
||||
$user_driver_license['has_license_3_5t_transporter'] = $request->has('has_license_3_5t_transporter');
|
||||
$user_driver_license['has_license_7_5t_truck'] = $request->has('has_license_7_5t_truck');
|
||||
$user_driver_license['has_license_12_5t_truck'] = $request->has('has_license_12_5t_truck');
|
||||
$user_driver_license['has_license_forklift'] = $request->has('has_license_forklift');
|
||||
|
||||
if (UserDriverLicense_valid($user_driver_license)) {
|
||||
if ($user_driver_license['user_id'] == null) {
|
||||
$user_driver_license = UserDriverLicenses_create($user_driver_license, $user_source);
|
||||
} else {
|
||||
UserDriverLicenses_update($user_driver_license);
|
||||
}
|
||||
engelsystem_log('Driver license information updated.');
|
||||
success(_('Your driver license information has been saved.'));
|
||||
redirect(user_link($user_source));
|
||||
} else {
|
||||
error(_('Please select at least one driving license.'));
|
||||
}
|
||||
} elseif ($user_driver_license['user_id'] != null) {
|
||||
UserDriverLicenses_delete($user_source['UID']);
|
||||
engelsystem_log('Driver license information removed.');
|
||||
success(_('Your driver license information has been removed.'));
|
||||
redirect(user_link($user_source));
|
||||
}
|
||||
engelsystem_log("Driver license information updated.");
|
||||
success(_("Your driver license information has been saved."));
|
||||
redirect(user_link($user_source));
|
||||
} else {
|
||||
error(_("Please select at least one driving license."));
|
||||
}
|
||||
} elseif ($user_driver_license['id'] != null) {
|
||||
UserDriverLicenses_delete($user_source['UID']);
|
||||
engelsystem_log("Driver license information removed.");
|
||||
success(_("Your driver license information has been removed."));
|
||||
redirect(user_link($user_source));
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
sprintf(_("Edit %s driving license information"), $user_source['Nick']),
|
||||
UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license)
|
||||
];
|
||||
}
|
||||
|
||||
?>
|
||||
return [
|
||||
sprintf(_('Edit %s driving license information'), $user_source['Nick']),
|
||||
UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license)
|
||||
];
|
||||
}
|
||||
|
@ -1,371 +1,473 @@
|
||||
<?php
|
||||
use Engelsystem\ShiftsFilter;
|
||||
|
||||
use Engelsystem\Database\DB;
|
||||
use Engelsystem\ShiftCalendarRenderer;
|
||||
use Engelsystem\ShiftsFilter;
|
||||
|
||||
/**
|
||||
* Route user actions.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function users_controller() {
|
||||
global $user;
|
||||
|
||||
if (! isset($user)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$_REQUEST['action'] = 'list';
|
||||
}
|
||||
|
||||
switch ($_REQUEST['action']) {
|
||||
default:
|
||||
case 'list':
|
||||
return users_list_controller();
|
||||
case 'view':
|
||||
return user_controller();
|
||||
case 'edit':
|
||||
return user_edit_controller();
|
||||
case 'delete':
|
||||
return user_delete_controller();
|
||||
case 'edit_vouchers':
|
||||
return user_edit_vouchers_controller();
|
||||
}
|
||||
function users_controller()
|
||||
{
|
||||
global $user;
|
||||
$request = request();
|
||||
|
||||
if (!isset($user)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
$action = 'list';
|
||||
if ($request->has('action')) {
|
||||
$action = $request->input('action');
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'view':
|
||||
return user_controller();
|
||||
case 'delete':
|
||||
return user_delete_controller();
|
||||
case 'edit_vouchers':
|
||||
return user_edit_vouchers_controller();
|
||||
case 'list':
|
||||
default:
|
||||
return users_list_controller();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a user, requires to enter own password for reasons.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function user_delete_controller() {
|
||||
global $privileges, $user;
|
||||
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
} else {
|
||||
$user_source = $user;
|
||||
}
|
||||
|
||||
if (! in_array('admin_user', $privileges)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
// You cannot delete yourself
|
||||
if ($user['UID'] == $user_source['UID']) {
|
||||
error(_("You cannot delete yourself."));
|
||||
redirect(user_link($user));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (! (isset($_REQUEST['password']) && verify_password($_REQUEST['password'], $user['Passwort'], $user['UID']))) {
|
||||
$valid = false;
|
||||
error(_("Your password is incorrect. Please try it again."));
|
||||
function user_delete_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
$request = request();
|
||||
|
||||
if ($request->has('user_id')) {
|
||||
$user_source = User($request->query->get('user_id'));
|
||||
} else {
|
||||
$user_source = $user;
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$result = User_delete($user_source['UID']);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete user.');
|
||||
}
|
||||
|
||||
mail_user_delete($user_source);
|
||||
success(_("User deleted."));
|
||||
engelsystem_log(sprintf("Deleted %s", User_Nick_render($user_source)));
|
||||
|
||||
redirect(users_link());
|
||||
|
||||
if (!in_array('admin_user', $privileges)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
sprintf(_("Delete %s"), $user_source['Nick']),
|
||||
User_delete_view($user_source)
|
||||
];
|
||||
|
||||
// You cannot delete yourself
|
||||
if ($user['UID'] == $user_source['UID']) {
|
||||
error(_('You cannot delete yourself.'));
|
||||
redirect(user_link($user));
|
||||
}
|
||||
|
||||
if ($request->has('submit')) {
|
||||
$valid = true;
|
||||
|
||||
if (
|
||||
!(
|
||||
$request->has('password')
|
||||
&& verify_password($request->postData('password'), $user['Passwort'], $user['UID'])
|
||||
)
|
||||
) {
|
||||
$valid = false;
|
||||
error(_('Your password is incorrect. Please try it again.'));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
User_delete($user_source['UID']);
|
||||
|
||||
mail_user_delete($user_source);
|
||||
success(_('User deleted.'));
|
||||
engelsystem_log(sprintf('Deleted %s', User_Nick_render($user_source)));
|
||||
|
||||
redirect(users_link());
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
sprintf(_('Delete %s'), $user_source['Nick']),
|
||||
User_delete_view($user_source)
|
||||
];
|
||||
}
|
||||
|
||||
function users_link() {
|
||||
return page_link_to('users');
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function users_link()
|
||||
{
|
||||
return page_link_to('users');
|
||||
}
|
||||
|
||||
function user_edit_link($user) {
|
||||
return page_link_to('admin_user') . '&user_id=' . $user['UID'];
|
||||
/**
|
||||
* @param array $user
|
||||
* @return string
|
||||
*/
|
||||
function user_edit_link($user)
|
||||
{
|
||||
return page_link_to('admin_user', ['user_id' => $user['UID']]);
|
||||
}
|
||||
|
||||
function user_delete_link($user) {
|
||||
return page_link_to('users') . '&action=delete&user_id=' . $user['UID'];
|
||||
/**
|
||||
* @param array $user
|
||||
* @return string
|
||||
*/
|
||||
function user_delete_link($user)
|
||||
{
|
||||
return page_link_to('users', ['action' => 'delete', 'user_id' => $user['UID']]);
|
||||
}
|
||||
|
||||
function user_link($user) {
|
||||
return page_link_to('users') . '&action=view&user_id=' . $user['UID'];
|
||||
/**
|
||||
* @param array $user
|
||||
* @return string
|
||||
*/
|
||||
function user_link($user)
|
||||
{
|
||||
return page_link_to('users', ['action' => 'view', 'user_id' => $user['UID']]);
|
||||
}
|
||||
|
||||
function user_edit_vouchers_controller() {
|
||||
global $privileges, $user;
|
||||
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
} else {
|
||||
$user_source = $user;
|
||||
}
|
||||
|
||||
if (! in_array('admin_user', $privileges)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['vouchers']) && test_request_int('vouchers') && trim($_REQUEST['vouchers']) >= 0) {
|
||||
$vouchers = trim($_REQUEST['vouchers']);
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function user_edit_vouchers_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
$request = request();
|
||||
|
||||
if ($request->has('user_id')) {
|
||||
$user_source = User($request->input('user_id'));
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter a valid number of vouchers."));
|
||||
$user_source = $user;
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$user_source['got_voucher'] = $vouchers;
|
||||
|
||||
$result = User_update($user_source);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update user.');
|
||||
}
|
||||
|
||||
success(_("Saved the number of vouchers."));
|
||||
engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf("Got %s vouchers", $user_source['got_voucher']));
|
||||
|
||||
redirect(user_link($user_source));
|
||||
|
||||
if (!in_array('admin_user', $privileges)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
sprintf(_("%s's vouchers"), $user_source['Nick']),
|
||||
User_edit_vouchers_view($user_source)
|
||||
];
|
||||
|
||||
if ($request->has('submit')) {
|
||||
$valid = true;
|
||||
|
||||
$vouchers = '';
|
||||
if (
|
||||
$request->has('vouchers')
|
||||
&& test_request_int('vouchers')
|
||||
&& trim($request->input('vouchers')) >= 0
|
||||
) {
|
||||
$vouchers = trim($request->input('vouchers'));
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please enter a valid number of vouchers.'));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$user_source['got_voucher'] = $vouchers;
|
||||
|
||||
User_update($user_source);
|
||||
|
||||
success(_('Saved the number of vouchers.'));
|
||||
engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf('Got %s vouchers',
|
||||
$user_source['got_voucher']));
|
||||
|
||||
redirect(user_link($user_source));
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
sprintf(_('%s\'s vouchers'), $user_source['Nick']),
|
||||
User_edit_vouchers_view($user_source)
|
||||
];
|
||||
}
|
||||
|
||||
function user_controller() {
|
||||
global $privileges, $user;
|
||||
|
||||
$user_source = $user;
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
if ($user_source == null) {
|
||||
error(_("User not found."));
|
||||
redirect('?');
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function user_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
$request = request();
|
||||
|
||||
$user_source = $user;
|
||||
if ($request->has('user_id')) {
|
||||
$user_source = User($request->input('user_id'));
|
||||
if ($user_source == null) {
|
||||
error(_('User not found.'));
|
||||
redirect(page_link_to('/'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$shifts = Shifts_by_user($user_source, in_array("user_shifts_admin", $privileges));
|
||||
foreach ($shifts as &$shift) {
|
||||
// TODO: Move queries to model
|
||||
$shift['needed_angeltypes'] = sql_select("SELECT DISTINCT `AngelTypes`.* FROM `ShiftEntry` JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id` WHERE `ShiftEntry`.`SID`='" . sql_escape($shift['SID']) . "' ORDER BY `AngelTypes`.`name`");
|
||||
foreach ($shift['needed_angeltypes'] as &$needed_angeltype) {
|
||||
$needed_angeltype['users'] = sql_select("
|
||||
SELECT `ShiftEntry`.`freeloaded`, `User`.*
|
||||
FROM `ShiftEntry`
|
||||
JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
|
||||
WHERE `ShiftEntry`.`SID`='" . sql_escape($shift['SID']) . "'
|
||||
AND `ShiftEntry`.`TID`='" . sql_escape($needed_angeltype['id']) . "'");
|
||||
|
||||
$shifts = Shifts_by_user($user_source, in_array('user_shifts_admin', $privileges));
|
||||
foreach ($shifts as &$shift) {
|
||||
// TODO: Move queries to model
|
||||
$shift['needed_angeltypes'] = DB::select('
|
||||
SELECT DISTINCT `AngelTypes`.*
|
||||
FROM `ShiftEntry`
|
||||
JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id`
|
||||
WHERE `ShiftEntry`.`SID` = ?
|
||||
ORDER BY `AngelTypes`.`name`
|
||||
',
|
||||
[$shift['SID']]
|
||||
);
|
||||
foreach ($shift['needed_angeltypes'] as &$needed_angeltype) {
|
||||
$needed_angeltype['users'] = DB::select('
|
||||
SELECT `ShiftEntry`.`freeloaded`, `User`.*
|
||||
FROM `ShiftEntry`
|
||||
JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
|
||||
WHERE `ShiftEntry`.`SID` = ?
|
||||
AND `ShiftEntry`.`TID` = ?
|
||||
',
|
||||
[$shift['SID'], $needed_angeltype['id']]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($user_source['api_key'] == "") {
|
||||
User_reset_api_key($user_source, false);
|
||||
}
|
||||
|
||||
return [
|
||||
$user_source['Nick'],
|
||||
User_view($user_source, in_array('admin_user', $privileges), User_is_freeloader($user_source), User_angeltypes($user_source), User_groups($user_source), $shifts, $user['UID'] == $user_source['UID'])
|
||||
];
|
||||
|
||||
if ($user_source['api_key'] == '') {
|
||||
User_reset_api_key($user_source, false);
|
||||
}
|
||||
|
||||
return [
|
||||
$user_source['Nick'],
|
||||
User_view(
|
||||
$user_source,
|
||||
in_array('admin_user', $privileges),
|
||||
User_is_freeloader($user_source),
|
||||
User_angeltypes($user_source),
|
||||
User_groups($user_source),
|
||||
$shifts,
|
||||
$user['UID'] == $user_source['UID']
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* List all users.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function users_list_controller() {
|
||||
global $privileges;
|
||||
|
||||
if (! in_array('admin_user', $privileges)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
$order_by = 'Nick';
|
||||
if (isset($_REQUEST['OrderBy']) && in_array($_REQUEST['OrderBy'], User_sortable_columns())) {
|
||||
$order_by = $_REQUEST['OrderBy'];
|
||||
}
|
||||
|
||||
$users = Users($order_by);
|
||||
if ($users === false) {
|
||||
engelsystem_error('Unable to load users.');
|
||||
}
|
||||
|
||||
foreach ($users as &$user) {
|
||||
$user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user));
|
||||
}
|
||||
|
||||
return [
|
||||
_('All users'),
|
||||
Users_view($users, $order_by, User_arrived_count(), User_active_count(), User_force_active_count(), ShiftEntries_freeleaded_count(), User_tshirts_count(), User_got_voucher_count())
|
||||
];
|
||||
function users_list_controller()
|
||||
{
|
||||
global $privileges;
|
||||
$request = request();
|
||||
|
||||
if (!in_array('admin_user', $privileges)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
$order_by = 'Nick';
|
||||
if ($request->has('OrderBy') && in_array($request->input('OrderBy'), User_sortable_columns())) {
|
||||
$order_by = $request->input('OrderBy');
|
||||
}
|
||||
|
||||
$users = Users($order_by);
|
||||
foreach ($users as &$user) {
|
||||
$user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user));
|
||||
}
|
||||
|
||||
return [
|
||||
_('All users'),
|
||||
Users_view(
|
||||
$users,
|
||||
$order_by,
|
||||
User_arrived_count(),
|
||||
User_active_count(),
|
||||
User_force_active_count(),
|
||||
ShiftEntries_freeleaded_count(),
|
||||
User_tshirts_count(),
|
||||
User_got_voucher_count()
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Second step of password recovery: set a new password using the token link from email
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function user_password_recovery_set_new_controller() {
|
||||
global $min_password_length;
|
||||
$user_source = User_by_password_recovery_token($_REQUEST['token']);
|
||||
if ($user_source == null) {
|
||||
error(_("Token is not correct."));
|
||||
redirect(page_link_to('login'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) {
|
||||
if ($_REQUEST['password'] != $_REQUEST['password2']) {
|
||||
$valid = false;
|
||||
error(_("Your passwords don't match."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Your password is to short (please use at least 6 characters)."));
|
||||
function user_password_recovery_set_new_controller()
|
||||
{
|
||||
$request = request();
|
||||
$user_source = User_by_password_recovery_token($request->input('token'));
|
||||
if ($user_source == null) {
|
||||
error(_('Token is not correct.'));
|
||||
redirect(page_link_to('login'));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
set_password($user_source['UID'], $_REQUEST['password']);
|
||||
success(_("Password saved."));
|
||||
redirect(page_link_to('login'));
|
||||
|
||||
if ($request->has('submit')) {
|
||||
$valid = true;
|
||||
|
||||
if (
|
||||
$request->has('password')
|
||||
&& strlen($request->postData('password')) >= config('min_password_length')
|
||||
) {
|
||||
if ($request->postData('password') != $request->postData('password2')) {
|
||||
$valid = false;
|
||||
error(_('Your passwords don\'t match.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Your password is to short (please use at least 6 characters).'));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
set_password($user_source['UID'], $request->postData('password'));
|
||||
success(_('Password saved.'));
|
||||
redirect(page_link_to('login'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return User_password_set_view();
|
||||
|
||||
return User_password_set_view();
|
||||
}
|
||||
|
||||
/**
|
||||
* First step of password recovery: display a form that asks for your email and send email with recovery link
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function user_password_recovery_start_controller() {
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['email']) && strlen(strip_request_item('email')) > 0) {
|
||||
$email = strip_request_item('email');
|
||||
if (check_email($email)) {
|
||||
$user_source = User_by_email($email);
|
||||
if ($user_source == null) {
|
||||
$valid = false;
|
||||
error(_("E-mail address is not correct."));
|
||||
function user_password_recovery_start_controller()
|
||||
{
|
||||
$request = request();
|
||||
if ($request->has('submit')) {
|
||||
$valid = true;
|
||||
|
||||
if ($request->has('email') && strlen(strip_request_item('email')) > 0) {
|
||||
$email = strip_request_item('email');
|
||||
if (check_email($email)) {
|
||||
$user_source = User_by_email($email);
|
||||
if ($user_source == null) {
|
||||
$valid = false;
|
||||
error(_('E-mail address is not correct.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('E-mail address is not correct.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please enter your e-mail.'));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$token = User_generate_password_recovery_token($user_source);
|
||||
engelsystem_email_to_user(
|
||||
$user_source,
|
||||
_('Password recovery'),
|
||||
sprintf(
|
||||
_('Please visit %s to recover your password.'),
|
||||
page_link_to('user_password_recovery', ['token' => $token])
|
||||
)
|
||||
);
|
||||
success(_('We sent an email containing your password recovery link.'));
|
||||
redirect(page_link_to('login'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("E-mail address is not correct."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter your e-mail."));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$token = User_generate_password_recovery_token($user_source);
|
||||
engelsystem_email_to_user($user_source, _("Password recovery"), sprintf(_("Please visit %s to recover your password."), page_link_to_absolute('user_password_recovery') . '&token=' . $token));
|
||||
success(_("We sent an email containing your password recovery link."));
|
||||
redirect(page_link_to('login'));
|
||||
}
|
||||
}
|
||||
|
||||
return User_password_recovery_view();
|
||||
|
||||
return User_password_recovery_view();
|
||||
}
|
||||
|
||||
/**
|
||||
* User password recovery in 2 steps.
|
||||
* (By email)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function user_password_recovery_controller() {
|
||||
if (isset($_REQUEST['token'])) {
|
||||
return user_password_recovery_set_new_controller();
|
||||
} else {
|
||||
function user_password_recovery_controller()
|
||||
{
|
||||
if (request()->has('token')) {
|
||||
return user_password_recovery_set_new_controller();
|
||||
}
|
||||
|
||||
return user_password_recovery_start_controller();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu title for password recovery.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function user_password_recovery_title() {
|
||||
return _("Password recovery");
|
||||
function user_password_recovery_title()
|
||||
{
|
||||
return _('Password recovery');
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a user from param user_id.
|
||||
*
|
||||
* return array
|
||||
*/
|
||||
function load_user() {
|
||||
if (! isset($_REQUEST['user_id'])) {
|
||||
redirect(page_link_to());
|
||||
}
|
||||
|
||||
$user = User($_REQUEST['user_id']);
|
||||
if ($user === false) {
|
||||
engelsystem_error("Unable to load user.");
|
||||
}
|
||||
|
||||
if ($user == null) {
|
||||
error(_("User doesn't exist."));
|
||||
redirect(page_link_to());
|
||||
}
|
||||
|
||||
return $user;
|
||||
function load_user()
|
||||
{
|
||||
$request = request();
|
||||
if (!$request->has('user_id')) {
|
||||
redirect(page_link_to());
|
||||
}
|
||||
|
||||
$user = User($request->input('user_id'));
|
||||
|
||||
if ($user == null) {
|
||||
error(_('User doesn\'t exist.'));
|
||||
redirect(page_link_to());
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter) {
|
||||
$shifts = Shifts_by_ShiftsFilter($shiftsFilter);
|
||||
$needed_angeltypes_source = NeededAngeltypes_by_ShiftsFilter($shiftsFilter);
|
||||
$shift_entries_source = ShiftEntries_by_ShiftsFilter($shiftsFilter);
|
||||
|
||||
$needed_angeltypes = [];
|
||||
$shift_entries = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$needed_angeltypes[$shift['SID']] = [];
|
||||
$shift_entries[$shift['SID']] = [];
|
||||
}
|
||||
foreach ($shift_entries_source as $shift_entry) {
|
||||
if (isset($shift_entries[$shift_entry['SID']])) {
|
||||
$shift_entries[$shift_entry['SID']][] = $shift_entry;
|
||||
/**
|
||||
* @param ShiftsFilter $shiftsFilter
|
||||
* @return ShiftCalendarRenderer
|
||||
*/
|
||||
function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter)
|
||||
{
|
||||
$shifts = Shifts_by_ShiftsFilter($shiftsFilter);
|
||||
$needed_angeltypes_source = NeededAngeltypes_by_ShiftsFilter($shiftsFilter);
|
||||
$shift_entries_source = ShiftEntries_by_ShiftsFilter($shiftsFilter);
|
||||
|
||||
$needed_angeltypes = [];
|
||||
$shift_entries = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$needed_angeltypes[$shift['SID']] = [];
|
||||
$shift_entries[$shift['SID']] = [];
|
||||
}
|
||||
}
|
||||
foreach ($needed_angeltypes_source as $needed_angeltype) {
|
||||
if (isset($needed_angeltypes[$needed_angeltype['SID']])) {
|
||||
$needed_angeltypes[$needed_angeltype['SID']][] = $needed_angeltype;
|
||||
foreach ($shift_entries_source as $shift_entry) {
|
||||
if (isset($shift_entries[$shift_entry['SID']])) {
|
||||
$shift_entries[$shift_entry['SID']][] = $shift_entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($needed_angeltypes_source);
|
||||
unset($shift_entries_source);
|
||||
|
||||
if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled())) {
|
||||
return new ShiftCalendarRenderer($shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
|
||||
}
|
||||
|
||||
$filtered_shifts = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$needed_angels_count = 0;
|
||||
foreach ($needed_angeltypes[$shift['SID']] as $needed_angeltype) {
|
||||
$taken = 0;
|
||||
foreach ($shift_entries[$shift['SID']] as $shift_entry) {
|
||||
if ($needed_angeltype['angel_type_id'] == $shift_entry['TID'] && $shift_entry['freeloaded'] == 0) {
|
||||
$taken ++;
|
||||
foreach ($needed_angeltypes_source as $needed_angeltype) {
|
||||
if (isset($needed_angeltypes[$needed_angeltype['SID']])) {
|
||||
$needed_angeltypes[$needed_angeltype['SID']][] = $needed_angeltype;
|
||||
}
|
||||
}
|
||||
|
||||
$needed_angels_count += max(0, $needed_angeltype['count'] - $taken);
|
||||
}
|
||||
if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) {
|
||||
$filtered_shifts[] = $shift;
|
||||
unset($needed_angeltypes_source);
|
||||
unset($shift_entries_source);
|
||||
|
||||
if (
|
||||
in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled())
|
||||
&& in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled())
|
||||
) {
|
||||
return new ShiftCalendarRenderer($shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
|
||||
}
|
||||
if (in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled()) && $taken >= $needed_angels_count) {
|
||||
$filtered_shifts[] = $shift;
|
||||
|
||||
$filtered_shifts = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$needed_angels_count = 0;
|
||||
$taken = 0;
|
||||
foreach ($needed_angeltypes[$shift['SID']] as $needed_angeltype) {
|
||||
$taken = 0;
|
||||
foreach ($shift_entries[$shift['SID']] as $shift_entry) {
|
||||
if ($needed_angeltype['angel_type_id'] == $shift_entry['TID'] && $shift_entry['freeloaded'] == 0) {
|
||||
$taken++;
|
||||
}
|
||||
}
|
||||
|
||||
$needed_angels_count += max(0, $needed_angeltype['count'] - $taken);
|
||||
}
|
||||
if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) {
|
||||
$filtered_shifts[] = $shift;
|
||||
}
|
||||
if (in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled()) && $taken >= $needed_angels_count) {
|
||||
$filtered_shifts[] = $shift;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ShiftCalendarRenderer($filtered_shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
|
||||
}
|
||||
|
||||
?>
|
||||
return new ShiftCalendarRenderer($filtered_shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
|
||||
}
|
||||
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
use Engelsystem\Application;
|
||||
use Engelsystem\Config\Config;
|
||||
use Engelsystem\Exceptions\Handler;
|
||||
use Engelsystem\Exceptions\Handlers\HandlerInterface;
|
||||
|
||||
/**
|
||||
* This file includes all needed functions, connects to the db etc.
|
||||
*/
|
||||
require_once __DIR__ . '/autoload.php';
|
||||
|
||||
|
||||
/**
|
||||
* Include legacy code
|
||||
*/
|
||||
require __DIR__ . '/includes.php';
|
||||
|
||||
|
||||
/**
|
||||
* Initialize and bootstrap the application
|
||||
*/
|
||||
$app = new Application(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..'));
|
||||
$appConfig = $app->make(Config::class);
|
||||
$appConfig->set(require config_path('app.php'));
|
||||
$app->bootstrap($appConfig);
|
||||
|
||||
|
||||
/**
|
||||
* Configure application
|
||||
*/
|
||||
date_default_timezone_set($app->get('config')->get('timezone'));
|
||||
|
||||
if (config('environment') == 'development') {
|
||||
$errorHandler = $app->get('error.handler');
|
||||
$errorHandler->setEnvironment(Handler::ENV_DEVELOPMENT);
|
||||
$app->bind(HandlerInterface::class, 'error.handler.development');
|
||||
ini_set('display_errors', true);
|
||||
error_reporting(E_ALL);
|
||||
} else {
|
||||
ini_set('display_errors', false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check for maintenance
|
||||
*/
|
||||
if ($app->get('config')->get('maintenance')) {
|
||||
echo file_get_contents(__DIR__ . '/../templates/maintenance.html');
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Init translations
|
||||
*/
|
||||
gettext_init();
|
||||
|
||||
|
||||
/**
|
||||
* Init authorization
|
||||
*/
|
||||
load_auth();
|
@ -1,104 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file includes all needed functions, connects to the db etc.
|
||||
*/
|
||||
require_once realpath(__DIR__ . '/../includes/mysqli_provider.php');
|
||||
|
||||
require_once realpath(__DIR__ . '/../includes/sys_auth.php');
|
||||
require_once realpath(__DIR__ . '/../includes/sys_form.php');
|
||||
require_once realpath(__DIR__ . '/../includes/sys_log.php');
|
||||
require_once realpath(__DIR__ . '/../includes/sys_menu.php');
|
||||
require_once realpath(__DIR__ . '/../includes/sys_page.php');
|
||||
require_once realpath(__DIR__ . '/../includes/sys_template.php');
|
||||
|
||||
require_once realpath(__DIR__ . '/../includes/model/AngelType_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/EventConfig_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/LogEntries_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/Message_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/NeededAngelTypes_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/Room_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/ShiftEntry_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/Shifts_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/ShiftsFilter.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/ShiftSignupState.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/ShiftTypes_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/UserAngelTypes_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/UserDriverLicenses_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/UserGroups_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/User_model.php');
|
||||
require_once realpath(__DIR__ . '/../includes/model/ValidationResult.php');
|
||||
|
||||
require_once realpath(__DIR__ . '/../includes/view/AngelTypes_view.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/EventConfig_view.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/Questions_view.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/Rooms_view.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarLane.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarRenderer.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarShiftRenderer.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/ShiftsFilterRenderer.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/Shifts_view.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/ShiftEntry_view.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/ShiftTypes_view.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/UserAngelTypes_view.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/UserDriverLicenses_view.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/UserHintsRenderer.php');
|
||||
require_once realpath(__DIR__ . '/../includes/view/User_view.php');
|
||||
|
||||
require_once realpath(__DIR__ . '/../includes/controller/angeltypes_controller.php');
|
||||
require_once realpath(__DIR__ . '/../includes/controller/event_config_controller.php');
|
||||
require_once realpath(__DIR__ . '/../includes/controller/rooms_controller.php');
|
||||
require_once realpath(__DIR__ . '/../includes/controller/shift_entries_controller.php');
|
||||
require_once realpath(__DIR__ . '/../includes/controller/shifts_controller.php');
|
||||
require_once realpath(__DIR__ . '/../includes/controller/shifttypes_controller.php');
|
||||
require_once realpath(__DIR__ . '/../includes/controller/users_controller.php');
|
||||
require_once realpath(__DIR__ . '/../includes/controller/user_angeltypes_controller.php');
|
||||
require_once realpath(__DIR__ . '/../includes/controller/user_driver_licenses_controller.php');
|
||||
|
||||
require_once realpath(__DIR__ . '/../includes/helper/graph_helper.php');
|
||||
require_once realpath(__DIR__ . '/../includes/helper/internationalization_helper.php');
|
||||
require_once realpath(__DIR__ . '/../includes/helper/message_helper.php');
|
||||
require_once realpath(__DIR__ . '/../includes/helper/error_helper.php');
|
||||
require_once realpath(__DIR__ . '/../includes/helper/email_helper.php');
|
||||
|
||||
require_once realpath(__DIR__ . '/../includes/mailer/shifts_mailer.php');
|
||||
require_once realpath(__DIR__ . '/../includes/mailer/users_mailer.php');
|
||||
|
||||
require_once realpath(__DIR__ . '/../config/config.default.php');
|
||||
if (file_exists(realpath(__DIR__ . '/../config/config.php'))) {
|
||||
require_once realpath(__DIR__ . '/../config/config.php');
|
||||
}
|
||||
|
||||
if ($maintenance_mode) {
|
||||
echo file_get_contents(__DIR__ . '/../public/maintenance.html');
|
||||
die();
|
||||
}
|
||||
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_active.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_arrive.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_free.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_groups.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_import.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_log.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_questions.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_rooms.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_shifts.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_user.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/guest_login.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/user_messages.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/user_myshifts.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/user_news.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/user_questions.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/user_settings.php');
|
||||
require_once realpath(__DIR__ . '/../includes/pages/user_shifts.php');
|
||||
|
||||
require_once realpath(__DIR__ . '/../vendor/parsedown/Parsedown.php');
|
||||
|
||||
session_start();
|
||||
|
||||
gettext_init();
|
||||
|
||||
sql_connect($config['host'], $config['user'], $config['pw'], $config['db']);
|
||||
|
||||
load_auth();
|
||||
|
||||
?>
|
@ -1,26 +1,50 @@
|
||||
<?php
|
||||
|
||||
function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_its_me = false) {
|
||||
global $user;
|
||||
|
||||
if ($not_if_its_me && $user['UID'] == $recipient_user['UID']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
gettext_locale($recipient_user['Sprache']);
|
||||
|
||||
$message = sprintf(_("Hi %s,"), $recipient_user['Nick']) . "\n\n" . _("here is a message for you from the engelsystem:") . "\n\n" . $message . "\n\n" . _("This email is autogenerated and has not to be signed. You got this email because you are registered in the engelsystem.");
|
||||
|
||||
gettext_locale();
|
||||
return engelsystem_email($recipient_user['email'], $title, $message);
|
||||
}
|
||||
/**
|
||||
* @param array $recipient_user
|
||||
* @param string $title
|
||||
* @param string $message
|
||||
* @param bool $not_if_its_me
|
||||
* @return bool
|
||||
*/
|
||||
function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_its_me = false)
|
||||
{
|
||||
global $user;
|
||||
|
||||
if ($not_if_its_me && $user['UID'] == $recipient_user['UID']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
gettext_locale($recipient_user['Sprache']);
|
||||
|
||||
$message = sprintf(_('Hi %s,'), $recipient_user['Nick']) . "\n\n"
|
||||
. _('here is a message for you from the engelsystem:') . "\n\n"
|
||||
. $message . "\n\n"
|
||||
. _('This email is autogenerated and has not to be signed. You got this email because you are registered in the engelsystem.');
|
||||
|
||||
function engelsystem_email($address, $title, $message) {
|
||||
global $no_reply_email;
|
||||
$result = mail($address, $title, $message, sprintf("Content-Type: text/plain; charset=UTF-8\r\nFrom: Engelsystem <%s>", $no_reply_email));
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to send email.');
|
||||
}
|
||||
gettext_locale();
|
||||
|
||||
return engelsystem_email($recipient_user['email'], $title, $message);
|
||||
}
|
||||
|
||||
?>
|
||||
/**
|
||||
* @param string $address
|
||||
* @param string $title
|
||||
* @param string $message
|
||||
* @return bool
|
||||
*/
|
||||
function engelsystem_email($address, $title, $message)
|
||||
{
|
||||
$result = mail(
|
||||
$address,
|
||||
$title,
|
||||
$message,
|
||||
sprintf("Content-Type: text/plain; charset=UTF-8\r\nFrom: Engelsystem <%s>", config('no_reply_email'))
|
||||
);
|
||||
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to send email.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,71 +1,83 @@
|
||||
<?php
|
||||
$locales = [
|
||||
'de_DE.UTF-8' => "Deutsch",
|
||||
'en_US.UTF-8' => "English"
|
||||
];
|
||||
|
||||
$default_locale = 'en_US.UTF-8';
|
||||
|
||||
/**
|
||||
* Return currently active locale
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function locale() {
|
||||
return $_SESSION['locale'];
|
||||
function locale()
|
||||
{
|
||||
return session()->get('locale');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns two letter language code from currently active locale
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function locale_short() {
|
||||
return substr(locale(), 0, 2);
|
||||
function locale_short()
|
||||
{
|
||||
return substr(locale(), 0, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes gettext for internationalization and updates the sessions locale to use for translation.
|
||||
*/
|
||||
function gettext_init() {
|
||||
global $locales, $default_locale;
|
||||
function gettext_init()
|
||||
{
|
||||
$locales = config('locales');
|
||||
$request = request();
|
||||
$session = session();
|
||||
|
||||
if (isset($_REQUEST['set_locale']) && isset($locales[$_REQUEST['set_locale']])) {
|
||||
$_SESSION['locale'] = $_REQUEST['set_locale'];
|
||||
} elseif (! isset($_SESSION['locale'])) {
|
||||
$_SESSION['locale'] = $default_locale;
|
||||
}
|
||||
if ($request->has('set_locale') && isset($locales[$request->input('set_locale')])) {
|
||||
$session->set('locale', $request->input('set_locale'));
|
||||
} elseif (!$session->has('locale')) {
|
||||
$session->set('locale', config('default_locale'));
|
||||
}
|
||||
|
||||
gettext_locale();
|
||||
bindtextdomain('default', realpath(__DIR__ . '/../../locale'));
|
||||
bind_textdomain_codeset('default', 'UTF-8');
|
||||
textdomain('default');
|
||||
gettext_locale();
|
||||
bindtextdomain('default', app('path.lang'));
|
||||
bind_textdomain_codeset('default', 'UTF-8');
|
||||
textdomain('default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Swich gettext locale.
|
||||
*
|
||||
* @param string $locale
|
||||
* @param string $locale
|
||||
*/
|
||||
function gettext_locale($locale = null) {
|
||||
if ($locale == null) {
|
||||
$locale = $_SESSION['locale'];
|
||||
}
|
||||
|
||||
putenv('LC_ALL=' . $locale);
|
||||
setlocale(LC_ALL, $locale);
|
||||
function gettext_locale($locale = null)
|
||||
{
|
||||
if ($locale == null) {
|
||||
$locale = session()->get('locale');
|
||||
}
|
||||
|
||||
putenv('LC_ALL=' . $locale);
|
||||
setlocale(LC_ALL, $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders language selection.
|
||||
*
|
||||
* @return string
|
||||
* @return array
|
||||
*/
|
||||
function make_langselect() {
|
||||
global $locales;
|
||||
$URL = $_SERVER["REQUEST_URI"] . (strpos($_SERVER["REQUEST_URI"], "?") > 0 ? '&' : '?') . "set_locale=";
|
||||
|
||||
$items = [];
|
||||
foreach ($locales as $locale => $name) {
|
||||
$items[] = toolbar_item_link(htmlspecialchars($URL) . $locale, '', '<img src="pic/flag/' . $locale . '.png" alt="' . $name . '" title="' . $name . '"> ' . $name);
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
function make_langselect()
|
||||
{
|
||||
$request = app('request');
|
||||
|
||||
?>
|
||||
$items = [];
|
||||
foreach (config('locales') as $locale => $name) {
|
||||
$url = url($request->getPathInfo(), ['set_locale' => $locale]);
|
||||
|
||||
$items[] = toolbar_item_link(
|
||||
htmlspecialchars($url),
|
||||
'',
|
||||
sprintf(
|
||||
'<img src="%s" alt="%s" title="%2$s"> %2$s',
|
||||
url('pic/flag/' . $locale . '.png'),
|
||||
$name
|
||||
)
|
||||
);
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Include legacy code
|
||||
*/
|
||||
$includeFiles = [
|
||||
__DIR__ . '/../includes/sys_auth.php',
|
||||
__DIR__ . '/../includes/sys_form.php',
|
||||
__DIR__ . '/../includes/sys_log.php',
|
||||
__DIR__ . '/../includes/sys_menu.php',
|
||||
__DIR__ . '/../includes/sys_page.php',
|
||||
__DIR__ . '/../includes/sys_template.php',
|
||||
|
||||
__DIR__ . '/../includes/model/AngelType_model.php',
|
||||
__DIR__ . '/../includes/model/EventConfig_model.php',
|
||||
__DIR__ . '/../includes/model/LogEntries_model.php',
|
||||
__DIR__ . '/../includes/model/Message_model.php',
|
||||
__DIR__ . '/../includes/model/NeededAngelTypes_model.php',
|
||||
__DIR__ . '/../includes/model/Room_model.php',
|
||||
__DIR__ . '/../includes/model/ShiftEntry_model.php',
|
||||
__DIR__ . '/../includes/model/Shifts_model.php',
|
||||
__DIR__ . '/../includes/model/ShiftsFilter.php',
|
||||
__DIR__ . '/../includes/model/ShiftSignupState.php',
|
||||
__DIR__ . '/../includes/model/ShiftTypes_model.php',
|
||||
__DIR__ . '/../includes/model/UserAngelTypes_model.php',
|
||||
__DIR__ . '/../includes/model/UserDriverLicenses_model.php',
|
||||
__DIR__ . '/../includes/model/UserGroups_model.php',
|
||||
__DIR__ . '/../includes/model/User_model.php',
|
||||
__DIR__ . '/../includes/model/ValidationResult.php',
|
||||
|
||||
__DIR__ . '/../includes/view/AngelTypes_view.php',
|
||||
__DIR__ . '/../includes/view/EventConfig_view.php',
|
||||
__DIR__ . '/../includes/view/Questions_view.php',
|
||||
__DIR__ . '/../includes/view/Rooms_view.php',
|
||||
__DIR__ . '/../includes/view/ShiftCalendarLane.php',
|
||||
__DIR__ . '/../includes/view/ShiftCalendarRenderer.php',
|
||||
__DIR__ . '/../includes/view/ShiftCalendarShiftRenderer.php',
|
||||
__DIR__ . '/../includes/view/ShiftsFilterRenderer.php',
|
||||
__DIR__ . '/../includes/view/Shifts_view.php',
|
||||
__DIR__ . '/../includes/view/ShiftEntry_view.php',
|
||||
__DIR__ . '/../includes/view/ShiftTypes_view.php',
|
||||
__DIR__ . '/../includes/view/UserAngelTypes_view.php',
|
||||
__DIR__ . '/../includes/view/UserDriverLicenses_view.php',
|
||||
__DIR__ . '/../includes/view/UserHintsRenderer.php',
|
||||
__DIR__ . '/../includes/view/User_view.php',
|
||||
|
||||
__DIR__ . '/../includes/controller/angeltypes_controller.php',
|
||||
__DIR__ . '/../includes/controller/event_config_controller.php',
|
||||
__DIR__ . '/../includes/controller/rooms_controller.php',
|
||||
__DIR__ . '/../includes/controller/shift_entries_controller.php',
|
||||
__DIR__ . '/../includes/controller/shifts_controller.php',
|
||||
__DIR__ . '/../includes/controller/shifttypes_controller.php',
|
||||
__DIR__ . '/../includes/controller/users_controller.php',
|
||||
__DIR__ . '/../includes/controller/user_angeltypes_controller.php',
|
||||
__DIR__ . '/../includes/controller/user_driver_licenses_controller.php',
|
||||
|
||||
__DIR__ . '/../includes/helper/graph_helper.php',
|
||||
__DIR__ . '/../includes/helper/internationalization_helper.php',
|
||||
__DIR__ . '/../includes/helper/message_helper.php',
|
||||
__DIR__ . '/../includes/helper/error_helper.php',
|
||||
__DIR__ . '/../includes/helper/email_helper.php',
|
||||
|
||||
__DIR__ . '/../includes/mailer/shifts_mailer.php',
|
||||
__DIR__ . '/../includes/mailer/users_mailer.php',
|
||||
|
||||
__DIR__ . '/../includes/pages/admin_active.php',
|
||||
__DIR__ . '/../includes/pages/admin_arrive.php',
|
||||
__DIR__ . '/../includes/pages/admin_free.php',
|
||||
__DIR__ . '/../includes/pages/admin_groups.php',
|
||||
__DIR__ . '/../includes/pages/admin_import.php',
|
||||
__DIR__ . '/../includes/pages/admin_log.php',
|
||||
__DIR__ . '/../includes/pages/admin_questions.php',
|
||||
__DIR__ . '/../includes/pages/admin_rooms.php',
|
||||
__DIR__ . '/../includes/pages/admin_shifts.php',
|
||||
__DIR__ . '/../includes/pages/admin_user.php',
|
||||
__DIR__ . '/../includes/pages/guest_login.php',
|
||||
__DIR__ . '/../includes/pages/user_messages.php',
|
||||
__DIR__ . '/../includes/pages/user_myshifts.php',
|
||||
__DIR__ . '/../includes/pages/user_news.php',
|
||||
__DIR__ . '/../includes/pages/user_questions.php',
|
||||
__DIR__ . '/../includes/pages/user_settings.php',
|
||||
__DIR__ . '/../includes/pages/user_shifts.php',
|
||||
];
|
||||
foreach ($includeFiles as $file) {
|
||||
require_once realpath($file);
|
||||
}
|
@ -1,104 +1,129 @@
|
||||
<?php
|
||||
|
||||
function mail_shift_change($old_shift, $new_shift) {
|
||||
$users = ShiftEntries_by_shift($old_shift["SID"]);
|
||||
$old_room = Room($old_shift["RID"]);
|
||||
$new_room = Room($new_shift["RID"]);
|
||||
|
||||
$noticable_changes = false;
|
||||
|
||||
$message = _("A Shift you are registered on has changed:");
|
||||
$message .= "\n";
|
||||
|
||||
if ($old_shift["name"] != $new_shift["name"]) {
|
||||
$message .= sprintf(_("* Shift type changed from %s to %s"), $old_shift["name"], $new_shift["name"]) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
|
||||
if ($old_shift["title"] != $new_shift["title"]) {
|
||||
$message .= sprintf(_("* Shift title changed from %s to %s"), $old_shift["title"], $new_shift["title"]) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
|
||||
if ($old_shift["start"] != $new_shift["start"]) {
|
||||
$message .= sprintf(_("* Shift Start changed from %s to %s"), date("Y-m-d H:i", $old_shift["start"]), date("Y-m-d H:i", $new_shift["start"])) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
|
||||
if ($old_shift["end"] != $new_shift["end"]) {
|
||||
$message .= sprintf(_("* Shift End changed from %s to %s"), date("Y-m-d H:i", $old_shift["end"]), date("Y-m-d H:i", $new_shift["end"])) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
|
||||
if ($old_shift["RID"] != $new_shift["RID"]) {
|
||||
$message .= sprintf(_("* Shift Location changed from %s to %s"), $old_room["Name"], $new_room["Name"]) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
|
||||
if (! $noticable_changes) {
|
||||
// There are no changes worth sending an E-Mail
|
||||
return;
|
||||
}
|
||||
|
||||
$message .= "\n";
|
||||
$message .= _("The updated Shift:") . "\n";
|
||||
|
||||
$message .= $new_shift["name"] . "\n";
|
||||
$message .= $new_shift["title"] . "\n";
|
||||
$message .= date("Y-m-d H:i", $new_shift["start"]) . " - " . date("H:i", $new_shift["end"]) . "\n";
|
||||
$message .= $new_room["Name"] . "\n";
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($user["email_shiftinfo"]) {
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Your Shift has changed"), $message, true);
|
||||
/**
|
||||
* @param array $old_shift
|
||||
* @param array $new_shift
|
||||
*/
|
||||
function mail_shift_change($old_shift, $new_shift)
|
||||
{
|
||||
$users = ShiftEntries_by_shift($old_shift['SID']);
|
||||
$old_room = Room($old_shift['RID']);
|
||||
$new_room = Room($new_shift['RID']);
|
||||
|
||||
$noticeable_changes = false;
|
||||
|
||||
$message = _('A Shift you are registered on has changed:');
|
||||
$message .= "\n";
|
||||
|
||||
if ($old_shift['name'] != $new_shift['name']) {
|
||||
$message .= sprintf(_('* Shift type changed from %s to %s'), $old_shift['name'], $new_shift['name']) . "\n";
|
||||
$noticeable_changes = true;
|
||||
}
|
||||
|
||||
if ($old_shift['title'] != $new_shift['title']) {
|
||||
$message .= sprintf(_('* Shift title changed from %s to %s'), $old_shift['title'], $new_shift['title']) . "\n";
|
||||
$noticeable_changes = true;
|
||||
}
|
||||
|
||||
if ($old_shift['start'] != $new_shift['start']) {
|
||||
$message .= sprintf(
|
||||
_('* Shift Start changed from %s to %s'),
|
||||
date('Y-m-d H:i', $old_shift['start']),
|
||||
date('Y-m-d H:i', $new_shift['start'])
|
||||
) . "\n";
|
||||
$noticeable_changes = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mail_shift_delete($shift) {
|
||||
$users = ShiftEntries_by_shift($shift["SID"]);
|
||||
$room = Room($shift["RID"]);
|
||||
|
||||
$message = _("A Shift you are registered on was deleted:") . "\n";
|
||||
|
||||
$message .= $shift["name"] . "\n";
|
||||
$message .= $shift["title"] . "\n";
|
||||
$message .= date("Y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
|
||||
$message .= $room["Name"] . "\n";
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($user["email_shiftinfo"]) {
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Your Shift was deleted"), $message, true);
|
||||
if ($old_shift['end'] != $new_shift['end']) {
|
||||
$message .= sprintf(
|
||||
_('* Shift End changed from %s to %s'),
|
||||
date('Y-m-d H:i', $old_shift['end']),
|
||||
date('Y-m-d H:i', $new_shift['end'])
|
||||
) . "\n";
|
||||
$noticeable_changes = true;
|
||||
}
|
||||
|
||||
if ($old_shift['RID'] != $new_shift['RID']) {
|
||||
$message .= sprintf(_('* Shift Location changed from %s to %s'), $old_room['Name'], $new_room['Name']) . "\n";
|
||||
$noticeable_changes = true;
|
||||
}
|
||||
|
||||
if (!$noticeable_changes) {
|
||||
// There are no changes worth sending an E-Mail
|
||||
return;
|
||||
}
|
||||
|
||||
$message .= "\n";
|
||||
$message .= _('The updated Shift:') . "\n";
|
||||
|
||||
$message .= $new_shift['name'] . "\n";
|
||||
$message .= $new_shift['title'] . "\n";
|
||||
$message .= date('Y-m-d H:i', $new_shift['start']) . ' - ' . date('H:i', $new_shift['end']) . "\n";
|
||||
$message .= $new_room['Name'] . "\n";
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($user['email_shiftinfo']) {
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _('Your Shift has changed'), $message, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mail_shift_assign($user, $shift) {
|
||||
if ($user["email_shiftinfo"]) {
|
||||
$room = Room($shift["RID"]);
|
||||
|
||||
$message = _("You have been assigned to a Shift:") . "\n";
|
||||
$message .= $shift["name"] . "\n";
|
||||
$message .= $shift["title"] . "\n";
|
||||
$message .= date("Y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
|
||||
$message .= $room["Name"] . "\n";
|
||||
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Assigned to Shift"), $message, true);
|
||||
}
|
||||
/**
|
||||
* @param array $shift
|
||||
*/
|
||||
function mail_shift_delete($shift)
|
||||
{
|
||||
$users = ShiftEntries_by_shift($shift['SID']);
|
||||
$room = Room($shift['RID']);
|
||||
|
||||
$message = _('A Shift you are registered on was deleted:') . "\n";
|
||||
|
||||
$message .= $shift['name'] . "\n";
|
||||
$message .= $shift['title'] . "\n";
|
||||
$message .= date('Y-m-d H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']) . "\n";
|
||||
$message .= $room['Name'] . "\n";
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($user['email_shiftinfo']) {
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _('Your Shift was deleted'), $message, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mail_shift_removed($user, $shift) {
|
||||
if ($user["email_shiftinfo"]) {
|
||||
$room = Room($shift["RID"]);
|
||||
|
||||
$message = _("You have been removed from a Shift:") . "\n";
|
||||
$message .= $shift["name"] . "\n";
|
||||
$message .= $shift["title"] . "\n";
|
||||
$message .= date("Y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
|
||||
$message .= $room["Name"] . "\n";
|
||||
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Removed from Shift"), $message, true);
|
||||
}
|
||||
/**
|
||||
* @param array $user
|
||||
* @param array $shift
|
||||
*/
|
||||
function mail_shift_assign($user, $shift)
|
||||
{
|
||||
if (!$user['email_shiftinfo']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$room = Room($shift['RID']);
|
||||
|
||||
$message = _('You have been assigned to a Shift:') . "\n";
|
||||
$message .= $shift['name'] . "\n";
|
||||
$message .= $shift['title'] . "\n";
|
||||
$message .= date('Y-m-d H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']) . "\n";
|
||||
$message .= $room['Name'] . "\n";
|
||||
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _('Assigned to Shift'), $message, true);
|
||||
}
|
||||
|
||||
?>
|
||||
function mail_shift_removed($user, $shift)
|
||||
{
|
||||
if (!$user['email_shiftinfo']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$room = Room($shift['RID']);
|
||||
|
||||
$message = _('You have been removed from a Shift:') . "\n";
|
||||
$message .= $shift['name'] . "\n";
|
||||
$message .= $shift['title'] . "\n";
|
||||
$message .= date('Y-m-d H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']) . "\n";
|
||||
$message .= $room['Name'] . "\n";
|
||||
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _('Removed from Shift'), $message, true);
|
||||
}
|
||||
|
@ -1,9 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @param User $user_source
|
||||
* @param array $user
|
||||
* @return bool
|
||||
*/
|
||||
function mail_user_delete($user) {
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Your account has been deleted"), _("Your angelsystem account has been deleted. If you have any questions regarding your account deletion, please contact heaven."));
|
||||
function mail_user_delete($user)
|
||||
{
|
||||
return engelsystem_email_to_user(
|
||||
$user,
|
||||
'[engelsystem] ' . _('Your account has been deleted'),
|
||||
_('Your angelsystem account has been deleted. If you have any questions regarding your account deletion, please contact heaven.')
|
||||
);
|
||||
}
|
||||
?>
|
@ -1,69 +1,84 @@
|
||||
<?php
|
||||
|
||||
use Engelsystem\Database\DB;
|
||||
|
||||
/**
|
||||
* Delete a shift type.
|
||||
*
|
||||
* @param int $shifttype_id
|
||||
*/
|
||||
function ShiftType_delete($shifttype_id) {
|
||||
return sql_query("DELETE FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
|
||||
function ShiftType_delete($shifttype_id)
|
||||
{
|
||||
DB::delete('DELETE FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a shift type.
|
||||
*
|
||||
* @param int $shifttype_id
|
||||
* @param string $name
|
||||
* @param int $angeltype_id
|
||||
* @param string $description
|
||||
* @param int $shifttype_id
|
||||
* @param string $name
|
||||
* @param int $angeltype_id
|
||||
* @param string $description
|
||||
*/
|
||||
function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) {
|
||||
return sql_query("UPDATE `ShiftTypes` SET
|
||||
`name`='" . sql_escape($name) . "',
|
||||
`angeltype_id`=" . sql_null($angeltype_id) . ",
|
||||
`description`='" . sql_escape($description) . "'
|
||||
WHERE `id`='" . sql_escape($shifttype_id) . "'");
|
||||
function ShiftType_update($shifttype_id, $name, $angeltype_id, $description)
|
||||
{
|
||||
DB::update('
|
||||
UPDATE `ShiftTypes` SET
|
||||
`name`=?,
|
||||
`angeltype_id`=?,
|
||||
`description`=?
|
||||
WHERE `id`=?
|
||||
',
|
||||
[
|
||||
$name,
|
||||
$angeltype_id,
|
||||
$description,
|
||||
$shifttype_id,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a shift type.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $angeltype_id
|
||||
* @param string $description
|
||||
* @return new shifttype id
|
||||
* @param string $name
|
||||
* @param int $angeltype_id
|
||||
* @param string $description
|
||||
* @return int|false new shifttype id
|
||||
*/
|
||||
function ShiftType_create($name, $angeltype_id, $description) {
|
||||
$result = sql_query("INSERT INTO `ShiftTypes` SET
|
||||
`name`='" . sql_escape($name) . "',
|
||||
`angeltype_id`=" . sql_null($angeltype_id) . ",
|
||||
`description`='" . sql_escape($description) . "'");
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return sql_id();
|
||||
function ShiftType_create($name, $angeltype_id, $description)
|
||||
{
|
||||
DB::insert('
|
||||
INSERT INTO `ShiftTypes` (`name`, `angeltype_id`, `description`)
|
||||
VALUES(?, ?, ?)
|
||||
',
|
||||
[
|
||||
$name,
|
||||
$angeltype_id,
|
||||
$description
|
||||
]
|
||||
);
|
||||
|
||||
return DB::getPdo()->lastInsertId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a shift type by id.
|
||||
*
|
||||
* @param int $shifttype_id
|
||||
* @param int $shifttype_id
|
||||
* @return array|null
|
||||
*/
|
||||
function ShiftType($shifttype_id) {
|
||||
$shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shift type.');
|
||||
}
|
||||
if ($shifttype == null) {
|
||||
return null;
|
||||
}
|
||||
return $shifttype[0];
|
||||
function ShiftType($shifttype_id)
|
||||
{
|
||||
return DB::selectOne('SELECT * FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all shift types.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function ShiftTypes() {
|
||||
return sql_select("SELECT * FROM `ShiftTypes` ORDER BY `name`");
|
||||
function ShiftTypes()
|
||||
{
|
||||
return DB::select('SELECT * FROM `ShiftTypes` ORDER BY `name`');
|
||||
}
|
||||
|
||||
?>
|
@ -1,432 +1,615 @@
|
||||
<?php
|
||||
|
||||
use Engelsystem\Database\DB;
|
||||
use Engelsystem\ShiftsFilter;
|
||||
use Engelsystem\ShiftSignupState;
|
||||
|
||||
function Shifts_by_room($room) {
|
||||
$result = sql_select("SELECT * FROM `Shifts` WHERE `RID`=" . sql_escape($room['RID']) . " ORDER BY `start`");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load shifts.");
|
||||
}
|
||||
return $result;
|
||||
/**
|
||||
* @param array $angeltype
|
||||
* @return array
|
||||
*/
|
||||
function Shifts_by_angeltype($angeltype) {
|
||||
return DB::select('
|
||||
SELECT DISTINCT `Shifts`.* FROM `Shifts`
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id` = `Shifts`.`SID`
|
||||
WHERE `NeededAngelTypes`.`angel_type_id` = ?
|
||||
AND `NeededAngelTypes`.`count` > 0
|
||||
AND `Shifts`.`PSID` IS NULL
|
||||
|
||||
UNION
|
||||
|
||||
SELECT DISTINCT `Shifts`.* FROM `Shifts`
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`room_id` = `Shifts`.`RID`
|
||||
WHERE `NeededAngelTypes`.`angel_type_id` = ?
|
||||
AND `NeededAngelTypes`.`count` > 0
|
||||
AND NOT `Shifts`.`PSID` IS NULL
|
||||
', [$angeltype['id'], $angeltype['id']]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $room
|
||||
* @return array
|
||||
*/
|
||||
function Shifts_by_room($room)
|
||||
{
|
||||
return DB::select('SELECT * FROM `Shifts` WHERE `RID`=? ORDER BY `start`', [$room['RID']]);
|
||||
}
|
||||
|
||||
function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
|
||||
$SQL = "SELECT * FROM (
|
||||
SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`
|
||||
/**
|
||||
* @param ShiftsFilter $shiftsFilter
|
||||
* @return array[]
|
||||
*/
|
||||
function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
|
||||
{
|
||||
$sql = 'SELECT * FROM (
|
||||
SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` AS `room_name`
|
||||
FROM `Shifts`
|
||||
JOIN `Room` USING (`RID`)
|
||||
JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id`
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
|
||||
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
|
||||
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
|
||||
AND `NeededAngelTypes`.`angel_type_id` IN (" . implode(',', $shiftsFilter->getTypes()) . ")
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id` = `Shifts`.`SID`
|
||||
WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ')
|
||||
AND `start` BETWEEN ? AND ?
|
||||
AND `NeededAngelTypes`.`angel_type_id` IN (' . implode(',', $shiftsFilter->getTypes()) . ')
|
||||
AND `NeededAngelTypes`.`count` > 0
|
||||
AND `Shifts`.`PSID` IS NULL
|
||||
|
||||
|
||||
UNION
|
||||
|
||||
SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`
|
||||
|
||||
SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` AS `room_name`
|
||||
FROM `Shifts`
|
||||
JOIN `Room` USING (`RID`)
|
||||
JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id`
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`room_id`=`Shifts`.`RID`
|
||||
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
|
||||
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
|
||||
AND `NeededAngelTypes`.`angel_type_id` IN (" . implode(',', $shiftsFilter->getTypes()) . ")
|
||||
WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ')
|
||||
AND `start` BETWEEN ? AND ?
|
||||
AND `NeededAngelTypes`.`angel_type_id` IN (' . implode(',', $shiftsFilter->getTypes()) . ')
|
||||
AND `NeededAngelTypes`.`count` > 0
|
||||
AND NOT `Shifts`.`PSID` IS NULL) as tmp_shifts
|
||||
|
||||
ORDER BY `start`";
|
||||
$result = sql_select($SQL);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load shifts by filter.");
|
||||
}
|
||||
return $result;
|
||||
AND NOT `Shifts`.`PSID` IS NULL) AS tmp_shifts
|
||||
|
||||
ORDER BY `start`';
|
||||
|
||||
return DB::select(
|
||||
$sql,
|
||||
[
|
||||
$shiftsFilter->getStartTime(),
|
||||
$shiftsFilter->getEndTime(),
|
||||
$shiftsFilter->getStartTime(),
|
||||
$shiftsFilter->getEndTime(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
|
||||
$SQL = "SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
|
||||
/**
|
||||
* @param ShiftsFilter $shiftsFilter
|
||||
* @return array[]
|
||||
*/
|
||||
function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
|
||||
{
|
||||
$sql = '
|
||||
SELECT
|
||||
`NeededAngelTypes`.*,
|
||||
`Shifts`.`SID`,
|
||||
`AngelTypes`.`id`,
|
||||
`AngelTypes`.`name`,
|
||||
`AngelTypes`.`restricted`,
|
||||
`AngelTypes`.`no_self_signup`
|
||||
FROM `Shifts`
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
|
||||
JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
|
||||
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
|
||||
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
|
||||
WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ')
|
||||
AND `start` BETWEEN ? AND ?
|
||||
AND `Shifts`.`PSID` IS NULL
|
||||
|
||||
UNION
|
||||
|
||||
SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
|
||||
SELECT
|
||||
`NeededAngelTypes`.*,
|
||||
`Shifts`.`SID`,
|
||||
`AngelTypes`.`id`,
|
||||
`AngelTypes`.`name`,
|
||||
`AngelTypes`.`restricted`,
|
||||
`AngelTypes`.`no_self_signup`
|
||||
FROM `Shifts`
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`room_id`=`Shifts`.`RID`
|
||||
JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
|
||||
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
|
||||
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
|
||||
AND NOT `Shifts`.`PSID` IS NULL";
|
||||
$result = sql_select($SQL);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load needed angeltypes by filter.");
|
||||
}
|
||||
return $result;
|
||||
WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ')
|
||||
AND `start` BETWEEN ? AND ?
|
||||
AND NOT `Shifts`.`PSID` IS NULL';
|
||||
|
||||
return DB::select(
|
||||
$sql,
|
||||
[
|
||||
$shiftsFilter->getStartTime(),
|
||||
$shiftsFilter->getEndTime(),
|
||||
$shiftsFilter->getStartTime(),
|
||||
$shiftsFilter->getEndTime(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) {
|
||||
$result = sql_select("SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
|
||||
FROM `Shifts`
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
|
||||
JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
|
||||
WHERE `Shifts`.`SID`=" . sql_escape($shift['SID']) . "
|
||||
AND `AngelTypes`.`id`=" . sql_escape($angeltype['id']) . "
|
||||
AND `Shifts`.`PSID` IS NULL
|
||||
|
||||
UNION
|
||||
|
||||
SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
|
||||
FROM `Shifts`
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`room_id`=`Shifts`.`RID`
|
||||
JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
|
||||
WHERE `Shifts`.`SID`=" . sql_escape($shift['SID']) . "
|
||||
AND `AngelTypes`.`id`=" . sql_escape($angeltype['id']) . "
|
||||
AND NOT `Shifts`.`PSID` IS NULL");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load needed angeltypes by filter.");
|
||||
}
|
||||
if (count($result) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $result[0];
|
||||
/**
|
||||
* @param array $shift
|
||||
* @param array $angeltype
|
||||
* @return array|null
|
||||
*/
|
||||
function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype)
|
||||
{
|
||||
return DB::selectOne('
|
||||
SELECT
|
||||
`NeededAngelTypes`.*,
|
||||
`Shifts`.`SID`,
|
||||
`AngelTypes`.`id`,
|
||||
`AngelTypes`.`name`,
|
||||
`AngelTypes`.`restricted`,
|
||||
`AngelTypes`.`no_self_signup`
|
||||
FROM `Shifts`
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
|
||||
JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
|
||||
WHERE `Shifts`.`SID`=?
|
||||
AND `AngelTypes`.`id`=?
|
||||
AND `Shifts`.`PSID` IS NULL
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
`NeededAngelTypes`.*,
|
||||
`Shifts`.`SID`,
|
||||
`AngelTypes`.`id`,
|
||||
`AngelTypes`.`name`,
|
||||
`AngelTypes`.`restricted`,
|
||||
`AngelTypes`.`no_self_signup`
|
||||
FROM `Shifts`
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`room_id`=`Shifts`.`RID`
|
||||
JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
|
||||
WHERE `Shifts`.`SID`=?
|
||||
AND `AngelTypes`.`id`=?
|
||||
AND NOT `Shifts`.`PSID` IS NULL
|
||||
',
|
||||
[
|
||||
$shift['SID'],
|
||||
$angeltype['id'],
|
||||
$shift['SID'],
|
||||
$angeltype['id']
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
|
||||
$SQL = "SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded`
|
||||
/**
|
||||
* @param ShiftsFilter $shiftsFilter
|
||||
* @return array
|
||||
*/
|
||||
function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
|
||||
{
|
||||
$sql = '
|
||||
SELECT
|
||||
`User`.`Nick`,
|
||||
`User`.`email`,
|
||||
`User`.`email_shiftinfo`,
|
||||
`User`.`Sprache`,
|
||||
`User`.`Gekommen`,
|
||||
`ShiftEntry`.`UID`,
|
||||
`ShiftEntry`.`TID`,
|
||||
`ShiftEntry`.`SID`,
|
||||
`ShiftEntry`.`Comment`,
|
||||
`ShiftEntry`.`freeloaded`
|
||||
FROM `Shifts`
|
||||
JOIN `ShiftEntry` ON `ShiftEntry`.`SID`=`Shifts`.`SID`
|
||||
JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
|
||||
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
|
||||
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
|
||||
ORDER BY `Shifts`.`start`";
|
||||
$result = sql_select($SQL);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load shift entries by filter.");
|
||||
}
|
||||
return $result;
|
||||
WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ')
|
||||
AND `start` BETWEEN ? AND ?
|
||||
ORDER BY `Shifts`.`start`';
|
||||
return DB::select(
|
||||
$sql,
|
||||
[
|
||||
$shiftsFilter->getStartTime(),
|
||||
$shiftsFilter->getEndTime(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a shift collides with other shifts (in time).
|
||||
*
|
||||
* @param Shift $shift
|
||||
* @param array<Shift> $shifts
|
||||
* @param array $shift
|
||||
* @param array $shifts
|
||||
* @return bool
|
||||
*/
|
||||
function Shift_collides($shift, $shifts) {
|
||||
foreach ($shifts as $other_shift) {
|
||||
if ($shift['SID'] != $other_shift['SID']) {
|
||||
if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) {
|
||||
return true;
|
||||
}
|
||||
function Shift_collides($shift, $shifts)
|
||||
{
|
||||
foreach ($shifts as $other_shift) {
|
||||
if ($shift['SID'] != $other_shift['SID']) {
|
||||
if (!($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of needed angels/free shift entries for an angeltype.
|
||||
*
|
||||
* @param array $needed_angeltype
|
||||
* @param array[] $shift_entries
|
||||
* @return int
|
||||
*/
|
||||
function Shift_free_entries($needed_angeltype, $shift_entries) {
|
||||
$taken = 0;
|
||||
foreach ($shift_entries as $shift_entry) {
|
||||
if ($shift_entry['freeloaded'] == 0) {
|
||||
$taken ++;
|
||||
function Shift_free_entries($needed_angeltype, $shift_entries)
|
||||
{
|
||||
$taken = 0;
|
||||
foreach ($shift_entries as $shift_entry) {
|
||||
if ($shift_entry['freeloaded'] == 0) {
|
||||
$taken++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return max(0, $needed_angeltype['count'] - $taken);
|
||||
return max(0, $needed_angeltype['count'] - $taken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if shift signup is allowed from the end users point of view (no admin like privileges)
|
||||
*
|
||||
* @param Shift $shift
|
||||
* The shift
|
||||
* @param AngelType $angeltype
|
||||
* The angeltype to which the user wants to sign up
|
||||
* @param array<Shift> $user_shifts
|
||||
* List of the users shifts
|
||||
* @param boolean $angeltype_supporter
|
||||
* True, if the user has angeltype supporter rights for the angeltype, which enables him to sign somebody up for the shift.
|
||||
* @param array $user
|
||||
* @param array $shift The shift
|
||||
* @param array $angeltype The angeltype to which the user wants to sign up
|
||||
* @param array|null $user_angeltype
|
||||
* @param array|null $user_shifts List of the users shifts
|
||||
* @param array $needed_angeltype
|
||||
* @param array[] $shift_entries
|
||||
* @return ShiftSignupState
|
||||
*/
|
||||
function Shift_signup_allowed_angel($user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries) {
|
||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||
|
||||
if ($user['Gekommen'] == 0) {
|
||||
return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
|
||||
}
|
||||
|
||||
if ($user_shifts == null) {
|
||||
$user_shifts = Shifts_by_user($user);
|
||||
}
|
||||
|
||||
$signed_up = false;
|
||||
foreach ($user_shifts as $user_shift) {
|
||||
if ($user_shift['SID'] == $shift['SID']) {
|
||||
$signed_up = true;
|
||||
break;
|
||||
function Shift_signup_allowed_angel(
|
||||
$user,
|
||||
$shift,
|
||||
$angeltype,
|
||||
$user_angeltype,
|
||||
$user_shifts,
|
||||
$needed_angeltype,
|
||||
$shift_entries
|
||||
) {
|
||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||
|
||||
if (config('signup_requires_arrival') && !$user['Gekommen']) {
|
||||
return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
|
||||
}
|
||||
|
||||
if ($user_shifts == null) {
|
||||
$user_shifts = Shifts_by_user($user);
|
||||
}
|
||||
|
||||
$signed_up = false;
|
||||
foreach ($user_shifts as $user_shift) {
|
||||
if ($user_shift['SID'] == $shift['SID']) {
|
||||
$signed_up = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($signed_up) {
|
||||
// you cannot join if you already singed up for this shift
|
||||
return new ShiftSignupState(ShiftSignupState::SIGNED_UP, $free_entries);
|
||||
}
|
||||
|
||||
if (time() > $shift['start']) {
|
||||
// you can only join if the shift is in future
|
||||
return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
|
||||
}
|
||||
if ($free_entries == 0) {
|
||||
// you cannot join if shift is full
|
||||
return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
|
||||
}
|
||||
|
||||
if ($user_angeltype == null) {
|
||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||
}
|
||||
|
||||
if (
|
||||
$user_angeltype == null
|
||||
|| ($angeltype['no_self_signup'] == 1 && $user_angeltype != null)
|
||||
|| ($angeltype['restricted'] == 1 && $user_angeltype != null && !isset($user_angeltype['confirm_user_id']))
|
||||
) {
|
||||
// you cannot join if user is not of this angel type
|
||||
// you cannot join if you are not confirmed
|
||||
// you cannot join if angeltype has no self signup
|
||||
|
||||
return new ShiftSignupState(ShiftSignupState::ANGELTYPE, $free_entries);
|
||||
}
|
||||
|
||||
if (Shift_collides($shift, $user_shifts)) {
|
||||
// you cannot join if user alread joined a parallel or this shift
|
||||
return new ShiftSignupState(ShiftSignupState::COLLIDES, $free_entries);
|
||||
}
|
||||
}
|
||||
|
||||
if ($signed_up) {
|
||||
// you cannot join if you already singed up for this shift
|
||||
return new ShiftSignupState(ShiftSignupState::SIGNED_UP, $free_entries);
|
||||
}
|
||||
|
||||
if (time() > $shift['start']) {
|
||||
// you can only join if the shift is in future
|
||||
return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
|
||||
}
|
||||
if ($free_entries == 0) {
|
||||
// you cannot join if shift is full
|
||||
return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
|
||||
}
|
||||
|
||||
if ($user_angeltype == null) {
|
||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||
}
|
||||
|
||||
if ($user_angeltype == null || ($angeltype['no_self_signup'] == 1 && $user_angeltype != null) || ($angeltype['restricted'] == 1 && $user_angeltype != null && ! isset($user_angeltype['confirm_user_id']))) {
|
||||
// you cannot join if user is not of this angel type
|
||||
// you cannot join if you are not confirmed
|
||||
// you cannot join if angeltype has no self signup
|
||||
|
||||
return new ShiftSignupState(ShiftSignupState::ANGELTYPE, $free_entries);
|
||||
}
|
||||
|
||||
if (Shift_collides($shift, $user_shifts)) {
|
||||
// you cannot join if user alread joined a parallel or this shift
|
||||
return new ShiftSignupState(ShiftSignupState::COLLIDES, $free_entries);
|
||||
}
|
||||
|
||||
// Hooray, shift is free for you!
|
||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
||||
|
||||
// Hooray, shift is free for you!
|
||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an angeltype supporter can sign up a user to a shift.
|
||||
*
|
||||
* @param array $needed_angeltype
|
||||
* @param array[] $shift_entries
|
||||
* @return ShiftSignupState
|
||||
*/
|
||||
function Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, $shift_entries) {
|
||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||
if ($free_entries == 0) {
|
||||
return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
|
||||
}
|
||||
|
||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
||||
function Shift_signup_allowed_angeltype_supporter($needed_angeltype, $shift_entries)
|
||||
{
|
||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||
if ($free_entries == 0) {
|
||||
return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
|
||||
}
|
||||
|
||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an admin can sign up a user to a shift.
|
||||
*
|
||||
* @param Shift $shift
|
||||
* The shift
|
||||
* @param AngelType $angeltype
|
||||
* The angeltype to which the user wants to sign up
|
||||
* @param array $needed_angeltype
|
||||
* @param array[] $shift_entries
|
||||
* @return ShiftSignupState
|
||||
*/
|
||||
function Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries) {
|
||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||
|
||||
if ($free_entries == 0) {
|
||||
// User shift admins may join anybody in every shift
|
||||
return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries);
|
||||
}
|
||||
|
||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
||||
function Shift_signup_allowed_admin($needed_angeltype, $shift_entries)
|
||||
{
|
||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||
|
||||
if ($free_entries == 0) {
|
||||
// User shift admins may join anybody in every shift
|
||||
return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries);
|
||||
}
|
||||
|
||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an angel can sign up for given shift.
|
||||
*
|
||||
* @param Shift $shift
|
||||
* The shift
|
||||
* @param AngelType $angeltype
|
||||
* The angeltype to which the user wants to sign up
|
||||
* @param array<Shift> $user_shifts
|
||||
* List of the users shifts
|
||||
* @param array $signup_user
|
||||
* @param array $shift The shift
|
||||
* @param array $angeltype The angeltype to which the user wants to sign up
|
||||
* @param array|null $user_angeltype
|
||||
* @param array|null $user_shifts List of the users shifts
|
||||
* @param array $needed_angeltype
|
||||
* @param array[] $shift_entries
|
||||
* @return ShiftSignupState
|
||||
*/
|
||||
function Shift_signup_allowed($signup_user, $shift, $angeltype, $user_angeltype = null, $user_shifts = null, $needed_angeltype, $shift_entries) {
|
||||
global $user, $privileges;
|
||||
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
return Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries);
|
||||
}
|
||||
|
||||
if (in_array('shiftentry_edit_angeltype_supporter', $privileges) && User_is_AngelType_supporter($user, $angeltype)) {
|
||||
return Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, $shift_entries);
|
||||
}
|
||||
|
||||
return Shift_signup_allowed_angel($signup_user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries);
|
||||
function Shift_signup_allowed(
|
||||
$signup_user,
|
||||
$shift,
|
||||
$angeltype,
|
||||
$user_angeltype,
|
||||
$user_shifts,
|
||||
$needed_angeltype,
|
||||
$shift_entries
|
||||
) {
|
||||
global $user, $privileges;
|
||||
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
return Shift_signup_allowed_admin($needed_angeltype, $shift_entries);
|
||||
}
|
||||
|
||||
if (
|
||||
in_array('shiftentry_edit_angeltype_supporter', $privileges)
|
||||
&& User_is_AngelType_supporter($user, $angeltype)
|
||||
) {
|
||||
return Shift_signup_allowed_angeltype_supporter($needed_angeltype, $shift_entries);
|
||||
}
|
||||
|
||||
return Shift_signup_allowed_angel(
|
||||
$signup_user,
|
||||
$shift,
|
||||
$angeltype,
|
||||
$user_angeltype,
|
||||
$user_shifts,
|
||||
$needed_angeltype,
|
||||
$shift_entries
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a shift by its external id.
|
||||
*
|
||||
* @param int $shift_psid
|
||||
*/
|
||||
function Shift_delete_by_psid($shift_psid) {
|
||||
return sql_query("DELETE FROM `Shifts` WHERE `PSID`='" . sql_escape($shift_psid) . "'");
|
||||
function Shift_delete_by_psid($shift_psid)
|
||||
{
|
||||
DB::delete('DELETE FROM `Shifts` WHERE `PSID`=?', [$shift_psid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a shift.
|
||||
*
|
||||
* @param int $shift_id
|
||||
*/
|
||||
function Shift_delete($shift_id) {
|
||||
mail_shift_delete(Shift($shift_id));
|
||||
|
||||
$result = sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'");
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shift.');
|
||||
}
|
||||
return $result;
|
||||
function Shift_delete($shift_id)
|
||||
{
|
||||
mail_shift_delete(Shift($shift_id));
|
||||
|
||||
DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a shift.
|
||||
*
|
||||
* @param array $shift
|
||||
* @return int Updated row count
|
||||
*/
|
||||
function Shift_update($shift) {
|
||||
global $user;
|
||||
$shift['name'] = ShiftType($shift['shifttype_id'])['name'];
|
||||
mail_shift_change(Shift($shift['SID']), $shift);
|
||||
|
||||
return sql_query("UPDATE `Shifts` SET
|
||||
`shifttype_id`='" . sql_escape($shift['shifttype_id']) . "',
|
||||
`start`='" . sql_escape($shift['start']) . "',
|
||||
`end`='" . sql_escape($shift['end']) . "',
|
||||
`RID`='" . sql_escape($shift['RID']) . "',
|
||||
`title`=" . sql_null($shift['title']) . ",
|
||||
`URL`=" . sql_null($shift['URL']) . ",
|
||||
`PSID`=" . sql_null($shift['PSID']) . ",
|
||||
`edited_by_user_id`='" . sql_escape($user['UID']) . "',
|
||||
`edited_at_timestamp`=" . time() . "
|
||||
WHERE `SID`='" . sql_escape($shift['SID']) . "'");
|
||||
function Shift_update($shift)
|
||||
{
|
||||
global $user;
|
||||
$shift['name'] = ShiftType($shift['shifttype_id'])['name'];
|
||||
mail_shift_change(Shift($shift['SID']), $shift);
|
||||
|
||||
return DB::update('
|
||||
UPDATE `Shifts` SET
|
||||
`shifttype_id` = ?,
|
||||
`start` = ?,
|
||||
`end` = ?,
|
||||
`RID` = ?,
|
||||
`title` = ?,
|
||||
`URL` = ?,
|
||||
`PSID` = ?,
|
||||
`edited_by_user_id` = ?,
|
||||
`edited_at_timestamp` = ?
|
||||
WHERE `SID` = ?
|
||||
',
|
||||
[
|
||||
$shift['shifttype_id'],
|
||||
$shift['start'],
|
||||
$shift['end'],
|
||||
$shift['RID'],
|
||||
$shift['title'],
|
||||
$shift['URL'],
|
||||
$shift['PSID'],
|
||||
$user['UID'],
|
||||
time(),
|
||||
$shift['SID']
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a shift by its external id.
|
||||
*
|
||||
* @param array $shift
|
||||
* @return bool|null
|
||||
* @throws Exception
|
||||
*/
|
||||
function Shift_update_by_psid($shift) {
|
||||
$shift_source = sql_select("SELECT `SID` FROM `Shifts` WHERE `PSID`=" . $shift['PSID']);
|
||||
if ($shift_source === false) {
|
||||
return false;
|
||||
}
|
||||
if (count($shift_source) == 0) {
|
||||
return null;
|
||||
}
|
||||
$shift['SID'] = $shift_source[0]['SID'];
|
||||
return Shift_update($shift);
|
||||
function Shift_update_by_psid($shift)
|
||||
{
|
||||
$shift_source = DB::selectOne('SELECT `SID` FROM `Shifts` WHERE `PSID`=?', [$shift['PSID']]);
|
||||
|
||||
if (empty($shift_source)) {
|
||||
throw new Exception('Shift not found.');
|
||||
}
|
||||
|
||||
$shift['SID'] = $shift_source['SID'];
|
||||
return Shift_update($shift);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new shift.
|
||||
*
|
||||
* @return new shift id or false
|
||||
* @param array $shift
|
||||
* @return int ID of the new created shift
|
||||
*/
|
||||
function Shift_create($shift) {
|
||||
global $user;
|
||||
$result = sql_query("INSERT INTO `Shifts` SET
|
||||
`shifttype_id`='" . sql_escape($shift['shifttype_id']) . "',
|
||||
`start`='" . sql_escape($shift['start']) . "',
|
||||
`end`='" . sql_escape($shift['end']) . "',
|
||||
`RID`='" . sql_escape($shift['RID']) . "',
|
||||
`title`=" . sql_null($shift['title']) . ",
|
||||
`URL`=" . sql_null($shift['URL']) . ",
|
||||
`PSID`=" . sql_null($shift['PSID']) . ",
|
||||
`created_by_user_id`='" . sql_escape($user['UID']) . "',
|
||||
`created_at_timestamp`=" . time());
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return sql_id();
|
||||
function Shift_create($shift)
|
||||
{
|
||||
global $user;
|
||||
DB::insert('
|
||||
INSERT INTO `Shifts` (
|
||||
`shifttype_id`,
|
||||
`start`,
|
||||
`end`,
|
||||
`RID`,
|
||||
`title`,
|
||||
`URL`,
|
||||
`PSID`,
|
||||
`created_by_user_id`,
|
||||
`edited_at_timestamp`,
|
||||
`created_at_timestamp`
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
',
|
||||
[
|
||||
$shift['shifttype_id'],
|
||||
$shift['start'],
|
||||
$shift['end'],
|
||||
$shift['RID'],
|
||||
$shift['title'],
|
||||
$shift['URL'],
|
||||
$shift['PSID'],
|
||||
$user['UID'],
|
||||
time(),
|
||||
time(),
|
||||
]
|
||||
);
|
||||
|
||||
return DB::getPdo()->lastInsertId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return users shifts.
|
||||
*
|
||||
* @param array $user
|
||||
* @param bool $include_freeload_comments
|
||||
* @return array
|
||||
*/
|
||||
function Shifts_by_user($user, $include_freeload_comments = false) {
|
||||
$result = sql_select("
|
||||
SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`,
|
||||
`ShiftEntry`.`id`, `ShiftEntry`.`SID`, `ShiftEntry`.`TID`, `ShiftEntry`.`UID`, `ShiftEntry`.`freeloaded`, `ShiftEntry`.`Comment`,
|
||||
" . ($include_freeload_comments ? "`ShiftEntry`.`freeload_comment`, " : "") . "
|
||||
`Shifts`.*, `Room`.*
|
||||
FROM `ShiftEntry`
|
||||
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
|
||||
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
|
||||
JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
|
||||
WHERE `UID`='" . sql_escape($user['UID']) . "'
|
||||
ORDER BY `start`
|
||||
");
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to load users shifts.');
|
||||
}
|
||||
return $result;
|
||||
function Shifts_by_user($user, $include_freeload_comments = false)
|
||||
{
|
||||
return DB::select('
|
||||
SELECT `ShiftTypes`.`id` AS `shifttype_id`, `ShiftTypes`.`name`,
|
||||
`ShiftEntry`.`id`, `ShiftEntry`.`SID`, `ShiftEntry`.`TID`, `ShiftEntry`.`UID`, `ShiftEntry`.`freeloaded`, `ShiftEntry`.`Comment`,
|
||||
' . ($include_freeload_comments ? '`ShiftEntry`.`freeload_comment`, ' : '') . '
|
||||
`Shifts`.*, `Room`.*
|
||||
FROM `ShiftEntry`
|
||||
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
|
||||
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
|
||||
JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
|
||||
WHERE `UID` = ?
|
||||
ORDER BY `start`
|
||||
',
|
||||
[
|
||||
$user['UID']
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Shift by id.
|
||||
*
|
||||
* @param $shift_id Shift
|
||||
* ID
|
||||
* @param int $shift_id Shift ID
|
||||
* @return array|null
|
||||
*/
|
||||
function Shift($shift_id) {
|
||||
$shifts_source = sql_select("
|
||||
function Shift($shift_id)
|
||||
{
|
||||
$result = DB::selectOne('
|
||||
SELECT `Shifts`.*, `ShiftTypes`.`name`
|
||||
FROM `Shifts`
|
||||
FROM `Shifts`
|
||||
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
|
||||
WHERE `SID`='" . sql_escape($shift_id) . "'");
|
||||
$shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift_id) . "'");
|
||||
|
||||
if ($shifts_source === false) {
|
||||
engelsystem_error('Unable to load shift.');
|
||||
}
|
||||
|
||||
if (empty($shifts_source)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = $shifts_source[0];
|
||||
|
||||
$result['ShiftEntry'] = $shiftsEntry_source;
|
||||
$result['NeedAngels'] = [];
|
||||
|
||||
$temp = NeededAngelTypes_by_shift($shift_id);
|
||||
foreach ($temp as $e) {
|
||||
$result['NeedAngels'][] = [
|
||||
'TID' => $e['angel_type_id'],
|
||||
'count' => $e['count'],
|
||||
'restricted' => $e['restricted'],
|
||||
'taken' => $e['taken']
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
WHERE `SID`=?', [$shift_id]);
|
||||
|
||||
if (empty($result)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$shiftsEntry_source = DB::select('
|
||||
SELECT `id`, `TID` , `UID` , `freeloaded`
|
||||
FROM `ShiftEntry`
|
||||
WHERE `SID`=?', [$shift_id]);
|
||||
|
||||
$result['ShiftEntry'] = $shiftsEntry_source;
|
||||
$result['NeedAngels'] = [];
|
||||
|
||||
$angelTypes = NeededAngelTypes_by_shift($shift_id);
|
||||
foreach ($angelTypes as $type) {
|
||||
$result['NeedAngels'][] = [
|
||||
'TID' => $type['angel_type_id'],
|
||||
'count' => $type['count'],
|
||||
'restricted' => $type['restricted'],
|
||||
'taken' => $type['taken']
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all shifts with needed angeltypes and count of subscribed jobs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function Shifts() {
|
||||
$shifts_source = sql_select("
|
||||
SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.`RID`, `Room`.`Name` as `room_name`
|
||||
FROM `Shifts`
|
||||
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
|
||||
JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID`
|
||||
");
|
||||
if ($shifts_source === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($shifts_source as &$shift) {
|
||||
$needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
|
||||
if ($needed_angeltypes === false) {
|
||||
return false;
|
||||
function Shifts()
|
||||
{
|
||||
$shifts_source = DB::select('
|
||||
SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.`RID`, `Room`.`Name` AS `room_name`
|
||||
FROM `Shifts`
|
||||
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
|
||||
JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID`
|
||||
');
|
||||
|
||||
foreach ($shifts_source as &$shift) {
|
||||
$needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
|
||||
$shift['angeltypes'] = $needed_angeltypes;
|
||||
}
|
||||
|
||||
$shift['angeltypes'] = $needed_angeltypes;
|
||||
}
|
||||
|
||||
return $shifts_source;
|
||||
}
|
||||
|
||||
?>
|
||||
return $shifts_source;
|
||||
}
|
||||
|
@ -1,104 +1,128 @@
|
||||
<?php
|
||||
|
||||
use Engelsystem\Database\DB;
|
||||
|
||||
/**
|
||||
* Returns a new empty UserDriverLicense
|
||||
* FIXME entity object needed
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function UserDriverLicense_new() {
|
||||
return [
|
||||
'user_id' => null,
|
||||
'has_car' => false,
|
||||
'has_license_car' => false,
|
||||
'has_license_3_5t_transporter' => false,
|
||||
'has_license_7_5t_truck' => false,
|
||||
'has_license_12_5t_truck' => false,
|
||||
'has_license_forklift' => false
|
||||
];
|
||||
function UserDriverLicense_new()
|
||||
{
|
||||
return [
|
||||
'user_id' => null,
|
||||
'has_car' => false,
|
||||
'has_license_car' => false,
|
||||
'has_license_3_5t_transporter' => false,
|
||||
'has_license_7_5t_truck' => false,
|
||||
'has_license_12_5t_truck' => false,
|
||||
'has_license_forklift' => false
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it valid?
|
||||
*
|
||||
* @param UserDriverLicense $user_driver_license
|
||||
* The UserDriverLicense to check
|
||||
* @param array $user_driver_license The UserDriverLicense to check
|
||||
* @return boolean
|
||||
*/
|
||||
function UserDriverLicense_valid($user_driver_license) {
|
||||
return $user_driver_license['has_license_car'] || $user_driver_license['has_license_3_5t_transporter'] || $user_driver_license['has_license_7_5t_truck'] || $user_driver_license['has_license_12_5t_truck'] || $user_driver_license['has_license_forklift'];
|
||||
function UserDriverLicense_valid($user_driver_license)
|
||||
{
|
||||
return
|
||||
$user_driver_license['has_license_car']
|
||||
|| $user_driver_license['has_license_3_5t_transporter']
|
||||
|| $user_driver_license['has_license_7_5t_truck']
|
||||
|| $user_driver_license['has_license_12_5t_truck']
|
||||
|| $user_driver_license['has_license_forklift'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a users driver license information
|
||||
*
|
||||
* @param int $user_id
|
||||
* The users id
|
||||
* @param int $user_id The users id
|
||||
* @return array|null
|
||||
*/
|
||||
function UserDriverLicense($user_id) {
|
||||
$user_driver_license = sql_select("SELECT * FROM `UserDriverLicenses` WHERE `user_id`='" . sql_escape($user_id) . "'");
|
||||
if ($user_driver_license === false) {
|
||||
engelsystem_error('Unable to load user driver license.');
|
||||
return false;
|
||||
}
|
||||
if (count($user_driver_license) > 0) {
|
||||
return $user_driver_license[0];
|
||||
}
|
||||
return null;
|
||||
function UserDriverLicense($user_id)
|
||||
{
|
||||
return DB::selectOne('
|
||||
SELECT *
|
||||
FROM `UserDriverLicenses`
|
||||
WHERE `user_id`=?', [$user_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a user's driver license entry
|
||||
*
|
||||
* @param UserDriverLicense $user_driver_license
|
||||
* The UserDriverLicense to create
|
||||
* @param array $user_driver_license The UserDriverLicense to create
|
||||
* @param array $user
|
||||
* @return array
|
||||
*/
|
||||
function UserDriverLicenses_create($user_driver_license, $user) {
|
||||
$user_driver_license['user_id'] = $user['UID'];
|
||||
$result = sql_query("
|
||||
INSERT INTO `UserDriverLicenses` SET
|
||||
`user_id`=" . sql_escape($user_driver_license['user_id']) . ",
|
||||
`has_car`=" . sql_bool($user_driver_license['has_car']) . ",
|
||||
`has_license_car`=" . sql_bool($user_driver_license['has_license_car']) . ",
|
||||
`has_license_3_5t_transporter`=" . sql_bool($user_driver_license['has_license_3_5t_transporter']) . ",
|
||||
`has_license_7_5t_truck`=" . sql_bool($user_driver_license['has_license_7_5t_truck']) . ",
|
||||
`has_license_12_5t_truck`=" . sql_bool($user_driver_license['has_license_12_5t_truck']) . ",
|
||||
`has_license_forklift`=" . sql_bool($user_driver_license['has_license_forklift']));
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to create user driver license');
|
||||
}
|
||||
return $user_driver_license;
|
||||
function UserDriverLicenses_create($user_driver_license, $user)
|
||||
{
|
||||
$user_driver_license['user_id'] = $user['UID'];
|
||||
DB::insert('
|
||||
INSERT INTO `UserDriverLicenses` (
|
||||
`user_id`,
|
||||
`has_car`,
|
||||
`has_license_car`,
|
||||
`has_license_3_5t_transporter`,
|
||||
`has_license_7_5t_truck`,
|
||||
`has_license_12_5t_truck`,
|
||||
`has_license_forklift`
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
',
|
||||
[
|
||||
$user_driver_license['user_id'],
|
||||
(int)$user_driver_license['has_car'],
|
||||
(int)$user_driver_license['has_license_car'],
|
||||
(int)$user_driver_license['has_license_3_5t_transporter'],
|
||||
(int)$user_driver_license['has_license_7_5t_truck'],
|
||||
(int)$user_driver_license['has_license_12_5t_truck'],
|
||||
(int)$user_driver_license['has_license_forklift'],
|
||||
]
|
||||
);
|
||||
|
||||
return $user_driver_license;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a user's driver license entry
|
||||
*
|
||||
* @param UserDriverLicense $user_driver_license
|
||||
* The UserDriverLicense to update
|
||||
* @param array $user_driver_license The UserDriverLicense to update
|
||||
*/
|
||||
function UserDriverLicenses_update($user_driver_license) {
|
||||
$result = sql_query("UPDATE `UserDriverLicenses` SET
|
||||
`has_car`=" . sql_bool($user_driver_license['has_car']) . ",
|
||||
`has_license_car`=" . sql_bool($user_driver_license['has_license_car']) . ",
|
||||
`has_license_3_5t_transporter`=" . sql_bool($user_driver_license['has_license_3_5t_transporter']) . ",
|
||||
`has_license_7_5t_truck`=" . sql_bool($user_driver_license['has_license_7_5t_truck']) . ",
|
||||
`has_license_12_5t_truck`=" . sql_bool($user_driver_license['has_license_12_5t_truck']) . ",
|
||||
`has_license_forklift`=" . sql_bool($user_driver_license['has_license_forklift']) . "
|
||||
WHERE `user_id`='" . sql_escape($user_driver_license['user_id']) . "'");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to update user driver license information");
|
||||
}
|
||||
return $result;
|
||||
function UserDriverLicenses_update($user_driver_license)
|
||||
{
|
||||
DB::update('
|
||||
UPDATE `UserDriverLicenses`
|
||||
SET
|
||||
`has_car`=?,
|
||||
`has_license_car`=?,
|
||||
`has_license_3_5t_transporter`=?,
|
||||
`has_license_7_5t_truck`=?,
|
||||
`has_license_12_5t_truck`=?,
|
||||
`has_license_forklift`=?
|
||||
WHERE `user_id`=?
|
||||
',
|
||||
[
|
||||
(int)$user_driver_license['has_car'],
|
||||
(int)$user_driver_license['has_license_car'],
|
||||
(int)$user_driver_license['has_license_3_5t_transporter'],
|
||||
(int)$user_driver_license['has_license_7_5t_truck'],
|
||||
(int)$user_driver_license['has_license_12_5t_truck'],
|
||||
(int)$user_driver_license['has_license_forklift'],
|
||||
$user_driver_license['user_id'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a user's driver license entry
|
||||
*
|
||||
* @param int $user_id
|
||||
* @param int $user_id
|
||||
*/
|
||||
function UserDriverLicenses_delete($user_id) {
|
||||
$result = sql_query("DELETE FROM `UserDriverLicenses` WHERE `user_id`=" . sql_escape($user_id));
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to remove user driver license information");
|
||||
}
|
||||
return $result;
|
||||
function UserDriverLicenses_delete($user_id)
|
||||
{
|
||||
DB::delete('DELETE FROM `UserDriverLicenses` WHERE `user_id`=?', [$user_id]);
|
||||
}
|
||||
?>
|
@ -1,17 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Engelsystem\Database\DB;
|
||||
|
||||
/**
|
||||
* Returns users groups
|
||||
* @param User $user
|
||||
*
|
||||
* @param array $user
|
||||
* @return array
|
||||
*/
|
||||
function User_groups($user) {
|
||||
return sql_select("
|
||||
SELECT `Groups`.*
|
||||
FROM `UserGroups`
|
||||
JOIN `Groups` ON `Groups`.`UID`=`UserGroups`.`group_id`
|
||||
WHERE `UserGroups`.`uid`='" . sql_escape($user['UID']) . "'
|
||||
ORDER BY `UserGroups`.`group_id`
|
||||
");
|
||||
function User_groups($user)
|
||||
{
|
||||
return DB::select('
|
||||
SELECT `Groups`.*
|
||||
FROM `UserGroups`
|
||||
JOIN `Groups` ON `Groups`.`UID`=`UserGroups`.`group_id`
|
||||
WHERE `UserGroups`.`uid`=?
|
||||
ORDER BY `UserGroups`.`group_id`
|
||||
',
|
||||
[$user['UID']]
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
@ -1,216 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Close connection.
|
||||
*/
|
||||
function sql_close() {
|
||||
global $sql_connection;
|
||||
|
||||
return $sql_connection->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return NULL if given value is null.
|
||||
*/
|
||||
function sql_null($value = null) {
|
||||
return $value == null ? 'NULL' : ("'" . sql_escape($value) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Start new transaction.
|
||||
*/
|
||||
function sql_transaction_start() {
|
||||
global $sql_nested_transaction_level;
|
||||
|
||||
if ($sql_nested_transaction_level ++ == 0) {
|
||||
return sql_query("BEGIN");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit transaction.
|
||||
*/
|
||||
function sql_transaction_commit() {
|
||||
global $sql_nested_transaction_level;
|
||||
|
||||
if (-- $sql_nested_transaction_level == 0) {
|
||||
return sql_query("COMMIT");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop transaction, revert database.
|
||||
*/
|
||||
function sql_transaction_rollback() {
|
||||
global $sql_nested_transaction_level;
|
||||
|
||||
if (-- $sql_nested_transaction_level == 0) {
|
||||
return sql_query("ROLLBACK");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an sql error.
|
||||
*
|
||||
* @param string $message
|
||||
* @return false
|
||||
*/
|
||||
function sql_error($message) {
|
||||
sql_close();
|
||||
|
||||
$message = trim($message) . "\n";
|
||||
$message .= debug_string_backtrace() . "\n";
|
||||
|
||||
error_log('mysql_provider error: ' . $message);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to mysql server.
|
||||
*
|
||||
* @param string $host
|
||||
* Host
|
||||
* @param string $user
|
||||
* Username
|
||||
* @param string $pass
|
||||
* Password
|
||||
* @param string $db_name
|
||||
* DB to select
|
||||
* @return mysqli The connection handler
|
||||
*/
|
||||
function sql_connect($host, $user, $pass, $db_name) {
|
||||
global $sql_connection;
|
||||
|
||||
$sql_connection = new mysqli($host, $user, $pass, $db_name);
|
||||
if ($sql_connection->connect_errno) {
|
||||
error("Unable to connect to MySQL: " . $sql_connection->connect_error);
|
||||
return sql_error("Unable to connect to MySQL: " . $sql_connection->connect_error);
|
||||
}
|
||||
|
||||
$result = $sql_connection->query("SET CHARACTER SET utf8;");
|
||||
if (! $result) {
|
||||
return sql_error("Unable to set utf8 character set (" . $sql_connection->errno . ") " . $sql_connection->error);
|
||||
}
|
||||
|
||||
$result = $sql_connection->set_charset('utf8');
|
||||
if (! $result) {
|
||||
return sql_error("Unable to set utf8 names (" . $sql_connection->errno . ") " . $sql_connection->error);
|
||||
}
|
||||
|
||||
return $sql_connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the selected db in current mysql-connection.
|
||||
*
|
||||
* @param
|
||||
* $db_name
|
||||
* @return bool true on success, false on error
|
||||
*/
|
||||
function sql_select_db($db_name) {
|
||||
global $sql_connection;
|
||||
if (! $sql_connection->select_db($db_name)) {
|
||||
return sql_error("No database selected.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL SELECT query
|
||||
*
|
||||
* @param string $query
|
||||
* @return Result array or false on error
|
||||
*/
|
||||
function sql_select($query) {
|
||||
global $sql_connection;
|
||||
|
||||
// echo $query . ";\n";
|
||||
// echo debug_string_backtrace() . "\n";
|
||||
|
||||
$result = $sql_connection->query($query);
|
||||
if ($result) {
|
||||
$data = [];
|
||||
while ($line = $result->fetch_assoc()) {
|
||||
array_push($data, $line);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
return sql_error("MySQL-query error: " . $query . " (" . $sql_connection->errno . ") " . $sql_connection->error);
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL execute a query
|
||||
*
|
||||
* @param string $query
|
||||
* @return mysqli_result boolean resource or false on error
|
||||
*/
|
||||
function sql_query($query) {
|
||||
global $sql_connection;
|
||||
|
||||
$result = $sql_connection->query($query);
|
||||
if ($result) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return sql_error("MySQL-query error: " . $query . " (" . $sql_connection->errno . ") " . $sql_connection->error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last inserted id.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function sql_id() {
|
||||
global $sql_connection;
|
||||
return $sql_connection->insert_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a string for a sql query.
|
||||
*
|
||||
* @param string $query
|
||||
* @return string
|
||||
*/
|
||||
function sql_escape($query) {
|
||||
global $sql_connection;
|
||||
return $sql_connection->real_escape_string($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a boolean for mysql-queries.
|
||||
*
|
||||
* @param boolean $boolean
|
||||
* @return string
|
||||
*/
|
||||
function sql_bool($boolean) {
|
||||
return $boolean == true ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Count query result lines.
|
||||
*
|
||||
* @param string $query
|
||||
* @return int Count of result lines
|
||||
*/
|
||||
function sql_num_query($query) {
|
||||
return sql_query($query)->num_rows;
|
||||
}
|
||||
|
||||
function sql_select_single_col($query) {
|
||||
$result = sql_select($query);
|
||||
return array_map('array_shift', $result);
|
||||
}
|
||||
|
||||
function sql_select_single_cell($query) {
|
||||
return array_shift(array_shift(sql_select($query)));
|
||||
}
|
||||
|
||||
?>
|
@ -1,67 +1,92 @@
|
||||
<?php
|
||||
|
||||
function admin_news() {
|
||||
global $user;
|
||||
|
||||
if (! isset($_GET["action"])) {
|
||||
redirect(page_link_to("news"));
|
||||
}
|
||||
|
||||
$html = '<div class="col-md-12"><h1>' . _("Edit news entry") . '</h1>' . msg();
|
||||
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
|
||||
$news_id = $_REQUEST['id'];
|
||||
} else {
|
||||
return error("Incomplete call, missing News ID.", true);
|
||||
}
|
||||
|
||||
$news = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
|
||||
if (empty($news)) {
|
||||
return error("No News found.", true);
|
||||
}
|
||||
switch ($_REQUEST["action"]) {
|
||||
default:
|
||||
redirect(page_link_to('news'));
|
||||
case 'edit':
|
||||
list($news) = $news;
|
||||
|
||||
$user_source = User($news['UID']);
|
||||
|
||||
$html .= form([
|
||||
form_info(_("Date"), date("Y-m-d H:i", $news['Datum'])),
|
||||
form_info(_("Author"), User_Nick_render($user_source)),
|
||||
form_text('eBetreff', _("Subject"), $news['Betreff']),
|
||||
form_textarea('eText', _("Message"), $news['Text']),
|
||||
form_checkbox('eTreffen', _("Meeting"), $news['Treffen'] == 1, 1),
|
||||
form_submit('submit', _("Save"))
|
||||
], page_link_to('admin_news&action=save&id=' . $news_id));
|
||||
|
||||
$html .= '<a class="btn btn-danger" href="' . page_link_to('admin_news&action=delete&id=' . $news_id) . '"><span class="glyphicon glyphicon-trash"></span> ' . _("Delete") . '</a>';
|
||||
break;
|
||||
|
||||
case 'save':
|
||||
list($news) = $news;
|
||||
|
||||
sql_query("UPDATE `News` SET
|
||||
`Datum`='" . sql_escape(time()) . "',
|
||||
`Betreff`='" . sql_escape($_POST["eBetreff"]) . "',
|
||||
`Text`='" . sql_escape($_POST["eText"]) . "',
|
||||
`UID`='" . sql_escape($user['UID']) . "',
|
||||
`Treffen`='" . sql_escape($_POST["eTreffen"]) . "'
|
||||
WHERE `ID`='" . sql_escape($news_id) . "'");
|
||||
engelsystem_log("News updated: " . $_POST["eBetreff"]);
|
||||
success(_("News entry updated."));
|
||||
redirect(page_link_to("news"));
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
list($news) = $news;
|
||||
|
||||
sql_query("DELETE FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
|
||||
engelsystem_log("News deleted: " . $news['Betreff']);
|
||||
success(_("News entry deleted."));
|
||||
redirect(page_link_to("news"));
|
||||
break;
|
||||
}
|
||||
return $html . '</div>';
|
||||
use Engelsystem\Database\DB;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function admin_news()
|
||||
{
|
||||
global $user, $privileges;
|
||||
$request = request();
|
||||
|
||||
if (!$request->has('action')) {
|
||||
redirect(page_link_to('news'));
|
||||
}
|
||||
|
||||
$html = '<div class="col-md-12"><h1>' . _('Edit news entry') . '</h1>' . msg();
|
||||
if ($request->has('id') && preg_match('/^\d{1,11}$/', $request->input('id'))) {
|
||||
$news_id = $request->input('id');
|
||||
} else {
|
||||
return error('Incomplete call, missing News ID.', true);
|
||||
}
|
||||
|
||||
$news = DB::selectOne('SELECT * FROM `News` WHERE `ID`=? LIMIT 1', [$news_id]);
|
||||
if (empty($news)) {
|
||||
return error('No News found.', true);
|
||||
}
|
||||
|
||||
switch ($request->input('action')) {
|
||||
case 'edit':
|
||||
$user_source = User($news['UID']);
|
||||
|
||||
$html .= form(
|
||||
[
|
||||
form_info(_('Date'), date('Y-m-d H:i', $news['Datum'])),
|
||||
form_info(_('Author'), User_Nick_render($user_source)),
|
||||
form_text('eBetreff', _('Subject'), $news['Betreff']),
|
||||
form_textarea('eText', _('Message'), $news['Text']),
|
||||
form_checkbox('eTreffen', _('Meeting'), $news['Treffen'] == 1, 1),
|
||||
form_submit('submit', _('Save'))
|
||||
],
|
||||
page_link_to('admin_news', ['action' => 'save', 'id' => $news_id])
|
||||
);
|
||||
|
||||
$html .= '<a class="btn btn-danger" href="'
|
||||
. page_link_to('admin_news', ['action' => 'delete', 'id' => $news_id])
|
||||
. '">'
|
||||
. '<span class="glyphicon glyphicon-trash"></span> ' . _('Delete')
|
||||
. '</a>';
|
||||
break;
|
||||
|
||||
case 'save':
|
||||
$text = $request->postData('eText');
|
||||
if (!in_array('admin_news_html', $privileges)) {
|
||||
$text = strip_tags($text);
|
||||
}
|
||||
|
||||
DB::update('
|
||||
UPDATE `News` SET
|
||||
`Datum`=?,
|
||||
`Betreff`=?,
|
||||
`Text`=?,
|
||||
`UID`=?,
|
||||
`Treffen`=?
|
||||
WHERE `ID`=?
|
||||
',
|
||||
[
|
||||
time(),
|
||||
strip_tags($request->postData('eBetreff')),
|
||||
$text,
|
||||
$user['UID'],
|
||||
$request->has('eTreffen') ? 1 : 0,
|
||||
$news_id
|
||||
]
|
||||
);
|
||||
|
||||
engelsystem_log('News updated: ' . $request->postData('eBetreff'));
|
||||
success(_('News entry updated.'));
|
||||
redirect(page_link_to('news'));
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
DB::delete('DELETE FROM `News` WHERE `ID`=? LIMIT 1', [$news_id]);
|
||||
engelsystem_log('News deleted: ' . $news['Betreff']);
|
||||
success(_('News entry deleted.'));
|
||||
redirect(page_link_to('news'));
|
||||
break;
|
||||
default:
|
||||
redirect(page_link_to('news'));
|
||||
}
|
||||
return $html . '</div>';
|
||||
}
|
||||
?>
|
@ -1,9 +1,17 @@
|
||||
<?php
|
||||
function credits_title() {
|
||||
return _("Credits");
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function credits_title()
|
||||
{
|
||||
return _('Credits');
|
||||
}
|
||||
|
||||
function guest_credits() {
|
||||
return template_render(__DIR__ . '/../../templates/guest_credits.html', []);
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function guest_credits()
|
||||
{
|
||||
return view(__DIR__ . '/../../templates/guest_credits.html');
|
||||
}
|
||||
?>
|
@ -1,400 +1,529 @@
|
||||
<?php
|
||||
|
||||
function login_title() {
|
||||
return _("Login");
|
||||
use Engelsystem\Database\DB;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function login_title()
|
||||
{
|
||||
return _('Login');
|
||||
}
|
||||
|
||||
function register_title() {
|
||||
return _("Register");
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function register_title()
|
||||
{
|
||||
return _('Register');
|
||||
}
|
||||
|
||||
function logout_title() {
|
||||
return _("Logout");
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function logout_title()
|
||||
{
|
||||
return _('Logout');
|
||||
}
|
||||
|
||||
// Engel registrieren
|
||||
function guest_register() {
|
||||
global $tshirt_sizes, $enable_tshirt_size, $default_theme, $user, $min_password_length;
|
||||
|
||||
$event_config = EventConfig();
|
||||
|
||||
$msg = "";
|
||||
$nick = "";
|
||||
$lastname = "";
|
||||
$prename = "";
|
||||
$age = "";
|
||||
$tel = "";
|
||||
$dect = "";
|
||||
$mobile = "";
|
||||
$mail = "";
|
||||
$email_shiftinfo = false;
|
||||
$email_by_human_allowed = false;
|
||||
$jabber = "";
|
||||
$hometown = "";
|
||||
$comment = "";
|
||||
$tshirt_size = '';
|
||||
$password_hash = "";
|
||||
$selected_angel_types = [];
|
||||
$planned_arrival_date = null;
|
||||
|
||||
$angel_types_source = AngelTypes();
|
||||
$angel_types = [];
|
||||
foreach ($angel_types_source as $angel_type) {
|
||||
$angel_types[$angel_type['id']] = $angel_type['name'] . ($angel_type['restricted'] ? " (restricted)" : "");
|
||||
if (! $angel_type['restricted']) {
|
||||
$selected_angel_types[] = $angel_type['id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['nick']) && strlen(User_validate_Nick($_REQUEST['nick'])) > 1) {
|
||||
$nick = User_validate_Nick($_REQUEST['nick']);
|
||||
if (sql_num_query("SELECT * FROM `User` WHERE `Nick`='" . sql_escape($nick) . "' LIMIT 1") > 0) {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Your nick "%s" already exists."), $nick), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Your nick "%s" is too short (min. 2 characters)."), User_validate_Nick($_REQUEST['nick'])), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['mail']) && strlen(strip_request_item('mail')) > 0) {
|
||||
$mail = strip_request_item('mail');
|
||||
if (! check_email($mail)) {
|
||||
$valid = false;
|
||||
$msg .= error(_("E-mail address is not correct."), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter your e-mail."), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['email_shiftinfo'])) {
|
||||
$email_shiftinfo = true;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['email_by_human_allowed'])) {
|
||||
$email_by_human_allowed = true;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['jabber']) && strlen(strip_request_item('jabber')) > 0) {
|
||||
$jabber = strip_request_item('jabber');
|
||||
if (! check_email($jabber)) {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please check your jabber account information."), true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($enable_tshirt_size) {
|
||||
if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']]) && $_REQUEST['tshirt_size'] != '') {
|
||||
$tshirt_size = $_REQUEST['tshirt_size'];
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please select your shirt size."), true);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) {
|
||||
if ($_REQUEST['password'] != $_REQUEST['password2']) {
|
||||
$valid = false;
|
||||
$msg .= error(_("Your passwords don't match."), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Your password is too short (please use at least %s characters)."), $min_password_length), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['planned_arrival_date'])) {
|
||||
$tmp = parse_date("Y-m-d H:i", $_REQUEST['planned_arrival_date'] . " 00:00");
|
||||
$result = User_validate_planned_arrival_date($tmp);
|
||||
$planned_arrival_date = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("Please enter your planned date of arrival. It should be after the buildup start date and before teardown end date."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Engel registrieren
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function guest_register()
|
||||
{
|
||||
global $user, $privileges;
|
||||
$tshirt_sizes = config('tshirt_sizes');
|
||||
$enable_tshirt_size = config('enable_tshirt_size');
|
||||
$min_password_length = config('min_password_length');
|
||||
$event_config = EventConfig();
|
||||
$request = request();
|
||||
$session = session();
|
||||
|
||||
$msg = '';
|
||||
$nick = '';
|
||||
$lastName = '';
|
||||
$preName = '';
|
||||
$age = 0;
|
||||
$tel = '';
|
||||
$dect = '';
|
||||
$mobile = '';
|
||||
$mail = '';
|
||||
$email_shiftinfo = false;
|
||||
$email_by_human_allowed = false;
|
||||
$jabber = '';
|
||||
$hometown = '';
|
||||
$comment = '';
|
||||
$tshirt_size = '';
|
||||
$password_hash = '';
|
||||
$selected_angel_types = [];
|
||||
foreach (array_keys($angel_types) as $angel_type_id) {
|
||||
if (isset($_REQUEST['angel_types_' . $angel_type_id])) {
|
||||
$selected_angel_types[] = $angel_type_id;
|
||||
}
|
||||
}
|
||||
|
||||
// Trivia
|
||||
if (isset($_REQUEST['lastname'])) {
|
||||
$lastname = strip_request_item('lastname');
|
||||
}
|
||||
if (isset($_REQUEST['prename'])) {
|
||||
$prename = strip_request_item('prename');
|
||||
}
|
||||
if (isset($_REQUEST['age']) && preg_match("/^[0-9]{0,4}$/", $_REQUEST['age'])) {
|
||||
$age = strip_request_item('age');
|
||||
}
|
||||
if (isset($_REQUEST['tel'])) {
|
||||
$tel = strip_request_item('tel');
|
||||
}
|
||||
if (isset($_REQUEST['dect'])) {
|
||||
$dect = strip_request_item('dect');
|
||||
}
|
||||
if (isset($_REQUEST['mobile'])) {
|
||||
$mobile = strip_request_item('mobile');
|
||||
}
|
||||
if (isset($_REQUEST['hometown'])) {
|
||||
$hometown = strip_request_item('hometown');
|
||||
$planned_arrival_date = null;
|
||||
|
||||
$angel_types_source = AngelTypes();
|
||||
$angel_types = [];
|
||||
foreach ($angel_types_source as $angel_type) {
|
||||
$angel_types[$angel_type['id']] = $angel_type['name'] . ($angel_type['restricted'] ? ' (restricted)' : '');
|
||||
if (!$angel_type['restricted']) {
|
||||
$selected_angel_types[] = $angel_type['id'];
|
||||
}
|
||||
}
|
||||
if (isset($_REQUEST['comment'])) {
|
||||
$comment = strip_request_item_nl('comment');
|
||||
|
||||
foreach ($tshirt_sizes as $key => $size) {
|
||||
if (empty($size)) {
|
||||
unset($tshirt_sizes[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
sql_query("
|
||||
INSERT INTO `User` SET
|
||||
`color`='" . sql_escape($default_theme) . "',
|
||||
`Nick`='" . sql_escape($nick) . "',
|
||||
`Vorname`='" . sql_escape($prename) . "',
|
||||
`Name`='" . sql_escape($lastname) . "',
|
||||
`Alter`='" . sql_escape($age) . "',
|
||||
`Telefon`='" . sql_escape($tel) . "',
|
||||
`DECT`='" . sql_escape($dect) . "',
|
||||
`Handy`='" . sql_escape($mobile) . "',
|
||||
`email`='" . sql_escape($mail) . "',
|
||||
`email_shiftinfo`=" . sql_bool($email_shiftinfo) . ",
|
||||
`email_by_human_allowed`=" . sql_bool($email_by_human_allowed) . ",
|
||||
`jabber`='" . sql_escape($jabber) . "',
|
||||
`Size`='" . sql_escape($tshirt_size) . "',
|
||||
`Passwort`='" . sql_escape($password_hash) . "',
|
||||
`kommentar`='" . sql_escape($comment) . "',
|
||||
`Hometown`='" . sql_escape($hometown) . "',
|
||||
`CreateDate`=NOW(),
|
||||
`Sprache`='" . sql_escape($_SESSION["locale"]) . "',
|
||||
`arrival_date`=NULL,
|
||||
`planned_arrival_date`='" . sql_escape($planned_arrival_date) . "'");
|
||||
|
||||
// Assign user-group and set password
|
||||
$user_id = sql_id();
|
||||
sql_query("INSERT INTO `UserGroups` SET `uid`='" . sql_escape($user_id) . "', `group_id`=-2");
|
||||
set_password($user_id, $_REQUEST['password']);
|
||||
|
||||
// Assign angel-types
|
||||
$user_angel_types_info = [];
|
||||
foreach ($selected_angel_types as $selected_angel_type_id) {
|
||||
sql_query("INSERT INTO `UserAngelTypes` SET `user_id`='" . sql_escape($user_id) . "', `angeltype_id`='" . sql_escape($selected_angel_type_id) . "'");
|
||||
$user_angel_types_info[] = $angel_types[$selected_angel_type_id];
|
||||
}
|
||||
|
||||
engelsystem_log("User " . User_Nick_render(User($user_id)) . " signed up as: " . join(", ", $user_angel_types_info));
|
||||
success(_("Angel registration successful!"));
|
||||
|
||||
// User is already logged in - that means a supporter has registered an angel. Return to register page.
|
||||
if (isset($user)) {
|
||||
redirect(page_link_to('register'));
|
||||
}
|
||||
|
||||
// If a welcome message is present, display registration success page.
|
||||
if ($event_config != null && $event_config['event_welcome_msg'] != null) {
|
||||
return User_registration_success_view($event_config['event_welcome_msg']);
|
||||
}
|
||||
|
||||
redirect('?');
|
||||
|
||||
if (!in_array('register', $privileges) || (!isset($user) && !config('registration_enabled'))) {
|
||||
error(_('Registration is disabled.'));
|
||||
|
||||
return page_with_title(register_title(), [
|
||||
msg(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$buildup_start_date = time();
|
||||
$teardown_end_date = null;
|
||||
if ($event_config != null) {
|
||||
if (isset($event_config['buildup_start_date'])) {
|
||||
$buildup_start_date = $event_config['buildup_start_date'];
|
||||
|
||||
if ($request->has('submit')) {
|
||||
$valid = true;
|
||||
|
||||
if ($request->has('nick') && strlen(User_validate_Nick($request->input('nick'))) > 1) {
|
||||
$nick = User_validate_Nick($request->input('nick'));
|
||||
if (count(DB::select('SELECT `UID` FROM `User` WHERE `Nick`=? LIMIT 1', [$nick])) > 0) {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_('Your nick "%s" already exists.'), $nick), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(
|
||||
_('Your nick "%s" is too short (min. 2 characters).'),
|
||||
User_validate_Nick($request->input('nick'))
|
||||
), true);
|
||||
}
|
||||
|
||||
if ($request->has('mail') && strlen(strip_request_item('mail')) > 0) {
|
||||
$mail = strip_request_item('mail');
|
||||
if (!check_email($mail)) {
|
||||
$valid = false;
|
||||
$msg .= error(_('E-mail address is not correct.'), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_('Please enter your e-mail.'), true);
|
||||
}
|
||||
|
||||
if ($request->has('email_shiftinfo')) {
|
||||
$email_shiftinfo = true;
|
||||
}
|
||||
|
||||
if ($request->has('email_by_human_allowed')) {
|
||||
$email_by_human_allowed = true;
|
||||
}
|
||||
|
||||
if ($request->has('jabber') && strlen(strip_request_item('jabber')) > 0) {
|
||||
$jabber = strip_request_item('jabber');
|
||||
if (!check_email($jabber)) {
|
||||
$valid = false;
|
||||
$msg .= error(_('Please check your jabber account information.'), true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($enable_tshirt_size) {
|
||||
if ($request->has('tshirt_size') && isset($tshirt_sizes[$request->input('tshirt_size')])) {
|
||||
$tshirt_size = $request->input('tshirt_size');
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_('Please select your shirt size.'), true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->has('password') && strlen($request->postData('password')) >= $min_password_length) {
|
||||
if ($request->postData('password') != $request->postData('password2')) {
|
||||
$valid = false;
|
||||
$msg .= error(_('Your passwords don\'t match.'), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(
|
||||
_('Your password is too short (please use at least %s characters).'),
|
||||
$min_password_length
|
||||
), true);
|
||||
}
|
||||
|
||||
if ($request->has('planned_arrival_date')) {
|
||||
$tmp = parse_date('Y-m-d H:i', $request->input('planned_arrival_date') . ' 00:00');
|
||||
$result = User_validate_planned_arrival_date($tmp);
|
||||
$planned_arrival_date = $result->getValue();
|
||||
if (!$result->isValid()) {
|
||||
$valid = false;
|
||||
error(_('Please enter your planned date of arrival. It should be after the buildup start date and before teardown end date.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please enter your planned date of arrival. It should be after the buildup start date and before teardown end date.'));
|
||||
}
|
||||
|
||||
$selected_angel_types = [];
|
||||
foreach (array_keys($angel_types) as $angel_type_id) {
|
||||
if ($request->has('angel_types_' . $angel_type_id)) {
|
||||
$selected_angel_types[] = $angel_type_id;
|
||||
}
|
||||
}
|
||||
|
||||
// Trivia
|
||||
if ($request->has('lastname')) {
|
||||
$lastName = strip_request_item('lastname');
|
||||
}
|
||||
if ($request->has('prename')) {
|
||||
$preName = strip_request_item('prename');
|
||||
}
|
||||
if ($request->has('age') && preg_match('/^\d{0,4}$/', $request->input('age'))) {
|
||||
$age = strip_request_item('age');
|
||||
}
|
||||
if ($request->has('tel')) {
|
||||
$tel = strip_request_item('tel');
|
||||
}
|
||||
if ($request->has('dect')) {
|
||||
if(strlen(strip_request_item('dect')) <= 5) {
|
||||
$dect = strip_request_item('dect');
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('For dect numbers are only 5 digits allowed.'));
|
||||
}
|
||||
}
|
||||
if ($request->has('mobile')) {
|
||||
$mobile = strip_request_item('mobile');
|
||||
}
|
||||
if ($request->has('hometown')) {
|
||||
$hometown = strip_request_item('hometown');
|
||||
}
|
||||
if ($request->has('comment')) {
|
||||
$comment = strip_request_item_nl('comment');
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
DB::insert('
|
||||
INSERT INTO `User` (
|
||||
`color`,
|
||||
`Nick`,
|
||||
`Vorname`,
|
||||
`Name`,
|
||||
`Alter`,
|
||||
`Telefon`,
|
||||
`DECT`,
|
||||
`Handy`,
|
||||
`email`,
|
||||
`email_shiftinfo`,
|
||||
`email_by_human_allowed`,
|
||||
`jabber`,
|
||||
`Size`,
|
||||
`Passwort`,
|
||||
`kommentar`,
|
||||
`Hometown`,
|
||||
`CreateDate`,
|
||||
`Sprache`,
|
||||
`arrival_date`,
|
||||
`planned_arrival_date`,
|
||||
`force_active`,
|
||||
`lastLogIn`,
|
||||
`api_key`,
|
||||
`got_voucher`
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?, NULL, ?, FALSE, 0, "", 0)
|
||||
',
|
||||
[
|
||||
config('theme'),
|
||||
$nick,
|
||||
$preName,
|
||||
$lastName,
|
||||
$age,
|
||||
$tel,
|
||||
$dect,
|
||||
$mobile,
|
||||
$mail,
|
||||
(int)$email_shiftinfo,
|
||||
(int)$email_by_human_allowed,
|
||||
$jabber,
|
||||
$tshirt_size,
|
||||
$password_hash,
|
||||
$comment,
|
||||
$hometown,
|
||||
$session->get('locale'),
|
||||
$planned_arrival_date,
|
||||
]
|
||||
);
|
||||
|
||||
// Assign user-group and set password
|
||||
$user_id = DB::getPdo()->lastInsertId();
|
||||
DB::insert('INSERT INTO `UserGroups` (`uid`, `group_id`) VALUES (?, -20)', [$user_id]);
|
||||
set_password($user_id, $request->postData('password'));
|
||||
|
||||
// Assign angel-types
|
||||
$user_angel_types_info = [];
|
||||
foreach ($selected_angel_types as $selected_angel_type_id) {
|
||||
DB::insert(
|
||||
'INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`, `supporter`) VALUES (?, ?, FALSE)',
|
||||
[$user_id, $selected_angel_type_id]
|
||||
);
|
||||
$user_angel_types_info[] = $angel_types[$selected_angel_type_id];
|
||||
}
|
||||
|
||||
engelsystem_log(
|
||||
'User ' . User_Nick_render(User($user_id))
|
||||
. ' signed up as: ' . join(', ', $user_angel_types_info)
|
||||
);
|
||||
success(_('Angel registration successful!'));
|
||||
|
||||
// User is already logged in - that means a supporter has registered an angel. Return to register page.
|
||||
if (isset($user)) {
|
||||
redirect(page_link_to('register'));
|
||||
}
|
||||
|
||||
// If a welcome message is present, display registration success page.
|
||||
if ($event_config != null && $event_config['event_welcome_msg'] != null) {
|
||||
return User_registration_success_view($event_config['event_welcome_msg']);
|
||||
}
|
||||
|
||||
redirect(page_link_to('/'));
|
||||
}
|
||||
}
|
||||
if(isset($event_config['teardown_end_date'])) {
|
||||
$teardown_end_date = $event_config['teardown_end_date'];
|
||||
|
||||
$buildup_start_date = time();
|
||||
$teardown_end_date = null;
|
||||
if ($event_config != null) {
|
||||
if (isset($event_config['buildup_start_date'])) {
|
||||
$buildup_start_date = $event_config['buildup_start_date'];
|
||||
}
|
||||
if (isset($event_config['teardown_end_date'])) {
|
||||
$teardown_end_date = $event_config['teardown_end_date'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return page_with_title(register_title(), [
|
||||
_("By completing this form you're registering as a Chaos-Angel. This script will create you an account in the angel task scheduler."),
|
||||
$msg,
|
||||
msg(),
|
||||
form([
|
||||
div('row', [
|
||||
div('col-md-6', [
|
||||
div('row', [
|
||||
div('col-sm-4', [
|
||||
form_text('nick', _("Nick") . ' ' . entry_required(), $nick)
|
||||
]),
|
||||
div('col-sm-8', [
|
||||
form_email('mail', _("E-Mail") . ' ' . entry_required(), $mail),
|
||||
form_checkbox('email_shiftinfo', _("The engelsystem is allowed to send me an email (e.g. when my shifts change)"), $email_shiftinfo),
|
||||
form_checkbox('email_by_human_allowed', _("Humans are allowed to send me an email (e.g. for ticket vouchers)"), $email_by_human_allowed)
|
||||
])
|
||||
]),
|
||||
div('row', [
|
||||
div('col-sm-6', [
|
||||
form_date('planned_arrival_date', _("Planned date of arrival") . ' ' . entry_required(), $planned_arrival_date, $buildup_start_date, $teardown_end_date)
|
||||
]),
|
||||
div('col-sm-6', [
|
||||
$enable_tshirt_size ? form_select('tshirt_size', _("Shirt size") . ' ' . entry_required(), $tshirt_sizes, $tshirt_size) : ''
|
||||
])
|
||||
]),
|
||||
div('row', [
|
||||
div('col-sm-6', [
|
||||
form_password('password', _("Password") . ' ' . entry_required())
|
||||
]),
|
||||
div('col-sm-6', [
|
||||
form_password('password2', _("Confirm password") . ' ' . entry_required())
|
||||
])
|
||||
]),
|
||||
form_checkboxes('angel_types', _("What do you want to do?") . sprintf(" (<a href=\"%s\">%s</a>)", page_link_to('angeltypes') . '&action=about', _("Description of job types")), $angel_types, $selected_angel_types),
|
||||
form_info("", _("Restricted angel types need will be confirmed later by a supporter. You can change your selection in the options section."))
|
||||
]),
|
||||
div('col-md-6', [
|
||||
div('row', [
|
||||
div('col-sm-4', [
|
||||
form_text('dect', _("DECT"), $dect)
|
||||
]),
|
||||
div('col-sm-4', [
|
||||
form_text('mobile', _("Mobile"), $mobile)
|
||||
]),
|
||||
div('col-sm-4', [
|
||||
form_text('tel', _("Phone"), $tel)
|
||||
])
|
||||
]),
|
||||
form_text('jabber', _("Jabber"), $jabber),
|
||||
div('row', [
|
||||
div('col-sm-6', [
|
||||
form_text('prename', _("First name"), $prename)
|
||||
]),
|
||||
div('col-sm-6', [
|
||||
form_text('lastname', _("Last name"), $lastname)
|
||||
])
|
||||
]),
|
||||
div('row', [
|
||||
div('col-sm-3', [
|
||||
form_text('age', _("Age"), $age)
|
||||
]),
|
||||
div('col-sm-9', [
|
||||
form_text('hometown', _("Hometown"), $hometown)
|
||||
])
|
||||
]),
|
||||
form_info(entry_required() . ' = ' . _("Entry required!"))
|
||||
])
|
||||
]),
|
||||
// form_textarea('comment', _("Did you help at former CCC events and which tasks have you performed then?"), $comment),
|
||||
form_submit('submit', _("Register"))
|
||||
])
|
||||
]);
|
||||
|
||||
return page_with_title(register_title(), [
|
||||
_('By completing this form you\'re registering as a Chaos-Angel. This script will create you an account in the angel task scheduler.'),
|
||||
$msg,
|
||||
msg(),
|
||||
form([
|
||||
div('row', [
|
||||
div('col-md-6', [
|
||||
div('row', [
|
||||
div('col-sm-4', [
|
||||
form_text('nick', _('Nick') . ' ' . entry_required(), $nick)
|
||||
]),
|
||||
div('col-sm-8', [
|
||||
form_email('mail', _('E-Mail') . ' ' . entry_required(), $mail),
|
||||
form_checkbox(
|
||||
'email_shiftinfo',
|
||||
_('The engelsystem is allowed to send me an email (e.g. when my shifts change)'),
|
||||
$email_shiftinfo
|
||||
),
|
||||
form_checkbox(
|
||||
'email_by_human_allowed',
|
||||
_('Humans are allowed to send me an email (e.g. for ticket vouchers)'),
|
||||
$email_by_human_allowed
|
||||
)
|
||||
])
|
||||
]),
|
||||
div('row', [
|
||||
div('col-sm-6', [
|
||||
form_date(
|
||||
'planned_arrival_date',
|
||||
_('Planned date of arrival') . ' ' . entry_required(),
|
||||
$planned_arrival_date, $buildup_start_date, $teardown_end_date
|
||||
)
|
||||
]),
|
||||
div('col-sm-6', [
|
||||
$enable_tshirt_size ? form_select('tshirt_size',
|
||||
_('Shirt size') . ' ' . entry_required(),
|
||||
$tshirt_sizes, $tshirt_size) : ''
|
||||
])
|
||||
]),
|
||||
div('row', [
|
||||
div('col-sm-6', [
|
||||
form_password('password', _('Password') . ' ' . entry_required())
|
||||
]),
|
||||
div('col-sm-6', [
|
||||
form_password('password2', _('Confirm password') . ' ' . entry_required())
|
||||
])
|
||||
]),
|
||||
form_checkboxes(
|
||||
'angel_types',
|
||||
_('What do you want to do?') . sprintf(
|
||||
' (<a href="%s">%s</a>)',
|
||||
page_link_to('angeltypes', ['action' => 'about']),
|
||||
_('Description of job types')
|
||||
),
|
||||
$angel_types,
|
||||
$selected_angel_types
|
||||
),
|
||||
form_info(
|
||||
'',
|
||||
_('Restricted angel types need will be confirmed later by a supporter. You can change your selection in the options section.')
|
||||
)
|
||||
]),
|
||||
div('col-md-6', [
|
||||
div('row', [
|
||||
div('col-sm-4', [
|
||||
form_text('dect', _('DECT'), $dect)
|
||||
]),
|
||||
div('col-sm-4', [
|
||||
form_text('mobile', _('Mobile'), $mobile)
|
||||
]),
|
||||
div('col-sm-4', [
|
||||
form_text('tel', _('Phone'), $tel)
|
||||
])
|
||||
]),
|
||||
form_text('jabber', _('Jabber'), $jabber),
|
||||
div('row', [
|
||||
div('col-sm-6', [
|
||||
form_text('prename', _('First name'), $preName)
|
||||
]),
|
||||
div('col-sm-6', [
|
||||
form_text('lastname', _('Last name'), $lastName)
|
||||
])
|
||||
]),
|
||||
div('row', [
|
||||
div('col-sm-3', [
|
||||
form_text('age', _('Age'), $age)
|
||||
]),
|
||||
div('col-sm-9', [
|
||||
form_text('hometown', _('Hometown'), $hometown)
|
||||
])
|
||||
]),
|
||||
form_info(entry_required() . ' = ' . _('Entry required!'))
|
||||
])
|
||||
]),
|
||||
// form_textarea('comment', _('Did you help at former CCC events and which tasks have you performed then?'), $comment),
|
||||
form_submit('submit', _('Register'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function entry_required() {
|
||||
return '<span class="text-info glyphicon glyphicon-warning-sign"></span>';
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function entry_required()
|
||||
{
|
||||
return '<span class="text-info glyphicon glyphicon-warning-sign"></span>';
|
||||
}
|
||||
|
||||
function guest_logout() {
|
||||
session_destroy();
|
||||
redirect(page_link_to("start"));
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
function guest_logout()
|
||||
{
|
||||
session()->invalidate();
|
||||
redirect(page_link_to('start'));
|
||||
return true;
|
||||
}
|
||||
|
||||
function guest_login() {
|
||||
$nick = "";
|
||||
|
||||
unset($_SESSION['uid']);
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
|
||||
if (isset($_REQUEST['nick']) && strlen(User_validate_Nick($_REQUEST['nick'])) > 0) {
|
||||
$nick = User_validate_Nick($_REQUEST['nick']);
|
||||
$login_user = sql_select("SELECT * FROM `User` WHERE `Nick`='" . sql_escape($nick) . "'");
|
||||
if (count($login_user) > 0) {
|
||||
$login_user = $login_user[0];
|
||||
if (isset($_REQUEST['password'])) {
|
||||
if (! verify_password($_REQUEST['password'], $login_user['Passwort'], $login_user['UID'])) {
|
||||
$valid = false;
|
||||
error(_("Your password is incorrect. Please try it again."));
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function guest_login()
|
||||
{
|
||||
$nick = '';
|
||||
$request = request();
|
||||
$session = session();
|
||||
$valid = true;
|
||||
|
||||
$session->remove('uid');
|
||||
|
||||
if ($request->has('submit')) {
|
||||
if ($request->has('nick') && strlen(User_validate_Nick($request->input('nick'))) > 0) {
|
||||
$nick = User_validate_Nick($request->input('nick'));
|
||||
$login_user = DB::selectOne('SELECT * FROM `User` WHERE `Nick`=?', [$nick]);
|
||||
if (!empty($login_user)) {
|
||||
if ($request->has('password')) {
|
||||
if (!verify_password($request->postData('password'), $login_user['Passwort'], $login_user['UID'])) {
|
||||
$valid = false;
|
||||
error(_('Your password is incorrect. Please try it again.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please enter a password.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('No user was found with that Nickname. Please try again. If you are still having problems, ask a Dispatcher.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter a password."));
|
||||
$valid = false;
|
||||
error(_('Please enter a nickname.'));
|
||||
}
|
||||
|
||||
if ($valid && !empty($login_user)) {
|
||||
$session->set('uid', $login_user['UID']);
|
||||
$session->set('locale', $login_user['Sprache']);
|
||||
|
||||
redirect(page_link_to('news'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("No user was found with that Nickname. Please try again. If you are still having problems, ask a Dispatcher."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter a nickname."));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$_SESSION['uid'] = $login_user['UID'];
|
||||
$_SESSION['locale'] = $login_user['Sprache'];
|
||||
|
||||
redirect(page_link_to('news'));
|
||||
}
|
||||
}
|
||||
|
||||
$event_config = EventConfig();
|
||||
|
||||
return page([
|
||||
div('col-md-12', [
|
||||
div('row', [
|
||||
EventConfig_countdown_page($event_config)
|
||||
]),
|
||||
div('row', [
|
||||
div('col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4', [
|
||||
div('panel panel-primary first', [
|
||||
div('panel-heading', [
|
||||
'<span class="icon-icon_angel"></span> ' . _("Login")
|
||||
]),
|
||||
div('panel-body', [
|
||||
msg(),
|
||||
form([
|
||||
form_text_placeholder('nick', _("Nick"), $nick),
|
||||
form_password_placeholder('password', _("Password")),
|
||||
form_submit('submit', _("Login")),
|
||||
! $valid ? buttons([
|
||||
button(page_link_to('user_password_recovery'), _("I forgot my password"))
|
||||
]) : ''
|
||||
])
|
||||
]),
|
||||
div('panel-footer', [
|
||||
glyph('info-sign') . _("Please note: You have to activate cookies!")
|
||||
])
|
||||
])
|
||||
])
|
||||
]),
|
||||
div('row', [
|
||||
div('col-sm-6 text-center', [
|
||||
heading(register_title(), 2),
|
||||
get_register_hint()
|
||||
]),
|
||||
div('col-sm-6 text-center', [
|
||||
heading(_("What can I do?"), 2),
|
||||
'<p>' . _("Please read about the jobs you can do to help us.") . '</p>',
|
||||
buttons([
|
||||
button(page_link_to('angeltypes') . '&action=about', _("Teams/Job description") . ' »')
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function get_register_hint() {
|
||||
global $privileges;
|
||||
|
||||
if (in_array('register', $privileges)) {
|
||||
return join('', [
|
||||
'<p>' . _("Please sign up, if you want to help us!") . '</p>',
|
||||
buttons([
|
||||
button(page_link_to('register'), register_title() . ' »')
|
||||
])
|
||||
$event_config = EventConfig();
|
||||
|
||||
return page([
|
||||
div('col-md-12', [
|
||||
div('row', [
|
||||
EventConfig_countdown_page($event_config)
|
||||
]),
|
||||
div('row', [
|
||||
div('col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4', [
|
||||
div('panel panel-primary first', [
|
||||
div('panel-heading', [
|
||||
'<span class="icon-icon_angel"></span> ' . _('Login')
|
||||
]),
|
||||
div('panel-body', [
|
||||
msg(),
|
||||
form([
|
||||
form_text_placeholder('nick', _('Nick'), $nick),
|
||||
form_password_placeholder('password', _('Password')),
|
||||
form_submit('submit', _('Login')),
|
||||
!$valid ? buttons([
|
||||
button(page_link_to('user_password_recovery'), _('I forgot my password'))
|
||||
]) : ''
|
||||
])
|
||||
]),
|
||||
div('panel-footer', [
|
||||
glyph('info-sign') . _('Please note: You have to activate cookies!')
|
||||
])
|
||||
])
|
||||
])
|
||||
]),
|
||||
div('row', [
|
||||
div('col-sm-6 text-center', [
|
||||
heading(register_title(), 2),
|
||||
get_register_hint()
|
||||
]),
|
||||
div('col-sm-6 text-center', [
|
||||
heading(_('What can I do?'), 2),
|
||||
'<p>' . _('Please read about the jobs you can do to help us.') . '</p>',
|
||||
buttons([
|
||||
button(
|
||||
page_link_to('angeltypes', ['action' => 'about']),
|
||||
_('Teams/Job description') . ' »'
|
||||
)
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
//FIXME: return error(_("Registration is disabled."), true);
|
||||
return error("Registration is <a href='https://engelsystem.de/33c3/overwhelmed.html'>disabled</a>.", true);
|
||||
}
|
||||
?>
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function get_register_hint()
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
if (in_array('register', $privileges) && config('registration_enabled')) {
|
||||
return join('', [
|
||||
'<p>' . _('Please sign up, if you want to help us!') . '</p>',
|
||||
buttons([
|
||||
button(page_link_to('register'), register_title() . ' »')
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
return error(_('Registration is disabled.'), true);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
function guest_start() {
|
||||
redirect(page_link_to('login'));
|
||||
function guest_start()
|
||||
{
|
||||
redirect(page_link_to('login'));
|
||||
return true;
|
||||
}
|
||||
?>
|
@ -1,57 +1,88 @@
|
||||
<?php
|
||||
|
||||
function questions_title() {
|
||||
return _("Ask the Heaven");
|
||||
use Engelsystem\Database\DB;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function questions_title()
|
||||
{
|
||||
return _('Ask the Heaven');
|
||||
}
|
||||
|
||||
function user_questions() {
|
||||
global $user;
|
||||
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$open_questions = sql_select("SELECT * FROM `Questions` WHERE `AID` IS NULL AND `UID`='" . sql_escape($user['UID']) . "'");
|
||||
|
||||
$answered_questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL AND `UID`='" . sql_escape($user['UID']) . "'");
|
||||
foreach ($answered_questions as &$question) {
|
||||
$answer_user_source = User($question['AID']);
|
||||
$question['answer_user'] = User_Nick_render($answer_user_source);
|
||||
}
|
||||
|
||||
return Questions_view($open_questions, $answered_questions, page_link_to("user_questions") . '&action=ask');
|
||||
} else {
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'ask':
|
||||
$question = strip_request_item_nl('question');
|
||||
if ($question != "") {
|
||||
$result = sql_query("INSERT INTO `Questions` SET `UID`='" . sql_escape($user['UID']) . "', `Question`='" . sql_escape($question) . "'");
|
||||
if ($result === false) {
|
||||
engelsystem_error(_("Unable to save question."));
|
||||
}
|
||||
success(_("You question was saved."));
|
||||
redirect(page_link_to("user_questions"));
|
||||
} else {
|
||||
return page_with_title(questions_title(), [
|
||||
error(_("Please enter a question!"), true)
|
||||
]);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
|
||||
$question_id = $_REQUEST['id'];
|
||||
} else {
|
||||
return error(_("Incomplete call, missing Question ID."), true);
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function user_questions()
|
||||
{
|
||||
global $user;
|
||||
$request = request();
|
||||
|
||||
if (!$request->has('action')) {
|
||||
$open_questions = DB::select(
|
||||
'SELECT * FROM `Questions` WHERE `AID` IS NULL AND `UID`=?',
|
||||
[$user['UID']]
|
||||
);
|
||||
|
||||
$answered_questions = DB::select(
|
||||
'SELECT * FROM `Questions` WHERE NOT `AID` IS NULL AND `UID`=?',
|
||||
[$user['UID']]
|
||||
);
|
||||
foreach ($answered_questions as &$question) {
|
||||
$answer_user_source = User($question['AID']);
|
||||
$question['answer_user'] = User_Nick_render($answer_user_source);
|
||||
}
|
||||
|
||||
$question = sql_select("SELECT * FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1");
|
||||
if (count($question) > 0 && $question[0]['UID'] == $user['UID']) {
|
||||
sql_query("DELETE FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1");
|
||||
redirect(page_link_to("user_questions"));
|
||||
} else {
|
||||
return page_with_title(questions_title(), [
|
||||
error(_("No question found."), true)
|
||||
]);
|
||||
|
||||
return Questions_view(
|
||||
$open_questions,
|
||||
$answered_questions,
|
||||
page_link_to('user_questions', ['action' => 'ask'])
|
||||
);
|
||||
} else {
|
||||
switch ($request->input('action')) {
|
||||
case 'ask':
|
||||
$question = strip_request_item_nl('question');
|
||||
if ($question != '') {
|
||||
DB::insert('
|
||||
INSERT INTO `Questions` (`UID`, `Question`)
|
||||
VALUES (?, ?)
|
||||
',
|
||||
[$user['UID'], $question]
|
||||
);
|
||||
|
||||
success(_('You question was saved.'));
|
||||
redirect(page_link_to('user_questions'));
|
||||
} else {
|
||||
return page_with_title(questions_title(), [
|
||||
error(_('Please enter a question!'), true)
|
||||
]);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if ($request->has('id') && preg_match('/^\d{1,11}$/', $request->input('id'))) {
|
||||
$question_id = $request->input('id');
|
||||
} else {
|
||||
return error(_('Incomplete call, missing Question ID.'), true);
|
||||
}
|
||||
|
||||
$question = DB::selectOne(
|
||||
'SELECT `UID` FROM `Questions` WHERE `QID`=? LIMIT 1',
|
||||
[$question_id]
|
||||
);
|
||||
if (!empty($question) && $question['UID'] == $user['UID']) {
|
||||
DB::delete(
|
||||
'DELETE FROM `Questions` WHERE `QID`=? LIMIT 1',
|
||||
[$question_id]
|
||||
);
|
||||
redirect(page_link_to('user_questions'));
|
||||
} else {
|
||||
return page_with_title(questions_title(), [
|
||||
error(_('No question found.'), true)
|
||||
]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
?>
|
@ -1,37 +1,50 @@
|
||||
<?php
|
||||
|
||||
function Questions_view($open_questions, $answered_questions, $ask_action) {
|
||||
foreach ($open_questions as &$question) {
|
||||
$question['actions'] = '<a href="' . page_link_to("user_questions") . '&action=delete&id=' . $question['QID'] . '">' . _("delete") . '</a>';
|
||||
$question['Question'] = str_replace("\n", '<br />', $question['Question']);
|
||||
}
|
||||
|
||||
foreach ($answered_questions as &$question) {
|
||||
$question['Question'] = str_replace("\n", '<br />', $question['Question']);
|
||||
$question['Answer'] = str_replace("\n", '<br />', $question['Answer']);
|
||||
$question['actions'] = '<a href="' . page_link_to("user_questions") . '&action=delete&id=' . $question['QID'] . '">' . _("delete") . '</a>';
|
||||
}
|
||||
|
||||
return page_with_title(questions_title(), [
|
||||
msg(),
|
||||
heading(_("Open questions"), 2),
|
||||
table([
|
||||
'Question' => _("Question"),
|
||||
'actions' => ""
|
||||
], $open_questions),
|
||||
heading(_("Answered questions"), 2),
|
||||
table([
|
||||
'Question' => _("Question"),
|
||||
'answer_user' => _("Answered by"),
|
||||
'Answer' => _("Answer"),
|
||||
'actions' => ""
|
||||
], $answered_questions),
|
||||
heading(_("Ask the Heaven"), 2),
|
||||
form([
|
||||
form_textarea('question', _("Your Question:"), ""),
|
||||
form_submit('submit', _("Save"))
|
||||
], $ask_action)
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* @param array[] $open_questions
|
||||
* @param array[] $answered_questions
|
||||
* @param string $ask_action
|
||||
* @return string
|
||||
*/
|
||||
function Questions_view($open_questions, $answered_questions, $ask_action)
|
||||
{
|
||||
foreach ($open_questions as &$question) {
|
||||
$question['actions'] = '<a href="'
|
||||
. page_link_to('user_questions', ['action' => 'delete', 'id' => $question['QID']])
|
||||
. '">'
|
||||
. _('delete')
|
||||
. '</a>';
|
||||
$question['Question'] = str_replace("\n", '<br />', $question['Question']);
|
||||
}
|
||||
|
||||
foreach ($answered_questions as &$question) {
|
||||
$question['Question'] = str_replace("\n", '<br />', $question['Question']);
|
||||
$question['Answer'] = str_replace("\n", '<br />', $question['Answer']);
|
||||
$question['actions'] = '<a href="'
|
||||
. page_link_to('user_questions', ['action' => 'delete', 'id' => $question['QID']])
|
||||
. '">'
|
||||
. _('delete')
|
||||
. '</a>';
|
||||
}
|
||||
|
||||
?>
|
||||
return page_with_title(questions_title(), [
|
||||
msg(),
|
||||
heading(_('Open questions'), 2),
|
||||
table([
|
||||
'Question' => _('Question'),
|
||||
'actions' => ''
|
||||
], $open_questions),
|
||||
heading(_('Answered questions'), 2),
|
||||
table([
|
||||
'Question' => _('Question'),
|
||||
'answer_user' => _('Answered by'),
|
||||
'Answer' => _('Answer'),
|
||||
'actions' => ''
|
||||
], $answered_questions),
|
||||
heading(_('Ask the Heaven'), 2),
|
||||
form([
|
||||
form_textarea('question', _('Your Question:'), ''),
|
||||
form_submit('submit', _('Save'))
|
||||
], $ask_action)
|
||||
]);
|
||||
}
|
||||
|
@ -1,20 +1,42 @@
|
||||
<?php
|
||||
use Engelsystem\ShiftsFilterRenderer;
|
||||
|
||||
use Engelsystem\ShiftCalendarRenderer;
|
||||
use Engelsystem\ShiftsFilterRenderer;
|
||||
|
||||
function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer, ShiftCalendarRenderer $shiftCalendarRenderer) {
|
||||
return page_with_title(glyph('map-marker') . $room['Name'], [
|
||||
$shiftsFilterRenderer->render(room_link($room)) ,
|
||||
$shiftCalendarRenderer->render()
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* @param array $room
|
||||
* @param ShiftsFilterRenderer $shiftsFilterRenderer
|
||||
* @param ShiftCalendarRenderer $shiftCalendarRenderer
|
||||
* @return string
|
||||
*/
|
||||
function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer, ShiftCalendarRenderer $shiftCalendarRenderer)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$assignNotice = '';
|
||||
if (config('signup_requires_arrival') && !$user['Gekommen']) {
|
||||
$assignNotice = info(render_user_arrived_hint(), true);
|
||||
}
|
||||
|
||||
function Room_name_render($room) {
|
||||
global $privileges;
|
||||
if (in_array('view_rooms', $privileges)) {
|
||||
return '<a href="' . room_link($room) . '">' . glyph('map-marker') . $room['Name'] . '</a>';
|
||||
}
|
||||
return glyph('map-marker') . $room['Name'];
|
||||
return page_with_title(glyph('map-marker') . $room['Name'], [
|
||||
$shiftsFilterRenderer->render(page_link_to('rooms', [
|
||||
'action' => 'view',
|
||||
'room_id' => $room['RID']
|
||||
])),
|
||||
$assignNotice,
|
||||
$shiftCalendarRenderer->render()
|
||||
]);
|
||||
}
|
||||
|
||||
?>
|
||||
/**
|
||||
* @param array $room
|
||||
* @return string
|
||||
*/
|
||||
function Room_name_render($room)
|
||||
{
|
||||
global $privileges;
|
||||
if (in_array('view_rooms', $privileges)) {
|
||||
return '<a href="' . room_link($room) . '">' . glyph('map-marker') . $room['Name'] . '</a>';
|
||||
}
|
||||
return glyph('map-marker') . $room['Name'];
|
||||
}
|
||||
|
@ -1,84 +1,145 @@
|
||||
<?php
|
||||
|
||||
function ShiftType_name_render($shifttype) {
|
||||
global $privileges;
|
||||
if (in_array('shifttypes', $privileges)) {
|
||||
return '<a href="' . shifttype_link($shifttype) . '">' . $shifttype['name'] . '</a>';
|
||||
}
|
||||
return $shifttype['name'];
|
||||
/**
|
||||
* @param array $shifttype
|
||||
* @return string
|
||||
*/
|
||||
function ShiftType_name_render($shifttype)
|
||||
{
|
||||
global $privileges;
|
||||
if (in_array('shifttypes', $privileges)) {
|
||||
return '<a href="' . shifttype_link($shifttype) . '">' . $shifttype['name'] . '</a>';
|
||||
}
|
||||
return $shifttype['name'];
|
||||
}
|
||||
|
||||
function ShiftType_delete_view($shifttype) {
|
||||
return page_with_title(sprintf(_("Delete shifttype %s"), $shifttype['name']), [
|
||||
info(sprintf(_("Do you want to delete shifttype %s?"), $shifttype['name']), true),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes'), _("cancel"), 'cancel'),
|
||||
button(page_link_to('shifttypes') . '&action=delete&shifttype_id=' . $shifttype['id'] . '&confirmed', _("delete"), 'ok')
|
||||
])
|
||||
]);
|
||||
/**
|
||||
* @param array $shifttype
|
||||
* @return string
|
||||
*/
|
||||
function ShiftType_delete_view($shifttype)
|
||||
{
|
||||
return page_with_title(sprintf(_('Delete shifttype %s'), $shifttype['name']), [
|
||||
info(sprintf(_('Do you want to delete shifttype %s?'), $shifttype['name']), true),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes'), _('cancel'), 'cancel'),
|
||||
button(
|
||||
page_link_to(
|
||||
'shifttypes',
|
||||
['action' => 'delete', 'shifttype_id' => $shifttype['id'], 'confirmed' => 1]
|
||||
),
|
||||
_('delete'),
|
||||
'ok btn-danger'
|
||||
)
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) {
|
||||
$angeltypes_select = [
|
||||
'' => _('All')
|
||||
];
|
||||
foreach ($angeltypes as $angeltype) {
|
||||
$angeltypes_select[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
|
||||
return page_with_title($shifttype_id ? _('Edit shifttype') : _('Create shifttype'), [
|
||||
msg(),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes'), shifttypes_title(), 'back')
|
||||
]),
|
||||
form([
|
||||
form_text('name', _('Name'), $name),
|
||||
form_select('angeltype_id', _('Angeltype'), $angeltypes_select, $angeltype_id),
|
||||
form_textarea('description', _('Description'), $description),
|
||||
form_info('', _('Please use markdown for the description.')),
|
||||
form_submit('submit', _('Save'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* @param string $name
|
||||
* @param int $angeltype_id
|
||||
* @param array[] $angeltypes
|
||||
* @param string $description
|
||||
* @param int|bool $shifttype_id
|
||||
* @return string
|
||||
*/
|
||||
function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id)
|
||||
{
|
||||
$angeltypes_select = [
|
||||
'' => _('All')
|
||||
];
|
||||
foreach ($angeltypes as $angeltype) {
|
||||
$angeltypes_select[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
|
||||
function ShiftType_view($shifttype, $angeltype) {
|
||||
$parsedown = new Parsedown();
|
||||
$title = $shifttype['name'];
|
||||
if ($angeltype) {
|
||||
$title .= ' <small>' . sprintf(_('for team %s'), $angeltype['name']) . '</small>';
|
||||
}
|
||||
return page_with_title($title, [
|
||||
msg(),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes'), shifttypes_title(), 'back'),
|
||||
$angeltype ? button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], $angeltype['name']) : '',
|
||||
button(page_link_to('shifttypes') . '&action=edit&shifttype_id=' . $shifttype['id'], _('edit'), 'edit'),
|
||||
button(page_link_to('shifttypes') . '&action=delete&shifttype_id=' . $shifttype['id'], _('delete'), 'delete')
|
||||
]),
|
||||
heading(_("Description"), 2),
|
||||
$parsedown->parse($shifttype['description'])
|
||||
]);
|
||||
return page_with_title($shifttype_id ? _('Edit shifttype') : _('Create shifttype'), [
|
||||
msg(),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes'), shifttypes_title(), 'back')
|
||||
]),
|
||||
form([
|
||||
form_text('name', _('Name'), $name),
|
||||
form_select('angeltype_id', _('Angeltype'), $angeltypes_select, $angeltype_id),
|
||||
form_textarea('description', _('Description'), $description),
|
||||
form_info('', _('Please use markdown for the description.')),
|
||||
form_submit('submit', _('Save'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function ShiftTypes_list_view($shifttypes) {
|
||||
foreach ($shifttypes as &$shifttype) {
|
||||
$shifttype['name'] = '<a href="' . page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype['id'] . '">' . $shifttype['name'] . '</a>';
|
||||
$shifttype['actions'] = table_buttons([
|
||||
button(page_link_to('shifttypes') . '&action=edit&shifttype_id=' . $shifttype['id'], _('edit'), 'btn-xs'),
|
||||
button(page_link_to('shifttypes') . '&action=delete&shifttype_id=' . $shifttype['id'], _('delete'), 'btn-xs')
|
||||
/**
|
||||
* @param array $shifttype
|
||||
* @param array $angeltype
|
||||
* @return string
|
||||
*/
|
||||
function ShiftType_view($shifttype, $angeltype)
|
||||
{
|
||||
$parsedown = new Parsedown();
|
||||
$title = $shifttype['name'];
|
||||
if ($angeltype) {
|
||||
$title .= ' <small>' . sprintf(_('for team %s'), $angeltype['name']) . '</small>';
|
||||
}
|
||||
return page_with_title($title, [
|
||||
msg(),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes'), shifttypes_title(), 'back'),
|
||||
$angeltype ? button(
|
||||
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
|
||||
$angeltype['name']
|
||||
) : '',
|
||||
button(
|
||||
page_link_to('shifttypes', ['action' => 'edit', 'shifttype_id' => $shifttype['id']]),
|
||||
_('edit'),
|
||||
'edit'
|
||||
),
|
||||
button(
|
||||
page_link_to('shifttypes', ['action' => 'delete', 'shifttype_id' => $shifttype['id']]),
|
||||
_('delete'),
|
||||
'delete'
|
||||
)
|
||||
]),
|
||||
heading(_('Description'), 2),
|
||||
$parsedown->parse($shifttype['description'])
|
||||
]);
|
||||
}
|
||||
|
||||
return page_with_title(shifttypes_title(), [
|
||||
msg(),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes') . '&action=edit', _('New shifttype'), 'add')
|
||||
]),
|
||||
table([
|
||||
'name' => _('Name'),
|
||||
'actions' => ''
|
||||
], $shifttypes)
|
||||
]);
|
||||
}
|
||||
|
||||
?>
|
||||
/**
|
||||
* @param array[] $shifttypes
|
||||
* @return string
|
||||
*/
|
||||
function ShiftTypes_list_view($shifttypes)
|
||||
{
|
||||
foreach ($shifttypes as &$shifttype) {
|
||||
$shifttype['name'] = '<a href="'
|
||||
. page_link_to('shifttypes', ['action' => 'view', 'shifttype_id' => $shifttype['id']])
|
||||
. '">'
|
||||
. $shifttype['name']
|
||||
. '</a>';
|
||||
$shifttype['actions'] = table_buttons([
|
||||
button(
|
||||
page_link_to(
|
||||
'shifttypes',
|
||||
['action' => 'edit', 'shifttype_id' => $shifttype['id']]
|
||||
),
|
||||
_('edit'),
|
||||
'btn-xs'
|
||||
),
|
||||
button(
|
||||
page_link_to('shifttypes', ['action' => 'delete', 'shifttype_id' => $shifttype['id']]),
|
||||
_('delete'),
|
||||
'btn-xs'
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
return page_with_title(shifttypes_title(), [
|
||||
msg(),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes', ['action' => 'edit']), _('New shifttype'), 'add')
|
||||
]),
|
||||
table([
|
||||
'name' => _('Name'),
|
||||
'actions' => ''
|
||||
], $shifttypes)
|
||||
]);
|
||||
}
|
||||
|
@ -1,88 +1,205 @@
|
||||
<?php
|
||||
|
||||
function UserAngelType_update_view($user_angeltype, $user, $angeltype, $supporter) {
|
||||
return page_with_title($supporter ? _("Add supporter rights") : _("Remove supporter rights"), [
|
||||
msg(),
|
||||
info(sprintf($supporter ? _("Do you really want to add supporter rights for %s to %s?") : _("Do you really want to remove supporter rights for %s from %s?"), $angeltype['name'], User_Nick_render($user)), true),
|
||||
buttons([
|
||||
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
|
||||
button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $user_angeltype['id'] . '&supporter=' . ($supporter ? '1' : '0') . '&confirmed', _("yes"), 'ok')
|
||||
])
|
||||
]);
|
||||
/**
|
||||
* @param array $user_angeltype
|
||||
* @param array $user
|
||||
* @param array $angeltype
|
||||
* @param bool $supporter
|
||||
* @return string
|
||||
*/
|
||||
function UserAngelType_update_view($user_angeltype, $user, $angeltype, $supporter)
|
||||
{
|
||||
return page_with_title($supporter ? _('Add supporter rights') : _('Remove supporter rights'), [
|
||||
msg(),
|
||||
info(sprintf(
|
||||
$supporter
|
||||
? _('Do you really want to add supporter rights for %s to %s?')
|
||||
: _('Do you really want to remove supporter rights for %s from %s?'),
|
||||
$angeltype['name'],
|
||||
User_Nick_render($user)
|
||||
), true),
|
||||
buttons([
|
||||
button(
|
||||
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
|
||||
_('cancel'),
|
||||
'cancel'
|
||||
),
|
||||
button(
|
||||
page_link_to('user_angeltypes', [
|
||||
'action' => 'update',
|
||||
'user_angeltype_id' => $user_angeltype['id'],
|
||||
'supporter' => ($supporter ? '1' : '0'),
|
||||
'confirmed' => 1,
|
||||
]),
|
||||
_('yes'),
|
||||
'ok'
|
||||
)
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function UserAngelTypes_delete_all_view($angeltype) {
|
||||
return page_with_title(_("Deny all users"), [
|
||||
msg(),
|
||||
info(sprintf(_("Do you really want to deny all users for %s?"), $angeltype['name']), true),
|
||||
buttons([
|
||||
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
|
||||
button(page_link_to('user_angeltypes') . '&action=delete_all&angeltype_id=' . $angeltype['id'] . '&confirmed', _("yes"), 'ok')
|
||||
])
|
||||
]);
|
||||
/**
|
||||
* @param array $angeltype
|
||||
* @return string
|
||||
*/
|
||||
function UserAngelTypes_delete_all_view($angeltype)
|
||||
{
|
||||
return page_with_title(_('Deny all users'), [
|
||||
msg(),
|
||||
info(sprintf(_('Do you really want to deny all users for %s?'), $angeltype['name']), true),
|
||||
buttons([
|
||||
button(
|
||||
page_link_to(
|
||||
'angeltypes',
|
||||
['action' => 'view', 'angeltype_id' => $angeltype['id']]
|
||||
),
|
||||
_('cancel'),
|
||||
'cancel'
|
||||
),
|
||||
button(
|
||||
page_link_to(
|
||||
'user_angeltypes',
|
||||
['action' => 'delete_all', 'angeltype_id' => $angeltype['id'], 'confirmed' => 1]
|
||||
),
|
||||
_('yes'),
|
||||
'ok'
|
||||
)
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function UserAngelTypes_confirm_all_view($angeltype) {
|
||||
return page_with_title(_("Confirm all users"), [
|
||||
msg(),
|
||||
info(sprintf(_("Do you really want to confirm all users for %s?"), $angeltype['name']), true),
|
||||
buttons([
|
||||
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
|
||||
button(page_link_to('user_angeltypes') . '&action=confirm_all&angeltype_id=' . $angeltype['id'] . '&confirmed', _("yes"), 'ok')
|
||||
])
|
||||
]);
|
||||
/**
|
||||
* @param array $angeltype
|
||||
* @return string
|
||||
*/
|
||||
function UserAngelTypes_confirm_all_view($angeltype)
|
||||
{
|
||||
return page_with_title(_('Confirm all users'), [
|
||||
msg(),
|
||||
info(sprintf(_('Do you really want to confirm all users for %s?'), $angeltype['name']), true),
|
||||
buttons([
|
||||
button(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]), _('cancel'),
|
||||
'cancel'),
|
||||
button(
|
||||
page_link_to('user_angeltypes',
|
||||
['action' => 'confirm_all', 'angeltype_id' => $angeltype['id'], 'confirmed' => 1]),
|
||||
_('yes'),
|
||||
'ok'
|
||||
)
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function UserAngelType_confirm_view($user_angeltype, $user, $angeltype) {
|
||||
return page_with_title(_("Confirm angeltype for user"), [
|
||||
msg(),
|
||||
info(sprintf(_("Do you really want to confirm %s for %s?"), User_Nick_render($user), $angeltype['name']), true),
|
||||
buttons([
|
||||
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
|
||||
button(page_link_to('user_angeltypes') . '&action=confirm&user_angeltype_id=' . $user_angeltype['id'] . '&confirmed', _("yes"), 'ok')
|
||||
])
|
||||
]);
|
||||
/**
|
||||
* @param array $user_angeltype
|
||||
* @param array $user
|
||||
* @param array $angeltype
|
||||
* @return string
|
||||
*/
|
||||
function UserAngelType_confirm_view($user_angeltype, $user, $angeltype)
|
||||
{
|
||||
return page_with_title(_('Confirm angeltype for user'), [
|
||||
msg(),
|
||||
info(sprintf(_('Do you really want to confirm %s for %s?'), User_Nick_render($user), $angeltype['name']), true),
|
||||
buttons([
|
||||
button(
|
||||
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
|
||||
_('cancel'),
|
||||
'cancel'
|
||||
),
|
||||
button(
|
||||
page_link_to(
|
||||
'user_angeltypes',
|
||||
['action' => 'confirm', 'user_angeltype_id' => $user_angeltype['id'], 'confirmed' => 1]
|
||||
),
|
||||
_('yes'),
|
||||
'ok'
|
||||
)
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function UserAngelType_delete_view($user_angeltype, $user, $angeltype) {
|
||||
return page_with_title(_("Remove angeltype"), [
|
||||
msg(),
|
||||
info(sprintf(_("Do you really want to delete %s from %s?"), User_Nick_render($user), $angeltype['name']), true),
|
||||
buttons([
|
||||
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
|
||||
button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $user_angeltype['id'] . '&confirmed', _("yes"), 'ok')
|
||||
])
|
||||
]);
|
||||
/**
|
||||
* @param array $user_angeltype
|
||||
* @param array $user
|
||||
* @param array $angeltype
|
||||
* @return string
|
||||
*/
|
||||
function UserAngelType_delete_view($user_angeltype, $user, $angeltype)
|
||||
{
|
||||
return page_with_title(_('Remove angeltype'), [
|
||||
msg(),
|
||||
info(sprintf(_('Do you really want to delete %s from %s?'), User_Nick_render($user), $angeltype['name']), true),
|
||||
buttons([
|
||||
button(
|
||||
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
|
||||
_('cancel'),
|
||||
'cancel'
|
||||
),
|
||||
button(
|
||||
page_link_to('user_angeltypes',
|
||||
['action' => 'delete', 'user_angeltype_id' => $user_angeltype['id'], 'confirmed' => 1]),
|
||||
_('yes'),
|
||||
'ok'
|
||||
)
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function UserAngelType_add_view($angeltype, $users_source, $user_id) {
|
||||
$users = [];
|
||||
foreach ($users_source as $user_source) {
|
||||
$users[$user_source['UID']] = User_Nick_render($user_source);
|
||||
}
|
||||
|
||||
return page_with_title(_("Add user to angeltype"), [
|
||||
msg(),
|
||||
buttons([
|
||||
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("back"), 'back')
|
||||
]),
|
||||
form([
|
||||
form_info(_("Angeltype"), $angeltype['name']),
|
||||
form_select('user_id', _("User"), $users, $user_id),
|
||||
form_submit('submit', _("Add"))
|
||||
])
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* @param array $angeltype
|
||||
* @param array[] $users_source
|
||||
* @param int $user_id
|
||||
* @return string
|
||||
*/
|
||||
function UserAngelType_add_view($angeltype, $users_source, $user_id)
|
||||
{
|
||||
$users = [];
|
||||
foreach ($users_source as $user_source) {
|
||||
$users[$user_source['UID']] = User_Nick_render($user_source);
|
||||
}
|
||||
|
||||
function UserAngelType_join_view($user, $angeltype) {
|
||||
return page_with_title(sprintf(_("Become a %s"), $angeltype['name']), [
|
||||
msg(),
|
||||
info(sprintf(_("Do you really want to add %s to %s?"), User_Nick_render($user), $angeltype['name']), true),
|
||||
buttons([
|
||||
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
|
||||
button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'] . '&user_id=' . $user['UID'] . '&confirmed', _("save"), 'ok')
|
||||
])
|
||||
]);
|
||||
return page_with_title(_('Add user to angeltype'), [
|
||||
msg(),
|
||||
buttons([
|
||||
button(
|
||||
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
|
||||
_('back'),
|
||||
'back'
|
||||
)
|
||||
]),
|
||||
form([
|
||||
form_info(_('Angeltype'), $angeltype['name']),
|
||||
form_select('user_id', _('User'), $users, $user_id),
|
||||
form_submit('submit', _('Add'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
?>
|
||||
/**
|
||||
* @param array $user
|
||||
* @param array $angeltype
|
||||
* @return string
|
||||
*/
|
||||
function UserAngelType_join_view($user, $angeltype)
|
||||
{
|
||||
return page_with_title(sprintf(_('Become a %s'), $angeltype['name']), [
|
||||
msg(),
|
||||
info(sprintf(_('Do you really want to add %s to %s?'), User_Nick_render($user), $angeltype['name']), true),
|
||||
buttons([
|
||||
button(
|
||||
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
|
||||
_('cancel'),
|
||||
'cancel'
|
||||
),
|
||||
button(
|
||||
page_link_to(
|
||||
'user_angeltypes',
|
||||
['action' => 'add', 'angeltype_id' => $angeltype['id'], 'user_id' => $user['UID'], 'confirmed' => 1]
|
||||
),
|
||||
_('save'),
|
||||
'ok'
|
||||
)
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -1,24 +1,19 @@
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
bootstrap="./includes/engelsystem_provider.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false">
|
||||
<testsuites>
|
||||
<testsuite name="Models">
|
||||
<directory>./test/model/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./include/</directory>
|
||||
<directory>./public/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<php>
|
||||
<const name="PHPUNIT_TESTSUITE" value="true" />
|
||||
</php>
|
||||
bootstrap="./tests/autoload.php"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.3/phpunit.xsd"
|
||||
colors="true"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Feature">
|
||||
<directory>./tests/Feature</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Unit">
|
||||
<directory>./tests/Unit</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./src/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
@ -0,0 +1,8 @@
|
||||
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine on
|
||||
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^ index.php [L]
|
||||
</IfModule>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue