[1] | 1 | <?php |
---|
| 2 | /** |
---|
[362] | 3 | * The Strangecode Codebase - a general application development framework for PHP |
---|
| 4 | * For details visit the project site: <http://trac.strangecode.com/codebase/> |
---|
[396] | 5 | * Copyright 2001-2012 Strangecode, LLC |
---|
[362] | 6 | * |
---|
| 7 | * This file is part of The Strangecode Codebase. |
---|
| 8 | * |
---|
| 9 | * The Strangecode Codebase is free software: you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License as published by the |
---|
| 11 | * Free Software Foundation, either version 3 of the License, or (at your option) |
---|
| 12 | * any later version. |
---|
| 13 | * |
---|
| 14 | * The Strangecode Codebase is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
| 17 | * details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License along with |
---|
| 20 | * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | /** |
---|
[1] | 24 | * TemplateGlue.inc.php |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | /** |
---|
[42] | 28 | * Print URL to download file with BBEdit/Interarchy. "USER" must be a pre-set |
---|
[1] | 29 | * environment variable. Files must reside within and be relative to env "DOCUMENT_ROOT". |
---|
| 30 | * |
---|
| 31 | * @access public |
---|
| 32 | * @param mixed $file File path relative to DOCUMENT_ROOT (i.e. '/_templates/index.ihtml'). |
---|
| 33 | * @return string <a> with file basename as text. |
---|
| 34 | */ |
---|
| 35 | function bbftp($file) |
---|
| 36 | { |
---|
[35] | 37 | return sprintf('<a href="bbftp://%s@%s:%s%s" title="%s" style="text-decoration: none; border-bottom: blue 1px dotted;">%s</a>', $_SERVER['USER'], $_SERVER['HTTP_HOST'], $_SERVER['DOCUMENT_ROOT'], $file, $file, basename($file)); |
---|
[1] | 38 | } |
---|
| 39 | |
---|
| 40 | /** |
---|
[42] | 41 | * Returns an image tag for image specified in $src. |
---|
[1] | 42 | * |
---|
| 43 | * @param string $src File name of the image, including path and file extension. |
---|
| 44 | * @param string $alt Alt tag text. |
---|
| 45 | * @param string $extra Additional attributes. |
---|
| 46 | */ |
---|
| 47 | function oImg($src, $alt='', $extra='') |
---|
| 48 | { |
---|
| 49 | $filepath = preg_match('!://!', $src) ? $src : getenv('DOCUMENT_ROOT') . $src; |
---|
[42] | 50 | |
---|
[35] | 51 | if (true === ($gis = @getimagesize($filepath)) && !preg_match('/width|height/', $extra)) { |
---|
| 52 | $image_size = $gis[3]; |
---|
| 53 | } else { |
---|
[1] | 54 | $image_size = ''; |
---|
| 55 | } |
---|
[42] | 56 | |
---|
[1] | 57 | return sprintf('<img src="%s" %s alt="%s" %s />', |
---|
| 58 | $src, |
---|
| 59 | $image_size, |
---|
| 60 | oTxt($alt), |
---|
| 61 | $extra |
---|
| 62 | ); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /** |
---|
[42] | 66 | * Prints an image tag for image specified in $src. |
---|
[1] | 67 | * |
---|
| 68 | * @param string $src File name of the image, including path and file extension. |
---|
| 69 | * @param string $alt Alt tag text. |
---|
| 70 | * @param string $extra Additional attributes. |
---|
| 71 | */ |
---|
| 72 | function printImg($src, $alt='', $extra='') |
---|
| 73 | { |
---|
| 74 | echo oImg($src, $alt, $extra); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | /** |
---|
| 78 | * Finds the values of an enumeration or set column of a MySQL database, returning them in an array. |
---|
[334] | 79 | * Use this to generate a pull-down menu of options or to validate the existence |
---|
[42] | 80 | * of options. (Quinn 10 Feb 2001) |
---|
[1] | 81 | * |
---|
| 82 | * @param string $db_table database table to lookup |
---|
| 83 | * @param string $db_col database column to lookup |
---|
[295] | 84 | * @param bool $sort Sort the output. |
---|
[1] | 85 | * @return array Array of the set/enum values on success, false on failure. |
---|
| 86 | */ |
---|
[295] | 87 | function getSetEnumFieldValues($db_table, $db_col, $sort=false) |
---|
[1] | 88 | { |
---|
[136] | 89 | $app =& App::getInstance(); |
---|
| 90 | $db =& DB::getInstance(); |
---|
| 91 | |
---|
| 92 | $qid = $db->query("SHOW COLUMNS FROM " . $db->escapeString($db_table) . " LIKE '" . $db->escapeString($db_col) . "'",false); |
---|
[42] | 93 | |
---|
[1] | 94 | $row = mysql_fetch_row($qid); |
---|
| 95 | if (preg_match('/^enum|^set/i', $row[1]) && preg_match_all("/'([^']*)'/", $row[1], $enum)) { |
---|
[295] | 96 | if ($sort) { |
---|
| 97 | natsort($enum[1]); |
---|
| 98 | } |
---|
[1] | 99 | return $enum[1]; |
---|
| 100 | } else { |
---|
[136] | 101 | $app->logMsg(sprintf('No set or enum fields found.', null), LOG_ERR, __FILE__, __LINE__); |
---|
[1] | 102 | return false; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * Prints option fields for a select form. Works only with enum or set |
---|
[42] | 108 | * data types in table columns. |
---|
[1] | 109 | * |
---|
| 110 | * @param string $db_table database table to lookup |
---|
| 111 | * @param string $db_col database column to lookup |
---|
[295] | 112 | * @param bool $sort Sort the output. |
---|
[1] | 113 | */ |
---|
[295] | 114 | function printSetSelectForm($db_table, $db_col, $preselected, $blank=false, $sort=false) |
---|
[1] | 115 | { |
---|
[295] | 116 | $values = getSetEnumFieldValues($db_table, $db_col, $sort); |
---|
[1] | 117 | if ($values === false) { |
---|
[21] | 118 | ?><option value=""> </option> |
---|
[1] | 119 | <?php |
---|
| 120 | return false; |
---|
| 121 | } |
---|
| 122 | if (true === $blank) { |
---|
| 123 | $selected = ($preselected == '') ? ' selected' : ''; |
---|
| 124 | ?><option value=""<?php echo $selected; ?>> </option> |
---|
| 125 | <?php |
---|
| 126 | } |
---|
| 127 | // When the 'blank' value needs a specific key->val pair. |
---|
| 128 | if (is_array($blank)) { |
---|
| 129 | foreach ($blank as $key=>$val) { |
---|
| 130 | $selected = ($preselected == $val) ? ' selected="selected"' : ''; |
---|
[348] | 131 | ?><option value="<?php echo oTxt($key); ?>"<?php echo $selected; ?>><?php echo oTxt($val); ?></option> |
---|
[1] | 132 | <?php |
---|
| 133 | } |
---|
| 134 | } |
---|
[32] | 135 | foreach ($values as $v) { |
---|
| 136 | $selected = ($v == $preselected) ? ' selected' : ''; |
---|
[348] | 137 | ?><option value="<?php echo oTxt($v); ?>"<?php echo $selected; ?>><?php echo oTxt($v); ?></option> |
---|
[1] | 138 | <?php |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /** |
---|
[32] | 143 | * Prints radio buttons from a set/enum column. |
---|
| 144 | * |
---|
| 145 | * @param string $db_table database table to lookup |
---|
| 146 | * @param string $db_col database column to lookup |
---|
[295] | 147 | * @param bool $sort Sort the output. |
---|
[32] | 148 | */ |
---|
[295] | 149 | function printEnumRadios($name, $db_table, $db_col, $preselected, $blank=false, $sort=false) |
---|
[32] | 150 | { |
---|
[295] | 151 | $values = getSetEnumFieldValues($db_table, $db_col, $sort); |
---|
[32] | 152 | if ($values === false) { |
---|
| 153 | return false; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | foreach ($values as $v) { |
---|
[337] | 157 | $selected = ($v == $preselected) ? ' checked="checked"' : ''; |
---|
[349] | 158 | ?><label class="sc-label-secondary"><input type="radio" name="<?php echo oTxt($name) ?>" id="<?php echo oTxt($v); ?>" value="<?php echo oTxt($v); ?>"<?php echo $selected; ?> /> <?php echo oTxt($v); ?></label> |
---|
[32] | 159 | <?php |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | /** |
---|
[1] | 164 | * Prints checkbox fields. Works only with enum or set |
---|
[42] | 165 | * data types in table columns. |
---|
[1] | 166 | * |
---|
| 167 | * @param string $db_table database table to lookup |
---|
| 168 | * @param string $db_col database column to lookup |
---|
| 169 | * @param array $preselected array of preselected values (matching the values in $db_col) |
---|
| 170 | * @param int $columns number of table columns to print |
---|
[334] | 171 | * @param int $flag set to 'allone' for name of input fields to all be the same of a multidimensional array. |
---|
[295] | 172 | * @param bool $sort Sort the output. |
---|
[1] | 173 | */ |
---|
[295] | 174 | function printSetCheckboxes($db_table, $db_col, $preselected, $columns=1, $flag=null, $sort) |
---|
[42] | 175 | { |
---|
[1] | 176 | ?> |
---|
| 177 | <table> |
---|
| 178 | <tr> |
---|
| 179 | <?php |
---|
| 180 | // Sometimes preselected comes as a comma list. |
---|
| 181 | if (!is_array($preselected)) { |
---|
| 182 | $preselected = explode(',', $preselected); |
---|
| 183 | } |
---|
[42] | 184 | |
---|
[1] | 185 | // Checkbox POST data has the primary data in the keys, and 'on' as the values. |
---|
| 186 | // Here we assume in all the values of an array are 'on' that we can find the data |
---|
| 187 | // in the array keys. |
---|
| 188 | $ps_value_count = array_count_values($preselected); |
---|
[64] | 189 | if (isset($ps_value_count['on']) && $ps_value_count['on'] == sizeof($preselected)) { |
---|
[1] | 190 | $preselected = array_keys($preselected); |
---|
| 191 | } |
---|
[42] | 192 | |
---|
[334] | 193 | // Retrieve values of a Set or ENUM database column. |
---|
[295] | 194 | $values = getSetEnumFieldValues($db_table, $db_col, $sort); |
---|
[42] | 195 | |
---|
[1] | 196 | // Initialize the HTML table generation vars. |
---|
| 197 | $num_cells = sizeof($values) - 1; |
---|
| 198 | $num_rows = floor($num_cells / $columns); |
---|
| 199 | $cols_lastrow = $num_cells % $columns; |
---|
| 200 | $row_cnt = 0; |
---|
| 201 | $col_cnt = 0; |
---|
[32] | 202 | foreach ($values as $v) { |
---|
[1] | 203 | if ($col_cnt == $columns) { |
---|
| 204 | // Begin a new row. |
---|
| 205 | ?></tr><tr><?php |
---|
| 206 | $col_cnt = 0; |
---|
| 207 | $row_cnt++; |
---|
| 208 | } |
---|
| 209 | if ($col_cnt < $cols_lastrow) { |
---|
| 210 | $lastrow_add = $col_cnt; |
---|
| 211 | } else { |
---|
| 212 | $lastrow_add = $cols_lastrow; |
---|
| 213 | } |
---|
| 214 | $curr = $num_rows * $col_cnt + $lastrow_add + $row_cnt; |
---|
| 215 | $col_cnt++; |
---|
[42] | 216 | |
---|
[1] | 217 | // Look for preselected value. |
---|
[32] | 218 | if (in_array($v, $preselected)) { |
---|
[1] | 219 | $checked = ' checked="checked"'; |
---|
| 220 | } else { |
---|
| 221 | $checked = ''; |
---|
| 222 | } |
---|
| 223 | if ('allone' == $flag) { |
---|
[334] | 224 | // Print a cell with multidimensional array checkboxes. |
---|
[32] | 225 | $html_name = 'dbcol[' . $db_col . '][' . $v . ']'; |
---|
[28] | 226 | } else { |
---|
[1] | 227 | // Print a cell with basic named checkboxes. |
---|
[32] | 228 | $html_name = $db_col . '[' . $v . ']'; |
---|
[1] | 229 | } |
---|
[349] | 230 | ?><td><label class="sc-label-secondary"><input type="checkbox" name="<?php echo oTxt($html_name); ?>" id="<?php echo oTxt($html_name); ?>"<?php echo $checked; ?> /> <?php echo oTxt($v); ?></label></td> |
---|
[28] | 231 | <?php |
---|
[1] | 232 | } |
---|
| 233 | if ($col_cnt < $columns) { |
---|
| 234 | // This last cell must expand to fill the last blank cells. |
---|
| 235 | ?><td colspan="<?php echo $columns - $col_cnt; ?>"> </td><?php |
---|
| 236 | } |
---|
| 237 | ?> |
---|
| 238 | </tr> |
---|
| 239 | </table><?php |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | /** |
---|
| 243 | * Prints radio select fields. Works only with enum or set |
---|
[42] | 244 | * data types in table columns. |
---|
[1] | 245 | * |
---|
| 246 | * @param string $db_table database table to lookup |
---|
| 247 | * @param string $db_col database column to lookup |
---|
| 248 | * @param array $preselected array of preselected values (matching the values in $db_col) |
---|
| 249 | * @param int $columns number of table columns to print |
---|
[295] | 250 | * @param bool $sort Sort the output. |
---|
[1] | 251 | */ |
---|
[295] | 252 | function printSetRadios($db_table, $db_col, $preselected, $columns=1, $sort=false) |
---|
[42] | 253 | { |
---|
[1] | 254 | ?> |
---|
| 255 | <table> |
---|
| 256 | <tr> |
---|
| 257 | <?php |
---|
| 258 | // Sometimes preselected comes as a comma list. |
---|
| 259 | if (!is_array($preselected)) { |
---|
| 260 | $preselected = explode(',', $preselected); |
---|
| 261 | } |
---|
[42] | 262 | |
---|
[1] | 263 | // Checkbox POST data has the primary data in the keys, and 'on' as the values. |
---|
| 264 | // Here we assume in all the values of an array are 'on' that we can find the data |
---|
| 265 | // in the array keys. |
---|
| 266 | $ps_value_count = array_count_values($preselected); |
---|
[53] | 267 | if (isset($ps_value_count['on']) && $ps_value_count['on'] == sizeof($preselected)) { |
---|
[1] | 268 | $preselected = array_keys($preselected); |
---|
| 269 | } |
---|
[42] | 270 | |
---|
[334] | 271 | // Retrieve values of a Set or ENUM database column. |
---|
[295] | 272 | $values = getSetEnumFieldValues($db_table, $db_col, $sort); |
---|
[42] | 273 | |
---|
[1] | 274 | // Initialize the HTML table generation vars. |
---|
| 275 | $num_cells = sizeof($values) - 1; |
---|
| 276 | $num_rows = floor($num_cells / $columns); |
---|
| 277 | $cols_lastrow = $num_cells % $columns; |
---|
| 278 | $row_cnt = 0; |
---|
| 279 | $col_cnt = 0; |
---|
[32] | 280 | foreach ($values as $v) { |
---|
[1] | 281 | if ($col_cnt == $columns) { |
---|
| 282 | // Begin a new row. |
---|
| 283 | ?></tr><tr><?php |
---|
| 284 | $col_cnt = 0; |
---|
| 285 | $row_cnt++; |
---|
| 286 | } |
---|
| 287 | if ($col_cnt < $cols_lastrow) { |
---|
| 288 | $lastrow_add = $col_cnt; |
---|
| 289 | } else { |
---|
| 290 | $lastrow_add = $cols_lastrow; |
---|
| 291 | } |
---|
| 292 | $curr = $num_rows * $col_cnt + $lastrow_add + $row_cnt; |
---|
| 293 | $col_cnt++; |
---|
[42] | 294 | |
---|
[1] | 295 | // Look for preselected value. |
---|
[32] | 296 | if (in_array($v, $preselected)) { |
---|
[1] | 297 | $checked = ' checked="checked"'; |
---|
| 298 | } else { |
---|
| 299 | $checked = ''; |
---|
| 300 | } |
---|
| 301 | // Print a cell with basic named checkboxes. |
---|
[349] | 302 | ?><td><label class="sc-label-secondary"><input type="radio" name="<?php echo oTxt($db_col); ?>" id="<?php echo oTxt($db_col . '-' . $v); ?>" value="<?php echo oTxt($v); ?>"<?php echo $checked; ?> /> <?php echo oTxt($v); ?></label></td> |
---|
[1] | 303 | <?php |
---|
| 304 | } |
---|
| 305 | if ($col_cnt < $columns) { |
---|
| 306 | // This last cell must expand to fill the last blank cells. |
---|
| 307 | ?><td colspan="<?php echo $columns - $col_cnt; ?>"> </td><?php |
---|
| 308 | } |
---|
| 309 | ?> |
---|
| 310 | </tr> |
---|
| 311 | </table><?php |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | /** |
---|
[42] | 315 | * Prints a pulldown menu containing the specified values and keys of a table. |
---|
[1] | 316 | * |
---|
| 317 | * @param string $db_table database table to lookup |
---|
| 318 | * @param string $key_column column containing the human-readable titles for the select menu |
---|
| 319 | * @param string $val_column column containing the computer values for the select menu |
---|
| 320 | * @param string $preselected the currently selected value of the menu. compared to the $val_column |
---|
| 321 | * @param bool $blank leave one blank at the top? |
---|
[334] | 322 | * @param string $extra_clause SQL exclude clause. Something like "WHERE girls != 'buckteeth'" |
---|
[1] | 323 | */ |
---|
[324] | 324 | function printSelectForm($db_table, $key_column, $val_column, $preselected, $blank=false, $extra_clause='', $sql_format='SELECT %1$s, %2$s FROM %3$s %4$s') |
---|
[1] | 325 | { |
---|
[136] | 326 | $db =& DB::getInstance(); |
---|
| 327 | |
---|
[1] | 328 | // Sometimes preselected comes as a comma list. |
---|
| 329 | if (!is_array($preselected)) { |
---|
| 330 | $preselected = array($preselected); |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | // Print a blank first option. |
---|
| 334 | if (true === $blank) { |
---|
| 335 | $selected = in_array('', $preselected) ? ' selected="selected"' : ''; |
---|
| 336 | ?><option value=""<?php echo $selected; ?>> </option> |
---|
| 337 | <?php |
---|
| 338 | } |
---|
[42] | 339 | |
---|
[1] | 340 | // When the 'blank' value needs a specific key->val pair. |
---|
| 341 | if (is_array($blank)) { |
---|
| 342 | foreach ($blank as $key=>$val) { |
---|
[323] | 343 | $selected = in_array($key, $preselected) ? ' selected="selected"' : ''; |
---|
[1] | 344 | ?><option value="<?php echo $key; ?>"<?php echo $selected; ?>><?php echo oTxt($val); ?></option> |
---|
| 345 | <?php |
---|
| 346 | } |
---|
| 347 | } |
---|
[324] | 348 | // $qid = $db->query("SELECT $key_column, $val_column FROM $db_table $extra_clause",false); |
---|
| 349 | $qid = $db->query(sprintf($sql_format, $key_column, $val_column, $db_table, $extra_clause),false); |
---|
[1] | 350 | while ($row = mysql_fetch_assoc($qid)) { |
---|
| 351 | $selected = in_array($row[$val_column], $preselected) ? ' selected="selected"' : ''; |
---|
| 352 | ?><option value="<?php echo $row[$val_column]; ?>"<?php echo $selected; ?>><?php echo oTxt($row[$key_column]); ?></option><?php |
---|
| 353 | } |
---|
| 354 | } |
---|
| 355 | |
---|
| 356 | /** |
---|
| 357 | * Prints checkbox fields. Works only with enum or set |
---|
[42] | 358 | * data types in table columns. |
---|
[1] | 359 | * |
---|
| 360 | * @param string $db_table database table to lookup |
---|
| 361 | * @param string $key_column column containing the human-readable titles for the select menu |
---|
| 362 | * @param string $val_column column containing the computer values for the select menu |
---|
| 363 | * @param string $preselected the currently selected value of the menu. compared to the $val_column |
---|
| 364 | * @param int $columns number of table columns to print |
---|
| 365 | * @param int $extra_clause extra sql to send at end of select statement. |
---|
| 366 | * @param bool $vert_columns display checkboxes in vertical orientation first. |
---|
| 367 | */ |
---|
| 368 | function printDBCheckboxes($db_table, $key_column, $val_column, $preselected, $columns=1, $extra_clause='', $vert_columns=false) |
---|
| 369 | { |
---|
[136] | 370 | $db =& DB::getInstance(); |
---|
| 371 | |
---|
[1] | 372 | // Sometimes preselected comes as a comma list. |
---|
| 373 | if (!is_array($preselected)) { |
---|
| 374 | $preselected = explode(',', $preselected); |
---|
| 375 | } |
---|
[42] | 376 | |
---|
[1] | 377 | // Checkbox POST data has the primary data in the keys, and 'on' as the values. |
---|
| 378 | // Here we assume in all the values of an array are 'on' that we can find the data |
---|
| 379 | // in the array keys. |
---|
| 380 | $ps_value_count = array_count_values($preselected); |
---|
[253] | 381 | if (isset($ps_value_count['on']) && $ps_value_count['on'] == sizeof($preselected)) { |
---|
[1] | 382 | $preselected = array_keys($preselected); |
---|
| 383 | } |
---|
[42] | 384 | |
---|
[136] | 385 | $qid = $db->query("SELECT $key_column, $val_column FROM $db_table $extra_clause",false); |
---|
[1] | 386 | while ($row = mysql_fetch_assoc($qid)) { |
---|
| 387 | $values[] = $row; |
---|
| 388 | } |
---|
[42] | 389 | |
---|
[1] | 390 | // Rearrange array so sort is in vertical columns. FIXME: doesn't work. |
---|
| 391 | // if ($vert_columns) { |
---|
| 392 | // $per_col = ceil(sizeof($values) / $columns); |
---|
| 393 | // $columns = ceil(sizeof($values) / $per_col); |
---|
| 394 | // $curr_row = 0; |
---|
| 395 | // $curr_col = 0; |
---|
| 396 | // $pos = 0; |
---|
| 397 | // foreach ($values as $k=>$v) { |
---|
| 398 | // $pos = $curr_row * $columns + $curr_col; |
---|
| 399 | // if ($curr_row <= $per_col) { |
---|
| 400 | // $curr_row++; |
---|
| 401 | // } else { |
---|
| 402 | // $curr_row = 0; |
---|
| 403 | // $curr_col++; |
---|
| 404 | // } |
---|
| 405 | // // echo '<li>' . $pos . '-' . $v[$key_column]; |
---|
| 406 | // $new_values[$pos] = $v; |
---|
| 407 | // } |
---|
| 408 | // $values = $new_values; |
---|
| 409 | // ksort($values); |
---|
| 410 | // } |
---|
| 411 | |
---|
| 412 | if (empty($values)) { |
---|
| 413 | return false; |
---|
| 414 | } |
---|
[42] | 415 | |
---|
[1] | 416 | // Initialize the HTML table generation vars. |
---|
| 417 | $num_cells = sizeof($values) - 1; |
---|
| 418 | $num_rows = floor($num_cells / $columns); |
---|
| 419 | $cols_lastrow = $num_cells % $columns; |
---|
| 420 | $row_cnt = 0; |
---|
| 421 | $col_cnt = 0; |
---|
| 422 | ?> |
---|
[28] | 423 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
[1] | 424 | <tr> |
---|
| 425 | <?php |
---|
| 426 | foreach ($values as $box) { |
---|
| 427 | if ($col_cnt == $columns) { |
---|
| 428 | // Begin a new row. |
---|
| 429 | ?></tr><tr><?php |
---|
| 430 | $col_cnt = 0; |
---|
| 431 | $row_cnt++; |
---|
| 432 | } |
---|
[42] | 433 | |
---|
[1] | 434 | if ($col_cnt < $cols_lastrow) { |
---|
| 435 | $lastrow_add = $col_cnt; |
---|
| 436 | } else { |
---|
| 437 | $lastrow_add = $cols_lastrow; |
---|
| 438 | } |
---|
[42] | 439 | |
---|
[1] | 440 | $curr = $num_rows * $col_cnt + $lastrow_add + $row_cnt; |
---|
| 441 | $col_cnt++; |
---|
[42] | 442 | |
---|
[1] | 443 | // Look for preselected value. |
---|
| 444 | if (in_array($box[$val_column], $preselected)) { |
---|
| 445 | $checked = ' checked="checked"'; |
---|
| 446 | } else { |
---|
| 447 | $checked = ''; |
---|
| 448 | } |
---|
[42] | 449 | |
---|
[1] | 450 | // Print a cell with basic named checkboxes. |
---|
[28] | 451 | $html_name = $val_column . '[' . $box[$val_column] . ']'; |
---|
[254] | 452 | $html_id = $val_column . '-' . $box[$val_column] . ''; |
---|
[28] | 453 | ?> |
---|
[349] | 454 | <td><input type="checkbox" name="<?php echo oTxt($html_name); ?>" id="<?php echo oTxt($html_id); ?>"<?php echo $checked; ?> /></td> |
---|
| 455 | <td><label for="<?php echo oTxt($html_id); ?>" class="sc-normal"><?php echo oTxt($box[$key_column]); ?></label></td> |
---|
[254] | 456 | <?php |
---|
[1] | 457 | } |
---|
[42] | 458 | |
---|
[1] | 459 | if ($col_cnt < $columns) { |
---|
| 460 | // This last cell must expand to fill the last blank cells. |
---|
| 461 | ?><td colspan="<?php echo $columns - $col_cnt; ?>"> </td><?php |
---|
| 462 | } |
---|
| 463 | ?> |
---|
| 464 | </tr> |
---|
| 465 | </table><?php |
---|
| 466 | } |
---|
| 467 | |
---|
| 468 | /** |
---|
| 469 | * Prints submit buttons based on given array of submit button names and titles. |
---|
| 470 | * |
---|
| 471 | * @access public |
---|
| 472 | * @param array $submit_buttons Array of buttons, the key being the button name, and value being the title of the button. |
---|
| 473 | * @return void |
---|
| 474 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
| 475 | * @version 1.0 |
---|
| 476 | * @since 15 Jun 2005 13:42:21 |
---|
| 477 | */ |
---|
| 478 | function printSubmitButtons($submit_buttons) |
---|
| 479 | { |
---|
| 480 | if (is_array($submit_buttons) && !empty($submit_buttons)) { |
---|
[197] | 481 | foreach ($submit_buttons as $i => $b) { |
---|
| 482 | if (is_array($b)) { |
---|
[336] | 483 | $defaults = array(); |
---|
| 484 | $defaults['type'] = isset($b['type']) ? $b['type'] : 'submit'; |
---|
| 485 | $defaults['id'] = isset($b['id']) ? $b['id'] : sprintf('sc-%s-button', $b['name']); |
---|
| 486 | $b = array_merge($defaults, $b); |
---|
| 487 | echo '<input'; |
---|
| 488 | foreach ($b as $key => $value) { |
---|
| 489 | printf(' %s="%s"', $key, oTxt($value)); |
---|
| 490 | } |
---|
| 491 | echo ' />'; |
---|
[197] | 492 | } else { |
---|
[334] | 493 | // For backwards compatibility. |
---|
[197] | 494 | ?><input type="submit" name="<?php echo oTxt($i) ?>" value="<?php echo oTxt($b); ?>" /><?php |
---|
| 495 | } |
---|
[1] | 496 | } |
---|
| 497 | } |
---|
| 498 | } |
---|
| 499 | |
---|
[337] | 500 | ?> |
---|