-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredmine.min.js
148 lines (140 loc) · 113 KB
/
redmine.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* 0.2.10 взаимодействие с redmine по средствам api
cscript redmine.min.js <instance> <method> [... <param>]
cscript redmine.min.js <instance> users.sync <source> <fields> [<auth>]
cscript redmine.min.js <instance> issues.sync <destination> <query> [<filters>] <fields>
cscript redmine.min.js <instance> issues.change [<query>] [<filters>] <fields>
<instance> - Адрес для подключения к Redmine в формате url (с указанием логина, пароля или ключа во фрагменте).
<method> - Собственный метод, который нужно выполнить.
users.sync - Синхранизация пользователей из источника данных.
<source> - Адрес для подключения к Active Directory в формате url (поддерживается протокол ldap).
<fields> - Поля и их значения в источнике в формате ID:value;id:value с шаблонизацией.
<auth> - Идентификатор режима аутентификации в Redmine.
issues.sync - Синхранизация задач в приёмник данных.
<destination> - Адрес для подключения к Cherwell в формате url (с указанием логина, пароля или клиента во фрагменте).
<query> - Идентификатор сохранённого запроса для всех проектов в Redmine и Cherwell.
<filters> - Фильтр в формате id:value,value;id:value,value с шаблонизацией.
<fields> - Поля и их значения в формате id:value;id:value с шаблонизацией.
issues.change - Изменение задач в Redmine.
<query> - Идентификатор сохранённого запроса для всех проектов.
<filters> - Фильтр в формате id:value,value;id:value,value с шаблонизацией.
<fields> - Поля и их значения в формате id:value;id:value с шаблонизацией.
*/
// 0.3.16 конструктор основного приложения
function App(a){this.val=a};
// 0.3.5 библиотека функций общего назначения
(function(q,D){q.lib={strFirstUpperCase:function(a){return a.substr(0,1).toUpperCase()+a.substr(1)},clone:function(a){switch(!0){case q.lib.validate(a,"date"):var b=new Date(a);break;case q.lib.validate(a,"array"):b=[];for(var c=0,d=a.length;c<d;c++)b[c]=q.lib.clone(a[c]);break;case q.lib.validate(a,"object"):b={};for(c in a)b[c]="prototype"!==c?q.lib.clone(a[c]):a[c];break;default:b=a}return b},compare:function(a,b,c){var d=0;b||(b=null);switch(!0){case q.lib.validate(a,"string"):b=q.lib.convert(b,
"string");c&&(a=a.toLowerCase(),b=b.toLowerCase());break;case q.lib.validate(a,"array"):b=b&&b.length?b.length:0;a=a.length;break;case q.lib.validate(a,"date"):b=b&&b.valueOf()?b.valueOf():0,a=a.valueOf()}a>b&&(d=1);a<b&&(d=-1);return d},difference:function(a,b,c){var d;c||(c=q.lib.compare);if(q.lib.validate(a,"array")){b||(b=[]);for(var e=0,h=a.length;e<h;e++){var n=a[e];for(var g=0,f=b.length;g<f;g++){var k=b[g];if(value=c(n,k))d||(d=[]),d.push(n)}}}else if(q.lib.validate(a,"object"))for(e in b||
(b={}),a)n=a[e],k=b[e],value=q.lib.difference(n,k,c),q.lib.validate(value,"undefined")||(d||(d={}),d[e]=value);else(value=q.lib.compare(a,b))&&(d=a);return d},strim:function(a,b,c,d,e){var h="";a=a?a.toString():h;b=b?b.toString():h;c=c?c.toString():h;if(e){var n=c?a.lastIndexOf(c):a.length;e=b&&~n?a.lastIndexOf(b,n-1):0}else e=b?a.indexOf(b):0,n=c&&~e?a.indexOf(c,e+b.length):a.length;~e&&~n&&(e=d?e:e+b.length,n=d?n+c.length:n,h=a.substr(e,n-e));return h},trim:function(a){return(a||"").replace(/^\s+|\s+$/g,
"")},validate:function(a,b){var c;switch(b){case "email":b="^([a-z0-9_-]+.)*[a-z0-9_-]+@[a-z0-9_-]+(.[a-z0-9_-]+)*.[a-z]{2,6}$";break;case "password":b="(?=^.{8,}$)((?=.*d)|(?=.*W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$";break;case "guid":b="^{[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}}$";break;case "md5":b="^[0-9a-fA-F]{32}$"}switch(b){case "boolean":a=!0===a||!1===a;break;case "string":a="[object String]"===Object.prototype.toString.call(a);break;case "number":a="[object Number]"===Object.prototype.toString.call(a);
break;case "function":a="[object Function]"===Object.prototype.toString.call(a);break;case "form":a=!(!a||!a.tagName||"form"!==a.tagName.toLowerCase());break;case "files":a="[object FileList]"===Object.prototype.toString.call(a);break;case "date":a="[object Date]"===Object.prototype.toString.call(a);break;case "array":a=Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a);break;case "xml":a=!(!a||!(c=(a.ownerDocument||a).documentElement)||"html"===c.nodeName.toLowerCase());
break;case "undefined":a=void 0===a;break;case "null":a=null===a;break;case "object":a=a===Object(a)&&"[object Null]"!==Object.prototype.toString.call(a)&&"[object Date]"!==Object.prototype.toString.call(a)&&"[object Function]"!==Object.prototype.toString.call(a)&&"[object FileList]"!==Object.prototype.toString.call(a)&&"[object Array]"!==Object.prototype.toString.call(a)&&!(a&&(c=(a.ownerDocument||a).documentElement)&&"html"!==c.nodeName.toLowerCase())&&!(a&&a.tagName&&"form"===a.tagName.toLowerCase());
break;default:a=(new RegExp(b)).test(""+a)}return a},obj2str:function(a,b,c,d,e){var h=[];c||(c="&");d||(d="=");e||(e=",");for(var n in a){var g=a[n];var f=b?encodeURIComponent(n):n;switch(!0){case q.lib.validate(g,"array"):g=g.join(e);case !q.lib.validate(g,"undefined"):f+=d,f+=b?encodeURIComponent(g):g}h.push(f)}return h.join(c)},str2obj:function(a,b,c,d){var e,h={};c||(c="&");d||(d="=");c=a.split(c);for(var n=0,g=c.length;n<g;n++)if(e=c[n])e=e.split(d,2),a=e[0],e=e[1],a=b?decodeURIComponent(a):
a,e=b&&e?decodeURIComponent(e):e,h[a]=e;return h},url2obj:function(a){var b={},c=!1;a=a?""+a:"";var d="fragment";var e="#";-1!=a.indexOf(e)&&(b[d]=q.lib.strim(a,e,null,!1),a=q.lib.strim(a,null,e,!1));d="query";e="?";-1!=a.indexOf(e)&&(b[d]=q.lib.strim(a,e,null,!1),a=q.lib.strim(a,null,e,!1));d="scheme";e="//";0==a.indexOf(e)&&(b[d]=q.lib.strim(a,null,e,!1),a=q.lib.strim(a,e,null,!1),c=!0);d="path";e="/";a.indexOf("://")>a.indexOf(e)&&(b[d]=q.lib.strim(a,e,null,!0),a=q.lib.strim(a,null,e,!1));d="path";
e="://";0==a.indexOf(e)&&(b[d]=q.lib.strim(a,e,null,!0),a=q.lib.strim(a,null,e,!1));d="scheme";e="://";!c&&0<a.indexOf(e)&&(b[d]=q.lib.strim(a,null,e,!1),a=q.lib.strim(a,e,null,!1),c=!0);d="path";e="/";c&&-1!=a.indexOf(e)&&(b[d]=q.lib.strim(a,e,null,!0),a=q.lib.strim(a,null,e,!1));d="path";e=a.length;!c&&0<e&&(b[d]=a,a="");e="@";if(-1!=a.indexOf(e)){var h=q.lib.strim(a,e,null,!1);a=q.lib.strim(a,null,e,!1);d="password";e=":";-1!=a.indexOf(e)&&(b[d]=q.lib.strim(a,e,null,!1),a=q.lib.strim(a,null,e,
!1));b.user=a;a=h}d="port";e=":";-1!=a.indexOf(e)&&(b[d]=q.lib.strim(a,e,null,!1),a=q.lib.strim(a,null,e,!1));c&&(b.domain=a);return b},obj2url:function(a){var b="";"user"in a&&(b="//");"password"in a&&(b="//");"domain"in a&&(b="//");"port"in a&&(b="//");var c="scheme";a[c]&&(b="://");var d=""+((a[c]?a[c]:"")+b);c="user";c in a&&(d+=""+a[c]);c="password";c in a&&(d+=":"+a[c]);b="";"user"in a&&(b="@");"password"in a&&(b="@");c="domain";d+=b+(a[c]?a[c]:"");c="port";c in a&&(d+=":"+a[c]);c="path";c in
a&&(d+=""+a[c]);c="query";c in a&&(d+="?"+a[c]);c="fragment";c in a&&(d+="#"+a[c]);return d},obj2arr:function(a,b){var c=[];switch(!0){case q.lib.validate(b,"string"):case q.lib.validate(b,"number"):var d=b;b=function(n){n||(n={});return n[d]}}for(var e in a){var h=a[e];h=b?b(h,e,a):h;q.lib.validate(h,"undefined")||c.push(h)}return c},arr2obj:function(a,b,c){var d={};switch(!0){case q.lib.validate(b,"string"):case q.lib.validate(b,"number"):var e=b;b=function(p){p||(p={});return p[e]}}switch(!0){case q.lib.validate(c,
"string"):case q.lib.validate(c,"number"):var h=c;c=function(p){p||(p={});return p[h]}}for(var n=0,g=a.length;n<g;n++){var f=a[n];var k=c?c(f,n,a):n;f=b?b(f,n,a):f;q.lib.validate(f,"undefined")||q.lib.validate(k,"undefined")||(d[k]=f)}return d},convert:function(a,b){switch(b){case "bool":case "boolean":a="true"===a?!0:"false"===a?!1:!!a;break;case "int":case "integer":case "float":case "double":case "real":case "number":a=Number(a);break;case "date":a=new Date(1E3*Number(a));break;case "string":q.lib.validate(a,
"boolean")?a=a?"true":"false":q.lib.validate(a,"date")?(a=a.valueOf()/1E3,a=a.toString()):a=q.lib.validate(a,"number")?a.toString():a&&a.toString?a.toString():"";break;case "auto":q.lib.validate(a,"string")&&(b=a.split('"'),3!=b.length||b[0]||b[2]||(a=b[1]),b=a.split("'"),3!=b.length||b[0]||b[2]||(a=b[1]),q.lib.compare("true",a,!0)?q.lib.compare("false",a,!0)?q.lib.compare("null",a,!0)?a.length&&!isNaN(a)&&(a=Number(a)):a=null:a=!1:a=!0)}return a},xhr:function(a,b,c,d,e,h,n,g){var f,k=6E5,p=0;var m=
f={responseText:""};var w=null;if(!p){var r=a?""+a:"get";a=r.toUpperCase();switch(a.toLowerCase()){case "get":w=!0;break;case "head":w=!0;break;case "delete":w=!0}}if(!p){var t=function(){};var v={upload:t,download:t,success:t,error:t,complete:t};if(q.lib.validate(h,"function"))v.complete=h;else if(h)for(u in v)t=h[u],q.lib.validate(t,"function")&&(v[u]=t);h=v}if(!p){v={"X-Requested-With":"XMLHttpRequest"};if(!1===c){var u="X-Requested-With";u in v&&delete v[u]}if(q.lib.validate(c,"object"))for(u in c)switch(t=
c[u],u.toLowerCase()){case "cookie":break;case "host":break;default:v[u]=t}c=v}if(!p){d=d?d:"";if(q.lib.validate(d,"form")){v={};for(var x=0,y=d.elements.length;x<y;x++)t=d.elements[x],t.name&&!t.disabled&&(u=(""+t.type).toLowerCase(),"checkbox"==u||"radio"==u?t.checked&&(v[t.name]=t.value?t.value:!0):v[t.name]=t.files&&t.files.length?t.files:t.value?t.value:D);d=v}q.lib.validate(d,"xml")&&(w=!1,c["Content-Type"]="application/xml",d.xml?d=d.xml:(v=new XMLSerializer,d=v.serializeToString(d)));if(q.lib.validate(d,
"object")){v=!1;for(u in d)if(t=d[u],q.lib.validate(t,"files")){w=!1;v=!0;break}if(v)for(u in v=new FormData,d)if(t=d[u],q.lib.validate(t,"files")){var z=d[u];x=0;for(y=z.length;x<y;x++)t=z[x],v.append(u,t)}else q.lib.validate(t,"undefined")&&(t=""),v.append(u,t);else d=q.lib.obj2str(d,!0),!w&&d&&(c["Content-Type"]="application/x-www-form-urlencoded")}}p||(r=b?""+b:"",w&&d&&(r=r?~r.indexOf("?")?r+"&":r+"?":r+"?",r+=d,d=""),b=r);if(!p){v=null;if(!v)try{v=new XMLHttpRequest}catch(A){}if(!v)for(w="$#!&%",
z=["Ms$#!&%xm$#!&%l2$#!&%.XM$#!&%LHT$#!&%TP.6.0","Ms$#!&%xm$#!&%l2$#!&%.XM$#!&%LHT$#!&%TP.3.0","Ms$#!&%xm$#!&%l2$#!&%.XM$#!&%LHT$#!&%TP","Micr$#!&%osoft$#!&%.XM$#!&%LH$#!&%TTP"],x=0,y=z.length;!v&&x<y;x++){t=z[x];r=t.split(w).join("");try{v=new ActiveXObject(r)}catch(A){}}v?m=v:p=1}if(!p){try{k=setTimeout(function(){r=m.responseText?m.responseText:"";m.abort();h.error(r,m);h.complete(r,m)},k)}catch(A){}m.upload&&(m.upload.onprogress=function(A){A.total&&A.loaded!=A.total&&h.upload(A,m)},m.onprogress=
function(A){A.total&&A.loaded!=A.total&&h.download(A,m)});m.onreadystatechange=function(A){if(4==m.readyState){try{clearTimeout(k)}catch(B){}u=m.status?m.status:200;r=m.responseText?m.responseText:"";200<=u&&300>u&&r?h.success(r,m):h.error(r,m);h.complete(r,m)}}}if(!p)try{g?m.open(a,b,e,n,g):n?m.open(a,b,e,n):m.open(a,b,e)}catch(A){m=f,p=2}if(!p)for(u in c)r=c[u],w="; ",q.lib.validate(r,"array")&&(z=r,r=z.join(w)),m.setRequestHeader(u,r);if(!p)try{d?m.send(d):m.send()}catch(A){m=f,p=3}if(1<p)try{clearTimeout(k)}catch(A){}p&&
(r="",h.error(r,m),h.complete(r,m));return m},ajax:function(a,b,c,d,e){return q.lib.xhr(a,b,c,d,!0,e)},sjax:function(a,b,c,d){return q.lib.xhr(a,b,c,d,!1)},strPad:function(a,b,c,d){var e,h=e="",n=function(g,f){for(;h.length<f;)h+=g;return h=h.substr(0,f)};a=""+a;c=c?""+c:" ";"left"!=d&&"right"!=d&&"both"!=d&&(d="right");0<(e=b-a.length)&&("left"==d?a=n(c,e)+a:"right"==d?a+=n(c,e):"both"==d&&(e=n(c,Math.ceil(e/2)),a=(e+a+a).substr(0,b)));return a},getCookie:function(a,b){var c=document.cookie.indexOf(a+
"="),d=c+a.length+1;if(!c&&a!=document.cookie.substring(0,a.length)||-1==c)return null;a=document.cookie.indexOf(";",d);-1==a&&(a=document.cookie.length);return b?decodeURIComponent(document.cookie.substring(d,a)):unescape(document.cookie.substring(d,a))},setCookie:function(a,b,c,d,e,h,n){var g=new Date((new Date).valueOf()+c);document.cookie=a+"="+(n?encodeURIComponent(b):escape(b))+(c?";expires="+g.toGMTString():"")+(d?";path="+d:"")+(e?";domain="+e:"")+(h?";secure":"");return!0},delCookie:function(a,
b,c){q.lib.getCookie(a)&&(document.cookie=a+"="+(b?";path="+b:"")+(c?";domain="+c:"")+";expires=Thu, 01-Jan-1970 00:00:01 GMT");return!0},getStorage:function(a,b){var c,d=null,e=null;if(c=window&&window.localStorage?localStorage.getItem(a):q.lib.getCookie(a)){var h=c.indexOf("?");-1!=h&&(type=c.substr(0,h),c=c.substr(h+1));b?(c=c.split("&"),!0!==b&&(c.length=Math.min(b,c.length))):c=[c];for(var n=0,g=c.length;n<g;n++){h=c[n].indexOf("=");if(-1!=h){if(a=c[n].substr(0,h),a=decodeURIComponent(a),d=c[n].substr(h+
1),!e){var f=!0;e={}}}else a=n,d=c[n],e||(f=!1,e=[]);d=decodeURIComponent(d);type&&(d=q.lib.convert(d,type));f?e[a]=d:e.push(d)}}else e=null;return b?e:d},setStorage:function(a,b){var c,d=[];var e=function(f,k){c||(c=q.lib.validate(f,"number")?"number":q.lib.validate(f,"date")?"date":q.lib.validate(f,"boolean")?"boolean":"string");f=q.lib.convert(f,"string");f=encodeURIComponent(f);q.lib.validate(k,"undefined")?d.push(f):(k=encodeURIComponent(k),d.push(k+"="+f))};if(q.lib.validate(b,"object"))for(var h in b)e(b[h],
h);else if(q.lib.validate(b,"array")){h=0;for(var n=b.length;h<n;h++)e(b[h])}else q.lib.validate(b,"null")||e(b);if(d=d.join("&"))if(d=c+"?"+d,window&&window.localStorage)try{localStorage.setItem(a,d);var g=!0}catch(f){g=!1}else g=q.lib.setCookie(a,d,31536E7,location.pathname,document.domain);else window&&window.localStorage?(localStorage.removeItem(a),g=!0):g=q.lib.delCookie(a,location.pathname,document.domain);return g},counter:function(){var a={};return function(b,c){var d=0;q.lib.validate(b,"array")&&
b.join("_");b&&(a[b]=a[b]||0,d=a[b],!1===c?delete a[b]:!0===c?a[b]++:c&&(a[b]+=c));return d}}(),on:function(){var a={};return function(b,c,d){var e,h=[],n=0;b=b.toString().split(/\s+/);for(var g=0,f=b.length;g<f;g++)if(e=b[g])if(a[e]||(a[e]=[0]),d)if(c){a[e][c]||(a[e][c]=[]);var k=a[e][c].length;a[e][c][k]=d;a[e][0]>=c&&h.push([e,c,k]);n++}else{k=1;for(var p=a[e].length;k<p;k++)if(a[e][k])for(var m=0,w=a[e][k].length;m<w;m++)a[e][k][m]===d&&(delete a[e][k][m],n++)}else if(a[e][0]++,c=c||a[e][0],a[e][c])for(k=
0;k<a[e][c].length;k++)a[e][c][k]&&h.push([e,c,k]),n++;g=0;for(f=h.length;g<f;g++)e=h[g][0],c=h[g][1],k=h[g][2],a[e]&&a[e][c]&&a[e][c][k]&&a[e][c][k].call(a[e][c][k],c);return n}}(),href:function(a){var b=document.createElement("a");b.href=a;return b.cloneNode(!1).href},getExt:function(a){var b="";var c=(""+a).lastIndexOf(".");-1!==c&&(b=a.substr(c+1),b=b.toLowerCase());return b},md5:function(a){var b=function(u,x){var y=u&2147483648;var z=x&2147483648;var A=u&1073741824;var B=x&1073741824;u=(u&1073741823)+
(x&1073741823);return A&B?u^2147483648^y^z:A|B?u&1073741824?u^3221225472^y^z:u^1073741824^y^z:u^y^z},c=function(u,x,y,z,A,B,C){u=b(u,b(b(x&y|~x&z,A),C));return b(u<<B|u>>>32-B,x)},d=function(u,x,y,z,A,B,C){u=b(u,b(b(x&z|y&~z,A),C));return b(u<<B|u>>>32-B,x)},e=function(u,x,y,z,A,B,C){u=b(u,b(b(x^y^z,A),C));return b(u<<B|u>>>32-B,x)},h=function(u,x,y,z,A,B,C){u=b(u,b(b(y^(x|~z),A),C));return b(u<<B|u>>>32-B,x)},n=function(u){var x="",y;for(y=0;3>=y;y++){var z=u>>>8*y&255;z="0"+z.toString(16);x+=z.substr(z.length-
2,2)}return x},g=[];a=function(u){u=u.replace(/\r\n/g,"\n");for(var x="",y=0;y<u.length;y++){var z=u.charCodeAt(y);128>z?x+=String.fromCharCode(z):(127<z&&2048>z?x+=String.fromCharCode(z>>6|192):(x+=String.fromCharCode(z>>12|224),x+=String.fromCharCode(z>>6&63|128)),x+=String.fromCharCode(z&63|128))}return x}(a.toString());g=function(u){var x=u.length;var y=x+8;for(var z=16*((y-y%64)/64+1),A=Array(z-1),B,C=0;C<x;)y=(C-C%4)/4,B=C%4*8,A[y]|=u.charCodeAt(C)<<B,C++;y=(C-C%4)/4;A[y]|=128<<C%4*8;A[z-2]=
x<<3;A[z-1]=x>>>29;return A}(a);var f=1732584193;var k=4023233417;var p=2562383102;var m=271733878;for(a=0;a<g.length;a+=16){var w=f;var r=k;var t=p;var v=m;f=c(f,k,p,m,g[a+0],7,3614090360);m=c(m,f,k,p,g[a+1],12,3905402710);p=c(p,m,f,k,g[a+2],17,606105819);k=c(k,p,m,f,g[a+3],22,3250441966);f=c(f,k,p,m,g[a+4],7,4118548399);m=c(m,f,k,p,g[a+5],12,1200080426);p=c(p,m,f,k,g[a+6],17,2821735955);k=c(k,p,m,f,g[a+7],22,4249261313);f=c(f,k,p,m,g[a+8],7,1770035416);m=c(m,f,k,p,g[a+9],12,2336552879);p=c(p,m,
f,k,g[a+10],17,4294925233);k=c(k,p,m,f,g[a+11],22,2304563134);f=c(f,k,p,m,g[a+12],7,1804603682);m=c(m,f,k,p,g[a+13],12,4254626195);p=c(p,m,f,k,g[a+14],17,2792965006);k=c(k,p,m,f,g[a+15],22,1236535329);f=d(f,k,p,m,g[a+1],5,4129170786);m=d(m,f,k,p,g[a+6],9,3225465664);p=d(p,m,f,k,g[a+11],14,643717713);k=d(k,p,m,f,g[a+0],20,3921069994);f=d(f,k,p,m,g[a+5],5,3593408605);m=d(m,f,k,p,g[a+10],9,38016083);p=d(p,m,f,k,g[a+15],14,3634488961);k=d(k,p,m,f,g[a+4],20,3889429448);f=d(f,k,p,m,g[a+9],5,568446438);
m=d(m,f,k,p,g[a+14],9,3275163606);p=d(p,m,f,k,g[a+3],14,4107603335);k=d(k,p,m,f,g[a+8],20,1163531501);f=d(f,k,p,m,g[a+13],5,2850285829);m=d(m,f,k,p,g[a+2],9,4243563512);p=d(p,m,f,k,g[a+7],14,1735328473);k=d(k,p,m,f,g[a+12],20,2368359562);f=e(f,k,p,m,g[a+5],4,4294588738);m=e(m,f,k,p,g[a+8],11,2272392833);p=e(p,m,f,k,g[a+11],16,1839030562);k=e(k,p,m,f,g[a+14],23,4259657740);f=e(f,k,p,m,g[a+1],4,2763975236);m=e(m,f,k,p,g[a+4],11,1272893353);p=e(p,m,f,k,g[a+7],16,4139469664);k=e(k,p,m,f,g[a+10],23,3200236656);
f=e(f,k,p,m,g[a+13],4,681279174);m=e(m,f,k,p,g[a+0],11,3936430074);p=e(p,m,f,k,g[a+3],16,3572445317);k=e(k,p,m,f,g[a+6],23,76029189);f=e(f,k,p,m,g[a+9],4,3654602809);m=e(m,f,k,p,g[a+12],11,3873151461);p=e(p,m,f,k,g[a+15],16,530742520);k=e(k,p,m,f,g[a+2],23,3299628645);f=h(f,k,p,m,g[a+0],6,4096336452);m=h(m,f,k,p,g[a+7],10,1126891415);p=h(p,m,f,k,g[a+14],15,2878612391);k=h(k,p,m,f,g[a+5],21,4237533241);f=h(f,k,p,m,g[a+12],6,1700485571);m=h(m,f,k,p,g[a+3],10,2399980690);p=h(p,m,f,k,g[a+10],15,4293915773);
k=h(k,p,m,f,g[a+1],21,2240044497);f=h(f,k,p,m,g[a+8],6,1873313359);m=h(m,f,k,p,g[a+15],10,4264355552);p=h(p,m,f,k,g[a+6],15,2734768916);k=h(k,p,m,f,g[a+13],21,1309151649);f=h(f,k,p,m,g[a+4],6,4149444226);m=h(m,f,k,p,g[a+11],10,3174756917);p=h(p,m,f,k,g[a+2],15,718787259);k=h(k,p,m,f,g[a+9],21,3951481745);f=b(f,w);k=b(k,r);p=b(p,t);m=b(m,v)}return(n(f)+n(k)+n(p)+n(m)).toLowerCase()},sha256:function(a){var b=function(d,e){var h=(d&65535)+(e&65535);return(d>>16)+(e>>16)+(h>>16)<<16|h&65535},c=function(d,
e){return d>>>e|d<<32-e};a=function(d){d=d.replace(/\r\n/g,"\n");for(var e="",h=0;h<d.length;h++){var n=d.charCodeAt(h);128>n?e+=String.fromCharCode(n):(127<n&&2048>n?e+=String.fromCharCode(n>>6|192):(e+=String.fromCharCode(n>>12|224),e+=String.fromCharCode(n>>6&63|128)),e+=String.fromCharCode(n&63|128))}return e}(a);return function(d){for(var e="",h=0;h<4*d.length;h++)e+="0123456789abcdef".charAt(d[h>>2]>>8*(3-h%4)+4&15)+"0123456789abcdef".charAt(d[h>>2]>>8*(3-h%4)&15);return e}(function(d,e){var h=
[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,
275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],n=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],g=Array(64),f,k;d[e>>5]|=128<<24-e%32;d[(e+64>>9<<4)+15]=e;for(f=0;f<d.length;f+=16){e=n[0];var p=n[1];var m=n[2];var w=n[3];var r=n[4];var t=n[5];var v=n[6];var u=n[7];for(k=0;64>k;k++){if(16>k)g[k]=d[k+f];else{var x=k;var y=g[k-
2];y=c(y,17)^c(y,19)^y>>>10;y=b(y,g[k-7]);var z=g[k-15];z=c(z,7)^c(z,18)^z>>>3;g[x]=b(b(y,z),g[k-16])}x=r;x=c(x,6)^c(x,11)^c(x,25);x=b(b(b(b(u,x),r&t^~r&v),h[k]),g[k]);u=e;u=c(u,2)^c(u,13)^c(u,22);y=b(u,e&p^e&m^p&m);u=v;v=t;t=r;r=b(w,x);w=m;m=p;p=e;e=b(x,y)}n[0]=b(e,n[0]);n[1]=b(p,n[1]);n[2]=b(m,n[2]);n[3]=b(w,n[3]);n[4]=b(r,n[4]);n[5]=b(t,n[5]);n[6]=b(v,n[6]);n[7]=b(u,n[7])}return n}(function(d){for(var e=[],h=0;h<8*d.length;h+=8)e[h>>5]|=(d.charCodeAt(h/8)&255)<<24-h%32;return e}(a),8*a.length))},
parseJSON:function(a){if(window&&window.JSON&&JSON.parse)try{var b=JSON.parse(a)}catch(c){b=eval("("+a+")")}else b=eval("("+a+")");return b},numDeclin:function(a,b,c,d){a=Number(a);a=Math.abs(a);a=Math.floor(a);var e=a%10;return 1!=(a%100-e)/10?0==e?b:1==e?c:5>e?d:b:b},num2str:function(a,b,c,d){var e,h;isNaN(b=Math.abs(b))&&(b=2);c==D&&(c=",");d==D&&(d=".");if(h=0>a)a=Math.abs(a);var n=parseInt(a=(+a||0).toFixed(b))+"";var g=(e=3<(e=n.length)?e%3:0)?n.substr(0,e)+d:"";d=n.substr(e).replace(/(\d{3})(?=\d)/g,
"$1"+d);a=b?c+Math.abs(a-n).toFixed(b).replace(/-/,0).slice(2):"";return(h?"-":"")+g+d+a},num2word:function(a,b,c){function d(u,x){u=u.toString().substr(-2);return x[0]+(/^[0,2-9]?[1]$/.test(u)?x[2]:/^[0,2-9]?[2-4]$/.test(u)?x[3]:x[1])}var e=[],h=[["ноль"],[,,,"три","четыре","пять","шесть","семь","восемь","девять"],"десять одиннадцать двенадцать тринадцать четырнадцать пятнадцать шестнадцать семнадцать восемнадцать девятнадцать".split(" "),[,,"двадцать","тридцать","сорок","пятьдесят","шестьдесят",
"семьдесят","восемьдесят","девяносто"],[,"сто","двести","триста","четыреста","пятьсот","шестьсот","семьсот","восемьсот","девятьсот"],[[,"один","два"],[,"одна","две"],[,"одно","два"]]],n=[["...ллион","ов","","а"],["тысяч","","а","и"],["миллион","ов","","а"],["миллиард","ов","","а"],["триллион","ов","","а"],["квадриллион","ов","","а"],["квинтиллион","ов","","а"],["секстилион","ов","","а"],["септилион","ов","","а"],["окталион","ов","","а"],["ноналион","ов","","а"],["декалион","ов","","а"],["эндекалион",
"ов","","а"],["додекалион","ов","","а"]],g=[[["цел","ых","ый","ых"],["цел","ых","ая","ых"],["цел","ых","ое","ых"]],["десят","ых","ая","ых"],["сот","ых","ая","ых"],["тясячн","ых","ая","ых"],["десятитысячн","ых","ая","ых"],["стотысячн","ых","ая","ых"],["милионн","ых","ая","ых"],["десятимилионн","ых","ая","ых"]];c=c||0;a=a.toString().split(".");for(var f=0,k=a.length;f<k;f++){f&&(a[f]=a[f].substr(0,g.length-1));l=a[f].length;a[f]=["","00","0"][a[f].split(/\d{3}/).join("").length]+a[f];for(var p=a[f].length,
m,w=0,r=-1,t=[];3*w<p;){m=a[f].substr(-3*(w+1),3);t[++r]=[];for(var v=0;2>=v;v++)if(0!=m[v])switch(v){case 0:t[r][t[r].length]=h[4][m[v]];break;case 1:1==m[v]?(t[r][t[r].length]=h[2][m[2]],v=3):t[r][t[r].length]=h[3][m[v]];break;case 2:t[r][t[r].length]=2>=m[v]?h[5][1==w||f?1:c][m[v]]:h[1][m[v]]}t[r].length||(t[r][t[r].length]=h[0][0]);0<m&&0<w&&(t[r][t[r].length]=d(m,n[w]));!w&&1<k&&(t[r][t[r].length]=d(m,f?g[l]:g[0][c]));w||!b||f||f!=k-1?!w&&b&&f&&(t[r][t[r].length]=b[0]+b[3]):t[r][t[r].length]=
d(m,b);t[r]=t[r].join(" ");w++}e[e.length]=t.reverse().join(" ")}return e.join(" ")},date2str:function(a,b){var c="Воскресенье Понедельник Вторник Среда Четверг Пятница Суббота".split(" "),d=" Января Февраля Марта Апреля Мая Июня Июля Августа Сентября Октября Ноября Декабря".split(" "),e={0:"ый",2:"ой",3:"ий",6:"ой",7:"ой",8:"ой",22:"ой",26:"ой",27:"ой",28:"ой"},h={"-660":"ST","-600":"HAST","-540":"AKT","-480":"AWST","-420":"CXT","-360":"СST","-300":"EST","-240":"AST","-210":"NST","-180":"ART",0:"GMT",
60:"CET",120:"CAT",180:"MSK",210:"IRST",300:"PKT",330:"IST",360:"BDT",390:"MST",420:"CXT",480:"AWST",540:"JST",570:"ACST",600:"AEST",660:"NFT"},n="";var g=function(w){var r="";switch(w){case "d":r+=q.lib.strPad(g("j"),2,"0","left");break;case "D":r+=g("l").substr(0,3);break;case "j":r+=a.getDate();break;case "l":r+=c[g("w")];break;case "N":r+=g("w")||7;break;case "S":r+=e[g("j")]||e[0];break;case "w":r+=a.getDay();break;case "z":r+=(a-new Date(a.getFullYear(),0,1))/864E5>>0;break;case "W":w=new Date(a.valueOf());
var t=(a.getDay()+6)%7;w.setDate(w.getDate()-t+3);t=w.valueOf();w.setMonth(0,1);4!==w.getDay()&&w.setMonth(0,1+(4-w.getDay()+7)%7);r+=1+Math.ceil((t-w)/6048E5);break;case "F":r+=d[g("n")];break;case "m":r+=q.lib.strPad(g("n"),2,"0","left");break;case "M":r+=g("F").substr(0,3);break;case "n":r+=a.getMonth()+1;break;case "t":r+=(new Date(a.getFullYear(),a.getMonth()+1,0)).getDate();break;case "L":r+=a.getFullYear()&3||!(a.getFullYear()%100)&&a.getFullYear()%400?0:1;break;case "o":(function(){var v=
new Date(a.valueOf());v.setDate(v.getDate()-(a.getDay()+6)%7+3);r+=v.getFullYear()})();break;case "Y":r+=a.getFullYear();break;case "y":r+=g("Y").substr(2,2);break;case "a":r+=11<a.getHours()?"pm":"am";break;case "A":r+=g("a").toUpperCase();break;case "B":(function(){var v=60*(a.getTimezoneOffset()+60);v=3600*a.getHours()+60*a.getMinutes()+a.getSeconds()+v;v=Math.floor(v/86.4);1E3<v&&(v-=1E3);0>v&&(v+=1E3);r+=q.lib.strPad(v,3,"0","left")})();break;case "g":r+=a.getHours()%12||12;break;case "G":r+=
a.getHours();break;case "h":r+=q.lib.strPad(g("g"),2,"0","left");break;case "H":r+=q.lib.strPad(g("G"),2,"0","left");break;case "i":r+=q.lib.strPad(a.getMinutes(),2,"0","left");break;case "s":r+=q.lib.strPad(a.getSeconds(),2,"0","left");break;case "u":r+=q.lib.strPad(1E3*a.getMilliseconds(),6,"0","left");break;case "e":r+=(new Date).toString().split(" ")[5].split("-")[0].split("+")[0];break;case "I":r+=(new Date(a.getFullYear(),0,1)).getTimezoneOffset()!=a.getTimezoneOffset()?1:0;break;case "O":r+=
(0<a.getTimezoneOffset()?"-":"+")+q.lib.strPad(Math.abs(a.getTimezoneOffset()/60*100),4,"0","left");break;case "P":r+=g("O").substr(0,3)+":"+g("O").substr(3,2);break;case "T":r+=h[-1*a.getTimezoneOffset()-60*Number(g("I"))]||h[0];break;case "Z":r+=-60*a.getTimezoneOffset();break;case "c":r+=g("Y")+"-"+g("m")+"-"+g("d")+"T"+g("h")+":"+g("i")+":"+g("s")+g("P");break;case "r":r+=g("D")+", "+g("j")+" "+g("M")+" "+g("Y")+" "+g("h")+":"+g("i")+":"+g("s")+" "+g("O");break;case "U":r+=Math.round(a.getTime()/
1E3)}return r};for(var f=0,k=b.length;f<k;f++){var p=b.charAt(f);n="\\"!==m?n+(g(p)||p):n+p;var m=p}return n},extend:function(){var a=arguments[0]||{},b=1,c=arguments.length,d=!1,e;q.lib.validate(a,"boolean")&&(d=a,a=arguments[1]||{},b=2);for(q.lib.validate(a,"object")||q.lib.validate(a,"function")||(a={});b<c;++b)if(null!=(e=arguments[b]))for(var h in e){var n=a[h],g=e[h];a!==g&&(d&&g&&q.lib.validate(g,"object")&&!g.nodeType?a[h]=q.lib.extend(d,n||(null!=g.length?[]:{}),g):q.lib.validate(g,"undefined")||
(a[h]=g))}return a},template:function(a,b,c){var d;if(a){b||(b={});a=a.toString();a=a.split("|");for(var e=a.length,h=e-1;-1<h;h--)if(d=a[h]){var n=!0;var g=d.split("{");for(var f=1,k=g.length;f<k;f++){d=g[f];var p=d.indexOf("}");if(~p){var m=d.substr(0,p);var w=m.split(">");var r=w.shift().split(".");if(q.lib.validate(b,"function"))m=b(r),n=!q.lib.validate(m,"undefined");else{m=b;for(var t=0,v=r.length;n&&t<v;t++){var u=r[t];(n=u in m)&&(m=m[u])}}t=0;for(v=w.length;n&&t<v;t++)n=w[t],c?(m=c(n,m),
n=!q.lib.validate(m,"undefined")):n=!1;n&&(p+=1,d=m+d.substr(p))}else d="{"+d;g[f]=d}d=g.join("");n?a[h]=d:a.splice(h,1)}else h&&h<e-1&&(a[h]="|");b=a.join("")}else b="";return b},getRandomString:function(a,b){var c="";b||(b=89);b=Math.min(Math.max(b,1),89);for(var d=0;d<a;d++)c+="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()-_+=;:,./?|`~[]{}".charAt(Math.round(Math.random()*(b-1)));return c},hasValue:function(a,b,c){var d,e=0;var h=1>=arguments.length;var n=!c&&q.lib.validate(b,
"string");var g=!c&&q.lib.validate(b,"boolean");switch(!0){case q.lib.validate(a,"array"):for(var f=0,k=a.length;f<k;f++)(d=h?!0:c?a[f]===b:n&&q.lib.validate(a[f],"string")?a[f].toLowerCase()==b.toLowerCase():g?b?a[f]:!a[f]:a[f]==b)&&e++;break;case q.lib.validate(a,"object"):for(k in a)(d=h?!0:c?a[k]===b:n&&q.lib.validate(a[k],"string")?a[k].toLowerCase()==b.toLowerCase():g?b?a[k]:!a[k]:a[f]==b)&&e++;break;case q.lib.validate(a,"string"):e=h?e+a.length:n?e+(a.toLowerCase().split(b.toLowerCase()).length-
1):e+(a.split(b).length-1);break;default:(h?a:c?a===b:g?b?a:!a:a==b)&&e++}return e},ini2obj:function(a,b){var c={};a=a?(""+a).split("\r\n"):"";for(var d=0,e=a.length;d<e;d++){var h=q.lib.trim(a[d]);if(h.indexOf(";")&&h.indexOf("#"))if(h.indexOf("[")||h.length!=h.indexOf("]",1)+1){if(~h.indexOf("=")){var n=q.lib.trim(q.lib.strim(h,null,"=",!1,!1));h=q.lib.trim(q.lib.strim(h,"=",null,!1,!1));b&&(h=q.lib.convert(h,"auto"))}else n=q.lib.trim(h),h=D;g?(q.lib.validate(c[g],"object")||(c[g]={}),n&&(c[g][n]=
h)):n&&(c[n]=h)}else var g=q.lib.trim(h.substr(1,h.length-1-1))}return c},tsv2arr:function(a,b,c,d,e){var h,n=0,g=[],f=[],k="\t",p=[];c&&(k=c);a=(a?""+a:"").split("\r\n");switch(!0){case q.lib.validate(b,"array"):c=0;for(var m=b.length;c<m;c++){var w=b[c];var r="";g.push(w);f.push(r)}break;case q.lib.validate(b,"object"):for(w in b)r=b[w],g.push(w),f.push(r);break;case !!b:b=a[n].split(k);c=0;for(m=b.length;c<m;c++){var t=b[c].split(":");w=t[0];r=t[1]||"";g.push(w);f.push(r)}n++}for(t=a.length;n<
t;n++)if(w=a[n]){b=w.split(k);var v=!1;var u=(h=g.length)?{}:[];w=h?g.length:b.length;c=0;for(m=w;c<m;c++){var x=b[c]||"";w=h?g[c]:u.length;r=f[c]||(d?"auto":"");h&&!w||e&&!x||(r&&(x=q.lib.convert(x,r)),u[w]=x,v=!0)}v&&p.push(u)}return p},arr2tsv:function(a,b,c,d){var e=0,h,n=!1,g=[],f=[],k=[],p="\t",m="";a||(a=[]);c&&(p=c);switch(!0){case q.lib.validate(b,"array"):c=0;for(var w=b.length;c<w;c++){var r=b[c];f.push(r);n=!0}break;case q.lib.validate(b,"object"):for(r in b){var t=b[r];f.push(r);k.push(t);
n=!0}}if(!f.length)for(c=0,w=a.length;c<w;c++)switch(t=a[c],!0){case q.lib.validate(t,"array"):c=0;for(w=t.length;c<w;c++)r=""+c,q.lib.hasValue(f,r,!0)||f.push(r);break;case q.lib.validate(t,"object"):for(r in t)q.lib.hasValue(f,r,!0)||(f.push(r),n=!0)}if(!k.length&&d)for(c=0,w=f.length;c<w;c++){b=t="";r=f[c];var v=0;for(h=a.length;v<h;v++)if(r in a[v]){b=a[v][r];switch(!0){case q.lib.validate(b,"boolean"):b="boolean";break;case q.lib.validate(b,"number"):b="number";break;case q.lib.validate(b,"date"):b=
"date";break;default:b=""}if(t&&t!=b)break;else t=b}b||(t="string");k[c]=t}if(f.length&&q.lib.validate(d,"boolean")){v=[];h=!1;c=0;for(w=f.length;c<w;c++)r=f[c],t=k[c],b=r+(d?":"+t:""),~b.indexOf(p)&&(b=b.split(p).join("")),~b.indexOf("\r\n")&&(b=b.split("\r\n").join("")),b&&(h=!0),v.push(b);v.length&&h&&(r=v.join(p),g.push(r))}for(d=a.length;e<d;e++){t=a[e];v=[];h=!1;r=n?f.length:t.length;c=0;for(w=r;c<w;c++)r=n?f[c]:c,b=r in t?t[r]:"",b=q.lib.convert(b,"string"),~b.indexOf(p)&&(b=b.split(p).join("")),
~b.indexOf("\r\n")&&(b=b.split("\r\n").join("")),b&&(h=!0),v.push(b);v.length&&h&&(r=v.join(p),g.push(r))}g.length&&(m=g.join("\r\n"));return m},nix2win:function(a,b,c){a=a?""+a:"";b?a="//"+b+a:a.indexOf("/")||(a=a.substring(1));c||(a=a.split("/").join("\\"));return a},wcd2wql:function(a,b,c){var d="";if(b){isBreak=!1;a=(a?""+a:"").split("|");for(var e=0,h=a.length;e<h;e++){a[e]=a[e].split("!");for(var n=0,g=a[e].length;n<g;n++){var f=a[e][n];var k=b;q.lib.validate(c,"function")&&(d=c(f,k),d.length&&
(f=d.shift()),d.length&&(k=d.shift()));f||(f="*");f&&!q.lib.hasValue(["true","false"],f,!1)&&(f="'"+f+"'");d=k+" "+(n?"<>":"=")+" "+f;a[e][n]=d}d=a[e].join(" AND ");2<h&&1<g&&(d="("+d+")");a[e]=d}d=a.join(" OR ");1<h&&(d="("+d+")")}return d},sort:function(a,b){var c=[],d=0;if(!q.lib.validate(b,"function")){switch(b){case "asc":case !0:d=1;break;case "desc":case !1:d=-1}b=function(g,f){return d?d*q.lib.compare(g,f,!1):0}}switch(!0){case q.lib.validate(a,"array"):var e=a.sort(b);break;case q.lib.validate(a,
"object"):e={};for(n in a)c.push(n);c.sort(b);b=0;for(var h=c.length;b<h;b++){var n=c[b];e[n]=a[n]}break;default:e=a}return e},count:function(a,b){var c=0;if(a)switch(!0){case q.lib.validate(a,"array"):b||(c=a.length);for(var d=c,e=a.length;d<e;d++){var h=a[d];b&&!h||c++}break;case q.lib.validate(a,"object"):for(d in a)h=a[d],b&&!h||c++}return c},match:function(a,b){var c;if(b&&"*"!=b){b=b?""+b:"";a=(a?""+a:"").toLowerCase();b=b.toLowerCase();var d=c=!1;b=b.split("|");for(var e=0,h=b.length;e<h&&
!d;e++){b[e]=b[e].split("!");for(var n=0,g=b[e].length;n<g&&!d;n++){var f=!0;var k=d=0;b[e][n]=b[e][n].split("*");for(var p=0,m=b[e][n].length;p<m&&f;p++){var w=b[e][n][p];d=a.indexOf(w,d);k=a.lastIndexOf(w);f=p?~d:!d;d+=w.length;k+=w.length}f&&w.length&&(f=(1<m?k:d)==a.length);c=n?c&&!f:c||f;d=n&&!c}}}else c=!0;return!!c},setParamKeys:function(a,b,c,d,e,h,n,g){var f,k,p,m,w=[],r=0;if(a&&e&&h){q.lib.validate(b,"array")?m=!0:b=[b];var t=!1;var v=0;for(k=b.length;v<k&&!t;v++)(f=b[v])||(t=!0);t&&(b=
[]);for(v=0;v<e.length;v++){k=e[v];var u="";if(g&&k==g)break;if(p=(p=(p=f=q.lib.strim(k,null,h,!1,!1))&&!q.lib.hasValue(f,"\\",!0))&&!q.lib.hasValue(f,"/",!0))u=f,k=q.lib.strim(k,h,null,!1,!1),n&&(t=k.split(n),3!=t.length||t[0]||t[2]||(k=t[1]));var x=!1;q.lib.validate(c,"function")&&(t=c(k,u),t.length&&(k=t.shift()),t.length&&(u=t.shift()),x=!0);t=!1;if(p=(p=!u||!b.length||q.lib.hasValue(b,u,!0))&&(m?u:!u))f=m?u:b[0],q.lib.validate(c,"array")?q.lib.hasValue(c,k,!0)&&(f||(f=k,k=!0),f&&(t=!0)):(x||
c&&(k=q.lib.convert(k,c)),f&&(t=!0));u=!1;t&&!q.lib.hasValue(w,f,!0)&&(w.push(f),u=!0);t&&(u||d)&&(d?(a[f]||(a[f]=[]),a[f].push(k)):a[f]=k,e.splice(v,1),v--,r++)}}return r}}})(App.prototype);
// 0.3.0 функци для работы в среде windows script host
(function(q,t,u){q.wsh={ldap:function(a,e){var b=[],f=[],d=0;if(!d){var c=new ActiveXObject("ADODB.Connection");var h=new ActiveXObject("NameTranslate");var g=new ActiveXObject("ADODB.Command")}d||(c.provider="ADsDSOObject",c.open("Active Directory Provider"),g.activeConnection=c,g.properties("Searchscope").value=2,g.properties("Page Size").value=100);if(!d)try{var k=GetObject("LDAP://RootDSE");var m=k.get("DefaultNamingContext")}catch(r){d=1}d||(f=[a],e&&f.push(e));for(var p=f.length-1;!d&&-1<p;p--){a=
f[p];e=k=null;var l="SELECT distinguishedName FROM 'LDAP://"+m+"'";if(!d&&a&&!e&&q.lib.validate(a,"guid")){c=(""+a).toUpperCase();try{h.init(3,""),h.set(7,c),e=h.get(1)}catch(r){d=2}}if(!d&&a&&!e)try{(e=a.get("distinguishedName"))&&(k=a)}catch(r){}if(!d&&a&&!e){c=l+" WHERE cn = '"+a+"' OR sAMAccountName = '"+a+"' OR distinguishedName = '"+a+"'";try{g.commandText=c;var n=g.execute();n.recordCount&&(e=n.fields("distinguishedName").value)}catch(r){}}if(!d&&!e){a?(c=""+a,c=q.lib.template(c,{scheme:"LDAP:",
parent:m,select:l}),c.toUpperCase().indexOf("WHERE")?c.toUpperCase().indexOf("SELECT")&&(d=3):c=l+" "+c):c=l+" WHERE distinguishedName = '"+m+"'";try{g.commandText=c,n=g.execute(),n.recordCount||(d=5)}catch(r){d=4}}if(!d&&e&&!p)if(k)b.push(k);else{c=e;try{k=GetObject("LDAP://"+c),b.push(k)}catch(r){d=6}}if(!d&&!e)for(a=0,l=n.recordCount;a<l;n.moveNext(),a++)c=n.fields("distinguishedName").value,a||(e=c),!p&&c&&(k=GetObject("LDAP://"+c),b.push(k));d||(m=e)}return b},iconv:function(a,e,b){var f=new ActiveXObject("ADODB.Stream");
f.type=2;f.mode=3;f.open();f.charset=e;f.writeText(b);f.position=0;f.charset=a;b=f.readText();f.close();return b},getFileText:function(a){var e="";var b=new ActiveXObject("ADODB.Stream");b.type=2;b.mode=3;b.open();try{b.loadFromFile(a),e=b.readText()}catch(f){}b.close();return e},setFileText:function(a,e,b){var f=!1,d=0;var c=new ActiveXObject("ADODB.Stream");c.type=2;c.mode=3;var h=new ActiveXObject("ADODB.Stream");h.type=1;h.mode=3;c.open();h.open();if(b)try{c.loadFromFile(a);var g=c.readText().charAt(0);
48111==g.charCodeAt(0)&&(f=!0);c.writeText("",1)}catch(k){}try{c.writeText(e),g=e&&e.charAt?e.charAt(0):"",48111==g.charCodeAt(0)&&(f=!0),c.position=f?2:0,c.copyTo(h),h.saveToFile(a,2)}catch(k){d=1}h.close();c.close();return!d},getFolder:function(a,e){var b=!1;var f=new ActiveXObject("Scripting.FileSystemObject");if(a){a=f.getAbsolutePathName(a);var d=a.split("\\");var c=d[0]?1:4;for(var h=d.length;h>c&&(a=d.slice(0,h).join("\\"),!f.folderExists(a));h--);for(var g=d.length;h<=g;h++)if(a=d.slice(0,
h).join("\\"),f.folderExists(a))b=f.getFolder(a);else if(e){if(h>c)try{b=f.createFolder(a)}catch(k){b=!1;break}}else{b=!1;break}}return b},setShortcut:function(a){var e,b,f,d={},c=!1,h=!1,g=0;var k=new ActiveXObject("WScript.Shell");var m=new ActiveXObject("Scripting.FileSystemObject");g||(a&&a.fullName?(a.targetPath&&(b=k.expandEnvironmentStrings(a.targetPath)),a.fullName&&(f=k.expandEnvironmentStrings(a.fullName))):g=1);if(!g&&"targetPath"in a&&!b&&(c=!0,m.fileExists(f)))try{m.deleteFile(f,!0)}catch(n){g=
3}if(!g&&!c)try{d=k.createShortcut(f)}catch(n){g=2}if(!g&&!c)for(e in a){var p=!0;b=a[e];switch(e.toLowerCase()){case "fullname":p=!1;break;case "targetpath":var l=k.expandEnvironmentStrings(b);l=m.getAbsolutePathName(l);d[e]==l&&(p=!1);l=m.getAbsolutePathName(b);!q.lib.compare(l,b,!0)&&q.lib.compare(l,b,!1)&&(b=l);break;case "iconlocation":b=~b.indexOf(",")?b.split(", ").join(","):b+",0"}if(p&&e in d&&d[e]!=b)try{d[e]=b,h=!0}catch(n){g=4}}if(!g&&h)try{d.save()}catch(n){g=5}if(!g&&!c&&m.getFileName(f)!=
m.getFileName(m.getAbsolutePathName(d.fullName)))try{m.moveFile(d.fullName,f)}catch(n){g=6}return g?!1:d},arg2arr:function(a){for(var e,b=[],f=0,d=a.length;f<d;f++)e=a.item(f),b.push(e);return b}}})(App.prototype,WSH);
// 2023.05.10 json2.js https://github.com/douglascrockford/JSON-js
"object"!==typeof JSON&&(JSON={});
(function(){function l(a){return 10>a?"0"+a:a}function p(){return this.valueOf()}function q(a){r.lastIndex=0;return r.test(a)?'"'+a.replace(r,function(c){var d=v[c];return"string"===typeof d?d:"\\u"+("0000"+c.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function m(a,c){var d=f,b=c[a];b&&"object"===typeof b&&"function"===typeof b.toJSON&&(b=b.toJSON(a));"function"===typeof k&&(b=k.call(c,a,b));switch(typeof b){case "string":return q(b);case "number":return isFinite(b)?String(b):"null";case "boolean":case "null":return String(b);
case "object":if(!b)return"null";f+=n;var g=[];if("[object Array]"===Object.prototype.toString.apply(b)){var h=b.length;for(a=0;a<h;a+=1)g[a]=m(a,b)||"null";c=0===g.length?"[]":f?"[\n"+f+g.join(",\n"+f)+"\n"+d+"]":"["+g.join(",")+"]";f=d;return c}if(k&&"object"===typeof k)for(h=k.length,a=0;a<h;a+=1){if("string"===typeof k[a]){var e=k[a];(c=m(e,b))&&g.push(q(e)+(f?": ":":")+c)}}else for(e in b)Object.prototype.hasOwnProperty.call(b,e)&&(c=m(e,b))&&g.push(q(e)+(f?": ":":")+c);c=0===g.length?"{}":f?
"{\n"+f+g.join(",\n"+f)+"\n"+d+"}":"{"+g.join(",")+"}";f=d;return c}}var w=/^[\],:{}\s]*$/,x=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,y=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,z=/(?:^|:|,)(?:\s*\[)+/g,r=/[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,t=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;"function"!==typeof Date.prototype.toJSON&&
(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+l(this.getUTCMonth()+1)+"-"+l(this.getUTCDate())+"T"+l(this.getUTCHours())+":"+l(this.getUTCMinutes())+":"+l(this.getUTCSeconds())+"Z":null},Boolean.prototype.toJSON=p,Number.prototype.toJSON=p,String.prototype.toJSON=p);var f,n,k;if("function"!==typeof JSON.stringify){var v={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};JSON.stringify=function(a,c,d){var b;n=f="";if("number"===
typeof d)for(b=0;b<d;b+=1)n+=" ";else"string"===typeof d&&(n=d);if((k=c)&&"function"!==typeof c&&("object"!==typeof c||"number"!==typeof c.length))throw Error("JSON.stringify");return m("",{"":a})}}"function"!==typeof JSON.parse&&(JSON.parse=function(a,c){function d(b,g){var h,e=b[g];if(e&&"object"===typeof e)for(h in e)if(Object.prototype.hasOwnProperty.call(e,h)){var u=d(e,h);void 0!==u?e[h]=u:delete e[h]}return c.call(b,g,e)}a=String(a);t.lastIndex=0;t.test(a)&&(a=a.replace(t,function(b){return"\\u"+
("0000"+b.charCodeAt(0).toString(16)).slice(-4)}));if(w.test(a.replace(x,"@").replace(y,"]").replace(z,"")))return a=eval("("+a+")"),"function"===typeof c?d({"":a},""):a;throw new SyntaxError("JSON.parse");})})();
// 0.2.10 взаимодействие с redmine по средствам api
var redmine=new App({apiRedmineUrl:null,apiRedmineKey:null,apiRedmineUser:null,apiRedminePassword:null,apiCherwellUrl:null,apiCherwellClient:null,apiCherwellUser:null,apiCherwellPassword:null,apiCherwellToken:null,apiADPath:null,userActive:1,userRegistered:2,userLocked:3,delimVal:":",delimKey:";",delimParam:",",delimMap:"=",delimId:"."});
(function(d,C,E){d.lib.extend(d,{fun:{str2val:function(a){switch(!0){case !a:a="";break;case "true"==a:a=!0;break;case "false"==a:a=!1;break;case !isNaN(a):a=Number(a);break;case "--"==a.charAt(4)+a.charAt(7)&&"::"==a.charAt(13)+a.charAt(16)&&"TZ"==a.charAt(10)+a.charAt(19):a=Date.UTC(Number(a.substring(0,4)),Number(a.substring(5,7))-1,Number(a.substring(8,10)),Number(a.substring(11,13)),Number(a.substring(14,16)),Number(a.substring(17,19))),a=new Date(a)}return a},val2str:function(a){switch(!0){case d.lib.validate(a,
"string"):case d.lib.validate(a,"number"):a=""+a;break;case d.lib.validate(a,"boolean"):a=a?"true":"false";break;case d.lib.validate(a,"date"):a=a.getUTCFullYear()+"-"+d.lib.strPad(a.getUTCMonth()+1,2,"0","left")+"-"+d.lib.strPad(a.getUTCDate(),2,"0","left")+"T"+d.lib.strPad(a.getUTCHours(),2,"0","left")+":"+d.lib.strPad(a.getUTCMinutes(),2,"0","left")+":"+d.lib.strPad(a.getUTCSeconds(),2,"0","left")+"Z";break;default:a=null}return a},xml2obj:function(a){var c={},k=null,l=!0;if(a){var b=a.documentElement?
a.documentElement:a;for(var f=0,m=b.attributes.length;f<m;f++){var e=b.attributes[f];l=!1;"type"!=e.name&&"array"!=e.value?c[e.name]=d.fun.str2val(e.value):a.documentElement||(k=!0)}k&&(c=[]);f=0;for(m=a.childNodes.length;f<m;f++)switch(b=a.childNodes[f],b.nodeType){case 1:l=!1;e=d.fun.xml2obj(b);k?c.push(e):c[b.nodeName]=e;break;case 3:l=!1,c=d.fun.str2val(b.nodeValue)}}else l=!1;return l?null:c},obj2xml:function(a,c){var k="item",l=null,b=null;var f={custom_fields:"custom_field",memberships:"membership",
groups:"group",issues:"issue",users:"user",roles:"role"};if(c)c.ownerDocument&&(l=c.ownerDocument);else{var m=["MSXML2.DOMDocument.6.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument"];for(var e=0,g=m.length;!l&&e<g;e++){var r=m[e];try{l=new ActiveXObject(r)}catch(q){}}m=l.createProcessingInstruction("xml",'version="1.0" encoding="UTF-8"');l.appendChild(m)}if(l){b=l.createDocumentFragment();if(d.lib.validate(a,"array"))for(c&&(c.setAttribute("type","array"),m=c.nodeName,k=f[m]?f[m]:k),e=0,g=a.length;e<
g;e++){var h=l.createElement(k);for(var n in a[e])switch(r=a[e][n],m=d.fun.val2str(r),!0){case "value"==n&&"custom_field"==k:case "membership"==k:case "user"==k:m=r,r={},r[n]=m;case !m:m=d.fun.obj2xml(r,h);h.appendChild(m);break;default:h.setAttribute(n,m)}b.appendChild(h)}if(d.lib.validate(a,"object")){c&&(k=c.nodeName);for(n in a)switch(r=a[n],m=d.fun.val2str(r),!0){case !!m&&"project"==k:case !!m&&"tracker"==k:case !!m&&"priority"==k:case !!m&&"author"==k:case !!m&&"category"==k:c&&c.setAttribute(n,
m);break;case !!c||!h&&!m:h=l.createElement(n),m=m?l.createTextNode(m):d.fun.obj2xml(r,h),h.appendChild(m),b.appendChild(h)}if(!c&&h)for(n in a)r=a[n],(m=d.fun.val2str(r))&&h.setAttribute(n,m)}c||l.appendChild(b)}return c?b:l},item2user:function(a,c){var k={},l=0;l||a||(l=1);l||c||(l=2);if(!l){var b=a.get("userAccountControl");k.status=b&2?d.val.userLocked:d.val.userActive}if(!l)for(var f in c)(b=c[f])&&(b=d.lib.template(b,function(m){var e=!0;var g=a;for(var r=0,h=m.length;e&&r<h;r++){var n=m[r];
try{r&&(g=d.wsh.ldap(g)[0]),g?g=g.get(n):e=!1}catch(q){e=!1}}if(e)return g},d.fun.filter)),b=d.fun.str2val(b),isNaN(f)?k[f]=b:(k.custom_fields||(k.custom_fields=[]),k.custom_fields.push({id:f,value:b}));return k},getAttribute:function(a,c){var k="";var l={"project.id":["project_id"],"tracker.id":["tracker_id"],"status.id":["status_id"],"priority.id":["priority_id"],"author.id":["author_id"],"assigned_to.id":["assigned_to_id"],"category.id":["category_id"],"fixed_version.id":["fixed_version_id"],"parent.id":["parent_issue_id"]};
switch(a){case "custom":for(var b in l){a=0;for(var f=l[b].length;a<f;a++)c==l[b][a]&&(k=b)}break;case "original":for(b in l)c==b&&(k=l[b][0])}return k},filter:function(a,c){var k,l,b=[];a=a?""+a:"";var f="(";var m=")";if((k=a.indexOf(f))<a.indexOf(m,k)){var e=d.lib.strim(a,f,m,!1,!1);e=e.split('"').join("").split("'").join("");a=d.lib.strim(a,"",f,!1,!1);b=e.split(d.val.delimParam)}f="[";m="]";e=a.split(m+f).join(d.val.delimId);e=e.split(f).join(d.val.delimId);e=e.split(m).join("");e=e.split('"').join("").split("'").join("");
f=e.split(d.val.delimId);switch(!0){case "phone"==a.toLowerCase():var g=c?d.lib.trim(""+c):"";g=g.replace(/\D/g,"");!g.indexOf("8")&&10<g.length&&(g="7"+g.substr(1));var r=[{index:0,length:g.length-10},{index:g.length-10,length:3},{index:g.length-7,length:3},{index:g.length-4,length:2},{index:g.length-2,length:2}];for(var h=0,n=r.length;h<n;h++){var q=r[h];var t=q.length+Math.min(0,q.index);r[h]=g.substr(Math.max(0,q.index),Math.max(0,t))}!r[0]&&r[1]&&(r[0]=7);g=r[0]?"+"+r[0]:"";g+=r[1]?" ("+r[1]+
") ":"";g+=r[2]?r[2]+"-":"";g+=r[3]?r[3]+(r[2]?"-":""):"";return g+=r[4]?r[4]:"";case "normal"==a.toLowerCase():g=c?d.lib.trim(""+c):"";r=[160];e=g;h=0;for(n=r.length;h<n;h++){var p=String.fromCharCode(r[h]);e=e.split(p).join("")}g=d.lib.trim(e);r=["FW:","Переслать:","RE:","Ответить:"];e=g;c=!1;h=0;for(n=r.length;h<n&&!c;h++)p=r[h],(k=e.indexOf(p))||(c=!0);c&&(e=e.substring(k+p.length),g=d.lib.trim(e));r=[".","!","?"];e=g;-1==e.indexOf("\n")&&(l=!0);c=!1;h=0;for(n=r.length;h<n&&l&&!c;h++)p=r[h],k=
e.indexOf(p),e.length-k==p.length&&(c=!0);c&&(e=e.substring(0,k),g=d.lib.trim(e));e=g;e.charAt(0)==e.charAt(0).toLowerCase()&&(e=e.charAt(0).toUpperCase()+e.substring(1));e=e.split(" ").join(" ");e=e.split(" \n").join("\n");return e=e.split("\n ").join("\n");case "context"==f[0].toLowerCase():t=!0;case "crop"==a.toLowerCase():g=c?d.lib.trim(""+c):"";var u=g.split("\n");g=0;q={from:["From:","От:"],deadline:["Deadline:","Срок:"],sent:["Sent:","Отправлено:"],to:["To:","Кому:"],copy:["Cc:","Копия:"],
subject:["Subject:","Тема:"],importance:["Importance:","Важность:"]};for(a in q)for(r=q[a],q[a]="",h=0,n=u.length;h<n;h++)for(e=u[h],c=!1,b=0,l=r.length;b<l&&!c;b++)p=r[b],k=e.indexOf(p),0<=k&&3>=k&&(!g||h==g)&&(g=h+1,q[a]=e.substring(k+p.length),c=!0);p=u.length;r=[/^.*(Best Regards|Best regards|BR).*$/,/^.*(Kind regards|kind regards).*$/,/^.*(С|C) (Уважением|уважением).*$/,/^.*(Получите Outlook для).*$/,/^(([\* ]*[A-ZА-Я][a-zа-я]{3,20}[\* ]*){2,3}[\* \/,]*){1,2}$/];c=!1;h=0;for(n=u.length;h<n&&
!c;h++){e=u[h];b=0;for(l=r.length;b<l&&!c;b++)r[b].test(e)&&(c=!0);c&&(!h&&g>h?(c=!1,h=g-1):p=h)}g>p&&(g=0,q={});e=u.slice(g,p).join("\n");if(t)switch(p=f[1]){case "from":e=q[p]||"";f="<";m=">";(k=e.indexOf(f))<e.indexOf(m,k)&&(e=d.lib.strim(e,f,m,!1,!1));f="(mailto:";m=")";(k=e.indexOf(f))<e.indexOf(m,k)&&(e=d.lib.strim(e,f,m,!1,!1));break;case "deadline":e=q[p]||""}g=d.lib.trim(e);if(!t||g)return g;break;case "clear"==a.toLowerCase():g=c?d.lib.trim(""+c):"";f="[";m=")";u=g.split("](");h=0;for(n=
u.length;h<n;h++)e=u[h],h&&~e.indexOf(m)&&(e=d.lib.strim(e,m,null,!1,!1)),~e.indexOf(f)&&(e=d.lib.strim(e,null,f,!1,!0)),u[h]=e;e=u.join("");g=d.lib.trim(e);return e=g.split("*").join("");case "hash"==a.toLowerCase():return g=c?d.lib.trim(""+c):"",g=d.lib.strim(g,"#","",!1,!1);case "set"==a.toLowerCase():g=c?d.lib.trim(""+c):"";t=!0;g=g?0<b.length?b[0]||g:"true":1<b.length?b[1]||(t=!1):"false";if(t)return g;break;case "map"==a.toLowerCase():g=c?d.lib.trim(""+c):"";t=!1;h=0;for(n=b.length;h<n&&!t;h++)~b[h].indexOf(d.val.delimMap)&&
(p=d.lib.strim(b[h],"",d.val.delimMap,!1,!1),"*"==p||g==p||!g&&!p)&&(g=d.lib.strim(b[h],d.val.delimMap,"",!1,!1),t=!0);if(t)return g;break;case "replace"==a.toLowerCase():return g=c?""+c:"",b[0]&&(g=g.split(b[0]).join(b[1]||"")),g;case "date"==a.toLowerCase():t=!0;if(d.lib.validate(c,"date"))g=c;else for(r=[{delim:".",year:2,month:1,day:0},{delim:"/",year:2,month:0,day:1},{delim:"-",year:0,month:1,day:2}],t=!1,h=0,n=r.length;h<n&&!t;h++)q=r[h],g=c?d.lib.trim(""+c):"",u=g.split(" ")[0].split(q.delim),
3==u.length&&(g=new Date(u[q.year],u[q.month]-1,u[q.day]),t=!isNaN(g));t&&b[1]&&(isNaN(b[1])?t=!1:g.setDate(g.getDate()+Number(b[1])));t&&(g=d.lib.date2str(g,b[0]||"Y-m-d"));if(t)return g;break;case "user"==f[0].toLowerCase():q||(q={include:"groups"});case "issue"==f[0].toLowerCase():q||(q={include:"journals,watchers"});case "project"==f[0].toLowerCase():q||(q={include:"trackers"});(e=c&&c.id?c.id:isNaN(c)?null:c)?(p=f.shift().toLowerCase(),c=d.api.redmine("get",p+"s/"+e,q),c=c[p]?c[p]:null):c?(p=
f.shift().toLowerCase()+"s",c={name:c},c=d.api.redmine("get",p,c),c=c[p]&&1==c[p].length?c[p][0]:null):c=null;t=q=c;h=0;for(n=f.length;t&&h<n;h++)if(p=f[h],isNaN(p))(t=p in q)&&(q=q[p]);else if(p=Number(p),t=q=q.custom_fields)for(t=!1,b=0,l=q.length;!t&&b<l;b++)if(t=p==q[b].id)q=q[b].value;if(t)return q;break;case "journal"==f[0].toLowerCase():e="details";p=f.shift().toLowerCase()+"s";g=f.pop();f=f.join(d.val.delimId);f=d.fun.getAttribute("original",f)||f;if(c&&c[p])for(h=0,n=c[p].length;h<n;h++)if(c[p][h][e])for(b=
0,l=c[p][h][e].length;b<l;b++)if(q=c[p][h][e][b],k=q.new_value||"",k=d.fun.str2val(k),t=d.lib.validate(k,"boolean"),t=!d.lib.compare(k,t?g?!0:!1:g),!t&&isNaN(k)&&(t=d.lib.hasValue(""+g,k,!1)),t=t&&(!f||f==q.name))r=c[p][h].user.id;if(r)return r}},fixUrlPath:function(a){a?"/"!=a.substring(a.length-1)&&(a+="/"):a="/";return a}},method:{"users.sync":function(a,c,k){var l,b,f,m={},e=0;e||(a=d.lib.url2obj(a),d.lib.hasValue(["ldap"],a.scheme,!1)?d.val.apiADPath=a.path||a.domain:e=7);if(!e){c=c?d.lib.str2obj(c,
!1,d.val.delimKey,d.val.delimVal):{};for(b in c)(a=c[b])&&(c[b]=a.split('"').join("").split("'").join("")),l||(l=b);c.login&&c.firstname&&c.mail&&c.lastname||(e=8)}e||(f=d.api.ad("WHERE 'objectClass' = 'user'"));if(!e)for(var g=0,r=f.length;g<r;g++){a=f[g];var h=d.fun.item2user(a,c);h.login&&h.firstname&&h.lastname&&(h.mail||(h.status=d.val.userLocked,delete h.mail),(b=h[l].toLowerCase())&&(m[b]=h))}h=[d.val.userActive,d.val.userRegistered,d.val.userLocked];f=[];g=0;for(r=h.length;!e&&g<r;g++){var n=
h[g];for(c=null;!c||c.total_count>c.offset;c.offset+=c.limit){c={offset:c?c.offset:0,status:n};c=d.api.redmine("get","users",c);c.users||(c.users=[]);for(var q=0,t=c.users.length;q<t;q++)a=c.users[q],a.status=n,f.push(a)}}e||f.length||(e=9);if(!e)for(g=0,r=f.length;g<r;g++)if(a=f[g],b=a[l].toLowerCase(),h=m[b]){if(c=d.lib.difference(h,a,function(p,u){return p.id==u.id&&p.value!=u.value}))k&&(c.auth_source_id=k),c={user:c},c=d.api.redmine("put","users/"+a.id,c);delete m[b]}if(!e)for(b in m)h=m[b],
d.val.userActive==h.status&&(k&&(h.auth_source_id=k),c={user:h},c=d.api.redmine("post","users",c)),delete m[b];return e},"issues.sync":function(a,c,k,l){var b,f,m,e,g,r={},h=0;l||(l=k,k=null);h||c&&!isNaN(c)||(h=7);h||(a=d.lib.url2obj(a),h||(a.fragment?(d.val.apiCherwellClient=a.fragment,delete a.fragment):h=8),h||(a.password&&a.user?(d.val.apiCherwellUser=a.user,d.val.apiCherwellPassword=a.password,delete a.password,delete a.user):h=9),h||(a.scheme&&a.domain?(a.path=d.fun.fixUrlPath(a.path),d.val.apiCherwellUrl=
d.lib.obj2url(a)):h=10));if(!h&&(k=k?d.lib.str2obj(k,!1,d.val.delimKey,d.val.delimVal):null))for(w in k)(b=k[w])&&(k[w]=b.split('"').join("").split("'").join(""));if(!h){l=l?d.lib.str2obj(l,!1,d.val.delimKey,d.val.delimVal):{};for(w in l)(b=l[w])&&(l[w]=b.split('"').join("").split("'").join("")),g||(g=w);if(!l.SuppliersReference||l.IncidentID)h=11}if(!h){var n=d.api.cherwell("get","getuserbyloginid/loginid/"+d.val.apiCherwellUser);n.recordId?f=n.recordId:h=12}h||(n=d.api.cherwell("get","getbusinessobjectsummary/busobname/Incident"),
n.length&&n[0].busObId?m=n[0].busObId:h=13);if(!h)if(n=d.api.cherwell("get","getbusinessobjectschema/busobid/"+m),n.fieldDefinitions){var q=n.fieldDefinitions;var t={};for(w in l){n=!1;var p=[w,"IncidentID"];for(var u=0,y=q.length;u<y;u++){a=q[u];for(var v=0,x=p.length;v<x;v++){var z=p[v];a.name==z&&(t[a.name]=a.fieldId,v||(n=!0))}}n||(h=15)}}else h=14;if(!h)for(u=1,q=[],n=null;!n||n.hasMoreRecords&&!h;u++)n={pagenumber:u},n=d.api.cherwell("get","getsearchresults/association/"+m+"/scope/User/scopeowner/"+
f+"/searchname/"+c,n),!n.hasError&&n.businessObjects?q=q.concat(n.businessObjects):h=16;if(!h)for(u=0,y=q.length;u<y;u++){a=q[u];var B={};v=0;for(x=a.fields.length;v<x;v++)if(e=t[a.fields[v].name]){b=a.fields[v].value;p=[160,13];var w=0;for(n=p.length;b&&w<n;w++)z=String.fromCharCode(p[w]),b=(""+b).split(z).join("");p=(""+b).split(" ");"12:00:00"==p[1]&&"AM"==p[2]&&3==p.length&&(b=p[0]);B[e]=b}(w=B[t[g]])&&(r[w]=B)}if(!h)for(q=[],n=null;!n||n.total_count>n.offset;n.offset+=n.limit)n={offset:n?n.offset:
0},c&&(n.query_id=c),n=d.api.redmine("get","issues",n),n.issues&&(q=q.concat(n.issues));if(!h)for(u=0,y=q.length;u<y;u++){a=q[u];a["true"]=!0;a["false"]=!1;for(z in a){var A=a[z];(z=d.fun.getAttribute("custom",z))&&(a[z]=A)}f=!0;if(k)for(w in k){c=k[w];if(isNaN(w))for(b=n=a,p=w.split(d.val.delimId),v=0,x=p.length;f&&v<x;v++)z=p[v],(f=z in n)&&(b=n=n[z]);else for(f=!1,p=a.custom_fields?a.custom_fields:[],v=0,x=p.length;!f&&v<x;v++)if(A=p[v],f=A.id==Number(w))b=A.value;if(f)for(c&&(c=d.lib.template(c,
a,d.fun.filter)),p=c.split(d.val.delimParam),f=!1,v=0,x=p.length;v<x&&!f;v++)c=p[v],c=d.fun.str2val(c),f=d.lib.validate(c,"boolean"),f=!d.lib.compare(c,f?b?!0:!1:b),!f&&isNaN(c)&&(f=d.lib.hasValue(""+b,c,!1));if(!f)break}if(f){B=A=null;var D=0;for(w in l)A||(A={}),(b=l[w])&&(b=d.lib.template(b,a,d.fun.filter)),b=d.fun.str2val(b),e=t[w],w==g&&(B=r[b]),B&&B[e]==b||D++,A[e]=b}if(f&&D){n={busObId:m,persist:!0,fields:[]};B&&(n.busObPublicId=B[t.IncidentID]);for(e in A)n.fields.push({value:A[e],fieldId:e,
dirty:!0});d.api.cherwell("post","savebusinessobject",n)}}return h},"issues.change":function(a,c,k){var l,b,f,m,e=0;isNaN(a)&&(k=c,c=a,a=null);k||(k=c,c=null);if(!e&&(c=c?d.lib.str2obj(c,!1,d.val.delimKey,d.val.delimVal):null))for(var g in c)(b=c[g])&&(c[g]=b.split('"').join("").split("'").join(""));if(!e)if(k=k?d.lib.str2obj(k,!1,d.val.delimKey,d.val.delimVal):null)for(g in k)(b=k[g])&&(k[g]=b.split('"').join("").split("'").join(""));else e=7;if(!e){var r=[];for(f=null;!f||f.total_count>f.offset;f.offset+=
f.limit)f={offset:f?f.offset:0},a&&(f.query_id=a),f=d.api.redmine("get","issues",f),f.issues&&(r=r.concat(f.issues))}if(!e)for(var h=0,n=r.length;h<n;h++){var q=r[h];q["true"]=!0;q["false"]=!1;for(l in q){var t=q[l];(l=d.fun.getAttribute("custom",l))&&(q[l]=t)}var p=!0;if(c)for(g in c){a=c[g];if(isNaN(g))for(b=f=q,list=g.split(d.val.delimId),u=0,y=list.length;p&&u<y;u++)l=list[u],(p=l in f)&&(b=f=f[l]);else{p=!1;list=q.custom_fields?q.custom_fields:[];for(var u=0,y=list.length;!p&&u<y;u++)if(t=list[u],
p=t.id==Number(g))b=t.value}if(p)for(a&&(a=d.lib.template(a,q,d.fun.filter)),list=a.split(d.val.delimParam),p=!1,u=0,y=list.length;u<y&&!p;u++)a=list[u],a=d.fun.str2val(a),p=d.lib.validate(a,"boolean"),p=!d.lib.compare(a,p?b?!0:!1:b),!p&&isNaN(a)&&(p=d.lib.hasValue(""+b,a,!1));if(!p)break}if(p){t=null;var v=0;for(g in k){t||(t={});(b=k[g])&&(b=d.lib.template(b,q,d.fun.filter));b=d.fun.str2val(b);g=d.fun.getAttribute("original",g)||g;switch(g){case "watcher":b&&(b=isNaN(b)?!1:Number(b));b&&(f={include:"watchers"},
f=d.api.redmine("get","issues/"+q.id,f),f.issue&&f.issue.watchers?m=f.issue.watchers:b=!1);if(b){var x=null;u=0;for(y=m.length;!x&&u<y;u++)x=m[u],Math.abs(b)!=x.id&&(x=null)}b&&(0<b&&!x&&(f={user_id:b},f={watcher:f},d.api.redmine("post","issues/"+q.id+"/watchers",f)),0>b&&x&&(b=Math.abs(b),d.api.redmine("delete","issues/"+q.id+"/watchers/"+b)));g=null}g&&(isNaN(g)?t[g]=b:(t.custom_fields||(t.custom_fields=[]),t.custom_fields.push({id:g,value:b})),v++)}}p&&v&&(f={issue:t},d.api.redmine("put","issues/"+
q.id,f))}return e}},api:{redmine:function(a,c,k){var l={},b=0;if(!b)switch(a.toLowerCase()){case "get":var f=!1;break;case "head":f=!1;break;case "delete":f=!1;break;default:f=!0}!b&&k&&f&&((k=d.fun.obj2xml(k))||(b=1));if(!b){c=d.val.apiRedmineUrl+c+".xml";var m={"Cache-Control":"no-store","If-None-Match":"empty"};d.val.apiRedmineKey&&(m["X-Redmine-API-Key"]=d.val.apiRedmineKey);m=d.lib.xhr(a,c,m,k,!1,null,d.val.apiRedmineUser,d.val.apiRedminePassword);k=m.responseXML;d.lib.validate(k,"xml")||(b=
2)}b||(k=d.fun.xml2obj(m.responseXML))&&(l=k);return l},cherwell:function(a,c,k){var l={},b=0;if(!b&&!d.val.apiCherwellToken){var f=d.val.apiCherwellUrl+"token";var m=new ActiveXObject("MSXML2.ServerXMLHTTP");m.open("POST",f,!1);m.setRequestHeader("Content-Type","application/x-www-form-urlencoded");m.send(d.lib.obj2str({client_id:d.val.apiCherwellClient,username:d.val.apiCherwellUser,password:d.val.apiCherwellPassword,grant_type:"password"},!0));m.responseText&&200==m.status?(f=JSON.parse(m.responseText).access_token)?
d.val.apiCherwellToken=f:b=2:b=1}if(!b)switch(a.toLowerCase()){case "get":var e=!1;break;case "head":e=!1;break;case "delete":e=!1;break;default:e=!0}!b&&k&&e&&(k=JSON.stringify(k));b||!k||e||(k=d.lib.obj2str(k,!0),c=~c.indexOf("?")?c+"&":c+"?",c+=k,k=null);if(!b){f=d.val.apiCherwellUrl+"api/V1/"+c;m=new ActiveXObject("MSXML2.ServerXMLHTTP");m.open(a.toUpperCase(),f,!1);m.setRequestHeader("Accept","application/json");m.setRequestHeader("Content-Type","application/json");m.setRequestHeader("Authorization",
"Bearer "+d.val.apiCherwellToken);try{k?m.send(k):m.send(),m.responseText&&200==m.status||(b=4)}catch(g){b=3}}b||(k=JSON.parse(m.responseText))&&(l=k);return l},ad:function(a){return d.wsh.ldap(a,d.val.apiADPath)}},init:function(){var a,c=[],k=0,l=0;if(!l){if(k<C.arguments.length){var b=C.arguments(k);b=d.lib.url2obj(b);!l&&b.fragment&&(b.user||b.password?l=2:(d.val.apiRedmineKey=b.fragment,delete b.fragment));!l&&b.user&&(b.password&&!b.fragment?(d.val.apiRedmineUser=b.user,d.val.apiRedminePassword=
b.password,delete b.password,delete b.user):l=3);l||(b.scheme&&b.domain?(b.path=d.fun.fixUrlPath(b.path),d.val.apiRedmineUrl=d.lib.obj2url(b)):l=4)}else l=1;k++}l||(k<C.arguments.length?(b=C.arguments(k),(a=d.method[b])||(l=6)):l=5,k++);if(!l)for(var f=C.arguments.length;k<f;k++)b=C.arguments(k),c.push(b);l||(l=a.apply(d,c));C.quit(l)}})})(redmine,WSH);redmine.init();