diff --git a/lib/feature.inc b/lib/feature.inc index 6a7dc5d..ad515ca 100644 --- a/lib/feature.inc +++ b/lib/feature.inc @@ -26,7 +26,7 @@ */ have ("feature"); - function featureOpen ($title, $url, $id) + function featureOpen ($title, $url=null, $id=null) { if ($url) { $part1 = ''; @@ -35,7 +35,7 @@ if ($id) $id = " id=\"$id\""; - echo ''; + echo ""; echo '

' . $part1 . $title . $part2 . '

'; echo '
'; } diff --git a/lib/news.inc b/lib/news.inc index 5806de3..7565805 100644 --- a/lib/news.inc +++ b/lib/news.inc @@ -66,7 +66,7 @@ function printNewsArray ($a) } -function latestNews ($max) +function latestNews ($max=5) { need ('sql'); @@ -77,7 +77,7 @@ function latestNews ($max) } -function printLatestNews ($max) +function printLatestNews ($max=5) { $filler = date ('d M Y'); $entries = latestNews ($max); diff --git a/lib/plan.inc b/lib/plan.inc new file mode 100644 index 0000000..3ce6716 --- /dev/null +++ b/lib/plan.inc @@ -0,0 +1,144 @@ + + Copyright (C) 2000 Daniel David Olson + + This program 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 2 + of the License, or (at your option) any later version. + + This program 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 this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA. +*/ + +have ('plan'); + // SQL definition for news table +$createQuery="CREATE TABLE plans (" + ." p_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT," + ." p_date TIMESTAMP NOT NULL DEFAULT NOW()," + ." p_user TINYTEXT NOT NULL," + ." p_title TINYTEXT NOT NULL," + ." p_plan TEXT NOT NULL" + .")"; + +function formatPlan ($date, $user, $subj, $text) +{ + return "
\n" + .'
' + . "Posted on $date by $user" + . "
\n" + ."

$subj

\n" + ." $text
\n" + ."
\n"; +} + + +function formatPlanArray ($a) +{ + need ('date'); + + return formatPlan (dateFromSQLDateTime ($a['p_date']), $a['p_user'], stripSlashes ($a['p_title']), stripSlashes ($a['p_plan'])); +} + + +function printPlan ($date, $user, $subj, $text) +{ + echo formatPlan ($date, $user, $subj, $text); +} + + +function printPlanArray ($a) +{ + echo formatPlanArray ($a); +} + + +function latestPlans ($user = null, $max = 5) +{ + need ('sql'); + + if ($user) { + $query = 'SELECT p_date, p_user, p_title, p_plan FROM plans' + ." WHERE p_user = " + ." (SELECT u_displayname FROM members WHERE u_username='$user')" + ." ORDER BY p_date DESC LIMIT $max"; + } else { + $query = 'SELECT p_date, p_user, p_title, p_plan FROM plans, members' + ." WHERE p_user = u_displayname" + ." ORDER BY p_date DESC LIMIT $max"; + } + + return sqlReadQuery ($query); +} + + +function printLatestPlans ($user = null, $max = 5) +{ + $filler = date ('d M Y'); + $entries = latestPlans ($user, $max); + + if ($entries === true) { // success, but no data + printPlan ($filler, 'Web Server', 'Sorry', 'Nobody has posted news yet, so I got nothing to say right now.'); + } elseif ($entries === false) { // bad query + printPlan ($filler, 'Web Server', 'Sorry', 'Got an error while finding news. Bug a project administrator, eh?'); + } elseif ($entries === null) { // boom + printPlan ($filler, 'Web Server', 'Sorry', 'Couldn\'t connect to the project news server...Sorry.'); + } else foreach ($entries as $entry) { + printPlanArray ($entry); + } +} + + +function searchPlans ($string, $user = null) +{ + need ('sql'); + + if ($user) + $where = " AND p_user='$user' "; + + $filler = date ('d M Y'); + $search = addSlashes ("%$string%"); + $query = 'SELECT p_date, p_user, p_title, p_plan FROM plans' + ." WHERE p_plan LIKE '$search'" + . $where + .' ORDER BY n_date DESC'; + + $entries = sqlReadQuery ($query); + if ($entries === true) { // success, but no data + printPlan ($filler, 'Web Server', 'Sorry', "No plan entries found matching '$string'"); + } elseif ($entries === false) { // bad query + printPlan ($filler, 'Web Server', 'Sorry', 'Got an error while finding news. Bug a project administrator, eh?'); + } elseif ($entries === null) { // boom + printPlan ($filler, 'Web Server', 'Sorry', 'Couldn\'t connect to the project plan server.'); + } else foreach ($entries as $entry) { + printPlanArray ($entry); + } +} + + +function usersWithPlans () +{ + need ('sql'); + + $query = 'SELECT u_username, u_displayname FROM members,plans' + .' WHERE u_displayname=p_user' + .' ORDER BY u_displayname'; + + return sqlReadQuery ($query); +} +?> \ No newline at end of file diff --git a/parts/plan_search.inc b/parts/plan_search.inc new file mode 100644 index 0000000..859aa93 --- /dev/null +++ b/parts/plan_search.inc @@ -0,0 +1,21 @@ +
' . $displayName . '

'; + } + } else { + echo '

Sorry, no users have posted Plan entries at this time.

'; + } + featureClose (); + } + + planUsers (); +?> \ No newline at end of file diff --git a/plan.php b/plan.php new file mode 100644 index 0000000..80d43e0 --- /dev/null +++ b/plan.php @@ -0,0 +1,37 @@ + 1) { + $user = substr ($user, 1); // strip off the starting slash + if (($pos = strpos ($user, '/')) !== false) { // and all others + $user = substr ($user, 0, $pos); + } + + if (is_array ($plans = latestPlans ($user, 5))) { + newsBoxOpen ("Latest Plans for " . $plans[0]['p_user']); + foreach ($plans as $plan) { + printPlanArray ($plan); + } + newsBoxClose (); + } else { + newsBoxOpen ("Latest Plans for " . $user); + printPlan ("Now", "Web Server", "Sorry", "

I don't know any user named "$user".

"); + newsBoxClose (); + } + } else { + if (is_array ($plans = latestPlans (null, 5))) { + newsBoxOpen ("Latest Plans for All Users"); + foreach ($plans as $plan) { + printPlanArray ($plan); + } + newsBoxClose (); + } + } +?> diff --git a/plans.php b/plans.php deleted file mode 100644 index c079bb0..0000000 --- a/plans.php +++ /dev/null @@ -1,17 +0,0 @@ - - - - - -