Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

update_dash_tile()

Parameters

ColumnTypeDefaultDescription
$tile
$url
$link
$title
$reload_interval
$all_users
$tile_audience
$current_specific_user_groups
$specific_user_groups
$default_order_by
$resource_count
$text ""
$delete 1

Location

include/dash_functions.php lines 72 to 149

Definition

 
function update_dash_tile($tile,$url,$link,$title,$reload_interval,$all_users,$tile_audience,$current_specific_user_groups,$specific_user_groups,$default_order_by,$resource_count,$text="",$delete=1)
    {
    global 
$userref;
    if(!
is_array($tile)){$tile get_tile($tile);}

    
#Sensible Defaults for insertion to Database
    
if(empty($reload_interval) || !is_numeric($reload_interval))
        {
$reload_interval=0;}
    
$delete $delete?1:0;
    
$all_users=$all_users?1:0;
    
$escaped_tile_ref escape_check($tile['ref']);

    if(!
is_numeric($default_order_by))
        {
        
$default_order_by=$tile["default_order_by"];
        }
    
$resource_count $resource_count?1:0;

    
sql_query("UPDATE dash_tile 
                SET 
                    url='"
.escape_check($url)."',
                    link='"
.escape_check($link)."',
                    title='"
.escape_check($title)."',
                    reload_interval_secs="
.$reload_interval.",
                    all_users='"
.$all_users."',
                    default_order_by='"
.$default_order_by."',
                    resource_count='"
.$resource_count."',
                    allow_delete='"
.$delete."',
                    txt='"
.escape_check($text)."'
                WHERE 
                    ref='"
.$tile["ref"]."'");

    if(
$tile_audience=='true'// All users tile
        
{
        
// Check if this was a specific usergroup tile
        
if (count($current_specific_user_groups)>|| $tile["all_users"]==0)
            {
            
#Delete the users existing record to ensure they don't get a duplicate.
            
sql_query("DELETE FROM user_dash_tile WHERE dash_tile=".$escaped_tile_ref);
            
sql_query("INSERT user_dash_tile (user,dash_tile,order_by) SELECT user.ref,'".$escaped_tile_ref."',5 FROM user");
            }

        
// This is an all users dash tile, delete any existing usergroup entries
        
sql_query("DELETE FROM usergroup_dash_tile WHERE dash_tile = '{$escaped_tile_ref}'");
           }
    elseif(
$tile_audience=='specific_user_groups'// Specific usergroups tile
        
{
        
// This is a usergroup specific dash tile
        // As is not meant for a specific user group, remove it from the users immediately    
        
if(count($current_specific_user_groups)==0)
            {
            
// This was an all users/usergroup dash tile, delete any existing user entries
            
sql_query("DELETE FROM user_dash_tile WHERE dash_tile = '{$escaped_tile_ref}'");
            }
        
        
// Remove tile from old user groups                    
        
foreach(array_diff($current_specific_user_groups,$specific_user_groups) as $remove_group)
            {                    
            
delete_usergroup_dash_tile($escaped_tile_ref,$remove_group);
            }                
        
        
// Newly selected user groups.
        
foreach(array_diff($specific_user_groups,$current_specific_user_groups) as $add_group)
            {
            
add_usergroup_dash_tile($add_group$escaped_tile_ref$default_order_by);
            
build_usergroup_dash($add_group,0,$escaped_tile_ref);
            }
        }
    else 
// Tile is now just for the current user
        
{
        
// This was an all users/usergroup dash tile, delete any existing user entries and add just for this user
        
sql_query("DELETE FROM usergroup_dash_tile WHERE dash_tile = '{$escaped_tile_ref}'");
        
sql_query("DELETE FROM user_dash_tile WHERE dash_tile = '{$escaped_tile_ref}'");
        
add_user_dash_tile($userref$escaped_tile_ref$default_order_by); 
        }
        
    
hook('after_update_dash_tile');
    }

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