function pbt_frontpage_options() { global $options; foreach ($options as $value) { switch (get_index($value, 'type')) { case "post-layout": ?> <div class="postbox"> <div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span><?php echo $value['name']; ?> </span><small> - <?php echo $value['desc']; ?> </small></h3> <div class="inside"> <table> <tr> <td style="padding-right: 15px;"> <img src="<?php echo THEME_URL; ?> /admin/images/option1.png" alt="Option 1" /> </td> <td style="padding-right: 15px;"> <img src="<?php echo THEME_URL; ?> /admin/images/option2.png" alt="Option 2" /> </td> <td style="padding-right: 15px;"> <img src="<?php echo THEME_URL; ?> /admin/images/option3.png" alt="Option 3" /> </td> <td style="padding-right: 15px;"> <img src="<?php echo THEME_URL; ?> /admin/images/option4.png" alt="Option 4" /> </td> </tr> <tr> <td align="center" style="padding-right: 15px;"> <input name="<?php echo $value['id']; ?> " type="radio" value="1"<?php if (theme_option($value['id']) == "1") { echo ' checked="checked"'; } ?> /> <label><?php _e('Option', "magazine-basic"); ?> 1</label> </td> <td align="center" style="padding-right: 15px;"> <input name="<?php echo $value['id']; ?> " type="radio" value="2"<?php if (theme_option($value['id']) == "2") { echo ' checked="checked"'; } ?> /> <label><?php _e('Option', "magazine-basic"); ?> 2</label> </td> <td align="center" style="padding-right: 15px;"> <input name="<?php echo $value['id']; ?> " type="radio" value="3"<?php if (theme_option($value['id']) == "3") { echo ' checked="checked"'; } ?> /> <label><?php _e('Option', "magazine-basic"); ?> 3</label> </td> <td align="center" style="padding-right: 15px;"> <input name="<?php echo $value['id']; ?> " type="radio" value="4"<?php if (theme_option($value['id']) == "4") { echo ' checked="checked"'; } ?> /> <label><?php _e('Option', "magazine-basic"); ?> 4</label> </td> </tr> </table> <br class="clear" /> </div> </div> <?php break; case "posts": textBox(2, $value['name'], $value['desc'], $value['id'], '', 2, 'center'); break; case "exorcon": radioBox(2, $value['name'], $value['desc'], $value['id'], array(__('Excerpt', "magazine-basic"), __('Content', "magazine-basic"))); break; case "excerpts": ?> <div class="postbox"> <div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span><?php echo $value['name']; ?> </span><small> - <?php echo $value['desc']; ?> </small></h3> <div class="inside"> <table class="rows"> <tr> <th><label><?php _e('Row', "magazine-basic"); ?> 1:</label></th> <th><label><?php _e('Row', "magazine-basic"); ?> 2:</label></th> <th><label><?php _e('Row', "magazine-basic"); ?> 3+:</label></th> </tr> <tr> <td><input name="excerpt_one" size="3" type="text" value="<?php echo theme_option('excerpt_one'); ?> " /></td> <td><input name="excerpt_two" size="3" type="text" value="<?php echo theme_option('excerpt_two'); ?> " /></td> <td><input name="excerpt_three" size="3" type="text" value="<?php echo theme_option('excerpt_three'); ?> " /></td> </tr> </table> <br class="clear" /> </div> </div> <?php break; case "latest": ?> <div class="postbox"> <div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span><?php echo $value['name']; ?> </span><small> - <?php echo $value['desc']; ?> </small></h3> <div class="inside"> <input name="<?php echo $value['id']; ?> " type="checkbox"<?php if (theme_option($value['id']) == "on") { echo ' checked="checked"'; } ?> /> <label><?php _e('Display "Latest Story"', "magazine-basic"); ?> </label> <br class="clear" /> </div> </div> <?php break; case "dates-index": ?> <div class="postbox"> <div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span><?php echo $value['name']; ?> </span><small> - <?php echo $value['desc']; ?> </small></h3> <div class="inside"> <input name="<?php echo $value['id']; ?> " type="checkbox" <?php if (theme_option($value['id']) == "on") { echo " checked=\"checked\""; } ?> /> <label><?php _e("Front Page", "magazine-basic"); ?> </label> <br class="clear" /> </div> </div> <?php break; case "authors-index": ?> <div class="postbox"> <div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span><?php echo $value['name']; ?> </span><small> - <?php echo $value['desc']; ?> </small></h3> <div class="inside"> <input name="<?php echo $value['id']; ?> " type="checkbox" <?php if (theme_option($value['id']) == "on") { echo " checked=\"checked\""; } ?> /> <label><?php _e("Front Page", "magazine-basic"); ?> </label> <br class="clear" /> </div> </div> <?php break; } } }
function buildFormFromTable($db, $table, $prevTable, $submitURL, $data = "", $extras = "", $fillDataFromID = 0, $from = "") { // // $formText = buildFormFromTable($db, $table, ...) // // Builds an html form for the specified table. The form will // include pull-downs for foreign table links. If anything fails, // $formText will comprise an informative message rather than // an actual table. You can include default values in 'd'. // // If d[id] is set, then this will be treated as an update rather // than an insert. The other values in d will over ride those from // the existing record, so be sure to unset those (or set them ="") // if you want to start with defaults from the db. // // if $fillDataFromID != 0, then it is sort of like an update- default // values will be pulled from the db from the specified id. Again, values // in d that are set and !="" will override those from the db, so be // sure to unset them if you want all defaults pulled from the db. // // Note that all the form fields are named "d[tableName][fieldName]". // Obviously, your function that processes the form data will need // to know this. // Eg: // // // Also, note that this function assumes that a new table form can be // displayed by submitting the form with "$table" set to the new table name. // $maxSelectLength = 30; // // GET FOREIGN TABLE LINKS // if (!($res = mysql_query('SELECT * FROM xLinks WHERE fromTable="' . $table . '"', $db))) { $formText = "MySQL error nr " . mysql_errno($db) . ": " . mysql_error($db); return $formText; } while ($row = mysql_fetch_array($res)) { $xlinks[$row['fromColumn']][-1] = "select from " . $row['toTable']; $xlinksTable[$row['fromColumn']] = $row['toTable']; // *** IS THERE A WAY TO SELECT JUST THE FIRST THREE COLUMNS? $res2 = mysql_query('SELECT * FROM ' . $row['toTable'], $db) or trigger_error("MySQL error nr " . mysql_errno($db) . ": " . mysql_error($db)); while ($row2 = mysql_fetch_row($res2)) { // This will be a 2d array- the 2nd dim is a hash with the item ID # as the key. if (strlen($row2[1]) > $maxSelectLength) { $row2[1] = substr($row2[1], 0, $maxSelectLength) . "..."; } $xlinks[$row['fromColumn']][$row2[0]] = "(" . $row2[0] . ") " . $row2[1]; // We decide if we should show the third field based on it's length. If it's too long, // then it's probably not worth showing, unless the second field is empty. if (mysql_field_len($res2, 2) < 100 | strlen($row2[1]) == 0) { if (strlen($row2[2]) > $maxSelectLength) { $row2[2] = substr($row2[2], 0, $maxSelectLength) . "..."; } $xlinks[$row['fromColumn']][$row2[0]] .= " " . $row2[2]; } } } $d = $data[$table]; unset($data[$table]); // If the fillDataFromID var is set to a real ID, then try to fill in the data from this entry. // This will be like an update except that we'll zero out the ID later so that it becomes a new entry. if (isset($fillDataFromID) && $fillDataFromID != 0) { $d['id'] = $fillDataFromID; } // If the 'id' field is set and non-zero, then this is an update form. // Get the old data for fill-in the defaults. if (isset($d['id']) && $d['id'] != 0) { if (!($res = mysql_query("SELECT * FROM {$table} WHERE id=" . $d['id'], $db))) { $formText = "MySQL error nr " . mysql_errno($db) . ": " . mysql_error($db); return $formText; } // We no longer overwrite defaults sent in via $data while ($row = mysql_fetch_array($res)) { foreach ($row as $field => $value) { if (!isset($d[$field]) || $d[$field] == "") { $d[$field] = $value; } } // end foreach } // end while // Zero the ID if we're cloning rather than updating if (isset($fillDataFromID) && $fillDataFromID != 0) { $d['id'] = 0; } } // end if // // BUILD HTML FORM // if (!($res = mysql_query("SHOW FIELDS FROM {$table}", $db))) { $formText = "MySQL error nr " . mysql_errno($db) . ": " . mysql_error($db); return $formText; } $formText = ""; if ($d['id'] != 0) { $pos = strpos($submitURL, '?'); if ($pos === false) { $formTopText = "<form method=POST name=\"" . $table . "_form\" action=\"{$submitURL}?updateId2=" . $d['id'] . "\">\n"; } else { $formTopText = "<form method=POST name=\"" . $table . "_form\" action=\"{$submitURL}&updateId2=" . $d['id'] . "\">\n"; } } else { $formTopText = "<form method=POST name=\"" . $table . "_form\" action=\"{$submitURL}\">\n"; } //$formTopText = "<form method=POST name=\"".$table."_form\" action=\"http://snarp.stanford.edu/info.php\">\n"; $formTopText .= "<table border=0 cellspacing=2 cellpadding=2>\n"; $formTopText .= "<input type=hidden name=\"table\" value=\"{$table}\">\n"; if (is_array($extras)) { foreach ($extras as $name => $value) { $formTopText .= "<input type=hidden name=\"{$name}\" value=\"{$value}\">\n"; } } if (is_array($data)) { foreach ($data as $otherTableName => $otherTableArray) { foreach ($otherTableArray as $name => $value) { $formTopText .= "<input type=hidden name=\"d[{$otherTableName}][{$name}]\" value=\"{$value}\">\n"; } } } if (isset($prevTable) && is_array($prevTable)) { foreach ($prevTable as $key => $val) { $formTopText .= "<input type=hidden name=prevTable[{$key}] value=\"{$val}\">\n"; } array_push($prevTable, $table); } else { $prevTable = array($table); } while ($row = mysql_fetch_array($res)) { $name = $row['Field']; //mysql_field_name($fields, $i); $typeStr = $row['Type']; //mysql_field_type($fields, $i); if ($name == 'id') { if ($d[$name] != 0) { $formTopText .= textField("Updating row " . $name . ":", "d[{$table}][{$name}]", $d[$name], 6, 0); // Since it will be disabled, we can't count on it being submitted with // the form. So, we add a hidden field. $formTopText .= "<input type=hidden name=\"d[{$table}][{$name}]\" value=\"{$d[$name]}\">\n"; } //else $formTopText .= textField($name.":", "junk", "<auto>", 6, 0); } elseif ($typeStr == 'date') { if (!isset($d[$name])) { $d[$name] = date("Y-m-d"); } $formText .= textField(translateField($db, $table, $name) . " (YYYY-MM-DD):", "d[{$table}][{$name}]", $d[$name], 10); } elseif ($typeStr == 'datetime') { // if(!isset($d[$name])) $d[$name] = date("Y-m-d H:00:00"); if ($name == 'end') { $d[$name] = date("Y-m-d H:59:00"); } else { $d[$name] = date("Y-m-d H:00:00"); } $formText .= textField($name . " (YYYY-MM-DD HH:MM:SS):", "d[{$table}][{$name}]", $d[$name], 19); } elseif ($typeStr == 'text') { $formText .= textBox($name . ":", "d[{$table}][{$name}]", $d[$name], 10); } elseif (strncasecmp($typeStr, 'enum', 4) == 0) { $vals = explode("','", "'," . substr($typeStr, 5, -1) . ",'"); $vals = array_slice($vals, 1, -1); $formText .= radioField($name . ":", "d[{$table}][{$name}]", $vals, $d[$name]); } elseif ($name == 'password') { $formText .= pwdField($name . ":", "d[{$table}][{$name}]", $d[$name], 16); } else { if (isset($xlinks[$name])) { if (!isset($d[$name]) || $d[$name] == '') { $d[$name] = -1; } $newLink = ""; foreach ($prevTable as $key => $val) { $newLink .= "&prevTable[{$key}]={$val}"; } // We put these at the beginning of formText so that all the pull-downs // appear at the top of the page. $formTopText .= selectField(translateField($db, $table, $name) . ":", "d[{$table}][{$name}]", $xlinks[$name], $d[$name], " <input type=submit name=\"" . $xlinksTable[$name] . "\" value=New>"); } else { list($type, $size, $extra) = preg_split('(\\(|\\))', $typeStr); if ($size > 40) { $formText .= textBox(translateField($db, $table, $name) . ":", "d[{$table}][{$name}]", $d[$name], round($size / 40)); } else { $formText .= textField(translateField($db, $table, $name) . ":", "d[{$table}][{$name}]", $d[$name], $size); } } } } $formText .= "</table><br><br>\n"; $formText .= "      <input type=submit name=\"{$table}\" value=Submit>\n"; $formText .= "      <input type=submit name=cancel value=Cancel>\n"; if ($from == "buildSession3") { $formText .= "      <input type=submit name=index value='Back to Main Index'>\n"; } $formText .= "</form>\n"; return $formTopText . $formText; }
function pbt_layout_options() { global $feed_me_seymour_options; foreach ($feed_me_seymour_options as $value) { switch (get_index($value, 'type')) { case "site": radioBox(2, $value['name'], $value['desc'], $value['id'], array(__('800px', "feed-me-seymour"), __('1024px', "feed-me-seymour")), array(800, 1024)); break; case "posts": textBox(2, $value['name'], $value['desc'], $value['id'], '', 2, 'center'); break; } } }