webdav_protocol.js 178KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643
  1. /*
  2. CalDavZAP - the open source CalDAV Web Client
  3. Copyright (C) 2011-2015
  4. Jan Mate <jan.mate@inf-it.com>
  5. Andrej Lezo <andrej.lezo@inf-it.com>
  6. Matej Mihalik <matej.mihalik@inf-it.com>
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU Affero General Public License as
  9. published by the Free Software Foundation, either version 3 of the
  10. License, or (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Affero General Public License for more details.
  15. You should have received a copy of the GNU Affero General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // VersionCheck (check for new version)
  19. function netVersionCheck()
  20. {
  21. $.ajax({
  22. type: 'GET',
  23. url: globalVersionCheckURL,
  24. cache: false,
  25. crossDomain: false,
  26. timeout: 30000,
  27. beforeSend: function(req) {
  28. req.setRequestHeader('X-client', globalXClientHeader);
  29. },
  30. contentType: 'text/xml; charset=utf-8',
  31. processData: true,
  32. data: '',
  33. dataType: 'xml',
  34. error: function(objAJAXRequest, strError){
  35. console.log("Error: [netVersionCheck: 'GET "+globalVersionCheckURL+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'");
  36. return false;
  37. },
  38. success: function(data, textStatus, xml)
  39. {
  40. var count=0;
  41. var tmp=$(xml.responseXML).find('updates').find(globalAppName.toLowerCase());
  42. var type=tmp.attr('type');
  43. var home=tmp.attr('homeURL');
  44. var version_txt=tmp.attr('version');
  45. var build_no_txt=(typeof globalEnableDevelBuilds=='undefined' || globalEnableDevelBuilds!=true ? tmp.attr('build_no') : tmp.attr('dev_build_no'));
  46. if(type==undefined || type=='' || home==undefined || home=='' || version_txt==undefined || version_txt=='' || build_no_txt==undefined || build_no_txt=='')
  47. return false;
  48. var build_no=build_no_txt.match(RegExp('^([0-9]+)$'));
  49. if(build_no==null)
  50. return false;
  51. if(globalBuildNo<parseInt(build_no[1]))
  52. {
  53. var showNofication=false;
  54. if(globalNewVersionNotifyUsers.length==0)
  55. showNofication=true;
  56. else
  57. {
  58. for(var i=0;i<globalAccountSettings.length;i++)
  59. if(globalNewVersionNotifyUsers.indexOf(globalAccountSettings[i].userAuth.userName)!=-1)
  60. {
  61. showNofication=true;
  62. break;
  63. }
  64. }
  65. if(showNofication==true)
  66. {
  67. $('div.update_h').html(localization[globalInterfaceLanguage].updateNotification.replace('%name%',globalAppName).replace('%new_ver%','<span id="newversion" class="update_h"></span>').replace('%curr_ver%', '<span id="version" class="update_h"></span>').replace('%url%', '<span id="homeurl" class="update_h" onclick=""></span>'));
  68. $('div.update_h').find('span#version').text(globalVersion);
  69. $('div.update_h').find('span#newversion').text(version_txt);
  70. $('div.update_h').find('span#homeurl').attr('onclick','window.open(\''+home+'\')');
  71. $('div.update_h').find('span#homeurl').text(home);
  72. setTimeout(function(){
  73. var orig_width=$('div.update_d').width();
  74. $('div.update_d').css('width', '0px');
  75. $('div.update_d').css('display','');
  76. $('div.update_d').animate({width: '+='+orig_width+'px'}, 500);
  77. }, 5000);
  78. }
  79. }
  80. }
  81. });
  82. }
  83. // Load the configuration from XML file
  84. function netCheckAndCreateConfiguration(configurationURL)
  85. {
  86. $.ajax({
  87. type: 'PROPFIND',
  88. url: configurationURL.href,
  89. cache: false,
  90. crossDomain: (typeof configurationURL.crossDomain=='undefined' ? true : configurationURL.crossDomain),
  91. xhrFields: {
  92. withCredentials: (typeof configurationURL.withCredentials=='undefined' ? false : configurationURL.withCredentials)
  93. },
  94. timeout: configurationURL.timeOut,
  95. beforeSend: function(req){
  96. if(globalSettings.usejqueryauth.value!=true && globalLoginUsername!='' && globalLoginPassword!='')
  97. req.setRequestHeader('Authorization', basicAuth(globalLoginUsername,globalLoginPassword));
  98. req.setRequestHeader('X-client', globalXClientHeader);
  99. req.setRequestHeader('Depth', '0');
  100. },
  101. username: (globalSettings.usejqueryauth.value==true ? globalLoginUsername : null),
  102. password: (globalSettings.usejqueryauth.value==true ? globalLoginPassword : null),
  103. contentType: 'text/xml; charset=utf-8',
  104. processData: true,
  105. data: '<?xml version="1.0" encoding="utf-8"?><D:propfind xmlns:D="DAV:"><D:prop><D:current-user-principal/></D:prop></D:propfind>',
  106. dataType: 'xml',
  107. error: function(objAJAXRequest, strError){
  108. console.log("Error: [netCheckAndCreateConfiguration: 'PROPFIND "+configurationURL.href+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  109. $('#LoginLoader').fadeOut(1200);
  110. return false;
  111. },
  112. success: function(data, textStatus, xml)
  113. {
  114. var count=0;
  115. if($(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('status').text().match(RegExp('200 OK$')))
  116. {
  117. if(typeof globalAccountSettings=='undefined')
  118. globalAccountSettings=[];
  119. globalAccountSettings[globalAccountSettings.length]=$.extend({}, configurationURL);
  120. globalAccountSettings[globalAccountSettings.length-1].type='network';
  121. if(typeof(globalAccountSettingsHook)=='function') // Hook for globalAccountSettings (openCRX)
  122. globalAccountSettings[globalAccountSettings.length-1].href=globalAccountSettingsHook(configurationURL.href, globalLoginUsername);
  123. else // standard version
  124. globalAccountSettings[globalAccountSettings.length-1].href=configurationURL.href+globalLoginUsername+'/';
  125. globalAccountSettings[globalAccountSettings.length-1].userAuth={userName: globalLoginUsername, userPassword: globalLoginPassword};
  126. count++;
  127. if(configurationURL.additionalResources!=undefined && configurationURL.additionalResources.length>0)
  128. {
  129. for(var i=0;i<configurationURL.additionalResources.length;i++)
  130. {
  131. if(globalLoginUsername!=configurationURL.additionalResources[i])
  132. {
  133. globalAccountSettings[globalAccountSettings.length]=$.extend({}, configurationURL);
  134. globalAccountSettings[globalAccountSettings.length-1].type='network';
  135. globalAccountSettings[globalAccountSettings.length-1].href=configurationURL.href+configurationURL.additionalResources[i]+'/';
  136. globalAccountSettings[globalAccountSettings.length-1].userAuth={userName: globalLoginUsername, userPassword: globalLoginPassword};
  137. count++;
  138. }
  139. }
  140. }
  141. }
  142. if(count)
  143. {
  144. if(globalAccountSettings[0].delegation)
  145. DAVresourceDelegation(globalAccountSettings[0], 0, 0);
  146. else
  147. {
  148. // start the client
  149. if(isAvaible('CardDavMATE'))
  150. runCardDAV();
  151. if(isAvaible('CalDavZAP'))
  152. runCalDAV();
  153. if(isAvaible('Projects'))
  154. runProjects();
  155. if(isAvaible('Settings'))
  156. runSettings();
  157. globalResourceNumber=globalAccountSettings.length;
  158. loadAllResources();
  159. }
  160. }
  161. else
  162. $('#LoginLoader').fadeOut(1200);
  163. }
  164. });
  165. }
  166. // Load the configuration from XML file
  167. function netLoadConfiguration(configurationURL)
  168. {
  169. $.ajax({
  170. type: 'GET',
  171. url: configurationURL.href+'?browser_date='+$.datepicker.formatDate("yyyy-MM-dd", new Date())+(ignoreServerSettings==true ? '&ignore_settings=1' : ''),
  172. cache: false,
  173. crossDomain: (typeof configurationURL.crossDomain=='undefined' ? true : configurationURL.crossDomain),
  174. xhrFields: {
  175. withCredentials: (typeof configurationURL.withCredentials=='undefined' ? false : configurationURL.withCredentials)
  176. },
  177. timeout: configurationURL.timeOut,
  178. beforeSend: function(req) {
  179. if(globalSettings.usejqueryauth.value!=true && globalLoginUsername!='' && globalLoginPassword!='')
  180. req.setRequestHeader('Authorization', basicAuth(globalLoginUsername,globalLoginPassword));
  181. req.setRequestHeader('X-client', globalXClientHeader);
  182. },
  183. username: (globalSettings.usejqueryauth.value==true ? globalLoginUsername : null),
  184. password: (globalSettings.usejqueryauth.value==true ? globalLoginPassword : null),
  185. contentType: 'text/xml; charset=utf-8',
  186. processData: true,
  187. data: '',
  188. dataType: 'xml',
  189. error: function(objAJAXRequest, strError){
  190. console.log("Error: [loadConfiguration: 'GET "+configurationURL.href+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  191. $('#LoginLoader').fadeOut(1200);
  192. return false;
  193. },
  194. success: function(data, textStatus, xml)
  195. {
  196. if(typeof globalAccountSettings=='undefined')
  197. globalAccountSettings=[];
  198. var count=0;
  199. var rex=new RegExp('^re(\\|[^:]*|):(.+)$');
  200. $(xml.responseXML).children('resources').children('resource').each(
  201. function(index, element)
  202. {
  203. if($(element).children().filterNsNode('type').children().filterNsNode('addressbook').length==1 || $(element).children().filterNsNode('type').children().filterNsNode('calendar').length==1)
  204. {
  205. // numeric/text options
  206. var href=$(element).children('href').text();
  207. var tmp=$(element).children('hreflabel').text();
  208. var hreflabel=(tmp!='' && tmp!='null' ? tmp : null);
  209. var username=$(element).children('userauth').children('username').text();
  210. var password=$(element).children('userauth').children('password').text();
  211. var timeout=$(element).children('timeout').text();
  212. var locktimeout=$(element).children('locktimeout').text();
  213. // array options
  214. var collectionTypes=new Array();
  215. if($(element).children().filterNsNode('type').children().filterNsNode('addressbook').length==1)
  216. collectionTypes[collectionTypes.length]='addressbook';
  217. if($(element).children().filterNsNode('type').children().filterNsNode('calendar').length==1)
  218. collectionTypes[collectionTypes.length]='calendar';
  219. // boolean options
  220. var tmp=$(element).children('withcredentials').text();
  221. var withcredentials=((tmp=='true' || tmp=='yes' || tmp=='1') ? true : false);
  222. var tmp=$(element).children('crossdomain').text();
  223. var crossdomain=((tmp=='false' || tmp=='no' || tmp=='0') ? false : true);
  224. var tmp=$(element).find('settingsaccount').text();
  225. var settingsaccount=((tmp=='true' || tmp=='yes' || tmp=='1') ? true : false);
  226. var tmp=$(element).find('checkcontenttype').text();
  227. var checkcontenttype=((tmp=='false' || tmp=='no' || tmp=='0') ? false : true);
  228. var tmp=$(element).find('ignorebound').text();
  229. var ignorebound=((tmp=='true' || tmp=='yes' || tmp=='1') ? true : false);
  230. // special options
  231. var forcereadonly=null;
  232. var tmp=$(element).children('forcereadonly');
  233. if(tmp.text()=='true')
  234. var forcereadonly=true;
  235. else
  236. {
  237. var tmp_ro=[];
  238. tmp.children('collection').each(
  239. function(index, element)
  240. {
  241. if((matched=$(element).text().match(rex))!=null && matched.length==3)
  242. tmp_ro[tmp_ro.length]=new RegExp(matched[2], matched[1].substring(matched[1].length>0 ? 1 : 0));
  243. else
  244. tmp_ro[tmp_ro.length]=$(element).text();
  245. }
  246. );
  247. if(tmp_ro.length>0)
  248. var forcereadonly=tmp_ro;
  249. }
  250. var delegation=false;
  251. var tmp=$(element).children('delegation');
  252. if(tmp.text()=='true')
  253. var delegation=true;
  254. else
  255. {
  256. var tmp_de=[];
  257. tmp.children('resource').each(
  258. function(index, element)
  259. {
  260. if((matched=$(element).text().match(rex))!=null && matched.length==3)
  261. tmp_de[tmp_de.length]=new RegExp(matched[2], matched[1].substring(matched[1].length>0 ? 1 : 0));
  262. else
  263. tmp_de[tmp_de.length]=$(element).text();
  264. }
  265. );
  266. if(tmp_de.length>0)
  267. var delegation=tmp_de;
  268. }
  269. var extendedDelegation=false;
  270. var tmp=$(element).children('extendeddelegation');
  271. if(tmp.text()=='true')
  272. extendedDelegation=true;
  273. var ignoreAlarms=false;
  274. var tmp=$(element).children('ignorealarms');
  275. if(tmp.text()=='true')
  276. var ignoreAlarms=true;
  277. else
  278. {
  279. var tmp_ia=[];
  280. tmp.children('collection').each(
  281. function(index, element)
  282. {
  283. if((matched=$(element).text().match(rex))!=null && matched.length==3)
  284. tmp_ia[tmp_ia.length]=new RegExp(matched[2], matched[1].substring(matched[1].length>0 ? 1 : 0));
  285. else
  286. tmp_ia[tmp_ia.length]=$(element).text();
  287. }
  288. );
  289. if(tmp_ia.length>0)
  290. var ignoreAlarms=tmp_ia;
  291. }
  292. var backgroundCalendars=[];
  293. var tmp=$(element).children('backgroundcalendars');
  294. if(tmp.text()!='')
  295. {
  296. tmp.children('collection').each(
  297. function(index, element)
  298. {
  299. if((matched=$(element).text().match(rex))!=null && matched.length==3)
  300. backgroundCalendars[backgroundCalendars.length]=new RegExp(matched[2], matched[1].substring(matched[1].length>0 ? 1 : 0));
  301. else
  302. backgroundCalendars[backgroundCalendars.length]=$(element).text();
  303. }
  304. );
  305. }
  306. globalAccountSettings[globalAccountSettings.length]={type: 'network', href: href, hrefLabel: hreflabel, crossDomain: crossdomain, settingsAccount: settingsaccount, checkContentType: checkcontenttype, forceReadOnly: forcereadonly, withCredentials: withcredentials, userAuth: {userName: username, userPassword: password}, timeOut: timeout, lockTimeOut: locktimeout, delegation: delegation, extendedDelegation: extendedDelegation, ignoreAlarms: ignoreAlarms, backgroundCalendars: backgroundCalendars, collectionTypes: collectionTypes, ignoreBound: ignorebound};
  307. count++;
  308. }
  309. }
  310. );
  311. if(count)
  312. {
  313. // store the pre-cached data for the client
  314. var tmp=$(xml.responseXML).children('resources').children('cache_data');
  315. if(tmp.length)
  316. globalXMLCache=tmp;
  317. if(globalAccountSettings[0].delegation)
  318. DAVresourceDelegation(globalAccountSettings[0], 0, 0);
  319. else
  320. {
  321. // start the client
  322. if(isAvaible('CardDavMATE'))
  323. {
  324. runCardDAV();
  325. }
  326. if(isAvaible('CalDavZAP'))
  327. runCalDAV();
  328. if(isAvaible('Projects'))
  329. runProjects();
  330. if(isAvaible('Settings'))
  331. runSettings();
  332. globalResourceNumber = globalAccountSettings.length;
  333. loadAllResources();
  334. }
  335. }
  336. else
  337. $('#LoginLoader').fadeOut(1200);
  338. }
  339. });
  340. }
  341. // Save the collection property (stored as DAV property on server)
  342. function netSaveProperty(inputCollection, hrefProperty, inputProperty, inputValue)
  343. {
  344. var dataXML = '<?xml version="1.0" encoding="utf-8"?><D:propertyupdate xmlns:D="DAV:"><D:set><D:prop><I:'+inputProperty+' xmlns:I="'+hrefProperty+'">'+inputValue+'</I:'+inputProperty+'></D:prop></D:set></D:propertyupdate>';
  345. $.ajax({
  346. type: 'PROPPATCH',
  347. url: inputCollection.url+inputCollection.href,
  348. cache: false,
  349. crossDomain: (typeof inputCollection.crossDomain=='undefined' ? true: inputCollection.crossDomain),
  350. xhrFields: {
  351. withCredentials: (typeof inputCollection.withCredentials=='undefined' ? false: inputCollection.withCredentials)
  352. },
  353. timeout: inputCollection.timeOut,
  354. beforeSend: function(req){
  355. if(globalSettings.usejqueryauth.value!=true && inputCollection.userAuth.userName!='' && inputCollection.userAuth.userPassword!='')
  356. req.setRequestHeader('Authorization', basicAuth(inputCollection.userAuth.userName, inputCollection.userAuth.userPassword));
  357. req.setRequestHeader('X-client', globalXClientHeader);
  358. req.setRequestHeader('Depth', '0');
  359. },
  360. username: (globalSettings.usejqueryauth.value==true ? inputCollection.userAuth.userName : null),
  361. password: (globalSettings.usejqueryauth.value==true ? inputCollection.userAuth.userPassword : null),
  362. contentType: 'text/xml',
  363. processData: true,
  364. data: dataXML,
  365. dataType: 'xml',
  366. error: function(objAJAXRequest, strError){
  367. console.log("Error: [netSaveProperty: 'PROPPATCH "+inputCollection.url+inputCollection.href+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' (this error code usually means network connection error, or your browser is trying to make a cross domain query, but it is not allowed by the destination server or the browser itself)': ''));
  368. if(inputProperty=='calendar-color')
  369. {
  370. if(inputCollection.listType=='vevent')
  371. {
  372. $('#ResourceCalDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.resourceCalDAVColor').css('background',inputCollection.ecolor);
  373. $('#ResourceCalDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('set',inputCollection.ecolor);
  374. }
  375. else
  376. {
  377. $('#ResourceCalDAVTODOList').find('[data-id="'+inputCollection.uid+'"]').find('.resourceCalDAVColor').css('background',inputCollection.ecolor);
  378. $('#ResourceCalDAVTODOList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('set',inputCollection.ecolor);
  379. }
  380. }
  381. else if(inputProperty=='addressbook-color')
  382. {
  383. $('#ResourceCardDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.resourceCardDAVColor').css('background',inputCollection.color);
  384. $('#ResourceCardDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('set',inputCollection.color);
  385. }
  386. return false;
  387. },
  388. success: function(data, textStatus, xml)
  389. {
  390. var color;
  391. if(inputProperty=='calendar-color')
  392. {
  393. var secondColl = null;
  394. if(inputCollection.listType=='vevent')
  395. {
  396. color = $('#ResourceCalDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('get').toHexString();
  397. if(inputCollection.fcSource!=null)
  398. {
  399. inputCollection.fcSource.backgroundColor=hexToRgba(color,0.9);
  400. inputCollection.fcSource.borderColor=color;
  401. inputCollection.fcSource.textColor=checkFontColor(color);
  402. }
  403. secondColl = globalResourceCalDAVList.getTodoCollectionByUID(inputCollection.uid);
  404. if(secondColl!=null)
  405. {
  406. $('#ResourceCalDAVTODOList').find('[data-id="'+inputCollection.uid+'"]').find('.resourceCalDAVColor').css('background',color);
  407. $('#ResourceCalDAVTODOList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('set',color);
  408. if(secondColl.fcSource!=null)
  409. {
  410. secondColl.fcSource.backgroundColor=hexToRgba(color,0.9);
  411. secondColl.fcSource.borderColor=color;
  412. }
  413. }
  414. }
  415. else
  416. {
  417. color = $('#ResourceCalDAVTODOList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('get').toHexString();
  418. if(inputCollection.fcSource!=null)
  419. {
  420. inputCollection.fcSource.backgroundColor=hexToRgba(color,0.9);
  421. inputCollection.fcSource.borderColor=color;
  422. }
  423. secondColl = globalResourceCalDAVList.getEventCollectionByUID(inputCollection.uid);
  424. if(secondColl!=null)
  425. {
  426. $('#ResourceCalDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.resourceCalDAVColor').css('background',color);
  427. $('#ResourceCalDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('set',color);
  428. if(secondColl.fcSource!=null)
  429. {
  430. secondColl.fcSource.backgroundColor=hexToRgba(color,0.9);
  431. secondColl.fcSource.borderColor=color;
  432. secondColl.fcSource.textColor=checkFontColor(color);
  433. }
  434. }
  435. }
  436. inputCollection.ecolor = color;
  437. if(secondColl!=null)
  438. secondColl.ecolor = color;
  439. if(inputCollection.listType=='vevent' || secondColl!=null)
  440. $('#calendar').fullCalendar('refetchEvents');
  441. if(inputCollection.listType=='vtodo' || secondColl!=null)
  442. $('#todoList').fullCalendar('refetchEvents');
  443. }
  444. else if(inputProperty=='addressbook-color')
  445. {
  446. color = $('#ResourceCardDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('get').toHexString();
  447. inputCollection.color = color;
  448. if($('#ResourceCardDAVList').find('[data-id="'+inputCollection.uid+'"]').parent().find('.contact_group').find('div[data-id]').length>0)
  449. $('#ResourceCardDAVList').find('[data-id="'+inputCollection.uid+'"]').parent().find('.contact_group').find('div[data-id]').find('.resourceCardDAVGroupColor').css('background',color);
  450. globalAddressbookList.applyABFilter(dataGetChecked('#ResourceCardDAVList'), false);
  451. var selUID = $('#vCardEditor').find('[data-attr-name="_DEST_"]').find('option:selected').attr('data-type');
  452. var selColl=globalResourceCardDAVList.getCollectionByUID(selUID);
  453. $('#ABContactColor').css('background-color', selColl.color);
  454. }
  455. }
  456. });
  457. }
  458. function DAVresourceDelegation(inputResource, index, lastIndex)
  459. {
  460. globalCalDAVResourceSync=false;
  461. var tmp=algoo_replace_regex(inputResource.href, globalAccountSettings);
  462. var baseHref=tmp[1]+tmp[2];
  463. var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2];
  464. var uidFull=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]+tmp[3]; //for the error handler
  465. var settingsXML='';
  466. var delegationXML='';
  467. if(typeof inputResource.extendedDelegation!='undefined' && inputResource.extendedDelegation)
  468. {
  469. if(inputResource.href.indexOf(globalLoginUsername)!=-1 && inputResource.settingsAccount && (globalSettings.settingstype.value=='' || globalSettings.settingstype.value==null || (globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null && globalSettings.settingstype.value=='principal-URL')))
  470. settingsXML = '<D:property name="settings" namespace="http://inf-it.com/ns/dav/"/>';
  471. delegationXML='<?xml version="1.0" encoding="utf-8"?><D:expand-property xmlns:D="DAV:"><D:property name="calendar-proxy-read-for" namespace="http://calendarserver.org/ns/"><D:property name="resourcetype"/><D:property name="current-user-privilege-set"/><D:property name="displayname"/><D:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/><D:property name="calendar-home-set" namespace="urn:ietf:params:xml:ns:caldav"/><D:property name="addressbook-home-set" namespace="urn:ietf:params:xml:ns:carddav"/></D:property><D:property name="calendar-proxy-write-for" namespace="http://calendarserver.org/ns/"><D:property name="resourcetype"/><D:property name="current-user-privilege-set"/><D:property name="displayname"/><D:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/><D:property name="calendar-home-set" namespace="urn:ietf:params:xml:ns:caldav"/><D:property name="addressbook-home-set" namespace="urn:ietf:params:xml:ns:carddav"/></D:property>'+settingsXML+'<D:property name="resourcetype"/><D:property name="current-user-privilege-set"/><D:property name="displayname"/><D:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/><D:property name="calendar-home-set" namespace="urn:ietf:params:xml:ns:caldav"/><D:property name="addressbook-home-set" namespace="urn:ietf:params:xml:ns:carddav"/></D:expand-property>';
  472. }
  473. else
  474. delegationXML='<?xml version="1.0" encoding="utf-8"?><A:expand-property xmlns:A="DAV:"><A:property name="calendar-proxy-read-for" namespace="http://calendarserver.org/ns/"><A:property name="email-address-set" namespace="http://calendarserver.org/ns/"/><A:property name="displayname" namespace="DAV:"/><A:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/></A:property><A:property name="calendar-proxy-write-for" namespace="http://calendarserver.org/ns/"><A:property name="email-address-set" namespace="http://calendarserver.org/ns/"/><A:property name="displayname" namespace="DAV:"/><A:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/></A:property></A:expand-property>';
  475. function ajaxComplete(data, textStatus, xml)
  476. {
  477. if(typeof globalAccountSettings=='undefined')
  478. globalAccountSettings=[];
  479. var hostPart=tmp[1]+tmp[2];
  480. var propElement=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop');
  481. var searchR=new Array();
  482. searchR[searchR.length]=$(propElement).children().filterNsNode('calendar-proxy-read-for');
  483. searchR[searchR.length]=$(propElement).children().filterNsNode('calendar-proxy-write-for');
  484. for(var m=0; m<searchR.length; m++)
  485. {
  486. searchR[m].children().filterNsNode('response').each(
  487. function(dindex,delement){
  488. var href = $(delement).children().filterNsNode('href').text();
  489. var found=false;
  490. for(var i=0; i<globalAccountSettings.length; i++)
  491. if(decodeURIComponent(globalAccountSettings[i].href)==(hostPart+href))
  492. found=true;
  493. if(!found)
  494. {
  495. globalAccountSettings[globalAccountSettings.length]=$.extend({}, inputResource);
  496. globalAccountSettings[globalAccountSettings.length-1].type=inputResource.type;
  497. globalAccountSettings[globalAccountSettings.length-1].href=decodeURIComponent(hostPart+href);
  498. globalAccountSettings[globalAccountSettings.length-1].userAuth={userName: inputResource.userAuth.userName, userPassword: inputResource.userAuth.userPassword};
  499. }
  500. if(typeof inputResource.extendedDelegation!='undefined' && inputResource.extendedDelegation)
  501. {
  502. $(delement).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('calendar-user-address-set').children().each(
  503. function(ind, elm)
  504. {
  505. var pHref = $(elm).text();
  506. if(pHref.indexOf('mailto:')!=-1)
  507. globalAccountSettings[globalAccountSettings.length-1].principalEmail=pHref.split('mailto:')[1];
  508. });
  509. var addressbook_home=$(delement).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('addressbook-home-set').children().filterNsNode('href').text();
  510. if(addressbook_home=='') // addressbook-home-set has no 'href' value -> SabreDav
  511. addressbook_home=$(delement).children().filterNsNode('href').text().replace('/principals/users/caldav.php','/caldav.php');
  512. if(addressbook_home.match(RegExp('^https?://','i'))!=null) // absolute URL returned
  513. globalAccountSettings[globalAccountSettings.length-1].abhref=addressbook_home;
  514. else // relative URL returned
  515. globalAccountSettings[globalAccountSettings.length-1].abhref=baseHref+addressbook_home;
  516. var calendar_home=$(delement).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('calendar-home-set').children().filterNsNode('href').text();
  517. if(calendar_home=='') // addressbook-home-set has no 'href' value -> SabreDav
  518. calendar_home=$(delement).children().filterNsNode('href').text().replace('/principals/users/caldav.php','/caldav.php');
  519. if(calendar_home.match(RegExp('^https?://','i'))!=null) // absolute URL returned
  520. globalAccountSettings[globalAccountSettings.length-1].cahref=calendar_home;
  521. else // relative URL returned
  522. globalAccountSettings[globalAccountSettings.length-1].cahref=baseHref+calendar_home;
  523. }
  524. });
  525. }
  526. if(typeof inputResource.extendedDelegation!='undefined' && inputResource.extendedDelegation && !settingsLoaded && inputResource.href.indexOf(globalLoginUsername)!=-1 && inputResource.settingsAccount && (globalSettings.settingstype.value=='' || globalSettings.settingstype.value==null || (globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null && globalSettings.settingstype.value=='principal-URL')))
  527. {
  528. var settings=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('settings').text();
  529. if(settings!='')
  530. {
  531. if(!ignoreServerSettings)
  532. loadSettings(settings, true, false);
  533. else
  534. {
  535. delete globalSettings.version.value;
  536. loadSettings(JSON.stringify(globalSettings), false, false);
  537. console.log('Ignoring server settings: '+'\n'+settings);
  538. }
  539. }
  540. else
  541. {
  542. delete globalSettings.version.value;
  543. loadSettings(JSON.stringify(globalSettings), false, false);
  544. }
  545. }
  546. if(typeof inputResource.extendedDelegation!='undefined' && inputResource.extendedDelegation)
  547. {
  548. var response=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response');
  549. $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('calendar-user-address-set').children().each(
  550. function(ind, elm)
  551. {
  552. var pHref = $(elm).text();
  553. if(pHref.indexOf('mailto:')!=-1)
  554. inputResource.principalEmail=pHref.split('mailto:')[1];
  555. });
  556. if(globalEmailAddress==''&&typeof inputResource.principalEmail!= 'undefined')
  557. globalEmailAddress=inputResource.principalEmail;
  558. var addressbook_home=response.children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('addressbook-home-set').children().filterNsNode('href').text();
  559. if(addressbook_home=='') // addressbook-home-set has no 'href' value -> SabreDav
  560. addressbook_home=response.children().filterNsNode('href').text().replace('/principals/users/caldav.php','/caldav.php');
  561. if(addressbook_home.match(RegExp('^https?://','i'))!=null) // absolute URL returned
  562. inputResource.abhref=addressbook_home;
  563. else // relative URL returned
  564. inputResource.abhref=baseHref+addressbook_home;
  565. var calendar_home=response.children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('calendar-home-set').children().filterNsNode('href').text();
  566. if(calendar_home=='') // addressbook-home-set has no 'href' value -> SabreDav
  567. calendar_home=response.children().filterNsNode('href').text().replace('/principals/users/caldav.php','/caldav.php');
  568. if(calendar_home.match(RegExp('^https?://','i'))!=null) // absolute URL returned
  569. inputResource.cahref=calendar_home;
  570. else // relative URL returned
  571. inputResource.cahref=baseHref+calendar_home;
  572. }
  573. if(index==lastIndex)
  574. {
  575. // start the client
  576. if(isAvaible('CardDavMATE'))
  577. runCardDAV();
  578. if(isAvaible('CalDavZAP'))
  579. runCalDAV();
  580. if(isAvaible('Projects'))
  581. runProjects();
  582. if(isAvaible('Settings'))
  583. runSettings();
  584. globalResourceNumber=globalAccountSettings.length;
  585. loadAllResources();
  586. }
  587. }
  588. // first try to process the cached data (if cached results are available in the "auth module" response)
  589. var tmpCache;
  590. var tmpDav = inputResource.href.match('^(.*/)([^/]+)/$');
  591. if(globalXMLCache!=null && (tmpCache=globalXMLCache.children('davprincipaldelegation[request_url="'+jqueryEscapeSelector(tmpDav[1]+encodeURIComponent(tmpDav[2])+'/')+'"]').remove()).length)
  592. {
  593. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  594. console.log('DBG Cache OK: '+arguments.callee.name+' url: \''+inputResource.href+'\': saved one request!');
  595. ajaxComplete('', 'success', {responseXML: tmpCache});
  596. }
  597. else
  598. {
  599. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  600. console.log('DBG Cache ERROR: '+arguments.callee.name+' url: \''+inputResource.href+'\': spend one request!');
  601. $.ajax({
  602. type: 'REPORT',
  603. url: inputResource.href,
  604. cache: false,
  605. crossDomain: (typeof inputResource.crossDomain=='undefined' ? true: inputResource.crossDomain),
  606. xhrFields:
  607. {
  608. withCredentials: (typeof inputResource.withCredentials=='undefined' ? false: inputResource.withCredentials)
  609. },
  610. timeout: inputResource.timeOut,
  611. beforeSend: function(req)
  612. {
  613. if(globalSettings.usejqueryauth.value!=true && inputResource.userAuth.userName!='' && inputResource.userAuth.userPassword!='')
  614. req.setRequestHeader('Authorization', basicAuth(inputResource.userAuth.userName, inputResource.userAuth.userPassword));
  615. req.setRequestHeader('X-client', globalXClientHeader);
  616. req.setRequestHeader('Depth', '0');
  617. },
  618. username: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userName : null),
  619. password: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userPassword : null),
  620. contentType: 'text/xml',
  621. processData: true,
  622. data: delegationXML,
  623. dataType: 'xml',
  624. error: function(objAJAXRequest, strError)
  625. {
  626. console.log("Error: [DAVresourceDelegation: 'REPORT "+uidFull+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' (this error code usually means network connection error, or your browser is trying to make a cross domain query, but it is not allowed by the destination server or the browser itself)': ''));
  627. },
  628. success: ajaxComplete
  629. });
  630. }
  631. }
  632. function netFindResource(inputResource, inputResourceIndex, forceLoad, indexR, loadArray)
  633. {
  634. if(globalPreventLogoutSync)
  635. {
  636. logout(true);
  637. return false;
  638. }
  639. if(indexR<globalAccountSettings.length)
  640. {
  641. globalResourceNumberCount++;
  642. if((isAvaible('CardDavMATE') && globalCardDAVInitLoad) || (isAvaible('CalDavZAP') && globalCalDAVInitLoad) || (isAvaible('Projects') && !isProjectsLoaded) || (isAvaible('Settings') && !isSettingsLoaded))
  643. $('#MainLoaderInner').html(localization[globalInterfaceLanguage].loadingResources.replace('%act%', globalResourceNumberCount).replace('%total%', globalResourceNumber));
  644. }
  645. if((typeof inputResource!='undefined' && typeof inputResource.collectionTypes!='undefined' && inputResource.collectionTypes!=null && (inputResource.collectionTypes.indexOf('calendar')==-1) && inputResource.collectionTypes.indexOf('addressbook')==-1) || (typeof inputResource!='undefined' && typeof loadArray!='undefined' && loadArray!=null && loadArray.indexOf(inputResource.href)==-1))
  646. {
  647. indexR++;
  648. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  649. return false;
  650. }
  651. if(indexR>=globalAccountSettings.length && settingsLoaded)
  652. {
  653. if(globalResourceIntervalID==null)
  654. globalResourceIntervalID=setInterval(reloadResources, globalSettings.syncresourcesinterval.value);
  655. globalCalDAVResourceSync=false;
  656. globalCardDAVResourceSync=false;
  657. globalSyncSettingsSave=false;
  658. var rexo=new RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)');
  659. var rex=new RegExp('^(https?://)(.*)', 'i');
  660. var accRex=new RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)', 'i');
  661. if((isAvaible('CalDavZAP') && !isCalDAVLoaded) || (isAvaible('CardDavMATE') && !isCardDAVLoaded))
  662. {
  663. if(isAvaible('CalDavZAP'))
  664. {
  665. if(!globalDefaultCalendarCollectionActiveAll)
  666. {
  667. for(var i=0; i<globalSettings.activecalendarcollections.value.length; i++)
  668. {
  669. if(typeof globalCrossServerSettingsURL!='undefined' && globalCrossServerSettingsURL!=null && globalCrossServerSettingsURL)
  670. {
  671. var tmpParts2=globalSettings.activecalendarcollections.value[i].match('^(.*/)([^/]+)/([^/]+)/$');
  672. var checkHref2=tmpParts2[2]+'/'+tmpParts2[3]+'/';
  673. if($('#ResourceCalDAVList input[data-id$="'+checkHref2+'"]:visible').length>0)
  674. {
  675. var elm=$('#ResourceCalDAVList input[data-id$="'+checkHref2+'"]');
  676. elm.trigger('click');
  677. globalVisibleCalDAVCollections.splice(globalVisibleCalDAVCollections.length, 0, elm.attr('data-id'));
  678. }
  679. }
  680. else
  681. {
  682. var uidPart=globalSettings.activecalendarcollections.value[i].match(rex)[1];
  683. var uidPart2=globalSettings.activecalendarcollections.value[i].match(rex)[2];
  684. if(globalLoginUsername!='')
  685. var uidPart3=globalLoginUsername;
  686. else
  687. var uidPart3=globalAccountSettings[0].userAuth.userName;
  688. var uid = uidPart+uidPart3+'@'+uidPart2;
  689. if($('#ResourceCalDAVList input[data-id="'+uid+'"]:visible').length>0)
  690. {
  691. $('#ResourceCalDAVList input[data-id="'+uid+'"]').trigger('click');
  692. globalVisibleCalDAVCollections.splice(globalVisibleCalDAVCollections.length, 0, uid);
  693. }
  694. }
  695. }
  696. if(globalSettings.activecalendarcollections.value.length>0 && globalVisibleCalDAVCollections.length==0)
  697. globalDefaultCalendarCollectionActiveAll=true;
  698. }
  699. if(globalDefaultCalendarCollectionActiveAll)
  700. for(var i=0; i<globalResourceCalDAVList.collections.length; i++)
  701. {
  702. if(globalResourceCalDAVList.collections[i].uid!=undefined && $('#ResourceCalDAVList input[data-id="'+globalResourceCalDAVList.collections[i].uid+'"]:visible').length>0)
  703. {
  704. $('#ResourceCalDAVList input[data-id="'+globalResourceCalDAVList.collections[i].uid+'"]').trigger('click');
  705. globalVisibleCalDAVCollections.splice(globalVisibleCalDAVCollections.length, 0, globalResourceCalDAVList.collections[i].uid);
  706. }
  707. }
  708. if(!globalDefaultTodoCalendarCollectionActiveAll)
  709. {
  710. for(var i=0; i<globalSettings.activetodocollections.value.length; i++)
  711. {
  712. if(typeof globalCrossServerSettingsURL!='undefined' && globalCrossServerSettingsURL!=null && globalCrossServerSettingsURL)
  713. {
  714. var tmpParts2=globalSettings.activetodocollections.value[i].match('^(.*/)([^/]+)/([^/]+)/$');
  715. var checkHref2=tmpParts2[2]+'/'+tmpParts2[3]+'/';
  716. if($('#ResourceCalDAVTODOList input[data-id$="'+checkHref2+'"]:visible').length>0)
  717. {
  718. var elm=$('#ResourceCalDAVTODOList input[data-id$="'+checkHref2+'"]');
  719. elm.trigger('click');
  720. globalVisibleCalDAVTODOCollections.splice(globalVisibleCalDAVTODOCollections.length, 0, elm.attr('data-id'));
  721. }
  722. }
  723. else
  724. {
  725. var uidPart=globalSettings.activetodocollections.value[i].match(rex)[1];
  726. var uidPart2=globalSettings.activetodocollections.value[i].match(rex)[2];
  727. if(globalLoginUsername!='')
  728. var uidPart3=globalLoginUsername;
  729. else
  730. var uidPart3=globalAccountSettings[0].userAuth.userName;
  731. var uid=uidPart+uidPart3+'@'+uidPart2;
  732. if($('#ResourceCalDAVTODOList input[data-id="'+uid+'"]:visible').length>0)
  733. {
  734. $('#ResourceCalDAVTODOList input[data-id="'+uid+'"]').trigger('click');
  735. globalVisibleCalDAVTODOCollections.splice(globalVisibleCalDAVTODOCollections.length, 0, uid);
  736. }
  737. }
  738. }
  739. if(globalSettings.activetodocollections.value.length>0 && globalVisibleCalDAVTODOCollections.length==0)
  740. globalDefaultTodoCalendarCollectionActiveAll=true;
  741. }
  742. if(globalDefaultTodoCalendarCollectionActiveAll)
  743. for(var i=0; i<globalResourceCalDAVList.TodoCollections.length; i++)
  744. {
  745. if(globalResourceCalDAVList.TodoCollections[i].uid!=undefined && $('#ResourceCalDAVTODOList input[data-id="'+globalResourceCalDAVList.TodoCollections[i].uid+'"]:visible').length>0)
  746. {
  747. $('#ResourceCalDAVTODOList input[data-id="'+globalResourceCalDAVList.TodoCollections[i].uid+'"]').trigger('click');
  748. globalVisibleCalDAVTODOCollections.splice(globalVisibleCalDAVTODOCollections.length, 0, globalResourceCalDAVList.TodoCollections[i].uid);
  749. }
  750. }
  751. if($('#ResourceCalDAVList .resourceCalDAV_item[data-id]:visible').length==0 && globalResourceCalDAVList.collections.length>1)
  752. {
  753. var enabledArray=new Array();
  754. for(var c=0; c<globalResourceCalDAVList.collections.length; c++)
  755. if(globalResourceCalDAVList.collections[c].uid!=undefined)
  756. {
  757. var tmp=globalResourceCalDAVList.collections[c].accountUID.match(accRex);
  758. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  759. if(globalAccountSettings[0].href==resourceCalDAV_href && globalAccountSettings[0].userAuth.userName==globalResourceCalDAVList.collections[c].userAuth.userName)
  760. enabledArray.push(globalResourceCalDAVList.collections[c]);
  761. }
  762. if(enabledArray.length==0)
  763. enabledArray.push(globalResourceCalDAVList.collections[1]);
  764. for(var c=0; c<enabledArray.length; c++)
  765. {
  766. enabledArray[c].makeLoaded=true;
  767. var uidParts=enabledArray[c].uid.match(rexo);
  768. globalSettings.loadedcalendarcollections.value.push(uidParts[1]+uidParts[3]);
  769. var resDOMItem=$('#ResourceCalDAVList').find('.resourceCalDAV_item[data-id="'+jqueryEscapeSelector(enabledArray[c].uid)+'"]');
  770. var resDOMHeader=resDOMItem.prevUntil('.resourceCalDAV_header').last().prev();
  771. if(!resDOMHeader.length)
  772. resDOMHeader=resDOMItem.prev();
  773. resDOMHeader.css('display','block');
  774. resDOMItem.css('display','');
  775. resDOMItem.find('input[type=checkbox]').not('.unloadCheck').trigger('click');
  776. globalVisibleCalDAVCollections.splice(globalVisibleCalDAVCollections.length, 0, enabledArray[c].uid);
  777. }
  778. }
  779. if($('#ResourceCalDAVTODOList .resourceCalDAVTODO_item[data-id]:visible').length==0 && globalResourceCalDAVList.TodoCollections.length>1)
  780. {
  781. var enabledArray=new Array();
  782. for(var c=0; c<globalResourceCalDAVList.TodoCollections.length; c++)
  783. if(globalResourceCalDAVList.TodoCollections[c].uid!=undefined)
  784. {
  785. var tmp=globalResourceCalDAVList.TodoCollections[c].accountUID.match(accRex);
  786. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  787. if(globalAccountSettings[0].href==resourceCalDAV_href && globalAccountSettings[0].userAuth.userName==globalResourceCalDAVList.TodoCollections[c].userAuth.userName)
  788. enabledArray.push(globalResourceCalDAVList.TodoCollections[c]);
  789. }
  790. if(enabledArray.length==0)
  791. enabledArray.push(globalResourceCalDAVList.TodoCollections[1]);
  792. for(var c=0; c<enabledArray.length; c++)
  793. {
  794. $('#ResourceCalDAVTODOList .resourceCalDAVTODO_item[data-id="'+enabledArray[c].uid+'"]').css('display','block')
  795. enabledArray[c].makeLoaded=true;
  796. var uidParts=enabledArray[c].uid.match(rexo);
  797. globalSettings.loadedtodocollections.value.push(uidParts[1]+uidParts[3]);
  798. var resDOMItem=$('#ResourceCalDAVTODOList').find('.resourceCalDAVTODO_item[data-id="'+jqueryEscapeSelector(enabledArray[c].uid)+'"]');
  799. var resDOMHeader=resDOMItem.prevUntil('.resourceCalDAVTODO_header').last().prev();
  800. if(!resDOMHeader.length)
  801. resDOMHeader=resDOMItem.prev();
  802. resDOMHeader.css('display','block');
  803. resDOMItem.css('display','');
  804. resDOMItem.find('input[type=checkbox]').not('.unloadCheck').trigger('click');
  805. globalVisibleCalDAVTODOCollections.splice(globalVisibleCalDAVTODOCollections.length, 0, enabledArray[c].uid);
  806. }
  807. }
  808. $('#ResourceCalDAVList').children('.resourceCalDAV_header').each(function(){
  809. if(!$(this).nextUntil('.resourceCalDAV_header').filter(':visible').length)
  810. $(this).css('display','none');
  811. });
  812. $('#ResourceCalDAVTODOList').children('.resourceCalDAVTODO_header').each(function(){
  813. if(!$(this).nextUntil('.resourceCalDAVTODO_header').filter(':visible').length)
  814. $(this).css('display','none');
  815. });
  816. selectActiveCalendar();
  817. }
  818. if(isAvaible('CardDavMATE'))
  819. {
  820. if($('#ResourceCardDAVList .resourceCardDAV_item:visible').length==0 && globalResourceCardDAVList.collections.length>1)
  821. {
  822. var enabledArray=new Array();
  823. for(var c=0; c<globalResourceCardDAVList.collections.length; c++)
  824. if(globalResourceCardDAVList.collections[c].uid!=undefined)
  825. {
  826. var tmp=globalResourceCardDAVList.collections[c].accountUID.match(accRex);
  827. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  828. if(globalAccountSettings[0].href==resourceCalDAV_href && globalAccountSettings[0].userAuth.userName==globalResourceCardDAVList.collections[c].userAuth.userName)
  829. enabledArray.push(globalResourceCardDAVList.collections[c]);
  830. }
  831. if(enabledArray.length==0)
  832. enabledArray.push(globalResourceCardDAVList.collections[1]);
  833. for(var c=0; c<enabledArray.length; c++)
  834. {
  835. $('#ResourceCardDAVList .resourceCardDAV_item .resourceCardDAV[data-id="'+enabledArray[c].uid+'"]').parent().css('display','block')
  836. enabledArray[c].makeLoaded=true;
  837. //$('#ResourceCardDAVList').find('.resourceCardDAV_item .resourceCardDAV').find('input[data-id="'+enabledArray[c].uid+'"]').trigger('click');
  838. var uidParts=enabledArray[c].uid.match(rexo);
  839. globalSettings.loadedaddressbookcollections.value.push(uidParts[1]+uidParts[3]);
  840. globalSettings.activeaddressbookcollections.value.push(uidParts[1]+uidParts[3]);
  841. }
  842. }
  843. $('#ResourceCardDAVList').children('.resourceCardDAV_header').each(function(){
  844. if(!$(this).nextUntil('.resourceCardDAV_header').filter(':visible').length)
  845. $(this).css('display','none');
  846. });
  847. }
  848. loadNextApplication(true);
  849. }
  850. var isTodoAv=false,isEventAv=false;
  851. if(isAvaible('CalDavZAP'))
  852. {
  853. setCalendarNumber(false);
  854. selectActiveCalendar();
  855. var cals=globalResourceCalDAVList.TodoCollections;
  856. if(cals.length==0 || (cals.length==1 && typeof cals[0].uid=='undefined'))
  857. {
  858. $('#intCaldavTodo').css('display','none');
  859. isTodoAv=false;
  860. }
  861. else
  862. {
  863. $('#intCaldavTodo').css('display','block');
  864. isTodoAv=true;
  865. }
  866. var calendarsArray=new Array();
  867. for(var i=0; i<cals.length; i++)
  868. if(cals[i].uid!=undefined)
  869. calendarsArray[calendarsArray.length]={displayValue:cals[i].displayvalue,uid:cals[i].uid, permissions_read_only:cals[i].permissions.read_only,makeLoaded:cals[i].makeLoaded};
  870. calendarsArray.sort(customResourceCompare);
  871. globalResourceCalDAVList.sortedTodoCollections=calendarsArray;
  872. var cals=globalResourceCalDAVList.collections;
  873. if(cals.length==0 || (cals.length==1 && typeof cals[0].uid=='undefined'))
  874. {
  875. $('#intCaldav').css('display','none');
  876. isEventAv=false;
  877. }
  878. else
  879. {
  880. $('#intCaldav').css('display','block');
  881. isEventAv=true;
  882. }
  883. calendarsArray=new Array();
  884. for(var i=0; i<cals.length; i++)
  885. if(cals[i].uid!=undefined)
  886. calendarsArray[calendarsArray.length]={displayValue:cals[i].displayvalue,uid:cals[i].uid, permissions_read_only:cals[i].permissions.read_only, makeLoaded:cals[i].makeLoaded};
  887. calendarsArray.sort(customResourceCompare);
  888. globalResourceCalDAVList.sortedCollections = calendarsArray;
  889. }
  890. var isAddrAv=false;
  891. if(isAvaible('CardDavMATE'))
  892. {
  893. selectActiveAddressbook();
  894. for(var adr in globalAddressbookList.vcard_groups)
  895. {
  896. if(globalAddressbookList.vcard_groups[adr].length>0)
  897. {
  898. extendDestSelect();
  899. if(typeof $('#vCardEditor').attr('data-vcard-uid')=='undefined')
  900. $('#vCardEditor').find('[data-attr-name="_DEST_"]').find('optiotn[data-type$="'+$('#ResourceCardDAVList').find('.resourceCardDAV_selected').find(':input[data-id]').attr('data-id')+'"]').prop('selected',true);
  901. }
  902. }
  903. var addrs=globalResourceCardDAVList.collections;
  904. if(addrs.length==0 || (addrs.length==1 && typeof addrs[0].uid == 'undefined'))
  905. {
  906. $('#intCarddav').css('display','none');
  907. isAddrAv=false;
  908. }
  909. else
  910. {
  911. isAddrAv=true;
  912. $('#intCarddav').css('display','block');
  913. }
  914. }
  915. if((isAvaible('CalDavZAP') && !isCalDAVLoaded) || (isAvaible('CardDavMATE') && !isCardDAVLoaded))
  916. {
  917. if(isAvaible('CalDavZAP'))
  918. {
  919. if(globalActiveApp=='CalDavTODO')
  920. if(!isTodoAv)
  921. globalActiveApp=null;
  922. if(globalActiveApp==null || globalActiveApp=='CalDavZAP')
  923. {
  924. if(!isEventAv)
  925. globalActiveApp=null;
  926. else
  927. globalActiveApp='CalDavZAP';
  928. }
  929. }
  930. if(isAvaible('CardDavMATE') && (globalActiveApp==null || globalActiveApp=='CardDavMATE'))
  931. {
  932. if(!isAddrAv)
  933. globalActiveApp=null;
  934. else
  935. globalActiveApp='CardDavMATE';
  936. }
  937. if(globalActiveApp!=null)
  938. checkForApplication(globalActiveApp);
  939. }
  940. ifLoadCollections();
  941. if(isAvaible('CalDavZAP'))
  942. {
  943. if($('#ResourceCalDAVList .resourceCalDAV_item:visible').not('.resourceCalDAV_item_ro').length==0)
  944. {
  945. $('#eventFormShower').css('display','none');
  946. $('#calendar').fullCalendar('setOptions',{'selectable':false});
  947. }
  948. else
  949. {
  950. $('#eventFormShower').css('display','block');
  951. $('#calendar').fullCalendar('setOptions',{'selectable':true});
  952. }
  953. if($('#ResourceCalDAVTODOList .resourceCalDAVTODO_item:visible').not('.resourceCalDAV_item_ro').length==0)
  954. $('#eventFormShowerTODO').css('display','none');
  955. else
  956. $('#eventFormShowerTODO').css('display','block');
  957. }
  958. return false;
  959. }
  960. else if(indexR>=globalAccountSettings.length && !settingsLoaded)
  961. {
  962. console.log("Error: [netFindResource]: 'Unable to load resources'");
  963. return false;
  964. }
  965. var tmp = algoo_replace_regex(inputResource.href, globalAccountSettings);
  966. var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2];
  967. var uidFull=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]+tmp[3]; // for the error handler
  968. var settingsXML='';
  969. if(inputResource.href.indexOf(globalLoginUsername)!=-1 && inputResource.settingsAccount && (globalSettings.settingstype.value=='' || globalSettings.settingstype.value==null || (globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null && globalSettings.settingstype.value=='principal-URL')))
  970. settingsXML='<I:settings xmlns:I="http://inf-it.com/ns/dav/"/>';
  971. var baseHref=tmp[1]+tmp[2];
  972. if(typeof inputResource.extendedDelegation!='undefined' && inputResource.extendedDelegation && (typeof inputResource.abhref!='undefined' || typeof inputResource.cahref!='undefined'))
  973. {
  974. if(isAvaible('CardDavMATE') && isAvaible('CalDavZAP'))
  975. {
  976. if(inputResource.abhref==inputResource.cahref)
  977. netLoadResource(inputResource, inputResource.abhref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  978. else
  979. netLoadResource(inputResource, inputResource.abhref, true, inputResourceIndex, forceLoad, indexR, loadArray);
  980. }
  981. else if(isAvaible('CardDavMATE'))
  982. netLoadResource(inputResource, inputResource.abhref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  983. else if(isAvaible('CalDavZAP'))
  984. netLoadResource(inputResource, inputResource.cahref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  985. return false;
  986. }
  987. $.ajax({
  988. type: 'PROPFIND',
  989. url: inputResource.href,
  990. cache: false,
  991. crossDomain: (typeof inputResource.crossDomain=='undefined' ? true : inputResource.crossDomain),
  992. xhrFields: {
  993. withCredentials: (typeof inputResource.withCredentials=='undefined' ? false : inputResource.withCredentials)
  994. },
  995. timeout: inputResource.timeOut,
  996. beforeSend: function(req) {
  997. if(globalSettings.usejqueryauth.value!=true && inputResource.userAuth.userName!='' && inputResource.userAuth.userPassword!='')
  998. req.setRequestHeader('Authorization', basicAuth(inputResource.userAuth.userName,inputResource.userAuth.userPassword));
  999. req.setRequestHeader('X-client', globalXClientHeader);
  1000. req.setRequestHeader('Depth', '0');
  1001. if(globalSettingsSaving!=''||(isAvaible('CardDavMATE') && (!globalCardDAVInitLoad && !globalCardDAVResourceSync)) || (isAvaible('CalDavZAP') && (!globalCalDAVInitLoad && !globalCalDAVResourceSync))||(isAvaible('Projects') && isProjectsLoaded))
  1002. /* XXX - System display:none changes */
  1003. if(globalSettingsSaving!='' || (isAvaible('Settings') && $('#SystemSettings').css('visibility')=='visible' && $('.resourceSettings_item_selected').attr('data-type')=='setting_group_password'))
  1004. {
  1005. indexR++;
  1006. if(((isAvaible('CardDavMATE') && globalCardDAVInitLoad) || (isAvaible('CalDavZAP') && globalCalDAVInitLoad)) && indexR==globalAccountSettings.length)
  1007. $('#MainLoader').fadeOut(1200);
  1008. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  1009. return false;
  1010. }
  1011. },
  1012. username: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userName : null),
  1013. password: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userPassword : null),
  1014. contentType: 'text/xml; charset=utf-8',
  1015. processData: true,
  1016. data: '<?xml version="1.0" encoding="utf-8"?><D:propfind xmlns:D="DAV:"><D:prop>'+settingsXML+'<D:current-user-privilege-set/><D:displayname/><D:resourcetype/><L:calendar-home-set xmlns:L="urn:ietf:params:xml:ns:caldav"/><R:addressbook-home-set xmlns:R="urn:ietf:params:xml:ns:carddav"/></D:prop></D:propfind>',
  1017. dataType: 'xml',
  1018. error: function(objAJAXRequest, strError){
  1019. console.log("Error: [netFindResource: 'PROPFIND "+uidFull+"']: code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  1020. indexR++;
  1021. inputResource.errorLoaded=true;
  1022. if(isAvaible('CalDavZAP'))
  1023. {
  1024. $('#intCaldav').find('.int_error').css('display', 'block');
  1025. $('#intCaldavTodo').find('.int_error').css('display', 'block');
  1026. }
  1027. if(isAvaible('CardDavMATE'))
  1028. $('#intCarddav').find('.int_error').css('display', 'block');
  1029. var allFail=true;
  1030. for(var i=0; i< globalAccountSettings.length; i++)
  1031. if(typeof globalAccountSettings[i].errorLoaded=='undefined' || globalAccountSettings[i].errorLoaded==null || globalAccountSettings[i].errorLoaded===false)
  1032. allFail=false;
  1033. if(((isAvaible('CardDavMATE') && globalCardDAVInitLoad) || (isAvaible('CalDavZAP' && globalCalDAVInitLoad))) && indexR==globalAccountSettings.length && allFail)
  1034. $('#MainLoader').fadeOut(1200);
  1035. else if((isAvaible('CardDavMATE') && !globalCardDAVInitLoad) || (isAvaible('CalDavZAP') && !globalCalDAVInitLoad))
  1036. {
  1037. if(isAvaible('CalDavZAP'))
  1038. handleCalDAVError(true, inputResource);
  1039. if(isAvaible('CardDavMATE'))
  1040. handleCardDAVError(true, inputResource)
  1041. }
  1042. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  1043. return false;
  1044. },
  1045. success: function(data, textStatus, xml)
  1046. {
  1047. inputResource.errorLoaded=false;
  1048. if(isAvaible('CalDavZAP') && isEachResourceLoaded())
  1049. {
  1050. $('#intCaldav').find('.int_error').css('display', 'none');
  1051. $('#intCaldavTodo').find('.int_error').css('display', 'none');
  1052. }
  1053. if(isAvaible('CardDavMATE') && isEachResourceLoaded())
  1054. $('#intCarddav').find('.int_error').css('display','none');
  1055. if(isAvaible('CalDavZAP') && !globalCalDAVInitLoad)
  1056. handleCalDAVError(false, inputResource);
  1057. if(isAvaible('CardDavMATE') && !globalCardDAVInitLoad)
  1058. handleCardDAVError(false, inputResource);
  1059. if(!settingsLoaded && inputResource.href.indexOf(globalLoginUsername)!=-1 && inputResource.settingsAccount && (globalSettings.settingstype.value=='' || globalSettings.settingstype.value==null || (globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null && globalSettings.settingstype.value=='principal-URL')))
  1060. {
  1061. var settings=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('settings').text();
  1062. if(settings!='')
  1063. {
  1064. if(!ignoreServerSettings)
  1065. loadSettings(settings, true, false);
  1066. else
  1067. {
  1068. delete globalSettings.version.value;
  1069. loadSettings(JSON.stringify(globalSettings), false, false);
  1070. console.log('Ignoring server settings: '+'\n'+settings);
  1071. }
  1072. }
  1073. else
  1074. {
  1075. delete globalSettings.version.value;
  1076. loadSettings(JSON.stringify(globalSettings), false, false);
  1077. }
  1078. }
  1079. else if(!globalSyncSettingsSave && inputResource.href.indexOf(globalLoginUsername)!=-1 && ((isAvaible('CardDavMATE')&&globalCardDAVResourceSync) || (isAvaible('CalDavZAP')&&globalCalDAVResourceSync)))
  1080. {
  1081. globalSyncSettingsSave=true;
  1082. var loadedCals = new Array(), loadedTodoCals = new Array(), loadedAddrs = new Array();
  1083. if(isAvaible('CardDavMATE'))
  1084. loadedAddrs = globalSettings.loadedaddressbookcollections.value.slice();
  1085. if(isAvaible('CalDavZAP'))
  1086. {
  1087. loadedCals = globalSettings.loadedcalendarcollections.value.slice();
  1088. loadedTodoCals = globalSettings.loadedtodocollections.value.slice();
  1089. }
  1090. var settings = $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('settings').text();
  1091. if(typeof globalPreviousSupportedSettings !='undefined' && globalPreviousSupportedSettings!=null)
  1092. loadSettings(settings, true, true);
  1093. if(isAvaible('CardDavMATE'))
  1094. globalSettings.loadedaddressbookcollections.value = loadedAddrs.slice();
  1095. if(isAvaible('CalDavZAP'))
  1096. {
  1097. globalSettings.loadedcalendarcollections.value = loadedCals.slice();
  1098. globalSettings.loadedtodocollections.value = loadedTodoCals.slice();
  1099. }
  1100. checkBeforeClose(false);
  1101. }
  1102. var response=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response');
  1103. var addressbook_home=response.children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('addressbook-home-set').children().filterNsNode('href').text();
  1104. if(addressbook_home=='') // addressbook-home-set has no 'href' value -> SabreDav
  1105. addressbook_home=response.children().filterNsNode('href').text().replace('/principals/users/caldav.php','/caldav.php');
  1106. if(addressbook_home.match(RegExp('^https?://','i'))!=null) // absolute URL returned
  1107. inputResource.abhref=addressbook_home;
  1108. else // relative URL returned
  1109. inputResource.abhref=baseHref+addressbook_home;
  1110. var calendar_home=response.children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('calendar-home-set').children().filterNsNode('href').text();
  1111. if(calendar_home=='') // addressbook-home-set has no 'href' value -> SabreDav
  1112. calendar_home=response.children().filterNsNode('href').text().replace('/principals/users/caldav.php','/caldav.php');
  1113. if(calendar_home.match(RegExp('^https?://','i'))!=null) // absolute URL returned
  1114. inputResource.cahref=calendar_home;
  1115. else // relative URL returned
  1116. inputResource.cahref=baseHref+calendar_home;
  1117. if(isAvaible('CardDavMATE') && isAvaible('CalDavZAP'))
  1118. {
  1119. if(inputResource.abhref==inputResource.cahref)
  1120. netLoadResource(inputResource, inputResource.abhref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  1121. else
  1122. netLoadResource(inputResource, inputResource.abhref, true, inputResourceIndex, forceLoad, indexR, loadArray);
  1123. }
  1124. else if(isAvaible('CardDavMATE'))
  1125. netLoadResource(inputResource, inputResource.abhref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  1126. else if(isAvaible('CalDavZAP'))
  1127. netLoadResource(inputResource, inputResource.cahref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  1128. }
  1129. });
  1130. }
  1131. function netLoadResource(inputResource, inputHref, hrefMode, inputResourceIndex, forceLoad, indexR, loadArray)
  1132. {
  1133. if(!isAvaible('CardDavMATE') || !globalCardDAVInitLoad || (globalCardDAVInitLoad && typeof inputResource.addressbookNo == 'undefined'))
  1134. inputResource.addressbookNo=0;
  1135. if(!isAvaible('CalDavZAP') || !globalCalDAVInitLoad || (globalCalDAVInitLoad && typeof inputResource.calendarNo=='undefined' && typeof inputResource.todoNo=='undefined'))
  1136. {
  1137. inputResource.calendarNo=0;
  1138. inputResource.todoNo=0;
  1139. }
  1140. var tmp = algoo_replace_regex(inputResource.abhref, globalAccountSettings);
  1141. var baseHref=tmp[1]+tmp[2];
  1142. var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2];
  1143. var uidFull=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]+tmp[3]; // for the error handler
  1144. var tmp=inputResource.href.match(RegExp('^(https?://)(.*)','i'));
  1145. var origUID=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2];
  1146. if(typeof globalSubscribedCalendars!='undefined' && globalSubscribedCalendars!=null && typeof inputResource.calendars!='undefined' && inputResource.calendars!=null && inputResource.calendars.length>0)
  1147. {
  1148. var tmp1=inputResource.href.match(RegExp('^(https?://)(.*)', 'i'));
  1149. var origUID1=tmp1[1]+inputResource.userAuth.userName+'@'+tmp1[2];
  1150. var resultTimestamp=new Date().getTime();
  1151. for(var k=0; k<globalSubscribedCalendars.calendars.length; k++)
  1152. {
  1153. color=globalSubscribedCalendars.calendars[k].color;
  1154. if(color=='')
  1155. {
  1156. var par=(uidBase+globalSubscribedCalendars.calendars[k].href).split('/');
  1157. var hash=hex_sha256(hex_sha256(par[par.length-3]+'/'+par[par.length-2]+'/'));
  1158. var hex=hash.substring(0,6);
  1159. while(checkColorBrightness(hex)>=252)
  1160. hex=hex_sha256(hex_sha256(hash)).substring(0,6);
  1161. color='#'+hex;
  1162. }
  1163. var syncRequired=true;
  1164. var uidPArts=(uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/').split('/');
  1165. if(globalSubscribedCalendars.calendars[k].typeList.indexOf('vevent')!=-1)
  1166. {
  1167. var uidParts=(uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/').match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)'));
  1168. var checkHref=uidParts[1]+uidParts[3];
  1169. if(!isHrefSet)
  1170. {
  1171. saveHref=uidBase+href;
  1172. isHrefSet=true;
  1173. }
  1174. if(!globalDefaultCalendarCollectionLoadAll)
  1175. {
  1176. var toBeLoad=false;
  1177. if(typeof globalCrossServerSettingsURL!='undefined' && globalCrossServerSettingsURL!=null && globalCrossServerSettingsURL)
  1178. {
  1179. var uidParts=(uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/').match(RegExp('/([^/]+/[^/]+/)$'));
  1180. var tmpParts=uidParts[1].match('^(.*/)([^/]+)/$');
  1181. var checkHref3=decodeURIComponent(tmpParts[1])+tmpParts[2]+'/';
  1182. var found=false;
  1183. for(var l=0; l<globalSettings.loadedcalendarcollections.value.length; l++)
  1184. {
  1185. var tmpParts2=globalSettings.loadedcalendarcollections.value[l].match('^(.*/)([^/]+)/([^/]+)/$');
  1186. var checkHref2=decodeURIComponent(tmpParts2[2])+'/'+tmpParts2[3]+'/';
  1187. if(checkHref3==checkHref2)
  1188. {
  1189. found=true;
  1190. globalSettings.loadedcalendarcollections.value[l]=checkHref;
  1191. break;
  1192. }
  1193. }
  1194. toBeLoad=found;
  1195. }
  1196. else
  1197. toBeLoad=globalSettings.loadedcalendarcollections.value.indexOf(checkHref)!=-1;
  1198. }
  1199. else
  1200. {
  1201. if(globalCalDAVInitLoad)
  1202. globalSettings.loadedcalendarcollections.value.push(checkHref);
  1203. var toBeLoad=true;
  1204. }
  1205. globalResourceCalDAVList.insertResource({makeLoaded:toBeLoad, typeList:globalSubscribedCalendars.calendars[k].typeList, listType:'vevent', syncRequired:syncRequired, ecolor: color, timestamp: resultTimestamp, uid: uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/', timeOut: inputResource.timeOut, displayvalue: globalSubscribedCalendars.calendars[k].displayName, userAuth: globalSubscribedCalendars.calendars[k].userAuth, resourceIndex: indexR, url: baseHref, accountUID: origUID1, href: globalSubscribedCalendars.calendars[k].href, hrefLabel: globalSubscribedCalendars.hrefLabel, permissions: {full: [], read_only: true}, crossDomain: inputResource.crossDomain, withCredentials: inputResource.withCredentials, interval: null, waitInterval: null, displayEventsArray: new Array(), pastUnloaded: '', fcSource: null,subscription: true, newlyAdded:toBeLoad, urlArray: new Array(), ignoreAlarms:globalSubscribedCalendars.calendars[k].ignoreAlarm,webdav_bind:false}, indexR, true);
  1206. if(inputResource!=undefined)
  1207. inputResource.calendarNo++;
  1208. syncRequired=false;
  1209. }
  1210. if(globalSubscribedCalendars.calendars[k].typeList.indexOf('vtodo')!=-1)
  1211. {
  1212. var uidParts=(uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/').match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)'));
  1213. var checkHref=uidParts[1]+uidParts[3];
  1214. if(!isHrefSet)
  1215. {
  1216. saveHref=uidBase+href;
  1217. isHrefSet=true;
  1218. }
  1219. if(!globalDefaultTodoCalendarCollectionLoadAll)
  1220. {
  1221. var toBeLoad=false;
  1222. if(typeof globalCrossServerSettingsURL!='undefined'&&globalCrossServerSettingsURL!=null&globalCrossServerSettingsURL)
  1223. {
  1224. var uidParts=(uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/').match(RegExp('/([^/]+/[^/]+/)$'));
  1225. var tmpParts=uidParts[1].match('^(.*/)([^/]+)/$');
  1226. var checkHref3=decodeURIComponent(tmpParts[1])+tmpParts[2]+'/';
  1227. var found=false;
  1228. for(var l=0; l<globalSettings.loadedtodocollections.value.length; l++)
  1229. {
  1230. var tmpParts2=globalSettings.loadedtodocollections.value[l].match('^(.*/)([^/]+)/([^/]+)/$');
  1231. var checkHref2=decodeURIComponent(tmpParts2[2])+'/'+tmpParts2[3]+'/';
  1232. if(checkHref3==checkHref2)
  1233. {
  1234. found=true;
  1235. globalSettings.loadedtodocollections.value[l]=checkHref;
  1236. break;
  1237. }
  1238. }
  1239. toBeLoad=found;
  1240. }
  1241. else
  1242. toBeLoad=globalSettings.loadedtodocollections.value.indexOf(checkHref)!=-1;
  1243. }
  1244. else
  1245. {
  1246. var toBeLoad=true;
  1247. if(globalCalDAVInitLoad)
  1248. globalSettings.loadedtodocollections.value.push(checkHref);
  1249. }
  1250. globalResourceCalDAVList.insertResource({makeLoaded:toBeLoad, typeList:globalSubscribedCalendars.calendars[k].typeList, listType:'vtodo', syncRequired:syncRequired, ecolor: color, timestamp: resultTimestamp, uid: uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/', timeOut: inputResource.timeOut, displayvalue: globalSubscribedCalendars.calendars[k].displayName, userAuth: globalSubscribedCalendars.calendars[k].userAuth, resourceIndex: indexR, url: baseHref, accountUID: origUID1, href: globalSubscribedCalendars.calendars[k].href, hrefLabel: globalSubscribedCalendars.hrefLabel, permissions: {full: [], read_only: true}, crossDomain: inputResource.crossDomain, withCredentials: inputResource.withCredentials, interval: null, waitInterval: null, displayEventsArray: new Array(), pastUnloaded: '', fcSource: null,subscription: true, newlyAdded:toBeLoad, urlArray: new Array(), ignoreAlarms:globalSubscribedCalendars.calendars[k].ignoreAlarm,webdav_bind:false}, indexR, false);
  1251. if(inputResource!=undefined)
  1252. inputResource.todoNo++;
  1253. }
  1254. }
  1255. //recursive call for resource loading
  1256. indexR++;
  1257. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  1258. return true;
  1259. }
  1260. var settingsXML='';
  1261. if(inputResource.href.indexOf(globalLoginUsername)!=-1 && inputResource.settingsAccount && globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null)
  1262. if((globalSettings.settingstype.value=='addressbook-home-set' && inputResource.abhref==inputHref) || (globalSettings.settingstype.value=='calendar-home-set' && inputResource.cahref==inputHref) || (globalSettings.settingstype.value=='principal-URL'&& ((isAvaible('CardDavMATE')&&globalCardDAVResourceSync) || (isAvaible('CalDavZAP')&&globalCalDAVResourceSync))))
  1263. settingsXML='<I:settings xmlns:I="http://inf-it.com/ns/dav/"/>';
  1264. function ajaxComplete(data, textStatus, xml)
  1265. {
  1266. var Rname='';
  1267. inputResource.errorLoaded=false;
  1268. if(isAvaible('CalDavZAP') && isEachResourceLoaded())
  1269. {
  1270. $('#intCaldav').find('.int_error').css('display','none');
  1271. $('#intCaldavTodo').find('.int_error').css('display','none');
  1272. }
  1273. if(isAvaible('CardDavMATE') && isEachResourceLoaded())
  1274. $('#intCarddav').find('.int_error').css('display','none');
  1275. if(isAvaible('CalDavZAP') && !globalCalDAVInitLoad)
  1276. handleCalDAVError(false, inputResource);
  1277. if(isAvaible('CardDavMATE') && !globalCardDAVInitLoad)
  1278. handleCardDAVError(false, inputResource);
  1279. var saveHref='';
  1280. isHrefSet=false;
  1281. var calendarNo=0;
  1282. var resultTimestamp=new Date().getTime();
  1283. if(!settingsLoaded && inputResource.href.indexOf(globalLoginUsername)!=-1 && inputResource.settingsAccount && globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null)
  1284. {
  1285. if((globalSettings.settingstype.value=='addressbook-home-set' && inputResource.abhref==inputHref) || (globalSettings.settingstype.value=='calendar-home-set' && inputResource.cahref==inputHref))
  1286. {
  1287. var settings=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('settings').text();
  1288. if(settings!='')
  1289. {
  1290. if(!ignoreServerSettings)
  1291. loadSettings(settings, true, false);
  1292. else
  1293. {
  1294. delete globalSettings.version.value;
  1295. loadSettings(JSON.stringify(globalSettings), false, false);
  1296. console.log('Ignoring server settings: '+'\n'+settings);
  1297. }
  1298. }
  1299. else
  1300. {
  1301. var calSettings=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('cal-settings').text();
  1302. if(calSettings!='')
  1303. {
  1304. if(!ignoreServerSettings)
  1305. loadSettings(calSettings, true, false);
  1306. else
  1307. {
  1308. delete globalSettings.version.value;
  1309. loadSettings(JSON.stringify(globalSettings), false, false);
  1310. console.log('Ignoring server settings: '+'\n'+calSettings);
  1311. }
  1312. }
  1313. else
  1314. {
  1315. delete globalSettings.version.value;
  1316. loadSettings(JSON.stringify(globalSettings), false, false);
  1317. }
  1318. }
  1319. }
  1320. }
  1321. else if(!settingsLoaded && inputResource.href.indexOf(globalLoginUsername)!=-1)
  1322. {
  1323. delete globalSettings.version.value;
  1324. loadSettings(JSON.stringify(globalSettings), false, false);
  1325. }
  1326. else if(!globalSyncSettingsSave && inputResource.href.indexOf(globalLoginUsername)!=-1 && ((isAvaible('CardDavMATE')&&globalCardDAVResourceSync) || (isAvaible('CalDavZAP')&&globalCalDAVResourceSync)))
  1327. {
  1328. globalSyncSettingsSave=true;
  1329. var loadedCals = new Array(), loadedTodoCals = new Array(), loadedAddrs = new Array();
  1330. if(isAvaible('CardDavMATE'))
  1331. loadedAddrs = globalSettings.loadedaddressbookcollections.value.slice();
  1332. if(isAvaible('CalDavZAP'))
  1333. {
  1334. loadedCals = globalSettings.loadedcalendarcollections.value.slice();
  1335. loadedTodoCals = globalSettings.loadedtodocollections.value.slice();
  1336. }
  1337. var settings = $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('settings').text();
  1338. if(typeof globalPreviousSupportedSettings !='undefined' && globalPreviousSupportedSettings!=null)
  1339. loadSettings(settings, true, true);
  1340. if(isAvaible('CardDavMATE'))
  1341. globalSettings.loadedaddressbookcollections.value = loadedAddrs.slice();
  1342. if(isAvaible('CalDavZAP'))
  1343. {
  1344. globalSettings.loadedcalendarcollections.value = loadedCals.slice();
  1345. globalSettings.loadedtodocollections.value = loadedTodoCals.slice();
  1346. }
  1347. checkBeforeClose(false);
  1348. }
  1349. $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').each(function(index, element){
  1350. $(element).children().filterNsNode('propstat').each(function(pindex, pelement){
  1351. var resources=$(pelement).children().filterNsNode('prop');
  1352. var color='';
  1353. var typeList=new Array();
  1354. resources.children().filterNsNode('supported-calendar-component-set').children().filterNsNode('comp').each(function(pindex, pelement){
  1355. typeList[typeList.length]=pelement.getAttribute('name').toLowerCase();
  1356. });
  1357. if(typeof inputResource!='undefined' && typeof inputResource.collectionTypes!='undefined' && inputResource.collectionTypes!=null && inputResource.collectionTypes.indexOf('calendar')!=-1 ||
  1358. typeof inputResource=='undefined' || inputResource.collectionTypes==null)
  1359. if((isAvaible('CalDavZAP') && resources.children().filterNsNode('resourcetype').children().filterNsNode('calendar').length==1 && resources.children().filterNsNode('resourcetype').children().filterNsNode('collection').length==1) && (inputResource.ignoreBound==undefined || !(inputResource.ignoreBound==true && resources.children().filterNsNode('resourcetype').children().filterNsNode('webdav-binding').length==1)))
  1360. {
  1361. if(resources.children().filterNsNode('calendar-color').length==1)
  1362. {
  1363. color=resources.children().filterNsNode('calendar-color').text();
  1364. if(color.length==9)
  1365. color=color.substring(0, 7);
  1366. }
  1367. var permissions=new Array();
  1368. resources.children().filterNsNode('current-user-privilege-set').children().filterNsNode('privilege').each(
  1369. function(index, element)
  1370. {
  1371. $(element).children().each(
  1372. function(index, element)
  1373. {
  1374. permissions[permissions.length]=$(element).prop('tagName').replace(/^[^:]+:/,'');
  1375. }
  1376. );
  1377. }
  1378. );
  1379. var read_only=false;
  1380. var href=$(element).children().filterNsNode('href').text();
  1381. if(href.match(RegExp('^https?://','i'))!=null)
  1382. {
  1383. var tmpH = algoo_replace_regex(href, globalAccountSettings);
  1384. if(tmpH!=null)
  1385. href = tmpH[3];
  1386. }
  1387. if(permissions.length>0 && permissions.indexOf('all')==-1 && permissions.indexOf('write')==-1 && permissions.indexOf('write-content')==-1)
  1388. read_only=true;
  1389. else if(inputResource.forceReadOnly!=undefined && (inputResource.forceReadOnly==true || inputResource.forceReadOnly instanceof Array))
  1390. {
  1391. if(inputResource.forceReadOnly instanceof Array)
  1392. {
  1393. for(var j=0; j<inputResource.forceReadOnly.length; j++)
  1394. if(typeof inputResource.forceReadOnly[j]=='string')
  1395. {
  1396. var index=href.indexOf(inputResource.forceReadOnly[j]);
  1397. if(index!=-1)
  1398. if(href.length==(index+inputResource.forceReadOnly[j].length))
  1399. read_only=true;
  1400. }
  1401. else if(typeof inputResource.forceReadOnly[j]=='object')
  1402. {
  1403. if(href.match(inputResource.forceReadOnly[j]) != null)
  1404. read_only=true;
  1405. }
  1406. }
  1407. else
  1408. read_only=true;
  1409. }
  1410. var displayvalue=resources.children().filterNsNode('displayname').text();
  1411. var headervalue=resources.children().filterNsNode('headervalue').text();
  1412. var synctoken=resources.children().filterNsNode('sync-token').text();
  1413. var oldSyncToken='';
  1414. var tmp_dv=href.match(RegExp('.*/([^/]+)/$', 'i'));
  1415. if(displayvalue=='') // MacOSX Lion Server
  1416. displayvalue=tmp_dv[1];
  1417. if(color=='')
  1418. {
  1419. var par=(uidBase+href).split('/');
  1420. var hash=hex_sha256(hex_sha256(par[par.length-3]+'/'+par[par.length-2]+'/'));
  1421. var hex=hash.substring(0,6);
  1422. while(checkColorBrightness(hex)>=252)
  1423. hex=hex_sha256(hex_sha256(hash)).substring(0,6);
  1424. color='#'+hex;
  1425. }
  1426. var ignoreAlarms=false;
  1427. var uidPArts=(uidBase+href).split('/');
  1428. if(typeof inputResource.ignoreAlarms=='boolean' && inputResource.ignoreAlarms)
  1429. ignoreAlarms = true;
  1430. else if(inputResource.ignoreAlarms instanceof Array && inputResource.ignoreAlarms.length>0)
  1431. {
  1432. for(var j=0; j<inputResource.ignoreAlarms.length; j++)
  1433. {
  1434. if(typeof inputResource.ignoreAlarms[j]=='string')
  1435. {
  1436. var index=href.indexOf(inputResource.ignoreAlarms[j]);
  1437. if(index!=-1)
  1438. if(href.length==(index+inputResource.ignoreAlarms[j].length))
  1439. ignoreAlarms=true;
  1440. }
  1441. else if (typeof inputResource.ignoreAlarms[j]=='object' && href.match(inputResource.ignoreAlarms[j])!=null)
  1442. ignoreAlarms = true;
  1443. }
  1444. }
  1445. // insert the resource
  1446. var webdav_bind=false;
  1447. if(resources.children().filterNsNode('resourcetype').children().filterNsNode('webdav-binding').length==1)
  1448. webdav_bind=true;
  1449. var checkContentType=(inputResource.checkContentType==undefined ? true : inputResource.checkContentType);
  1450. var syncRequired=true;
  1451. if(typeList.indexOf('vevent')!=-1)
  1452. {
  1453. var someChanged=false;
  1454. var existingResource=globalResourceCalDAVList.getEventCollectionByUID(uidBase+href);
  1455. if(existingResource!=null)
  1456. {
  1457. if(existingResource.syncToken!=synctoken)
  1458. someChanged=true;
  1459. }
  1460. else
  1461. {
  1462. someChanged=true;
  1463. if(synctoken=='')
  1464. synctoken=null;
  1465. }
  1466. var uidParts=(uidBase+href).match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)'));
  1467. var checkHref=uidParts[1]+uidParts[3];
  1468. if(!isHrefSet)
  1469. {
  1470. saveHref=uidBase+href;
  1471. isHrefSet=true;
  1472. }
  1473. if(!globalDefaultCalendarCollectionLoadAll)
  1474. {
  1475. var toBeLoad=false;
  1476. if(typeof globalCrossServerSettingsURL!='undefined' && globalCrossServerSettingsURL!=null && globalCrossServerSettingsURL)
  1477. {
  1478. var uidParts=(uidBase+href).match(RegExp('/([^/]+/[^/]+/)$'));
  1479. var tmpParts=uidParts[1].match('^(.*/)([^/]+)/$');
  1480. var checkHref3=decodeURIComponent(tmpParts[1])+tmpParts[2]+'/';
  1481. var found=false;
  1482. for(var l=0; l<globalSettings.loadedcalendarcollections.value.length; l++)
  1483. {
  1484. var tmpParts2=globalSettings.loadedcalendarcollections.value[l].match('^(.*/)([^/]+)/([^/]+)/$');
  1485. var checkHref2=decodeURIComponent(tmpParts2[2])+'/'+tmpParts2[3]+'/';
  1486. if(checkHref3==checkHref2)
  1487. {
  1488. found=true;
  1489. globalSettings.loadedcalendarcollections.value[l]=checkHref;
  1490. break;
  1491. }
  1492. }
  1493. toBeLoad=found;
  1494. }
  1495. else
  1496. toBeLoad=globalSettings.loadedcalendarcollections.value.indexOf(checkHref)!=-1;
  1497. }
  1498. else
  1499. {
  1500. var toBeLoad=true;
  1501. if(globalCalDAVInitLoad)
  1502. globalSettings.loadedcalendarcollections.value.push(checkHref);
  1503. }
  1504. if(!toBeLoad)
  1505. oldSyncToken='';
  1506. globalResourceCalDAVList.insertResource({makeLoaded:toBeLoad, typeList:typeList, listType:'vevent', ecolor: color, timestamp: resultTimestamp, uid: uidBase+href, timeOut: inputResource.timeOut, displayvalue: displayvalue, headervalue:headervalue, userAuth: inputResource.userAuth, resourceIndex: indexR, url: baseHref, accountUID: origUID, href: href, hrefLabel: inputResource.hrefLabel, permissions: {full: permissions, read_only: read_only}, crossDomain: inputResource.crossDomain, withCredentials: inputResource.withCredentials, interval: null, waitInterval: null, displayEventsArray: new Array(), pastUnloaded: '', fcSource: null, subscription: false, newlyAdded:toBeLoad, urlArray:null, ignoreAlarms:ignoreAlarms,webdav_bind:webdav_bind, syncRequired:syncRequired, checkContentType: checkContentType, syncToken: synctoken, oldSyncToken: oldSyncToken, someChanged:someChanged}, indexR, true);
  1507. if(globalAccountSettings[indexR]!=undefined)
  1508. globalAccountSettings[indexR].calendarNo++;
  1509. syncRequired=false;
  1510. }
  1511. if(typeList.indexOf('vtodo')!=-1)
  1512. {
  1513. var someChanged=false;
  1514. var existingResource=globalResourceCalDAVList.getTodoCollectionByUID(uidBase+href);
  1515. if(syncRequired && existingResource!=null)
  1516. {
  1517. if(existingResource.syncToken!=synctoken)
  1518. someChanged=true;
  1519. }
  1520. else
  1521. {
  1522. someChanged=true;
  1523. if(synctoken=='')
  1524. synctoken=null;
  1525. }
  1526. var uidParts=(uidBase+href).match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)'));
  1527. var checkHref=uidParts[1]+uidParts[3];
  1528. if(!isHrefSet)
  1529. {
  1530. saveHref=uidBase+href;
  1531. isHrefSet=true;
  1532. }
  1533. if(!globalDefaultTodoCalendarCollectionLoadAll)
  1534. {
  1535. var toBeLoad=false;
  1536. if(typeof globalCrossServerSettingsURL!='undefined' && globalCrossServerSettingsURL!=null && globalCrossServerSettingsURL)
  1537. {
  1538. var uidParts=(uidBase+href).match(RegExp('/([^/]+/[^/]+/)$'));
  1539. var tmpParts=uidParts[1].match('^(.*/)([^/]+)/$');
  1540. var checkHref3=decodeURIComponent(tmpParts[1])+tmpParts[2]+'/';
  1541. var found=false;
  1542. for(var l=0; l<globalSettings.loadedtodocollections.value.length; l++)
  1543. {
  1544. var tmpParts2=globalSettings.loadedtodocollections.value[l].match('^(.*/)([^/]+)/([^/]+)/$');
  1545. var checkHref2=decodeURIComponent(tmpParts2[2])+'/'+tmpParts2[3]+'/';
  1546. if(checkHref3==checkHref2)
  1547. {
  1548. found=true;
  1549. globalSettings.loadedtodocollections.value[l]=checkHref;
  1550. break;
  1551. }
  1552. }
  1553. toBeLoad=found;
  1554. }
  1555. else
  1556. toBeLoad=globalSettings.loadedtodocollections.value.indexOf(checkHref)!=-1;
  1557. }
  1558. else
  1559. {
  1560. var toBeLoad=true;
  1561. if(globalCalDAVInitLoad)
  1562. globalSettings.loadedtodocollections.value.push(checkHref);
  1563. }
  1564. if(!toBeLoad)
  1565. oldSyncToken='';
  1566. globalResourceCalDAVList.insertResource({makeLoaded:toBeLoad, typeList:typeList, hrefArray: new Array(), listType:'vtodo', ecolor: color, timestamp: resultTimestamp, uid: uidBase+href, timeOut: inputResource.timeOut, displayvalue: displayvalue, headervalue: headervalue, userAuth: inputResource.userAuth, resourceIndex: indexR, url: baseHref, accountUID: origUID, href: href, hrefLabel: inputResource.hrefLabel, permissions: {full: permissions, read_only: read_only}, crossDomain: inputResource.crossDomain, withCredentials: inputResource.withCredentials, interval: null, waitInterval: null, displayEventsArray: new Array(), pastUnloaded: '', fcSource: null, subscription: false, newlyAdded:toBeLoad, urlArray:null, ignoreAlarms:ignoreAlarms,webdav_bind:webdav_bind,syncRequired:syncRequired, checkContentType: checkContentType, syncToken: synctoken, oldSyncToken: oldSyncToken, someChanged:someChanged}, indexR, false);
  1567. if(globalAccountSettings[indexR]!=undefined)
  1568. globalAccountSettings[indexR].todoNo++;
  1569. }
  1570. }
  1571. if(typeof inputResource!='undefined' && typeof inputResource.collectionTypes!='undefined' && inputResource.collectionTypes!=null && inputResource.collectionTypes.indexOf('addressbook')!=-1 || typeof inputResource=='undefined' || inputResource.collectionTypes==null)
  1572. if((isAvaible('CardDavMATE') && resources.children().filterNsNode('resourcetype').children().filterNsNode('addressbook').length==1 && resources.children().filterNsNode('resourcetype').children().filterNsNode('collection').length==1) && (inputResource.ignoreBound==undefined || !(inputResource.ignoreBound==true && resources.children().filterNsNode('resourcetype').children().filterNsNode('webdav-binding').length==1)))
  1573. {
  1574. if(resources.children().filterNsNode('addressbook-color').length==1)
  1575. {
  1576. color=resources.children().filterNsNode('addressbook-color').text();
  1577. if(color.length==9)
  1578. color=color.substring(0, 7);
  1579. }
  1580. var permissions=new Array();
  1581. resources.children().filterNsNode('current-user-privilege-set').children().filterNsNode('privilege').each(
  1582. function(index, element)
  1583. {
  1584. $(element).children().each(
  1585. function(index, element)
  1586. {
  1587. permissions[permissions.length]=$(element).prop('tagName').replace(/^[^:]+:/,'');
  1588. }
  1589. );
  1590. }
  1591. );
  1592. var disableLocking=false;
  1593. var tmp_lock_support=resources.children().filterNsNode('supportedlock').children().filterNsNode('lockentry').children().filterNsNode('lockscope').children().filterNsNode('exclusive');
  1594. if(typeof tmp_lock_support=='undefined' || tmp_lock_support.length==undefined || tmp_lock_support.length==0)
  1595. disableLocking=true;
  1596. var href=$(element).children().filterNsNode('href').text();
  1597. if(href.match(RegExp('^https?://','i'))!=null)
  1598. {
  1599. var tmpH = algoo_replace_regex(href, globalAccountSettings);
  1600. if(tmpH!=null)
  1601. href = tmpH[3];
  1602. }
  1603. var tmp_cn=href.match(RegExp('/([^/]+)/?$')); // collection name
  1604. var read_only=false;
  1605. if(((typeof globalDisablePermissionChecking=='undefined' || globalDisablePermissionChecking!=true) && (permissions.length>0 && permissions.indexOf('all')==-1 && permissions.indexOf('write')==-1 && permissions.indexOf('write-content')==-1)) || (inputResource.forceReadOnly!=undefined && (inputResource.forceReadOnly==true || inputResource.forceReadOnly instanceof Array && inputResource.forceReadOnly.indexOf(tmp_cn[1])!=-1)))
  1606. read_only=true;
  1607. var displayvalue=resources.children().filterNsNode('displayname').text();
  1608. var headervalue=resources.children().filterNsNode('headervalue').text();
  1609. var synctoken=resources.children().filterNsNode('sync-token').text();
  1610. var oldSyncToken='';
  1611. var tmp_dv=href.match(RegExp('.*/([^/]+)/$','i'));
  1612. if(displayvalue=='') // OS X Server
  1613. displayvalue=tmp_dv[1];
  1614. if(color=='')
  1615. {
  1616. var par=(uidBase+href).split('/');
  1617. var hash=hex_sha256(hex_sha256(par[par.length-3]+'/'+par[par.length-2]+'/'));
  1618. var hex=hash.substring(0,6);
  1619. while(checkColorBrightness(hex)>=252)
  1620. hex=hex_sha256(hex_sha256(hash)).substring(0,6);
  1621. color='#'+hex;
  1622. }
  1623. var checkContentType=(inputResource.checkContentType==undefined ? true : inputResource.checkContentType);
  1624. // insert the resource
  1625. var someChanged=false;
  1626. var existingResource=globalResourceCardDAVList.getCollectionByUID(uidBase+href);
  1627. if(existingResource!=null)
  1628. {
  1629. if(existingResource.syncToken!=synctoken)
  1630. someChanged=true;
  1631. if(typeof globalForceSyncURLArray!='undefined' && globalForceSyncURLArray.length>0 && globalForceSyncURLArray.indexOf(existingResource.uid)!=-1)
  1632. {
  1633. someChanged=true;
  1634. }
  1635. }
  1636. else
  1637. {
  1638. someChanged=true;
  1639. if(synctoken=='')
  1640. synctoken=null;
  1641. }
  1642. var uidParts=(uidBase+href).match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)'));
  1643. var checkHref=uidParts[1]+uidParts[3];
  1644. if(!isHrefSet)
  1645. {
  1646. saveHref=uidBase+href;
  1647. isHrefSet=true;
  1648. }
  1649. if(!globalDefaultAddrCollectionLoadAll)
  1650. {
  1651. var toBeLoad=false;
  1652. if(typeof globalCrossServerSettingsURL!='undefined' && globalCrossServerSettingsURL!=null && globalCrossServerSettingsURL)
  1653. {
  1654. var uidParts=(uidBase+href).match(RegExp('/([^/]+/[^/]+/)$'));
  1655. var tmpParts=uidParts[1].match('^(.*/)([^/]+)/$');
  1656. var checkHref3=decodeURIComponent(tmpParts[1])+tmpParts[2]+'/';
  1657. var found=false;
  1658. for(var l=0; l<globalSettings.loadedaddressbookcollections.value.length; l++)
  1659. {
  1660. var tmpParts2=globalSettings.loadedaddressbookcollections.value[l].match('^(.*/)([^/]+)/([^/]+)/$');
  1661. var checkHref2=decodeURIComponent(tmpParts2[2])+'/'+tmpParts2[3]+'/';
  1662. if(checkHref3==checkHref2)
  1663. {
  1664. found=true;
  1665. globalSettings.loadedaddressbookcollections.value[l]=checkHref;
  1666. break;
  1667. }
  1668. }
  1669. toBeLoad=found;
  1670. }
  1671. else
  1672. toBeLoad=globalSettings.loadedaddressbookcollections.value.indexOf(checkHref)!=-1;
  1673. }
  1674. else
  1675. {
  1676. var toBeLoad=true;
  1677. if(globalCardDAVInitLoad)
  1678. globalSettings.loadedaddressbookcollections.value.push(checkHref);
  1679. }
  1680. globalResourceCardDAVList.insertResource({makeLoaded:toBeLoad, timestamp: resultTimestamp, uid: uidBase+href, timeOut: inputResource.timeOut, displayvalue: displayvalue, headervalue: headervalue, userAuth: inputResource.userAuth, url: baseHref, accountUID: origUID, href: href, hrefLabel: inputResource.hrefLabel, color: color, permissions: {full: permissions, read_only: read_only}, crossDomain: inputResource.crossDomain, withCredentials: inputResource.withCredentials, checkContentType: checkContentType, isLoaded:false, newlyAdded:toBeLoad, indexResource:indexR, disableLocking: disableLocking, syncToken: synctoken, oldSyncToken:oldSyncToken, someChanged:someChanged}, inputResourceIndex);
  1681. inputResource.addressbookNo++;
  1682. }
  1683. });
  1684. });
  1685. if(saveHref!='')
  1686. {
  1687. var saveUserHref=saveHref.replace(new RegExp('[^/]+/$'),'');
  1688. if(typeof globalResourceCalDAVList!='undefined' && globalResourceCalDAVList!=null)
  1689. globalResourceCalDAVList.removeOldResources(saveUserHref, resultTimestamp);
  1690. if(typeof globalResourceCardDAVList!='undefined' && globalResourceCardDAVList!=null)
  1691. globalResourceCardDAVList.removeOldResources(saveUserHref, resultTimestamp);
  1692. }
  1693. //recursive call for resource loading
  1694. if(hrefMode)
  1695. netLoadResource(inputResource, inputResource.cahref, false, inputResourceIndex, forceLoad, indexR, loadArray)
  1696. else
  1697. {
  1698. indexR++;
  1699. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  1700. }
  1701. }
  1702. // first try to process the cached data (if cached results are available in the "auth module" response)
  1703. var tmpCache;
  1704. if(globalXMLCache!=null && (tmpCache=globalXMLCache.children('davprincipalcollections[request_url="'+jqueryEscapeSelector(inputHref)+'"]').remove()).length)
  1705. {
  1706. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  1707. console.log('DBG Cache OK: '+arguments.callee.name+' url: \''+inputHref+'\': saved one request!');
  1708. ajaxComplete('', 'success', {responseXML: tmpCache});
  1709. }
  1710. else
  1711. {
  1712. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  1713. console.log('DBG Cache ERROR: '+arguments.callee.name+' url: \''+inputHref+'\': spend one request!');
  1714. $.ajax({
  1715. type: 'PROPFIND',
  1716. url: inputHref,
  1717. cache: false,
  1718. crossDomain: (typeof inputResource.crossDomain=='undefined' ? true : inputResource.crossDomain),
  1719. xhrFields: {
  1720. withCredentials: (typeof inputResource.withCredentials=='undefined' ? false : inputResource.withCredentials)
  1721. },
  1722. timeout: inputResource.timeOut,
  1723. beforeSend: function(req){
  1724. if(globalSettings.usejqueryauth.value!=true && inputResource.userAuth.userName!='' && inputResource.userAuth.userPassword!='')
  1725. req.setRequestHeader('Authorization', basicAuth(inputResource.userAuth.userName, inputResource.userAuth.userPassword));
  1726. req.setRequestHeader('X-client', globalXClientHeader);
  1727. req.setRequestHeader('Depth', '1');
  1728. if(globalSettingsSaving!=''||(isAvaible('CardDavMATE') && (!globalCardDAVInitLoad && !globalCardDAVResourceSync)) || (isAvaible('CalDavZAP') && (!globalCalDAVInitLoad && !globalCalDAVResourceSync))||(isAvaible('Projects') && isProjectsLoaded))
  1729. /* XXX - System display:none changes */
  1730. if(globalSettingsSaving!='' || (isAvaible('Settings') && $('#SystemSettings').css('visibility')=='visible' && $('.resourceSettings_item_selected').attr('data-type')=='setting_group_password'))
  1731. {
  1732. indexR++;
  1733. if(((isAvaible('CardDavMATE')&&globalCardDAVInitLoad) || (isAvaible('CalDavZAP'&&globalCalDAVInitLoad))) && indexR==globalAccountSettings.length)
  1734. $('#MainLoader').fadeOut(1200);
  1735. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  1736. return false;
  1737. }
  1738. },
  1739. username: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userName : null),
  1740. password: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userPassword : null),
  1741. contentType: 'text/xml; charset=utf-8',
  1742. processData: true,
  1743. data: '<?xml version="1.0" encoding="utf-8"?><D:propfind xmlns:D="DAV:"><D:prop>'+settingsXML+'<D:current-user-privilege-set/><D:displayname/><D:supportedlock/><D:resourcetype/><D:supported-report-set/><D:sync-token/><A:calendar-color xmlns:A="'+(typeof globalCalendarColorPropertyXmlns!='undefined'&&globalCalendarColorPropertyXmlns!=null&&globalCalendarColorPropertyXmlns!='' ? globalCalendarColorPropertyXmlns : 'http://apple.com/ns/ical/')+'"/><I:headervalue xmlns:I="http://inf-it.com/ns/dav/"/><I:addressbook-color xmlns:I="'+(typeof globalAddrColorPropertyXmlns!='undefined'&&globalAddrColorPropertyXmlns!=null&&globalAddrColorPropertyXmlns!='' ? globalAddrColorPropertyXmlns : 'http://inf-it.com/ns/ab/')+'"/><L:supported-calendar-component-set xmlns:L="urn:ietf:params:xml:ns:caldav"/><R:max-image-size xmlns:R="urn:ietf:params:xml:ns:carddav"/></D:prop></D:propfind>',
  1744. dataType: 'xml',
  1745. error: function(objAJAXRequest, strError){
  1746. console.log("Error: [netLoadResource: 'PROPFIND "+uidFull+"']: code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  1747. inputResource.errorLoaded=true;
  1748. if(isAvaible('CalDavZAP'))
  1749. {
  1750. $('#intCaldav').find('.int_error').css('display','block');
  1751. $('#intCaldavTodo').find('.int_error').css('display','block');
  1752. }
  1753. if(isAvaible('CardDavMATE'))
  1754. $('#intCarddav').find('.int_error').css('display','block');
  1755. if(hrefMode)
  1756. netLoadResource(inputResource, inputResource.cahref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  1757. else
  1758. {
  1759. indexR++;
  1760. var allFail=true;
  1761. for(var i=0; i< globalAccountSettings.length; i++)
  1762. if(typeof globalAccountSettings[i].errorLoaded=='undefined' || globalAccountSettings[i].errorLoaded==null || globalAccountSettings[i].errorLoaded===false)
  1763. allFail=false;
  1764. if(((isAvaible('CardDavMATE')&&globalCardDAVInitLoad) || (isAvaible('CalDavZAP')&&globalCalDAVInitLoad)) && indexR==globalAccountSettings.length && allFail)
  1765. $('#MainLoader').fadeOut(1200);
  1766. if(isAvaible('CalDavZAP') && !globalCalDAVInitLoad)
  1767. handleCalDAVError(true, inputResource);
  1768. if(isAvaible('CardDavMATE') && !globalCardDAVInitLoad)
  1769. handleCardDAVError(true, inputResource);
  1770. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  1771. }
  1772. return false;
  1773. },
  1774. success: ajaxComplete
  1775. });
  1776. }
  1777. }// Save the client settings (stored as DAV property on server)
  1778. function netSaveSettings(inputResource, inputSettings, isFormSave, collectionLoad)
  1779. {
  1780. var tmp = algoo_replace_regex(inputResource.href, globalAccountSettings);
  1781. var baseHref=tmp[1]+tmp[2];
  1782. var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2];
  1783. var uidFull=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]+tmp[3]; //for the error handler
  1784. var saveHref = inputResource.href;
  1785. var serverSettingss = transformToServer(inputSettings);
  1786. if(globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null)
  1787. {
  1788. if(globalSettings.settingstype.value=='addressbook-home-set')
  1789. saveHref = inputResource.abhref;
  1790. else if(globalSettings.settingstype.value=='calendar-home-set')
  1791. saveHref = inputResource.cahref;
  1792. }
  1793. $.ajax({
  1794. type: 'PROPPATCH',
  1795. url: saveHref,
  1796. cache: false,
  1797. crossDomain: (typeof inputResource.crossDomain=='undefined' ? true: inputResource.crossDomain),
  1798. xhrFields: {
  1799. withCredentials: (typeof inputResource.withCredentials=='undefined' ? false: inputResource.withCredentials)
  1800. },
  1801. timeout: inputResource.timeOut,
  1802. beforeSend: function(req){
  1803. if(globalSettings.usejqueryauth.value!=true && inputResource.userAuth.userName!='' && inputResource.userAuth.userPassword!='')
  1804. req.setRequestHeader('Authorization', basicAuth(inputResource.userAuth.userName, inputResource.userAuth.userPassword));
  1805. req.setRequestHeader('X-client', globalXClientHeader);
  1806. req.setRequestHeader('Depth', '0');
  1807. },
  1808. username: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userName : null),
  1809. password: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userPassword : null),
  1810. contentType: 'text/xml',
  1811. processData: true,
  1812. data: '<?xml version="1.0" encoding="utf-8"?><D:propertyupdate xmlns:D="DAV:"><D:set><D:prop><I:settings xmlns:I="http://inf-it.com/ns/dav/">'+JSON.stringify(serverSettingss)+'</I:settings></D:prop></D:set></D:propertyupdate>',
  1813. dataType: 'xml',
  1814. error: function(objAJAXRequest, strError){
  1815. console.log("Error: [netSaveSettings: 'PROPPATCH "+uidFull+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' (this error code usually means network connection error, or your browser is trying to make a cross domain query, but it is not allowed by the destination server or the browser itself)': ''));
  1816. if(isAvaible('Settings'))
  1817. show_editor_loader_messageSettings('message_error', localization[globalInterfaceLanguage].errSettingsSaved);
  1818. var loader=null;
  1819. if(typeof globalSettingsSaving!='undefined')
  1820. {
  1821. if(globalSettingsSaving=='event')
  1822. loader=$('#CalendarLoader');
  1823. else if(globalSettingsSaving=='todo')
  1824. loader=$('#CalendarLoaderTODO');
  1825. else if(globalSettingsSaving=='addressbook')
  1826. loader=$('#AddressbookOverlay');
  1827. }
  1828. if(loader!=null)
  1829. {
  1830. loader.addClass('message_error').children('.loaderInfo').text(localization[globalInterfaceLanguage].errCollectionLoad);
  1831. setTimeout(function(){
  1832. loader.addClass('loader_hidden').removeClass('message_error').children('.loaderInfo').text('');
  1833. }, globalHideInfoMessageAfter);
  1834. }
  1835. globalSettingsSaving='';
  1836. return false;
  1837. },
  1838. success: function(data, textStatus, xml)
  1839. {
  1840. if(isAvaible('Settings')&&isFormSave)
  1841. {
  1842. /* if((isAvaible('CardDavMATE')&&globalCardDAVResourceSync) || (isAvaible('CalDavZAP')&&globalCalDAVResourceSync))
  1843. {
  1844. var myInt = setInterval(function(){
  1845. if((isAvaible('CardDavMATE')&&!globalCardDAVResourceSync) && (isAvaible('CalDavZAP')&&!globalCalDAVResourceSync))
  1846. {
  1847. clearInterval(myInt);
  1848. applySettings(getChangedSettings(globalSettings, inputSettings));
  1849. globalSettings = inputSettings;
  1850. }
  1851. },100);
  1852. }
  1853. else
  1854. {*/
  1855. applySettings(getChangedSettings(globalSettings, inputSettings));
  1856. globalSettings = inputSettings;
  1857. // }
  1858. }
  1859. else if(collectionLoad)
  1860. {
  1861. /* if((isAvaible('CardDavMATE')&&globalCardDAVResourceSync) || (isAvaible('CalDavZAP')&&globalCalDAVResourceSync))
  1862. {
  1863. var myInt = setInterval(function(){
  1864. if((isAvaible('CardDavMATE')&&!globalCardDAVResourceSync) && (isAvaible('CalDavZAP')&&!globalCalDAVResourceSync))
  1865. {
  1866. clearInterval(myInt);
  1867. checkForLoadedCollections(inputSettings);
  1868. globalSettings = inputSettings;
  1869. }
  1870. },100);
  1871. }
  1872. else
  1873. {*/
  1874. checkForLoadedCollections(inputSettings);
  1875. globalSettings = inputSettings;
  1876. // }
  1877. }
  1878. }
  1879. });
  1880. }
  1881. function deleteVcalendarFromCollection(inputUID,inputForm, putMode)
  1882. {
  1883. var tmp=inputUID.match(vCalendar.pre['uidParts']);
  1884. var collection_uid=tmp[1]+tmp[2]+'@'+tmp[3]+tmp[4]+tmp[5];
  1885. var put_href=tmp[1]+tmp[3]+tmp[4]+tmp[5]+tmp[6];
  1886. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  1887. var resourceCalDAV_user=tmp[2];
  1888. var resourceSettings=null;
  1889. var rid=inputUID.substring(0, inputUID.lastIndexOf('/')+1);
  1890. if(inputForm=='vevent')
  1891. var resources=globalResourceCalDAVList.collections;
  1892. else
  1893. var resources=globalResourceCalDAVList.TodoCollections;
  1894. var rex=vCalendar.pre['accountUidParts'];
  1895. for(var j=0;j<resources.length;j++)
  1896. {
  1897. if(rid==resources[j].uid)
  1898. {
  1899. var tmp=resources[j].accountUID.match(rex);
  1900. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  1901. var resourceCalDAV_user=tmp[2];
  1902. // find the original settings for the resource and user
  1903. for(var i=0;i<globalAccountSettings.length;i++)
  1904. if(globalAccountSettings[i].href==resourceCalDAV_href && globalAccountSettings[i].userAuth.userName==resourceCalDAV_user)
  1905. resourceSettings=globalAccountSettings[i];
  1906. break;
  1907. }
  1908. }
  1909. if(resourceSettings==null)
  1910. return false;
  1911. // the begin of each error message
  1912. if(inputForm=='vevent')
  1913. var errBegin=localization[globalInterfaceLanguage].errUnableDeleteBeginCalDAV;
  1914. else
  1915. var errBegin=localization[globalInterfaceLanguage].errUnableDeleteTodoBeginCalDAV;
  1916. var vcalendarList=new Array();
  1917. $.ajax({
  1918. type: 'DELETE',
  1919. url: put_href,
  1920. cache: false,
  1921. crossDomain: true,
  1922. xhrFields: {
  1923. withCredentials: (typeof resourceSettings.withCredentials=='undefined' ? false: resourceSettings.withCredentials)
  1924. },
  1925. timeout: resourceSettings.timeOut,
  1926. beforeSend: function(req)
  1927. {
  1928. if(globalSettings.usejqueryauth.value!=true && resourceSettings.userAuth.userName!='' && resourceSettings.userAuth.userPassword!='')
  1929. req.setRequestHeader('Authorization', basicAuth(resourceSettings.userAuth.userName, resourceSettings.userAuth.userPassword));
  1930. req.setRequestHeader('X-client', globalXClientHeader);
  1931. },
  1932. username: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userName : null),
  1933. password: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userPassword : null),
  1934. contentType: 'text/calendar',
  1935. processData: true,
  1936. data: '',
  1937. dataType: 'text',
  1938. error: function(objAJAXRequest, strError){
  1939. console.log("Error: [deleteVcalendarFromCollection: 'DELETE "+put_href+"']: code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  1940. switch (objAJAXRequest.status)
  1941. {
  1942. case 401:
  1943. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp401));
  1944. break;
  1945. case 403:
  1946. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp403));
  1947. break;
  1948. case 405:
  1949. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp405));
  1950. break;
  1951. case 408:
  1952. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp408));
  1953. break;
  1954. case 410:
  1955. if(inputForm=='vevent')
  1956. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].CalDAVerrHttp410));
  1957. else
  1958. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].CalDAVerrTodoHttp410));
  1959. break;
  1960. case 500:
  1961. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp500));
  1962. break;
  1963. default:
  1964. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttpCommon.replace('%%', objAJAXRequest.status)));
  1965. break;
  1966. }
  1967. return false;
  1968. },
  1969. success: function(data, textStatus, xml){
  1970. if(inputForm=='vevent')
  1971. globalEventList.removeOldEvent(inputUID, true, true);
  1972. else if(putMode)
  1973. globalEventList.removeOldEvent(inputUID, true, false);
  1974. if(putMode)
  1975. return true;
  1976. if(inputForm=='vevent')
  1977. {
  1978. show_editor_loader_messageCalendar('vevent', 'message_success', localization[globalInterfaceLanguage].txtAllDeleted, function(a)
  1979. {
  1980. //setTimeout(function()
  1981. //{
  1982. $('#show').val('');
  1983. $('#CAEvent').hide();
  1984. $('#event_details_template').remove();
  1985. $('#CAEvent').append(cleanVcalendarTemplate);
  1986. $('#EventDisabler').fadeOut(globalEditorFadeAnimation, function(){
  1987. $('#timezonePicker').prop('disabled', false);
  1988. });
  1989. //}, a);
  1990. });
  1991. }
  1992. else
  1993. {
  1994. show_editor_loader_messageCalendar('vtodo', 'message_success', localization[globalInterfaceLanguage].txtAllDeletedTodo, function(a)
  1995. {
  1996. //setTimeout(function()
  1997. //{
  1998. $('#showTODO').val('');
  1999. $('#TodoDisabler').fadeOut(globalEditorFadeAnimation, function(){
  2000. $('#timezonePickerTODO').prop('disabled', false);
  2001. });
  2002. globalEventList.removeOldEvent(inputUID, true, false);
  2003. //}, a);
  2004. });
  2005. }
  2006. }
  2007. });
  2008. }
  2009. function moveVcalendarToCollection(accountUID, inputUID, inputEtag, inputVcalendar, delUID,inputForm,isFormHidden,deleteMode,textArray)
  2010. {
  2011. var resultTimestamp=new Date().getTime();
  2012. if(inputForm=='vtodo')
  2013. globalTodoLoaderHide = localization[globalInterfaceLanguage].txtAllSavedTodo;
  2014. var hex=hex_sha256(inputVcalendar+(new Date().getTime()));
  2015. var tmp=delUID.match(vCalendar.pre['uidParts']);
  2016. var tmpDest=inputUID.match(vCalendar.pre['uidParts']);
  2017. var collection_uid=tmpDest[1]+tmpDest[2]+'@'+tmpDest[3]+tmpDest[4]+tmpDest[5];
  2018. //console.log(collection_uid)
  2019. // if inputEtag is empty, we have a newly created vevent/vtodo and need to create a .ics file name for it
  2020. var put_href=tmp[1]+tmp[3]+tmp[4]+tmp[5]+tmp[6];
  2021. var dest_href=tmpDest[1]+tmpDest[3]+tmpDest[4]+tmpDest[5]+tmpDest[6];
  2022. var put_href_part=tmp[4]+tmp[5]+tmp[6];
  2023. var dest_href_part=tmpDest[4]+tmpDest[5]+tmpDest[6];
  2024. var resourceSettings=null;
  2025. // find the original settings for the resource and user
  2026. var tmp=accountUID.match(vCalendar.pre['accountUidParts']);
  2027. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  2028. var resourceCalDAV_user=tmp[2];
  2029. for(var i=0;i<globalAccountSettings.length;i++)
  2030. if(globalAccountSettings[i].href==resourceCalDAV_href && globalAccountSettings[i].userAuth.userName==resourceCalDAV_user)
  2031. resourceSettings=globalAccountSettings[i];
  2032. if(resourceSettings==null)
  2033. return false;
  2034. // the begin of each error message
  2035. if(inputForm=='vevent')
  2036. var errBegin=localization[globalInterfaceLanguage].errUnableSaveBeginCalDAV;
  2037. else
  2038. var errBegin=localization[globalInterfaceLanguage].errUnableSaveTodoBeginCalDAV;
  2039. var collection=globalResourceCalDAVList.getEventCollectionByUID(collection_uid);
  2040. if(collection==null)
  2041. collection=globalResourceCalDAVList.getTodoCollectionByUID(collection_uid);
  2042. var vcalendarList=new Array();
  2043. $.ajax({
  2044. type: 'MOVE',
  2045. url: put_href,
  2046. cache: false,
  2047. crossDomain: (typeof resourceSettings.crossDomain=='undefined' ? true: resourceSettings.crossDomain),
  2048. xhrFields: {
  2049. withCredentials: (typeof resourceSettings.withCredentials=='undefined' ? false: resourceSettings.withCredentials)
  2050. },
  2051. timeout: resourceSettings.timeOut,
  2052. beforeSend: function(req)
  2053. {
  2054. if(globalSettings.usejqueryauth.value!=true && resourceSettings.userAuth.userName!='' && resourceSettings.userAuth.userPassword!='')
  2055. req.setRequestHeader('Authorization', basicAuth(resourceSettings.userAuth.userName, resourceSettings.userAuth.userPassword));
  2056. req.setRequestHeader('X-client', globalXClientHeader);
  2057. req.setRequestHeader('Destination', dest_href);
  2058. },
  2059. username: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userName : null),
  2060. password: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userPassword : null),
  2061. contentType: 'text/calendar',
  2062. processData: true,
  2063. data: inputVcalendar,
  2064. dataType: 'text',
  2065. error: function(objAJAXRequest, strError)
  2066. {
  2067. console.log("Error: [moveVcalendarToCollection: 'MOVE from: "+put_href+" to: "+dest_href+"']: code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  2068. switch (objAJAXRequest.status)
  2069. {
  2070. case 401:
  2071. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp401));
  2072. break;
  2073. case 403:
  2074. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp403));
  2075. break;
  2076. case 405:
  2077. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp405));
  2078. break;
  2079. case 408:
  2080. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp408));
  2081. break;
  2082. case 412:
  2083. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp412));
  2084. netLoadCalendar(globalResourceCalDAVList.getCollectionByUID(collection_uid), [{etag: '', href: put_href_part}], (collection.forceSyncPROPFIND==undefined || collection.forceSyncPROPFIND==false ? true : false), false, true, true,true, null, null);
  2085. break;
  2086. case 500:
  2087. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp500));
  2088. break;
  2089. default:
  2090. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttpCommon.replace('%%', objAJAXRequest.status)));
  2091. break;
  2092. }
  2093. if(inputForm=='vtodo')
  2094. globalTodoLoaderHide='';
  2095. if(($('#InvitationBoxContent').is(':visible'))&&(inputForm=='vevent'||inputForm=='schedule-inbox'))
  2096. {
  2097. if(!$('#InvitationBoxHeader').find('.invitation_header_item_selected').length)
  2098. $('#InvitationBoxHeader').find('.invitation_header_item').first().trigger('click');
  2099. else
  2100. filterInvitations($('#InvitationBoxHeader').find('.invitation_header_item_selected').attr('data-type'));
  2101. }
  2102. return false;
  2103. },
  2104. success: function(data, textStatus, xml){
  2105. globalRevertFunction=null;
  2106. var isTODO=false;
  2107. globalWindowFocus=false;
  2108. if(inputForm=='vevent' || (inputForm=='schedule-inbox' && $('#CAEvent').is(':visible')))
  2109. {
  2110. var eventSuccessMessage=localization[globalInterfaceLanguage].txtAllSaved;
  2111. if(deleteMode)
  2112. eventSuccessMessage=localization[globalInterfaceLanguage].txtAllDeleted;
  2113. show_editor_loader_messageCalendar(inputForm, 'message_success', eventSuccessMessage, function(a){
  2114. //setTimeout(function(){
  2115. $('#show').val('');
  2116. if(isFormHidden!=true)
  2117. {
  2118. $('#CAEvent').hide();
  2119. $('#calendar').fullCalendar('unselect');
  2120. $('#event_details_template').remove();
  2121. $('#CAEvent').append(cleanVcalendarTemplate);
  2122. $('#EventDisabler').fadeOut(globalEditorFadeAnimation, function(){
  2123. $('#timezonePicker').prop('disabled', false);
  2124. });
  2125. }
  2126. //}, a);
  2127. });
  2128. globalEventList.removeOldEvent(delUID, true, true);
  2129. }
  2130. else if(inputForm=='vtodo')
  2131. globalEventList.removeOldEvent(delUID, true, false);
  2132. if(inputForm=='vevent')
  2133. netLoadCalendar(globalResourceCalDAVList.getEventCollectionByUID(collection_uid), [{etag: '', href: dest_href_part}], (collection.forceSyncPROPFIND==undefined || collection.forceSyncPROPFIND==false ? true : false), false, true,false, true, null, null);
  2134. else if(inputForm=='vtodo')
  2135. {
  2136. $('#showTODO').val(inputUID);
  2137. netLoadCalendar(globalResourceCalDAVList.getTodoCollectionByUID(collection_uid), [{etag: '', href: dest_href_part}], (collection.forceSyncPROPFIND==undefined || collection.forceSyncPROPFIND==false ? true : false), false, true,false, true, null, null);
  2138. }
  2139. globalWindowFocus=true;
  2140. }
  2141. });
  2142. }
  2143. function putVcalendarToCollection(accountUID, inputUID, inputEtag, inputVcalendar, delUID,inputForm,isFormHidden,deleteMode,textArray)
  2144. {
  2145. var resultTimestamp=new Date().getTime();
  2146. if(inputForm=='vtodo')
  2147. globalTodoLoaderHide = localization[globalInterfaceLanguage].txtAllSavedTodo;
  2148. // line folding (RFC2445 - section 4.1) - maximum of 75 octects (and cannot break
  2149. // multi-octet UTF8-characters) allowed on one line, excluding a line break (CRLF)
  2150. inputVcalendar=vObjectLineFolding(inputVcalendar);
  2151. var hex=hex_sha256(inputVcalendar+(new Date().getTime()));
  2152. var tmp=inputUID.match(vCalendar.pre['uidParts']);
  2153. var collection_uid=tmp[1]+tmp[2]+'@'+tmp[3]+tmp[4]+tmp[5];
  2154. // if inputEtag is empty, we have a newly created vevent/vtodo and need to create a .ics file name for it
  2155. if(inputEtag!='')
  2156. {
  2157. var put_href=tmp[1]+tmp[3]+tmp[4]+tmp[5]+tmp[6];
  2158. var put_href_part=tmp[4]+tmp[5]+tmp[6];
  2159. }
  2160. else
  2161. {
  2162. if(inputUID.charAt(inputUID.length-1)!='/')
  2163. {
  2164. var put_href=tmp[1]+tmp[3]+tmp[4]+tmp[5]+tmp[6];
  2165. var put_href_part=tmp[4]+tmp[5]+tmp[6];
  2166. }
  2167. else
  2168. {
  2169. var vcalendarFile=hex+'.ics';
  2170. var put_href=tmp[1]+tmp[3]+tmp[4]+tmp[5]+vcalendarFile;
  2171. var put_href_part=tmp[4]+tmp[5]+vcalendarFile;
  2172. inputUID+=vcalendarFile;
  2173. }
  2174. }
  2175. var resourceSettings=null;
  2176. // find the original settings for the resource and user
  2177. var tmp=accountUID.match(vCalendar.pre['accountUidParts']);
  2178. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  2179. var resourceCalDAV_user=tmp[2];
  2180. for(var i=0;i<globalAccountSettings.length;i++)
  2181. if(globalAccountSettings[i].href==resourceCalDAV_href && globalAccountSettings[i].userAuth.userName==resourceCalDAV_user)
  2182. resourceSettings=globalAccountSettings[i];
  2183. if(resourceSettings==null)
  2184. return false;
  2185. // the begin of each error message
  2186. if(inputForm=='vevent')
  2187. var errBegin=localization[globalInterfaceLanguage].errUnableSaveBeginCalDAV;
  2188. else
  2189. var errBegin=localization[globalInterfaceLanguage].errUnableSaveTodoBeginCalDAV;
  2190. var collection=globalResourceCalDAVList.getEventCollectionByUID(collection_uid);
  2191. if(collection==null)
  2192. collection=globalResourceCalDAVList.getTodoCollectionByUID(collection_uid);
  2193. var vcalendarList=new Array();
  2194. $.ajax({
  2195. type: 'PUT',
  2196. url: put_href,
  2197. cache: false,
  2198. crossDomain: (typeof resourceSettings.crossDomain=='undefined' ? true: resourceSettings.crossDomain),
  2199. xhrFields: {
  2200. withCredentials: (typeof resourceSettings.withCredentials=='undefined' ? false: resourceSettings.withCredentials)
  2201. },
  2202. timeout: resourceSettings.timeOut,
  2203. beforeSend: function(req)
  2204. {
  2205. req.setRequestHeader('Prefer', 'return=representation');
  2206. if(globalSettings.usejqueryauth.value!=true && resourceSettings.userAuth.userName!='' && resourceSettings.userAuth.userPassword!='')
  2207. req.setRequestHeader('Authorization', basicAuth(resourceSettings.userAuth.userName, resourceSettings.userAuth.userPassword));
  2208. req.setRequestHeader('X-client', globalXClientHeader);
  2209. if(inputEtag!='')
  2210. req.setRequestHeader('If-Match', inputEtag);
  2211. else // adding new object
  2212. req.setRequestHeader('If-None-Match', '*');
  2213. },
  2214. username: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userName : null),
  2215. password: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userPassword : null),
  2216. contentType: 'text/calendar',
  2217. processData: true,
  2218. data: inputVcalendar,
  2219. dataType: 'text',
  2220. error: function(objAJAXRequest, strError)
  2221. {
  2222. console.log("Error: [putVcalendarToCollection: 'PUT "+put_href+"']: code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  2223. switch (objAJAXRequest.status)
  2224. {
  2225. case 401:
  2226. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp401));
  2227. break;
  2228. case 403:
  2229. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp403));
  2230. break;
  2231. case 405:
  2232. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp405));
  2233. break;
  2234. case 408:
  2235. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp408));
  2236. break;
  2237. case 412:
  2238. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp412));
  2239. netLoadCalendar(globalResourceCalDAVList.getCollectionByUID(collection_uid), [{etag: '', href: put_href_part}], (collection.forceSyncPROPFIND==undefined || collection.forceSyncPROPFIND==false ? true : false), false, true, true,true, null, null);
  2240. break;
  2241. case 500:
  2242. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttp500));
  2243. break;
  2244. default:
  2245. show_editor_loader_messageCalendar(inputForm, 'message_error', errBegin.replace('%%', localization[globalInterfaceLanguage].errHttpCommon.replace('%%', objAJAXRequest.status)));
  2246. break;
  2247. }
  2248. if(inputForm=='vevent' && globalRevertFunction!=null)
  2249. {
  2250. globalRevertFunction();
  2251. globalRevertFunction=null
  2252. }
  2253. else if(inputForm=='vtodo')
  2254. {
  2255. globalTodoLoaderHide='';
  2256. if(isFormHidden)
  2257. $('#todoList').fullCalendar('allowSelectEvent',true);
  2258. }
  2259. return false;
  2260. },
  2261. success: function(data, textStatus, xml){
  2262. globalRevertFunction=null;
  2263. if(delUID!='')
  2264. deleteVcalendarFromCollection(delUID,inputForm, true);
  2265. if(textArray.length>0)
  2266. {
  2267. var tArr = textArray[0];
  2268. textArray.splice(0,1);
  2269. putVcalendarToCollection(accountUID, inputUID.substring(0, inputUID.lastIndexOf('/')+1), '', tArr, delUID,inputForm,isFormHidden,deleteMode,textArray)
  2270. }
  2271. var newEtag=xml.getResponseHeader('Etag');
  2272. var isTODO=false;
  2273. globalWindowFocus=false;
  2274. if(inputForm=='vevent')
  2275. {
  2276. var eventSuccessMessage=localization[globalInterfaceLanguage].txtAllSaved;
  2277. if(deleteMode)
  2278. eventSuccessMessage=localization[globalInterfaceLanguage].txtAllDeleted;
  2279. show_editor_loader_messageCalendar(inputForm, 'message_success', eventSuccessMessage, function(a){
  2280. //setTimeout(function(){
  2281. $('#show').val('');
  2282. if(isFormHidden!=true)
  2283. {
  2284. $('#CAEvent').hide();
  2285. $('#calendar').fullCalendar('unselect');
  2286. $('#event_details_template').remove();
  2287. $('#CAEvent').append(cleanVcalendarTemplate);
  2288. $('#EventDisabler').fadeOut(globalEditorFadeAnimation, function(){
  2289. $('#timezonePicker').prop('disabled', false);
  2290. });
  2291. }
  2292. //}, a);
  2293. });
  2294. }
  2295. else
  2296. {
  2297. if(newEtag!=null)
  2298. {
  2299. if(deleteMode)
  2300. globalTodoLoaderHide=localization[globalInterfaceLanguage].txtAllDeletedTodo;
  2301. show_editor_loader_messageCalendar(inputForm, 'message_success', globalTodoLoaderHide, function(a){
  2302. globalTodoLoaderHide='';
  2303. if(inputForm=='vtodo'&&isFormHidden!=true)
  2304. $('#showTODO').val('');
  2305. $('#TodoDisabler').fadeOut(globalEditorFadeAnimation, function(){
  2306. $('#timezonePickerTODO').prop('disabled', false);
  2307. });
  2308. });
  2309. }
  2310. }
  2311. if(newEtag!=null)
  2312. {
  2313. var rid=inputUID.substring(0, inputUID.lastIndexOf('/')+1);
  2314. if(inputForm=='vevent')
  2315. {
  2316. var resources=globalResourceCalDAVList.collections;
  2317. for(var j=0;j<resources.length;j++)
  2318. {
  2319. if(rid==resources[j].uid)
  2320. {
  2321. if(inputVcalendar!='')
  2322. {
  2323. var rawVcalendar=inputVcalendar;
  2324. if(xml.getResponseHeader('Preference-Applied')=='return=representation' && xml.responseText)
  2325. rawVcalendar=xml.responseText;
  2326. var vcalendar_clean=vCalendarCleanup(rawVcalendar);
  2327. }
  2328. else
  2329. return true;
  2330. globalEventList.insertEvent(true, resources[j], {isRepeat: false, isTODO: false, untilDate: '', sortStart: '', start: '', end: '', sortkey: '', timestamp: resultTimestamp, accountUID: resources[j].accountUID, uid: inputUID, displayValue: resources[j].displayvalue, etag: newEtag, vcalendar: vcalendar_clean}, true, true,false);
  2331. break;
  2332. }
  2333. }
  2334. }
  2335. else
  2336. {
  2337. var resources=globalResourceCalDAVList.TodoCollections;
  2338. for(var j=0;j<resources.length;j++)
  2339. {
  2340. if(rid==resources[j].uid)
  2341. {
  2342. if(inputVcalendar!='')
  2343. {
  2344. var rawVcalendar=inputVcalendar;
  2345. if(xml.getResponseHeader('Preference-Applied')=='return=representation' && xml.responseText)
  2346. rawVcalendar=xml.responseText;
  2347. var vcalendar_clean=vCalendarCleanup(rawVcalendar);
  2348. }
  2349. else
  2350. return true;
  2351. if(inputForm=='vtodo'&&isFormHidden!=true)
  2352. $('#showTODO').val(inputUID);
  2353. globalEventList.insertEvent(true, resources[j], {isRepeat: false, isTODO: false, untilDate: '', sortStart: '', start: '', end: '', sortkey: '', timestamp: resultTimestamp, accountUID: resources[j].accountUID, uid: inputUID, displayValue: resources[j].displayvalue, etag: newEtag, vcalendar: vcalendar_clean}, true, false,false);
  2354. if(isFormHidden)
  2355. $('#todoList').fullCalendar('allowSelectEvent',true);
  2356. if(inputEtag=='' || isFormHidden)
  2357. $('#todoList').fullCalendar('selectEvent',$('[data-id="'+inputUID+'"]'));
  2358. break;
  2359. }
  2360. }
  2361. }
  2362. }
  2363. else
  2364. {
  2365. if(inputForm=='vevent')
  2366. netLoadCalendar(globalResourceCalDAVList.getEventCollectionByUID(collection_uid), [{etag: '', href: put_href_part}], (collection.forceSyncPROPFIND==undefined || collection.forceSyncPROPFIND==false ? true : false), false, true,false, true, null, null);
  2367. else
  2368. {
  2369. if(isFormHidden)
  2370. $('#todoList').fullCalendar('allowSelectEvent',true);
  2371. if(inputForm=='vtodo'&&isFormHidden!=true)
  2372. $('#showTODO').val(inputUID);
  2373. netLoadCalendar(globalResourceCalDAVList.getTodoCollectionByUID(collection_uid), [{etag: '', href: put_href_part}], (collection.forceSyncPROPFIND==undefined || collection.forceSyncPROPFIND==false ? true : false), false, true,false, true, null, null);
  2374. }
  2375. }
  2376. globalWindowFocus=true;
  2377. return true;
  2378. }
  2379. });
  2380. }
  2381. /*
  2382. Permissions (from the davical wiki):
  2383. all - aggregate of all permissions
  2384. read - grants basic read access to the principal or collection.
  2385. unlock - grants access to write content (i.e. update data) to the collection, or collections of the principal.
  2386. read-acl - grants access to read ACLs on the collection, or collections of the principal.
  2387. read-current-user-privilege-set - grants access to read the current user's privileges on the collection, or collections of the write-acl-grants access to writing ACLs on the collection, or collections of the principal.
  2388. write - aggregate of write-properties, write-content, bind & unbind
  2389. write-properties - grants access to update properties of the principal or collection. In DAViCal, when granted to a user principal, this will only grant access to update properties of the principal's collections and not the user principal itself. When granted to a group or resource principal this will grant access to update the principal properties.
  2390. write - content-grants access to write content (i.e. update data) to the collection, or collections of the principal.
  2391. bind - grants access to creating resources in the collection, or in collections of the principal. Created resources may be new collections, although it is an error to create collections within calendar collections.
  2392. unbind - grants access to deleting resources (including collections) from the collection, or from collections of the principal.
  2393. */
  2394. function CalDAVnetLoadCollection(inputCollection, forceLoad, allSyncMode, recursiveIterator, collections)
  2395. {
  2396. if(recursiveIterator>=collections.length)
  2397. {
  2398. setLoadingLimit(forceLoad, allSyncMode);
  2399. if(!globalCalDAVInitLoad && isCalDAVLoaded && allSyncMode)
  2400. {
  2401. $('#SystemCalDavZAP .fc-header-center ').removeClass('r_operate_all');
  2402. loadNextApplication(false);
  2403. }
  2404. return false;
  2405. }
  2406. if(collections.length>0)
  2407. {
  2408. if(inputCollection.uid!=undefined && inputCollection.makeLoaded && inputCollection.newlyAdded && globalSettingsSaving!='')
  2409. {
  2410. updateMainLoaderText(inputCollection.listType);
  2411. }
  2412. if(inputCollection.uid==undefined || inputCollection.subscription || (!inputCollection.newlyAdded && !inputCollection.syncRequired && !forceLoad && allSyncMode) || (!inputCollection.newlyAdded && !inputCollection.someChanged && !globalCalDAVInitLoad &&allSyncMode) || ((inputCollection.listType=='vtodo'&&globalSettings.todopastlimit.value==null) || (inputCollection.listType=='vevent'&&globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null))&&!inputCollection.syncRequired)
  2413. {
  2414. if(inputCollection.subscription && inputCollection.syncRequired && inputCollection.uid!=undefined)
  2415. {
  2416. netLoadCalendarSubscription(globalAccountSettings[0], inputCollection, recursiveIterator, forceLoad, collections);
  2417. }
  2418. recursiveIterator++;
  2419. if(recursiveIterator>=collections.length && inputCollection.uid!='undefined' && inputCollection.listType=='vevent')
  2420. {
  2421. setLoadingLimit(forceLoad, allSyncMode);
  2422. recursiveIterator=0;
  2423. if((globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null) || allSyncMode)
  2424. CalDAVnetLoadCollection(globalResourceCalDAVList.TodoCollections[0], forceLoad, allSyncMode, 0, globalResourceCalDAVList.TodoCollections);
  2425. }
  2426. else
  2427. CalDAVnetLoadCollection(collections[recursiveIterator], forceLoad, allSyncMode, recursiveIterator, collections);
  2428. if(inputCollection.uid!=undefined)
  2429. {
  2430. if(!inputCollection.syncRequired && globalCalDAVInitLoad)
  2431. {
  2432. if(inputCollection.listType=='vtodo')
  2433. $('#ResourceCalDAVTODOList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2434. else
  2435. $('#ResourceCalDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2436. if(((inputCollection.listType=='vtodo'&&globalSettings.todopastlimit.value==null) || (inputCollection.listType=='vevent'&&globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null))||(globalLimitLoading=='' && globalLimitTodoLoading==''))
  2437. {
  2438. globalAccountSettings[inputCollection.resourceIndex].todoNo--;
  2439. if((globalAccountSettings[inputCollection.resourceIndex].calendarNo==0 && globalAccountSettings[inputCollection.resourceIndex].todoNo==0 && globalCalDAVInitLoad) || !globalCalDAVInitLoad)
  2440. updateMainLoader();
  2441. }
  2442. else if((globalOnlyCalendarNumber>0 && globalOnlyCalendarNumberCount==globalOnlyCalendarNumber) || (globalTodoCalendarNumber>0 && globalOnlyTodoCalendarNumberCount==globalTodoCalendarNumber))
  2443. updateMainLoader(true,inputCollection.listType);
  2444. }
  2445. else if(!globalCalDAVInitLoad && !inputCollection.someChanged)
  2446. {
  2447. if(inputCollection.listType=='vevent')
  2448. $('#ResourceCalDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2449. else
  2450. $('#ResourceCalDAVTODOList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2451. }
  2452. }
  2453. return false;
  2454. }
  2455. }
  2456. var resourceSettings=null;
  2457. // find the original settings for the resource and user
  2458. var tmp=inputCollection.accountUID.match(vCalendar.pre['accountUidParts']);
  2459. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  2460. var resourceCalDAV_user=tmp[2];
  2461. for(var i=0;i<globalAccountSettings.length;i++)
  2462. if(globalAccountSettings[i].href==resourceCalDAV_href && globalAccountSettings[i].userAuth.userName==resourceCalDAV_user)
  2463. resourceSettings=globalAccountSettings[i];
  2464. // POROVNAT S TYM AKO JE TO V CARDDAVMATE
  2465. if(inputCollection.makeLoaded && globalSettingsSaving=='')
  2466. updateMainLoaderText(inputCollection.listType);
  2467. if((globalSettings.eventstartpastlimit.value!=null || globalSettings.eventstartfuturelimit.value!=null )&&!allSyncMode && inputCollection.listType=='vevent')
  2468. $('#ResourceCalDAVList [data-id="'+inputCollection.uid+'"]').addClass('r_operate');
  2469. if(!inputCollection.makeLoaded)
  2470. {
  2471. if(inputCollection.listType == 'vevent')
  2472. $('#ResourceCalDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2473. else if(inputCollection.listType == 'vtodo')
  2474. $('#ResourceCalDAVTODOList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2475. recursiveIterator++;
  2476. if((globalLimitLoading=='' && globalLimitTodoLoading=='') || ((inputCollection.listType=='vtodo'&&globalSettings.todopastlimit.value==null) || (inputCollection.listType=='vevent'&&globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null)))
  2477. {
  2478. if(inputCollection.listType == 'vevent')
  2479. globalAccountSettings[inputCollection.resourceIndex].calendarNo--;
  2480. else if(inputCollection.listType == 'vtodo')
  2481. {
  2482. globalAccountSettings[inputCollection.resourceIndex].todoNo--;
  2483. }
  2484. if((globalAccountSettings[inputCollection.resourceIndex].calendarNo==0 && globalAccountSettings[inputCollection.resourceIndex].todoNo==0 && globalCalDAVInitLoad))
  2485. {
  2486. updateMainLoader();
  2487. }
  2488. }
  2489. else if((globalOnlyCalendarNumber>0 && globalOnlyCalendarNumberCount==globalOnlyCalendarNumber) || (globalTodoCalendarNumber>0 && globalOnlyTodoCalendarNumberCount==globalTodoCalendarNumber))
  2490. updateMainLoader(true,inputCollection.listType);
  2491. if(recursiveIterator>=collections.length && inputCollection.uid!='undefined' && inputCollection.listType=='vevent')
  2492. {
  2493. recursiveIterator=0;
  2494. setLoadingLimit(forceLoad, allSyncMode);
  2495. if((globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value == null ) || allSyncMode)
  2496. CalDAVnetLoadCollection(globalResourceCalDAVList.TodoCollections[0], forceLoad, allSyncMode, 0, globalResourceCalDAVList.TodoCollections);
  2497. }
  2498. else
  2499. CalDAVnetLoadCollection(collections[recursiveIterator], forceLoad, allSyncMode, recursiveIterator, collections);
  2500. return false;
  2501. }
  2502. if(inputCollection.forceSyncPROPFIND!=undefined && inputCollection.forceSyncPROPFIND==true)
  2503. var requestText='<?xml version="1.0" encoding="utf-8"?><D:propfind xmlns:D="DAV:"><D:prop><D:getcontenttype/><D:getetag/></D:prop></D:propfind>';
  2504. else if(((inputCollection.listType=='vtodo'&&globalSettings.todopastlimit.value==null) || (inputCollection.listType=='vevent'&&globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null))) // all sync turned off
  2505. {
  2506. var requestText='<?xml version="1.0" encoding="utf-8"?><D:sync-collection xmlns:D="DAV:"><D:prop><D:getcontenttype/><D:getetag/></D:prop><D:sync-level>1</D:sync-level>'+(forceLoad==true || inputCollection.syncToken==undefined || inputCollection.syncToken=='' ? '<D:sync-token/>' : '<D:sync-token>'+inputCollection.syncToken+'</D:sync-token>')+'</D:sync-collection>';
  2507. }
  2508. else // if inputCollection.forceSyncPROPFIND is undefined or false
  2509. {
  2510. var requestText = '';
  2511. if(!forceLoad && !inputCollection.newlyAdded)
  2512. requestText='<?xml version="1.0" encoding="utf-8"?><D:sync-collection xmlns:D="DAV:"><D:prop><D:getcontenttype/><D:getetag/></D:prop><D:sync-level>1</D:sync-level>'+(forceLoad==true || inputCollection.syncToken==undefined || inputCollection.syncToken=='' ? '<D:sync-token/>' : '<D:sync-token>'+inputCollection.syncToken+'</D:sync-token>')+'</D:sync-collection>';
  2513. else
  2514. {
  2515. if(inputCollection.listType=='vevent')
  2516. {
  2517. if(globalCalDAVInitLoad&&allSyncMode)
  2518. {
  2519. if(globalSettings.eventstartpastlimit.value!=null)
  2520. {
  2521. globalLoadedLimit = new Date();
  2522. globalLoadedLimit.setDate(1);
  2523. globalLoadedLimit.setHours(0);
  2524. globalLoadedLimit.setMinutes(0);
  2525. globalLoadedLimit.setSeconds(0);
  2526. globalLoadedLimit.setMilliseconds(0);
  2527. globalLoadedLimit.setMonth(globalLoadedLimit.getMonth()-globalSettings.eventstartpastlimit.value);
  2528. }
  2529. if(globalSettings.eventstartfuturelimit.value!=null)
  2530. {
  2531. globalToLoadedLimit = new Date();
  2532. globalToLoadedLimit.setDate(1);
  2533. globalToLoadedLimit.setHours(0);
  2534. globalToLoadedLimit.setMinutes(0);
  2535. globalToLoadedLimit.setSeconds(0);
  2536. globalToLoadedLimit.setMilliseconds(0);
  2537. globalToLoadedLimit.setMonth(globalToLoadedLimit.getMonth()+globalSettings.eventstartfuturelimit.value+1);
  2538. }
  2539. }
  2540. var pastInterval = '', futureInterval = '';
  2541. if(!inputCollection.newlyAdded || globalCalDAVInitLoad)
  2542. {
  2543. if(globalSettings.eventstartpastlimit.value!=null && (allSyncMode || globalLimitLoading=='past'))
  2544. {
  2545. var pastDate = new Date(globalLoadedLimit.getTime());
  2546. pastDate.setDate(pastDate.getDate()-7);
  2547. if(allSyncMode)
  2548. pastInterval = ' start="'+$.fullCalendar.formatDate(pastDate ,"yyyyMMdd'T'HHmmss")+'Z"';
  2549. else
  2550. pastInterval = ' start="'+$.fullCalendar.formatDate(pastDate ,"yyyyMMdd'T'HHmmss")+'Z" end="'+$.fullCalendar.formatDate(globalBeginPast,"yyyyMMdd'T'HHmmss")+'Z"';
  2551. if(recursiveIterator==(collections.length-1))
  2552. globalBeginPast = new Date(pastDate.getTime());
  2553. }
  2554. if(globalSettings.eventstartfuturelimit.value!=null && (allSyncMode || globalLimitLoading=='future'))
  2555. {
  2556. var futureDate = new Date(globalToLoadedLimit.getTime());
  2557. futureDate.setDate(futureDate.getDate()+14);
  2558. if(allSyncMode)
  2559. futureInterval = ' end="'+$.fullCalendar.formatDate(futureDate ,"yyyyMMdd'T'HHmmss")+'Z"';
  2560. else
  2561. futureInterval = ' start="'+$.fullCalendar.formatDate(globalBeginFuture ,"yyyyMMdd'T'HHmmss")+'Z" end="'+$.fullCalendar.formatDate(futureDate,"yyyyMMdd'T'HHmmss")+'Z"';
  2562. if(recursiveIterator==(collections.length-1))
  2563. globalBeginFuture = new Date(futureDate.getTime());
  2564. }
  2565. }
  2566. else
  2567. {
  2568. var pastDate = new Date(globalLoadedLimit.getTime());
  2569. var futureDate = new Date(globalToLoadedLimit.getTime());
  2570. pastInterval = ' start="'+$.fullCalendar.formatDate(pastDate ,"yyyyMMdd'T'HHmmss")+'Z"';
  2571. futureInterval = ' end="'+$.fullCalendar.formatDate(futureDate ,"yyyyMMdd'T'HHmmss")+'Z"';
  2572. }
  2573. if(!allSyncMode)
  2574. requestText='<?xml version="1.0" encoding="UTF-8"?><L:calendar-query xmlns:L="urn:ietf:params:xml:ns:caldav"><D:prop xmlns:D="DAV:"><D:getcontenttype/><D:getetag/><L:calendar-data/></D:prop><L:filter><L:comp-filter name="VCALENDAR"><L:comp-filter name="VEVENT"><L:time-range'+(globalLimitLoading=='past' ? pastInterval : futureInterval)+'/></L:comp-filter></L:comp-filter></L:filter></L:calendar-query>';
  2575. else
  2576. requestText='<?xml version="1.0" encoding="UTF-8"?><L:calendar-query xmlns:L="urn:ietf:params:xml:ns:caldav"><D:prop xmlns:D="DAV:"><D:getcontenttype/><D:getetag/><L:calendar-data/></D:prop><L:filter><L:comp-filter name="VCALENDAR"><L:comp-filter name="VEVENT"><L:time-range'+pastInterval+futureInterval+'/></L:comp-filter></L:comp-filter></L:filter></L:calendar-query>';
  2577. }
  2578. else if(inputCollection.listType=='vtodo')
  2579. {
  2580. if(allSyncMode)
  2581. {
  2582. if(globalSettings.todopastlimit.value!=null)
  2583. {
  2584. globalLoadedLimitTodo = new Date();
  2585. globalLoadedLimitTodo.setDate(1);
  2586. globalLoadedLimitTodo.setHours(0);
  2587. globalLoadedLimitTodo.setMinutes(0);
  2588. globalLoadedLimitTodo.setSeconds(0);
  2589. globalLoadedLimitTodo.setMilliseconds(0);
  2590. globalLoadedLimitTodo.setMonth(globalLoadedLimitTodo.getMonth()-globalSettings.todopastlimit.value);
  2591. }
  2592. if(globalSettings.eventstartfuturelimit.value!=null)
  2593. {
  2594. globalToLoadedLimitTodo = new Date();
  2595. globalToLoadedLimitTodo.setDate(1);
  2596. globalToLoadedLimitTodo.setHours(0);
  2597. globalToLoadedLimitTodo.setMinutes(0);
  2598. globalToLoadedLimitTodo.setSeconds(0);
  2599. globalToLoadedLimitTodo.setMilliseconds(0);
  2600. globalToLoadedLimitTodo.setMonth(globalToLoadedLimitTodo.getMonth()+globalSettings.eventstartfuturelimit.value+1);
  2601. }
  2602. }
  2603. var pastInterval = '', futureInterval = '';
  2604. if(!inputCollection.newlyAdded || globalCalDAVInitLoad)
  2605. {
  2606. if(globalSettings.todopastlimit.value!=null && (allSyncMode || globalLimitTodoLoading=='pastTodo'))
  2607. {
  2608. if(allSyncMode)
  2609. pastInterval = ' start="'+$.fullCalendar.formatDate(globalLoadedLimitTodo ,"yyyyMMdd'T'HHmmss")+'Z"';
  2610. else
  2611. pastInterval = ' start="'+$.fullCalendar.formatDate(globalLoadedLimitTodo ,"yyyyMMdd'T'HHmmss")+'Z" end="'+$.fullCalendar.formatDate(new Date(new Date(globalLoadedLimitTodo.getTime()).setMonth(globalLoadedLimitTodo.getMonth()+globalSettings.todopastlimit.value+1)),"yyyyMMdd'T'HHmmss")+'Z"';
  2612. }
  2613. }
  2614. else
  2615. pastInterval = ' start="'+$.fullCalendar.formatDate(globalLoadedLimitTodo ,"yyyyMMdd'T'HHmmss")+'Z"';
  2616. /*if(!globalSettings.appleremindersmode.value && globalSettings.eventstartfuturelimit.value!=null && (allSyncMode || globalLimitLoading=='futureTodo'))
  2617. {
  2618. if(allSyncMode)
  2619. futureInterval = ' end="'+$.fullCalendar.formatDate(globalToLoadedLimitTodo ,"yyyyMMdd'T'HHmmss")+'Z"';
  2620. else
  2621. futureInterval = ' start="'+$.fullCalendar.formatDate(new Date(new Date(globalToLoadedLimitTodo.getTime()).setMonth(globalToLoadedLimitTodo.getMonth()-globalSettings.eventstartfuturelimit.value-1)) ,"yyyyMMdd'T'HHmmss")+'Z" end="'+$.fullCalendar.formatDate(globalToLoadedLimitTodo,"yyyyMMdd'T'HHmmss")+'Z"';
  2622. }*/
  2623. if(!allSyncMode)
  2624. requestText='<?xml version="1.0" encoding="utf-8"?><L:calendar-query xmlns:L="urn:ietf:params:xml:ns:caldav"><D:prop xmlns:D="DAV:"><D:getcontenttype/><D:getetag/><L:calendar-data/></D:prop><L:filter><L:comp-filter name="VCALENDAR"><L:comp-filter name="VTODO"><L:time-range'+(globalLimitTodoLoading=='pastTodo' ? pastInterval : futureInterval)+'/></L:comp-filter></L:comp-filter></L:filter></L:calendar-query>';
  2625. else
  2626. requestText='<?xml version="1.0" encoding="utf-8"?><L:calendar-query xmlns:L="urn:ietf:params:xml:ns:caldav"><D:prop xmlns:D="DAV:"><D:getcontenttype/><D:getetag/><L:calendar-data/></D:prop><L:filter><L:comp-filter name="VCALENDAR"><L:comp-filter name="VTODO"><L:time-range'+pastInterval+futureInterval+'/></L:comp-filter></L:comp-filter></L:filter></L:calendar-query>';
  2627. }
  2628. }
  2629. }
  2630. function ajaxComplete(data, textStatus, xml)
  2631. {
  2632. $('[data-id="'+inputCollection.uid+'"]').removeClass('r_error');
  2633. if(inputCollection.listType=='vevent' && $('#ResourceCalDAVList').find('.r_error').length==0 && isEachResourceLoaded())
  2634. $('#intCaldav').find('.int_error').css('display','none');
  2635. else if(inputCollection.listType=='vtodo' && $('#ResourceCalDAVTODOList').find('.r_error').length==0 && isEachResourceLoaded())
  2636. $('#intCaldavTodo').find('.int_error').css('display','none');
  2637. var prevNew = inputCollection.newlyAdded;
  2638. inputCollection.newlyAdded = false;
  2639. var vcalendarList=new Array();
  2640. var isXMLEmpty=true;
  2641. if(((inputCollection.listType=='vtodo'&&globalSettings.todopastlimit.value!=null) || (inputCollection.listType=='vevent'&&(globalSettings.eventstartpastlimit.value!=null || globalSettings.eventstartfuturelimit.value!=null))))
  2642. {
  2643. var hrefCounter = 0;
  2644. $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode(new RegExp('^(sync-)?response$')).children().filterNsNode('href').each(function(index, element){
  2645. hrefCounter++;
  2646. });
  2647. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].collectionLength=hrefCounter;
  2648. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].counter=0;
  2649. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].resourceIndex=inputCollection.resourceIndex;
  2650. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].listType=inputCollection.listType;
  2651. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].typeList=inputCollection.typeList;
  2652. }
  2653. var re_found = new RegExp('200 OK$');
  2654. var re_not_found = new RegExp('404 Not Found$');
  2655. $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode(new RegExp('^(sync-)?response$')).each(
  2656. function(index, element)
  2657. {
  2658. var hrefVal=$(element).children().filterNsNode('href').text();
  2659. var etagVal=$(element).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('getetag').text();
  2660. var allowContent=false;
  2661. // checkContentType is undocumented but useful if somebody needs to disable it (wrong server response, etc.)
  2662. if(inputCollection.checkContentType!=false)
  2663. {
  2664. var contenttypeVal=$(element).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('getcontenttype').text();
  2665. if(contenttypeVal!=undefined)
  2666. {
  2667. contenttypeValArr=contenttypeVal.toLowerCase().replace(vCalendar.pre['spaceRex'],'').split(';');
  2668. if(contenttypeValArr.indexOf('text/calendar')!=-1 || contenttypeValArr.indexOf('text/x-vcalendar')!=-1)
  2669. allowContent=true;
  2670. }
  2671. }
  2672. else
  2673. allowContent=true;
  2674. var result=$(element).find('*').filterNsNode('status').text(); // note for 404 there is no propstat!
  2675. var match=false;
  2676. if(hrefVal[hrefVal.length-1]!='/') /* Google CalDAV problem with resource URL if content type checking is disabled */
  2677. {
  2678. if(allowContent==true)
  2679. {
  2680. if(result.match(re_found)) // HTTP OK
  2681. {
  2682. vcalendarList[vcalendarList.length]={etag: etagVal, href: hrefVal};
  2683. match=true;
  2684. }
  2685. }
  2686. if(!match && result.match(re_not_found)) // HTTP Not Found
  2687. vcalendarList[vcalendarList.length]={deleted: true, etag: etagVal, href: hrefVal};
  2688. }
  2689. if((forceLoad || prevNew) && ((inputCollection.listType=='vtodo'&&globalSettings.todopastlimit.value!=null) || (inputCollection.listType=='vevent'&&(globalSettings.eventstartpastlimit.value!=null || globalSettings.eventstartfuturelimit.value!=null))))
  2690. {
  2691. var resultTimestamp=new Date().getTime();
  2692. if($(element).children().filterNsNode('propstat').children().filterNsNode('status').text().match(RegExp('200 OK$'))) // HTTP OK
  2693. {
  2694. var uid=inputCollection.uid+hrefVal.replace(vCalendar.pre['hrefValRex'], '');
  2695. var vcalendar_raw=$(element).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('calendar-data').text();
  2696. if(vcalendar_raw!='')
  2697. {
  2698. isXMLEmpty=false;
  2699. var vcalendar_clean=vCalendarCleanup(vcalendar_raw);
  2700. }
  2701. else
  2702. {
  2703. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  2704. return true;
  2705. }
  2706. if((vcalendar_clean==undefined) || ((check=vcalendar_clean.match(vCalendar.pre['vcalendar']))==null))
  2707. {
  2708. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  2709. console.log("Error: '"+uid+"': unable to parse vCalendar");
  2710. return true;
  2711. }
  2712. if((check=vcalendar_clean.match(vCalendar.pre['vevent']))!=null)
  2713. {
  2714. if(inputCollection.typeList.indexOf('vevent')!=-1)
  2715. globalEventList.insertEvent(false,inputCollection, {threadChange: '', isRepeat: false, isDrawn: false, isTODO: false, untilDate: '', sortStart: '', start: '', end: '', sortkey: '', timestamp: resultTimestamp, accountUID: inputCollection.accountUID, uid: uid, displayValue: inputCollection.displayvalue, counter: 0, etag: etagVal, vcalendar: vcalendar_clean}, false, true,true); // when the inputMode=='sync' we force reload the vevent/vtodo
  2716. else
  2717. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  2718. }
  2719. else if((check=vcalendar_clean.match(vCalendar.pre['vtodo']))!=null)
  2720. {
  2721. if(inputCollection.typeList.indexOf('vtodo')!=-1)
  2722. globalEventList.insertEvent(false,inputCollection, {threadChange: '', isRepeat: false, isDrawn: false, isTODO: true, untilDate: '', sortStart: '', start: '', end: '', sortkey: '', timestamp: resultTimestamp, accountUID: inputCollection.accountUID, uid: uid, displayValue: inputCollection.displayvalue, counter: 0, etag: etagVal, vcalendar: vcalendar_clean}, false, false, true); // when the inputMode=='sync' we force reload the vevent/vtodo
  2723. else
  2724. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  2725. }
  2726. else
  2727. {
  2728. console.log("Error: '"+uid+"': unable to parse vEvent or vTodo");
  2729. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  2730. return true;
  2731. }
  2732. }
  2733. else
  2734. {
  2735. var uid=inputCollection.uid+hrefVal.replace(vCalendar.pre['hrefValRex'], '');
  2736. console.log("Error: '"+uid+"': unable to parse vEvent or vTodo");
  2737. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  2738. return true;
  2739. }
  2740. }
  2741. }
  2742. );
  2743. if(allSyncMode && !forceLoad && !prevNew)
  2744. {
  2745. // store the syncToken
  2746. if(inputCollection.forceSyncPROPFIND==undefined || inputCollection.forceSyncPROPFIND==false)
  2747. inputCollection.syncToken=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('sync-token').text();
  2748. }
  2749. /* inputCollection.someChanged = false;
  2750. if(globalSettings.eventstartpastlimit.value!=null || globalSettings.eventstartfuturelimit.value!=null)
  2751. {
  2752. inputCollection.oldSyncToken = inputCollection.syncToken;
  2753. inputCollection.someChanged = false;
  2754. }
  2755. */
  2756. //loading of todo calendar when imit is set and we need to make 2 ajax filter requests
  2757. if(((inputCollection.listType=='vtodo'&&globalSettings.todopastlimit.value!=null) || (inputCollection.listType=='vevent'&&(globalSettings.eventstartpastlimit.value!=null || globalSettings.eventstartfuturelimit.value!=null))) && !isXMLEmpty)
  2758. {
  2759. inputCollection.oldSyncToken = inputCollection.syncToken;
  2760. inputCollection.someChanged = false;
  2761. if(collections.length>0)
  2762. {
  2763. recursiveIterator++;
  2764. if(recursiveIterator>=collections.length && inputCollection.uid!='undefined' && inputCollection.listType=='vevent')
  2765. {
  2766. setLoadingLimit(forceLoad, allSyncMode);
  2767. recursiveIterator=0;
  2768. if(allSyncMode)
  2769. CalDAVnetLoadCollection(globalResourceCalDAVList.TodoCollections[0], forceLoad, allSyncMode, 0, globalResourceCalDAVList.TodoCollections);
  2770. }
  2771. else
  2772. CalDAVnetLoadCollection(collections[recursiveIterator], forceLoad, allSyncMode, recursiveIterator, collections);
  2773. /*if(globalLimitLoading=='')
  2774. {
  2775. if(inputCollection.listType == 'vevent')
  2776. globalAccountSettings[inputCollection.resourceIndex].calendarNo--;
  2777. else if(inputCollection.listType == 'vtodo')
  2778. globalAccountSettings[inputCollection.resourceIndex].todoNo--;
  2779. if(globalAccountSettings[inputCollection.resourceIndex].calendarNo==0 && globalAccountSettings[inputCollection.resourceIndex].todoNo==0)
  2780. updateMainLoader();
  2781. }*/
  2782. if((globalOnlyCalendarNumber>0 && globalOnlyCalendarNumberCount==globalOnlyCalendarNumber) || (globalTodoCalendarNumber>0 && globalOnlyTodoCalendarNumberCount==globalTodoCalendarNumber))
  2783. updateMainLoader(true,inputCollection.listType);
  2784. }
  2785. return false;
  2786. }
  2787. if(((inputCollection.listType=='vtodo'&&globalSettings.todopastlimit.value!=null) || (inputCollection.listType=='vevent'&&(globalSettings.eventstartpastlimit.value!=null || globalSettings.eventstartfuturelimit.value!=null))) && ((forceLoad && !allSyncMode)||(prevNew && !globalCalDAVInitLoad)))
  2788. netLoadCalendar(inputCollection, vcalendarList, (inputCollection.forceSyncPROPFIND==undefined || inputCollection.forceSyncPROPFIND==false ? true : false), true, forceLoad,allSyncMode, false, recursiveIterator, collections);
  2789. else
  2790. netLoadCalendar(inputCollection, vcalendarList, (inputCollection.forceSyncPROPFIND==undefined || inputCollection.forceSyncPROPFIND==false ? true : false), true, forceLoad,allSyncMode, false, recursiveIterator, collections);
  2791. vcalendarList=null;
  2792. if(typeof globalParallelAjaxCallCalDAVEnabled!='undefined' && globalParallelAjaxCallCalDAVEnabled!=null && globalParallelAjaxCallCalDAVEnabled)
  2793. {
  2794. if(collections.length>0)
  2795. {
  2796. recursiveIterator++;
  2797. if(recursiveIterator>=collections.length && inputCollection.uid!='undefined' && inputCollection.listType=='vevent')
  2798. {
  2799. recursiveIterator=0;
  2800. if((globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null) || allSyncMode)
  2801. CalDAVnetLoadCollection(globalResourceCalDAVList.TodoCollections[0], forceLoad, allSyncMode, 0, globalResourceCalDAVList.TodoCollections);
  2802. }
  2803. else
  2804. CalDAVnetLoadCollection(collections[recursiveIterator], forceLoad, allSyncMode, recursiveIterator, collections);
  2805. }
  2806. }
  2807. }
  2808. // first try to process the cached data (if cached results are available in the "auth module" response)
  2809. var tmpCache;
  2810. var component='';
  2811. if(inputCollection.listType=='vtodo')
  2812. component='VTODO';
  2813. else if(inputCollection.listType=='vevent')
  2814. component='VEVENT';
  2815. if(globalXMLCache!=null && (tmpCache=globalXMLCache.children('caldavcalendarquery[request_url="'+jqueryEscapeSelector(inputCollection.url+inputCollection.href)+'"][request_component="'+component+'"]').remove()).length)
  2816. {
  2817. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  2818. console.log('DBG Cache OK: '+arguments.callee.name+' component: '+component+' url: \''+inputCollection.url+inputCollection.href+'\': saved one request!');
  2819. ajaxComplete('', 'success', {responseXML: tmpCache});
  2820. }
  2821. else
  2822. {
  2823. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  2824. console.log('DBG Cache ERROR: '+arguments.callee.name+' url: \''+inputCollection.url+inputCollection.href+'\': spend one request!');
  2825. $.ajax({
  2826. type: (inputCollection.forceSyncPROPFIND!=undefined && inputCollection.forceSyncPROPFIND==true ? 'PROPFIND' : 'REPORT'),
  2827. url: inputCollection.url+inputCollection.href,
  2828. cache: false,
  2829. crossDomain: (typeof inputCollection.crossDomain=='undefined' ? true: inputCollection.crossDomain),
  2830. xhrFields: {
  2831. withCredentials: (typeof inputCollection.withCredentials=='undefined' ? false: inputCollection.withCredentials)
  2832. },
  2833. timeout: inputCollection.timeOut,
  2834. beforeSend: function(req){
  2835. if(globalSettings.usejqueryauth.value!=true && inputCollection.userAuth.userName!='' && inputCollection.userAuth.userPassword!='')
  2836. req.setRequestHeader('Authorization', basicAuth(inputCollection.userAuth.userName, inputCollection.userAuth.userPassword));
  2837. req.setRequestHeader('X-client', globalXClientHeader);
  2838. req.setRequestHeader('Depth', '1');
  2839. /* XXX - System display:none changes */
  2840. if(isAvaible('Settings') && $('#SystemSettings').css('visibility')=='visible' && $('.resourceSettings_item_selected').attr('data-type')=='setting_group_password')
  2841. {
  2842. if(collections.length>0)
  2843. {
  2844. recursiveIterator++;
  2845. if(recursiveIterator>=collections.length && inputCollection.uid!='undefined' && inputCollection.listType=='vevent')
  2846. {
  2847. setLoadingLimit(forceLoad, allSyncMode);
  2848. recursiveIterator=0;
  2849. if(allSyncMode || (globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null))
  2850. CalDAVnetLoadCollection(globalResourceCalDAVList.TodoCollections[0], forceLoad, allSyncMode, 0, globalResourceCalDAVList.TodoCollections);
  2851. }
  2852. else
  2853. CalDAVnetLoadCollection(collections[recursiveIterator], forceLoad, allSyncMode, recursiveIterator, collections);
  2854. }
  2855. return false;
  2856. }
  2857. },
  2858. username: (globalSettings.usejqueryauth.value==true ? inputCollection.userAuth.userName : null),
  2859. password: (globalSettings.usejqueryauth.value==true ? inputCollection.userAuth.userPassword : null),
  2860. contentType: 'text/xml; charset=utf-8',
  2861. processData: true,
  2862. data: requestText,
  2863. dataType: 'xml',
  2864. error: function(objAJAXRequest, strError){
  2865. if(((inputCollection.listType=='vtodo'&&globalSettings.todopastlimit.value!=null) || (inputCollection.listType=='vevent'&&(globalSettings.eventstartpastlimit.value!=null || globalSettings.eventstartfuturelimit.value!=null))) && objAJAXRequest.responseXML!=null && $(objAJAXRequest.responseXML).children().filterNsNode('C:SUPPORTED-FILTER').length>0)
  2866. {
  2867. if(inputCollection.listType=='vevent')
  2868. {
  2869. globalSettings.eventstartfuturelimit.value = null;
  2870. globalSettings.eventstartpastlimit.value = null;
  2871. }
  2872. else
  2873. globalSettings.todopastlimit.value = null;
  2874. globalCalendarNumberCount--;
  2875. CalDAVnetLoadCollection(collections[recursiveIterator], forceLoad, allSyncMode, recursiveIterator, collections);
  2876. }
  2877. if((objAJAXRequest.status==400 /* bad request */ || objAJAXRequest.status==403 /* forbidden (for stupid servers) */ || objAJAXRequest.status==501 /* unimplemented */) && inputCollection.forceSyncPROPFIND!=true /* prevent recursion */)
  2878. {
  2879. collections[recursiveIterator].forceSyncPROPFIND=true;
  2880. if(inputCollection.listType=='vevent')
  2881. {
  2882. globalSettings.eventstartfuturelimit.value = null;
  2883. globalSettings.eventstartpastlimit.value = null;
  2884. }
  2885. else
  2886. globalSettings.todopastlimit.value = null;
  2887. globalCalendarNumberCount--;
  2888. CalDAVnetLoadCollection(collections[recursiveIterator], forceLoad, allSyncMode, recursiveIterator, collections);
  2889. return true;
  2890. }
  2891. else
  2892. {
  2893. if(collections.length>0)
  2894. {
  2895. recursiveIterator++;
  2896. if(recursiveIterator>=collections.length && inputCollection.uid!='undefined' && inputCollection.listType=='vevent')
  2897. {
  2898. recursiveIterator=0;
  2899. setLoadingLimit(forceLoad, allSyncMode);
  2900. if(allSyncMode || (globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null ))
  2901. CalDAVnetLoadCollection(globalResourceCalDAVList.TodoCollections[0], forceLoad, allSyncMode, 0, globalResourceCalDAVList.TodoCollections);
  2902. }
  2903. else
  2904. CalDAVnetLoadCollection(collections[recursiveIterator], forceLoad, allSyncMode, recursiveIterator, collections);
  2905. }
  2906. if(inputCollection.listType=='vevent')
  2907. {
  2908. $('#ResourceCalDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2909. $('#intCaldav').find('.int_error').css('display','block');
  2910. }
  2911. else
  2912. {
  2913. $('#ResourceCalDAVTODOList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2914. $('#intCaldavTodo').find('.int_error').css('display','block');
  2915. }
  2916. $('[data-id="'+inputCollection.uid+'"]').addClass('r_error');
  2917. inputCollection.syncToken = inputCollection.oldSyncToken;
  2918. if((globalLimitTodoLoading=='' && globalLimitLoading=='') || ((inputCollection.listType=='vtodo'&&globalSettings.todopastlimit.value==null) || (inputCollection.listType=='vevent'&&globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null)))
  2919. {
  2920. if(inputCollection.listType == 'vevent')
  2921. globalAccountSettings[inputCollection.resourceIndex].calendarNo--;
  2922. else if(inputCollection.listType == 'vtodo')
  2923. {
  2924. globalAccountSettings[inputCollection.resourceIndex].todoNo--;
  2925. }
  2926. if((globalAccountSettings[inputCollection.resourceIndex].calendarNo==0 && globalAccountSettings[inputCollection.resourceIndex].todoNo==0 && globalCalDAVInitLoad) || !globalCalDAVInitLoad)
  2927. {
  2928. updateMainLoader();
  2929. }
  2930. }
  2931. else if((globalOnlyCalendarNumber>0 && globalOnlyCalendarNumberCount==globalOnlyCalendarNumber) || (globalTodoCalendarNumber>0 && globalOnlyTodoCalendarNumberCount==globalTodoCalendarNumber))
  2932. updateMainLoader(true,inputCollection.listType);
  2933. console.log("Error: [CalDAVnetLoadCollection: '"+(inputCollection.forceSyncPROPFIND!=undefined && inputCollection.forceSyncPROPFIND==true ? 'PROPFIND' : 'REPORT')+" "+inputCollection.url+inputCollection.href+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  2934. return false;
  2935. }
  2936. },
  2937. success: ajaxComplete
  2938. });
  2939. }
  2940. }
  2941. function netLoadCalendar(inputCollection, vcalendarList, syncReportSupport, removeUntouched, forceLoad, allSyncMode, forceCall, recursiveIterator, collections)
  2942. {
  2943. var vcalendarChangedList=new Array();
  2944. var rid='';
  2945. var resultTimestamp=new Date().getTime();
  2946. if(!inputCollection.subscription)
  2947. {
  2948. if(syncReportSupport==true)
  2949. {
  2950. if(inputCollection.listType=='vevent')
  2951. var isEvent = true;
  2952. else
  2953. var isEvent = false;
  2954. for(var i=0;i<vcalendarList.length;i++)
  2955. if(vcalendarList[i].deleted==true)
  2956. globalEventList.removeOldEvent(inputCollection.uid+vcalendarList[i].href.replace(vCalendar.pre['hrefValRex'], ''), true, isEvent);
  2957. else
  2958. vcalendarChangedList[vcalendarChangedList.length]=vcalendarList[i].href;
  2959. }
  2960. else // no sync-collection REPORT supported (we need to delete vevents/vtodos by timestamp comparison)
  2961. {
  2962. for(var i=0;i<vcalendarList.length;i++)
  2963. {
  2964. var uid=inputCollection.uid+vcalendarList[i].href.replace(vCalendar.pre['hrefValRex'],'');
  2965. if(!globalEventList.checkAndTouchIfExists(inputCollection.uid,uid,vcalendarList[i].etag,resultTimestamp))
  2966. vcalendarChangedList[vcalendarChangedList.length]=vcalendarList[i].href;
  2967. }
  2968. if(inputCollection.listType=='vevent')
  2969. var isEvent = true;
  2970. else
  2971. var isEvent = false;
  2972. globalEventList.removeOldEvents(inputCollection.uid, resultTimestamp, isEvent);
  2973. }
  2974. // not loaded vCalendars from the last multiget (if any)
  2975. if(recursiveIterator!=null)
  2976. if(collections[recursiveIterator]!=undefined)
  2977. if(collections[recursiveIterator].pastUnloaded!=undefined && collections[recursiveIterator].pastUnloaded!=null && collections[recursiveIterator].pastUnloaded.length>0)
  2978. vcalendarChangedList=vcalendarChangedList.concat(collections[recursiveIterator].pastUnloaded).sort().unique();
  2979. // if nothing is changed on server return
  2980. if(vcalendarChangedList.length==0)
  2981. {
  2982. inputCollection.someChanged = false;
  2983. inputCollection.oldSyncToken = inputCollection.syncToken;
  2984. if(forceLoad || globalSettingsSaving!='')
  2985. {
  2986. if(inputCollection.listType=='vevent')
  2987. $('#ResourceCalDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2988. else
  2989. $('#ResourceCalDAVTODOList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2990. if(((inputCollection.listType=='vtodo'&&globalSettings.todopastlimit.value==null) || (inputCollection.listType=='vevent'&&globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null)) || (globalLimitLoading=='' && globalLimitTodoLoading==''))
  2991. {
  2992. if(inputCollection.listType=='vevent')
  2993. globalAccountSettings[inputCollection.resourceIndex].calendarNo--;
  2994. else if(inputCollection.listType=='vtodo')
  2995. globalAccountSettings[inputCollection.resourceIndex].todoNo--;
  2996. if(globalAccountSettings[inputCollection.resourceIndex].calendarNo==0 && globalAccountSettings[inputCollection.resourceIndex].todoNo==0 && globalCalDAVInitLoad)
  2997. updateMainLoader();
  2998. else if(globalSettingsSaving!='')
  2999. updateMainLoader(true,inputCollection.listType,inputCollection.uid);
  3000. }
  3001. else if((globalOnlyCalendarNumber>0 && globalOnlyCalendarNumberCount==globalOnlyCalendarNumber) || (globalTodoCalendarNumber>0 && globalOnlyTodoCalendarNumberCount==globalTodoCalendarNumber) || globalSettingsSaving!='')
  3002. updateMainLoader(true,inputCollection.listType);
  3003. }
  3004. if((typeof globalParallelAjaxCallCalDAVEnabled=='undefined' || globalParallelAjaxCallCalDAVEnabled==null || !globalParallelAjaxCallCalDAVEnabled) && collections.length>0)
  3005. {
  3006. recursiveIterator++;
  3007. if(recursiveIterator>=collections.length && inputCollection.uid!='undefined' && inputCollection.listType=='vevent')
  3008. {
  3009. recursiveIterator=0;
  3010. if((globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null) || allSyncMode)
  3011. CalDAVnetLoadCollection(globalResourceCalDAVList.TodoCollections[0], forceLoad, allSyncMode, 0, globalResourceCalDAVList.TodoCollections);
  3012. }
  3013. else
  3014. CalDAVnetLoadCollection(collections[recursiveIterator], forceLoad, allSyncMode, recursiveIterator, collections);
  3015. }
  3016. return true;
  3017. }
  3018. }
  3019. else
  3020. {
  3021. var evCount=0;
  3022. for(c in vcalendarList)
  3023. if(vcalendarList[c].etag!=undefined && vcalendarList[c].etag!=null)
  3024. evCount++;
  3025. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].collectionLength=evCount;
  3026. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].counter=0;
  3027. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].resourceIndex=inputCollection.resourceIndex;
  3028. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].listType=inputCollection.listType;
  3029. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].typeList=inputCollection.typeList;
  3030. // if(inputCollection.listType=='vevent')
  3031. // $('#ResourceCalDAVList [data-id="'+inputCollection.uid+'"]').addClass('r_operate');
  3032. // else
  3033. // $('#ResourceCalDAVTODOList [data-id="'+inputCollection.uid+'"]').addClass('r_operate');
  3034. if($('.r_operate_all').length==0)
  3035. $('#SystemCalDavZAP .fc-header-center ').addClass('r_operate_all');
  3036. for(eventUID in vcalendarList)
  3037. {
  3038. if(vcalendarList[eventUID].etag==undefined || vcalendarList[eventUID]==null)
  3039. continue;
  3040. var etag=vcalendarList[eventUID].etag;
  3041. var uid=vcalendarList[eventUID].href;
  3042. var vcalendar_raw=vcalendarList[eventUID].eventText;
  3043. if(vcalendar_raw!='')
  3044. var vcalendar_clean=vCalendarCleanup(vcalendar_raw);
  3045. else
  3046. {
  3047. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  3048. return true;
  3049. }
  3050. if((check=vcalendar_clean.match(vCalendar.pre['vevent']))!=null)
  3051. {
  3052. if(inputCollection.typeList.indexOf('vevent')!=-1)
  3053. globalEventList.insertEvent(forceCall,inputCollection, {threadChange: '', isRepeat: false, isDrawn: false, isTODO: false, untilDate: '', sortStart: '', start: '', end: '', sortkey: '', timestamp: resultTimestamp, accountUID: inputCollection.accountUID, uid: uid, displayValue: inputCollection.displayvalue, counter: 0, etag: etag, vcalendar: 'BEGIN:VCALENDAR'+vcalendar_clean+ 'END:VCALENDAR\r\n'}, false, true,true); // when the inputMode=='sync' we force reload the vevent/vtodo
  3054. else
  3055. {
  3056. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  3057. }
  3058. }
  3059. else if((check=vcalendar_clean.match(vCalendar.pre['vtodo']))!=null)
  3060. {
  3061. if(inputCollection.typeList.indexOf('vtodo')!=-1)
  3062. globalEventList.insertEvent(forceCall, inputCollection, {threadChange: '', isRepeat: false, isDrawn: false, isTODO: false, untilDate: '', sortStart: '', start: '', end: '', sortkey: '', timestamp: resultTimestamp, accountUID: inputCollection.accountUID, uid: uid, displayValue: inputCollection.displayvalue, counter: 0, etag: etag, vcalendar: 'BEGIN:VCALENDAR'+vcalendar_clean+ 'END:VCALENDAR\r\n'}, false, false,true); // when the inputMode=='sync' we force reload the vevent/vtodo
  3063. else
  3064. {
  3065. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  3066. }
  3067. }
  3068. else
  3069. {
  3070. console.log("Error: '"+uid+"': unable to parse vEvent or vTodo");
  3071. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  3072. }
  3073. }
  3074. if(evCount==0)
  3075. {
  3076. if(inputCollection.listType=='vevent')
  3077. $('#ResourceCalDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  3078. else
  3079. $('#ResourceCalDAVTODOList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  3080. if(allSyncMode && globalLimitLoading=='' && globalLimitTodoLoading=='')
  3081. {
  3082. if(inputCollection.typeList.indexOf('vevent')!=-1)
  3083. globalAccountSettings[inputCollection.resourceIndex].calendarNo--;
  3084. if(inputCollection.typeList.indexOf('vtodo')!=-1)
  3085. globalAccountSettings[inputCollection.resourceIndex].todoNo--;
  3086. if((globalAccountSettings[inputCollection.resourceIndex].calendarNo==0 && globalAccountSettings[inputCollection.resourceIndex].todoNo==0 && globalCalDAVInitLoad))
  3087. updateMainLoader();
  3088. else if(globalSettingsSaving!='')
  3089. updateMainLoader(true,inputCollection.listType,inputCollection.uid);
  3090. }
  3091. else if((globalOnlyCalendarNumber>0 && globalOnlyCalendarNumberCount==globalOnlyCalendarNumber) || (globalTodoCalendarNumber>0 && globalOnlyTodoCalendarNumberCount==globalTodoCalendarNumber))
  3092. updateMainLoader(true,inputCollection.listType);
  3093. }
  3094. return false;
  3095. }
  3096. if($('.r_operate_all').length==0)
  3097. $('#SystemCalDavZAP .fc-header-center ').addClass('r_operate_all');
  3098. multigetData='<?xml version="1.0" encoding="utf-8"?><L:calendar-multiget xmlns:D="DAV:" xmlns:L="urn:ietf:params:xml:ns:caldav"><D:prop><D:getetag/><L:calendar-data/></D:prop><D:href>'+vcalendarChangedList.join('</D:href><D:href>')+'</D:href></L:calendar-multiget>';
  3099. var returnValue=false;
  3100. $.ajax({
  3101. type: 'REPORT',
  3102. url: inputCollection.url+inputCollection.href,
  3103. cache: false,
  3104. crossDomain: (typeof inputCollection.crossDomain=='undefined' ? true: inputCollection.crossDomain),
  3105. xhrFields: {
  3106. withCredentials: (typeof inputCollection.withCredentials=='undefined' ? false: inputCollection.withCredentials)
  3107. },
  3108. timeout: inputCollection.timeOut,
  3109. beforeSend: function(req){
  3110. if(globalSettings.usejqueryauth.value!=true && inputCollection.userAuth.userName!='' && inputCollection.userAuth.userPassword!='')
  3111. req.setRequestHeader('Authorization', basicAuth(inputCollection.userAuth.userName, inputCollection.userAuth.userPassword));
  3112. req.setRequestHeader('X-client', globalXClientHeader);
  3113. },
  3114. username: (globalSettings.usejqueryauth.value==true ? inputCollection.userAuth.userName : null),
  3115. password: (globalSettings.usejqueryauth.value==true ? inputCollection.userAuth.userPassword : null),
  3116. contentType: 'text/xml',
  3117. processData: true,
  3118. data: multigetData,
  3119. dataType: 'xml',
  3120. error: function(objAJAXRequest, strError) {
  3121. // unable to load vcalendars, try to load them next time
  3122. if(recursiveIterator!=null)
  3123. if(inputCollection.pastUnloaded!=null && inputCollection.pastUnloaded!=undefined)
  3124. inputCollection.pastUnloaded=vcalendarChangedList;
  3125. console.log("Error: [netLoadCalendar: 'REPORT "+inputCollection.url+inputCollection.href+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  3126. if(inputCollection.listType=='vevent')
  3127. {
  3128. $('#ResourceCalDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  3129. $('#intCaldav').find('.int_error').css('display','block');
  3130. }
  3131. else
  3132. {
  3133. $('#ResourceCalDAVTODOList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  3134. $('#intCaldavTodo').find('.int_error').css('display','block');
  3135. }
  3136. $('[data-id="'+inputCollection.uid+'"]').addClass('r_error');
  3137. inputCollection.syncToken = inputCollection.oldSyncToken;
  3138. if(((inputCollection.listType=='vtodo'&&globalSettings.todopastlimit.value==null) || (inputCollection.listType=='vevent'&&globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null)) || (globalLimitLoading=='' && globalLimitTodoLoading==''))
  3139. {
  3140. if(inputCollection.listType.indexOf('vevent')!=-1)
  3141. globalAccountSettings[inputCollection.resourceIndex].calendarNo--;
  3142. else if(inputCollection.listType.indexOf('vtodo')!=-1)
  3143. globalAccountSettings[inputCollection.resourceIndex].todoNo--;
  3144. if((globalAccountSettings[inputCollection.resourceIndex].calendarNo==0 && globalAccountSettings[inputCollection.resourceIndex].todoNo==0 && globalCalDAVInitLoad))
  3145. updateMainLoader();
  3146. else if(globalSettingsSaving!='')
  3147. updateMainLoader(true,inputCollection.listType,inputCollection.uid);
  3148. }
  3149. else if((globalOnlyCalendarNumber>0 && globalOnlyCalendarNumberCount==globalOnlyCalendarNumber) || (globalTodoCalendarNumber>0 && globalOnlyTodoCalendarNumberCount==globalTodoCalendarNumber))
  3150. updateMainLoader(true,inputCollection.listType);
  3151. if((typeof globalParallelAjaxCallCalDAVEnabled=='undefined' || globalParallelAjaxCallCalDAVEnabled==null || !globalParallelAjaxCallCalDAVEnabled) && collections.length>0)
  3152. {
  3153. recursiveIterator++;
  3154. if(recursiveIterator>=collections.length && inputCollection.uid!='undefined' && inputCollection.listType=='vevent')
  3155. {
  3156. recursiveIterator=0;
  3157. if((globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null) || allSyncMode)
  3158. CalDAVnetLoadCollection(globalResourceCalDAVList.TodoCollections[0], forceLoad, allSyncMode, 0, globalResourceCalDAVList.TodoCollections);
  3159. }
  3160. else
  3161. CalDAVnetLoadCollection(collections[recursiveIterator], forceLoad, allSyncMode, recursiveIterator, collections);
  3162. }
  3163. return false;
  3164. },
  3165. success: function(data, textStatus, xml){
  3166. inputCollection.someChanged = false;
  3167. if(inputCollection.listType=='vevent' && $('#ResourceCalDAVList').find('.r_error').length==0 && isEachResourceLoaded())
  3168. $('#intCaldav').find('.int_error').css('display','none');
  3169. else if(inputCollection.listType=='vtodo' && $('#ResourceCalDAVTODOList').find('.r_error').length==0 && isEachResourceLoaded())
  3170. $('#intCaldavTodo').find('.int_error').css('display','none');
  3171. inputCollection.oldSyncToken = inputCollection.syncToken;
  3172. inputCollection.pastUnloaded='';
  3173. var hrefCounter = 0;
  3174. $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('href').each(function(index, element){
  3175. hrefCounter++;
  3176. });
  3177. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].collectionLength=hrefCounter;
  3178. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].counter=0;
  3179. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].resourceIndex=inputCollection.resourceIndex;
  3180. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].listType=inputCollection.listType;
  3181. globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType].typeList=inputCollection.typeList;
  3182. var isXMLEmpty=true;
  3183. var re_found = new RegExp('200 OK$');
  3184. $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').each(function(index, element){
  3185. if($(element).children().filterNsNode('propstat').children().filterNsNode('status').text().match(re_found)) // HTTP OK
  3186. {
  3187. isXMLEmpty=false;
  3188. var etag=$(element).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('getetag').text();
  3189. var uid=inputCollection.uid+$(element).children().filterNsNode('href').text().replace(vCalendar.pre['hrefValRex'], '');
  3190. var vcalendar_raw=$(element).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('calendar-data').text();
  3191. if(vcalendar_raw!='')
  3192. var vcalendar_clean=vCalendarCleanup(vcalendar_raw);
  3193. else
  3194. {
  3195. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  3196. return true;
  3197. }
  3198. if((vcalendar_clean==undefined) || ((check=vcalendar_clean.match(vCalendar.pre['vcalendar']))==null))
  3199. {
  3200. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  3201. console.log("Error: '"+uid+"': unable to parse vCalendar");
  3202. return true;
  3203. }
  3204. if((check=vcalendar_clean.match(vCalendar.pre['vevent']))!=null)
  3205. {
  3206. if(inputCollection.typeList.indexOf('vevent')!=-1)
  3207. globalEventList.insertEvent(forceCall,inputCollection, {threadChange: '', isRepeat: false, isDrawn: false, isTODO: false, untilDate: '', sortStart: '', start: '', end: '', sortkey: '', timestamp: resultTimestamp, accountUID: inputCollection.accountUID, uid: uid, displayValue: inputCollection.displayvalue, counter: 0, etag: etag, vcalendar: vcalendar_clean}, false, true,true); // when the inputMode=='sync' we force reload the vevent/vtodo
  3208. else
  3209. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  3210. }
  3211. else if((check=vcalendar_clean.match(vCalendar.pre['vtodo']))!=null)
  3212. {
  3213. if(inputCollection.typeList.indexOf('vtodo')!=-1)
  3214. globalEventList.insertEvent(forceCall,inputCollection, {threadChange: '', isRepeat: false, isDrawn: false, isTODO: false, untilDate: '', sortStart: '', start: '', end: '', sortkey: '', timestamp: resultTimestamp, accountUID: inputCollection.accountUID, uid: uid, displayValue: inputCollection.displayvalue, counter: 0, etag: etag, vcalendar: vcalendar_clean}, false, false, true); // when the inputMode=='sync' we force reload the vevent/vtodo
  3215. else
  3216. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  3217. }
  3218. else
  3219. {
  3220. console.log("Error: '"+uid+"': unable to parse vEvent or vTodo");
  3221. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  3222. return true;
  3223. }
  3224. }
  3225. else
  3226. {
  3227. var uid=inputCollection.uid+$(element).children().filterNsNode('href').text().replace(vCalendar.pre['hrefValRex'], '');
  3228. console.log("Error: '"+uid+"': unable to parse vEvent or vTodo");
  3229. checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType],false);
  3230. return true;
  3231. }
  3232. });
  3233. if(isXMLEmpty)
  3234. {
  3235. if(inputCollection.listType=='vevent')
  3236. $('#ResourceCalDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  3237. else
  3238. $('#ResourceCalDAVTODOList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  3239. if(globalLimitLoading=='' && globalLimitTodoLoading=='')
  3240. {
  3241. if(inputCollection.typeList.indexOf('vevent')!=-1)
  3242. globalAccountSettings[inputCollection.resourceIndex].calendarNo--;
  3243. else if(inputCollection.typeList.indexOf('vtodo')!=-1)
  3244. globalAccountSettings[inputCollection.resourceIndex].todoNo--;
  3245. if(globalAccountSettings[inputCollection.resourceIndex].calendarNo==0 && globalAccountSettings[inputCollection.resourceIndex].todoNo==0 && globalCalDAVInitLoad)
  3246. updateMainLoader();
  3247. else if(globalSettingsSaving!='')
  3248. updateMainLoader(true,inputCollection.listType,inputCollection.uid);
  3249. }
  3250. else if((globalOnlyCalendarNumber>0 && globalOnlyCalendarNumberCount==globalOnlyCalendarNumber) || (globalTodoCalendarNumber>0 && globalOnlyTodoCalendarNumberCount==globalTodoCalendarNumber))
  3251. updateMainLoader(true,inputCollection.listType);
  3252. }
  3253. if((typeof globalParallelAjaxCallCalDAVEnabled=='undefined' || globalParallelAjaxCallCalDAVEnabled==null || !globalParallelAjaxCallCalDAVEnabled) && collections.length>0)
  3254. {
  3255. recursiveIterator++;
  3256. if(recursiveIterator>=collections.length && inputCollection.uid!='undefined' && inputCollection.listType=='vevent')
  3257. {
  3258. recursiveIterator=0;
  3259. if((globalSettings.eventstartpastlimit.value==null && globalSettings.eventstartfuturelimit.value==null) || allSyncMode)
  3260. CalDAVnetLoadCollection(globalResourceCalDAVList.TodoCollections[0], forceLoad, allSyncMode, 0, globalResourceCalDAVList.TodoCollections);
  3261. }
  3262. else
  3263. CalDAVnetLoadCollection(collections[recursiveIterator], forceLoad, allSyncMode, recursiveIterator, collections);
  3264. }
  3265. if(globalTodoLoaderHide!='')
  3266. {
  3267. show_editor_loader_messageCalendar('vtodo', 'message_success', globalTodoLoaderHide, function(a){
  3268. globalTodoLoaderHide='';
  3269. $('#showTODO').val('');
  3270. $('#TodoDisabler').fadeOut(globalEditorFadeAnimation, function(){
  3271. $('#timezonePickerTODO').prop('disabled', false);
  3272. });
  3273. });
  3274. }
  3275. }
  3276. });
  3277. }
  3278. function netLoadCalendarSubscription(inputResource, inputCollection, recursiveIterator, forceLoad, collections)
  3279. {
  3280. if(!inputCollection.makeLoaded || globalLimitLoading!='' || globalLimitTodoLoading!='')
  3281. {
  3282. if(inputCollection.makeLoaded)
  3283. updateMainLoaderText(inputCollection.listType);
  3284. if(inputCollection.listType=='vevent')
  3285. $('#ResourceCalDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  3286. else
  3287. $('#ResourceCalDAVTODOList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  3288. if(globalLimitLoading=='' && globalLimitTodoLoading=='')
  3289. {
  3290. if(inputCollection.typeList.indexOf('vevent')!=-1)
  3291. globalAccountSettings[inputCollection.resourceIndex].calendarNo--;
  3292. else if(inputCollection.typeList.indexOf('vtodo')!=-1)
  3293. globalAccountSettings[inputCollection.resourceIndex].todoNo--;
  3294. if((globalAccountSettings[inputCollection.resourceIndex].calendarNo==0 && globalAccountSettings[inputCollection.resourceIndex].todoNo==0 && globalCalDAVInitLoad) || !globalCalDAVInitLoad)
  3295. updateMainLoader();
  3296. }
  3297. else if(globalLimitLoading!='' || globalLimitTodoLoading!='')
  3298. updateMainLoader();
  3299. return false;
  3300. }
  3301. $.ajax({
  3302. type: 'GET',
  3303. url: inputCollection.href,
  3304. cache: false,
  3305. crossDomain: false,
  3306. timeout: 30000,
  3307. beforeSend: function(req) {
  3308. if(globalSettings.usejqueryauth.value!=true && inputResource.userAuth.userName!='' && inputResource.userAuth.userPassword!='')
  3309. req.setRequestHeader('Authorization', basicAuth(inputResource.userAuth.userName, inputResource.userAuth.userPassword));
  3310. },
  3311. username: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userName : null),
  3312. password: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userPassword : null),
  3313. contentType: 'text/plain',
  3314. processData: true,
  3315. data: '',
  3316. dataType: 'text',
  3317. error: function(objAJAXRequest, strError){
  3318. console.log("Error: [netLoadCalendarSubscription: 'GET "+inputCollection.href+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'");
  3319. if(inputCollection.listType=='vevent')
  3320. {
  3321. $('#ResourceCalDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  3322. $('#intCaldav').find('.int_error').css('display','block');
  3323. }
  3324. else
  3325. {
  3326. $('#ResourceCalDAVTODOList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  3327. $('#intCaldavTodo').find('.int_error').css('display','block');
  3328. }
  3329. $('[data-id="'+inputCollection.uid+'"]').addClass('r_error');
  3330. if(globalLimitLoading=='' && globalLimitTodoLoading=='')
  3331. {
  3332. if(inputCollection.typeList.indexOf('vevent')!=-1)
  3333. globalAccountSettings[inputCollection.resourceIndex].calendarNo--;
  3334. else if(inputCollection.typeList.indexOf('vtodo')!=-1)
  3335. globalAccountSettings[inputCollection.resourceIndex].todoNo--;
  3336. if((globalAccountSettings[inputCollection.resourceIndex].calendarNo==0 && globalAccountSettings[inputCollection.resourceIndex].todoNo==0 && globalCalDAVInitLoad) || !globalCalDAVInitLoad)
  3337. updateMainLoader();
  3338. }
  3339. return false;
  3340. },
  3341. success: function(data, response, text)
  3342. {
  3343. if(inputCollection.listType=='vevent' && $('#ResourceCalDAVList').find('.r_error').length==0 && isEachResourceLoaded())
  3344. $('#intCaldav').find('.int_error').css('display','none');
  3345. else if(inputCollection.listType=='vtodo' && $('#ResourceCalDAVTODOList').find('.r_error').length==0 && isEachResourceLoaded())
  3346. $('#intCaldavTodo').find('.int_error').css('display','none');
  3347. var vcalendarText = vCalendarCleanup(text.responseText);
  3348. inputCollection.urlArray={};
  3349. inputCollection.newlyAdded = false;
  3350. if(inputCollection.typeList.indexOf('vevent')!=-1)
  3351. {
  3352. var parseCounter=0;
  3353. var isEvent = false;
  3354. if(vcalendarText.match(vCalendar.pre['vevent'])!=null)
  3355. isEvent = true;
  3356. while(vcalendarText.match(vCalendar.pre['vevent'])!=null)
  3357. {
  3358. var partEvent=vcalendarText.substring(vcalendarText.indexOf('BEGIN:VEVENT')-2,vcalendarText.indexOf('END:VEVENT')+'END:VEVENT'.length);
  3359. var realEventUID=partEvent.match(vCalendar.pre['contentline_UID']);
  3360. if(realEventUID!=null)
  3361. {
  3362. realEventUID=realEventUID[0].match(vCalendar.pre['contentline_parse'])[4];
  3363. realEventUID=realEventUID.replace('/','');
  3364. }
  3365. var hex = hex_sha256(partEvent);
  3366. if(inputCollection.urlArray != null)
  3367. {
  3368. if(inputCollection.urlArray[inputCollection.uid+realEventUID+'.ics']!=null && inputCollection.urlArray[inputCollection.uid+realEventUID+'.ics']!=undefined)
  3369. inputCollection.urlArray[inputCollection.uid+realEventUID+'.ics'].eventText+=partEvent+'\r\n';
  3370. else
  3371. inputCollection.urlArray[inputCollection.uid+realEventUID+'.ics'] = {etag: hex, href: inputCollection.uid+realEventUID+'.ics', eventText : partEvent+'\r\n'};
  3372. }
  3373. vcalendarText = vcalendarText.replace(partEvent,'');
  3374. parseCounter++;
  3375. }
  3376. if(parseCounter==0 && isEvent)
  3377. {
  3378. if(typeof realEventUID=='undefined' || realEventUID==null)
  3379. console.log("Error: '"+inputCollection.uid+"': unable to parse subscribed vEvent");
  3380. else
  3381. console.log("Error: '"+inputCollection.uid+realEventUID+'.ics'+"': unable to parse subscribed vEvent");
  3382. }
  3383. }
  3384. if(inputCollection.typeList.indexOf('vtodo')!=-1)
  3385. {
  3386. var parseCounter=0;
  3387. var isTodo = false;
  3388. if(vcalendarText.match(vCalendar.pre['vtodo'])!=null)
  3389. isTodo = true;
  3390. while(vcalendarText.match(vCalendar.pre['vtodo'])!=null)
  3391. {
  3392. var partEvent=vcalendarText.substring(vcalendarText.indexOf('BEGIN:VTODO')-2,vcalendarText.indexOf('END:VTODO')+'END:VTODO'.length);
  3393. var realEventUID=partEvent.match(vCalendar.pre['contentline_UID']);
  3394. if(realEventUID!=null)
  3395. {
  3396. realEventUID=realEventUID[0].match(vCalendar.pre['contentline_parse'])[4];
  3397. realEventUID=realEventUID.replace('/','');
  3398. }
  3399. var hex = hex_sha256(partEvent);
  3400. if(inputCollection.urlArray != null)
  3401. {
  3402. if(inputCollection.urlArray[inputCollection.uid+realEventUID+'.ics']!=null && inputCollection.urlArray[inputCollection.uid+realEventUID+'.ics']!=undefined)
  3403. inputCollection.urlArray[inputCollection.uid+realEventUID+'.ics'].eventText+=partEvent+'\r\n';
  3404. else
  3405. inputCollection.urlArray[inputCollection.uid+realEventUID+'.ics'] = {etag: hex, href: inputCollection.uid+realEventUID+'.ics', eventText : partEvent+'\r\n'};
  3406. }
  3407. vcalendarText = vcalendarText.replace(partEvent,'');
  3408. parseCounter++;
  3409. }
  3410. if(parseCounter==0 && isTodo)
  3411. {
  3412. if(typeof realEventUID=='undefined' || realEventUID==null)
  3413. console.log("Error: '"+inputCollection.uid+"': unable to parse subscribed vTodo");
  3414. else
  3415. console.log("Error: '"+inputCollection.uid+realEventUID+'.ics'+"': unable to parse subscribed vTodo");
  3416. }
  3417. }
  3418. if(typeof globalEventList.events[inputCollection.uid] != 'undefined')
  3419. {
  3420. for(event in globalEventList.events[inputCollection.uid])
  3421. {
  3422. if(inputCollection.urlArray[event] == undefined || inputCollection.urlArray[event] == null)
  3423. globalEventList.removeOldEvent(event, true, true);
  3424. }
  3425. }
  3426. else
  3427. {
  3428. for(event in globalEventList.todos[inputCollection.uid])
  3429. if(inputCollection.urlArray[event] == undefined || inputCollection.urlArray[event] == null)
  3430. globalEventList.removeOldEvent(event, true, false);
  3431. }
  3432. netLoadCalendar(inputCollection, inputCollection.urlArray, (inputCollection.forceSyncPROPFIND==undefined || inputCollection.forceSyncPROPFIND==false ? true : false), true, forceLoad, true, false, recursiveIterator, collections);
  3433. }
  3434. });
  3435. }