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 $is_msie=is_msie();
00294
00295 if ($is_msie == 0 )
00296 echo '<!doctype html>';
00297 else
00298 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN" >';
00299
00300 echo "<HTML>";
00301
00302 if ($p_script2 != "")
00303 $p_script2 = '<script src="' . $p_script2 . '" type="text/javascript"></script>';
00304 $style=trim($style);
00305 $DIR=dirname(__FILE__);
00306 echo "<HEAD>";
00307 if ( $is_msie == 1 )echo ' <meta http-equiv="x-ua-compatible" content="IE=edge"/>';
00308 echo "
00309 <TITLE>$title</TITLE>
00310 <link rel=\"icon\" type=\"image/ico\" href=\"favicon.ico\" />
00311 <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
00312 <LINK REL=\"stylesheet\" type=\"text/css\" href=\"./$style\" media=\"screen\">
00313 <link rel=\"stylesheet\" type=\"text/css\" href=\"style-print.css\" media=\"print\">" .
00314 $p_script2 . "
00315 ";
00316 echo '<script language="javascript" src="js/calendar.js"></script>
00317 <script type="text/javascript" src="js/lang/calendar-en.js"></script>
00318 <script language="javascript" src="js/calendar-setup.js"></script>
00319 <LINK REL="stylesheet" type="text/css" href="calendar-blue.css" media="screen">';
00320
00321 echo ' </HEAD> ';
00322
00323 echo "<BODY $p_script>";
00324 echo '<div id="info_div"></div>';
00325 echo '<div id="error_div">'.
00326 HtmlInput::title_box(_("Erreur"), 'error_div','hide').
00327 '<div id="error_content_div">'.
00328 '</div>'.
00329 '<p style="text-align:center">'.
00330 HtmlInput::button_action('Valider','$(\'error_div\').style.visibility=\'hidden\';$(\'error_content_div\').innerHTML=\'\';').
00331 '</p>'.
00332 '</div>';
00333
00334 if (isset($_SESSION['g_lang']))
00335 {
00336 set_language();
00337 }
00338
00339 }
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351 function html_min_page_start($p_theme="", $p_script="", $p_script2="")
00352 {
00353
00354 $cn = new Database();
00355 if ($p_theme != "")
00356 {
00357 $Res = $cn->exec_sql("select the_filestyle from theme
00358 where the_name='" . $p_theme . "'");
00359 if (Database::num_row($Res) == 0)
00360 $style = "style-classic.css";
00361 else
00362 {
00363 $s = Database::fetch_array($Res, 0);
00364 $style = $s['the_filestyle'];
00365 }
00366 }
00367 else
00368 {
00369 $style = "style-classic.css";
00370 }
00371 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN">';
00372 echo "<HTML>";
00373
00374
00375 if ($p_script2 != "")
00376 $p_script2 = '<script src="' . $p_script2 . '" type="text/javascript"></script>';
00377
00378 echo "<HEAD>
00379 <TITLE>NOALYSS</TITLE>
00380 <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF8\">
00381 <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$style\" media=\"screen\">
00382 <link rel=\"stylesheet\" type=\"text/css\" href=\"style-print.css\" media=\"print\">" .
00383 $p_script2 . "
00384 <script src=\"js/scripts.js\" type=\"text/javascript\"></script>";
00385 echo '</HEAD>
00386 ';
00387
00388 echo "<BODY $p_script>";
00389
00390 if (basename($_SERVER['PHP_SELF']) == 'user_login.php')
00391 {
00392 return;
00393 }
00394 }
00395
00396
00397
00398
00399
00400
00401 function html_page_stop()
00402 {
00403 echo "</BODY>";
00404 echo "</HTML>";
00405 }
00406
00407
00408
00409
00410
00411
00412
00413 function NoAccess($js=1)
00414 {
00415 if ($js == 1)
00416 {
00417 echo "<script>";
00418 echo "alert ('" . _('Cette action ne vous est pas autorisée Contactez votre responsable') . "');";
00419 echo "</script>";
00420 }
00421 else
00422 {
00423 echo '<div class="redcontent">';
00424 echo '<h2 class="error">' . _(' Cette action ne vous est pas autorisée Contactez votre responsable') . '</h2>';
00425 echo '</div>';
00426 }
00427 exit - 1;
00428 }
00429
00430
00431
00432
00433 function FormatString($p_string)
00434 {
00435 return sql_string($p_string);
00436 }
00437
00438
00439
00440
00441
00442
00443
00444 function sql_string($p_string)
00445 {
00446 $p_string = trim($p_string);
00447 if (strlen($p_string) == 0)
00448 return null;
00449 $p_string = str_replace("'", "''", $p_string);
00450 $p_string = str_replace('\\', '\\\\', $p_string);
00451 return $p_string;
00452 }
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468 function ShowItem($p_array, $p_dir='V', $class="mtitle", $class_ref="mtitle", $default="", $p_extra="")
00469 {
00470
00471 $ret = "<TABLE $p_extra>";
00472
00473 if ($p_dir == 'V')
00474 {
00475 foreach ($p_array as $all => $href)
00476 {
00477 $javascript = (isset($href[4])) ? $href[4] : "";
00478 $title = "";
00479 $set = "XX";
00480 if (isset($href[2]))
00481 $title = $href[2];
00482 if (isset($href[3]))
00483 $set = $href[3];
00484
00485 if ($set == $default)
00486 $ret.='<TR><TD CLASS="selectedcell"><A class="' . $class_ref . '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] . '</A></TD></TR>';
00487 else
00488 $ret.='<TR><TD CLASS="' . $class . '"><A class="' . $class_ref . '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] . '</A></TD></TR>';
00489 }
00490 }
00491
00492 else if ($p_dir == 'H')
00493 {
00494
00495 $ret.="<TR>";
00496 foreach ($p_array as $all => $href)
00497 {
00498 $title = "";
00499 $javascript = (isset($href[4])) ? $href[4] : "";
00500
00501 $set = "A";
00502 if (isset($href[2]))
00503 $title = $href[2];
00504
00505 if (isset($href[3]))
00506 $set = $href[3];
00507
00508 if ($default === $href[0] || $set === $default)
00509 {
00510 $ret.='<TD CLASS="selectedcell"><A class="' . $class_ref . '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] . '</A></TD>';
00511 }
00512 else
00513 {
00514 $ret.='<TD CLASS="' . $class . '"><A class="' . $class_ref . '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] . '</A></TD>';
00515 }
00516 }
00517 $ret.="</TR>";
00518 }
00519 $ret.="</TABLE>";
00520 return $ret;
00521 }
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533 function echo_warning($p_string)
00534 {
00535 echo '<H2 class="error">' . $p_string . "</H2>";
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549 function getPeriodeName($p_cn, $p_id, $pos='p_start')
00550 {
00551 if ($pos != 'p_start' and
00552 $pos != 'p_end')
00553 echo_error('ac_common.php' . "-" . __LINE__ . ' UNDEFINED PERIODE');
00554 $ret = $p_cn->get_value("select to_char($pos,'Mon YYYY') as t from parm_periode where p_id=$p_id");
00555 return $ret;
00556 }
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569 function getPeriodeFromMonth($p_cn, $p_date)
00570 {
00571 $R = $p_cn->get_value("select p_id from parm_periode where
00572 to_char(p_start,'DD.MM.YYYY') = '01.$p_date'");
00573 if ($R == "")
00574 return -1;
00575 return $R;
00576 }
00577
00578
00579
00580
00581
00582
00583 function Decode($p_html)
00584 {
00585 $p_html = str_replace('%0D', '', $p_html);
00586 $p_html = str_replace('%0A', '', $p_html);
00587 $p_html = urldecode($p_html);
00588 return $p_html;
00589 }
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601 function sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', $p_field='jr_tech_per')
00602 {
00603
00604 if ($p_form != 'p_id' &&
00605 $p_form != 'date')
00606 {
00607 echo_error(__FILE__, __LINE__, 'Mauvais parametres ');
00608 exit(-1);
00609 }
00610 if ($p_form == 'p_id')
00611 {
00612
00613 $pPeriode = new Periode($p_cn);
00614 $a_start = $pPeriode->get_date_limit($p_from);
00615 $a_end = $pPeriode->get_date_limit($p_to);
00616 if ($a_start == null || $a_end == null)
00617 throw new Exception(__FILE__ . __LINE__ . sprintf(_('Attention periode
00618 non trouvee periode p_from= %s p_to_periode = %s'), $p_from ,
00619 $p_to));
00620
00621
00622 $p_from = $a_start['p_start'];
00623 $p_to = $a_end['p_end'];
00624 }
00625 if ($p_from == $p_to)
00626 $periode = " $p_field = (select p_id from parm_periode " .
00627 " where " .
00628 " p_start = to_date('$p_from','DD.MM.YYYY')) ";
00629 else
00630 $periode = "$p_field in (select p_id from parm_periode " .
00631 " where p_start >= to_date('$p_from','DD.MM.YYYY') and p_end <= to_date('$p_to','DD.MM.YYYY')) ";
00632 return $periode;
00633 }
00634
00635
00636
00637
00638
00639
00640
00641
00642 function alert($p_msg, $buffer=false)
00643 {
00644 $r = '<script>';
00645 $r.= 'alert(\'' . j($p_msg) . '\')';
00646 $r.= '</script>';
00647
00648 if ($buffer)
00649 return $r;
00650 echo $r;
00651 }
00652
00653
00654
00655
00656 function set_language()
00657 {
00658 // desactivate local check
00659 if ( defined("LOCALE") && LOCALE==0 ) return;
00660 if ( ! isset ($_SESSION['g_lang'])) return;
00661 $dir = "";
00662 // set differently the language depending of the operating system
00663 if (what_os() == 1)
00664 {
00665 $dir = setlocale(LC_MESSAGES, $_SESSION['g_lang']);
00666 if ($dir == "")
00667 {
00668 $g_lang = 'fr_FR.utf8';
00669 $dir = setlocale(LC_MESSAGES, $g_lang);
00670 // echo '<span class="notice">' . $_SESSION['g_lang'] . ' domaine non supporté</h2>';
00671 }
00672 bindtextdomain('messages', './lang');
00673 textdomain('messages');
00674 bind_textdomain_codeset('messages', 'UTF8');
00675
00676 return;
00677 }
00678 // for windows
00679 putenv('LANG=' . $_SESSION['g_lang']);
00680 $dir = setlocale(LC_ALL, $_SESSION['g_lang']);
00681 bindtextdomain('messages', '.\\lang');
00682 textdomain('messages');
00683 bind_textdomain_codeset('messages', 'UTF8');
00684 }
00685
00686
00687
00688
00689
00690
00691
00692
00693 function what_os()
00694 {
00695 $inc_path = get_include_path();
00696
00697 if (strpos($inc_path, ";") != 0)
00698 {
00699 $os = 0; /* $os is 0 for windoz */
00700 }
00701 else
00702 {
00703 $os = 1; /* $os is 1 for unix */
00704 }
00705 return $os;
00706 }
00707
00708
00709
00710
00711
00712
00713 function shrink_date($p_date)
00714 {
00715 $date = str_replace('.', '', $p_date);
00716 $str_date = substr($date, 0, 4) . substr($date, 6, 2);
00717 return $str_date;
00718 }
00719
00720
00721
00722
00723
00724 function smaller_date($p_date)
00725 {
00726 $str_date = substr($p_date, 0, 6) . substr($p_date, 8, 2);
00727 return $str_date;
00728 }
00729
00730
00731
00732
00733
00734
00735
00736
00737 function format_date($p_date, $p_from_format = 'YYYY-MM-DD',$p_to_format='DD.MM.YYYY')
00738 {
00739 if ($p_from_format == 'YYYY-MM-DD')
00740 {
00741 $date = explode('-', $p_date);
00742 if (count($date) != 3)
00743 return $p_date;
00744 }
00745 if ($p_from_format == 'DD.MM.YYYY')
00746 {
00747 $temp_date = explode('.', $p_date);
00748 if (count($temp_date) != 3)
00749 return $p_date;
00750 $date[0] = $temp_date[2]; // 0 is year
00751 $date[1] = $temp_date[1]; // 1 for month
00752 $date[2] = $temp_date[0]; // 2 for day
00753 }
00754
00755 switch ($p_to_format)
00756 {
00757 case 'DD.MM.YYYY':
00758 $str_date = $date[2] . '.' . $date[1] . '.' . $date[0];
00759 break;
00760 case 'YYYY-MM-DD':
00761 $str_date = $date[0] . '-' . $date[1] . '-' . $date[2];
00762 break;
00763 case 'YYYYMMDD':
00764 $str_date = $date[0] . $date[1] . $date[2];
00765 break;
00766 case 'YYYY/MM/DD':
00767 $str_date = $date[0] . '/' . $date[1] . '/' . $date[2];
00768 break;
00769
00770 }
00771 return $str_date;
00772 }
00773
00774
00775
00776
00777
00778
00779 function ajax_disconnected($div)
00780 {
00781
00782
00783
00784 if (!isset($_SESSION['g_user']))
00785 {
00786 $script = 'var a=$("' . $div . '");a.style.height="70%";a.style.width="70%";';
00787 $script.='a.style.top=posY-20+offsetY;a.style.left=posX+offsetX;';
00788 $script = create_script($script);
00789 $html = $script;
00790 $html.=HtmlInput::anchor_close($div);
00791 $html.='<div>';
00792 $html.=h2(_('Données non disponibles'), 'class="title" style="width:auto"');
00793 $html.=h2(_('Veuillez vous reconnecter'), 'class="error"');
00794 $html.=alert(_("Déconnecté"), true);
00795 $html.="<script>logout();</script>";
00796 $html = escape_xml($html);
00797 header('Content-type: text/xml; charset=UTF-8');
00798 echo <<<EOF
00799 <?xml version="1.0" encoding="UTF-8"?>
00800 <data>
00801 <ctl>$div</ctl>
00802 <code>$html</code>
00803 </data>
00804 EOF;
00805 exit();
00806 }
00807 }
00808
00809
00810
00811
00812
00813 function show_module($selected)
00814 {
00815 global $g_user;
00816 $cn = Dossier::connect();
00817 $amodule = $cn->get_array("select
00818 me_code,me_menu,me_url,me_javascript,p_order,me_type,me_description
00819 from v_all_menu
00820 where
00821 user_name=$1
00822 and p_type_display='M'
00823 order by p_order", array($g_user->login));
00824
00825 if ($selected != -1)
00826 {
00827 require_once('template/module.php');
00828 $file = $cn->get_array("select me_file,me_parameter,me_javascript,me_type,me_description from v_all_menu
00829 where me_code=$1 and user_name=$2", array($selected,$g_user->login));
00830 if ( count($file ) == 0 )
00831 {
00832 echo '</div>';
00833 echo '</div>';
00834 echo '<div class="content">';
00835 echo_warning(_("Module inexistant")."[ $selected ] ");
00836 echo '</div>';
00837 exit();
00838 }
00839 if ($file[0]['me_file'] != '')
00840 {
00841 if ($file[0]['me_parameter'] != "")
00842 {
00843 // if there are paramter put them in superglobal
00844 $array=compute_variable($file[0]['me_parameter']);
00845 put_global($array);
00846 }
00847
00848 // if file is not a plugin, include the file, otherwise
00849 // include the plugin launcher
00850 if ($file[0]['me_type'] != 'PL')
00851 {
00852 require_once $file[0]['me_file'];
00853 }
00854 else
00855 {
00856 // nothing : direct call to plugin
00857 }
00858 }
00859 if ( $file[0]['me_javascript'] != '')
00860 {
00861 create_script($file[0]['me_javascript']);
00862 }
00863 }
00864 }
00865
00866
00867
00868
00869
00870 function find_default_module()
00871 {
00872 global $g_user;
00873 $cn = Dossier::connect();
00874
00875 $default_module = $cn->get_array("select me_code
00876 from profile_menu join profile_user using (p_id)
00877 where
00878 p_type_display='M' and
00879 user_name=$1 and pm_default=1", array($g_user->login));
00880
00881 /*
00882 * Try to find the smallest order for module
00883 */
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='M' and
00890 user_name=$1 order by p_order limit 1", array($g_user->login));
00891
00892 // if no default try to find the default menu
00893 if ( empty ($default_module))
00894 {
00895 $default_module = $cn->get_array("select me_code
00896 from profile_menu join profile_user using (p_id)
00897 where
00898 p_type_display='E' and
00899 user_name=$1 and pm_default=1 ", array($g_user->login));
00900 /*
00901 * Try to find a default menu by order
00902 */
00903 if (empty ($default_module))
00904 {
00905 $default_module = $cn->get_array("select me_code
00906 from profile_menu join profile_user using (p_id)
00907 where
00908 user_name=$1 and p_order=(select min(p_order) from profile_menu join profile_user using (p_id)
00909 where user_name=$2) limit 1", array($g_user->login, $g_user->login));
00910 }
00911
00912 /*
00913 * if nothing found, there is no profile for this user => exit
00914 */
00915 if (empty ($default_module))
00916 {
00917 echo_warning(_("Utilisateur n'a pas de profile, votre administrateur doit en configurer un dans CFGSEC"));
00918 exit();
00919 }
00920 }
00921 return $default_module[0]['me_code'];
00922 }
00923
00924 if (count($default_module) > 1)
00925 {
00926 // return the first module found
00927 return $default_module[0]['me_code'];
00928 }
00929 elseif (count($default_module) == 1)
00930 {
00931 return $default_module[0]['me_code'];
00932 }
00933 }
00934
00935
00936
00937
00938
00939
00940
00941 function show_menu($module, $idx)
00942 {
00943 global $g_user;
00944 $cn = Dossier::connect();
00945 $amenu = $cn->get_array("select
00946 me_menu,me_code,me_url,me_javascript,me_type,me_description
00947 from v_all_menu
00948 where
00949 me_code_dep=$1 and user_name=$2 order by p_order", array($module[$idx], $g_user->login));
00950
00951 if (!empty($amenu) && count($amenu) > 1)
00952 {
00953 $a_style_menu=array('topmenu','menu2','menu3');
00954 if ( $idx > count($a_style_menu))
00955 $style_menu='menu3';
00956 else {
00957 $style_menu=$a_style_menu[$idx];
00958 }
00959 require 'template/menu.php';
00960 }
00961 elseif (count($amenu) == 1)
00962 {
00963 echo '<div class="topmenu">';
00964 echo h2info($amenu[0]['me_menu']);
00965 echo '</div>';
00966 $module[$idx] = $amenu[0]['me_code'];
00967 }
00968
00969 if (empty($amenu) || count($amenu) == 1)
00970 {
00971 $file = $cn->get_array("select me_file,me_parameter,me_javascript,me_type
00972 from menu_ref
00973 join profile_menu using (me_code)
00974 join profile_user using (p_id)
00975 where
00976 me_code=$1 and
00977 user_name=$2 and
00978 (me_file is not null or trim(me_file) <>'' or
00979 me_javascript is not null or trim (me_javascript) <> '')", array($module[$idx],$g_user->login));
00980
00981 if (count($file)==0)
00982 {
00983 echo "Configuration incorrecte pour ce module ".$module[$idx];
00984 exit;
00985 }
00986
00987 if ($file[0]['me_file'] != "")
00988 {
00989 if ($file[0]['me_parameter'] !== "")
00990 {
00991 // if there are paramter put them in superglobal
00992 $array=compute_variable($file[0]['me_parameter']);
00993 put_global($array);
00994 }
00995 /*
00996 * Log the file we input to put in the folder test-noalyss for replaying it
00997 */
00998 if (LOGINPUT) {
00999 $file_loginput=fopen($_ENV['TMP'].'/scenario-'.$_SERVER['REQUEST_TIME'].'.php','a+');
01000 fwrite($file_loginput, "include '".$file[0]['me_file']."';");
01001 fwrite($file_loginput,"\n");
01002 fclose($file_loginput);
01003 }
01004 // if file is not a plugin, include the file, otherwise
01005 // include the plugin launcher
01006 if ( $file[0]['me_type'] != 'PL')
01007 require_once $file[0]['me_file'];
01008 else
01009 require 'extension_get.inc.php';
01010
01011 exit();
01012 }
01013 if ( $file[0]['me_javascript'] != '')
01014 {
01015 $js= str_replace('<DOSSIER>', dossier::id(), $file[0]['me_javascript']);
01016 echo create_script($js);
01017 }
01018 }
01019 }
01020
01021
01022
01023
01024
01025 function put_global($array)
01026 {
01027 for ($i=0;$i<count($array);$i++)
01028 {
01029 $key=$array[$i]['key'];
01030 $value=$array[$i]['value'];
01031 $_GET[$key]=$value;
01032 $_POST[$key]=$value;
01033 $_REQUEST[$key]=$value;
01034 }
01035 }
01036
01037
01038
01039
01040
01041
01042 function compute_variable($p_string)
01043 {
01044 $array=array();
01045 if ($p_string == '') return $array;
01046
01047 $var=explode("&",$p_string);
01048 if (empty ($var)) return $array;
01049 for ($i=0;$i < count($var);$i++)
01050 {
01051 $var2=explode('=',$var[$i]);
01052 $array[$i]['key']=$var2[0];
01053 $array[$i]['value']=$var2[1];
01054 }
01055 return $array;
01056 }
01057 function ajax_xml_error($p_code,$p_string)
01058 {
01059 $html = escape_xml($p_string);
01060 header('Content-type: text/xml; charset=UTF-8');
01061 echo <<<EOF
01062 <?xml version="1.0" encoding="UTF-8"?>
01063 <data>
01064 <code>$p_code</code>
01065 <value>$html</value>
01066 </data>
01067 EOF;
01068 }
01069 function display_dashboard_operation($p_array,$p_title,$p_div)
01070 {
01071 ?>
01072 <div id="<?php echo $p_div;?>" class="inner_box" style="display:none;top:250;left:25%;width: 50%;min-height:50%;overflow:auto;">
01073 <?php
01074 echo HtmlInput::title_box($p_title, $p_div, "hide");
01075 ?>
01076 <?php if (count($p_array)>0) :?>
01077 <table class="result">
01078 <tr>
01079 <th><?php echo _('Date')?></th>
01080 <th><?php echo _('Code Interne')?></th>
01081 <th><?php echo _('Description')?></th>
01082 <th>
01083 <?php echo _('Montant')?>
01084 </th>
01085
01086 </tr>
01087 <?php
01088 for ($i=0;$i<count($p_array);$i++):
01089 ?>
01090 <tr class="<?php echo (($i%2)==0)?'odd':'even';?>">
01091 <td>
01092 <?php echo smaller_date(format_date($p_array[$i]['jr_date']) );?>
01093 </td>
01094 <td>
01095 <?php echo HtmlInput::detail_op($p_array[$i]['jr_id'], $p_array[$i]['jr_internal']) ?>
01096 </td>
01097 <td>
01098 <?php echo h($p_array[$i]['jr_comment']) ?>
01099 </td>
01100 <td>
01101 <?php echo nbm($p_array[$i]['jr_montant']) ?>
01102 </td>
01103 </tr>
01104 <?php
01105 endfor;
01106 ?>
01107 </table>
01108 <?php else: ?>
01109 <h2 class="notice"><?php echo _('Aucune donnée')?></h2>
01110 <?php
01111 endif;
01112 ?>
01113 </div>
01114 <?php
01115 }
01116 function get_array_column($p_array,$key)
01117 {
01118 $array=array();
01119 for ($i=0;$i<count($p_array);$i++)
01120 {
01121 $r=$p_array[$i];
01122 if ( isset($r[$key])) {
01123 $array[]=$r[$key];
01124 }
01125 }
01126 return $array;
01127 }
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137 function factory_Ledger(Database &$p_cn, $ledger_id)
01138 {
01139 include_once 'class_acc_ledger_sold.php';
01140 include_once 'class_acc_ledger_purchase.php';
01141 include_once 'class_acc_ledger_fin.php';
01142
01143 $ledger=new Acc_Ledger($p_cn, $ledger_id);
01144 $type=$ledger->get_type();
01145
01146 switch ($type)
01147 {
01148 case 'VEN':
01149 $obj=new Acc_Ledger_Sold($p_cn, $ledger_id);
01150 break;
01151 case 'ACH':
01152 $obj=new Acc_Ledger_Purchase($p_cn, $ledger_id);
01153 break;
01154 case 'FIN':
01155 $obj= new Acc_Ledger_Fin($p_cn, $ledger_id);
01156 break;
01157 case 'ODS':
01158 $obj=$ledger;
01159 break;
01160
01161 default:
01162 throw new Exception('Ledger type not found');
01163 }
01164 return $obj;
01165 }
01166
01167
01168
01169
01170 function is_msie()
01171 {
01172 if ( strpos ($_SERVER['HTTP_USER_AGENT'],'MSIE 8.0') != 0 ||
01173 strpos ($_SERVER['HTTP_USER_AGENT'],'MSIE 9.0') != 0 )
01174 $is_msie=1;
01175 else
01176 $is_msie=0;
01177 return $is_msie;
01178 }
01179 ?>