From 1bcde3c6ba88a93deaa0848df4de0b0857d9bf49 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Wed, 12 Nov 2008 22:04:04 -0500 Subject: [PATCH] added real logins, login administration, task viewer page, contractor main page --- .gitignore | 6 ++ code/config.php | 18 ++++++ code/tasks.php | 6 +- index.html | 4 +- index.php | 38 ++++++++---- login.php | 22 ++++--- logout.php | 8 +++ narrative_example.html | 21 +++++++ people.html | 63 ++++++++++++++++++++ people.php | 155 ++++++++++++++++++++++++++++++++++++++++++++++++ tasks.html | 32 +++++++--- tasks.php | 76 ++++++++++++++++++++---- template.html | 1 + 13 files changed, 408 insertions(+), 42 deletions(-) create mode 100644 .gitignore create mode 100644 logout.php create mode 100644 narrative_example.html create mode 100644 people.html create mode 100644 people.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a6417db --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +code/wfpl +images +*.tgz +run.php +style*.css +w diff --git a/code/config.php b/code/config.php index 4232c67..60d5c1f 100644 --- a/code/config.php +++ b/code/config.php @@ -2,3 +2,21 @@ require_once('code/db_connect.php'); require_once('code/wfpl/session_messages.php'); + +function cms_get() { + if(logged_in()) { + return array('logout_bar' => '
Log out
'); + } + return false; +} + +function logged_in_as_admin() { + if(!isset($GLOBALS['logged_in_as_admin'])) { + $GLOBALS['logged_in_as_admin'] = (logged_in() == 1); # logged_in() returns id. id #1 is admin + } + return $GLOBALS['logged_in_as_admin']; +} + +function logged_in_as_contractor() { + return logged_in_as_admin(); +} diff --git a/code/tasks.php b/code/tasks.php index 2b05771..b985661 100644 --- a/code/tasks.php +++ b/code/tasks.php @@ -42,15 +42,15 @@ function task_state_pretty($state) { case TASK_NEEDS_CLARIFICATION: return "needs clarification"; case TASK_NEEDS_QUOTE: - return "waiting for price from Jason"; + return "to be priced"; case TASK_NEEDS_GO_AHEAD: - return "waiting for you to approve price"; + return "waiting for you to approve the price"; case TASK_QUEUED: return "queued"; case TASK_WORKING: return "work in progress"; case TASK_BUG: - return "investigation in progress"; + return "to be investigated"; case TASK_NEEDS_TESTING: return "needs testing"; case TASK_FINISHED: diff --git a/index.html b/index.html index 6b1ddf4..fd63432 100644 --- a/index.html +++ b/index.html @@ -9,9 +9,9 @@ -

Progress

+

Progress Manager

-

This page is for commissioning Jason Woofenden, working out the details of what is to be done and the cost, and managing schedules and priorities.

+

This page is for commissioning Jason Woofenden, working out the details of the tasks, costs and priorities.

Commission a new feature/updateReport a problem

diff --git a/index.php b/index.php index 121f099..d87d74f 100644 --- a/index.php +++ b/index.php @@ -8,7 +8,7 @@ function enc_money($float) { function index_main() { if(!logged_in()) { - return './login'; + return 'login'; } $ret = _index_main(); if($ret) { @@ -17,16 +17,25 @@ function index_main() { tem_show('main_body'); } -function task_summary($tem_prefix, $where_clause) { - $rows = db_get_rows('tasks', 'id,price,title,state', $where_clause); +# pass multiple argumens for where-clause and printf-args just like db_get_rows() +function task_summary($tem_prefix, $where_clause/*, ... */) { + $args = func_get_args(); + $args = array_slice($args, 1); + array_unshift($args, 'tasks', 'id,price,title,state,client_id'); + print_r($args); + $rows = call_user_func_array('db_get_rows', $args); + #$rows = db_get_rows('tasks', 'id,price,title,state,client_id', $where_clause); if($rows) { $total = 0.0; foreach($rows as $row) { - list($id, $price, $title, $state) = $row; + list($id, $price, $title, $state, $client_id) = $row; tem_set('task_id', $id); tem_set('task_title', $title); tem_set('task_price', $price); tem_set('task_state', task_state_pretty($state)); + if(logged_in_as_contractor()) { + tem_set('client', db_get_value('people', 'name', 'where id=%i', $client_id)); + } tem_show($tem_prefix . '_row'); $total += $price; } @@ -38,12 +47,19 @@ function task_summary($tem_prefix, $where_clause) { } function _index_main() { - task_summary('needs_attention', 'where state=' . TASK_DRAFT . ' || state=' . TASK_NEEDS_CLARIFICATION . ' || state=' . TASK_NEEDS_GO_AHEAD . ' || state=' . TASK_NEEDS_TESTING . ' order by id'); - task_summary('queue', 'where state=' . TASK_QUEUED . ' order by ord'); - task_summary('jason', 'where state=' . TASK_NEEDS_QUOTE . ' || state=' . TASK_WORKING . ' || state=' . TASK_BUG . ' order by id desc'); - #task_summary('jason_pricing', 'where state=' . TASK_NEEDS_QUOTE . ' order by id desc'); - #task_summary('jason_working', 'where state=' . TASK_WORKING . ' order by id desc'); - task_summary('finished_unpaid', 'where state=' . TASK_FINISHED . ' && paid = 0 order by id desc'); - task_summary('finished_paid', 'where state=' . TASK_FINISHED . ' && paid = 1 order by id desc'); + $client_id = logged_in(); + if(logged_in_as_contractor()) { + task_summary('needs_attention', 'where state=%i || state=%i || state=%i order by id desc', TASK_NEEDS_QUOTE, TASK_WORKING, TASK_BUG); + task_summary('finished_unpaid', 'where state=%i && paid = 0 order by id desc', TASK_FINISHED); + task_summary('finished_paid', 'where state=%i && paid = 1 order by id desc', TASK_FINISHED); + } else { + task_summary('needs_attention', 'where state=' . TASK_DRAFT . ' || state=' . TASK_NEEDS_CLARIFICATION . ' || state=' . TASK_NEEDS_GO_AHEAD . ' || state=' . TASK_NEEDS_TESTING . ' order by id'); + task_summary('queue', 'where state=' . TASK_QUEUED . " && client_id=$client_id order by ord"); + task_summary('jason', 'where state=' . TASK_NEEDS_QUOTE . ' || state=' . TASK_WORKING . ' || state=' . TASK_BUG . ' order by id desc'); + #task_summary('jason_pricing', 'where state=' . TASK_NEEDS_QUOTE . ' order by id desc'); + #task_summary('jason_working', 'where state=' . TASK_WORKING . ' order by id desc'); + task_summary('finished_unpaid', 'where state=' . TASK_FINISHED . ' && paid = 0 order by id desc'); + task_summary('finished_paid', 'where state=' . TASK_FINISHED . ' && paid = 1 order by id desc'); + } return; } diff --git a/login.php b/login.php index 0d77fa2..5dcaa64 100644 --- a/login.php +++ b/login.php @@ -21,14 +21,20 @@ function login_main() { if(isset($_REQUEST['username'])) { list($username, $password, $url) = login_get_fields(); - if($username == 'test' && $password == 'test') { - message("Logged in successfully."); - session_new(); - session_set('auth_username', "admin:$id"); - if($url) { - return $url; - } else { - return './'; + $row = db_get_row('people', 'id,password', 'where username=%"', $username); + + if($row) { + list($id, $password_hash) = $row; + + if($password_hash && check_password($password_hash, $password)) { + message("Logged in successfully."); + session_new(); + session_set('auth_username', "$id"); + if($url) { + return $url; + } else { + return './'; + } } } diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..45d4876 --- /dev/null +++ b/logout.php @@ -0,0 +1,8 @@ + + + + + + + + + +

Narrative Example

+ +

When you commission Jason Woofenden you are asked to write about your change/addition in the form of a first-person narrative. In this narrative you write as if the change/addition you would like has already been implemented. You write the specifics of what you do and what you see as a result.

+

Here is an example of a narrative for a new page:

+ +

I go to my home page, (or any other page on my site) and I click a link labeled "Contact Us" which is just below the "About Us" link on the left. Then I see a page with a headline "Contact Us" and a form with these fields: "Name", "E-mail", "Comments" and a button "Send". When I click "Send", all information entered is e-mailed to foo@example.com and I see a page with the headline "Thank You" and this paragraph: "Thank you for your interest. We can usually reply within one business day."

+ +

After Jason makes the changes, you can verify that they are complete by following the steps in the narrative and making sure you can see everything it describes.

+ + + diff --git a/people.html b/people.html new file mode 100644 index 0000000..abcb0e8 --- /dev/null +++ b/people.html @@ -0,0 +1,63 @@ + + + + + people entry + + + + + + + +
+ + +
+ +

~message_text.html~

+ +
+ + + +

Add a new entryEdit entry "~username.html~"

+ +
+ + + + + + + + + + + + + +
Username:
Password:
Name:
Privs:
Balance:
+
+ + +

people Listing

+ + +

[Add a new record]

+ + + + +
~username.html~[delete this record]
+ + +

No ~field_plural.html~ in database.

+ + +

[Add a new record]

+ + + + + diff --git a/people.php b/people.php new file mode 100644 index 0000000..1690a4b --- /dev/null +++ b/people.php @@ -0,0 +1,155 @@ + diff --git a/tasks.html b/tasks.html index 829132c..efc99c4 100644 --- a/tasks.html +++ b/tasks.html @@ -9,17 +9,34 @@ - -

Add a new taskEdit task #~tasks_edit_id~ "~title.html~"

+ +

Task #~task_id~Problem Report "~title.html~"

+ +

Title: ~title.html~

+ +

Status: ~state.html~

+ +

URL: ~url.html~

+ +

Narrative:
+ ~description.htmlbrtab~

+ +

Back

+ + + +

Report a problemAdd a new taskEdit task #~tasks_edit_id~ "~title.html~"

- + + + - - + + @@ -29,12 +46,11 @@
Title:
Title:
URL:
Url:
Description:
Below, write as if the change/addition you would like has already been implemented. Write a first-person narrative with the specifics of what you do and what you see as a result. See an example.Below, describe in detail 1) what you do, 2) what you expect to see, 3) what you see instead
- - -

Thank you for taking the time to fill out this form.

+

Cancel

+ diff --git a/tasks.php b/tasks.php index e923b21..6351ca6 100644 --- a/tasks.php +++ b/tasks.php @@ -13,6 +13,18 @@ require_once('code/wfpl/messages.php'); require_once('code/wfpl/email.php'); require_once('code/db_connect.php'); +# replace every character in $str with " " +function tonbsp($matches) { + return str_repeat(' ', strlen($matches[0]) * 2); +} + +# encode as html, make it display newlines and leading spaces +function enc_htmlbrtab($str) { + $str = enc_htmlbr($str); + $str = preg_replace_callback("|^ *|m", tonbsp, $str); + return $str; +} + function tasks_get_fields() { $title = format_oneline($_REQUEST['title']); $url = format_oneline($_REQUEST['url']); @@ -30,28 +42,74 @@ function tasks_tem_sets($title, $url, $description) { } function tasks_main() { - $ret = _tasks_main(); - if($ret) { - return $ret; + if(!logged_in()) { + $GLOBALS['url'] = this_url(); + return 'login'; } + + if(isset($_REQUEST['tasks_id'])) { + $ret = tasks_display_main(); + if($ret) { + return $ret; + } + tem_show('display_body'); + } else { + $ret = tasks_edit_main(); + if($ret) { + return $ret; + } + tem_show('edit_body'); + } + tem_show('main_body'); } -function _tasks_main() { +function tasks_display_main() { + $task_id = format_int($_REQUEST['tasks_id']);; + $row = db_get_row('tasks', 'title,url,description,state', 'where id=%i', $task_id); + if($row) { + list($title, $url, $description, $state) = $row; + tem_set('task_id', $task_id); + tem_set('title', $title); + tem_set('url', $url); + tem_set('description', $description); + tem_set('state', task_state_pretty($state)); + if($state == TASK_BUG) { + tem_show('bug_title'); + } else { + tem_show('normal_title'); + } + } else { + message("Task #$task_id not found"); + return './'; + } +} + +function tasks_edit_main() { + $state = TASK_DRAFT; # will be overwritten $edit_id = format_int($_REQUEST['tasks_edit_id']); unset($_REQUEST['tasks_edit_id']); if($edit_id) { # add hidden field for database id of row we're editing tem_set('tasks_edit_id', $edit_id); tem_show('editing'); + + $state = db_get_value('tasks', 'state', 'where id=%i', $edit_id); } if(isset($_REQUEST['tasks_new_bug'])) { tem_show('bug_submit'); + $state = TASK_BUG; } else { tem_show('normal_submits'); } + if($state == TASK_BUG) { + tem_show('bug_instructions'); + } else { + tem_show('normal_instructions'); + } + $delete_id = format_int($_REQUEST['tasks_delete_id']); unset($_REQUEST['tasks_delete_id']); if($delete_id) { @@ -61,10 +119,6 @@ function _tasks_main() { return './tasks.html'; } - if(!$edit_id) { - tem_show('new_msg'); - } - if(isset($_REQUEST['title'])) { list($title, $url, $description) = tasks_get_fields(); @@ -127,9 +181,11 @@ function _tasks_main() { # this has to be later in the file because it requres that client_id be set already if($edit_id) { tem_show('edit_msg'); + } elseif($state == TASK_BUG) { + tem_show('bug_msg'); + } else { + tem_show('new_msg'); } - - tem_show('form'); } ?> diff --git a/template.html b/template.html index 3cdc104..c83c8e9 100644 --- a/template.html +++ b/template.html @@ -23,6 +23,7 @@
+
-- 1.7.10.4