Advertisement
Guest User

Untitled

a guest
Jun 8th, 2023
70
0
29 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 24.44 KB | None | 0 0
  1. <?php
  2.  
  3. class Core {
  4.     /* */
  5.  
  6.     private static $config_file = "conf.ini";
  7.  
  8.     /* */
  9.     //var $db_conf;
  10.  
  11.     private static $link = null;
  12.    
  13.     /**
  14.      *
  15.      * @param type $file
  16.      */
  17.     public static function getDBConfig() {
  18.         $conf = parse_ini_file(Core::$config_file);
  19.         return $conf;
  20.         //die(var_dump($conf) );
  21.         //exit;
  22.         //$db_conf = array();
  23.         //$this->db_conf = $conf;
  24.     }
  25.  
  26.     public static function connectDB() {
  27.         $conf = Core::getDBConfig();
  28.         //$link = mysql_connect($conf["host"], $conf["user"], $conf["password"]) or die("Could not connect: " . mysql_error());
  29. /*$link = mysql_connect (MYSQL_HOST,
  30.                            MYSQL_BENUTZER,
  31.                            MYSQL_KENNWORT,
  32.                            MYSQL_DATENBANK);*/
  33.         //Core::$link = new mysqli(MYSQL_HOST, MYSQL_BENUTZER, MYSQL_KENNWORT, MYSQL_DATENBANK);
  34.         Core::$link = new mysqli($conf["host"], $conf["user"], $conf["password"], $conf["name"]);
  35.         //mysql_set_charset('utf8', $link);
  36.         /* check connection */
  37.         if (mysqli_connect_errno()) {
  38.             printf("Connect failed: %s\n", mysqli_connect_error());
  39.             exit();
  40.         }
  41.         if (!Core::$link->set_charset("utf8")) {
  42.             printf("Error loading character set utf8: %s\n", Core::$link->error);
  43.         } else {
  44.             //printf("Current character set: %s\n", Core::$link->character_set_name());
  45.         }
  46.        
  47.         // select our database
  48.        
  49.         // select our database
  50.         //mysql_select_db(MYSQL_DATENBANK) or die(mysql_error());
  51.         Core::$link->select_db($conf["name"]);
  52.     }
  53.  
  54.     public static function closeDB() {
  55.         //mysql_close();
  56.         Core::$link->close();
  57.     }
  58.  
  59.     /**
  60.      * Adds a patient into db-table 'patients'.
  61.      * @param array $patient [surname, prename, birthday, telephone, description]
  62.      */
  63.     public static function addStaff(array $staff) {
  64.         $sql = "INSERT INTO staff (surname, prename, birthday, telephone, description_text) " .
  65.                 " VALUES ('" . $staff['surname'] . "', '" . $staff['prename'] . "', '" . $staff['birthday'] . "', '" . $staff['telephone'] . "', '" . $staff['description_text'] . "')";
  66.         //echo $sql;
  67.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  68.         $result = Core::$link->query($sql);
  69.  
  70.         if (!$result) {
  71.             return 'Error: ' . mysqli_error(Core::$link);
  72.         }
  73.         //while ($myrow = mysql_fetch_array($result)) {
  74.         //}
  75.         //mysql_free_result($result);
  76.         //$result->close();
  77.         return true;
  78.     }
  79.  
  80.     /**
  81.      * Adds a patient into db-table 'patients'.
  82.      * @param array $patient [surname, prename, birthday, telephone, description]
  83.      */
  84.     public static function addPatient(array $patient) {
  85.         $sql = "INSERT INTO patients (surname, prename, birthday, telephone, description_text, town, zipcode, street) " .
  86.                 " VALUES ('" . $patient['surname'] . "', '" . $patient['prename'] . "', '" . $patient['birthday'] . "', '" . $patient['telephone'] . "', '" . $patient['description_text'] . "', '" . $patient['town'] . "', '" . $patient['zipcode'] . "' ,'" . $patient['street'] . "')";
  87.         //echo $sql;
  88.         //r$esult = mysql_query($sql) or die("Invalid query: " . mysql_error());
  89.         $result = Core::$link->query($sql);
  90.  
  91.         if (!$result) {
  92.             return 'Error: ' . mysqli_error(Core::$link);
  93.         }
  94.         //while ($myrow = mysql_fetch_array($result)) {
  95.         //}
  96.         //mysql_free_result($result);
  97.         //$result->close();
  98.         return true;
  99.     }
  100.  
  101.     /**
  102.      * Deletes a patient from database.
  103.      * Caution: No valid-checking.
  104.      *
  105.      * @param type $id_patient
  106.      */
  107.     public static function removePatient($id_patient) {
  108.         $sql = "DELETE FROM patients WHERE id_patient=" . $id_patient;
  109.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  110.         $result = Core::$link->query($sql);
  111.  
  112.         if (!$result) {
  113.             return 'Error: ' . mysqli_error(Core::$link);
  114.         }
  115.         //mysql_free_result($result);
  116.         //$result->close();
  117.         return true;
  118.     }
  119.  
  120.     /**
  121.      * Deletes a staff from database.
  122.      * Caution: No valid-checking.
  123.      *
  124.      * @param type $id_patient
  125.      */
  126.     public static function removeStaff($id_staff) {
  127.         $sql = "DELETE FROM staff WHERE id_staff = " . intval($id_staff). ";";
  128.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  129.         $result = Core::$link->query($sql);
  130.  
  131.         if (!$result) {
  132.             return 'Error: ' . mysqli_error(Core::$link);
  133.         }
  134.         //mysql_free_result($result);
  135.         //$result->close();
  136.         //echo "staff: ".$id_staff;
  137.         return true;
  138.     }
  139.  
  140.    
  141.     public static function removeStaffWorkingTime($id_staff_workingtime) {
  142.         $sql = "DELETE FROM staff_workingtimes WHERE id_staff_workingtime=" . $id_staff_workingtime;
  143.         //echo $sql;
  144.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  145.         $result = Core::$link->query($sql);
  146.  
  147.         if (!$result) {
  148.             return 'Error: ' . mysqli_error(Core::$link);
  149.         }
  150.         //mysql_free_result($result);
  151.         //$result->close();
  152.         //echo "staff: ".$id_staff;
  153.         return true;
  154.     }
  155.    
  156.     /**
  157.      * Updates a patient from database.
  158.      * Caution: No valid-checking.
  159.      *
  160.      * @param array $patient
  161.      */
  162.     public static function updatePatient(array $patient) {
  163.         $update_fields = "";
  164.         //if(isset($patient['surname']) && $pat
  165.        
  166.         $sql = "UPDATE patients SET " .
  167.                 "surname='" . $patient['surname'] . "', " .
  168.                 "prename='" . $patient['prename'] . "', " .
  169.                 "birthday='" . $patient['birthday'] . "', " .
  170.                 "telephone='" . $patient['telephone'] . "', " .
  171.                 "description_text='" . $patient['description_text'] . "', " .
  172.                 "town='" . $patient['town'] . "', " .
  173.                 "zipcode='" . $patient['zipcode'] . "', " .
  174.                 "street='" . $patient['street'] . "' " .
  175.                 "WHERE id_patient=" . $patient['id_patient'];
  176.         //echo $sql;
  177.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  178.         $result = Core::$link->query($sql);
  179.  
  180.         if (!$result) {
  181.             return 'Error: ' . mysqli_error(Core::$link);
  182.         }
  183.         //mysql_free_result($result);
  184.         return true;
  185.     }
  186.  
  187.    
  188.     /**
  189.      * Updates a staff from database.
  190.      * Caution: No valid-checking.
  191.      *
  192.      * @param array $patient
  193.      */
  194.     public static function updateStaff(array $staff) {
  195.         $update_fields = "";
  196.         //if(isset($patient['surname']) && $pat
  197.        
  198.         $sql = "UPDATE staff SET " .
  199.                 "surname='" . $staff['surname'] . "', " .
  200.                 "prename='" . $staff['prename'] . "', " .
  201.                 "birthday='" . $staff['birthday'] . "', " .
  202.                 "telephone='" . $staff['telephone'] . "', " .
  203.                 "description_text='" . $staff['description_text'] . "', " .
  204.                 "is_present='".$staff['active']. "' ".
  205.                 "WHERE id_staff=" . $staff['id_staff'];
  206.         //echo $sql;
  207.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  208.         $result = Core::$link->query($sql);
  209.  
  210.         if (!$result) {
  211.             return 'Error: ' . mysqli_error(Core::$link);
  212.         }
  213.         //mysql_free_result($result);
  214.         return true;
  215.     }
  216.    
  217.     public static function updateStaffActiveCheck($id_staff, $checked){
  218.        
  219.         $sql = "UPDATE staff SET ".
  220.                 "is_present='".$checked."' ".
  221.                 "WHERE id_staff=".$id_staff;
  222.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  223.         $result = Core::$link->query($sql);
  224.  
  225.         if (!$result) {
  226.             return 'Error: ' . mysqli_error(Core::$link);
  227.         }
  228.         //mysql_free_result($result);
  229.         return true;
  230.     }
  231.    
  232.     public static function updatePatientTreatmentCheck($id_patient_treatment, $checked){
  233.         $sql = "UPDATE patients_treatments SET ".
  234.                 "is_present='".$checked."' ".
  235.                 "WHERE id_patient_treatment=".$id_patient_treatment;
  236.         //echo $sql;
  237.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  238.         $result = Core::$link->query($sql);
  239.  
  240.         if (!$result) {
  241.             return 'Error: ' . mysqli_error(Core::$link);
  242.         }
  243.         //mysql_free_result($result);
  244.         return true;
  245.     }
  246.  
  247.     public static function getStaffList($session){
  248.     var_dump($session);
  249.     var_dump($_SESSION);
  250.  
  251.           if ($session['name'] =="admin" || $session['name'] =="Piet") {
  252.                 $sql = "SELECT * FROM staff";
  253.           }
  254.           else {
  255.                 $sql = "SELECT * FROM staff where surname = '".$session['name']."'";
  256.           }
  257.  
  258.         $result = Core::$link->query($sql);
  259.  
  260.         if (!$result) {
  261.             return 'Error: ' . mysqli_error(Core::$link);
  262.         }
  263.  
  264.         $return = array();
  265.         while ($myrow = mysqli_fetch_assoc($result)) {
  266.             if ($myrow['birthday'] !== '0000-00-00') {
  267.                 $myrow['birthday'] = date("d.m.Y", strtotime($myrow['birthday']));
  268.             } else {
  269.                 $myrow['birthday'] = '';
  270.             }
  271.             $return[] = $myrow;
  272.         }
  273.  
  274.         return $return;
  275.     }
  276.    
  277.     public static function getStaff($id_staff) {
  278.         $sql = "SELECT * FROM staff WHERE id_staff=" . $id_staff;
  279.         //$result = mysql_query($sql);
  280.         $result = Core::$link->query($sql);
  281.  
  282.         if (!$result) {
  283.             return 'Error: ' . mysqli_error(Core::$link);
  284.         }
  285.         $return = mysqli_fetch_assoc($result);
  286.         if ($return['birthday'] !== '0000-00-00') {
  287.             $return['birthday'] = date("d.m.Y", strtotime($return['birthday']));
  288.         } else {
  289.             $return['birthday'] = '';
  290.         }
  291.         //mysql_free_result($result);
  292.         //$result->close();
  293.         return $return;
  294.     }
  295.    
  296.    
  297.     public static function getPatients() {
  298. //        $patient = array();
  299. //        $patient['id_patient'] = 64;
  300. //        $patient['surname'] = 'testiwow';
  301. //        $patient['prename'] = 'warum denn nur';
  302. //        updatePatientAction($patient);
  303. //        echo "warum test";
  304.         $sql = "SELECT * FROM patients ORDER BY surname ASC";
  305.         //$result = mysql_query($sql);
  306.  
  307.         $result = Core::$link->query($sql);
  308.  
  309.         if (!$result) {
  310.             return 'Error: ' . mysqli_error(Core::$link);
  311.         }
  312.        
  313.         $return = array();
  314.         while ($myrow = mysqli_fetch_assoc($result)) {
  315.             if ($myrow['birthday'] !== '0000-00-00') {
  316.                 $myrow['birthday'] = date("d.m.Y", strtotime($myrow['birthday']));
  317.             } else {
  318.                 $myrow['birthday'] = '';
  319.             }
  320.             $return[] = $myrow;
  321.         }
  322.  
  323.         //mysql_free_result($result);
  324.         //$result->close();
  325.         return $return;
  326.     }
  327.  
  328.     public static function getTreatmentDate($date, $id_staff = null){
  329.         //$date = "2014-03-19";
  330.         //echo $date;
  331.         //$sql = "SELECT * FROM patients_treatments WHERE date(treatment_date)='". $date. "' ORDER BY treatment_date ASC";
  332.        
  333.         // original
  334.         if(isset($id_staff)){
  335.             $sql = "SELECT pt.*, p.surname, p.prename, t.shortcut, t.color, t.is_multiple_patients FROM patients_treatments pt LEFT JOIN patients p ON pt.id_patient=p.id_patient LEFT JOIN treatments t ON pt.id_treatment=t.id_treatment WHERE date(pt.treatment_date)='". $date. "' AND pt.id_staff=".$id_staff." ORDER BY treatment_date DESC";
  336.         }
  337.         else{
  338.             $sql = "SELECT pt.*, p.surname, p.prename, t.shortcut, t.color, t.is_multiple_patients FROM patients_treatments pt LEFT JOIN patients p ON pt.id_patient=p.id_patient LEFT JOIN treatments t ON pt.id_treatment=t.id_treatment WHERE date(pt.treatment_date)='". $date. "' ORDER BY treatment_date DESC";
  339.         }
  340.        
  341.         //echo $sql;
  342.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());;
  343.         $result = Core::$link->query($sql);
  344.  
  345.         if (!$result) {
  346.             return 'Error: ' . mysqli_error(Core::$link);
  347.         }
  348.        
  349.         $return = array();
  350.         while($myrow = mysqli_fetch_assoc($result)){
  351.             //echo $myrow['id_patient_treatment']."\n";
  352.             //$myrow['treatment_date'] = date
  353.             $myrow['treatment_date'] = date("d.m.Y H:i", strtotime($myrow['treatment_date']));
  354.             $myrow['treatment_time_end'] = date("H:i", strtotime($myrow['treatment_time_end']));
  355.             $return[] = $myrow;
  356.         }
  357.        
  358.          //mysql_free_result($result);
  359.          //$result->close();
  360.          //echo var_dump($return);
  361.          return $return;
  362.     }
  363.    
  364.     public static function getTreatmentDates($id_patient){
  365.         $sql = "SELECT * FROM patients_treatments WHERE id_patient=". $id_patient. " ORDER BY treatment_date DESC";
  366.         //$result = mysql_query($sql);
  367.        
  368.         $result = Core::$link->query($sql);
  369.  
  370.         if (!$result) {
  371.             return 'Error: ' . mysqli_error(Core::$link);
  372.         }
  373.        
  374.         $return = array();
  375.         while($myrow = mysqli_fetch_assoc($result)){
  376.             //$myrow['treatment_date'] = date
  377.             $myrow['treatment_date'] = date("d.m.Y H:i", strtotime($myrow['treatment_date']));
  378.             $myrow['treatment_time_end'] = date("H:i", strtotime($myrow['treatment_time_end']));
  379.             $return[] = $myrow;
  380.         }
  381.        
  382.          //mysql_free_result($result);
  383.          //$result->close();
  384.          return $return;  
  385.     }
  386.    
  387.     public static function getTreatmentDatesByStaff($id_staff){
  388.         $sql = "SELECT * FROM patients_treatments WHERE id_staff=". $id_staff. " ORDER BY treatment_date ASC";
  389.         //$result = mysql_query($sql);
  390.        
  391.         $result = Core::$link->query($sql);
  392.  
  393.         if (!$result) {
  394.             return 'Error: ' . mysqli_error(Core::$link);
  395.         }
  396.        
  397.         $return = array();
  398.         while($myrow = mysqli_fetch_assoc($result)){
  399.             //$myrow['treatment_date'] = date
  400.             $myrow['treatment_date'] = date("d.m.Y H:i", strtotime($myrow['treatment_date']));
  401.             $myrow['treatment_time_end'] = date("H:i", strtotime($myrow['treatment_time_end']));
  402.             $return[] = $myrow;
  403.         }
  404.        
  405.          //mysql_free_result($result);
  406.          //$result->close();
  407.          return $return;  
  408.     }
  409.    
  410.     public static function getPatientTreatment($id_patient_treatment){
  411.         $sql = "SELECT * FROM patients_treatments WHERE id_patient_treatment=". $id_patient_treatment. " ORDER BY treatment_date ASC";
  412.         //$result = mysql_query($sql);
  413.         $result = Core::$link->query($sql);
  414.  
  415.         if (!$result) {
  416.             return 'Error: ' . mysqli_error(Core::$link);
  417.         }
  418.         $return = mysqli_fetch_assoc($result);
  419.             //$myrow['treatment_date'] = date
  420.             $return['treatment_date'] = date("d.m.Y H:i", strtotime($return['treatment_date']));
  421.             $return['treatment_time_end'] = date("H:i", strtotime($return['treatment_time_end']));
  422.             //$return[] = $myrow;
  423.        
  424.        
  425.          //mysql_free_result($result);
  426.          //$result->close();
  427.          return $return;  
  428.     }
  429.    
  430.     public static function getWorkingTimes($id_staff, $date){
  431.         $sql = "";
  432.         if(isset($id_staff)){
  433.             $sql = "SELECT * FROM staff_workingtimes WHERE id_staff=".$id_staff;
  434.             if(isset($date) && $date !== ""){
  435.                 //$sql .= " AND date(beginning_time) >='".$date."' AND date(end_time) <='".$date."'";
  436.                 $sql .= " AND date(beginning_time) <='".$date."' AND date(end_time) >='".$date."'";
  437.             }
  438.         }
  439.         else{
  440.             $sql = "SELECT * FROM staff_workingtimes";
  441.             if(isset($date) && $date !== ""){
  442.                 $sql .= " WHERE date(beginning_time) <='".$date."' AND date(end_time) >='".$date."'";
  443.             }
  444.         }
  445.         //return $sql;
  446.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  447.         $result = Core::$link->query($sql);
  448.  
  449.         if (!$result) {
  450.             return 'Error: ' . mysqli_error(Core::$link);
  451.         }
  452.         $return = array();
  453.         while($myrow = mysqli_fetch_assoc($result)){
  454.             //echo $myrow['id_staff'];
  455.             //echo $myrow['id_patient_treatment']."\n";
  456.             //$myrow['treatment_date'] = date
  457.             $myrow['beginning_time'] = date("d.m.Y H:i", strtotime($myrow['beginning_time']));
  458.             $myrow['end_time'] = date("d.m.Y H:i", strtotime($myrow['end_time']));
  459.             $return[] = $myrow;
  460.         }
  461.        
  462.         //mysql_free_result($result);
  463.         //$result->close();
  464.         return $return;
  465.     }
  466.    
  467.     public static function getPatient($id_patient) {
  468.         $sql = "SELECT * FROM patients WHERE id_patient=" . $id_patient;
  469.         //$result = mysql_query($sql);
  470.         $result = Core::$link->query($sql);
  471.  
  472.         if (!$result) {
  473.             return 'Error: ' . mysqli_error(Core::$link);
  474.         }
  475.         $return = mysqli_fetch_assoc($result);
  476.         if ($return['birthday'] !== '0000-00-00') {
  477.             $return['birthday'] = date("d.m.Y", strtotime($return['birthday']));
  478.         } else {
  479.             $return['birthday'] = '';
  480.         }
  481.         //mysql_free_result($result);
  482.         //$result->close();
  483.         return $return;
  484.     }
  485.  
  486.     public static function checkOverlappingTreatmentDates($id_staff, $treatment_date, $treatment_time_end){
  487.         // (t1 < t1_a && t1_a < t2) || (t1 < t2_a && t2_a < t2)
  488.         //SELECT * FROM patients_treatments WHERE id_staff=1 AND treatment_date LIKE '%2014-03-20%' AND ((treatment_date <= '2014-03-20 11:05' AND '11:05' < treatment_time_end) OR (treatment_date < '2014-03-20 11:25' AND '11:25' <= treatment_time_end));
  489.         $tdate = explode(' ', $treatment_date);
  490.         //$sql = "SELECT COUNT(id_patient_treatment) FROM patients_treatments WHERE id_staff=".$id_staff." AND (treatment_date >= '".$treatment_date."' AND treatment_time_end='".$tdate[1]."') OR (treatment_date ";
  491.         $sql = "SELECT COUNT(id_patient_treatment) FROM patients_treatments WHERE id_staff=".$id_staff." AND treatment_date LIKE '%".$tdate[0]."%' AND ((treatment_date <= '".$treatment_date."' AND '".$tdate[1]."' < treatment_time_end) OR (treatment_date < '".$tdate[0]." ".$treatment_time_end."' AND '".$treatment_time_end."' <= treatment_time_end) OR ('".$treatment_date."' <= treatment_date AND treatment_time_end <= '".$treatment_time_end."'))";
  492.         //echo $sql;
  493.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  494.         $result = Core::$link->query($sql);
  495.  
  496.         if (!$result) {
  497.             return 'Error: ' . mysqli_error(Core::$link);
  498.         }
  499.         $row = mysqli_fetch_assoc($result);
  500.         //mysql_free_result($result);
  501.         //$result->close();
  502.         if($row['COUNT(id_patient_treatment)']){
  503.             return false;
  504.         }
  505.         return true;
  506.     }
  507.    
  508.     public static function isHitExactlyTreatmentDate($id_staff, $treatment_date, $treatment_time_end){
  509.         $tdate = explode(' ', $treatment_date);
  510.        
  511.         //$sql = "SELECT COUNT(pt.id_patient_treatment) FROM patients_treatments pt LEFT JOIN treatments t ON pt.id_treatment=t.id_treatment WHERE pt.id_staff=".$id_staff." AND t.is_multiple_patients='true' AND pt.treatment_date LIKE '%".$tdate[0]."%' AND ((treatment_date = '".$treatment_date."' AND '".$tdate[1]."' = treatment_time_end) OR (treatment_date = '".$tdate[0]." ".$treatment_time_end."' AND '".$treatment_time_end."' = treatment_time_end) OR ('".$treatment_date."' = treatment_date AND treatment_time_end = '".$treatment_time_end."'))";
  512.         $sql = "SELECT COUNT(pt.id_patient_treatment) FROM patients_treatments pt LEFT JOIN treatments t ON pt.id_treatment=t.id_treatment WHERE pt.id_staff=".$id_staff." AND t.is_multiple_patients='true' AND pt.treatment_date = '".$tdate[0]." ".$tdate[1]."' AND pt.treatment_time_end='".$treatment_time_end."'";
  513.         //return $sql;
  514.         $result = Core::$link->query($sql);
  515.  
  516.         if (!$result) {
  517.             return 'Error: ' . mysqli_error(Core::$link);
  518.         }
  519.         $row = mysqli_fetch_assoc($result);
  520.         //mysql_free_result($result);
  521.         //$result->close();
  522.         //return $row['COUNT(pt.id_patient_treatment)'];
  523.         if($row['COUNT(pt.id_patient_treatment)']){
  524.             return true;
  525.         }
  526.         return false;
  527.     }
  528.    
  529.    
  530.     public static function isOnHoliday($id_staff, $treatment_date, $treatment_time_end){
  531.         $tdate = explode(' ', $treatment_date);
  532.        
  533.         $sql = "SELECT COUNT(id_staff_workingtime) FROM staff_workingtimes WHERE id_staff=".$id_staff." AND matter='HOLIDAY' AND date(beginning_time)<='".$tdate[0]."' AND date(end_time)>='".$tdate[0]."'";
  534.  
  535.         $result = Core::$link->query($sql);
  536.  
  537.         if (!$result) {
  538.             return 'Error: ' . mysqli_error(Core::$link);
  539.         }
  540.         $row = mysqli_fetch_assoc($result);
  541.         //return $sql;
  542.         //mysql_free_result($result);
  543.         //$result->close();
  544.         if($row['COUNT(id_staff_workingtime)']){
  545.             return true;
  546.         }
  547.        
  548.         return false;
  549.                
  550.     }
  551.     public static function insertTreatmentDate($id_patient, $id_staff, $id_treatment, $treatment_date, $treatment_time_end, $description) {
  552.         $sql = "INSERT INTO patients_treatments (id_patient, id_staff, id_treatment, treatment_date, treatment_time_end, description) " .
  553.                 "VALUES ('" . $id_patient . "', '" . $id_staff . "', '" . $id_treatment . "', '" . $treatment_date . "', '" . $treatment_time_end . "', '". $description."')";
  554.         //echo $sql;
  555.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  556.        
  557.         $result = Core::$link->query($sql);
  558.  
  559.         if (!$result) {
  560.             return 'Error: ' . mysqli_error(Core::$link);
  561.         }
  562.        
  563.         //mysql_free_result($result);
  564.         //$result->close();
  565.         return true;
  566.     }
  567.  
  568.     public static function insertWorkingTime($id_staff, $beginning_time, $end_time, $matter){
  569.         $sql = "INSERT INTO staff_workingtimes (id_staff, beginning_time, end_time, matter) ".
  570.                 "VALUES ('".$id_staff."', '". $beginning_time. "', '".$end_time."', '".$matter."')";
  571.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  572.         $result = Core::$link->query($sql);
  573.  
  574.         if (!$result) {
  575.             return 'Error: ' . mysqli_error(Core::$link);
  576.         }
  577.         //mysql_free_result($result);
  578.         //$result->close();
  579.         return true;
  580.     }
  581.    
  582.     public static function removeTreatmentDate($id_patient_treatment) {
  583.         $sql = "DELETE FROM patients_treatments WHERE id_patient_treatment=" . $id_patient_treatment;
  584.         //echo $sql;
  585.         //$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
  586.         $result = Core::$link->query($sql);
  587.  
  588.         if (!$result) {
  589.             return 'Error: ' . mysqli_error(Core::$link);
  590.         }
  591.         //mysql_free_result($result);
  592.         //$result->close();
  593.     }
  594.    
  595.     public static function getTreatments(){
  596.         $sql = "SELECT * FROM treatments";
  597.         //$result = mysql_query($sql);
  598.         $result = Core::$link->query($sql);
  599.  
  600.         if (!$result) {
  601.             return 'Error: ' . mysqli_error(Core::$link);
  602.         }
  603.         $return = array();
  604.         while($myrow = mysqli_fetch_assoc($result)){
  605.             //$myrow['treatment_time_end'] = "what";//date("H:i", strtotime($myrow['treatment_time_end'])). "what";
  606.             $return[] = $myrow;
  607.         }
  608.        
  609.         //mysql_free_result($result);
  610.         //$result->close();
  611.         return $return;
  612.     }
  613.  
  614.     public static function getTreatment($id_treatment) {
  615.         $sql = "SELECT * FROM treatments WHERE id_treatment=" . $id_treatment;
  616.         //$result = mysql_query($sql);
  617.         //echo $sql;
  618.         $result = Core::$link->query($sql);
  619.  
  620. //        if (!$result) {
  621. //            return 'Error: ' . mysqli_error(Core::$link);
  622. //        }
  623.         $return = mysqli_fetch_assoc($result);
  624.         //mysql_free_result($result);
  625.         //$result->close();
  626.         return $return;
  627.     }
  628. }
  629.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement