
require_once($_ENV['JIVENV']['funcFiles']['getDutyDuties']['filePath']);
require_once($_ENV['JIVENV']['funcFiles']['getDutyTasks']['filePath']);
require_once($_ENV['JIVENV']['funcFiles']['updDutyTasks']['filePath']);

$dutyArgs['id'] = %id%;
$getDuty = getDutyDuties($dutyArgs);

$userID = $getDuty['rows'][0]['user_id'];

$taskArgs['duty_id'] = %id%;
$getTasks = getDutyTasks($taskArgs);

if(count($getTasks['rows']) > 0){
	for ($i=0; $i < count($getTasks['rows']); $i++) { 
	    $task = $getTasks['rows'][$i];
	    $taskID = $task['id'];
	
	    $arg['id'] = $taskID;
	    $arg['user_id'] = $userID;
	
	    if ($task['user_id'] == null) {
	        $updTask = updDutyTasks($arg);
	        $out['taskUpdate'] = $updTask;
	    }
	  }
}
/*
require_once($_ENV['JIVENV']['funcFiles']['getDutyDuties']['filePath']);
    require_once($_ENV['JIVENV']['funcFiles']['getUserDetails']['filePath']);
    require_once($_ENV['JIVENV']['funcFiles']['sendMessage']['filePath']);

    $functionOut = json_decode(getDutyDuties(%id%), TRUE);

    $userId	= $functionOut['rows'][0]['user_id'];

    $userDetailOut = json_decode(getUserDetails($userId), TRUE);
    
    $mail = $userDetailOut['rows'][0]['email'];

    if ($mail != null || $mail != "") {

        // try {
            sendMessage(
                array(
                    "id"=>%id%,
                    "template" => "new_duty_template",
                    "recipients" => $mail
                )
            );
        // } catch(Exception $e) {
        //     $out['error'] = true;
        //     $out['message'] = $e->getMessage();
        //   }
      
    }
    // else{
    //     $out['error'] = true;
    //     $out['message'] = "Cannot send mail to this user";
    // }

 */