noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
ajax.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 12/08/24
20/*!
21 * \file
22 * \brief manage Ajax call for widget , called from html/ajax_misc.php.
23 * \par Variables are :
24 * * action = action to perform
25 * * w is the widget code or if empty , the Widget class will be used
26 *
27 * \par for Widget Class, possible actions are
28 *
29 * * widget.display : display the widget param : user_widget_id, user_widget_code
30 * * widget.refresh
31 * * widget.manage
32 * * widget.save
33 * * widget.insert
34 *
35 */
36global $cn;
38
39require_once 'widget.php';
40
41try {
42 $action=$http->request("action");
43 $w=$http->request("w","string","widget");
44} catch (\Exception $e) {
45 echo $e->getMessage();
46}
47
48// action = display,
49if ($action == 'widget.display') {
50 try {
51 $widget=\Noalyss\Widget\Widget::build_user_widget($http->request('user_widget_id'),$http->request("widget_code"));
52 $widget?->display();
53
54 } catch (\Exception $e) {
55 echo $e->getMessage();
56 }
57
58 return;
59}
60// call from a widget
61if ( $w != "widget") {
62 // security
63 // widget exists ? Protect against attack when w is a relative path to something else
64 $count=$cn->get_value("select count(*) from widget_dashboard where wd_code=$1",[$w]);
65 if ($count == 1 && file_exists(NOALYSS_INCLUDE."/widget/$w/ajax.php")) {
66 require NOALYSS_INCLUDE."/widget/$w/ajax.php";
67 return;
68 }
69}
70/**************************************************************************
71// action == manage , display a dialog box to add , remove or change parameter of widget
72// if must possible to add several time the same widget , example mini-report
73 *************************************************************************/
74if ( $action == 'widget.manage') {
75 echo \HtmlInput::title_box(_("Elements"), 'widget_box_id',p_mod: 'none',p_draggable: 'y');
76 echo '<div style="padding:0.3rem">';
77 echo span(_('Organiser les éléments en utilisant la souris (Drag & Drop) puis sauver'),'class="text-muted text-center"');
79
80
81 echo '<ul class="aligned-block">';
82 echo '<li>'.\HtmlInput::button_action(_('Fermer'),'widget.remove_ident();removeDiv('."'widget_box_id'".')').'</li>';
83 echo '<li>'.\HtmlInput::button_action(_('Sauver'),'widget.save()').'</li>';
84 echo '<li>'.\HtmlInput::button_action(_('Ajouter'),'widget.input()').'</li>';
85
86 echo '<ul>';
87
88 echo create_script("widget.create_sortable()");
89 echo '</div>';
90 return;
91}
92/**************************************************************************
93 *
94// save the order of the widget
95 *************************************************************************/
96if ( $action == 'widget.save') {
97 $query=$http->request("param","string","");
98 try {
99 parse_str($query, $aWigdet);
100 if (isset ($aWigdet['contain_widget']))
101 \Noalyss\Widget\Widget::save($aWigdet['contain_widget']);
102 else
103 \Noalyss\Widget\Widget::save(array());
104
105 } catch (\Exception $e) {
106 echo "NOK";
107 echo $e->getMessage();
108 }
109 return;
110}
111/**************************************************************************
112 * refresh dashboard
113 *
114 *************************************************************************/
115if ($action == 'widget.refresh') {
116 require NOALYSS_TEMPLATE."/dashboard.php";
117 return;
118}
119if ($action == "widget.input") {
120 echo \HtmlInput::title_box(_("Elements à ajouter"), 'widget_box_select_id',p_draggable: 'y');
121 echo '<div style="padding:0.3rem">';
123 echo '</div>';
124 echo '<ul class="aligned-block">';
125 echo '<li>'.\HtmlInput::button_close('widget_box_select_id','button').'</li>';
126 echo '<ul>';
127 echo '</div>';
128 return;
129}
130/*************************************************************************
131 * insert a new widget with param if any
132 ************************************************************************/
133if ($action == 'widget.insert') {
134 // insert new widget in user_widget + list "contain_widget"
135 $param = $http->request("param","string",null);
136 $widget_code = $http->request("widget_code");
137 $widget_id=$cn->get_value("select wd_id from widget_dashboard where wd_code=$1 ",[$widget_code]);
138 if (empty($widget_id)) return;
139
140 $user_widget_id = $cn->get_value("insert into user_widget(use_login,dashboard_widget_id,uw_parameter,uw_order)
141values ($1,$2,$3,1000) returning uw_id",[$g_user->getLogin(),$widget_id,$param]);
142 $widget=\Noalyss\Widget\Widget::build_user_widget($user_widget_id, $widget_code);
143 $widget->input(false);
144 return;
145}
span($p_string, $p_extra='')
Definition ac_common.php:43
global $g_user
if no group available , then stop
foreach($array as $idx=> $m) $w
_("actif, passif,charge,...")
manage the http input (get , post, request) and extract from an array
static build_user_widget($user_widget_id, $widget_code)
Build a widget thank the user_widget_id (SQL :PK : USER_WIDGET.UW_ID) and $widget_code.
Definition widget.php:137
static save($array)
save widget order from an array
Definition widget.php:234
static display_available()
@brier display activated widgets
Definition widget.php:214
static select_available()
show all the widget that can be added
Definition widget.php:267
$count
create_script($p_string)
create the HTML for adding the script tags around of the script