1<?php 2 3// Pandora FMS - http://pandorafms.com 4// ================================================== 5// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas 6// Please see http://pandorafms.org for full contribution list 7 8// This program is free software; you can redistribute it and/or 9// modify it under the terms of the GNU Lesser General Public License 10// as published by the Free Software Foundation; version 2 11 12// This program is distributed in the hope that it will be useful, 13// but WITHOUT ANY WARRANTY; without even the implied warranty of 14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15// GNU General Public License for more details. 16 17/** 18 * @package Include 19 * @subpackage HTML 20 */ 21 22if (!isset($config)) { 23 $working_dir = getcwd(); 24 $working_dir = str_replace("\\", "/", $working_dir); // Windows compatibility 25 $levels = substr_count($working_dir, '/'); 26 27 for ($i = 0; $i < $levels; $i++) { 28 if(file_exists(str_repeat("../", $i) . 'config.php')) { 29 require_once(str_repeat("../", $i) . "config.php"); 30 break; // Skip config.php loading after load the first one 31 } 32 else if(file_exists(str_repeat("../", $i) . 'include/config.php')) { 33 //For path from the enterprise structure dirs. 34 require_once(str_repeat("../", $i) . "include/config.php"); 35 break; // Skip config.php loading after load the first one 36 } 37 } 38} 39 40require_once ($config['homedir'].'/include/functions.php'); 41require_once ($config['homedir'].'/include/functions_users.php'); 42require_once ($config['homedir'].'/include/functions_groups.php'); 43require_once ($config['homedir'].'/include/functions_ui.php'); 44 45 46/** 47 * Prints the print_r with < pre > tags 48 */ 49function html_debug_print ($var, $file = '') { 50 $more_info = ''; 51 if (is_string($var)) { 52 $more_info = 'size: ' . strlen($var); 53 } 54 elseif (is_bool($var)) { 55 $more_info = 'val: ' . 56 ($var ? 'true' : 'false'); 57 } 58 elseif (is_null($var)) { 59 $more_info = 'is null'; 60 } 61 elseif (is_array($var)) { 62 $more_info = count($var); 63 } 64 65 if ($file === true) 66 $file = '/tmp/logDebug'; 67 68 if (strlen($file) > 0) { 69 $f = fopen($file, "a"); 70 ob_start(); 71 echo date("Y/m/d H:i:s") . " (" . gettype($var) . ") " . $more_info . "\n"; 72 print_r($var); 73 echo "\n\n"; 74 $output = ob_get_clean(); 75 fprintf($f,"%s",$output); 76 fclose($f); 77 } 78 else { 79 echo "<pre>" . 80 date("Y/m/d H:i:s") . " (" . gettype($var) . ") " . $more_info . 81 "</pre>"; 82 echo "<pre>";print_r($var);echo "</pre>"; 83 } 84} 85 86// Alias for "html_debug_print" 87function html_debug ($var, $file = '') { 88 html_debug_print ($var, $file); 89} 90 91function html_f2str($function, $params) { 92 ob_start(); 93 94 call_user_func_array($function, $params); 95 96 return ob_get_clean(); 97} 98 99/** 100 * Print side layer 101 * 102 * @params mixed Hash with all the params: 103 * 104 * position: left or right 105 * width: width of the layer 106 * height: height of the layer 107 * icon_closed: icon showed when layer is hidden 108 * icon_open: icon showed when layer is showed 109 * top_text: text over the content 110 * body_text: content of layer 111 * bottom_text: text under the contet 112 * 113 * @return string HTML code if return parameter is true. 114 */ 115 116function html_print_side_layer ($params) { 117 global $config; 118 119 // Check mandatory values, if any of them is missed, return '' 120 $mandatory = array('icon_closed', 'body_text'); 121 122 foreach ($mandatory as $man) { 123 if (!isset($params[$man])) { 124 return ''; 125 } 126 } 127 128 // Set default values if not setted 129 $defaults = array( 130 'position' => 'left', 131 'width' => '400', 132 'height' => '97%', 133 'top_text' => '', 134 'bottom_text' => '', 135 'top' => '0', 136 'autotop' => '', 137 'right' => '0', 138 'autoright' => '', 139 'vertical_mode' => 'out', 140 'icon_width' => 50, 141 'icon_height' => 50, 142 'icon_open' => $params['icon_closed'] 143 ); 144 145 foreach ($defaults as $token => $value) { 146 if (!isset($params[$token])) { 147 $params[$token] = $value; 148 } 149 } 150 151 //z-index is 1 because 2 made the calendar show under the side_layer 152 153 switch ($params['position']) { 154 case 'left': 155 $round_class = 'menu_sidebar_radius_right'; 156 $body_float = 'left'; 157 $button_float = 'right'; 158 break; 159 case 'right': 160 $round_class = 'menu_sidebar_radius_left'; 161 $body_float = 'right'; 162 $button_float = 'left'; 163 break; 164 case 'bottom': 165 $round_class = 'menu_sidebar_radius_left menu_sidebar_radius_right'; 166 $body_float = 'right'; 167 $button_float = 'left'; 168 break; 169 } 170 171 $out_html = '<div id="side_layer" class="menu_sidebar ' . $round_class . '" style="display:none; z-index:1; overflow: hidden; height: ' . $params['height'] . '; width: ' . $params['width'] . ';">'; 172 173 $table->id = 'side_layer_layout'; 174 $table->width = $params['width'] . 'px'; 175 $table->cellspacing = 2; 176 $table->cellpadding = 2; 177 $table->class = 'none'; 178 179 $top = '<div id="side_top_text" style="width: 100%";">' . 180 $params['top_text'] . '</div>'; 181 182 $button = '<div id="show_menu" style="vertical-align: middle; position: relative; width: ' . $params['icon_width'] . 'px; padding-right: 17px; text-align: right; height: ' . $params['icon_height'] . 'px;">'; 183 //Use the no_meta parameter because this image is only in the base console 184 $button .= html_print_image( 185 $params['position'] == 'left' ? 186 $params['icon_open'] 187 : 188 $params['icon_closed'], 189 true, array('id' => 'graph_menu_arrow'), 190 false, false, true); 191 $button .= '</div>'; 192 193 $body = '<div id="side_body_text" style="width: 100%;">' . $params['body_text'] . '</div>'; 194 195 $bottom = '<div id="side_bottom_text" style="text-align: ' . $params['position'] . ';">' . 196 $params['bottom_text'] . '</div>'; 197 198 switch ($params['position']) { 199 case 'left': 200 $table->size[1] = '15%'; 201 202 $table->data[0][0] = $top; 203 $table->data[0][1] = ''; 204 $table->rowclass[0] = ''; 205 206 $table->data[1][0] = $body; 207 208 $table->data[1][1] = $button; 209 $table->rowclass[1] = ''; 210 211 $table->data[2][0] = $bottom; 212 $table->data[2][1] = ''; 213 $table->rowclass[2] = ''; 214 break; 215 case 'right': 216 $table->size[0] = '15%'; 217 218 $table->data[0][0] = ''; 219 $table->data[0][1] = $top; 220 $table->rowclass[0] = ''; 221 222 $table->data[1][0] = $button; 223 224 $table->data[1][1] = $body; 225 $table->rowclass[1] = ''; 226 227 $table->data[2][0] = ''; 228 $table->data[2][1] = $bottom; 229 $table->rowclass[2] = ''; 230 break; 231 case 'bottom': 232 $table->data[0][0] = $button; 233 $table->cellstyle[0][0] = 'text-align: center;'; 234 $table->rowclass[0] = ''; 235 236 $table->data[1][0] = $top; 237 $table->rowclass[1] = ''; 238 239 240 $table->data[2][0] = $body; 241 $table->rowclass[2] = ''; 242 243 $table->data[3][0] = $bottom; 244 $table->rowclass[3] = ''; 245 break; 246 } 247 248 $out_html .= html_print_table($table, true); 249 250 $out_html .= '</div>'; 251 252 $out_js = "<script type='text/javascript'> 253 <!-- 254 hidded_sidebar('" . $params['position'] . "', " . $params['width'] . ", '" . $params['height'] . "', " . $params['icon_width'] . ", 255 '" . $params['top'] . "', '" . $params['autotop'] . "', '" . $params['right'] . "', 256 '" . $params['autoright'] . "', '" . $params['icon_closed'] . "', '" . $params['icon_open'] . "', '" . $config['homeurl'] . "' 257 , '" . $params['vertical_mode'] . "'); 258 //--> 259 </script>"; 260 261 echo $out_html . $out_js; 262} 263 264/** 265 * Prints an array of fields in a popup menu of a form. 266 * 267 * Based on choose_from_menu() from Moodle 268 * 269 * @param array Array with dropdown values. Example: $fields["value"] = "label" 270 * @param string Select form name 271 * @param variant Current selected value. Can be a single value or an 272 * array of selected values (in combination with multiple) 273 * @param string Javascript onChange code. 274 * @param string Label when nothing is selected. 275 * @param variant Value when nothing is selected 276 * @param bool Whether to return an output string or echo now (optional, echo by default). 277 * @param bool Set the input to allow multiple selections (optional, single selection by default). 278 * @param bool Whether to sort the options or not (optional, unsorted by default). 279 * 280 * @return string HTML code if return parameter is true. 281 */ 282function html_print_select_style ($fields, $name, $selected = '', $style='', $script = '', $nothing = '', $nothing_value = 0, $return = false, $multiple = false, $sort = true, $class = '', $disabled = false) { 283 $output = "\n"; 284 285 static $idcounter = array (); 286 287 //If duplicate names exist, it will start numbering. Otherwise it won't 288 if (isset ($idcounter[$name])) { 289 $idcounter[$name]++; 290 } 291 else { 292 $idcounter[$name] = 0; 293 } 294 295 $id = preg_replace('/[^a-z0-9\:\;\-\_]/i', '', $name.($idcounter[$name] ? $idcounter[$name] : '')); 296 297 $attributes = ""; 298 if (!empty ($script)) { 299 $attributes .= ' onchange="'.$script.'"'; 300 } 301 if (!empty ($multiple)) { 302 $attributes .= ' multiple="multiple" size="10"'; 303 } 304 if (!empty ($class)) { 305 $attributes .= ' class="'.$class.'"'; 306 } 307 if (!empty ($disabled)) { 308 $attributes .= ' disabled="disabled"'; 309 } 310 311 $output .= '<select style="'.$style.'" id="'.$id.'" name="'.$name.'"'.$attributes.'>'; 312 313 if ($nothing != '' || empty ($fields)) { 314 if ($nothing == '') { 315 $nothing = __('None'); 316 } 317 $output .= '<option value="'.$nothing_value.'"'; 318 if ($nothing_value == $selected) { 319 $output .= ' selected="selected"'; 320 } 321 $output .= '>'.$nothing.'</option>'; 322 } 323 324 if (!empty ($fields)) { 325 if ($sort !== false) { 326 asort ($fields); 327 } 328 foreach ($fields as $value => $label) { 329 $output .= '<option value="'.$value.'"'; 330 if (is_array ($selected) && in_array ($value, $selected)) { 331 $output .= ' selected="selected"'; 332 } 333 elseif (is_numeric ($value) && is_numeric ($selected) && $value == $selected) { 334 //This fixes string ($value) to int ($selected) comparisons 335 $output .= ' selected="selected"'; 336 } 337 elseif ($value === $selected) { 338 //Needs type comparison otherwise if $selected = 0 and $value = "string" this would evaluate to true 339 $output .= ' selected="selected"'; 340 } 341 if ($label === '') { 342 $output .= '>'.$value."</option>"; 343 } 344 else { 345 $output .= '>'.$label."</option>"; 346 } 347 } 348 } 349 350 $output .= "</select>"; 351 352 if ($return) 353 return $output; 354 355 echo $output; 356} 357 358/** 359 * Prints the groups of user of fields in a popup menu of a form. 360 * 361 * @param string User id 362 * @param string The privilege to evaluate 363 * @param boolean $returnAllGroup Flag the return group, by default true. 364 * @param boolean $returnAllColumns Flag to return all columns of groups. 365 * @param array Array with dropdown values. Example: $fields["value"] = "label" 366 * @param string Select form name 367 * @param variant Current selected value. Can be a single value or an 368 * array of selected values (in combination with multiple) 369 * @param string Javascript onChange code. 370 * @param string Label when nothing is selected. 371 * @param variant Value when nothing is selected 372 * @param bool Whether to return an output string or echo now (optional, echo by default). 373 * @param bool Set the input to allow multiple selections (optional, single selection by default). 374 * @param bool Whether to sort the options or not (optional, unsorted by default). 375 * @param string $style The string of style. 376 * @param integer $id_group The id of node that must do not show the children and own. 377 * @param string $keys_field The field of the group used in the array keys. By default ID 378 * 379 * @return string HTML code if return parameter is true. 380 */ 381function html_print_select_groups($id_user = false, $privilege = "AR", 382 $returnAllGroup = true, $name, $selected = '', $script = '', 383 $nothing = '', $nothing_value = 0, $return = false, 384 $multiple = false, $sort = true, $class = '', $disabled = false, 385 $style = false, $option_style = false, $id_group = false, 386 $keys_field = 'id_grupo', $strict_user = false) { 387 388 global $config; 389 390 $fields = users_get_groups_for_select($id_user, $privilege, 391 $returnAllGroup, true, $id_group, $keys_field); 392 393 if ($strict_user) { 394 $fields = users_get_strict_mode_groups($config['id_user'], $returnAllGroup); 395 } 396 397 $output = html_print_select ($fields, $name, $selected, $script, 398 $nothing, $nothing_value, $return, $multiple, false, $class, 399 $disabled, $style, $option_style); 400 401 if ($return) { 402 return $output; 403 } 404 else { 405 echo $output; 406 } 407} 408 409/** 410 * Prints an array of fields in a popup menu of a form. 411 * 412 * Based on choose_from_menu() from Moodle 413 * 414 * @param array Array with dropdown values. Example: $fields["value"] = "label" 415 * @param string Select form name 416 * @param variant Current selected value. Can be a single value or an 417 * array of selected values (in combination with multiple) 418 * @param string Javascript onChange code. 419 * @param string Label when nothing is selected. 420 * @param variant Value when nothing is selected 421 * @param bool Whether to return an output string or echo now (optional, echo by default). 422 * @param bool Set the input to allow multiple selections (optional, single selection by default). 423 * @param bool Whether to sort the options or not (optional, unsorted by default). 424 * @param string $style The string of style. 425 * @param mixed $size Max elements showed in the select or default (size=10). 426 * 427 * @return string HTML code if return parameter is true. 428 */ 429function html_print_select ($fields, $name, $selected = '', $script = '', 430 $nothing = '', $nothing_value = 0, $return = false, $multiple = false, 431 $sort = true, $class = '', $disabled = false, $style = false, 432 $option_style = false, $size = false) { 433 434 $output = "\n"; 435 436 static $idcounter = array (); 437 438 //If duplicate names exist, it will start numbering. Otherwise it won't 439 if (isset ($idcounter[$name])) { 440 $idcounter[$name]++; 441 } 442 else { 443 $idcounter[$name] = 0; 444 } 445 446 $id = preg_replace('/[^a-z0-9\:\;\-\_]/i', '', $name.($idcounter[$name] ? $idcounter[$name] : '')); 447 448 $attributes = ""; 449 if (!empty ($script)) { 450 $attributes .= ' onchange="'.$script.'"'; 451 } 452 if (!empty ($multiple)) { 453 if ($size !== false) { 454 $attributes .= ' multiple="multiple" size="' . $size . '"'; 455 } 456 else { 457 $attributes .= ' multiple="multiple" size="10"'; 458 } 459 } 460 if (!empty ($class)) { 461 $attributes .= ' class="'.$class.'"'; 462 } 463 if (!empty ($disabled)) { 464 $attributes .= ' disabled="disabled"'; 465 } 466 467 if ($style === false) { 468 $styleText = 'style=""'; 469 } 470 else { 471 $styleText = 'style="' .$style . '"'; 472 } 473 474 $output .= '<select id="'.$id.'" name="'.$name.'"'.$attributes.' ' . $styleText . '>'; 475 476 if ($nothing != '' || empty ($fields)) { 477 if ($nothing == '') { 478 $nothing = __('None'); 479 } 480 $output .= '<option value="'.$nothing_value.'"'; 481 482 if ($nothing_value == $selected) { 483 $output .= ' selected="selected"'; 484 } 485 else if (is_array ($selected)) { 486 if (in_array ($nothing_value, $selected)) { 487 $output .= ' selected="selected"'; 488 } 489 } 490 $output .= '>'.$nothing.'</option>'; 491 } 492 493 if (is_array($fields) && !empty ($fields)) { 494 if ($sort !== false) { 495 // Sorting the fields in natural way and case insensitive preserving keys 496 $first_elem = reset($fields); 497 if (!is_array($first_elem)) 498 uasort($fields, "strnatcasecmp"); 499 } 500 $lastopttype = ''; 501 foreach ($fields as $value => $label) { 502 $optlabel = $label; 503 if (is_array($label)) { 504 if (isset($label['optgroup'])) { 505 if ($label['optgroup'] != $lastopttype) { 506 if ($lastopttype != '') { 507 $output .= '</optgroup>'; 508 } 509 $output .= '<optgroup label="'.$label['optgroup'].'">'; 510 $lastopttype = $label['optgroup']; 511 } 512 } 513 $optlabel = $label['name']; 514 } 515 516 $output .= '<option value="'.$value.'"'; 517 if (is_array ($selected) && in_array ($value, $selected)) { 518 $output .= ' selected="selected"'; 519 } 520 elseif (is_numeric ($value) && is_numeric ($selected) && 521 $value == $selected) { 522 //This fixes string ($value) to int ($selected) comparisons 523 $output .= ' selected="selected"'; 524 } 525 elseif ($value === $selected) { 526 //Needs type comparison otherwise if $selected = 0 and $value = "string" this would evaluate to true 527 $output .= ' selected="selected"'; 528 } 529 if (is_array ($option_style) && 530 in_array ($value, array_keys($option_style))) { 531 $output .= ' style="'.$option_style[$value].'"'; 532 } 533 if ($optlabel === '') { 534 $output .= '>'.$value."</option>"; 535 } 536 else { 537 $output .= '>'.$optlabel."</option>"; 538 } 539 } 540 if (is_array($label)) { 541 $output .= '</optgroup>'; 542 } 543 } 544 545 $output .= "</select>"; 546 547 if ($return) 548 return $output; 549 550 echo $output; 551} 552 553/** 554 * Prints an array of fields in a popup menu of a form based on a SQL query. 555 * The first and second columns of the query will be used. 556 * 557 * The element will have an id like: "password-$value". Based on choose_from_menu() from Moodle. 558 * 559 * @param string $sql SQL sentence, the first field will be the identifier of the option. 560 * The second field will be the shown value in the dropdown. 561 * @param string $name Select form name 562 * @param string $selected Current selected value. 563 * @param string $script Javascript onChange code. 564 * @param string $nothing Label when nothing is selected. 565 * @param string $nothing_value Value when nothing is selected 566 * @param bool $return Whether to return an output string or echo now (optional, echo by default). 567 * @param bool $multiple Whether to allow multiple selections or not. Single by default 568 * @param bool $sort Whether to sort the options or not. Sorted by default. 569 * @param bool $disabled if it's true, disable the select. 570 * @param string $style The string of style. 571 * @param mixed $size Max elements showed in select or default (size=10) 572 * @param int $truncante_size Truncate size of the element, by default is set to GENERIC_SIZE_TEXT constant 573 * 574 * @return string HTML code if return parameter is true. 575 */ 576function html_print_select_from_sql ($sql, $name, $selected = '', 577 $script = '', $nothing = '', $nothing_value = '0', $return = false, 578 $multiple = false, $sort = true, $disabled = false, $style = false, $size = false, $trucate_size = GENERIC_SIZE_TEXT) { 579 global $config; 580 581 $fields = array (); 582 $result = db_get_all_rows_sql ($sql); 583 if ($result === false) 584 $result = array (); 585 586 foreach ($result as $row) { 587 $id = array_shift($row); 588 $value = array_shift($row); 589 $fields[$id] = ui_print_truncate_text( 590 $value, $trucate_size, false, true, false); 591 } 592 593 return html_print_select ($fields, $name, $selected, $script, 594 $nothing, $nothing_value, $return, $multiple, $sort, '', 595 $disabled, $style,'', $size); 596} 597 598function html_print_extended_select_for_post_process($name, $selected = '', 599 $script = '', $nothing = '', $nothing_value = '0', $size = false, 600 $return = false, $select_style = false, $unique_name = true, 601 $disabled = false) { 602 603 global $config; 604 605 require_once($config['homedir'] . "/include/functions_post_process.php"); 606 607 608 $fields = post_process_get_custom_values(); 609 $selected_float = (float)$selected; 610 $found = false; 611 foreach ($fields as $value => $text) { 612 $value = (float)$value; 613 614 615 616 if ($value == $selected_float) { 617 $found = true; 618 break; 619 } 620 } 621 if (!$found) { 622 $fields[floatval($selected)] = floatval($selected); 623 } 624 625 626 if ($unique_name === true) { 627 $uniq_name = uniqid($name); 628 } 629 else { 630 $uniq_name = $name; 631 } 632 633 634 635 636 ob_start(); 637 638 echo '<div id="' . $uniq_name . '_default" style="width:100%;display:inline;">'; 639 html_print_select ($fields, $uniq_name . '_select', $selected, 640 "" . $script, $nothing, $nothing_value, false, false, false, 641 '', $disabled, 'font-size: xx-small;' . $select_style); 642 echo ' <a href="javascript:">' . 643 html_print_image('images/pencil.png', true, 644 array('class' => $uniq_name . '_toggler', 645 'alt' => __('Custom'), 646 'title' => __('Custom'), 647 'style' => 'width: 18px;')) . 648 '</a>'; 649 echo '</div>'; 650 651 echo '<div id="' . $uniq_name . '_manual" style="width:100%;display:inline;">'; 652 html_print_input_text ($uniq_name . '_text', $selected, '', 20); 653 654 html_print_input_hidden($name, $selected, false, $uniq_name); 655 echo ' <a href="javascript:">' . 656 html_print_image('images/default_list.png', true, 657 array('class' => $uniq_name . '_toggler', 658 'alt' => __('List'), 659 'title' => __('List'), 660 'style' => 'width: 18px;')) . '</a>'; 661 echo '</div>'; 662 663 echo "<script type='text/javascript'> 664 $(document).ready (function () { 665 post_process_select_init('$uniq_name'); 666 post_process_select_events('$uniq_name'); 667 }); 668 669 </script>"; 670 671 $returnString = ob_get_clean(); 672 673 674 675 676 if ($return) 677 return $returnString; 678 else 679 echo $returnString; 680} 681 682/** 683 * Render a pair of select for times and text box for set the time more fine. 684 * 685 * @param string Select form name 686 * @param variant Current selected value. Can be a single value or an 687 * array of selected values (in combination with multiple) 688 * @param string Javascript onChange (select) code. 689 * @param string Label when nothing is selected. 690 * @param variant Value when nothing is selected 691 * @param integer $size Size of the input. 692 * @param bool Whether to return an output string or echo now (optional, echo by default). 693 * @param bool Wherter to assign to combo a unique name (to have more than one on same page, like dashboard) 694 * 695 * @return string HTML code if return parameter is true. 696 */ 697 698function html_print_extended_select_for_time ($name, $selected = '', 699 $script = '', $nothing = '', $nothing_value = '0', $size = false, 700 $return = false, $select_style = false, $unique_name = true) { 701 702 global $config; 703 704 $fields = get_periods(); 705 706 if ( ! $selected ) { 707 foreach( $fields as $t_key => $t_value){ 708 if ( $t_key != -1 ) { // -1 means 'custom' 709 $selected = $t_key; 710 break; 711 } 712 } 713 } 714 715 if (($selected !== false) && (!isset($fields[$selected]) && $selected != 0)) { 716 $fields[$selected] = human_time_description_raw($selected,true); 717 } 718 719 $units = array( 720 1 => __('seconds'), 721 SECONDS_1MINUTE => __('minutes'), 722 SECONDS_1HOUR => __('hours'), 723 SECONDS_1DAY => __('days'), 724 SECONDS_1WEEK => __('weeks'), 725 SECONDS_1MONTH => __('months'), 726 SECONDS_1YEAR => __('years')); 727 728 // The advanced control is only for admins 729 if (!is_user_admin($config['id_user'])) { 730 unset($fields[-1]); 731 732 $returnString = html_print_select ($fields, $name, $selected,"" . $script, 733 $nothing, $nothing_value, true, false, false, '', false, 'font-size: xx-small;'.$select_style); 734 735 if ($return) { 736 return $returnString; 737 } 738 else { 739 echo $returnString; 740 return; 741 } 742 } 743 744 if ($unique_name === true) { 745 $uniq_name = uniqid($name); 746 } 747 else { 748 $uniq_name = $name; 749 } 750 751 ob_start(); 752 //Use the no_meta parameter because this image is only in the base console 753 echo '<div id="'.$uniq_name.'_default" style="width:100%;display:inline;">'; 754 html_print_select ($fields, $uniq_name . '_select', $selected,"" . $script, 755 $nothing, $nothing_value, false, false, false, '', false, 'font-size: xx-small;'.$select_style); 756 echo ' <a href="javascript:">' . 757 html_print_image('images/pencil.png', true, 758 array('class' => $uniq_name . '_toggler', 759 'alt' => __('Custom'), 760 'title' => __('Custom'), 761 'style' => 'width: 18px;'), false, false, true) . 762 '</a>'; 763 echo '</div>'; 764 765 echo '<div id="'.$uniq_name.'_manual" style="width:100%;display:inline;">'; 766 html_print_input_text ($uniq_name . '_text', $selected, '', $size); 767 768 html_print_input_hidden ($name, $selected, false, $uniq_name); 769 html_print_select ($units, $uniq_name . '_units', 1, "" . $script, 770 $nothing, $nothing_value, false, false, false, '', false, 'font-size: xx-small;'.$select_style); 771 echo ' <a href="javascript:">' . 772 html_print_image('images/default_list.png', true, 773 array('class' => $uniq_name . '_toggler', 774 'alt' => __('List'), 775 'title' => __('List'), 'style' => 'width: 18px;')) . 776 '</a>'; 777 echo '</div>'; 778 echo "<script type='text/javascript'> 779 $(document).ready (function () { 780 period_select_init('$uniq_name'); 781 period_select_events('$uniq_name'); 782 }); 783 function period_select_".$name."_update(seconds) { 784 $('#text-".$uniq_name."_text').val(seconds); 785 adjustTextUnits('".$uniq_name."'); 786 calculateSeconds('".$uniq_name."'); 787 $('#".$uniq_name."_manual').show(); 788 $('#".$uniq_name."_default').hide(); 789 } 790 </script>"; 791 $returnString = ob_get_clean(); 792 793 if ($return) 794 return $returnString; 795 else 796 echo $returnString; 797} 798 799/** 800 * Print selects to configure the cron of a module. 801 * 802 * @param string Run hour. 803 * @param string Run minute. 804 * @param string Run day of the month. 805 * @param string Run month. 806 * @param string Run day of the week. 807 * @param bool Whether to return an output string or echo now (optional, echo by default). 808 * @param bool Print cron grayed 809 * 810 * @return string HTML code if return parameter is true. 811 */ 812function html_print_extended_select_for_cron ($hour = '*', $minute = '*', $mday = '*', $month = '*', $wday = '*', $return = false, $disabled = false) { 813 814 # Hours 815 for ($i = 0; $i < 24; $i++) { 816 $hours[$i] = $i; 817 } 818 819 # Minutes 820 for ($i = 0; $i < 60; $i+=5) { 821 $minutes[$i] = $i; 822 } 823 824 # Month days 825 for ($i = 0; $i < 31; $i++) { 826 $mdays[$i] = $i; 827 } 828 829 # Months 830 for ($i = 0; $i < 12; $i++) { 831 $months[$i] = date('F', mktime (0, 0, 0, $i, 1)); 832 } 833 834 # Days of the week 835 $wdays = array( 836 __('Sunday'), 837 __('Monday'), 838 __('Tuesday'), 839 __('Wednesday'), 840 __('Thursday'), 841 __('Friday'), 842 __('Saturday')); 843 844 # Print selectors 845 $table = new stdClass(); 846 $table->id = 'cron'; 847 $table->width = '100%'; 848 $table->class = 'databox data'; 849 $table->head[0] = __('Hour'); 850 $table->head[1] = __('Minute'); 851 $table->head[2] = __('Month day'); 852 $table->head[3] = __('Month'); 853 $table->head[4] = __('Week day'); 854 855 $table->data[0][0] = html_print_select ($hours, 'hour', $hour, '', __('Any'), '*', true, false, false,'',$disabled); 856 $table->data[0][1] = html_print_select ($minutes, 'minute', $minute, '', __('Any'), '*', true, false, false,'',$disabled); 857 $table->data[0][2] = html_print_select ($mdays, 'mday', $mday, '', __('Any'), '*', true, false, false,'',$disabled); 858 $table->data[0][3] = html_print_select ($months, 'month', $month, '', __('Any'), '*', true, false, false,'',$disabled); 859 $table->data[0][4] = html_print_select ($wdays, 'wday', $wday, '', __('Any'), '*', true, false, false,'',$disabled); 860 861 return html_print_table ($table, $return); 862} 863 864/** 865 * Render an input text element. Extended version, use html_print_input_text() to simplify. 866 * 867 * @param string $name Input name. 868 * @param string $value Input value. 869 * @param string $id Input HTML id. 870 * @param string $alt Do not use, invalid for text and password. Use html_print_input_image 871 * @param int $size Size of the input. 872 * @param int $maxlength Maximum length allowed. 873 * @param bool $disabled Disable the button (optional, button enabled by default). 874 * @param mixed $script JavaScript to attach to this. It is array the index is event to set a script, it is only string for "onkeyup" event. 875 * @param mixed $attributes Attributes to add to this tag. Should be an array for correction. 876 * @param bool $return Whether to return an output string or echo now (optional, echo by default). 877 * @param bool $password Whether it is a password input or not. Not password by default. 878 * 879 * @return string HTML code if return parameter is true. 880 */ 881function html_print_input_text_extended ($name, $value, $id, $alt, $size, $maxlength, $disabled, $script, $attributes, $return = false, $password = false) { 882 static $idcounter = 0; 883 884 if ($maxlength == 0) 885 $maxlength = 255; 886 887 if ($size == 0) 888 $size = 10; 889 890 ++$idcounter; 891 892 $valid_attrs = array ("accept", "disabled", "maxlength", 893 "name", "readonly", "size", "value", "accesskey", 894 "class", "dir", "id", "lang", "style", "tabindex", 895 "title", "xml:lang", "onfocus", "onblur", "onselect", 896 "onchange", "onclick", "ondblclick", "onmousedown", 897 "onmouseup", "onmouseover", "onmousemove", "onmouseout", 898 "onkeypress", "onkeydown", "onkeyup", "required"); 899 900 $output = '<input '.($password ? 'type="password" autocomplete="off" ' : 'type="text" '); 901 902 if ($disabled && (!is_array ($attributes) || !array_key_exists ("disabled", $attributes))) { 903 $output .= 'readonly="readonly" '; 904 } 905 906 if (is_array ($attributes)) { 907 foreach ($attributes as $attribute => $attr_value) { 908 if (! in_array ($attribute, $valid_attrs)) { 909 continue; 910 } 911 $output .= $attribute.'="'.$attr_value.'" '; 912 } 913 } 914 else { 915 $output .= trim ($attributes)." "; 916 $attributes = array (); 917 } 918 919 if (!empty($alt)) { 920 $output .= 'alt="' . $alt . '" '; 921 } 922 923 //Attributes specified by function call 924 $attrs = array ("name" => "unnamed", "value" => "", 925 "id" => "text-".sprintf ('%04d', $idcounter), 926 "size" => "", "maxlength" => ""); 927 928 foreach ($attrs as $attribute => $default) { 929 if (array_key_exists ($attribute, $attributes)) { 930 continue; 931 } //If the attribute was already processed, skip 932 933 /* 934 * Remember, this next code have a $$ that for example there is a var as 935 * $a = 'john' then $$a is a var $john . 936 * 937 * In this case is use for example for $name and $atribute = 'name' . 938 * 939 */ 940 941 /* Exact operator because we want to show "0" on the value */ 942 if ($attribute !== '') { 943 $output .= $attribute.'="'.$$attribute.'" '; 944 } 945 elseif ($default != '') { 946 $output .= $attribute.'="'.$default.'" '; 947 } 948 } 949 950 if (!empty($script)) { 951 if (is_string($script)) { 952 $code = $script; 953 $script = array(); 954 $script["onkeyup"] = $code; 955 } 956 957 foreach ($script as $event => $code) { 958 $output .= ' ' . $event . '="'.$code.'" '; 959 } 960 } 961 962 $output .= '/>'; 963 964 if (!$return) 965 echo $output; 966 967 return $output; 968} 969 970/** 971 * Render an input password element. 972 * 973 * The element will have an id like: "password-$name" 974 * 975 * @param mixed parameters: 976 * - id: string 977 * - style: string 978 * - hidden: boolean 979 * - content: string 980 * @param bool return or echo flag 981 * 982 * @return string HTML code if return parameter is true. 983 */ 984function html_print_div ($options, $return = false) { 985 $output = '<div'; 986 987 //Valid attributes (invalid attributes get skipped) 988 $attrs = array ("id", "style", "class"); 989 990 if (isset ($options['hidden'])) { 991 if (isset($options['style'])) { 992 $options['style'] .= 'display:none;'; 993 } 994 else { 995 $options['style'] = 'display:none;'; 996 } 997 } 998 999 foreach ($attrs as $attribute) { 1000 if (isset ($options[$attribute])) { 1001 $output .= ' '.$attribute.'="'.io_safe_input_html ($options[$attribute]).'"'; 1002 } 1003 } 1004 1005 $output .= '>'; 1006 1007 $output .= isset ($options['content']) ? $options['content'] : ''; 1008 1009 $output .= '</div>'; 1010 1011 if ($return) { 1012 return $output; 1013 } 1014 else { 1015 echo $output; 1016 } 1017} 1018 1019 1020/** 1021 * Render an input password element. 1022 * 1023 * The element will have an id like: "password-$name" 1024 * 1025 * @param string $name Input name. 1026 * @param string $value Input value. 1027 * @param string $alt Alternative HTML string (optional). 1028 * @param int $size Size of the input (optional). 1029 * @param int $maxlength Maximum length allowed (optional). 1030 * @param bool $return Whether to return an output string or echo now (optional, echo by default). 1031 * @param bool $disabled Disable the button (optional, button enabled by default). 1032 * 1033 * @return string HTML code if return parameter is true. 1034 */ 1035function html_print_input_password ($name, $value, $alt = '', 1036 $size = 50, $maxlength = 255, $return = false, $disabled = false, 1037 $required = false) { 1038 1039 if ($maxlength == 0) 1040 $maxlength = 255; 1041 1042 if ($size == 0) 1043 $size = 10; 1044 1045 $attr = array(); 1046 if ($required) 1047 $attr['required'] = 'required'; 1048 1049 return html_print_input_text_extended ($name, $value, 'password-'.$name, $alt, $size, $maxlength, $disabled, '', $attr, $return, true); 1050} 1051 1052/** 1053 * Render an input text element. 1054 * 1055 * The element will have an id like: "text-$name" 1056 * 1057 * @param string $name Input name. 1058 * @param string $value Input value. 1059 * @param string $alt Alternative HTML string (invalid - not used). 1060 * @param int $size Size of the input (optional). 1061 * @param int $maxlength Maximum length allowed (optional). 1062 * @param bool $return Whether to return an output string or echo now (optional, echo by default). 1063 * @param bool $disabled Disable the button (optional, button enabled by default). 1064 * 1065 * @return string HTML code if return parameter is true. 1066 */ 1067function html_print_input_text ($name, $value, $alt = '', $size = 50, $maxlength = 255, $return = false, $disabled = false, $required = false) { 1068 if ($maxlength == 0) 1069 $maxlength = 255; 1070 1071 if ($size == 0) 1072 $size = 10; 1073 1074 $attr = array(); 1075 if ($required) 1076 $attr['required'] = 'required'; 1077 1078 return html_print_input_text_extended ($name, $value, 'text-'.$name, $alt, $size, $maxlength, $disabled, '', $attr, $return); 1079} 1080 1081/** 1082 * Render an input image element. 1083 * 1084 * The element will have an id like: "image-$name" 1085 * 1086 * @param string $name Input name. 1087 * @param string $src Image source. 1088 * @param string $value Input value. 1089 * @param string $style HTML style property. 1090 * @param bool $return Whether to return an output string or echo now (optional, echo by default). 1091 * 1092 * @return string HTML code if return parameter is true. 1093 */ 1094function html_print_input_image ($name, $src, $value, $style = '', $return = false, $options = false) { 1095 global $config; 1096 static $idcounter = 0; 1097 1098 ++$idcounter; 1099 1100 /* Checks if user's skin is available */ 1101 $isFunctionSkins = enterprise_include_once ('include/functions_skins.php'); 1102 1103 if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) { 1104 $skin_path = enterprise_hook('skins_get_image_path',array($src)); 1105 if ($skin_path) 1106 $src = $skin_path; 1107 } 1108 1109 // If metaconsole is activated and image doesn't exists try to search on normal console 1110 if (is_metaconsole()) { 1111 if (false === @file_get_contents($src, 0, null, 0, 1)) { 1112 $src = '../../' . $src; 1113 } 1114 } 1115 1116 // path to image 1117 $src = ui_get_full_url($src); 1118 1119 $output = '<input id="image-'.$name.$idcounter.'" src="'.$src.'" style="'.$style.'" name="'.$name.'" type="image"'; 1120 1121 //Valid attributes (invalid attributes get skipped) 1122 $attrs = array ("alt", "accesskey", "lang", "tabindex", 1123 "title", "xml:lang", "onclick", "ondblclick", "onmousedown", 1124 "onmouseup", "onmouseover", "onmousemove", "onmouseout", 1125 "onkeypress", "onkeydown", "onkeyup"); 1126 1127 foreach ($attrs as $attribute) { 1128 if (isset ($options[$attribute])) { 1129 $output .= ' '.$attribute.'="'.io_safe_input_html ($options[$attribute]).'"'; 1130 } 1131 } 1132 1133 $output .= ' value="'.$value.'" />'; 1134 1135 if ($return) 1136 return $output; 1137 echo $output; 1138} 1139 1140/** 1141 * Render an input hidden element. 1142 * 1143 * The element will have an id like: "hidden-$name" 1144 * 1145 * @param string $name Input name. 1146 * @param string $value Input value. 1147 * @param bool $return Whether to return an output string or echo now (optional, echo by default). 1148 * @param string $class Set the class of input. 1149 * 1150 * @return string HTML code if return parameter is true. 1151 */ 1152function html_print_input_hidden ($name, $value, $return = false, $class = false) { 1153 if ($class !== false) { 1154 $classText = 'class="' . $class . '"'; 1155 } 1156 else { 1157 $classText = ''; 1158 } 1159 1160 $separator = '"'; 1161 1162 if (is_string($value)) { 1163 if (strstr($value, '"')) { 1164 $separator = "'"; 1165 } 1166 } 1167 1168 $output = '<input id="hidden-' . $name . '" ' . 1169 'name="' . $name . '" ' . 1170 'type="hidden" ' . 1171 $classText . ' ' . 1172 'value=' . $separator . $value . $separator . ' />'; 1173 1174 if ($return) 1175 return $output; 1176 1177 echo $output; 1178} 1179 1180/** 1181 * Render an input hidden element. Extended version, use html_print_input_hidden() to simplify. 1182 * 1183 * The element will have an id like: "hidden-$name" 1184 * 1185 * @param string $name Input name. 1186 * @param string $value Input value. 1187 * @param string $id Input value. 1188 * @param bool $return Whether to return an output string or echo now (optional, echo by default). 1189 * @param string $class Set the class of input. 1190 * 1191 * @return string HTML code if return parameter is true. 1192 */ 1193function html_print_input_hidden_extended($name, $value, $id, $return = false, $class = false) { 1194 if ($class !== false) { 1195 $classText = 'class="' . $class . '"'; 1196 } 1197 else { 1198 $classText = ''; 1199 } 1200 1201 if (empty($id)) { 1202 $ouput_id = 'hidden-' . $name; 1203 } 1204 else { 1205 $ouput_id = $id; 1206 } 1207 1208 $output = '<input id="' . $ouput_id . '" name="' . $name . '" type="hidden" ' . $classText . ' value="' . $value . '" />'; 1209 1210 if ($return) 1211 return $output; 1212 1213 echo $output; 1214} 1215 1216/** 1217 * Render an submit input button element. 1218 * 1219 * The element will have an id like: "submit-$name" 1220 * 1221 * @param string $label Input label. 1222 * @param string $name Input name. 1223 * @param bool $disabled Whether to disable by default or not. Enabled by default. 1224 * @param array $attributes Additional HTML attributes. 1225 * @param bool $return Whether to return an output string or echo now (optional, echo by default). 1226 * 1227 * @return string HTML code if return parameter is true. 1228 */ 1229function html_print_submit_button ($label = 'OK', $name = '', $disabled = false, $attributes = '', $return = false) { 1230 if (!$name) { 1231 $name = "unnamed"; 1232 } 1233 1234 if (is_array ($attributes)) { 1235 $attr_array = $attributes; 1236 $attributes = ''; 1237 foreach ($attr_array as $attribute => $value) { 1238 $attributes .= $attribute.'="'.$value.'" '; 1239 } 1240 } 1241 1242 $output = '<input type="submit" id="submit-'.$name.'" name="'.$name.'" value="'. $label .'" '. $attributes; 1243 if ($disabled) 1244 $output .= ' disabled="disabled"'; 1245 $output .= ' />'; 1246 if (!$return) 1247 echo $output; 1248 1249 return $output; 1250} 1251 1252/** 1253 * Render an submit input button element. 1254 * 1255 * The element will have an id like: "button-$name" 1256 * 1257 * @param string $label Input label. 1258 * @param string $name Input name. 1259 * @param bool $disabled Whether to disable by default or not. Enabled by default. 1260 * @param string $script JavaScript to attach 1261 * @param string $attributes Additional HTML attributes. 1262 * @param bool $return Whether to return an output string or echo now (optional, echo by default). 1263 * @param bool $imageButton Set the button as a image button without text, by default is false. 1264 * 1265 * @return string HTML code if return parameter is true. 1266 */ 1267function html_print_button ($label = 'OK', $name = '', $disabled = false, $script = '', $attributes = '', $return = false, $imageButton = false) { 1268 $output = ''; 1269 1270 $alt = $title = ''; 1271 if ($imageButton) { 1272 $alt = $title = $label; 1273 $label = ''; 1274 } 1275 1276 $output .= '<input title="' . $title . '" alt="' . $alt . '" type="button" id="button-'.$name.'" name="'.$name.'" value="'. $label .'" onClick="'. $script.'" '.$attributes; 1277 if ($disabled) 1278 $output .= ' disabled'; 1279 $output .= ' />'; 1280 if ($return) 1281 return $output; 1282 1283 echo $output; 1284} 1285 1286/** 1287 * Render an input textarea element. 1288 * 1289 * The element will have an id like: "textarea_$name" 1290 * 1291 * @param string $name Input name. 1292 * @param int $rows How many rows (height) 1293 * @param int $columns How many columns (width) 1294 * @param string $value Text in the textarea 1295 * @param string $attributes Additional attributes 1296 * @param bool $return Whether to return an output string or echo now (optional, echo by default). * 1297 * 1298 * @return string HTML code if return parameter is true. 1299 */ 1300function html_print_textarea ($name, $rows, $columns, $value = '', $attributes = '', $return = false) { 1301 $output = '<textarea id="textarea_'.$name.'" name="'.$name.'" cols="'.$columns.'" rows="'.$rows.'" '.$attributes.' >'; 1302 //$output .= io_safe_input ($value); 1303 $output .= ($value); 1304 $output .= '</textarea>'; 1305 1306 if ($return) 1307 return $output; 1308 1309 echo $output; 1310} 1311 1312/** 1313 * Return a table parameters predefined 1314 * 1315 * @param string model 1316 * - Transparent: More basic template. No borders, all the columns with same width 1317 * @param int number of columns 1318 * 1319 * @return object Table object 1320 */ 1321function html_get_predefined_table ($model = 'transparent', $columns = 4) { 1322 $width_percent = 100/$columns; 1323 1324 switch($model) { 1325 case 'transparent': 1326 default: 1327 $table = new stdClass(); 1328 1329 $table->class = "none"; 1330 $table->cellpadding = 0; 1331 $table->cellspacing = 0; 1332 $table->head = array (); 1333 $table->data = array (); 1334 $table->style = array_fill(0, 4, 'text-align:center; width: ' . $width_percent . '%;'); 1335 $table->width = "100%"; 1336 } 1337 1338 return $table; 1339} 1340 1341/** 1342 * Print a nicely formatted table. Code taken from moodle. 1343 * 1344 * @param object Object with several properties: 1345 * $table->head - An array of heading names. 1346 * $table->head_colspan - An array of colspans of each head column. 1347 * $table->headstyle - An array of styles of each head column. 1348 * $table->align - An array of column alignments 1349 * $table->valign - An array of column alignments 1350 * $table->size - An array of column sizes 1351 * $table->wrap - An array of "nowrap"s or nothing 1352 * $table->style - An array of personalized style for each column. 1353 * $table->rowid - An array of personalized ids of each row. 1354 * $table->rowstyle - An array of personalized style of each row. 1355 * $table->rowclass - An array of personalized classes of each row (odd-evens classes will be ignored). 1356 * $table->colspan - An array of colspans of each column. 1357 * $table->rowspan - An array of rowspans of each column. 1358 * $table->data[] - An array of arrays containing the data. 1359 * $table->width - A percentage of the page 1360 * $table->border - Border of the table. 1361 * $table->tablealign - Align the whole table (float left or right) 1362 * $table->cellpadding - Padding on each cell 1363 * $table->cellspacing - Spacing between cells 1364 * $table->cellstyle - Style of a cell 1365 * $table->cellclass - Class of a cell 1366 * $table->class - CSS table class 1367 * $table->id - Table ID (useful in JavaScript) 1368 * $table->headclass[] - An array of classes for each heading 1369 * $table->title - Title of the table is a single string that will be on top of the table in the head spanning the whole table 1370 * $table->titlestyle - Title style 1371 * $table->titleclass - Title class 1372 * $table->styleTable - Table style 1373 * $table->caption - Table title 1374 * @param bool Whether to return an output string or echo now 1375 * 1376 * @return string HTML code if return parameter is true. 1377 */ 1378function html_print_table (&$table, $return = false) { 1379 $output = ''; 1380 static $table_count = 0; 1381 1382 $table_count++; 1383 if (isset ($table->align)) { 1384 foreach ($table->align as $key => $aa) { 1385 if ($aa) { 1386 $align[$key] = ' text-align:'. $aa.';'; 1387 } 1388 else { 1389 $align[$key] = ''; 1390 } 1391 } 1392 } 1393 if (isset ($table->valign)) { 1394 foreach ($table->valign as $key => $aa) { 1395 if ($aa) { 1396 $valign[$key] = ' vertical-align:'. $aa.';'; 1397 } 1398 else { 1399 $valign[$key] = ''; 1400 } 1401 } 1402 } 1403 if (isset ($table->size)) { 1404 foreach ($table->size as $key => $ss) { 1405 if ($ss) { 1406 $size[$key] = ' width:'. $ss .';'; 1407 } 1408 else { 1409 $size[$key] = ''; 1410 } 1411 } 1412 } 1413 if (isset ($table->style)) { 1414 foreach ($table->style as $key => $st) { 1415 if ($st) { 1416 $style[$key] = ' '. $st .';'; 1417 } 1418 else { 1419 $style[$key] = ''; 1420 } 1421 } 1422 } 1423 1424 $styleTable = ''; 1425 if (isset ($table->styleTable)) { 1426 $styleTable = $table->styleTable; 1427 } 1428 if (isset ($table->rowid)) { 1429 foreach ($table->rowid as $key => $id) { 1430 $rowid[$key] = $id; 1431 } 1432 } 1433 if (isset ($table->rowstyle)) { 1434 foreach ($table->rowstyle as $key => $st) { 1435 $rowstyle[$key] = ' '. $st .';'; 1436 } 1437 } 1438 if (isset ($table->rowclass)) { 1439 foreach ($table->rowclass as $key => $class) { 1440 $rowclass[$key] = $class; 1441 } 1442 } 1443 if (isset ($table->colspan)) { 1444 foreach ($table->colspan as $keyrow => $cspan) { 1445 foreach ($cspan as $key => $span) { 1446 $colspan[$keyrow][$key] = ' colspan="'.$span.'"'; 1447 } 1448 } 1449 } 1450 if (isset ($table->cellstyle)) { 1451 foreach ($table->cellstyle as $keyrow => $cstyle) { 1452 foreach ($cstyle as $key => $cst) { 1453 $cellstyle[$keyrow][$key] = $cst; 1454 } 1455 } 1456 } 1457 if (isset ($table->cellclass)) { 1458 foreach ($table->cellclass as $keyrow => $cclass) { 1459 foreach ($cclass as $key => $ccl) { 1460 $cellclass[$keyrow][$key] = $ccl; 1461 } 1462 } 1463 } 1464 1465 if (isset ($table->rowspan)) { 1466 foreach ($table->rowspan as $keyrow => $rspan) { 1467 foreach ($rspan as $key => $span) { 1468 $rowspan[$keyrow][$key] = ' rowspan="'.$span.'"'; 1469 } 1470 } 1471 } 1472 1473 1474 if (empty ($table->width)) { 1475 //$table->width = '80%'; 1476 } 1477 1478 if (empty ($table->border)) { 1479 if (empty($table)) { 1480 $table = new stdClass(); 1481 } 1482 $table->border = '0'; 1483 } 1484 1485 if (empty ($table->tablealign) || $table->tablealign != 'left' || $table->tablealign != 'right') { 1486 $table->tablealign = ''; 1487 } 1488 else { 1489 $table->tablealign = 'style="float:'.$table->tablealign.';"'; //Align is deprecated. Use float instead 1490 } 1491 1492 if (!isset ($table->cellpadding)) { 1493 $table->cellpadding = '4'; 1494 } 1495 1496 if (!isset ($table->cellspacing)) { 1497 $table->cellspacing = '4'; 1498 } 1499 1500 if (empty ($table->class)) { 1501 $table->class = 'databox'; 1502 } 1503 1504 if (empty ($table->titlestyle)) { 1505 $table->titlestyle = 'text-align:center;'; 1506 } 1507 1508 $tableid = empty ($table->id) ? 'table'.$table_count : $table->id; 1509 1510 if (!empty($table->width)) { 1511 $output .= '<table style="width:' . $table->width . ';' . $styleTable . '"'.$table->tablealign; 1512 } 1513 else { 1514 $output .= '<table style="' . $styleTable . '"'.$table->tablealign; 1515 } 1516 $output .= ' cellpadding="'.$table->cellpadding.'" cellspacing="'.$table->cellspacing.'"'; 1517 $output .= ' border="'.$table->border.'" class="'.$table->class.'" id="'.$tableid.'">'; 1518 1519 $countcols = 0; 1520 1521 if (!empty($table->caption)) { 1522 $output .= '<caption style="text-align: left"><h4>' . $table->caption . '</h4></caption>'; 1523 } 1524 1525 if (!empty ($table->head)) { 1526 $countcols = count ($table->head); 1527 $output .= '<thead><tr>'; 1528 1529 if (isset ($table->title)) { 1530 $output .= '<th colspan="'.$countcols.'"'; 1531 if (isset ($table->titlestyle)) { 1532 $output .= ' style="'.$table->titlestyle.'"'; 1533 } 1534 if (isset ($table->titleclass)) { 1535 $output .= ' class="'.$table->titleclass.'"'; 1536 } 1537 $output .= '>'.$table->title.'</th></tr><tr>'; 1538 } 1539 1540 foreach ($table->head as $key => $heading) { 1541 if (!isset ($size[$key])) { 1542 $size[$key] = ''; 1543 } 1544 if (!isset ($align[$key])) { 1545 $align[$key] = ''; 1546 } 1547 if (!isset ($table->headclass[$key])) { 1548 $table->headclass[$key] = 'header c'.$key; 1549 } 1550 if (isset ($table->head_colspan[$key])) { 1551 $headColspan = 'colspan = "' . $table->head_colspan[$key] . '"'; 1552 } 1553 else $headColspan = ''; 1554 1555 if (isset ($table->headstyle[$key])) { 1556 $headStyle = ' style = "' . $table->headstyle[$key] . '" '; 1557 } 1558 else $headStyle = ''; 1559 1560 $output .= '<th class="'.$table->headclass[$key].'" ' . $headColspan . $headStyle . ' scope="col">'. $heading .'</th>'; 1561 } 1562 $output .= '</tr></thead>'."\n"; 1563 } 1564 1565 $output .= '<tbody>'."\n"; 1566 if (!empty ($table->data)) { 1567 $oddeven = 1; 1568 foreach ($table->data as $keyrow => $row) { 1569 if (!isset ($rowstyle[$keyrow])) { 1570 $rowstyle[$keyrow] = ''; 1571 } 1572 if (!isset ($rowid[$keyrow])) { 1573 $rowid[$keyrow] = $tableid."-".$keyrow; 1574 } 1575 $oddeven = $oddeven ? 0 : 1; 1576 $class = 'datos'.($oddeven ? "" : "2"); 1577 if (isset ($rowclass[$keyrow])) { 1578 $class = $rowclass[$keyrow]; 1579 } 1580 $output .= '<tr id="'.$rowid[$keyrow].'" style="'.$rowstyle[$keyrow].'" class="'.$class.'">'."\n"; 1581 /* Special separator rows */ 1582 if ($row == 'hr' and $countcols) { 1583 $output .= '<td colspan="'. $countcols .'"><div class="tabledivider"></div></td>'; 1584 continue; 1585 } 1586 1587 if (!is_array($row)) 1588 $row = (array)$row; 1589 1590 /* It's a normal row */ 1591 foreach ($row as $key => $item) { 1592 if (!isset ($size[$key])) { 1593 $size[$key] = ''; 1594 } 1595 if (!isset ($cellstyle[$keyrow][$key])) { 1596 $cellstyle[$keyrow][$key] = ''; 1597 } 1598 if (!isset ($cellclass[$keyrow][$key])) { 1599 $cellclass[$keyrow][$key] = ''; 1600 } 1601 if (!isset ($colspan[$keyrow][$key])) { 1602 $colspan[$keyrow][$key] = ''; 1603 } 1604 if (!isset ($rowspan[$keyrow][$key])) { 1605 $rowspan[$keyrow][$key] = ''; 1606 } 1607 if (!isset ($align[$key])) { 1608 $align[$key] = ''; 1609 } 1610 if (!isset ($valign[$key])) { 1611 $valign[$key] = ''; 1612 } 1613 if (!isset ($wrap[$key])) { 1614 $wrap[$key] = ''; 1615 } 1616 if (!isset ($style[$key])) { 1617 $style[$key] = ''; 1618 } 1619 1620 $output .= '<td id="'.$tableid.'-'.$keyrow.'-'.$key.'" style="'. $cellstyle[$keyrow][$key].$style[$key].$valign[$key].$align[$key].$size[$key].$wrap[$key] .'" '.$colspan[$keyrow][$key].' '.$rowspan[$keyrow][$key].' class="' . $class . ' ' . $cellclass[$keyrow][$key] . '">'. $item .'</td>'."\n"; 1621 } 1622 $output .= '</tr>'."\n"; 1623 } 1624 } 1625 $output .= '</tbody></table>'."\n"; 1626 1627 if ($return) 1628 return $output; 1629 1630 echo $output; 1631} 1632 1633 1634 1635/** 1636 * Render a radio button input. Extended version, use html_print_radio_button() to simplify. 1637 * 1638 * @param string Input name. 1639 * @param string Input value. 1640 * @param string Set the button to be marked (optional, unmarked by default). 1641 * @param bool Disable the button (optional, button enabled by default). 1642 * @param string Script to execute when onClick event is triggered (optional). 1643 * @param string Optional HTML attributes. It's a free string which will be 1644 inserted into the HTML tag, use it carefully (optional). 1645 * @param bool Whether to return an output string or echo now (optional, echo by default). 1646 * 1647 * @return string HTML code if return parameter is true. 1648 */ 1649function html_print_radio_button_extended ($name, $value, $label, $checkedvalue, $disabled, $script, $attributes, $return = false) { 1650 static $idcounter = 0; 1651 1652 $output = ''; 1653 1654 $output = '<input type="radio" name="'.$name.'" value="'.$value.'"'; 1655 $htmlid = 'radiobtn'.sprintf ('%04d', ++$idcounter); 1656 $output .= ' id="'.$htmlid.'"'; 1657 1658 if ($value == $checkedvalue) { 1659 $output .= ' checked="checked"'; 1660 } 1661 if ($disabled) { 1662 $output .= ' disabled="disabled"'; 1663 } 1664 if ($script != '') { 1665 $output .= ' onClick="'. $script . '"'; 1666 } 1667 $output .= ' ' . $attributes ; 1668 $output .= ' />'; 1669 1670 if ($label != '') { 1671 $output .= '<label for="'.$htmlid.'">'. $label .'</label>' . "\n"; 1672 } 1673 1674 if ($return) 1675 return $output; 1676 1677 echo $output; 1678} 1679 1680/** 1681 * Render a radio button input. 1682 * 1683 * @param string Input name. 1684 * @param string Input value. 1685 * @param string Label to add after the radio button (optional). 1686 * @param string Checked and selected value, the button will be selected if it matches $value (optional). 1687 * @param bool Whether to return an output string or echo now (optional, echo by default). 1688 * 1689 * @return string HTML code if return parameter is true. 1690 */ 1691function html_print_radio_button ($name, $value, $label = '', $checkedvalue = '', $return = false) { 1692 $output = html_print_radio_button_extended ($name, $value, $label, $checkedvalue, false, '', '', true); 1693 1694 if ($return) 1695 return $output; 1696 1697 echo $output; 1698} 1699 1700/** 1701 * Render a checkbox button input. Extended version, use html_print_checkbox() to simplify. 1702 * 1703 * @param string Input name. 1704 * @param string Input value. 1705 * @param string Set the button to be marked (optional, unmarked by default). 1706 * @param bool Disable the button (optional, button enabled by default). 1707 * @param string Script to execute when onClick event is triggered (optional). 1708 * @param string Optional HTML attributes. It's a free string which will be 1709 inserted into the HTML tag, use it carefully (optional). 1710 * @param bool Whether to return an output string or echo now (optional, echo by default). 1711 * 1712 * @return string HTML code if return parameter is true. 1713 */ 1714function html_print_checkbox_extended ($name, $value, $checked, $disabled, $script, $attributes, $return = false, $id='') { 1715 static $idcounter = array (); 1716 1717 //If duplicate names exist, it will start numbering. Otherwise it won't 1718 if (isset ($idcounter[$name])) { 1719 $idcounter[$name]++; 1720 } 1721 else { 1722 $idcounter[$name] = 0; 1723 } 1724 1725 $id_aux = preg_replace('/[^a-z0-9\:\;\-\_]/i', '', $name.($idcounter[$name] ? $idcounter[$name] : '')); 1726 1727 $output = '<input name="'.$name.'" type="checkbox" value="'.$value.'" '. ($checked ? 'checked="checked"': ''); 1728 if ($id == '') { 1729 $output .= ' id="checkbox-'.$id_aux.'"'; 1730 } else { 1731 $output .= ' '.$id.'"'; 1732 } 1733 1734 if ($script != '') { 1735 $output .= ' onclick="'. $script . '"'; 1736 } 1737 1738 if ($disabled) { 1739 $output .= ' disabled="disabled"'; 1740 } 1741 1742 $output .= ' ' . $attributes ; 1743 $output .= ' />'; 1744 $output .= "\n"; 1745 1746 if ($return === false) 1747 echo $output; 1748 1749 return $output; 1750} 1751 1752/** 1753 * Render a checkbox button input. 1754 * 1755 * @param string Input name. 1756 * @param string Input value. 1757 * @param string Set the button to be marked (optional, unmarked by default). 1758 * @param bool Whether to return an output string or echo now (optional, echo by default). 1759 * @param bool $disabled Disable the button (optional, button enabled by default). 1760 * 1761 * @return string HTML code if return parameter is true. 1762 */ 1763function html_print_checkbox ($name, $value, $checked = false, $return = false, $disabled = false, $script = '', $disabled_hidden = false) { 1764 $output = html_print_checkbox_extended ($name, $value, (bool) $checked, $disabled, $script, '', true); 1765 if (!$disabled_hidden) { 1766 $output .= html_print_input_hidden($name . '_sent', 1, true); 1767 } 1768 1769 if ($return === false) 1770 echo $output; 1771 1772 return $output; 1773} 1774 1775/** 1776 * Prints an image HTML element. 1777 * 1778 * @param string $src Image source filename. 1779 * @param bool $return Whether to return or print 1780 * @param array $options Array with optional HTML options to set. At this moment, the 1781 * following options are supported: alt, style, title, width, height, class, pos_tree. 1782 * @param bool $return_src Whether to return src field of image ('images/*.*') or complete html img tag ('<img src="..." alt="...">'). 1783 * @param bool $relative Whether to use relative path to image or not (i.e. $relative= true : /pandora/<img_src>). 1784 * 1785 * @return string HTML code if return parameter is true. 1786 */ 1787function html_print_image ($src, $return = false, $options = false, 1788 $return_src = false, $relative = false, $no_in_meta = false, $isExternalLink = false) { 1789 1790 global $config; 1791 1792 // If metaconsole is in use then don't use skins 1793 if (!is_metaconsole()) { 1794 1795 /* Checks if user's skin is available */ 1796 $isFunctionSkins = enterprise_include_once ('include/functions_skins.php'); 1797 1798 if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) { 1799 $skin_path = enterprise_hook('skins_get_image_path',array($src)); 1800 1801 if ($skin_path) 1802 $src = $skin_path; 1803 } 1804 1805 } 1806 1807 1808 // If metaconsole is activated and image doesn't exists try to search on normal console 1809 if (is_metaconsole()) { 1810 if (!$relative) { 1811 $working_dir = str_replace("\\", "/", getcwd()); // Windows compatibility 1812 if ($no_in_meta){ 1813 $src = '../../' . $src; 1814 } 1815 else if (strstr($working_dir, 'enterprise/meta') === false) { 1816 if ($src[0] !== '/') { 1817 $src = '/' . $src; 1818 } 1819 1820 if (!is_readable($working_dir . '/enterprise/meta' . $src)) { 1821 if ($isExternalLink) { 1822 $src = ui_get_full_url($src); 1823 } 1824 else { 1825 $src = ui_get_full_url('../..' . $src); 1826 } 1827 } 1828 else { 1829 $src = ui_get_full_url($src); 1830 } 1831 } 1832 else { 1833 if ($src[0] !== '/') { 1834 $src = '/' . $src; 1835 } 1836 1837 if (is_readable($working_dir . $src)) { 1838 $src = ui_get_full_url($src); 1839 } 1840 else if (!is_readable($src)) { 1841 $src = ui_get_full_url('../../' . $src); 1842 } 1843 } 1844 } 1845 else { 1846 $src = '../../' . $src; 1847 } 1848 } 1849 else { 1850 if (!$relative) { 1851 $src_tmp = $src; 1852 $src = ui_get_full_url($src); 1853 } 1854 } 1855 1856 // Only return src field of image 1857 if ($return_src) { 1858 if (!$return) { 1859 echo io_safe_input($src); 1860 return; 1861 } 1862 return io_safe_input($src); 1863 } 1864 1865 $output = '<img src="' . $src . '" '; // Dont use safe_input here or the performance will dead 1866 $style = ''; 1867 1868 if (!empty ($options)) { 1869 //Deprecated or value-less attributes 1870 if (isset ($options["align"])) { 1871 $style .= 'align:' . $options["align"] . ';'; //Align is deprecated, use styles. 1872 } 1873 1874 if (isset ($options["border"])) { 1875 $style .= 'border:' . $options["border"] . 'px;'; //Border is deprecated, use styles 1876 } 1877 1878 if (isset ($options["hspace"])) { 1879 $style .= 'margin-left:' . $options["hspace"] . 'px;'; //hspace is deprecated, use styles 1880 $style .= 'margin-right:' . $options["hspace"] . 'px;'; 1881 } 1882 1883 if (isset ($options["ismap"])) { 1884 $output .= 'ismap="ismap" '; //Defines the image as a server-side image map 1885 } 1886 1887 if (isset ($options["vspace"])) { 1888 $style .= 'margin-top:' . $options["vspace"] . 'px;'; //hspace is deprecated, use styles 1889 $style .= 'margin-bottom:' . $options["vspace"] . 'px;'; 1890 } 1891 1892 if (isset ($options["style"])) { 1893 $style .= $options["style"]; 1894 } 1895 1896 // If title is provided activate forced title 1897 if (isset ($options["title"]) && $options["title"] != '') { 1898 if (isset ($options['class'])) { 1899 $options['class'] .= ' forced_title'; 1900 } 1901 else { 1902 $options['class'] = 'forced_title'; 1903 } 1904 1905 // New way to show the force_title (cleaner and better performance) 1906 $output .= 'data-title="'.io_safe_input_html($options["title"]).'" '; 1907 $output .= 'data-use_title_for_force_title="1" '; 1908 } 1909 1910 //Valid attributes (invalid attributes get skipped) 1911 $attrs = array ("height", "longdesc", "usemap", "width", "id", 1912 "class", "lang", "xml:lang", "onclick", "ondblclick", 1913 "onmousedown", "onmouseup", "onmouseover", "onmousemove", 1914 "onmouseout", "onkeypress", "onkeydown", "onkeyup", "pos_tree"); 1915 1916 foreach ($attrs as $attribute) { 1917 if (isset ($options[$attribute])) { 1918 $output .= $attribute . '="' . 1919 io_safe_input_html ($options[$attribute]) . '" '; 1920 } 1921 } 1922 } 1923 else { 1924 $options = array (); 1925 } 1926 1927 if (!isset ($options["alt"]) && isset ($options["title"])) { 1928 $options["alt"] = io_safe_input_html($options["title"]); //Set alt to title if it's not set 1929 } 1930 1931 if (!empty ($style)) { 1932 $output .= 'style="'.$style.'" '; 1933 } 1934 1935 if (isset($options["alt"])) 1936 $output .= 'alt="'.io_safe_input_html ($options['alt']).'" />'; 1937 else 1938 $output .= '/>'; 1939 1940 if (!$return) { 1941 echo $output; 1942 } 1943 1944 return $output; 1945} 1946 1947/** 1948 * Render an input text element. Extended version, use html_print_input_text() to simplify. 1949 * 1950 * @param string Input name. 1951 * @param bool Whether to return an output string or echo now (optional, echo by default). 1952 * @param array An array with optional HTML parameters. 1953 * Key size: HTML size attribute. 1954 * Key disabled: Whether to disable the input or not. 1955 * Key class: HTML class 1956 */ 1957function html_print_input_file ($name, $return = false, $options = false) { 1958 $output = ''; 1959 1960 $output .= '<input type="file" value="" name="'.$name.'" id="file-'.$name.'" '; 1961 1962 if ($options) { 1963 if (isset ($options['size'])) 1964 $output .= 'size="'.$options['size'].'"'; 1965 1966 if (isset ($options['disabled'])) 1967 $output .= 'disabled="disabled"'; 1968 1969 if (isset ($options['class'])) 1970 $output .= 'class="'.$options['class'].'"'; 1971 } 1972 1973 $output .= ' />'; 1974 1975 if ($return) 1976 return $output; 1977 echo $output; 1978} 1979 1980/** 1981 * Render a label for a input elemennt. 1982 * 1983 * @param string Label text. 1984 * @param string Input id to refer. 1985 * @param bool Whether to return an output string or echo now (optional, echo by default). 1986 * @param array An array with optional HTML parameters. 1987 * Key html: Extra HTML to add after the label. 1988 * Key class: HTML class 1989 */ 1990function html_print_label ($text, $id, $return = false, $options = false) { 1991 $output = ''; 1992 1993 $output .= '<label id="label-'.$id.'" '; 1994 1995 if ($options) { 1996 if (isset ($options['class'])) 1997 $output .= 'class="'.$options['class'].'" '; 1998 } 1999 2000 $output .= 'for="'.$id.'" >'; 2001 $output .= $text; 2002 $output .= '</label>'; 2003 2004 if ($options) { 2005 if (isset ($options['html'])) 2006 $output .= $options['html']; 2007 } 2008 2009 if ($return) 2010 return $output; 2011 2012 echo $output; 2013} 2014 2015/** 2016 * Convert a html color like #FF00FF into the rgb values like (255,0,255). 2017 * 2018 * @param string color in format #FFFFFF, FFFFFF, #FFF or FFF 2019 */ 2020function html_html2rgb($htmlcolor) 2021{ 2022 if ($htmlcolor[0] == '#') { 2023 $htmlcolor = substr($htmlcolor, 1); 2024 } 2025 2026 if (strlen($htmlcolor) == 6) { 2027 $r = hexdec($htmlcolor[0].$htmlcolor[1]); 2028 $g = hexdec($htmlcolor[2].$htmlcolor[3]); 2029 $b = hexdec($htmlcolor[4].$htmlcolor[5]); 2030 return array($r, $g, $b); 2031 } 2032 elseif (strlen($htmlcolor) == 3) { 2033 $r = hexdec($htmlcolor[0].$htmlcolor[0]); 2034 $g = hexdec($htmlcolor[1].$htmlcolor[1]); 2035 $b = hexdec($htmlcolor[2].$htmlcolor[2]); 2036 return array($r, $g, $b); 2037 } 2038 else { 2039 return false; 2040 } 2041} 2042 2043/** 2044 * Print a magic-ajax control to select the module. 2045 * 2046 * @param string $name The name of ajax control, by default is "module". 2047 * @param string $default The default value to show in the ajax control. 2048 * @param array $id_agents The array list of id agents as array(1,2,3), by default is false and the function use all agents (if the ACL desactive). 2049 * @param bool $ACL Filter the agents by the ACL list of user. 2050 * @param string $scriptResult The source code of script to call, by default is 2051 * empty. And the example is: 2052 * function (e, data, formatted) { 2053 * ... 2054 * } 2055 * 2056 * And the formatted is the select item as string. 2057 * 2058 * @param array $filter Other filter of modules. 2059 * @param bool $return If it is true return a string with the output instead to echo the output. 2060 * 2061 * @return mixed If the $return is true, return the output as string. 2062 */ 2063function html_print_autocomplete_modules($name = 'module', 2064 $default = '', $id_agents = false, $ACL = true, $scriptResult = '', 2065 $filter = array(), $return = false,$id_agent_module = 0) { 2066 2067 global $config; 2068 2069 if ($id_agents === false) { 2070 $groups = array(); 2071 if ($ACL) { 2072 $groups = users_get_groups($config['id_user'], "AW", false); 2073 $groups = array_keys($groups); 2074 2075 if (empty($groups)) { 2076 $id_groups = 0; 2077 } else { 2078 $id_groups = implode(',', $groups); 2079 } 2080 2081 $agents = db_get_all_rows_sql('SELECT id_agente 2082 FROM tagente 2083 WHERE id_grupo IN (' . $id_groups . ')'); 2084 } 2085 else { 2086 $agents = db_get_all_rows_sql('SELECT id_agente 2087 FROM tagente'); 2088 } 2089 2090 if ($agents === false) $agents = array(); 2091 2092 $id_agents = array(); 2093 foreach ($agents as $agent) { 2094 $id_agents[] = $agent['id_agente']; 2095 } 2096 } 2097 else { 2098 if ($ACL) { 2099 $groups = users_get_groups($config['id_user'], "AW", false); 2100 $groups = array_keys($groups); 2101 2102 $agents = db_get_all_rows_sql('SELECT id_agente FROM tagente WHERE id_grupo IN (' . implode(',', $groups) . ')'); 2103 2104 if ($agents === false) $agents = array(); 2105 2106 $id_agentsACL = array(); 2107 foreach ($agents as $agent) { 2108 if (array_search($agent['id_agente'], $id_agents) !== false) { 2109 $id_agentsACL[] = $agent['id_agente']; 2110 } 2111 } 2112 2113 $id_agents = $id_agentsACL; 2114 } 2115 } 2116 2117 ob_start(); 2118 2119 html_print_input_text_extended ($name, $default, 'text-' . $name, '', 30, 100, false, '', 2120 array('style' => 'background: url(images/input_module.png) no-repeat right;')); 2121 html_print_input_hidden($name . "_hidden", $id_agent_module); 2122 ui_print_help_tip(__('Type at least two characters to search the module.'), false); 2123 2124 $javascript_ajax_page = 2125 ui_get_full_url('ajax.php', false, false, false, false); 2126 ?> 2127 <script type="text/javascript"> 2128 function escapeHTML (str) 2129 { 2130 var div = document.createElement('div'); 2131 var text = document.createTextNode(str); 2132 div.appendChild(text); 2133 return div.innerHTML; 2134 } 2135 2136 $(document).ready (function () { 2137 $("#text-<?php echo $name; ?>").autocomplete({ 2138 minLength: 2, 2139 source: function( request, response ) { 2140 var term = request.term; //Word to search 2141 2142 data_params = { 2143 page: "include/ajax/module", 2144 q: term, 2145 search_modules: 1, 2146 id_agents: '<?php echo json_encode($id_agents); ?>', 2147 other_filter: '<?php echo json_encode($filter); ?>' 2148 }; 2149 2150 jQuery.ajax ({ 2151 data: data_params, 2152 async: false, 2153 type: "POST", 2154 url: action="<?php echo $javascript_ajax_page;?>", 2155 timeout: 10000, 2156 dataType: "json", 2157 success: function (data) { 2158 temp = []; 2159 $.each(data, function (id, module) { 2160 temp.push({ 2161 'value' : id, 2162 'label' : module}); 2163 }); 2164 2165 response(temp); 2166 } 2167 }); 2168 }, 2169 change: function( event, ui ) { 2170 if (!ui.item) 2171 $("input[name='<?php echo $name; ?>_hidden']") 2172 .val(0); 2173 return false; 2174 }, 2175 select: function( event, ui ) { 2176 $("input[name='<?php echo $name; ?>_hidden']") 2177 .val(ui.item.value); 2178 2179 $("#text-<?php echo $name; ?>").val( ui.item.label ); 2180 return false; 2181 } 2182 } 2183 ); 2184 }); 2185 </script> 2186 <?php 2187 2188 $output = ob_get_clean(); 2189 2190 if ($return) { 2191 return $output; 2192 } 2193 else { 2194 echo $output; 2195 } 2196} 2197?> 2198