$validated = 1; if (!isset($_POST["taskDescription"])) { $validated = 0; } if (!isset($_POST["userid"]) && !isset($_POST["touserid"])) { $validated = 0; } if ($validated == 1) { $db = new \creamy\DbHandler(); // check password $userid = isset($_POST["touserid"]) ? $_POST["touserid"] : $_POST["userid"]; $taskDescription = $_POST["taskDescription"]; $taskDescription = stripslashes($taskDescription); $taskDescription = $db->escape_string($taskDescription); $taskInitialProgress = 0; $result = $db->createTask($userid, $taskDescription, $taskInitialProgress); if ($result === true) { // if the task was assigned to the user by another user, send the receiver a message. $user = \creamy\CreamyUser::currentUser(); if (isset($user)) { $myId = $user->getUserId(); if ($myId != $userid) { // I'm creating a task for another user. Mail that user. require_once 'MailHandler.php'; $mh = \creamy\MailHandler::getInstance(); $mh->sendNewTaskMailToUser($myId, $userid, $taskDescription); } } // return result ob_clean(); print CRM_DEFAULT_SUCCESS_RESPONSE;