function Address($task_id, $type) { global $db, $fs, $proj, $user; $users = array(); $emails = array(); $jabbers = array(); $onlines = array(); $task_details = Flyspray::GetTaskDetails($task_id); // Get list of users from the notification tab // Decision: If a notification-user have the limited-flag set, only // task-relevant messages should be send to him if ($type > 4) { $limitedStr = " AND n.limited = 0"; } else { $limitedStr = ""; } $get_users = $db->Query(' SELECT * FROM {notifications} n LEFT JOIN {users} u ON n.user_id = u.user_id WHERE n.task_id = ? ' . $limitedStr, array($task_id)); self::AssignRecipients($db->FetchAllArray($get_users), $emails, $jabbers, $onlines); // Get list of assignees $get_users = $db->Query(' SELECT * FROM {assigned} a LEFT JOIN {users} u ON a.user_id = u.user_id WHERE a.task_id = ?', array($task_id)); self::AssignRecipients($db->FetchAllArray($get_users), $emails, $jabbers, $onlines); // Now, we add the project contact addresses... // ...but only if the task is public if ($task_details['mark_private'] != '1' && in_array($type, Flyspray::int_explode(' ', $proj->prefs['notify_types']))) { // FIXME! Have to find users preferred language here too, // must fetch from database. But the address could also be a mailing // list address and user not exist in database, use fs->prefs in that case, $proj_emails = preg_split('/[\\s,;]+/', $proj->prefs['notify_email'], -1, PREG_SPLIT_NO_EMPTY); $desired = implode("','", $proj_emails); if ($desired != '') { $get_users = $db->Query("\n\t\t\t\t\tSELECT DISTINCT u.user_id, u.email_address, u.jabber_id,\n\t\t\t\t\tu.notify_online, u.notify_type, u.notify_own, u.lang_code\n\t\t\t\t\tFROM {users} u\n\t\t\t\t\tWHERE u.email_address IN ('{$desired}')"); self::AssignRecipients($db->FetchAllArray($get_users), $emails, $jabbers, $onlines); } $proj_jids = explode(',', $proj->prefs['notify_jabber']); $desired = implode("','", $proj_jids); if ($desired != '') { $get_users = $db->Query("\n\t\t\t\t\tSELECT DISTINCT u.user_id, u.email_address, u.jabber_id,\n\t\t\t\t\tu.notify_online, u.notify_type, u.notify_own, u.lang_code\n\t\t\t\t\tFROM {users} u\n\t\t\t\t\tWHERE u.jabber_id IN ('{$desired}')"); self::AssignRecipients($db->FetchAllArray($get_users), $emails, $jabbers, $onlines); } // Now, handle notification addresses that are not assigned to any user... foreach ($proj_emails as $email) { if (!array_key_exists($email, $emails)) { $emails[$email] = array('recipient' => $email, 'lang' => $fs->prefs['lang_code']); } } foreach ($proj_jids as $jabber) { if (!array_key_exists($jabber, $jabbers)) { $jabbers[$jabber] = array('recipient' => $jabber, 'lang' => $fs->prefs['lang_code']); } } /* echo "<pre>"; echo var_dump($proj_emails); echo var_dump($proj_jids); echo "</pre>"; */ // End of checking if a task is private } // Send back three arrays containing the notification addresses return array($emails, $jabbers, $onlines); }
function Address($task_id, $type) { global $db, $fs, $proj, $user; $users = array(); $jabber_users = array(); $email_users = array(); $task_details = Flyspray::GetTaskDetails($task_id); // Get list of users from the notification tab $get_users = $db->Query('SELECT * FROM {notifications} n LEFT JOIN {users} u ON n.user_id = u.user_id WHERE n.task_id = ?', array($task_id)); while ($row = $db->FetchRow($get_users)) { if ($row['user_id'] == $user->id && !$user->infos['notify_own']) { continue; } if ($fs->prefs['user_notify'] == '1' && ($row['notify_type'] == NOTIFY_EMAIL || $row['notify_type'] == NOTIFY_BOTH) || $fs->prefs['user_notify'] == '2') { array_push($email_users, $row['email_address']); } if ($fs->prefs['user_notify'] == '1' && ($row['notify_type'] == NOTIFY_JABBER || $row['notify_type'] == NOTIFY_BOTH) || $fs->prefs['user_notify'] == '3') { array_push($jabber_users, $row['jabber_id']); } } // Get list of assignees $get_users = $db->Query('SELECT * FROM {assigned} a LEFT JOIN {users} u ON a.user_id = u.user_id WHERE a.task_id = ?', array($task_id)); while ($row = $db->FetchRow($get_users)) { if ($row['user_id'] == $user->id && !$user->infos['notify_own']) { continue; } if ($fs->prefs['user_notify'] == '1' && ($row['notify_type'] == NOTIFY_EMAIL || $row['notify_type'] == NOTIFY_BOTH) || $fs->prefs['user_notify'] == '2') { array_push($email_users, $row['email_address']); } if ($fs->prefs['user_notify'] == '1' && ($row['notify_type'] == NOTIFY_JABBER || $row['notify_type'] == NOTIFY_BOTH) || $fs->prefs['user_notify'] == '3') { array_push($jabber_users, $row['jabber_id']); } } // Now, we add the project contact addresses... // ...but only if the task is public if ($task_details['mark_private'] != '1' && in_array($type, Flyspray::int_explode(' ', $proj->prefs['notify_types']))) { $proj_emails = preg_split('/[\\s,;]+/', $proj->prefs['notify_email'], -1, PREG_SPLIT_NO_EMPTY); $proj_jids = explode(',', $proj->prefs['notify_jabber']); foreach ($proj_emails as $key => $val) { if (!empty($val) && !in_array($val, $email_users)) { array_push($email_users, $val); } } foreach ($proj_jids as $key => $val) { if (!empty($val) && !in_array($val, $jabber_users)) { array_push($jabber_users, $val); } } // End of checking if a task is private } // Send back two arrays containing the notification addresses return array($email_users, array_unique($jabber_users)); }