Code Duplication    Length = 30-34 lines in 3 locations

htdocs/restorecaches.php 3 locations

@@ 756-786 (lines=31) @@
753
        $user_id = $cache['user_id'];
754
755
        // coordinates
756
        if (in_array('coords', $roptions) &&
757
            sql_value(
758
                "SELECT `cache_id`
759
                 FROM `cache_coordinates`
760
                 WHERE `cache_id`='&1'
761
                   AND `date_created`>='&2'",
762
                0,
763
                $cacheid,
764
                $rdate
765
            )
766
        ) {
767
            $rs = sql(
768
                "SELECT `latitude`,
769
                        `longitude`
770
                 FROM `cache_coordinates`
771
                 WHERE `cache_id`='&1'
772
                   AND `date_created` < '&2'
773
                 ORDER BY `date_created` DESC
774
                 LIMIT 1",
775
                $cacheid,
776
                $rdate
777
            );
778
            if ($r = sql_fetch_assoc($rs)) { // should always be true ...
779
                if (!$simulate) {
780
                    sql(
781
                        "UPDATE `caches` SET `latitude`='&1', `longitude`='&2' WHERE `cache_id`='&3'",
782
                        $r['latitude'],
783
                        $r['longitude'],
784
                        $cacheid
785
                    );
786
                }
787
788
                $restored[$wp]['coords'] = true;
789
            }
@@ 794-823 (lines=30) @@
791
        }
792
793
        // country
794
        if (in_array('coords', $roptions) &&
795
            sql_value(
796
                "SELECT `cache_id`
797
                 FROM `cache_countries`
798
                 WHERE `cache_id`='&1'
799
                   AND `date_created`>='&2'",
800
                0,
801
                $cacheid,
802
                $rdate
803
            )
804
        ) {
805
            $rs = sql(
806
                "SELECT `country`
807
                 FROM `cache_countries`
808
                 WHERE `cache_id`='&1'
809
                   AND `date_created` < '&2'
810
                 ORDER BY `date_created` DESC
811
                LIMIT 1",
812
                $cacheid,
813
                $rdate
814
            );
815
            if ($r = sql_fetch_assoc($rs)) { // should always be true ...
816
                if (!$simulate) {
817
                    sql(
818
                        "UPDATE `caches` SET `country`='&1'  WHERE `cache_id`='&2'",
819
                        $r['country'],
820
                        $cacheid
821
                    );
822
                }
823
824
                $restored[$wp]['country'] = true;
825
            }
826
            sql_free_result($rs);
@@ 873-906 (lines=34) @@
870
        sql_free_result($rs);
871
872
        // attributes
873
        if (in_array('settings', $roptions)) {
874
            $rs = sql(
875
                "SELECT *
876
                 FROM `caches_attributes_modified`
877
                 WHERE `cache_id`='&1'
878
                   AND `date_modified`>='&2'
879
                   AND `attrib_id` != 6 /* OConly */
880
                 ORDER BY `date_modified` DESC",
881
                $cacheid,
882
                $rdate
883
            );
884
885
            // revert all attribute changes in reverse order.
886
            // recording limit of one change per attribute, cache and day ensures that no exponentially
887
            // growing list of recording entries can emerge from multiple reverts.
888
889
            while ($r = sql_fetch_assoc($rs)) {
890
                if (!$simulate) {
891
                    if ($r['was_set']) {
892
                        sql(
893
                            "INSERT IGNORE INTO `caches_attributes` (`cache_id`,`attrib_id`)
894
                             VALUES ('&1','&2')",
895
                            $cacheid,
896
                            $r['attrib_id']
897
                        );
898
                    } else {
899
                        sql(
900
                            "DELETE FROM `caches_attributes` WHERE `cache_id`='&1' AND `attrib_id`='&2'",
901
                            $cacheid,
902
                            $r['attrib_id']
903
                        );
904
                    }
905
                }
906
                $restored[$wp]['attributes'] = true;
907
            }
908
            sql_free_result($rs);
909
        }