JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
contractor can enter tasks for clients without switching login
authorJason Woofenden <jason283@herkamire.com>
Mon, 8 Dec 2008 09:06:17 +0000 (04:06 -0500)
committerJason Woofenden <jason283@herkamire.com>
Mon, 8 Dec 2008 09:06:17 +0000 (04:06 -0500)
tasks.html
tasks.php

index af09c86..80d3dba 100644 (file)
   <form action="tasks" method="post"><!--~editing start~--><input type="hidden" name="tasks_edit_id" value="~tasks_edit_id.attr~" /><!--~end~-->
     <table cellspacing="0" cellpadding="4" border="0" summary="">
 
+<!--~client_row start~-->
+      <tr><td class="caption">Client: </td><td class="field"><select name="client_id"><!--~client_id.options~--></select></td></tr>
+<!--~end~-->
+
       <tr><td class="caption">Title: </td><td class="field"><input type="text" size="40" name="title" value="~title.attr~" /></td></tr>
 
       <tr><td class="caption">URL: </td><td class="field"><input type="text" size="40" name="url" value="~url.attr~" /></td></tr>
index 7c5f0d4..8995d80 100644 (file)
--- a/tasks.php
+++ b/tasks.php
@@ -32,14 +32,14 @@ function description_has_fixmes($description) {
 }
 
 # replace every character in $str with "&nbsp;"
-function tonbsp($matches) {
+function to_nbsp($matches) {
        return str_repeat('&nbsp;', 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);
+       $str = preg_replace_callback("|^ *|m", to_nbsp, $str);
        return $str;
 }
 
@@ -210,7 +210,7 @@ function tasks_edit_main() {
 
        if(isset($_REQUEST['tasks_approve_price_id'])) {
                $id = $_REQUEST['tasks_approve_price_id'];
-               $owner = db_get_value('tasks', 'client_id', 'where id=%i', $id);;
+               $owner = db_get_value('tasks', 'client_id', 'where id=%i', $id);
                if(logged_in() != $owner) {
                        message("Error: can't approve a task entered by/for another client.");
                        return './';
@@ -290,7 +290,7 @@ function tasks_edit_main() {
                        }
                }
 
-               if("you're happy with the POSTed values") {
+               if("you're happy with the POSTed values") { # if you change this change the one above
                        if($edit_id) {
                                if(isset($_REQUEST['price']) && logged_in_as_contractor()) {
                                        db_update('tasks', 'title,url,description,state,price', $title, $url, $description, $state, $price, 'where id=%i', $edit_id);
@@ -302,6 +302,9 @@ function tasks_edit_main() {
                                # new task
                                $paid = 0;
                                $client_id = logged_in();
+                               if(logged_in_as_contractor() && $_REQUEST['client_id']) {
+                                       $client_id = format_int($_REQUEST['client_id']);
+                               }
                                db_insert('tasks', 'client_id,title,url,description,state,paid', $client_id, $title, $url, $description, $state, $paid);
                                message('Task saved.');
                        }
@@ -348,6 +351,11 @@ function tasks_edit_main() {
                tem_show('bug_msg');
        } else {
                tem_show('new_msg');
+               if(logged_in_as_contractor()) {
+                       pulldown('client_id', db_get_rows('people', 'id,name', 'where id > 1'), PULLDOWN_2D);
+                       tem_set('client_id', format_int($_REQUEST['client_id']));
+                       tem_show('client_row');
+               }
        }
 
        # display instructions