Last active
November 4, 2015 11:54
-
-
Save xezpeleta/40a4b22b7398dee1696a to your computer and use it in GitHub Desktop.
It sends a satisfaction survey to the Mantis user when the bug is closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/php | |
<?php | |
## | |
# mantis-users-survey.php: Asebetetze inkestaren esteka bidaltzen zaio erabiltzaileari, bere matxura | |
# itxi ostean. Horretarako, script hau egunero exekutatu behar da CRON bitartez. | |
# Adibidez: | |
# 55 23 * * * /root/scripts/mantis-users-survey.php >> /root/scripts/mantis-survey.log | |
## | |
$db_host='localhost'; | |
$db_user='mantis'; | |
$db_pass=''; | |
$db_name='mantis'; | |
$email_from='Erakunde Izena <[email protected]>'; | |
$email_subject='Matxuraren asebetetze inkesta'; | |
$email_body_tpl="Kaixo <!realname!>,\n | |
Duela gutxi zuk sartutako matxura bat itxi dugu. Zer iruditu zaizu bertan izandako erantzuna? Emaiguzu zure iritzia inkesta honen bitartez: | |
\thttp://goo.gl/forms/<your-form-id> | |
\n | |
Zure matxuraren inguruko datu gehiago: | |
\tIzenburua: <!summary!> | |
\tMatxura: http://matxurak.yourdomain.eus/view.php?id=<!bug_text_id!> | |
\n | |
Beste informaziorik behar baduzu, sartu Mantenuko Komunitatera: http://www.yourdomain.eus/mantenua | |
\n | |
Mila esker, | |
\n | |
"; | |
function tag($val) { | |
return '/<!' . $val . '!>/'; | |
} | |
$link = mysql_connect($db_host, $db_user, $db_pass) or die('DB error - Cannot connect: ' . mysql_error()); | |
mysql_select_db($db_name) or die('DB error - Cannot select database: '); | |
// Mantis updated date format. Now using timestamp! | |
#$query = "SELECT bug.summary, user.email, user.realname, bug.bug_text_id FROM `mantis_bug_table` as bug, `mantis_user_table` as user WHERE bug.reporter_id=user.id and bug.last_updated >= '" . date("Y-m-d") . " 00:00:00' and bug.status = '80'"; | |
$query = "SELECT bug.summary, user.email, user.realname, bug.bug_text_id FROM `mantis_bug_table` as bug, `mantis_user_table` as user WHERE bug.reporter_id=user.id and bug.last_updated >= '" . strtotime('-1 day', time()) . "' and bug.status = '80'"; | |
$result = mysql_query($query) or die('DB error - Query error: ' . mysql_error()); | |
echo ("===========================\n"); // log output | |
echo ("Date: " . date("Y/m/d") . "\n"); // log output | |
while ($bug = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
$email_body = preg_replace(array_map('tag', array_keys($bug)), array_values($bug), $email_body_tpl); | |
//$email_to = '[email protected]'; // testing | |
$email_to = $bug['email']; | |
$email_header = '"From: ". $email_from . "\r\n";'; | |
ini_set('sendmail_from', "[email protected]"); | |
mail($email_to, $email_subject, $email_body, $email_header); | |
## | |
## Debug | |
## | |
//echo ("\nFrom: " . $email_from); | |
//echo ("\nTo: " . $bug['realname'] . " <" . $bug['email'] . ">"); | |
//echo ("\nSubject: " . $email_subject); | |
//echo ("\n\n" . $email_body); | |
## | |
## Output | |
## | |
echo ("BugID = " . $bug['bug_text_id'] . " | EmailTo = " . $email_to . "\n"); | |
} | |
echo ("===========================\n"); // log output | |
mysql_free_result($result); | |
mysql_close($link); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment