public function saveFilter($post, $auto_assign = false, $replace_customer = false) { ini_set('display_errors', 'on'); if ($post['idfilter'] != 0) { $id_filter = $post['idfilter']; $this->deleteCondition($id_filter); if ($post['idgroup'] == 0) { Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'mj_filter` SET `name` = "' . pSQL($post['name']) . '", `description` = "' . pSQL($post['description']) . '" WHERE `id_filter`=' . (int) $id_filter); } else { $query = ' UPDATE `' . _DB_PREFIX_ . 'mj_filter` SET `name` = "' . pSQL($post['name']) . '", `description` = "' . pSQL($post['description']) . '", `id_group` = "' . (int) $post['idgroup'] . '", `assignment_auto` = ' . (int) (bool) $auto_assign . ', `replace_customer` = ' . (int) (bool) $replace_customer . ' WHERE `id_filter`=' . (int) $id_filter; Db::getInstance()->Execute($query); } /* try { */ $segmentSynchronization = new HooksSynchronizationSegment(MailjetTemplate::getApi()); $mailjetFiterid = $this->_getMailjetContactListId($id_filter); $segmentSynchronization->updateName($mailjetFiterid, $id_filter, pSQL($post['name'])); /* } catch (Exception $e) { } */ } else { Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'mj_filter` (`name`, `description`, `date_start`, `date_end`, `id_group`, `assignment_auto`, `replace_customer`) VALUES ("' . pSQL($post['name']) . '", "' . pSQL($post['description']) . '", NULL, NULL, "' . (int) $post['idgroup'] . '", ' . (int) (bool) $auto_assign . ', ' . (int) (bool) $replace_customer . ')'); $id_filter = Db::getInstance()->getValue('SELECT MAX(id_filter) FROM `' . _DB_PREFIX_ . 'mj_filter`'); } $nb = count($post['fieldSelect']); for ($i = 0; $i < $nb; $i++) { Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'mj_condition`(`id_filter`, `id_basecondition`, `id_sourcecondition`, `id_fieldcondition`, `rule_a`, `rule_action`, `data`, `value1`, `value2`) VALUES (' . (int) $id_filter . ', ' . pSQL($post['baseSelect'][$i]) . ', ' . pSQL($post['sourceSelect'][$i]) . ', ' . pSQL($post['fieldSelect'][$i]) . ', "' . pSQL($post['rule_a'][$i]) . '", "' . pSQL($post['rule_action'][$i]) . '", "' . pSQL($post['data'][$i]) . '", "' . $this->_formatDate(pSQL($post['value1'][$i])) . '", "' . $this->_formatDate(pSQL($post['value2'][$i])) . '")'); } if ($auto_assign) { $auto_assign_text = $this->ll(96); if ($replace_customer) { $replace_customer_text = $this->ll(97); } else { $replace_customer_text = $this->ll(98); } } else { $auto_assign_text = '--'; $replace_customer_text = '--'; } if (!($group_name = $this->getGroupName((int) $post['idgroup']))) { $group_name = '--'; } /* ** ** */ foreach ($post as &$p) { $p = str_replace("\\'", "'", $p); } $post['id'] = $id_filter; $post['replace_customer'] = $replace_customer_text; $post['auto_assign'] = $auto_assign_text; $post['group_name'] = $group_name; return Tools::jsonEncode($post); /* ** ** */ // return '{"id" : '.$id_filter.',"name" : "'.pSQL($post['name']).'", "description" : "'.pSQL($post['description']).'", "replace_customer" : "'.$replace_customer_text.'", "auto_assign" : "'.$auto_assign_text.'", "group_name" : "'.$group_name.'"}'; }