noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
ajax_admin.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
20// Copyright 2015 Author Dany De Bontridder danydb@aevalys.eu
21
22if (!defined('ALLOWED'))
23 die('Appel direct ne sont pas permis');
24/**
25 * @file
26 * @brief the file contents the code which answer to ajax call from
27 * admin-noalyss.php
28 * @see admin-noalyss.php ajax_misc.php admin.js
29 */
31$audit=true;
32if ($g_user->isAdmin()==0)
33{
34 $g_user->audit('FAIL',"ADMIN : ".var_export($_REQUEST,true));
35 die();
36}
37session_write_close();
40$op=$http->request("op");
41$g_user->audit('SUCCESS',"ADMIN : $op");
42// From admin, grant the access to a folder to an
43// user
44if ($op=='folder_add') // operation
45{
46
47 $cn=new Database();
48 try
49 {
50 $user_id=$http->get("p_user", "number"); // get variable
51 $dossier_id=$http->get("p_dossier", "number"); // get variable
52 $user=new Noalyss_User($cn, $user_id);
53 $user->set_folder_access($dossier_id, true);
54 $dossiercn=new Database($dossier_id);
55 // By default new Noalyss_User has the profile 1 (admin) and ledger's security
56 // + action's security are disabled
57 $user=new Noalyss_User($dossiercn, $user_id);
58 $user->set_status_security_action(0);
59 $user->set_status_security_ledger(0);
60 $user->save_profile(1);
61 $dossier=new Dossier($dossier_id);
62 $dossier->load();
63 $content="<td>".h($dossier->dos_name)."</td><td>".h($dossier->dos_description)."</td>".
64 "<td>".
65 HtmlInput::anchor(_('Enleve'), "", " onclick=\"folder_remove({$user_id},{$dossier_id});\"").
66 "</td>";
67 $status='OK';
68 }
69 catch (Exception $exc)
70 {
71 error_log($exc->getTraceAsString());
72 $content=_('Erreur paramètre');
73 $status="NOK";
74 return;
75 }
76
77
78 //----------------------------------------------------------------
79 // Answer in XML
80 header('Content-type: text/xml; charset=UTF-8');
81 $dom=new DOMDocument('1.0', 'UTF-8');
82 $xml_content=$dom->createElement('content', $content);
83 $xml_status=$dom->createElement('status', $status);
84 $root=$dom->createElement("root");
85 $root->appendChild($xml_content);
86 $root->appendChild($xml_status);
87 $dom->appendChild($root);
88 echo $dom->saveXML();
89 exit();
90}
91// From admin, revoke the access to a folder from an
92// user
93if ($op=='folder_remove') // operation
94{
95 try
96 {
97 $cn=new Database();
98 $user_id=$http->get("p_user", "number"); // get variable
99 $dossier_id=$http->get("p_dossier", "number"); // get variable
100 $user=new Noalyss_User($cn, $user_id);
101 $user->set_folder_access($dossier_id, false);
102 $content="";
103 $status='OK';
104 }
105 catch (Exception $exc)
106 {
107 error_log($exc->getTraceAsString());
108 $content=_('Erreur paramètre');
109 $status="NOK";
110 }
111
112 //----------------------------------------------------------------
113 // Answer in XML
114 header('Content-type: text/xml; charset=UTF-8');
115 $dom=new DOMDocument('1.0', 'UTF-8');
116 $xml_content=$dom->createElement('content', $content);
117 $xml_status=$dom->createElement('status', $status);
118 $root=$dom->createElement("root");
119 $root->appendChild($xml_content);
120 $root->appendChild($xml_status);
121 $dom->appendChild($root);
122 echo $dom->saveXML();
123 exit();
124}
125/**
126 * Display the forbidden folders if the request comes from a form
127 * with an input text (id:database_filter_input) then this text is
128 * used as a filter
129 *
130 */
131if ($op=='folder_display') // operation
132{
133
134 $cn=new Database();
135 try
136 {
137 $user_id=$http->get("p_user", "number"); // get variable
138 $p_filter=$http->get('p_filter', "string", '');
139 ob_start();
140 $user=new Noalyss_User($cn, $user_id);
141 $a_dossier=Dossier::show_dossier('X', $user->id, $p_filter, MAX_FOLDER_TO_SHOW);
142 echo HtmlInput::title_box(_("Liste dossier"), 'folder_list_div');
143 ?>
144 <form method="get" onsubmit="folder_display('<?php echo $user_id ?>');
145 return false">
146 <p style="text-align: center">
147 <?php echo _('Recherche'); ?>
148
149 <input type="text" id="database_filter_input" class="input_text" autofocus="true" autocomplete="off" nohistory autocomplete="false" value="<?php echo $p_filter ?>"
150 onkeyup="filter_table(this, 'folder_display_tb', '1,2,3', 0)" >
151 <input type="button" class="smallbutton" onclick="$('database_filter_input').value = '';filter_table($('database_filter_input'), 'folder_display_tb', '1,2,3', 0);" value="X">
152 <input type="submit" class="smallbutton" value="<?php echo _('Rechercher') ?>">
153 </p>
154 </form>
155 <p>
156 <?php
157 $nb_dossier=count($a_dossier);
159 echo _('Dossiers trouvés').':'.$nb_dossier." "._('Dossiers affichés').$max.' '._('Limite dossiers').":".MAX_FOLDER_TO_SHOW;
160 ?>
161 </p>
162 <?php
163 require NOALYSS_TEMPLATE.'/folder_display.php';
164 $content=ob_get_clean();
165 $status='OK';
166 }
167 catch (Exception $exc)
168 {
169 error_log($exc->getTraceAsString());
170 $content=_('Erreur paramètre');
171 $status="NOK";
172 }
173
174
175
176
177 //----------------------------------------------------------------
178 // Answer in XML
179 header('Content-type: text/xml; charset=UTF-8');
180 $dom=new DOMDocument('1.0', 'UTF-8');
181 $xml=escape_xml($content);
182 $xml_content=$dom->createElement('content', $xml);
183 $xml_status=$dom->createElement('status', $status);
184 $root=$dom->createElement("root");
185 $root->appendChild($xml_content);
186 $root->appendChild($xml_status);
187 $dom->appendChild($root);
188 echo $dom->saveXML();
189 exit();
190}
191// For the operation 'modele_drop','modele_modify','folder_modify','folder_drop'
192// the p_dossier parameter is mandatory
193if (in_array($op, array('modele_drop', 'modele_modify', 'folder_modify', 'folder_drop')))
194{
195 try
196 {
197 $dossier=$http->get('p_dossier', "number");
198 $content=_('Erreur paramètre');
199 $status="NOK";
200 }
201 catch (Exception $exc)
202 {
203 error_log($exc->getTraceAsString());
204 $content=_('Erreur paramètre');
205 $status="NOK";
206 //----------------------------------------------------------------
207 // Answer in XML
208 header('Content-type: text/xml; charset=UTF-8');
209 $dom=new DOMDocument('1.0', 'UTF-8');
210 $xml=escape_xml($content);
211 $xml_content=$dom->createElement('content', $xml);
212 $xml_status=$dom->createElement('status', $status);
213 $root=$dom->createElement("root");
214 $root->appendChild($xml_content);
215 $root->appendChild($xml_status);
216 $dom->appendChild($root);
217 echo $dom->saveXML();
218 exit();
219 }
220
221 // Modify the description or the name of folder
222 if ($op=='folder_modify')
223 {
224 $dos=new Dossier($dossier);
225 ob_start();
226 $dos->load();
227 echo HtmlInput::title_box(_('Modification'), 'folder_admin_div');
228 $wText=new IText();
229 echo '<form action="admin-noalyss.php" method="post">';
230 echo HtmlInput::hidden('action', 'dossier_mgt');
231 echo HtmlInput::hidden('d', $dos->get_parameter("id"));
232 echo _('Nom').' : ';
233 echo $wText->input('name', $dos->get_parameter('name'));
234 echo '<br>';
235 $wDesc=new ITextArea();
236 $wDesc->heigh=5;
237 echo _('Description').' : <br>';
238 echo $wDesc->input('desc', $dos->get_parameter('desc'));
239 echo '<br>';
240
241 echo _('Max. email / jour (-1 = illimité)');
242 $max_email_input=new INum('max_email');
243 $max_email_input->value=$dos->get_parameter('max_email');
244 $max_email_input->prec=0;
245 echo $max_email_input->input();
246 echo '<ul class="aligned-block">';
247 echo "<li>";
248 echo HtmlInput::submit('upd', _('Modifie'));
249 echo "</li>";
250 echo "<li>";
251 echo HtmlInput::button_close("folder_admin_div");
252 echo "</li>";
253 echo '</ul>';
254
255
256 echo '</form>';
257 $content=ob_get_clean();
258 $status='OK';
259 }
260 else if ($op=='folder_drop')
261 {
262 // ask to confirm the removal a folder
263 $dos=new Dossier($dossier);
264 ob_start();
265 echo HtmlInput::title_box(_('Efface'), 'folder_admin_div');
266 $dos->load();
267 echo '<form action="admin-noalyss.php" method="post">';
268 echo HtmlInput::hidden('action', 'dossier_mgt');
269 echo HtmlInput::hidden('d', $dossier);
270 echo HtmlInput::hidden('sa', 'remove');
271 echo '<h2 class="error">'._('Etes vous sûr et certain de vouloir effacer ').$dos->dos_name.' ???</h2>';
272 $confirm=new ICheckBox();
273 $confirm->name="p_confirm";
274 echo '<p>';
275 echo _("Tapez le code de confirmation");
276 echo confirm_with_string("fld_drop",5);
277 echo '</p>';
278 echo '<ul class="aligned-block">';
279 echo "<li>";
280 echo HtmlInput::submit('remove', _('Effacer'));
281 echo "</li>";
282 echo "<li>";
283 echo HtmlInput::button_close("folder_admin_div");
284 echo "</li>";
285 echo '</ul>';
286 echo '</form>';
287
288 $content=ob_get_clean();
289 $status='OK';
290 }
291 else if ($op=='modele_drop')
292 {
293 // ask to confirm the removal a folder
294 $cn=new Database();
295 $name=$cn->get_value('select mod_name from modeledef where mod_id=$1', array($dossier));
296 ob_start();
297 echo HtmlInput::title_box(_('Efface'), 'folder_admin_div');
298 echo '<form action="admin-noalyss.php" method="post">';
299 echo HtmlInput::hidden('m', $dossier);
300 echo HtmlInput::hidden('sa', 'remove');
301 echo HtmlInput::hidden('action', 'modele_mgt');
302 echo '<h2 class="error">'._('Etes vous sure et certain de vouloir effacer ').$name.' ?</h2>';
303 $confirm=new ICheckBox();
304 $confirm->name="p_confirm";
305 echo '<p>';
306 echo _('Cochez la case si vous êtes sûr de vouloir effacer ce modèle');
307 echo $confirm->input();
308 echo '</p>';
309 echo '<ul class="aligned-block">';
310 echo "<li>";
311 echo HtmlInput::submit('remove', _('Effacer'));
312 echo "</li>";
313 echo "<li>";
314 echo HtmlInput::button_close("folder_admin_div");
315 echo "</li>";
316 echo '</ul>';
317
318 echo '</form>';
319 $content=ob_get_clean();
320 $status='OK';
321 }
322 else if ($op=='modele_modify')
323 {
324 // Modify the description or the name of a template
325 $cn=new Database();
326 ob_start();
327 echo HtmlInput::title_box(_('Modification'), 'folder_admin_div');
328 echo '<form method="post">';
329 $name=$cn->get_value(
330 "select mod_name from modeledef where ".
331 " mod_id=$1", array($dossier));
332
333 $desc=$cn->get_value(
334 "select mod_desc from modeledef where ".
335 " mod_id=$1", array($dossier));
336 $wText=new IText();
337 echo 'Nom : '.$wText->input('name', $name);
338 $wDesc=new ITextArea();
339 $wDesc->heigh=5;
340 echo '<br>Description :<br>';
341 echo $wDesc->input('desc', $desc);
342 echo HtmlInput::hidden('m', $dossier);
343 echo HtmlInput::hidden('action', 'modele_mgt');
344
345 echo '<ul class="aligned-block">';
346 echo "<li>";
347 echo HtmlInput::submit('upd', _('Modifie'));
348 echo "</li>";
349 echo "<li>";
350 echo HtmlInput::button_close("folder_admin_div");
351 echo "</li>";
352 echo '</ul>';
353
354
355 echo '</form>';
356 $content=ob_get_clean();
357 $status='OK';
358 }
359 //----------------------------------------------------------------
360 // Answer in XML
361 header('Content-type: text/xml; charset=UTF-8');
362 $dom=new DOMDocument('1.0', 'UTF-8');
363 $xml=escape_xml($content);
364 $xml_content=$dom->createElement('content', $xml);
365 $xml_status=$dom->createElement('status', $status);
366 $root=$dom->createElement("root");
367 $root->appendChild($xml_content);
368 $root->appendChild($xml_status);
369 $dom->appendChild($root);
370 echo $dom->saveXML();
371 exit();
372}
373//------------------------------------------------------------------
374// Upgrade Core
375//------------------------------------------------------------------
376if ($op=='upgradeCore')
377{
378 $task_id=$http->request("task_id");
380 $progress->set_value(2);
382 $core=$repo->make_object("core", " ");
383 try {
384 $progress->set_value(5);
385 $core->download();
386 $progress->set_value(55);
387 if ( DEBUGNOALYSS == 0 )
388 {
389 $core->install();
390 }
391 $progress->set_value(100);
392
393 $url=sprintf('<a href="%s"> install.php</a>', NOALYSS_URL."/install.php");
394 printf(_("Afin de terminer l'installation aller sur %s , à la fin de la procédure , demandez à effacer le fichier install.php"),
395 $url);
396 } catch (Exception $ex ) {
397 echo '<p class="notice">';
398 echo $ex->getMessage();
399 echo '</p>';
400 $progress->set_value(100);
401 }
402 return;
403}
404//---------------------------------------------------------------------------------------------------------
405// Upgrade or install plugin
406//---------------------------------------------------------------------------------------------------------
407if ($op=='upgradePlugin')
408{
409 $task_id=$http->request("task_id");
410 $code=$http->post("code_plugin");
412 $progress->set_value(2);
414 $plugin=$repo->make_object("plugin", $code);
415 $progress->set_value(5);
416 $plugin->download();
417 $progress->set_value(55);
418 $plugin->install();
419 $progress->set_value(100);
420 echo _("L'extension doit être activée dans le dossier avec C0PLG");
421 return;
422}
423//------------------------------------------------------------------------------------------------------------------
424// Install template
425//------------------------------------------------------------------------------------------------------------------
426if ($op=="installTemplate")
427{
428 $task_id=$http->request("task_id");
429 $name=$http->post("code");
431 $progress->set_value(2);
433 $progress->set_value(4);
434 $template=$package_repository->make_object("template", $name);
435 $progress->set_value(30);
436 $template->download();
437 $progress->set_value(70);
438 $template->install();
439 $progress->set_value(100);
440 echo _("Modèle installé");
441 return;
442}
443?>
confirm_with_string($p_ctl_name, $p_car)
generate a string of p_car character and a input text with name p_ctl_name work like a kind of captch...
p($p_string)
Definition ac_common.php:39
set_language()
set the lang thanks the _SESSION['g_lang'] var.
global $g_user
if no group available , then stop
switch($op2) $xml
$dossier_id
$op
h( $row[ 'oa_description'])
$opd_description style
if(isset($_REQUEST['gDossier']) && $http->request("gDossier","number", 0) !=0) $repo
$_REQUEST['ac']
_("actif, passif,charge,...")
$ex
$input_from type
contains the class for connecting to Noalyss
static show_dossier($p_type, $p_login="", $p_text="", $limit=0)
Show the folder where user have access.
static button_close($div_name, $class='smallbutton')
close button for the HTML popup
static hidden($p_name, $p_value, $p_id="")
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n', $raw="")
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
manage the http input (get , post, request) and extract from an array
Html Input.
This class handles only the numeric input, the input will call a javascript to change comma to period...
Html Input.
Data & function about connected users.
connect to NOALYSS_PACKAGE and fetch the file web.xml , it displays content of this file ,...
Use one db for tracking progress bar value, the task id must be unique and let you follow the progres...
const MAX_FOLDER_TO_SHOW(!defined('MAX_SEARCH_CARD'))
Definition constant.php:147
$max_email_input
for($i=0;$i< $count;$i++) $template
for($e=0; $e< count($afiche); $e++) exit
if(count($a_dossier)==0) $nb_dossier
escape_xml($p_xml)
When data are transfered thanks ajax in a xml document, the xml can not contains some character,...
$core
$package_repository