noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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)",
70 Dossier::id(), $frd_id, $objname, $ad_id);
71 $label=$cn->get_value("select ad_text from attr_def where ad_id=$1",
72 [$ad_id]);
73 $content=sprintf('<li id="%s_elt%d" style="cursor:move;border:1px solid navy;padding : 0.5rem 0.2rem 0.5rem 0.2rem;margin-top:2px">%s', $objname
74 ,$ad_id,$label);
75 $content.=Icon_Action::trash(uniqid(), $js);
76 $content.='</li>';
77 $answer['content']=$content;
78 }
79 catch (Exception $exc)
80 {
81 echo $exc->getMessage();
82 error_log($exc->getTraceAsString());
83 $answer['message']=$exc->getMessage();
84 }
85
86
87 break;
88 case "remove_attribute":
89 try
90 {
91 if ($cn->get_value("select count(*) from jnt_fic_attr
92 join fiche_def using (fd_id)
93 where frd_id=$1 and ad_id=$2",
94 [$frd_id, $ad_id])>0)
95 throw new Exception(_("Attribut déjà utilisé"));
96 if (in_array($ad_id, [ATTR_DEF_NAME,ATTR_DEF_QUICKCODE]) )
97 {
98 throw new Exception(_("Attribut obligatoire"));
99 }
100 $answer['content']=$cn->get_value("select ad_text from attr_def where ad_id=$1",
101 [$ad_id]);
102 $answer['status']="OK";
103 $answer['message']="";
104 $cn->exec_sql("delete from attr_min where frd_id=$1 and ad_id=$2",
105 [$frd_id,$ad_id]);
106 }
107 catch (Exception $exc)
108 {
109 echo $exc->getMessage();
110 error_log($exc->getTraceAsString());
111 $answer['message']=$exc->getMessage();
112 }
113 break;
114
115 default:
116 break;
117}
118
119
120header("Content-type: text/json; charset: utf8", true);
121echo json_encode($answer,
122 JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
123return;
global $g_user
if no group available , then stop
$answer
_("actif, passif,charge,...")
$ex
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