Sync from remote server: 2025-10-12 18:56:41
This commit is contained in:
118
Tilt/Users_Def.m
Executable file
118
Tilt/Users_Def.m
Executable file
@@ -0,0 +1,118 @@
|
||||
function [Mail,Users_Report,activeEN,siteID,NomeSito] = Users_Def(IDcentralina,conn,FileName)
|
||||
|
||||
text = 'Users function started';
|
||||
fileID = fopen(FileName,'a');
|
||||
fmt = '%s \r';
|
||||
fprintf(fileID,fmt,text);
|
||||
|
||||
% A partire dalla centralina, risalgo al site ID
|
||||
comando = ['select site_id from units where name like ''' IDcentralina ''' '];
|
||||
curs = exec(conn,comando);
|
||||
curs = fetch(curs);
|
||||
siteID = num2str(cell2mat(curs.Data));
|
||||
|
||||
% --- Cerco gli utenti ---
|
||||
|
||||
% - Definisco gli Users
|
||||
% A partire dal site ID, risalgo al company ID
|
||||
comando = ['select company_id, name, lat, lon, alarm_email from sites where id like ''' siteID ''' '];
|
||||
curs = exec(conn,comando);
|
||||
curs = fetch(curs);
|
||||
Site = curs.Data;
|
||||
Company_id = num2str(cell2mat(Site(1,1)));
|
||||
NomeSito = Site(1,2);
|
||||
|
||||
% A partire dal company ID, mi scarico le info relative a Send Email Alarm
|
||||
comando = ['select send_alarm from companies where id like ''' Company_id ''' '];
|
||||
curs = exec(conn,comando);
|
||||
curs = fetch(curs);
|
||||
Mail = cell2mat(curs.Data);
|
||||
|
||||
% A partire dal company ID, risalgo agli utenti e alla loro mail di
|
||||
% quella company che sono admin
|
||||
comando = ['select fname, lname, email, language_id, report from users where '...
|
||||
'company_id like ''' Company_id ''' '];
|
||||
curs = exec(conn,comando);
|
||||
curs = fetch(curs);
|
||||
Users = curs.Data;
|
||||
|
||||
% Elimino gli utenti che non devono ricevere il report
|
||||
[rU,cU] = size(Users);
|
||||
Users_Report = cell(1,1);
|
||||
rpt = 1;
|
||||
if cU > 1
|
||||
for u = 1:rU
|
||||
if cell2mat(Users(u,5)) == 1
|
||||
[rUA,cUA] = size(Users_Report);
|
||||
if rUA == 1 && cUA == 1
|
||||
clear Users_Report
|
||||
end
|
||||
Users_Report(rpt,:) = Users(u,1:4);
|
||||
rpt = rpt+1;
|
||||
end
|
||||
end
|
||||
end
|
||||
ini_CoV = rpt;
|
||||
|
||||
% Cone of vision
|
||||
% A partire dal site ID, risalgo al USER ID degli utenti nel
|
||||
% cone-of-vision per quel sito
|
||||
comando = ['select user_id from coneofvisions where site_id like ''' siteID ''' '];
|
||||
curs = exec(conn,comando);
|
||||
curs = fetch(curs);
|
||||
CoV = cell2mat(curs.Data);
|
||||
|
||||
comando = ['select report_cov from coneofvisions where site_id like ''' siteID ''' '];
|
||||
curs = exec(conn,comando);
|
||||
curs = fetch(curs);
|
||||
Auth_CoV = cell2mat(curs.Data);
|
||||
|
||||
% A partire dal USER ID, risalgo agli utenti e alla loro email se sono company manager
|
||||
[rC, ~] = size(CoV);
|
||||
n = 1;
|
||||
if strcmp(char(CoV(1,:)),'No Data') % almeno un utente da cercare nel database
|
||||
else
|
||||
for i=1:rC
|
||||
if Auth_CoV(i) == 1
|
||||
Utente = num2str(CoV(i,1));
|
||||
comando = ['select fname, lname, email, language_id '...
|
||||
'from users where id = ''' Utente ''' '];
|
||||
curs = exec(conn,comando);
|
||||
curs = fetch(curs);
|
||||
COV = curs.Data;
|
||||
Users_CoV(n,:) = COV;
|
||||
n = n+1;
|
||||
end
|
||||
end
|
||||
end
|
||||
if n>1 % Esistono utenti CoV per il report
|
||||
[~,cU] = size(Users_Report);
|
||||
if cU == 1
|
||||
Users_Report = Users_CoV;
|
||||
else
|
||||
Users_Report(rpt:rpt+n-2,:) = Users_CoV;
|
||||
end
|
||||
end
|
||||
[rU,cU] = size(Users_Report);
|
||||
if rU == 0
|
||||
Mail = 0;
|
||||
end
|
||||
|
||||
% A chi mando la mail
|
||||
activeEN = 0;
|
||||
if cU >1 % sono presenti utenti a cui inviare la mail
|
||||
for i = 1:rU
|
||||
if Users_Report{i,4} == 2
|
||||
activeIT = 1;
|
||||
else
|
||||
activeEN = 1;
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
text = 'Users function worked correctly';
|
||||
fprintf(fileID,fmt,text);
|
||||
fclose(fileID);
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user