00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 include_once("constant.php");
00029 require_once('class_database.php');
00030 require_once('class_periode.php');
00031
00032
00033
00034
00035
00036 function h($p_string)
00037 {
00038 return htmlspecialchars($p_string);
00039 }
00040
00041 function span($p_string, $p_extra='')
00042 {
00043 return '<span ' . $p_extra . '>' . $p_string . '</span>';
00044 }
00045
00046 function hi($p_string)
00047 {
00048 return '<i>' . htmlspecialchars($p_string) . '</i>';
00049 }
00050
00051 function hb($p_string)
00052 {
00053 return '<b>' . htmlspecialchars($p_string) . '</b>';
00054 }
00055
00056 function th($p_string, $p_extra='',$raw='')
00057 {
00058 return '<th ' . $p_extra . '>' . htmlspecialchars($p_string).$raw . '</th>';
00059 }
00060
00061 function h2info($p_string)
00062 {
00063 return '<h2 class="info">' . htmlspecialchars($p_string) . '</h2>';
00064 }
00065
00066 function h2($p_string, $p_class="",$raw="")
00067 {
00068 return '<h2 ' . $p_class . '>' . $raw.htmlspecialchars($p_string) . '</h2>';
00069 }
00070 function h1($p_string, $p_class="")
00071 {
00072 return '<h1 ' . $p_class . '>' . htmlspecialchars($p_string) . '</h1>';
00073 }
00074
00075
00076
00077
00078
00079
00080
00081 function td($p_string='', $p_extra='')
00082 {
00083 return '<td ' . $p_extra . '>' . $p_string . '</td>';
00084 }
00085
00086 function tr($p_string, $p_extra='')
00087 {
00088 return '<tr ' . $p_extra . '>' . $p_string . '</tr>';
00089 }
00090
00091
00092
00093 function j($p_string)
00094 {
00095 $a = preg_replace("/\r?\n/", "\\n", addslashes($p_string));
00096 $a = str_replace("'", '\'', $a);
00097 return $a;
00098 }
00099
00100
00101
00102
00103
00104 function nb($p_number)
00105 {
00106 $r = sprintf('%.2f', $p_number);
00107 $r = str_replace('.', ',', $r);
00108
00109 return $r;
00110 }
00111
00112
00113
00114
00115
00116 function nbm($p_number)
00117 {
00118
00119 if (trim($p_number) == '')
00120 return '';
00121 if ($p_number == 0)
00122 return "0,00";
00123
00124 $a = doubleval($p_number);
00125 $r = number_format($a, 2, ",", ".");
00126 if (trim($r) == '')
00127 {
00128 var_dump($r);
00129 var_dump($p_number);
00130 var_dump($a);
00131 exit();
00132 }
00133
00134 return $r;
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 function echo_error($p_log, $p_line="", $p_message="")
00149 {
00150 echo "ERREUR :" . $p_log . " " . $p_line . " " . $p_message;
00151 $fdebug = fopen($_ENV['TMP'] . DIRECTORY_SEPARATOR . "noalyss_error.log", "a+");
00152 if ($fdebug != null)
00153 {
00154 fwrite($fdebug, date("Ymd H:i:s") . $p_log . " " . $p_line . " " . $p_message . "\n");
00155 fclose($fdebug);
00156 }
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 function cmpDate($p_date, $p_date_oth)
00171 {
00172 date_default_timezone_set('Europe/Brussels');
00173
00174 $l_date = isDate($p_date);
00175 $l2_date = isDate($p_date_oth);
00176 if ($l_date == null || $l2_date == null)
00177 {
00178 throw new Exception("erreur date [$p_date] [$p_date_oth]");
00179 }
00180 $l_adate = explode(".", $l_date);
00181 $l2_adate = explode(".", $l2_date);
00182 $l_mkdate = mktime(0, 0, 0, $l_adate[1], $l_adate[0], $l_adate[2]);
00183 $l2_mkdate = mktime(0, 0, 0, $l2_adate[1], $l2_adate[0], $l2_adate[2]);
00184
00185 return $l_mkdate - $l2_mkdate;
00186 }
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 function isNumber(&$p_int)
00198 {
00199 if (strlen(trim($p_int)) == 0)
00200 return 0;
00201 if (is_numeric($p_int) === true)
00202 return 1;
00203 else
00204 return 0;
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 function isDate($p_date)
00219 {
00220 if (strlen(trim($p_date)) == 0)
00221 return null;
00222 if (preg_match("/^[0-9]{1,2}\.[0-9]{1,2}\.20[0-9]{2}$/", $p_date) == 0)
00223 {
00224
00225 return null;
00226 }
00227 else
00228 {
00229 $l_date = explode(".", $p_date);
00230
00231 if (sizeof($l_date) != 3)
00232 return null;
00233
00234 if ($l_date[2] > COMPTA_MAX_YEAR || $l_date[2] < COMPTA_MIN_YEAR)
00235 {
00236 return null;
00237 }
00238
00239 if (checkdate($l_date[1], $l_date[0], $l_date[2]) == false)
00240 {
00241 return null;
00242 }
00243 }
00244 return $p_date;
00245 }
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 function html_page_start($p_theme="", $p_script="", $p_script2="")
00258 {
00259 require_once 'class_html_input.php';
00260
00261 static $already_call=0;
00262 if ( $already_call==1)return;
00263 $already_call=1;
00264
00265 $cn = new Database();
00266 if ($p_theme != "")
00267 {
00268 $Res = $cn->exec_sql("select the_filestyle from theme
00269 where the_name='" . $p_theme . "'");
00270 if (Database::num_row($Res) == 0)
00271 $style = "style-classic.css";
00272 else
00273 {
00274 $s = Database::fetch_array($Res, 0);
00275 $style = $s['the_filestyle'];
00276 }
00277 }
00278 else
00279 {
00280 $style = "style-classic.css";
00281 }
00282 $title="NOALYSS";
00283
00284 if ( isset ($_REQUEST['ac'])) {
00285 if (strpos($_REQUEST['ac'],'/') <> 0)
00286 {
00287 $m= explode('/',$_REQUEST['ac']);
00288 $title=$m[count($m)-1]." ".$title;
00289 }
00290 else
00291 $title=$_REQUEST['ac']." ".$title;
00292 }
00293 echo '<!doctype html>';
00294 echo "<HTML>";
00295
00296 if ($p_script2 != "")
00297 $p_script2 = '<script src="' . $p_script2 . '" type="text/javascript"></script>';
00298
00299 echo "<HEAD>
00300 <TITLE>$title</TITLE>
00301 <link rel=\"icon\" type=\"image/ico\" href=\"favicon.ico\" />
00302 <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
00303 <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$style\" media=\"screen\">
00304 <link rel=\"stylesheet\" type=\"text/css\" href=\"style-print.css\" media=\"print\">" .
00305 $p_script2 . "
00306 ";
00307 echo '<script language="javascript" src="js/calendar.js"></script>
00308 <script type="text/javascript" src="js/lang/calendar-en.js"></script>
00309 <script language="javascript" src="js/calendar-setup.js"></script>
00310 <LINK REL="stylesheet" type="text/css" href="calendar-blue.css" media="screen">
00311 </HEAD>
00312 ';
00313
00314 echo "<BODY $p_script>";
00315 echo '<div id="info_div"></div>';
00316 echo '<div id="error_div">'.
00317 HtmlInput::title_box(_("Erreur"), 'error_div','hide').
00318 '<div id="error_content_div">'.
00319 '</div>'.
00320 '<p style="text-align:center">'.
00321 HtmlInput::button_action('Valider','$(\'error_div\').style.visibility=\'hidden\';$(\'error_content_div\').innerHTML=\'\';').
00322 '</p>'.
00323 '</div>';
00324
00325 if (isset($_SESSION['g_lang']))
00326 {
00327 set_language();
00328 }
00329
00330 }
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 function html_min_page_start($p_theme="", $p_script="", $p_script2="")
00343 {
00344
00345 $cn = new Database();
00346 if ($p_theme != "")
00347 {
00348 $Res = $cn->exec_sql("select the_filestyle from theme
00349 where the_name='" . $p_theme . "'");
00350 if (Database::num_row($Res) == 0)
00351 $style = "style-classic.css";
00352 else
00353 {
00354 $s = Database::fetch_array($Res, 0);
00355 $style = $s['the_filestyle'];
00356 }
00357 }
00358 else
00359 {
00360 $style = "style-classic.css";
00361 }
00362 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN">';
00363 echo "<HTML>";
00364
00365
00366 if ($p_script2 != "")
00367 $p_script2 = '<script src="' . $p_script2 . '" type="text/javascript"></script>';
00368
00369 echo "<HEAD>
00370 <TITLE>NOALYSS</TITLE>
00371 <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF8\">
00372 <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$style\" media=\"screen\">
00373 <link rel=\"stylesheet\" type=\"text/css\" href=\"style-print.css\" media=\"print\">" .
00374 $p_script2 . "
00375 <script src=\"js/scripts.js\" type=\"text/javascript\"></script>";
00376 echo '</HEAD>
00377 ';
00378
00379 echo "<BODY $p_script>";
00380
00381 if (basename($_SERVER['PHP_SELF']) == 'user_login.php')
00382 {
00383 return;
00384 }
00385 }
00386
00387
00388
00389
00390
00391
00392 function html_page_stop()
00393 {
00394 echo "</BODY>";
00395 echo "</HTML>";
00396 }
00397
00398
00399
00400
00401
00402
00403
00404 function NoAccess($js=1)
00405 {
00406 if ($js == 1)
00407 {
00408 echo "<script>";
00409 echo "alert ('" . _('Cette action ne vous est pas autorisée Contactez votre responsable') . "');";
00410 echo "</script>";
00411 }
00412 else
00413 {
00414 echo '<div class="redcontent">';
00415 echo '<h2 class="error">' . _(' Cette action ne vous est pas autorisée Contactez votre responsable') . '</h2>';
00416 echo '</div>';
00417 }
00418 exit - 1;
00419 }
00420
00421
00422
00423
00424 function FormatString($p_string)
00425 {
00426 return sql_string($p_string);
00427 }
00428
00429
00430
00431
00432
00433
00434
00435 function sql_string($p_string)
00436 {
00437 $p_string = trim($p_string);
00438 if (strlen($p_string) == 0)
00439 return null;
00440 $p_string = str_replace("'", "''", $p_string);
00441 $p_string = str_replace('\\', '\\\\', $p_string);
00442 return $p_string;
00443 }
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459 function ShowItem($p_array, $p_dir='V', $class="mtitle", $class_ref="mtitle", $default="", $p_extra="")
00460 {
00461
00462 $ret = "<TABLE $p_extra>";
00463
00464 if ($p_dir == 'V')
00465 {
00466 foreach ($p_array as $all => $href)
00467 {
00468 $javascript = (isset($href[4])) ? $href[4] : "";
00469 $title = "";
00470 $set = "XX";
00471 if (isset($href[2]))
00472 $title = $href[2];
00473 if (isset($href[3]))
00474 $set = $href[3];
00475
00476 if ($set == $default)
00477 $ret.='<TR><TD CLASS="selectedcell"><A class="' . $class_ref . '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] . '</A></TD></TR>';
00478 else
00479 $ret.='<TR><TD CLASS="' . $class . '"><A class="' . $class_ref . '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] . '</A></TD></TR>';
00480 }
00481 }
00482
00483 else if ($p_dir == 'H')
00484 {
00485
00486 $ret.="<TR>";
00487 foreach ($p_array as $all => $href)
00488 {
00489 $title = "";
00490 $javascript = (isset($href[4])) ? $href[4] : "";
00491
00492 $set = "A";
00493 if (isset($href[2]))
00494 $title = $href[2];
00495
00496 if (isset($href[3]))
00497 $set = $href[3];
00498
00499 if ($default === $href[0] || $set === $default)
00500 {
00501 $ret.='<TD CLASS="selectedcell"><A class="' . $class_ref . '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] . '</A></TD>';
00502 }
00503 else
00504 {
00505 $ret.='<TD CLASS="' . $class . '"><A class="' . $class_ref . '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] . '</A></TD>';
00506 }
00507 }
00508 $ret.="</TR>";
00509 }
00510 $ret.="</TABLE>";
00511 return $ret;
00512 }
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524 function echo_warning($p_string)
00525 {
00526 echo '<H2 class="error">' . $p_string . "</H2>";
00527 }
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540 function getPeriodeName($p_cn, $p_id, $pos='p_start')
00541 {
00542 if ($pos != 'p_start' and
00543 $pos != 'p_end')
00544 echo_error('ac_common.php' . "-" . __LINE__ . ' UNDEFINED PERIODE');
00545 $ret = $p_cn->get_value("select to_char($pos,'Mon YYYY') as t from parm_periode where p_id=$p_id");
00546 return $ret;
00547 }
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560 function getPeriodeFromMonth($p_cn, $p_date)
00561 {
00562 $R = $p_cn->get_value("select p_id from parm_periode where
00563 to_char(p_start,'DD.MM.YYYY') = '01.$p_date'");
00564 if ($R == "")
00565 return -1;
00566 return $R;
00567 }
00568
00569
00570
00571
00572
00573
00574 function Decode($p_html)
00575 {
00576 $p_html = str_replace('%0D', '', $p_html);
00577 $p_html = str_replace('%0A', '', $p_html);
00578 $p_html = urldecode($p_html);
00579 return $p_html;
00580 }
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592 function sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', $p_field='jr_tech_per')
00593 {
00594
00595 if ($p_form != 'p_id' &&
00596 $p_form != 'date')
00597 {
00598 echo_error(__FILE__, __LINE__, 'Mauvais parametres ');
00599 exit(-1);
00600 }
00601 if ($p_form == 'p_id')
00602 {
00603
00604 $pPeriode = new Periode($p_cn);
00605 $a_start = $pPeriode->get_date_limit($p_from);
00606 $a_end = $pPeriode->get_date_limit($p_to);
00607 if ($a_start == null || $a_end == null)
00608 throw new Exception(__FILE__ . __LINE__ . sprintf(_('Attention periode
00609 non trouvee periode p_from= %s p_to_periode = %s'), $p_from ,
00610 $p_to));
00611
00612
00613 $p_from = $a_start['p_start'];
00614 $p_to = $a_end['p_end'];
00615 }
00616 if ($p_from == $p_to)
00617 $periode = " $p_field = (select p_id from parm_periode " .
00618 " where " .
00619 " p_start = to_date('$p_from','DD.MM.YYYY')) ";
00620 else
00621 $periode = "$p_field in (select p_id from parm_periode " .
00622 " where p_start >= to_date('$p_from','DD.MM.YYYY') and p_end <= to_date('$p_to','DD.MM.YYYY')) ";
00623 return $periode;
00624 }
00625
00626
00627
00628
00629
00630
00631
00632
00633 function alert($p_msg, $buffer=false)
00634 {
00635 $r = '<script language="javascript">';
00636 $r.= 'alert(\'' . j($p_msg) . '\')';
00637 $r.= '</script>';
00638
00639 if ($buffer)
00640 return $r;
00641 echo $r;
00642 }
00643
00644
00645
00646
00647 function set_language()
00648 {
00649 // desactivate local check
00650 if ( defined("LOCALE") && LOCALE==0 ) return;
00651 if ( ! isset ($_SESSION['g_lang'])) return;
00652 $dir = "";
00653 // set differently the language depending of the operating system
00654 if (what_os() == 1)
00655 {
00656 $dir = setlocale(LC_MESSAGES, $_SESSION['g_lang']);
00657 if ($dir == "")
00658 {
00659 $g_lang = 'fr_FR.utf8';
00660 $dir = setlocale(LC_MESSAGES, $g_lang);
00661 // echo '<span class="notice">' . $_SESSION['g_lang'] . ' domaine non supporté</h2>';
00662 }
00663 bindtextdomain('messages', './lang');
00664 textdomain('messages');
00665 bind_textdomain_codeset('messages', 'UTF8');
00666
00667 return;
00668 }
00669 // for windows
00670 putenv('LANG=' . $_SESSION['g_lang']);
00671 $dir = setlocale(LC_ALL, $_SESSION['g_lang']);
00672 bindtextdomain('messages', '.\\lang');
00673 textdomain('messages');
00674 bind_textdomain_codeset('messages', 'UTF8');
00675 }
00676
00677
00678
00679
00680
00681
00682
00683
00684 function what_os()
00685 {
00686 $inc_path = get_include_path();
00687
00688 if (strpos($inc_path, ";") != 0)
00689 {
00690 $os = 0; /* $os is 0 for windoz */
00691 }
00692 else
00693 {
00694 $os = 1; /* $os is 1 for unix */
00695 }
00696 return $os;
00697 }
00698
00699
00700
00701
00702
00703
00704 function shrink_date($p_date)
00705 {
00706 $date = str_replace('.', '', $p_date);
00707 $str_date = substr($date, 0, 4) . substr($date, 6, 2);
00708 return $str_date;
00709 }
00710
00711
00712
00713
00714
00715 function smaller_date($p_date)
00716 {
00717 $str_date = substr($p_date, 0, 6) . substr($p_date, 8, 2);
00718 return $str_date;
00719 }
00720
00721
00722
00723
00724
00725
00726
00727
00728 function format_date($p_date, $p_from_format = 'YYYY-MM-DD',$p_to_format='DD.MM.YYYY')
00729 {
00730 if ($p_from_format == 'YYYY-MM-DD')
00731 {
00732 $date = explode('-', $p_date);
00733 if (count($date) != 3)
00734 return $p_date;
00735 }
00736 if ($p_from_format == 'DD.MM.YYYY')
00737 {
00738 $temp_date = explode('.', $p_date);
00739 if (count($temp_date) != 3)
00740 return $p_date;
00741 $date[0] = $temp_date[2]; // 0 is year
00742 $date[1] = $temp_date[1]; // 1 for month
00743 $date[2] = $temp_date[0]; // 2 for day
00744 }
00745
00746 switch ($p_to_format)
00747 {
00748 case 'DD.MM.YYYY':
00749 $str_date = $date[2] . '.' . $date[1] . '.' . $date[0];
00750 break;
00751 case 'YYYY-MM-DD':
00752 $str_date = $date[0] . '-' . $date[1] . '-' . $date[2];
00753 break;
00754 case 'YYYYMMDD':
00755 $str_date = $date[0] . $date[1] . $date[2];
00756 break;
00757 case 'YYYY/MM/DD':
00758 $str_date = $date[0] . '/' . $date[1] . '/' . $date[2];
00759 break;
00760
00761 }
00762 return $str_date;
00763 }
00764
00765
00766
00767
00768
00769
00770 function ajax_disconnected($div)
00771 {
00772
00773
00774
00775 if (!isset($_SESSION['g_user']))
00776 {
00777 $script = 'var a=$("' . $div . '");a.style.height="70%";a.style.width="70%";';
00778 $script.='a.style.top=posY-20+offsetY;a.style.left=posX+offsetX;';
00779 $script = create_script($script);
00780 $html = $script;
00781 $html.=HtmlInput::anchor_close($div);
00782 $html.='<div>';
00783 $html.=h2(_('Données non disponibles'), 'class="title" style="width:auto"');
00784 $html.=h2(_('Veuillez vous reconnecter'), 'class="error"');
00785 $html.=alert(_("Déconnecté"), true);
00786 $html = escape_xml($html);
00787
00788 header('Content-type: text/xml; charset=UTF-8');
00789 echo <<<EOF
00790 <?xml version="1.0" encoding="UTF-8"?>
00791 <data>
00792 <ctl>$div</ctl>
00793 <code>$html</code>
00794 </data>
00795 EOF;
00796 exit();
00797 }
00798 }
00799
00800
00801
00802
00803
00804 function show_module($selected)
00805 {
00806 global $g_user;
00807 $cn = Dossier::connect();
00808 $amodule = $cn->get_array("select
00809 me_code,me_menu,me_url,me_javascript,p_order,me_type,me_description
00810 from v_all_menu
00811 where
00812 user_name=$1
00813 and p_type_display='M'
00814 order by p_order", array($g_user->login));
00815
00816 if ($selected != -1)
00817 {
00818 require_once('template/module.php');
00819 $file = $cn->get_array("select me_file,me_parameter,me_javascript,me_type,me_description from v_all_menu
00820 where me_code=$1 and user_name=$2", array($selected,$g_user->login));
00821 if ( count($file ) == 0 )
00822 {
00823 echo '</div>';
00824 echo '</div>';
00825 echo '<div class="content">';
00826 echo_warning(_("Module inexistant")."[ $selected ] ");
00827 echo '</div>';
00828 exit();
00829 }
00830 if ($file[0]['me_file'] != '')
00831 {
00832 if ($file[0]['me_parameter'] != "")
00833 {
00834 // if there are paramter put them in superglobal
00835 $array=compute_variable($file[0]['me_parameter']);
00836 put_global($array);
00837 }
00838
00839 // if file is not a plugin, include the file, otherwise
00840 // include the plugin launcher
00841 if ($file[0]['me_type'] != 'PL')
00842 {
00843 require_once $file[0]['me_file'];
00844 }
00845 else
00846 {
00847 // nothing : direct call to plugin
00848 }
00849 }
00850 if ( $file[0]['me_javascript'] != '')
00851 {
00852 create_script($file[0]['me_javascript']);
00853 }
00854 }
00855 }
00856
00857
00858
00859
00860
00861 function find_default_module()
00862 {
00863 global $g_user;
00864 $cn = Dossier::connect();
00865
00866 $default_module = $cn->get_array("select me_code
00867 from profile_menu join profile_user using (p_id)
00868 where
00869 p_type_display='M' and
00870 user_name=$1 and pm_default=1", array($g_user->login));
00871
00872 /*
00873 * Try to find the smallest order for module
00874 */
00875 if (empty($default_module))
00876 {
00877 $default_module = $cn->get_array("select me_code
00878 from profile_menu join profile_user using (p_id)
00879 where
00880 p_type_display='M' and
00881 user_name=$1 order by p_order limit 1", array($g_user->login));
00882
00883 // if no default try to find the default menu
00884 if ( empty ($default_module))
00885 {
00886 $default_module = $cn->get_array("select me_code
00887 from profile_menu join profile_user using (p_id)
00888 where
00889 p_type_display='E' and
00890 user_name=$1 and pm_default=1 ", array($g_user->login));
00891 /*
00892 * Try to find a default menu by order
00893 */
00894 if (empty ($default_module))
00895 {
00896 $default_module = $cn->get_array("select me_code
00897 from profile_menu join profile_user using (p_id)
00898 where
00899 user_name=$1 and p_order=(select min(p_order) from profile_menu join profile_user using (p_id)
00900 where user_name=$2) limit 1", array($g_user->login, $g_user->login));
00901 }
00902
00903 /*
00904 * if nothing found, there is no profile for this user => exit
00905 */
00906 if (empty ($default_module))
00907 {
00908 echo_warning(_("Utilisateur n'a pas de profile, votre administrateur doit en configurer un dans CFGSEC"));
00909 exit();
00910 }
00911 }
00912 return $default_module[0]['me_code'];
00913 }
00914
00915 if (count($default_module) > 1)
00916 {
00917 // return the first module found
00918 return $default_module[0]['me_code'];
00919 }
00920 elseif (count($default_module) == 1)
00921 {
00922 return $default_module[0]['me_code'];
00923 }
00924 }
00925
00926
00927
00928
00929
00930
00931
00932 function show_menu($module, $idx)
00933 {
00934 global $g_user;
00935 $cn = Dossier::connect();
00936 $amenu = $cn->get_array("select
00937 me_menu,me_code,me_url,me_javascript,me_type,me_description
00938 from v_all_menu
00939 where
00940 me_code_dep=$1 and user_name=$2 order by p_order", array($module[$idx], $g_user->login));
00941
00942 if (!empty($amenu) && count($amenu) > 1)
00943 {
00944 $a_style_menu=array('topmenu','menu2','menu3');
00945 if ( $idx > count($a_style_menu))
00946 $style_menu='menu3';
00947 else {
00948 $style_menu=$a_style_menu[$idx];
00949 }
00950 require 'template/menu.php';
00951 }
00952 elseif (count($amenu) == 1)
00953 {
00954 echo '<div class="topmenu">';
00955 echo h2info($amenu[0]['me_menu']);
00956 echo '</div>';
00957 $module[$idx] = $amenu[0]['me_code'];
00958 }
00959
00960 if (empty($amenu) || count($amenu) == 1)
00961 {
00962 $file = $cn->get_array("select me_file,me_parameter,me_javascript,me_type
00963 from menu_ref
00964 join profile_menu using (me_code)
00965 join profile_user using (p_id)
00966 where
00967 me_code=$1 and
00968 user_name=$2 and
00969 (me_file is not null or trim(me_file) <>'' or
00970 me_javascript is not null or trim (me_javascript) <> '')", array($module[$idx],$g_user->login));
00971
00972 if (count($file)==0)
00973 {
00974 echo "Configuration incorrecte pour ce module ".$module[$idx];
00975 exit;
00976 }
00977
00978 if ($file[0]['me_file'] != "")
00979 {
00980 if ($file[0]['me_parameter'] !== "")
00981 {
00982 // if there are paramter put them in superglobal
00983 $array=compute_variable($file[0]['me_parameter']);
00984 put_global($array);
00985 }
00986
00987 // if file is not a plugin, include the file, otherwise
00988 // include the plugin launcher
00989 if ( $file[0]['me_type'] != 'PL')
00990 require_once $file[0]['me_file'];
00991 else
00992 require 'extension_get.inc.php';
00993
00994 exit();
00995 }
00996 if ( $file[0]['me_javascript'] != '')
00997 {
00998 $js= str_replace('<DOSSIER>', dossier::id(), $file[0]['me_javascript']);
00999 echo create_script($js);
01000 }
01001 }
01002 }
01003
01004
01005
01006
01007
01008 function put_global($array)
01009 {
01010 for ($i=0;$i<count($array);$i++)
01011 {
01012 $key=$array[$i]['key'];
01013 $value=$array[$i]['value'];
01014 $_GET[$key]=$value;
01015 $_POST[$key]=$value;
01016 $_REQUEST[$key]=$value;
01017 }
01018 }
01019
01020
01021
01022
01023
01024
01025 function compute_variable($p_string)
01026 {
01027 $array=array();
01028 if ($p_string == '') return $array;
01029
01030 $var=explode("&",$p_string);
01031 if (empty ($var)) return $array;
01032 for ($i=0;$i < count($var);$i++)
01033 {
01034 $var2=explode('=',$var[$i]);
01035 $array[$i]['key']=$var2[0];
01036 $array[$i]['value']=$var2[1];
01037 }
01038 return $array;
01039 }
01040 function ajax_xml_error($p_code,$p_string)
01041 {
01042 $html = escape_xml($p_string);
01043 header('Content-type: text/xml; charset=UTF-8');
01044 echo <<<EOF
01045 <?xml version="1.0" encoding="UTF-8"?>
01046 <data>
01047 <code>$p_code</code>
01048 <value>$html</value>
01049 </data>
01050 EOF;
01051 }
01052 function display_dashboard_operation($p_array,$p_title,$p_div)
01053 {
01054 ?>
01055 <div id="<?php echo $p_div;?>" class="inner_box" style="display:none;top:250;left:25%;width: 50%;min-height:50%;overflow:auto;">
01056 <?php
01057 echo HtmlInput::title_box($p_title, $p_div, "hide");
01058 ?>
01059 <?php if (count($p_array)>0) :?>
01060 <table class="result">
01061 <tr>
01062 <th><?php echo _('Date')?></th>
01063 <th><?php echo _('Code Interne')?></th>
01064 <th><?php echo _('Description')?></th>
01065 <th>
01066 <?php echo _('Montant')?>
01067 </th>
01068
01069 </tr>
01070 <?php
01071 for ($i=0;$i<count($p_array);$i++):
01072 ?>
01073 <tr class="<?php echo (($i%2)==0)?'odd':'even';?>">
01074 <td>
01075 <?php echo smaller_date(format_date($p_array[$i]['jr_date']) );?>
01076 </td>
01077 <td>
01078 <?php echo HtmlInput::detail_op($p_array[$i]['jr_id'], $p_array[$i]['jr_internal']) ?>
01079 </td>
01080 <td>
01081 <?php echo h($p_array[$i]['jr_comment']) ?>
01082 </td>
01083 <td>
01084 <?php echo nbm($p_array[$i]['jr_montant']) ?>
01085 </td>
01086 </tr>
01087 <?php
01088 endfor;
01089 ?>
01090 </table>
01091 <?php else: ?>
01092 <h2 class="notice"><?php echo _('Aucune donnée')?></h2>
01093 <?php
01094 endif;
01095 ?>
01096 </div>
01097 <?php
01098 }
01099 function get_array_column($p_array,$key)
01100 {
01101 $array=array();
01102 for ($i=0;$i<count($p_array);$i++)
01103 {
01104 $r=$p_array[$i];
01105 if ( isset($r[$key])) {
01106 $array[]=$r[$key];
01107 }
01108 }
01109 return $array;
01110 }
01111 ?>