JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
contractor can enter tasks for clients without switching login
[contractor-progress.git] / tasks.php
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 " "
-function tonbsp($matches) {
+function to_nbsp($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);
+       $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