'; if ($nothing != '') { $output .= '"; } } } $output .= ""; if ($return) return $output; echo $output; } /** * Prints an array of fields in a popup menu of a form based on a SQL query. * The first and second columns of the query will be used. * * The element will have an id like: "password-$value". Based on choose_from_menu() from Moodle. * * @param string SQL sentence, the first field will be the identifier of the option. * The second field will be the shown value in the dropdown. * @param string Select form name * @param string Current selected value. * @param string Javascript onChange code. * @param string Label when nothing is selected. * @param string Value when nothing is selected * @param bool Whether to return an output string or echo now (optional, echo by default). * @param bool Whether to allow multiple selections or not. Single by default * @param bool Whether to sort the options or not. Sorted by default. * * @return string HTML code if return parameter is true. */ function print_select_from_sql ($sql, $name, $selected = '', $script = '', $nothing = '', $nothing_value = '0', $return = false, $multiple = false, $sort = true) { $fields = array (); $result = get_db_all_rows_sql ($sql); if ($result === false) $result = array (); foreach ($result as $row) { $fields[$row[0]] = $row[1]; } return print_select ($fields, $name, $selected, $script, $nothing, $nothing_value, $return, $multiple, $sort); } /** * Render an input text element. Extended version, use print_input_text() to simplify. * * @param string Input name. * @param string Input value. * @param string Input HTML id. * @param string Alternative HTML string. * @param int Size of the input. * @param int Maximum length allowed. * @param bool Disable the button (optional, button enabled by default). * @param string Alternative HTML string. * @param bool Whether to return an output string or echo now (optional, echo by default). * @param bool Whether it is a password input or not. Not password by default. * * @return string HTML code if return parameter is true. */ function print_input_text_extended ($name, $value, $id, $alt, $size, $maxlength, $disabled, $script, $attributes, $return = false, $password = false) { static $idcounter = 0; ++$idcounter; $type = $password ? 'password' : 'text'; if (empty ($name)) { $name = 'unnamed'; } if (empty ($alt)) { $alt = 'textfield'; } if (! empty ($maxlength)) { $maxlength = ' maxlength="'.$maxlength.'" '; } $output = ''; if ($return) return $output; echo $output; } /** * Render an input hidden element. * * The element will have an id like: "hidden-$name" * * @param string Input name. * @param string Input value. * @param bool Whether to return an output string or echo now (optional, echo by default). * * @return string HTML code if return parameter is true. */ function print_input_hidden ($name, $value, $return = false) { $output = ''; if ($return) return $output; echo $output; } /** * Render an submit input button element. * * The element will have an id like: "submit-$name" * * @param string Input label. * @param string Input name. * @param bool Whether to disable by default or not. Enabled by default. * @param string Additional HTML attributes. * @param bool Whether to return an output string or echo now (optional, echo by default). * * @return string HTML code if return parameter is true. */ function print_submit_button ($label = 'OK', $name = '', $disabled = false, $attributes = '', $return = false) { $output = ''; $output .= ''; $output .= $value; $output .= ''; if ($return) return $output; echo $output; } /** * Print a nicely formatted table. Code taken from moodle. * * @param object $table is an object with several properties: * $table->head - An array of heading names. * $table->align - An array of column alignments * $table->valign - An array of column alignments * $table->size - An array of column sizes * $table->wrap - An array of "nowrap"s or nothing * $table->style - An array of personalized style for each column. * $table->rowstyle - An array of personalized style of each row. * $table->rowclass - An array of personalized classes of each row (odd-evens classes will be ignored). * $table->colspan - An array of colspans of each column. * $table->data[] - An array of arrays containing the data. * $table->width - A percentage of the page * $table->border - Border of the table. * $table->tablealign - Align the whole table * $table->cellpadding - Padding on each cell * $table->cellspacing - Spacing between cells * $table->class - CSS table class * $table->id - Table ID (useful in JavaScript) * $table->headclass[] - An array of classes for each heading * $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 * $table->titlestyle - Title style * $table->titleclass - Title class * @param bool $return whether to return an output string or echo now * * @return string HTML code if return parameter is true. */ function print_table (&$table, $return = false) { $output = ''; static $table_count = 0; $table_count++; if (isset ($table->align)) { foreach ($table->align as $key => $aa) { if ($aa) { $align[$key] = ' text-align:'. $aa.';'; } else { $align[$key] = ''; } } } if (isset ($table->valign)) { foreach ($table->valign as $key => $aa) { if ($aa) { $valign[$key] = ' vertical-align:'. $aa.';'; } else { $valign[$key] = ''; } } } if (isset ($table->size)) { foreach ($table->size as $key => $ss) { if ($ss) { $size[$key] = ' width:'. $ss .';'; } else { $size[$key] = ''; } } } if (isset ($table->style)) { foreach ($table->style as $key => $st) { if ($st) { $style[$key] = ' '. $st .';'; } else { $style[$key] = ''; } } } if (isset ($table->rowstyle)) { foreach ($table->rowstyle as $key => $st) { $rowstyle[$key] = ' '. $st .';'; } } if (isset ($table->rowclass)) { foreach ($table->rowclass as $key => $class) { $rowclass[$key] = $class; } } if (isset ($table->colspan)) { foreach ($table->colspan as $keyrow => $cspan) { foreach ($cspan as $key => $span) { $colspan[$keyrow][$key] = ' colspan="'.$span.'"'; } } } if (empty ($table->width)) { $table->width = '80%'; } if (empty ($table->border)) { $table->border = '0px'; } if (empty ($table->tablealign)) { $table->tablealign = 'center'; } if (!isset ($table->cellpadding)) { $table->cellpadding = '4'; } if (!isset ($table->cellspacing)) { $table->cellspacing = '4'; } if (empty ($table->class)) { $table->class = 'databox'; } $tableid = empty ($table->id) ? 'table'.$table_count : $table->id; $output .= 'cellpadding.'" cellspacing="'.$table->cellspacing.'"'; $output .= ' border="'.$table->border.'" class="'.$table->class.'" id="'.$tableid.'">'; $countcols = 0; if (!empty ($table->head)) { $countcols = count ($table->head); $output .= ''; if (isset ($table->title)) { $output .= ''; } foreach ($table->head as $key => $heading) { if (!isset ($size[$key])) { $size[$key] = ''; } if (!isset ($align[$key])) { $align[$key] = ''; } if (!isset ($table->headclass[$key])) { $table->headclass[$key] = 'header c'.$key; } $output .= ''; } $output .= ''."\n"; } $output .= ''."\n"; if (!empty ($table->data)) { $oddeven = 1; foreach ($table->data as $keyrow => $row) { if (!isset ($rowstyle[$keyrow])) { $rowstyle[$keyrow] = ''; } $oddeven = $oddeven ? 0 : 1; $class = 'datos'.($oddeven ? "" : "2"); if (isset ($rowclass[$keyrow])) { $class = $rowclass[$keyrow]; } $output .= ''."\n"; /* Special separator rows */ if ($row == 'hr' and $countcols) { $output .= ''; continue; } /* It's a normal row */ foreach ($row as $key => $item) { if (!isset ($size[$key])) { $size[$key] = ''; } if (!isset ($colspan[$keyrow][$key])) { $colspan[$keyrow][$key] = ''; } if (!isset ($align[$key])) { $align[$key] = ''; } if (!isset ($valign[$key])) { $valign[$key] = ''; } if (!isset ($wrap[$key])) { $wrap[$key] = ''; } if (!isset ($style[$key])) { $style[$key] = ''; } $output .= ''."\n"; } $output .= ''."\n"; } } $output .= '
titlestyle)) { $output .= ' style="'.$table->titlestyle.'"'; } if (isset ($table->titleclass)) { $output .= ' class="'.$table->titleclass.'"'; } $output .= '>'.$table->title.'
'. $heading .'
'. $item .'
'."\n"; if ($return) return $output; echo $output; } /** * Render a radio button input. Extended version, use print_radio_button() to simplify. * * @param string $name Input name. * @param string $value Input value. * @param string $checked Set the button to be marked (optional, unmarked by default). * @param bool $disabled Disable the button (optional, button enabled by default). * @param string $script Script to execute when onClick event is triggered (optional). * @param string $attributes Optional HTML attributes. It's a free string which will be inserted into the HTML tag, use it carefully (optional). * @param bool $return Whether to return an output string or echo now (optional, echo by default). * * @return string HTML code if return parameter is true. */ function print_radio_button_extended ($name, $value, $label, $checkedvalue, $disabled, $script, $attributes, $return = false) { static $idcounter = 0; $output = ''; $output = ''. $label .'' . "\n"; } if ($return) return $output; echo $output; } /** * Render a radio button input. * * @param string $name Input name. * @param string $value Input value. * @param string $label Label to add after the radio button (optional). * @param string $checkedvalue Checked and selected value, the button will be selected if it matches $value (optional). * @param bool $return Whether to return an output string or echo now (optional, echo by default). * * @return string HTML code if return parameter is true. */ function print_radio_button ($name, $value, $label = '', $checkedvalue = '', $return = false) { $output = print_radio_button_extended ($name, $value, $label, $checkedvalue, false, '', '', true); if ($return) return $output; echo $output; } /** * Render a checkbox button input. Extended version, use print_checkbox() to simplify. * * @param string $name Input name. * @param string $value Input value. * @param string $checked Set the button to be marked (optional, unmarked by default). * @param bool $disabled Disable the button (optional, button enabled by default). * @param string $script Script to execute when onClick event is triggered (optional). * @param string $attributes Optional HTML attributes. It's a free string which will be inserted into the HTML tag, use it carefully (optional). * @param bool $return Whether to return an output string or echo now (optional, echo by default). * * @return string HTML code if return parameter is true. */ function print_checkbox_extended ($name, $value, $checked, $disabled, $script, $attributes, $return = false) { static $idcounter = 0; $htmlid = 'checkbox'.sprintf ('%04d', ++$idcounter); $output = ''; if ($return) return $output; echo $output; } /** * Prints an image HTML element. * * @param string Image source filename. * @param array Array with optional HTML options to set. At this moment, the * following options are supported: alt, style, title, width, height, class. * * @return string HTML code if return parameter is true. */ function print_image ($src, $return = false, $options = false) { $output = ''.$bad.''; } else { $output = '<'.$tag.' class="suc" '.$attributes.'>'.$good.''; } if ($return === false) echo $output; return $output; } /** * Evaluates a unix timestamp and returns a span (or whatever tag specified) * with as title the correctly formatted full timestamp and a time comparation * in the tag * * @param int $unixtime: Any type of timestamp really, but we prefer unixtime * @param bool $return whether to output the string or return it * @param array $option: An array with different options for this function * Key html_attr: which html attributes to add (defaults to none) * Key tag: Which html tag to use (defaults to span) * * @return string HTML code if return parameter is true. */ function print_timestamp ($unixtime, $return = false, $option = array ()) { global $config; if (isset ($option["html_attr"])) { $attributes = $option["html_attr"]; } else { $attributes = ""; } if (isset ($option["tag"])) { $tag = $option["tag"]; } else { $tag = "span"; } if (!is_numeric ($unixtime)) { $unixtime = strtotime ($unixtime); } //prominent_time is either timestamp or comparation if ($unixtime == 0) { $title = __('Never'); $data = __('Never'); } elseif ($config["prominent_time"] == "timestamp") { $title = human_time_comparation ($unixtime); $data = date ($config["date_format"], $unixtime); } else { $title = date ($config["date_format"], $unixtime); $data = human_time_comparation ($unixtime); } $output = '<'.$tag; switch ($tag) { default: //Usually tags have title attributes, so by default we add, then fall through to add attributes and data $output .= ' title="'.$title.'"'; case "h1": case "h2": case "h3": //Above tags don't have title attributes $output .= ' '.$attributes.'>'.$data.''; } if ($return === false) { echo $output; } return $output; } /** * Prints a username with real name, link to the user_edit page etc. * * @param string $username The username to render * @param bool $return Whether to return or print * * @return string HTML code if return parameter is true. */ function print_username ($username, $return = false) { $string = ''.dame_nombre_real ($username).''; if ($return === false) { echo $string; } return $string; } /** * Print group icon within a link * * @param string $id_group Group id * @param bool $return Whether to return or print * @param string $path What path to use (relative to images/). Defaults to groups_small * @return string HTML code if return parameter is true. */ function print_group_icon ($id_group, $return = false, $path = "groups_small") { $icon = (string) get_db_value ('icon', 'tgrupo', 'id_grupo', (int) $id_group); if (empty ($icon)) { return "-"; } $return = ''; $return .= ''.get_group_name ($id_group).''; $return .= ''; if ($return === false) { echo $return; } return $return; } /** * Get the icon of an operating system. * * @param int $id_os Operating system id * @param bool $name Whether to also append the name of the OS after the icon * @param bool $return Whether to return or echo the result * * @return string HTML with icon of the OS */ function print_os_icon ($id_os, $name = true, $return = false) { $icon = (string) get_db_value ('icon_name', 'tconfig_os', 'id_os', (int) $id_os); $os_name = get_os_name ($id_os); if (empty ($icon)) { return "-"; } $output = ''.$os_name.''; if ($name === true) { $output .= ' - '.$os_name; } if ($return === false) { echo $output; } return $output; } /** * Prints an agent name with the correct link * * @param int $agent Agent id * @param bool $return Whether to return the string or echo it too * @param int $cutoff After how much characters to cut off the inside of the link. The full agent name will remain in the roll-over * * @return string HTML with agent name and link **/ function print_agent_name ($id_agent, $return = false, $cutoff = 0) { $agent_name = (string) get_agent_name ($id_agent); $output = ''; if ($cutoff > 0 && (mb_strlen ($agent_name, "UTF-8") > $cutoff)) { $output .= mb_substr (utf8_decode ($agent_name), 0, $cutoff, "UTF-8").'...'; } else { $output .= $agent_name; } $output .= ''; //TODO: Add a pretty javascript (using jQuery) popup-box with agent details if ($return === false) { echo $output; } return $output; } ?>