diff --git a/drupal/modules/epal/src/Client.php b/drupal/modules/epal/src/Client.php index de1a4b1c41a9113e3e792d673e09833dbd90ac84..0b2cbf704605ea91c180803985f5d5eceeac1bb1 100644 --- a/drupal/modules/epal/src/Client.php +++ b/drupal/modules/epal/src/Client.php @@ -30,23 +30,11 @@ class Client $this->_settings = array_merge($this->_settings, $settings); $this->_settings['ws_endpoint_token'] = "{$this->_settings['ws_endpoint']}/oauth2/token"; $this->_settings['ws_endpoint_token_granttype'] = 'password'; - $this->_settings['ws_endpoint_studentepalinfo'] = "{$this->_settings['ws_endpoint']}/api/epal/GetStudentEpalInfo"; $this->_settings['ws_endpoint_studentepalcertification'] = "{$this->_settings['ws_endpoint']}/api/epal/GetStudentEpalCertification"; $this->_settings['ws_endpoint_studentepalpromotion'] = "{$this->_settings['ws_endpoint']}/api/epal/GetStudentEpalPromotion"; $this->_settings['ws_endpoint_alldidactiyear'] = "{$this->_settings['ws_endpoint']}/api/general/GetAllDidactiYear"; } - /** - * Επιστρέφει πίνακα με κλειδιά τα property names των πεδίων που επιστρέφει η GetStudentEpalInfo - * και τιμές λεκτικά - ετικέτες τους. - * - * @return array - */ - public function getStudentInfoFields() - { - return $this->studentInfoFields; - } - /** * Λαμβάνει το authentication token * diff --git a/drupal/modules/epal/src/ClientConsumer.php b/drupal/modules/epal/src/ClientConsumer.php new file mode 100755 index 0000000000000000000000000000000000000000..c85655e94976eb0710501b34b226566f2e4ad42c --- /dev/null +++ b/drupal/modules/epal/src/ClientConsumer.php @@ -0,0 +1,153 @@ + "2008 - 2009", + "2" => "2011 - 2012", + "3" => "1999 - 2000", + "4" => "2000 - 2001", + "5" => "2009 - 2010", + "6" => "2010 - 2011", + "7" => "2001 - 2002", + "8" => "2002 - 2003", + "9" => "2003 - 2004", + "10" => "2004 - 2005", + "11" => "2005 - 2006", + "12" => "2006 - 2007", + "13" => "2007 - 2008", + "17" => "2012 - 2013", + "18" => "2013 - 2014", + "22" => "2014 - 2015", + "23" => "2015 - 2016", + "24" => "2016 - 2017" + ]; + protected $cached_level_names = [ + "1" => "Α", + "2" => "Β", + "3" => "Γ", + "4" => "Δ" + ]; + + public function __construct($settings, EntityTypeManagerInterface $entityTypeManager, LoggerChannelFactoryInterface $loggerChannel) + { + $this->settings = $settings; + $this->entityTypeManager = $entityTypeManager; + $this->logger = $loggerChannel->get('epal-school'); + $this->client = new Client($this->settings, $this->logger); + } + + public function getAllDidactiYear() + { + $ts_start = microtime(true); + + // try { + // $catalog = $this->client->getAllDidactiYear(); + // } catch (\Exception $e) { + // $catalog = []; + // } + $catalog = $this->cached_didactic_years; + + $duration = microtime(true) - $ts_start; + $this->logger->info(__METHOD__ . " :: timed [{$duration}]"); + + return $catalog; + } + + public function getStudentEpalPromotion($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name) + { + $ts_start = microtime(true); + + try { + $result = $this->client->getStudentEpalPromotion($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name); + } catch (\Exception $e) { + $result = -1; + } + + $duration = microtime(true) - $ts_start; + $this->logger->info(__METHOD__ . " :: timed [{$duration}]"); + + return $result; + } + + public function getStudentEpalCertification($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name) + { + $ts_start = microtime(true); + + try { + $result = $this->client->getStudentEpalCertification($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name); + } catch (\Exception $e) { + $result = -1; + } + + $duration = microtime(true) - $ts_start; + $this->logger->info(__METHOD__ . " :: timed [{$duration}]"); + + return $result; + } + + /** + * If $ending is provided + * it is assumed as the second part of the academic-year (i.e. 2017 for 2016-2017), + * the function returns the corresponding id to match first; + * If $id is provided, return the corresponding label. + * $id has priority over $ending, if both are supplied. + * + * @return null|string null if no input or no info located + */ + public function getDidacticYear($ending = null, $id = null) + { + $value = null; + if ($id !== null) { + if (array_key_exists($id, $this->cached_didactic_years)) { + $value = $this->cached_didactic_years[$id]; + } + } elseif ($ending !== null) { + $remain = array_filter($this->cached_didactic_years, function ($v) use ($ending) { + $pos = strpos($v, "$ending"); + return ($pos !== false && $pos > 4); + }); + if (count($remain) > 0) { + $values = array_keys($remain); + $value = $values[0]; + } + } + return $value; + } + + /** + * Get the level name of the denoted class level + * + * @return string|mixed The level name of the provided failsafe value if not found + */ + public function getLevelName($id, $failsafe_value = 'X') + { + $value = $failsafe_value; + if (array_key_exists($id, $this->cached_level_names)) { + $value = $this->cached_level_names["$id"]; + } + return $value; + } + + private function generateRandomString($length) + { + $characters = ['Α','Β','Γ','Δ','Ε','Ζ','Η','Θ','Ι','Κ','Λ','Μ','Ν','Ξ','Ο','Π','Ρ','Σ','Τ','Υ','Φ','Χ','Ψ','Ω']; + $charactersLength = count($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } +} diff --git a/drupal/modules/epal/src/Controller/ApplicationSubmit.php b/drupal/modules/epal/src/Controller/ApplicationSubmit.php index 0b1ddd6f6aff2ea44030e6f0ed4c625b7454a025..b3a237a8af1f7f5ca68e6dc0a371a101fc00cc04 100755 --- a/drupal/modules/epal/src/Controller/ApplicationSubmit.php +++ b/drupal/modules/epal/src/Controller/ApplicationSubmit.php @@ -13,63 +13,83 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Drupal\Core\Logger\LoggerChannelFactoryInterface; -class ApplicationSubmit extends ControllerBase { +use Drupal\epal\ClientConsumer; + +class ApplicationSubmit extends ControllerBase +{ + + const UNIT_TYPE_NIP = 1; + const UNIT_TYPE_DIM = 2; + const UNIT_TYPE_GYM = 3; + const UNIT_TYPE_LYK = 4; + const UNIT_TYPE_EPAL = 5; + + const CERT_GYM = 'Απολυτήριο Γυμνασίου'; + const CERT_LYK = 'Απολυτήριο Λυκείου'; protected $entityTypeManager; protected $logger; protected $connection; + protected $client; // client consumer - public function __construct( - EntityTypeManagerInterface $entityTypeManager, - Connection $connection, - LoggerChannelFactoryInterface $loggerChannel) - { - $this->entityTypeManager = $entityTypeManager; - $this->connection = $connection; - $this->logger = $loggerChannel->get('epal'); + public function __construct( + EntityTypeManagerInterface $entityTypeManager, + Connection $connection, + LoggerChannelFactoryInterface $loggerChannel + ) { + $this->entityTypeManager = $entityTypeManager; + $this->connection = $connection; + $this->logger = $loggerChannel->get('epal'); + + $config = $this->config('epal.settings'); + $settings = []; + foreach (['ws_endpoint', 'ws_username', 'ws_password', 'verbose', 'NO_SAFE_CURL'] as $setting) { + $settings[$setting] = $config->get($setting); + } + $this->client = new ClientConsumer($settings, $entityTypeManager, $loggerChannel); } - public static function create(ContainerInterface $container) + public static function create(ContainerInterface $container) { return new static( - $container->get('entity_type.manager'), - $container->get('database'), - $container->get('logger.factory') - ); + $container->get('entity_type.manager'), + $container->get('database'), + $container->get('logger.factory') + ); } - public function appSubmit(Request $request) { - if (!$request->isMethod('POST')) { - return $this->respondWithStatus([ - "error_code" => 2001 - ], Response::HTTP_METHOD_NOT_ALLOWED); - } - $applicationForm = array(); - - $content = $request->getContent(); - - if (!empty($content)) { - $applicationForm = json_decode($content, TRUE); - } - else { - return $this->respondWithStatus([ - "error_code" => 5002 - ], Response::HTTP_BAD_REQUEST); - } - $transaction = $this->connection->startTransaction(); - try { - //insert records in entity: epal_student - $authToken = $request->headers->get('PHP_AUTH_USER'); - $epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken)); - $epalUser = reset($epalUsers); - if (!$epalUser){ - return $this->respondWithStatus([ - "error_code" => 4003 - ], Response::HTTP_FORBIDDEN); - } - - - $student = array( + public function appSubmit(Request $request) + { + if (!$request->isMethod('POST')) { + return $this->respondWithStatus([ + "error_code" => 2001 + ], Response::HTTP_METHOD_NOT_ALLOWED); + } + $applicationForm = array(); + + $content = $request->getContent(); + + if (!empty($content)) { + $applicationForm = json_decode($content, true); + } else { + return $this->respondWithStatus([ + "error_code" => 5002 + ], Response::HTTP_BAD_REQUEST); + } + + $transaction = $this->connection->startTransaction(); + try { + //insert records in entity: epal_student + $authToken = $request->headers->get('PHP_AUTH_USER'); + $epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken)); + $epalUser = reset($epalUsers); + if (!$epalUser) { + return $this->respondWithStatus([ + "error_code" => 4003 + ], Response::HTTP_FORBIDDEN); + } + + $student = array( 'langcode' => 'el', 'student_record_id' => 0, 'sex' => 0, @@ -84,40 +104,42 @@ class ApplicationSubmit extends ControllerBase { 'points' => 0, 'user_id' => $epalUser->user_id->target_id, 'epaluser_id' => $epalUser->id(), - 'name' => $applicationForm[0]['name'], - 'studentsurname' => $applicationForm[0]['studentsurname'], - 'birthdate' => $applicationForm[0]['studentbirthdate'], - 'fatherfirstname' => $applicationForm[0]['fatherfirstname'], - 'motherfirstname' => $applicationForm[0]['motherfirstname'], - 'regionaddress' => $applicationForm[0]['regionaddress'], - 'regionarea' => $applicationForm[0]['regionarea'], - 'regiontk' => $applicationForm[0]['regiontk'], + 'name' => $applicationForm[0]['name'], + 'studentsurname' => $applicationForm[0]['studentsurname'], + 'birthdate' => $applicationForm[0]['studentbirthdate'], + 'fatherfirstname' => $applicationForm[0]['fatherfirstname'], + 'motherfirstname' => $applicationForm[0]['motherfirstname'], + 'regionaddress' => $applicationForm[0]['regionaddress'], + 'regionarea' => $applicationForm[0]['regionarea'], + 'regiontk' => $applicationForm[0]['regiontk'], 'certificatetype' => $applicationForm[0]['certificatetype'], - 'graduation_year' => $applicationForm[0]['graduation_year'], + 'graduation_year' => $applicationForm[0]['graduation_year'], 'lastschool_registrynumber' => $applicationForm[0]['lastschool_registrynumber'], 'lastschool_unittypeid' => $applicationForm[0]['lastschool_unittypeid'], 'lastschool_schoolname' => $applicationForm[0]['lastschool_schoolname'], 'lastschool_schoolyear' => $applicationForm[0]['lastschool_schoolyear'], 'lastschool_class' => $applicationForm[0]['lastschool_class'], - 'currentclass' => $applicationForm[0]['currentclass'], + 'currentclass' => $applicationForm[0]['currentclass'], 'guardian_name' => $applicationForm[0]['cu_name'], 'guardian_surname' => $applicationForm[0]['cu_surname'], 'guardian_fathername' => $applicationForm[0]['cu_fathername'], 'guardian_mothername' => $applicationForm[0]['cu_mothername'], 'agreement' => $applicationForm[0]['disclaimer_checked'], - 'relationtostudent' => $applicationForm[0]['relationtostudent'], - 'telnum' => $applicationForm[0]['telnum'] + 'relationtostudent' => $applicationForm[0]['relationtostudent'], + 'telnum' => $applicationForm[0]['telnum'] ); if (($errorCode = $this->validateStudent($student)) > 0) { return $this->respondWithStatus([ - "error_code" => $errorCode ], Response::HTTP_OK); + "error_code" => $errorCode + ], Response::HTTP_OK); } + $lastSchoolRegistryNumber = $student['lastschool_registrynumber']; $lastSchoolYear = (int)(substr($student['lastschool_schoolyear'], -4)); if ((int)date("Y") === $lastSchoolYear && (int)$student['lastschool_unittypeid'] === 5) { $epalSchools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('registry_no' => $lastSchoolRegistryNumber)); - $epalSchool = reset($epalSchools); + $epalSchool = reset($epalSchools); /* if (!$epalSchool){ return $this->respondWithStatus([ "error_code" => 4004 @@ -128,79 +150,166 @@ class ApplicationSubmit extends ControllerBase { } else { $student['currentepal'] = 0; } - } else { $student['currentepal'] = 0; } - $entity_storage_student = $this->entityTypeManager->getStorage('epal_student'); - $entity_object = $entity_storage_student->create($student); - $entity_storage_student->save($entity_object); - - $created_student_id = $entity_object->id(); - - for ($i = 0; $i < sizeof($applicationForm[1]); $i++) { - $epalchosen = array( - 'student_id' => $created_student_id, - 'epal_id' => $applicationForm[1][$i]['epal_id'], - 'choice_no' => $applicationForm[1][$i]['choice_no'] - ); - $entity_storage_epalchosen = $this->entityTypeManager->getStorage('epal_student_epal_chosen'); - $entity_object = $entity_storage_epalchosen->create($epalchosen); - $entity_storage_epalchosen->save($entity_object); - } - - - if ($applicationForm[0]['currentclass'] === "3" || $applicationForm[0]['currentclass'] === "4" ) { - $course = array( - 'student_id' => $created_student_id, - 'coursefield_id' => $applicationForm[3]['coursefield_id'] - ); - - $entity_storage_course = $this->entityTypeManager->getStorage('epal_student_course_field'); - $entity_object = $entity_storage_course->create($course); - $entity_storage_course->save($entity_object); - } - - else if ($applicationForm[0]['currentclass'] === "2") { - $sector = array( - 'student_id' => $created_student_id, - 'sectorfield_id' => $applicationForm[3]['sectorfield_id'] - ); - - $entity_storage_sector = $this->entityTypeManager->getStorage('epal_student_sector_field'); - $entity_object = $entity_storage_sector->create($sector); - $entity_storage_sector->save($entity_object); - } - return $this->respondWithStatus([ - "error_code" => 0 - ], Response::HTTP_OK); - } - - catch (\Exception $e) { - print_r($e->getMessage()); - $this->logger->warning($e->getMessage()); - - $transaction->rollback(); - return $this->respondWithStatus([ - "error_code" => 5001 - ], Response::HTTP_INTERNAL_SERVER_ERROR); - } - } - - private function respondWithStatus($arr, $s) { - $res = new JsonResponse($arr); - $res->setStatusCode($s); - return $res; - } - - private function validateStudent($student) { - if(!$student["agreement"]) { - return 1001; - } - if(!$student["lastschool_schoolyear"] || strlen($student["lastschool_schoolyear"]) !== 9) { - return 1002; - } - return 0; - } + $entity_storage_student = $this->entityTypeManager->getStorage('epal_student'); + $entity_object = $entity_storage_student->create($student); + $entity_storage_student->save($entity_object); + + $created_student_id = $entity_object->id(); + + for ($i = 0; $i < sizeof($applicationForm[1]); $i++) { + $epalchosen = array( + 'student_id' => $created_student_id, + 'epal_id' => $applicationForm[1][$i]['epal_id'], + 'choice_no' => $applicationForm[1][$i]['choice_no'] + ); + $entity_storage_epalchosen = $this->entityTypeManager->getStorage('epal_student_epal_chosen'); + $entity_object = $entity_storage_epalchosen->create($epalchosen); + $entity_storage_epalchosen->save($entity_object); + } + + + if ($applicationForm[0]['currentclass'] === "3" || $applicationForm[0]['currentclass'] === "4") { + $course = array( + 'student_id' => $created_student_id, + 'coursefield_id' => $applicationForm[3]['coursefield_id'] + ); + $entity_storage_course = $this->entityTypeManager->getStorage('epal_student_course_field'); + $entity_object = $entity_storage_course->create($course); + $entity_storage_course->save($entity_object); + } elseif ($applicationForm[0]['currentclass'] === "2") { + $sector = array( + 'student_id' => $created_student_id, + 'sectorfield_id' => $applicationForm[3]['sectorfield_id'] + ); + $entity_storage_sector = $this->entityTypeManager->getStorage('epal_student_sector_field'); + $entity_object = $entity_storage_sector->create($sector); + $entity_storage_sector->save($entity_object); + } + return $this->respondWithStatus([ + "error_code" => 0 + ], Response::HTTP_OK); + } catch (\Exception $e) { + $this->logger->warning($e->getMessage()); + $transaction->rollback(); + + return $this->respondWithStatus([ + "error_code" => 5001 + ], Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + private function respondWithStatus($arr, $s) + { + $res = new JsonResponse($arr); + $res->setStatusCode($s); + return $res; + } + + /** + * + * @return int error code ελέγχου; 0 εάν ο έλεγχος επιτύχει, μη μηδενικό εάν αποτύχει: + * 1001 δεν επιλέχθηκε το πλαίσιο συμφωνης γνώμης + * 1002 λανθασμένο τελευταίο έτος φοίτησης + * 1003 λανθασμένη ημερομηνία + * 8000 μη αναμενόμενο λάθος + * 8001 δικτυακό λάθος κλήσης υπηρεσίας επιβεβαίωσης στοιχείων + * 8002 τα στοιχεία φοίτησης δεν επικυρώθηκαν + * 8003 τα στοιχεία φοίτησης δεν είναι έγκυρα + */ + private function validateStudent($student) + { + if (!$student["agreement"]) { + return 1001; + } + if (!$student["lastschool_schoolyear"] || strlen($student["lastschool_schoolyear"]) !== 9) { + return 1002; + } + + // date in YYY-MM-DD, out d-m-Y + $date_parts = explode('-', $student['birthdate'], 3); + if ((count($date_parts) !== 3) || + (checkdate($date_parts[1], $date_parts[2], $date_parts[0]) !== true)) { + return 1003; + } + $birthdate = "{$date_parts[2]}-{$date_parts[1]}-{$date_parts[0]}"; + + // check as per specs: + // - can't check certification prior to 2014, pass through + // - check certification if last passed class is gym + // - check promotion if last passed class is not gym + + $check_certification = true; + $check_promotion = true; + if (intval($student['lastschool_unittypeid']) == self::UNIT_TYPE_GYM) { + $check_promotion = false; + $check_certification = true; + } + if (intval($student['graduation_year']) < 2014 && + intval($student['certificatetype']) == self::CERT_GYM) { + $check_certification = false; + } + + // now check service + $pass = true; + $error_code = 0; + if (($check_certification === true) || + ($check_promotion === true)) { + if ($check_promotion === true) { + $service = 'getStudentEpalPromotion'; + } else { + $service = 'getStudentEpalCertification'; + } + try { + $didactic_year_id = $this->client->getDidacticYear(substr($student["lastschool_schoolyear"], -4, 4)); + $level_name = $this->client->getLevelName($student['lastschool_class']); + $service_rv = $this->client->$service( + $didactic_year_id, + $student['studentsurname'], + $student['name'], + $student['fatherfirstname'], + $student['motherfirstname'], + $birthdate, + $student['lastschool_registrynumber'], + $level_name + ); + $pass = ($service_rv === true); + if ($service_rv === true) { + $error_code = 0; + } elseif ($service_rv === false) { + $error_code = 8002; + } elseif ($service_rv === null) { + $error_code = 8003; + } else { + // -1 is an exception and data is already validated + $error_code = 8001; + } + } catch (\Exception $e) { + $pass = false; + $error_code = 8000; + } + } + + // TODO REMOVE + $this->logger->info( + 'check certification: [' . var_export($check_certification, true) . '] ' . + 'check promotion: [' . var_export($check_promotion, true) . '] ' . + 'pass: [' . var_export($pass, true) . '] ' . + 'check: ' . print_r([ + $didactic_year_id, + $student['studentsurname'], + $student['name'], + $student['fatherfirstname'], + $student['motherfirstname'], + $birthdate, + $student['lastschool_registrynumber'], + $level_name + ], true)); + // return 1000; // TODO stop here until all checks are finished + + return $error_code; + } } diff --git a/source/components/student-application-form/application.submit.ts b/source/components/student-application-form/application.submit.ts index dc9ecf806a57f9912a341149d710ad0b443b5ac3..accd647505f92462adbab2aa3efef6bc7ab30a01 100644 --- a/source/components/student-application-form/application.submit.ts +++ b/source/components/student-application-form/application.submit.ts @@ -16,7 +16,7 @@ import { EPALCLASSES_INITIAL_STATE } from '../../store/epalclasses/epalclasses.i import { SECTOR_COURSES_INITIAL_STATE } from '../../store/sectorcourses/sectorcourses.initial-state'; import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfields.initial-state'; import { StudentEpalChosen, StudentCourseChosen, StudentSectorChosen } from '../students/student'; -import {AppSettings} from '../../app.settings'; +import { AppSettings } from '../../app.settings'; import { ILoginInfo, ILoginInfoToken } from '../../store/logininfo/logininfo.types'; import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial-state'; import { EpalClassesActions } from '../../actions/epalclass.actions'; @@ -48,30 +48,30 @@ import { HelperDataService } from '../../services/helper-data-service'; -
- -
+
+ +
+ + - - -
-
-
Στοιχεία αιτούμενου
-
-
-
Όνομα
-
{{ loginInfoRow$.cu_name }}
-
Επώνυμο
-
{{ loginInfoRow$.cu_surname }}
-
-
-
Όνομα πατέρα
-
{{ loginInfoRow$.cu_fathername }}
-
Όνομα μητέρας
-
{{ loginInfoRow$.cu_mothername }}
-
+
+
+
Στοιχεία αιτούμενου
+
+
+
Όνομα
+
{{ loginInfoRow$.cu_name }}
+
Επώνυμο
+
{{ loginInfoRow$.cu_surname }}
+
+
+
Όνομα πατέρα
+
{{ loginInfoRow$.cu_fathername }}
+
Όνομα μητέρας
+
{{ loginInfoRow$.cu_mothername }}
-
+
+
Διεύθυνση
{{studentDataField$.regionaddress}}
@@ -88,35 +88,31 @@ import { HelperDataService } from '../../services/helper-data-service';

{{studentDataField$.motherfirstname}}

{{studentDataField$.studentbirthdate}}

-

{{studentDataField$.certificatetype}}

-

{{studentDataField$.graduation_year}}

-

{{studentDataField$.lastschool_schoolname.name}}

-

{{studentDataField$.lastschool_schoolyear}}

- -

Α'

-

Β'

-

Γ'

-

Δ'

- -

{{studentDataField$.relationtostudent}}

-

{{studentDataField$.telnum}}

+

{{studentDataField$.certificatetype}}

+

{{studentDataField$.graduation_year}}

+

{{studentDataField$.lastschool_schoolname.name}}

+

{{studentDataField$.lastschool_schoolyear}}

+

Α'

+

Β'

+

Γ'

+

Δ'

+

{{studentDataField$.relationtostudent}}

+

{{studentDataField$.telnum}}

+
+
+
+
-
-
- -
-
- -
- -
- +
+ +
+
` }) @@ -128,7 +124,7 @@ import { HelperDataService } from '../../services/helper-data-service'; private courseSelected; private sectorSelected; private classSelected; - private totalPoints= 0; + private totalPoints = 0; private studentDataFields$: BehaviorSubject; private regions$: BehaviorSubject; private sectors$: BehaviorSubject; @@ -154,30 +150,30 @@ import { HelperDataService } from '../../services/helper-data-service'; private disclaimer_checked: number; constructor( - private _hds: HelperDataService, - private _csa: SectorCoursesActions, - private _sfa: SectorFieldsActions, - private _rsa: RegionSchoolsActions, - private _eca: EpalClassesActions, - private _sdfa: StudentDataFieldsActions, - private _ngRedux: NgRedux, - private router: Router, - private http: Http - ) { - - this.regions$ = new BehaviorSubject(REGION_SCHOOLS_INITIAL_STATE); - this.epalclasses$ = new BehaviorSubject(EPALCLASSES_INITIAL_STATE); - this.sectors$ = new BehaviorSubject(SECTOR_COURSES_INITIAL_STATE); - this.sectorFields$ = new BehaviorSubject(SECTOR_FIELDS_INITIAL_STATE); - this.studentDataFields$ = new BehaviorSubject(STUDENT_DATA_FIELDS_INITIAL_STATE); - this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE); - - this.modalTitle = new BehaviorSubject(""); - this.modalText = new BehaviorSubject(""); - this.modalHeader = new BehaviorSubject(""); - this.isModalShown = new BehaviorSubject(false); - this.showLoader = new BehaviorSubject(false); - }; + private _hds: HelperDataService, + private _csa: SectorCoursesActions, + private _sfa: SectorFieldsActions, + private _rsa: RegionSchoolsActions, + private _eca: EpalClassesActions, + private _sdfa: StudentDataFieldsActions, + private _ngRedux: NgRedux, + private router: Router, + private http: Http + ) { + + this.regions$ = new BehaviorSubject(REGION_SCHOOLS_INITIAL_STATE); + this.epalclasses$ = new BehaviorSubject(EPALCLASSES_INITIAL_STATE); + this.sectors$ = new BehaviorSubject(SECTOR_COURSES_INITIAL_STATE); + this.sectorFields$ = new BehaviorSubject(SECTOR_FIELDS_INITIAL_STATE); + this.studentDataFields$ = new BehaviorSubject(STUDENT_DATA_FIELDS_INITIAL_STATE); + this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE); + + this.modalTitle = new BehaviorSubject(""); + this.modalText = new BehaviorSubject(""); + this.modalHeader = new BehaviorSubject(""); + this.isModalShown = new BehaviorSubject(false); + this.showLoader = new BehaviorSubject(false); + }; @@ -185,73 +181,73 @@ import { HelperDataService } from '../../services/helper-data-service'; ngOnInit() { ($('#studentFormSentNotice')).appendTo("body"); - this.loginInfoSub = this._ngRedux.select(state => { - if (state.loginInfo.size > 0) { - state.loginInfo.reduce(({}, loginInfoToken) => { - this.authToken = loginInfoToken.auth_token; - - this.cu_name = loginInfoToken.cu_name; - this.cu_surname = loginInfoToken.cu_surname; - this.cu_fathername = loginInfoToken.cu_fathername; - this.cu_mothername = loginInfoToken.cu_mothername; - this.disclaimer_checked = loginInfoToken.disclaimer_checked; - - return loginInfoToken; - }, {}); - } - return state.loginInfo; - }).subscribe(this.loginInfo$); - - this.epalclassesSub = this._ngRedux.select(state => { - if (state.epalclasses.size > 0) { - state.epalclasses.reduce(({}, epalclass) => { - this.classSelected = epalclass.name; - return epalclass; - }, {}); - } - return state.epalclasses; - }).subscribe(this.epalclasses$); - - this.studentDataFieldsSub = this._ngRedux.select(state => { - return state.studentDataFields; - }).subscribe(this.studentDataFields$); - - this.regionsSub = this._ngRedux.select(state => { - state.regions.reduce((prevRegion, region) =>{ - region.epals.reduce((prevEpal, epal) =>{ - if (epal.selected === true) { - this.epalSelected.push(Number(epal.epal_id)); - this.epalSelectedOrder.push(epal.order_id); - } - return epal; - }, {}); - return region; - }, {}); - return state.regions; - }).subscribe(this.regions$); - - this.sectorsSub = this._ngRedux.select(state => { - state.sectors.reduce((prevSector, sector) =>{ - sector.courses.reduce((prevCourse, course) =>{ - if (course.selected === true) { - this.courseSelected = course.course_id - } - return course; - }, {}); - return sector; - }, {}); - return state.sectors; - }).subscribe(this.sectors$); - - this.sectorFieldsSub = this._ngRedux.select(state => { - state.sectorFields.reduce(({}, sectorField) =>{ - if (sectorField.selected === true) { - this.sectorSelected = sectorField.id + this.loginInfoSub = this._ngRedux.select(state => { + if (state.loginInfo.size > 0) { + state.loginInfo.reduce(({ }, loginInfoToken) => { + this.authToken = loginInfoToken.auth_token; + + this.cu_name = loginInfoToken.cu_name; + this.cu_surname = loginInfoToken.cu_surname; + this.cu_fathername = loginInfoToken.cu_fathername; + this.cu_mothername = loginInfoToken.cu_mothername; + this.disclaimer_checked = loginInfoToken.disclaimer_checked; + + return loginInfoToken; + }, {}); } - return sectorField; - }, {}); - return state.sectorFields; - }).subscribe(this.sectorFields$); + return state.loginInfo; + }).subscribe(this.loginInfo$); + + this.epalclassesSub = this._ngRedux.select(state => { + if (state.epalclasses.size > 0) { + state.epalclasses.reduce(({ }, epalclass) => { + this.classSelected = epalclass.name; + return epalclass; + }, {}); + } + return state.epalclasses; + }).subscribe(this.epalclasses$); + + this.studentDataFieldsSub = this._ngRedux.select(state => { + return state.studentDataFields; + }).subscribe(this.studentDataFields$); + + this.regionsSub = this._ngRedux.select(state => { + state.regions.reduce((prevRegion, region) => { + region.epals.reduce((prevEpal, epal) => { + if (epal.selected === true) { + this.epalSelected.push(Number(epal.epal_id)); + this.epalSelectedOrder.push(epal.order_id); + } + return epal; + }, {}); + return region; + }, {}); + return state.regions; + }).subscribe(this.regions$); + + this.sectorsSub = this._ngRedux.select(state => { + state.sectors.reduce((prevSector, sector) => { + sector.courses.reduce((prevCourse, course) => { + if (course.selected === true) { + this.courseSelected = course.course_id + } + return course; + }, {}); + return sector; + }, {}); + return state.sectors; + }).subscribe(this.sectors$); + + this.sectorFieldsSub = this._ngRedux.select(state => { + state.sectorFields.reduce(({ }, sectorField) => { + if (sectorField.selected === true) { + this.sectorSelected = sectorField.id + } + return sectorField; + }, {}); + return state.sectorFields; + }).subscribe(this.sectorFields$); }; @@ -272,147 +268,177 @@ import { HelperDataService } from '../../services/helper-data-service'; } submitNow() { - //αποστολή στοιχείων μαθητή στο entity: epal_student - // let aitisiObj: Array = []; - let aitisiObj: Array = []; - let epalObj: Array = []; - - let std = this.studentDataFields$.getValue().get(0); - console.log(std); - aitisiObj[0] = {}; - aitisiObj[0].name = std.name; - aitisiObj[0].studentsurname = std.studentsurname; - aitisiObj[0].studentbirthdate = std.studentbirthdate; - aitisiObj[0].fatherfirstname = std.fatherfirstname; - aitisiObj[0].motherfirstname = std.motherfirstname; - aitisiObj[0].regionaddress = std.regionaddress; - aitisiObj[0].regionarea = std.regionarea; - aitisiObj[0].regiontk = std.regiontk; - aitisiObj[0].certificatetype = std.certificatetype; -// aitisiObj[0].graduation_year = std.graduation_year; -// aitisiObj[0].lastschool_registrynumber = std.lastschool_registrynumber; -// aitisiObj[0].lastschool_schoolyear = std.lastschool_schoolyear; -// aitisiObj[0].lastschool_class = std.lastschool_class; -// aitisiObj[0].currentepal = std.currentepal; - - aitisiObj[0].graduation_year = std.graduation_year; - aitisiObj[0].lastschool_registrynumber = std.lastschool_schoolname.registry_no; - aitisiObj[0].lastschool_schoolname = std.lastschool_schoolname.name; - aitisiObj[0].lastschool_schoolyear = std.lastschool_schoolyear; - aitisiObj[0].lastschool_unittypeid = std.lastschool_schoolname.unit_type_id; - aitisiObj[0].lastschool_class = std.lastschool_class; -// aitisiObj[0].currentepal = 154; - - aitisiObj[0].relationtostudent = std.relationtostudent; - aitisiObj[0].telnum = std.telnum; - - aitisiObj[0].cu_name = this.cu_name; - aitisiObj[0].cu_surname = this.cu_surname; - aitisiObj[0].cu_fathername = this.cu_fathername; - aitisiObj[0].cu_mothername = this.cu_mothername; - aitisiObj[0].disclaimer_checked = this.disclaimer_checked; - aitisiObj[0].currentclass = this.classSelected; - - for (let i=0; i < this.epalSelected.length; i++) - epalObj[i] =new StudentEpalChosen(null, this.epalSelected[i] , this.epalSelectedOrder[i]); - aitisiObj['1'] = epalObj; - - if (aitisiObj[0]['currentclass'] === "2" ) - aitisiObj['3'] = new StudentSectorChosen(null, this.sectorSelected); - else if (aitisiObj[0]['currentclass'] === "3" || aitisiObj[0]['currentclass'] === "4" ) { - aitisiObj['3'] = new StudentCourseChosen(null, this.courseSelected); - } - - this.submitRecord(aitisiObj); - } - - - submitRecord(record) { - let authTokenPost = this.authToken + ":" + this.authToken; - - let headers = new Headers({ - "Authorization": "Basic " + btoa(authTokenPost), - "Accept": "*/*", - "Access-Control-Allow-Credentials": "true", - "Content-Type": "application/json", - }); - - let options = new RequestOptions({ headers: headers, method: "post", withCredentials: true }); - let connectionString = `${AppSettings.API_ENDPOINT}/epal/appsubmit`; - this.showLoader.next(true); - this.http.post(connectionString, record, options) - .map((res: Response) => res.json()) - .subscribe( - success => { - ($('.loading')).remove(); - this.showLoader.next(false); - let errorCode = parseInt(success.error_code); - if (errorCode === 0) { - this.modalTitle.next("Υποβολή Αίτησης Εγγραφής"); - this.modalText.next("Η υποβολή της αίτησής σας πραγματοποιήθηκε. Μπορείτε να την εκτυπώσετε από την επιλογή 'Εμφάνιση - Εκτύπωση Αίτησης'. Θα ειδοποιηθείτε στο e-mail που δηλώσατε για την εξέλιξη της αίτησής σας"); - this.modalHeader.next("modal-header-success"); - this._eca.initEpalClasses(); - this._sfa.initSectorFields(); - this._rsa.initRegionSchools(); - this._csa.initSectorCourses(); - this._sdfa.initStudentDataFields(); - console.log("success post"); - this.showModal(); - } - else if (errorCode === 1001) { - this.modalTitle.next("Αποτυχία Υποβολής Αίτησης"); - this.modalText.next("Δεν έχετε αποδεχθεί τους όρους χρήσης"); - this.modalHeader.next("modal-header-danger"); - console.log("no disclaimer checked"); - this.showModal(); - } else { - this.modalTitle.next("Αποτυχία Υποβολής Αίτησης"); - this.modalText.next("Ελέξτε τη φόρμα σας. Υπάρχουν λάθη - ελλείψεις που δεν επιτρέπουν την υποβολή"); - this.modalHeader.next("modal-header-danger"); - console.log("other error"); - this.showModal(); - } - }, - error => { - ($('.loading')).remove(); - this.showLoader.next(false); - this.modalHeader.next("modal-header-danger"); - this.modalTitle.next("Υποβολή Αίτησης Εγγραφής"); - this.modalText.next("Η υποβολή της αίτησής σας απέτυχε. Παρακαλούμε προσπαθήστε πάλι και αν το πρόβλημα συνεχίσει να υφίσταται, επικοινωνήστε με την ομάδα υποστήριξης"); - this.showLoader.next(false); - this.showModal(); - console.log("Error HTTP POST Service")}, - () => { - console.log("write this message anyway"); - ($('.loading')).remove(); - this.showLoader.next(false); - }, - - ); - - } - - public showModal():void { - ($('#studentFormSentNotice')).modal('show'); - } - - public hideModal():void { - console.log("going to post-submit from hide()"); - ($('#studentFormSentNotice')).modal('hide'); - if (this.modalHeader.getValue() === "modal-header-success") { - this.router.navigate(['/post-submit']); - } - - } - - public onHidden():void { - this.isModalShown.next(false); - console.log("going to post-submit"); - this.router.navigate(['/post-submit']); - } - - navigateBack() { - this.router.navigate(['/student-application-form-main']); - } + //αποστολή στοιχείων μαθητή στο entity: epal_student + // let aitisiObj: Array = []; + let aitisiObj: Array = []; + let epalObj: Array = []; + + let std = this.studentDataFields$.getValue().get(0); + console.log(std); + aitisiObj[0] = {}; + aitisiObj[0].name = std.name; + aitisiObj[0].studentsurname = std.studentsurname; + aitisiObj[0].studentbirthdate = std.studentbirthdate; + aitisiObj[0].fatherfirstname = std.fatherfirstname; + aitisiObj[0].motherfirstname = std.motherfirstname; + aitisiObj[0].regionaddress = std.regionaddress; + aitisiObj[0].regionarea = std.regionarea; + aitisiObj[0].regiontk = std.regiontk; + aitisiObj[0].certificatetype = std.certificatetype; + // aitisiObj[0].graduation_year = std.graduation_year; + // aitisiObj[0].lastschool_registrynumber = std.lastschool_registrynumber; + // aitisiObj[0].lastschool_schoolyear = std.lastschool_schoolyear; + // aitisiObj[0].lastschool_class = std.lastschool_class; + // aitisiObj[0].currentepal = std.currentepal; + + aitisiObj[0].graduation_year = std.graduation_year; + aitisiObj[0].lastschool_registrynumber = std.lastschool_schoolname.registry_no; + aitisiObj[0].lastschool_schoolname = std.lastschool_schoolname.name; + aitisiObj[0].lastschool_schoolyear = std.lastschool_schoolyear; + aitisiObj[0].lastschool_unittypeid = std.lastschool_schoolname.unit_type_id; + aitisiObj[0].lastschool_class = std.lastschool_class; + // aitisiObj[0].currentepal = 154; + + aitisiObj[0].relationtostudent = std.relationtostudent; + aitisiObj[0].telnum = std.telnum; + + aitisiObj[0].cu_name = this.cu_name; + aitisiObj[0].cu_surname = this.cu_surname; + aitisiObj[0].cu_fathername = this.cu_fathername; + aitisiObj[0].cu_mothername = this.cu_mothername; + aitisiObj[0].disclaimer_checked = this.disclaimer_checked; + aitisiObj[0].currentclass = this.classSelected; + + for (let i = 0; i < this.epalSelected.length; i++) + epalObj[i] = new StudentEpalChosen(null, this.epalSelected[i], this.epalSelectedOrder[i]); + aitisiObj['1'] = epalObj; + + if (aitisiObj[0]['currentclass'] === "2") + aitisiObj['3'] = new StudentSectorChosen(null, this.sectorSelected); + else if (aitisiObj[0]['currentclass'] === "3" || aitisiObj[0]['currentclass'] === "4") { + aitisiObj['3'] = new StudentCourseChosen(null, this.courseSelected); + } + + this.submitRecord(aitisiObj); + } + + + submitRecord(record) { + let authTokenPost = this.authToken + ":" + this.authToken; + + let headers = new Headers({ + "Authorization": "Basic " + btoa(authTokenPost), + "Accept": "*/*", + "Access-Control-Allow-Credentials": "true", + "Content-Type": "application/json", + }); + + let options = new RequestOptions({ headers: headers, method: "post", withCredentials: true }); + let connectionString = `${AppSettings.API_ENDPOINT}/epal/appsubmit`; + this.showLoader.next(true); + this.http.post(connectionString, record, options) + .map((res: Response) => res.json()) + .subscribe(success => { + ($('.loading')).remove(); + this.showLoader.next(false); + let errorCode = parseInt(success.error_code); + + let mTitle = ""; + let mText = ""; + let mHeader = ""; + switch (errorCode) { + case 0: + this._eca.initEpalClasses(); + this._sfa.initSectorFields(); + this._rsa.initRegionSchools(); + this._csa.initSectorCourses(); + this._sdfa.initStudentDataFields(); + mTitle = "Υποβολή Αίτησης Εγγραφής"; + mText = "Η υποβολή της αίτησής σας πραγματοποιήθηκε. Μπορείτε να την εκτυπώσετε από την επιλογή 'Εμφάνιση - Εκτύπωση Αίτησης'. Θα ειδοποιηθείτε στο e-mail που δηλώσατε για την εξέλιξη της αίτησής σας."; + mHeader = "modal-header-success"; + break; + case 1001: + mTitle = "Αποτυχία Υποβολής Αίτησης"; + mText = "Δεν έχετε αποδεχθεί τους όρους χρήσης"; + mHeader = "modal-header-danger"; + break; + case 1002: + mTitle = "Αποτυχία Υποβολής Αίτησης"; + mText = "Ελέξτε τη φόρμα σας. Υπάρχουν λάθη - ελλείψεις που δεν επιτρέπουν την υποβολή."; + mHeader = "modal-header-danger"; + break; + case 1003: + mTitle = "Αποτυχία Υποβολής Αίτησης"; + mText = "Ελέξτε τη φόρμα σας. Η ημερομηνία γέννησης δεν είναι έγκυρη."; + mHeader = "modal-header-danger"; + break; + case 8000: + case 8001: + mTitle = "Αποτυχία Υποβολής Αίτησης"; + mText = "Προέκυψε σφάλμα κατά τη διάρκεια ελέγχου των στοιχείων φοίτησης σας. Παρακαλώ δοκιμάστε ξανά ή προσπαθήστε αργότερα. Εάν το πρόβλημα συνεχίσει να υφίσταται, επικοινωνήστε με την ομάδα υποστήριξης."; + mHeader = "modal-header-danger"; + break; + case 8002: + mTitle = "Αποτυχία Υποβολής Αίτησης"; + mText = "Τα στοιχεία φοίτησης που υποβάλλατε δεν επικυρώθηκαν. Παρακαλώ ελέγξτε τη φόρμα σας και προσπαθήστε ξανά. Εάν το θέμα συνεχίσει να υφίσταται, επικοινωνήστε με την ομάδα υποστήριξης."; + mHeader = "modal-header-danger"; + break; + case 8003: + mTitle = "Αποτυχία Υποβολής Αίτησης"; + mText = "Τα στοιχεία φοίτησης που υποβάλλατε δεν είναι έγκυρα. Παρακαλώ ελέγξτε τη φόρμα σας και προσπαθήστε ξανά. Εάν το θέμα συνεχίσει να υφίσταται, επικοινωνήστε με την ομάδα υποστήριξης."; + mHeader = "modal-header-danger"; + break; + default: + mTitle = "Αποτυχία Υποβολής Αίτησης"; + mText = "Ελέξτε τη φόρμα σας. Υπάρχουν λάθη - ελλείψεις που δεν επιτρέπουν την υποβολή."; + mHeader = "modal-header-danger"; + } + + this.modalTitle.next(mTitle); + this.modalText.next(mText); + this.modalHeader.next(mHeader); + this.showModal(); + }, + error => { + ($('.loading')).remove(); + this.modalHeader.next("modal-header-danger"); + this.modalTitle.next("Υποβολή Αίτησης Εγγραφής"); + this.modalText.next("Η υποβολή της αίτησής σας απέτυχε. Παρακαλούμε προσπαθήστε πάλι και αν το πρόβλημα συνεχίσει να υφίσταται, επικοινωνήστε με την ομάδα υποστήριξης."); + this.showModal(); + this.showLoader.next(false); + console.log("Error HTTP POST Service") + }, + () => { + console.log("write this message anyway"); + ($('.loading')).remove(); + this.showLoader.next(false); + }, + + ); + + } + + public showModal(): void { + ($('#studentFormSentNotice')).modal('show'); + } + + public hideModal(): void { + console.log("going to post-submit from hide()"); + ($('#studentFormSentNotice')).modal('hide'); + if (this.modalHeader.getValue() === "modal-header-success") { + this.router.navigate(['/post-submit']); + } + + } + + public onHidden(): void { + this.isModalShown.next(false); + console.log("going to post-submit"); + this.router.navigate(['/post-submit']); + } + + navigateBack() { + this.router.navigate(['/student-application-form-main']); + } }