-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional scripts
- Loading branch information
Showing
3 changed files
with
306 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,271 @@ | ||
<?php | ||
# This page tests sending an E-mail if a due date is getting near | ||
# Real email is sent but notes are not created for the various issues | ||
require_once( '../../../core.php' ); | ||
$t_login = config_get( 'plugin_Reminder_reminder_login' ); | ||
$ok=auth_attempt_script_login( $t_login ); | ||
$t_core_path = config_get( 'core_path' ); | ||
require_once( $t_core_path.'bug_api.php' ); | ||
require_once( $t_core_path.'email_api.php' ); | ||
require_once( $t_core_path.'bugnote_api.php' ); | ||
require_once( $t_core_path.'category_api.php' ); | ||
require_once( $t_core_path.'helper_api.php' ); | ||
$t_rem_project = config_get( 'plugin_Reminder_reminder_project_id' ); | ||
$t_rem_days = config_get( 'plugin_Reminder_reminder_days_treshold' ); | ||
$t_rem_status = config_get( 'plugin_Reminder_reminder_bug_status' ); | ||
$t_rem_body = config_get( 'plugin_Reminder_reminder_mail_subject' ); | ||
$t_rem_store = config_get( 'plugin_Reminder_reminder_store_as_note' ); | ||
$t_rem_ignore = config_get( 'plugin_Reminder_reminder_ignore_unset' ); | ||
$t_rem_ign_past = config_get( 'plugin_Reminder_reminder_ignore_past' ); | ||
$t_rem_handler = config_get( 'plugin_Reminder_reminder_handler' ); | ||
$t_rem_group1 = config_get( 'plugin_Reminder_reminder_group_issues' ); | ||
$t_rem_group2 = config_get( 'plugin_Reminder_reminder_group_project' ); | ||
$t_rem_manager = config_get( 'plugin_Reminder_reminder_manager_overview' ); | ||
$t_rem_subject = config_get( 'plugin_Reminder_reminder_group_subject' ); | ||
$t_rem_body1 = config_get( 'plugin_Reminder_reminder_group_body1' ); | ||
$t_rem_body2 = config_get( 'plugin_Reminder_reminder_group_body2' ); | ||
|
||
$t_rem_hours = config_get('plugin_Reminder_reminder_hours'); | ||
if (ON != $t_rem_hours){ | ||
$multiply=24; | ||
} else{ | ||
$multiply=1; | ||
} | ||
// | ||
// access level for manager= 70 | ||
// this needs to be made flexible | ||
// we will only produce overview for those projects that have a separate manager | ||
// | ||
$baseline = time()+ ($t_rem_days*$multiply*60*60); | ||
$basenow = time(); | ||
|
||
echo "Path setting retrieved : ".config_get('path'); | ||
echo "<br>"; | ||
|
||
if ( ON == $t_rem_handler ) { | ||
$query = "select id,handler_id,project_id from {bug} bugs where status in (".implode(",", $t_rem_status).") and due_date<=$baseline and handler_id>0 "; | ||
$query = "select bugs.id, bugs.handler_id, bugs.project_id, bugs.priority, bugs.category_id, bugs.status, bugs.severity, bugs.summary from {bug} bugs JOIN {bug_text} text ON (bugs.bug_text_id = text.id) where status in (".implode(",", $t_rem_status).") and due_date<=$baseline and handler_id<>0 "; | ||
|
||
if ( ON == $t_rem_ign_past ) { | ||
$query .=" and due_date>=$basenow" ; | ||
} else{ | ||
if ( ON == $t_rem_ignore ) { | ||
$query .=" and due_date>1" ; | ||
} | ||
} | ||
$t_rem_include = config_get('plugin_Reminder_reminder_include'); | ||
$t_rem_projects = "("; | ||
$t_rem_projects .= config_get('plugin_Reminder_reminder_project_id'); | ||
$t_rem_projects .= ")"; | ||
if ( ON==$t_rem_include ){ | ||
if ( !empty( config_get( 'plugin_Reminder_reminder_project_id' ) ) ) { | ||
$query .= " and bugs.project_id IN ". $t_rem_projects; | ||
} | ||
} else { | ||
if (!empty( config_get( 'plugin_Reminder_reminder_project_id' ) )) { | ||
$query .= " and bugs.project_id NOT IN ".$t_rem_projects; | ||
} | ||
} | ||
|
||
if ( ON == $t_rem_group1 ) { | ||
$query .=" order by handler_id" ; | ||
}else{ | ||
if ( ON == $t_rem_group2 ) { | ||
$query .=" order by bugs.project_id,handler_id" ; | ||
} | ||
} | ||
$results = db_query( $query ); | ||
$resnum=db_num_rows($results); | ||
if ( OFF == $t_rem_group1 ) { | ||
if ($results) { | ||
while ($row1 = db_fetch_array($results)) { | ||
$id = $row1['id']; | ||
$handler = $row1['handler_id']; | ||
$list = string_get_bug_view_url_with_fqdn( $id, $handler2 ); | ||
$body = $t_rem_body1; | ||
$body .= "<br>"; | ||
$body .= $list; | ||
$body .= "<br>"; | ||
$body .= $t_rem_body2; | ||
$result = email_group_reminder( $handler, $body ); | ||
# Add reminder as bugnote if store reminders option is ON. | ||
if ( ON == $t_rem_store ) { | ||
$t_attr = '|'.$handler2.'|'; | ||
bugnote_add( $id, $t_rem_body, 0, config_get( 'default_reminder_view_status' ) == VS_PRIVATE, REMINDER, $t_attr, NULL, FALSE ); | ||
} | ||
} | ||
} | ||
} else { | ||
if ($results){ | ||
$start = true ; | ||
$list= ""; | ||
// first group and store reminder per issue | ||
while ($row1 = db_fetch_array($results)) { | ||
$id = $row1['id']; | ||
$handler = $row1['handler_id']; | ||
$project = $row1['project_id']; | ||
if ($start){ | ||
$handler2 = $handler ; | ||
$start = false ; | ||
} | ||
if ($handler==$handler2){ | ||
$list .= formatBugEntry($row1); | ||
// $list .="<br>"; | ||
// $list .= string_get_bug_view_url_with_fqdn( $id, $handler2 ); | ||
# Add reminder as bugnote if store reminders option is ON. | ||
if ( ON == $t_rem_store ) { | ||
$t_attr = '|'.$handler2.'|'; | ||
bugnote_add( $id, $t_rem_body, 0, config_get( 'default_reminder_view_status' ) == VS_PRIVATE, REMINDER, $t_attr, NULL, FALSE ); | ||
} | ||
} else { | ||
// now send the grouped email | ||
$body = $t_rem_body1; | ||
$body .= "<br>"; | ||
$body .= $list; | ||
$body .= "<br>"; | ||
$body .= $t_rem_body2; | ||
$result = email_group_reminder( $handler2, $body); | ||
$handler2 = $handler ; | ||
$list .= formatBugEntry($row1); | ||
// $list ="<br>"; | ||
// $list= string_get_bug_view_url_with_fqdn( $id, $handler2 ); | ||
# Add reminder as bugnote if store reminders option is ON. | ||
if ( ON == $t_rem_store ) { | ||
$t_attr = '|'.$handler2.'|'; | ||
bugnote_add( $id, $t_rem_body, 0, config_get( 'default_reminder_view_status' ) == VS_PRIVATE, REMINDER, $t_attr, NULL, FALSE ); | ||
} | ||
} | ||
} | ||
// handle last one | ||
if ($resnum>0){ | ||
// now send the grouped email | ||
$body = $t_rem_body1; | ||
$body .= "<br>"; | ||
$body .= $list; | ||
$body .= "<br>"; | ||
$body .= $t_rem_body2; | ||
$result = email_group_reminder( $handler2, $body); | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
if ( ON == $t_rem_manager ) { | ||
// select relevant issues in combination with an assigned manager to the project | ||
$query = "select id,handler_id,user_id from {bug} bugs,{project_user_list} man where status in (".implode(",", $t_rem_status).") and due_date<=$baseline "; | ||
if ( ON == $t_rem_ign_past ) { | ||
$query .=" and due_date>=$basenow" ; | ||
} else{ | ||
if ( ON == $t_rem_ignore ) { | ||
$query .=" and due_date>1" ; | ||
} | ||
} | ||
|
||
$t_rem_include = config_get('plugin_Reminder_reminder_include'); | ||
$t_rem_projects = "("; | ||
$t_rem_projects .= config_get('plugin_Reminder_reminder_project_id'); | ||
$t_rem_projects .= ")"; | ||
if (ON==$t_rem_include){ | ||
if ($t_rem_projects <>"0") { | ||
$query .= " and bugs.project_id IN ". $t_rem_projects; | ||
} | ||
}else{ | ||
$query .= " and bugs.project_id NOT IN ".$t_rem_projects; | ||
} | ||
$query .=" and bugs.project_id=man.project_id and man.access_level=70" ; | ||
$query .=" order by man.project_id,man.user_id" ; | ||
$results = db_query( $query ); | ||
$resnum=db_num_rows($results); | ||
if ($results){ | ||
$start = true ; | ||
$list= ""; | ||
// first group and store reminder per issue | ||
while ($row1 = db_fetch_array($results)) { | ||
$id = $row1['id']; | ||
$handler = $row1['handler_id']; | ||
$manager = $row1['user_id']; | ||
if ($start){ | ||
$man2 = $manager ; | ||
$start = false ; | ||
} | ||
if ($manager==$man2){ | ||
$list .=" \n\n"; | ||
$list .= string_get_bug_view_url_with_fqdn( $id, $man2 ); | ||
} else { | ||
// now send the grouped email | ||
$body = $t_rem_body1. " \n\n"; | ||
$body .= $list. " \n\n"; | ||
$body .= $t_rem_body2; | ||
$result = email_group_reminder( $man2, $body); | ||
$man2 = $manager ; | ||
$list= string_get_bug_view_url_with_fqdn( $id, $man2 ); | ||
$list .= " \n\n"; | ||
} | ||
} | ||
// handle last one | ||
if ($resnum>0){ | ||
// now send the grouped email | ||
$body = $t_rem_body1. " \n\n"; | ||
$body .= $list. " \n\n"; | ||
$body .= $t_rem_body2; | ||
$result = email_group_reminder( $man2, $body); | ||
|
||
} | ||
} | ||
} | ||
|
||
|
||
# Send Grouped reminder | ||
function email_group_reminder( $p_user_id, $issues ) { | ||
$t_username = user_get_field( $p_user_id, 'username' ); | ||
$t_email = user_get_email( $p_user_id ); | ||
$t_subject = config_get( 'plugin_Reminder_reminder_group_subject' ); | ||
$t_message = $issues ; | ||
if( !is_blank( $t_email ) ) { | ||
echo $t_email; | ||
echo '**'; | ||
echo $t_subject; | ||
echo '<br>'; | ||
echo $t_message; | ||
echo '<br>'; | ||
email_store( $t_email, $t_subject, $t_message ); | ||
if( OFF == config_get( 'email_send_using_cronjob' ) ) { | ||
email_send_all(); | ||
} | ||
} | ||
} | ||
|
||
function formatBugEntry($data){ | ||
lang_push( user_pref_get_language( $data['handler_id'] ) ); | ||
|
||
$p_visible_bug_data = $data; | ||
$p_visible_bug_data['email_project'] = project_get_name( $data['project_id']); | ||
$p_visible_bug_data['email_category'] = category_get_name($data['category_id']); | ||
|
||
$t_email_separator1 = config_get( 'email_separator1' ); | ||
$t_email_separator2 = config_get( 'email_separator2' ); | ||
|
||
$p_visible_bug_data['email_bug'] = $data['id']; | ||
$p_visible_bug_data['email_status'] = get_enum_element( 'status', $p_visible_bug_data['status'], $data['handler_id'], $data['project_id'] ); | ||
$p_visible_bug_data['email_severity'] = get_enum_element( 'severity', $p_visible_bug_data['severity'] ); | ||
$p_visible_bug_data['email_priority'] = get_enum_element( 'priority', $p_visible_bug_data['priority'] ); | ||
$p_visible_bug_data['email_reproducibility'] = get_enum_element( 'reproducibility', $p_visible_bug_data['reproducibility'] ); | ||
$p_visible_bug_data['email_summary'] = $data['summary']; | ||
|
||
$t_message = $t_email_separator1 . " \n"; | ||
$t_message .= string_get_bug_view_url_with_fqdn( $data['id'], $data['handler_id'] ) . " \n"; | ||
$t_message .= $t_email_separator1 . " \n"; | ||
|
||
$t_message .= email_format_attribute( $p_visible_bug_data, 'email_project' ); | ||
$t_message .= email_format_attribute( $p_visible_bug_data, 'email_bug' ); | ||
$t_message .= email_format_attribute( $p_visible_bug_data, 'email_category' ); | ||
$t_message .= email_format_attribute( $p_visible_bug_data, 'email_priority' ); | ||
$t_message .= email_format_attribute( $p_visible_bug_data, 'email_status' ); | ||
$t_message .= $t_email_separator1 . " \n"; | ||
|
||
$t_message .= email_format_attribute( $p_visible_bug_data, 'email_summary' ); | ||
$t_message .= $t_email_separator1 . " \n\n\n"; | ||
|
||
return $t_message; | ||
} |
Oops, something went wrong.