Code Duplication    Length = 15-16 lines in 10 locations

require/class.Stats.php 10 locations

@@ 642-656 (lines=15) @@
639
                return $all[0]['total'];
640
        }
641
642
	public function addStat($type,$cnt,$stats_date) {
643
		global $globalDBdriver;
644
		if ($globalDBdriver == 'mysql') {
645
			$query = "INSERT INTO stats (stats_type,cnt,stats_date) VALUES (:type,:cnt,:stats_date) ON DUPLICATE KEY UPDATE cnt = :cnt";
646
                } else {
647
			$query = "UPDATE stats SET cnt = :cnt WHERE stats_type = :type AND stats_date = :stats_date; INSERT INTO stats (stats_type,cnt,stats_date) SELECT :type,:cnt,:stats_date WHERE NOT EXISTS (SELECT 1 FROM stats WHERE  stats_type = :type AND stats_date = :stats_date);"; 
648
		}
649
                $query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date);
650
                 try {
651
                        $sth = $this->db->prepare($query);
652
                        $sth->execute($query_values);
653
                } catch(PDOException $e) {
654
                        return "error : ".$e->getMessage();
655
                }
656
        }
657
	public function updateStat($type,$cnt,$stats_date) {
658
		global $globalDBdriver;
659
		if ($globalDBdriver == 'mysql') {
@@ 657-672 (lines=16) @@
654
                        return "error : ".$e->getMessage();
655
                }
656
        }
657
	public function updateStat($type,$cnt,$stats_date) {
658
		global $globalDBdriver;
659
		if ($globalDBdriver == 'mysql') {
660
			$query = "INSERT INTO stats (stats_type,cnt,stats_date) VALUES (:type,:cnt,:stats_date) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date";
661
		} else {
662
            		//$query = "INSERT INTO stats (stats_type,cnt,stats_date) VALUES (:type,:cnt,:stats_date) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date";
663
			$query = "UPDATE stats SET cnt = cnt+:cnt WHERE stats_type = :type AND stats_date = :stats_date; INSERT INTO stats (stats_type,cnt,stats_date) SELECT :type,:cnt,:stats_date WHERE NOT EXISTS (SELECT 1 FROM stats WHERE  stats_type = :type AND stats_date = :stats_date);"; 
664
                }
665
                $query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date);
666
                 try {
667
                        $sth = $this->db->prepare($query);
668
                        $sth->execute($query_values);
669
                } catch(PDOException $e) {
670
                        return "error : ".$e->getMessage();
671
                }
672
        }
673
	public function getStatsSource($date,$stats_type = '') {
674
		if ($stats_type == '') {
675
			$query = "SELECT * FROM stats_source WHERE stats_date = :date ORDER BY source_name";
@@ 691-705 (lines=15) @@
688
                return $all;
689
        }
690
691
	public function addStatSource($data,$source_name,$stats_type,$date) {
692
		global $globalDBdriver;
693
		if ($globalDBdriver == 'mysql') {
694
			$query = "INSERT INTO stats_source (source_data,source_name,stats_type,stats_date) VALUES (:data,:source_name,:stats_type,:stats_date) ON DUPLICATE KEY UPDATE source_data = :data";
695
		} else {
696
			$query = "UPDATE stats_source SET source_data = :data WHERE stats_date = :stats_date AND source_name = :source_name AND stats_type = :stats_type; INSERT INTO stats_source (source_data,source_name,stats_type,stats_date) SELECT :data,:source_name,:stats_type,:stats_date WHERE NOT EXISTS (SELECT 1 FROM stats_source WHERE stats_date = :stats_date AND source_name = :source_name AND stats_type = :stats_type);"; 
697
                }
698
                $query_values = array(':data' => $data,':stats_date' => $date,':source_name' => $source_name,':stats_type' => $stats_type);
699
                 try {
700
                        $sth = $this->db->prepare($query);
701
                        $sth->execute($query_values);
702
                } catch(PDOException $e) {
703
                        return "error : ".$e->getMessage();
704
                }
705
        }
706
	public function addStatFlight($type,$date_name,$cnt) {
707
                $query = "INSERT INTO stats_flight (stats_type,flight_date,cnt) VALUES (:type,:flight_date,:cnt)";
708
                $query_values = array(':type' => $type,':flight_date' => $date_name,':cnt' => $cnt);
@@ 716-730 (lines=15) @@
713
                        return "error : ".$e->getMessage();
714
                }
715
        }
716
	public function addStatAircraftRegistration($registration,$cnt,$aircraft_icao = '') {
717
		global $globalDBdriver;
718
		if ($globalDBdriver == 'mysql') {
719
			$query = "INSERT INTO stats_registration (aircraft_icao,registration,cnt) VALUES (:aircraft_icao,:registration,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt";
720
		} else {
721
			$query = "UPDATE stats_registration SET cnt = cnt+:cnt WHERE registration = :registration; INSERT INTO stats_registration (aircraft_icao,registration,cnt) SELECT :aircraft_icao,:registration,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_registration WHERE registration = :registration);"; 
722
		}
723
                $query_values = array(':aircraft_icao' => $aircraft_icao,':registration' => $registration,':cnt' => $cnt);
724
                 try {
725
                        $sth = $this->db->prepare($query);
726
                        $sth->execute($query_values);
727
                } catch(PDOException $e) {
728
                        return "error : ".$e->getMessage();
729
                }
730
        }
731
	public function addStatCallsign($callsign_icao,$cnt,$airline_icao = '') {
732
		global $globalDBdriver;
733
		if ($globalDBdriver == 'mysql') {
@@ 731-745 (lines=15) @@
728
                        return "error : ".$e->getMessage();
729
                }
730
        }
731
	public function addStatCallsign($callsign_icao,$cnt,$airline_icao = '') {
732
		global $globalDBdriver;
733
		if ($globalDBdriver == 'mysql') {
734
			$query = "INSERT INTO stats_callsign (callsign_icao,airline_icao,cnt) VALUES (:callsign_icao,:airline_icao,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt";
735
		} else {
736
			$query = "UPDATE stats_callsign SET cnt = cnt+:cnt WHERE callsign_icao = :callsign_icao; INSERT INTO stats_callsign (callsign_icao,airline_icao,cnt) SELECT :callsign_icao,:airline_icao,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_callsign WHERE callsign_icao = :callsign_icao);"; 
737
		}
738
                $query_values = array(':callsign_icao' => $callsign_icao,':airline_icao' => $airline_icao,':cnt' => $cnt);
739
                 try {
740
                        $sth = $this->db->prepare($query);
741
                        $sth->execute($query_values);
742
                } catch(PDOException $e) {
743
                        return "error : ".$e->getMessage();
744
                }
745
        }
746
	public function addStatCountry($iso2,$iso3,$name,$cnt) {
747
		global $globalDBdriver;
748
		if ($globalDBdriver == 'mysql') {
@@ 746-760 (lines=15) @@
743
                        return "error : ".$e->getMessage();
744
                }
745
        }
746
	public function addStatCountry($iso2,$iso3,$name,$cnt) {
747
		global $globalDBdriver;
748
		if ($globalDBdriver == 'mysql') {
749
			$query = "INSERT INTO stats_country (iso2,iso3,name,cnt) VALUES (:iso2,:iso3,:name,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt";
750
		} else {
751
			$query = "UPDATE stats_country SET cnt = cnt+:cnt WHERE iso2 = :iso2; INSERT INTO stats_country (iso2,iso3,name,cnt) SELECT :iso2,:iso3,:name,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_country WHERE iso2 = :iso2);"; 
752
		}
753
                $query_values = array(':iso2' => $iso2,':iso3' => $iso3,':name' => $name,':cnt' => $cnt);
754
                 try {
755
                        $sth = $this->db->prepare($query);
756
                        $sth->execute($query_values);
757
                } catch(PDOException $e) {
758
                        return "error : ".$e->getMessage();
759
                }
760
        }
761
	public function addStatAircraft($aircraft_icao,$cnt,$aircraft_name = '') {
762
		global $globalDBdriver;
763
		if ($globalDBdriver == 'mysql') {
@@ 761-775 (lines=15) @@
758
                        return "error : ".$e->getMessage();
759
                }
760
        }
