noalyss Version-9
noalyss_script.js
Go to the documentation of this file.
1/*
2 * This file is part of NOALYSS.
3 *
4 * NOALYSS is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * NOALYSS is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with NOALYSS; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18/* $Revision$ */
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief javascript script, always added to every page
24 *
25 */
26var ask_reload = 0;
27// tag_choose Element which contains all the selected tags
28var tag_choose = '';
29var aDraggableElement = new Array();
30
31// document.viewport depends of prototype.js
32var viewport = document.viewport.getDimensions(); // Gets the viewport as an object literal
33var width = viewport.width; // Usable window width
34var height = viewport.height;
35 /**
36 * return undefined if nothing is found , otherwise return the DOM elemnt
37 * @param {type} p_name_dom
38 * @param {type} name_child
39 * @returns {undefined}
40 */
41function in_child(p_element,name_child) {
42 var element=p_element
43 if ( typeof p_element !== "object" ) {
44 element=document.getElementById(p_element);
45
46 }
47 if ( ! element ) return undefined;
48 for ( var e=0; e < element.childElementCount;e++) {
49 if ( element.childNodes[e].id == name_child) {
50 return element.childNodes[e];
51 }
52 }
53}
54/**
55 * callback function when we just need to update a hidden div with an info
56 * message
57 */
58function infodiv(req, json)
59{
60 try
61 {
62 remove_waiting_box();
63 var answer = req.responseXML;
64 var a = answer.getElementsByTagName('ctl');
65 var html = answer.getElementsByTagName('code');
66 if (a.length === 0)
67 {
68 var rec = req.responseText;
69 alert_box('erreur :' + rec);
70 }
71 var name_ctl = a[0].firstChild.nodeValue;
72 var code_html = getNodeText(html[0]);
73
74 code_html = unescape_xml(code_html);
75 g(name_ctl + "info").innerHTML = code_html;
76 } catch (e)
77 {
78 alert_box("success_box" + e.message);
79 }
80 try
81 {
82 code_html.evalScripts();
83 } catch (e)
84 {
85 alert_box(content[53] + "\n" + e.message);
86 }
87
88}
89/**
90 * delete a row from a table (tb) the input button send the this
91 * as second parameter
92 */
93function deleteRow(tb, obj)
94{
95 smoke.confirm(content[50], function (e)
96 {
97 if (e) {
98 var td = obj.parentNode;
99 var tr = td.parentNode;
100 var lidx = tr.rowIndex;
101 g(tb).deleteRow(lidx);
102
103 } else {
104 return;
105 }
106 });
107}
108function deleteRowRec(tb, obj)
109{
110 var tr = obj;
111 var lidx = tr.rowIndex;
112 g(tb).deleteRow(lidx);
113}
114/*!\brief remove trailing and heading space
115 * \param the string to modify
116 * \return string without heading and trailing space
117 */
118function trim(s)
119{
120 return s.replace(/^\s+/, '').replace(/\s+$/, '');
121}
122
123/**
124 * retrieve an element thanks its ID
125 * @param ID is a string
126 * @return the found object of undefined if not found
127 */
128function g(ID)
129{
130 if (document.getElementById)
131 {
132 return this.document.getElementById(ID);
133 } else if (document.all)
134 {
135 return document.all[ID];
136 } else
137 {
138 return undefined;
139 }
140}
141/**
142 * enable the type of periode
143 */
144function enable_type_periode()
145{
146 if ($("type_periode").options[$("type_periode").selectedIndex].value == 0)
147 {
148 $('from_periode').enable();
149 $('to_periode').enable();
150 $('from_date').disable();
151 $('to_date').disable();
152 $('p_step').enable();
153 } else
154 {
155 $('from_periode').disable();
156 $('to_periode').disable();
157 $('from_date').enable();
158 $('to_date').enable();
159 $('p_step').disable();
160 }
161}
162
163/**
164 * will reload the window but it is dangerous if we have submitted
165 * a form with POST
166 */
167function refresh_window()
168{
169 window.location.reload();
170}
171
172/**
173 *@fn encodeJSON(obj)
174 * we receive a json object as parameter and the function returns the string
175 * with the format variable=value&var2=val2...
176 */
177function encodeJSON(obj)
178{
179 if (typeof obj != 'object')
180 {
181 alert_box('encodeParameter obj n\'est pas un objet');
182 }
183 try
184 {
185 var str = '';
186 var e = 0;
187 for (var i in obj)
188 {
189 if (e !== 0)
190 {
191 str += '&';
192 } else
193 {
194 e = 1;
195 }
196 str += i;
197 str += '=' + encodeURI(obj[i]);
198 }
199 return str;
200 } catch (e)
201 {
202 alert_box('encodeParameter ' + e.message);
203 return "";
204 }
205}
206function hide(p_param)
207{
208 g(p_param).style.display = 'none';
209}
210function show(p_param)
211{
212 g(p_param).style.display = 'block';
213}
214
215/**
216 * set the focus on the selected field
217 *@param Field id of the control
218 *@param selectIt : the value selected in case of Field is a object select, numeric
219 */
220function SetFocus(Field, SelectIt)
221{
222 var elem = g(Field);
223 if (elem)
224 {
225 elem.focus();
226 }
227 return true;
228}
229/**
230 * set a DOM id with a value in the parent window (the caller),
231 @param p_ctl is the name of the control
232 @param p_value is the value to set in
233 @param p_add if we don't replace the current value but we add something
234 */
235function set_inparent(p_ctl, p_value, p_add)
236{
237 self.opener.set_value(p_ctl, p_value, p_add);
238}
239
240/**
241 * set a DOM id with a value, it will consider if it the attribute
242 value or innerHTML has be used
243 @param p_ctl is the name of the control
244 @param p_value is the value to set in
245 @param p_add if we don't replace the current value but we add something
246 */
247function set_value(p_ctl, p_value, p_add)
248{
249 if (g(p_ctl))
250 {
251 var g_ctrl = g(p_ctl);
252 if (p_add != undefined && p_add === 1)
253 {
254 if (g_ctrl.value)
255 {
256 p_value = g_ctrl.value + ',' + p_value;
257 }
258 }
259 if (g_ctrl.tagName === 'INPUT')
260 {
261 g(p_ctl).value = p_value;
262 }
263 if (g_ctrl.tagName === 'SPAN')
264 {
265 g(p_ctl).innerHTML = p_value;
266 }
267 if (g_ctrl.tagName === 'SELECT')
268 {
269 g(p_ctl).value = p_value;
270 }
271 }
272}
273/**
274 * compute small math in numeric cells
275 * @param string value
276 * @returns float
277 */
278function compute_number(value)
279{
280 var retval = 0;
281
282 var exp = new RegExp("^[0-9/*+-.()]+$", "g");
283 /*pour éviter un eval() mal intentionné*/
284 var res = exp.test(value);
285 if (res)
286 {
287 /*pour gérer un nombre non valide comme 5..36 ou 5.3.6
288 parce qu'il est possible d'entrer plusieurs
289 points dans le nombre et eval() lève une exception*/
290 try
291 {
292 retval = eval(value);
293 } catch (e)
294 {
295 return parseFloat(value);
296 }
297 /*pour gérer les divisions par 0*/
298 if (retval == Infinity)
299 {
300 return 0;
301 } else
302 {
303 return retval;
304 }
305 } else {
306 return 0;
307 }
308}
309/**
310 * format the number change comma to point
311 *@param HTML obj
312 */
313function format_number(obj, p_prec)
314{
315 var precision = 2;
316 if (p_prec === undefined)
317 {
318 precision = 2;
319 } else {
320 precision = p_prec;
321 }
322 var value = obj.value;
323 value = value.replace(/ /g, '');
324 value = value.replace(/,/g, '.');
325
326
327 value=compute_number(value);
328
329 value = parseFloat(value);
330 if (isNaN(value))
331 {
332 value = 0;
333 }
334 var arrondi = Math.pow(10, precision);
335
336 value = Math.round(value * arrondi) / arrondi;
337
338 $(obj).value = value;
339}
340
341/**
342 * Replace slash , space and minus by dot
343 * @param p_object DOM Element date to check
344 */
345function format_date(p_object)
346{
347 p_object.value=p_object.value.replace(/\//g,'.');
348 p_object.value=p_object.value.replace(/-/g,'.');
349 p_object.value=p_object.value.replace(/ /g,'.');
350 p_object.value=p_object.value.replace(/\.\./g,'.');
351 var tmp_value = p_object.value;
352 a_split=tmp_value.split('.');
353 if (a_split[2] && a_split[2].match(/[0-9]{2}/) && a_split[2].length==2) {
354 a_split[2]="20"+a_split[2];
355 p_object.value=a_split[0]+"."+a_split[1]+"."+a_split[2];
356 }
357 var nMonth=parseFloat(a_split[1])-1;
358 var ma_date = new Date(a_split[2], nMonth, a_split[0]);
359 if(ma_date.getFullYear()==a_split[2] && ma_date.getMonth()==nMonth && ma_date.getDate() == a_split[0]){
360 return;
361 } else {
362 new Effect.Highlight(p_object.id,{startcolor:"#ff0000"});
363 p_object.value="";
364 }
365
366
367}
368/**
369 * check if the object is hidden or show and perform the opposite,
370 * show the hidden obj or hide the shown one. With display : flex,
371 *@param name of the object
372 * @param button id of the button
373 * @param rotate : if true with rotate the object of p_button otherwise
374 */
375function toggleHideShow(p_obj, p_button,rotate)
376{
377 var div_obj=g(p_obj);
378 var stat = div_obj.style.display;
379
380 var str = ( g(p_button))?g(p_button).value:"";
381
382 if (stat === 'none')
383 {
384 // specific for the DIV id search_form
385 if( div_obj.id=='search_form') { show(p_obj); } else { $(p_obj).show()}
386 str = str.replace(/Afficher/, content[62]);
387 g(p_button).value = str;
388 } else
389 {
390 // specific for the DIV di search_form
391 if(!div_obj.id=='search_form') { hide(p_obj); } else { $(p_obj).hide()}
392 str = str.replace(/Cacher/, content[63]);
393 g(p_button).value = str;
394 }
395 if ( ! rotate ) return;
396 if ( stat == "none") {
397 g(p_button).addClassName ("icon-up-open-1")
398 g(p_button).removeClassName(" icon-down-open-2")
399 } else {
400 g(p_button).removeClassName("icon-up-open-1")
401 g(p_button).addClassName(" icon-down-open-2")
402
403 }
404
405}
406/**
407 * open popup with the search windows
408 *@param p_dossier the dossier where to search
409 *@param p_style style of the detail value are E for expert or S for simple
410 */
411function popup_recherche(p_dossier)
412{
413 var w = window.open("recherche.php?gDossier=" + p_dossier + "&ac=SEARCH", '', 'statusbar=no,scrollbars=yes,toolbar=no');
414 w.focus();
415}
416/**
417 * replace the special characters (><'") by their HTML representation
418 *@return a string without the offending char.
419 */
420function unescape_xml(code_html)
421{
422 code_html = code_html.replace(/\&lt;/, '<');
423 code_html = code_html.replace(/\&gt;/, '>');
424 code_html = code_html.replace(/\&quot;/, '"');
425 code_html = code_html.replace(/\&apos;/, "'");
426 code_html = code_html.replace(/\&amp;/, '&');
427 return code_html;
428}
429/**
430 * Firefox splits the XML into 4K chunk, so to retrieve everything we need
431 * to get the different parts thanks textContent
432 *@param xmlNode a node (result of var data = =answer.getElementsByTagName('code'))
433 *@return all the content of the XML node
434 */
435function getNodeText(xmlNode)
436{
437 if (!xmlNode)
438 return '';
439 if (typeof (xmlNode.textContent) != "undefined")
440 {
441 return xmlNode.textContent;
442 }
443 if (xmlNode.firstChild && xmlNode.firstChild.nodeValue)
444 return xmlNode.firstChild.nodeValue;
445 return "";
446}
447/**
448 * change the periode in the calendar of the dashboard
449 *@param object select
450 */
451function change_month(obj)
452{
453 var action = new Ajax.Request(
454 "ajax_misc.php",
455 {
456 method: 'get',
457 parameters: {gDossier: obj.gDossier, op: 'cal', "per": obj.value, t: obj.type_display, notitle: obj.notitle},
458 onFailure: ajax_misc_failure,
459 onSuccess: success_misc
460 }
461 );
462
463}
464/**
465 * basic answer to ajax on success, it will fill the DOMID code with
466 * the code. In that case, you need to create the object before the Ajax.Request
467 *The difference with success box is that
468 *@see add_div removeDiv success_box is that the width and height are not changed ajax_misc.php
469 *@param code is the ID of the object containing the html (div, button...)
470 *@param value is the html code, with it you fill the ctl element
471 */
472
473function success_misc(req)
474{
475 try
476 {
477 var answer = req.responseXML;
478 var html = answer.getElementsByTagName('code');
479 if (html.length === 0)
480 {
481 var rec = req.responseText;
482 alert_box('erreur :' + rec);
483 }
484 var nodeXml = html[0];
485 var code_html = getNodeText(nodeXml);
486 code_html = unescape_xml(code_html);
487 $("user_cal").innerHTML = code_html;
488 } catch (e)
489 {
490 alert_box(e.message);
491 }
492 try
493 {
494 code_html.evalScripts();
495 } catch (e)
496 {
497 alert_box(content[53] + "\n" + e.message);
498 }
499
500
501}
502function loading()
503{
504 var str='<div class="loading_msg"></div>';
505 str+='<div class="loading_msg"></div>';
506 str+='<div class="loading_msg"></div>';
507 str+='<div class="loading_msg"></div>';
508 str+='<div class="loading_msg"></div>';
509
510 return str;
511}
512
513function ajax_misc_failure()
514{
515 alert_box(content[53]);
516}
517/**
518 * remove a document_modele
519 */
520function cat_doc_remove(p_dt_id, p_dossier)
521{
522 var queryString = "gDossier=" + p_dossier + "&op=rem_cat_doc" + "&dt_id=" + p_dt_id;
523 var action = new Ajax.Request(
524 "ajax_misc.php", {method: 'get',
525 parameters: queryString,
526 onFailure: ajax_misc_failure,
527 onSuccess: function (req)
528 {
529 try
530 {
531 var answer = req.responseXML;
532 var html = answer.getElementsByTagName('dtid');
533 if (html.length === 0)
534 {
535 var rec = req.responseText;
536 alert_box('erreur <br>' + rec);
537 return;
538 }
539 var nodeXML = html[0];
540 var row_id = getNodeText(nodeXML);
541 if (row_id === 'nok')
542 {
543 var message_node = answer.getElementsByTagName('message');
544 var message_text = getNodeText(message_node[0]);
545 alert_box('erreur <br>' + message_text);
546 return;
547 }
548 $('row' + row_id).style.textDecoration = "line-through";
549 $('X' + row_id).style.display = 'none';
550 $('M' + row_id).style.display = 'none';
551 } catch (e)
552 {
553 alert_box(e.message);
554 }
555 }
556 }
557 );
558}
559/**
560 * change a document_modele
561 */
562function cat_doc_change(p_dt_id, p_dossier)
563{
564 var queryString = "gDossier=" + p_dossier + "&op=mod_cat_doc" + "&dt_id=" + p_dt_id;
565 var nTop = calcy(posY);
566 var nLeft = "200px";
567 var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:50em;height:auto";
568
569 removeDiv('change_doc_div');
570 waiting_box();
571 var action = new Ajax.Request(
572 "ajax_misc.php",
573 {
574 method: 'get', parameters: queryString,
575 onFailure: ajax_misc_failure,
576 onSuccess: function (req) {
577 remove_waiting_box();
578 add_div({id: 'change_doc_div', style: str_style, cssclass: 'inner_box', drag: "1"});
579 $('change_doc_div').innerHTML = req.responseText;
580
581 }
582 }
583 );
584}
585
586/**
587 * display the popup with vat and explanation
588 *@param obj with 4 attributes gdossier, ctl,popup
589 *@param p_function_callback callback function to be called after,
590 */
591function popup_select_tva(obj,p_function_callback)
592{
593 try
594 {
595 if ($('tva_select')) {
596 removeDiv('tva_select');
597 }
598
599 var queryString = "gDossier=" + obj.gDossier + "&op=dsp_tva" + "&ctl=" + obj.ctl + '&popup=' + 'tva_select';
600 if (obj.jcode)
601 queryString += '&code=' + obj.jcode;
602 if (obj.compute)
603 queryString += '&compute=' + obj.compute;
604 if (obj.filter)
605 queryString += '&filter=' + obj.filter;
606
607 var action = new Ajax.Request(
608 "ajax_misc.php",
609 {method: 'get',
610 parameters: queryString,
611 onFailure: ajax_misc_failure,
612 onSuccess: function (req)
613 {
614 try
615 {
616 var answer = req.responseXML;
617 var popup = answer.getElementsByTagName('popup');
618 if (popup.length === 0)
619 {
620 var rec = req.responseText;
621 alert_box('erreur :' + rec);
622 }
623 var html = answer.getElementsByTagName('code');
624
625 var name_ctl = popup[0].firstChild.nodeValue;
626 var nodeXml = html[0];
627 var code_html = getNodeText(nodeXml);
628 code_html = unescape_xml(code_html);
629
630 var nTop = posY - 200;
631 var nLeft = "15%";
632 var str_style = "top:" + nTop + "px;left:" + nLeft + ";right:" + nLeft + ";width:55em;height:auto";
633
634 var popup = {'id': 'tva_select', 'cssclass': 'inner_box', 'style': str_style, 'html': code_html, 'drag': false};
635 add_div(popup);
636 $('lk_tva_select_table').focus();
637 sorttable.makeSortable($('tva_select_table'));
638 if ( p_function_callback) {
639 p_function_callback.call(null);
640 }
641 } catch (e)
642 {
643 alert_box("success_popup_select_tva " + e.message);
644 }
645 }
646 }
647 );
648 } catch (e)
649 {
650 alert_box("popup_select_tva " + e.message);
651 }
652}
653
654
655/**
656 * display the popup with vat and explanation
657 *@param obj with 4 attributes gdossier, ctl,popup
658 */
659function set_tva_label(obj)
660{
661 try
662 {
663 var queryString = "gDossier=" + obj.gDossier + "&op=label_tva" + "&id=" + obj.value;
664 if (obj.jcode)
665 queryString += '&code=' + obj.jcode;
666 var action = new Ajax.Request(
667 "ajax_misc.php",
668 {method: 'get',
669 parameters: queryString,
670 onFailure: ajax_misc_failure,
671 onSuccess: success_set_tva_label
672 }
673 );
674 } catch (e)
675 {
676 alert_box("set_tva_label " + e.message);
677 }
678}
679/**
680 * display the popup with vat and explanations
681 *@param string req answer from ajax
682 */
683function success_set_tva_label(req)
684{
685 try
686 {
687 var answer = req.responseXML;
688 var code = answer.getElementsByTagName('code');
689 var value = answer.getElementsByTagName('value');
690
691 if (code.length === 0)
692 {
693 var rec = req.responseText;
694 alert_box('erreur :' + rec);
695 }
696
697 var label_code = code[0].firstChild.nodeValue;
698 var label_value = value[0].firstChild.nodeValue;
699 set_value(label_code, label_value);
700 } catch (e)
701 {
702 alert_box("success_set_tva_label " + e.message);
703 }
704
705}
706
707/**
708 * Create a div without showing it
709 * @param {type} obj
710 * the attributes are
711 * - style to add style
712 * - id to add an id
713 * - cssclass to add a class
714 * - html is the content
715 * - drag is the div can be moved
716 * @returns html dom element
717 * @see add_div
718 */
719function create_div(obj)
720{
721 try
722 {
723 var top = document;
724 var elt = null;
725 if (!$(obj.id)) {
726 elt = top.createElement('div');
727 } else {
728 elt = $(obj.id);
729 }
730 if (obj.id)
731 {
732 elt.setAttribute('id', obj.id);
733 }
734 if (obj.style)
735 {
736 if (elt.style.setAttribute)
737 { /* IE7 bug */
738 elt.style.setAttribute('cssText', obj.style);
739 } else
740 { /* good Browser */
741 elt.setAttribute('style', obj.style);
742 }
743 }
744 if (obj.cssclass)
745 {
746 elt.setAttribute('class', obj.cssclass); /* FF */
747 elt.setAttribute('className', obj.cssclass); /* IE */
748 }
749 if (obj.html)
750 {
751 elt.innerHTML = obj.html;
752 }
753
754 var bottom_div = document.body;
755 elt.hide();
756 bottom_div.appendChild(elt);
757
758 /* if ( obj.effect && obj.effect != 'none' ) { Effect.Grow(obj.id,{direction:'top-right',duration:0.1}); }
759 else if ( ! obj.effect ){ Effect.Grow(obj.id,{direction:'top-right',duration:0.1}); }*/
760 if (obj.drag)
761 {
762 aDraggableElement[obj.id] = new Draggable(obj.id, {starteffect: function ()
763 {
764 new Effect.Highlight(obj.id, {scroll: window, queue: 'end'});
765 }}
766 );
767
768
769 }
770 return elt;
771 } catch (e)
772 {
773 error_message("create_div " + e.message);
774 }
775}
776/**
777 * add dynamically a object for AJAX
778 *@param obj.
779 * the attributes are
780 * - style to add style
781 * - id to add an id
782 * - cssclass to add a class
783 * - html is the content
784 * - drag is the div can be moved
785 */
786function add_div(obj)
787{
788 try {
789 var elt = create_div(obj);
790 /* elt.setStyle({visibility:'visible'}); */
791 elt.style.visibility = 'visible';
792 elt.show();
793 return elt;
794 } catch (e)
795 {
796 alert_box("add_div " + e.message);
797 }
798}
799/**
800 * remove a object created with add_div
801 * @param elt id of the elt
802 */
803function removeDiv(elt)
804{
805 if (g(elt))
806 {
807 document.body.removeChild(g(elt));
808 }
809 // if reloaded if asked the window will be reloaded when
810 // the box is closed
811 if (ask_reload === 1)
812 {
813 // avoid POST window.location = window.location.href;
814 window.location.reload();
815 }
816}
817function waiting_node()
818{
819 $('info_div').innerHTML = 'Un instant';
820 $('info_div').style.display = "block";
821}
822/**
823 *show a box while loading
824 *must be remove when ajax is successfull
825 * the id is wait_box
826 */
827function waiting_box()
828{
829 var obj = {
830 id: 'wait_box', html: loading()+'<p>' + content[65] + '</p>'
831 };
832 var y = fixed_position(10, 250)
833 obj.style = y + ";width:20%;margin-left:40%;";
834 if ($('wait_box')) {
835 removeDiv('wait_box');
836 }
837 waiting_node();
838 add_div(obj);
839
840
841}
842/**
843 * call add_div to add a DIV and after call the ajax
844 * the queryString, the callback for function for success and error management
845 * the method is always GET
846 *@param obj, the mandatory attributes are
847 * - obj.qs querystring
848 * - obj.js_success callback function in javascript for handling the xml answer
849 * - obj.js_error callback function for error
850 * - obj.callback the php file to call
851 * - obj.fixed optional let you determine the position, otherwise works like IPopup
852 *@see add_div IBox
853 */
854function show_box(obj)
855{
856 add_div(obj);
857 if (!obj.fixed)
858 {
859 g(obj.id).style.top = calcy(40) + "px";
860 show(obj.id);
861 } else
862 {
863 show(obj.id);
864 }
865
866 var action = new Ajax.Request(
867 obj.callback,
868 {
869 method: 'GET',
870 parameters: obj.qs,
871 onFailure: eval(obj.js_error),
872 onSuccess: eval(obj.js_success)
873 });
874}
875/**
876 * receive answer from ajax and just display it into the IBox
877 * XML must contains at least 2 fields : ctl is the ID of the IBOX and
878 * code is the HTML to put in it
879 *@see fill_box
880 */
881function success_box(req, json)
882{
883 try
884 {
885 var answer = req.responseXML;
886 var a = answer.getElementsByTagName('ctl');
887 var html = answer.getElementsByTagName('code');
888 if (a.length === 0)
889 {
890 var rec = req.responseText;
891 alert_box(content[48] + rec);
892 }
893 var name_ctl = a[0].firstChild.nodeValue;
894 var code_html = getNodeText(html[0]);
895
896 code_html = unescape_xml(code_html);
897 g(name_ctl).innerHTML = code_html;
898 g(name_ctl).style.height = 'auto';
899
900 if (name_ctl == 'popup')
901 g(name_ctl).style.width = 'auto';
902 } catch (e)
903 {
904 alert_box("success_box" + e.message);
905 }
906 try
907 {
908 code_html.evalScripts();
909 } catch (e)
910 {
911 alert_box(content[53] + "\n" + e.message);
912 }
913}
914
915function error_box()
916{
917 alert_box(content[53]);
918}
919/**
920 * show the ledger choice
921 */
922function show_ledger_choice(json_obj)
923{
924 try
925 {
926 waiting_box();
927 var i = 0;
928 var query = "gDossier=" + json_obj.dossier + '&type=' + json_obj.type + '&div=' + json_obj.div + '&op=ledger_show';
929 query = query + '&nbjrn=' + $(json_obj.div + 'nb_jrn').value;
930 query = query + '&all_type=' + json_obj.all_type;
931 for (i = 0; i < $(json_obj.div + 'nb_jrn').value; i++) {
932 query = query + "&r_jrn[]=" + $(json_obj.div + 'r_jrn[' + i + ']').value;
933 }
934 query = encodeURI(query);
935 var action = new Ajax.Request(
936 "ajax_misc.php",
937 {method: 'get',
938 parameters: query,
939 onFailure: ajax_misc_failure,
940 onSuccess: function (req, json) {
941 try {
942 if ( req.responseText === 'NOCONX') { reconnect();return;}
943 var obj = {
944 id: json_obj.div + 'jrn_search',
945 cssclass: 'inner_box',
946 style: ';position:absolute;width:auto;z-index:20;margin-left:20%',
947 drag: 1
948 };
949 //var y=calcy(posY);
950 var y = posY;
951
952 obj.style = "top:" + y + 'px;' + obj.style;
953 /* if ( json_obj.class )
954 {
955 obj.cssclass=json_obj.class;
956 }*/
957 add_div(obj);
958
959
960 var answer = req.responseXML;
961 var a = answer.getElementsByTagName('ctl');
962 var html = answer.getElementsByTagName('code');
963 if (a.length === 0) {
964 var rec = req.responseText;
965 alert_box('erreur :' + rec);
966 }
967 var name_ctl = a[0].firstChild.nodeValue;
968 var code_html = getNodeText(html[0]);
969
970 code_html = unescape_xml(code_html);
971 remove_waiting_box();
972 g(obj.id).innerHTML = code_html;
973
974 } catch (e) {
975 alert_box("show_ledger_callback" + e.message);
976 }
977 try {
978 code_html.evalScripts();
979 } catch (e) {
980 alert_box(content[53] + "\n" + e.message);
981 }
982
983 }
984
985 }
986 );
987 } catch (e) {
988 alert_box('show_ledger_choice' + e.message);
989 }
990}
991/**
992 * hide the ledger choice
993 */
994function hide_ledger_choice(p_frm_search)
995{
996 try
997 {
998 var nb = $(p_frm_search).nb_jrn.value;
999 var div = "";
1000 if ($(p_frm_search).div) {
1001 div = $(p_frm_search).div.value;
1002 }
1003 var i = 0;
1004 var str = "";
1005 var name = "";
1006 var n_name = "";
1007 var sel = 0;
1008 for (i = 0; i < nb; i++) {
1009 n_name = div + "r_jrn[" + sel + "]";
1010 name = div + "r_jrn" + i;
1011 if ($(name).checked) {
1012 str += '<input type="hidden" id="' + n_name + '" name="' + n_name + '" value="' + $(name).value + '">';
1013 sel++;
1014 }
1015 }
1016 str += '<input type="hidden" name="' + div + 'nb_jrn" id="' + div + 'nb_jrn" value="' + sel + '">';
1017 $('ledger_id' + div).innerHTML = str;
1018 removeDiv(div + 'jrn_search');
1019 return false;
1020 } catch (e) {
1021 alert_box('hide_ledger_choice' + e.message);
1022 return false;
1023 }
1024
1025}
1026/**
1027 * show the cat of ledger choice
1028 */
1029function show_cat_choice()
1030{
1031 g('div_cat').style.visibility = 'visible';
1032}
1033/**
1034 * hide the cat of ledger choice
1035 */
1036function hide_cat_choice()
1037{
1038 g('div_cat').style.visibility = 'hidden';
1039}
1040/**
1041 * add a row for the forecast item
1042 */
1043function for_add_row(tableid)
1044{
1045 style = 'class="input_text"';
1046 var mytable = g(tableid).tBodies[0];
1047 var nNumberRow = mytable.rows.length;
1048 var oRow = mytable.insertRow(nNumberRow);
1049 var rowToCopy = mytable.rows[1];
1050 var nNumberCell = rowToCopy.cells.length;
1051 var nb = g("nbrow");
1052 var oNewRow = mytable.insertRow(nNumberRow);
1053 for (var e = 0; e < nNumberCell; e++)
1054 {
1055 var newCell = oRow.insertCell(e);
1056 var tt = rowToCopy.cells[e].innerHTML;
1057 new_tt = tt.replace(/an_cat0/g, "an_cat" + nb.value);
1058 new_tt = new_tt.replace(/an_cat_acc0/g, "an_cat_acc" + nb.value);
1059 new_tt = new_tt.replace(/an_qc0/g, "an_qc" + nb.value);
1060 new_tt = new_tt.replace(/an_label0/g, "an_label" + nb.value);
1061 new_tt = new_tt.replace(/month0/g, "month" + nb.value);
1062 new_tt = new_tt.replace(/an_cat_amount0/g, "an_cat_amount" + nb.value);
1063 new_tt = new_tt.replace(/an_deb0/g, "an_deb" + nb.value);
1064 newCell.innerHTML = new_tt;
1065 new_tt.evalScripts();
1066 }
1067 $("an_cat_acc" + nb.value).value = "";
1068 $("an_qc" + nb.value).value = "";
1069 $("an_label" + nb.value).value = "";
1070 $("an_cat_amount" + nb.value).value = "0";
1071 nb.value++;
1072}
1073/**
1074 * toggle all the checkbox in a given form
1075 * @param form_id id of the form
1076 */
1077function toggle_checkbox(form_id)
1078{
1079 var form = g(form_id);
1080 for (var i = 0; i < form.length; i++)
1081 {
1082 var e = form.elements[i];
1083 if (e.type === 'checkbox')
1084 {
1085 if (e.checked === true)
1086 {
1087 e.checked = false;
1088 } else
1089 {
1090 e.checked = true;
1091 }
1092 }
1093 }
1094}
1095/**
1096 * select all the checkbox in a given form
1097 * @param form_id id of the form
1098 */
1099function select_checkbox(form_id)
1100{
1101 var form = $(form_id);
1102 for (var i = 0; i < form.length; i++)
1103 {
1104 var e = form.elements[i];
1105 if (e.type === 'checkbox')
1106 {
1107 e.checked = true;
1108 }
1109 }
1110}
1111/**
1112 * select all the checkbox in a given form if the specific attribute
1113 * has the given value
1114 * @param form_id id of the form
1115 * @param attribute name
1116 * @param attribute value
1117 */
1118function select_checkbox_attribute(form_id, p_attribute_name, p_attribute_value)
1119{
1120 var form = $(form_id);
1121 for (var i = 0; i < form.length; i++)
1122 {
1123 var e = form.elements[i];
1124 if (e.type === 'checkbox' && e.getAttribute(p_attribute_name) == p_attribute_value)
1125 {
1126 e.checked = true;
1127 }
1128 }
1129}
1130/**
1131 * unselect all the checkbox in a given form
1132 * @param form_id id of the form
1133 */
1134function unselect_checkbox(form_id)
1135{
1136 var form = $(form_id);
1137 for (var i = 0; i < form.length; i++)
1138 {
1139 var e = form.elements[i];
1140 if (e.type === 'checkbox')
1141 {
1142 e.checked = false;
1143 }
1144 }
1145}
1146/**
1147 * show the calculator
1148 */
1149function show_calc()
1150{
1151 if (g('calc1'))
1152 {
1153 this.document.getElementById('inp').value = "";
1154 this.document.getElementById('inp').focus();
1155 return;
1156 }
1157 var sid = 'calc1';
1158 var shtml = '';
1159 shtml += "<div class=\"bxbutton\">";
1160 shtml += '<a class="icon" onclick="pin(\'calc1\')" id="pin_calc1">&#xf047;</a> <a onclick="removeDiv(\'calc1\');" href="javascript:void(0)" title="" class="icon">&#10761;</a>';
1161 shtml += "</div>";
1162 shtml += ' <h2 class="title">' + content[66] + '</h2>';
1163 shtml += '<form name="calc_line" method="GET" onSubmit="cal();return false;" >' + content[68] + '<input class="input_text" type="text" id="inp" name="calculator"> <input type="button" value="Efface" class="button" onClick="Clean();return false;" > <input type="button" value="Efface historique" class="button" onClick="CleanHistory();return false;" > <input type="button" class="button" value="Fermer" onClick="removeDiv(\'calc1\')" >';
1164 shtml += '</form><span class="highligth" style="display:block" id="sub_total"> ' + content[67] + ' </span><span style="display:block" id="listing"> </span>';
1165
1166 var obj = {id: sid, html: shtml,
1167 drag: false, style: 'z-index:98'
1168 };
1169 add_div(obj);
1170 this.document.getElementById('inp').focus();
1171}
1172function display_periode(p_dossier, p_id)
1173{
1174
1175 try
1176 {
1177 var queryString = "gDossier=" + p_dossier + "&op=input_per" + "&p_id=" + p_id;
1178 var popup = {'id': 'mod_periode', 'cssclass': 'inner_box', 'html': loading(), 'style': 'width:30em', 'drag': true};
1179 if (!$('mod_periode')) {
1180 add_div(popup);
1181 }
1182 var action = new Ajax.Request(
1183 "ajax_misc.php",
1184 {method: 'get',
1185 parameters: queryString,
1186 onFailure: ajax_misc_failure,
1187 onSuccess: success_display_periode
1188 }
1189 );
1190 $('mod_periode').style.top = (posY - 70) + "px";
1191 $('mod_periode').style.left = (posX - 70) + "px";
1192 } catch (e)
1193 {
1194 alert_box("display_periode " + e.message);
1195 }
1196
1197}
1198function success_display_periode(req)
1199{
1200 try
1201 {
1202
1203 var answer = req.responseXML;
1204 var html = answer.getElementsByTagName('data');
1205
1206 if (html.length === 0)
1207 {
1208 var rec = req.responseText;
1209 alert_box('erreur :' + rec);
1210 }
1211
1212 var code_html = getNodeText(html[0]);
1213 code_html = unescape_xml(code_html);
1214
1215 $('mod_periode').innerHTML = code_html;
1216 } catch (e)
1217 {
1218 alert_box("success_display_periode".e.message);
1219 }
1220 try
1221 {
1222 code_html.evalScripts();
1223 } catch (e)
1224 {
1225 alert_box(content[53] + "\n" + e.message);
1226 }
1227
1228}
1229function save_periode(obj)
1230{
1231 try
1232 {
1233 var queryString = $(obj).serialize() + "&op=save_per";
1234
1235 var action = new Ajax.Request(
1236 "ajax_misc.php",
1237 {method: 'post',
1238 parameters: queryString,
1239 onFailure: ajax_misc_failure,
1240 onSuccess: success_display_periode
1241 }
1242 );
1243
1244 } catch (e)
1245 {
1246 alert_box("display_periode " + e.message);
1247 }
1248
1249 return false;
1250}
1251/**
1252 * basic answer to ajax on success, it will fill the ctl with
1253 * the code. In that case, you need to create the object before the Ajax.Request
1254 *The difference with success box is that
1255 *@see add_div removeDiv success_box is that the width and height are not changed
1256 *@param ctl is the ID of the object containing the html (div, button...)
1257 *@param code is the html code, with it you fill the ctl element
1258 */
1259function fill_box(req)
1260{
1261 try {
1262 if (req.responseText=='NOCONX') { reconnect(); return;}
1263 remove_waiting_box();
1264
1265 var answer = req.responseXML;
1266 var a = answer.getElementsByTagName('ctl');
1267 var html = answer.getElementsByTagName('code');
1268 if (a.length === 0) {
1269 var rec = req.responseText;
1270 alert_box('erreur :' + rec);
1271 }
1272 var name_ctl = a[0].firstChild.nodeValue;
1273 var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
1274 code_html = unescape_xml(code_html);
1275 $(name_ctl).innerHTML = code_html;
1276 } catch (e) {
1277 alert_box(e.message);
1278 if (console) {
1279 console.error(e);
1280 console.error("log answer = " + req.responseText);
1281 }
1282 }
1283 try {
1284 code_html.evalScripts();
1285 } catch (e) {
1286 if (console) {
1287 console.error(e);
1288 console.error("log answer = " + req.responseText);
1289 }
1290 alert_box(content[53] + "\n" + e.message);
1291 }
1292
1293
1294}
1295/**
1296 *display a popin to let you modified a predefined operation
1297 *@param dossier_id
1298 *@param od_id from table op_predef
1299 */
1300function mod_predf_op(dossier_id, od_id,p_ledger)
1301{
1302 var target = "mod_predf_op";
1303 removeDiv(target);
1304 var str_style = "top:10%;left:2%;width:96%";
1305
1306 var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
1307
1308 add_div(div);
1309
1310 var qs = "gDossier=" + dossier_id + '&op=mod_predf&id=' + od_id+'&ledger_id='+p_ledger;
1311
1312 var action = new Ajax.Request('ajax_misc.php',
1313 {
1314 method: 'get',
1315 parameters: qs,
1316 onFailure: null,
1317 onSuccess: fill_box
1318 }
1319 );
1320
1321}
1322
1323function save_predf_op(obj)
1324{
1325 waiting_box();
1326 var querystring = $(obj).serialize() + '&op=save_predf';
1327 // Create a ajax request to get all the person
1328 var action = new Ajax.Request('ajax_misc.php',
1329 {
1330 method: 'post',
1331 parameters: querystring,
1332 onFailure: null,
1333 onSuccess: refresh_window
1334 }
1335 );
1336
1337 return false;
1338}
1339
1340/**
1341 *ctl_concern is the widget to update
1342 *amount_id is either a html obj. or an amount and the field tiers if given
1343 * @param {type} dossier
1344 * @param {type} ctl_concern
1345 * @param {float or string} amount_id Amount or DOM Id of the element containing the amount
1346 * @param {float} ledger
1347 * @param {type} p_id_targetDom Element (div) where to display the search result
1348 * @param p_tiers id of the Tiers
1349 * @returns {undefined}
1350 */
1351function search_reconcile(dossier, ctl_concern, amount_id, ledger, p_id_target, p_tiers)
1352{
1353 if (amount_id === undefined)
1354 {
1355 amount_id = 0;
1356 } else if ($(amount_id))
1357 {
1358 if ($(amount_id).value)
1359 {
1360 amount_id = $(amount_id).value;
1361 } else if
1362 ($(amount_id).innerHTML) {
1363 amount_id = $(amount_id).innerHTML;
1364 }
1365 }
1366 var tiers = "";
1367 if (p_tiers)
1368 tiers = p_tiers;
1369 var target = "";
1370 if (p_id_target != "") {
1371 target = p_id_target;
1372 } else {
1373 target = "search" + layer;
1374 removeDiv(target);
1375 }
1376 var str_style = fixed_position(77, 99);
1377 str_style += ";width:92%;overflow:auto;";
1378 waiting_box();
1379 var hide_operation = $(ctl_concern).getAttribute("hide_operation");
1380 var single_operation = $(ctl_concern).getAttribute("single_operation");
1381
1382 var param_send = {gDossier: dossier,
1383 ctlc: ctl_concern,
1384 op: 'search_op',
1385 ac: 'JSSEARCH',
1386 amount_id: amount_id,
1387 ledger: ledger,
1388 target: target,
1389 tiers: tiers,
1390 hide_operation: hide_operation,
1391 single_operation:single_operation
1392 };
1393
1394 var qs = encodeJSON(param_send);
1395
1396 var action = new Ajax.Request('ajax_misc.php',
1397 {
1398 method: 'get',
1399 parameters: qs,
1400 onFailure: null,
1401 onSuccess: function (req) {
1402 remove_waiting_box();
1403 var div = {id: target, cssclass: 'inner_box', style: str_style, drag: 0};
1404 add_div(div);
1405 $(target).innerHTML = req.responseText;
1406 req.responseText.evalScripts();
1407 }
1408 }
1409 );
1410}
1411/**
1412 * search in a popin obj if the object form
1413 */
1414function search_operation(obj)
1415{
1416 try {
1417 var dossier = g('gDossier').value;
1418 waiting_box();
1419 var target = "search" + layer;
1420 if ($(obj)["target"]) {
1421 target = $(obj)["target"].value;
1422 }
1423 var qs = Form.serialize('search_form_ajx') + "&op=search_op";
1424 var action = new Ajax.Request('ajax_misc.php',
1425 {
1426 method: 'get',
1427 parameters: qs,
1428 onFailure: null,
1429 onSuccess: function (req) {
1430 remove_waiting_box();
1431 $(target).innerHTML = req.responseText;
1432 req.responseText.evalScripts();
1433 }
1434 }
1435 );
1436 } catch (e)
1437 {
1438 remove_waiting_box();
1439 alert_box(e.message);
1440 }
1441}
1442/**
1443 * Update the field e_concerned, from class_iconcerned
1444 * Value is the field where to put the quick-code but only if one checkbox has been
1445 * selected
1446 * @param {type} obj
1447 * @returns {undefined}
1448 */
1449function set_reconcile(obj)
1450{
1451
1452 try
1453 {
1454 var ctlc = obj.elements['ctlc'];
1455 var tiers = obj.elements['tiers'];
1456 if (!obj.elements['target'])
1457 return;
1458 var target = obj.elements['target'].value;
1459 var single_operation = obj.elements['single_operation'].value;
1460 for (var e = 0; e < obj.elements.length; e++)
1461 {
1462
1463 var elmt = obj.elements[e];
1464 if (elmt.type === "checkbox")
1465 {
1466 if (elmt.checked === true)
1467 {
1468 var str_name = elmt.name;
1469 var nValue = str_name.replace("jr_concerned", "");
1470 if ($(ctlc.value).value != '') {
1471 $(ctlc.value).value += ',';
1472
1473 } else {
1474
1475 if (tiers && tiers.value != "") {
1476 $(tiers.value).value = elmt.value;
1477 /* set the name */
1478 new Ajax.Request("fid.php",{
1479 method:"get",
1480 parameters:{gDossier:obj.elements['gDossier'].value,"FID":elmt.value},
1481 onSuccess:function(req){
1482 // find the row number
1483 //tiers.value = e_othern
1484 var tiers_card=new String(tiers.value);
1485 var num=tiers_card.replace("e_other","");
1486 var tiers_name_id="e_other"+"_name"+num;
1487 var answer = req.responseText.evalJSON();
1488 $(tiers_name_id).value=answer["name"];
1489 }
1490 });
1491 }
1492 }
1493 if (single_operation==0) {
1494 $(ctlc.value).value += nValue;
1495 } else {
1496 $(ctlc.value).value = nValue;
1497
1498 }
1499 }
1500 }
1501 }
1502 removeDiv(obj.elements['target'].value);
1503 } catch (e)
1504 {
1505 alert_box(e.message)
1506 }
1507}
1508function remove_waiting_node()
1509{
1510 $('info_div').innerHTML = "";
1511 $('info_div').style.display = "none";
1512
1513}
1514function remove_waiting_box()
1515{
1516 if ($('wait_box')) {
1517 Effect.Fade('wait_box', {duration: 0.6});
1518 }
1519
1520 remove_waiting_node();
1521}
1522/**
1523 * Show all the detail of a profile : Menu, Management, Repository and
1524 * let the user to modify it
1525 * @param {type} gDossier
1526 * @param {type} profile_id
1527 * @returns {undefined}
1528 */
1529function get_profile_detail(gDossier, profile_id)
1530{
1531 waiting_box();
1532 var qs = "op=display_profile&gDossier=" + gDossier + "&p_id=" + profile_id + "&ctl=detail_profile";
1533 var action = new Ajax.Request('ajax_misc.php',
1534 {
1535 method: 'get',
1536 parameters: qs,
1537 onFailure: null,
1538 onSuccess: function (req) {
1539 remove_waiting_box();
1540 $('list_profile').hide();
1541 $('detail_profile').innerHTML = req.responseText;
1542 req.responseText.evalScripts();
1543 $('detail_profile').show();
1544 if (profile_id != "-1")
1545 profile_show('profile_gen_div');
1546 }
1547 }
1548 );
1549}
1550function get_profile_detail_success_obsolete(xml)
1551{
1552 remove_waiting_box();
1553
1554}
1555/**
1556 * compute the string to position a div in a fixed way
1557 * @return string
1558 */
1559function fixed_position(p_sx, p_sy)
1560{
1561 var sx = p_sx;
1562 var sy = calcy(p_sy);
1563
1564 var str_style = "top:" + sy + "px;left:" + sx + "px;position:absolute";
1565 return str_style;
1566
1567}
1568/**
1569 * compute Y even if the windows has scrolled down or up
1570 *@return the correct Y position
1571 */
1572function calcy(p_sy)
1573{
1574 var sy = p_sy;
1575 if (window.pageYOffset)
1576 {
1577 sy = window.pageYOffset + p_sy;
1578 } else
1579 {
1580 sy = document.documentElement.scrollTop + p_sy;
1581 }
1582
1583 return sy;
1584
1585}
1586/**
1587 * display a box with the menu option
1588 * @param {type} gdossier
1589 * @param {type} pm_id
1590 * @returns {undefined}
1591 */
1592function mod_menu(gdossier, pm_id)
1593{
1594 waiting_box();
1595 removeDiv('divdm' + pm_id);
1596 var qs = "op=det_menu&gDossier=" + gdossier + "&pm_id=" + pm_id + "&ctl=divdm" + pm_id;
1597 var pos = fixed_position(50, 250);
1598 var action = new Ajax.Request('ajax_misc.php',
1599 {
1600 method: 'get',
1601 parameters: qs,
1602 onFailure: null,
1603 onSuccess: function (req) {
1604 try {
1605 remove_waiting_box();
1606 add_div({id: "divdm" + pm_id, drag: 1, cssclass: "inner_box", style: pos});
1607 $('divdm' + pm_id).innerHTML = req.responseText;
1608 } catch (e) {
1609 alert_box(e.message);
1610 }
1611 }
1612 }
1613 );
1614}
1615/**
1616 * Display the submenu of a menu or a module, used in setting the menu
1617 *
1618 * @param {type} p_dossier
1619 * @param {type} p_profile
1620 * @param {type} p_dep
1621 * @returns {undefined}
1622 */
1623function display_sub_menu(p_dossier, p_profile, p_dep, p_level)
1624{
1625 waiting_box();
1626 new Ajax.Request('ajax_misc.php',
1627 {
1628 method: 'get',
1629 parameters: {op: 'display_submenu',
1630 gDossier: p_dossier,
1631 dep: p_dep,
1632 p_profile: p_profile,
1633 p_level: p_level
1634 },
1635 onSuccess: function (req) {
1636 try {
1637 remove_waiting_box();
1638 if ($('menu_table').rows.length > p_level) {
1639 $('menu_table').rows[1].remove();
1640 }
1641 $('sub' + p_dep).addClassName("selectedmenu");
1642 var new_row = document.createElement('TR');
1643 new_row.innerHTML = req.responseText;
1644 $('menu_table').appendChild(new_row);
1645 } catch (e) {
1646 alert_box(e.message);
1647 }
1648 }
1649 })
1650}
1651/**
1652 * in CFGPRO, ask to confirm before removing a submenu and its children
1653 * @param {type} p_dossier
1654 * @param {type} profile_menu_id
1655 * @returns {undefined}
1656 */
1657function remove_sub_menu(p_dossier, profile_menu_id)
1658{
1659 confirm_box(null, content[47],
1660 function () {
1661 waiting_box();
1662 new Ajax.Request('ajax_misc.php',
1663 {
1664 method: 'get',
1665 parameters: {op: 'remove_submenu', gDossier: p_dossier,
1666 p_profile_menu_id: profile_menu_id},
1667 onSuccess: function (req) {
1668 try {
1669 remove_waiting_box();
1670 $('sub' + profile_menu_id).remove();
1671 if ($('menu_table').rows.length > 1) {
1672 $('menu_table').rows[1].remove();
1673 }
1674
1675 } catch (e)
1676 {
1677 alert_box(e.message);
1678 }
1679 }
1680 }
1681 )
1682 });
1683
1684}
1685/**
1686 * add a menu to a profile, propose only the available menu
1687 * @param obj json object
1688 * - dossier : ,
1689 * - p_id : profile id ,
1690 * - type : Type of menu are "pr" for Printing "me" for plain menu
1691 * - p_level : level of menu (0 -> module,1-> top menu, 2->submenu)
1692 * - dep : the parent menu id (pm_id)
1693 *
1694 */
1695function add_menu(obj)
1696{
1697 var pdossier = obj.dossier;
1698 var p_id = obj.p_id;
1699 var p_type = obj.type;
1700
1701 waiting_box();
1702 removeDiv('divdm' + p_id);
1703 var pos = fixed_position(250, 150) + ";width:50%;";
1704 var action = new Ajax.Request('ajax_misc.php',
1705 {
1706 method: 'get',
1707 parameters: {op: 'add_menu',
1708 'gDossier': pdossier,
1709 'p_id': p_id,
1710 'ctl': 'divdm' + p_id,
1711 'type': p_type,
1712 'dep': obj.dep,
1713 'p_level': obj.p_level},
1714 onFailure: null,
1715 onSuccess: function (req) {
1716 try {
1717 remove_waiting_box();
1718 add_div({id: "divdm" + p_id, drag: 1, "cssclass": "inner_box", "style": pos});
1719 $('divdm' + p_id).innerHTML = req.responseText;
1720 } catch (e) {
1721 alert_box(e.message);
1722 }
1723 }
1724 }
1725 );
1726}
1727/**
1728 * Display a box to enter data for adding a new plugin from
1729 * the CFGMENU
1730 * @param {type} p_dossier
1731 * @returns {undefined}
1732 */
1733function add_plugin(p_dossier)
1734{
1735 waiting_box();
1736 removeDiv('divplugin');
1737 var qs = "op=add_plugin&gDossier=" + p_dossier + "&ctl=divplugin";
1738
1739 var action = new Ajax.Request('ajax_misc.php',
1740 {
1741 method: 'get',
1742 parameters: qs,
1743 onFailure: null,
1744 onSuccess: function (req) {
1745 try {
1746 remove_waiting_box();
1747 var pos = fixed_position(250, 150) + ";width:30%";
1748 add_div({id: "divplugin", drag: 1, cssclass: "inner_box", style: pos});
1749 $('divplugin').innerHTML = req.responseText;
1750 } catch (e) {
1751 alert_box(e.message);
1752 }
1753 }
1754 }
1755 );
1756}
1757/**
1758 * Modify a menu
1759 * @param {type} p_dossier
1760 * @param {type} me_code
1761 * @returns {undefined}
1762 */
1763function mod_plugin(p_dossier, me_code)
1764{
1765 waiting_box();
1766 removeDiv('divplugin');
1767 var qs = "op=mod_plugin&gDossier=" + p_dossier + "&ctl=divplugin&me_code=" + me_code;
1768
1769 var action = new Ajax.Request('ajax_misc.php',
1770 {
1771 method: 'get',
1772 parameters: qs,
1773 onFailure: null,
1774 onSuccess: function (req) {
1775 try {
1776 remove_waiting_box();
1777 var pos = fixed_position(250, 150) + ";width:30%";
1778 add_div({id: "divplugin", drag: 1, cssclass: "inner_box", style: pos});
1779 $('divplugin').innerHTML = req.responseText;
1780
1781 } catch (e) {
1782 alert_box(e.message);
1783 }
1784 }
1785 }
1786 );
1787}
1788function create_menu(p_dossier)
1789{
1790 waiting_box();
1791 removeDiv('divmenu');
1792 var qs = "op=create_menu&gDossier=" + p_dossier + "&ctl=divmenu";
1793
1794 var action = new Ajax.Request('ajax_misc.php',
1795 {
1796 method: 'get',
1797 parameters: qs,
1798 onFailure: null,
1799 onSuccess: function (req) {
1800 try {
1801 remove_waiting_box();
1802 var pos = fixed_position(250, 150) + ";width:30%";
1803 add_div({
1804 id: "divmenu",
1805 drag: 1,
1806 cssclass: "inner_box",
1807 style: pos
1808 });
1809 $('divmenu').innerHTML = req.responseText;
1810 } catch (e) {
1811 alert_box(e.message);
1812 }
1813 }
1814 }
1815 );
1816}
1817function modify_menu(p_dossier, me_code)
1818{
1819 waiting_box();
1820 removeDiv('divmenu');
1821 var qs = "op=modify_menu&gDossier=" + p_dossier + "&ctl=divmenu&me_code=" + me_code;
1822
1823 var action = new Ajax.Request('ajax_misc.php',
1824 {
1825 method: 'get',
1826 parameters: qs,
1827 onFailure: null,
1828 onSuccess: function (req) {
1829 try {
1830 remove_waiting_box();
1831 var pos = fixed_position(250, 150) + ";width:30%";
1832 add_div({
1833 id: "divmenu",
1834 drag: 1,
1835 cssclass: "inner_box",
1836 style: pos
1837 });
1838 $('divmenu').innerHTML = req.responseText;
1839
1840 } catch (e) {
1841 alert_box(e.message);
1842 }
1843 }
1844 }
1845 );
1846}
1847function get_properties(obj)
1848{
1849 var a_array = [];
1850 var s_type = "[" + typeof obj + "]";
1851 for (var m in obj)
1852 {
1853 a_array.push(m);
1854 }
1855 alert_box(s_type + a_array.join(","));
1856}
1857/**
1858 * add a line in the form for the report
1859 * @param p_dossier dossier id to connect
1860 */
1861function rapport_add_row(p_dossier)
1862{
1863 style = 'style="border: 1px solid blue;"';
1864 var table = $("rap1");
1865 var line = table.rows.length;
1866
1867 var row = table.insertRow(line);
1868 // left cell
1869 var cellPos = row.insertCell(0);
1870 cellPos.innerHTML = '<input type="text" ' + style + ' size="3" id="pos' + line + '" name="pos' + line + '" value="' + line + '">';
1871
1872 // right cell
1873 var cellName = row.insertCell(1);
1874 cellName.innerHTML = '<input type="text" ' + style + ' size="40" id="text' + line + '" name="text' + line + '">';
1875
1876 // button + formula
1877 var cellbutton = row.insertCell(2);
1878 var but_html = table.rows[1].cells[2].innerHTML;
1879 but_html = but_html.replace(/form0/g, "form" + line);
1880 cellbutton.innerHTML = but_html;
1881 but_html.evalScripts();
1882
1883 g('form' + line).value = '';
1884}
1885/**
1886 * Search an action in an inner box
1887 */
1888function search_action(dossier, ctl_concern)
1889{
1890 try
1891 {
1892 waiting_box();
1893 var dossier = g('gDossier').value;
1894
1895 var target = "search_action_div";
1896 removeDiv(target);
1897 var str_style = fixed_position(77, 99);
1898
1899 var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
1900
1901
1902 var target = {gDossier: dossier,
1903 ctlc: ctl_concern,
1904 op: 'search_action',
1905 ctl: target
1906 };
1907
1908 var qs = encodeJSON(target);
1909
1910 var action = new Ajax.Request('ajax_misc.php',
1911 {
1912 method: 'get',
1913 parameters: qs,
1914 onFailure: null,
1915 onSuccess: function (req) {
1916 try {
1917 remove_waiting_box();
1918 add_div(div);
1919 $('search_action_div').innerHTML = req.responseText;
1920 req.responseText.evalScripts();
1921 } catch (e) {
1922 alert_box(e.message);
1923 }
1924 }
1925 }
1926 );
1927 } catch (e) {
1928 alert_box(e.message);
1929 }
1930}
1931
1932function result_search_action(obj)
1933{
1934 try
1935 {
1936 var queryString = $(obj).serialize() + "&op=search_action";
1937 var action = new Ajax.Request(
1938 "ajax_misc.php",
1939 {method: 'get',
1940 parameters: queryString,
1941 onFailure: ajax_misc_failure,
1942 onSuccess: function (req) {
1943 try {
1944 remove_waiting_box();
1945 $('search_action_div').innerHTML = req.responseText;
1946 req.responseText.evalScripts();
1947 } catch (e) {
1948 alert_box(e.message);
1949 }
1950 }
1951 }
1952 )
1953
1954 } catch (e)
1955 {
1956 alert_box("display_periode " + e.message);
1957 }
1958
1959 return false;
1960}
1961
1962function set_action_related(p_obj)
1963{
1964
1965 try
1966 {
1967 var obj = $(p_obj);
1968 var ctlc = obj.elements['ctlc'];
1969
1970 for (var e = 0; e < obj.elements.length; e++)
1971 {
1972
1973 var elmt = obj.elements[e];
1974 if (elmt.type === "checkbox")
1975 {
1976 if (elmt.checked === true)
1977 {
1978 var str_name = elmt.name;
1979 var nValue = elmt.value;
1980 if ($(ctlc.value).value != '') {
1981 $(ctlc.value).value += ',';
1982 }
1983 $(ctlc.value).value += nValue;
1984 }
1985 }
1986 }
1987 removeDiv('search_action_div');
1988 return false;
1989 } catch (e)
1990 {
1991 alert_box(e.message);
1992 return false;
1993 }
1994}
1995/**
1996 * Show a form to modify or add a new repository
1997 *@param p_dossier
1998 *@param r_id : repository id
1999 */
2000function stock_repo_change(p_dossier, r_id)
2001{
2002 var queryString = "gDossier=" + p_dossier + "&op=mod_stock_repo" + "&r_id=" + r_id;
2003 var nTop = calcy(posY);
2004 var nLeft = "10.1562%";
2005 var str_style = "top:" + nTop + "px;left:" + nLeft + ";height:auto;width:auto";
2006
2007 removeDiv('change_stock_repo_div');
2008 waiting_box();
2009 var action = new Ajax.Request(
2010 "ajax_misc.php",
2011 {
2012 method: 'get', parameters: queryString,
2013 onFailure: ajax_misc_failure,
2014 onSuccess: function (req) {
2015 remove_waiting_box();
2016 add_div({id: 'change_stock_repo_div', style: str_style, cssclass: 'inner_box', drag: "1"});
2017 $('change_stock_repo_div').innerHTML = req.responseText;
2018
2019 }
2020 }
2021 );
2022}
2023function stock_inv_detail(p_dossier, p_id)
2024{
2025 var queryString = "gDossier=" + p_dossier + "&op=view_mod_stock" + "&c_id=" + p_id + "&ctl=view_mod_stock_div";
2026 var nTop = calcy(posY);
2027 var nLeft = "10%";
2028 var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:80%;";
2029
2030 removeDiv('view_mod_stock_div');
2031 waiting_box();
2032 var action = new Ajax.Request(
2033 "ajax_misc.php",
2034 {
2035 method: 'get', parameters: queryString,
2036 onFailure: ajax_misc_failure,
2037 onSuccess: function (req) {
2038 remove_waiting_box();
2039 add_div({id: 'view_mod_stock_div', style: str_style, cssclass: 'inner_box', drag: "1"});
2040 $('view_mod_stock_div').innerHTML = req.responseText;
2041 req.responseText.evalScripts();
2042 }
2043 }
2044 );
2045}
2046function show_fin_chdate(obj_id)
2047{
2048 try
2049 {
2050 var ch = $(obj_id).options[$(obj_id).selectedIndex].value;
2051 if (ch == 2) {
2052 $('chdate_ext').hide();
2053 $('thdate').show();
2054 }
2055 if (ch == 1) {
2056 $('chdate_ext').show();
2057 $('thdate').hide();
2058 }
2059 var nb = $('nb_item').value;
2060 for (i = 0; i < nb; i++) {
2061 if ($('tdchdate' + i)) {
2062 if (ch == 2) {
2063 $('tdchdate' + i).show();
2064 }
2065 if (ch == 1) {
2066 $('tdchdate' + i).hide();
2067
2068 }
2069 }
2070 }
2071 } catch (e) {
2072 alert_box(e.message);
2073 }
2074}
2075/**
2076 * tab menu for the profile parameter
2077 */
2078function profile_show(p_div)
2079{
2080 try {
2081 var div = ['profile_gen_div', 'profile_menu_div', 'profile_print_div', 'profile_gestion_div', 'profile_repo_div','profile_menu_mobile_div'];
2082 for (var r = 0; r < div.length; r++) {
2083 $(div[r]).hide();
2084 }
2085 $(p_div).show();
2086 } catch (e)
2087 {
2088 alert_box(e.message);
2089 }
2090}
2091function detail_category_show(p_div, p_dossier, p_id)
2092{
2093 $(p_div).show();
2094 waiting_box();
2095 $('detail_category_div').innerHTML = "";
2096 var queryString = "gDossier=" + p_dossier + "&id=" + p_id + "&op=fddetail";
2097 var action = new Ajax.Request(
2098 "ajax_misc.php",
2099 {
2100 method: 'get', parameters: queryString,
2101 onFailure: ajax_misc_failure,
2102 onSuccess: function (req) {
2103 remove_waiting_box();
2104 $('list_cat_div').hide();
2105 $('detail_category_div').innerHTML = req.responseText;
2106 $('detail_category_div').show();
2107 req.responseText.evalScripts();
2108 }
2109 }
2110 );
2111}
2112/**
2113 * check if the parameter is a valid a valid date or not, returns true if it is valid otherwise
2114 * false
2115 * @param p_str_date the string of the date (format DD.MM.YYYY)
2116 */
2117function check_date(p_str_date)
2118{
2119 var format = /^\d{2}\.\d{2}\.\d{4}$/;
2120 if (!format.test(p_str_date)) {
2121 return false;
2122 } else {
2123 var date_temp = p_str_date.split('.');
2124 var nMonth = parseFloat(date_temp[1]) - 1;
2125 var ma_date = new Date(date_temp[2], nMonth, date_temp[0]);
2126 if (ma_date.getFullYear() == date_temp[2] && ma_date.getMonth() == nMonth && ma_date.getDate() == date_temp[0]) {
2127 return true;
2128 } else {
2129 return false;
2130 }
2131 }
2132
2133}
2134/**
2135 * get the string in the id and check if the date is valid
2136 * @param p_id_date is the id of the element to check
2137 * @return true if the date is valid
2138 * @see check_date
2139 */
2140function check_date_id(p_id_date)
2141{
2142 var str_date = $(p_id_date).value;
2143 return check_date(str_date);
2144}
2145/**
2146 *
2147 * @param ag_id to view
2148 * @param dossier is the folder
2149 * @param modify : show the modify button values : 0 for no 1 for yes
2150 */
2151function view_action(ag_id, dossier, modify)
2152{
2153 waiting_box();
2154 layer++;
2155 id = 'action' + layer;
2156
2157 querystring = 'gDossier=' + dossier + '&op=vw_action&ag_id=' + ag_id + '&div=' + id + '&mod=' + modify;
2158 var action = new Ajax.Request(
2159 "ajax_misc.php",
2160 {
2161 method: 'get',
2162 parameters: querystring,
2163 onFailure: error_box,
2164 onSuccess: function (req) {
2165 try {
2166 if (req.responseText === 'NOCONX') { reconnect();return;}
2167 remove_waiting_box();
2168 var answer = req.responseXML;
2169 var ctl = answer.getElementsByTagName('ctl');
2170 if (ctl.length == 0) {
2171 throw 'ajax failed ctl view_action';
2172 }
2173 var ctl_txt = getNodeText(ctl[0]);
2174 var html = answer.getElementsByTagName('code');
2175 if (html.length === 0)
2176 {
2177 var rec = req.responseText;
2178 throw 'ajax failed html view_action';
2179 }
2180 var code_html = getNodeText(html[0]);
2181 code_html = unescape_xml(code_html);
2182 var pos = fixed_position(0, 50) + ";width:90%;left:5%;";
2183 add_div({
2184 id: id,
2185 cssclass: "inner_box",
2186 style: pos
2187 });
2188 $(id).innerHTML = code_html;
2189 if (ctl_txt == 'ok') {
2190 // compute detail
2191 var detail=in_child(id,"follow_up_detail");
2192 if (detail) {
2193 compute_all_ledger();
2194 }
2195
2196
2197 }
2198 code_html.evalScripts();
2199 } catch (e) {
2200 alert_box('view_action' + e.message);
2201 }
2202 }
2203 }
2204 );
2205}
2206/**
2207 * filter quickly a table
2208 * @param phrase : phrase to seach
2209 * @param _id : id of the table
2210 * @param colnr : string containing the column number where you're searching separated by a comma
2211 * @param start_row : first row (1 if you have table header)
2212 * @returns nothing
2213 * @see HtmlInput::filter_table
2214 */
2215function filter_table(phrase, _id, colnr, start_row) {
2216 $('info_div').innerHTML = content[65];
2217 $('info_div').style.display = "block";
2218 var words = $(phrase).value.toLowerCase();
2219 var table = document.getElementById(_id);
2220
2221 // if colnr contains a comma then check several columns
2222 var aCol = new Array();
2223 if (colnr.indexOf(',') >= 0) {
2224 aCol = colnr.split(',');
2225 } else {
2226 aCol[0] = colnr;
2227 }
2228 var ele;
2229 var tot_found = 0;
2230
2231 for (var r = start_row; r < table.rows.length; r++) {
2232 var found = 0;
2233 for (var col = 0; col < aCol.length; col++)
2234 {
2235 var idx = aCol[col];
2236 if (table.rows[r].cells[idx])
2237 {
2238 ele = table.rows[r].cells[idx].innerHTML.replace(/<[^>]+>/g, "");
2239 //var displayStyle = 'none';
2240 if (ele.toLowerCase().indexOf(words) >= 0) {
2241 found = 1;
2242 }
2243 }
2244
2245 }
2246 if (found === 1) {
2247 tot_found++;
2248 table.rows[r].style.display = '';
2249 } else {
2250 table.rows[r].style.display = 'none';
2251 }
2252 $('info_div').style.display = "none";
2253 $('info_div').innerHTML = "";
2254 }
2255 if (tot_found == 0) {
2256 if ($('info_' + _id)) {
2257 $('info_' + _id).innerHTML = content[69];
2258 }
2259 } else {
2260 if ($('info_' + _id)) {
2261 $('info_' + _id).innerHTML = " ";
2262 }
2263 }
2264 $('info_div').style.display = "none";
2265 $('info_div').innerHTML = "";
2266}
2267/**
2268 * filter quickly a list
2269 * @param phrase : DOM id of the input text where we find the word to seach, the searchable content use the className searchContent
2270 * @param _id : id of the list
2271 * @returns nothing
2272 * @see HtmlInput::filter_list
2273 */
2274function filter_list(phrase, _id) {
2275 $('info_div').innerHTML = content[65];
2276 $('info_div').style.display = "block";
2277 var words = $(phrase).value.toLowerCase();
2278 var l_list = document.getElementById(_id);
2279
2280
2281 var tot_found = 0;
2282
2283 for (var r = 0; r < l_list.childNodes.length; r++) {
2284 var found = 0;
2285
2286 if (l_list.childNodes[r].nodeType != 1) {
2287 continue;
2288 }
2289 let ele = "";
2290 let la_content = l_list.childNodes[r].getElementsByClassName("search-content");
2291
2292 let e = 0;
2293 for (e = 0; e < la_content.length; e++) {
2294 ele += la_content[e].innerText;
2295 }
2296
2297 console.debug (`ele = ${ele}`);
2298 if (ele.toLowerCase().indexOf(words) >= 0) {
2299 tot_found++;
2300 l_list.childNodes[r].style.display = 'block';
2301 } else {
2302 l_list.childNodes[r].style.display = 'none';
2303 }
2304
2305 }
2306 if (tot_found == 0) {
2307 if ($('info_' + _id)) {
2308 $('info_' + _id).innerHTML = content[69];
2309 }
2310 } else {
2311 if ($('info_' + _id)) {
2312 $('info_' + _id).innerHTML = " ";
2313 }
2314 }
2315 $('info_div').style.display = "none";
2316 $('info_div').innerHTML = "";
2317}
2318
2319/**
2320 * filter quickly a select
2321 * @param phrase : DOM id of the input text where we find the word to seach
2322 * @param _id : id of the list
2323 * @returns nothing
2324 * @see HtmlInput::filter_list
2325 */
2326function filter_multiselect(phrase, _id) {
2327 $('info_div').innerHTML = content[65];
2328 $('info_div').style.display = "block";
2329 var words = $(phrase).value.toLowerCase();
2330 var l_list = document.getElementById(_id);
2331
2332 var tot_found = 0;
2333
2334 for (var r = 0; r < l_list.options.length; r++) {
2335 var found = 0;
2336 var ele = l_list.options[r].text;
2337
2338 if (ele.toLowerCase().indexOf(words) >= 0) {
2339 tot_found++;
2340 l_list.options[r].style.display = 'block';
2341 } else {
2342 l_list.options[r].style.display = 'none';
2343 }
2344 $('info_div').style.display = "none";
2345 $('info_div').innerHTML = "";
2346 }
2347 if (tot_found == 0) {
2348 if ($('info_' + _id)) {
2349 $('info_' + _id).innerHTML = content[69];
2350 }
2351 } else {
2352 if ($('info_' + _id)) {
2353 $('info_' + _id).innerHTML = " ";
2354 }
2355 }
2356}
2357/**
2358 *
2359 * Display the task late or for today in dashboard
2360 */
2361function display_task(p_id)
2362{
2363
2364 $(p_id).style.top = posY + 'px';
2365 $(p_id).style.left = "10%";
2366 $(p_id).style.width = "80%";
2367 $(p_id).style.display = 'block';
2368
2369}
2370/**
2371 *
2372 * Set a message in the info
2373 */
2374function info_message(p_message)
2375{
2376 $('info_div').innerHTML = p_message;
2377 $('info_div').style.display = "block";
2378}
2379/**
2380 * hide the info box
2381 */
2382function info_hide()
2383{
2384 $('info_div').style.display = "none";
2385}
2386/**
2387 * Show the navigator in a internal window
2388 * @returns {undefined}
2389 */
2390function ask_navigator(p_dossier) {
2391 try {
2392 waiting_box();
2393 removeDiv('navi_div')
2394 var queryString = "gDossier=" + p_dossier + "&op=navigator";
2395 var action = new Ajax.Request(
2396 "ajax_misc.php",
2397 {
2398 method: 'get', parameters: queryString,
2399 onFailure: ajax_misc_failure,
2400 onSuccess: function (req) {
2401 remove_waiting_box();
2402 add_div({id: 'navi_div', style: 'top:2em;', cssclass: 'inner_box'});
2403 $('navi_div').innerHTML = req.responseText;
2404 try
2405 {
2406 req.responseText.evalScripts();
2407 sorttable.makeSortable($("navi_tb"));
2408 } catch (e)
2409 {
2410 alert_box("answer_box Impossible executer script de la reponse\n" + e.message);
2411 }
2412
2413 }
2414 }
2415 );
2416 } catch (e) {
2417 info_message(e.message);
2418 }
2419
2420}
2421/**
2422 * Display an internal windows to set the user's preference
2423 *
2424 */
2425function set_preference(p_dossier) {
2426 try {
2427 waiting_box();
2428 removeDiv('preference_div')
2429 var queryString = "gDossier=" + p_dossier + "&op=preference";
2430 var action = new Ajax.Request(
2431 "ajax_misc.php",
2432 {
2433 method: 'get', parameters: queryString,
2434 onFailure: ajax_misc_failure,
2435 onSuccess: function (req) {
2436 remove_waiting_box();
2437 if (req.responseText === 'NOCONX') { reconnect();return;}
2438 add_div({id: 'preference_div', drag: 1});
2439 $('preference_div').innerHTML = req.responseText;
2440 try
2441 {
2442 req.responseText.evalScripts();
2443 } catch (e)
2444 {
2445 alert_box("answer_box Impossible executer script de la reponse\n" + e.message);
2446 }
2447
2448 }
2449 }
2450 );
2451 } catch (e) {
2452 info_message(e.message);
2453 }
2454
2455}
2456/**
2457 * Display user's bookmark
2458 *
2459 */
2460function show_bookmark(p_dossier) {
2461 try {
2462 waiting_box();
2463 removeDiv('bookmark_div');
2464 var param = window.location.search;
2465 param = param.gsub('?', '');
2466 var queryString = "gDossier=" + p_dossier + "&op=bookmark&" + param;
2467 var action = new Ajax.Request(
2468 "ajax_misc.php",
2469 {
2470 method: 'get', parameters: queryString,
2471 onFailure: ajax_misc_failure,
2472 onSuccess: function (req) {
2473 remove_waiting_box();
2474 add_div({id: 'bookmark_div', cssclass: 'inner_box', drag: 1});
2475 $('bookmark_div').innerHTML = req.responseText;
2476 try
2477 {
2478 req.responseText.evalScripts();
2479 } catch (e)
2480 {
2481 alert_box(content[53] + "\n" + e.message);
2482 }
2483
2484 }
2485 }
2486 );
2487 } catch (e) {
2488 info_message(e.message);
2489 }
2490
2491}
2492/**
2493 * save the bookmark
2494 */
2495function save_bookmark() {
2496 try {
2497 waiting_box();
2498 var queryString = "op=bookmark&" + $("bookmark_frm").serialize();
2499 var action = new Ajax.Request(
2500 "ajax_misc.php",
2501 {
2502 method: 'get', parameters: queryString,
2503 onFailure: ajax_misc_failure,
2504 onSuccess: function (req) {
2505 remove_waiting_box();
2506 // removeDiv('bookmark_div');
2507 //
2508 $('bookmark_div').innerHTML = req.responseText;
2509 try
2510 {
2511 req.responseText.evalScripts();
2512 } catch (e)
2513 {
2514 alert_box(content[53] + "\n" + e.message);
2515 }
2516
2517 }
2518 }
2519 );
2520 } catch (e) {
2521 info_message(e.message);
2522 }
2523
2524}
2525/**
2526 * remove selected bookmark
2527 */
2528function remove_bookmark() {
2529 try {
2530 waiting_box();
2531 var queryString = "op=bookmark&" + $("bookmark_del_frm").serialize();
2532 var action = new Ajax.Request(
2533 "ajax_misc.php",
2534 {
2535 method: 'get', parameters: queryString,
2536 onFailure: ajax_misc_failure,
2537 onSuccess: function (req) {
2538 remove_waiting_box();
2539 $('bookmark_div').innerHTML = req.responseText;
2540 try
2541 {
2542 req.responseText.evalScripts();
2543 } catch (e)
2544 {
2545 alert_box(content[53] + "\n" + e.message);
2546 }
2547
2548 }
2549 }
2550 );
2551 } catch (e) {
2552 error_message(e.message);
2553 }
2554
2555}
2556/**
2557 * display the error message into the div error_content_div (included into error_div)
2558 *@param message message to display
2559 *@note there is no protection
2560 */
2561function error_message(message)
2562{
2563 $('error_content_div').innerHTML = message;
2564 $('error_div').style.visibility = 'visible';
2565}
2566/**
2567 * show the detail of a tag and propose to save it
2568 */
2569function show_tag(p_dossier, p_ac, p_tag_id, p_post)
2570{
2571 try {
2572 waiting_box();
2573 var queryString = "op=tag_detail&tag=" + p_tag_id + "&gDossier=" + p_dossier + "&ac=" + p_ac + '&form=' + p_post;
2574 var action = new Ajax.Request(
2575 "ajax_misc.php",
2576 {
2577 method: 'get', parameters: queryString,
2578 onFailure: ajax_misc_failure,
2579 onSuccess: function (req) {
2580 var answer = req.responseXML;
2581 var html = answer.getElementsByTagName('code');
2582 if (html.length === 0)
2583 {
2584 var rec = req.responseText;
2585 alert_box('erreur :' + rec);
2586 }
2587 var code_html = getNodeText(html[0]);
2588 code_html = unescape_xml(code_html);
2589 remove_waiting_box();
2590 var posy = calcy(250);
2591 add_div({id: 'tag_div', cssclass: 'inner_box', drag: 0, style: "position:fixed;top:15%;"});
2592 $('tag_div').innerHTML = code_html;
2593 try
2594 {
2595 code_html.evalScripts();
2596 } catch (e)
2597 {
2598 alert_box(content[53] + "\n" + e.message);
2599 }
2600
2601 }
2602 }
2603 );
2604 } catch (e) {
2605 error_message(e.message);
2606 }
2607}
2608
2609/**
2610 * save the modified tag
2611 */
2612function save_tag()
2613{
2614 try {
2615 waiting_box();
2616 var queryString = "op=tag_save&" + $("tag_detail_frm").serialize();
2617 var action = new Ajax.Request(
2618 "ajax_misc.php",
2619 {
2620 method: 'get',
2621 parameters: queryString,
2622 onFailure: ajax_misc_failure,
2623 onSuccess: function (req, j) {
2624 remove_waiting_box();
2625 removeDiv('tag_div');
2626 }
2627 }
2628 );
2629 } catch (e) {
2630 error_message(e.message);
2631 return false;
2632 }
2633 return false;
2634
2635}
2636/**
2637 * Show a list of tag which can be added to the current followup document
2638 * @param {type} p_dossier
2639 * @param {type} ag_id
2640 * @returns {undefined}
2641 */
2642function action_tag_select(p_dossier, ag_id)
2643{
2644 try {
2645 waiting_box();
2646 var queryString = "ag_id=" + ag_id + "&op=tag_list&gDossier=" + p_dossier;
2647 var action = new Ajax.Request(
2648 "ajax_misc.php",
2649 {
2650 method: 'get', parameters: queryString,
2651 onFailure: ajax_misc_failure,
2652 onSuccess: function (req, j) {
2653 var answer = req.responseXML;
2654 var html = answer.getElementsByTagName('code');
2655 if (html.length === 0)
2656 {
2657 var rec = unescape_xml(req.responseText);
2658 error_message('erreur :' + rec);
2659 }
2660 var code_html = getNodeText(html[0]);
2661 code_html = unescape_xml(code_html);
2662 var pos = fixed_position(35, 229);
2663 add_div({id: 'tag_div', style: pos, cssclass: 'inner_box tag', drag: 0});
2664
2665 remove_waiting_box();
2666 $('tag_div').innerHTML = code_html;
2667 }
2668 }
2669 );
2670 } catch (e) {
2671 error_message(e.message);
2672 }
2673}
2674/**
2675 * Add the current tag to the current ag_id
2676 * @param {type} p_dossier
2677 * @param {type} ag_id
2678 * @param p_isgroup g it is a group , t is a single tag
2679 * @returns {undefined}
2680 */
2681function action_tag_add(p_dossier, ag_id, t_id,p_isgroup)
2682{
2683 try {
2684 waiting_box();
2685 var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_add&gDossier=" + p_dossier+"&isgroup="+p_isgroup;
2686 var action = new Ajax.Request(
2687 "ajax_misc.php",
2688 {
2689 method: 'get', parameters: queryString,
2690 onFailure: ajax_misc_failure,
2691 onSuccess: function (req, j) {
2692 var answer = req.responseXML;
2693 var html = answer.getElementsByTagName('code');
2694 if (html.length === 0)
2695 {
2696 var rec = unescape_xml(req.responseText);
2697 error_message('erreur :' + rec);
2698 }
2699 var code_html = getNodeText(html[0]);
2700 code_html = unescape_xml(code_html);
2701 remove_waiting_box();
2702 $('action_tag_td').innerHTML = code_html;
2703 removeDiv('tag_div');
2704 }
2705 }
2706 );
2707 } catch (e) {
2708 error_message(e.message);
2709 }
2710}
2711/**
2712 * remove the current tag to the current ag_id
2713 * @param {type} p_dossier
2714 * @param {type} ag_id
2715 * @returns {undefined}
2716 */
2717function action_tag_remove(p_dossier, ag_id, t_id)
2718{
2719 confirm_box(null, content[50], function () {
2720 try {
2721 waiting_box();
2722 var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_remove&gDossier=" + p_dossier;
2723 var action = new Ajax.Request(
2724 "ajax_misc.php",
2725 {
2726 method: 'get', parameters: queryString,
2727 onFailure: ajax_misc_failure,
2728 onSuccess: function (req) {
2729 var answer = req.responseXML;
2730 var html = answer.getElementsByTagName('code');
2731 if (html.length === 0)
2732 {
2733 var rec = unescape_xml(req.responseText);
2734 error_message('erreur :' + rec);
2735 }
2736 var code_html = getNodeText(html[0]);
2737 code_html = unescape_xml(code_html);
2738 remove_waiting_box();
2739 $('action_tag_td').innerHTML = code_html;
2740
2741 }
2742 }
2743 );
2744 } catch (e) {
2745 error_message(e.message);
2746 }
2747 });
2748}
2749
2750/**
2751 * Activate a tag
2752 * @param int p_dossier
2753 * @param int p_tag_id
2754 */
2755function activate_tag(p_dossier, p_tag_id) {
2756 waiting_box();
2757 new Ajax.Request("ajax_misc.php",
2758 {
2759 method: "get",
2760 parameters: {gDossier: p_dossier, op: 'tag_activate', t_id: p_tag_id},
2761 onSuccess: function (req) {
2762 remove_waiting_box();
2763 var answer = req.responseText.evalJSON();
2764 var tagId = "tag_onoff" + p_tag_id;
2765 $(tagId).update(answer.code);
2766 $(tagId).setStyle(answer.style);
2767 remove_waiting_box();
2768 }
2769 })
2770}
2771/**
2772 * Display a div with available tags, this div can update the cell
2773 * tag_choose_td
2774 * @param {type} p_dossier
2775 * @param {string} p_prefix is the prefix of the div
2776 * @param {string} Calling object either Tag_Operation or Tag_Action
2777 * @returns {undefined}
2778 *
2779 */
2780function search_display_tag(p_dossier, p_prefix,p_object)
2781{
2782 try {
2783 waiting_box();
2784 var queryString = { op : "search_display_tag",gDossier:p_dossier,pref:p_prefix,caller_obj:p_object};
2785 var action = new Ajax.Request(
2786 "ajax_misc.php",
2787 {
2788 method: 'get', parameters: queryString,
2789 onFailure: ajax_misc_failure,
2790 onSuccess: function (req, j) {
2791 var answer = req.responseXML;
2792 var html = answer.getElementsByTagName('code');
2793 if (html.length === 0)
2794 {
2795 var rec = unescape_xml(req.responseText);
2796 error_message('erreur :' + rec);
2797 }
2798 var code_html = getNodeText(html[0]);
2799 code_html = unescape_xml(code_html);
2800 remove_waiting_box();
2801 add_div({id: p_prefix + 'tag_div', style: 'left:10%;width:70%', cssclass: 'inner_box', drag: 1});
2802 $(p_prefix + 'tag_div').style.top = calcy(200)+"px"
2803 $(p_prefix + 'tag_div').style.left = 20+ "%";
2804 remove_waiting_box();
2805 $(p_prefix + 'tag_div').innerHTML = code_html;
2806 code_html.evalScripts();
2807 }
2808 }
2809 );
2810 } catch (e) {
2811 error_message(e.message);
2812 }
2813}
2814/**
2815 * Add the selected tag (p_tag_id) to the cell of tag_choose_td in the search screen
2816 * in the search screen
2817 * @param {type} p_dossier
2818 * @param {type} p_tag_id
2819 * @param p_prefix is the prefix of the widget
2820 * @param p_obj is either g for group of tag or t for a single tag
2821 */
2822function search_add_tag(p_dossier, p_tag_id, p_prefix,p_obj)
2823{
2824 try {
2825 var clear_button = 0;
2826 if (tag_choose === '' && p_prefix === 'search') {
2827 tag_choose = $(p_prefix + 'tag_choose_td').innerHTML;
2828 clear_button = 1;
2829 }
2830 waiting_box();
2831 var queryString = "op=search_add_tag&gDossier=" + p_dossier + "&id=" + p_tag_id + "&clear=" + clear_button + '&pref=' + p_prefix+"&obj="+p_obj;
2832 var action = new Ajax.Request(
2833 "ajax_misc.php",
2834 {
2835 method: 'get', parameters: queryString,
2836 onFailure: ajax_misc_failure,
2837 onSuccess: function (req, j) {
2838 var answer = req.responseXML;
2839 var html = answer.getElementsByTagName('html');
2840 if (html.length === 0)
2841 {
2842 var rec = unescape_xml(req.responseText);
2843 error_message('erreur :' + rec);
2844 }
2845 var code_html = getNodeText(html[0]);
2846 code_html = unescape_xml(code_html);
2847 remove_waiting_box();
2848 $(p_prefix + 'tag_choose_td').innerHTML = $(p_prefix + 'tag_choose_td').innerHTML + code_html;
2849 removeDiv(p_prefix + 'tag_div');
2850 }
2851 }
2852 );
2853 } catch (e) {
2854 error_message(e.message);
2855 }
2856}
2857/**
2858 * Clear the tags in the cell tag_choose_td of the search screen
2859 * @returns {undefined}
2860 */
2861function search_clear_tag(p_dossier, p_prefix)
2862{
2863 if (p_prefix != 'search') {
2864 $(p_prefix + 'tag_choose_td').innerHTML = "";
2865 return;
2866 }
2867 try {
2868 var queryString = "op=search_clear_tag&gDossier=" + p_dossier + "&pref=" + p_prefix;
2869 var action = new Ajax.Request(
2870 "ajax_misc.php",
2871 {
2872 method: 'get', parameters: queryString,
2873 onFailure: ajax_misc_failure,
2874 onSuccess: function (req, j) {
2875 var answer = req.responseXML;
2876 var html = answer.getElementsByTagName('html');
2877 if (html.length === 0)
2878 {
2879 var rec = unescape_xml(req.responseText);
2880 error_message('erreur :' + rec);
2881 }
2882 var code_html = getNodeText(html[0]);
2883 code_html = unescape_xml(code_html);
2884 $(p_prefix + 'tag_choose_td').innerHTML = code_html;
2885 tag_choose = "";
2886 }
2887 }
2888 );
2889 } catch (e) {
2890 error_message(e.message);
2891 }
2892}
2893function action_show_checkbox()
2894{
2895 var a = document.getElementsByName('ag_id_td');
2896 for (var i = 0; i < a.length; i++) {
2897 a[i].style.display = 'block';
2898 }
2899}
2900function action_hide_checkbox()
2901{
2902 var a = document.getElementsByName('ag_id_td');
2903 for (var i = 0; i < a.length; i++) {
2904 a[i].style.display = 'none';
2905 }
2906}
2907/**
2908 *
2909 * @param {type} obj
2910 * object attribute : g
2911 * - Dossier dossier_id,
2912 * - invalue DOM Element where you can find the periode to zoom
2913 * - outdiv ID of the target (DIV)
2914 *
2915 */
2916function calendar_zoom(obj)
2917{
2918 try {
2919 waiting_box();
2920 var per_periode = null;
2921 var notitle = 0;
2922 var from = 0;
2923 if ($(obj.invalue)) {
2924 per_periode = $(obj.invalue).value;
2925 }
2926 if (obj.notitle && obj.notitle == 1) {
2927 notitle = 1;
2928 }
2929 var action = new Ajax.Request(
2930 "ajax_misc.php",
2931 {
2932 method: 'get',
2933 parameters: {"notitle": notitle, "op": 'calendar_zoom', 'from': from, 'gDossier': obj.gDossier, 'in': per_periode, 'out': obj.outdiv, 'distype': obj.distype},
2934 onFailure: ajax_misc_failure,
2935 onSuccess: function (req, j) {
2936 if (req.responseText === 'NOCONX') { reconnect();return;}
2937 var answer = req.responseXML;
2938 var html = answer.getElementsByTagName('html');
2939 if (html.length === 0)
2940 {
2941 var rec = unescape_xml(req.responseText);
2942 error_message('erreur :' + rec);
2943 }
2944 var code_html = getNodeText(html[0]);
2945 code_html = unescape_xml(code_html);
2946
2947 // if the target doesn't exist
2948 // then create it
2949 if (obj.outdiv === undefined) {
2950 obj.outdiv = 'calendar_zoom_div';
2951 }
2952 if ($(obj.outdiv) == undefined) {
2953 var str_style = 'top:10%;margin-left:2%;';
2954// var str_style = fixed_position(0, 120);
2955 add_div({id: obj.outdiv, style: 'margin-left:3%;width:94%;' + str_style, cssclass: "inner_box", drag: 0});
2956 }
2957 remove_waiting_box();
2958 $(obj.outdiv).innerHTML = code_html;
2959 $(obj.outdiv).show();
2960 }
2961 }
2962 );
2963 } catch (e) {
2964 error_message('calendar_zoom ' + e.message);
2965 }
2966
2967
2968}
2969/**
2970 * add a line in the form for the stock
2971 */
2972function stock_add_row()
2973{
2974 try {
2975 style = 'class="input_text"';
2976 var mytable = g("stock_tb").tBodies[0];
2977 var ofirstRow = mytable.rows[1];
2978 var line = mytable.rows.length;
2979 var nCell = mytable.rows[1].cells.length;
2980 var row = mytable.insertRow(line);
2981 var nb = g("row");
2982 for (var e = 0; e < nCell; e++)
2983 {
2984 var newCell = row.insertCell(e);
2985 if (mytable.rows[1].cells[e].hasClassName('num')) {
2986 newCell.addClassName("num");
2987 }
2988
2989 var tt = ofirstRow.cells[e].innerHTML;
2990 var new_tt = tt.replace(/sg_code0/g, "sg_code" + nb.value);
2991 new_tt = new_tt.replace(/sg_quantity0/g, "sg_quantity" + nb.value);
2992 new_tt = new_tt.replace(/label0/g, "label" + nb.value);
2993 newCell.innerHTML = new_tt;
2994 new_tt.evalScripts();
2995 }
2996
2997 g("sg_code" + nb.value).innerHTML = '&nbsp;';
2998 g("sg_code" + nb.value).value = '';
2999 g("label" + nb.value).innerHTML = '';
3000 g("sg_quantity" + nb.value).value = '0';
3001
3002 nb.value++;
3003
3004 new_tt.evalScripts();
3005 } catch (e) {
3006 alert_box(e.message);
3007 }
3008
3009}
3010function show_description(p_id)
3011{
3012 $('print_desc' + p_id).hide();
3013 $('input_desc' + p_id).show();
3014
3015}
3016/**
3017 * Display an empty card to fill , with the right card category
3018 * @param pn_fiche_card_id : fiche_def.fd_id
3019 * @param pn_dossier_id
3020 */
3021function select_cat(pn_fiche_card_id, pn_dossier_id, ps_element_id)
3022{
3023 dis_blank_card({"ctl": "div_new_card", "fd_id": pn_fiche_card_id, "op2": "bc", "op": "card", gDossier: pn_dossier_id, "elementId": ps_element_id});
3024 removeDiv('select_card_div');
3025}
3026/**
3027 * Show the DIV and hide the other, the array of possible DIV are
3028 * in a_tabs,
3029 * @param {array} a_tabs name of possible tabs
3030 * @param {strng} p_display_tab tab to display
3031 */
3032function show_tabs(a_tabs, p_display_tab)
3033{
3034 try
3035 {
3036 if (a_tabs.length == 0) {
3037 console.error('a_tabs in empty');
3038 throw ("a_tabs empty");
3039 return;
3040 }
3041 var i = 0;
3042 for (i = 0; i < a_tabs.length; i++) {
3043 $(a_tabs[i]).hide();
3044 }
3045 $(p_display_tab).show();
3046 } catch (e) {
3047 alert_box(e.message);
3048 }
3049
3050}
3051/**
3052 * Change the class of all the "LI" element of a UL or OL
3053 * @param node of ul (this)
3054 */
3055function unselect_other_tab(p_tab)
3056{
3057 try {
3058 var other = p_tab.getElementsByTagName("li");
3059 var i = 0;
3060 var tab = null;
3061 for (i = 0; i < other.length; i++) {
3062 tab = other[i];
3063 tab.className = "tabs";
3064 }
3065 } catch (e) {
3066 if (console)
3067 console.error(e.message);
3068 alert_box('unselect_other_tab ' + e.message);
3069 }
3070}
3071/**
3072 * logout function call from ajax
3073 * @see ajax_disconnected
3074 * @returns {undefined}
3075 */
3076function logout()
3077{
3078 var tmp_place = window.location.href
3079 var tmp_b = tmp_place.split('/')
3080 var tmp_last = tmp_b.length - 1
3081 var place_logout = tmp_place.replace(tmp_b[tmp_last], 'logout.php');
3082 window.location.href = place_logout;
3083}
3084/**
3085 * Create a div which can be used in a anchor
3086 * @returns {undefined}
3087 */
3088function create_anchor_up()
3089{
3090 if (document.getElementById('up_top'))
3091 return;
3092
3093 var newElt = document.createElement('div');
3094 newElt.setAttribute('id', 'up_top');
3095 newElt.innerHTML = '<a id="up_top"></a>';
3096
3097 var parent = $('info_div').parentNode;
3098 parent.insertBefore(newElt, $('info_div'));
3099
3100}
3101/**
3102 * Initialize the window to show the button "UP" if the window is scrolled
3103 * vertically
3104 * @returns {undefined}
3105 */
3106function init_scroll()
3107{
3108 var up = new Element('div', {"class": "",
3109 "style": "padding:5px;left:auto;width:auto;height: auto;display:none;position:fixed;bottom:30%;right:50px;text-align:center;font-size:20px",
3110 id: "go_up"
3111 });
3112 up.innerHTML = '<a class="icon" onclick="document.getElementById(\'go_up\').hide()" style="float:right;font-size:70%">&#xe816;</a> <a class="icon" href="#up_top" >&#xe81a;</a><a href="javascript:show_calc()" class="icon">&#xf1ec;</a>';
3113 document.body.appendChild(up);
3114 window.onscroll = function () {
3115 if ( document.getElementById("select_box_content") )
3116 { document.getElementById("select_box_content").setStyle({display:"none"})};
3117 if (document.viewport.getScrollOffsets().top > 0) {
3118 if ($('go_up').visible() == false) {
3119 $('go_up').setOpacity(0.65);
3120 $('go_up').show();
3121 $('go_up').style.zIndex = 99;
3122 }
3123 } else {
3124 $('go_up').hide();
3125 }
3126 }
3127
3128}
3129/**
3130 * Confirm a form thanks a modal dialog Box, it returns true if we agree otherwise
3131 * false
3132 * @code
3133 <form onsubmit="return confirm_box(this,'message')">
3134 </form>
3135 * @endcode
3136 * @param p_obj form element (object) or element id (string)
3137 * @param p_message message to display
3138 * @param p_callback_true callback function or null
3139 * @param p_waiting if true display a waiting box
3140 * @returns true or false
3141 */
3142function confirm_box(p_obj, p_message, p_callback_true,p_waiting)
3143{
3144 waiting_box();
3145 try {
3146 // Find id of the end
3147 var name = "";
3148 if (p_obj != null)
3149 {
3150 if (typeof (p_obj) === "object") {
3151 name = p_obj.id;
3152 } else {
3153 name = p_obj;
3154 }
3155 }
3156
3157 // execute the callback function or submit the form
3158 if ( ! p_callback_true )
3159 {
3160
3161 smoke.confirm(p_message, function (e) {
3162 if (e) {
3163 if (p_waiting){waiting_box();}
3164 $(name).submit();
3165 }
3166 });
3167 } else {
3168 smoke.confirm(p_message, function (e)
3169 {
3170 if (e) {
3171 p_callback_true.apply();
3172 }
3173 });
3174 }
3175 } catch (e) {
3176 alert_box(e.message);
3177 }
3178 remove_waiting_box();
3179 return false;
3180}
3181/**
3182 * Alert box in CSS and HTML to replace the common javascript alert
3183 * @param p_message message to display
3184 * @returns void
3185 */
3186function alert_box(p_message)
3187{
3188 smoke.alert(p_message, undefined, {ok: 'ok', classname: "inner_box"});
3189}
3190
3191
3192/**
3193 * Colorize the rows of the table
3194 * @param string p_table id of the table
3195 */
3196function alternate_row_color(p_table)
3197{
3198 var table_colored=$(p_table);
3199 if (! table_colored.tBodies[0] ) return;
3200
3201 var len = table_colored.tBodies[0].rows.length;
3202 var i = 0;
3203 var localClass = "";
3204 for (i = 1; i < len; i++) {
3205 localClass = (i % 2 == 0) ? "even" : "odd";
3206 if ( table_colored.tBodies[0].rows[i].hasClassName("odd"))
3207 {
3208 table_colored.tBodies[0].rows[i].removeClassName("odd");
3209 }
3210 if (table_colored.tBodies[0].rows[i].hasClassName("even"))
3211 {
3212 table_colored.tBodies[0].rows[i].removeClassName("even");
3213 }
3214 table_colored.tBodies[0].rows[i].addClassName(localClass);
3215 }
3216
3217}
3218/**
3219 * Make an DOM element draggable or not
3220 * @param object_id DOM id
3221 */
3222function pin(object_id) {
3223 if (aDraggableElement[object_id]) {
3224 aDraggableElement[object_id].destroy();
3225 aDraggableElement[object_id] = undefined;
3226 $('pin_' + object_id).innerHTML = "&#xf047;";
3227 } else {
3228 aDraggableElement[object_id] = new Draggable(object_id, {starteffect: function ()
3229 {
3230 new Effect.Highlight(object_id, {scroll: window, queue: 'end'});
3231 }}
3232 );
3233 $('pin_' + object_id).innerHTML = "&#xe809;";
3234 }
3235}
3236/**
3237 * Show only the rows into the table (p_table_id) with the attribute (p_attribute_name) and if this attribute
3238 * has the value of (attribut_value)
3239 * @param p_table_id table id
3240 * @param p_attribute_name the name of the attribute
3241 * @param p_attribute_value the value of the attribute we want to show
3242 */
3243function show_only_row(p_table_id, p_attribute_name, p_attribute_value)
3244{
3245 if (!$(p_table_id)) {
3246 throw "Invalide table id"
3247 }
3248 var mTable = $(p_table_id);
3249 var ncount = mTable.rows.length
3250 for (var i = 0; i < ncount; i++) {
3251 var mRow = mTable.rows[i];
3252 if (mRow.getAttribute(p_attribute_name) != undefined && mRow.getAttribute(p_attribute_name) != p_attribute_value) {
3253 mRow.hide();
3254 } else {
3255 mRow.show();
3256 }
3257 }
3258}
3259/**
3260 * Show all the rows into the table (p_table_id)
3261 * @param p_table_id table id
3262 */
3263function show_all_row(p_table_id)
3264{
3265 if (!$(p_table_id)) {
3266 throw "Invalide table id"
3267 }
3268 var mTable = $(p_table_id);
3269 var ncount = mTable.rows.length
3270 for (var i = 0; i < ncount; i++) {
3271 var mRow = mTable.rows[i];
3272 mRow.show();
3273 }
3274
3275}
3276/**
3277 * @class
3278 * Periode handling
3279 * Variables :
3280 * - id of the row of the periode row_per_(p_periode_id) , attribute exercice =per_exercice,periode_id=p_id
3281 * - (this.dialog)
3282 * - id of the table with the rows : periode_tbl
3283 *
3284 * Members :
3285 * - periode_id the concerned Periode , 0 none
3286 * - p_ledger : the id of ledger (jrn_def.jrn_def_id), 0 for global
3287 * - pcallback : default ajax_misc.php (this.callback) with the parameter { op:'periode',gDossier,[action:display,remove,save],p_id:p_periode_id}
3288 * - dossier
3289 * - js_obj_name : name of the js object (this.js_obj_name)
3290 * - ajax_test : file to include for debugging
3291 * - dialog : id of the dialog box (update / add ) periode_box
3292 *
3293 */
3294var Periode = function (p_ledger) {
3295 this.periode_id = 0;
3296 this.p_ledger = p_ledger;
3297 this.dialog = 'periode_box';
3298 this.pcallback = 'ajax_misc.php';
3299 this.dossier = 0;
3300 this.js_obj_name = "";
3301 this.ajax_test = "";
3302 this.set_callback = function (p_phpfile) {
3303 this.pcallback = p_phpfile;
3304 };
3305 this.set_dossier = function (p_dosid) {
3306 this.dossier = p_dosid;
3307 };
3308 /**
3309 * set_js_obj_name (p_js_obj_name)
3310 * We need to know the javascript variable name , to pass it to ajax and
3311 * create a HTML containing the right variable
3312 * @param p_js_obj_name name of the variable js we use on caller side
3313 */
3314 this.set_js_obj_name = function (p_js_obj_name) {
3315 this.js_obj_name = p_js_obj_name;
3316 };
3317
3318 /**
3319 * Remove the periode , so call new Ajax and hide the row if successful
3320 * otherwise show dialog box.
3321 * @parameter p_periode_id is the id of periode
3322 */
3323 this.remove = function (p_periode_id) {
3324
3325 var js_param = {"gDossier": this.dossier,
3326 "op": "periode",
3327 "act": "remove",
3328 "p_id": p_periode_id,
3329 "ledger_id": 0,
3330 "js_var": this.js_obj_name};
3331 if (this.ajax_test != "") {
3332 js_param["TestAjaxFile"] = this.ajax_test;
3333 }
3334 here = this;
3335 smoke.confirm("Confirmer ?", function (e) {
3336 if (e) {
3337 waiting_box();
3338 new Ajax.Request(here.pcallback,
3339 {
3340 method: "POST",
3341 parameters: js_param,
3342 onSuccess: function (req) {
3343 var answer = req.responseText.evalJSON();
3344 remove_waiting_box();
3345 if (answer.status == "OK")
3346 {
3347 $("row_per_" + p_periode_id).remove();
3348 alternate_row_color("periode_tbl");
3349 } else {
3350 smoke.alert(answer.content);
3351 }
3352 }
3353 });
3354 }
3355 });
3356 };
3357
3358 /**
3359 * display a dialog box to update a periode, call save either display
3360 * an error box or update the row.
3361 * the name of variable is requested
3362 * to build the right button , javascript in the html of answer
3363 * @parameter p_periode_id is the id of periode
3364 */
3365 this.box_display = function (p_periode_id) {
3366 if (this.js_obj_name == "") {
3367 smoke.alert("ERROR BOX_ADD")
3368 }
3369
3370 var js_param = {"gDossier": this.dossier,
3371 "op": "periode",
3372 "act": "show",
3373 "p_id": p_periode_id,
3374 "ledger_id": this.p_ledger,
3375 "js_var": this.js_obj_name};
3376 if (this.ajax_test != "") {
3377 js_param["TestAjaxFile"] = this.ajax_test;
3378 }
3379 var here = this;
3380 new Ajax.Request(here.pcallback,
3381 {
3382 method: "POST",
3383 parameters: js_param,
3384 onSuccess: function (req) {
3385 remove_waiting_box();
3386 var json = req.responseText.evalJSON();
3387 var y = 100;
3388 add_div({"id": "mod_periode", "style": "position:fixed;top:" + y + "px;width:50%", "cssclass": "inner_box", 'html': "wait"});
3389 $('mod_periode').update(json.content);
3390 }
3391 });
3392 };
3393 /**
3394 * close the periode, call ajax and receive a json object with the attribute
3395 * status, content
3396 * @parameter p_periode_id is the id of periode
3397 */
3398 this.close_periode = function (p_periode_id) {
3399 if (this.js_obj_name == "") {
3400 smoke.alert("ERROR BOX_ADD")
3401 }
3402
3403 if (this.ajax_test != "") {
3404 js_param["TestAjaxFile"] = this.ajax_test;
3405 }
3406 var here = this;
3407 smoke.confirm("Confirmer ?", function (e) {
3408 if (e) {
3409 here._close(p_periode_id);
3410 }
3411 });
3412 };
3413 /**
3414 * Internal function to close without confirming
3415 * @param {type} p_periode_id
3416 * @returns {undefined}
3417 */
3418 this._close = function (p_periode_id) {
3419 if (this.js_obj_name == "") {
3420 smoke.alert("ERROR BOX_ADD")
3421 }
3422 var js_param = {"gDossier": this.dossier,
3423 "op": "periode",
3424 "act": "close",
3425 "ledger_id": this.p_ledger,
3426 "p_id": p_periode_id,
3427 "js_var": this.js_obj_name
3428 };
3429 if (this.ajax_test != "") {
3430 js_param["TestAjaxFile"] = this.ajax_test;
3431 }
3432 var here = this;
3433 waiting_box();
3434 new Ajax.Request(here.pcallback,
3435 {
3436 method: "POST",
3437 parameters: js_param,
3438 onSuccess: function (req) {
3439 remove_waiting_box();
3440 var json = req.responseText.evalJSON();
3441 if (json.status == 'OK')
3442 {
3443 $('row_per_' + p_periode_id).update(json.content);
3444 new Effect.Highlight('row_per_' + p_periode_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3445 } else {
3446 smoke.alert(json.content);
3447 }
3448 }
3449 });
3450 };
3451 /**
3452 * reopen the periode
3453 * @parameter p_periode_id is the SQL id of parm_periode or the id of
3454 * jrn_periode
3455 */
3456 this.open_periode = function (p_periode_id) {
3457 if (this.js_obj_name == "") {
3458 smoke.alert("ERROR BOX_ADD")
3459 }
3460 var js_param = {"gDossier": this.dossier,
3461 "op": "periode",
3462 "act": "reopen",
3463 "ledger_id": this.p_ledger,
3464 "p_id": p_periode_id,
3465 "js_var": this.js_obj_name
3466 };
3467 if (this.ajax_test != "") {
3468 js_param["TestAjaxFile"] = this.ajax_test;
3469 }
3470 var here = this;
3471 smoke.confirm("Confirmer ?", function (e) {
3472 if (e) {
3473 waiting_box();
3474 new Ajax.Request(here.pcallback,
3475 {
3476 method: "POST",
3477 parameters: js_param,
3478 onSuccess: function (req) {
3479 remove_waiting_box();
3480 var json = req.responseText.evalJSON();
3481 if (json.status == 'OK')
3482 {
3483 $('row_per_' + p_periode_id).update(json.content);
3484 new Effect.Highlight('row_per_' + p_periode_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3485 } else {
3486 smoke.alert(json.content);
3487 }
3488 }
3489 });
3490 }
3491 });
3492 };
3493 /**
3494 * This DOMID of the DIV containing the form is mod_periode
3495 * @param {type} p_frm
3496 * @returns {Boolean}
3497 */
3498 this.save = function (p_frm) {
3499 var js_param = $(p_frm).serialize(true);
3500 waiting_box();
3501 js_param["js_var"] = this.js_obj_name;
3502 js_param["act"] = "save";
3503 js_param["op"] = "periode";
3504 var here = this;
3505 new Ajax.Request(this.pcallback, {
3506 method: "POST",
3507 parameters: js_param,
3508 onSuccess: function (req) {
3509
3510 var answer = req.responseText.evalJSON();
3511 remove_waiting_box();
3512 if (answer.status == "OK") {
3513 $('row_per_' + js_param['periode_id']).update(answer.content);
3514 removeDiv('mod_periode');
3515 new Effect.Highlight('row_per_' + js_param['periode_id'], {startcolor: '#FAD4D4', endcolor: '#F78082'});
3516 } else {
3517 smoke.alert(answer.content);
3518 }
3519 }
3520 });
3521 return false;
3522 };
3523 /**
3524 * Thanks the object DOMID sel_per_closed[] the selected periodes are
3525 * closed
3526 * @see Periode._close
3527 */
3528 this.close_selected = function () {
3529 var here = this;
3530 var a_selected = document.getElementsByName('sel_per_close[]');
3531 var count = 0;
3532 var i = 0;
3533 for (i = 0; i < a_selected.length; i++) {
3534 if (a_selected[i].checked == true) {
3535 // Close the selected periode
3536 count++;
3537 }
3538 }
3539 if (count == 0) {
3540 smoke.signal("Sélectionner au moins une période", function () {}, {duration: 1500});
3541 return;
3542 }
3543 smoke.confirm("Confirmer fermeture de " + count + " periode", function (e) {
3544 if (e) {
3545 var a_selected = document.getElementsByName('sel_per_close[]');
3546 var i = 0;
3547 for (i = 0; i < a_selected.length; i++) {
3548 if (a_selected[i].checked == true) {
3549 // Close the selected periode
3550 here._close(a_selected[i].value);
3551 }
3552 }
3553 }
3554 }
3555 );
3556 };
3557 /**
3558 * Insert a periode into the list, always at the bottom !
3559 * DomId :
3560 * # FORM id :insert_periode_frm
3561 * # DIV id = periode_add
3562 * # table id = periode_tbl
3563 */
3564 this.insert_periode = function () {
3565 var p_frm = 'insert_periode_frm';
3566 var js_param = $(p_frm).serialize(true);
3567 waiting_box();
3568 js_param["js_var"] = this.js_obj_name;
3569 js_param["act"] = "insert_periode";
3570 js_param["op"] = "periode";
3571 js_param["p_id"] = "-1";
3572 js_param["ledger_id"] = "0";
3573 var here = this;
3574 new Ajax.Request(this.pcallback, {
3575 method: "POST",
3576 parameters: js_param,
3577 onSuccess: function (req) {
3578 var answer = req.responseText.evalJSON();
3579 remove_waiting_box();
3580 if (answer.status == "OK") {
3581 var new_row = document.createElement("tr");
3582 $('periode_tbl').append(new_row);
3583 new_row.replace(answer.content);
3584
3585 // hide the form
3586 $('periode_add').hide();
3587 new Effect.Highlight('row_per_' + answer.p_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3588 alternate_row_color('periode_tbl');
3589 } else {
3590 smoke.alert(answer.content);
3591 }
3592 }
3593 });
3594 return false;
3595 }
3596
3597}
3598/**
3599 * Show the periodes from the exercice contained into the id (p_exercice_sel)
3600 * @param p_table_id DOM ID of the table
3601 */
3602Periode.filter_exercice = function (p_table_id) {
3603 var rows = $(p_table_id).rows;
3604 var selected_value = $('p_exercice_sel').value;
3605 for (var i = 1; i < rows.length; i++) {
3606 var exercice = rows[i].getAttribute("per_exercice");
3607 if (selected_value == -1) {
3608 rows[i].show();
3609 } else if (selected_value == exercice) {
3610 rows[i].show();
3611 } else {
3612 rows[i].hide();
3613 }
3614
3615 }
3616};
3617
3618// keep track of progress bar
3619var progressBar = [];
3620// idx of progress bar
3621var progressIdx = 0;
3622
3623/**
3624 * Start the progress bar
3625 * @param {string} p_taskid id to monitor
3626 * @param {int} p_message
3627 */
3628function progress_bar_start(p_taskid, p_message)
3629{
3630 try {
3631 progressIdx++;
3632 // block the window
3633
3634 var message = '<p>' + content[70] + '</p>';
3635 if (p_message) {
3636 message = p_message;
3637 }
3638
3639 add_div({id: "blocking" + progressIdx, cssclass: "smoke-base smoke-visible "});
3640
3641 add_div({id: "message" + progressIdx, cssclass: "inner_box", style: "z-index:1000;position:fixed;top:30%;width:40%;left:30%"});
3642 $("message" + progressIdx).update('<h3>' + content[65] + '</h3>' + message);
3643 // Create a div
3644 add_div({id: "progressDiv" + progressIdx, cssclass: "progressbar", html: '<span id="progressValue">0</span>'});
3645 // Check status every sec.
3646 progressBar[progressIdx] = setInterval(progress_bar_check.bind(null, progressIdx, p_taskid), 1000);
3647 } catch (e) {
3648 console.error(e.message);
3649 }
3650}
3651
3652/**
3653 * Check every second the status
3654 * @param {integer} p_idx idx of progressbar
3655 * @param {string} p_taskid id to monitor
3656 */
3657function progress_bar_check(p_idx, p_taskid)
3658{
3659 try {
3660
3661 new Ajax.Request("ajax_misc.php", {
3662 parameters: {gDossier: 0, task_id: p_taskid, op: "progressBar"},
3663 method: "get",
3664 onSuccess: function (req) {
3665 try
3666 {
3667 var answer = req.responseText.evalJSON();
3668 var progress_div = $("progressDiv" + progressIdx);
3669 var a_child = progress_div.childNodes;
3670 var i = 0;
3671 for (i = 0; i < a_child.length; i++) {
3672 if (a_child[i].id = "progressValue") {
3673 var progressValue = a_child[i];
3674 }
3675 }
3676 var progress = parseFloat(progressValue.innerHTML);
3677 if (answer.value <= progress) {
3678 return;
3679 }
3680
3681 progressValue.innerHTML = answer.value;
3682 progressValue.setStyle("width:" + answer.value + "%");
3683 if (answer.value == 100) {
3684 clearInterval(progressBar[p_idx]);
3685 progressValue.innerHTML = "Success";
3686 Effect.BlindUp("progressDiv" + p_idx, {duration: 1.0, scaleContent: false})
3687 $("message" + p_idx).remove();
3688 $("blocking" + p_idx).remove();
3689 setTimeout(function () {
3690 $("progressDiv" + progressIdx).remove
3691 }, 1100);
3692 }
3693 } catch (e) {
3694 clearInterval(progressBar[p_idx]);
3695 document.getElementById("progressValue").innerHTML = req.responseText;
3696 console.error(e.message);
3697 }
3698 }
3699 });
3700 } catch (e) {
3701 clearInterval(progressBar[p_idx]);
3702 console.error(e.message);
3703 }
3704}
3705
3706/**
3707 * In the user's setting box, update the period list with the choosen exercice
3708 * @param {int} p_dossier
3709 */
3710function updatePeriodePreference(p_dossier)
3711{
3712 waiting_box();
3713 var exercice = $('exercice_setting').value;
3714 new Ajax.Updater('setting_period', "ajax_misc.php", {method: "get", parameters: {"op": "pref_exercice", "gDossier": p_dossier, "exercice": exercice}});
3715 remove_waiting_box();
3716}
3717/**
3718 * Update the from and to periode list when changing the exercice
3719 * @param {int} p_dossier
3720 * @param {string} p_exercice dom id of the exercice (SELECT)
3721 * @param {type} p_periode_from id of the starting periode
3722 * @param {type} p_periode_to id of the ending periode
3723 * @param {type} p_last possible value = 1 to show last date or 0 the first
3724 */
3725function updatePeriode(p_dossier, p_exercice, p_periode_from, p_periode_to, p_last)
3726{
3727 waiting_box();
3728 var exercice = $(p_exercice).value;
3729 new Ajax.Updater(p_periode_from, "ajax_misc.php",
3730 { method: "get",
3731 parameters: {op: "periode_change", "gDossier": p_dossier, "exercice": exercice,
3732 field: p_periode_from, "type": "from", "last": p_last}});
3733 if ( p_periode_to && p_last ) {
3734 new Ajax.Updater(p_periode_to, "ajax_misc.php",
3735 { method: "get",
3736 parameters: {op: "periode_change", "gDossier": p_dossier, "exercice": exercice,
3737 field: p_periode_to, "type": "to", "last": p_last}});
3738 }
3739 remove_waiting_box();
3740}
3741/**
3742 *
3743 * @param {string} p_domid DOM id of the span containing the padlock icon
3744 * @returns none
3745 */
3746function toggle_lock(p_domid)
3747{
3748 var padlock = document.getElementById(p_domid);
3749 if (padlock == null) {
3750 console.error("domid invalid");
3751 }
3752 var status = padlock.getAttribute("is_locked");
3753 if (status == 1) {
3754 padlock.innerHTML = "&#xe832;";
3755 padlock.setAttribute("is_locked", 0);
3756 } else if (status == 0) {
3757 padlock.innerHTML = "&#xe831;";
3758 padlock.setAttribute("is_locked", 1);
3759 } else {
3760 throw "toggle_lock failed";
3761 }
3762
3763
3764}
3765/**
3766 *
3767 * @returns {undefined}
3768 */
3769function show_ledger_fin_currency()
3770{
3771 var ledger=$('p_jrn').value;
3772 var dossier=$('gDossier').value;
3773 // $('ledger_currency').
3774 var a=new Ajax.Updater("ledger_currency",
3775 "ajax_misc.php",
3776 {
3777 parameters: {"op":"currencyCode","gDossier":dossier,"ledger":ledger}
3778 });
3779}
3780
3781/***
3782 * Update Preference, applied the new CSS
3783 */
3784function updatePreference()
3785{
3786 try {
3787 waiting_box();
3788 var param = $('preference_frm').serialize() + "&op=preference&action=save";
3789
3790 new Ajax.Request("ajax_misc.php", {
3791 method: "post",
3792 parameters: param,
3793 onSuccess: function (req) {
3794 var answer = req.responseText.evalJSON();
3795 // $('pagestyle').setAttribute('href', style.style);
3796 if ( answer['psw']=='NOK') {
3797 smoke.alert(answer['msg']);
3798 } else {
3799 removeDiv('preference_div');
3800 }
3801 }
3802 });
3803 } catch (e)
3804 {
3805 smoke.alert(content[48] + e.message);
3806 }
3807 remove_waiting_box();
3808
3809}
3810
3811/**
3812 * turn on or off , set an domElement to 1 or 0 and change the icon
3813 * @param string icon_domid : id of the domElement which must be changed
3814 * @param string p_value_domid : id of domElement containing 1 or 0
3815 * @see param_jrn.php
3816 */
3817function toggle_onoff(icon_domid, p_value_domid)
3818{
3819 if ($(p_value_domid).value == 0) {
3820 $(p_value_domid).value = 1;
3821 $(icon_domid).innerHTML = '&#xf205;';
3822 $(icon_domid).style = 'color:green';
3823 } else {
3824 $(p_value_domid).value = 0;
3825 $(icon_domid).innerHTML = '&#xf204;';
3826 $(icon_domid).style = 'color:red';
3827 }
3828}
3829/**
3830 * turn on or off , set an domElement to 1 or 0 and change the icon
3831 * @param string icon_domid : id of the domElement which must be changed
3832 * @param string p_value_domid : id of domElement containing 1 or 0
3833 * @see param_jrn.php
3834 */
3835function toggle_checkbox_onoff(icon_domid, p_value_domid)
3836{
3837
3838 if ($(p_value_domid).value == 0) {
3839 $(p_value_domid).value = 1;
3840 $(icon_domid).innerHTML = '&#xe741;';
3841 } else {
3842 $(p_value_domid).value = 0;
3843 $(icon_domid).innerHTML = '&#xf096;';
3844 }
3845}
3846/**
3847 * in CFGLED show or hide the row depending if the warning is enable or not
3848 *
3849 * @param {type} p_enable
3850 * @param {type} p_row
3851 * @returns {undefined}
3852 */
3853function toggle_row_warning_enable(p_enable, p_row)
3854{
3855 if ($(p_enable).value == 1) {
3856 $(p_row).show();
3857 } else {
3858 $(p_row).hide();
3859 }
3860}
3861
3862/**
3863 * return a json object which is the merge of the 2 json objects
3864 * from 2015 : Object.assign(obj1, obj2);
3865 * @param p_json1 object 1 to merge
3866 * @param p_json2 object 2 to merge
3867 * @returns new json object
3868 */
3869function json_concat(p_json1,p_json2)
3870{
3871
3872 var result = {};
3873 for (var key in p_json1) {
3874 result[key] = p_json1[key];
3875 }
3876 for (var key in p_json2) {
3877 result[key] = p_json2[key];
3878 }
3879 return result;
3880
3881}
3882
3883
3884/**
3885 * this function unchecks other checkbox , it mimics the way a radio behaves
3886 * @param string p_click is the DOM id of the checkbox you clicked
3887 * @param string p_name is the name of all the checkbox to uncheck
3888 */
3889function uncheck_other(p_click,p_name)
3890{
3891 var aCheckbox=document.getElementsByName(p_name);
3892 if (aCheckbox.length == 0) return;
3893 var i=0;
3894 for (i=0;i<aCheckbox.length;i++) {
3895 aCheckbox[i].checked=false;
3896 }
3897 p_click.checked=true;
3898}
3899/**
3900 * @class operation Tag Manage the tag with operations
3901 * @returns {undefined}
3902 */
3903var operation_tag = function (p_div)
3904{
3905 this.ctl = p_div;
3906 /**
3907 * Show a list of tag which can be added to the current followup document
3908 * @param {type} p_dossier
3909 * @param {type} jrn_id
3910 * @returns {undefined}
3911 */
3912 this.select = function (p_dossier, p_jrn_id)
3913 {
3914 try {
3915 waiting_box();
3916 var queryString = {jrn_id:p_jrn_id,op:"operation_tag_select",gDossier:p_dossier,ctl:this.ctl};
3917 var action = new Ajax.Request(
3918 "ajax_misc.php",
3919 {
3920 method: 'get',
3921 parameters: queryString,
3922 onFailure: ajax_misc_failure,
3923 onSuccess: function (req, j) {
3924 remove_waiting_box();
3925
3926 var answer = req.responseXML;
3927 var html = answer.getElementsByTagName('code');
3928 if (html.length === 0)
3929 {
3930 var rec = unescape_xml(req.responseText);
3931 error_message('erreur :' + rec);
3932 }
3933 var code_html = getNodeText(html[0]);
3934 code_html = unescape_xml(code_html);
3935 var pos = fixed_position(35, 229);
3936 add_div({id: 'tag_div', style: pos, cssclass: 'inner_box tag', drag: 0});
3937
3938 remove_waiting_box();
3939 $('tag_div').innerHTML = code_html;
3940 }
3941 }
3942 );
3943 } catch (e) {
3944 error_message(e.message);
3945 }
3946 };
3947
3948 /**
3949 * Add the current tag to the current ag_id
3950 * @param {int} p_dossier
3951 * @param int ag_id
3952 * @param p_isgroup g it is a group , t is a single tag
3953 * @returns void
3954 */
3955 this.add = function (p_dossier, p_jrn_id, t_id, p_isgroup)
3956 {
3957 try {
3958 waiting_box();
3959 var queryString = {t_id:t_id,jrn_id:p_jrn_id,op:"operation_tag_add",
3960 gDossier:p_dossier,ctl:this.ctl,isgroup:p_isgroup};
3961 var ctl=this.ctl;
3962 var action = new Ajax.Request(
3963 "ajax_misc.php",
3964 {
3965 method: 'get', parameters: queryString,
3966 onFailure: ajax_misc_failure,
3967 onSuccess: function (req, j) {
3968 var answer = req.responseXML;
3969 var html = answer.getElementsByTagName('code');
3970 if (html.length === 0)
3971 {
3972 var rec = unescape_xml(req.responseText);
3973 error_message('erreur :' + rec);
3974 }
3975 var code_html = getNodeText(html[0]);
3976 code_html = unescape_xml(code_html);
3977 remove_waiting_box();
3978 $('operation_tag_td'+ctl).innerHTML = code_html;
3979 removeDiv('tag_div');
3980 }
3981 }
3982 );
3983 } catch (e) {
3984 error_message(e.message);
3985 }
3986 };
3987 /**
3988 * remove the current tag to the current ag_id
3989 * @param {int} p_dossier
3990 * @param {int} ag_id
3991 * @returns void
3992 */
3993 this.remove = function (p_dossier, p_jrn_id, t_id)
3994 {
3995 var ctl=this.ctl;
3996 confirm_box(null, content[50], function () {
3997 try {
3998 waiting_box();
3999 var queryString = {t_id:t_id,jrn_id:p_jrn_id,op:"operation_tag_remove",gDossier:p_dossier,ctl:ctl};
4000 var action = new Ajax.Request(
4001 "ajax_misc.php",
4002 {
4003 method: 'get',
4004 parameters: queryString,
4005 onFailure: ajax_misc_failure,
4006 onSuccess: function (req, j) {
4007 var answer = req.responseXML;
4008 var html = answer.getElementsByTagName('code');
4009 if (html.length === 0)
4010 {
4011 var rec = unescape_xml(req.responseText);
4012 error_message('erreur :' + rec);
4013 }
4014 var code_html = getNodeText(html[0]);
4015 code_html = unescape_xml(code_html);
4016 remove_waiting_box();
4017 $('operation_tag_td'+ctl).innerHTML = code_html;
4018
4019 }
4020 }
4021 );
4022 } catch (e) {
4023 error_message(e.message);
4024 }
4025 });
4026 };
4027};
4028
4029/**
4030 * Check the sum of size of all the FILES to upload
4031 * @param p_object the form DOM object,
4032 * @param p_max_size MAX_FILE_SIZE constant (see config.inc.php or constant.php)
4033 * @returns true if the sum of filesize is greater than the limit
4034 */
4035function check_file_size(p_object,p_max_size)
4036{
4037 var sum_file=0;
4038 for(var i=0;i<p_object.elements.length;i++) {
4039 var a=p_object.elements[i];
4040
4041 if ( p_object.elements[i].getAttribute('type')=="file" )
4042 {
4043 for (let x = 0; x < p_object.elements[i].files.length ; x++) {
4044 if( p_object.elements[i].files[x]){
4045
4046 sum_file+=p_object.elements[i].files[x].size;
4047 }
4048 }
4049 }
4050 }
4051 if ( sum_file > p_max_size) {alert_box(content[78]);return false;}
4052 return true;
4053}
4054
4055/**
4056 * Check that the receipt file is not too big
4057 * @see ajax_ledger.php , ledger_detail_file
4058 * @param int p_max_size maximum size
4059 * @param p_info name of the waiting box
4060 * @returns true if file size is less than the maximum
4061 */
4062function check_receipt_size(p_max_size,p_info)
4063{
4064 document.getElementById(p_info).style.display="inline";
4065
4066 var f=document.getElementById("receipt_id");
4067 if ( f && f.files[0] && f.files[0].size > parseFloat(p_max_size)) {
4068 document.getElementById("receipt_info_id").innerHTML=content[78];
4069 document.getElementById(p_info).style.display="none";
4070 return false;
4071 }
4072 document.getElementById("receipt_info_id").innerHTML="";
4073 document.getElementById("form_file").submit();
4074 return true;
4075}
4076/**
4077 * toggle size of a div : fullsize or normal
4078 *
4079 */
4080function full_size(p_div) {
4081 div_dom=document.getElementById(p_div);
4082 if ( ! div_dom ) return;
4083 if ( div_dom.hasClassName('fullsize')) {
4084 div_dom.removeClassName('fullsize');$('size_'+p_div).innerHTML='&#xe80a;';
4085 } else {
4086 div_dom.addClassName('fullsize');$('size_'+p_div).innerHTML='&#xe83d;';
4087 }
4088
4089}
4090
4091/**
4092 * download a document from an url
4093 */
4094function download_document(p_url)
4095{
4096 waiting_box();
4097 document.location=p_url;
4098 remove_waiting_box();
4099}
4100/**
4101 * download a document from a form
4102 */
4103function download_document_form(p_form_id)
4104{
4105 waiting_box();
4106 var url="export.php?"+$(p_form_id).serialize();
4107 document.location=url;
4108 remove_waiting_box();
4109 return false;
4110}
4111/**
4112 * Pause a javascript
4113 */
4114function pausecomp(millis)
4115 {
4116 var date = new Date();
4117 var curDate = null;
4118 do { curDate = new Date(); }
4119 while(curDate-date < millis);
4120}
4121/**
4122 * propose to reconnect
4123 * @returns {undefined}
4124 */
4125function reconnect(){
4126 remove_waiting_box();
4127 new Ajax.Request('ajax_misc.php',{
4128 method:'get',
4129 parameters:{op:"disconnect"},
4130 onSuccess:function (req) {
4131 var pos="position:fixed;top:0px;width:95%;height:95%";
4132 var div= add_div({
4133 'id':"reconnect_bx",
4134 cssclass:"inner_box",
4135 style:pos
4136 });
4137 div.innerHTML=req.responseText;
4138 }
4139 });
4140}
4141
4142/**
4143 * enlarge an INPUT TEXT
4144 *
4145 */
4146function enlarge_text(p_domid,p_size) {
4147 try {
4148 var element= document.getElementById(p_domid);
4149 if ( !element) {console.error (`enlarge text doesn't exist [${p_domid}]`)}
4150 var current_size=parseInt(element.getAttribute('size'));
4151 element.setAttribute('size',current_size+parseInt(p_size));
4152 } catch (e) {
4153 console.error(`enlarge text fails with ${p_domid} ${p_size} `);
4154 console.error(e.message);
4155 }
4156
4157
4158}
4159
4160/**
4161 * @brief display a box with the customer , supplier or event for today or late
4162 * @param p_detail , what to do
4163 */
4164function event_display_detail(p_dossier,p_detail) {
4165
4166 try
4167 {
4168 // create div if not exists
4169 var dgbox="situation_detail_div";
4170 waiting_box();
4171
4172 var queryString={gDossier:p_dossier,op:'event_display_detail','what':p_detail};
4173 // call ajax and update content of the div
4174 var action = new Ajax.Request(
4175 "ajax_misc.php" ,
4176 {
4177 method:'get',
4178 parameters:queryString,
4179 onFailure:ajax_misc_failure,
4180 onSuccess:function(req){
4181 remove_waiting_box();
4182 if (req.responseText == 'NOCONX') {
4183 reconnect();
4184 return;
4185 }
4186 if ( ! document.getElementById(dgbox)) {
4187 var div_style="position:fixed;"+";top:30%";
4188 add_div({id:dgbox,cssclass:'inner_box',html:loading(),style:div_style,drag:true});
4189
4190 }
4191
4192 $(dgbox).update(req.responseText)
4193
4194 }
4195 }
4196 );
4197 event_display_main(p_dossier);
4198 }catch( e)
4199 {
4200 alert_box(e.message);
4201 }
4202}
4203
4204/**
4205 * @brief refresh the main display in the dashboard to reflect possible changes
4206 * @param p_dossier
4207 */
4208function event_display_main(p_dossier) {
4209 try
4210 {
4211 waiting_box();
4212 var dgbox="situation_div";
4213 var queryString={gDossier:p_dossier,op:'event_display_detail','what':"main_display"};
4214 var action = new Ajax.Request(
4215 "ajax_misc.php" ,
4216 {
4217 method:'GET',
4218 parameters:queryString,
4219 onFailure:ajax_misc_failure,
4220 onSuccess:function(req){
4221 remove_waiting_box();
4222 if (req.responseText == 'NOCONX') {
4223 reconnect();
4224 return;
4225 }
4226
4227 $(dgbox).update(req.responseText)
4228
4229 }
4230 }
4231 );
4232 }catch( e)
4233 {
4234 alert_box(e.message);
4235 }
4236}
4237
4238/**
4239 * @brief check if password is strong or not, update a DIV element
4240 * @param p_pass_domid DOM ID of the INPUT element with the password
4241 * @param p_result_domid DOM ID of the element to update
4242 */
4243function check_password_strength(p_pass_domid,p_result_domid,details)
4244{
4245 try
4246 {
4247 if ( $(p_pass_domid).value=="") { $(p_result_domid).update("");return;}
4248 var queryString= {
4249 'op':"password_chk"
4250 ,pass:$(p_pass_domid).value
4251 };
4252 var action = new Ajax.Request(
4253 "ajax_misc.php" ,
4254 {
4255 method:'GET',
4256 parameters:queryString,
4257 onFailure:ajax_misc_failure,
4258 onSuccess:function(req){
4259 remove_waiting_box();
4260 if (req.responseText == 'NOCONX') {
4261 return;
4262 }
4263 var answer=req.responseJSON;
4264 console.debug(answer);
4265 if (answer['password']=='nok') {
4266
4267 $(p_pass_domid).setStyle("background-color:red");
4268 if ( details) {
4269 $(p_result_domid).update(answer['msg'])
4270 }
4271 return;
4272 }
4273 $(p_pass_domid).setStyle("background-color: lightgreen");
4274 $(p_result_domid).update("")
4275 }
4276 }
4277 );
4278 }catch( e)
4279 {
4280 alert_box(e.message);
4281 }
4282}
4283
4284/**
4285 * @brief
4286 */