# %" output double quotes, surrounding the variable which is encoded to be in there.
# %s output encoded to be in double quotes, but don't output the quotes
#
-# complex example: db_get_rows('mytable', 'id', 'name=%" or company like "%%%s%%"', $name, $company_partial);
+# complex example: db_get_rows('mytable', 'id', 'where name=%" or company like "%%%s%%"', $name, $company_partial);
function db_printf($str) {
$args = func_get_args();
$args = array_slice($args, 1);
- _db_printf($str, $args);
+ return _db_printf($str, $args);
}
# This function does the work, but takes the parameters in an array
function db_send_get($table, $columns, $where, $args) {
$sql = "SELECT $columns FROM $table";
if($where) {
- $sql .= ' WHERE ' . _db_printf($where, $args);
+ $sql .= ' ' . _db_printf($where, $args);
}
return db_send_query($sql);
# db_update('users', 'name', 'Bruce');
#
# # name user #6 Bruce
-# db_update('users', 'name', 'Bruce', 'id= %"', 6);
+# db_update('users', 'name', 'Bruce', 'where id=%i', 6);
#
# # update the whole bit for user #6
-# db_update('users', 'name,email,description', 'Bruce', 'bruce@example.com', 'is a cool guy', 'id= %"', 6);
+# db_update('users', 'name,email,description', 'Bruce', 'bruce@example.com', 'is a cool guy', 'where id=%i', 6);
#
# # update the whole bit for user #6 (passing data as an array)
# $data = array('Bruce', 'bruce@example.com', 'is a cool guy');
-# db_update('users', 'name,email,description', $data, 'id= %"', 6);
+# db_update('users', 'name,email,description', $data, 'where id=%i', 6);
# The prototype is really something like this:
-# db_update(table, columns, values..., where(optional), where_args...(optional
+# db_update(table, columns, values..., where(optional), where_args...(optional))
function db_update($table, $columns, $values) {
$args = func_get_args();
$args = array_slice($args, 2);
$where = $args[0];
$args = array_slice($args, 1);
- $sql .= ' WHERE ';
+ $sql .= ' ';
# any left for where claus arguments?
if($args) {
$sql .= _db_printf($where, $args);
function db_delete($table, $where = '') {
$sql = "DELETE FROM $table";
if($where) {
- $sql .= ' WHERE ';
+ $sql .= ' ';
$args = func_get_args();
$args = array_slice($args, 2);
if($args) {
}
function redirect($url, $status = '302 Moved Temporarily', $message = '') {
- header("HTTP/1.1 $status");
+ header("HTTP/1.0 $status");
header("Location: $url");
echo($message);
exit();
--- /dev/null
+<?php
+
+# Copyright (C) 2007 Jason Woofenden
+#
+# This file is part of wfpl.
+#
+# wfpl is free software; you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# wfpl 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 Lesser General Public License for
+# more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with wfpl; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+
+# This file is useful for putting message boxe(s) on the screen.
+#
+# Just call message("message here") whenever you have something to report.
+#
+# Once a template is loaded, call display_messages(). Your template should have
+# a <!--~message_box start~--> section with ~message_text.html~ tag in it.
+#
+# If you want a divider (any text between message boxes when there are multiple
+# boxes) provide a sub-template section named "message_divider" INSIDE
+# "message_box" at the begining of it.
+#
+# If you'd like something around the group of all message boxes, you can put
+# the whole thing in a sub-template section called "message_container"
+
+# Simple example:
+#
+# <!--~message_box start~-->
+# <p>~message_text.html~</p>
+# <!--~end~-->
+
+# Full-featured example:
+#
+# <!--~message_container start~-->
+# <div style="border: 2px solid red; background: #800; padding: 15px">
+# <!--~message_box start~-->
+# <!--~message_divider start~-->
+# <hr />
+# <!--~end~-->
+# <p>~message_text.html~</p>
+# <!--~end~-->
+# </div>
+# <!--~end~-->
+
+require_once('code/wfpl/template.php');
+
+function message($msg) {
+ if(!isset($GLOBALS['wfpl_messages'])) {
+ $GLOBALS['wfpl_messages'] = array();
+ }
+
+ $GLOBALS['wfpl_messages'][] = $msg;
+}
+
+# if you want the messages in a template other than the default one, pass it like so:
+#
+# display_messages(ref($my_template));
+function display_messages($template = 0) {
+ $first = true;
+ if($template === 0) {
+ $template = &$GLOBALS['wfpl_template'];
+ } else {
+ $template = &$template->ref;
+ }
+
+ if($GLOBALS['wfpl_messages']) {
+ foreach($GLOBALS['wfpl_messages'] as $msg) {
+ if($first) {
+ $first = false;
+ } else {
+ $template->sub('message_divider');
+ }
+ $template->set('message_text', $msg);
+ $template->sub('message_box');
+ }
+ $template->sub('message_container');
+ }
+}
+
+?>
list(~php_fields~) = db_get_row('~form_name~', '~db_fields~', 'id = %"', $edit_id);
~tem_sets.tab~
} else {
- # form not submitted, you can set default values like so
+ # form not submitted, you can set default values like so:
#tem_set('~always_field~', 'Yes');
}<!--~upload_max start~-->
# RewriteEngine on
# RewriteRule ^$ /foo/run.php
-# RewriteRule ^/foo/[^/]*\.html$ /foo/run.php
+# RewriteRule ^foo/[^/]*\.html$ /foo/run.php
require_once('code/wfpl/file_run.php');
+require_once('code/wfpl/http.php');
function run_php($basename = false) {
if($basename) {
}
if($php_file != $html_file && file_exists($php_file)) {
require_once('code/wfpl/template.php');
- if(file_exists($html_file)) tem_load($html_file);
+ if(file_exists($html_file)) {
+ $GLOBALS['wfpl_template'] = new tem();
+ tem_load($html_file);
+ }
$other = file_run($php_file);
if($other) {
+ if(strpos($other, ':')) {
+ redirect($other);
+ exit();
+ }
run_php($other);
return;
}
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# you'll need this file that calles db_connect()
-require_once('db_connect.php');
+if(!isset($GLOBALS['wfpl_db_handle'])) {
+ require_once('db_connect.php');
+}
# and these database tables:
-# create table sessions (id int unique auto_increment, session_key varchar(16), length int, expires int);
-# create table session_data (id int unique auto_increment, session_id int, name varchar(100), value text);
+# create table wfpl_sessions (id int unique auto_increment, session_key varchar(16), length int, expires int);
+# create table wfpl_session_data (id int unique auto_increment, session_id int, name varchar(100), value text);
# GLOSSARY
#
function session_new($length = 86400) {
$session_key = session_generate_key();
- db_insert('sessions', 'session_key,length', $session_key, $length);
+ db_insert('wfpl_sessions', 'session_key,length', $session_key, $length);
$GLOBALS['session_id'] = db_auto_id();
$GLOBALS['session_key'] = $session_key;
$_REQUEST['session_key'] = $session_key; #just in case someone calls session_exists() after session_new()
# assumes there's a session. call session_init() if you'd like one auto-create one if not found.
function session_touch($length = false) {
if(!$length) {
- $length = db_get_value('sessions', 'length', 'id = %i', $GLOBALS['session_id']);
+ $length = db_get_value('wfpl_sessions', 'length', 'where id=%i', $GLOBALS['session_id']);
}
$expires = time() + $length;
header('Set-Cookie: session_key=' . $GLOBALS['session_key']);
- db_update('sessions', 'expires', $expires, 'id = %i', $GLOBALS['session_id']);
+ db_update('wfpl_sessions', 'expires', $expires, 'where id=%i', $GLOBALS['session_id']);
}
# delete expired sessions from database
function session_purge_old() {
$now = time();
- $exired_sessions = db_get_column('sessions', 'id', 'expires < %i', $now);
- db_delete('sessions', 'expires < %i', $now);
+ $exired_sessions = db_get_column('wfpl_sessions', 'id', 'where expires < %i', $now);
+ db_delete('wfpl_sessions', 'where expires < %i', $now);
if($expired_sessions) {
foreach($expired_sessions as $expired_session) {
- db_delete('session_data', 'session_id=%i', $expired_session);
+ db_delete('wfpl_session_data', 'where session_id=%i', $expired_session);
}
}
}
$GLOBALS['session_key'] = $session_key;
session_purge_old();
- $id = db_get_value('sessions', 'id', 'session_key = %"', $session_key);
+ $id = db_get_value('wfpl_sessions', 'id', 'where session_key=%"', $session_key);
if($id === false) {
return false;
}
# save a variable into the session
function session_set($name, $value) {
- db_replace('session_data', 'name,value', $name, $value);
+ db_replace('wfpl_session_data', 'name,value', $name, $value);
}
# get a variable into the session
function session_get($name) {
- return db_get_value('session_data', 'value', 'name=%"', $name);
+ return db_get_value('wfpl_session_data', 'value', 'where name=%"', $name);
}
?>