class _user{constructor(userId,userFullName,userName,email,accountstatus=1,userTitle=-1,userTitleSignature="",billingProfile=-1,workplaceid=-1,permissionLevel=-1,companyId=-1,photo="",sourceid=0){this.uId=userId;this.uFullName=userFullName;this.uName=userName;this.email=email;this.accountstatus=accountstatus;this.uTle=userTitle;this.uTleSign=userTitleSignature;this.bProfile=billingProfile;this.pLevel=permissionLevel;this.workplaceid=workplaceid;this.companyId=companyId;this.photo=photo;this.sourceid=sourceid}}
var SYSTEM_USER_TITLE=[];var SYSTEM_USER_WHO_CALL="UTIINFO";var SYSTEM_USER_TARGET="";var SYSTEM_USER_PERMISSIN_LIST=[];function systemUserOnLoad(){var pageTitle="Dados pessoais";var wc="UTIINFO";var pagePermission="0000";const urlParams=new URLSearchParams(window.location.search);if(urlParams.has('sender')){wc=urlParams.get('sender')}
if(wc=="UTICAD"){pagePermission="2001";pageTitle="Cadastro de utilizador"}
SYSTEM_USER_WHO_CALL=wc;setPageTitleWhoCall(pagePermission,wc,pageTitle);showNotification();function suoLoad(){var userId=(wc=="UTIINFO")?SYSTEM_USER_STATUS.userId:-1;setSystemUserBillingProfile();fillSelectSystemUserTitle('selUtiCadTitle');fillSelectSystemUserBillingProfile('selUtiCadBillingprofile');fillSelectSystemUserPermissionLevel('selUtiCadPermissionLevel');fillSelectDependencyFull('selUtiCadDependency',-1,1);systemUserGetUserInfo(userId);const divButtons=document.getElementById('divButtonsBar');divButtons.innerHTML="";if((wc=="UTICAD")||(wc=="UDAUTICAD")){let btSearch=document.createElement("button");btSearch.setAttribute("class","mainButton labelSearck-RedDark");btSearch.type="button";btSearch.innerHTML="Procurar utilizador";btSearch.style.marginRight="5px";btSearch.onclick=function(){showDivSearcher('divUserSearch','btUtiProSearchUser')};divButtons.appendChild(btSearch);let btNewUser=document.createElement("button");btNewUser.setAttribute("class","mainButton labelNew-RedDard");btNewUser.type="button";btNewUser.innerHTML="Novo utilizador";btNewUser.style.marginRight="5px";btNewUser.onclick=function(){systemUserGetUserInfo(-1)};divButtons.appendChild(btNewUser)}
let btSave=document.createElement("button");btSave.setAttribute("class","mainButton labelSave-RedDark");btSave.type="button";btSave.innerHTML="Guardar";btSave.onclick=function(){systemUserSaveUser('')};divButtons.appendChild(btSave);let btPrint=document.createElement("button");btPrint.setAttribute("class","mainButton labelPrint-RedDark");btPrint.type="button";btPrint.onclick=function(){printPageA4(document.title)};divButtons.appendChild(btPrint);systemUserAutocomplete('txtUtiCadUserFullName');systemUserSetUploadPhoto();if((wc=="UTICAD")||(wc=="UDAUTICAD")){var userPending=sessionStorage.getItem("systemUserUserId");if((userPending!=null)&&(userPending!="")){systemUserGetUserInfo(userPending)}}
sessionStorage.setItem('systemUserUserId','');systemUserSearchOnLoad();hideNotification()}
checkUserStatusAfterExecute(suoLoad)}
function userCheckLicenseLimit(){if(Number(LICENSE_STATUS.maxusers)>-1){if(Number(LICENSE_STATUS.currentUsers)>=Number(LICENSE_STATUS.maxusers)){showParts('divUtiCadLicenseLimit');return!1}}
return!0}
function systemUserSetUploadPhoto(maxFileSize=1024000,localPathUpLoadFile="USER"){var extList={1:'JPEG',2:'JPG',3:'PNG'};extList=JSON.stringify(extList);var dropzone=document.getElementById(UPLOAD_DIV_DROP_BOX);dropzone.ondragover=dropzone.ondragenter=function(event){event.stopPropagation();event.preventDefault()};dropzone.ondrop=function(event){event.stopPropagation();event.preventDefault();var filesArray=event.dataTransfer.files;for(var i=0;i<filesArray.length;i++){sendFile(filesArray[i],extList,maxFileSize,localPathUpLoadFile,'pUtiCadUploadMsg',"lbUtiCadOldPhoto","lbUtiCadNewPhoto","imgUtiCadPhoto")}}}
function systemUserGetPermissinList(userId){SYSTEM_USER_PERMISSIN_LIST=[];if(!desktopSecurityCheck()){return!1}
var FILTER={};FILTER.sessionId=getSessionId();FILTER.userId=userId;FILTER.target=(SYSTEM_USER_WHO_CALL!="UDAUTICAD")?"":"GME";FILTER.licenseLevel=LICENSE_STATUS.licenselevel;var http=new XMLHttpRequest();var params="action=getSystemUserPermissionList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_SYSTEM_USER_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){const divPermission=document.getElementById('divUtiCadPermissions');divPermission.innerHTML="";var tableRef=document.createElement('tbody');var nRows=0;var permissionGroup="";var permissions=validateSession(http);permissions.forEach(element=>createTbl(element));function createTbl(element){let permission=JSON.parse(element);const permissionCode=permission.permissionCode;let permClassName="class"+permission.groupName.replace(/[^0-9\A-z\-]/g,"")+permission.permissionGroup;SYSTEM_USER_PERMISSIN_LIST[nRows]=permission;nRows+=1;if(permissionGroup!=permission.groupName){permissionGroup=permission.groupName;let divPermGroupSH=document.createElement('div');divPermission.appendChild(divPermGroupSH);divPermGroupSH.style.display="flex";let btHideShow=document.createElement('button');btHideShow.type="button";btHideShow.setAttribute('class','smallButtom');btHideShow.innerHTML="+";btHideShow.id="bt"+permissionGroup.replace(/[^0-9\A-z\-]/g,"");let lbPermGroup=document.createElement('legend');lbPermGroup.style.padding="7px 0";lbPermGroup.innerHTML="Permissões para "+permissionGroup;let rangeStsAll=document.createElement("input");rangeStsAll.type="range";rangeStsAll.min=0;rangeStsAll.max=1;rangeStsAll.name=permClassName;rangeStsAll.value=0;rangeStsAll.onchange=function(){systemUserPerssionGroupChange(this)};if(SYSTEM_USER_WHO_CALL=="UTIINFO"){rangeStsAll.disabled="true"}
divPermGroupSH.appendChild(btHideShow);divPermGroupSH.appendChild(lbPermGroup);divPermGroupSH.appendChild(rangeStsAll);let divPermissinGroup=document.createElement('div');divPermissinGroup.id="div"+permissionGroup.replace(/[^0-9\A-z\-]/g,"");divPermission.appendChild(divPermissinGroup);let tblPerm=document.createElement('table');tblPerm.style.width="100%";divPermissinGroup.appendChild(tblPerm);let tblHeader=document.createElement('thead');tblHeader.setAttribute('class','tblHead1');tblPerm.appendChild(tblHeader);let rwHeader=tblHeader.insertRow(-1);rwHeader.setAttribute('class','tblTdInvoice');let thRw=rwHeader.insertCell(-1);thRw.innerHTML="#";let thPerm=rwHeader.insertCell(-1);thPerm.innerHTML="Permissão";let thLv=rwHeader.insertCell(-1);thLv.innerHTML="Nível";let thSta=rwHeader.insertCell(-1);thSta.innerHTML="Estado";tableRef=document.createElement('tbody');tblPerm.appendChild(tableRef);setSpanHideFieldSet(btHideShow.id,divPermissinGroup.id)}
let newRow=tableRef.insertRow(-1);newRow.setAttribute("class","borderGray");let cellRow=newRow.insertCell(-1);cellRow.setAttribute("class","colRowNumber");cellRow.innerHTML=nRows;let cellPemissionName=newRow.insertCell(-1);cellPemissionName.innerHTML=permission.permissionName;let cellPemissionLevel=newRow.insertCell(-1);cellPemissionLevel.setAttribute("class","colProductId");cellPemissionLevel.innerHTML=permission.level;let cellStatus=newRow.insertCell(-1);let rangeStatus=document.createElement("input");rangeStatus.classList.add(permClassName);rangeStatus.title=permission.level;rangeStatus.type="range";rangeStatus.id="rangeUtiCadPermissionStatus"+nRows;rangeStatus.min=0;rangeStatus.max=1;rangeStatus.name=nRows;rangeStatus.value=permission.permissionstatus;rangeStatus.onchange=function(){systemUserPermissionChange(rangeStatus.name)};if((SYSTEM_USER_WHO_CALL=="UTIINFO")||(Number(SYSTEM_USER_STATUS.permissionlevel)<Number(permission.level))||(!checkPermission('2004'))){rangeStatus.disabled=!0}
cellStatus.appendChild(rangeStatus);cellStatus.style.textAlign="center";cellStatus.style.width="60px"}}};http.send(params)}
function systemUserPermissionChange(nLine){var pStatus=document.getElementById('rangeUtiCadPermissionStatus'+nLine).value;var permission=SYSTEM_USER_PERMISSIN_LIST[Number(nLine)-1];permission.permissionstatus=pStatus}
function systemUserPerssionGroupChange(rangeGroup){var classForLook=rangeGroup.name;var nextValue=rangeGroup.value;const demoClasses=document.getElementsByClassName(classForLook);var divsTeste=Array.prototype.filter.call(demoClasses,function(elementoTeste){if(Number(elementoTeste.title)<=Number(SYSTEM_USER_STATUS.permissionlevel)){elementoTeste.value=nextValue;systemUserPermissionChange(elementoTeste.name)}})}
var USERNAME_STATUS=0;var USERNAME_TRYING=0;function systemUserResetPassOnLoad(a){showNotification();function surpoLoad(){document.getElementById('txtUtiPassUserId').value=SYSTEM_USER_STATUS.userId;document.getElementById('txtUtiPassUserFullName').value=SYSTEM_USER_STATUS.userFullName;hideNotification()}
checkUserStatusAfterExecute(surpoLoad)}
function systemUserResetPassSave(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.desktopkey="";FILTER.userId=document.getElementById('txtUtiPassUserId').value
FILTER.username=SYSTEM_USER_STATUS.email;FILTER.oldPass=document.getElementById('txtUtiPassOldPass').value;FILTER.newPass=document.getElementById('txtUtiPassNewPass').value;FILTER.newPassRepit=document.getElementById('txtUtiPassNewPassRepit').value;var mandatoryField=!1;var msg="";if(FILTER.oldPass==""){mandatoryField=!0;msg="Deve indicar a antiga palavra-passe. <br>"}
if(FILTER.newPass.length<6){mandatoryField=!0;msg+="A nova palavra-passe deve ter no mínimo 6 caracteres. <br>"}
if(FILTER.newPassRepit==""){mandatoryField=!0;msg+="Deve repitir a nova palavra-passe. <br>"}
if(FILTER.newPass!=FILTER.newPassRepit){mandatoryField=!0;msg+="Nova palavra-passe não combina. <br>"}
if(ST_SRH_WAITING_SERVER==1){mandatoryField=!0;msg+="Aguardando resposta do servidor. <br>"}
if(mandatoryField){alert(msg);return!1}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=saveSystemUserResetPassWord"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_SYSTEM_USER_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){ST_SRH_WAITING_SERVER=0;var response=validateSession(http);if(response.status==1){showNotification(response.msg,1);if(ST_SRH_MAIN_WHO_CALL=="INITPAG"){hideParts('divUserPassResetPassword')}}else{showNotification(response.msg,0)}}};http.send(params)}
function fillSelectSystemUserTitle(selectId){const selUserTitle=document.getElementById(selectId);if(selUserTitle!==null){selUserTitle.innerHTML="";for(var i=1;i<SYSTEM_USER_TITLE.length;i++){let optTitle=document.createElement('option');optTitle.value=i;optTitle.innerHTML=SYSTEM_USER_TITLE[i];selUserTitle.appendChild(optTitle)}}}
function fillSelectSystemUserBillingProfile(selectId){const selProfile=document.getElementById(selectId);if(selProfile!==null){selProfile.innerHTML="";var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selProfile.appendChild(optionStart);SYSTEM_USER_BILLING_PROFILE.forEach(fillSel);function fillSel(item,index){if(Number(index)>0){let optProfile=document.createElement('option');optProfile.value=index;optProfile.innerHTML=item;selProfile.appendChild(optProfile)}}}}
function fillSelectSystemUserPermissionLevel(selectId){const selPermission=document.getElementById(selectId);if(selPermission!==null){selPermission.innerHTML="";selPermission.innerHTML="";var optionStart=document.createElement("option");optionStart.value="-1";optionStart.setAttribute('class','selectPlaceHolder');optionStart.innerHTML="Seleccionar";selPermission.appendChild(optionStart);var max=Number(SYSTEM_USER_STATUS.permissionlevel);if(max>0){for(var i=1;i<=max;i++){let optTitle=document.createElement('option');optTitle.value=i;optTitle.innerHTML='Nível '+i;selPermission.appendChild(optTitle)}}}}
function systemUserListOnLoad(){showNotification();setPageTitleWhoCall("2001","UTILIST","Lista de utilizadores cadastrados");function cleanListTbl(){cleanElement('tblUtiLisDetailsTable');cleanElement('tblUtiLisResumeTable');setTriggerButtonByText('txtUtiLisInitialDate','btUTILISViewAll');setTriggerButtonByText('txtUtiLisEndDate','btUTILISViewAll');systemUserListDetails('');document.getElementById('lbResultOnList').innerHTML=0}
function cloLoad(){setSystemUserBillingProfile();fillSelectSystemUserBillingProfile('selUtiLisBillingprofile');fillSelectSystemUserPermissionLevel('selUtiLisPermissionLevel');var date=new Date();setElementValue("txtUtiLisInitialDate",setLocalDate(new Date(date.getFullYear(),date.getMonth(),1),10));setElementValue("txtUtiLisEndDate",setLocalDate(new Date(),10));document.getElementById('txtUtiLisInitialDate').onchange=function(){cleanListTbl()};document.getElementById('txtUtiLisEndDate').onchange=function(){cleanListTbl()};document.getElementById('selUtiLisBillingprofile').onchange=function(){cleanListTbl()};document.getElementById('selUtiLisPermissionLevel').onchange=function(){cleanListTbl()};hideNotification()}
checkUserStatusAfterExecute(cloLoad)}
function systemUserRestartPassOnLoad(){showNotification();setPageTitleWhoCall("2005","UTIREINPASS","Reiniciar palavra passe");function cloLoad(){setSystemUserBillingProfile();systemUserSearchOnLoad();hideNotification()}
checkUserStatusAfterExecute(cloLoad)}
function systemUserSelfRegisterOnLoad(a){document.getElementById('txtUtiCadUserFullName').value="";document.getElementById('txtUtiCadUserName').value="";document.getElementById('txtUtiCadUserEmail').value="";document.getElementById('txtUtiCadNewPass').value="";document.getElementById('txtUtiCadPassRepit').value="";document.getElementById('txtUtiCadUserFullName').focus()}
function systemUserDashBordOnLoad(){showNotification();setPageTitleWhoCall("0000","USERDASHBORD","Painel do operador");function sudboLoad(){var date=new Date();setElementValue("txtUDSBdInitialDate",setLocalDate(new Date(date.getFullYear(),date.getMonth(),1),10));setElementValue("txtUDSBdEndDate",setLocalDate(new Date(),10));systemUserDashBordLoadInfo();hideNotification()}
checkUserStatusAfterExecute(sudboLoad)}
function systemUserDashBordLoadInfo(){systemUserDashBordGetInterest();systemUserDashBordGetOrders();systemUserDashBordGetSales();systemUserDashBordGetComissions()}
var PROMOTION_SILICA_LIST=[]