data_process.js 156 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265
  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. String.prototype.parseComnpactISO8601=function(uid)
  19. {
  20. if(this.length>=15)
  21. var formattedString=this.substring(0, 4)+'/'+this.substring(4, 6)+'/'+this.substring(6, 8)+' '+this.substring(9, 11)+':'+this.substring(11, 13)+':'+this.substring(13, 15);
  22. else
  23. var formattedString=this.substring(0, 4)+'/'+this.substring(4, 6)+'/'+this.substring(6, 8)+' '+'00:00:00';
  24. var value=Date.parse(formattedString);
  25. if(isNaN(value))
  26. return false
  27. else
  28. return new Date(value);
  29. }
  30. function repeatStartCompare(objA,objB)
  31. {
  32. var startA='',startB='';
  33. if(objA.rec_id!='')
  34. startA=objA.rec_id.parseComnpactISO8601();
  35. else if(objA.start)
  36. startA=new Date(objA.start.getTime());
  37. else if(objA.end)
  38. startA=new Date(objA.end.getTime());
  39. else
  40. startA=Infinity;
  41. if(objB.rec_id!='')
  42. startB=objB.rec_id.parseComnpactISO8601();
  43. else if(objB.start)
  44. startB=new Date(objB.start.getTime());
  45. else if(objB.end)
  46. startB=new Date(objB.end.getTime());
  47. else
  48. startB=Infinity;
  49. if(startA<startB)
  50. return -1;
  51. if(startA>startB)
  52. return 1;
  53. return 0;
  54. }
  55. function findWeek(weekNo,inDate,day)
  56. {
  57. var distance = (day + 7 - inDate.getDay()) % 7;
  58. var date = new Date(inDate.getTime());
  59. date.setDate(date.getDate() + distance);
  60. if(date.getWeekNo() <= weekNo)
  61. date.setDate(date.getDate() + 7*(weekNo-date.getWeekNo()));
  62. else
  63. {
  64. var actualYearWeeks = new Date(date.getFullYear(),11,31,1,1,1).getWeekNo();
  65. date.setDate(date.getDate() + 7*(actualYearWeeks-date.getWeekNo()));
  66. }
  67. }
  68. String.prototype.getSecondsFromOffset=function()
  69. {
  70. if(this.length>=5)
  71. {
  72. var hours=this.substring(1,3);
  73. var minutes=this.substring(3,5);
  74. var seconds='00';
  75. if(this.length>=7)
  76. seconds=this.substring(5,7);
  77. var value=parseInt(hours,10)*60*60+parseInt(minutes,10)*60+parseInt(seconds,10);
  78. if(this.charAt(0)=='-')
  79. value=value*-1;
  80. if(!isNaN(value))
  81. return value
  82. else
  83. return 0;
  84. }
  85. else
  86. return 0;
  87. }
  88. Array.prototype.indexElementOf=function(value)
  89. {
  90. for(var i=0;i<this.length;i++)
  91. if(this[i].indexOf(value)!=-1)
  92. return i;
  93. return -1;
  94. }
  95. function setAlertTimeouts(isTodo, alertTime, dateStart, dateEnd, params, firstInstance, uid)
  96. {
  97. var alertTimeOut=new Array();
  98. if(isTodo && dateEnd!='')
  99. {
  100. if(typeof dateEnd=='string')
  101. dateStart = dateEnd;
  102. else
  103. dateStart=new Date(dateEnd.getTime());
  104. }
  105. else if(isTodo && dateStart!='')
  106. {
  107. if(typeof dateStart=='string')
  108. dateEnd=dateStart;
  109. else
  110. dateEnd=new Date(dateStart.getTime());
  111. }
  112. if(alertTime.length>0)
  113. {
  114. for(var v=0;v<alertTime.length;v++)
  115. {
  116. if((alertTime[v].charAt(0)=='-') || (alertTime[v].charAt(0)=='+') || firstInstance)
  117. {
  118. var startTime;
  119. var aTime='';
  120. if((dateStart!='' || dateEnd!='') && alertTime[v].charAt(0)=='-')
  121. {
  122. if(typeof dateStart=='string')
  123. startTime = $.fullCalendar.parseDate(dateStart);
  124. else
  125. startTime=new Date(dateStart.getTime());
  126. aTime=startTime.getTime() - parseInt(alertTime[v].substring(1, alertTime[v].length-1));
  127. }
  128. else if((dateStart!='' || dateEnd!='') && alertTime[v].charAt(0)=='+')
  129. {
  130. if(typeof dateEnd=='string')
  131. startTime = $.fullCalendar.parseDate(dateEnd);
  132. else
  133. startTime=new Date(dateEnd.getTime());
  134. aTime=startTime.getTime() + parseInt(alertTime[v].substring(1, alertTime[v].length-1));
  135. }
  136. else if(firstInstance)
  137. {
  138. aTime=$.fullCalendar.parseDate(alertTime[v]);
  139. if(isTodo)
  140. var displayDate=(dateEnd=='' ? dateStart : dateEnd);
  141. else
  142. var displayDate=dateStart;
  143. if(displayDate!='')
  144. startTime = new Date(displayDate.getTime());
  145. else
  146. startTime='';
  147. }
  148. var now=new Date();
  149. if(aTime!==''&&aTime>now)
  150. {
  151. var delay=aTime-now;
  152. if(maxAlarmValue<delay)
  153. delay=maxAlarmValue;
  154. if(isTodo)
  155. alertTimeOut[alertTimeOut.length]=setTimeout(function(startTime){
  156. showAlertTODO(uid, (aTime-now), {start:(startTime!='' ? new Date(startTime.getTime()) : ''), status:params.status, title:params.title});
  157. }, delay,startTime);
  158. else
  159. alertTimeOut[alertTimeOut.length]=setTimeout(function(startTime){
  160. showAlertEvents(uid, (aTime-now), {start:new Date(startTime.getTime()), allDay:params.allDay, title:params.title});
  161. }, delay,startTime);
  162. }
  163. }
  164. }
  165. }
  166. return alertTimeOut;
  167. }
  168. function isInRecurrenceArray(varDate,stringUID,recurrence_id_array, tzName)
  169. {
  170. var checkRec=false;
  171. var checkDate='';
  172. if(typeof varDate=='string')
  173. checkDate=$.fullCalendar.parseDate(varDate);
  174. else
  175. checkDate=new Date(varDate.getTime());
  176. if(recurrence_id_array.length>0)
  177. {
  178. for(var ir=0;ir<recurrence_id_array.length;ir++)
  179. {
  180. var recString = recurrence_id_array[ir].split(';')[0];
  181. if(recString.charAt(recString.length-1)=='Z')
  182. {
  183. if(globalSettings.timezonesupport.value && tzName in timezones)
  184. {
  185. var recValOffsetFrom=getOffsetByTZ(tzName, varDate);
  186. var recTime = new Date(recString.parseComnpactISO8601().getTime());
  187. if(recValOffsetFrom)
  188. {
  189. var rintOffset=recValOffsetFrom.getSecondsFromOffset()*1000;
  190. recTime.setTime(recTime.getTime()+rintOffset);
  191. }
  192. if(recTime.toString()+recurrence_id_array[ir].split(';')[1] == varDate+stringUID)
  193. checkRec=true;
  194. }
  195. }
  196. else
  197. {
  198. if(recString.parseComnpactISO8601().toString()+recurrence_id_array[ir].split(';')[1] == varDate+stringUID)
  199. checkRec=true;
  200. }
  201. }
  202. }
  203. return checkRec;
  204. }
  205. function applyTimezone(previousTimezone,isEventLocal)
  206. {
  207. updateMainLoaderTextTimezone();
  208. $('#MainLoader').show();
  209. var eventsDone=false;
  210. var todosDone=false;
  211. var collections=globalResourceCalDAVList.collections;
  212. var todoCollections=globalResourceCalDAVList.TodoCollections;
  213. var calendarCount=0, calendarCounter=0;
  214. var todoCount=0, todoCounter=0;
  215. for(var i=0;i<collections.length;i++)
  216. if(collections[i].uid!=undefined)
  217. calendarCount++;
  218. for(var i=0;i<todoCollections.length;i++)
  219. if(todoCollections[i].uid!=undefined)
  220. todoCount++;
  221. var eventsArray=globalEventList.displayEventsArray;
  222. var todosArray=globalEventList.displayTodosArray;
  223. for(var i=0;i<collections.length;i++)
  224. if(collections[i].uid!=undefined)
  225. {
  226. setTimeout(function(i){
  227. for(var j=0;j<eventsArray[collections[i].uid].length;j++)
  228. {
  229. if(eventsArray[collections[i].uid][j].timeZone=='local' || eventsArray[collections[i].uid][j].allDay)
  230. continue;
  231. var dateStart=eventsArray[collections[i].uid][j].start;
  232. var previousOffset=getOffsetByTZ(previousTimezone, dateStart).getSecondsFromOffset();
  233. var actualOffset='';
  234. if(typeof globalSessionTimeZone!='undefined' && globalSessionTimeZone!=null && globalSessionTimeZone!='')
  235. actualOffset=getOffsetByTZ(globalSessionTimeZone, dateStart).getSecondsFromOffset();
  236. else
  237. actualOffset=dateStart.getTimezoneOffset()*60*-1;
  238. //if timezonesupport is turned off go to local
  239. if(typeof isEventLocal!='undefined')
  240. actualOffset=getOffsetByTZ(eventsArray[collections[i].uid][j].timeZone, dateStart).getSecondsFromOffset();
  241. if(typeof isEventLocal!='undefined' && !isEventLocal)
  242. var intOffset=(previousOffset-actualOffset)*1000;
  243. else
  244. var intOffset=(actualOffset-previousOffset)*1000;
  245. eventsArray[collections[i].uid][j].start.setTime(eventsArray[collections[i].uid][j].start.getTime()+intOffset);
  246. if(eventsArray[collections[i].uid][j].end)
  247. eventsArray[collections[i].uid][j].end.setTime(eventsArray[collections[i].uid][j].end.getTime()+intOffset);
  248. var calEvent=eventsArray[collections[i].uid][j];
  249. if(j==0 || j>0 && eventsArray[collections[i].uid][j].id!=eventsArray[collections[i].uid][j-1].id)
  250. if(calEvent.alertTime.length>0)
  251. {
  252. for(var k=0; k<calEvent.alertTimeOut.length; k++)
  253. clearTimeout(calEvent.alertTimeOut[k]);
  254. var aTime='', now=new Date();
  255. for(var alarmIterator=0;alarmIterator<calEvent.alertTime.length;alarmIterator++)
  256. {
  257. if(eventsArray[collections[i].uid][j].start!=null && calEvent.alertTime[alarmIterator].charAt(0)=='-')
  258. aTime=eventsArray[collections[i].uid][j].start.getTime() - parseInt(calEvent.alertTime[alarmIterator].substring(1, calEvent.alertTime[alarmIterator].length-1));
  259. else if(eventsArray[collections[i].uid][j].end!=null && calEvent.alertTime[alarmIterator].charAt(0)=='+')
  260. aTime=eventsArray[collections[i].uid][j].end.getTime() + parseInt(calEvent.alertTime[alarmIterator].substring(1, calEvent.alertTime[alarmIterator].length-1));
  261. else
  262. {
  263. var previousOffset=getOffsetByTZ(previousTimezone, $.fullCalendar.parseDate(calEvent.alertTime[alarmIterator])).getSecondsFromOffset();
  264. var actualOffset='';
  265. if(typeof globalSessionTimeZone!='undefined' && globalSessionTimeZone!=null && globalSessionTimeZone!='')
  266. actualOffset=getOffsetByTZ(globalSessionTimeZone, $.fullCalendar.parseDate(calEvent.alertTime[alarmIterator])).getSecondsFromOffset();
  267. else
  268. actualOffset=$.fullCalendar.parseDate(calEvent.alertTime[alarmIterator]).getTimezoneOffset()*60*-1;
  269. if(typeof isEventLocal!='undefined')
  270. actualOffset=getOffsetByTZ(eventsArray[collections[i].uid][j].timeZone, $.fullCalendar.parseDate(calEvent.alertTime[alarmIterator])).getSecondsFromOffset();
  271. if(typeof isEventLocal!='undefined' && !isEventLocal)
  272. var intOffset=(previousOffset-actualOffset)*1000;
  273. else
  274. var intOffset=(actualOffset-previousOffset)*1000;
  275. aTime=new Date($.fullCalendar.parseDate(calEvent.alertTime[alarmIterator]).getTime()+intOffset);
  276. eventsArray[collections[i].uid][j].alertTime[alarmIterator]=$.fullCalendar.formatDate(aTime, "yyyy-MM-dd HH:mm:ss");
  277. }
  278. if(aTime>now)
  279. {
  280. var delay=aTime-now;
  281. if(maxAlarmValue<delay)
  282. delay=maxAlarmValue;
  283. eventsArray[collections[i].uid][j].alertTimeOut[alarmIterator]=setTimeout(function(){
  284. showAlertEvents(calEvent.id, (aTime-now), {start:calEvent.start, allDay:calEvent.allDay, title:calEvent.title});
  285. }, delay);
  286. }
  287. }
  288. }
  289. }
  290. calendarCounter++;
  291. if(calendarCounter==calendarCount)
  292. {
  293. refetchCalendarEvents();
  294. eventsDone=true;
  295. if(todosDone)
  296. $('#MainLoader').hide();
  297. }
  298. },10,i);
  299. }
  300. for(var i=0;i<todoCollections.length;i++)
  301. if(todoCollections[i].uid!=undefined)
  302. {
  303. setTimeout(function(i){
  304. for(var j=0;j<todosArray[todoCollections[i].uid].length;j++)
  305. {
  306. if(todosArray[todoCollections[i].uid][j].start)
  307. {
  308. if(typeof todosArray[todoCollections[i].uid][j].start =='string')
  309. todosArray[todoCollections[i].uid][j].start = $.fullCalendar.parseDate(todosArray[todoCollections[i].uid][j].start);
  310. var dateStart = todosArray[todoCollections[i].uid][j].start;
  311. var previousOffset=getOffsetByTZ(previousTimezone, dateStart).getSecondsFromOffset();
  312. var actualOffset='';
  313. if(typeof globalSessionTimeZone!='undefined' && globalSessionTimeZone!=null && globalSessionTimeZone!='')
  314. actualOffset=getOffsetByTZ(globalSessionTimeZone, dateStart).getSecondsFromOffset();
  315. else
  316. actualOffset=dateStart.getTimezoneOffset()*60*-1;
  317. var intOffset=(actualOffset-previousOffset)*1000;
  318. todosArray[todoCollections[i].uid][j].start.setTime(todosArray[todoCollections[i].uid][j].start.getTime()+intOffset);
  319. }
  320. if(todosArray[todoCollections[i].uid][j].end)
  321. {
  322. if(typeof todosArray[todoCollections[i].uid][j].end =='string')
  323. todosArray[todoCollections[i].uid][j].end=$.fullCalendar.parseDate(todosArray[todoCollections[i].uid][j].end);
  324. var dateEnd = todosArray[todoCollections[i].uid][j].end;
  325. var previousOffset=getOffsetByTZ(previousTimezone, dateEnd).getSecondsFromOffset();
  326. var actualOffset='';
  327. if(typeof globalSessionTimeZone!='undefined' && globalSessionTimeZone!=null && globalSessionTimeZone!='')
  328. actualOffset=getOffsetByTZ(globalSessionTimeZone, dateEnd).getSecondsFromOffset();
  329. else
  330. actualOffset=dateEnd.getTimezoneOffset()*60*-1;
  331. if(typeof isEventLocal!='undefined')
  332. actualOffset=getOffsetByTZ(todosArray[todoCollections[i].uid][j].timeZone, dateStart).getSecondsFromOffset();
  333. if(typeof isEventLocal!='undefined' && !isEventLocal)
  334. var intOffset=(previousOffset-actualOffset)*1000;
  335. else
  336. var intOffset=(actualOffset-previousOffset)*1000;
  337. todosArray[todoCollections[i].uid][j].end.setTime(todosArray[todoCollections[i].uid][j].end.getTime()+intOffset);
  338. }
  339. var todoEvent=todosArray[todoCollections[i].uid][j];
  340. if(j==0 || j>0 && todosArray[todoCollections[i].uid][j].id!=todosArray[todoCollections[i].uid][j-1].id)
  341. if(todoEvent.alertTime.length>0)
  342. {
  343. if(todoEvent.end)
  344. var showDate= new Date(todoEvent.end.getTime());
  345. else if(todoEvent.start)
  346. var showDate= new Date(todoEvent.start.getTime());
  347. else
  348. var showDate=new Date();
  349. for(var k=0; k<todoEvent.alertTimeOut.length; k++)
  350. clearTimeout(todoEvent.alertTimeOut[k]);
  351. var aTime='', now='';
  352. for(var alarmIterator=0;alarmIterator<todoEvent.alertTime.length;alarmIterator++)
  353. {
  354. if(todoEvent.alertTime[alarmIterator].charAt(0)=='-' || todoEvent.alertTime[alarmIterator].charAt(0)=='+')
  355. {
  356. aTime=showDate.getTime();
  357. var dur=parseInt(todoEvent.alertTime[alarmIterator].substring(1, todoEvent.alertTime[alarmIterator].length-1));
  358. if(todoEvent.alertTime[alarmIterator].charAt(0)=='-')
  359. aTime=aTime-dur;
  360. else
  361. aTime=aTime+dur;
  362. now=new Date();
  363. }
  364. else
  365. {
  366. var previousOffset=getOffsetByTZ(previousTimezone, $.fullCalendar.parseDate(todoEvent.alertTime[alarmIterator])).getSecondsFromOffset();
  367. var actualOffset='';
  368. if(typeof globalSessionTimeZone!='undefined' && globalSessionTimeZone!=null && globalSessionTimeZone!='')
  369. actualOffset=getOffsetByTZ(globalSessionTimeZone, $.fullCalendar.parseDate(todoEvent.alertTime[alarmIterator])).getSecondsFromOffset();
  370. else
  371. actualOffset=$.fullCalendar.parseDate(todoEvent.alertTime[alarmIterator]).getTimezoneOffset()*60*-1;
  372. if(typeof isEventLocal!='undefined')
  373. actualOffset=getOffsetByTZ(todosArray[todoCollections[i].uid][j].timeZone, $.fullCalendar.parseDate(todoEvent.alertTime[alarmIterator])).getSecondsFromOffset();
  374. if(typeof isEventLocal!='undefined' && !isEventLocal)
  375. var intOffset=(previousOffset-actualOffset)*1000;
  376. else
  377. var intOffset=(actualOffset-previousOffset)*1000;
  378. aTime=new Date($.fullCalendar.parseDate(todoEvent.alertTime[alarmIterator]).getTime()+intOffset);
  379. todosArray[todoCollections[i].uid][j].alertTime[alarmIterator]=$.fullCalendar.formatDate(aTime, "yyyy-MM-dd HH:mm:ss");
  380. now=new Date();
  381. }
  382. if(aTime>now)
  383. {
  384. var delay=aTime-now;
  385. if(maxAlarmValue<delay)
  386. delay=maxAlarmValue;
  387. todosArray[todoCollections[i].uid][j].alertTimeOut[alarmIterator]=setTimeout(function(){
  388. showAlertEvents(todoEvent.id, (aTime-now), {start:showDate, allDay:todoEvent.allDay, title:todoEvent.title});
  389. }, delay);
  390. }
  391. }
  392. }
  393. }
  394. todoCounter++;
  395. if(todoCounter==todoCount)
  396. {
  397. refetchTodoEvents();
  398. todosDone=true;
  399. if(eventsDone)
  400. $('#MainLoader').hide();
  401. }
  402. },10,i);
  403. }
  404. }
  405. function getLocalOffset(date)
  406. {
  407. if(typeof globalSessionTimeZone!='undefined' && globalSessionTimeZone!=null && globalSessionTimeZone!='')
  408. return getOffsetByTZ(globalSessionTimeZone, date).getSecondsFromOffset()*-1;
  409. else
  410. date.getTimezoneOffset()*60;
  411. }
  412. function changeRuleForFuture(inputEvent, repeatCount)
  413. {
  414. var vcalendar=inputEvent.vcalendar;
  415. var vcalendar_element=vcalendar.match(vCalendar.pre['contentline_RRULE2']);
  416. if(vcalendar_element!=null)
  417. {
  418. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  419. var ruleParts=parsed[4].split(';');
  420. var foundUntil=false;
  421. var parsedLine=parsed[0];
  422. for(var i=0; i<ruleParts.length;i++)
  423. {
  424. if(ruleParts[i].indexOf('UNTIL')!=-1 || ruleParts[i].indexOf('COUNT')!=-1)
  425. {
  426. parsedLine=parsedLine.replace(ruleParts[i],'COUNT='+(repeatCount-1));
  427. foundUntil=true;
  428. }
  429. }
  430. if(!foundUntil)
  431. {
  432. var tmp=parsed[4]+';COUNT='+(repeatCount-1);
  433. parsedLine=parsedLine.replace(parsed[4], tmp);
  434. }
  435. vcalendar=vcalendar.replace(parsed[0], parsedLine);
  436. }
  437. return vcalendar;
  438. }
  439. function buildTimezoneComponent(tzName)
  440. {
  441. var component='';
  442. var dayNames=['SU','MO', 'TU', 'WE', 'TH', 'FR', 'SA'];
  443. if(!tzName || tzName=='local' || tzName=='UTC')
  444. return component;
  445. if(tzName in timezones)
  446. {
  447. component+='BEGIN:VTIMEZONE\r\nTZID:'+tzName+'\r\n';
  448. for(comp in timezones[tzName])
  449. {
  450. if(comp=='daylightComponents')
  451. {
  452. var daylightC=timezones[tzName].daylightComponents;
  453. var compName='DAYLIGHT';
  454. }
  455. else if(comp=='standardComponents')
  456. {
  457. var daylightC=timezones[tzName].standardComponents;
  458. var compName='STANDARD';
  459. }
  460. for(var i in daylightC)
  461. {
  462. if(isNaN(i))
  463. continue;
  464. component+='BEGIN:'+compName+'\r\n';
  465. for(key in daylightC[i])
  466. {
  467. switch(key)
  468. {
  469. case 'dtStart':
  470. component+='DTSTART:'+daylightC[i][key]+'\r\n';
  471. break;
  472. case 'tzName':
  473. component+='TZNAME:'+daylightC[i][key]+'\r\n';
  474. break;
  475. case 'tzOffsetFROM':
  476. component+='TZOFFSETFROM:'+daylightC[i][key]+'\r\n';
  477. break;
  478. case 'tzOffsetTO':
  479. component+='TZOFFSETTO:'+daylightC[i][key]+'\r\n';
  480. break;
  481. case 'startMonth':
  482. component+='RRULE:FREQ=YEARLY';
  483. if(daylightC[i]['startMonth'])
  484. component+=';BYMONTH='+daylightC[i]['startMonth'];
  485. if(typeof daylightC[i]['startDay']!='undefined' && typeof dayNames[daylightC[i]['startDay']]!='undefined')
  486. {
  487. if(!daylightC[i]['startCount'])
  488. component+=';BYDAY='+dayNames[daylightC[i]['startDay']];
  489. else
  490. component+=';BYDAY='+daylightC[i]['startCount']+dayNames[daylightC[i]['startDay']];
  491. }
  492. component+='\r\n';
  493. break;
  494. case 'rDates':
  495. if(daylightC[i]['rDates'])
  496. for(var j=0;j<daylightC[i]['rDates'].length;j++)
  497. component+='RDATE:'+daylightC[i]['rDates'][j]+'\r\n';
  498. break;
  499. default:
  500. break;
  501. }
  502. }
  503. component+='END:'+compName+'\r\n';
  504. }
  505. }
  506. component+='END:VTIMEZONE\r\n';
  507. }
  508. return component;
  509. }
  510. function getOffsetByTZ(tZone, date,uid)
  511. {
  512. var offset='+0000';
  513. if(tZone in timezones && tZone!='UTC')
  514. {
  515. var objDayLight='', objStandard='';
  516. var checkRule=true;
  517. var daylightComponents=timezones[tZone].daylightComponents;
  518. var actualDaylightComponent;
  519. if(daylightComponents)
  520. {
  521. for(var i=0;i<daylightComponents.length;i++)
  522. {
  523. if(daylightComponents[i].dtStart.parseComnpactISO8601()>date)
  524. continue;
  525. if(checkRule && daylightComponents[i].startMonth) // is RRULE SET
  526. {
  527. objDayLight=daylightComponents[i];
  528. actualDaylightComponent=getDateFromDay(objDayLight, date,false,uid);
  529. break;
  530. }
  531. else
  532. {
  533. for(var j=0;j<daylightComponents[i].rDates.length; j++)
  534. {
  535. if(daylightComponents[i].rDates[j].parseComnpactISO8601()<date && (actualDaylightComponent==null || (date-daylightComponents[i].rDates[j].parseComnpactISO8601())<(date-actualDaylightComponent.startDate)))
  536. {
  537. objDayLight=daylightComponents[i];
  538. actualDaylightComponent={offsetFrom:objDayLight.tzOffsetFROM, offsetTo: objDayLight.tzOffsetTO,startDate: daylightComponents[i].rDates[j].parseComnpactISO8601()};
  539. }
  540. }
  541. }
  542. checkRule=false;
  543. }
  544. }
  545. var standardComponents=timezones[tZone].standardComponents;
  546. var actualStandardComponent;
  547. checkRule=true;
  548. if(standardComponents)
  549. {
  550. for(var i=0;i<standardComponents.length;i++)
  551. {
  552. if(standardComponents[i].dtStart.parseComnpactISO8601()>date)
  553. continue;
  554. if(checkRule && standardComponents[i].startMonth) // is RRULE SET
  555. {
  556. objDayLight=standardComponents[i];
  557. actualStandardComponent=getDateFromDay(objDayLight, date);
  558. break;
  559. }
  560. else
  561. {
  562. for(var j=0;j<standardComponents[i].rDates.length; j++)
  563. {
  564. if(standardComponents[i].rDates[j].parseComnpactISO8601()<date && (actualStandardComponent==null || (date-standardComponents[i].rDates[j].parseComnpactISO8601())<(date-actualStandardComponent.startDate)))
  565. {
  566. objStandard=standardComponents[i];
  567. actualStandardComponent={offsetFrom:objStandard.tzOffsetFROM, offsetTo: objStandard.tzOffsetTO,startDate: standardComponents[i].rDates[j].parseComnpactISO8601()};
  568. }
  569. }
  570. }
  571. checkRule=false;
  572. }
  573. }
  574. if(actualDaylightComponent && actualStandardComponent)
  575. {
  576. if(actualDaylightComponent.startDate>actualStandardComponent.startDate)
  577. offset=actualDaylightComponent.offsetTo;
  578. else
  579. offset=actualStandardComponent.offsetTo;
  580. }
  581. else if(actualDaylightComponent)
  582. offset=actualDaylightComponent.offsetTo;
  583. else if(actualStandardComponent)
  584. offset=actualStandardComponent.offsetTo;
  585. }
  586. else if(tZone == 'local')
  587. offset = getStringLocalOffset(date);
  588. return offset;
  589. }
  590. function getStringLocalOffset(date)
  591. {
  592. var offset = '+0000';
  593. var localOffset = date.getTimezoneOffset();
  594. if(localOffset>0)
  595. {
  596. var hours = Math.floor(localOffset/60);
  597. var minutes = localOffset - hours*60;
  598. offset = '-' + (hours<10 ? '0'+hours : hours);
  599. offset += (minutes<10 ? '0'+minutes : minutes);
  600. }
  601. else if(localOffset<0)
  602. {
  603. localOffset = localOffset*-1;
  604. var hours = Math.floor(localOffset/60);
  605. var minutes = localOffset - hours*60;
  606. offset = '+' + (hours<10 ? '0'+hours : hours);
  607. offset += (minutes<10 ? '0'+minutes : minutes);
  608. }
  609. return offset;
  610. }
  611. function getDayLightObject(tzObject,t)
  612. {
  613. var dayLightStartDate, dayLightEndDate, myDate=t;
  614. dayLightStartDate=getDateFromDay(tzObject, t);
  615. dayLightEndDate=getDateFromDay(tzObject, t);
  616. for(var i=0;i<tzObject.rDatesDT.length;i++)
  617. {
  618. var dateDT=tzObject.rDatesDT[i].parseComnpactISO8601();
  619. if(dateDT)
  620. if(dateDT.getFullYear()==t.getFullYear())
  621. {
  622. dayLightStartDate=dateDT;
  623. break;
  624. }
  625. }
  626. for(var i=0;i<tzObject.rDatesST.length;i++)
  627. {
  628. var dateST=tzObject.rDatesST[i].parseComnpactISO8601();
  629. if(dateST && dateST.getFullYear()==t.getFullYear())
  630. {
  631. dayLightEndDate=dateST;
  632. break;
  633. }
  634. }
  635. if(dayLightStartDate>dayLightEndDate)
  636. {
  637. if(myDate>dayLightStartDate)
  638. dayLightEndDate.setFullYear(dayLightEndDate.getFullYear()+1);
  639. else
  640. dayLightStartDate.setFullYear(dayLightStartDate.getFullYear()-1);
  641. }
  642. return {dayLightStartDate : dayLightStartDate, dayLightEndDate: dayLightEndDate};
  643. }
  644. function deleteEventFromArray(uid)
  645. {
  646. var rid=uid.substring(0, uid.lastIndexOf('/')+1);
  647. var count=0;
  648. if(globalEventList.displayEventsArray[rid]!=null && typeof globalEventList.displayEventsArray[rid] != 'undefined')
  649. for(var i=globalEventList.displayEventsArray[rid].length-1;i>=0;i--)
  650. if(globalEventList.displayEventsArray[rid][i].id==uid)
  651. {
  652. count++;
  653. for(var o=0;o<globalEventList.displayEventsArray[rid][i].alertTimeOut.length;o++)
  654. clearTimeout(globalEventList.displayEventsArray[rid][i].alertTimeOut[o]);
  655. globalEventList.displayEventsArray[rid].splice(i, 1);
  656. }
  657. if(count==0)
  658. if(globalEventList.displayTodosArray[rid]!=null && typeof globalEventList.displayTodosArray[rid] != 'undefined')
  659. for(var i=globalEventList.displayTodosArray[rid].length-1;i>=0;i--)
  660. if(globalEventList.displayTodosArray[rid][i].id==uid)
  661. {
  662. for(var o=0;o<globalEventList.displayTodosArray[rid][i].alertTimeOut.length;o++)
  663. clearTimeout(globalEventList.displayTodosArray[rid][i].alertTimeOut[o]);
  664. globalEventList.displayTodosArray[rid].splice(i, 1);
  665. }
  666. }
  667. function findEventInArray(uid, isEvent,repeatHash)
  668. {
  669. var rid=uid.substring(0, uid.lastIndexOf('/')+1);
  670. var firstItem=null;
  671. if(isEvent)
  672. {
  673. for(var i=0; i<globalEventList.displayEventsArray[rid].length;i++)
  674. if(globalEventList.displayEventsArray[rid][i].id==uid)
  675. return globalEventList.displayEventsArray[rid][i];
  676. }
  677. else
  678. {
  679. for(var i=0; i<globalEventList.displayTodosArray[rid].length;i++)
  680. if(globalEventList.displayTodosArray[rid][i].id==uid)
  681. {
  682. if(typeof repeatHash=='undefined' || repeatHash==null)
  683. return globalEventList.displayTodosArray[rid][i];
  684. else if(globalEventList.displayTodosArray[rid][i].repeatHash==repeatHash)
  685. return globalEventList.displayTodosArray[rid][i];
  686. else if(firstItem==null)
  687. firstItem=globalEventList.displayTodosArray[rid][i];
  688. }
  689. }
  690. return firstItem || '';
  691. }
  692. function getvCalendarstart(inputEvent)
  693. {
  694. var vcalendar_element='',
  695. itsOK=false;
  696. var vEvent=inputEvent.vcalendar;
  697. if(vEvent.match(vCalendar.pre['vcalendar']))
  698. {
  699. vcalendar_element=vEvent.match(vCalendar.pre['beginVTODO']);
  700. if(vcalendar_element!=null)
  701. {
  702. var endVT=vEvent.match(vCalendar.pre['endVTODO']);
  703. if(endVT!=null)
  704. return '1970-01-01T01:01:01Z';
  705. return false;
  706. }
  707. vcalendar_element=vEvent.match(vCalendar.pre['beginVEVENT']);
  708. if(vcalendar_element==null)
  709. itsOK=false;
  710. else
  711. itsOK=true;
  712. if(!itsOK)
  713. return false;
  714. vcalendar_element=vEvent.match(vCalendar.pre['endVEVENT']);
  715. if(vcalendar_element==null)
  716. itsOK=false;
  717. else
  718. itsOK=true;
  719. if(!itsOK)
  720. return false;
  721. var oo='',
  722. start='',
  723. help1;
  724. /*
  725. vcalendar_element=vEvent.match(vCalendar.pre['tzone']);
  726. if(vcalendar_element!=null)
  727. vEvent=vEvent.replace(vcalendar_element[0],'');
  728. */
  729. //FIX
  730. // var beginTimeZone=vEvent.indexOf('BEGIN:VTIMEZONE');
  731. // var startEndTimeZone=vEvent.lastIndexOf('END:VTIMEZONE');
  732. // var endTimeZone=0;
  733. // if(beginTimeZone!=-1 && startEndTimeZone!=-1)
  734. // {
  735. // for(i=(startEndTimeZone+2);i<vEvent.length;i++)
  736. // {
  737. // if(vEvent.charAt(i)=='\n')
  738. // {
  739. // endTimeZone=i+1;
  740. // break;
  741. // }
  742. // }
  743. // vTimeZone=vEvent.substring(beginTimeZone, endTimeZone);
  744. // vEvent=vEvent.substring(0, beginTimeZone)+vEvent.substring(endTimeZone, vEvent.length);
  745. // }
  746. vEvent = vEvent.replace(/BEGIN:VTIMEZONE((\s|.)*?)END:VTIMEZONE\r\n/g, '');
  747. vcalendar_element=vEvent.match(vCalendar.pre['contentline_DTSTART']);
  748. if(vcalendar_element!=null)
  749. {
  750. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  751. start=parsed[4];
  752. help1=start;
  753. if(help1.indexOf("T")==-1)
  754. help1=help1.substring(0, 4)+'-'+help1.substring(4, 6)+'-'+help1.substring(6, 8)+'T00:00:00Z';
  755. else
  756. help1=help1.substring(0, 4)+'-'+help1.substring(4, 6)+'-'+help1.substring(6, 8)+'T'+help1.substring(9, 11)+':'+help1.substring(11, 13)+':'+help1.substring(13, 15)+'Z';
  757. start=help1;
  758. }
  759. if(start!='')
  760. {
  761. var t=$.fullCalendar.parseDate(help1);
  762. if((t.toString())=='Invalid Date')
  763. return false;
  764. }
  765. return help1;
  766. }
  767. else
  768. return -1;
  769. }
  770. function giveMeUntilDate(start, count, frequency, interval, allDay)
  771. {
  772. var varDate=$.fullCalendar.parseDate(start);
  773. var monthPlus=0,
  774. dayPlus=0;
  775. if(frequency=="DAILY")
  776. {
  777. monthPlus=0,
  778. dayPlus=1;
  779. }
  780. else if(frequency=="WEEKLY")
  781. {
  782. monthPlus=0,
  783. dayPlus=7;
  784. }
  785. else if(frequency=="MONTHLY")
  786. {
  787. monthPlus=1,
  788. dayPlus=0;
  789. }
  790. else if(frequency=="YEARLY")
  791. {
  792. monthPlus=12,
  793. dayPlus=0;
  794. }
  795. var iterator=1, counter=1;
  796. while(iterator<count)
  797. {
  798. if(counter%interval==0)
  799. iterator++;
  800. if(allDay)
  801. var td=new Date(varDate.getFullYear(), varDate.getMonth()+monthPlus, varDate.getDate()+dayPlus);
  802. else
  803. var td=new Date(varDate.getFullYear(), varDate.getMonth()+monthPlus, varDate.getDate()+dayPlus, varDate.getHours(), varDate.getMinutes(), varDate.getSeconds());
  804. varDate=td;
  805. counter++;
  806. }
  807. return varDate;
  808. }
  809. function checkAndFixMultipleUID(vcalendar, isEvent)
  810. {
  811. var vcalendarOrig = vcalendar;
  812. var uidArray={};
  813. var uidC=0;
  814. var eventStringArray=new Array();
  815. var componentS = 'VEVENT';
  816. if(!isEvent)
  817. componentS='VTODO';
  818. var checkVcalendar = vcalendarOrig;
  819. var valarm=checkVcalendar.match(vCalendar.pre['valarm']);
  820. if(valarm!=null)
  821. checkVcalendar=checkVcalendar.replace(valarm[0], '');
  822. while(checkVcalendar.match(vCalendar.pre['contentline_UID'])!= null)
  823. {
  824. vcalendar_element=checkVcalendar.match(vCalendar.pre['contentline_UID']);
  825. if(vcalendar_element[0]!=null)
  826. {
  827. if(typeof uidArray[vcalendar_element[0]]=='undefined')
  828. {
  829. uidArray[vcalendar_element[0]]={isTimezone:false, string:''};
  830. uidC++;
  831. }
  832. }
  833. checkVcalendar=checkVcalendar.replace(vcalendar_element[0], '\r\n');
  834. }
  835. if(uidC==1)
  836. return [vcalendar];
  837. var beginTimeZone=vcalendarOrig.indexOf('BEGIN:VTIMEZONE');
  838. var startEndTimeZone=vcalendarOrig.lastIndexOf('END:VTIMEZONE');
  839. var endTimeZone=0;
  840. var vTimeZone='';
  841. if(beginTimeZone!=-1 && startEndTimeZone!=-1)
  842. {
  843. for(i=(startEndTimeZone+2);i<vcalendarOrig.length;i++)
  844. {
  845. if(vcalendarOrig.charAt(i)=='\n')
  846. {
  847. endTimeZone=i+1;
  848. break;
  849. }
  850. }
  851. vTimeZone=vcalendarOrig.substring(beginTimeZone, endTimeZone);
  852. vcalendarOrig=vcalendarOrig.substring(0, beginTimeZone)+vcalendarOrig.substring(endTimeZone, vcalendarOrig.length);
  853. }
  854. while(vcalendarOrig.match(vCalendar.pre[componentS.toLowerCase()])!=null)
  855. {
  856. if(vcalendarOrig.substring(vcalendarOrig.indexOf('BEGIN:'+componentS)-2, vcalendarOrig.indexOf('BEGIN:'+componentS))=='\r\n')
  857. {
  858. var partEvent=vcalendarOrig.substring(vcalendarOrig.indexOf('BEGIN:'+componentS)-2,vcalendarOrig.indexOf('END:'+componentS)+('END:'+componentS).length);
  859. vcalendarOrig=vcalendarOrig.replace(partEvent, '');
  860. }
  861. else
  862. {
  863. var partEvent=vcalendarOrig.substring(vcalendarOrig.indexOf('BEGIN:'+componentS),vcalendarOrig.indexOf('END:'+componentS)+('END:'+componentS).length);
  864. vcalendarOrig=vcalendarOrig.replace(partEvent, '');
  865. partEvent+='\r\n';
  866. }
  867. var tmpEvent = partEvent;
  868. var valarm=tmpEvent.match(vCalendar.pre['valarm']);
  869. if(valarm!=null)
  870. tmpEvent=tmpEvent.replace(valarm[0], '');
  871. vcalendar_element=tmpEvent.match(vCalendar.pre['contentline_UID']);
  872. if(vcalendar_element[0]!=null)
  873. {
  874. var vcalendar_element_start=tmpEvent.match(vCalendar.pre['contentline_DTSTART']);
  875. if(vcalendar_element_start!=null)
  876. {
  877. var parsed=vcalendar_element_start[0].match(vCalendar.pre['contentline_parse']);
  878. var pars=vcalendarSplitParam(parsed[3]);
  879. if(pars.indexElementOf('TZID=')!=-1)
  880. uidArray[vcalendar_element[0]].isTimezone=true;
  881. }
  882. if(!isEvent && !uidArray[vcalendar_element[0]].isTimezone)
  883. {
  884. var vcalendar_element_start=tmpEvent.match(vCalendar.pre['contentline_DUE']);
  885. if(vcalendar_element_start!=null)
  886. {
  887. var parsed=vcalendar_element_start[0].match(vCalendar.pre['contentline_parse']);
  888. var pars=vcalendarSplitParam(parsed[3]);
  889. if(pars.indexElementOf('TZID=')!=-1)
  890. uidArray[vcalendar_element[0]].isTimezone=true;
  891. }
  892. }
  893. uidArray[vcalendar_element[0]].string+=partEvent;
  894. }
  895. }
  896. for(var uid in uidArray)
  897. {
  898. var vcalendarS = '';
  899. // vEvent BEGIN (required by RFC)
  900. if(vCalendar.tplM['begin']!=null && (process_elem=vCalendar.tplM['begin'][0])!=undefined)
  901. vcalendarS+=vCalendar.tplM['begin'][0];
  902. else
  903. {
  904. process_elem=vCalendar.tplC['begin'];
  905. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  906. vcalendarS+=process_elem;
  907. }
  908. // VERSION (required by RFC)
  909. if(vCalendar.tplM['contentline_VERSION']!=null && (process_elem=vCalendar.tplM['contentline_VERSION'][0])!=undefined)
  910. {
  911. // replace the object and related objects' group names (+ append the related objects after the processed)
  912. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  913. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  914. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  915. }
  916. else
  917. {
  918. process_elem=vCalendar.tplC['contentline_VERSION'];
  919. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  920. }
  921. process_elem=process_elem.replace('##:::##version##:::##', '2.0');
  922. vcalendarS+=process_elem;
  923. // CALSCALE
  924. if(vCalendar.tplM['contentline_CALSCALE']!=null && (process_elem=vCalendar.tplM['contentline_CALSCALE'][0])!=undefined)
  925. {
  926. // replace the object and related objects' group names (+ append the related objects after the processed)
  927. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  928. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  929. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  930. }
  931. else
  932. {
  933. process_elem=vCalendar.tplC['contentline_CALSCALE'];
  934. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  935. }
  936. process_elem=process_elem.replace('##:::##calscale##:::##', 'GREGORIAN');
  937. vcalendarS+=process_elem;
  938. if(uidArray[uid].isTimezone)
  939. vcalendarS+=vTimeZone;
  940. vcalendarS=vcalendarS.substring(0, vcalendarS.length-2);
  941. vcalendarS+=uidArray[uid].string;
  942. if(vcalendarS.lastIndexOf('\r\n')!=(vcalendarS.length-2))
  943. vcalendarS+='\r\n';
  944. // PRODID
  945. if(vCalendar.tplM['contentline_PRODID']!=null && (process_elem=vCalendar.tplM['contentline_PRODID'][0])!=undefined)
  946. {
  947. // replace the object and related objects' group names (+ append the related objects after the processed)
  948. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  949. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  950. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  951. }
  952. else
  953. {
  954. process_elem=vCalendar.tplC['contentline_PRODID'];
  955. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  956. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  957. }
  958. process_elem=process_elem.replace('##:::##value##:::##', '-//Inf-IT//'+globalAppName+' '+globalVersion+'//EN');
  959. vcalendarS+=process_elem;
  960. if(typeof vCalendar.tplM['unprocessed']!='undefined' && vCalendar.tplM['unprocessed']!='' && vCalendar.tplM['unprocessed']!=null)
  961. vcalendarS+=vCalendar.tplM['unprocessed'].replace(RegExp('^\r\n'), '');
  962. vCalendar.tplM['unprocessed']=new Array();
  963. // vCalendar END (required by RFC)
  964. if(vCalendar.tplM['end']!=null && (process_elem=vCalendar.tplM['end'][0])!=undefined)
  965. vcalendarS+=vCalendar.tplM['end'][0];
  966. else
  967. {
  968. process_elem=vCalendar.tplC['end'];
  969. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  970. vcalendarS+=process_elem;
  971. }
  972. eventStringArray.push(vcalendarS);
  973. }
  974. return eventStringArray;
  975. }
  976. function dataToVcalendar(operation, accountUID, inputUID, inputEtag, delUID,isFormHidden, deleteMode)
  977. {
  978. var vevent=false,
  979. vCalendarText='',
  980. groupCounter=0;
  981. var sel_option='local';
  982. // vEvent BEGIN (required by RFC)
  983. if(vCalendar.tplM['begin']!=null && (process_elem=vCalendar.tplM['begin'][0])!=undefined)
  984. vCalendarText+=vCalendar.tplM['begin'][0];
  985. else
  986. {
  987. process_elem=vCalendar.tplC['begin'];
  988. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  989. vCalendarText+=process_elem;
  990. }
  991. // VERSION (required by RFC)
  992. if(vCalendar.tplM['contentline_VERSION']!=null && (process_elem=vCalendar.tplM['contentline_VERSION'][0])!=undefined)
  993. {
  994. // replace the object and related objects' group names (+ append the related objects after the processed)
  995. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  996. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  997. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  998. }
  999. else
  1000. {
  1001. process_elem=vCalendar.tplC['contentline_VERSION'];
  1002. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1003. }
  1004. process_elem=process_elem.replace('##:::##version##:::##', '2.0');
  1005. vCalendarText+=process_elem;
  1006. // CALSCALE
  1007. if(vCalendar.tplM['contentline_CALSCALE']!=null && (process_elem=vCalendar.tplM['contentline_CALSCALE'][0])!=undefined)
  1008. {
  1009. // replace the object and related objects' group names (+ append the related objects after the processed)
  1010. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1011. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1012. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1013. }
  1014. else
  1015. {
  1016. process_elem=vCalendar.tplC['contentline_CALSCALE'];
  1017. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1018. }
  1019. process_elem=process_elem.replace('##:::##calscale##:::##', 'GREGORIAN');
  1020. vCalendarText+=process_elem;
  1021. if(delUID!='')
  1022. var rid=delUID.substring(0, delUID.lastIndexOf('/')+1);
  1023. else
  1024. var rid=inputUID.substring(0, inputUID.lastIndexOf('/')+1);
  1025. var inputEvents=jQuery.grep(globalEventList.displayEventsArray[rid],function(e){if(e.id==$('#uid').val() && (e.repeatCount<2 || !e.repeatCount))return true});
  1026. var tzArray=new Array();
  1027. var tzString='';
  1028. var isTimeZone=false;
  1029. var origVcalendarString='';
  1030. var eventStringArray=new Array();
  1031. if(inputEvents.length>0)
  1032. {
  1033. var rid=$('#uid').val().substring(0, $('#uid').val().lastIndexOf('/')+1);
  1034. if(rid)
  1035. if(globalEventList.events[rid][$('#uid').val()].uid!=undefined)
  1036. origVcalendarString=globalEventList.events[rid][$('#uid').val()].vcalendar;
  1037. while(origVcalendarString.match(vCalendar.pre['vevent'])!=null)
  1038. {
  1039. if(origVcalendarString.substring(origVcalendarString.indexOf('BEGIN:VEVENT')-2, origVcalendarString.indexOf('BEGIN:VEVENT'))=='\r\n')
  1040. {
  1041. var partEvent=origVcalendarString.substring(origVcalendarString.indexOf('BEGIN:VEVENT')-2,origVcalendarString.indexOf('END:VEVENT')+'END:VEVENT'.length);
  1042. origVcalendarString=origVcalendarString.replace(partEvent, '');
  1043. }
  1044. else
  1045. {
  1046. var partEvent=origVcalendarString.substring(origVcalendarString.indexOf('BEGIN:VEVENT'),origVcalendarString.indexOf('END:VEVENT')+'END:VEVENT'.length);
  1047. origVcalendarString=origVcalendarString.replace(partEvent, '');
  1048. partEvent+='\r\n';
  1049. }
  1050. eventStringArray[eventStringArray.length]=partEvent;
  1051. }
  1052. }
  1053. var origTimezone = '';
  1054. for(var iE=0;iE<inputEvents.length;iE++)
  1055. {
  1056. if(tzArray.indexOf(inputEvents[iE].timeZone)==-1)
  1057. {
  1058. if(inputEvents[iE].allDay ||(deleteMode && ($('#vcalendarHash').val()==hex_sha256(inputEvents[iE].vcalendar))))
  1059. continue;
  1060. var component=buildTimezoneComponent(inputEvents[iE].timeZone);
  1061. if(component!='' && ($('#vcalendarHash').val()!=hex_sha256(inputEvents[iE].vcalendar)))
  1062. {
  1063. tzArray[tzArray.length]=inputEvents[iE].timeZone;
  1064. tzString+=component;
  1065. if(tzString.lastIndexOf('\r\n')!=(tzString.length-2))
  1066. tzString+='\r\n';
  1067. isTimeZone=true;
  1068. }
  1069. else if(component!='' && $('#vcalendarHash').val()==hex_sha256(inputEvents[iE].vcalendar))
  1070. origTimezone+=component;
  1071. }
  1072. }
  1073. if(isTimeZone)
  1074. {
  1075. if(vCalendarText.lastIndexOf('\r\n')!=(vCalendarText.length-2))
  1076. vCalendarText+='\r\n';
  1077. vCalendarText+=tzString;
  1078. }
  1079. var beginVcalendar = vCalendarText;
  1080. var realEvent='';
  1081. var futureMode = false;
  1082. for(var j=0;j<inputEvents.length;j++)
  1083. {
  1084. eventStringArray.splice(eventStringArray.indexOf(inputEvents[j].vcalendar),1);
  1085. if(($('#futureStart').val()== '' && $('#vcalendarHash').val()!=hex_sha256(inputEvents[j].vcalendar)) || inputEvents[j].rec_id!=$('#recurrenceID').val())
  1086. {
  1087. var stringUIDcurrent=inputEvents[j].vcalendar.match(vCalendar.pre['contentline_UID']);
  1088. if(stringUIDcurrent!=null)
  1089. stringUIDcurrent=stringUIDcurrent[0].match(vCalendar.pre['contentline_parse'])[4];
  1090. if((deleteMode && $('#vcalendarHash').val()==hex_sha256(inputEvents[j].vcalendar)) || (deleteMode && !inputEvents[j].rec_id && $('#vcalendarUID').val()==stringUIDcurrent))
  1091. {
  1092. var ruleString=inputEvents[j].vcalendar.match(vCalendar.pre['contentline_RRULE2']);
  1093. var origRuleString=ruleString;
  1094. var exDate=inputEvents[j].start;
  1095. var process_elem=vCalendar.tplC['contentline_EXDATE'];
  1096. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1097. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1098. if(inputEvents[j].allDay)
  1099. {
  1100. exDate=$('#recurrenceID').val();
  1101. process_elem=process_elem.replace('##:::##AllDay##:::##', ';'+vcalendarEscapeValue('VALUE=DATE'));
  1102. process_elem=process_elem.replace('##:::##TZID##:::##', vcalendarEscapeValue(''));
  1103. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(exDate));
  1104. }
  1105. else
  1106. {
  1107. exDate=$('#recurrenceID').val().parseComnpactISO8601();
  1108. if(!$('#allday').prop('checked'))
  1109. if(globalSettings.timezonesupport.value)
  1110. sel_option=$('#timezone').val();
  1111. if(sel_option!='local')
  1112. {
  1113. var valOffsetFrom=getOffsetByTZ(sel_option, exDate);
  1114. var intOffset = valOffsetFrom.getSecondsFromOffset()*-1;
  1115. exDate = new Date(exDate.setSeconds(intOffset));
  1116. }
  1117. else
  1118. exDate=new Date(exDate.setSeconds(getLocalOffset(exDate)));
  1119. exDate=$.fullCalendar.formatDate(exDate, "yyyyMMdd'T'HHmmss'Z'");
  1120. process_elem=process_elem.replace('##:::##AllDay##:::##', vcalendarEscapeValue(''));
  1121. process_elem=process_elem.replace('##:::##TZID##:::##','');
  1122. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(exDate));
  1123. }
  1124. inputEvents[j].vcalendar=inputEvents[j].vcalendar.replace(ruleString,ruleString+process_elem);
  1125. }
  1126. if(inputEvents[j].vcalendar.indexOf('\r\n')==0 && vCalendarText.lastIndexOf('\r\n')==(vCalendarText.length-2))
  1127. vCalendarText+=inputEvents[j].vcalendar.substring(2,inputEvents[j].vcalendar.length);
  1128. else if((inputEvents[j].vcalendar.indexOf('\r\n')==0 && vCalendarText.lastIndexOf('\r\n')!=(vCalendarText.length-2)) || (inputEvents[j].vcalendar.indexOf('\r\n')!=0 && vCalendarText.lastIndexOf('\r\n')==(vCalendarText.length-2)) )
  1129. vCalendarText+=inputEvents[j].vcalendar;
  1130. else
  1131. vCalendarText+='\r\n'+inputEvents[j].vcalendar;
  1132. }
  1133. else if($('#futureStart').val().split(';')[0]!='' && $('#futureStart').val().split(';')[1]!=inputEvents[j].start)
  1134. {
  1135. if($('#futureStart').val().split(';')[0]>1 && $('#vcalendarHash').val()==hex_sha256(inputEvents[j].vcalendar))
  1136. inputEvents[j].vcalendar=changeRuleForFuture(inputEvents[j], $('#futureStart').val().split(';')[0]);
  1137. if(inputEvents[j].vcalendar.indexOf('\r\n')==0 && vCalendarText.lastIndexOf('\r\n')==(vCalendarText.length-2))
  1138. vCalendarText+=inputEvents[j].vcalendar.substring(2,inputEvents[j].vcalendar.length);
  1139. else if((inputEvents[j].vcalendar.indexOf('\r\n')==0 && vCalendarText.lastIndexOf('\r\n')!=(vCalendarText.length-2)) || (inputEvents[j].vcalendar.indexOf('\r\n')!=0 && vCalendarText.lastIndexOf('\r\n')==(vCalendarText.length-2)) )
  1140. vCalendarText+=inputEvents[j].vcalendar;
  1141. else
  1142. vCalendarText+='\r\n'+inputEvents[j].vcalendar;
  1143. futureMode=true;
  1144. }
  1145. else if(deleteMode && $('#futureStart').val().split(';')[0]!='' && $('#futureStart').val().split(';')[1]==inputEvents[j].start)
  1146. {
  1147. if($('#vcalendarHash').val()==hex_sha256(inputEvents[j].vcalendar))
  1148. {
  1149. inputEvents[j].vcalendar=changeRuleForFuture(inputEvents[j], 2);
  1150. }
  1151. if(inputEvents[j].vcalendar.indexOf('\r\n')==0 && vCalendarText.lastIndexOf('\r\n')==(vCalendarText.length-2))
  1152. vCalendarText+=inputEvents[j].vcalendar.substring(2,inputEvents[j].vcalendar.length);
  1153. else if((inputEvents[j].vcalendar.indexOf('\r\n')==0 && vCalendarText.lastIndexOf('\r\n')!=(vCalendarText.length-2)) || (inputEvents[j].vcalendar.indexOf('\r\n')!=0 && vCalendarText.lastIndexOf('\r\n')==(vCalendarText.length-2)) )
  1154. vCalendarText+=inputEvents[j].vcalendar;
  1155. else
  1156. vCalendarText+='\r\n'+inputEvents[j].vcalendar;
  1157. }
  1158. else
  1159. {
  1160. realEvent=inputEvents[j];
  1161. }
  1162. }
  1163. vCalendarText=vCalendarText.replace(realEvent.vcalendar,'');
  1164. for(var ip=0; ip<eventStringArray.length;ip++)
  1165. {
  1166. if(eventStringArray[ip].indexOf('\r\n')==0 && vCalendarText.lastIndexOf('\r\n')==(vCalendarText.length-2))
  1167. vCalendarText+=eventStringArray[ip].substring(2,eventStringArray[ip].length);
  1168. else if((eventStringArray[ip].indexOf('\r\n')==0 && vCalendarText.lastIndexOf('\r\n')!=(vCalendarText.length-2)) || (eventStringArray[ip].indexOf('\r\n')!=0 && vCalendarText.lastIndexOf('\r\n')==(vCalendarText.length-2)) )
  1169. vCalendarText+=eventStringArray[ip];
  1170. else
  1171. vCalendarText+='\r\n'+eventStringArray[ip];
  1172. }
  1173. var origEvent = '';
  1174. if(deleteMode || futureMode)
  1175. {
  1176. if(vCalendarText.lastIndexOf('\r\n')!=(vCalendarText.length-2))
  1177. vCalendarText+='\r\n';
  1178. if(!isTimeZone && futureMode && origTimezone!='')
  1179. {
  1180. vCalendarText+=origTimezone;
  1181. if(vCalendarText.lastIndexOf('\r\n')!=(vCalendarText.length-2))
  1182. vCalendarText+='\r\n';
  1183. }
  1184. // PRODID
  1185. if(vCalendar.tplM['contentline_PRODID']!=null && (process_elem=vCalendar.tplM['contentline_PRODID'][0])!=undefined)
  1186. {
  1187. // replace the object and related objects' group names (+ append the related objects after the processed)
  1188. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1189. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1190. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1191. }
  1192. else
  1193. {
  1194. process_elem=vCalendar.tplC['contentline_PRODID'];
  1195. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1196. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1197. }
  1198. process_elem=process_elem.replace('##:::##value##:::##', '-//Inf-IT//'+globalAppName+' '+globalVersion+'//EN');
  1199. vCalendarText+=process_elem;
  1200. if((typeof vCalendar.tplM['unprocessed']!='undefined') && (vCalendar.tplM['unprocessed']!='') && (vCalendar.tplM['unprocessed']!=null))
  1201. vCalendarText+=vCalendar.tplM['unprocessed'].replace(RegExp('^\r\n'), '');
  1202. vCalendar.tplM['unprocessed']=new Array();
  1203. // vCalendar END (required by RFC)
  1204. if(vCalendar.tplM['end']!=null && (process_elem=vCalendar.tplM['end'][0])!=undefined)
  1205. vCalendarText+=vCalendar.tplM['end'][0];
  1206. else
  1207. {
  1208. process_elem=vCalendar.tplC['end'];
  1209. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1210. vCalendarText+=process_elem;
  1211. }
  1212. if(deleteMode)
  1213. {
  1214. var fixedArr = checkAndFixMultipleUID(vCalendarText,true);
  1215. var inputS = fixedArr[0];
  1216. fixedArr.splice(0,1);
  1217. return putVcalendarToCollection(accountUID, inputUID, inputEtag, inputS, delUID,'vevent',isFormHidden,deleteMode,fixedArr);
  1218. }
  1219. else if(futureMode)
  1220. {
  1221. origEvent = vCalendarText;
  1222. vCalendarText = beginVcalendar;
  1223. }
  1224. }
  1225. var timeZoneAttr='';
  1226. if(typeof globalSessionTimeZone!='undefined' && globalSessionTimeZone)
  1227. sel_option=globalSessionTimeZone;
  1228. var isUTC=false;
  1229. if(!$('#allday').prop('checked'))
  1230. {
  1231. if(globalSettings.timezonesupport.value)
  1232. sel_option=$('#timezone').val();
  1233. //else
  1234. //{
  1235. // if(inputEvents.length>0)
  1236. // sel_option=inputEvents[0].timeZone;
  1237. //}
  1238. if(sel_option=='UTC')
  1239. {
  1240. isUTC=true;
  1241. timeZoneAttr='';
  1242. }
  1243. else if(sel_option=='local')
  1244. timeZoneAttr='';
  1245. else if(sel_option=='custom')
  1246. timeZoneAttr=';'+vcalendarEscapeValue('TZID='+realEvent.timeZone);
  1247. else
  1248. timeZoneAttr=';'+vcalendarEscapeValue('TZID='+sel_option);
  1249. var timezoneComponent='';
  1250. if(globalSettings.rewritetimezonecomponent.value || !vCalendar.tplM['unprocessedVTIMEZONE'])
  1251. {
  1252. if(tzArray.indexOf(sel_option)==-1)
  1253. timezoneComponent=buildTimezoneComponent(sel_option);
  1254. }
  1255. else
  1256. timezoneComponent=vCalendar.tplM['unprocessedVTIMEZONE'];
  1257. if(vCalendarText.lastIndexOf('\r\n')!=(vCalendarText.length-2))
  1258. vCalendarText+='\r\n';
  1259. vCalendarText+=timezoneComponent;
  1260. }
  1261. // ---------------------------------- EVENT ---------------------------------- //
  1262. if(vCalendar.tplM['beginVEVENT']!=null && (process_elem=vCalendar.tplM['beginVEVENT'][0])!=undefined)
  1263. {
  1264. if(vCalendarText.lastIndexOf('\r\n')==(vCalendarText.length-2))
  1265. vCalendarText+=vCalendar.tplM['beginVEVENT'][0];
  1266. else
  1267. vCalendarText+='\r\n'+vCalendar.tplM['beginVEVENT'][0];
  1268. vevent=true;
  1269. }
  1270. else
  1271. {
  1272. process_elem=vCalendar.tplC['beginVEVENT'];
  1273. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1274. if(vCalendarText.lastIndexOf('\r\n')==(vCalendarText.length-2))
  1275. vCalendarText+=process_elem;
  1276. else
  1277. vCalendarText+='\r\n'+process_elem;
  1278. vevent=true;
  1279. }
  1280. var d,
  1281. utc,
  1282. d=new Date();
  1283. utc=d.getUTCFullYear()+(d.getUTCMonth()+1<10 ? '0' : '')+(d.getUTCMonth()+1)+(d.getUTCDate()<10 ? '0' : '')+d.getUTCDate()+'T'+(d.getUTCHours()<10 ? '0' : '')+d.getUTCHours()+(d.getUTCMinutes()<10 ? '0' : '')+d.getUTCMinutes()+(d.getUTCSeconds()<10 ? '0' : '')+d.getUTCSeconds()+'Z';
  1284. var create=true;
  1285. if($('#recurrenceID').val()=='')
  1286. var checkVal='orig';
  1287. else
  1288. var checkVal=$('#recurrenceID').val();
  1289. var created='';
  1290. for(vev in vCalendar.tplM['contentline_CREATED'])
  1291. {
  1292. if(vev==checkVal)
  1293. created=vCalendar.tplM['contentline_CREATED'][vev];
  1294. }
  1295. if(created!='')
  1296. {
  1297. process_elem=created;
  1298. // replace the object and related objects' group names (+ append the related objects after the processed)
  1299. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1300. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1301. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1302. }
  1303. else
  1304. {
  1305. process_elem=vCalendar.tplC['contentline_CREATED'];
  1306. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1307. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1308. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(utc));
  1309. }
  1310. vCalendarText+=process_elem;
  1311. if(vCalendar.tplM['contentline_LM']!=null && (process_elem=vCalendar.tplM['contentline_LM'][0])!=undefined)
  1312. {
  1313. // replace the object and related objects' group names (+ append the related objects after the processed)
  1314. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1315. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1316. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1317. }
  1318. else
  1319. {
  1320. process_elem=vCalendar.tplC['contentline_LM'];
  1321. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1322. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1323. }
  1324. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(utc));
  1325. vCalendarText+=process_elem;
  1326. if(vCalendar.tplM['contentline_DTSTAMP']!=null && (process_elem=vCalendar.tplM['contentline_DTSTAMP'][0])!=undefined)
  1327. {
  1328. // replace the object and related objects' group names (+ append the related objects after the processed)
  1329. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1330. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1331. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1332. }
  1333. else
  1334. {
  1335. process_elem=vCalendar.tplC['contentline_DTSTAMP'];
  1336. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1337. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1338. }
  1339. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(utc));
  1340. vCalendarText+=process_elem;
  1341. // UID (required by RFC)
  1342. if($('#futureStart').val()=='' && (operation!='MOVE_IN'&& operation!='MOVE_OTHER') && (vCalendar.tplM['contentline_UID']!=null && (process_elem=vCalendar.tplM['contentline_UID'][0])!=undefined))
  1343. {
  1344. // replace the object and related objects' group names (+ append the related objects after the processed)
  1345. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1346. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1347. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1348. }
  1349. else
  1350. {
  1351. process_elem=vCalendar.tplC['contentline_UID'];
  1352. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1353. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1354. // it is VERY small probability, that for 2 newly created vevents/vtodos the same UID is generated (but not impossible :( ...)
  1355. var newUID=globalEventList.getNewUID();
  1356. process_elem=process_elem.replace('##:::##uid##:::##', newUID);
  1357. }
  1358. vCalendarText+=process_elem;
  1359. if(vCalendar.tplM['contentline_SUMMARY']!=null && (process_elem=vCalendar.tplM['contentline_SUMMARY'][0])!=undefined)
  1360. {
  1361. // replace the object and related objects' group names (+ append the related objects after the processed)
  1362. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1363. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1364. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1365. }
  1366. else
  1367. {
  1368. process_elem=vCalendar.tplC['contentline_SUMMARY'];
  1369. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1370. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1371. }
  1372. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue($('#name').val()));
  1373. //process_elem=process_elem.replace('##:::##value##:::##',vcalendarEscapeValue('zmena'));
  1374. vCalendarText+=process_elem;
  1375. if($('#priority').val()!='0')
  1376. {
  1377. if(vCalendar.tplM['contentline_PRIORITY']!=null && (process_elem=vCalendar.tplM['contentline_PRIORITY'][0])!=undefined)
  1378. {
  1379. // replace the object and related objects' group names (+ append the related objects after the processed)
  1380. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1381. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1382. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1383. }
  1384. else
  1385. {
  1386. process_elem=vCalendar.tplC['contentline_PRIORITY'];
  1387. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1388. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1389. }
  1390. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue($('#priority').val()));
  1391. vCalendarText+=process_elem;
  1392. }
  1393. if(vevent)
  1394. {
  1395. if($('#repeat').val()!='no-repeat')
  1396. {
  1397. var interval=$("#repeat_interval_detail").val();
  1398. var byDay='';
  1399. var monthDay='';
  1400. var bymonth='';
  1401. var wkst='';
  1402. var isCustom=false;
  1403. if(interval==1 || interval=='')
  1404. interval='';
  1405. else interval=";INTERVAL="+$("#repeat_interval_detail").val();
  1406. var frequency=$('#repeat').val();
  1407. if(frequency=='TWO_WEEKLY')
  1408. {
  1409. frequency='WEEKLY';
  1410. interval=";INTERVAL="+2;
  1411. }
  1412. else if(frequency=='BUSINESS')
  1413. {
  1414. frequency='WEEKLY';
  1415. byDay=';BYDAY=';
  1416. if(globalSettings.weekenddays.value.length>0)
  1417. {
  1418. for(var i=0;i<7;i++)
  1419. if(globalSettings.weekenddays.value.indexOf(i)==-1)
  1420. byDay+=i+',';
  1421. byDay=byDay.substring(0,byDay.length-1);
  1422. byDay=byDay.replace(1,'MO').replace(2,'TU').replace(3,'WE').replace(4,'TH').replace(5,'FR').replace(6,'SA').replace(0,'SU');
  1423. }
  1424. else
  1425. {
  1426. byDay='SA,SU';
  1427. }
  1428. interval='';
  1429. }
  1430. else if(frequency=='WEEKEND')
  1431. {
  1432. frequency='WEEKLY';
  1433. byDay=';BYDAY=';
  1434. if(globalSettings.weekenddays.value.length>0)
  1435. {
  1436. for(var i=0;i<globalSettings.weekenddays.value.length;i++)
  1437. byDay+=globalSettings.weekenddays.value[i]+',';
  1438. byDay=byDay.substring(0,byDay.length-1);
  1439. byDay=byDay.replace(1,'MO').replace(2,'TU').replace(3,'WE').replace(4,'TH').replace(5,'FR').replace(6,'SA').replace(0,'SU');
  1440. }
  1441. else
  1442. {
  1443. byDay='SA,SU';
  1444. }
  1445. interval='';
  1446. }
  1447. else if(frequency=='CUSTOM_WEEKLY')
  1448. {
  1449. frequency='WEEKLY';
  1450. var byDayArray=$('#week_custom .customTable td.selected');
  1451. if(byDayArray.length>0)
  1452. {
  1453. byDay=';BYDAY=';
  1454. for(var ri=0;ri<byDayArray.length;ri++)
  1455. byDay+=$(byDayArray[ri]).attr('data-type')+',';
  1456. byDay=byDay.substring(0,byDay.length-1);
  1457. byDay=byDay.replace(1,'MO').replace(2,'TU').replace(3,'WE').replace(4,'TH').replace(5,'FR').replace(6,'SA').replace(0,'SU');
  1458. if(globalSettings.mozillasupport.value==null || !globalSettings.mozillasupport.value)
  1459. if(realEvent!='')
  1460. {
  1461. if(realEvent.wkst!='')
  1462. wkst=';WKST='+realEvent.wkst.replace(1,'MO').replace(2,'TU').replace(3,'WE').replace(4,'TH').replace(5,'FR').replace(6,'SA').replace(0,'SU');
  1463. }
  1464. else
  1465. wkst=';WKST='+globalSettings.datepickerfirstdayofweek.value.toString().replace(1,'MO').replace(2,'TU').replace(3,'WE').replace(4,'TH').replace(5,'FR').replace(6,'SA').replace(0,'SU');
  1466. }
  1467. }
  1468. else if(frequency=='CUSTOM_MONTHLY')
  1469. {
  1470. frequency='MONTHLY';
  1471. var byDayFirstPart='';
  1472. var monthCustomOption = $('#repeat_month_custom_select').val();
  1473. if(monthCustomOption!='custom' && $('#repeat_month_custom_select2').val()!='DAY')
  1474. {
  1475. if(monthCustomOption!='')
  1476. byDay=';BYDAY=';
  1477. switch(monthCustomOption)
  1478. {
  1479. case 'every':
  1480. byDayFirstPart='';
  1481. break;
  1482. case 'first':
  1483. byDayFirstPart='1';
  1484. break;
  1485. case 'second':
  1486. byDayFirstPart='2';
  1487. break;
  1488. case 'third':
  1489. byDayFirstPart='3';
  1490. break;
  1491. case 'fourth':
  1492. byDayFirstPart='4';
  1493. break;
  1494. case 'fifth':
  1495. byDayFirstPart='5';
  1496. break;
  1497. case 'last':
  1498. byDayFirstPart='-1';
  1499. break;
  1500. default:
  1501. byDayFirstPart='';
  1502. break;
  1503. }
  1504. byDay+= byDayFirstPart+$('#repeat_month_custom_select2').val();
  1505. }
  1506. else if(monthCustomOption!='custom' && $('#repeat_month_custom_select2').val()=='DAY')
  1507. {
  1508. byDay='';
  1509. switch(monthCustomOption)
  1510. {
  1511. case 'every':
  1512. monthDay=';BYMONTHDAY=';
  1513. for(var p=1;p<32;p++)
  1514. monthDay+=p+',';
  1515. monthDay=monthDay.substring(0,monthDay.length-1);
  1516. break;
  1517. case 'first':
  1518. monthDay=';BYMONTHDAY=1';
  1519. break;
  1520. case 'second':
  1521. monthDay=';BYMONTHDAY=2';
  1522. break;
  1523. case 'third':
  1524. monthDay=';BYMONTHDAY=3';
  1525. break;
  1526. case 'fourth':
  1527. monthDay=';BYMONTHDAY=4';
  1528. break;
  1529. case 'fifth':
  1530. monthDay=';BYMONTHDAY=5';
  1531. break;
  1532. case 'last':
  1533. monthDay=';BYMONTHDAY=-1';
  1534. break;
  1535. default:
  1536. byDayFirstPart='';
  1537. monthDay='';
  1538. break;
  1539. }
  1540. }
  1541. else
  1542. {
  1543. var monthDayArray = $('#month_custom2 .selected');
  1544. if(monthDayArray.length>0)
  1545. {
  1546. monthDay=';BYMONTHDAY=';
  1547. for(var ri=0;ri<monthDayArray.length;ri++)
  1548. monthDay+=$(monthDayArray[ri]).attr('data-type')+',';
  1549. monthDay=monthDay.substring(0,monthDay.length-1);
  1550. }
  1551. }
  1552. }
  1553. else if(frequency=='CUSTOM_YEARLY')
  1554. {
  1555. frequency='YEARLY';
  1556. var byDayFirstPart='';
  1557. var monthCustomOption = $('#repeat_year_custom_select1').val();
  1558. var monthArray = $('#year_custom3 .selected');
  1559. if(monthArray.length>0)
  1560. {
  1561. bymonth=';BYMONTH=';
  1562. for(var ri=0;ri<monthArray.length;ri++)
  1563. {
  1564. var val = parseInt($(monthArray[ri]).attr('data-type'),10);
  1565. if(!isNaN(val))
  1566. bymonth+=(val+1)+',';
  1567. }
  1568. bymonth=bymonth.substring(0,bymonth.length-1);
  1569. }
  1570. if(monthCustomOption!='custom' && $('#repeat_year_custom_select2').val()!='DAY')
  1571. {
  1572. if(monthCustomOption!='')
  1573. byDay=';BYDAY=';
  1574. switch(monthCustomOption)
  1575. {
  1576. case 'every':
  1577. byDayFirstPart='';
  1578. break;
  1579. case 'first':
  1580. byDayFirstPart='1';
  1581. break;
  1582. case 'second':
  1583. byDayFirstPart='2';
  1584. break;
  1585. case 'third':
  1586. byDayFirstPart='3';
  1587. break;
  1588. case 'fourth':
  1589. byDayFirstPart='4';
  1590. break;
  1591. case 'fifth':
  1592. byDayFirstPart='5';
  1593. break;
  1594. case 'last':
  1595. byDayFirstPart='-1';
  1596. break;
  1597. default:
  1598. byDayFirstPart='';
  1599. break;
  1600. }
  1601. byDay+= byDayFirstPart+$('#repeat_year_custom_select2').val();
  1602. }
  1603. else if(monthCustomOption!='custom' && $('#repeat_year_custom_select2').val()=='DAY')
  1604. {
  1605. byDay='';
  1606. switch(monthCustomOption)
  1607. {
  1608. case 'every':
  1609. monthDay=';BYMONTHDAY=';
  1610. for(var p=1;p<32;p++)
  1611. monthDay+=p+',';
  1612. monthDay=monthDay.substring(0,monthDay.length-1);
  1613. break;
  1614. case 'first':
  1615. monthDay=';BYMONTHDAY=1';
  1616. break;
  1617. case 'second':
  1618. monthDay=';BYMONTHDAY=2';
  1619. break;
  1620. case 'third':
  1621. monthDay=';BYMONTHDAY=3';
  1622. break;
  1623. case 'fourth':
  1624. monthDay=';BYMONTHDAY=4';
  1625. break;
  1626. case 'fifth':
  1627. monthDay=';BYMONTHDAY=5';
  1628. break;
  1629. case 'last':
  1630. monthDay=';BYMONTHDAY=-1';
  1631. break;
  1632. default:
  1633. byDayFirstPart='';
  1634. monthDay='';
  1635. break;
  1636. }
  1637. }
  1638. else
  1639. {
  1640. var monthDayArray = $('#year_custom1 .selected');
  1641. if(monthDayArray.length>0)
  1642. {
  1643. monthDay=';BYMONTHDAY=';
  1644. for(var ri=0;ri<monthDayArray.length;ri++)
  1645. monthDay+=$(monthDayArray[ri]).attr('data-type')+',';
  1646. monthDay=monthDay.substring(0,monthDay.length-1);
  1647. }
  1648. }
  1649. }
  1650. else if($('#repeat option:selected').attr('data-type')=="custom_repeat")
  1651. isCustom=true;
  1652. if(vCalendar.tplM['contentline_RRULE']!=null && (process_elem=vCalendar.tplM['contentline_RRULE'][0])!=undefined)
  1653. {
  1654. // replace the object and related objects' group names (+ append the related objects after the processed)
  1655. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1656. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1657. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1658. }
  1659. else
  1660. {
  1661. process_elem=vCalendar.tplC['contentline_RRULE'];
  1662. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1663. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1664. }
  1665. if(!isCustom)
  1666. {
  1667. if($('#repeat_end_details').val()=="on_date")
  1668. {
  1669. var dateUntil=$.datepicker.parseDate(globalSettings.datepickerformat.value, $('#repeat_end_date').val());
  1670. var datetime_until='';
  1671. if(!$('#allday').prop('checked'))
  1672. {
  1673. var tForR=new Date(Date.parse("01/02/1990, "+$('#time_from').val() ));
  1674. dateUntil.setHours(tForR.getHours());
  1675. dateUntil.setMinutes(tForR.getMinutes());
  1676. dateUntil.setSeconds(tForR.getSeconds());
  1677. if(globalSettings.timezonesupport.value && sel_option in timezones)
  1678. var valOffsetFrom=getOffsetByTZ(sel_option, dateUntil);
  1679. if(valOffsetFrom)
  1680. {
  1681. var intOffset=valOffsetFrom.getSecondsFromOffset()*1000*-1;
  1682. dateUntil.setTime(dateUntil.getTime()+intOffset);
  1683. }
  1684. datetime_until=$.fullCalendar.formatDate(dateUntil, "yyyyMMdd'T'HHmmss'Z'");
  1685. }
  1686. else
  1687. datetime_until=$.fullCalendar.formatDate(dateUntil, 'yyyyMMdd')+'T000000Z';
  1688. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue("FREQ="+frequency)+interval+";UNTIL="+datetime_until+bymonth+monthDay+byDay+wkst);
  1689. }
  1690. else if($('#repeat_end_details').val()=="after")
  1691. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue("FREQ="+frequency)+interval+";COUNT="+(parseInt($('#repeat_end_after').val()))+bymonth+monthDay+byDay+wkst);
  1692. else
  1693. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue("FREQ="+frequency)+interval+bymonth+monthDay+byDay+wkst);
  1694. }
  1695. else
  1696. process_elem=process_elem.replace('##:::##value##:::##',$('#repeat').val());
  1697. vCalendarText+=process_elem;
  1698. if(realEvent.repeatStart)
  1699. {
  1700. var a=$.datepicker.parseDate(globalSettings.datepickerformat.value, $('#date_from').val());
  1701. var repeatStart=realEvent.repeatStart;
  1702. var b=new Date(1970,1,1,0,0,0);
  1703. if(!$('#allday').prop('checked'))
  1704. {
  1705. b=new Date(Date.parse("01/02/1990, "+$('#time_from').val() ));
  1706. a.setHours(b.getHours());
  1707. a.setMinutes(b.getMinutes());
  1708. a.setSeconds(b.getSeconds());
  1709. }
  1710. var offsetDate=a-repeatStart;
  1711. for(var iter in vCalendar.tplM['contentline_EXDATE'])
  1712. {
  1713. if(isNaN(iter))
  1714. continue;
  1715. var exStr=('\r\n'+vCalendar.tplM['contentline_EXDATE'][iter]).match(vCalendar.pre['contentline_parse']);
  1716. var exVal=exStr[4].parseComnpactISO8601();
  1717. if(exVal)
  1718. {
  1719. if(exStr[4].indexOf('T')==-1 && !$('#allday').prop('checked'))
  1720. {
  1721. //HERE
  1722. var timePart = new Date(Date.parse("01/02/1990, "+$('#time_from').val() ));
  1723. var time_from = $.fullCalendar.formatDate(b, 'HHmmss');
  1724. exVal = (exStr[4] + 'T' + time_from).parseComnpactISO8601();
  1725. if(sel_option!='local')
  1726. {
  1727. var valOffsetFrom=getOffsetByTZ(sel_option, exVal);
  1728. var intOffset = valOffsetFrom.getSecondsFromOffset()*-1;
  1729. exVal = new Date(exVal.setSeconds(intOffset));
  1730. }
  1731. }
  1732. else if(exStr[4].indexOf('T')!=-1 && !$('#allday').prop('checked'))
  1733. {
  1734. if(sel_option!='local')
  1735. {
  1736. var valOffsetFrom=getOffsetByTZ(sel_option, exVal);
  1737. var origValOffset = getOffsetByTZ(realEvent.timeZone, exVal);
  1738. var intOffset = (valOffsetFrom.getSecondsFromOffset() - origValOffset.getSecondsFromOffset())*-1;
  1739. exVal = new Date(exVal.setSeconds(intOffset));
  1740. }
  1741. else
  1742. {
  1743. var origValOffset = getOffsetByTZ(realEvent.timeZone, exVal);
  1744. exVal = new Date(exVal.setSeconds(origValOffset.getSecondsFromOffset()));
  1745. }
  1746. }
  1747. var value=new Date(exVal.getTime()+offsetDate);
  1748. process_elem=vCalendar.tplC['contentline_EXDATE'];
  1749. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1750. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1751. if(!$('#allday').prop('checked'))
  1752. {
  1753. //if(exStr[4].indexOf('T')==-1)
  1754. // var newValue=new Date(value.setMinutes(new Date().getTimezoneOffset()));
  1755. newValue=$.fullCalendar.formatDate(value, "yyyyMMdd'T'HHmmss")+(sel_option!='local' ? 'Z' : '');
  1756. process_elem=process_elem.replace('##:::##AllDay##:::##', vcalendarEscapeValue(''));
  1757. process_elem=process_elem.replace('##:::##TZID##:::##', vcalendarEscapeValue(''));
  1758. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(newValue));
  1759. }
  1760. else
  1761. {
  1762. var newValue=$.fullCalendar.formatDate(value, "yyyyMMdd");
  1763. process_elem=process_elem.replace('##:::##AllDay##:::##', ';'+vcalendarEscapeValue('VALUE=DATE'));
  1764. process_elem=process_elem.replace('##:::##TZID##:::##', vcalendarEscapeValue(''));
  1765. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(newValue));
  1766. }
  1767. vCalendarText+=process_elem;
  1768. }
  1769. }
  1770. }
  1771. }
  1772. var a=$('#eventDetailsTable').find("tr[data-id]");
  1773. var lastDataId=0;
  1774. for(var i=0;i<a[a.length-1].attributes.length;i++)
  1775. if(a[a.length-1].attributes[i].nodeName=="data-id")
  1776. {
  1777. lastDataId=a[a.length-1].attributes[i].value;
  1778. break;
  1779. }
  1780. var alarmIterator=0;
  1781. var alarmUniqueArray = new Array();
  1782. for(var t=0;t<lastDataId;t++)
  1783. {
  1784. if($(".alert[data-id="+(t+1)+"]").length>0)
  1785. {
  1786. var alarmText = '';
  1787. if($(".alert[data-id="+(t+1)+"]").val()!='none')
  1788. {
  1789. if(vCalendar.tplM['beginVALARM']!=null && (process_elem=vCalendar.tplM['beginVALARM'][0])!=undefined)
  1790. alarmText+=vCalendar.tplM['beginVALARM'][0];
  1791. else
  1792. {
  1793. process_elem=vCalendar.tplC['beginVALARM'];
  1794. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1795. alarmText+=process_elem;
  1796. vevent=true;
  1797. }
  1798. if($(".alert[data-id="+(t+1)+"]").val()=='message')
  1799. {
  1800. if($(".alert_message_details[data-id="+(t+1)+"]").val()=='on_date')
  1801. {
  1802. if(vCalendar.tplM['contentline_TRIGGER']!=null && (process_elem=vCalendar.tplM['contentline_TRIGGER'][0])!=undefined)
  1803. {
  1804. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1805. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1806. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1807. }
  1808. else
  1809. {
  1810. process_elem=vCalendar.tplC['contentline_TRIGGER'];
  1811. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1812. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1813. }
  1814. var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value, $(".message_date_input[data-id="+(t+1)+"]").val());
  1815. var datetime_to=$.fullCalendar.formatDate(dateTo, 'yyyy-MM-dd');
  1816. var aDate=new Date(Date.parse("01/02/1990, "+$(".message_time_input[data-id="+(t+1)+"]").val() ));
  1817. var time_to=$.fullCalendar.formatDate(aDate, 'HH:mm:ss');
  1818. var alarmDT=$.fullCalendar.parseDate(datetime_to+'T'+time_to);
  1819. if(globalSettings.timezonesupport.value)
  1820. sel_option=$('#timezone').val();
  1821. if($('.timezone_row').css('display')=='none')
  1822. sel_option='local';
  1823. if(sel_option!='local')
  1824. {
  1825. var origValOffset=getOffsetByTZ(sel_option, alarmDT);
  1826. var origIntOffset = origValOffset.getSecondsFromOffset()*-1;
  1827. alarmDT = new Date(alarmDT.setSeconds(origIntOffset));
  1828. }
  1829. var newValue=$.fullCalendar.formatDate(alarmDT, "yyyyMMdd'T'HHmmss")+(sel_option!='local' ? 'Z' : '');
  1830. process_elem=process_elem.replace('##:::##VALUE=DATE-TIME##:::##', ';VALUE=DATE-TIME');
  1831. process_elem=process_elem.replace('##:::##VALUE=DURATION##:::##', '');
  1832. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(newValue));
  1833. alarmText+=process_elem;
  1834. }
  1835. else
  1836. {
  1837. var duration='';
  1838. var before_after=$(".before_after_input[data-id="+(t+1)+"]").val();
  1839. if($(".alert_message_details[data-id="+(t+1)+"]").val()=='minutes_before')
  1840. duration="-PT"+before_after+"M";
  1841. if($(".alert_message_details[data-id="+(t+1)+"]").val()=='hours_before')
  1842. duration="-PT"+before_after+"H";
  1843. if($(".alert_message_details[data-id="+(t+1)+"]").val()=='days_before')
  1844. duration="-P"+before_after+"D";
  1845. if($(".alert_message_details[data-id="+(t+1)+"]").val()=='weeks_before')
  1846. duration="-P"+before_after+"W";
  1847. if($(".alert_message_details[data-id="+(t+1)+"]").val()=='seconds_before')
  1848. duration="-PT"+before_after+"S";
  1849. if($(".alert_message_details[data-id="+(t+1)+"]").val()=='minutes_after')
  1850. duration="PT"+before_after+"M";
  1851. if($(".alert_message_details[data-id="+(t+1)+"]").val()=='hours_after')
  1852. duration="PT"+before_after+"H";
  1853. if($(".alert_message_details[data-id="+(t+1)+"]").val()=='days_after')
  1854. duration="P"+before_after+"D";
  1855. if($(".alert_message_details[data-id="+(t+1)+"]").val()=='weeks_after')
  1856. duration="P"+before_after+"W";
  1857. if($(".alert_message_details[data-id="+(t+1)+"]").val()=='seconds_after')
  1858. duration="PT"+before_after+"S";
  1859. if(vCalendar.tplM['contentline_TRIGGER']!=null && (process_elem=vCalendar.tplM['contentline_TRIGGER'][0])!=undefined)
  1860. {
  1861. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1862. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1863. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1864. }
  1865. else
  1866. {
  1867. process_elem=vCalendar.tplC['contentline_TRIGGER'];
  1868. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1869. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1870. }
  1871. process_elem=process_elem.replace('##:::##VALUE=DATE-TIME##:::##', '');
  1872. process_elem=process_elem.replace('##:::##VALUE=DURATION##:::##', ';VALUE=DURATION');
  1873. process_elem=process_elem.replace('##:::##value##:::##', duration);
  1874. alarmText+=process_elem;
  1875. }
  1876. if(vCalendar.tplM['contentline_ACTION']!=null && (process_elem=vCalendar.tplM['contentline_ACTION'][0])!=undefined)
  1877. {
  1878. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1879. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1880. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1881. }
  1882. else
  1883. {
  1884. process_elem=vCalendar.tplC['contentline_ACTION'];
  1885. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1886. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1887. }
  1888. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue('DISPLAY'));
  1889. alarmText+=process_elem;
  1890. var a=new Date();
  1891. if(vCalendar.tplM['contentline_DESCRIPTION']!=null && (process_elem=vCalendar.tplM['contentline_DESCRIPTION'][0])!=undefined)
  1892. {
  1893. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1894. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1895. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1896. }
  1897. else
  1898. {
  1899. process_elem=vCalendar.tplC['contentline_DESCRIPTION'];
  1900. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1901. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1902. }
  1903. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue('Reminder'));
  1904. alarmText+=process_elem;
  1905. }
  1906. if((typeof vCalendar.tplM['unprocessedVALARM']!='undefined' && typeof vCalendar.tplM['unprocessedVALARM'][t]!='undefined') && (vCalendar.tplM['unprocessedVALARM'][t]!='') && (vCalendar.tplM['unprocessedVALARM'][t]!=null))
  1907. {
  1908. tmp=vCalendar.tplM['unprocessedVALARM'][t].replace(RegExp('^\r\n'), '').replace(RegExp('\r\n$'), '');
  1909. if(tmp.indexOf('\r\n')==0)
  1910. tmp=tmp.substring(2, tmp.length);
  1911. if(tmp.lastIndexOf('\r\n')!=(tmp.length-2))
  1912. tmp+='\r\n';
  1913. alarmText+=tmp;
  1914. }
  1915. if(vCalendar.tplM['endVALARM']!=null && (process_elem=vCalendar.tplM['endVALARM'][0])!=undefined)
  1916. alarmText+=vCalendar.tplM['endVALARM'][0];
  1917. else
  1918. {
  1919. process_elem=vCalendar.tplC['endVALARM'];
  1920. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1921. alarmText+=process_elem;
  1922. }
  1923. if(alarmUniqueArray.indexOf(alarmText)==-1)
  1924. {
  1925. alarmUniqueArray.push(alarmText);
  1926. vCalendarText+=alarmText;
  1927. }
  1928. }
  1929. }
  1930. }
  1931. vCalendar.tplM['unprocessedVALARM']=new Array();
  1932. if($('#avail').val()!='none')
  1933. {
  1934. if(vCalendar.tplM['contentline_TRANSP']!=null && (process_elem=vCalendar.tplM['contentline_TRANSP'][0])!=undefined)
  1935. {
  1936. // replace the object and related objects' group names (+ append the related objects after the processed)
  1937. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1938. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1939. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1940. }
  1941. else
  1942. {
  1943. process_elem=vCalendar.tplC['contentline_TRANSP'];
  1944. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1945. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1946. }
  1947. if($('#avail').val()=='busy')
  1948. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue('OPAQUE'));
  1949. else
  1950. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue('TRANSPARENT'));
  1951. vCalendarText+=process_elem;
  1952. }
  1953. if($('#url_EVENT').val()!='')
  1954. {
  1955. if(vCalendar.tplM['contentline_URL']!=null && (process_elem=vCalendar.tplM['contentline_URL'][0])!=undefined)
  1956. {
  1957. // replace the object and related objects' group names (+ append the related objects after the processed)
  1958. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1959. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1960. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1961. }
  1962. else
  1963. {
  1964. process_elem=vCalendar.tplC['contentline_URL'];
  1965. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1966. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1967. }
  1968. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue($('#url_EVENT').val()));
  1969. vCalendarText+=process_elem;
  1970. }
  1971. }
  1972. //DESCRIPTION
  1973. if($('#note').val()!='')
  1974. {
  1975. // NOTE
  1976. if(vCalendar.tplM['contentline_NOTE']!=null && (process_elem=vCalendar.tplM['contentline_NOTE'][0])!=undefined)
  1977. {
  1978. // replace the object and related objects' group names (+ append the related objects after the processed)
  1979. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  1980. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  1981. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  1982. }
  1983. else
  1984. {
  1985. process_elem=vCalendar.tplC['contentline_NOTE'];
  1986. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  1987. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  1988. }
  1989. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue($('#note').val()));
  1990. vCalendarText+=process_elem;
  1991. }
  1992. if($('#status').val()!='NONE')
  1993. {
  1994. //if((value=$('[id="vcalendar_editor"] [data-type="\\%note"]').find('textarea').val())!='')
  1995. //{
  1996. if(vCalendar.tplM['contentline_STATUS']!=null && (process_elem=vCalendar.tplM['contentline_STATUS'][0])!=undefined)
  1997. {
  1998. // replace the object and related objects' group names (+ append the related objects after the processed)
  1999. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  2000. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  2001. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  2002. }
  2003. else
  2004. {
  2005. process_elem=vCalendar.tplC['contentline_STATUS'];
  2006. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  2007. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  2008. }
  2009. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue($('#status').val()));
  2010. vCalendarText+=process_elem;
  2011. }
  2012. //CLASS
  2013. if($('#type').val()!='')
  2014. {
  2015. // CLASS
  2016. if(vCalendar.tplM['contentline_CLASS']!=null && (process_elem=vCalendar.tplM['contentline_CLASS'][0])!=undefined)
  2017. {
  2018. // replace the object and related objects' group names (+ append the related objects after the processed)
  2019. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  2020. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  2021. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  2022. }
  2023. else
  2024. {
  2025. process_elem=vCalendar.tplC['contentline_CLASS'];
  2026. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  2027. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  2028. if(typeof vCalendar.tplM['contentline_CLASS'] =='undefined' || vCalendar.tplM['contentline_CLASS']==null || vCalendar.tplM['contentline_CLASS'].length==0)
  2029. process_elem='';
  2030. }
  2031. if($('.row_type').css('display')!='none')
  2032. {
  2033. process_elem=vCalendar.tplC['contentline_CLASS'];
  2034. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  2035. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  2036. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue($('#type').val().toUpperCase()));
  2037. }
  2038. vCalendarText+=process_elem;
  2039. }
  2040. //RECURRENCE-ID
  2041. if($('#recurrenceID').val())
  2042. {
  2043. if(vCalendar.tplM['contentline_REC_ID']!=null && (process_elem=vCalendar.tplM['contentline_REC_ID'][0])!=undefined)
  2044. {
  2045. // replace the object and related objects' group names (+ append the related objects after the processed)
  2046. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  2047. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  2048. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  2049. }
  2050. else
  2051. {
  2052. process_elem=vCalendar.tplC['contentline_REC_ID'];
  2053. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  2054. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  2055. }
  2056. var rec_id=$('#recurrenceID').val()
  2057. if(rec_id.indexOf('T')==-1)
  2058. {
  2059. process_elem=process_elem.replace('##:::##AllDay##:::##', ';'+vcalendarEscapeValue('VALUE=DATE'));
  2060. process_elem=process_elem.replace('##:::##TZID##:::##', vcalendarEscapeValue(''));
  2061. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(rec_id));
  2062. }
  2063. else
  2064. {
  2065. process_elem=process_elem.replace('##:::##AllDay##:::##', vcalendarEscapeValue(''));
  2066. /*if((typeof vCalendar.tplM['unprocessed']!='undefined') && (vCalendar.tplM['unprocessed']!='') && (vCalendar.tplM['unprocessed']!=null))
  2067. {
  2068. var checkTZID=vCalendar.tplM['unprocessed'].match(vCalendar.pre['contentline_TZID']);
  2069. if(checkTZID!=null)
  2070. {
  2071. parsed=checkTZID[0].match(vCalendar.pre['contentline_parse']);
  2072. process_elem=process_elem.replace('##:::##TZID##:::##', ';'+vcalendarEscapeValue("TZID="+parsed[4]));
  2073. }
  2074. else
  2075. process_elem=process_elem.replace('##:::##TZID##:::##', ';'+vcalendarEscapeValue("TZID="+ sel_option));
  2076. }
  2077. else*/
  2078. process_elem=process_elem.replace('##:::##TZID##:::##',timeZoneAttr);
  2079. if(isUTC && rec_id.charAt(rec_id.length-1)!='Z')
  2080. rec_id+='Z';
  2081. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(rec_id));
  2082. }
  2083. vCalendarText+=process_elem;
  2084. }
  2085. if(vCalendar.tplM['contentline_E_DTSTART']!=null && (process_elem=vCalendar.tplM['contentline_E_DTSTART'][0])!=undefined)
  2086. {
  2087. // replace the object and related objects' group names (+ append the related objects after the processed)
  2088. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  2089. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  2090. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  2091. }
  2092. else
  2093. {
  2094. process_elem=vCalendar.tplC['contentline_E_DTSTART'];
  2095. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  2096. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  2097. }
  2098. var datetime_from='', datetime_to='';
  2099. var a=$.datepicker.parseDate(globalSettings.datepickerformat.value, $('#date_from').val());
  2100. var a2=$.datepicker.parseDate(globalSettings.datepickerformat.value, $('#date_to').val());
  2101. var b=new Date(1970, 1, 1, 0, 0, 0);
  2102. if(datetime_from=='')
  2103. datetime_from=$.fullCalendar.formatDate(a, 'yyyyMMdd');
  2104. if(datetime_to=='')
  2105. datetime_to=$.fullCalendar.formatDate(a2, 'yyyyMMdd');
  2106. var dateTo=$.datepicker.parseDate('yymmdd',datetime_to);
  2107. if($('#allday').prop('checked'))
  2108. {
  2109. process_elem=process_elem.replace('##:::##AllDay##:::##', ';'+vcalendarEscapeValue('VALUE=DATE'));
  2110. process_elem=process_elem.replace('##:::##TZID##:::##', vcalendarEscapeValue(''));
  2111. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(datetime_from));
  2112. }
  2113. else
  2114. {
  2115. b=new Date(Date.parse("01/02/1990, "+$('#time_from').val() ));
  2116. var time_from=$.fullCalendar.formatDate(b, 'HHmmss');
  2117. process_elem=process_elem.replace('##:::##AllDay##:::##', vcalendarEscapeValue(''));
  2118. /*if((typeof vCalendar.tplM['unprocessed']!='undefined') && (vCalendar.tplM['unprocessed']!='') && (vCalendar.tplM['unprocessed']!=null))
  2119. {
  2120. var checkTZID=vCalendar.tplM['unprocessed'].match(vCalendar.pre['contentline_TZID']);
  2121. if(checkTZID!=null)
  2122. {
  2123. parsed=checkTZID[0].match(vCalendar.pre['contentline_parse']);
  2124. process_elem=process_elem.replace('##:::##TZID##:::##', ';'+vcalendarEscapeValue("TZID="+parsed[4]));
  2125. }
  2126. else
  2127. process_elem=process_elem.replace('##:::##TZID##:::##', ';'+vcalendarEscapeValue("TZID="+ sel_option));
  2128. }
  2129. else*/
  2130. process_elem=process_elem.replace('##:::##TZID##:::##', timeZoneAttr);
  2131. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(datetime_from+'T'+time_from+(isUTC ? 'Z' : '')));
  2132. }
  2133. vCalendarText+=process_elem;
  2134. if(realEvent!='')
  2135. {
  2136. if(realEvent.type!='')
  2137. {
  2138. var repeatStart=realEvent.repeatStart;
  2139. a.setHours(b.getHours());
  2140. a.setMinutes(b.getMinutes());
  2141. a.setSeconds(b.getSeconds());
  2142. var changeDate=a;
  2143. var offsetDate=changeDate-repeatStart;
  2144. var realEventUID=realEvent.vcalendar.match(vCalendar.pre['contentline_UID']);
  2145. if(realEventUID!=null)
  2146. realEventUID=realEventUID[0].match(vCalendar.pre['contentline_parse'])[4];
  2147. if(offsetDate!=0)
  2148. {
  2149. var vcalendarOrig=vCalendarText;
  2150. var eventArray=new Array(),backupEventArray= new Array();
  2151. while(vcalendarOrig.match(vCalendar.pre['vevent'])!=null)
  2152. {
  2153. if(vcalendarOrig.substring(vcalendarOrig.indexOf('BEGIN:VEVENT')-2, vcalendarOrig.indexOf('BEGIN:VEVENT'))=='\r\n')
  2154. {
  2155. var partEvent=vcalendarOrig.substring(vcalendarOrig.indexOf('BEGIN:VEVENT')-2,vcalendarOrig.indexOf('END:VEVENT')+'END:VEVENT'.length);
  2156. vcalendarOrig=vcalendarOrig.replace(partEvent, '');
  2157. }
  2158. else
  2159. {
  2160. var partEvent=vcalendarOrig.substring(vcalendarOrig.indexOf('BEGIN:VEVENT'),vcalendarOrig.indexOf('END:VEVENT')+'END:VEVENT'.length);
  2161. vcalendarOrig=vcalendarOrig.replace(partEvent, '');
  2162. partEvent+='\r\n';
  2163. }
  2164. eventArray[eventArray.length]=partEvent;
  2165. backupEventArray[backupEventArray.length]=partEvent;
  2166. }
  2167. if(eventArray.length==0)
  2168. console.log("Error: '"+inputUID+"': unable to parse vEvent");
  2169. for(var it=0;it<eventArray.length;it++)
  2170. {
  2171. var findUid=eventArray[it].match(vCalendar.pre['contentline_UID']);
  2172. if(findUid!=null)
  2173. {
  2174. if(findUid[0].match(vCalendar.pre['contentline_parse'])[4]!=realEventUID)
  2175. continue;
  2176. }
  2177. var findRec=eventArray[it].match(vCalendar.pre['contentline_RECURRENCE_ID']);
  2178. if(findRec!=null)
  2179. {
  2180. var parsed=findRec[0].match(vCalendar.pre['contentline_parse']);
  2181. process_elem=vCalendar.tplC['contentline_REC_ID'];
  2182. process_elem=process_elem.replace('##:::##group_wd##:::##', parsed[1]);
  2183. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  2184. var value=parsed[4].parseComnpactISO8601();
  2185. if(value)
  2186. {
  2187. value=new Date(value.getTime()+offsetDate)
  2188. var newValue=$.fullCalendar.formatDate(value, "yyyyMMdd'T'HHmmss");
  2189. if(isUTC)
  2190. newValue+='Z';
  2191. if($('#allday').prop('checked'))
  2192. {
  2193. newValue=$.fullCalendar.formatDate(value, "yyyyMMdd");
  2194. process_elem=process_elem.replace('##:::##AllDay##:::##', ';'+vcalendarEscapeValue('VALUE=DATE'));
  2195. process_elem=process_elem.replace('##:::##TZID##:::##', vcalendarEscapeValue(''));
  2196. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(newValue));
  2197. }
  2198. else
  2199. {
  2200. process_elem=process_elem.replace('##:::##AllDay##:::##', vcalendarEscapeValue(''));
  2201. /*if((typeof vCalendar.tplM['unprocessed']!='undefined') && (vCalendar.tplM['unprocessed']!='') && (vCalendar.tplM['unprocessed']!=null))
  2202. {
  2203. var checkTZID=vCalendar.tplM['unprocessed'].match(vCalendar.pre['contentline_TZID']);
  2204. if(checkTZID!=null)
  2205. {
  2206. parsed=checkTZID[0].match(vCalendar.pre['contentline_parse']);
  2207. process_elem=process_elem.replace('##:::##TZID##:::##', ';'+vcalendarEscapeValue("TZID="+parsed[4]));
  2208. }
  2209. else
  2210. process_elem=process_elem.replace('##:::##TZID##:::##', ';'+vcalendarEscapeValue("TZID="+ sel_option));
  2211. }
  2212. else*/
  2213. process_elem=process_elem.replace('##:::##TZID##:::##', timeZoneAttr);
  2214. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(newValue));
  2215. }
  2216. eventArray[it]=eventArray[it].replace(findRec[0],'\r\n'+process_elem);
  2217. }
  2218. }
  2219. vCalendarText=vCalendarText.replace(backupEventArray[it],eventArray[it]);
  2220. }
  2221. }
  2222. }
  2223. }
  2224. if(vCalendar.tplM['contentline_E_DTEND']!=null && (process_elem=vCalendar.tplM['contentline_E_DTEND'][0])!=undefined)
  2225. {
  2226. // replace the object and related objects' group names (+ append the related objects after the processed)
  2227. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  2228. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  2229. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  2230. }
  2231. else
  2232. {
  2233. process_elem=vCalendar.tplC['contentline_E_DTEND'];
  2234. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  2235. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  2236. }
  2237. if($('#allday').prop('checked'))
  2238. {
  2239. var dateAfter=new Date(dateTo.getFullYear(), dateTo.getMonth(), dateTo.getDate()+1);
  2240. dateAfter=dateAfter.getFullYear()+''+((dateAfter.getMonth()+1)<10 ? '0'+(dateAfter.getMonth()+1) : (dateAfter.getMonth()+1))+''+ ((dateAfter.getDate())<10 ? '0'+(dateAfter.getDate()) : (dateAfter.getDate()));
  2241. process_elem=process_elem.replace('##:::##AllDay##:::##', ';'+vcalendarEscapeValue('VALUE=DATE'));
  2242. process_elem=process_elem.replace('##:::##TZID##:::##', vcalendarEscapeValue(""));
  2243. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(dateAfter));
  2244. }
  2245. else
  2246. {
  2247. var b2=new Date(Date.parse("01/02/1990, "+$('#time_to').val() ));
  2248. var time_to=$.fullCalendar.formatDate(b2, 'HHmmss');
  2249. process_elem=process_elem.replace('##:::##AllDay##:::##', vcalendarEscapeValue(''));
  2250. /*if((typeof vCalendar.tplM['unprocessed']!='undefined') && (vCalendar.tplM['unprocessed']!='') && (vCalendar.tplM['unprocessed']!=null))
  2251. {
  2252. var checkTZID=vCalendar.tplM['unprocessed'].match(vCalendar.pre['contentline_TZID']);
  2253. if(checkTZID!=null)
  2254. {
  2255. parsed=checkTZID[0].match(vCalendar.pre['contentline_parse']);
  2256. process_elem=process_elem.replace('##:::##TZID##:::##', ';'+vcalendarEscapeValue("TZID="+parsed[4]));
  2257. }
  2258. else
  2259. process_elem=process_elem.replace('##:::##TZID##:::##', ';'+vcalendarEscapeValue("TZID="+sel_option));
  2260. }
  2261. else*/
  2262. process_elem=process_elem.replace('##:::##TZID##:::##', timeZoneAttr);
  2263. process_elem=process_elem.replace('##:::##value##:::##', vcalendarEscapeValue(datetime_to+'T'+time_to+(isUTC ? 'Z' : '')));
  2264. }
  2265. vCalendarText+=process_elem;
  2266. //RFC OPTIONAL
  2267. if(vCalendar.tplM['contentline_LOCATION']!=null && (process_elem=vCalendar.tplM['contentline_LOCATION'][0])!=undefined)
  2268. {
  2269. // replace the object and related objects' group names (+ append the related objects after the processed)
  2270. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)','m'));
  2271. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  2272. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.','\\.'),'mg'),'\r\nitem'+(groupCounter++)+'.').substring(2);
  2273. }
  2274. else
  2275. {
  2276. process_elem=vCalendar.tplC['contentline_LOCATION'];
  2277. process_elem=process_elem.replace('##:::##group_wd##:::##','');
  2278. process_elem=process_elem.replace('##:::##params_wsc##:::##','');
  2279. }
  2280. if($('#location').val()!='')
  2281. {
  2282. process_elem=process_elem.replace('##:::##value##:::##',vcalendarEscapeValue($('#location').val()));
  2283. vCalendarText+=process_elem;
  2284. }
  2285. if($('#recurrenceID').val()=='')
  2286. var checkVal='orig';
  2287. else
  2288. var checkVal=$('#recurrenceID').val();
  2289. if(typeof vCalendar.tplM['unprocessedVEVENT']!='undefined' && vCalendar.tplM['unprocessedVEVENT']!=null)
  2290. {
  2291. for(vev in vCalendar.tplM['unprocessedVEVENT'])
  2292. if(vev==checkVal)
  2293. vCalendarText+=vCalendar.tplM['unprocessedVEVENT'][vev].replace(RegExp('^\r\n'), '');
  2294. }
  2295. //vCalendar.tplM['unprocessedVEVENT']=new Array();
  2296. if(vCalendar.tplM['endVEVENT']!=null && (process_elem=vCalendar.tplM['endVEVENT'][0])!=undefined)
  2297. vCalendarText+=vCalendar.tplM['endVEVENT'][0];
  2298. else
  2299. {
  2300. process_elem=vCalendar.tplC['endVEVENT'];
  2301. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  2302. vCalendarText+=process_elem;
  2303. }
  2304. // PRODID
  2305. if(vCalendar.tplM['contentline_PRODID']!=null && (process_elem=vCalendar.tplM['contentline_PRODID'][0])!=undefined)
  2306. {
  2307. // replace the object and related objects' group names (+ append the related objects after the processed)
  2308. parsed=('\r\n'+process_elem).match(RegExp('\r\n((?:'+vCalendar.re['group']+'\\.)?)', 'm'));
  2309. if(parsed[1]!='') // if group is present, replace the object and related objects' group names
  2310. process_elem=('\r\n'+process_elem).replace(RegExp('\r\n'+parsed[1].replace('.', '\\.'), 'mg'), '\r\nitem'+(groupCounter++)+'.').substring(2);
  2311. }
  2312. else
  2313. {
  2314. process_elem=vCalendar.tplC['contentline_PRODID'];
  2315. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  2316. process_elem=process_elem.replace('##:::##params_wsc##:::##', '');
  2317. }
  2318. process_elem=process_elem.replace('##:::##value##:::##', '-//Inf-IT//'+globalAppName+' '+globalVersion+'//EN');
  2319. vCalendarText+=process_elem;
  2320. if(typeof vCalendar.tplM['unprocessed']!='undefined' && vCalendar.tplM['unprocessed']!='' && vCalendar.tplM['unprocessed']!=null)
  2321. vCalendarText+=vCalendar.tplM['unprocessed'].replace(RegExp('^\r\n'), '');
  2322. vCalendar.tplM['unprocessed']=new Array();
  2323. // vCalendar END (required by RFC)
  2324. if(vCalendar.tplM['end']!=null && (process_elem=vCalendar.tplM['end'][0])!=undefined)
  2325. vCalendarText+=vCalendar.tplM['end'][0];
  2326. else
  2327. {
  2328. process_elem=vCalendar.tplC['end'];
  2329. process_elem=process_elem.replace('##:::##group_wd##:::##', '');
  2330. vCalendarText+=process_elem;
  2331. }
  2332. var nextVcalendars = new Array();
  2333. if(futureMode && origEvent!='')
  2334. {
  2335. var fixed = checkAndFixMultipleUID(origEvent,true);
  2336. if(fixed.length==1)
  2337. nextVcalendars[nextVcalendars.length]=origEvent;
  2338. else
  2339. nextVcalendars=fixed;
  2340. }
  2341. // replace unsupported XML characters
  2342. vCalendarText=vCalendarText.replace(/[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD]/g, ' ');
  2343. var fixedArr = checkAndFixMultipleUID(vCalendarText,true);
  2344. fixedArr = $.merge(nextVcalendars,fixedArr);
  2345. var inputS = fixedArr[0];
  2346. fixedArr.splice(0,1);
  2347. if(operation=='MOVE_IN')
  2348. return moveVcalendarToCollection(accountUID, inputUID, inputEtag, inputS, delUID, 'vevent', isFormHidden, deleteMode, fixedArr);
  2349. else
  2350. return putVcalendarToCollection(accountUID, inputUID, inputEtag, inputS, delUID, 'vevent', isFormHidden, deleteMode, fixedArr);
  2351. }
  2352. function fullVcalendarToData(inputEvent)
  2353. {
  2354. CalDAVeditor_cleanup();
  2355. var vcalendar='';
  2356. var rid=inputEvent.id.substring(0, inputEvent.id.lastIndexOf('/')+1);
  2357. if(globalEventList.events[rid][inputEvent.id].uid!=undefined)
  2358. vcalendar=globalEventList.events[rid][inputEvent.id].vcalendar;
  2359. if(!vcalendar)
  2360. return false;
  2361. var vcalendar_full=vcalendar.split('\r\n');
  2362. if((parsed=('\r\n'+vcalendar_full[0]+'\r\n').match(vCalendar.pre['contentline_parse']))==null)
  2363. return false;
  2364. //BEGIN, END VCALENDAR
  2365. vCalendar.tplM['begin'][0]=vCalendar.tplC['begin'].replace(/##:::##group_wd##:::##/g, vcalendar_begin_group=parsed[1]);
  2366. // parsed (contentline_parse)=[1]->"group.", [2]->"name", [3]->";param;param", [4]->"value"
  2367. if((parsed=('\r\n'+vcalendar_full[vcalendar_full.length-2]+'\r\n').match(vCalendar.pre['contentline_parse']))==null)
  2368. return false;
  2369. // values not directly supported by the editor (old values are kept intact)
  2370. vCalendar.tplM['end'][0]=vCalendar.tplC['end'].replace(/##:::##group_wd##:::##/g, vcalendar_end_group=parsed[1]);
  2371. if(vcalendar_begin_group!=vcalendar_end_group)
  2372. return false;// the vCalendar BEGIN and END "group" are different
  2373. // remove the vCalendar BEGIN and END
  2374. vcalendar='\r\n'+vcalendar_full.slice(1, vcalendar_full.length-2).join('\r\n')+'\r\n';
  2375. /*
  2376. vcalendar_element=vcalendar.match(vCalendar.pre['tzone']);
  2377. if(vcalendar_element!=null)
  2378. vcalendar=vcalendar.replace(vcalendar_element[0],'');
  2379. */
  2380. //FIX TIMEZONE
  2381. var beginTimeZone=vcalendar.indexOf('BEGIN:VTIMEZONE');
  2382. var startEndTimeZone=vcalendar.lastIndexOf('END:VTIMEZONE');
  2383. var endTimeZone=0;
  2384. var vTimeZone='';
  2385. if(beginTimeZone!=-1 && startEndTimeZone!=-1)
  2386. {
  2387. for(i=(startEndTimeZone+2);i<vcalendar.length;i++)
  2388. {
  2389. if(vcalendar.charAt(i)=='\n')
  2390. {
  2391. endTimeZone=i+1;
  2392. break;
  2393. }
  2394. }
  2395. vTimeZone=vcalendar.substring(beginTimeZone, endTimeZone);
  2396. vcalendar=vcalendar.substring(0, beginTimeZone)+vcalendar.substring(endTimeZone, vcalendar.length);
  2397. }
  2398. vcalendar_element=vcalendar.match(RegExp('\r\n'+vCalendar.re['contentline_CALSCALE'], 'mi'));
  2399. if(vcalendar_element!=null)
  2400. {
  2401. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2402. //note=String(vcalendar_element).split(':')[1];
  2403. version=vcalendarUnescapeValue(parsed[4]);
  2404. vCalendar.tplM['contentline_CALSCALE'][0]=vCalendar.tplC['contentline_CALSCALE'];
  2405. vCalendar.tplM['contentline_CALSCALE'][0]=vCalendar.tplM['contentline_CALSCALE'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2406. vCalendar.tplM['contentline_CALSCALE'][0]=vCalendar.tplM['contentline_CALSCALE'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2407. vcalendar=vcalendar.replace(vcalendar_element[0], '\r\n');
  2408. if(parsed[1]!='')
  2409. {
  2410. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2411. while ((vcalendar_element_related=vcalendar.match(re))!=null)
  2412. {
  2413. // append the parameter to its parent
  2414. vCalendar.tplM['contentline_CALSCALE'][0]+=vcalendar_element_related[0].substr(2);
  2415. // remove the processed parameter
  2416. vcalendar=vcalendar.replace(vcalendar_element_related[0], '\r\n');
  2417. }
  2418. }
  2419. }
  2420. vcalendar_element=vcalendar.match(RegExp('\r\n'+vCalendar.re['contentline_VERSION'], 'mi'));
  2421. if(vcalendar_element!=null)
  2422. {
  2423. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2424. //note=String(vcalendar_element).split(':')[1];
  2425. version=vcalendarUnescapeValue(parsed[4]);
  2426. vCalendar.tplM['contentline_VERSION'][0]=vCalendar.tplC['contentline_VERSION'];
  2427. vCalendar.tplM['contentline_VERSION'][0]=vCalendar.tplM['contentline_VERSION'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2428. vCalendar.tplM['contentline_VERSION'][0]=vCalendar.tplM['contentline_VERSION'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2429. vcalendar=vcalendar.replace(vcalendar_element[0], '\r\n');
  2430. if(parsed[1]!='')
  2431. {
  2432. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2433. while ((vcalendar_element_related=vcalendar.match(re))!=null)
  2434. {
  2435. // append the parameter to its parent
  2436. vCalendar.tplM['contentline_VERSION'][0]+=vcalendar_element_related[0].substr(2);
  2437. // remove the processed parameter
  2438. vcalendar=vcalendar.replace(vcalendar_element_related[0], '\r\n');
  2439. }
  2440. }
  2441. }
  2442. //PRODID
  2443. vcalendar_element=vcalendar.match(RegExp('\r\n'+vCalendar.re['contentline_PRODID'], 'mi'));
  2444. if(vcalendar_element!=null)
  2445. {
  2446. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2447. vCalendar.tplM['contentline_PRODID'][0]=vCalendar.tplC['contentline_PRODID'];
  2448. vCalendar.tplM['contentline_PRODID'][0]=vCalendar.tplM['contentline_PRODID'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2449. vCalendar.tplM['contentline_PRODID'][0]=vCalendar.tplM['contentline_PRODID'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2450. vcalendar=vcalendar.replace(vcalendar_element[0], '\r\n');
  2451. if(parsed[1]!='')
  2452. {
  2453. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2454. while ((vcalendar_element_related=vcalendar.match(re))!=null)
  2455. {
  2456. // append the parameter to its parent
  2457. vCalendar.tplM['contentline_PRODID'][0]+=vcalendar_element_related[0].substr(2);
  2458. // remove the processed parameter
  2459. vcalendar=vcalendar.replace(vcalendar_element_related[0], '\r\n');
  2460. }
  2461. }
  2462. }
  2463. var eventArray=new Array();
  2464. while(vcalendar.match(vCalendar.pre['vevent'])!=null)
  2465. {
  2466. var partEvent=vcalendar.substring(vcalendar.indexOf('BEGIN:VEVENT')-2,vcalendar.indexOf('END:VEVENT')+'END:VEVENT'.length);
  2467. eventArray[eventArray.length]=partEvent;
  2468. vcalendar=vcalendar.replace(partEvent, '');
  2469. }
  2470. if(eventArray.length==0)
  2471. console.log("Error: '"+inputEvent.id+"': unable to parse vEvent");
  2472. for(var it=0;it<eventArray.length;it++)
  2473. {
  2474. // ------------------------------ VEVENT ------------------------------ //
  2475. var vevent=eventArray[it];
  2476. var vevent_full=vevent.split('\r\n');
  2477. if(vevent==null)
  2478. return false;
  2479. //vcalendar=vcalendar.replace(vevent[0], '\r\n');
  2480. //BEGIN
  2481. if((parsed=('\r\nBEGIN:VEVENT\r\n').match(vCalendar.pre['contentline_parse']))==null)
  2482. return false;
  2483. //BEGIN, END VCALENDAR
  2484. vCalendar.tplM['beginVEVENT'][0]=vCalendar.tplC['beginVEVENT'].replace(/##:::##group_wd##:::##/g, vcalendar_begin_group=parsed[1]);
  2485. // parsed (contentline_parse)=[1]->"group.", [2]->"name", [3]->";param;param", [4]->"value"
  2486. if((parsed=('\r\n'+vcalendar_full[vevent_full.length-2]+'\r\n').match(vCalendar.pre['contentline_parse']))==null)
  2487. return false;
  2488. // values not directly supported by the editor (old values are kept intact)
  2489. vCalendar.tplM['endVEVENT'][0]=vCalendar.tplC['endVEVENT'].replace(/##:::##group_wd##:::##/g, vcalendar_end_group=parsed[1]);
  2490. if(vcalendar_begin_group!=vcalendar_end_group)
  2491. return false;// the vCalendar BEGIN and END "group" are different
  2492. // remove the vCalendar BEGIN and END
  2493. vevent='\r\n'+vevent_full.slice(2, vevent_full.length-1).join('\r\n')+'\r\n';
  2494. //SUMMARY
  2495. vcalendar_element=vevent.match(RegExp('\r\n'+vCalendar.re['contentline_SUMMARY'], 'mi'));
  2496. if(vcalendar_element!=null)
  2497. {
  2498. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2499. //note=String(vcalendar_element).split(':')[1];
  2500. title=vcalendarUnescapeValue(parsed[4]);
  2501. vCalendar.tplM['contentline_SUMMARY'][0]=vCalendar.tplC['contentline_SUMMARY'];
  2502. vCalendar.tplM['contentline_SUMMARY'][0]=vCalendar.tplM['contentline_SUMMARY'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2503. vCalendar.tplM['contentline_SUMMARY'][0]=vCalendar.tplM['contentline_SUMMARY'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2504. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2505. if(parsed[1]!='')
  2506. {
  2507. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2508. while ((vcalendar_element_related=vevent.match(re))!=null)
  2509. {
  2510. // append the parameter to its parent
  2511. vCalendar.tplM['contentline_SUMMARY'][0]+=vcalendar_element_related[0].substr(2);
  2512. // remove the processed parameter
  2513. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2514. }
  2515. }
  2516. }
  2517. vcalendar_element=vevent.match(RegExp('\r\n'+vCalendar.re['contentline_TRANSP'], 'mi'));
  2518. if(vcalendar_element!=null)
  2519. {
  2520. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2521. //note=String(vcalendar_element).split(':')[1];
  2522. title=vcalendarUnescapeValue(parsed[4]);
  2523. vCalendar.tplM['contentline_TRANSP'][0]=vCalendar.tplC['contentline_TRANSP'];
  2524. vCalendar.tplM['contentline_TRANSP'][0]=vCalendar.tplM['contentline_TRANSP'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2525. vCalendar.tplM['contentline_TRANSP'][0]=vCalendar.tplM['contentline_TRANSP'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2526. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2527. if(parsed[1]!='')
  2528. {
  2529. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2530. while ((vcalendar_element_related=vevent.match(re))!=null)
  2531. {
  2532. // append the parameter to its parent
  2533. vCalendar.tplM['contentline_TRANSP'][0]+=vcalendar_element_related[0].substr(2);
  2534. // remove the processed parameter
  2535. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2536. }
  2537. }
  2538. }
  2539. vcalendar_element=vevent.match(RegExp('\r\n'+vCalendar.re['contentline_PRIORITY'], 'mi'));
  2540. if(vcalendar_element!=null)
  2541. {
  2542. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2543. //note=String(vcalendar_element).split(':')[1];
  2544. title=vcalendarUnescapeValue(parsed[4]);
  2545. vCalendar.tplM['contentline_PRIORITY'][0]=vCalendar.tplC['contentline_PRIORITY'];
  2546. vCalendar.tplM['contentline_PRIORITY'][0]=vCalendar.tplM['contentline_PRIORITY'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2547. vCalendar.tplM['contentline_PRIORITY'][0]=vCalendar.tplM['contentline_PRIORITY'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2548. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2549. if(parsed[1]!='')
  2550. {
  2551. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2552. while ((vcalendar_element_related=vevent.match(re))!=null)
  2553. {
  2554. // append the parameter to its parent
  2555. vCalendar.tplM['contentline_PRIORITY'][0]+=vcalendar_element_related[0].substr(2);
  2556. // remove the processed parameter
  2557. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2558. }
  2559. }
  2560. }
  2561. //LOCATION
  2562. vcalendar_element=vevent.match(RegExp('\r\n'+vCalendar.re['contentline_LOCATION'], 'mi'));
  2563. if(vcalendar_element!=null)
  2564. {
  2565. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2566. //note=String(vcalendar_element).split(':')[1];
  2567. title=vcalendarUnescapeValue(parsed[4]);
  2568. vCalendar.tplM['contentline_LOCATION'][0]=vCalendar.tplC['contentline_LOCATION'];
  2569. vCalendar.tplM['contentline_LOCATION'][0]=vCalendar.tplM['contentline_LOCATION'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2570. vCalendar.tplM['contentline_LOCATION'][0]=vCalendar.tplM['contentline_LOCATION'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2571. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2572. if(parsed[1]!='')
  2573. {
  2574. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2575. while ((vcalendar_element_related=vevent.match(re))!=null)
  2576. {
  2577. // append the parameter to its parent
  2578. vCalendar.tplM['contentline_LOCATION'][0]+=vcalendar_element_related[0].substr(2);
  2579. // remove the processed parameter
  2580. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2581. }
  2582. }
  2583. }
  2584. //URL
  2585. vcalendar_element=vevent.match(RegExp('\r\n'+vCalendar.re['contentline_URL'], 'mi'));
  2586. if(vcalendar_element!=null)
  2587. {
  2588. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2589. //note=String(vcalendar_element).split(':')[1];
  2590. title=vcalendarUnescapeValue(parsed[4]);
  2591. vCalendar.tplM['contentline_URL'][0]=vCalendar.tplC['contentline_URL'];
  2592. vCalendar.tplM['contentline_URL'][0]=vCalendar.tplM['contentline_URL'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2593. vCalendar.tplM['contentline_URL'][0]=vCalendar.tplM['contentline_URL'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2594. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2595. if(parsed[1]!='')
  2596. {
  2597. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2598. while ((vcalendar_element_related=vevent.match(re))!=null)
  2599. {
  2600. // append the parameter to its parent
  2601. vCalendar.tplM['contentline_URL'][0]+=vcalendar_element_related[0].substr(2);
  2602. // remove the processed parameter
  2603. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2604. }
  2605. }
  2606. }
  2607. // ------------------------------ VALARM ------------------------------ //
  2608. var valarm=vevent.match(vCalendar.pre['valarm']);
  2609. if(valarm!=null)
  2610. {
  2611. vevent=vevent.replace(valarm[0], '');
  2612. var alarmString='';
  2613. var alarmArray=new Array();
  2614. for(var i=0;i<valarm[0].length;i++)
  2615. {
  2616. if(valarm[0].substring(i-'END:VALARM'.length, i)=='END:VALARM')
  2617. {
  2618. alarmArray[alarmArray.length]=alarmString+'\r\n';
  2619. alarmString='';
  2620. }
  2621. alarmString+=valarm[0][i];
  2622. }
  2623. for(var j=0;j<alarmArray.length;j++)
  2624. {
  2625. checkA=alarmArray[j].match(vCalendar.re['valarm']);
  2626. if(checkA!=null)
  2627. {
  2628. var valarm_full=checkA[0].split('\r\n');
  2629. //BEGIN
  2630. if((parsed=('\r\n'+valarm_full[0]+'\r\n').match(vCalendar.pre['contentline_parse']))==null)
  2631. return false;
  2632. //BEGIN, END VCALENDAR
  2633. vCalendar.tplM['beginVALARM'][j]=vCalendar.tplC['beginVALARM'].replace(/##:::##group_wd##:::##/g, vcalendar_begin_group=parsed[1]);
  2634. // parsed (contentline_parse)=[1]->"group.", [2]->"name", [3]->";param;param", [4]->"value"
  2635. if((parsed=('\r\n'+valarm_full[valarm_full.length-2]+'\r\n').match(vCalendar.pre['contentline_parse']))==null)
  2636. return false;
  2637. // values not directly supported by the editor (old values are kept intact)
  2638. vCalendar.tplM['endVALARM'][j]=vCalendar.tplC['endVALARM'].replace(/##:::##group_wd##:::##/g, vcalendar_end_group=parsed[1]);
  2639. if(vcalendar_begin_group!=vcalendar_end_group)
  2640. return false;// the vCalendar BEGIN and END "group" are different
  2641. // remove the vCalendar BEGIN and END
  2642. alarmArray[j]='\r\n'+valarm_full.slice(1, valarm_full.length-2).join('\r\n')+'\r\n';
  2643. trigger=alarmArray[j].match(vCalendar.pre['contentline_TRIGGER']);
  2644. if(trigger!=null)
  2645. {
  2646. parsed=(trigger[0]+'\r\n').match(vCalendar.pre['contentline_parse']);
  2647. vCalendar.tplM['contentline_TRIGGER'][j]=vCalendar.tplC['contentline_TRIGGER'];
  2648. vCalendar.tplM['contentline_TRIGGER'][j]=vCalendar.tplM['contentline_TRIGGER'][j].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2649. var pars=vcalendarSplitParam(parsed[3]);
  2650. var parString='';
  2651. for(var i=0;i<pars.length;i++)
  2652. {
  2653. if((pars[i]!='VALUE=DATE-TIME') && (pars[i]!='VALUE=DURATION') && (pars[i]!=''))
  2654. parString+=';'+pars[i];
  2655. }
  2656. vCalendar.tplM['contentline_TRIGGER'][j]=vCalendar.tplM['contentline_TRIGGER'][j].replace(/##:::##params_wsc##:::##/g, parString);
  2657. alarmArray[j]=alarmArray[j].replace(trigger[0], '');
  2658. if(parsed[1]!='')
  2659. {
  2660. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2661. while ((vcalendar_element_related=vevent.match(re))!=null)
  2662. {
  2663. // append the parameter to its parent
  2664. vCalendar.tplM['contentline_TRIGGER'][j]+=vcalendar_element_related[0].substr(2);
  2665. // remove the processed parameter
  2666. vevent=vevent.replace(vcalendar_element_related[0], '');
  2667. }
  2668. }
  2669. }
  2670. note=alarmArray[j].match(vCalendar.pre['contentline_NOTE']);
  2671. if(note!=null)
  2672. {
  2673. parsed=note[0].match(vCalendar.pre['contentline_parse']);
  2674. vCalendar.tplM['contentline_VANOTE'][j]=vCalendar.tplC['contentline_VANOTE'];
  2675. vCalendar.tplM['contentline_VANOTE'][j]=vCalendar.tplM['contentline_VANOTE'][j].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2676. vCalendar.tplM['contentline_VANOTE'][j]=vCalendar.tplM['contentline_VANOTE'][j].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2677. alarmArray[j]=alarmArray[j].replace(note[0], '\r\n');
  2678. if(parsed[1]!='')
  2679. {
  2680. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2681. while ((vcalendar_element_related=vevent.match(re))!=null)
  2682. {
  2683. // append the parameter to its parent
  2684. vCalendar.tplM['contentline_VANOTE'][0]+=vcalendar_element_related[0].substr(2);
  2685. // remove the processed parameter
  2686. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2687. }
  2688. }
  2689. }
  2690. action=(alarmArray[j]).match(vCalendar.pre['contentline_ACTION']);
  2691. if(action!=null)
  2692. {
  2693. parsed=action[0].match(vCalendar.pre['contentline_parse']);
  2694. vCalendar.tplM['contentline_ACTION'][j]=vCalendar.tplC['contentline_ACTION'];
  2695. vCalendar.tplM['contentline_ACTION'][j]=vCalendar.tplM['contentline_ACTION'][j].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2696. vCalendar.tplM['contentline_ACTION'][j]=vCalendar.tplM['contentline_ACTION'][j].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2697. alarmArray[j]=alarmArray[j].replace(action[0], '\r\n');
  2698. if(parsed[1]!='')
  2699. {
  2700. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2701. while ((vcalendar_element_related=vevent.match(re))!=null)
  2702. {
  2703. // append the parameter to its parent
  2704. vCalendar.tplM['contentline_ACTION'][0]+=vcalendar_element_related[0].substr(2);
  2705. // remove the processed parameter
  2706. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2707. }
  2708. }
  2709. }
  2710. var checkUnprocess=$.trim(alarmArray[j]);
  2711. if(checkUnprocess!='')
  2712. vCalendar.tplM['unprocessedVALARM'][j]=alarmArray[j];
  2713. }
  2714. }
  2715. }
  2716. // NOTE
  2717. vcalendar_element=vevent.match(vCalendar.pre['contentline_NOTE']);
  2718. if(vcalendar_element!=null)
  2719. {
  2720. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2721. vCalendar.tplM['contentline_NOTE'][0]=vCalendar.tplC['contentline_NOTE'];
  2722. vCalendar.tplM['contentline_NOTE'][0]=vCalendar.tplM['contentline_NOTE'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2723. vCalendar.tplM['contentline_NOTE'][0]=vCalendar.tplM['contentline_NOTE'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2724. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2725. if(parsed[1]!='')
  2726. {
  2727. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2728. while ((vcalendar_element_related=vevent.match(re))!=null)
  2729. {
  2730. // append the parameter to its parent
  2731. vCalendar.tplM['contentline_NOTE'][0]+=vcalendar_element_related[0].substr(2);
  2732. // remove the processed parameter
  2733. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2734. }
  2735. }
  2736. }
  2737. //CLASS
  2738. vcalendar_element=vevent.match(vCalendar.pre['contentline_CLASS']);
  2739. if(vcalendar_element!=null)
  2740. {
  2741. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2742. vCalendar.tplM['contentline_CLASS'][0]=vCalendar.tplC['contentline_CLASS'];
  2743. vCalendar.tplM['contentline_CLASS'][0]=vCalendar.tplM['contentline_CLASS'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2744. vCalendar.tplM['contentline_CLASS'][0]=vCalendar.tplM['contentline_CLASS'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2745. vCalendar.tplM['contentline_CLASS'][0]=vCalendar.tplM['contentline_CLASS'][0].replace(/##:::##value##:::##/g, parsed[4]);
  2746. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2747. if(parsed[1]!='')
  2748. {
  2749. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2750. while ((vcalendar_element_related=vevent.match(re))!=null)
  2751. {
  2752. // append the parameter to its parent
  2753. vCalendar.tplM['contentline_CLASS'][0]+=vcalendar_element_related[0].substr(2);
  2754. // remove the processed parameter
  2755. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2756. }
  2757. }
  2758. }
  2759. vcalendar_element=vevent.match(vCalendar.pre['contentline_STATUS']);
  2760. if(vcalendar_element!=null)
  2761. {
  2762. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2763. title=vcalendarUnescapeValue(parsed[4]);
  2764. vCalendar.tplM['contentline_STATUS'][0]=vCalendar.tplC['contentline_STATUS'];
  2765. vCalendar.tplM['contentline_STATUS'][0]=vCalendar.tplM['contentline_STATUS'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2766. vCalendar.tplM['contentline_STATUS'][0]=vCalendar.tplM['contentline_STATUS'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2767. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2768. if(parsed[1]!='')
  2769. {
  2770. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2771. while ((vcalendar_element_related=vevent.match(re))!=null)
  2772. {
  2773. // append the parameter to its parent
  2774. vCalendar.tplM['contentline_STATUS'][0]+=vcalendar_element_related[0].substr(2);
  2775. // remove the processed parameter
  2776. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2777. }
  2778. }
  2779. }
  2780. //RECURRENCE-ID
  2781. var rec='';
  2782. vcalendar_element=vevent.match(vCalendar.pre['contentline_RECURRENCE_ID']);
  2783. if(vcalendar_element!=null)
  2784. {
  2785. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2786. var rec=parsed[4];
  2787. vCalendar.tplM['contentline_REC_ID'][0]=vCalendar.tplC['contentline_REC_ID'];
  2788. vCalendar.tplM['contentline_REC_ID'][0]=vCalendar.tplM['contentline_REC_ID'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2789. var pars=vcalendarSplitParam(parsed[3]);
  2790. var parString='';
  2791. for(var i=0;i<pars.length;i++)
  2792. {
  2793. if((pars[i]!='VALUE=DATE') && (pars[i].indexOf('TZID=')==-1) && (pars[i]!=''))
  2794. parString+=';'+pars[i];
  2795. }
  2796. vCalendar.tplM['contentline_REC_ID'][0]=vCalendar.tplM['contentline_REC_ID'][0].replace(/##:::##params_wsc##:::##/g, parString);
  2797. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2798. if(parsed[1]!='')
  2799. {
  2800. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2801. while ((vcalendar_element_related=vevent.match(re))!=null)
  2802. {
  2803. // append the parameter to its parent
  2804. vCalendar.tplM['contentline_REC_ID'][0]+=vcalendar_element_related[0].substr(2);
  2805. // remove the processed parameter
  2806. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2807. }
  2808. }
  2809. }
  2810. if(rec=='')
  2811. rec='orig';
  2812. //EXDATE
  2813. var i=-1;
  2814. while(vevent.match(vCalendar.pre['contentline_EXDATE'])!= null)
  2815. {
  2816. i++;
  2817. vcalendar_element=vevent.match(vCalendar.pre['contentline_EXDATE']);
  2818. if(vcalendar_element!=null)
  2819. {
  2820. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2821. vCalendar.tplM['contentline_EXDATE'][i]=vCalendar.tplC['contentline_EXDATE'];
  2822. vCalendar.tplM['contentline_EXDATE'][i]=vCalendar.tplM['contentline_EXDATE'][i].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2823. var pars=vcalendarSplitParam(parsed[3]);
  2824. var parString='', dateStr='';
  2825. for(var j=0;j<pars.length;j++)
  2826. {
  2827. if(pars[j]!='VALUE=DATE' && pars[j]!='')
  2828. parString+=';'+pars[j];
  2829. if(pars[j]=='VALUE=DATE')
  2830. dateStr=pars[j];
  2831. }
  2832. if(dateStr.indexOf('VALUE=DATE')!=-1)
  2833. vCalendar.tplM['contentline_EXDATE'][i]=vCalendar.tplM['contentline_EXDATE'][i].replace(/##:::##AllDay##:::##/g, ';VALUE=DATE');
  2834. else
  2835. vCalendar.tplM['contentline_EXDATE'][i]=vCalendar.tplM['contentline_EXDATE'][i].replace(/##:::##AllDay##:::##/g, '');
  2836. vCalendar.tplM['contentline_EXDATE'][i]=vCalendar.tplM['contentline_EXDATE'][i].replace(/##:::##TZID##:::##/g, '');
  2837. vCalendar.tplM['contentline_EXDATE'][i]=vCalendar.tplM['contentline_EXDATE'][i].replace(/##:::##params_wsc##:::##/g, parString);
  2838. vCalendar.tplM['contentline_EXDATE'][i]=vCalendar.tplM['contentline_EXDATE'][i].replace(/##:::##value##:::##/g,parsed[4]);
  2839. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2840. if(parsed[1]!='')
  2841. {
  2842. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2843. while ((vcalendar_element_related=vevent.match(re))!=null)
  2844. {
  2845. // append the parameter to its parent
  2846. vCalendar.tplM['contentline_EXDATE'][i]+=vcalendar_element_related[0].substr(2);
  2847. // remove the processed parameter
  2848. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2849. }
  2850. }
  2851. }
  2852. }
  2853. //END
  2854. vcalendar_element=vevent.match(vCalendar.pre['contentline_DTEND']);
  2855. if(vcalendar_element!=null)
  2856. {
  2857. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2858. vCalendar.tplM['contentline_E_DTEND'][0]=vCalendar.tplC['contentline_E_DTEND'];
  2859. vCalendar.tplM['contentline_E_DTEND'][0]=vCalendar.tplM['contentline_E_DTEND'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2860. var pars=vcalendarSplitParam(parsed[3]);
  2861. var parString='';
  2862. for(var i=0;i<pars.length;i++)
  2863. {
  2864. if((pars[i]!='VALUE=DATE') && (pars[i].indexOf('TZID=')==-1) && (pars[i]!=''))
  2865. parString+=';'+pars[i];
  2866. }
  2867. vCalendar.tplM['contentline_E_DTEND'][0]=vCalendar.tplM['contentline_E_DTEND'][0].replace(/##:::##params_wsc##:::##/g, parString);
  2868. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2869. if(parsed[1]!='')
  2870. {
  2871. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2872. while ((vcalendar_element_related=vevent.match(re))!=null)
  2873. {
  2874. // append the parameter to its parent
  2875. vCalendar.tplM['contentline_E_DTEND'][0]+=vcalendar_element_related[0].substr(2);
  2876. // remove the processed parameter
  2877. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2878. }
  2879. }
  2880. }
  2881. //START
  2882. vcalendar_element=vevent.match(vCalendar.pre['contentline_DTSTART']);
  2883. if(vcalendar_element!=null)
  2884. {
  2885. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2886. vCalendar.tplM['contentline_E_DTSTART'][0]=vCalendar.tplC['contentline_E_DTSTART'];
  2887. vCalendar.tplM['contentline_E_DTSTART'][0]=vCalendar.tplM['contentline_E_DTSTART'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2888. var pars=vcalendarSplitParam(parsed[3]);
  2889. var parString='';
  2890. for(var i=0;i<pars.length;i++)
  2891. {
  2892. if((pars[i]!='VALUE=DATE') && (pars[i].indexOf('TZID=')==-1) && (pars[i]!=''))
  2893. parString+=';'+pars[i];
  2894. }
  2895. vCalendar.tplM['contentline_E_DTSTART'][0]=vCalendar.tplM['contentline_E_DTSTART'][0].replace(/##:::##params_wsc##:::##/g, parString);
  2896. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2897. if(parsed[1]!='')
  2898. {
  2899. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2900. while ((vcalendar_element_related=vevent.match(re))!=null)
  2901. {
  2902. // append the parameter to its parent
  2903. vCalendar.tplM['contentline_E_DTSTART'][0]+=vcalendar_element_related[0].substr(2);
  2904. // remove the processed parameter
  2905. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2906. }
  2907. }
  2908. }
  2909. //RRULE
  2910. vcalendar_element=vevent.match(vCalendar.pre['contentline_RRULE2']);
  2911. if(vcalendar_element!=null)
  2912. {
  2913. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2914. vCalendar.tplM['contentline_RRULE'][0]=vCalendar.tplC['contentline_RRULE'];
  2915. vCalendar.tplM['contentline_RRULE'][0]=vCalendar.tplM['contentline_RRULE'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2916. var pars=parsed[4].split(';');
  2917. var parString='';
  2918. for(var i=0;i<pars.length;i++)
  2919. {
  2920. if((pars[i].indexOf('FREQ=')==-1) && (pars[i].indexOf('COUNT=')==-1) && (pars[i].indexOf('UNTIL=')==-1) && (pars[i]!='') && (pars[i].indexOf('INTERVAL=')==-1) && (pars[i].indexOf('BYDAY=')==-1)
  2921. && (pars[i].indexOf('BYMONTHDAY=')==-1) && (pars[i].indexOf('BYMONTH=')==-1) && (pars[i].indexOf('WKST=')==-1))
  2922. parString+=';'+pars[i];
  2923. }
  2924. vCalendar.tplM['contentline_RRULE'][0]=vCalendar.tplM['contentline_RRULE'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2925. vCalendar.tplM['contentline_RRULE'][0]=vCalendar.tplM['contentline_RRULE'][0].replace(/##:::##value##:::##/g, '##:::##value##:::##'+parString);
  2926. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2927. if(parsed[1]!='')
  2928. {
  2929. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2930. while ((vcalendar_element_related=vevent.match(re))!=null)
  2931. {
  2932. // append the parameter to its parent
  2933. vCalendar.tplM['contentline_RRULE'][0]+=vcalendar_element_related[0].substr(2);
  2934. // remove the processed parameter
  2935. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2936. }
  2937. }
  2938. }
  2939. //UID
  2940. vcalendar_element=inputEvent.vcalendar.match(RegExp('\r\n'+vCalendar.re['contentline_UID'], 'mi'));
  2941. if(vcalendar_element!=null)
  2942. {
  2943. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2944. vCalendar.tplM['contentline_UID'][0]=vCalendar.tplC['contentline_UID'];
  2945. vCalendar.tplM['contentline_UID'][0]=vCalendar.tplM['contentline_UID'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2946. vCalendar.tplM['contentline_UID'][0]=vCalendar.tplM['contentline_UID'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2947. vCalendar.tplM['contentline_UID'][0]=vCalendar.tplM['contentline_UID'][0].replace(/##:::##uid##:::##/g,parsed[4]);
  2948. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2949. if(parsed[1]!='')
  2950. {
  2951. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2952. while ((vcalendar_element_related=vevent.match(re))!=null)
  2953. {
  2954. // append the parameter to its parent
  2955. vCalendar.tplM['contentline_UID'][0]+=vcalendar_element_related[0].substr(2);
  2956. // remove the processed parameter
  2957. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2958. }
  2959. }
  2960. }
  2961. //CREATED
  2962. vcalendar_element=vevent.match(RegExp('\r\n'+vCalendar.re['contentline_CREATED'], 'mi'));
  2963. if(vcalendar_element!=null)
  2964. {
  2965. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2966. vCalendar.tplM['contentline_CREATED'][rec]=vCalendar.tplC['contentline_CREATED'];
  2967. vCalendar.tplM['contentline_CREATED'][rec]=vCalendar.tplM['contentline_CREATED'][rec].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2968. vCalendar.tplM['contentline_CREATED'][rec]=vCalendar.tplM['contentline_CREATED'][rec].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2969. vCalendar.tplM['contentline_CREATED'][rec]=vCalendar.tplM['contentline_CREATED'][rec].replace(/##:::##value##:::##/g,parsed[4]);
  2970. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2971. if(parsed[1]!='')
  2972. {
  2973. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2974. while ((vcalendar_element_related=vevent.match(re))!=null)
  2975. {
  2976. // append the parameter to its parent
  2977. vCalendar.tplM['contentline_CREATED'][rec]+=vcalendar_element_related[0].substr(2);
  2978. // remove the processed parameter
  2979. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  2980. }
  2981. }
  2982. }
  2983. //LAST-MODIFIED
  2984. vcalendar_element=vevent.match(RegExp('\r\n'+vCalendar.re['contentline_LM'], 'mi'));
  2985. if(vcalendar_element!=null)
  2986. {
  2987. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  2988. vCalendar.tplM['contentline_LM'][0]=vCalendar.tplC['contentline_LM'];
  2989. vCalendar.tplM['contentline_LM'][0]=vCalendar.tplM['contentline_LM'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  2990. vCalendar.tplM['contentline_LM'][0]=vCalendar.tplM['contentline_LM'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  2991. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  2992. if(parsed[1]!='')
  2993. {
  2994. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  2995. while ((vcalendar_element_related=vevent.match(re))!=null)
  2996. {
  2997. // append the parameter to its parent
  2998. vCalendar.tplM['contentline_LM'][0]+=vcalendar_element_related[0].substr(2);
  2999. // remove the processed parameter
  3000. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  3001. }
  3002. }
  3003. }
  3004. //DTSTAMP
  3005. vcalendar_element=vevent.match(RegExp('\r\n'+vCalendar.re['contentline_DTSTAMP'], 'mi'));
  3006. if(vcalendar_element!=null)
  3007. {
  3008. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3009. vCalendar.tplM['contentline_DTSTAMP'][0]=vCalendar.tplC['contentline_DTSTAMP'];
  3010. vCalendar.tplM['contentline_DTSTAMP'][0]=vCalendar.tplM['contentline_DTSTAMP'][0].replace(/##:::##group_wd##:::##/g, parsed[1]);
  3011. vCalendar.tplM['contentline_DTSTAMP'][0]=vCalendar.tplM['contentline_DTSTAMP'][0].replace(/##:::##params_wsc##:::##/g, parsed[3]);
  3012. vevent=vevent.replace(vcalendar_element[0], '\r\n');
  3013. if(parsed[1]!='')
  3014. {
  3015. var re=RegExp('\r\n'+parsed[1].replace('.','\\..*')+'\r\n', 'im');
  3016. while ((vcalendar_element_related=vevent.match(re))!=null)
  3017. {
  3018. // append the parameter to its parent
  3019. vCalendar.tplM['contentline_DTSTAMP'][0]+=vcalendar_element_related[0].substr(2);
  3020. // remove the processed parameter
  3021. vevent=vevent.replace(vcalendar_element_related[0], '\r\n');
  3022. }
  3023. }
  3024. }
  3025. if(vevent.indexOf('\r\n')==0)
  3026. vevent=vevent.substring(2, vevent.length-2);
  3027. if(vevent.lastIndexOf('\r\n')!=(vevent.length-2))
  3028. vevent+='\r\n';
  3029. vCalendar.tplM['unprocessedVEVENT'][rec]=vevent;
  3030. }
  3031. if(vcalendar.indexOf('\r\n')==0)
  3032. vcalendar=vcalendar.substring(2, vcalendar.length-2);
  3033. if(vcalendar.lastIndexOf('\r\n')!=(vcalendar.length-2))
  3034. vcalendar+='\r\n';
  3035. //if(vTimeZone!='')
  3036. // vcalendar+=vTimeZone;
  3037. vCalendar.tplM['unprocessedVTIMEZONE']=vTimeZone;
  3038. vCalendar.tplM['unprocessed']=vcalendar;
  3039. }
  3040. function parseAlarmWeek(value)
  3041. {
  3042. var durValue='';
  3043. var durChar='W';
  3044. var toSecondsValue=60*60*24*7;
  3045. value=value.substring(value.indexOf('P')+1);
  3046. durValue=value.substring(0, value.indexOf(durChar));
  3047. return durValue*toSecondsValue*1000+durChar;
  3048. }
  3049. function parseAlarmDay(value)
  3050. {
  3051. var durValue='';
  3052. var durChar='D';
  3053. var toSecondsValue=60*60*24;
  3054. var returnValue=0;
  3055. value=value.substring(value.indexOf('P')+1);
  3056. durValue=value.substring(0, value.indexOf(durChar));
  3057. returnValue=durValue*toSecondsValue*1000;
  3058. value=value.substring(value.indexOf(durChar+1));
  3059. if(value.indexOf('T')!=-1)
  3060. {
  3061. durValue=parseAlarmTime(value);
  3062. if(durValue)
  3063. {
  3064. durChar=durValue.substring(durValue.length-1);
  3065. durValue=durValue.substring(0, durValue.length-1);
  3066. returnValue+=durValue;
  3067. }
  3068. }
  3069. return returnValue+durChar;
  3070. }
  3071. function parseAlarmTime(value)
  3072. {
  3073. var durValue='';
  3074. var durChar='';
  3075. var toSecondsValue=0;
  3076. var returnValue=0;
  3077. value=value.substring(value.indexOf('T')+1);
  3078. while(value!='')
  3079. {
  3080. if(value.indexOf('H')!=-1)
  3081. {
  3082. durChar='H';
  3083. toSecondsValue=60*60;
  3084. }
  3085. else if(value.indexOf('M')!=-1)
  3086. {
  3087. durChar='M';
  3088. toSecondsValue=60;
  3089. }
  3090. else if(value.indexOf('S')!=-1)
  3091. {
  3092. durChar='S';
  3093. toSecondsValue=1;
  3094. }
  3095. durValue=value.substring(0, value.indexOf(durChar))
  3096. value=value.substring(value.indexOf(durChar)+1);
  3097. returnValue+=durValue*toSecondsValue;
  3098. }
  3099. if(durChar!='')
  3100. return returnValue*1000+durChar;
  3101. else
  3102. return false;
  3103. }
  3104. function getDateFromDay(objComponent, t, disableRecursion,uid)
  3105. {
  3106. var daylightStartsMonth=objComponent.startMonth-1,
  3107. daylightStartsDay=objComponent.startDay,
  3108. daylightStartCount=objComponent.startCount,
  3109. daylightStartsHours=objComponent.dtStart.parseComnpactISO8601(uid).getHours(),
  3110. daylightStartsMinutes=objComponent.dtStart.parseComnpactISO8601().getMinutes();
  3111. //daylightStartsDay++;
  3112. if(daylightStartsDay==7)
  3113. daylightStartsDay=0;
  3114. var checkDate=new Date(t.getFullYear(), daylightStartsMonth,1,23,59,0);
  3115. if(disableRecursion)
  3116. checkDate.setFullYear(checkDate.getFullYear()-1);
  3117. var firstOfMonthDayOfWeek=checkDate.getDay();
  3118. if(firstOfMonthDayOfWeek!=daylightStartsDay)
  3119. {
  3120. var daysUntilFirst=(1+daylightStartsDay-firstOfMonthDayOfWeek)%7;
  3121. if(daysUntilFirst<=0)
  3122. checkDate.setDate(daysUntilFirst+7);
  3123. else
  3124. checkDate.setDate(daysUntilFirst);
  3125. }
  3126. if(daylightStartCount>0)
  3127. {
  3128. var daysUntilDaylight=(parseInt(daylightStartCount)-1)*7;
  3129. var dayLightStartDate=new Date(checkDate.getFullYear(), checkDate.getMonth(), checkDate.getDate()+daysUntilDaylight, daylightStartsHours, daylightStartsMinutes);
  3130. }
  3131. else
  3132. {
  3133. var tmpLastDay=21+checkDate.getDate();
  3134. var checkTmpDay=new Date(t.getFullYear(),daylightStartsMonth,tmpLastDay+7,23,59,0);
  3135. if(checkTmpDay.getMonth()!=daylightStartsMonth)
  3136. var lastDay=tmpLastDay;
  3137. else
  3138. var lastDay=tmpLastDay+7;
  3139. var daysUntilDaylight=(daylightStartCount+1)*7;
  3140. var dayLightStartDate=new Date(checkDate.getFullYear(), checkDate.getMonth(), lastDay+daysUntilDaylight, daylightStartsHours, daylightStartsMinutes);
  3141. }
  3142. if(dayLightStartDate>t && !disableRecursion)
  3143. dayLightStartDate=getDateFromDay(objComponent, t, true).startDate;
  3144. return {offsetFrom:objComponent.tzOffsetFROM, offsetTo: objComponent.tzOffsetTO, startDate: dayLightStartDate};
  3145. }
  3146. function vcalendarToData(inputCollection, inputEvent, isNew)
  3147. {
  3148. var vcalendarOrig=inputEvent.vcalendar;
  3149. var eventArray=new Array();
  3150. //CHECK CALSCALE
  3151. var elem=vcalendarOrig.match(vCalendar.pre['contentline_CALSCALE']);
  3152. if(elem!=null)
  3153. {
  3154. calscale=elem[0].match(vCalendar.pre['contentline_parse'])[4];
  3155. if(calscale!='GREGORIAN')
  3156. {
  3157. console.log("Error:'"+inputEvent.uid+"': Unsupported calscale in:"+vcalendarOrig);
  3158. return false;
  3159. }
  3160. }
  3161. //CHECK VERSION
  3162. var elemV=vcalendarOrig.match(vCalendar.pre['contentline_VERSION']);
  3163. if(elemV!=null)
  3164. {
  3165. var ver=elemV[0].match(vCalendar.pre['contentline_parse'])[4];
  3166. if(ver!='2.0')
  3167. {
  3168. console.log("Error:'"+inputEvent.uid+"': Unsupported version ("+ver+") in:"+vcalendarOrig);
  3169. return false;
  3170. }
  3171. }
  3172. //FIX TIMEZONE
  3173. var beginTimeZone=vcalendarOrig.indexOf('BEGIN:VTIMEZONE');
  3174. var startEndTimeZone=vcalendarOrig.lastIndexOf('END:VTIMEZONE');
  3175. var endTimeZone=0;
  3176. var rid=inputEvent.uid.substring(0, inputEvent.uid.lastIndexOf('/')+1);
  3177. var evid=inputEvent.uid.substring(inputEvent.uid.lastIndexOf('/')+1, inputEvent.uid.length);
  3178. var isChange=false,
  3179. needReload=false;
  3180. if(!isNew)
  3181. {
  3182. var events=findEventInArray(inputEvent.uid, true);
  3183. if(events!='')
  3184. {
  3185. if(events.etag!=inputEvent.etag)
  3186. {
  3187. for(var i=0; i<events.alertTimeOut.length; i++)
  3188. clearTimeout(events.alertTimeOut[i]);
  3189. deleteEventFromArray(inputEvent.uid);
  3190. if($('#show').val()!='')
  3191. {
  3192. if($('#show').val()==inputEvent.uid)
  3193. {
  3194. if($('#repeatEvent').val()=="true" || $('#recurrenceID').val()!='')
  3195. {
  3196. var name=globalCalEvent.title;
  3197. showEventForm(null, null, {title: name, id:inputEvent.uid}, globalJsEvent, 'show','', true);
  3198. $('#editAll').css('visibility','hidden');
  3199. $('#editFuture').css('visibility','hidden');
  3200. $('#editOnlyOne').css('visibility','hidden');
  3201. $('#repeatConfirmBoxContent').html('<b>'+name+"</b> "+localization[globalInterfaceLanguage].repeatChangeTxt);
  3202. $('#repeatConfirmBoxQuestion').html(localization[globalInterfaceLanguage].repeatChangeTxtClose);
  3203. }
  3204. else
  3205. needReload=true;
  3206. }
  3207. }
  3208. isChange=true;
  3209. }
  3210. }
  3211. }
  3212. if((beginTimeZone!=-1) && (startEndTimeZone!=-1))
  3213. {
  3214. for(i=(startEndTimeZone+2);i<vcalendarOrig.length;i++)
  3215. {
  3216. if(vcalendarOrig.charAt(i)=='\n')
  3217. {
  3218. endTimeZone=i+1;
  3219. break;
  3220. }
  3221. }
  3222. vTimeZone=vcalendarOrig.substring(beginTimeZone, endTimeZone);
  3223. vcalendar=vcalendarOrig.substring(0, beginTimeZone)+vcalendarOrig.substring(endTimeZone, vcalendarOrig.length);
  3224. }
  3225. /*
  3226. vcalendar_element=vcalendar.match(vCalendar.pre['tzone']);
  3227. if(vcalendar_element!=null)
  3228. vcalendar=vcalendar.replace(vcalendar_element[0],'');
  3229. */
  3230. var recurrence_id_array=new Array();
  3231. while(vcalendarOrig.match(vCalendar.pre['vevent'])!=null)
  3232. {
  3233. if(vcalendarOrig.substring(vcalendarOrig.indexOf('BEGIN:VEVENT')-2, vcalendarOrig.indexOf('BEGIN:VEVENT'))=='\r\n')
  3234. {
  3235. var partEvent=vcalendarOrig.substring(vcalendarOrig.indexOf('BEGIN:VEVENT')-2,vcalendarOrig.indexOf('END:VEVENT')+'END:VEVENT'.length);
  3236. vcalendarOrig=vcalendarOrig.replace(partEvent, '');
  3237. }
  3238. else
  3239. {
  3240. var partEvent=vcalendarOrig.substring(vcalendarOrig.indexOf('BEGIN:VEVENT'),vcalendarOrig.indexOf('END:VEVENT')+'END:VEVENT'.length);
  3241. vcalendarOrig=vcalendarOrig.replace(partEvent, '');
  3242. partEvent+='\r\n';
  3243. }
  3244. var rec_array=partEvent.match(vCalendar.pre['contentline_RECURRENCE_ID']);
  3245. var uidString=partEvent.match(vCalendar.pre['contentline_UID']);
  3246. if(uidString!=null && rec_array!=null)
  3247. {
  3248. recurrence_id_array[recurrence_id_array.length]=rec_array[0].match(vCalendar.pre['contentline_parse'])[4]+';'+uidString[0].match(vCalendar.pre['contentline_parse'])[4];
  3249. }
  3250. eventArray[eventArray.length]=partEvent;
  3251. }
  3252. if(eventArray.length==0)
  3253. console.log("Error: '"+inputEvent.uid+"': unable to parse vEvent");
  3254. for(var evIt=0; evIt<eventArray.length; evIt++)
  3255. {
  3256. var oo='',
  3257. note='',
  3258. start='',
  3259. end='',
  3260. title='',
  3261. location='',
  3262. all=false,
  3263. frequency='',
  3264. interval='',
  3265. byMonthDay='',
  3266. byDay='',
  3267. until='',
  3268. isUntilDate=false,
  3269. isRepeat=false,
  3270. alertTime=new Array(),
  3271. alertNote=new Array(),
  3272. alertTimeOut=new Array(),
  3273. valOffsetFrom='',
  3274. valOffsetTo='',
  3275. intOffset=0,
  3276. tzName='local',
  3277. realStart='',
  3278. realEnd='',
  3279. rec_id='',
  3280. wkst='',
  3281. classType='',
  3282. avail='',
  3283. hrefUrl='',
  3284. returnForValue = true,
  3285. stringUID='',
  3286. priority="0",
  3287. status='',
  3288. pars=new Array();
  3289. var dtStartTimezone='';
  3290. var dates = new Array();
  3291. var vcalendar=eventArray[evIt];
  3292. var stringUID=vcalendar.match(vCalendar.pre['contentline_UID']);
  3293. if(stringUID!=null)
  3294. stringUID=stringUID[0].match(vCalendar.pre['contentline_parse'])[4];
  3295. var exDates=new Array();
  3296. var exDate=null;
  3297. var exDate_array=new Array();
  3298. var vcalendar2=vcalendar+'';
  3299. while(vcalendar2.match(vCalendar.pre['contentline_EXDATE'])!= null)
  3300. {
  3301. exDate=vcalendar2.match(vCalendar.pre['contentline_EXDATE']);
  3302. exDate_array[exDate_array.length]=exDate[0];
  3303. vcalendar2=vcalendar2.replace(exDate,'\r\n');
  3304. }
  3305. vcalendar_element=vcalendar.match(vCalendar.pre['contentline_RRULE2']);
  3306. if(vcalendar_element!=null)
  3307. {
  3308. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3309. // || ((parsed[4].indexOf('FREQ=MONTHLY')!=-1||parsed[4].indexOf('FREQ=YEARLY')!=-1)&&parsed[4].indexOf('BYDAY')!=-1)&&parsed[4].search('[0-9]')==-1)
  3310. // if(parsed[4].indexOf('BYSETPOS')!=-1 || parsed[4].indexOf('BYWEEKNO')!=-1)
  3311. // {
  3312. // console.log("Error:'"+inputEvent.uid+"': Unsupported recurrence rule in event:"+vcalendar);
  3313. // return false;
  3314. // }
  3315. pars=parsed[4].split(';');
  3316. var parString='';
  3317. if(pars.length>0)
  3318. isRepeat=true;
  3319. for(var i=0;i<pars.length;i++)
  3320. {
  3321. if(pars[i].indexOf('FREQ=')!=-1)
  3322. frequency=pars[i].split('=')[1];
  3323. else if(pars[i].indexOf('INTERVAL=')!=-1)
  3324. interval=pars[i].split('=')[1];
  3325. else if(pars[i].indexOf('COUNT=')!=-1)
  3326. {
  3327. until=pars[i].split('=')[1];
  3328. if(until==0)
  3329. {
  3330. returnForValue = false;
  3331. break
  3332. }
  3333. else if(isNaN(until))
  3334. {
  3335. returnForValue = false;
  3336. break
  3337. }
  3338. }
  3339. else if(pars[i].indexOf('UNTIL=')!=-1)
  3340. {
  3341. isUntilDate=true;
  3342. until=pars[i].split('=')[1];
  3343. //if(until.indexOf('T')==-1)
  3344. // until+='T000000Z';
  3345. }
  3346. else if(pars[i].indexOf('WKST=')!=-1)
  3347. {
  3348. wkst=pars[i].split('=')[1].replace(/\d*MO/,1).replace(/\d*TU/,2).replace(/\d*WE/,3).replace(/\d*TH/,4).replace(/\d*FR/,5).replace(/\d*SA/,6).replace(/\d*SU/,0);
  3349. if(globalSettings.mozillasupport.value!=null && globalSettings.mozillasupport.value)
  3350. wkst='';
  3351. }
  3352. else if(pars[i].indexOf('BYMONTHDAY=')!=-1)
  3353. byMonthDay=pars[i].split('=')[1];
  3354. else if(pars[i].indexOf('BYDAY=')!=-1)
  3355. {
  3356. byDay=pars[i].split('=')[1];
  3357. byDay=byDay.replace(/\d*MO/,1).replace(/\d*TU/,2).replace(/\d*WE/,3).replace(/\d*TH/,4).replace(/\d*FR/,5).replace(/\d*SA/,6).replace(/\d*SU/,0).split(',');
  3358. if(byDay.length>1 &&(frequency=='MONTHLY'||frequency=='YEARLY'))
  3359. {
  3360. console.log("Error:'"+inputEvent.uid+"': Unsupported recurrence rule in event:"+vcalendar);
  3361. return false;
  3362. }
  3363. }
  3364. }
  3365. if(!returnForValue)
  3366. {
  3367. continue;
  3368. }
  3369. if(!interval)
  3370. interval=1;
  3371. }
  3372. var dayLightStartDate, dayLightEndDate, tzObject;
  3373. vcalendar_element=vcalendar.match(vCalendar.pre['contentline_DTSTART']);
  3374. if(vcalendar_element!=null)
  3375. {
  3376. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3377. start=parsed[4];
  3378. var help1=start;
  3379. if(help1.indexOf("T")==-1)
  3380. {
  3381. help1=help1.substring(0, 4)+'-'+help1.substring(4, 6)+'-'+help1.substring(6, 8);
  3382. all=true;
  3383. }
  3384. else
  3385. {
  3386. help1=help1.substring(0, 4)+'-'+help1.substring(4, 6)+'-'+help1.substring(6, 8)+'T'+help1.substring(9, 11)+':'+help1.substring(11, 13)+':'+help1.substring(13, 15);
  3387. all=false;
  3388. }
  3389. var t=$.fullCalendar.parseDate(help1);
  3390. if(t==null)
  3391. return false;
  3392. if(t.toString()=='Invalid Date')
  3393. return false;
  3394. if(!all)
  3395. {
  3396. parsed_value=vcalendarSplitParam(parsed[3]);
  3397. for(h=1;h<parsed_value.length;h++)
  3398. if(parsed_value[h]!='')
  3399. dtStartTimezone=parsed_value[h];
  3400. dtStartTimezone=dtStartTimezone.split('=')
  3401. if(start.charAt(start.length-1)=='Z')
  3402. tzName='UTC';
  3403. if(dtStartTimezone.length>1 || tzName=='UTC')
  3404. {
  3405. if(tzName!='UTC')
  3406. tzName=$.trim(dtStartTimezone[1]);
  3407. var finTZ = checkTimezone(tzName);
  3408. if(finTZ!=null)
  3409. tzName = finTZ;
  3410. if(globalSettings.timezonesupport.value && tzName in timezones)
  3411. {
  3412. valOffsetFrom=getOffsetByTZ(tzName, t);
  3413. intOffset=(getLocalOffset(t)*-1*1000)-valOffsetFrom.getSecondsFromOffset()*1000;
  3414. }
  3415. }
  3416. else if(processedTimezones.indexOf(tzName)==-1)
  3417. {
  3418. if(timeZonesEnabled.indexOf(tzName)==-1)
  3419. timeZonesEnabled.push('local');
  3420. processedTimezones.push('local');
  3421. }
  3422. if(tzName!='' && tzName != 'local')
  3423. if(processedTimezones.indexOf(tzName)==-1)
  3424. {
  3425. if(timeZonesEnabled.indexOf(tzName)==-1)
  3426. timeZonesEnabled.push(tzName);
  3427. processedTimezones.push(tzName);
  3428. }
  3429. }
  3430. else
  3431. tzName = globalSessionTimeZone;
  3432. realStart=$.fullCalendar.parseDate(help1);
  3433. inputEvent.start=$.fullCalendar.parseDate(help1);
  3434. start=$.fullCalendar.parseDate(help1);
  3435. if(intOffset)
  3436. {
  3437. inputEvent.start.setTime(inputEvent.start.getTime()+intOffset);
  3438. start.setTime(start.getTime()+intOffset);
  3439. }
  3440. if(exDate_array!=null)
  3441. for(var j=0;j<exDate_array.length;j++)
  3442. {
  3443. var exString=(exDate_array[j]+'\r\n').match(vCalendar.pre['contentline_parse'])[4];
  3444. if(exString.indexOf('T')!=-1 && exString.indexOf('Z')!=-1)
  3445. var utcTime=exString.parseComnpactISO8601().setSeconds(getLocalOffset(exString.parseComnpactISO8601())*-1);
  3446. else if(exString.indexOf('T')!=-1 && exString.indexOf('Z')==-1)
  3447. var utcTime=exString.parseComnpactISO8601();
  3448. else
  3449. {
  3450. if(help1.indexOf('T')!=-1)
  3451. exString += 'T' + $.fullCalendar.formatDate(start,'HHmmss');
  3452. var utcTime=exString.parseComnpactISO8601();
  3453. }
  3454. exDates[exDates.length]=new Date(utcTime).toString();
  3455. }
  3456. var valarm=vcalendar.match(vCalendar.pre['valarm']);
  3457. if(valarm!=null)
  3458. {
  3459. vcalendar=vcalendar.replace(valarm[0], '');
  3460. var alarmString='';
  3461. var alarmArray=new Array();
  3462. for(var i=0;i<valarm[0].length;i++)
  3463. {
  3464. if(valarm[0].substring(i-'END:VALARM'.length, i)=='END:VALARM')
  3465. {
  3466. alarmArray[alarmArray.length]=alarmString+'\r\n';
  3467. alarmString='';
  3468. }
  3469. alarmString+=valarm[0][i];
  3470. }
  3471. for(var j=0;j<alarmArray.length;j++)
  3472. {
  3473. checkA=alarmArray[j].match(vCalendar.re['valarm']);
  3474. if(checkA!=null)
  3475. {
  3476. action=(alarmArray[j]).match(vCalendar.pre['contentline_ACTION']);
  3477. if(action!=null)
  3478. parsed=action[0].match(vCalendar.pre['contentline_parse']);
  3479. else
  3480. break;
  3481. trigger=alarmArray[j].match(vCalendar.pre['contentline_TRIGGER']);
  3482. if(trigger!=null)
  3483. {
  3484. parsed=(trigger[0]+'\r\n').match(vCalendar.pre['contentline_parse']);
  3485. if(parsed!=null)
  3486. {
  3487. value=parsed[4];
  3488. var checkD=value.match(vCalendar.pre['date-time-value']);
  3489. var intOffsetA='';
  3490. var tzNameA='';
  3491. if(checkD!=null)
  3492. {
  3493. if(parsed[3])
  3494. var dtStartTimezoneA=parsed[3].split('=');
  3495. var alarmTimeA=$.fullCalendar.parseDate(value.substring(0, 4)+'-'+value.substring(4, 6)+'-'+value.substring(6, 8)+'T'+value.substring(9, 11)+':'+value.substring(11, 13)+':'+value.substring(13, 15));
  3496. if(value.charAt(value.length-1)=='Z')
  3497. tzNameA='UTC';
  3498. if(dtStartTimezoneA.length>1 || tzNameA=='UTC')
  3499. {
  3500. if(tzNameA!='UTC' && dtStartTimezoneA[0]==';TZID')
  3501. tzNameA=$.trim(dtStartTimezoneA[1]);
  3502. var finTZ = checkTimezone(tzNameA);
  3503. if(finTZ!=null)
  3504. tzNameA = finTZ;
  3505. if(globalSettings.timezonesupport.value && tzNameA in timezones)
  3506. {
  3507. var valOffsetFromA=getOffsetByTZ(tzNameA, alarmTimeA);
  3508. intOffsetA=getOffsetByTZ(tzName, alarmTimeA).getSecondsFromOffset()*1000-valOffsetFromA.getSecondsFromOffset()*1000;
  3509. }
  3510. }
  3511. else if(processedTimezones.indexOf(tzName)==-1)
  3512. {
  3513. if(timeZonesEnabled.indexOf(tzName)==-1)
  3514. timeZonesEnabled.push('local');
  3515. processedTimezones.push('local');
  3516. }
  3517. if(tzNameA!='' && tzNameA != 'local')
  3518. if(processedTimezones.indexOf(tzNameA)==-1)
  3519. {
  3520. if(timeZonesEnabled.indexOf(tzNameA)==-1)
  3521. timeZonesEnabled.push(tzNameA);
  3522. processedTimezones.push(tzNameA);
  3523. }
  3524. if(intOffsetA!='')
  3525. alarmTimeA.setTime(alarmTimeA.getTime()+intOffsetA);
  3526. alertTime[j]=$.fullCalendar.formatDate(alarmTimeA,"yyyy-MM-dd'T'HH:mm:ss");
  3527. }
  3528. else
  3529. {
  3530. alertTime[j]=0;
  3531. if(value.indexOf('W')!=-1)
  3532. alertTime[j]=parseAlarmWeek(value);
  3533. else if(value.indexOf('D')!=-1)
  3534. alertTime[j]=parseAlarmDay(value);
  3535. else if(value.indexOf('T')!=-1)
  3536. alertTime[j]=parseAlarmTime(value);
  3537. if(parsed[4].charAt(0)=="-")
  3538. alertTime[j]="-"+alertTime[j];
  3539. else
  3540. alertTime[j]="+"+alertTime[j];
  3541. }
  3542. }
  3543. }
  3544. else
  3545. break;
  3546. noteA=alarmArray[j].match(vCalendar.pre['contentline_NOTE']);
  3547. if(noteA!=null)
  3548. {
  3549. parsed=noteA[0].match(vCalendar.pre['contentline_parse']);
  3550. alertNote[j]=parsed[4];
  3551. }
  3552. else
  3553. alertNote[j]='Default note';
  3554. }
  3555. }
  3556. }
  3557. vcalendar_element=vcalendar.match(vCalendar.pre['contentline_LOCATION']);
  3558. if(vcalendar_element!=null)
  3559. {
  3560. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3561. location=vcalendarUnescapeValue(parsed[4]);
  3562. }
  3563. vcalendar_element=vcalendar.match(vCalendar.pre['contentline_NOTE']);
  3564. if(vcalendar_element!=null)
  3565. {
  3566. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3567. note=vcalendarUnescapeValue(parsed[4]);
  3568. }
  3569. vcalendar_element=vcalendar.match(vCalendar.pre['contentline_SUMMARY']);
  3570. if(vcalendar_element!=null)
  3571. {
  3572. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3573. title=vcalendarUnescapeValue(parsed[4]);
  3574. }
  3575. vcalendar_element=vcalendar.match(vCalendar.pre['contentline_PRIORITY']);
  3576. if(vcalendar_element!=null)
  3577. {
  3578. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3579. priority=vcalendarUnescapeValue(parsed[4]);
  3580. }
  3581. var index=0;
  3582. for(var p=0;p<globalResourceCalDAVList.collections.length;p++)
  3583. if(typeof globalResourceCalDAVList.collections[p].uid !='undefined' && globalResourceCalDAVList.collections[p].uid==inputCollection.uid)
  3584. {
  3585. index=p;
  3586. break;
  3587. }
  3588. var firstPart=index.pad(String(globalResourceCalDAVList.collections.length).length);
  3589. var compareString=(firstPart + title).toLowerCase();
  3590. vcalendar_element=vcalendar.match(vCalendar.pre['contentline_CLASS']);
  3591. if(vcalendar_element!=null)
  3592. {
  3593. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3594. classType=vcalendarUnescapeValue(parsed[4]);
  3595. }
  3596. vcalendar_element=vcalendar.match(vCalendar.pre['contentline_STATUS']);
  3597. if(vcalendar_element!=null)
  3598. {
  3599. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3600. status=vcalendarUnescapeValue(parsed[4]);
  3601. }
  3602. vcalendar_element=vcalendar.match(vCalendar.pre['contentline_TRANSP']);
  3603. if(vcalendar_element!=null)
  3604. {
  3605. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3606. avail=vcalendarUnescapeValue(parsed[4]);
  3607. }
  3608. vcalendar_element=vcalendar.match(vCalendar.pre['contentline_URL']);
  3609. if(vcalendar_element!=null)
  3610. {
  3611. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3612. hrefUrl=vcalendarUnescapeValue(parsed[4]);
  3613. }
  3614. vcalendar_element=vcalendar.match(vCalendar.pre['contentline_RECURRENCE_ID']);
  3615. if(vcalendar_element!=null)
  3616. {
  3617. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3618. var rec=parsed[4];
  3619. /*if(rec.indexOf("T")==-1)
  3620. {
  3621. rec=rec.substring(0, 4)+'/'+rec.substring(4, 6)+'/'+rec.substring(6, 8);
  3622. var d=$.fullCalendar.parseDate(rec);
  3623. var da=new Date(d.getTime()-1*24*60*60*1000);
  3624. var day=da.getDate();
  3625. if(day<10)
  3626. day='0'+day;
  3627. var month=da.getMonth();
  3628. month++;
  3629. if(month<10)
  3630. month='0'+month;
  3631. rec=da.getFullYear()+'-'+month+'-'+day;
  3632. }
  3633. else
  3634. rec=rec.substring(0, 4)+'-'+rec.substring(4, 6)+'-'+rec.substring(6, 8)+'T'+rec.substring(9, 11)+':'+rec.substring(11, 13)+':'+rec.substring(13, 15);
  3635. rec_id=$.fullCalendar.parseDate(rec);*/
  3636. //if(!rec_id || rec_id=='Invalid Date')
  3637. // rec_id='';
  3638. rec_id=rec;
  3639. }
  3640. var isDuration = false;
  3641. var dur = 0;
  3642. vcalendar_element=vcalendar.match(vCalendar.pre['contentline_DTEND']);
  3643. if(vcalendar_element!=null)
  3644. {
  3645. parsed=vcalendar_element[0].match(vCalendar.pre['contentline_parse']);
  3646. end=parsed[4];
  3647. var help=end;
  3648. if(help.indexOf("T")==-1)
  3649. {
  3650. help=help.substring(0, 4)+'-'+help.substring(4, 6)+'-'+help.substring(6, 8);
  3651. var d=$.fullCalendar.parseDate(help);
  3652. var da=new Date(d.getTime());
  3653. if(help1.indexOf("T")==-1)
  3654. da.setDate(da.getDate()-1);
  3655. help=$.fullCalendar.formatDate(da, "yyyy-MM-dd");
  3656. all=true;
  3657. if(help1.indexOf("T")!=-1)
  3658. {
  3659. all=false;
  3660. help+='T00:00:00';
  3661. if(tzName == 'UTC')
  3662. help+='Z';
  3663. }
  3664. }
  3665. else
  3666. {
  3667. help=help.substring(0, 4)+'-'+help.substring(4, 6)+'-'+help.substring(6, 8)+'T'+help.substring(9, 11)+':'+help.substring(11, 13)+':'+help.substring(13, 15);
  3668. all=false;
  3669. }
  3670. }
  3671. else
  3672. {
  3673. var checkDur=vcalendar.match(vCalendar.pre['dur-value']);
  3674. if(checkDur!=null)
  3675. {
  3676. var checkP = (checkDur[0]+'\r\n').match(vCalendar.pre['contentline_parse']);
  3677. if(checkP != null)
  3678. {
  3679. var value=checkP[4];
  3680. var number = 0;
  3681. if(value.indexOf('W')!=-1)
  3682. number=parseAlarmWeek(value);
  3683. else if(value.indexOf('D')!=-1)
  3684. number=parseAlarmDay(value);
  3685. else if(value.indexOf('T')!=-1)
  3686. number=parseAlarmTime(value);
  3687. if(parsed[4].charAt(0)=="-")
  3688. number="-"+number;
  3689. else
  3690. number="+"+number;
  3691. dur=parseInt(number.substring(1, number.length-1),10);
  3692. isDuration = true;
  3693. }
  3694. }
  3695. }
  3696. if(isDuration)
  3697. {
  3698. var st='';
  3699. if(!all)
  3700. st = $.fullCalendar.parseDate(help1);
  3701. else
  3702. {
  3703. st = $.fullCalendar.parseDate(help1+'T00:00:00');
  3704. //date object mindfuck problem
  3705. st.setMilliseconds(-1);
  3706. }
  3707. var durDate = new Date(st.getTime() + dur);
  3708. help = $.fullCalendar.formatDate(durDate,"yyyy-MM-dd'T'HH:mm:ss");
  3709. }
  3710. if(typeof help=='undefined' || help=='' || help==null)
  3711. help=help1;
  3712. var t1=$.fullCalendar.parseDate(help);
  3713. if(t1==null)
  3714. return false;
  3715. else if(t1.toString()=='Invalid Date')
  3716. return false;
  3717. if(!all)
  3718. {
  3719. if(end.charAt(end.length-1)=='Z')
  3720. tzName='UTC';
  3721. if(dtStartTimezone.length>1 || tzName=='UTC')
  3722. {
  3723. if(tzName!='UTC')
  3724. tzName=$.trim(dtStartTimezone[1]);
  3725. var finTZ = checkTimezone(tzName);
  3726. if(finTZ!=null)
  3727. tzName = finTZ;
  3728. if(globalSettings.timezonesupport.value && tzName in timezones)
  3729. {
  3730. valOffsetFrom=getOffsetByTZ(tzName, t1);
  3731. intOffset=(getLocalOffset(t1)*-1*1000)-valOffsetFrom.getSecondsFromOffset()*1000;
  3732. }
  3733. }
  3734. else if(processedTimezones.indexOf(tzName)==-1)
  3735. {
  3736. if(timeZonesEnabled.indexOf(tzName)==-1)
  3737. timeZonesEnabled.push('local');
  3738. processedTimezones.push('local');
  3739. }
  3740. //realEnd=$.fullCalendar.parseDate(help);
  3741. //help1+=valOffsetFrom;
  3742. if(tzName!='' && tzName != 'local')
  3743. if(processedTimezones.indexOf(tzName)==-1)
  3744. {
  3745. if(timeZonesEnabled.indexOf(tzName)==-1)
  3746. timeZonesEnabled.push(tzName);
  3747. processedTimezones.push(tzName);
  3748. }
  3749. }
  3750. else
  3751. tzName = globalSessionTimeZone;
  3752. realEnd=$.fullCalendar.parseDate(help);
  3753. inputEvent.end=$.fullCalendar.parseDate(help);
  3754. end=$.fullCalendar.parseDate(help);
  3755. if(intOffset)
  3756. {
  3757. inputEvent.end.setTime(inputEvent.end.getTime()+intOffset);
  3758. end.setTime(end.getTime()+intOffset);
  3759. }
  3760. }
  3761. else
  3762. return false;
  3763. if(globalVisibleCalDAVCollections.indexOf(rid)!=-1 || isChange || isNew)
  3764. {
  3765. if(isRepeat)
  3766. {
  3767. var futureRLimit = new Date(globalToLoadedLimit.getTime())
  3768. futureRLimit.setDate(futureRLimit.getDate()+14);
  3769. var ruleString=vcalendar.match(vCalendar.pre['contentline_RRULE2'])[0].match(vCalendar.pre['contentline_parse'])[4];
  3770. inputEvent.isRepeat=true;
  3771. if(realStart)
  3772. var varDate=new Date(realStart.getTime());
  3773. else
  3774. var varDate=new Date(start.getTime());
  3775. if(realEnd)
  3776. var varEndDate=new Date(realEnd.getTime());
  3777. else
  3778. var varEndDate=new Date(end.getTime());
  3779. var lastGenDate='';
  3780. var repeatStart=new Date(varDate.getTime());
  3781. var repeatEnd=new Date(varEndDate.getTime());
  3782. var untilDate='',realUntilDate='',realUntil='';
  3783. if(until!=='')
  3784. {
  3785. if(isUntilDate)
  3786. {
  3787. if(until.indexOf('T')!=-1)
  3788. {
  3789. var uString = until.substring(0, 4)+'-'+until.substring(4, 6)+'-'+until.substring(6, 8)+'T'+until.substring(9, 11)+':'+until.substring(11, 13)+':'+until.substring(13, 15);
  3790. var ut=$.fullCalendar.parseDate(uString);
  3791. if(ut==null)
  3792. return false;
  3793. if(ut.toString()=='Invalid Date')
  3794. return false;
  3795. if(!all)
  3796. {
  3797. if(globalSettings.timezonesupport.value && tzName in timezones)
  3798. valOffsetFrom=getOffsetByTZ(tzName, ut);
  3799. if(valOffsetFrom)
  3800. {
  3801. var intOffset=valOffsetFrom.getSecondsFromOffset()*1000;
  3802. ut.setTime(ut.getTime()+intOffset);
  3803. }
  3804. }
  3805. untilDate = new Date(ut.getTime());
  3806. }
  3807. else
  3808. {
  3809. untilDate=$.fullCalendar.parseDate(until.substring(0, 4)+'-'+until.substring(4, 6)+'-'+until.substring(6, 8));
  3810. untilDate.setHours(realStart.getHours());
  3811. untilDate.setMinutes(realStart.getMinutes());
  3812. untilDate.setSeconds(realStart.getSeconds());
  3813. }
  3814. realUntil='';
  3815. }
  3816. else
  3817. {
  3818. untilDate='';
  3819. realUntil=until;
  3820. }
  3821. realUntilDate=untilDate;
  3822. inputEvent.untilDate=untilDate;
  3823. }
  3824. else
  3825. {
  3826. untilDate=new Date(futureRLimit.getTime());
  3827. realUntilDate='';
  3828. inputEvent.untilDate='never';
  3829. }
  3830. var repeatCount=0, realRepeatCount=0;
  3831. if(!inputEvent.isDrawn)
  3832. {
  3833. if(alertTime.length>0)
  3834. {
  3835. var aTime='';
  3836. var now=new Date();
  3837. if(!inputCollection.ignoreAlarms)
  3838. alertTimeOut=setAlertTimeouts(false,alertTime, start, end, {allDay:all, title:title}, true, inputEvent.uid);
  3839. }
  3840. realRepeatCount++;
  3841. var checkRec=isInRecurrenceArray(varDate,stringUID,recurrence_id_array, tzName);
  3842. if(exDates.length>0)
  3843. if(exDates.indexOf(varDate.toString())!=-1)
  3844. checkRec=true;
  3845. if(!checkRec)
  3846. {
  3847. repeatCount++;
  3848. var tmpObj=new items(inputEvent.etag, start, end, title, all, inputEvent.uid, rid, evid, note, inputEvent.displayValue, alertTime, alertNote, realUntilDate, frequency, interval, realUntil, repeatStart, repeatEnd, byMonthDay,repeatCount, realRepeatCount, vcalendar, location, alertTimeOut,tzName, realStart, realEnd, byDay, rec_id,wkst,classType, avail,hrefUrl, compareString,priority,status,ruleString);
  3849. globalEventList.displayEventsArray[rid].splice(globalEventList.displayEventsArray[rid].length, 0, tmpObj);
  3850. }
  3851. }
  3852. var lastGenDate=generateRepeatInstances({
  3853. untilDate:realUntilDate,
  3854. repeatStart:varDate,
  3855. futureRLimit:futureRLimit,
  3856. stringUID:stringUID,
  3857. recurrence_id_array:recurrence_id_array,
  3858. exDates:exDates,
  3859. alertTime:alertTime,
  3860. ignoreAlarms:inputCollection.ignoreAlarms,
  3861. items:new items(inputEvent.etag, varDate, varEndDate, title, all, inputEvent.uid, rid, evid, note, inputEvent.displayValue, alertTime, alertNote, realUntilDate, frequency, interval, realUntil, repeatStart, repeatEnd, byMonthDay, repeatCount, realRepeatCount, vcalendar, location, alertTimeOut, tzName, realStart, realEnd, byDay, rec_id,wkst,classType, avail,hrefUrl,compareString,priority,status,ruleString)
  3862. });
  3863. }
  3864. else
  3865. {
  3866. if(!inputCollection.ignoreAlarms)
  3867. alertTimeOut=setAlertTimeouts(false,alertTime, start, end, {allDay:all, title:title},true,inputEvent.uid);
  3868. var tmpObj=new items(inputEvent.etag, start, end, title, all, inputEvent.uid, rid, evid, note, inputEvent.displayValue, alertTime, alertNote, '', '', '', '', '', '', '', '', '', vcalendar, location, alertTimeOut, tzName, realStart, realEnd, byDay, rec_id,wkst,classType, avail,hrefUrl,compareString,priority,status,ruleString);
  3869. if(isChange)
  3870. {
  3871. if(needReload)
  3872. showEventForm(null, null, tmpObj, globalJsEvent, 'show', '');
  3873. }
  3874. globalEventList.displayEventsArray[rid].splice(globalEventList.displayEventsArray[rid].length, 0, tmpObj);
  3875. }
  3876. }
  3877. }
  3878. inputEvent.isDrawn=true;
  3879. }
  3880. function notRFCDataToRFCData(vcalendarString)
  3881. {
  3882. // If vCalendar contains only '\n' instead of '\r\n' we correct this
  3883. if(vcalendarString.match(RegExp('\r', 'm'))==null)
  3884. vcalendarString=vcalendarString.replace(RegExp('\n', 'gm'), '\r\n');
  3885. // remove multiple empty lines
  3886. vcalendarString=vcalendarString.replace(RegExp('(\r\n)+','gm'),'\r\n');
  3887. // remove line folding
  3888. vcalendarString=vcalendarString.replace(RegExp('\r\n'+vCalendar.re['WSP'], 'gm'), '');
  3889. // append '\r\n' to the end of the vCalendar if missing
  3890. if(vcalendarString[vcalendarString.length-1]!='\n')
  3891. vcalendarString+='\r\n';
  3892. return vcalendarString;
  3893. }
  3894. function vCalendarCleanup(vcalendarString)
  3895. {
  3896. vcalendarString=notRFCDataToRFCData(vcalendarString);
  3897. return vcalendarString;
  3898. }