noalyss Version-9
ajax_template_cat_category.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2016) Author Dany De Bontridder <dany@alchimerys.be>
21
22if (!defined('ALLOWED'))
23 die('Appel direct ne sont pas permis');
24
25/**
26 * @file
27 * @brief manage attribut of a Template of Category of card. The answer must be
28 * in json
29 */
31$answer['status']="NOK";
32$answer['content']="";
33$answer['message']=_("Commande inconnue");
34
35
36/**
37 * security
38 */
39try
40{
41 if ($g_user->check_module("CMCARD")==0)
42 throw new Exception(_("Accès non autorisé"));
44 $action=$http->request("action");
45 $ad_id=$http->request("ad_id", "number");
46 $frd_id=$http->request("frd_id", "number");
47 $objname=$http->request("objname");
48}
49catch (Exception $ex)
50{
51 $answer['message']=_("Accès non autorisé");
52 header("Content-type: text/json; charset: utf8", true);
53 echo json_encode($answer,
54 JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
55 return;
56}
57switch ($action)
58{
59 case "add_attribute":
60 try
61 {
62 if ($cn->get_value("select count(*) from attr_min where frd_id=$1 and ad_id=$2",
63 [$frd_id, $ad_id])>0)
64 throw new Exception(_("Attribut déjà ajouté"));
65 $cn->exec_sql("insert into attr_min (frd_id,ad_id) values ($1,$2)",
66 [$frd_id, $ad_id]);
67 $answer['status']="OK";
68 $answer['message']="";
69 $js=sprintf("category_card.remove_attribut('%s','%s','%s',%d)",
71 $answer['content']=$cn->get_value("select ad_text from attr_def where ad_id=$1",
72 [$ad_id]).
73 Icon_Action::trash(uniqid(), $js);
74 }
75 catch (Exception $exc)
76 {
77 echo $exc->getMessage();
78 error_log($exc->getTraceAsString());
79 $answer['message']=$exc->getMessage();
80 }
81
82
83 break;
84 case "remove_attribute":
85 try
86 {
87 if ($cn->get_value("select count(*) from jnt_fic_attr
88 join fiche_def using (fd_id)
89 where frd_id=$1 and ad_id=$2",
90 [$frd_id, $ad_id])>0)
91 throw new Exception(_("Attribut déjà utilisé"));
92 if (in_array($ad_id, [ATTR_DEF_NAME,ATTR_DEF_QUICKCODE]) )
93 {
94 throw new Exception(_("Attribut obligatoire"));
95 }
96 $answer['content']=$cn->get_value("select ad_text from attr_def where ad_id=$1",
97 [$ad_id]);
98 $answer['status']="OK";
99 $answer['message']="";
100 $cn->exec_sql("delete from attr_min where frd_id=$1 and ad_id=$2",
101 [$frd_id,$ad_id]);
102 }
103 catch (Exception $exc)
104 {
105 echo $exc->getMessage();
106 error_log($exc->getTraceAsString());
107 $answer['message']=$exc->getMessage();
108 }
109 break;
110
111 default:
112 break;
113}
114
115
116header("Content-type: text/json; charset: utf8", true);
117echo json_encode($answer,
118 JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
119return;
global $g_user
if no group available , then stop
$ex
Definition: balance.inc.php:45
static id()
return the 'gDossier' value after a check
manage the http input (get , post, request) and extract from an array
static trash($p_id, $p_javascript)
Display the icon of a trashbin.
const ATTR_DEF_NAME
Definition: constant.php:216
const ATTR_DEF_QUICKCODE
Definition: constant.php:237