public static function update_invoices_active()
 {
     check_ajax_referer('invoices_update_feed_active', 'invoices_update_feed_active');
     $id = $_POST["id"];
     $feed = TemplateData::get_invoices_feed($id);
     TemplateData::update_invoices_data($id, $feed["form_id"], $_POST["is_active"], $feed["meta"]);
 }
<?php

$id = !empty($_POST["invoices_setting_id"]) ? $_POST["invoices_setting_id"] : absint($_GET["id"]);
$config = empty($id) ? array("meta" => array(), "is_active" => true) : TemplateData::get_invoices_feed($id);
$is_validation_error = false;
$config["form_id"] = rgpost("invoices_submit") ? absint(rgpost("invoices_form")) : rgar($config, "form_id");
$config["is_active"] = rgpost("invoices_submit") ? absint(rgpost("invoices_isactive")) : rgar($config, "is_active");
$count = 0;
if (isset($config['meta']['files'])) {
    $count = count($config['meta']['files']);
}
$form = isset($config["form_id"]) && $config["form_id"] ? $form = RGFormsModel::get_form_meta($config["form_id"]) : array();
if (rgpost("invoices_submit")) {
    $newfiles = rearrange($_FILES['invoices_file']);
    $count = count($newfiles);
    if (!empty($config['meta'])) {
        $config['meta']['files'] = array_merge($config['meta']['files']);
        if (isset($_POST['edit_file_enable'])) {
            $needles = $_POST['edit_file_enable'];
        } else {
            $needles = array();
        }
        if (count(rgpost("edit_file_ids"))) {
            foreach ($config['meta']['files'] as $key => $val) {
                if (in_array($val['file_id'], $needles)) {
                    $config['meta']['files'][$key]['enable'] = 1;
                } else {
                    $config['meta']['files'][$key]['enable'] = 0;
                }
                $index = array_search($val['file_id'], rgpost("edit_file_ids"));
                if (count($index)) {