noalyss Version-10
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,
49 *
50 *************************************************************************/
51if ($action == 'widget.display') {
52 try {
53 $widget=\Noalyss\Widget\Widget::build_user_widget($http->request('user_widget_id'),$http->request("widget_code"));
54 $widget?->set_var_name($http->request("var_name"),'string','');
55 $widget?->display();
56
57 } catch (\Exception $e) {
59 echo $e->getMessage();
60 }
61
62 return;
63}
64/**************************************************************************
65// call from a widget
66 *
67 *************************************************************************/
68if ( $w != "widget") {
69 // security
70 // widget exists ? Protect against attack when w is a relative path to something else
71 $count=$cn->get_value("select count(*) from widget_dashboard where wd_code=$1",[$w]);
72 if ($count == 1 && file_exists(NOALYSS_INCLUDE."/widget/$w/ajax.php")) {
73 require NOALYSS_INCLUDE."/widget/$w/ajax.php";
74 return;
75 }
76}
77/**************************************************************************
78// action == manage , display a dialog box to add , remove or change parameter of widget
79// if must possible to add several time the same widget , example mini-report
80 *************************************************************************/
81if ( $action == 'widget.manage') {
82 echo \HtmlInput::title_box(_("Elements"), 'widget_box_id',p_mod: 'none',p_draggable: 'y');
83 echo '<div style="padding:0.3rem">';
84 echo span(_('Organiser les éléments en utilisant la souris (Drag & Drop) puis sauver'),'class="text-muted text-center"');
86
87
88 echo '<ul class="aligned-block">';
89 echo '<li>'.\HtmlInput::button_action(_('Fermer'),'widget.remove_ident();removeDiv('."'widget_box_id'".')').'</li>';
90 echo '<li>'.\HtmlInput::button_action(_('Sauver'),'widget.save()').'</li>';
91 echo '<li>'.\HtmlInput::button_action(_('Ajouter'),'widget.input()').'</li>';
92
93 echo '<ul>';
94
95 echo create_script("widget.create_sortable()");
96 echo '</div>';
97 return;
98}
99/**************************************************************************
100 *
101// save the order of the widget
102 *************************************************************************/
103if ( $action == 'widget.save') {
104 $query=$http->request("param","string","");
105 try {
106 parse_str($query, $aWigdet);
107 if (isset ($aWigdet['contain_widget']))
108 \Noalyss\Widget\Widget::save($aWigdet['contain_widget']);
109 else
110 \Noalyss\Widget\Widget::save(array());
111
112 } catch (\Exception $e) {
113 echo "NOK";
114 echo $e->getMessage();
115 }
116 return;
117}
118/**************************************************************************
119 * refresh dashboard
120 *
121 *************************************************************************/
122if ($action == 'widget.refresh') {
123 require NOALYSS_TEMPLATE."/dashboard.php";
124 return;
125}
126if ($action == "widget.input") {
127 echo \HtmlInput::title_box(_("Elements à ajouter"), 'widget_box_select_id',p_draggable: 'y');
128 echo '<div style="padding:0.3rem">';
130 echo '</div>';
131 echo '<ul class="aligned-block">';
132 echo '<li>'.\HtmlInput::button_close('widget_box_select_id','button').'</li>';
133 echo '<ul>';
134 echo '</div>';
135 return;
136}
137/*************************************************************************
138 * insert a new widget with param if any
139 ************************************************************************/
140if ($action == 'widget.insert') {
141 // insert new widget in user_widget + list "contain_widget"
142 $param = $http->request("param","string",null);
143 $widget_code = $http->request("widget_code");
144 $widget_id=$cn->get_value("select wd_id from widget_dashboard where wd_code=$1 ",[$widget_code]);
145 if (empty($widget_id)) return;
146
147 $user_widget_id = $cn->get_value("insert into user_widget(use_login,dashboard_widget_id,uw_parameter,uw_order)
148values ($1,$2,$3,1000) returning uw_id",[$g_user->getLogin(),$widget_id,$param]);
149 $widget=\Noalyss\Widget\Widget::build_user_widget($user_widget_id, $widget_code);
150 $widget->input(false);
151 return;
152}
span($p_string, $p_extra='')
Definition ac_common.php:43
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
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:159
static save($array)
save widget order from an array
Definition widget.php:256
static display_available()
@brier display activated widgets
Definition widget.php:236
static select_available()
show all the widget that can be added
Definition widget.php:289
$count
create_script($p_string)
create the HTML for adding the script tags around of the script