$delete_old->execute($data); //remove previously assigned users //Then put in the current assignments $resps = array(); foreach ($responsibles as $responsible) { if (stristr($responsible, '_grp_')) { //user has selected a group as defined in config $group = substr($responsible, 5); $all_in_group = all_users_in_group($dbh, $group); $resps[] = $all_in_group; } elseif (stristr($responsible, '_spv_')) { $supervisor = substr($responsible, 5); $all_in_group = all_users_by_supvsr($dbh, $supervisor); $resps[] = $all_in_group; } elseif (stristr($responsible, '_all_users_')) { $resps[] = all_active_users_a($dbh); } else { $resps[] = $responsible; } } $resps_flat = flatten_array($resps); $add_resp = $dbh->prepare("INSERT INTO cm_events_responsibles (id,event_id,username,time_added) VALUES (NULL, :last_id,:resp,NOW())"); for ($i = 0; $i < sizeof($resps_flat); $i++) { $data = array('last_id' => $event_id, 'resp' => $resps_flat[$i]); $add_resp->execute($data); } //Then notify only the newly-added users of the assignement via email $new_assignees = array_diff($resps_flat, $curs_flat); if (!empty($new_assignees)) { foreach ($new_assignees as $n) { $email = user_email($dbh, $resps_flat[$i]);
} } if ($new_ccs) { $ccs = null; foreach ($new_ccs as $cc) { //user has selected a group as defined in config if (stristr($cc, '_grp_')) { $group = substr($cc, 5); $all_in_group = all_users_in_group($dbh, $group); $ccs .= implode(',', $all_in_group) . ','; } elseif (stristr($cc, '_spv_')) { $supervisor = substr($cc, 5); $all_in_group = all_users_by_supvsr($dbh, $supervisor); $ccs .= implode(',', $all_in_group) . ','; } elseif (stristr($to, '_all_users_')) { $ccs .= implode(',', all_active_users_a($dbh)) . ','; } elseif (stristr($to, '_all_on_case_')) { $ccs .= implode(',', all__users_on_case($dbh, $assoc_case)) . ','; } else { $ccs .= $cc . ','; } } } else { $ccs = null; } //next insert into db $q = $dbh->prepare("INSERT INTO `cm_messages` (`id`, `thread_id`, `to`, `from`, `ccs`, `subject`, `body`, `assoc_case`, `time_sent`, `read`, `archive`, `starred`) VALUES (NULL, '', :tos, :sender, :ccs, :subject, :body, :assoc_case, CURRENT_TIMESTAMP, :sender_has_read, '', '');"); //strip trailing commas, if present if (substr($tos, -1) == ',') { $tos = substr($tos, 0, -1); }