Commit 5f6e1b24 authored by Open Source Developer's avatar Open Source Developer

tr

parents 6f2a83e2 99fed932
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -91,7 +91,7 @@ class CASLogin extends ControllerBase
$this->allowed2 = $CASOSTConfig->allowed2->value;
$this->allowed2Value = $CASOSTConfig->allowed2value->value;
}
// phpCAS::setDebug("/home/haris/devel/eepal/drupal/modules/casost/phpcas.log");
phpCAS::setDebug("/home/haris/devel/eepal/drupal/modules/casost/phpcas.log");
// Enable verbose error messages. Disable in production!
//phpCAS::setVerbose(true);
......@@ -124,6 +124,10 @@ class CASLogin extends ControllerBase
return $response;
}
$attributes = phpCAS::getAttributes();
foreach ($attributes as $attr_key => $attr_value) {
$this->logger->warning($attr_key);
$this->logger->warning(phpCAS::getAttribute($attr_key));
}
/* $isAllowed = true;
$att1 = $attributes[$this->allowed1];
......@@ -166,21 +170,37 @@ class CASLogin extends ControllerBase
$filterAttribute = function ($attribute) use ($attributes) {
if (!isset($attributes[$attribute])) {
return;
}
if (is_array($attributes[$attribute])) {
return $attributes[$attribute];
return false;
}
return $attributes[$attribute];
};
$exposedRole = 'director';
$internalRole = 'epal';
$CASTitle = preg_replace('/\s+/', '', $filterAttribute('title'));
if ($CASTitle === 'ΠΕΡΙΦΕΡΕΙΑΚΗΔΙΕΥΘΥΝΣΗΕΚΠΑΙΔΕΥΣΗΣ-ΠΔΕ') {
$exposedRole = 'pde';
$internalRole = 'regioneduadmin';
} else if ($CASTitle === 'ΔΙΕΥΘΥΝΣΗΔΕ-ΔIΔΕ') {
$exposedRole = 'dide';
$internalRole = 'eduadmin';
} else if ($CASTitle === 'ΕΠΑΛ') {
$exposedRole = 'director';
$internalRole = 'epal';
} else {
$response = new Response();
$this->logger->warning(t('Access is allowed only to official school accounts or administration'));
$response->setContent(t('Access is allowed only to official school accounts or administration'));
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json;charset=UTF-8');
return $response;
}
// $this->logger->warning('cn=' . $filterAttribute('cn'));
$epalToken = $this->authenticatePhase2($request, $CASUser, $filterAttribute('cn'));
$epalToken = $this->authenticatePhase2($request, $CASUser, $internalRole, $filterAttribute('cn'));
if ($epalToken) {
$cookie = new Cookie('auth_token', $epalToken, 0, '/', null, false, false);
$cookie2 = new Cookie('auth_role', 'director', 0, '/', null, false, false);
$cookie2 = new Cookie('auth_role', $exposedRole, 0, '/', null, false, false);
return new RedirectResponseWithCookie($this->redirectUrl, 302, array ($cookie, $cookie2));
// $headers = array("auth_token" => $epalToken, "auth_role" => "director");
......@@ -203,7 +223,7 @@ class CASLogin extends ControllerBase
}
}
public function authenticatePhase2($request, $CASUser, $cn)
public function authenticatePhase2($request, $CASUser, $internalRole, $cn)
{
$trx = $this->connection->startTransaction();
try {
......@@ -241,7 +261,7 @@ class CASLogin extends ControllerBase
$user->set('preferred_admin_langcode', $language_interface->getId());
//Adding default user role
$user->addRole('epal');
$user->addRole($internalRole);
$user->save();
}
......
......@@ -95,7 +95,7 @@ class CASLogout extends ControllerBase
// Enable debugging
// phpCAS::setDebug("/home/haris/devel/eepal/drupal/modules/casost/phpcas.log");
// Enable verbose error messages. Disable in production!
// phpCAS::setVerbose(true);
// phpCAS::setVerbose(true);
// Initialize phpCAS
phpCAS::client($this->serverVersion,
......@@ -110,6 +110,7 @@ class CASLogout extends ControllerBase
if (!$user) {
$this->logger->warning("user not found");
$response = new Response();
$response->setContent('forbidden');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -78,10 +78,12 @@ epal.demo_data:
_access: 'TRUE'
epal.allocation:
path: '/epal/distribution'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\Distribution::createDistribution'
requirements:
_access: 'TRUE'
_user_is_logged_in: 'TRUE'
sectorperschool:
path: '/epal/sectorperSchool/{epalId}'
options:
......@@ -107,7 +109,7 @@ confirmstudents:
requirements:
_user_is_logged_in: 'TRUE'
studentperschool:
path: '/epal/studentperSchool/{epalId}/{selectId}/{classId}'
path: '/epal/studentperSchool/{epalId}/{selectId}/{classId}/{limitdown}/{limitup}'
options:
_auth: [ 'basic_auth' ]
defaults:
......@@ -130,3 +132,19 @@ epal.ministry.log_in_go:
_controller: '\Drupal\epal\Controller\MinistryLogin::loginGo'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.log_out_go:
path: '/ministry/logout'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\MinistryLogin::logoutGo'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.general_report:
path: '/ministry/general-report'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\Distribution::makegGeneralReport'
requirements:
_user_is_logged_in: 'TRUE'
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -155,7 +155,7 @@ public function getSpecialPerSchool(Request $request, $epalId , $sectorId)
}
public function getStudentPerSchool(Request $request, $epalId , $selectId, $classId)
public function getStudentPerSchool(Request $request, $epalId , $selectId, $classId, $limitdown, $limitup)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
......@@ -192,32 +192,46 @@ public function getStudentPerSchool(Request $request, $epalId , $selectId, $clas
if ($studentPerSchool) {
$list = array();
foreach ($studentPerSchool as $object)
{
$studentId = $object -> id() ;
$epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $studentId));
$epalStudent = reset($epalStudents);
$i = 0;
if ($epalStudents) {
$list[] = array(
'id' => $epalStudent -> id(),
'name' => $epalStudent -> name ->value,
'studentsurname' => $epalStudent -> studentsurname ->value,
'fatherfirstname' => $epalStudent -> fatherfirstname ->value,
'fathersurname' =>$epalStudent -> fathersurname ->value,
'motherfirstname' => $epalStudent -> motherfirstname ->value,
'mothersurname' =>$epalStudent -> mothersurname ->value,
'birthdate' =>$epalStudent -> birthdate ->value,
);
$i++;
$i = 0;
if ($limitdown==$limitup && $limitup == 0)
{
$list=array(
'id' => sizeof($studentPerSchool)
);
}
else
{
foreach ($studentPerSchool as $object)
{
$studentId = $object -> id() ;
$epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $studentId));
$epalStudent = reset($epalStudents);
if ($epalStudents) {
if ($i >= $limitdown && $i < $limitup)
{
$list[] = array(
'i' => $i,
'id' => $epalStudent -> id(),
'name' => $epalStudent -> name ->value,
'studentsurname' => $epalStudent -> studentsurname ->value,
'fatherfirstname' => $epalStudent -> fatherfirstname ->value,
'fathersurname' =>$epalStudent -> fathersurname ->value,
'motherfirstname' => $epalStudent -> motherfirstname ->value,
'mothersurname' =>$epalStudent -> mothersurname ->value,
'birthdate' =>$epalStudent -> birthdate ->value,
);
}
$i++;
}
}
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
else {
$list = array();
return $this->respondWithStatus($list, Response::HTTP_OK);
......
......@@ -73,15 +73,37 @@ class Distribution extends ControllerBase {
$numDistributions = 3;
$sizeOfBlock = 100000;
/*
//POST method is checked
if (!$request->isMethod('POST')) {
return $this->respondWithStatus([
"message" => t("Method Not Allowed")
], Response::HTTP_METHOD_NOT_ALLOWED);
}
*/
}
//user validation
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if (!$user) {
return $this->respondWithStatus([
'message' => t("User not found"),
], Response::HTTP_FORBIDDEN);
}
//user role validation
$roles = $user->getRoles();
$validRole = false;
foreach ($roles as $role)
if ($role === "ministry") {
$validRole = true;
break;
}
if (!$validRole) {
return $this->respondWithStatus([
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
//clearDistributionResults();
$transaction = $this->connection->startTransaction();
......@@ -91,18 +113,18 @@ class Distribution extends ControllerBase {
$this->connection->delete('epal_student_class')->execute();
$limitUp_class = $this->retrieveCapacityLimitUp("Α");
print_r("<br> ΑΝΩΤΑΤΟ ΟΡΙΟ ΜΑΘΗΤΩΝ: " . $limitUp_class);
//print_r("<br> ΑΝΩΤΑΤΟ ΟΡΙΟ ΜΑΘΗΤΩΝ: " . $limitUp_class);
while ($this->choice_id <= $numDistributions) {
print_r("<br>ΠΕΡΑΣΜΑ: " . $this->choice_id);
//print_r("<br>ΠΕΡΑΣΜΑ: " . $this->choice_id);
//υπολογισμός πλήθους non-finalized αιτήσεων για να καθοριστεί ο αριθμός των fetches που θα κάνουμε με συγκεκριμένο sizeOfBlock
if ($this->choice_id === 1) {
$sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id'));
$numData = $sCon->countQuery()->execute()->fetchField();
print_r("<br>numData: " . $numData);
//print_r("<br>numData: " . $numData);
}
$j = 1;
......@@ -110,7 +132,7 @@ class Distribution extends ControllerBase {
if ($this->choice_id === 1) {
while ($num <= $numData) {
print_r("<br>FETCH: " . $j);
//print_r("<br>FETCH: " . $j);
$sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id', 'name', 'currentclass', 'currentepal', 'points'))
->condition('eStudent.id', 1+ $sizeOfBlock*($j-1), '>=')
......@@ -131,9 +153,6 @@ class Distribution extends ControllerBase {
->condition('eStudent.id', $this->pendingStudents, 'IN');
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
//foreach ($epalStudents as $x)
// print_r("<br> TEST:" . $x->id . " ");
$this->locateStudent($this->choice_id, $epalStudents);
}
else { //αν δεν υπάρχουν εκκρεμότητες, μην συνεχίζεις με άλλο πέρασμα
......@@ -177,6 +196,7 @@ class Distribution extends ControllerBase {
} //end while
} //end try
catch (\Exception $e) {
......@@ -187,9 +207,26 @@ class Distribution extends ControllerBase {
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
//return new RedirectResponse($this->redirectUrl . '?auth_token=' . $epalToken.'&auth_role=director', 302, []);
//return new RedirectResponse("../eepal/dist/#/minister/minister-view");
/*
return $this->respondWithStatus([
"message" => t("Distribution has made successfully")
], Response::HTTP_OK);
*/
$postData = null;
if ($content = $request->getContent()) {
$postData = json_decode($content);
return $this->respondWithStatus([
'message' => "Distribution has made successfu",
], Response::HTTP_OK);
}
else {
return $this->respondWithStatus([
'message' => t("post with no data"),
], Response::HTTP_BAD_REQUEST);
}
}
......@@ -204,8 +241,8 @@ class Distribution extends ControllerBase {
try {
foreach ($epalStudents as $epalStudent) {
print_r("<br>ΚΑΤΑΝΟΜΗ ΜΑΘΗΤΩΝ ΝΟ: " . $choice_id);
print_r("<br>ΜΑΘΗΤΗΣ: " . $epalStudent->id);
//print_r("<br>ΚΑΤΑΝΟΜΗ ΜΑΘΗΤΩΝ ΝΟ: " . $choice_id);
//print_r("<br>ΜΑΘΗΤΗΣ: " . $epalStudent->id);
$clCon = $this->connection->select('epal_student_epal_chosen', 'epals')
->fields('epals', array('student_id', 'epal_id', 'choice_no'))
......@@ -215,7 +252,7 @@ class Distribution extends ControllerBase {
if (sizeof($epalSchoolsChosen) !== 0) {
$epalSchoolChos = reset($epalSchoolsChosen);
print_r(" SCHOOL_ID:" . $epalSchoolChos->epal_id . " STUDENT_ID " . $epalStudent->id);
//print_r(" SCHOOL_ID:" . $epalSchoolChos->epal_id . " STUDENT_ID " . $epalStudent->id);
$epal_dist_id = $epalSchoolChos->epal_id;
if ($epalStudent->currentclass === "2") {
......@@ -316,7 +353,7 @@ class Distribution extends ControllerBase {
->condition('studentClass.specialization_id', $secCourId, '=');
$epalStudentClass = $clCon->execute()->fetchAll(\PDO::FETCH_OBJ);
print_r("<br> ΣΧΟΛΕΙΟ: " . $epalId . " ΤΑΞΗ: " . $classId . " ΤΟΜΕΑΣ/ΕΙΔΙΚΟΤΗΤΑ: " . $secCourId . " ΧΩΡΗΤΙΚΟΤΗΤΑ: " . sizeof($epalStudentClass));
//print_r("<br> ΣΧΟΛΕΙΟ: " . $epalId . " ΤΑΞΗ: " . $classId . " ΤΟΜΕΑΣ/ΕΙΔΙΚΟΤΗΤΑ: " . $secCourId . " ΧΩΡΗΤΙΚΟΤΗΤΑ: " . sizeof($epalStudentClass));
//ΕΠΙΠΛΕΟΝ ΕΠΙΠΕΔΟ ΑΣΦΑΛΕΙΑΣ: αν δεν υπάρχει ο συγκεκριμένος τομέας/ειδικότητα στο σχολείο
//ο μαθητής που τοποθετήθηκε με την locateStudent να διαγραφεί
......@@ -337,7 +374,7 @@ class Distribution extends ControllerBase {
$limit = $limitup * $capacity;
if (sizeof($epalStudentClass) > $limit) {
print_r("<br>ΥΠΕΡΧΕΙΛΙΣΗ!");
//print_r("<br>ΥΠΕΡΧΕΙΛΙΣΗ!");
foreach ($epalStudentClass as $epalStudCl) {
//Υπολογισμός μορίων του μαθητή και (πιθανή) αποθήκευσή τους
//ΣΗΜΕΙΩΣΗ: Ο υπoλογισμός γίνεται στο front-end
......@@ -395,7 +432,7 @@ class Distribution extends ControllerBase {
foreach($students as $student) {