<?php
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
$users_mob_getAllXmlExceptN = "
	SELECT 	id,username,long_name,typ,mg.access
	FROM 	users 
    LEFT JOIN mobile_grantedusers AS mg ON id = mg.user_id
	WHERE   typ!='N'
	ORDER   BY long_name ASC,username ASC 
	LIMIT 	%u,21 ";
$adm_mob_getUserIdByGroup = "
	SELECT DISTINCT id,username,long_name,typ,mg.access
	FROM 		users u
    INNER JOIN  users_group_map AS ugm ON u.id=ugm.user_id
    LEFT JOIN   mobile_grantedusers AS mg ON id = mg.user_id        
	WHERE      	ugm.group_id IN (%s)
	ORDER BY 	long_name ASC, username ASC
	LIMIT 		%u,21 ";
$adm_mob_getUserIdByGroupRestricted = "
	SELECT DISTINCT u.id
	FROM 		users u
    INNER JOIN  users_group_map AS ugm ON u.id=ugm.user_id     
	WHERE      	ugm.group_id IN (%s)";  
$adm_getGroupId = "
SELECT  group_id
FROM    adm_group_map
WHERE   user_id = %u";
$users_mob_searchXmlAllowed = "SELECT DISTINCT id,username,long_name,typ,mg.access 
                    FROM users
                    INNER JOIN users_group_map AS ugm ON users.id = ugm.user_id
                    LEFT JOIN mobile_grantedusers AS mg ON id = mg.user_id
            		WHERE ugm.group_id IN (%s)
                    AND typ in ('I','A') 
                    AND (username like %s OR long_name like %s) 
            		ORDER BY long_name, username LIMIT %u,21 ";    
$users_mob_searchXml = "
    SELECT id,username,long_name,typ,mg.access
    FROM users 
    LEFT JOIN mobile_grantedusers AS mg ON id = mg.user_id
    WHERE typ in ('I','A') 
    AND (username like %s OR long_name like %s) 
	ORDER BY long_name, username LIMIT %u,21 ";  
$users_mob_removeAllAccess = "DELETE FROM mobile_grantedusers";
$users_mob_removeAllAccessRestricted = "DELETE FROM mobile_grantedusers
                                        WHERE user_id IN (%s)";
$users_mob_addAllAccess = "INSERT INTO mobile_grantedusers ( user_id, access ) 
                           SELECT id,1
                           FROM users";
$users_mob_addAllAccessRestricted = "
    INSERT INTO mobile_grantedusers ( user_id, access ) 
    SELECT users.id,1
    FROM users
    INNER JOIN  users_group_map AS ugm ON users.id=ugm.user_id     
	WHERE ugm.group_id IN (%s) ";
$users_mob_updateUserAccess = "UPDATE mobile_grantedusers
                               SET access=%u
                               WHERE user_id = %u";
$ctrl_scriptAccess = "  SELECT id
                        FROM adm_tabs AS at
                        INNER JOIN adm_tabs_map AS atm ON at.id = atm.tab_id
                        WHERE atm.user_id = %u
                        AND at.name IN (%s) ";
$users_mob_addUserAccess = "INSERT INTO mobile_grantedusers ( user_id, access ) 
                           VALUES (%u,1)";                        
$widgets_mob_getWidget = "SELECT title, picture, available, name
                          FROM dir_item
                          LEFT JOIN mobile_widgets AS mw ON dir_item.id = mw.item_id
                          WHERE id = %u";
$widgets_mob_updateWidgetProperties = "UPDATE mobile_widgets
                                       SET title=%s, picture=%s, available=%u
                                       WHERE item_id = %u";
$widgets_mob_addWidgetProperties = "INSERT INTO mobile_widgets ( item_id, title, picture, available ) 
                                    VALUES (%u,%s,%s,%u)";  
$widgets_mob_getAdminAllowedWidgets = "
    SELECT dir_item.id, 
           dir_item.name, 
           dir_item.status, 
           dir_item.icon,
           mobile_widgets.available
    FROM dir_cat_item,
         adm_group_map,
         users_group_category_map,
         dir_item
    LEFT JOIN mobile_widgets ON dir_item.id = mobile_widgets.item_id
    WHERE adm_group_map.group_id=users_group_category_map.group_id 
    AND users_group_category_map.category_id=dir_cat_item.category_id 
    AND dir_cat_item.item_id=dir_item.id 
    AND dir_item.status!='S' 
    AND adm_group_map.user_id=%u 
    ORDER BY name ASC, id DESC LIMIT %u,21";                                       
$widgets_mob_getAllValidXml = "
    SELECT id, name, status, icon, available
    FROM dir_item
    LEFT JOIN mobile_widgets ON dir_item.id = mobile_widgets.item_id
	WHERE status!='S' 
    ORDER BY name ASC, id DESC 
    LIMIT %u,21 ";            
?>