Commit 1fe5273a authored by Σταύρος Παπαδάκης's avatar Σταύρος Παπαδάκης

Merge branch 'volunteer-forms' into 'master'

Volunteer forms

See merge request !29
parents 7f10e8cc b7d1935e
......@@ -28,7 +28,8 @@ return [
'module/open_data/bootstrap.php',
'module/university_form/bootstrap.php',
'module/teacher_form/bootstrap.php',
'module/enable_db_login/bootstrap.php',
'module/admin/bootstrap.php',
],
'cache_config' => 'data/cache/config/settings.php',
];
......@@ -47,7 +47,9 @@ return [
['/teacher-form', ['guest'], ['get', 'post']],
['/teacher-form/submit-success',['guest'], ['get','post']],
['/teacher-form/mm',['guest'], ['get']],
['/admin', ['admin'], ['get']],
['/admin/university-form/display', ['admin'], ['get']],
['/admin/teacher-form/display', ['admin'], ['get']],
],
],
],
......
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return [
'enabledblogin' => [
'enable_routes' => [
'enabledblogin'
],
'enable_patterns' => [
'/enabledblogin'
],
'disable_routes' => [
'disabledblogin',
'user.logout'
],
'disable_patterns' => [
'/disabledblogin',
'/user/logout'
],
],
];
......@@ -79,5 +79,11 @@ return [
],
],
'admin' => [
'adminhome' => [
'label' => 'Σελίδα διαχειριστή',
'route' => 'admin',
],
]
],
];
# Υποσύστημα διαχειριστή
Παρέχει πρόσβαση σε διαχειριστικές λειτουργίες. Εφόσον ο χρήστης πιστοποιείται
με ρόλο admin εμφανίζεται το μενού διαχειριστικών λειτουργιών.
## Routes
Διαθέσιμα routes (paths) και λειτουργίες.
- admin (/admin): αρχική σελίδα διαχειριστή
## Οδηγίες
Για να είναι προσβάσιμο, πρέπει:
- να προσθέσετε την παρακάτω γραμμή στο `acl.global.php` ή `acl.local.php`,
στο acl.guards.routes
```
['/admin', ['admin'], ['get']],
```
<?php
use Slim\App;
use Slim\Container;
use Slim\Http\Request;
use Slim\Http\Response;
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return function (App $app) {
$container = $app->getContainer();
$events = $container['events'];
$events('on', 'app.autoload', function ($autoloader) {
$autoloader->addPsr4('GrEduLabs\\Admin\\', __DIR__ . '/src/');
});
$events('on', 'app.services', function (Container $container) {
$container[GrEduLabs\Admin\Action\Index::class] = function ($c) {
return new GrEduLabs\Admin\Action\Index($c['view']);
};
});
$events('on', 'app.bootstrap', function (App $app, Container $c) {
$view = $c->get('view');
$view->getEnvironment()->getLoader()->prependPath(__DIR__ . '/templates');
$app->get('/admin', GrEduLabs\Admin\Action\Index::class)
->setName('admin');
});
};
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\Admin\Action;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Views\Twig;
class Index {
/**
* @var Twig
*/
protected $view;
/**
* Constructor.
*
* @param Twig $view
*/
public function __construct(Twig $view) {
$this->view = $view;
}
public function __invoke(Request $req, Response $res) {
return $this->view->render($res, 'admin/index.twig');
}
}
{% extends "layout.twig" %}
{% block content %}
<div id="adminarea">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Σελίδα διαχειριστή</h4>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Διαθέσιμες διαχειριστικές λειτουργίες</th>
<th>&nbsp;</th>
<tr>
</thead>
<tbody>
<tr>
<td>Καταχωρημένες αιτήσεις εθελοντών - Εκπαιδευτικοί</td>
<td class="text-right">
<a class="btn btn-primary btn-sm" href="{{ path_for('export.csv', {type: 'volunteer_teachers'}) }}"><i class="fa fa-download"></i> Αρχείο .csv</a>
<a class="btn btn-default btn-sm" href="{{ path_for('admin.volunteer.teacher') }}"><span class="fa fa-list"></span> Προβολή</a>
</td>
</tr>
<tr>
<td>Καταχωρημένες αιτήσεις εθελοντών - Ιδρύματα</td>
<td class="text-right">
<a class="btn btn-primary btn-sm" href="{{ path_for('export.csv', {type: 'volunteer_institutions'}) }}"><span class="fa fa-download"></span> Αρχείο .csv</a>
<a class="btn btn-default btn-sm" href="{{ path_for('admin.volunteer.univ') }}"><span class="fa fa-list"></span> Προβολή</a>
</td>
</tr>
</tbody>
</table>
<div class="panel-footer text-center">
<a class="btn btn-sm btn-default" href="{{ path_for('index') }}"><span class="fa fa-home"></span> Αρχική</a>
<a class="btn btn-sm btn-primary" href="{{ path_for('admin') }}"><span class="fa fa-user-secret"></span> Διαχειριστής</a>
<a class="btn btn-sm btn-default" href="{{ path_for('user.logout') }}"><span class="fa fa-lock"></span> Αποσύνδεση</a>
</div>
</div>
</div>
{% endblock %}
......@@ -27,6 +27,16 @@
{% for page in nav('main') %}
{{ macros.li(page)}}
{% endfor %}
{% if not nav('admin') is empty %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="fa fa-user-secret"></span> Διαχειριστής <span class="caret"></span></a>
<ul class="dropdown-menu">
{% for page in nav('admin') %}
{{ macros.li(page)}}
{% endfor %}
</ul>
</li>
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% for page in nav('authentication') %}
......
......@@ -7,6 +7,7 @@ use Slim\App;
use Slim\Container;
use Slim\Http\Request;
use Slim\Http\Response;
use GrEduLabs\UniversityForm\Service\UniversityFormService;
/**
* gredu_labs.
......@@ -22,6 +23,13 @@ return function (App $app) {
$events('on', 'app.services', function (Container $c) {
$c['csv_export_protected_exports'] = function ($c) {
return [
'volunteer_teachers',
'volunteer_institutions',
];
};
$c['csv_export_config'] = function ($c) {
return [
......@@ -95,7 +103,6 @@ return function (App $app) {
'Σχόλια - Παρατηρήσεις',
],
],
'appnewforms' => [
'data_callback' => 'csv_export_appnewforms',
'headers' => [
......@@ -107,8 +114,6 @@ return function (App $app) {
'Σχόλια - Παρατηρήσεις',
],
],
'appforms_items' => [
'data_callback' => 'csv_export_appforms_items',
'headers' => [
......@@ -142,6 +147,63 @@ return function (App $app) {
'Αιτιολογία χρήσης',
],
],
'volunteer_teachers' => [
'data_callback' => 'csv_export_volunteer_teachers',
'headers' => [
'ID',
'Όνομα',
'Επώνυμο',
'Ειδικότητα',
'Ειδικότητα (λεκτικό)',
'Αριθμός Μητρώου',
'Τηλέφωνο',
'Email',
'Σχολείο που υπηρετεί',
'Τηλέφωνο Σχολείου',
'Σχόλια/Παρατηρήσεις',
'Σχετική δράση που συμμετείχε',
'URL δράσης που συμμετείχε',
'Περιγραφή δράσης που συμμετείχε',
'Έργο 1',
'Έργο 2',
'Έργο 3',
'Έργο 4',
'Έργο 5',
'Έργο 6',
'Έργο 7',
'Έργο 8',
'Έργο 9',
'Έργο 10',
],
],
'volunteer_institutions' => [
'data_callback' => 'csv_export_volunteer_institutions',
'headers' => [
'ID',
'Ίδρυμα',
'Σχολή',
'Τμήμα',
'Ερευνητικό Κέντρο',
'Ινστιτούτο',
'Άλλο',
'Υπεύθυνος Επικοινωνίας',
'Τηλέφωνο',
'Email',
'Σχόλια/Παρατηρήσεις',
'Έργα',
'Περιγραφή (ακολουθούν ανά στήλη)',
'Έργο 1',
'Έργο 2',
'Έργο 3',
'Έργο 4',
'Έργο 5',
'Έργο 6',
'Έργο 7',
'Έργο 8',
'Έργο 9',
'Έργο 10',
],
],
];
};
......@@ -179,6 +241,78 @@ return function (App $app) {
};
};
$c['csv_export_volunteer_teachers'] = function ($c) {
return function () {
$sql = 'SELECT `volunteerteachers`.`id`, '
. '`volunteerteachers`.`name`, '
. '`volunteerteachers`.`surname`, '
. '`volunteerteachers`.`eidikothta`, '
. '`branch`.`name` AS `eidikothta_name`, '
. '`volunteerteachers`.`arithmitroou`, '
. '`volunteerteachers`.`telef`, '
. '`volunteerteachers`.`email`, '
. '`volunteerteachers`.`school`, '
. '`volunteerteachers`.`schooltelef`, '
. '`volunteerteachers`.`comments`, '
. '`volunteerteachers`.`projecttitle`, '
. '`volunteerteachers`.`projecturl`, '
. '`volunteerteachers`.`projectdescription` '
. ' FROM `volunteerteachers` JOIN `branch` ON (`volunteerteachers`.`eidikothta` = `branch`.`id`) '
// . ' FROM `volunteerteachers` '
. ' ORDER BY id ';
$volunteer_teachers = R::getAll($sql);
$volunteer_teachers = array_map(function ($row) {
$row['projectdescription'] = UniversityFormService::recomposeProjects($row['projectdescription'], false);
if (($projects = preg_split('/' . UniversityFormService::PLAIN_TEXT_SEPARATOR . '/msUu', $row['projectdescription'])) !== false) {
foreach ($projects as $i => $proj) {
$row["project{$i}"] = $proj;
}
}
return $row;
}, $volunteer_teachers);
return $volunteer_teachers;
};
};
$c['csv_export_volunteer_institutions'] = function ($c) {
return function () {
$sql = 'SELECT `id`, '
. '`idrima`, '
. '`sxolh`, '
. '`tmhma`, '
. '`ereunitiko`, '
. '`institute`, '
. '`other`,'
. '`person`, '
. '`telef`, '
. '`email`, '
. '`comments`, '
. '`erga`, '
. '`projectdescription` '
. ' FROM `univ` '
. ' ORDER BY id';
$volunteer_institutions = R::getAll($sql);
$volunteer_institutions = array_map(function ($row) {
$row['projectdescription'] = UniversityFormService::recomposeProjects($row['projectdescription'], false);
if (($projects = preg_split('/' . UniversityFormService::PLAIN_TEXT_SEPARATOR . '/msUu', $row['projectdescription'])) !== false) {
foreach ($projects as $i => $proj) {
$row["project{$i}"] = $proj;
}
}
return $row;
}, $volunteer_institutions);
return $volunteer_institutions;
};
};
$c['csv_export_schools'] = function ($c) {
return function () {
......@@ -347,7 +481,6 @@ return function (App $app) {
$appForms = R::getAll($sql, $appFormIds);
return $appForms;
};
};
......@@ -392,7 +525,7 @@ return function (App $app) {
$c['csv_export_appforms_items'] = function ($c) {
return function () use ($c){
return function () use ($c) {
$settings = $c->get('settings');
$version = $settings['application_form']['itemcategory']['currentversion'];
......@@ -487,13 +620,22 @@ return function (App $app) {
return $appForms;
};
};
});
$events('on', 'app.bootstrap', function (App $app, Container $c) {
$app->get('/export/csv/edulabs_{type}.csv', function (Request $req, Response $res, array $args) use ($c) {
$type = $args['type'];
$role = call_user_func($c['current_role']);
if (in_array($type, $c['csv_export_protected_exports'])) {
if ($role !== 'admin') {
$res = $res->withStatus(403);
$res->getBody()->write('Forbidden. The information requested in not available.');
return $res;
}
}
try {
$config = $c['csv_export_config'];
......
# Ενεργοποίηση σύνδεσης μέσω βάσης δεδομένων
Το συγκεκριμένο module ενεργοποιεί τη φόρμα σύνδεσης μέσω βάση δεδομένων
άσχετα από τη ρύθμιση Container['settings']['sso']['enable_database_login'].
Χρειάζεται να ενεργοποιηθεί μόνο στην περίπτωση που έχει ενεργοποιηθεί το
module sch_sso και απαιτείται σύνδεση τοπικού χρήστη για συγκεκριμένες
λειτουργίες.
## Ρυθμίσεις
Το αρχείο `enable_db_login.{global,local}.php χρησιμοποιείται για την
παραμετροποίηση. Οι προεπιλεγμένες ρυθμίσεις είναι οι παρακάτω.
```
'enabledblogin' => [
'enable_routes' => [
'enabledblogin'
],
'enable_patterns' => [
'/enabledblogin'
],
'disable_routes' => [
'disabledblogin',
'user.logout'
],
'disable_patterns' => [
'/disabledblogin',
'/user/logout'
],
],
```
Οι ρυθμίσεις έχουν ως εξής:
- enable_routes: ονόματα routes που ενεργοποιούν τη σύνδεση μέσω ΒΔ
- enable_patterns: url paths που ενεργοποιούν τη σύνδεση μέσω ΒΔ
- disable_routes: ονόματα routes που απενεργοποιούν τη σύνδεση μέσω ΒΔ
- disable_patterns: url paths που απενεργοποιούν τη σύνδεση μέσω ΒΔ
_Προτεραιότητα έχει η απενεργοποίηση._
##Routes
Το module δηλώνει δύο routes (στα αντίστοιχα paths) ώστε να παρέχεται ένα
παράδειγμα χρήσης.
- enabledblogin (/enabledblogin) που ενεργοποιεί τη σύνδεση μέσω ΒΔ
- disabledblogin (/disabledblogin) που απενεργοποιεί τη σύνδεση μέσω ΒΔ
*Δεν* είναι απαραίτητο να προστεθούν τα routes στο `acl.{global,local}.php`
(acl.guards.routes).
<?php
use Slim\App;
use Slim\Container;
use Slim\Http\Request;
use Slim\Http\Response;
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return function (App $app) {
$container = $app->getContainer();
$events = $container['events'];
$events('on', 'app.autoload', function ($autoloader) {
$autoloader->addPsr4('GrEduLabs\\EnableDBLogin\\', __DIR__ . '/src/');
});
$events('on', 'app.services', function (Container $container) {
$container[GrEduLabs\EnableDBLogin\Middleware\EnableDBLogin::class] = function ($c) {
return new GrEduLabs\EnableDBLogin\Middleware\EnableDBLogin($c);
};
$container[GrEduLabs\EnableDBLogin\Action\Index::class] = function ($c) {
return new GrEduLabs\EnableDBLogin\Action\Index($c);
};
});
$events('on', 'app.bootstrap', function (App $app, Container $c) {
$app->add(GrEduLabs\EnableDBLogin\Middleware\EnableDBLogin::class);
});
$events('on', 'app.bootstrap', function (App $app, Container $c) {
if (isset($_SESSION['enableDLogin'])) {
$c['router']->getNamedRoute('user.login')->add(function (Request $req, Response $res, callable $next) use ($c) {
$c['view']['enable_database_login'] = true;
return $next($req, $res);
});
}
}, -98); // must be in order to set last
$events('on', 'app.bootstrap', function (App $app, Container $c) {
$app->get('/enabledblogin', GrEduLabs\EnableDBLogin\Action\Index::class)
->setName('enabledblogin');
$app->get('/disabledblogin', GrEduLabs\EnableDBLogin\Action\Index::class)
->setName('disabledblogin');
});
};
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\EnableDBLogin\Action;
use Slim\Container;
use Slim\Http\Request;
use Slim\Http\Response;
class Index {
protected $_c;
/**
* Constructor.
*
* @param Twig $view
*/
public function __construct(Container $c) {
$this->_c = $c;
}
public function __invoke(Request $req, Response $res) {
return $res->withRedirect($this->_c['router']->pathFor('index'));
}
}
<?php
/**
* EnableDBLogin enables the database login form for specific routes or urls.
* To use set the enable_db_login.{global,local}.php
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\EnableDBLogin\Middleware;
use Slim\Container;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class EnableDBLogin {
private $_c;
public function __construct(Container $c) {
$this->_c = $c;
}
public function __invoke(ServerRequestInterface $req, ResponseInterface $res, callable $next) {
$route = $req->getAttribute('route');
if ($route) {
$routeName = $route->getName();
$routePattern = $route->getPattern();
$dblogin_settings = $this->_c->get('settings')->get('enabledblogin');
if ($dblogin_settings) {
$enableRouteNames = isset($dblogin_settings['enable_routes']) ? $dblogin_settings['enable_routes'] : [];
$enableRoutePatterns = isset($dblogin_settings['enable_patterns']) ? $dblogin_settings['enable_patterns'] : [];
$disableRouteNames = isset($dblogin_settings['disable_routes']) ? $dblogin_settings['disable_routes'] : [];
$disableRoutePatterns = isset($dblogin_settings['disable_patterns']) ? $dblogin_settings['disable_patterns'] : [];
if (in_array($routeName, $enableRouteNames) ||
in_array($routePattern, $enableRoutePatterns)) {
$_SESSION['enableDLogin'] = true;
$this->_c['logger']->info("SET enableDLogin via route=[" . var_export($routeName, true) . '], path=[' . var_export($routePattern, true) . ']');
}
if (in_array($routeName, $disableRouteNames) ||
in_array($routePattern, $disableRoutePatterns)) {
unset($_SESSION['enableDLogin']);
$this->_c['logger']->info("UNSET enableDLogin via route=[" . var_export($routeName, true) . '], path=[' . var_export($routePattern, true) . ']');
}
}
}
return $next($req, $res);
}
}
......@@ -12,7 +12,6 @@ use Slim\Http\Response;
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return function (App $app) {
$container = $app->getContainer();
$events = $container['events'];
......@@ -33,17 +32,22 @@ return function (App $app) {
$container[GrEduLabs\TeacherForm\Action\TeacherForm::class] = function ($c) {
return new GrEduLabs\TeacherForm\Action\TeacherForm(
$c->get('view'),
$c->get(GrEduLabs\TeacherForm\Service\TeacherFormServiceInterface::class),
$c->get(GrEduLabs\TeacherForm\InputFilter\TeacherForm::class),
$c->get('router')->pathFor('teacher_form.submit_success'),
$c);
$c->get('view'), $c->get(GrEduLabs\TeacherForm\Service\TeacherFormServiceInterface::class), $c->get(GrEduLabs\TeacherForm\InputFilter\TeacherForm::class), $c->get('router')->pathFor('teacher_form.submit_success'), $c);
};
$container[GrEduLabs\TeacherForm\Action\SubmitSuccess::class] = function ($c) {
return new GrEduLabs\TeacherForm\Action\SubmitSuccess(
$c->get('view'),
$c->get('router')->pathFor('teacher_form')
$c->get('view'), $c->get('router')->pathFor('teacher_form')
);
};
$container[GrEduLabs\TeacherForm\Service\TeacherFormServiceInterface::class] = function ($c) {
return new GrEduLabs\TeacherForm\Service\TeacherFormService();
};
$container[GrEduLabs\TeacherForm\Action\Display::class] = function ($c) {
return new GrEduLabs\TeacherForm\Action\Display(
$c->get('view'), $c->get(GrEduLabs\TeacherForm\Service\TeacherFormServiceInterface::class)
);
};
});
......@@ -78,7 +82,7 @@ return function (App $app) {
}
$cnt = count($responseData['data']);
$school_arr = [];
for ($i=0; $i<$cnt; $i++) {
for ($i = 0; $i < $cnt; $i++) {
$school_arr[$i]['mm_id'] = $responseData['data'][$i]['mm_id'];
$school_arr[$i]['value'] = $responseData['data'][$i]['name'];
$school_arr[$i]['tel'] = $responseData['data'][$i]['phone_number'];
......@@ -86,5 +90,8 @@ return function (App $app) {
return $res->withJson($school_arr);
})->setName('teacher_form.mm');
$app->get('/admin/teacher-form/display', GrEduLabs\TeacherForm\Action\Display::class)
->setName('admin.volunteer.teacher');
});
};
ALTER TABLE `volunteerteachers` MODIFY `eidikothta` int(11) UNSIGNED;
ALTER TABLE `volunteerteachers` ADD CONSTRAINT `fk_branch_id` FOREIGN KEY (`eidikothta`) REFERENCES `branch`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
......@@ -13,61 +13,61 @@
$("#select_school").autocomplete({
source: window.location.protocol + "//" + window.location.host + "/teacher-form/mm",
minLength: 4,
select: function(event, ui) {
select: function (event, ui) {
console.log(ui);
$("#mm_id").val(ui.item.mm_id);
$("#el-school").val(ui.item.value);
$("#el-schooltelef").val(ui.item.tel);
},
html: false,
open: function(event, ui) {
open: function (event, ui) {
$(".ui-autocomplete").css("z-index", 1000);
}
});
}(window.jQuery, _, window.EDULABS.utils));