2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Contains functions used by browse_foreigners.php
10 * Function to get html for one relational key
12 * @param integer $horizontal_count the current horizontal count
13 * @param string $header table header
14 * @param boolean $odd_row for the row background color
15 * @param array $keys all the keys
16 * @param integer $indexByKeyname index by keyname
17 * @param array $descriptions descriptions
18 * @param integer $indexByDescription index by description
19 * @param string $current_value current value on the edit form
21 * @return string $html the generated html
23 function PMA_getHtmlForOneKey($horizontal_count, $header, $odd_row, $keys,
24 $indexByKeyname, $descriptions, $indexByDescription, $current_value
29 // whether the key name corresponds to the selected value in the form
30 $rightKeynameIsSelected = false;
31 $leftKeynameIsSelected = false;
33 if ($GLOBALS['cfg']['RepeatCells'] > 0
34 && $horizontal_count > $GLOBALS['cfg']['RepeatCells']
37 $horizontal_count = 0;
41 // key names and descriptions for the left section,
42 // sorted by key names
43 $leftKeyname = $keys[$indexByKeyname];
47 ) = PMA_getDescriptionAndTitle($descriptions[$indexByKeyname]);
49 // key names and descriptions for the right section,
50 // sorted by descriptions
51 $rightKeyname = $keys[$indexByDescription];
54 $rightDescriptionTitle
55 ) = PMA_getDescriptionAndTitle($descriptions[$indexByDescription]);
57 $indexByDescription++
;
59 if (! empty($current_value)) {
60 $rightKeynameIsSelected = $rightKeyname == $current_value;
61 $leftKeynameIsSelected = $leftKeyname == $current_value;
64 $output .= '<tr class="noclick ' . ($odd_row ?
'odd' : 'even') . '">';
65 $odd_row = ! $odd_row;
67 $output .= PMA_getHtmlForColumnElement(
68 'class="nowrap"', $leftKeynameIsSelected,
69 $leftKeyname, $leftDescription,
73 $output .= PMA_getHtmlForColumnElement(
74 '', $leftKeynameIsSelected, $leftKeyname,
75 $leftDescription, $leftDescriptionTitle
78 $output .= '<td width="20%">'
79 . '<img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png" alt=""'
80 . ' width="1" height="1" /></td>';
82 $output .= PMA_getHtmlForColumnElement(
83 '', $rightKeynameIsSelected, $rightKeyname,
84 $rightDescription, $rightDescriptionTitle
87 $output .= PMA_getHtmlForColumnElement(
88 'class="nowrap"', $rightKeynameIsSelected,
89 $rightKeyname, $rightDescription,
90 $rightDescriptionTitle
94 return array($output, $horizontal_count, $odd_row, $indexByDescription);
98 * Function to get html for relational field selection
100 * @param string $db current database
101 * @param string $table current table
102 * @param string $field field
103 * @param array $foreignData foreign column data
104 * @param string $fieldkey field key
105 * @param string $current_value current columns's value
109 function PMA_getHtmlForRelationalFieldSelection($db, $table, $field, $foreignData,
110 $fieldkey, $current_value
112 $gotopage = PMA_getHtmlForGotoPage($foreignData);
113 $showall = PMA_getHtmlForShowAll($foreignData);
115 $output = '<form class="ajax" '
116 . 'id="browse_foreign_form" name="browse_foreign_from" '
117 . 'action="browse_foreigners.php" method="post">'
119 . PMA_URL_getHiddenInputs($db, $table)
120 . '<input type="hidden" name="field" value="' . htmlspecialchars($field)
122 . '<input type="hidden" name="fieldkey" value="'
123 . (isset($fieldkey) ?
htmlspecialchars($fieldkey) : '') . '" />';
125 if (isset($_REQUEST['rownumber'])) {
126 $output .= '<input type="hidden" name="rownumber" value="'
127 . htmlspecialchars($_REQUEST['rownumber']) . '" />';
129 $filter_value = (isset($_REQUEST['foreign_filter'])
130 ?
htmlspecialchars($_REQUEST['foreign_filter'])
132 $output .= '<span class="formelement">'
133 . '<label for="input_foreign_filter">' . __('Search:') . '</label>'
134 . '<input type="text" name="foreign_filter" '
135 . 'id="input_foreign_filter" '
136 . 'value="' . $filter_value . '" data-old="' . $filter_value . '" '
138 . '<input type="submit" name="submit_foreign_filter" value="'
141 . '<span class="formelement">' . $gotopage . '</span>'
142 . '<span class="formelement">' . $showall . '</span>'
146 $output .= '<table width="100%" id="browse_foreign_table">';
148 if (!is_array($foreignData['disp_row'])) {
149 $output .= '</tbody>'
156 <th>' . __('Keyname') . '</th>
157 <th>' . __('Description') . '</th>
158 <td width="20%"></td>
159 <th>' . __('Description') . '</th>
160 <th>' . __('Keyname') . '</th>
163 $output .= '<thead>' . $header . '</thead>' . "\n"
164 . '<tfoot>' . $header . '</tfoot>' . "\n"
167 $descriptions = array();
169 foreach ($foreignData['disp_row'] as $relrow) {
170 if ($foreignData['foreign_display'] != false) {
171 $descriptions[] = $relrow[$foreignData['foreign_display']];
173 $descriptions[] = '';
176 $keys[] = $relrow[$foreignData['foreign_field']];
181 $horizontal_count = 0;
183 $indexByDescription = 0;
185 foreach ($keys as $indexByKeyname => $value) {
191 ) = PMA_getHtmlForOneKey(
192 $horizontal_count, $header, $odd_row, $keys, $indexByKeyname,
193 $descriptions, $indexByDescription, $current_value
198 $output .= '</tbody>'
205 * Get the description (possibly truncated) and the title
207 * @param string $description the key name's description
209 * @return array the new description and title
211 function PMA_getDescriptionAndTitle($description)
213 $limitChars = $GLOBALS['cfg']['LimitChars'];
214 if (mb_strlen($description) <= $limitChars) {
215 $description = htmlspecialchars(
218 $descriptionTitle = '';
220 $descriptionTitle = htmlspecialchars(
223 $description = htmlspecialchars(
225 $description, 0, $limitChars
230 return array($description, $descriptionTitle);
234 * Function to get html for each column element
236 * @param string $cssClass class="nowrap" or ''
237 * @param bool $isSelected whether current equals form's value
238 * @param string $keyname current key
239 * @param string $description current value
240 * @param string $title current title
244 function PMA_getHtmlForColumnElement($cssClass, $isSelected, $keyname,
247 $keyname = htmlspecialchars($keyname);
249 if (! empty($cssClass)) {
250 $output .= ' ' . $cssClass;
253 . ($isSelected ?
'<strong>' : '')
254 . '<a class="foreign_value" data-key="' . $keyname . '" '
255 . 'href="#" title="' . __('Use this value')
260 if ($cssClass !== '') {
263 $output .= $description;
266 $output .= '</a>' . ($isSelected ?
'</strong>' : '') . '</td>';
272 * Function to get html for show all case
274 * @param array $foreignData foreign data
278 function PMA_getHtmlForShowAll($foreignData)
281 if (is_array($foreignData['disp_row'])) {
282 if ($GLOBALS['cfg']['ShowAll']
283 && ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows'])
285 $showall = '<input type="submit" id="foreign_showAll" '
286 . 'name="foreign_showAll" '
287 . 'value="' . __('Show all') . '" />';
295 * Function to get html for the goto page option
297 * @param array $foreignData foreign data
301 function PMA_getHtmlForGotoPage($foreignData)
304 isset($_REQUEST['pos']) ?
$pos = $_REQUEST['pos'] : $pos = 0;
305 if (!is_array($foreignData['disp_row'])) {
309 $session_max_rows = $GLOBALS['cfg']['MaxRows'];
310 $pageNow = @floor
($pos / $session_max_rows) +
1;
311 $nbTotalPage = @ceil
($foreignData['the_total'] / $session_max_rows);
313 if ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows']) {
314 $gotopage = PMA\libraries\Util
::pageselector(
332 * Function to get foreign limit
334 * @param string $foreign_showAll foreign navigation
338 function PMA_getForeignLimit($foreign_showAll)
340 if (isset($foreign_showAll) && $foreign_showAll == __('Show all')) {
343 isset($_REQUEST['pos']) ?
$pos = $_REQUEST['pos'] : $pos = 0;
344 return 'LIMIT ' . $pos . ', ' . intval($GLOBALS['cfg']['MaxRows']) . ' ';