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