From 4b0943c8b03eaef702c88592a5d8ae1823b3eaf0 Mon Sep 17 00:00:00 2001
From: Alex Orluc <alex.orluc@maarch.org>
Date: Mon, 19 Mar 2018 19:40:58 +0100
Subject: [PATCH] FEAT #6641 merge from 17_06_project_develop

---
 apps/maarch_entreprise/ajaxIndexingModel.php | 59 ++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 apps/maarch_entreprise/ajaxIndexingModel.php

diff --git a/apps/maarch_entreprise/ajaxIndexingModel.php b/apps/maarch_entreprise/ajaxIndexingModel.php
new file mode 100644
index 00000000000..10bf4da2690
--- /dev/null
+++ b/apps/maarch_entreprise/ajaxIndexingModel.php
@@ -0,0 +1,59 @@
+<?php
+/**
+* Copyright Maarch since 2008 under licence GPLv3.
+* See LICENCE.txt file at the root folder for more details.
+* This file is part of Maarch software.
+
+*
+* @brief   ajaxIndexingModel
+*
+* @author  dev <dev@maarch.org>
+* @ingroup apps
+*/
+$db = new Database();
+$mode = $_REQUEST['mode'];
+
+if ($mode == 'up') {
+    $id = $_REQUEST['id'];
+    $content = $_REQUEST['content'];
+    $stmt = $db->query(
+        'UPDATE indexingModels SET fields_content = ? WHERE id = ?', [$content, $id]);
+    $result_txt = 'Modèle modifié';
+} elseif ($mode == 'del') {
+    $id = $_REQUEST['id'];
+
+    $stmt = $db->query(
+        'DELETE FROM indexingModels WHERE id = ?', [$id]
+    );
+    $result_txt = 'Modèle supprimé';
+} elseif ($mode == 'get') {
+    $id = $_REQUEST['id'];
+
+    $stmt = $db->query(
+        'select fields_content FROM indexingModels WHERE id=?', [$id]
+    );
+
+    $res = $stmt->fetchObject();
+    $result_txt = $res->fields_content;
+} else {
+    $label = $_REQUEST['label'];
+    $content = $_REQUEST['content'];
+    $mode = $_REQUEST['mode'];
+
+    $stmt = $db->query(
+        'INSERT INTO indexingModels (label, fields_content) VALUES(?,?)', [$label, $content]
+    );
+    $id = $db->lastInsertId('indexingmodels_id_seq');
+
+    $stmt = $db->query(
+        'select id,label FROM indexingModels WHERE id=?', [$id]
+    );
+
+    $res = $stmt->fetchObject();
+    $result = json_encode($res);
+
+    $result_txt = 'Modèle ajouté';
+}
+
+echo '{"status" : 0,"result" : "'.addslashes($result).'","result_txt" : "'.addslashes($result_txt).'"}';
+exit();
-- 
GitLab