Created
May 29, 2017 00:58
-
-
Save rmsaitam/e7a627c951527018e849401efdf83b91 to your computer and use it in GitHub Desktop.
Query Permissão acesso dia da semana e horário por usuário ao sistema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT dayname(now()) as dia_semana, | |
perm_acesso_seg, hinicio_manha_seg, hfim_manha_seg, hinicio_tarde_seg, hfim_tarde_seg, | |
perm_acesso_ter, hinicio_manha_ter, hfim_manha_ter, hinicio_tarde_ter, hfim_tarde_ter, | |
perm_acesso_qua, hinicio_manha_qua, hfim_manha_qua, hinicio_tarde_qua, hfim_tarde_qua, | |
perm_acesso_qui, hinicio_manha_qui, hfim_manha_qui, hinicio_tarde_qui, hfim_tarde_qui, | |
perm_acesso_sex, hinicio_manha_sex, hfim_manha_sex, hinicio_tarde_sex, hfim_tarde_sex, | |
perm_acesso_sab, hinicio_manha_sab, hfim_manha_sab, hinicio_tarde_sab, hfim_tarde_sab, | |
perm_acesso_dom, hinicio_manha_dom, hfim_manha_dom, hinicio_tarde_dom, hfim_tarde_dom, | |
CASE dayname(NOW()) | |
WHEN 'Monday' THEN perm_acesso_seg=1 AND (TIME(NOW()) BETWEEN hinicio_manha_seg AND hfim_manha_seg) OR | |
(TIME(NOW()) BETWEEN hinicio_tarde_seg AND hfim_tarde_seg) | |
WHEN 'Tuesday' THEN perm_acesso_ter=1 AND (TIME(NOW()) BETWEEN hinicio_manha_ter AND hfim_manha_ter) OR | |
(TIME(NOW()) BETWEEN hinicio_tarde_ter AND hfim_tarde_ter) | |
WHEN 'Wednesday' THEN perm_acesso_qua=1 AND (TIME(NOW()) BETWEEN hinicio_manha_qua AND hfim_manha_qua) OR | |
(TIME(NOW()) BETWEEN hinicio_tarde_qua AND hfim_tarde_qua) | |
WHEN 'Thursday' THEN perm_acesso_qui=1 AND (TIME(NOW()) BETWEEN hinicio_manha_qui AND hfim_manha_qui) OR | |
(TIME(NOW()) BETWEEN hinicio_tarde_qui AND hfim_tarde_qui) | |
WHEN 'Friday' THEN perm_acesso_sex=1 AND (TIME(NOW()) BETWEEN hinicio_manha_sex AND hfim_manha_sex) OR | |
(TIME(NOW()) BETWEEN hinicio_tarde_sex AND hfim_tarde_sex) | |
WHEN 'Saturday' THEN perm_acesso_sab=1 AND (TIME(NOW()) BETWEEN hinicio_manha_sab AND hfim_manha_sab) OR | |
(TIME(NOW()) BETWEEN hinicio_tarde_sab AND hfim_tarde_sab) | |
WHEN 'Sunday' THEN perm_acesso_dom=1 AND (TIME(NOW()) BETWEEN hinicio_manha_dom AND hfim_manha_dom) OR | |
(TIME(NOW()) BETWEEN hinicio_tarde_dom AND hfim_tarde_dom) | |
END AS acesso_d_semana | |
FROM cfg_usr_perm upa | |
INNER JOIN cfg_usr u ON(upa.id_usr = u.id) | |
WHERE upa.id_usr=$id_usr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment