Collections functions
Encryption functions
General 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
$send_all_users
$user_groups array

Location

include/reporting_functions.php lines 175 to 245

Definition

 
function create_periodic_email($user$report$period$email_days$send_all_users, array $user_groups)
    {
    
# Delete any matching rows for this report/period.
    
$query sprintf("
            DELETE
              FROM report_periodic_emails
             WHERE user = '%s'
               AND report = '%s'
               AND period = '%s';
        "
,
        
escape_check($user),
        
escape_check($report),
        
escape_check($period)
    );
    
sql_query($query);

    
# Insert a new row.
    
$query sprintf("
            INSERT INTO report_periodic_emails (
                                                   user,
                                                   report,
                                                   period,
                                                   email_days
                                               )
                 VALUES (
                            '%s',  # user
                            '%s',  # report
                            '%s',  # period
                            '%s'   # email_days
                        );
        "
,
        
escape_check($user),
        
escape_check($report),
        
escape_check($period),
        
escape_check($email_days)
    );
    
sql_query($query);
    
$ref sql_insert_id();
    
    
# Send to all users?
    
if (checkperm('m'))
        {
        if(
$send_all_users)
            {
            
sql_query("UPDATE report_periodic_emails SET send_all_users = 1 WHERE ref = '" escape_check($ref) . "';");
            }

        if(!empty(
$user_groups))
            {

            
// Manually implode usergroups to allow an escape_check()
            
$ugstring="";
            
$ugindex=0;
            
$ugcount=count($user_groups);
            foreach(
$user_groups as $ug) {
                
$ugindex+=1;
                if(
$ugindex $ugcount) {
                    
$ugstring $ugstring escape_check($ug) . ",";
                }
                else {
                    
$ugstring $ugstring escape_check($ug);
                }
            }

            
sql_query("UPDATE report_periodic_emails SET user_groups = '" $ugstring "' WHERE ref = '" escape_check($ref) . "';");
            }
        }

    
# Return
    
return true;
    }

This article was last updated 13th July 2020 15:35 Europe/London time based on the source file dated 24th June 2020 14:38 Europe/London time.