761
	public function addStatAircraft($aircraft_icao,$cnt,$aircraft_name = '') {
762
		global $globalDBdriver;
763
		if ($globalDBdriver == 'mysql') {
764
			$query = "INSERT INTO stats_aircraft (aircraft_icao,aircraft_name,cnt) VALUES (:aircraft_icao,:aircraft_name,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt";
765
		} else {
766
			$query = "UPDATE stats_aircraft SET cnt = cnt+:cnt WHERE aircraft_icao = :aircraft_icao; INSERT INTO stats_aircraft (aircraft_icao,aircraft_name,cnt) SELECT :aircraft_icao,:aircraft_name,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_aircraft WHERE aircraft_icao = :aircraft_icao);"; 
767
		}
768
                $query_values = array(':aircraft_icao' => $aircraft_icao,':aircraft_name' => $aircraft_name,':cnt' => $cnt);
769
                 try {
770
                        $sth = $this->db->prepare($query);
771
                        $sth->execute($query_values);
772
                } catch(PDOException $e) {
773
                        return "error : ".$e->getMessage();
774
                }
775
        }
776
	public function addStatAirline($airline_icao,$cnt,$airline_name = '') {
777
		global $globalDBdriver;
778
		if ($globalDBdriver == 'mysql') {
@@ 776-790 (lines=15) @@
773
                        return "error : ".$e->getMessage();
774
                }
775
        }
776
	public function addStatAirline($airline_icao,$cnt,$airline_name = '') {
777
		global $globalDBdriver;
778
		if ($globalDBdriver == 'mysql') {
779
			$query = "INSERT INTO stats_airline (airline_icao,airline_name,cnt) VALUES (:airline_icao,:airline_name,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt,airline_name = :airline_name";
780
		} else {
781
			$query = "UPDATE stats_airline SET cnt = cnt+:cnt WHERE airline_icao = :airline_icao; INSERT INTO stats_airline (airline_icao,airline_name,cnt) SELECT :airline_icao,:airline_name,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_airline WHERE airline_icao = :airline_icao);"; 
782
		}
783
                $query_values = array(':airline_icao' => $airline_icao,':airline_name' => $airline_name,':cnt' => $cnt);
784
                 try {
785
                        $sth = $this->db->prepare($query);
786
                        $sth->execute($query_values);
787
                } catch(PDOException $e) {
788
                        return "error : ".$e->getMessage();
789
                }
790
        }
791
	public function addStatOwner($owner_name,$cnt) {
792
		global $globalDBdriver;
793
		if ($globalDBdriver == 'mysql') {
@@ 791-805 (lines=15) @@
788
                        return "error : ".$e->getMessage();
789
                }
790
        }
791
	public function addStatOwner($owner_name,$cnt) {
792
		global $globalDBdriver;
793
		if ($globalDBdriver == 'mysql') {
794
			$query = "INSERT INTO stats_owner (owner_name,cnt) VALUES (:owner_name,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt";
795
		} else {
796
			$query = "UPDATE stats_owner SET cnt = cnt+:cnt WHERE owner_name = :owner_name; INSERT INTO stats_owner (owner_name,cnt) SELECT :owner_name,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_owner WHERE owner_name = :owner_name);"; 
797
		}
798
                $query_values = array(':owner_name' => $owner_name,':cnt' => $cnt);
799
                 try {
800
                        $sth = $this->db->prepare($query);
801
                        $sth->execute($query_values);
802
                } catch(PDOException $e) {
803
                        return "error : ".$e->getMessage();
804
                }
805
        }
806
	public function addStatPilot($pilot_id,$cnt) {
807
		global $globalDBdriver;
808
		if ($globalDBdriver == 'mysql') {
@@ 806-820 (lines=15) @@
803
                        return "error : ".$e->getMessage();
804
                }
805
        }
806
	public function addStatPilot($pilot_id,$cnt) {
807
		global $globalDBdriver;
808
		if ($globalDBdriver == 'mysql') {
809
			$query = "INSERT INTO stats_pilot (pilot_id,cnt) VALUES (:pilot_id,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt";
810
		} else {
811
			$query = "UPDATE stats_pilot SET cnt = cnt+:cnt WHERE pilot_id = :pilot_id; INSERT INTO stats_pilot (pilot_id,cnt) SELECT :pilot_id,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_pilot WHERE pilot_id = :pilot_id);"; 
812
		}
813
                $query_values = array(':pilot_id' => $pilot_id,':cnt' => $cnt);
814
                 try {
815
                        $sth = $this->db->prepare($query);
816
                        $sth->execute($query_values);
817
                } catch(PDOException $e) {
818
                        return "error : ".$e->getMessage();
819
                }
820
        }
821
	public function addStatDepartureAirports($airport_icao,$airport_name,$airport_city,$airport_country,$departure) {
822
		global $globalDBdriver;
823
		if ($globalDBdriver == 'mysql') {