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@session_start(); 24 25//looking for default value of ocs config 26//default_values => replace with your data if config data is null or empty 27//default_values => array(array())// ex: array('LOCAL_SERVER'=>array('TVALUE'=>'http:\\localhost')) 28function look_config_default_values($field_name, $like = '', $default_values = '') { 29 if ($like == '') { 30 $sql = "select NAME,IVALUE,TVALUE,COMMENTS from config where NAME in "; 31 $arg_sql = array(); 32 $arg = mysql2_prepare($sql, $arg_sql, $field_name); 33 } else { 34 $arg['SQL'] = "select NAME,IVALUE,TVALUE,COMMENTS from config where NAME like '%s'"; 35 $arg['ARG'] = $field_name; 36 } 37 $resdefaultvalues = mysql2_query_secure($arg['SQL'], $_SESSION['OCS']["readServer"], $arg['ARG']); 38 while ($item = mysqli_fetch_object($resdefaultvalues)) { 39 $result['name'][$item->NAME] = $item->NAME; 40 $result['ivalue'][$item->NAME] = $item->IVALUE; 41 $result['tvalue'][$item->NAME] = $item->TVALUE; 42 $result['comments'][$item->NAME] = $item->COMMENTS; 43 } 44 45 if (is_array($default_values)) { 46 foreach ($default_values as $key => $value) { 47 $key = strtolower($key); 48 if (is_array($value)) { 49 foreach ($value as $name => $val) { 50 if (!is_defined($result[$key][$name])) { 51 $result[$key][$name] = $val; 52 } 53 } 54 } 55 } 56 } 57 58 return $result; 59} 60 61/* * ****************************************************SQL FUNCTION*************************************************** */ 62 63function generate_secure_sql($sql, $arg = '') { 64 65 if (is_array($arg)) { 66 foreach ($arg as $value) { 67 $arg_array_escape_string[] = mysqli_real_escape_string($_SESSION['OCS']["readServer"], $value); 68 } 69 $arg_escape_string = $arg_array_escape_string; 70 } elseif ($arg != '') { 71 $arg_escape_string = mysqli_real_escape_string($_SESSION['OCS']["readServer"], $arg); 72 } 73 if (isset($arg_escape_string)) { 74 if (is_array($arg_escape_string)) { 75 $sql = vsprintf($sql, $arg_escape_string); 76 } else { 77 $sql = sprintf($sql, $arg_escape_string); 78 } 79 } 80 return $sql; 81} 82 83function mysql2_query_secure($sql, $link, $arg = '', $log = false) { 84 global $l, $lbl_log; 85 $query = generate_secure_sql($sql, $arg); 86 if ($log) { 87 addLog($log, $query, $lbl_log); 88 } 89 90 if ($_SESSION['OCS']['DEBUG'] == 'ON') { 91 $_SESSION['OCS']['SQL_DEBUG'][] = html_entity_decode($query, ENT_QUOTES); 92 } 93 94 if (DEMO) { 95 $rest = mb_strtoupper(substr($query, 0, 6)); 96 if ($rest == 'UPDATE' || $rest == 'INSERT' || $rest == 'DELETE') { 97 if (DEMO_MSG != 'show') { 98 msg_info($l->g(2103)); 99 define('DEMO_MSG', 'show'); 100 } 101 return false; 102 } 103 } 104 $result = mysqli_query($link, $query); 105 if ($_SESSION['OCS']['DEBUG'] == 'ON' && !$result) { 106 msg_error(mysqli_error($link)); 107 } 108 return $result; 109} 110 111/* 112 * use this function before mysql2_query_secure 113 * $sql= requeste 114 * $arg_sql = arguments for mysql2_query_secure 115 * $arg_tab = arguments to implode 116 * 117 */ 118 119function mysql2_prepare($sql, $arg_sql, $arg_tab = '', $nocot = false) { 120 if ($arg_sql == '') { 121 $arg_sql = array(); 122 } 123 124 if (!is_array($arg_tab)) { 125 $arg_tab = explode(',', $arg_tab); 126 } 127 128 $sql .= " ( "; 129 foreach ($arg_tab as $value) { 130 if (!$nocot) { 131 $sql .= " '%s', "; 132 } else { 133 $sql .= " %s, "; 134 } 135 array_push($arg_sql, $value); 136 } 137 $sql = substr($sql, 0, -2) . " ) "; 138 return array('SQL' => $sql, 'ARG' => $arg_sql); 139} 140 141function prepare_sql_tab($list_fields, $explu = array(), $distinct = false) { 142 $begin_arg = array(); 143 $begin_sql = "SELECT "; 144 if ($distinct) { 145 $begin_sql .= " distinct "; 146 } 147 foreach ($list_fields as $key => $value) { 148 if (!in_array($key, $explu)) { 149 $begin_sql .= '%s, '; 150 array_push($begin_arg, $value); 151 } 152 } 153 return array('SQL' => substr($begin_sql, 0, -2) . " ", 'ARG' => $begin_arg); 154} 155 156function dbconnect($server, $compte_base, $pswd_base, $db = DB_NAME, $sslkey = SSL_KEY, $sslcert = SSL_CERT, $cacert = CA_CERT, $port = 3306, $sslmode = SSL_MODE, $enablessl = ENABLE_SSL) { 157 error_reporting(E_ALL & ~E_NOTICE); 158 mysqli_report(MYSQLI_REPORT_STRICT); 159 //$link is ok? 160 try { 161 $dbc = mysqli_init(); 162 if($enablessl == "1") { 163 $dbc->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true); 164 $dbc->ssl_set($sslkey, $sslcert, $cacert, NULL, NULL); 165 if($sslmode == "MYSQLI_CLIENT_SSL") { 166 $connect = MYSQLI_CLIENT_SSL; 167 } elseif($sslmode == "MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT") { 168 $connect = MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT; 169 } 170 } else { 171 $connect = NULL; 172 } 173 174 $dbc->options(MYSQLI_INIT_COMMAND, "SET NAMES 'utf8'"); 175 $dbc->options(MYSQLI_INIT_COMMAND, "SET sql_mode='NO_ENGINE_SUBSTITUTION'"); 176 177 $link = mysqli_real_connect($dbc, $server, $compte_base, $pswd_base, NULL, $port, NULL, $connect); 178 179 if($link) { 180 $link = $dbc; 181 } 182 } catch (Exception $e) { 183 if (mysqli_connect_errno()) { 184 return "ERROR: MySql connection problem " . $e->getCode() . "<br>" . $e->getMessage(); 185 } 186 } 187 //database is ok? 188 if (!$link->select_db($db)) { 189 return "NO_DATABASE"; 190 } 191 192 return $link; 193} 194 195// Function to retrieve the columns that are full-text indexed within a table 196// Arguments: 197// $tableName : The name of the SQL table to query 198// $tableAlias: The alias of the SQL table in the query 199function dbGetFTIndex($tableName, $tableAlias) { 200 201 $ft_idx = []; 202 $sql_ft='show index from ' . $tableName . ';'; 203 $resultDetails = mysql2_query_secure($sql_ft, $_SESSION['OCS']["readServer"]); 204 while($row = mysqli_fetch_object($resultDetails)){ 205 if ( $row->Index_type == 'FULLTEXT') { 206 $ft_idx[ $row->Column_name ] = "$tableAlias.$row->Column_name"; 207 } 208 } 209 210 return $ft_idx; 211} 212 213/* * *********************************END SQL FUNCTION***************************************** */ 214 215function addLog($type, $value = "", $lbl_sql = '') { 216 if ($_SESSION['OCS']['LOG_GUI'] == 1) { 217 //if (is_writable(LOG_FILE)) { 218 $logHandler = fopen(LOG_FILE, "a"); 219 $dte = getDate(); 220 $date = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $dte["mday"], $dte["mon"], $dte["year"], $dte["hours"], $dte["minutes"], $dte["seconds"]); 221 if ($lbl_sql != '') { 222 $value = $lbl_sql . ' => ' . $value; 223 } 224 $towite = $_SESSION['OCS']["loggeduser"] . ";" . $date . ";" . DB_NAME . ";" . $type . ";" . $value . ";" . $_SERVER['REMOTE_ADDR'] . ";\n"; 225 fwrite($logHandler, $towite); 226 fclose($logHandler); 227 //} 228 } 229} 230 231 232function dateTimeFromMysql($v) { 233 global $l; 234 $d = DateTime::createFromFormat('Y-m-d H:i:s', $v); 235 return $d? $d->format($l->g(1242)) : ''; 236} 237 238function reloadform_closeme($form = '', $close = false) { 239 echo "<script>"; 240 if ($form != '') { 241 echo "window.opener.document.forms['" . $form . "'].submit();"; 242 } 243 if ($close) { 244 echo "self.close();"; 245 } 246 echo "</script>"; 247} 248 249function change_window($url){ 250 echo "<script>"; 251 if ($url != '') { 252 echo "window.location.href = '".$url."';"; 253 } 254 echo "</script>"; 255} 256 257function read_profil_file($name, $writable = '') { 258 global $l; 259 //Select config file depending on user profile 260 $ms_cfg_file = $_SESSION['OCS']['CONF_PROFILS_DIR'] . $name . "_config.txt"; 261 $search = array('INFO' => 'MULTI', 'PAGE_PROFIL' => 'MULTI', 'RESTRICTION' => 'MULTI', 'ADMIN_BLACKLIST' => 'MULTI', 'CONFIGURATION' => 'MULTI'); 262 if (!is_writable($_SESSION['OCS']['OLD_CONF_DIR']) && $writable != '') { 263 msg_error($l->g(297) . ":<br>" . $_SESSION['OCS']['OLD_CONF_DIR'] . "<br>" . $l->g(1148)); 264 } 265 return read_files($search, $ms_cfg_file, $writable); 266} 267 268function read_config_file($writable = '') { 269 //Select config file depending on user profile 270 $ms_cfg_file = $_SESSION['OCS']['CONF_PROFILS_DIR'] . "4all_config.txt"; 271 $search = array('ORDER_FIRST_TABLE' => 'MULTI2', 272 'ORDER_SECOND_TABLE' => 'MULTI2', 273 'ORDER' => 'MULTI2', 274 'LBL' => 'MULTI', 275 'MENU' => 'MULTI', 276 'MENU_TITLE' => 'MULTI', 277 'MENU_NAME' => 'MULTI', 278 'URL' => 'MULTI', 279 'DIRECTORY' => 'MULTI', 280 'JAVASCRIPT' => 'MULTI'); 281 return read_files($search, $ms_cfg_file, $writable); 282} 283 284function read_files($search, $ms_cfg_file, $writable = '') { 285 global $l; 286 if (!is_writable($ms_cfg_file) && $writable != '') { 287 msg_error($ms_cfg_file . " " . $l->g(1006) . ". " . $l->g(1147)); 288 return false; 289 } 290 291 if (file_exists($ms_cfg_file)) { 292 $profil_data = read_configuration($ms_cfg_file, $search); 293 return $profil_data; 294 } else { 295 return false; 296 } 297} 298 299function msg($txt, $css, $closeid = false) { 300 global $protectedPost; 301 302 if (is_defined($protectedPost['close_alert'])) { 303 $_SESSION['OCS']['CLOSE_ALERT'][$protectedPost['close_alert']] = 1; 304 } 305 306 if (!$_SESSION['OCS']['CLOSE_ALERT'][$closeid]) { 307 echo "<center><div id='my-alert-" . $closeid . "' class='alert alert-" . $css . " fade in' role='alert'>"; 308 if ($closeid != false) { 309 echo "<button type='button' class='close' data-dismiss='alert'><span aria-hidden='true'>×</span><span class='sr-only'>Close</span></button>"; 310 } 311 echo $txt . "</div></center>"; 312 if ($closeid != false) { 313 echo "<script>$('#my-alert-" . $closeid . "').on('closed.bs.alert', function () { 314 pag('" . $closeid . "','close_alert','close_msg'); 315 })</script>"; 316 317 echo open_form('close_msg'); 318 echo "<input type='hidden' name='close_alert' id='close_alert' value=''>"; 319 echo close_form(); 320 } 321 if ($css == 'error') { 322 addLog('MSG_' . $css, $txt); 323 } 324 } 325} 326 327function msg_info($txt, $close = false) { 328 msg($txt, 'info', $close); 329} 330 331function msg_success($txt, $close = false) { 332 msg($txt, 'success', $close); 333} 334 335function msg_warning($txt, $close = false) { 336 msg($txt, 'warning', $close); 337} 338 339function msg_error($txt, $close = false) { 340 msg($txt, 'danger', $close); 341 return true; 342} 343 344function html_header($noJavascript = false) { 345 if (!$_SESSION['OCS']['readServer']) { 346 $value_theme = look_config_default_values('CUSTOM_THEME'); 347 } 348 if(is_null($value_theme)){ 349 $value_theme['tvalue']['CUSTOM_THEME'] = DEFAULT_THEME; 350 } 351 352 header("Pragma: no-cache"); 353 header("Expires: -1"); 354 header("Cache-control: must-revalidate, post-check=0, pre-check=0"); 355 header("Cache-control: private", false); 356 header("Content-type: text/html; charset=utf-8"); 357 echo '<!--DOCTYPE html--> 358 <html> 359 <head> 360 <meta charset="utf-8"> 361 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 362 <meta name="viewport" content="width=device-width, initial-scale=1"> 363 364 <title>OCS Inventory</title> 365 <link rel="shortcut icon" href="favicon.ico"> 366 <link rel="stylesheet" href="libraries/bootstrap/css/bootstrap.min.css"> 367 <link rel="stylesheet" href="libraries/bootstrap/css/bootstrap-theme.min.css"> 368 <link rel="stylesheet" href="libraries/select2/css/select2.min.css" /> 369 <link rel="stylesheet" href="css/dataTables-custom.css"> 370 <link rel="stylesheet" href="libraries/datatable/media/css/dataTables.bootstrap.css"> 371 <link rel="stylesheet" href="css/ocsreports.css"> 372 <link rel="stylesheet" href="css/bootstrap-datetimepicker.css"> 373 <link rel="stylesheet" href="css/header.css"> 374 <link rel="stylesheet" href="css/computer_details.css"> 375 <link rel="stylesheet" href="css/bootstrap-formhelpers.css"> 376 <link rel="stylesheet" href="css/forms.css"> 377 <link rel="stylesheet" href="themes/'.$value_theme['tvalue']['CUSTOM_THEME'].'/style.css">'; 378 379 if (!$noJavascript) { 380 //js for graph 381 echo ' 382 <script src="libraries/jquery/jquery.js" type="text/javascript"></script> 383 <script src="libraries/jquery-migrate-1/jquery-migrate.min.js" type="text/javascript"></script> 384 <script src="libraries/jquery-fileupload/jquery.ui.widget.min.js" type="text/javascript"></script> 385 <script src="libraries/jquery-fileupload/jquery.iframe-transport.min.js" type="text/javascript"></script> 386 <script src="libraries/jquery-fileupload/jquery.fileupload.min.js" type="text/javascript"></script> 387 <script src="libraries/bootstrap/js/bootstrap.min.js" type="text/javascript"></script> 388 <script src="libraries/select2/js/select2.min.js" type="text/javascript"></script> 389 <script src="js/bootstrap-custom.js" type="text/javascript"></script> 390 <script src="js/bootstrap-datetimepicker.js" type="text/javascript"></script> 391 <script src="js/bootstrap-datetimepicker-locale.js" type="text/javascript"></script> 392 <script src="js/bootstrap-formhelpers.js" type="text/javascript"></script> 393 <script src="libraries/charts.js/Chart.min.js" type="text/javascript"></script> 394 <!-- js for Datatables --> 395 <script src="libraries/datatable/media/js/jquery.dataTables.min.js" type="text/javascript"></script> 396 <script src="libraries/datatable/media/js/dataTables.bootstrap.js" type="text/javascript"></script> 397 <script src="js/function.js" type="text/javascript"></script> 398 <script src="js/dataTables.conditionalPaging.js" type="text/javascript"></script> 399 <script src="libraries/ace/js/ace.js" type="text/javascript"></script>'; 400 401 if (isset($_SESSION['OCS']['JAVASCRIPT'])) { 402 foreach ($_SESSION['OCS']['JAVASCRIPT'] as $file) { 403 echo "<script src='" . MAIN_SECTIONS_DIR_VISU . $file . "' type='text/javascript'></script>"; 404 } 405 } 406 } 407 echo "</head> 408 <body>"; 409} 410 411function strip_tags_array($value = '') { 412 if (is_object($value)) { 413 $value = get_class($value); 414 $value = strip_tags($value, "<p><b><i><font><br><center>"); 415 $value = "Objet de la classe " . $value; 416 return $value; 417 } 418 419 $value = is_array($value) ? array_map('strip_tags_array', $value) : strip_tags($value, "<p><b><i><font><br><center>"); 420 421 if(!is_array($value)){ 422 // set double encode to false to avoid re encoding html entities 423 $value = htmlspecialchars($value, ENT_QUOTES, $encoding = '', false); 424 } 425 426 return $value; 427} 428 429function open_form($form_name, $action = '', $more = '', $class = '') { 430 if (!isset($_SESSION['OCS']['CSRFNUMBER']) || !is_numeric($_SESSION['OCS']['CSRFNUMBER']) || $_SESSION['OCS']['CSRFNUMBER'] >= CSRF) { 431 $_SESSION['OCS']['CSRFNUMBER'] = 0; 432 } 433 $form = "<form class='" . $class . "' name='" . $form_name . "' id='" . $form_name . "' method='POST' action='" . $action . "' " . $more . " >"; 434 $csrf_value = sha1(microtime()); 435 $_SESSION['OCS']['CSRF'][$_SESSION['OCS']['CSRFNUMBER']] = $csrf_value; 436 $form .= "<input type='hidden' name='CSRF_" . $_SESSION['OCS']['CSRFNUMBER'] . "' id='CSRF_" . $_SESSION['OCS']['CSRFNUMBER'] . "' value='" . $csrf_value . "'>"; 437 $_SESSION['OCS']['CSRFNUMBER'] ++; 438 return $form; 439} 440 441function close_form() { 442 return "</form>"; 443} 444 445/* 446 * Return a json from the website which help ocs determine if a new version is available 447 */ 448 449function get_update_json() { 450 451 $ch = curl_init(); 452 curl_setopt($ch, CURLOPT_URL, UPDATE_JSON_URI); 453 curl_setopt($ch, CURLOPT_TIMEOUT, 1); 454 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 455 456 $content = curl_exec($ch); 457 curl_close($ch); 458 459 if (!$content) { 460 return false; 461 } 462 463 $json = json_decode($content); 464 465 if ($json != null) { 466 return $json; 467 } else { 468 return false; 469 } 470} 471 472function formGroup($inputType, $inputName, $name, $size, $maxlength, $inputValue = "", $class = "", $optionsSelect = [], $arrayDisplayValues = [], $attrBalise = "", $groupAddon = ""){ 473 echo "<div class='form-group'>"; 474 echo "<label class='control-label col-sm-2' for='".$inputName."'>".$name."</label>"; 475 echo "<div class='col-sm-10'>"; 476 if($groupAddon != ""){ 477 echo "<div class='input-group'>"; 478 } 479 480 if($inputType == "select"){ 481 echo "<select name='".$inputName."' id='".$inputName."' class='form-control ".$class."' ".$attrBalise.">"; 482 foreach ($optionsSelect as $option => $value){ 483 echo "<option value='".$option."' ".($inputValue == $option ? 'selected' : '').">".($arrayDisplayValues[$option] ? $arrayDisplayValues[$option] : $option)."</option>"; 484 } 485 echo "</select>"; 486 } else { 487 if($inputType == "checkbox") { 488 echo "<input type='".$inputType."' name='".$inputName."' id='".$inputName."' size='".$size."' maxlength='".$maxlength."' value='".$inputValue."' class='".$class."' ".$attrBalise.">"; 489 } else { 490 echo "<input type='".$inputType."' name='".$inputName."' id='".$inputName."' size='".$size."' maxlength='".$maxlength."' value='".$inputValue."' class='form-control ".$class."' ".$attrBalise.">"; 491 } 492 } 493 if($groupAddon != ""){ 494 echo "<span class='input-group-addon' id='".$name."-addon'>".$groupAddon."</span>"; 495 echo "</div>"; 496 } 497 echo "</div>"; 498 echo "</div>"; 499} 500 501//fonction qui permet d'utiliser un calendrier dans un champ 502function calendars($NameInputField,$DateFormat) 503{ 504 $lang = $_SESSION['OCS']['LANGUAGE']; 505 $calendar = "<i class=\"glyphicon glyphicon-calendar\"></i>"; 506 $calendar .= "<script type=\"text/javascript\"> 507 $(\".form_datetime\").datetimepicker({ 508 format: \"".$DateFormat."\", 509 autoclose: true, 510 todayBtn: true, 511 language:\"".$lang."\", 512 pickerPosition: \"bottom-left\" 513 }); 514 </script>"; 515 return $calendar; 516} 517 518 519 520function modif_values($field_labels, $fields, $hidden_fields, $options = array(), $field_name="form-group") { 521 global $l; 522 523 $options = array_merge(array( 524 'title' => null, 525 'comment' => null, 526 'button_name' => 'modif', 527 'show_button' => true, 528 'form_name' => 'CHANGE', 529 'top_action' => null, 530 'show_frame' => true 531 ), $options); 532 533 if ($options['form_name'] != 'NO_FORM') { 534 echo open_form($options['form_name'], '', '', 'form-horizontal'); 535 } 536 537 if (is_array($field_labels)) { 538 foreach ($field_labels as $key => $label) { 539 540 $field = $fields[$key]; 541 542 if (is_array($field_name)){ 543 $name = $field_name[$key]; 544 } else { 545 $name = $field_name; 546 } 547 548 /** 549 * 0 = text 550 * 1 = textarea 551 * 2 = select 552 * 3 = hidden 553 * 4 = password 554 * 5 = checkbox 555 * 6 = text multiple 556 * 7 = hidden 557 * 8 = button 558 * 9 = link 559 * 10 = ? 560 * 11 = Radio 561 * 12 = QRCode 562 * 13 = Disabled 563 * 14 = Date 564 * 15 = number 565 **/ 566 if($field['INPUT_TYPE'] == 0 || 567 $field['INPUT_TYPE'] == 1 || 568 $field['INPUT_TYPE'] == 6 || 569 $field['INPUT_TYPE'] == 10|| 570 $field['INPUT_TYPE'] == 14 571 ){ 572 $inputType = 'text'; 573 } else if($field['INPUT_TYPE'] == 2){ 574 $inputType = 'select'; 575 } else if($field['INPUT_TYPE'] == 3){ 576 $inputType = 'hidden'; 577 } else if($field['INPUT_TYPE'] == 4){ 578 $inputType = 'password'; 579 } else if($field['INPUT_TYPE'] == 5){ 580 $inputType = 'checkbox'; 581 } else if($field['INPUT_TYPE'] == 8){ 582 $inputType = 'button'; 583 } else if($field['INPUT_TYPE'] == 9) { 584 $inputType = 'link'; 585 } else if($field['INPUT_TYPE'] == 13){ 586 $inputType = 'disabled'; 587 } else if($field['INPUT_TYPE'] == 12){ 588 $inputType = 'qrcode'; 589 } elseif($field['INPUT_TYPE'] == 11){ 590 $inputType = 'radio'; 591 } elseif($field['INPUT_TYPE'] == 15){ 592 $inputType = 'number'; 593 } else { 594 $inputType = 'hidden'; 595 } 596 597 echo "<div class='$name'>"; 598 echo "<label for='".$field['INPUT_NAME']."' class='col-sm-2 control-label'>".$label."</label>"; 599 echo "<div class='col-sm-10'>"; 600 601 $field_checkbox = array(); 602 if($inputType == 'text'){ 603 if($field['INPUT_TYPE'] == 14){ 604 echo "<div class='input-group date form_datetime'>"; 605 }else{ 606 echo "<div class='input-group'>"; 607 } 608 echo "<input type='".$inputType."' name='".$field['INPUT_NAME']."' id='".$field['INPUT_NAME']."' value='".$field['DEFAULT_VALUE']."' class='form-control' ".$field['CONFIG']['JAVASCRIPT'].">"; 609 if($field['COMMENT_AFTER'] == ""){ 610 echo "</div>"; 611 } 612 }else if($inputType == 'number'){ 613 echo "<div class='input-group'>"; 614 echo "<input type='".$inputType."' name='".$field['INPUT_NAME']."' id='".$field['INPUT_NAME']."' value='".$field['DEFAULT_VALUE']."' min='1' class='form-control' ".$field['CONFIG']['JAVASCRIPT'].">"; 615 if($field['COMMENT_AFTER'] == ""){ 616 echo "</div>"; 617 } 618 }else if($inputType == 'disabled'){ 619 echo "<div class='input-group'>"; 620 echo "<input type='text' name='".$field['INPUT_NAME']."' id='".$field['INPUT_NAME']."' value='".$field['DEFAULT_VALUE']."' class='form-control' ".$field['CONFIG']['JAVASCRIPT']." readonly>"; 621 if($field['COMMENT_AFTER'] == ""){ 622 echo "</div>"; 623 } 624 }else if($inputType == 'select'){ 625 echo "<div class='input-group'>"; 626 echo "<select name='".$field['INPUT_NAME']."' class='form-control' ".$field['CONFIG']['JAVASCRIPT'].">"; 627 echo "<option value='' selected></option>"; 628 foreach ($field['DEFAULT_VALUE'] as $key => $value){ 629 if($key == $field['CONFIG']['SELECTED_VALUE']){ 630 echo "<option value='".$key."' selected>".$value."</option>"; 631 }else{ 632 echo "<option value='".$key."'>".$value."</option>"; 633 } 634 } 635 echo "</select>"; 636 if($field['COMMENT_AFTER'] == ""){ 637 echo "</div>"; 638 } 639 } else if($inputType == 'checkbox'){ 640 if($field["CONFIG"]["SELECTED_VALUE"] != ''){ 641 $field_check = explode("&&&", $field["CONFIG"]["SELECTED_VALUE"]); 642 foreach($field_check as $keys => $values){ 643 if($values != ''){ 644 $field_checkbox[$values] = $values; 645 } 646 } 647 } 648 echo "<div>"; 649 foreach ($field['DEFAULT_VALUE'] as $key => $value){ 650 if(array_key_exists($value, $field_checkbox)){ 651 echo "<div><input style='display:initial;width:20px;height: 14px;' type='".$inputType."' name='".$field['INPUT_NAME']."_".$value."' value='".$key."' id='".$field['INPUT_NAME']."_".$value."' class='form-control' ".$field['CONFIG']['JAVASCRIPT']." checked> $value </div> "; 652 }else{ 653 echo "<div><input style='display:initial;width:20px;height: 14px;' type='".$inputType."' name='".$field['INPUT_NAME']."_".$value."' value='".$key."' id='".$field['INPUT_NAME']."_".$value."' class='form-control' ".$field['CONFIG']['JAVASCRIPT']."> $value </div>"; 654 } 655 } 656 if($field['COMMENT_AFTER'] == ""){ 657 echo "</div>"; 658 } 659 } else if($inputType == 'radio'){ 660 if($field["CONFIG"]["SELECTED_VALUE"] != ''){ 661 $field_radio = explode("&&&", $field["CONFIG"]["SELECTED_VALUE"]); 662 foreach($field_radio as $keys => $values){ 663 if($values != ''){ 664 $field_radio[$values] = $values; 665 } 666 } 667 } 668 echo "<div>"; 669 foreach ($field['DEFAULT_VALUE'] as $key => $value){ 670 if(array_key_exists($key, $field_radio)){ 671 echo "<div><input style='display:initial;width:20px;height: 14px;' type='".$inputType."' name='".$field['INPUT_NAME']."' value='".$key."' id='".$field['INPUT_NAME']."_".$value."' class='form-control' ".$field['CONFIG']['JAVASCRIPT']." checked> $value </div> "; 672 }else{ 673 echo "<div><input style='display:initial;width:20px;height: 14px;' type='".$inputType."' name='".$field['INPUT_NAME']."' value='".$key."' id='".$field['INPUT_NAME']."_".$value."' class='form-control' ".$field['CONFIG']['JAVASCRIPT'].">$value </div>"; 674 } 675 } 676 if($field['COMMENT_AFTER'] == ""){ 677 echo "</div>"; 678 } 679 } else if( $inputType == 'button' || $inputType == 'link'){ 680 echo "<a href='".$field['DEFAULT_VALUE']."' class='".($inputType == 'button') ? 'btn' : ''."' ".$field['CONFIG']['JAVASCRIPT']."></a>"; 681 } else if($inputType == 'qrcode'){ 682 echo "<img src='" . $field['CONFIG']['DEFAULT'] . "' ".$field['CONFIG']['SIZE']." ".$field['CONFIG']['JAVASCRIPT'].">"; 683 } else{ 684 echo "<input type='".$inputType."' name='".$field['INPUT_NAME']."' id='".$field['INPUT_NAME']."' value='".$field['DEFAULT_VALUE']."' class='form-control' ".$field['CONFIG']['JAVASCRIPT'].">"; 685 } 686 687 if($field['COMMENT_AFTER'] != ""){ 688 echo "<span class='input-group-addon' id='".$field['INPUT_NAME']."-addon'>".$field['COMMENT_AFTER']."</span>"; 689 echo "</div>"; 690 } 691 echo "</div>"; 692 echo "</div>"; 693 694 } 695 } 696 697 if ($options['show_button'] === 'BUTTON') { 698 echo '<div class="form-buttons">'; 699 echo '<input type="submit" name="Valid_'.$options['button_name'].'" value="'.$l->g(13).'"/>'; 700 echo '</div>'; 701 } else if ($options['show_button']) { 702 echo '<div class="form-buttons">'; 703 echo '<input type="submit" name="Valid_'.$options['button_name'].'" class="btn btn-success" value="'.$l->g(1363).'"/>'; 704 echo '<input type="submit" name="Reset_'.$options['button_name'].'" class="btn btn-danger" value="'.$l->g(1364).'"/>'; 705 echo '</div>'; 706 } 707 708 if ($hidden_fields) { 709 foreach ($hidden_fields as $key => $value) { 710 echo "<input type='hidden' name='".$key."' id='".$key."' value='".htmlspecialchars($value, ENT_QUOTES)."'>"; 711 } 712 } 713 714 if ($options['form_name'] != 'NO_FORM') { 715 echo close_form(); 716 } 717} 718 719/** 720 * Test if a var is defined && contains something (not only blank char) 721 * @param type $var var to test 722 * @return boolean result 723 */ 724function is_defined(&$var) { 725 $result = false; 726 727 // var is set ? 728 if (isset($var)) { 729 // PHP 5.3 hack : can't empty(trim($var)) 730 // Don't trim if it's an array 731 if(!is_array($var)){ 732 $maVar = trim($var); 733 }else{ 734 $maVar = array_filter($var); 735 } 736 737 // Var contains something else than blank char ? 738 if (!empty($maVar)) { 739 $result = true; 740 } 741 } 742 return $result; 743} 744 745/** 746 * Check for all php dependencies in a function 747 * Called on install and update 748 */ 749function check_requirements(){ 750 751 global $l; 752 753 //messages lbl 754 $msg_lbl = array(); 755 $msg_lbl['info'] = array(); 756 $msg_lbl['warning'] = array(); 757 $msg_lbl['error'] = array(); 758 //msg=you have to update database 759 if (isset($fromAuto) && $fromAuto == true) { 760 $msg_lbl['info'][] = $l->g(2031) . " " . $valUpd["tvalue"] . " " . $l->g(2032) . " (" . GUI_VER . "). " . $l->g(2033); 761 } 762 //msg=your config file doesn't exist 763 if (isset($fromdbconfig_out) && $fromdbconfig_out == true) { 764 $msg_lbl['info'][] = $l->g(2034); 765 } 766 //max to upload 767 $pms = "post_max_size"; 768 $umf = "upload_max_filesize"; 769 $valTpms = ini_get($pms); 770 $valTumf = ini_get($umf); 771 $valBpms = return_bytes($valTpms); 772 $valBumf = return_bytes($valTumf); 773 if ($valBumf > $valBpms) { 774 $MaxAvail = trim(mb_strtoupper($valTpms), "M"); 775 } else { 776 $MaxAvail = trim(mb_strtoupper($valTumf), "M"); 777 } 778 $msg_lbl['info'][] = $l->g(2040) . " " . $MaxAvail . $l->g(1240) . "<br>" . $l->g(2041) . "<br><br><font color=red>" . $l->g(2102) . "</font>"; 779 //msg=no php-session function 780 if (!function_exists('session_start')) { 781 $msg_lbl['error'][] = $l->g(2035); 782 } 783 //msg= no mysqli_connect function 784 if (!function_exists('mysqli_real_connect')) { 785 $msg_lbl['error'][] = $l->g(2037); 786 } 787 if ((file_exists(CONF_MYSQL) && !is_writable(CONF_MYSQL)) || (!file_exists(CONF_MYSQL) && !is_writable(CONF_MYSQL_DIR))) { 788 $msg_lbl['error'][] = "<br><center><font color=red><b>" . $l->g(2052) . "</b></font></center>"; 789 } 790 //msg for phpversion 791 if (version_compare(phpversion(), '5.4', '<')) { 792 $msg_lbl['warning'][] = $l->g(2113) . " " . phpversion() . " ) "; 793 } 794 if (!function_exists('xml_parser_create')) { 795 $msg_lbl['warning'][] = $l->g(2036); 796 } 797 if (!function_exists('imagefontwidth')) { 798 $msg_lbl['warning'][] = $l->g(2038); 799 } 800 if (!function_exists('openssl_open')) { 801 $msg_lbl['warning'][] = $l->g(2039); 802 } 803 if (!function_exists('curl_version')) { 804 $msg_lbl['warning'][] = $l->g(2125); 805 } 806 // Check if var lib directory is writable 807 if (is_writable(VARLIB_DIR)) { 808 if (!file_exists(VARLIB_DIR . "/download")) { 809 mkdir(VARLIB_DIR . "/download"); 810 } 811 if (!file_exists(VARLIB_DIR . "/logs")) { 812 mkdir(VARLIB_DIR . "/logs"); 813 } 814 if (!file_exists(VARLIB_DIR . "/scripts")) { 815 mkdir(VARLIB_DIR . "/scripts"); 816 } 817 } else { 818 $msg_lbl['warning'][] = "Var lib dir should be writable : " . VARLIB_DIR; 819 } 820 // Check if ocsreports is writable 821 if (!is_writable(CONF_MYSQL_DIR)) { 822 $msg_lbl['warning'][] = "Ocs reports' dir should be writable : " . CONF_MYSQL_DIR; 823 } 824 //show messages 825 foreach ($msg_lbl as $k => $v) { 826 $show = implode("<br>", $v); 827 if ($show != '') { 828 call_user_func_array("msg_" . $k, array($show)); 829 //stop if error 830 if ($k == "error") { 831 die(); 832 } 833 } 834 } 835 836} 837 838/** 839 * From a byte value return an int 840 * 841 * @param type $val 842 * @return int 843 */ 844function return_bytes($val) { 845 $val = trim($val); 846 $last = strtolower($val[strlen($val) - 1]); 847 switch ($last) { 848 case 'g': 849 $val *= 1024; 850 case 'm': 851 $val *= 1024; 852 case 'k': 853 $val *= 1024; 854 } 855 856 return $val; 857} 858 859?> 860