Advertisement
Guest User

Untitled

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