Deedlit

maincontroller.php

Jul 7th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 21.18 KB | None | 0 0
  1. <?php
  2.  
  3. class MainController extends Controller
  4. {
  5.  
  6.  
  7.     public function __construct($model = null, $action = null)
  8.     {
  9.         if ($model == null && $action == null)
  10.         {
  11.             parent::__construct();
  12.             $this->setDefaultAction('test');
  13.             return;
  14.         }
  15.  
  16.         if($action === 'e403' || $action === 'e404')
  17.             parent::__construct($model, $action, array(Controller::HAS_VIEW));
  18.         else
  19.             parent::__construct($model, $action);
  20.     }
  21.  
  22.  
  23.     public function e403_Action()
  24.     {
  25.         try
  26.         {
  27.             $this->_view->set('session_check', false);
  28.             $this->_view->set('title', '403');
  29.             $m = App::getMessages('request', true);
  30.             if(is_null($m) || $m == '')
  31.                 $m = 'Dostęp do tej lokalizacji lub obiektu jest zabroniony.';
  32.             $this->_view->set('message', $m);
  33.             if($this->isLoggedIn())
  34.             {
  35.                 $this->_view->set('user', MSession::getUser());
  36.                 $this->_view->set('user_data', MSession::getUserData());
  37.                 $this->_view->set('default_route', MSession::getUserDefaultRoute());
  38.             }
  39.             else
  40.             {
  41.                 $this->_view->set('user', null);
  42.                 $this->_view->set('user_data', null);
  43.                 $this->_view->set('default_route', MSession::getUserDefaultRoute());
  44.             }
  45.  
  46.             return $this->_view->output();
  47.         }
  48.         catch(Exception $e)
  49.         {
  50.             echo "Application error:" . $e->getMessage();
  51.         }
  52.     }
  53.  
  54.  
  55.     public function e404_Action()
  56.     {
  57.         try
  58.         {
  59.             $this->_view->set('session_check', false);
  60.             $this->_view->set('title', '404');
  61.             $m = App::getMessages('request', true);
  62.             if(is_null($m) || $m == '')
  63.                 $m = 'Żadanie nie może być zrealizowane. Upewnij się, że prowadzony adres jest poprawny oraz że obiekt docelowy istnieje.';
  64.             $this->_view->set('message', $m);
  65.             if($this->isLoggedIn())
  66.             {
  67.                 $this->_view->set('user', MSession::getUser());
  68.                 $this->_view->set('user_data', MSession::getUserData());
  69.                 $this->_view->set('default_route', MSession::getUserDefaultRoute());
  70.             }
  71.             else
  72.             {
  73.                 $this->_view->set('user', null);
  74.                 $this->_view->set('user_data', null);
  75.                 $this->_view->set('default_route', MSession::getUserDefaultRoute());
  76.             }
  77.  
  78.             return $this->_view->output();
  79.         }
  80.         catch(Exception $e)
  81.         {
  82.             echo "Application error:" . $e->getMessage();
  83.         }
  84.     }
  85.  
  86.  
  87.     public function index_ActionCheckAccess()
  88.     {
  89.         if(!$this->isLoggedIn())
  90.         {
  91.             App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
  92.             App::redirect(Route::build()->controller('admin')->action('login'));
  93.             return false;
  94.         }
  95.         $user = MSession::getUser();
  96.         return $user->canLoinToForm();
  97.     }
  98.  
  99.  
  100.     public function recos_ActionCheckAccess()
  101.     {
  102.         if(!$this->isLoggedIn())
  103.         {
  104.             App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
  105.             App::redirect(Route::build()->controller('admin')->action('login'));
  106.             return false;
  107.         }
  108.         $user = MSession::getUser();
  109.         return $user->canLoinToForm();
  110.     }
  111.  
  112.     public function test_ActionCheckAccess()
  113.     {
  114.         if(!$this->isLoggedIn())
  115.         {
  116.             App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
  117.             App::redirect(Route::build()->controller('admin')->action('login'));
  118.             return false;
  119.         }
  120.         $user = MSession::getUser();
  121.         return $user->canLoinToForm();
  122.     }
  123.  
  124.     public function email_ActionCheckAccess()
  125.     {
  126.         if(!$this->isLoggedIn())
  127.         {
  128.             App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
  129.             App::redirect(Route::build()->controller('admin')->action('login'));
  130.             return false;
  131.         }
  132.         $user = MSession::getUser();
  133.         return $user->canLoinToForm();
  134.     }
  135.  
  136.     public function export_ActionCheckAccess()
  137.     {
  138.         if(!$this->isLoggedIn())
  139.         {
  140.             App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
  141.             App::redirect(Route::build()->controller('admin')->action('login'));
  142.             return false;
  143.         }
  144.         $user = MSession::getUser();
  145.         return $user->canLoinToForm();
  146.     }
  147.  
  148.     public function ranking_ActionCheckAccess()
  149.     {
  150.         return true;
  151.     }
  152.  
  153.     public function ranking_Action($opt)
  154.     {
  155.         try
  156.         {
  157.             $user = MSession::getUser();
  158.  
  159.             $this->_view->set('title', messages::getTranslation("ranking_title"));
  160.             $this->_view->set('pageTitle', messages::getTranslation("ranking_title"));
  161.             $this->_view->set('action', 'ranking');
  162. //          $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
  163.             $this->_view->set('opt', $opt);
  164.             $this->_view->set('patient_id', -1);
  165.             $this->_view->set('user', $user);
  166.  
  167.             return $this->_view->output();
  168.         }
  169.         catch(Exception $e)
  170.         {
  171.             echo "Application error:" . $e->getMessage();
  172.         }
  173.     }
  174.  
  175.  
  176.     public function my_tests_ActionCheckAccess()
  177.     {
  178.         if(!$this->isLoggedIn())
  179.         {
  180.             App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
  181.             App::redirect(Route::build()->controller('admin')->action('login'));
  182.             return false;
  183.         }
  184.         $user = MSession::getUser();
  185.         return $user->canLoinToForm();
  186.     }
  187.  
  188.     public function email_Action($opt)
  189.     {
  190.         try
  191.         {
  192.             $user = MSession::getUser();
  193.  
  194.             $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
  195.             $this->_view->set('opt', $opt);
  196.             $this->_view->set('patient_id', $patient_id);
  197.             $m = Model::getInstance('Variables'); //new VariablesModel();
  198.             $patient = Model::getInstance('Patient'); //new PatientModel();
  199.             if($patient_id != 0)
  200.             {
  201.                 $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
  202.                 $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
  203.             }
  204.             else
  205.             {
  206.                 $this->_view->set('dane_osobowe_pacjenta', array());
  207.                 $this->_view->set('dane_pacjenta', array());
  208.             }
  209.             $vars = $m->getPatientFormActiveVariables();
  210.             $this->_view->set('variables', $vars);
  211.             $this->_view->set('kliniki', $patient->getClinics());
  212.             $this->_view->set('grupy', $m->getActiveGroups($vars));
  213.             $this->_view->set('title', messages::getTranslation("patient_form_email_title"));
  214.             $this->_view->set('pageTitle', messages::getTranslation("patient_form_email_title"));
  215.             $this->_view->set('user', $user);
  216.             $this->_view->set('action', 'email');
  217.             $this->_view->set('email', $opt);
  218.  
  219.             return $this->_view->output();
  220.         }
  221.         catch(Exception $e)
  222.         {
  223.             echo "Application error:" . $e->getMessage();
  224.         }
  225.     }
  226.  
  227.     public function export_Action($opt)
  228.     {
  229.         try
  230.         {
  231.             $user = MSession::getUser();
  232.  
  233.             // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
  234.             //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
  235.             $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
  236.             $this->_view->set('opt', $opt);
  237.             $this->_view->set('patient_id', $patient_id);
  238.             $m = Model::getInstance('Variables'); //new VariablesModel();
  239.             $patient = Model::getInstance('Patient'); //new PatientModel();
  240.             if($patient_id != 0)
  241.             {
  242.                 $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
  243.                 $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
  244.             }
  245.             else
  246.             {
  247.                 $this->_view->set('dane_osobowe_pacjenta', array());
  248.                 $this->_view->set('dane_pacjenta', array());
  249.             }
  250.             $vars = $m->getPatientFormActiveVariables();
  251.             $this->_view->set('variables', $vars);
  252.             $this->_view->set('kliniki', $patient->getClinics());
  253.             $this->_view->set('grupy', $m->getActiveGroups($vars));
  254.             $this->_view->set('title', messages::getTranslation("patient_form_export_title"));
  255.             $this->_view->set('pageTitle', messages::getTranslation("patient_form_export_title"));
  256.             $this->_view->set('user', $user);
  257.             $this->_view->set('action', 'export');
  258.  
  259.             return $this->_view->output();
  260.         }
  261.         catch(Exception $e)
  262.         {
  263.             echo "Application error:" . $e->getMessage();
  264.         }
  265.     }
  266.  
  267.     public function subscribe_Action($opt)
  268.     {
  269.         try
  270.         {
  271.             $user = MSession::getUser();
  272.  
  273.             // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
  274.             //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
  275.             $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
  276.             $this->_view->set('opt', $opt);
  277.             $this->_view->set('patient_id', $patient_id);
  278.             $this->_view->set('title', messages::getTranslation("patient_form_title"));
  279.             $this->_view->set('pageTitle', messages::getTranslation("patient_form_title"));
  280.             $this->_view->set('user', $user);
  281.             $this->_view->set('action', 'subscribe');
  282.  
  283.             return $this->_view->output();
  284.         }
  285.         catch(Exception $e)
  286.         {
  287.             echo "Application error:" . $e->getMessage();
  288.         }
  289.     }
  290.  
  291.     public function my_tests_Action($opt)
  292.     {
  293.         try
  294.         {
  295.             $user = MSession::getUser();
  296.  
  297.             // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
  298.             //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
  299.             $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
  300.             $this->_view->set('opt', $opt);
  301.             $this->_view->set('patient_id', $patient_id);
  302.             $m = Model::getInstance('Variables'); //new VariablesModel();
  303.             $patient = Model::getInstance('Patient'); //new PatientModel();
  304.             if($patient_id != 0)
  305.             {
  306.                 $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
  307.                 $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
  308.             }
  309.             else
  310.             {
  311.                 $this->_view->set('dane_osobowe_pacjenta', array());
  312.                 $this->_view->set('dane_pacjenta', array());
  313.             }
  314.             $vars = $m->getPatientFormActiveVariables();
  315.             $this->_view->set('variables', $vars);
  316.             $this->_view->set('kliniki', $patient->getClinics());
  317.             $this->_view->set('grupy', $m->getActiveGroups($vars));
  318.             $this->_view->set('title', messages::getTranslation("patient_form_title"));
  319.             $this->_view->set('pageTitle', messages::getTranslation("patient_form_title"));
  320.             $this->_view->set('user', $user);
  321.             $this->_view->set('action', 'my_tests');
  322.  
  323.             return $this->_view->output();
  324.         }
  325.         catch(Exception $e)
  326.         {
  327.             echo "Application error:" . $e->getMessage();
  328.         }
  329.     }
  330.  
  331.  
  332.     public function recos_Action($opt)
  333.     {
  334.         try
  335.         {
  336.             $user = MSession::getUser();
  337.  
  338.             // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
  339.             //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
  340.             $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
  341.             $this->_view->set('opt', $opt);
  342.             $this->_view->set('patient_id', $patient_id);
  343.             $m = Model::getInstance('Variables'); //new VariablesModel();
  344.             $patient = Model::getInstance('Patient'); //new PatientModel();
  345.             if($patient_id != 0)
  346.             {
  347.                 $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
  348.                 $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
  349.             }
  350.             else
  351.             {
  352.                 $this->_view->set('dane_osobowe_pacjenta', array());
  353.                 $this->_view->set('dane_pacjenta', array());
  354.             }
  355.             $vars = $m->getPatientFormActiveVariables();
  356.             $this->_view->set('variables', $vars);
  357.             $this->_view->set('kliniki', $patient->getClinics());
  358.             $this->_view->set('grupy', $m->getActiveGroups($vars));
  359.             $this->_view->set('title', messages::getTranslation("patient_form_title"));
  360.             $this->_view->set('pageTitle', messages::getTranslation("patient_form_title"));
  361.             $this->_view->set('user', $user);
  362.             $this->_view->set('action', 'recos');
  363.  
  364.             return $this->_view->output();
  365.         }
  366.         catch(Exception $e)
  367.         {
  368.             echo "Application error:" . $e->getMessage();
  369.         }
  370.     }
  371.  
  372.  
  373.     public function home_Action($opt)
  374.     {
  375.         try
  376.         {
  377.             $user = MSession::getUser();
  378.  
  379.             // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
  380.             //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
  381.             $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
  382.             $this->_view->set('opt', $opt);
  383.             $this->_view->set('patient_id', $patient_id);
  384.             $m = Model::getInstance('Variables'); //new VariablesModel();
  385.             $patient = Model::getInstance('Patient'); //new PatientModel();
  386.             if($patient_id != 0)
  387.             {
  388.                 $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
  389.                 $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
  390.             }
  391.             else
  392.             {
  393.                 $this->_view->set('dane_osobowe_pacjenta', array());
  394.                 $this->_view->set('dane_pacjenta', array());
  395.             }
  396.             $vars = $m->getPatientFormActiveVariables();
  397.             $this->_view->set('variables', $vars);
  398.             $this->_view->set('kliniki', $patient->getClinics());
  399.             $this->_view->set('grupy', $m->getActiveGroups($vars));
  400.             $this->_view->set('title', messages::getTranslation("patient_form_title"));
  401.             $this->_view->set('pageTitle', messages::getTranslation("patient_form_title"));
  402.             $this->_view->set('user', $user);
  403.             $this->_view->set('action', 'home');
  404.  
  405.             return $this->_view->output();
  406.         }
  407.         catch(Exception $e)
  408.         {
  409.             echo "Application error:" . $e->getMessage();
  410.         }
  411.     }
  412.  
  413.  
  414.     /**
  415.      * Formularz pacjenta (indywidualna prognoza).
  416.      * @return type
  417.      */
  418.     public function test_Action($opt)
  419.     {
  420.         try
  421.         {
  422.             // sprawdzenie subskrypcji dla produktów test i post ivf-test
  423.             $subscriptionDCount = WPHelperFuncs::getSubscriptionDayCount(9);
  424.             $subscriptionDCount2 = WPHelperFuncs::getSubscriptionDayCount(10);
  425.             if ($subscriptionDCount2 > $subscriptionDCount)
  426.                 $subscriptionDCount = $subscriptionDCount2;
  427.  
  428.             if ($subscriptionDCount < 1 && Config::getCfg('usr_allow_without_subscription', false))
  429.                 $subscriptionDCount = 1;
  430.  
  431.             $user = MSession::getUser();
  432.  
  433.             // TODO: parp testy
  434.             if ($user->getUserId() == 43 || $user->getUserId() == 49 || $user->getUserId() == 50 || $user->getUserId() == 51)
  435.             {
  436.                 $subscriptionDCount = 30;
  437.                 $subscriptionDCount2 = 30;
  438.             }
  439.  
  440.             // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
  441.             //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
  442.             $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
  443.             $this->_view->set('subscriptiondc', $subscriptionDCount);
  444.             $this->_view->set('post_ivf', $subscriptionDCount2 > 0);
  445.             $this->_view->set('opt', $opt);
  446.             $this->_view->set('patient_id', $patient_id);
  447.             $m = Model::getInstance('Variables'); //new VariablesModel();
  448.             $patient = Model::getInstance('Patient'); //new PatientModel();
  449.             if($patient_id != 0)
  450.             {
  451.                 $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
  452.                 $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
  453.             }
  454.             else
  455.             {
  456.                 $this->_view->set('dane_osobowe_pacjenta', array());
  457.                 $this->_view->set('dane_pacjenta', array());
  458.             }
  459.             $vars = $m->getPatientFormActiveVariables();
  460.             $this->_view->set('variables', $vars);
  461.             $this->_view->set('kliniki', $patient->getClinics());
  462.             $this->_view->set('grupy', $m->getActiveGroups($vars));
  463.             $this->_view->set('title', messages::getTranslation("patient_form_title"));
  464.             $this->_view->set('pageTitle', messages::getTranslation("patient_form_title"));
  465.             $this->_view->set('user', $user);
  466.             $this->_view->set('action', 'test');
  467.  
  468.             return $this->_view->output();
  469.         }
  470.         catch(Exception $e)
  471.         {
  472.             echo "Application error:" . $e->getMessage();
  473.         }
  474.     }
  475.  
  476.  
  477.     /**
  478.      * Formularz pacjenta (indywidualna prognoza).
  479.      * @return type
  480.      */
  481.     public function index_Action()
  482.     {
  483.         try
  484.         {
  485.             $user = MSession::getUser();
  486.  
  487.             // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
  488.             //$patient_id = $user->getUserId();//isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
  489.             $patient_id = (int) ($user->getAssignedProfileData()['patient_id']);
  490.             $this->_view->set('patient_id', $patient_id);
  491.             $m = Model::getInstance('Variables'); //new VariablesModel();
  492.             $patient = Model::getInstance('Patient'); //new PatientModel();
  493.             if($patient_id != 0)
  494.             {
  495.                 $this->_view->set('dane_osobowe_pacjenta', $patient->getPatient($patient_id));
  496.                 $this->_view->set('dane_pacjenta', $m->getPatientVariables($patient_id));
  497.             }
  498.             else
  499.             {
  500.                 $this->_view->set('dane_osobowe_pacjenta', array());
  501.             }
  502.             $vars = $m->getPatientFormActiveVariables();
  503.             $this->_view->set('variables', $vars);
  504.             $this->_view->set('kliniki', $patient->getClinics());
  505.             $this->_view->set('grupy', $m->getActiveGroups($vars));
  506.             $this->_view->set('title', messages::getTranslation("patient_form_title"));
  507.             $this->_view->set('pageTitle', messages::getTranslation("patient_form_title"));
  508.             $this->_view->set('user', $user);
  509.  
  510.             return $this->_view->output();
  511.         }
  512.         catch(Exception $e)
  513.         {
  514.             echo "Application error:" . $e->getMessage();
  515.         }
  516.     }
  517.  
  518.  
  519.     public function calc_ActionCheckAccess()
  520.     {
  521.         if(!$this->isLoggedIn())
  522.         {
  523.             App::addMessage('login', Message::build()->type('danger')->title('Zaloguj się')->body('By skorzystać z tej funkcji, należy się zalogować'));
  524.             App::redirect(Route::build()->controller('admin')->action('login'));
  525.             return false;
  526.         }
  527.         $user = MSession::getUser();
  528.         return $user->canLoinToForm();
  529.     }
  530.  
  531.  
  532.  
  533.     /**
  534.      * Zapis formularza do bazy, uruchomienie skryptu R i wyświetlenie indywidualnej prognozy
  535.      * @return type
  536.      */
  537.     public function calc_Action($opt)
  538.     {
  539.         $o = array();
  540.         $action = '';
  541.         if(isset($opt) && $opt !== NULL)
  542.         {
  543.             $o = explode(",", $opt);
  544.             $action = $o[0];
  545.         }
  546.         $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>';
  547.         $user = MSession::getUser();
  548.  
  549. //        var_dump($_POST); die;
  550.  
  551.         if(count($_POST) > 0)
  552.         {
  553.             // id pacjenta powinno być przekazywane przez sesję! do testów używam zmiennej przekazywanej przez get
  554.             $patient_id = (int) ($user->getAssignedProfileData()['patient_id']); //isset($_GET['patientid']) ? filter_input(INPUT_GET, "patientid") : -1;
  555.             $this->_view->set('patient_id', $patient_id);
  556.             $db = Db::init();
  557.             $clinic_id = (int) ($_POST['typ_testu'] == 'standard' ? 0 : $_POST['wybor_kliniki']);
  558.             $po_ivf = $_POST['po_inv'] == 'Y';
  559.  
  560.             $birthDate = $_POST['birth_date'];
  561.  
  562.             $birthDate = explode("-", $birthDate);
  563.             $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]));
  564.  
  565.             $current_step = 2;
  566.             $pid = (int) $patient_id;
  567.  
  568.             $v = $_POST['zmienna'];
  569.  
  570. //          $v[1] = (int) $age;
  571.             $v[4] = 1;
  572.             try
  573.             {
  574.                 if($v[2] == 0)
  575.                     $v[2] = 100;
  576.  
  577.                 $v[4] = $v[3] / (($v[2] / 100.0) * ($v[2] / 100.0)); // ustawienie wartości BMI
  578.             }
  579.             catch(Exception $e)
  580.             {
  581.  
  582.             }
  583.             $r = false;
  584.             $varsModel = Model::getInstance('Variables'); //new VariablesModel();
  585.             $varsModel->setPatientId($pid);
  586.             foreach($v as $vId => $val)
  587.             {
  588.                 $v2 = $val;
  589.                 if ($v2 != '')
  590.                     $varsModel->setVariableValue($vId, $v2);
  591.             }
  592.  
  593.             $r = $varsModel->store();
  594.             if($action == 'store')
  595.             {
  596.                 $this->_view->set('store', true);
  597.                 if($r)
  598.                 {
  599.                     $rezultat = '0%';
  600. //                  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.'));
  601. //                  app::addScriptDefinition("setTimeout(function(){window.location='" . Route::build()->controller('admin')->action('index')->opt(['results'])->get() . "';}, 5000);", true);
  602.                 }
  603.             }
  604.             else if($r)
  605.             {
  606.                 /** uruchomienie skryptów R dla zmiennych i nowo dodanego pacjenta */
  607.                 $po = (int) $po_ivf ? 1 : 0;
  608.  
  609.                 // echo "Rscript ../script2.R $pid $po $clinic_id\n\n----";
  610.                 $r = exec("Rscript ./bin/script2.R $pid $po $clinic_id > /dev/null &");
  611.  
  612.                 if ($r != 0)
  613.                     $rezultat = "Błąd: skontaktuj się z administratorem.";
  614.  
  615.                 //exec($cmd, $outArray, $ret)
  616.                 // echo $r;
  617.                 //echo "$r\n\n\n";
  618.  
  619.                 //$znaj = array();
  620.                 //preg_match("(\%(.*?)\%)", $r, $znaj);
  621.  
  622.                 //if(isset($znaj[0]))
  623.                 //  $rezultat = round(trim($znaj[0], "%") * 100, 2) . "%";
  624.  
  625.                 $recos = [];
  626.  
  627.                 $reco = Model::getInstance('Reco');//new RecoModel();
  628.                 $recom = Recommendation::init($reco);
  629.                 $recos = $recom->generate_reco($pid);
  630.                 $cats = $reco->getRecoCategories();
  631.  
  632.                 $this->_view->set('recos', $recos);
  633.                 $this->_view->set('cats', $cats);
  634.  
  635.                 $recom->storeRecommendation($recos);
  636.             }
  637.         }
  638.         try
  639.         {
  640. //              $this->_view->set('display_prognosis', false);
  641.             $this->_view->set('session_check', false);
  642.             $this->_view->set('title', messages::getTranslation("patient_form_title_result"));
  643.             $this->_view->set('rezultat', $rezultat);
  644.             $this->_view->set('user', $user);
  645.             $this->_view->set('action', 'calc');
  646.             return $this->_view->output();
  647.         }
  648.         catch(Exception $e)
  649.         {
  650.             echo "Application error:" . $e->getMessage();
  651.         }
  652.     }
  653. }
  654.  
Add Comment
Please, Sign In to add comment