webdav_protocol.js 178 KB

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