Collections functions
General functions
Render functions
Theme permission 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 304 to 336

Definition

 
function create_periodic_email($user$report$period$email_days, array $user_groups, array $search_params)
    {
    
# 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'))
        {
        if(!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 5th October 2022 03:35 Europe/London time based on the source file dated 29th September 2022 18:05 Europe/London time.