Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MainController extends Controller
- {
- public function __construct($model = null, $action = null)
- {
- if ($model == null && $action == null)
- {
- parent::__construct();
- $this->setDefaultAction('test');
- return;
- }
- if($action === 'e403' || $action === 'e404')
- parent::__construct($model, $action, array(Controller::HAS_VIEW));
- else
- parent::__construct($model, $action);
- }
- public function e403_Action()
- {
- try
- {
- $this->_view->set('session_check', false);
- $this->_view->set('title', '403');
- $m = App::getMessages('request', true);
- if(is_null($m) || $m == '')
- $m = 'Dostęp do tej lokalizacji lub obiektu jest zabroniony.';
- $this->_view->set('message', $m);
- if($this->isLoggedIn())
- {
- $this->_view->set('user', MSession::getUser());
- $this->_view->set('user_data', MSession::getUserData());
- $this->_view->set('default_route', MSession::getUserDefaultRoute());
- }
- else
- {
- $this->_view->set('user', null);
- $this->_view->set('user_data', null);
- $this->_view->set('default_route', MSession::getUserDefaultRoute());
- }
- return $this->_view->output();
- }
- catch(Exception $e)
- {
- echo "Application error:" . $e->getMessage();
- }
- }
- public function e404_Action()
- {
- try
- {
- $this->_view->set('session_check', false);
- $this->_view->set('title', '404');
- $m = App::getMessages('request', true);
- if(is_null($m) || $m == '')
- $m = 'Żadanie nie może być zrealizowane. Upewnij się, że prowadzony adres jest poprawny oraz że obiekt docelowy istnieje.';
- $this->_view->set('message', $m);
- if($this->isLoggedIn())
- {
- $this->_view->set('user', MSession::getUser());
- $this->_view->set('user_data', MSession::getUserData());
- $this->_view->set('default_route', MSession::getUserDefaultRoute());
- }
- else
- {
- $this->_view->set('user', null);
- $this->_view->set('user_data', null);
- $this->_view->set('default_route', MSession::getUserDefaultRoute());
- }
- return $this->_view->output();
- }
- catch(Exception $e)
- {
- echo "Application error:" . $e->getMessage();
- }
- }
- public function index_ActionCheckAccess()
- {
- if(!$this->isLoggedIn())
- {
- App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
- App::redirect(Route::build()->controller('admin')->action('login'));
- return false;
- }
- $user = MSession::getUser();
- return $user->canLoinToForm();
- }
- public function recos_ActionCheckAccess()
- {
- if(!$this->isLoggedIn())
- {
- App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
- App::redirect(Route::build()->controller('admin')->action('login'));
- return false;
- }
- $user = MSession::getUser();
- return $user->canLoinToForm();
- }
- public function test_ActionCheckAccess()
- {
- if(!$this->isLoggedIn())
- {
- App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
- App::redirect(Route::build()->controller('admin')->action('login'));
- return false;
- }
- $user = MSession::getUser();
- return $user->canLoinToForm();
- }
- public function email_ActionCheckAccess()
- {
- if(!$this->isLoggedIn())
- {
- App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
- App::redirect(Route::build()->controller('admin')->action('login'));
- return false;
- }
- $user = MSession::getUser();
- return $user->canLoinToForm();
- }
- public function export_ActionCheckAccess()
- {
- if(!$this->isLoggedIn())
- {
- App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
- App::redirect(Route::build()->controller('admin')->action('login'));
- return false;
- }
- $user = MSession::getUser();
- return $user->canLoinToForm();
- }
- public function ranking_ActionCheckAccess()
- {
- return true;
- }
- public function ranking_Action($opt)
- {
- try
- {
- $user = MSession::getUser();
- $this->_view->set('title', messages::getTranslation("ranking_title"));
- $this->_view->set('pageTitle', messages::getTranslation("ranking_title"));
- $this->_view->set('action', 'ranking');
- // $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
- $this->_view->set('opt', $opt);
- $this->_view->set('patient_id', -1);
- $this->_view->set('user', $user);
- return $this->_view->output();
- }
- catch(Exception $e)
- {
- echo "Application error:" . $e->getMessage();
- }
- }
- public function my_tests_ActionCheckAccess()
- {
- if(!$this->isLoggedIn())
- {
- App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
- App::redirect(Route::build()->controller('admin')->action('login'));
- return false;
- }
- $user = MSession::getUser();
- return $user->canLoinToForm();
- }
- public function email_Action($opt)
- {
- try
- {
- $user = MSession::getUser();
- $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
- $this->_view->set('opt', $opt);
- $this->_view->set('patient_id', $patient_id);
- $m = Model::getInstance('Variables'); //new VariablesModel();
- $patient = Model::getInstance('Patient'); //new PatientModel();
- if($patient_id != 0)
- {
- $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
- $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
- }
- else
- {
- $this->_view->set('dane_osobowe_pacjenta', array());
- $this->_view->set('dane_pacjenta', array());
- }
- $vars = $m->getPatientFormActiveVariables();
- $this->_view->set('variables', $vars);
- $this->_view->set('kliniki', $patient->getClinics());
- $this->_view->set('grupy', $m->getActiveGroups($vars));
- $this->_view->set('title', messages::getTranslation("patient_form_email_title"));
- $this->_view->set('pageTitle', messages::getTranslation("patient_form_email_title"));
- $this->_view->set('user', $user);
- $this->_view->set('action', 'email');
- $this->_view->set('email', $opt);
- return $this->_view->output();
- }
- catch(Exception $e)
- {
- echo "Application error:" . $e->getMessage();
- }
- }
- public function export_Action($opt)
- {
- try
- {
- $user = MSession::getUser();
- // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
- //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
- $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
- $this->_view->set('opt', $opt);
- $this->_view->set('patient_id', $patient_id);
- $m = Model::getInstance('Variables'); //new VariablesModel();
- $patient = Model::getInstance('Patient'); //new PatientModel();
- if($patient_id != 0)
- {
- $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
- $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
- }
- else
- {
- $this->_view->set('dane_osobowe_pacjenta', array());
- $this->_view->set('dane_pacjenta', array());
- }
- $vars = $m->getPatientFormActiveVariables();
- $this->_view->set('variables', $vars);
- $this->_view->set('kliniki', $patient->getClinics());
- $this->_view->set('grupy', $m->getActiveGroups($vars));
- $this->_view->set('title', messages::getTranslation("patient_form_export_title"));
- $this->_view->set('pageTitle', messages::getTranslation("patient_form_export_title"));
- $this->_view->set('user', $user);
- $this->_view->set('action', 'export');
- return $this->_view->output();
- }
- catch(Exception $e)
- {
- echo "Application error:" . $e->getMessage();
- }
- }
- public function subscribe_Action($opt)
- {
- try
- {
- $user = MSession::getUser();
- // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
- //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
- $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
- $this->_view->set('opt', $opt);
- $this->_view->set('patient_id', $patient_id);
- $this->_view->set('title', messages::getTranslation("patient_form_title"));
- $this->_view->set('pageTitle', messages::getTranslation("patient_form_title"));
- $this->_view->set('user', $user);
- $this->_view->set('action', 'subscribe');
- return $this->_view->output();
- }
- catch(Exception $e)
- {
- echo "Application error:" . $e->getMessage();
- }
- }
- public function my_tests_Action($opt)
- {
- try
- {
- $user = MSession::getUser();
- // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
- //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
- $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
- $this->_view->set('opt', $opt);
- $this->_view->set('patient_id', $patient_id);
- $m = Model::getInstance('Variables'); //new VariablesModel();
- $patient = Model::getInstance('Patient'); //new PatientModel();
- if($patient_id != 0)
- {
- $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
- $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
- }
- else
- {
- $this->_view->set('dane_osobowe_pacjenta', array());
- $this->_view->set('dane_pacjenta', array());
- }
- $vars = $m->getPatientFormActiveVariables();
- $this->_view->set('variables', $vars);
- $this->_view->set('kliniki', $patient->getClinics());
- $this->_view->set('grupy', $m->getActiveGroups($vars));
- $this->_view->set('title', messages::getTranslation("patient_form_title"));
- $this->_view->set('pageTitle', messages::getTranslation("patient_form_title"));
- $this->_view->set('user', $user);
- $this->_view->set('action', 'my_tests');
- return $this->_view->output();
- }
- catch(Exception $e)
- {
- echo "Application error:" . $e->getMessage();
- }
- }
- public function recos_Action($opt)
- {
- try
- {
- $user = MSession::getUser();
- // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
- //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
- $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
- $this->_view->set('opt', $opt);
- $this->_view->set('patient_id', $patient_id);
- $m = Model::getInstance('Variables'); //new VariablesModel();
- $patient = Model::getInstance('Patient'); //new PatientModel();
- if($patient_id != 0)
- {
- $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
- $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
- }
- else
- {
- $this->_view->set('dane_osobowe_pacjenta', array());
- $this->_view->set('dane_pacjenta', array());
- }
- $vars = $m->getPatientFormActiveVariables();
- $this->_view->set('variables', $vars);
- $this->_view->set('kliniki', $patient->getClinics());
- $this->_view->set('grupy', $m->getActiveGroups($vars));
- $this->_view->set('title', messages::getTranslation("patient_form_title"));
- $this->_view->set('pageTitle', messages::getTranslation("patient_form_title"));
- $this->_view->set('user', $user);
- $this->_view->set('action', 'recos');
- return $this->_view->output();
- }
- catch(Exception $e)
- {
- echo "Application error:" . $e->getMessage();
- }
- }
- public function home_Action($opt)
- {
- try
- {
- $user = MSession::getUser();
- // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
- //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
- $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
- $this->_view->set('opt', $opt);
- $this->_view->set('patient_id', $patient_id);
- $m = Model::getInstance('Variables'); //new VariablesModel();
- $patient = Model::getInstance('Patient'); //new PatientModel();
- if($patient_id != 0)
- {
- $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
- $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
- }
- else
- {
- $this->_view->set('dane_osobowe_pacjenta', array());
- $this->_view->set('dane_pacjenta', array());
- }
- $vars = $m->getPatientFormActiveVariables();
- $this->_view->set('variables', $vars);
- $this->_view->set('kliniki', $patient->getClinics());
- $this->_view->set('grupy', $m->getActiveGroups($vars));
- $this->_view->set('title', messages::getTranslation("patient_form_title"));
- $this->_view->set('pageTitle', messages::getTranslation("patient_form_title"));
- $this->_view->set('user', $user);
- $this->_view->set('action', 'home');
- return $this->_view->output();
- }
- catch(Exception $e)
- {
- echo "Application error:" . $e->getMessage();
- }
- }
- /**
- * Formularz pacjenta (indywidualna prognoza).
- * @return type
- */
- public function test_Action($opt)
- {
- try
- {
- // sprawdzenie subskrypcji dla produktów test i post ivf-test
- $subscriptionDCount = WPHelperFuncs::getSubscriptionDayCount(9);
- $subscriptionDCount2 = WPHelperFuncs::getSubscriptionDayCount(10);
- if ($subscriptionDCount2 > $subscriptionDCount)
- $subscriptionDCount = $subscriptionDCount2;
- if ($subscriptionDCount < 1 && Config::getCfg('usr_allow_without_subscription', false))
- $subscriptionDCount = 1;
- $user = MSession::getUser();
- // TODO: parp testy
- if ($user->getUserId() == 43 || $user->getUserId() == 49 || $user->getUserId() == 50 || $user->getUserId() == 51)
- {
- $subscriptionDCount = 30;
- $subscriptionDCount2 = 30;
- }
- // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
- //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
- $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
- $this->_view->set('subscriptiondc', $subscriptionDCount);
- $this->_view->set('post_ivf', $subscriptionDCount2 > 0);
- $this->_view->set('opt', $opt);
- $this->_view->set('patient_id', $patient_id);
- $m = Model::getInstance('Variables'); //new VariablesModel();
- $patient = Model::getInstance('Patient'); //new PatientModel();
- if($patient_id != 0)
- {
- $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
- $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
- }
- else
- {
- $this->_view->set('dane_osobowe_pacjenta', array());
- $this->_view->set('dane_pacjenta', array());
- }
- $vars = $m->getPatientFormActiveVariables();
- $this->_view->set('variables', $vars);
- $this->_view->set('kliniki', $patient->getClinics());
- $this->_view->set('grupy', $m->getActiveGroups($vars));
- $this->_view->set('title', messages::getTranslation("patient_form_title"));
- $this->_view->set('pageTitle', messages::getTranslation("patient_form_title"));
- $this->_view->set('user', $user);
- $this->_view->set('action', 'test');
- return $this->_view->output();
- }
- catch(Exception $e)
- {
- echo "Application error:" . $e->getMessage();
- }
- }
- /**
- * Formularz pacjenta (indywidualna prognoza).
- * @return type
- */
- public function index_Action()
- {
- try
- {
- $user = MSession::getUser();
- // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
- //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
- $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
- $this->_view->set('patient_id', $patient_id);
- $m = Model::getInstance('Variables'); //new VariablesModel();
- $patient = Model::getInstance('Patient'); //new PatientModel();
- if($patient_id != 0)
- {
- $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
- $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
- }
- else
- {
- $this->_view->set('dane_osobowe_pacjenta', array());
- }
- $vars = $m->getPatientFormActiveVariables();
- $this->_view->set('variables', $vars);
- $this->_view->set('kliniki', $patient->getClinics());
- $this->_view->set('grupy', $m->getActiveGroups($vars));
- $this->_view->set('title', messages::getTranslation("patient_form_title"));
- $this->_view->set('pageTitle', messages::getTranslation("patient_form_title"));
- $this->_view->set('user', $user);
- return $this->_view->output();
- }
- catch(Exception $e)
- {
- echo "Application error:" . $e->getMessage();
- }
- }
- public function calc_ActionCheckAccess()
- {
- if(!$this->isLoggedIn())
- {
- App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
- App::redirect(Route::build()->controller('admin')->action('login'));
- return false;
- }
- $user = MSession::getUser();
- return $user->canLoinToForm();
- }
- /**
- * Zapis formularza do bazy, uruchomienie skryptu R i wyświetlenie indywidualnej prognozy
- * @return type
- */
- public function calc_Action($opt)
- {
- $o = array();
- $action = '';
- if(isset($opt) && $opt !== NULL)
- {
- $o = explode(",", $opt);
- $action = $o[0];
- }
- $rezultat = '<i class="fa fa-circle-o-notch fa-spin"></i> '.messages::getTranslation('msg_calculating'); //Obliczanie. Proszę czekać....<br><small>Operacja może potrwać kilka minut.<br>Prosimy nie odświeżać strony.</small>';
- $user = MSession::getUser();
- // var_dump($_POST); die;
- if(count($_POST) > 0)
- {
- // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
- $patient_id = (int) ($user->getAssignedProfileData()['patient_id']); //isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
- $this->_view->set('patient_id', $patient_id);
- $db = Db::init();
- $clinic_id = (int) ($_POST['typ_testu'] == 'standard' ? 0 : $_POST['wybor_kliniki']);
- $po_ivf = $_POST['po_inv'] == 'Y';
- $birthDate = $_POST['birth_date'];
- $birthDate = explode("-", $birthDate);
- $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[1], $birthDate[2], $birthDate[0]))) > date("md") ? ((date("Y") - $birthDate[0]) - 1) : (date("Y") - $birthDate[0]));
- $current_step = 2;
- $pid = (int) $patient_id;
- $v = $_POST['zmienna'];
- // $v[1] = (int) $age;
- $v[4] = 1;
- try
- {
- if($v[2] == 0)
- $v[2] = 100;
- $v[4] = $v[3] / (($v[2] / 100.0) * ($v[2] / 100.0)); // ustawienie wartości BMI
- }
- catch(Exception $e)
- {
- }
- $r = false;
- $varsModel = Model::getInstance('Variables'); //new VariablesModel();
- $varsModel->setPatientId($pid);
- foreach($v as $vId => $val)
- {
- $v2 = $val;
- if ($v2 != '')
- $varsModel->setVariableValue($vId, $v2);
- }
- $r = $varsModel->store();
- if($action == 'store')
- {
- $this->_view->set('store', true);
- if($r)
- {
- $rezultat = '0%';
- // app::addMessage(app::MSG_INFO, message::build()->type('info')->title('Komunikat')->body('Dane wprowadzone do formularza zostały zapamiętane. Za chwilę nastąpi automatyczne przekierowanie.'));
- // app::addScriptDefinition("setTimeout(function(){window.location='" . Route::build()->controller('admin')->action('index')->opt(['results'])->get() . "';}, 5000);", true);
- }
- }
- else if($r)
- {
- /** uruchomienie skryptów R dla zmiennych i nowo dodanego pacjenta */
- $po = (int) $po_ivf ? 1 : 0;
- // echo "Rscript ../script2.R $pid $po $clinic_id\n\n----";
- $r = exec("Rscript ./bin/script2.R $pid $po $clinic_id > /dev/null &");
- if ($r != 0)
- $rezultat = "Błąd: skontaktuj się z administratorem.";
- //exec($cmd, $outArray, $ret)
- // echo $r;
- //echo "$r\n\n\n";
- //$znaj = array();
- //preg_match("(\%(.*?)\%)", $r, $znaj);
- //if(isset($znaj[0]))
- // $rezultat = round(trim($znaj[0], "%") * 100, 2) . "%";
- $recos = [];
- $reco = Model::getInstance('Reco');//new RecoModel();
- $recom = Recommendation::init($reco);
- $recos = $recom->generate_reco($pid);
- $cats = $reco->getRecoCategories();
- $this->_view->set('recos', $recos);
- $this->_view->set('cats', $cats);
- $recom->storeRecommendation($recos);
- }
- }
- try
- {
- // $this->_view->set('display_prognosis', false);
- $this->_view->set('session_check', false);
- $this->_view->set('title', messages::getTranslation("patient_form_title_result"));
- $this->_view->set('rezultat', $rezultat);
- $this->_view->set('user', $user);
- $this->_view->set('action', 'calc');
- return $this->_view->output();
- }
- catch(Exception $e)
- {
- echo "Application error:" . $e->getMessage();
- }
- }
- }
Add Comment
Please, Sign In to add comment