function TUser()
{
//Функция запрашивает информацию о текущем пользователе с сервера
this.LoadData = function()
{
var r = new TRequest(this);
var xs='';
if(r.callServer(ScriptName,xs))
{
this.showShadow(true);
}
};
this.applyReq=function(req,fn,node)
{
//alert(getXMLNodeSerialisation(node));
this.showShadow(false);
if(fn==7)
{
var nCmd=findFirstNode(node, "cmd");
if(nCmd!=null)
{
if(findFirstNode(nCmd,'#cdata-section').nodeValue=="1") //Logout
{
location.reload();
//window.location.href = '../';
}else if(findFirstNode(nCmd,'#cdata-section').nodeValue=="2") //Check if user not logged
{
if(findNode(node,'#cdata-section').nodeValue=="0") //if not logged
{
this.showLoginForm();
}else
{
this.name=getCdataValue(findNode(node,'name'));
this.surname=getCdataValue(findNode(node,'surname'));
this.patronymic=getCdataValue(findNode(node,'patronymic'));
if (typeof this.onUpdateName !== 'undefined') {
this.onUpdateName(this.name,this.surname,this.patronymic);
}
//configGUIbyAccessLevel();
//var shadow=document.getElementById("shadow");
//if(shadow.parentNode!=null) shadow.parentNode.removeChild(shadow);
}
}else if(findFirstNode(nCmd,'#cdata-section').nodeValue=="3") //Login
{
//if(findNode(node,'#cdata-section').nodeValue=="0") //if not logged
//{
// alert(_('Invalid_username_and_or_password'));
//}else
//{
// location.reload();
//}
}else if(findFirstNode(nCmd,'#cdata-section').nodeValue=="4") //Register
{
//if(findNode(node,'#cdata-section').nodeValue=="1") //if register
//{
// alert(_('New_user_is_registered')+'\n'+_('The_password_has_been_sent_to_you_by_Email'));
// location.reload();
//}
}
}
}
};
//Display login and registration form
this.showLoginForm = function()
{
if(this.win==null || this.win.closed)
{
this.win=new TWin(true);
this.win.TWin(10,10);
this.win.setCaption(_('Authorization'));
this.win.setSize("350px","200px");
var str='
';
this.win.setContent(str);
//Center the window and display the shadow
//if(this.win.tbl.offsetHeight>this.win.div.offsetHeight) this.win.div.style.height=this.win.tbl.offsetHeight+"px";
//if(this.win.tbl.offsetWidth>this.win.div.offsetWidth) this.win.div.style.width=this.win.tbl.offsetWidth+"px";
this.win.setCenter();
this.win.shadow=true;
this.win.hide(false);
//Нажатие на кнопку авторизоваться
var obj=null;
obj=document.getElementById('TLogin_E'+this.uid);
if(obj!==null)
{
obj.onclick=function(thiz)
{
return function()
{
var xs='\
\
\n\
\
\
';
var request=new TRequest(thiz);
if(request.callServer(ScriptName,xs))
{
thiz.win.showProgressBar();
}
};
}(this);
}
}
};
//logout current user
this.Logout = function()
{
xs='';
var request=new TRequest(this);
if(request.callServer(ScriptName,xs))
{
this.showShadow();
}
};
//Checking the session without its extension, if it is completed, we display the authorization window.
this.checkSession = function()
{
$.getJSON('../session',{},function(thiz){return function(data){ if(data.result=='ERROR'){thiz.showLoginForm();} };}(this));
setTimeout(function(thiz){return function(){thiz.checkSession();};}(this), 10000);
};
this.showShadow = function(visible)
{
if(visible)
{
this.divsh=document.createElement('div'); //Тень для модального окна
this.divsh.style.cssText="display: block; position: fixed; z-index:9999; top:0; left:0; height: 100%; width: 100%; background: rgba(0,0,0,0.3);";
document.body.appendChild( this.divsh );
}else
{
deleteHTML(this.divsh);
}
};
//Check whether the already authorized (+ attempt to log in through "hash").
this.isLogined=function()
{
var xs='';
var request=new TRequest(this);
if(request.callServer(ScriptName,xs))
{
this.showShadow(true);
alert(ScriptName+" = "+xs);
//m_winPP.showProgressBar();
}
};
this.divsh=null;
this.id=null;
this.name='';
this.surname='';
this.patronymic='';
this.temp=false;
this.role='';
//Запрашиваю данные о текущем пользователе с сервера
//this.LoadData();
};
/*
* Login form (not cross-source).
* [^\x00-\x7F]+
*/
function TLogin()
{
this.showLoginForm = function()
{
this.win.TWin(10,10);
this.win.shadow=true;
this.win.setCaption(document.createTextNode("Enter"));
var str='';
this.win.setContent(str);
var e=document.getElementById('TLogin_E'+this.uid);
e.onclick=function(obj){ return function(){obj.onEnter(); };}(this);
e=document.getElementById('tcLogin'+this.uid);
e.onkeydown=function(obj){ return function(e){ if(e.which==13) obj.onEnter(); return true; };}(this);
e=document.getElementById('tcPassword'+this.uid);
e.onkeydown=function(obj){ return function(e){ if(e.which==13) obj.onEnter(); return true; };}(this);
this.win.setSize("300px","155px");
this.win.setCenter();
this.win.obj=this;
this.win.hide(false);
};
this.onEnter=function()
{
var login=document.getElementById('tcLogin'+this.uid).value;
var password=document.getElementById('tcPassword'+this.uid).value;
if(login=='' || password=='')
{ str="Not filled in the required fields: ";
if(login=='') str+='"'+_('Login')+' (E-mail)"';
if(login=='' && password=='') str+=', ';
if(password=='') str+='"Password"';
str+='!';
alert(str);
}else
this.Login(login,password,document.getElementById('save_'+this.uid).checked);
};
this.applyReq=function(req,fn,node)
{
// alert(getXMLNodeSerialisation(node));
if (fn==-1)
{
alert(findFirstNode(node,'#cdata-section').nodeValue);
}else if (fn==4)
{
//nodeToTable(node);
}else if (fn==7)
{
var cmd=getCdataValue(findFirstNode(node,"cmd"));
//alert('cmd='+cmd);
if(cmd==='0')
{
this.m_lo=getCdataValue(findFirstNode(node,"login")) == '0' ? false : true;
if(!this.m_lo)
{ this.showLoginForm();
}else
{
var name=getCdataValue(findFirstNode(node,"name"));
var user_name=document.getElementById('user_name');
if(user_name!=null) user_name.innerHTML=name;
//Информируем слушатеелй о логине
for(i=0;i\n\
\n\
';
//alert(xs);
if(this.request.callServer(ScriptName,xs))
{
this.win.showProgressBar();
}
};
//Check whether the already authorized (+ attempt to log in through "hash").
this.Logined=function()
{
var xs='';
//alert('xs='+xs);
this.request.callServer(ScriptName,xs);
};
//logout current user
this.Exit=function()
{
if(this.request.callServer(ScriptName,''))
{
setCookie('GUID', '', 60, '/','','');
showProgressBar(document.body);
}
};
this.addListener=function(l)
{ if(l.OnLogin==null) alert('Object does not have the function "OnLogin()"!');
this.m_ls[this.m_ls.length]=l;
};
this.remListener=function(l)
{ for(i=0;i\n\
\n\
\n\
';
document.getElementById('TWin_Co_'+win.tWinId).innerHTML=str;
win.setSize("300px","100px");
//Центрируем окно и отображаем тень
if(win.tbl.offsetHeight>win.div.offsetHeight) win.div.style.height=win.tbl.offsetHeight+"px";
if(win.tbl.offsetWidth>win.div.offsetWidth) win.div.style.width=win.tbl.offsetWidth+"px";
win.setCenter();
win.shadow=true;
win.hide(false);
//Click on restore button
var obj=null;
obj=document.getElementById(win.uid+'_restore');
if(obj!=null)
{
obj.onclick=function(win)
{ return function()
{
win.showProgressBar();
//showProgressBar(document.getElementById('TWin_DT_'+win.tWinId),win.uid);
var em=document.getElementById(win.uid+'_email').value;
if(em==''){ document.getElementById(win.uid+'_email').select(); alert(_('Not_filled_Email_address')); win.hideProgressBar(); return; }
if(! isEmail(em)){ document.getElementById(win.uid+'_email').select(); alert(_('Please_enter_a_valid_email_address')); win.hideProgressBar(); return; }
//Send AJAX reqwest to server
var xml='\
\
\
\
\
';
//Anonymous object
obj=new function(win)
{
this.processReqChange = function(xmlHttpRequest, url, xmlString)
{
if(typeof(xmlHttpRequest.status)=='undefined' || xmlHttpRequest.status == 200)
{
if(typeof(xmlHttpRequest.responseXML)=='undefined' && xmlHttpRequest.contentType.match(/\/xml/)) //For IE XDomainRequest
xmlHttpRequest.responseXML=CreateXMLDOC(xmlHttpRequest.responseText);
//загрузился xml документ начинаем его разбирать (по id функции в документе)
var xmldoc = xmlHttpRequest.responseXML
if(xmldoc==null) alert(_('Wrong_XML_document')+"!\n"+xmlHttpRequest.responseText);
var node = xmldoc.documentElement;
if((node==null)||(node.getAttribute("fn")==null)) alert(_('Error')+"\n "+_("No_data")+"!\n"+xmlHttpRequest.responseText);
else
{
//alert("Принятый браузером XML=\n"+getXMLNodeSerialisation(node));
var fn = node.getAttribute("fn");
if (fn==-1)
{
alert(findFirstNode(node,'#cdata-section').nodeValue);
this.win.hideProgressBar();
}else
if(fn==7)
{
alert(findFirstNode(node,'#cdata-section').nodeValue);
this.win.Close();
}
}
}else
{
if(confirm(_('Failed_to_get_data')+"\n URL: "+url+"\n"+xmlHttpRequest.statusText+"\nRedo the request?"))
{
var call=new myXMLHttpRequest(this);
call.callServer(url,xmlString);
}
}
return null;
};
this.win=win; //For close after showing message.
}
(win);
var call=new myXMLHttpRequest(obj);
call.callServer(ScriptName,xml);
};
}(win);
}
}