Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

create_periodic_email()

Description

Creates a new automatic periodic e-mail report

Parameters

ColumnTypeDefaultDescription
$user
$report
$period
$email_days
$user_groups array
$search_params array

Location

include/reporting_functions.php lines 330 to 365

Definition

 
function create_periodic_email($user$report$period$email_days, array $user_groups, array $search_params)
    {
    if (
$email_days 1)
        {
        
$email_days 1# Minimum email frequency is daily.
        
}
    
# Delete any matching rows for this report/period.
    
$query "DELETE FROM report_periodic_emails
              WHERE user = ?
              AND report = ?
              AND period = ?"
;
    
$parameters=array("i",$user"i",$report"i",$period);
    
ps_query($query,$parameters);

    
# Insert a new row.
    
$query "INSERT INTO report_periodic_emails 
                        (user, report, period, email_days, search_params)
                 VALUES (?,?,?,?,?)"
;
    
$parameters=array("i",$user"i",$report"i",$period"i",$email_days
                      
"s",json_encode($search_paramsJSON_UNESCAPED_UNICODE JSON_NUMERIC_CHECK));
    
ps_query($query,$parameters);

    
$ref sql_insert_id();
    
    
# Send to all users?
    
if (
        
checkperm('m')
        && !empty(
$user_groups)
        ) {
            
$ugstring=implode(",",$user_groups);
            
ps_query("UPDATE report_periodic_emails SET user_groups = ? WHERE ref = ?",array("s",$ugstring"i",$ref));
        }

    
# Return
    
return true;
    }

This article was last updated 21st May 2024 11:35 Europe/London time based on the source file dated 8th May 2024 18:45 Europe/London time.