1<?php 2/* 3 * Copyright 2005-2016 OCSInventory-NG/OCSInventory-ocsreports contributors. 4 * See the Contributors file for more details about them. 5 * 6 * This file is part of OCSInventory-NG/OCSInventory-ocsreports. 7 * 8 * OCSInventory-NG/OCSInventory-ocsreports is free software: you can redistribute 9 * it and/or modify it under the terms of the GNU General Public License as 10 * published by the Free Software Foundation, either version 2 of the License, 11 * or (at your option) any later version. 12 * 13 * OCSInventory-NG/OCSInventory-ocsreports is distributed in the hope that it 14 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with OCSInventory-NG/OCSInventory-ocsreports. if not, write to the 20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 21 * MA 02110-1301, USA. 22 */ 23$chiffres = "onKeyPress=\"return scanTouche(event,/[0-9]/)\" onkeydown='convertToUpper(this)' 24 onkeyup='convertToUpper(this)' 25 onblur='convertToUpper(this)' 26 onclick='convertToUpper(this)'"; 27$majuscule = "onKeyPress=\"return scanTouche(event,/[0-9 a-z A-Z]/)\" onkeydown='convertToUpper(this)' 28 onkeyup='convertToUpper(this)' 29 onblur='convertToUpper(this)'"; 30$sql_field = "onKeyPress=\"return scanTouche(event,/[0-9a-zA-Z_-]/)\" onkeydown='convertToUpper(this)' 31 onkeyup='convertToUpper(this)' 32 onblur='convertToUpper(this)'"; 33 34function printEnTete($ent) { 35 echo "<h3 class='text-center'>$ent</h3>"; 36} 37 38/** 39 * Includes the javascript datetime picker 40 */ 41function incPicker() { 42 global $l; 43 44 echo "<script type='text/javascript'> 45 var MonthName=["; 46 47 for ($mois = 527; $mois < 538; $mois++) { 48 echo "\"" . $l->g($mois) . "\","; 49 } 50 echo "\"" . $l->g(538) . "\""; 51 52 echo "]; 53 var WeekDayName=["; 54 55 for ($jour = 539; $jour < 545; $jour++) { 56 echo "\"" . $l->g($jour) . "\","; 57 } 58 echo "\"" . $l->g(545) . "\""; 59 60 echo "]; 61 </script> 62 <script type='text/javascript' src='js/bootstrap-datetimepicker.js'></script>"; 63} 64 65 66function datePick($input, $checkOnClick = false) { 67 global $l; 68 $dateForm = $l->g(1270); 69 if ($checkOnClick) { 70 $cOn = ",'$checkOnClick'"; 71 } 72 $ret = "<span class=\"glyphicon glyphicon-calendar\"></span>"; 73 $ret .= "<script type=\"text/javascript\"> 74 $(\".form_datetime\").datetimepicker({ 75 format: \"".$dateForm."\", 76 autoclose: true, 77 todayBtn: true, 78 pickerPosition: \"bottom-left\" 79 }); 80 </script>"; 81 return $ret; 82} 83 84function replace_entity_xml($txt) { 85 $cherche = array("&", "<", ">", "\"", "'"); 86 $replace = array("&", "<", ">", """, "'"); 87 return str_replace($cherche, $replace, $txt); 88} 89 90function printEnTete_tab($ent) { 91 echo "<br><table border=0 WIDTH = '62%' ALIGN = 'Center' CELLPADDING='5'> 92 <tr height=40px bgcolor=#f2f2f2 align=center><td><b>" . $ent . "</b></td></tr></table>"; 93} 94 95function xml_encode($txt) { 96 $cherche = array("&", "<", ">", "\"", "'", "é", "è", "ô", "Î", "î", "à", "ç", "ê", "â"); 97 $replace = array("&", "<", ">", """, "'", "é", "è", "ô", "Î", "î", "à", "ç", "ê", "â"); 98 return str_replace($cherche, $replace, $txt); 99} 100 101function xml_decode($txt) { 102 $cherche = array("â", "ê", "ç", "à", "<", ">", """, "'", "é", "è", "ô", "Î", "î", "&"); 103 $replace = array("â", "ê", "ç", "à", "<", ">", "\"", "'", "é", "è", "ô", "Î", "î", "&"); 104 return str_replace($cherche, $replace, $txt); 105} 106 107//fonction qui permet d'afficher un tableau dynamique de données 108/* 109 * Columns : Each available column of the table 110 * $columns = array { 111 * 'NAME'=>'h.name', ... 112 * 'Column name' => Database value, 113 * } 114 * Default_fields : Default columns displayed 115 * $default_fields= array{ 116 * 'NAME'=>'NAME', ... 117 * 'Column name' => 'Column name', 118 * } 119 * Option : All the options for the specific table 120 * $option= array{ 121 * 'form_name'=> "show_all",.... 122 * 'Option' => value, 123 * 124 * } 125 * List_col_cant_del : All the columns that will always be displayed 126 * $list_col_cant_del= array { 127 * 'NAME'=>'NAME', ... 128 * 'Column name' => 'Column name', 129 * } 130 */ 131function ajaxtab_entete_fixe($columns, $default_fields, $option = array(), $list_col_cant_del) { 132 global $protectedPost, $l, $pages_refs; 133 134 //Translated name of the column 135 $lbl_column = array("ACTIONS" => $l->g(1381), 136 "CHECK" => "<input type='checkbox' name='ALL' id='checkboxALL' Onclick='checkall();'>"); 137 if (!isset($tab_options['NO_NAME']['NAME'])) { 138 $lbl_column["NAME"] = $l->g(23); 139 } 140 141 if (!empty($option['LBL'])) { 142 $lbl_column = array_merge($lbl_column, $option['LBL']); 143 } 144 $columns_special = array("CHECK", 145 "SUP", 146 "NBRE", 147 "NULL", 148 "MODIF", 149 "SELECT", 150 "ZIP", 151 "OTHER", 152 "STAT", 153 "ACTIVE", 154 "MAC", 155 "EDIT_DEPLOY", 156 "SHOW_DETAILS", 157 "ARCHIVER", 158 "RESTORE", 159 ); 160 //If the column selected are different from the default columns 161 if (!empty($_COOKIE[$option['table_name'] . "_col"])) { 162 $visible_col = unserialize($_COOKIE[$option['table_name'] . "_col"]); 163 } 164 165 $input = $columns; 166 167 //Don't allow to hide columns that should not be hidden 168 foreach ($list_col_cant_del as $key => $col_cant_del) { 169 unset($input[$col_cant_del]); 170 unset($input[$key]); 171 } 172 $list_col_can_del = $input; 173 $columns_unique = array_unique($columns); 174 if (isset($columns['CHECK'])) { 175 $column_temp = $columns['CHECK']; 176 unset($columns['CHECK']); 177 $columns_temp['CHECK'] = $column_temp; 178 $columns = $columns_temp + $columns; 179 } 180 $actions = array( 181 "MODIF", 182 "EDIT_DEPLOY", 183 "SUP", 184 "ZIP", 185 "STAT", 186 "ACTIVE", 187 "SHOW_DETAILS", 188 "ARCHIVER", 189 "RESTORE", 190 ); 191 $action_visible = false; 192 193 foreach ($actions as $action) { 194 if (isset($columns[$action])) { 195 $action_visible = true; 196 $columns['ACTIONS'] = "h.ID"; 197 break; 198 } 199 } 200 //Set the ajax requested address 201 if (isset($_SERVER['QUERY_STRING'])) { 202 if (isset($option['computersectionrequest'])) { 203 parse_str($_SERVER['QUERY_STRING'], $addressoption); 204 unset($addressoption['all']); 205 unset($addressoption['cat']); 206 $addressoption['option'] = $option['computersectionrequest']; 207 $address = "ajax.php?" . http_build_query($addressoption); 208 } else { 209 $address = isset($_SERVER['QUERY_STRING']) ? "ajax.php?" . $_SERVER['QUERY_STRING'] : ""; 210 } 211 } 212 $opt = false; 213 ?> 214 215 <div align=center> 216 <div class="<?php echo $option['table_name']; ?>_top_settings" style="display:none;"> 217 </div> 218 <?php 219 220 if (!isset ($protectedPost['COL_SEARCH'])){ 221 $selected_col='ALL'; 222 } else { 223 $selected_col = $protectedPost['COL_SEARCH']; 224 } 225 226 //Display the Column selector 227 if (!empty($list_col_can_del)) { 228 // Sort columns show / hide select by default 229 ksort($list_col_can_del); 230 231 $opt = true; 232 ?> 233 234 <div class="row"> 235 <div class="col col-md-4 col-xs-offset-0 col-md-offset-4"> 236 <div class="form-group"> 237 <label class="control-label col-sm-4" for="select_col<?php echo $option['table_name']; ?>"><?php echo $l->g(1349); ?> :</label> 238 <div class="col-sm-8"> 239 <select class="form-control" id="select_col<?php echo $option['table_name']; ?>" name="select_col<?php echo $option['table_name']; ?>"> 240 <option value="default"><?php echo $l->g(6001); ?></option> 241 <?php 242 foreach ($list_col_can_del as $key => $col) { 243 $name = explode('.', $col); 244 $name = explode(' as ', end($name)); 245 $value = end($name); 246 if (!empty($option['REPLACE_COLUMN_KEY'][$key])) { 247 $value = $option['REPLACE_COLUMN_KEY'][$key]; 248 } 249 if (array_key_exists($key, $lbl_column)) { 250 echo "<option value='$value'>$lbl_column[$key]</option>"; 251 } else { 252 echo "<option value='$value'>$key</option>"; 253 } 254 } 255 ?> 256 </select> 257 </div> 258 </div> 259 </div> 260 </div> 261 262 <?php 263 } 264 ?> 265 266 267 <div id="<?php echo $option['table_name']; ?>_csv_download" 268 style="display: none"> 269 <?php 270 //Display of the result count 271 if (!isset($option['no_download_result'])) { 272 echo "<div id='" . $option['table_name'] . "_csv_page'><label id='infopage_" . $option['table_name'] . "'></label> " . $l->g(90) . "<a href='index.php?" . PAG_INDEX . "=" . $pages_refs['ms_csv'] . "&no_header=1&tablename=" . $option['table_name'] . "&base=" . $tab_options['BASE'] . "'><small> (" . $l->g(183) . ")</small></a></div>"; 273 echo "<div id='" . $option['table_name'] . "_csv_total'><label id='infototal_" . $option['table_name'] . "'></label> " . $l->g(90) . " <a href='index.php?" . PAG_INDEX . "=" . $pages_refs['ms_csv'] . "&no_header=1&tablename=" . $option['table_name'] . "&nolimit=true&base=" . $tab_options['BASE'] . "'><small>(" . $l->g(183) . ")</small></a></div>"; 274 } 275 ?> 276 </div> 277 <?php 278 echo "<a href='#' id='reset" . $option['table_name'] . "' onclick='delete_cookie(\"" . $option['table_name'] . "_col\");window.location.reload();' style='display: none;' >" . $l->g(1380) . "</a>"; 279 ?> 280 </div> 281 282 <script> 283 // Check all the checkboxes 284 function checkall() 285 { 286 var table_id = "table#<?php echo $option['table_name']; ?>"; 287 $(table_id + " tbody tr td input:checkbox").each(function () { 288 value = !$(this).attr('checked'); 289 document.getElementById($(this).attr('id')).checked = value; 290 }); 291 } 292 $(document).ready(function () { 293 var table_name = "<?php echo $option['table_name']; ?>"; 294 var table_id = "table#<?php echo $option['table_name']; ?>"; 295 var form_name = "form#<?php echo $option['form_name']; ?>"; 296 var csrfid = "input#CSRF_<?php echo $_SESSION['OCS']['CSRFNUMBER']; ?>"; 297 298 /* 299 Table Skeleton Creation. 300 A Full documentation about DataTable constructor can be found at 301 https://datatables.net/manual/index 302 */ 303 var dom = '<<"row"lf ' + 304 '<"dataTables_processing" r>><"#' + table_name + '_settings" >' + 305 't<"row" <"col-md-2" i><"col-md-10" p>>>'; 306 307 var table = $(table_id).dataTable({ 308 "processing": true, 309 "serverSide": true, 310 "dom": dom, 311 "ajax": { 312 'url': '<?php echo $address; ?>&no_header=true&no_footer=true', 313 "type": "POST", 314 //Error handling 315 "error": function (xhr, error, thrown) { 316 var statusErrorMap = { 317 '400': "<?php echo $l->g(1352); ?>", 318 '401': "<?php echo $l->g(1353); ?>", 319 '403': "<?php echo $l->g(1354); ?>", 320 '404': "<?php echo $l->g(1355); ?>", 321 '414': "<?php echo $l->g(1356); ?>", 322 '500': "<?php echo $l->g(1357); ?>", 323 '503': "<?php echo $l->g(1358); ?>" 324 }; 325 if (statusErrorMap[xhr.status] != undefined) { 326 if (xhr.status == 401) { 327 window.location.reload(); 328 } 329 } 330 }, 331 //Set the $_POST request to the ajax file. d contains all datatables needed info 332 "data": function (d) { 333 if ($(table_id).width() < $(this).width()) { 334 $(table_id).width('100%'); 335 $(".dataTables_scrollHeadInner").width('100%'); 336 $(".dataTables_scrollHeadInner>table").width('100%'); 337 } 338 //Add CSRF 339 d.CSRF_<?php echo $_SESSION['OCS']['CSRFNUMBER']; ?> = $(csrfid).val(); 340 var visible = []; 341 if (document.getElementById('checkboxALL')) { 342 document.getElementById('checkboxALL').checked = false; 343 } 344 $.each(d.columns, function (index, value) { 345 var col = "." + this['data']; 346 if ($(table_id).DataTable().column(col).visible()) { 347 visible.push(index); 348 } 349 }); 350 var ocs = []; 351 //Add the actual $_POST to the $_POST of the ajax request 352 <?php 353 foreach ($protectedPost as $key => $value) { 354 if (!is_array($value)) { 355 echo "d['" . $key . "'] = '" . $value . "'; \n"; 356 } 357 if($key == "visible_col") { 358 $visible_col = $value; 359 } 360 } 361 ?> 362 ocs.push($(form_name).serialize()); 363 d.visible_col = visible; 364 d.ocs = ocs; 365 }, 366 "dataSrc": function (json) { 367 if (json.customized) { 368 $("#reset" + table_name).show(); 369 } else { 370 $("#reset" + table_name).hide(); 371 } 372 if (json.debug) { 373 $("<p>" + json.debug + "</p><hr>").hide().prependTo('#' + table_name + '_debug div').fadeIn(1000); 374 $(".datatable_request").show(); 375 } 376 return json.data; 377 }, 378 379 }, 380 381 //Save datatable state (page length, sort order, ...) in localStorage 382 "stateSave": true, 383 "stateDuration": 0, 384 //Override search filter and page start after loading last datatable state 385 "stateLoadParams": function (settings, data) { 386 data.search.search = ""; 387 data.start = 0; 388 }, 389 "conditionalPaging": true, 390 "lengthMenu": [ 10, 25, 50, 100, 250, 500, 1000], 391 //Column definition 392 "columns": [ 393 <?php 394 395 $index = 0; 396 397 // Unset visible columns session var 398 unset($_SESSION['OCS']['visible_col'][$option['table_name']]); 399 400 //Visibility handling 401 foreach ($columns as $key => $column) { 402 if (!empty($visible_col)) { 403 if ((in_array($index, $visible_col))) { 404 // add visibles columns 405 $_SESSION['OCS']['visible_col'][$option['table_name']][$key] = $column; 406 $visible = 'true'; 407 } else { 408 $visible = 'false'; 409 } 410 $index ++; 411 } else { 412 if (( (in_array($key, $default_fields)) || (in_array($key, $list_col_cant_del)) || array_key_exists($key, $default_fields) || ($key == "ACTIONS" )) && !(in_array($key, $actions))) { 413 // add visibles columns 414 $_SESSION['OCS']['visible_col'][$option['table_name']][$key] = $column; 415 $visible = 'true'; 416 } else { 417 $visible = 'false'; 418 } 419 } 420 //Can the column be ordered 421 if (in_array($key, $columns_special) || !empty($option['NO_TRI'][$key]) || $key == "ACTIONS") { 422 $orderable = 'false'; 423 } else { 424 $orderable = 'true'; 425 } 426 //Cannot search in Delete or checkbox columns 427 if (!array_key_exists($key, $columns_unique) || in_array($key, $columns_special)) { 428 if (!empty($option['REPLACE_COLUMN_KEY'][$key])) { 429 $key = $option['REPLACE_COLUMN_KEY'][$key]; 430 } 431 echo "{'data' : '" . $key . "' , 'class':'" . $key . "', 432'name':'" . $key . "', 'defaultContent': ' ', 433'orderable': " . $orderable . ",'searchable': false, 434'visible' : " . $visible . "}, \n"; 435 } else { 436 $name = explode('.', $column); 437 $name = explode(' as ', end($name)); 438 $name = end($name); 439 if (!empty($option['REPLACE_COLUMN_KEY'][$key])) { 440 $name = $option['REPLACE_COLUMN_KEY'][$key]; 441 } 442 echo "{ 'data' : '" . $name . "' , 'class':'" . $name . "', 443'name':'" . $column . "', 'defaultContent': ' ', 444'orderable': " . $orderable . ", 'visible' : " . $visible . "},\n "; 445 } 446 } 447 ?> 448 ], 449 //Translation 450 "language": { 451 "sEmptyTable": "<?php echo $l->g(1334); ?>", 452 "sInfo": "<?php echo $l->g(1335); ?>", 453 "sInfoEmpty": "<?php echo $l->g(1336); ?>", 454 "sInfoFiltered": "<?php echo $l->g(1337); ?>", 455 "sInfoPostFix": "", 456 "sInfoThousands": "<?php echo $l->g(1350); ?>", 457 "decimal": "<?php echo $l->g(1351); ?>", 458 "sLengthMenu": "<?php echo $l->g(1338); ?>", 459 "sLoadingRecords": "<?php echo $l->g(1339); ?>", 460 "sProcessing": "<?php echo $l->g(1340); ?>", 461 "sSearch": "<?php echo $l->g(1341); ?>", 462 "sZeroRecords": "<?php echo $l->g(1342); ?>", 463 "oPaginate": { 464 "sFirst": "<?php echo $l->g(1343); ?>", 465 "sLast": "<?php echo $l->g(1344); ?>", 466 "sNext": "<?php echo $l->g(1345); ?>", 467 "sPrevious": "<?php echo $l->g(1346); ?>", 468 }, 469 "oAria": { 470 "sSortAscending": ": <?php echo $l->g(1347); ?>", 471 "sSortDescending": ": <?php echo $l->g(1348); ?>", 472 } 473 }, 474 "scrollX": 'true' 475 }); 476 477 //Column Show/Hide 478 $("#select_col" + table_name).change(function () { 479 var col = "." + $(this).val(); 480 $(table_id).DataTable().column(col).visible(!($(table_id).DataTable().column(col).visible())); 481 $(table_id).DataTable().ajax.reload(); 482 $("#select_col" + table_name).val('default'); 483 }); 484 485 //$("<span id='" + table_name + "_settings_toggle' class='glyphicon glyphicon-chevron-down table_settings_toggle'></span>").hide().appendTo("#" + table_name + "_filter label"); 486 $("#" + table_name + "_settings").hide(); 487 $("." + table_name + "_top_settings").contents().appendTo("#" + table_name + "_settings"); 488 $("#" + table_name + "_settings").addClass('table_settings'); 489 $("body").on("click", "#" + table_name + "_settings_toggle", function () { 490 $("#" + table_name + "_settings_toggle").toggleClass("glyphicon-chevron-up"); 491 $("#" + table_name + "_settings_toggle").toggleClass("glyphicon-chevron-down"); 492 $("#<?php echo $option['table_name']; ?>_settings").fadeToggle(); 493 494 }); 495 <?php if ($opt) { ?> 496 $("#" + table_name + "_settings_toggle").show(); 497 <?php 498 } 499//Csv Export 500 if (!isset($option['no_download_result'])) { 501 ?> 502 $(table_id).on('draw.dt', function () { 503 var start = $(table_id).DataTable().page.info().start + 1; 504 var end = $(table_id).DataTable().page.info().end; 505 var total = $(table_id).DataTable().page.info().recordsDisplay; 506 //Show one line only if results fit in one page 507 if (total == 0) { 508 $('#' + table_name + '_csv_download').hide(); 509 $("#" + table_name + "_settings_toggle").hide(); 510 } else { 511 if (end != total || start != 1) { 512 $('#' + table_name + '_csv_page').show(); 513 $('#infopage_' + table_name).text(start + "-" + end); 514 } else { 515 $('#' + table_name + '_csv_page').hide(); 516 } 517 $('#infototal_' + table_name).text(total); 518 $('#' + table_name + '_csv_download').show(); 519 $("#" + table_name + "_settings_toggle").show(); 520 } 521 }); 522 <?php 523 } 524 ?> 525 }); 526 527 </script> 528 <?php 529 if ($titre != "") { 530 printEnTete_tab($titre); 531 } 532 echo "<div class='tableContainer'>"; 533 echo "<table id='" . $option['table_name'] . "' width='100%' class='table table-striped table-condensed table-hover cell-border'><thead><tr>"; 534 //titre du tableau 535 foreach ($columns as $k => $v) { 536 if (array_key_exists($k, $lbl_column)) { 537 echo "<th><font >" . $lbl_column[$k] . "</font></th>"; 538 } else { 539 echo "<th><font >" . $k . "</font></th>"; 540 } 541 } 542 echo "</tr> 543 </thead>"; 544 545 echo "</table></div>"; 546 echo "<input type='hidden' id='SUP_PROF' name='SUP_PROF' value=''>"; 547 echo "<input type='hidden' id='MODIF' name='MODIF' value=''>"; 548 echo "<input type='hidden' id='SELECT' name='SELECT' value=''>"; 549 echo "<input type='hidden' id='OTHER' name='OTHER' value=''>"; 550 echo "<input type='hidden' id='ACTIVE' name='ACTIVE' value=''>"; 551 echo "<input type='hidden' id='CONFIRM_CHECK' name='CONFIRM_CHECK' value=''>"; 552 echo "<input type='hidden' id='OTHER_BIS' name='OTHER_BIS' value=''>"; 553 echo "<input type='hidden' id='OTHER_TER' name='OTHER_TER' value=''>"; 554 echo "<input type='hidden' id='EDIT_DEPLOY' name='EDIT_DEPLOY' value=''>"; 555 echo "<input type='hidden' id='SHOW_DETAILS' name='SHOW_DETAILS' value=''>"; 556 echo "<input type='hidden' id='ARCHIVER' name='ARCHIVER' value=''>"; 557 echo "<input type='hidden' id='RESTORE' name='RESTORE' value=''>"; 558 559 if ($_SESSION['OCS']['DEBUG'] == 'ON') { 560 ?><center> 561 <div id="<?php echo $option['table_name']; ?>_debug" class="alert alert-info" role="alert"> 562 <b>[DEBUG]TABLE REQUEST[DEBUG]</b> 563 <hr> 564 <b class="datatable_request" style="display:none;">LAST REQUEST:</b> 565 <div></div> 566 </div> 567 </center><?php 568 } 569 return true; 570} 571 572function tab_entete_fixe($entete_colonne, $data, $titre, $width, $lien = array(), $option = array()) { 573 echo "<div align=center>"; 574 global $protectedGet, $l; 575 if ($protectedGet['sens'] == "ASC") { 576 $sens = "DESC"; 577 } else { 578 $sens = "ASC"; 579 } 580 581 if (isset($data)) { 582 ?> 583 <script> 584 function changerCouleur(obj, state) { 585 if (state == true) { 586 bcolor = obj.style.backgroundColor; 587 fcolor = obj.style.color; 588 obj.style.backgroundColor = '#FFDAB9'; 589 obj.style.color = 'red'; 590 return true; 591 } else { 592 obj.style.backgroundColor = bcolor; 593 obj.style.color = fcolor; 594 return true; 595 } 596 return false; 597 } 598 </script> 599 <?php 600 if ($titre != "") { 601 printEnTete_tab($titre); 602 } 603 echo "<div class='tableContainer' id='data' style=\"width:" . $width . "%;\"><table cellspacing='0' class='ta'><tr>"; 604 //titre du tableau 605 $i = 1; 606 607 foreach ($entete_colonne as $k => $v) { 608 if (in_array($v, $lien)) { 609 echo "<th class='ta' >" . $v . "</th>"; 610 } else { 611 echo "<th class='ta'><font size=1 align=center>" . $v . "</font></th>"; 612 } 613 $i++; 614 } 615 echo " 616 </tr> 617 <tbody class='ta'>"; 618 619 $j = 0; 620 //lignes du tableau 621 foreach ($data as $v2) { 622 ($j % 2 == 0 ? $color = "#f2f2f2" : $color = "#ffffff"); 623 echo "<tr class='ta' bgcolor='" . $color . "' onMouseOver='changerCouleur(this, true);' onMouseOut='changerCouleur(this, false);'>"; 624 foreach ($v2 as $k => $v) { 625 if (isset($option['B'][$i])) { 626 $begin = "<b>"; 627 $end = "</b>"; 628 } else { 629 $begin = ""; 630 $end = ""; 631 } 632 633 634 if ($v == "") { 635 $v = " "; 636 } 637 echo "<td class='ta' >" . $begin . $v . $end . "</td>"; 638 } 639 $j++; 640 echo "</tr><tr>"; 641 } 642 echo "</tr></tbody></table></div></div>"; 643 } else { 644 msg_warning($l->g(766)); 645 return false; 646 } 647 return true; 648} 649 650/* 651 * fonction liée à tab_modif_values qui permet d'afficher le champ défini avec la fonction champsform 652 * $name = nom du champ 653 * $input_name = nom du champ récupéré dans le $protectedPost 654 * $input_type = 0 : <input type='text'> 655 * 1 : <textarea> 656 * 2 : <select><option> 657 * $input_reload = si un select doit effectuer un reload, on y met le nom du formulaire à reload 658 * 659 */ 660function show_modif($name, $input_name, $input_type, $input_reload = "", $configinput = array('MAXLENGTH' => 100, 'SIZE' => 20, 'JAVASCRIPT' => "", 'DEFAULT' => "YES", 'COLS' => 30, 'ROWS' => 5)) 661{ 662 global $protectedPost, $l, $pages_refs; 663 664 if ($configinput == "") 665 $configinput = array('MAXLENGTH' => 100, 'SIZE' => 20, 'JAVASCRIPT' => "", 'DEFAULT' => "YES", 'COLS' => 30, 'ROWS' => 5); 666 //del stripslashes if $name is not an array 667 if (!is_array($name)) { 668 $name = htmlspecialchars($name, ENT_QUOTES); 669 } 670 if ($input_type == 1) { 671 672 return "<textarea name='" . $input_name . "' id='" . $input_name . "' cols='" . $configinput['COLS'] . "' rows='" . $configinput['ROWS'] . "' class='down' >" . $name . "</textarea>"; 673 674 } elseif ($input_type == 0) 675 return "<input type='text' name='" . $input_name . "' id='" . $input_name . "' SIZE='" . $configinput['SIZE'] . "' MAXLENGTH='" . $configinput['MAXLENGTH'] . "' value=\"" . $name . "\" class='form-control'\" " . $configinput['JAVASCRIPT'] . ">"; 676 elseif ($input_type == 2) { 677 $champs = "<div class='form-group'>"; 678 679 680 echo "<div class='col col-sm-10 col-sm-offset-2'>"; 681 $champs .= "<select name='" . $input_name . "' id='" . $input_name . "' " . (isset($configinput['JAVASCRIPT']) ? $configinput['JAVASCRIPT'] : ''); 682 if ($input_reload != "") $champs .= " onChange='document." . $input_reload . ".submit();'"; 683 $champs .= " class='down form-control' >"; 684 if (isset($configinput['DEFAULT']) and $configinput['DEFAULT'] == "YES") 685 $champs .= "<option value='' class='hi' ></option>"; 686 $countHl = 0; 687 if ($name != '') { 688 natcasesort($name); 689 foreach ($name as $key => $value) { 690 $champs .= "<option value=\"" . $key . "\""; 691 if ($protectedPost[$input_name] == $key) 692 $champs .= " selected"; 693 $champs .= ($countHl % 2 == 1 ? " class='hi'" : " class='down'") . " >" . $value . "</option>"; 694 $countHl++; 695 } 696 } 697 $champs .= "</select></div></div>"; 698 return $champs; 699 } elseif ($input_type == 3) { 700 $hid = "<input type='hidden' id='" . $input_name . "' name='" . $input_name . "' value='" . $name . "'>"; 701 // echo $name."<br>"; 702 return $name . $hid; 703 } elseif ($input_type == 4) 704 return "<input size='" . $configinput['SIZE'] . "' type='password' name='" . $input_name . "' class='hi' />"; 705 elseif ($input_type == 5 and isset($name) and is_array($name)) { 706 foreach ($name as $key => $value) { 707 $champs .= "<input type='checkbox' name='" . $input_name . "_" . $key . "' id='" . $input_name . "_" . $key . "' "; 708 if ($protectedPost[$input_name . "_" . $key] == 'on') 709 $champs .= " checked "; 710 if ($input_reload != "") $champs .= " onChange='document." . $input_reload . ".submit();'"; 711 $champs .= " >" . $value . " <br>"; 712 } 713 return $champs; 714 } elseif ($input_type == 6) { 715 if (isset($configinput['NB_FIELD'])) 716 $i = $configinput['NB_FIELD']; 717 else 718 $i = 6; 719 $j = 0; 720 echo $name; 721 while ($j < $i) { 722 $champs .= "<input type='text' name='" . $input_name . "_" . $j . "' id='" . $input_name . "_" . $j . "' SIZE='" . $configinput['SIZE'] . "' MAXLENGTH='" . $configinput['MAXLENGTH'] . "' value=\"" . $protectedPost[$input_name . "_" . $j] . "\" class='down'\" " . $configinput['JAVASCRIPT'] . ">"; 723 $j++; 724 } 725 return $champs; 726 } elseif ($input_type == 7) 727 return "<input type='hidden' id='" . $input_name . "' name='" . $input_name . "' value='" . $name . "'>"; 728 elseif ($input_type == 8) { 729 return "<input type='button' id='" . $input_name . "' name='" . $input_name . "' value='" . $l->g(1048) . "' OnClick='window.open(\"index.php?" . PAG_INDEX . "=" . $pages_refs['ms_upload_file_popup'] . "&head=1&n=" . $input_name . "&tab=" . $name . "&dde=" . $configinput['DDE'] . "\",\"active\",\"location=0,status=0,scrollbars=0,menubar=0,resizable=0,width=550,height=350\")'>"; 730 } elseif ($input_type == 9) { 731 $aff = ""; 732 if (is_array($name)) { 733 foreach ($name as $key => $value) { 734 $aff .= "<a href=\"index.php?" . PAG_INDEX . "=" . $pages_refs['ms_view_file'] . "&prov=dde_wk&no_header=1&value=" . $key . "\">" . 735 $value . "</a><br>"; 736 } 737 } 738 return $aff; 739 } elseif ($input_type == 10) { 740 //le format de de $name doit etre sous la forme d'une requete sql avec éventuellement 741 //des arguments. Dans ce cas, les arguments sont séparés de la requête par $$$$ 742 //et les arguments entre eux par des virgules 743 //echo $name; 744 $sql = explode('$$$$', $name); 745 if (isset($sql[1])) { 746 $arg_sql = explode(',', $sql[1]); 747 $i = 0; 748 while ($arg_sql[$i]) { 749 $arg[$i] = $protectedPost[$arg_sql[$i]]; 750 $i++; 751 } 752 } 753 if (isset($arg_sql)) 754 $result = mysql2_query_secure($sql[0], $_SESSION['OCS']["readServer"], $arg); 755 else 756 $result = mysql2_query_secure($sql[0], $_SESSION['OCS']["readServer"]); 757 if (isset($result) and $result != '') { 758 $i = 0; 759 while ($colname = mysqli_fetch_field($result)) 760 $entete2[$i++] = $colname->name; 761 762 $i = 0; 763 while ($item = mysqli_fetch_object($result)) { 764 $j = 0; 765 while ($entete2[$j]) { 766 $data2[$i][$entete2[$j]] = $item->$entete2[$j]; 767 $j++; 768 } 769 $i++; 770 } 771 } 772 return tab_entete_fixe($entete2, $data2, "", 60, 300); 773 } elseif ($input_type == 11 and isset($name) and is_array($name)) { 774 foreach ($name as $key => $value) { 775 $champs .= "<input type='radio' name='" . $input_name . "' id='" . $input_name . "' value='" . $key . "'"; 776 if ($protectedPost[$input_name] == $key) { 777 $champs .= " checked "; 778 } 779 $champs .= " >" . $value . " <br>"; 780 } 781 return $champs; 782 } elseif ($input_type == 12) { //IMG type 783 $champs = "<img src='" . $configinput['DEFAULT'] . "' "; 784 if ($configinput['SIZE'] != '20') 785 $champs .= $configinput['SIZE'] . " "; 786 787 if ($configinput['JAVASCRIPT'] != '') 788 $champs .= $configinput['JAVASCRIPT'] . " "; 789 $champs .= ">"; 790 return $champs; 791 //"<img src='index.php?".PAG_INDEX."=".$pages_refs['ms_qrcode']."&no_header=1&systemid=".$protectedGet['systemid']."' width=60 height=60 onclick=window.open(\"index.php?".PAG_INDEX."=".$pages_refs['ms_qrcode']."&no_header=1&systemid=".$protectedGet['systemid']."\")>"; 792 793 } elseif ($input_type == 13) { 794 795 return "<input id='" . $input_name . "' name='" . $input_name . "' type='file' accept='archive/zip'>"; 796 797 } 798} 799 800function tab_modif_values($field_labels, $fields, $hidden_fields, $options = array()) { 801 global $l; 802 803 $options = array_merge(array( 804 'title' => null, 805 'comment' => null, 806 'button_name' => 'modif', 807 'show_button' => true, 808 'form_name' => 'CHANGE', 809 'top_action' => null, 810 'show_frame' => true 811 ), $options); 812 813 if ($options['form_name'] != 'NO_FORM') { 814 echo open_form($options['form_name'], '', '', 'form-horizontal'); 815 } 816 817 if ($options['show_frame']) { 818 echo '<div class="form-frame form-frame-'.$options['form_name'].'">'; 819 } 820 if ($options['title']) { 821 echo '<h3>'.$options['title'].'</h3>'; 822 } 823 824 if (is_array($field_labels)) { 825 foreach ($field_labels as $key => $label) { 826 $field = $fields[$key]; 827 828 /** 829 * 0 = text 830 * 1 = textarea 831 * 2 = select 832 * 3 = hidden 833 * 4 = password 834 * 5 = checkbox 835 * 6 = text multiple 836 * 7 = hidden 837 * 8 = button 838 * 9 = link 839 * 10 = ? 840 **/ 841 842 843 //formGroup($field['INPUT_TYPE']); 844 echo '<div class="field field-'.$field['INPUT_NAME'].'">'; 845 echo '<label>'.$label.'</label>'; 846 847 if ($field['COMMENT_BEFORE']) { 848 echo '<span class="comment_before">'.$field['COMMENT_BEFORE'].'</span>'; 849 } 850 851 echo show_modif($field['DEFAULT_VALUE'], $field['INPUT_NAME'], $field['INPUT_TYPE'], $field['RELOAD'], $field['CONFIG']); 852 853 if ($field['COMMENT_AFTER']) { 854 echo '<span class="comment_after">'.$field['COMMENT_AFTER'].'</span>'; 855 } 856 857 echo '</div>'; 858 } 859 } else { 860 echo $field_labels; 861 } 862 863 if ($options['comment']) { 864 echo '<div class="form-field"><i>'.$options['comment'].'</i></div>'; 865 } 866 867 if ($options['show_button'] === 'BUTTON') { 868 echo '<div class="form-buttons">'; 869 echo '<input type="submit" name="Valid_'.$options['button_name'].'" value="'.$l->g(13).'"/>'; 870 echo '</div>'; 871 } else if ($options['show_button']) { 872 echo '<div class="form-buttons">'; 873 echo '<input type="submit" name="Valid_'.$options['button_name'].'" value="'.$l->g(1363).'"/>'; 874 echo '<input type="submit" name="Reset_'.$options['button_name'].'" value="'.$l->g(1364).'"/>'; 875 echo '</div>'; 876 } 877 878 if ($options['show_frame']) { 879 echo "</div>"; 880 } 881 882 if ($hidden_fields) { 883 foreach ($hidden_fields as $key => $value) { 884 echo "<input type='hidden' name='".$key."' id='".$key."' value='".htmlspecialchars($value, ENT_QUOTES)."'>"; 885 } 886 } 887 888 if ($options['form_name'] != 'NO_FORM') { 889 echo close_form(); 890 } 891} 892 893function show_field($name_field,$type_field,$value_field,$config=array()){ 894 global $protectedPost; 895 foreach($name_field as $key=>$value){ 896 $tab_typ_champ[$key]['DEFAULT_VALUE']=$value_field[$key]; 897 $tab_typ_champ[$key]['INPUT_NAME']=$name_field[$key]; 898 $tab_typ_champ[$key]['INPUT_TYPE']=$type_field[$key]; 899 900 901 if (!isset($config['ROWS'][$key]) or $config['ROWS'][$key] == '') 902 $tab_typ_champ[$key]['CONFIG']['ROWS']=7; 903 else 904 $tab_typ_champ[$key]['CONFIG']['ROWS']=$config['ROWS'][$key]; 905 906 if (!isset($config['COLS'][$key]) or $config['COLS'][$key] == '') 907 $tab_typ_champ[$key]['CONFIG']['COLS']=40; 908 else 909 $tab_typ_champ[$key]['CONFIG']['COLS']=$config['COLS'][$key]; 910 911 if (!isset($config['SIZE'][$key]) or $config['SIZE'][$key] == '') 912 $tab_typ_champ[$key]['CONFIG']['SIZE']=50; 913 else 914 $tab_typ_champ[$key]['CONFIG']['SIZE']=$config['SIZE'][$key]; 915 916 if (!isset($config['MAXLENGTH'][$key]) or $config['MAXLENGTH'][$key] == '') 917 $tab_typ_champ[$key]['CONFIG']['MAXLENGTH']=255; 918 else 919 $tab_typ_champ[$key]['CONFIG']['MAXLENGTH']=$config['MAXLENGTH'][$key]; 920 921 if (isset($config['COMMENT_AFTER'][$key])) { 922 $tab_typ_champ[$key]['COMMENT_AFTER']= $config['COMMENT_AFTER'][$key]; 923 } 924 925 926 if (isset($config['DDE'][$key])) { 927 $tab_typ_champ[$key]['CONFIG']['DDE']=$config['DDE'][$key]; 928 } 929 930 if (isset($config['SELECT_DEFAULT'][$key])) { 931 $tab_typ_champ[$key]['CONFIG']['DEFAULT']=$config['SELECT_DEFAULT'][$key]; 932 if($tab_typ_champ[$key]['CONFIG']['DEFAULT'] == 'YES'){ 933 $tab_typ_champ[$key]['CONFIG']['SELECTED_VALUE'] = $config['SELECTED_VALUE'][$key]; 934 } 935 } 936 if (isset($config['JAVASCRIPT'][$key])) { 937 $tab_typ_champ[$key]['CONFIG']['JAVASCRIPT']=$config['JAVASCRIPT'][$key]; 938 } 939 } 940 941 return $tab_typ_champ; 942} 943 944function filtre($tab_field,$form_name,$query,$arg='',$arg_count=''){ 945 global $protectedPost,$l; 946// if ($protectedPost['RAZ_FILTRE'] == "RAZ") 947// unset($protectedPost['FILTRE_VALUE'],$protectedPost['FILTRE']); 948 if ($protectedPost['FILTRE_VALUE'] and $protectedPost['FILTRE']){ 949 $temp_query=explode("GROUP BY",$query); 950 if ($temp_query[0] == $query) 951 $temp_query=explode("group by",$query); 952 953 if (substr_count(mb_strtoupper ($temp_query[0]), "WHERE")>0){ 954 $t_query=explode("WHERE",$temp_query[0]); 955 if ($t_query[0] == $temp_query[0]) 956 $t_query=explode("where",$temp_query[0]); 957 $temp_query[0]= $t_query[0]." WHERE (".$t_query[1].") and "; 958 959 }else 960 $temp_query[0].= " where "; 961 if (substr($protectedPost['FILTRE'],0,2) == 'a.'){ 962 require_once('require/function_admininfo.php'); 963 $id_tag=explode('_',substr($protectedPost['FILTRE'],2)); 964 if (!isset($id_tag[1])) 965 $tag=1; 966 else 967 $tag=$id_tag[1]; 968 $list_tag_id= find_value_in_field($tag,$protectedPost['FILTRE_VALUE']); 969 } 970 if ($list_tag_id){ 971 $query_end= " in (".implode(',',$list_tag_id).")"; 972 }else{ 973 if ($arg == '') 974 $query_end = " like '%".$protectedPost['FILTRE_VALUE']."%' "; 975 else{ 976 $query_end = " like '%s' "; 977 array_push($arg,'%' . $protectedPost['FILTRE_VALUE'] . '%'); 978 if (is_array($arg_count)) 979 array_push($arg_count,'%' . $protectedPost['FILTRE_VALUE'] . '%'); 980 else 981 $arg_count[] = '%' . $protectedPost['FILTRE_VALUE'] . '%'; 982 } 983 } 984 $query= $temp_query[0].$protectedPost['FILTRE'].$query_end; 985 if (isset($temp_query[1])) 986 $query.="GROUP BY ".$temp_query[1]; 987 } 988 $view=show_modif($tab_field,'FILTRE',2); 989 $view.=show_modif($protectedPost['FILTRE_VALUE'],'FILTRE_VALUE',0); 990 991 echo $l->g(883).": ".$view."<input type='submit' value='".$l->g(1109)."' name='SUB_FILTRE'><a href=# onclick='return pag(\"RAZ\",\"RAZ_FILTRE\",\"".$form_name."\");'><img src=image/delete-small.png></a></td></tr><tr><td align=center>"; 992 echo "<input type=hidden name='RAZ_FILTRE' id='RAZ_FILTRE' value=''>"; 993 return array('SQL'=>$query,'ARG'=>$arg,'ARG_COUNT'=>$arg_count); 994} 995 996 997 998 999 1000function tab_list_error($data,$title) 1001{ 1002 global $l; 1003 1004 echo "<br>"; 1005 echo "<table align='center' width='50%' border='0' bgcolor='#C7D9F5' style='border: solid thin; border-color:#A1B1F9'>"; 1006 echo "<tr><td colspan=20 align='center'><font color='RED'>".$title."</font></td></tr><tr>"; 1007 $i=0; 1008 $j=0; 1009 while ($data[$i]) 1010 { 1011 if ($j == 10) 1012 { 1013 echo "</tr><tr>"; 1014 $j=0; 1015 } 1016 echo "<td align='center'>".$data[$i]."<td>"; 1017 $i++; 1018 $j++; 1019 } 1020 echo "</td></tr></table>"; 1021 1022} 1023 1024function nb_page($form_name = '',$taille_cadre='80',$bgcolor='#C7D9F5',$bordercolor='#9894B5',$table_name=''){ 1025 global $protectedPost,$l; 1026 1027 //catch nb result by page 1028 if (isset($_SESSION['OCS']['nb_tab'][$table_name])) 1029 $protectedPost["pcparpage"]=$_SESSION['OCS']['nb_tab'][$table_name]; 1030 elseif(isset($_COOKIE[$table_name.'_nbpage'])) 1031 $protectedPost["pcparpage"]=$_COOKIE[$table_name.'_nbpage']; 1032 1033 1034 if ($protectedPost['old_pcparpage'] != $protectedPost['pcparpage']) 1035 $protectedPost['page']=0; 1036 1037 if (!(isset($protectedPost["pcparpage"])) or $protectedPost["pcparpage"] == ""){ 1038 $protectedPost["pcparpage"]=PC4PAGE; 1039 1040 } 1041 $html_show = "<table align=center width='80%' border='0' bgcolor=#f2f2f2>"; 1042 //gestion d"une phrase d'alerte quand on utilise le filtre 1043 if (isset($protectedPost['FILTRE_VALUE']) and $protectedPost['FILTRE_VALUE'] != '' and $protectedPost['RAZ_FILTRE'] != 'RAZ') 1044 $html_show .= msg_warning($l->g(884)); 1045 $html_show .= "<tr><td align=right>"; 1046 1047 if (!isset($protectedPost['SHOW'])) 1048 $protectedPost['SHOW'] = "SHOW"; 1049 if ($protectedPost['SHOW'] == 'SHOW') 1050 $html_show .= "<a href=# OnClick='pag(\"NOSHOW\",\"SHOW\",\"".$form_name."\");'><img src=image/no_show.png></a>"; 1051 elseif ($protectedPost['SHOW'] != 'NEVER_SHOW') 1052 $html_show .= "<a href=# OnClick='pag(\"SHOW\",\"SHOW\",\"".$form_name."\");'><img src=image/show.png></a>"; 1053 1054 $html_show .= "</td></tr></table>"; 1055 $html_show .= "<table align=center width='80%' border='0' bgcolor=#f2f2f2"; 1056 1057 if($protectedPost['SHOW'] == 'NOSHOW' or $protectedPost['SHOW'] == 'NEVER_SHOW') 1058 $html_show .= " style='display:none;'"; 1059 1060 $html_show .= "><tr><td align=center>"; 1061 $html_show .= "<table cellspacing='5' width='".$taille_cadre."%' BORDER='0' ALIGN = 'Center' CELLPADDING='0' BGCOLOR='".$bgcolor."' BORDERCOLOR='".$bordercolor."'><tr><td align=center>"; 1062 $machNmb = array(5=>5,10=>10,15=>15,20=>20,50=>50,100=>100,200=>200,1000000=>$l->g(215)); 1063 $pcParPageHtml= $l->g(340).": ".show_modif($machNmb,'pcparpage',2,$form_name,array('DEFAULT'=>'NO')); 1064 $pcParPageHtml .= "</td></tr></table> 1065 </td></tr><tr><td align=center>"; 1066 $html_show .= $pcParPageHtml; 1067 1068 1069 if (isset($protectedPost["pcparpage"])){ 1070 $deb_limit=$protectedPost['page']*$protectedPost["pcparpage"]; 1071 $fin_limit=$deb_limit+$protectedPost["pcparpage"]-1; 1072 } 1073 1074 $html_show .= "<input type='hidden' id='SHOW' name='SHOW' value='".$protectedPost['SHOW']."'>"; 1075 if ($form_name != '') 1076 echo $html_show; 1077 1078 return (array("BEGIN"=>$deb_limit,"END"=>$fin_limit)); 1079} 1080 1081function show_page($valCount,$form_name){ 1082 global $protectedPost; 1083 if (isset($protectedPost["pcparpage"]) and $protectedPost["pcparpage"] != 0) 1084 $nbpage= ceil($valCount/$protectedPost["pcparpage"]); 1085 if ($nbpage >1){ 1086 $up=$protectedPost['page']+1; 1087 $down=$protectedPost['page']-1; 1088 echo "<table align='center' width='99%' border='0' bgcolor=#f2f2f2>"; 1089 echo "<tr><td align=center>"; 1090 if ($protectedPost['page'] > 0) 1091 echo "<img src='image/prec24.png' OnClick='pag(\"".$down."\",\"page\",\"".$form_name."\")'> "; 1092 //if ($nbpage<10){ 1093 $i=0; 1094 $deja=""; 1095 while ($i<$nbpage){ 1096 $point=""; 1097 if ($protectedPost['page'] == $i){ 1098 if ($i<$nbpage-10 and $i>10 and $deja==""){ 1099 $point=" ... "; 1100 $deja="ok"; 1101 } 1102 if($i<$nbpage-10 and $i>10){ 1103 $point2=" ... "; 1104 } 1105 echo $point."<font color=red>".$i."</font> ".$point2; 1106 } 1107 elseif($i>$nbpage-10 or $i<10) 1108 echo "<a OnClick='pag(\"".$i."\",\"page\",\"".$form_name."\")'>".$i."</a> "; 1109 elseif ($i<$nbpage-10 and $i>10 and $deja==""){ 1110 echo " ... "; 1111 $deja="ok"; 1112 } 1113 $i++; 1114 } 1115 1116 if ($protectedPost['page']< $nbpage-1) 1117 echo "<img src='image/proch24.png' OnClick='pag(\"".$up."\",\"page\",\"".$form_name."\")'> "; 1118 1119 } 1120 echo "</td></tr></table>"; 1121 echo "<input type='hidden' id='page' name='page' value='".$protectedPost['page']."'>"; 1122 echo "<input type='hidden' id='old_pcparpage' name='old_pcparpage' value='".$protectedPost['pcparpage']."'>"; 1123} 1124 1125 1126function onglet($def_onglets,$form_name,$post_name,$ligne) 1127{ 1128 global $protectedPost; 1129 /* $protectedPost['onglet_soft']=stripslashes($protectedPost['onglet_soft']); 1130 $protectedPost['old_onglet_soft']=stripslashes($protectedPost['old_onglet_soft']);*/ 1131 if ($protectedPost["old_".$post_name] != $protectedPost[$post_name]){ 1132 $protectedPost['page']=0; 1133 } 1134 if (!isset($protectedPost[$post_name]) and is_array($def_onglets)){ 1135 foreach ($def_onglets as $key=>$value){ 1136 $protectedPost[$post_name]=$key; 1137 break; 1138 } 1139 } 1140 1141 if ($def_onglets != ""){ 1142 1143 echo "<ul class=\"nav nav-pills\" style='display: inline-block' role=\"tablist\">"; 1144 1145 $current=""; 1146 1147 foreach($def_onglets as $key=>$value){ 1148 1149 echo "<li "; 1150 if (is_numeric($protectedPost[$post_name])){ 1151 if ($protectedPost[$post_name] == $key or (!isset($protectedPost[$post_name]) and $current != 1)){ 1152 echo "class='active'"; 1153 $current=1; 1154 } 1155 }else{ 1156 if (mysqli_real_escape_string($_SESSION['OCS']["readServer"],stripslashes($protectedPost[$post_name])) === mysqli_real_escape_string($_SESSION['OCS']["readServer"],stripslashes($key)) or (!isset($protectedPost[$post_name]) and $current != 1)){ 1157 echo "class='active'"; 1158 $current=1; 1159 } 1160 } 1161 1162 echo "><a OnClick='pag(\"".htmlspecialchars($key, ENT_QUOTES)."\",\"".$post_name."\",\"".$form_name."\")'>".htmlspecialchars($value, ENT_QUOTES)."</a></li>"; 1163 } 1164 echo "</ul>"; 1165 echo "<input type='hidden' id='".$post_name."' name='".$post_name."' value='".$protectedPost[$post_name]."'>"; 1166 echo "<input type='hidden' id='old_".$post_name."' name='old_".$post_name."' value='".$protectedPost[$post_name]."'>"; 1167 } 1168 1169} 1170 1171 1172function show_tabs($def_onglets,$form_name,$post_name, $onclick = false) 1173{ 1174 global $protectedPost; 1175 1176 if ($protectedPost["old_".$post_name] != $protectedPost[$post_name]){ 1177 $protectedPost['page']=0; 1178 } 1179 if (!isset($protectedPost[$post_name]) and is_array($def_onglets)){ 1180 foreach ($def_onglets as $key=>$value){ 1181 $protectedPost[$post_name]=$key; 1182 break; 1183 } 1184 } 1185 if ($def_onglets != ""){ 1186 echo "<div class='col col-md-2'>"; 1187 echo "<ul class='nav nav-pills nav-stacked navbar-left'>"; 1188 $current=""; 1189 $i=0; 1190 foreach($def_onglets as $key=>$value){ 1191 echo "<li "; 1192 if (is_numeric($protectedPost[$post_name])){ 1193 if ($protectedPost[$post_name] == $key or (!isset($protectedPost[$post_name]) and $current != 1)){ 1194 echo "id='current' class='active'"; 1195 $current=1; 1196 } 1197 }else{ 1198 if (mysqli_real_escape_string($_SESSION['OCS']["readServer"],stripslashes($protectedPost[$post_name])) === mysqli_real_escape_string($_SESSION['OCS']["readServer"],stripslashes($key)) or (!isset($protectedPost[$post_name]) and $current != 1)){ 1199 echo "id='current' class='active'"; 1200 $current=1; 1201 } 1202 } 1203 $clickjs = "OnClick='pag(\"".htmlspecialchars($key, ENT_QUOTES)."\",\"".$post_name."\",\"".$form_name."\")'"; 1204 echo "><a "; 1205 echo ($onclick == true) ? $clickjs : ''; 1206 echo " >".htmlspecialchars($value, ENT_QUOTES)."</a></li>"; 1207 $i++; 1208 } 1209 echo "</ul> 1210 </div>"; 1211 echo "<input type='hidden' id='".$post_name."' name='".$post_name."' value='".$protectedPost[$post_name]."'>"; 1212 echo "<input type='hidden' id='old_".$post_name."' name='old_".$post_name."' value='".$protectedPost[$post_name]."'>"; 1213 } 1214 1215 1216} 1217 1218 1219 1220 1221 1222function gestion_col($entete,$data,$list_col_cant_del,$form_name,$tab_name,$list_fields,$default_fields,$id_form='form'){ 1223 global $protectedPost,$l; 1224 //search in cookies columns values 1225 if (isset($_COOKIE[$tab_name]) and $_COOKIE[$tab_name] != '' and !isset($_SESSION['OCS']['col_tab'][$tab_name])){ 1226 $col_tab=explode("///", $_COOKIE[$tab_name]); 1227 foreach ($col_tab as $key=>$value){ 1228 $_SESSION['OCS']['col_tab'][$tab_name][$value]=$value; 1229 } 1230 } 1231 if (isset($protectedPost['SUP_COL']) and $protectedPost['SUP_COL'] != ""){ 1232 unset($_SESSION['OCS']['col_tab'][$tab_name][$protectedPost['SUP_COL']]); 1233 } 1234 if ($protectedPost['restCol'.$tab_name]){ 1235 $_SESSION['OCS']['col_tab'][$tab_name][$protectedPost['restCol'.$tab_name]]=$protectedPost['restCol'.$tab_name]; 1236 } 1237 if ($protectedPost['RAZ'] != ""){ 1238 unset($_SESSION['OCS']['col_tab'][$tab_name]); 1239 $_SESSION['OCS']['col_tab'][$tab_name]=$default_fields; 1240 } 1241 if (!isset($_SESSION['OCS']['col_tab'][$tab_name])){ 1242 $_SESSION['OCS']['col_tab'][$tab_name]=$default_fields; 1243 } 1244 //add all fields we must have 1245 if (is_array($list_col_cant_del)){ 1246 if (!is_array($_SESSION['OCS']['col_tab'][$tab_name])) 1247 $_SESSION['OCS']['col_tab'][$tab_name]=array(); 1248 foreach ($list_col_cant_del as $key=>$value){ 1249 if (!in_array($key,$_SESSION['OCS']['col_tab'][$tab_name])){ 1250 $_SESSION['OCS']['col_tab'][$tab_name][$key]=$key; 1251 } 1252 } 1253 } 1254 1255 if (is_array($entete)){ 1256 if (!is_array($_SESSION['OCS']['col_tab'][$tab_name])) 1257 $_SESSION['OCS']['col_tab'][$tab_name]=array(); 1258 foreach ($entete as $k=>$v){ 1259 if (in_array($k,$_SESSION['OCS']['col_tab'][$tab_name])){ 1260 $data_with_filter['entete'][$k]=$v; 1261 if (!isset($list_col_cant_del[$k])) 1262 $data_with_filter['entete'][$k].="<a href=# onclick='return pag(\"".xml_encode($k)."\",\"SUP_COL\",\"".$id_form."\");'><img src=image/delete-small.png></a>"; 1263 } 1264 else 1265 $list_rest[$k]=$v; 1266 1267 1268 } 1269 } 1270 if (is_array($data)){ 1271 if (!is_array($_SESSION['OCS']['col_tab'][$tab_name])) 1272 $_SESSION['OCS']['col_tab'][$tab_name]=array(); 1273 foreach ($data as $k=>$v){ 1274 foreach ($v as $k2=>$v2){ 1275 if (in_array($k2,$_SESSION['OCS']['col_tab'][$tab_name])){ 1276 $data_with_filter['data'][$k][$k2]=$v2; 1277 } 1278 } 1279 1280 } 1281 } 1282 if (is_array ($list_rest)){ 1283 //$list_rest=lbl_column($list_rest); 1284 $select_restCol= $l->g(349).": ".show_modif($list_rest,'restCol'.$tab_name,2,$form_name); 1285 $select_restCol .= "<a href=# OnClick='pag(\"".$tab_name."\",\"RAZ\",\"".$id_form."\");'><img src=image/delete-small.png></a></td></tr></table>"; //</td></tr><tr><td align=center> 1286 echo $select_restCol; 1287 }else 1288 echo "</td></tr></table>"; 1289 echo "<input type='hidden' id='SUP_COL' name='SUP_COL' value=''>"; 1290 echo "<input type='hidden' id='TABLE_NAME' name='TABLE_NAME' value='".$tab_name."'>"; 1291 echo "<input type='hidden' id='RAZ' name='RAZ' value=''>"; 1292 return( $data_with_filter); 1293 1294 1295} 1296 1297function lbl_column($list_fields){ 1298 //p($list_rest); 1299 require_once('maps.php'); 1300 $return_fields=array(); 1301 $return_default=array(); 1302 foreach($list_fields as $poub=>$table){ 1303 if (isset($lbl_column[$table])){ 1304 foreach($lbl_column[$table] as $field=>$lbl){ 1305 //echo $field; 1306 if (isset($alias_table[$table])){ 1307 $return_fields[$lbl]=$alias_table[$table].'.'.$field; 1308 if (isset($default_column[$table])){ 1309 foreach($default_column[$table] as $poub2=>$default_field) 1310 $return_default[$lbl_column[$table][$default_field]]=$lbl_column[$table][$default_field]; 1311 }else{ 1312 msg_error($table.' DEFAULT VALUES NOT DEFINE IN MAPS.PHP'); 1313 return false; 1314 } 1315 }else{ 1316 msg_error($table.' ALIAS NOT DEFINE IN MAPS.PHP'); 1317 return false; 1318 } 1319 1320 } 1321 1322 }else{ 1323 msg_error($table.' NOT DEFINE IN MAPS.PHP'); 1324 return false; 1325 } 1326 } 1327 ksort($return_fields); 1328 return array('FIELDS'=>$return_fields,'DEFAULT_FIELDS'=>$return_default); 1329} 1330 1331 1332 1333//fonction qui permet de ne selectionner que certaines lignes du tableau 1334/* 1335 * Columns : Each available column of the table 1336* $queryDetails = string 'SELECT QUERY' 1337* Tab_options : All the options for the specific table 1338* $tab_options= array{ 1339* 'form_name'=> "show_all",.... 1340* 'Option' => value, 1341* } 1342*/ 1343function ajaxfiltre($queryDetails,$tab_options){ 1344 // Research field of the table 1345 if ($tab_options["search"] && $tab_options["search"]['value']!=""){ 1346 $search = mysqli_real_escape_string($_SESSION['OCS']["readServer"],$tab_options["search"]['value']); 1347 $search = str_replace('%','%%',$search); 1348 $sqlword['WHERE']= preg_split("/where/i", $queryDetails); 1349 $sqlword['GROUPBY']= preg_split("/group by/i", $queryDetails); 1350 $sqlword['HAVING']= preg_split("/having/i", $queryDetails); 1351 $sqlword['ORDERBY']= preg_split("/order by/i", $queryDetails); 1352 foreach ($sqlword as $word=>$filter){ 1353 if (!empty($filter['3'])){ 1354 foreach ($filter as $key => $row){ 1355 if ($key == 3){ 1356 1357 $rang =0; 1358 foreach($tab_options['visible_col'] as $index=>$column){ 1359 if($tab_options['columns'][$column]['name'] == $tab_options['NO_SEARCH'][$tab_options['columns'][$column]['name']]){ 1360 $tab_options['columns'][$column]['searchable'] = false; 1361 } 1362 $searchable = ($tab_options['columns'][$column]['searchable'] == "true") ? true : false; 1363 $name = preg_replace("/[^A-Za-z0-9\._]/", "", $tab_options['columns'][$column]['name']); 1364 if (!empty($tab_options["replace_query_arg"][$name])){ 1365 $name= $tab_options["replace_query_arg"][$name]; 1366 } 1367 if(is_array($tab_options['HAVING'])&&isset($tab_options['HAVING'][$name])){ 1368 $searchable =true; 1369 } 1370 if (!empty($tab_options['NO_SEARCH'][$tab_options['columns'][$column]['name']])){ 1371 $searchable = false; 1372 } 1373 1374 if ($searchable){ 1375 1376 if ($name != 'c' && $tab_options['COL_SEARCH'] == 'default') { 1377 if ($rang == 0){ 1378 $filtertxt = " HAVING (( ".$name." LIKE '%%".$search."%%' ) "; 1379 } else { 1380 $filtertxt .= " OR ( ".$name." LIKE '%%".$search."%%' ) "; 1381 } 1382 } else if (empty($tab_options["COL_SEARCH"])) { 1383 if ($rang == 0){ 1384 $filtertxt = " HAVING (( ".$name." LIKE '%%".$search."%%' ) "; 1385 } else { 1386 $filtertxt .= " OR ( ".$name." LIKE '%%".$search."%%' ) "; 1387 } 1388 } 1389 $rang++; 1390 } 1391 } 1392 if ($word == "HAVING"){ 1393 $queryDetails .= $filtertxt.") AND ".$row; 1394 } else { 1395 $queryDetails .= $filtertxt.") ".$row; 1396 } 1397 } 1398 else { 1399 if($key>1){ 1400 $queryDetails.=" ".$word." ".$row; 1401 }else{ 1402 $queryDetails = $row; 1403 } 1404 1405 } 1406 } 1407 return $queryDetails; 1408 } 1409 } 1410 1411 // Check if at least one of the column used in the query if full-text indexed 1412 foreach ($tab_options['visible_col'] as $column) { 1413 if ($tab_options['columns'][$column]['ft_index'] == 'true') { 1414 // Find the correct place where to do the full-text search in the query 1415 if (count($sqlword['WHERE'])>1) { 1416 $ft_queryDetails1 = $sqlword['WHERE'][0]; 1417 $ft_queryDetails2 = $sqlword['WHERE'][1]; 1418 $ft_place = 'WHERE'; 1419 } elseif (count($sqlword['GROUPBY'])>1) { 1420 $ft_queryDetails1 = $sqlword['GROUPBY'][0]; 1421 $ft_queryDetails2 = $sqlword['GROUPBY'][1]; 1422 $ft_place = 'GROUP BY'; 1423 } 1424 break; 1425 } 1426 } 1427 1428 // Add filtering criteria 1429 if (!empty($ft_place)) { 1430 1431 // Search with at least 1 full-text indexed columns 1432 $index = 0; 1433 1434 foreach ($tab_options['visible_col'] as $column) { 1435 $cname = $tab_options['columns'][$column]['name']; 1436 1437 // Find out if the column is searchable 1438 if($tab_options['columns'][$column]['name'] == $tab_options['NO_SEARCH'][$tab_options['columns'][$column]['name']]){ 1439 $tab_options['columns'][$column]['searchable'] = false; 1440 } 1441 $searchable = ($tab_options['columns'][$column]['searchable'] == "true") ? true : false; 1442 1443 // Find out if the column is searchable and is full-text indexed 1444 if ($searchable && $tab_options['columns'][$column]['ft_index'] == 'true') { 1445 // Add a '+' in front of, and a '*' at the end of, each work when $search contains several words 1446 $search = trim($search); 1447 if (stripos($search, ' ') !== false) { 1448 $search1 = '+'.implode(' +', explode(' ',$search)); 1449 $search1 = implode(explode(' ',$search1),'* ')."*"; 1450 } else { 1451 $search1 = $search . "*"; 1452 } 1453 // Append the search term 1454 if ($index==0) { 1455 $ft_queryDetails1 .= " WHERE (MATCH ($cname) AGAINST ('$search1' IN BOOLEAN MODE)"; 1456 } else { 1457 $ft_queryDetails1 .= " OR MATCH ($cname) AGAINST ('$search1' IN BOOLEAN MODE)"; 1458 } 1459 $index++; 1460 } elseif ($searchable && $tab_options['columns'][$column]['ft_index'] == 'false') { 1461 // Column is searchable but isn't full-text indexed 1462 if ($index==0) { 1463 $ft_queryDetails1 .= " WHERE ( $cname LIKE '%%$search%%')"; 1464 } else { 1465 $ft_queryDetails1 .= " OR $cname LIKE '%%$search%%')"; 1466 } 1467 $index++; 1468 } 1469 } 1470 1471 // Close the full-text search clause if we added any 1472 if ($index>0) { 1473 if ($ft_place == 'WHERE') { 1474 $queryDetails = $ft_queryDetails1 . ") AND " . $ft_queryDetails2; 1475 } else { 1476 $queryDetails = $ft_queryDetails1 . ") GROUP BY " . $ft_queryDetails2; 1477 } 1478 } 1479 1480 return $queryDetails; 1481 } 1482 1483 // REQUEST SELECT FROM 1484 $queryDetails .= " HAVING "; 1485 $index =0; 1486 foreach($tab_options['visible_col'] as $column){ 1487 $cname = $tab_options['columns'][$column]['name']; 1488 $account_select = null; 1489 1490 // Special treatment if accountinfo select type 1491 if (substr($cname,0,2) == 'a.'){ 1492 require_once('require/function_admininfo.php'); 1493 $id_tag=explode('_',substr($cname,2)); 1494 if($id_tag[0] != 'TAG') { 1495 $info_tag = find_info_accountinfo($id_tag[1]); 1496 if($info_tag[$id_tag[1]]['type'] == 2) { 1497 $info = find_value_field('ACCOUNT_VALUE_' . $info_tag[$id_tag[1]]['name']); 1498 foreach($info as $key => $value) { 1499 if(strpos(strtolower($value), strtolower($search)) !== false) { 1500 $acc_select[$key] = $key; 1501 } 1502 } 1503 if($acc_select != null) { 1504 $account_select = implode(',', $acc_select); 1505 } 1506 } 1507 } 1508 } 1509 1510 // (Cyrille: The following 2 tests are used at least 3 times in this file. Wouldn't it be a good time to create a function?) 1511 if($tab_options['columns'][$column]['name'] == $tab_options['NO_SEARCH'][$tab_options['columns'][$column]['name']]){ 1512 $tab_options['columns'][$column]['searchable'] = false; 1513 } 1514 $searchable = ($tab_options['columns'][$column]['searchable'] == "true") ? true : false; 1515 1516 // (Cyrille: What the hell is the purpose of this "HAVING" array?) 1517 if(is_array($tab_options['HAVING'])&&isset($tab_options['HAVING'][$column])){ 1518 $searchable =true; 1519 } 1520 1521 // if account info select -> change comparator 1522 if($account_select != null) { 1523 $search_arg = "IN (".$account_select.")"; 1524 } else { 1525 $search_arg = "LIKE '%%".$search."%%'"; 1526 } 1527 1528 // If column is searchable and doesn't have a full-text index 1529 if ($searchable && (empty($tab_options['columns'][$column]['ft_index']) || $tab_options['columns'][$column]['ft_index'] == 'false')) { 1530 if ($cname != 'c' && $tab_options['COL_SEARCH'] == 'default') { 1531 if ($index == 0){ 1532 $filter = " (( ".$cname." ".$search_arg." ) "; 1533 } else { 1534 $filter .= " OR ( ".$cname." ".$search_arg." ) "; 1535 } 1536 } else if (empty($tab_options["COL_SEARCH"])) { 1537 if ($index == 0){ 1538 $filter = " (( ".$cname." ".$search_arg." ) "; 1539 } else { 1540 $filter .= " OR ( ".$cname." ".$search_arg." ) "; 1541 } 1542 } 1543 $index++; 1544 } 1545 } 1546 $queryDetails .= $filter.") "; 1547 } 1548 return $queryDetails; 1549} 1550 1551 1552//fonction qui retourne un string contenant le bloc généré ORDER BY de la requete 1553/* 1554* Tab_options : All the options for the specific table 1555* &$tab_options= array{ 1556* 'form_name'=> "show_all",.... 1557* 'Option' => value, 1558* } 1559*/ 1560function ajaxsort(&$tab_options) { 1561 $tri = ''; 1562 $tab_iplike = array('H.IPADDR','IPADDRESS','IP','IPADDR','IP_MIN','IP_MAX'); 1563 1564 if ($tab_options['columns'][$tab_options['order']['0']['column']]['orderable'] == "true") { 1565 // reset 1566 foreach ($tab_options['order'] as $index => $v ) { 1567 // get column name 1568 $name = $tab_options['columns'][$tab_options['order'][$index]['column']]['name']; 1569 1570 if (!empty($tab_options["replace_query_arg"][$name])) { 1571 $name = $tab_options["replace_query_arg"][$name]; 1572 } 1573 // field name is IP format alike 1574 if (in_array(mb_strtoupper($name),$tab_iplike)) { 1575 $tri .= " INET_ATON(".$name.") ".$v['dir'].", "; 1576 } else if($tab_options['TRI']['DATE'][$name]) { 1577 if(isset($tab_options['ARG_SQL'])) { 1578 $tri .= " STR_TO_DATE(%s,'%s') %s"; 1579 $tab_options['ARG_SQL'][] = $name; 1580 $tab_options['ARG_SQL'][] = $tab_options['TRI']['DATE'][$name]; 1581 $tab_options['ARG_SQL'][] = $v['dir']; 1582 } else { 1583 $tri .= " STR_TO_DATE(".$name.",'".$tab_options['TRI']['DATE'][$name]."') ".$v['dir']; 1584 } 1585 } else { 1586 if ( strpos($name,".") === false ) { 1587 $tri .= "".$name." ".$v['dir'].", "; 1588 } else { 1589 $tri .= $name . " ".$v['dir'].", "; 1590 } 1591 } 1592 } 1593 $tri = rtrim($tri, ", "); 1594 } 1595 1596 if($tri != "") { 1597 return " order by ".$tri; 1598 } else { 1599 return ""; 1600 } 1601} 1602 1603//fonction qui retourne un string contenant le bloc généré LIMIT de la requete 1604/* 1605* Tab_options : All the options for the specific table 1606* $tab_options= array{ 1607* 'form_name'=> "show_all",.... 1608* 'Option' => value, 1609* } 1610*/ 1611function ajaxlimit($tab_options){ 1612 if (isset($tab_options['start'])){ 1613 $limit = " limit ".$tab_options['start']." , "; 1614 }else{ 1615 $limit = " limit 0 , "; 1616 } 1617 if (isset($tab_options['length'])){ 1618 $limit .= $tab_options['length']." "; 1619 }else{ 1620 $limit .= "10 "; 1621 } 1622 return $limit; 1623} 1624 1625 1626//fonction qui met en forme les resultats 1627/* 1628* ResultDetails : Query return 1629* $resultDetails = mysqli_result 1630* $list_fields : Each available column of the table 1631* $list_fields = array { 1632* 'NAME'=>'h.name', ... 1633* 'Column name' => Database value, 1634* } 1635* Tab_options : All the options for the specific table 1636* $tab_options= array{ 1637* 'form_name'=> "show_all",.... 1638* 'Option' => value, 1639* } 1640*/ 1641function ajaxgestionresults($resultDetails,$list_fields,$tab_options){ 1642 global $protectedPost,$l,$pages_refs; 1643 $form_name=$tab_options['form_name']; 1644 $_SESSION['OCS']['list_fields'][$tab_options['table_name']]=$list_fields; 1645 $_SESSION['OCS']['col_tab'][$tab_options['table_name']]= array_flip($list_fields); 1646 if($resultDetails){ 1647 while($row = mysqli_fetch_assoc($resultDetails)) 1648 { 1649 if (isset($tab_options['AS'])){ 1650 foreach($tab_options['AS'] as $k=>$v){ 1651 if($v!="SNAME"){ 1652 $n = explode('.',$k); 1653 $n = end($n); 1654 $row[$n]= $row[$v]; 1655 } 1656 } 1657 } 1658 $row_temp = $row; 1659 foreach($row as $rowKey=>$rowValue){ 1660 $row[$rowKey]=$rowValue; 1661 } 1662 foreach($list_fields as $key=>$column){ 1663 $name = explode('.',$column); 1664 $column = end($name); 1665 $value_of_field = $row[$column]; 1666 switch($key){ 1667 case "CHECK": 1668 // condition below added to fix static grp visbility checkbox 1669 if (isset($tab_options['JAVA']['CHECK'])){ 1670 $grp_name = array(); 1671 // workaround to get grp name (matches anything btw > and <) 1672 preg_match('/(?<=>)(.*?)(?=<)/', $row['NAME'], $grp_name); 1673 $javascript="OnClick='confirme(\"".htmlspecialchars($grp_name[0], ENT_QUOTES)."\",".$value_of_field.",\"".$form_name."\",\"CONFIRM_CHECK\",\"".htmlspecialchars($tab_options['JAVA']['CHECK']['QUESTION'], ENT_QUOTES)." \")'"; 1674 }else{ 1675 $javascript=""; 1676 } 1677 1678 if ($value_of_field!= ' '){ 1679 $row[$key] = "<input type='checkbox' name='check".$value_of_field."' id='check".$value_of_field."' ".$javascript." ".(isset($tab_options['check'.$value_of_field])? " checked ": "").">"; 1680 } 1681 break; 1682 case "SUP": 1683 if ( $value_of_field!= ' '){ 1684 if (isset($tab_options['LBL_POPUP'][$key])) { 1685 if (isset($row[$tab_options['LBL_POPUP'][$key]])) { 1686 $lbl_msg=$l->g(640)." ".$row_temp[$tab_options['LBL_POPUP'][$key]]; 1687 } else { 1688 $lbl_msg=$tab_options['LBL_POPUP'][$key]; 1689 } 1690 } else { 1691 $lbl_msg=$l->g(640)." ".$value_of_field; 1692 } 1693 if($form_name == "admins" && $_SESSION['OCS']["loggeduser"] == htmlspecialchars($value_of_field, ENT_QUOTES)) { 1694 // Do nothing 1695 } else { 1696 $row[$key]="<a href=# OnClick='confirme(\"\",\"".htmlspecialchars($value_of_field, ENT_QUOTES)."\",\"".$form_name."\",\"SUP_PROF\",\"".htmlspecialchars($lbl_msg, ENT_QUOTES)."\");'><span class='glyphicon glyphicon-remove'></span></a>"; 1697 } 1698 } 1699 break; 1700 case "NAME": 1701 if ( !isset($tab_options['NO_NAME']['NAME'])){ 1702 $link_computer="index.php?".PAG_INDEX."=".$pages_refs['ms_computer']."&head=1"; 1703 if ($row['ID']) 1704 $link_computer.="&systemid=".$row['ID']; 1705 elseif($row['hardwareID']) 1706 $link_computer.="&systemid=".$row['hardwareID']; 1707 1708 if ($row['MD5_DEVICEID']) 1709 $link_computer.= "&crypt=".$row['MD5_DEVICEID']; 1710 $row[$column]="<a href='".$link_computer."'>".$value_of_field."</a>"; 1711 } 1712 break; 1713 case "GROUP_NAME": 1714 $row['NAME']="<a href='index.php?".PAG_INDEX."=".$pages_refs['ms_group_show']."&head=1&systemid=".$row['ID']."'>".$value_of_field."</a>"; 1715 break; 1716 case "NULL": 1717 $row[$key]=" "; 1718 break; 1719 case "MODIF": 1720 $row[$key]="<a href=# OnClick='pag(\"".htmlspecialchars($value_of_field, ENT_QUOTES)."\",\"MODIF\",\"".$form_name."\");'><span class='glyphicon glyphicon-edit'></span></a>"; 1721 break; 1722 case "SELECT": 1723 $row[$key]="<a href=# OnClick='confirme(\"\",\"".htmlspecialchars($value_of_field, ENT_QUOTES)."\",\"".$form_name."\",\"SELECT\",\"".htmlspecialchars($tab_options['QUESTION']['SELECT'],ENT_QUOTES)."\");'><img src=image/prec16.png></a>"; 1724 $lien = 'KO'; 1725 break; 1726 case "OTHER": 1727 $row[$key]="<a href=# OnClick='pag(\"".htmlspecialchars($value_of_field, ENT_QUOTES)."\",\"OTHER\",\"".$form_name."\");'><img src=image/red.png></a>"; 1728 break; 1729 case "ZIP": 1730 $row[$key]="<a href=\"index.php?".PAG_INDEX."=".$pages_refs['ms_tele_compress']."&no_header=1×tamp=".$value_of_field."&type=".$tab_options['TYPE']['ZIP']."\"><span class='glyphicon glyphicon-download-alt' title='".$l->g(2120)."'></span></a>"; 1731 break; 1732 case "STAT": 1733 $row[$key]="<a href=\"index.php?".PAG_INDEX."=".$pages_refs['ms_tele_stats']."&head=1&stat=".$value_of_field."\"><span class='glyphicon glyphicon-stats' title='".$l->g(1251)."'></span></a>"; 1734 break; 1735 case "ACTIVE": 1736 $row[$key]="<a href=\"index.php?".PAG_INDEX."=".$pages_refs['ms_tele_popup_active']."&head=1&active=".$value_of_field."\"><span class='glyphicon glyphicon-ok' title='".$l->g(431)."'></span></a>"; 1737 break; 1738 case "SHOWACTIVE": 1739 if(!empty($tab_options['SHOW_ONLY'][$key][$row['FILEID']])){ 1740 $row[$column]="<a href='index.php?".PAG_INDEX."=".$pages_refs['ms_tele_actives']."&head=1×tamp=".$row['FILEID']."' >".$value_of_field."</a>"; 1741 } 1742 break; 1743 case "MAC": 1744 if (isset($_SESSION['OCS']["mac"][mb_strtoupper(substr($value_of_field,0,8))])) 1745 $constr=$_SESSION['OCS']["mac"][mb_strtoupper(substr($value_of_field,0,8))]; 1746 else 1747 $constr="<font color=red>".$l->g(885)."</font>"; 1748 $row[$key]=$value_of_field." (<small>".$constr."</small>)"; 1749 break; 1750 case "MOD_TAGS": 1751 if ($value_of_field!= ' '){ 1752 $row[$key]="<center><a href='index.php?".PAG_INDEX."=".$pages_refs['ms_custom_perim']."&head=1&id=".$value_of_field."' ><span class='glyphicon glyphicon-edit'></span></a><center>"; 1753 } 1754 break; 1755 case "SHOW_DETAILS": 1756 $row[$key]='<a href="#'.$value_of_field.'" data-toggle="modal" data-target="#'.$value_of_field.'" title="'.$l->g(9013).'"><span class="glyphicon glyphicon-search"></span></a>'; 1757 break; 1758 case "ARCHIVER": 1759 if ($value_of_field!= ' '){ 1760 $lbl_msg=$l->g(1550)." ".$value_of_field; 1761 $row[$key]="<a href=# OnClick='confirme(\"\",\"".htmlspecialchars($value_of_field, ENT_QUOTES)."\",\"".$form_name."\",\"ARCHIVER\",\"".htmlspecialchars($lbl_msg, ENT_QUOTES)."\");'><span class='glyphicon glyphicon-save' title='".$l->g(1551)."'></span></a>"; 1762 } 1763 break; 1764 case "RESTORE": 1765 if ($value_of_field!= ' '){ 1766 $lbl_msg=$l->g(1553)." ".$value_of_field; 1767 $row[$key]="<a href=# OnClick='confirme(\"\",\"".htmlspecialchars($value_of_field, ENT_QUOTES)."\",\"".$form_name."\",\"RESTORE\",\"".htmlspecialchars($lbl_msg, ENT_QUOTES)."\");'><span class='glyphicon glyphicon-open' title='".$l->g(1552)."'></span></a>"; 1768 } 1769 break; 1770 default : 1771 if (substr($key,0,11) == "PERCENT_BAR"){ 1772 //require_once("function_graphic.php"); 1773 //echo percent_bar($value_of_field); 1774 $row[$column]="<CENTER>".percent_bar($value_of_field)."</CENTER>"; 1775 } 1776 1777 if (!empty($tab_options['REPLACE_VALUE'][$key])){ 1778 $temp_val=explode('&&&',$value_of_field); 1779 if (count($temp_val)==1) { 1780 $temp_val=explode('&&&',$value_of_field); 1781 } 1782 if (count($temp_val)!=1) { 1783 $multi_value=0; 1784 $temp_value_of_field=""; 1785 while (isset($temp_val[$multi_value])){ 1786 $temp_value_of_field.=$temp_val[$multi_value]."<br>"; 1787 $multi_value++; 1788 } 1789 $temp_value_of_field=substr($temp_value_of_field,0,-4); 1790 $value_of_field=$temp_value_of_field; 1791 $row[$column]=$value_of_field; 1792 } 1793 else { 1794 $row[$column]=$tab_options['REPLACE_VALUE'][$key][$value_of_field]; 1795 } 1796 } 1797 if(!empty($tab_options['VALUE'][$key])){ 1798 if(!empty($tab_options['LIEN_CHAMP'][$key])){ 1799 $value_of_field=$tab_options['VALUE'][$key][$row[$tab_options['LIEN_CHAMP'][$key]]]; 1800 }else{ 1801 $row[$column] = $tab_options['VALUE'][$key][$row['ID']]; 1802 } 1803 } 1804 if(!empty($tab_options['REPLACE_VALUE_ALL_TIME'][$key][$row[$tab_options['FIELD_REPLACE_VALUE_ALL_TIME']]])){ 1805 $row[$column]=$tab_options['REPLACE_VALUE_ALL_TIME'][$key][$row[$tab_options['FIELD_REPLACE_VALUE_ALL_TIME']]]; 1806 } 1807 if (!empty($tab_options['LIEN_LBL'][$key])){ 1808 if(strpos($row[$tab_options['LIEN_CHAMP'][$key]], '+')){ 1809 $row[$tab_options['LIEN_CHAMP'][$key]] = str_replace("+", "%2B", $row[$tab_options['LIEN_CHAMP'][$key]]); 1810 } 1811 $row[$column]= "<a href='".$tab_options['LIEN_LBL'][$key].$row[$tab_options['LIEN_CHAMP'][$key]]."'>".$value_of_field."</a>"; 1812 } 1813 if (!empty($tab_options['REPLACE_COLUMN_KEY'][$key])){ 1814 $row[$tab_options['REPLACE_COLUMN_KEY'][$key]]=$row[$column]; 1815 unset($row[$column]); 1816 } 1817 1818 } 1819 if(!empty($tab_options['COLOR'][$key])){ 1820 $row[$column]= "<font color='".$tab_options['COLOR'][$key]."'>".$row[$column]."</font>"; 1821 } 1822 if(!empty($tab_options['SHOW_ONLY'][$key])){ 1823 if(empty($tab_options['SHOW_ONLY'][$key][$value_of_field])&& empty($tab_options['EXIST'][$key]) 1824 ||(reset($tab_options['SHOW_ONLY'][$key]) == $row[$tab_options['EXIST'][$key]])){ 1825 $row[$key]=""; 1826 } 1827 } 1828 1829 } 1830 $actions = array( 1831 "MODIF", 1832 "EDIT_DEPLOY", 1833 "SUP", 1834 "ZIP", 1835 "STAT", 1836 "ACTIVE", 1837 "SHOW_DETAILS", 1838 "ARCHIVER", 1839 "RESTORE", 1840 ); 1841 foreach($actions as $action){ 1842 $row['ACTIONS'].= " ".$row[$action]; 1843 } 1844 $rows[] = $row; 1845 } 1846 }else{ 1847 $rows = 0; 1848 } 1849 return $rows; 1850} 1851 1852//fonction qui ggere le retour de la requete Ajax 1853/* 1854* $list_fields : Each available column of the table 1855* $list_fields = array { 1856* 'NAME'=>'h.name', ... 1857* 'Column name' => Database value, 1858* } 1859* Default_fields : Default columns displayed 1860* $default_fields= array{ 1861* 'NAME'=>'NAME', ... 1862* 'Column name' => 'Column name', 1863* } 1864* List_col_cant_del : All the columns that will always be displayed 1865* $list_col_cant_del= array { 1866* 'NAME'=>'NAME', ... 1867* 'Column name' => 'Column name', 1868* } 1869* $queryDetails = string 'SELECT QUERY' 1870* Tab_options : All the options for the specific table 1871* $tab_options= array{ 1872* 'form_name'=> "show_all",.... 1873* 'Option' => value, 1874* } 1875*/ 1876function tab_req($list_fields,$default_fields,$list_col_cant_del,$queryDetails,$tab_options) 1877{ 1878 global $protectedPost,$l,$pages_refs; 1879 1880 if($queryDetails === false){ 1881 $res = array("draw"=> $tab_options['draw'],"recordsTotal"=> 0, "recordsFiltered"=> 0 , "data"=>0 ); 1882 echo json_encode($res); 1883 die; 1884 } 1885 $columns_special = array("CHECK", 1886 "SUP", 1887 "GROUP_NAME", 1888 "NULL", 1889 "MODIF", 1890 "MOD_TAGS", 1891 "SELECT", 1892 "ZIP", 1893 "OTHER", 1894 "STAT", 1895 "ACTIVE", 1896 "MAC", 1897 "MD5_DEVICEID", 1898 "EDIT_DEPLOY", 1899 "SHOW_DETAILS", 1900 "ARCHIVER", 1901 "RESTORE", 1902 ); 1903 1904 1905 $actions = array( 1906 "MODIF", 1907 "EDIT_DEPLOY", 1908 "SUP", 1909 "ZIP", 1910 "STAT", 1911 "ACTIVE", 1912 "SHOW_DETAILS", 1913 "ARCHIVER", 1914 "RESTORE", 1915 ); 1916 foreach($actions as $action){ 1917 if(isset($list_fields[$action])){ 1918 $list_fields['ACTIONS']="h.ID"; 1919 break; 1920 } 1921 } 1922 1923 $visible = 0; 1924 foreach($list_fields as $key=>$column){ 1925 if (((in_array($key,$default_fields))||(in_array($key,$list_col_cant_del))|| in_array($key, $columns_special)||array_key_exists($key,$default_fields) || $key=="ACTIONS") && !in_array($key,$actions)){ 1926 $visible++; 1927 } 1928 } 1929 $data = serialize($tab_options['visible_col']); 1930 $customized=false; 1931 if (count($tab_options['visible_col'])!=$visible){ 1932 $customized=true; 1933 setcookie($tab_options['table_name']."_col",$data,time()+31536000); 1934 } 1935 else{ 1936 if (isset($_COOKIE[$tab_options['table_name']."_col"])){ 1937 if($data != $_COOKIE[$tab_options['table_name']."_col"]){ 1938 setcookie($tab_options['table_name']."_col",$data,time()+31536000); 1939 } 1940 else{ 1941 setcookie($tab_options['table_name']."_col", FALSE, time() - 3600 ); 1942 } 1943 } 1944 } 1945 if (isset($tab_options['REQUEST'])){ 1946 foreach ($tab_options['REQUEST'] as $field_name => $value){ 1947 $resultDetails = mysql2_query_secure($value, $_SESSION['OCS']["readServer"],$tab_options['ARG'][$field_name]); 1948 while($item = mysqli_fetch_object($resultDetails)){ 1949 if ($item -> FIRST != "") 1950 $tab_options['SHOW_ONLY'][$field_name][$item -> FIRST]=$item -> FIRST; 1951 } 1952 } 1953 } 1954 $table_name = $tab_options['table_name']; 1955 //search static values 1956 if (isset($_SESSION['OCS']['SQL_DATA_FIXE'][$table_name])){ 1957 foreach ($_SESSION['OCS']['SQL_DATA_FIXE'][$table_name] as $key=>$sql){ 1958 if (!isset($_SESSION['OCS']['ARG_DATA_FIXE'][$table_name][$key])) 1959 $arg=array(); 1960 else 1961 $arg=$_SESSION['OCS']['ARG_DATA_FIXE'][$table_name][$key]; 1962 if ($table_name == "TAB_MULTICRITERE"){ 1963 $sql.=" and hardware_id in (".implode(',',$_SESSION['OCS']['ID_REQ']).") group by hardware_id "; 1964 //ajout du group by pour régler le problème des résultats multiples sur une requete 1965 //on affiche juste le premier critère qui match 1966 $result = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"]); 1967 }else{ 1968 //add sort on column if need it 1969 if ($protectedPost['tri_fixe']!='' and strstr($sql,$protectedPost['tri_fixe'])){ 1970 $sql.=" order by '%s' %s"; 1971 array_push($protectedPost['tri_fixe'],$arg); 1972 array_push($protectedPost['sens_'.$table_name],$arg); 1973 } 1974 $sql.= $limit; 1975 $result = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"],$arg); 1976 } 1977 while($item = mysqli_fetch_object($result)){ 1978 if ($item->HARDWARE_ID != "") 1979 $champs_index=$item->HARDWARE_ID; 1980 elseif($item->FILEID != "") 1981 $champs_index=$item->FILEID; 1982 //echo $champs_index."<br>"; 1983 if (isset($tablename_fixe_value)){ 1984 if (strstr($sql,$tablename_fixe_value[0])) 1985 $list_id_tri_fixe[]=$champs_index; 1986 } 1987 foreach ($item as $field=>$value){ 1988 if ($field != "HARDWARE_ID" and $field != "FILEID" and $field != "ID"){ 1989 $tab_options['NO_SEARCH'][$field]=$field; 1990 // echo "<br>champs => ".$field." valeur => ".$value; 1991 $tab_options['REPLACE_VALUE_ALL_TIME'][$field][$champs_index]=$value; 1992 } 1993 } 1994 } 1995 } 1996 } 1997 $link=$_SESSION['OCS']["readServer"]; 1998 1999 $sqlfunctions[]='count'; 2000 $sqlfunctions[]='sum'; 2001 $sqlfunctions[]='min'; 2002 $sqlfunctions[]='max'; 2003 foreach($sqlfunctions as $sqlfunction){ 2004 preg_match("/$sqlfunction\(.+\) \w*/i", $queryDetails, $matches); 2005 foreach ($matches as $match){ 2006 $req = preg_split("/\)/", $match); 2007 $request=$req['0'].") "; 2008 $column = trim($req['1']); 2009 $tab_options['HAVING'][$column]['name']=$request ; 2010 } 2011 } 2012 2013 $queryDetails = ajaxfiltre($queryDetails,$tab_options); 2014 2015 $queryDetails .= ajaxsort($tab_options); 2016 $_SESSION['OCS']['csv']['SQLNOLIMIT'][$tab_options['table_name']]=$queryDetails; 2017 $queryDetails .= ajaxlimit($tab_options); 2018 $_SESSION['OCS']['csv']['SQL'][$tab_options['table_name']]=$queryDetails; 2019 $_SESSION['OCS']['csv']['REPLACE_VALUE'][$tab_options['table_name']]=$tab_options['REPLACE_VALUE']; 2020 2021 if (isset($tab_options['ARG_SQL'])) 2022 $_SESSION['OCS']['csv']['ARG'][$tab_options['table_name']]=$tab_options['ARG_SQL']; 2023 2024 $queryDetails=substr_replace(ltrim($queryDetails),"SELECT SQL_CALC_FOUND_ROWS ", 0 , 6); 2025 if (isset($tab_options['ARG_SQL'])) 2026 $resultDetails = mysql2_query_secure($queryDetails, $link,$tab_options['ARG_SQL']); 2027 else 2028 $resultDetails = mysql2_query_secure($queryDetails, $link); 2029 2030 2031 $rows = ajaxgestionresults($resultDetails,$list_fields,$tab_options); 2032 2033 if (is_null($rows)){ 2034 $rows=0; 2035 } 2036 2037 if(is_array($_SESSION['OCS']['SQL_DEBUG']) && ($_SESSION['OCS']['DEBUG'] == 'ON')){ 2038 $debug = end($_SESSION['OCS']['SQL_DEBUG']); 2039 } 2040 // Data set length after filtering 2041 $resFilterLength = mysql2_query_secure("SELECT FOUND_ROWS()",$link); 2042 $recordsFiltered = mysqli_fetch_row($resFilterLength); 2043 $recordsFiltered=intval($recordsFiltered[0]); 2044 if($rows === 0){ 2045 $recordsFiltered = 0; 2046 } 2047 if($tab_options["search"] && $tab_options["search"]['value']==""){ 2048 $_SESSION['OCS'][$tab_options['table_name']]['nb_resultat']=$recordsFiltered; 2049 } 2050 if (isset($_SESSION['OCS'][$tab_options['table_name']]['nb_resultat'])){ 2051 $recordsTotal = $_SESSION['OCS'][$tab_options['table_name']]['nb_resultat']; 2052 2053 }else{ 2054 $recordsTotal=$recordsFiltered; 2055 } 2056 if(is_array($_SESSION['OCS']['SQL_DEBUG']) && ($_SESSION['OCS']['DEBUG'] == 'ON')){ 2057 $res = array("draw"=> $tab_options['draw'],"recordsTotal"=> $recordsTotal, 2058 "recordsFiltered"=> $recordsFiltered, "data"=>$rows, "customized"=>$customized, 2059 "debug"=>$debug); 2060 }else{ 2061 $res = array("draw"=> $tab_options['draw'],"recordsTotal"=> $recordsTotal, 2062 "recordsFiltered"=> $recordsFiltered, "data"=>$rows, "customized"=>$customized); 2063 } 2064 echo json_encode($res); 2065} 2066 2067function del_selection($form_name){ 2068 global $l; 2069?> 2070 <script language=javascript> 2071 function garde_check(image,id) 2072 { 2073 var idchecked = ''; 2074 for(i=0; i<document.<?php echo $form_name ?>.elements.length; i++) 2075 { 2076 if(document.<?php echo $form_name ?>.elements[i].name.substring(0,5) == 'check'){ 2077 if (document.<?php echo $form_name ?>.elements[i].checked) 2078 idchecked = idchecked + document.<?php echo $form_name ?>.elements[i].name.substring(5) + ','; 2079 } 2080 } 2081 idchecked = idchecked.substr(0,(idchecked.length -1)); 2082 confirme('',idchecked,"<?php echo $form_name ?>","del_check","<?php echo $l->g(900) ?>"); 2083 } 2084 </script> 2085<?php 2086 //foreach ($img as $key=>$value){ 2087 echo "<a href=# onclick=garde_check()><span class='glyphicon glyphicon-remove delete-span' title='".$l->g(162)."' ></span></a>"; 2088 //} 2089 echo "<input type='hidden' id='del_check' name='del_check' value=''>"; 2090} 2091 2092function js_tooltip() { 2093 echo "<script language='javascript' type='text/javascript' src='js/tooltip.js'></script>"; 2094 echo "<div id='mouse_pointer' class='tooltip'></div>"; 2095} 2096 2097function tooltip($txt) { 2098 return " onmouseover=\"show_me('" . addslashes($txt) . "');\" onmouseout='hidden_me();'"; 2099} 2100 2101function iframe($link) { 2102 global $l; 2103 echo "<div class='iframe_div'>"; 2104 echo "<p><a href='$link' target='blank' class='iframe_link' >" . $l->g(1374) . "</a></p>"; 2105 echo "<div style='height:100%'><iframe class='well well-sm' src=\"$link\"> </iframe></div>"; 2106 echo "</div>"; 2107} 2108?> 2109