Merge branch 'master' into permissions

This commit is contained in:
Paolo
2018-06-21 15:19:59 +02:00
30 changed files with 722 additions and 194 deletions
+214
View File
@@ -0,0 +1,214 @@
<?php
/**
* FH-Complete
*
* @package FHC-API
* @author FHC-Team
* @copyright Copyright (c) 2016, fhcomplete.org
* @license GPLv3
* @link http://fhcomplete.org
* @since Version 1.0
* @filesource
*/
if (! defined('BASEPATH'))
exit('No direct script access allowed');
class AmpelMail extends FHC_Controller
{
const CIS_AMPELVERWALTUNG_URL =
CIS_ROOT. "index.php?sprache=German&content_id=&menu=".
CIS_ROOT. "menu.php?content_id=&content=".
CIS_ROOT. "private/tools/ampelverwaltung.php";
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
// Allow script execution only from CLI
if ($this->input->is_cli_request())
{
$cli = true;
}
else
{
$this->output->set_status_header(403, 'Jobs must be run from the CLI');
echo "Jobs must be run from the CLI";
exit;
}
// Load models
$this->load->model('content/Ampel_model', 'AmpelModel');
$this->load->model('person/Person_model', 'PersonModel');
// Load helpers
$this->load->helper('sancho');
}
/**
* Main function index as help
*
* @return void
*/
public function index()
{
$result = "The following are the available command line interface commands\n\n";
$result .= "php index.ci.php jobs/AmpelMail generateAmpelMail";
echo $result. PHP_EOL;
}
/**
* Generates mail content for new and overdue Ampeln, which
* 1. are not confirmed by the user yet and
* 2. are marked to be sent by email
* Ampel is new when inserted within the last 7 days before the cronjob runs (as cronjob runs weekly)
* Ampel is overdue when the cronjob runs after the deadline date.
* @return void
*/
public function generateAmpelMail()
{
// Get all notifications, that are not expired, not before vorlaufzeit AND email is true
$result_active_ampeln = $this->AmpelModel->active(true);
// Stores users, description, deadline and system-link of notifications
$new_ampel_data_arr = array(); // data of new notifications that are not confirmed
$overdue_ampel_data_arr = array(); // data of overdue notifications that are not confirmed
if (hasData($result_active_ampeln))
{
$ampel_arr = $result_active_ampeln->retval;
// Loop through ampeln
foreach ($ampel_arr as $ampel)
{
$ampel_id = $ampel->ampel_id;
$now = date_create(date('Y-m-d'));
$deadline = date_create($ampel->deadline);
$insert_date = date_create($ampel->insertamum);
$qry_all_ampel_user = $ampel->benutzer_select; // sql select to get all user who get this ampel
$new = false;
$overdue = false;
// get all user, who get this ampel
$result_ampel_user = $this->AmpelModel->execBenutzerSelect($qry_all_ampel_user);
if (hasData($result_ampel_user))
{
$ampel_user_arr = $result_ampel_user->retval;
// loop through all user, who get this ampel
foreach ($ampel_user_arr as $ampel_user)
{
$uid = $ampel_user->uid;
// break if ampel was almost confirmed by the user
if($this->AmpelModel->isConfirmed($ampel_id, $uid)) break;
// check if ampel is new (inserted within last week, as cronjob will run every week)
if ($now->diff($insert_date)->days <= 7) $new = true;
//check if ampel is overdue
if ($now > $deadline) $overdue = true;
// if ampel is new
if ($new)
{
$html_text = '<p><strong>'. strtoupper($ampel->kurzbz). '</strong></p><br>';
// create template-specific data array of new notifications
// if uid already exists in the array, only the html text will be added to the existing html text
$new_ampel_data_arr =
$this->_getAmpelContentData($uid, $html_text, $new_ampel_data_arr);
}
// if ampel is overdue
if ($overdue)
{
$html_text = '
<p><strong>'. strtoupper($ampel->kurzbz). '</strong><br>
<small>
<i style="color: #65696E;">Die Deadline für die Bestätigung war am
<span style="color: #FF0000;">'. date_format($deadline, 'Y-m-d'). '</span>
</i>
</small></p><br>';
// create template-specific data array of overdue notifications
// if uid already exists in the array, only the html text will be added to the existing html text
$overdue_ampel_data_arr =
$this->_getAmpelContentData($uid, $html_text, $overdue_ampel_data_arr);
}
}
}
elseif (isError($result_ampel_user))
{
show_error($result_ampel_user->error);
}
}
}
elseif (isError($result_active_ampeln))
{
show_error($result_active_ampeln->error);
}
// Send mails for new ampeln merged by user
foreach ($new_ampel_data_arr as $new_ampel_data)
{
sendMail(
'Sancho_Content_AmpelNeu',
$new_ampel_data,
$new_ampel_data['uid']. '@'. DOMAIN,
'Du hast eine neue Ampel!',
'sancho_header_neue_nachrichten_in_ampelsystem.jpg'
);
};
// Send mails for overdue ampeln merged by user
foreach ($overdue_ampel_data_arr as $overdue_ampel_data)
{
sendMail(
'Sancho_Content_AmpelUeberfaellig',
$overdue_ampel_data,
$overdue_ampel_data['uid']. '@'. DOMAIN,
'Bestätige bitte Deine Ampel!',
'sancho_header_ampel_overdue.jpg'
);
};
}
// ------------------------------------------------------------------------
// Private methods
/**
* Returns associative array with data as needed in the ampel content templates.
* @param string $uid UID, needed to merge user.
* @param string $html_text Specific HTML Content to be set initially for a user or to add if user exists.
* @param array $ampel_data_arr Array with ampeln.
* @return array
*/
private function _getAmpelContentData($uid, $html_text, $ampel_data_arr)
{
$firstName = $this->PersonModel->getByUid($uid)->retval[0]->vorname;
// check if user already exists in the array
$key_position = array_search($uid, array_column($ampel_data_arr, 'uid'));
// If user already exists in the array, add only new ampel data to users ampel list
if ($key_position !== false)
{
$ampel_data_arr[$key_position]['ampel_list'] .= $html_text;
}
// If user does not exist, create new user and push all data needed
else
{
$ampel_data_arr[] = array(
'uid' => $uid,
'firstName' => $firstName,
'ampel_list' => $html_text,
'link' => self::CIS_AMPELVERWALTUNG_URL
);
}
return $ampel_data_arr;
}
}
@@ -40,7 +40,7 @@ class Prestudentstatus extends Auth_Controller
public function index()
{
$result = "The following are the available command line interface commands\n\n";
$result .= "php index.ci.php jobs/Prestudentstatus CorrectStudienplan";
$result .= "php ".$this->config->item('index_page')." jobs/Prestudentstatus CorrectStudienplan";
echo $result.PHP_EOL;
}
@@ -12,12 +12,18 @@ class InfoCenter extends Auth_Controller
const APP = 'infocenter';
const TAETIGKEIT = 'bewerbung';
const URL_PREFIX = '/system/infocenter/InfoCenter'; // URL prefix for this controller
const INFOCENTER_URI = 'system/infocenter/InfoCenter'; // URL prefix for this controller
const INDEX_PAGE = 'index';
const FREIGEGEBEN_PAGE = 'freigegeben';
const SHOW_DETAILS_PAGE = 'showDetails';
const NAVIGATION_PAGE = 'navigation_page';
const ORIGIN_PAGE = 'origin_page';
private $_uid; // contains the UID of the logged user
// Used to log with PersonLogLib
private $logparams = array(
private $_logparams = array(
'saveformalgep' => array(
'logtype' => 'Action',
'name' => 'Document formally checked',
@@ -119,29 +125,33 @@ class InfoCenter extends Auth_Controller
// Public methods
/**
* Default
* Main page of the InfoCenter tool
*/
public function index()
{
$this->setNavigationMenuIndex(); // define the navigation menu for this page
$this->_setNavigationMenuIndex(); // define the navigation menu for this page
$this->load->view('system/infocenter/infocenter.php');
}
/**
* Freigegeben page of the InfoCenter tool
*/
public function freigegeben()
{
$this->setNavigationMenuFreigegeben(); // define the navigation menu for this page
$this->_setNavigationMenuFreigegeben(); // define the navigation menu for this page
$this->load->view('system/infocenter/infocenterFreigegeben.php');
}
/**
* Personal details page of the InfoCenter tool
* Initialization function, gets person and prestudent data and loads the view with the data
* @param $person_id
*/
public function showDetails()
{
$this->setNavigationMenuShowDetails();
$this->_setNavigationMenuShowDetails();
$person_id = $this->input->get('person_id');
@@ -156,8 +166,8 @@ class InfoCenter extends Auth_Controller
if (empty($personexists->retval))
show_error('person does not exist!');
$origin_page = $this->input->get('origin_page');
if ($origin_page == 'index')
$origin_page = $this->input->get(self::ORIGIN_PAGE);
if ($origin_page == self::INDEX_PAGE)
{
// mark person as locked for editing
$result = $this->PersonLockModel->lockPerson($person_id, $this->_uid, self::APP);
@@ -174,8 +184,8 @@ class InfoCenter extends Auth_Controller
$prestudentdata
);
$data['fhc_controller_id'] = $this->getControllerId();
$data['origin_page'] = $origin_page;
$data[self::FHC_CONTROLLER_ID] = $this->getControllerId();
$data[self::ORIGIN_PAGE] = $origin_page;
$this->load->view('system/infocenter/infocenterDetails.php', $data);
}
@@ -191,7 +201,7 @@ class InfoCenter extends Auth_Controller
if (isError($result))
show_error($result->retval);
redirect(self::URL_PREFIX.'?fhc_controller_id='.$this->getControllerId());
redirect('/'.self::INFOCENTER_URI.'?'.self::FHC_CONTROLLER_ID.'='.$this->getControllerId());
}
/**
@@ -230,9 +240,7 @@ class InfoCenter extends Auth_Controller
}
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($json));
$this->output->set_content_type('application/json')->set_output(json_encode($json));
}
/**
@@ -243,9 +251,7 @@ class InfoCenter extends Auth_Controller
{
$prestudent = $this->PrestudentModel->getLastPrestudent($person_id, true);
$this->output
->set_content_type('application/json')
->set_output(json_encode($prestudent));
$this->output->set_content_type('application/json')->set_output(json_encode($prestudent));
}
/**
@@ -324,9 +330,7 @@ class InfoCenter extends Auth_Controller
$this->_log($logdata['person_id'], 'savezgv', array($logdata['studiengang_kurzbz'], $prestudent_id));
}
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($result));
$this->output->set_content_type('application/json')->set_output(json_encode($result));
}
/**
@@ -479,9 +483,7 @@ class InfoCenter extends Auth_Controller
$this->_log($person_id, 'savenotiz', array($titel));
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($result));
$this->output->set_content_type('application/json')->set_output(json_encode($result));
}
/**
@@ -512,9 +514,7 @@ class InfoCenter extends Auth_Controller
$this->_log($person_id, 'updatenotiz', array($titel));
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($result));
$this->output->set_content_type('application/json')->set_output(json_encode($result));
}
/**
@@ -581,9 +581,7 @@ class InfoCenter extends Auth_Controller
{
$result = $this->personloglib->getParkedDate($person_id);
$this->output
->set_content_type('application/json')
->set_output(json_encode($result));
$this->output->set_content_type('application/json')->set_output(json_encode($result));
}
/**
@@ -596,9 +594,7 @@ class InfoCenter extends Auth_Controller
$result = $this->personloglib->park($person_id, date_format(date_create($date), 'Y-m-d'), self::TAETIGKEIT, self::APP, null, $this->_uid);
$this->output
->set_content_type('application/json')
->set_output(json_encode($result));
$this->output->set_content_type('application/json')->set_output(json_encode($result));
}
/**
@@ -610,9 +606,7 @@ class InfoCenter extends Auth_Controller
$result = $this->personloglib->unPark($person_id);
$this->output
->set_content_type('application/json')
->set_output(json_encode($result));
$this->output->set_content_type('application/json')->set_output(json_encode($result));
}
/**
@@ -631,9 +625,26 @@ class InfoCenter extends Auth_Controller
$json = $result->retval[0]->ende;
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($json));
$this->output->set_content_type('application/json')->set_output(json_encode($json));
}
/**
* Wrapper for setNavigationMenu, returns JSON message
*/
public function setNavigationMenuArrayJson()
{
$navigation_page = $this->input->get(self::NAVIGATION_PAGE);
if (strpos($navigation_page, self::INDEX_PAGE) !== false)
{
$this->_setNavigationMenuIndex();
}
else
{
$this->_setNavigationMenuFreigegeben();
}
$this->outputJsonSuccess('success');
}
// -----------------------------------------------------------------------------------------------------------------
@@ -652,9 +663,9 @@ class InfoCenter extends Auth_Controller
/**
* Define the navigation menu for the index page
*/
public function setNavigationMenuIndex()
private function _setNavigationMenuIndex()
{
$this->load->library('NavigationLib', array('navigation_page' => 'system/infocenter/InfoCenter/index'));
$this->load->library('NavigationLib', array(self::NAVIGATION_PAGE => self::INFOCENTER_URI.'/'.self::INDEX_PAGE));
$listFiltersSent = array();
$listFiltersNotSent = array();
@@ -743,16 +754,16 @@ class InfoCenter extends Auth_Controller
/**
* Define the navigation menu for the showDetails page
*/
public function setNavigationMenuShowDetails()
private function _setNavigationMenuShowDetails()
{
$this->load->library('NavigationLib', array('navigation_page' => 'system/infocenter/InfoCenter/showDetails'));
$this->load->library('NavigationLib', array(self::NAVIGATION_PAGE => self::INFOCENTER_URI.'/'.self::SHOW_DETAILS_PAGE));
$origin_page = $this->input->get('origin_page');
$origin_page = $this->input->get(self::ORIGIN_PAGE);
$link = base_url('index.ci.php/system/infocenter/InfoCenter/index');
if ($origin_page == 'freigegeben')
$link = site_url(self::INFOCENTER_URI.'/'.self::INDEX_PAGE);
if ($origin_page == self::FREIGEGEBEN_PAGE)
{
$link = base_url('index.ci.php/system/infocenter/InfoCenter/freigegeben');
$link = site_url(self::INFOCENTER_URI.'/'.self::FREIGEGEBEN_PAGE);
}
$this->navigationlib->setSessionMenu(
@@ -771,9 +782,9 @@ class InfoCenter extends Auth_Controller
/**
* Define the navigation menu for the freigegeben page
*/
public function setNavigationMenuFreigegeben()
private function _setNavigationMenuFreigegeben()
{
$this->load->library('NavigationLib', array('navigation_page' => 'system/infocenter/InfoCenter/freigegeben'));
$this->load->library('NavigationLib', array(self::NAVIGATION_PAGE => self::INFOCENTER_URI.'/'.self::FREIGEGEBEN_PAGE));
$listFilters = array();
$listCustomFilters = array();
@@ -832,24 +843,8 @@ class InfoCenter extends Auth_Controller
}
/**
* Wrapper for setNavigationMenu, returns JSON message
* Utility method used to fill elements of the InfoCenter left menu of the main InfoCenter page
*/
public function setNavigationMenuArrayJson()
{
$navigation_page = $this->input->get('navigation_page');
if (strpos($navigation_page, 'index') !== false)
{
$this->setNavigationMenuIndex();
}
else
{
$this->setNavigationMenuFreigegeben();
}
$this->outputJsonSuccess('success');
}
private function _fillFilters($filters, &$tofill)
{
$toPrint = "%s?%s=%s&%s=%s";
@@ -859,7 +854,7 @@ class InfoCenter extends Auth_Controller
$tofill['children'][] = array(
'link' => sprintf(
$toPrint,
site_url('system/infocenter/InfoCenter'), 'filter_id', $filterId,
site_url(self::INFOCENTER_URI), 'filter_id', $filterId,
FHC_Controller::FHC_CONTROLLER_ID,
$this->getControllerId()
),
@@ -868,6 +863,9 @@ class InfoCenter extends Auth_Controller
}
}
/**
* Utility method used to fill elements of the InfoCenter left menu of the freigegeben InfoCenter page
*/
private function _fillFiltersFreigegeben($filters, &$tofill)
{
$toPrint = "%s?%s=%s&%s=%s";
@@ -877,7 +875,7 @@ class InfoCenter extends Auth_Controller
$tofill['children'][] = array(
'link' => sprintf(
$toPrint,
site_url('system/infocenter/InfoCenter/freigegeben'), 'filter_id', $filterId,
site_url(self::INFOCENTER_URI.'/'.self::FREIGEGEBEN_PAGE), 'filter_id', $filterId,
FHC_Controller::FHC_CONTROLLER_ID,
$this->getControllerId()
),
@@ -886,6 +884,10 @@ class InfoCenter extends Auth_Controller
}
}
/**
* Utility method used to fill elements of the InfoCenter left menu
* with the list of the custom filter of the authenticated user
*/
private function _fillCustomFilters($filters, &$tofill)
{
$toPrint = "%s?%s=%s&%s=%s";
@@ -895,7 +897,7 @@ class InfoCenter extends Auth_Controller
$tofill['children'][] = array(
'link' => sprintf(
$toPrint,
site_url('system/infocenter/InfoCenter'), 'filter_id', $filterId,
site_url(self::INFOCENTER_URI), 'filter_id', $filterId,
FHC_Controller::FHC_CONTROLLER_ID,
$this->getControllerId()
),
@@ -1089,7 +1091,18 @@ class InfoCenter extends Auth_Controller
$this->PrestudentModel->addSelect('person_id');
$person_id = $this->PrestudentModel->load($prestudent_id)->retval[0]->person_id;
redirect(self::URL_PREFIX.'/showDetails?person_id='.$person_id.'&fhc_controller_id='.$this->getControllerId().'#'.$section);
redirect(
sprintf(
'/%s/%s?%s=%s&%s=%s#%s',
self::INFOCENTER_URI,
self::SHOW_DETAILS_PAGE,
'person_id',
$person_id,
self::FHC_CONTROLLER_ID,
$this->getControllerId(),
$section
)
);
}
/**
@@ -1121,7 +1134,7 @@ class InfoCenter extends Auth_Controller
*/
private function _log($person_id, $logname, $messageparams)
{
$logdata = $this->logparams[$logname];
$logdata = $this->_logparams[$logname];
$datatolog = array(
'name' => $logdata['name']