Example #1
0
$task_end_date = new CDate($task->task_end_date);
$task->task_percent_complete = dPgetParam($_POST, 'task_percent_complete', null);
if (dPgetParam($_POST, 'task_end_date', '') != '') {
    $new_date = new CDate($_POST['task_end_date']);
    $new_date->setTime($task_end_date->hour, $task_end_date->minute, $task_end_date->second);
    $task->task_end_date = $new_date->format(FMT_DATETIME_MYSQL);
}
if ($task->task_percent_complete >= 100 && (!$task->task_end_date || $task->task_end_date == '0000-00-00 00:00:00')) {
    $task->task_end_date = $obj->task_log_date;
}
if ($msg = $task->store()) {
    $AppUI->setMsg($msg, UI_MSG_ERROR, true);
}
$new_task_end = new CDate($task->task_end_date);
if ($new_task_end->dateDiff($task_end_date)) {
    $task->addReminder();
}
if ($notify_owner && ($msg = $task->notifyOwner())) {
    $AppUI->setMsg($msg, UI_MSG_ERROR);
}
// Check if we need to email the task log to anyone.
$email_assignees = dPgetParam($_POST, 'email_assignees', null);
$email_task_contacts = dPgetParam($_POST, 'email_task_contacts', null);
$email_project_contacts = dPgetParam($_POST, 'email_project_contacts', null);
$email_others = dPgetParam($_POST, 'email_others', '');
$email_extras = dPgetParam($_POST, 'email_extras', null);
if ($task->email_log($obj, $email_assignees, $email_task_contacts, $email_project_contacts, $email_others, $email_extras)) {
    $obj->store();
    // Save the updated message. It is not an error if this fails.
}
$AppUI->redirect('m=tasks&a=view&task_id=' . $obj->task_log_task . '&tab=0#tasklog' . $obj->task_log_id);
    $AppUI->setMsg($obj->getError(), UI_MSG_ERROR);
    $AppUI->redirect('m=tasks&a=view&task_id=' . $obj->task_log_task);
}
$action = $del ? 'deleted' : 'stored';
$result = $del ? $obj->delete() : $obj->store();
if (count($obj->getError())) {
    $AppUI->setMsg($result, UI_MSG_ERROR, true);
    $AppUI->holdObject($obj);
    $AppUI->redirect('m=tasks&a=view&task_id=' . $obj->task_log_task);
}
if ($result) {
    $AppUI->setMsg('Task Log ' . $action, UI_MSG_OK, true);
    $task = new CTask();
    $task->load($obj->task_log_task);
    if ('on' == $notify_owner) {
        if ($msg = $task->notifyOwner()) {
            $AppUI->setMsg($msg, UI_MSG_ERROR);
        }
    }
    // Check if we need to email the task log to anyone.
    $email_assignees = w2PgetParam($_POST, 'email_assignees', null);
    $email_task_contacts = w2PgetParam($_POST, 'email_task_contacts', null);
    $email_project_contacts = w2PgetParam($_POST, 'email_project_contacts', null);
    $email_others = w2PgetParam($_POST, 'email_others', '');
    $email_log_user = w2PgetParam($_POST, 'email_log_user', '');
    $task_log_creator = (int) w2PgetParam($_POST, 'task_log_creator', 0);
    $email_extras = w2PgetParam($_POST, 'email_extras', null);
    // Email the user this task log is being created for, might not be the person
    // creating the logf
    $user_to_email = 0;
    if (isset($email_log_user) && 'on' == $email_log_user && $task_log_creator) {