* Copyright 2001-2010 Strangecode, LLC * * This file is part of The Strangecode Codebase. * * The Strangecode Codebase is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your option) * any later version. * * The Strangecode Codebase is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * The Strangecode Codebase. If not, see . */ /** * TemplateGlue.inc.php */ /** * Print URL to download file with BBEdit/Interarchy. "USER" must be a pre-set * environment variable. Files must reside within and be relative to env "DOCUMENT_ROOT". * * @access public * @param mixed $file File path relative to DOCUMENT_ROOT (i.e. '/_templates/index.ihtml'). * @return string with file basename as text. */ function bbftp($file) { return sprintf('%s', $_SERVER['USER'], $_SERVER['HTTP_HOST'], $_SERVER['DOCUMENT_ROOT'], $file, $file, basename($file)); } /** * Returns an image tag for image specified in $src. * * @param string $src File name of the image, including path and file extension. * @param string $alt Alt tag text. * @param string $extra Additional attributes. */ function oImg($src, $alt='', $extra='') { $filepath = preg_match('!://!', $src) ? $src : getenv('DOCUMENT_ROOT') . $src; if (true === ($gis = @getimagesize($filepath)) && !preg_match('/width|height/', $extra)) { $image_size = $gis[3]; } else { $image_size = ''; } return sprintf('%s', $src, $image_size, oTxt($alt), $extra ); } /** * Prints an image tag for image specified in $src. * * @param string $src File name of the image, including path and file extension. * @param string $alt Alt tag text. * @param string $extra Additional attributes. */ function printImg($src, $alt='', $extra='') { echo oImg($src, $alt, $extra); } /** * Finds the values of an enumeration or set column of a MySQL database, returning them in an array. * Use this to generate a pull-down menu of options or to validate the existence * of options. (Quinn 10 Feb 2001) * * @param string $db_table database table to lookup * @param string $db_col database column to lookup * @param bool $sort Sort the output. * @return array Array of the set/enum values on success, false on failure. */ function getSetEnumFieldValues($db_table, $db_col, $sort=false) { $app =& App::getInstance(); $db =& DB::getInstance(); $qid = $db->query("SHOW COLUMNS FROM " . $db->escapeString($db_table) . " LIKE '" . $db->escapeString($db_col) . "'",false); $row = mysql_fetch_row($qid); if (preg_match('/^enum|^set/i', $row[1]) && preg_match_all("/'([^']*)'/", $row[1], $enum)) { if ($sort) { natsort($enum[1]); } return $enum[1]; } else { $app->logMsg(sprintf('No set or enum fields found.', null), LOG_ERR, __FILE__, __LINE__); return false; } } /** * Prints option fields for a select form. Works only with enum or set * data types in table columns. * * @param string $db_table database table to lookup * @param string $db_col database column to lookup * @param bool $sort Sort the output. */ function printSetSelectForm($db_table, $db_col, $preselected, $blank=false, $sort=false) { $values = getSetEnumFieldValues($db_table, $db_col, $sort); if ($values === false) { ?> val pair. if (is_array($blank)) { foreach ($blank as $key=>$val) { $selected = ($preselected == $val) ? ' selected="selected"' : ''; ?>
 
 
val pair. if (is_array($blank)) { foreach ($blank as $key=>$val) { $selected = in_array($key, $preselected) ? ' selected="selected"' : ''; ?> query("SELECT $key_column, $val_column FROM $db_table $extra_clause",false); $qid = $db->query(sprintf($sql_format, $key_column, $val_column, $db_table, $extra_clause),false); while ($row = mysql_fetch_assoc($qid)) { $selected = in_array($row[$val_column], $preselected) ? ' selected="selected"' : ''; ?>query("SELECT $key_column, $val_column FROM $db_table $extra_clause",false); while ($row = mysql_fetch_assoc($qid)) { $values[] = $row; } // Rearrange array so sort is in vertical columns. FIXME: doesn't work. // if ($vert_columns) { // $per_col = ceil(sizeof($values) / $columns); // $columns = ceil(sizeof($values) / $per_col); // $curr_row = 0; // $curr_col = 0; // $pos = 0; // foreach ($values as $k=>$v) { // $pos = $curr_row * $columns + $curr_col; // if ($curr_row <= $per_col) { // $curr_row++; // } else { // $curr_row = 0; // $curr_col++; // } // // echo '
  • ' . $pos . '-' . $v[$key_column]; // $new_values[$pos] = $v; // } // $values = $new_values; // ksort($values); // } if (empty($values)) { return false; } // Initialize the HTML table generation vars. $num_cells = sizeof($values) - 1; $num_rows = floor($num_cells / $columns); $cols_lastrow = $num_cells % $columns; $row_cnt = 0; $col_cnt = 0; ?>
    />  
    * @version 1.0 * @since 15 Jun 2005 13:42:21 */ function printSubmitButtons($submit_buttons) { if (is_array($submit_buttons) && !empty($submit_buttons)) { foreach ($submit_buttons as $i => $b) { if (is_array($b)) { $defaults = array(); $defaults['type'] = isset($b['type']) ? $b['type'] : 'submit'; $defaults['id'] = isset($b['id']) ? $b['id'] : sprintf('sc-%s-button', $b['name']); $b = array_merge($defaults, $b); echo ' $value) { printf(' %s="%s"', $key, oTxt($value)); } echo ' />'; } else { // For backwards compatibility. ?>