noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
ajax_category_card_definition.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright Author Dany De Bontridder danydb@aevalys.eu 7/08/24
20/*!
21 * \file
22 * \brief ajax from CCARD : add , remove or sort attributes from CCARD
23 */
24if (!defined('ALLOWED')) die('Appel direct ne sont pas permis');
25global $g_user;
26
27if ($g_user->check_module('CCARD') == 0) return;
29try {
30 $fiche_def = $http->request('fiche_def_id', 'number');
31 $op2 = $http->request("op2");
32} catch (\Exception $e) {
33 echo $e->getMessage();
34 return;
35}
36
37global $cn;
38
39if ($op2 == 'add') {
40 $ad_id=$http->get("ad_id","number");
41 $row = $cn->get_row('select ad_id , ad_text from attr_def where ad_id=$1',[$ad_id]);
42 Fiche_Def::print_existing_attribut($row['ad_id'], $row['ad_text']);
43
44} elseif ($op2 == 'remove') {
45 $ad_id=$http->get("ad_id","number");
46 $row = $cn->get_row('select ad_id , ad_text from attr_def where ad_id=$1',[$ad_id]);
47 Fiche_Def::print_available_attribut($row['ad_id'], $row['ad_text'],'');
48} elseif ($op2 == 'save') {
49
50 $str_Attribut=$http->post("attribut");
51 parse_str($str_Attribut, $row);
52 $aAttribut=$row['attribut_card'];
53 $nb_attribut=count($aAttribut);
54 try {
55 $cn->start();
56 $cn->exec_sql("create temporary table xxattribut (x_order int, x_adid int, x_fdid int)");
57 $order = 10;
58 for( $i = 0;$i < $nb_attribut;$i++) {
59 $o=$order*($i+1);
60 $cn->exec_sql("insert into xxattribut values ($1,$2,$3)",[$o,$aAttribut[$i],$fiche_def]);
61 }
62 $cn->exec_sql("delete from jnt_fic_attr where fd_id=$1 and ad_id not in (select x_adid from xxattribut)",[$fiche_def]);
63 $cn->exec_sql("insert into jnt_fic_attr(ad_id,fd_id,jnt_order)
64 select x_adid,x_fdid,x_order
65 from xxattribut
66 on conflict do nothing ");
67 $cn->exec_sql('update jnt_fic_attr set jnt_order = x_order from xxattribut where ad_id=x_adid and fd_id=x_fdid');
68 $cn->commit();
69 echo 'OK';
70 } catch (\Exception $e) {
71 echo $e->getMessage();
72 $cn->rollback();
73 }
74
75} else {
76 die("[$op2] action inconnue");
77}
global $g_user
if no group available , then stop
$fiche_def
static print_existing_attribut($attribut_id, $attribut_text)
display existing attribut
static print_available_attribut($attribut_id, $attribut_text, $class)
display available attribut
manage the http input (get , post, request) and extract from an array
if( $delta< 0) elseif( $delta==0)