$data['error'] = 'OK'; $data['countAlive'] = $data['countKilled'] = 0; try { $l = new Liste(); $data['priorities'] = $PRIORITIES; $data['labels'] = $l->getListe('t_labels', "*", 'id', 'ASC'); $data['devs'] = $l->getListe('t_devs', "*", 'id', 'ASC', 'id', '>=', '0'); $l->getListe('t_bugs', "id", "priority", "DESC", "closed", "=", 0); $data['countAlive'] = $l->countResults(); $l->getListe('t_bugs', "id", "priority", "DESC", "closed", "=", 1); $data['countKilled'] = $l->countResults(); $l->resetFiltre(); $l->addFiltre('nom', '!=', 'password_access'); $l->addFiltre('nom', '!=', 'api_access'); $l->getListe('t_config', '*', 'id', 'ASC'); $data['globalConf'] = $l->simplifyList('nom'); $data['available_languages'] = array(); foreach (glob($pathLang . '/*') as $langFile) { if (is_dir($langFile)) { continue; } $data['available_languages'][] = preg_replace('/\\.php/', '', basename($langFile)); } $data['LANG'] = $LANG; } catch (Exception $e) { $data['error'] = $e->getMessage(); } header('HTTP/1.1 200 OK'); header('Content-type: application/json; charset=UTF-8'); echo ")]}',\n"; // Pour sécu anti injection JSONP
/** * Send an email notification to devs * @param STRING $type The type of notification to send ('new', 'close', 'comment', or 'assign') * @return INt Number of email actually sent */ public function notify($type) { global $LANG; $iC = new Infos('t_config'); $iC->loadInfos('nom', 'enable_notify'); if ($iC->getInfos('value') == 0) { return 0; } $iC->loadInfos('nom', 'project_name'); $project_name = $iC->getInfos('value'); $iC->loadInfos('nom', 'language'); $language = $iC->getInfos('value'); $mail = new PHPMailer(true); $mail->isMail(); if ($language === 'Francais') { $mail->setLanguage('fr', INSTALL_PATH . 'language/phpMailer/'); } $mail->CharSet = 'UTF-8'; $mail->From = "*****@*****.**"; $mail->FromName = "Bughunter {$project_name}"; $mail->isHTML(true); switch ($type) { case "new": $subject = $LANG['Notify_newBug_subject']; $bodyTxt = $LANG['Notify_newBug_body']; break; case "close": $subject = $LANG['Notify_killBug_subject']; $bodyTxt = $LANG['Notify_killBug_body']; break; case "comment": $subject = $LANG['Notify_comment_subject']; $bodyTxt = $LANG['Notify_comment_body']; break; case "assign": $subject = $LANG['Notify_assign_subject']; $bodyTxt = $LANG['Notify_assign_body']; break; default: throw new Exception("Notification type unknown."); } $bugData = $this->getBugData(true); $subject = preg_replace('/\\{\\{BUG_ID\\}\\}/', $bugData['id'], $subject); $mail->Subject = $subject; $template = file_get_contents(INSTALL_PATH . 'mails/template.html'); $html = preg_replace('/\\{\\{SUBJECT\\}\\}/', $subject, $template); $html = preg_replace('/\\{\\{BODY\\}\\}/', $bodyTxt, $html); $html = preg_replace('/\\{\\{DATE\\}\\}/', date('Y-m-d'), $html); $html = preg_replace('/\\{\\{PROJECT\\}\\}/', $project_name, $html); $html = preg_replace('/\\{\\{URL_BH\\}\\}/', preg_replace('/\\/actions$/', '', get_url()), $html); $html = preg_replace('/\\{\\{REPORTER\\}\\}/', $bugData['author'], $html); $html = preg_replace('/\\{\\{BUG_ID\\}\\}/', $bugData['id'], $html); $html = preg_replace('/\\{\\{BUG_TITLE\\}\\}/', $bugData['title'], $html); $html = preg_replace('/\\{\\{BUG_DESCR\\}\\}/', $bugData['description'], $html); $html = preg_replace('/\\{\\{BUG_LABEL\\}\\}/', $bugData['label']['name'], $html); if ($type === "comment") { $comm = end($bugData['comment']); $html = preg_replace('/\\{\\{COMM_AUTHOR\\}\\}/', $comm['dev']['pseudo'], $html); $html = preg_replace('/\\{\\{COMM_MESSAGE\\}\\}/', nl2br($comm['message']), $html); } $l = new Liste(); $l->addFiltre('id', '>', '0'); $l->addFiltre('notify', '=', '1'); $l->getListe('t_devs'); $devs = $l->simplifyList(); if (!$devs) { return 0; } $countSent = 0; foreach ($devs as $dev) { if ($type === "assign" && $bugData['FK_dev_ID'] != $dev['id']) { continue; } $mail->Body = $html; $mail->addAddress($dev['mail']); if ($mail->send()) { $countSent++; } $mail->clearAddresses(); // file_put_contents(INSTALL_PATH.'data/debugMail_'.$dev['pseudo'].'.html', $html); } return $countSent; }