Code Duplication    Length = 15-15 lines in 2 locations

api/functions.php 2 locations

@@ 184-198 (lines=15) @@
181
                    }
182
                }
183
184
                if (count($array_category) > 1 && count($array_category) < 5) {
185
                    for ($i = count($array_category); $i > 0; $i--) {
186
                        $slot = $i - 1;
187
                        if (!$slot) {
188
                            $category_query .= "select id from ".prefix_table("nested_tree")." where title LIKE '".$array_category[$slot]."' AND parent_id = 0";
189
                        } else {
190
                            $category_query .= "select id from ".prefix_table("nested_tree")." where title LIKE '".$array_category[$slot]."' AND parent_id = (";
191
                        }
192
                    }
193
                    for ($i = 1; $i < count($array_category); $i++) { $category_query .= ")"; }
194
                } elseif (count($array_category) == 1) {
195
                    $category_query = "select id from ".prefix_table("nested_tree")." where title LIKE '".$array_category[0]."' AND parent_id = 0";
196
                } else {
197
                    rest_error('NO_CATEGORY');
198
                }
199
200
                // Delete items which in category
201
                $response = DB::delete(prefix_table("items"), "id_tree = (".$category_query.")");
@@ 231-245 (lines=15) @@
228
                    rest_error('MALFORMED');
229
                }
230
231
                if (count($array_category) > 1 && count($array_category) < 5) {
232
                    for ($i = count($array_category); $i > 0; $i--) {
233
                        $slot = $i - 1;
234
                        if (!$slot) {
235
                            $category_query .= "select id from ".prefix_table("nested_tree")." where title LIKE '".$array_category[$slot]."' AND parent_id = 0";
236
                        } else {
237
                            $category_query .= "select id from ".prefix_table("nested_tree")." where title LIKE '".$array_category[$slot]."' AND parent_id = (";
238
                        }
239
                    }
240
                    for ($i = 1; $i < count($array_category); $i++) { $category_query .= ")"; }
241
                } elseif (count($array_category) == 1) {
242
                    $category_query = "select id from ".prefix_table("nested_tree")." where title LIKE '".$array_category[0]."' AND parent_id = 0";
243
                } else {
244
                    rest_error('NO_CATEGORY');
245
                }
246
247
                // Delete item
248
                $response = DB::delete(prefix_table("items"), "id_tree = (".$category_query.") and label LIKE '".$item."'");