Beispiel #1
0
 function edit_timeSheetItem($commands)
 {
     $item_fields = $this->get_fields("item");
     // Time Sheet Item commands
     if ($commands["item"]) {
         $timeSheetItem = new timeSheetItem();
         if ($commands["item"] && strtolower($commands["item"] != "new")) {
             $timeSheetItem->set_id($commands["item"]);
             if (!$timeSheetItem->select()) {
                 alloc_error("Unable to select time sheet item with ID: " . $commands["item"]);
             }
         }
         $timeSheet = $timeSheetItem->get_foreign_object("timeSheet");
         $timeSheetItem->currency = $timeSheet->get_value("currencyTypeID");
         $timeSheetItem->set_value("rate", $timeSheetItem->get_value("rate", DST_HTML_DISPLAY));
         foreach ($commands as $k => $v) {
             // Validate/coerce the fields
             if ($k == "unit") {
                 $changes[$k] = "timeSheetItemDurationUnitID";
                 in_array($v, array(1, 2, 3, 4, 5)) or $err[] = "Invalid unit. Try a number from 1-5.";
             } else {
                 if ($k == "task") {
                     $changes[$k] = "taskID";
                     $t = new task();
                     $t->set_id($v);
                     $t->select();
                     is_object($timeSheet) && $timeSheet->get_id() && $t->get_value("projectID") != $timeSheet->get_value("projectID") and $err[] = "Invalid task. Task belongs to different project.";
                 }
             }
             // Plug the value in
             if ($item_fields[$k][0]) {
                 $changes[$k] = $item_fields[$k][0];
                 $timeSheetItem->set_value($item_fields[$k][0], sprintf("%s", $v));
             }
         }
         $after_label2 = "After:  ";
         if (strtolower($commands["item"]) != "new") {
             $str = $this->condense_changes($changes, $timeSheetItem->row());
             $str and $status[] = "msg";
             $str and $message[] = "Before: " . $str;
         } else {
             $after_label2 = "Fields: ";
         }
         if ($commands["delete"]) {
             $id = $timeSheetItem->get_id();
             $timeSheetItem->delete();
             $status[] = "yay";
             $message[] = "Time sheet item " . $id . " deleted.";
             // Save timeSheetItem
         } else {
             if (!$err && $commands["item"] && $timeSheetItem->save()) {
                 $timeSheetItem->select();
                 $str = $this->condense_changes($changes, $timeSheetItem->row());
                 $str and $status[] = "msg";
                 $str and $message[] = $after_label2 . $str;
                 $status[] = "yay";
                 if (strtolower($commands["item"]) == "new") {
                     $message[] = "Time sheet item " . $timeSheetItem->get_id() . " created.";
                 } else {
                     $message[] = "Time sheet item " . $timeSheetItem->get_id() . " updated.";
                 }
                 // Problems
             } else {
                 if ($err && $commands["item"]) {
                     alloc_error("Problem updating time sheet item: " . implode("\n", (array) $err));
                 }
             }
         }
     }
     return array($status, $message);
 }