1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450 |
- <?php
- ?>
- <?php
- include_once('class.baserecurrence.php');
-
- class Recurrence extends BaseRecurrence {
-
-
- var $recipprops = Array(
- PR_ENTRYID,
- PR_SEARCH_KEY,
- PR_DISPLAY_NAME,
- PR_EMAIL_ADDRESS,
- PR_RECIPIENT_ENTRYID,
- PR_RECIPIENT_TYPE,
- PR_SEND_INTERNET_ENCODING,
- PR_SEND_RICH_INFO,
- PR_RECIPIENT_DISPLAY_NAME,
- PR_ADDRTYPE,
- PR_DISPLAY_TYPE,
- PR_DISPLAY_TYPE_EX,
- PR_RECIPIENT_TRACKSTATUS,
- PR_RECIPIENT_TRACKSTATUS_TIME,
- PR_RECIPIENT_FLAGS,
- PR_ROWID
- );
-
- function __construct($store, $message)
- {
- $properties = array();
- $properties["entryid"] = PR_ENTRYID;
- $properties["parent_entryid"] = PR_PARENT_ENTRYID;
- $properties["message_class"] = PR_MESSAGE_CLASS;
- $properties["icon_index"] = PR_ICON_INDEX;
- $properties["subject"] = PR_SUBJECT;
- $properties["display_to"] = PR_DISPLAY_TO;
- $properties["importance"] = PR_IMPORTANCE;
- $properties["sensitivity"] = PR_SENSITIVITY;
- $properties["startdate"] = "PT_SYSTIME:PSETID_Appointment:0x820d";
- $properties["duedate"] = "PT_SYSTIME:PSETID_Appointment:0x820e";
- $properties["recurring"] = "PT_BOOLEAN:PSETID_Appointment:0x8223";
- $properties["recurring_data"] = "PT_BINARY:PSETID_Appointment:0x8216";
- $properties["busystatus"] = "PT_LONG:PSETID_Appointment:0x8205";
- $properties["label"] = "PT_LONG:PSETID_Appointment:0x8214";
- $properties["alldayevent"] = "PT_BOOLEAN:PSETID_Appointment:0x8215";
- $properties["private"] = "PT_BOOLEAN:PSETID_Common:0x8506";
- $properties["meeting"] = "PT_LONG:PSETID_Appointment:0x8217";
- $properties["startdate_recurring"] = "PT_SYSTIME:PSETID_Appointment:0x8235";
- $properties["enddate_recurring"] = "PT_SYSTIME:PSETID_Appointment:0x8236";
- $properties["recurring_pattern"] = "PT_STRING8:PSETID_Appointment:0x8232";
- $properties["location"] = "PT_STRING8:PSETID_Appointment:0x8208";
- $properties["duration"] = "PT_LONG:PSETID_Appointment:0x8213";
- $properties["responsestatus"] = "PT_LONG:PSETID_Appointment:0x8218";
- $properties["reminder"] = "PT_BOOLEAN:PSETID_Common:0x8503";
- $properties["reminder_minutes"] = "PT_LONG:PSETID_Common:0x8501";
- $properties["recurrencetype"] = "PT_LONG:PSETID_Appointment:0x8231";
- $properties["contacts"] = "PT_MV_STRING8:PSETID_Common:0x853a";
- $properties["contacts_string"] = "PT_STRING8:PSETID_Common:0x8586";
- $properties["categories"] = "PT_MV_STRING8:PS_PUBLIC_STRINGS:Keywords";
- $properties["reminder_time"] = "PT_SYSTIME:PSETID_Common:0x8502";
- $properties["commonstart"] = "PT_SYSTIME:PSETID_Common:0x8516";
- $properties["commonend"] = "PT_SYSTIME:PSETID_Common:0x8517";
- $properties["basedate"] = "PT_SYSTIME:PSETID_Appointment:0x8228";
- $properties["timezone_data"] = "PT_BINARY:PSETID_Appointment:0x8233";
- $properties["timezone"] = "PT_STRING8:PSETID_Appointment:0x8234";
- $properties["flagdueby"] = "PT_SYSTIME:PSETID_Common:0x8560";
- $properties["side_effects"] = "PT_LONG:PSETID_Common:0x8510";
- $properties["hideattachments"] = "PT_BOOLEAN:PSETID_Common:0x8514";
- $this->proptags = getPropIdsFromStrings($store, $properties);
- parent::__construct($store, $message);
- }
-
- function createException($exception_props, $base_date, $delete = false, $exception_recips = array(), $copy_attach_from = false)
- {
- $baseday = $this->dayStartOf($base_date);
- $basetime = $baseday + $this->recur["startocc"] * 60;
-
- if ($this->isException($baseday))
- $this->deleteException($baseday);
- if(!$delete) {
- if (isset($exception_props[$this->proptags["startdate"]]) && !$this->isValidExceptionDate($base_date, $this->fromGMT($this->tz, $exception_props[$this->proptags["startdate"]])))
- return false;
-
- foreach (array("subject", "location", "label", "reminder", "reminder_minutes", "alldayevent", "busystatus") as $propname)
- if(isset($this->messageprops[$this->proptags[$propname]]))
- $props[$this->proptags[$propname]] = $this->messageprops[$this->proptags[$propname]];
-
- $props[PR_MESSAGE_CLASS] = "IPM.OLE.CLASS.{00061055-0000-0000-C000-000000000046}";
- unset($exception_props[PR_MESSAGE_CLASS]);
- unset($exception_props[PR_ICON_INDEX]);
- $props = $exception_props + $props;
-
-
- $props[$this->proptags["basedate"]] = $this->toGMT($this->tz, $basetime);
- if (!isset($exception_props[$this->proptags["startdate"]]))
- $props[$this->proptags["startdate"]] = $this->getOccurrenceStart($base_date);
- if (!isset($exception_props[$this->proptags["duedate"]]))
- $props[$this->proptags["duedate"]] = $this->getOccurrenceEnd($base_date);
-
- if (isset($props[$this->proptags["startdate"]]))
- $props[$this->proptags["commonstart"]] = $props[$this->proptags["startdate"]];
- if (isset($props[$this->proptags["duedate"]]))
- $props[$this->proptags["commonend"]] = $props[$this->proptags["duedate"]];
-
- $this->createExceptionAttachment($props, $exception_recips, $copy_attach_from);
-
- $changed_item = array();
-
- $changed_item["basedate"] = $baseday;
- $changed_item["start"] = $this->fromGMT($this->tz, $props[$this->proptags["startdate"]]);
- $changed_item["end"] = $this->fromGMT($this->tz, $props[$this->proptags["duedate"]]);
- if (array_key_exists($this->proptags["subject"], $exception_props))
- $changed_item["subject"] = $exception_props[$this->proptags["subject"]];
- if (array_key_exists($this->proptags["location"], $exception_props))
- $changed_item["location"] = $exception_props[$this->proptags["location"]];
- if (array_key_exists($this->proptags["label"], $exception_props))
- $changed_item["label"] = $exception_props[$this->proptags["label"]];
- if (array_key_exists($this->proptags["reminder"], $exception_props))
- $changed_item["reminder_set"] = $exception_props[$this->proptags["reminder"]];
- if (array_key_exists($this->proptags["reminder_minutes"], $exception_props))
- $changed_item["remind_before"] = $exception_props[$this->proptags["reminder_minutes"]];
- if (array_key_exists($this->proptags["alldayevent"], $exception_props))
- $changed_item["alldayevent"] = $exception_props[$this->proptags["alldayevent"]];
- if (array_key_exists($this->proptags["busystatus"], $exception_props))
- $changed_item["busystatus"] = $exception_props[$this->proptags["busystatus"]];
-
- array_push($this->recur["changed_occurences"], $changed_item);
- } else {
-
- array_push($this->recur["deleted_occurences"], $baseday);
- }
-
-
- mapi_setprops($this->message, array ( $this->proptags["hideattachments"] => true ));
-
- $this->saveRecurrence();
-
- return true;
- }
-
-
- function modifyException($exception_props, $base_date, $exception_recips = array(), $copy_attach_from = false)
- {
- if (isset($exception_props[$this->proptags["startdate"]]) && !$this->isValidExceptionDate($base_date, $this->fromGMT($this->tz, $exception_props[$this->proptags["startdate"]])))
- return false;
-
- $baseday = $this->dayStartOf($base_date);
- $basetime = $baseday + $this->recur["startocc"] * 60;
- $extomodify = false;
- for($i = 0, $len = count($this->recur["changed_occurences"]); $i < $len; $i++)
- if($this->isSameDay($this->recur["changed_occurences"][$i]["basedate"], $baseday))
- $extomodify = &$this->recur["changed_occurences"][$i];
-
- if(!$extomodify)
- return false;
-
-
- unset($exception_props[$this->proptags["basedate"]]);
- if (array_key_exists($this->proptags["startdate"], $exception_props))
- $extomodify["start"] = $this->fromGMT($this->tz, $exception_props[$this->proptags["startdate"]]);
- if (array_key_exists($this->proptags["duedate"], $exception_props))
- $extomodify["end"] = $this->fromGMT($this->tz, $exception_props[$this->proptags["duedate"]]);
- if (array_key_exists($this->proptags["subject"], $exception_props))
- $extomodify["subject"] = $exception_props[$this->proptags["subject"]];
- if (array_key_exists($this->proptags["location"], $exception_props))
- $extomodify["location"] = $exception_props[$this->proptags["location"]];
- if (array_key_exists($this->proptags["label"], $exception_props))
- $extomodify["label"] = $exception_props[$this->proptags["label"]];
- if (array_key_exists($this->proptags["reminder"], $exception_props))
- $extomodify["reminder_set"] = $exception_props[$this->proptags["reminder"]];
- if (array_key_exists($this->proptags["reminder_minutes"], $exception_props))
- $extomodify["remind_before"] = $exception_props[$this->proptags["reminder_minutes"]];
- if (array_key_exists($this->proptags["alldayevent"], $exception_props))
- $extomodify["alldayevent"] = $exception_props[$this->proptags["alldayevent"]];
- if (array_key_exists($this->proptags["busystatus"], $exception_props))
- $extomodify["busystatus"] = $exception_props[$this->proptags["busystatus"]];
- $exception_props[PR_MESSAGE_CLASS] = "IPM.OLE.CLASS.{00061055-0000-0000-C000-000000000046}";
-
- if (isset($exception_props[$this->proptags["startdate"]]))
- $exception_props[$this->proptags["commonstart"]] = $exception_props[$this->proptags["startdate"]];
- if (isset($exception_props[$this->proptags["duedate"]]))
- $exception_props[$this->proptags["commonend"]] = $exception_props[$this->proptags["duedate"]];
- $attach = $this->getExceptionAttachment($baseday);
- if(!$attach) {
- if ($copy_attach_from) {
- $this->deleteExceptionAttachment($base_date);
- $this->createException($exception_props, $base_date, false, $exception_recips, $copy_attach_from);
- } else {
- $this->createExceptionAttachment($exception_props, $exception_recips, $copy_attach_from);
- }
- } else {
- $message = mapi_attach_openobj($attach, MAPI_MODIFY);
-
- mapi_setprops($message, $exception_props);
- $this->setExceptionRecipients($message, $exception_recips, false);
- mapi_savechanges($message);
-
-
- $props = array();
- if (isset($exception_props[$this->proptags["startdate"]]))
- $props[PR_EXCEPTION_STARTTIME] = $this->fromGMT($this->tz, $exception_props[$this->proptags["startdate"]]);
- if (isset($exception_props[$this->proptags["duedate"]]))
- $props[PR_EXCEPTION_ENDTIME] = $this->fromGMT($this->tz, $exception_props[$this->proptags["duedate"]]);
- if (!empty($props))
- mapi_setprops($attach, $props);
- mapi_savechanges($attach);
- }
-
- $this->saveRecurrence();
- return true;
- }
-
-
-
-
-
-
- function isValidExceptionDate($basedate, $start)
- {
-
-
-
- if($this->isException($basedate)) {
-
-
- $oldexception = $this->getChangeException($basedate);
- $prevday = $this->dayStartOf($oldexception["start"]);
- } else {
-
- $prevday = $basedate;
- }
-
- $startday = $this->dayStartOf($start);
-
-
- if($prevday < $startday)
- $items = $this->getItems($this->toGMT($this->tz, $prevday), $this->toGMT($this->tz, $startday + 24 * 60 * 60));
- else
- $items = $this->getItems($this->toGMT($this->tz, $startday), $this->toGMT($this->tz, $prevday + 24 * 60 * 60));
-
-
-
- return count($items) == 1;
- }
-
- function isValidReminderTime($basedate, $reminderminutes, $startdate)
- {
- $isreminderrangeset = false;
-
-
- $occitems = $this->getItems($this->messageprops[$this->proptags["startdate"]], $this->toGMT($this->tz, $basedate));
-
- if(!empty($occitems)) {
-
- $previousitem_startdate = $occitems[count($occitems) - 1][$this->proptags["startdate"]];
-
- if($startdate - ($reminderminutes*60) <= $previousitem_startdate)
- return false;
- }
-
-
- $currentOcc = $this->getItems($this->toGMT($this->tz, $basedate), 0x7ff00000, 2, true);
-
-
- if(count($currentOcc) > 1) {
- $next = $currentOcc[1];
-
- $nextOccReminderTime = $next[$this->proptags["startdate"]] - ($next[$this->proptags["reminder_minutes"]] * 60);
-
- if($nextOccReminderTime <= $startdate)
- return false;
- }
-
- return true;
- }
-
- function setRecurrence($tz, $recur)
- {
-
- if($tz)
- $this->tz = $tz;
-
- $this->recur = $recur;
-
- if(!isset($this->recur["changed_occurences"]))
- $this->recur["changed_occurences"] = Array();
-
- if(!isset($this->recur["deleted_occurences"]))
- $this->recur["deleted_occurences"] = Array();
-
- $this->deleteAttachments();
- $this->saveRecurrence();
-
- $messageProps = mapi_getprops($this->message, Array($this->proptags["recurring_pattern"]));
- if (empty($messageProps[$this->proptags["recurring_pattern"]]))
- $this->saveRecurrencePattern();
- }
-
-
-
- function getOccurrenceStart($basedate) {
- $daystart = $this->dayStartOf($basedate);
- return $this->toGMT($this->tz, $daystart + $this->recur["startocc"] * 60);
- }
-
- function getOccurrenceEnd($basedate) {
- $daystart = $this->dayStartOf($basedate);
- return $this->toGMT($this->tz, $daystart + $this->recur["endocc"] * 60);
- }
-
-
- function getOccurenceStart($basedate) {
- return $this->getOccurrenceStart($basedate);
- }
- function getOccurenceEnd($basedate) {
- return $this->getOccurrenceEnd($basedate);
- }
-
- function getNextReminderTime($timestamp)
- {
-
- $items = $this->getItems($timestamp, 0x7ff00000, 10, true);
-
- $nextreminder = false;
-
- for($i = 0, $len = count($items); $i < $len; $i++)
- {
- $item = $items[$i];
- $tempnextreminder = $item[$this->proptags["startdate"]] - ( $item[$this->proptags["reminder_minutes"]] * 60 );
-
-
- if($tempnextreminder > $timestamp)
- {
- $nextreminder = $tempnextreminder;
- break;
- }
- }
- return $nextreminder;
- }
-
-
- static function getCalendarItems($store, $calendar, $viewstart, $viewend, $propsrequested)
- {
- return getCalendarItems($store, $calendar, $viewstart, $viewend, $propsrequested);
- }
-
-
- function saveRecurrencePattern()
- {
-
-
- $type = $this->recur['type'];
- $everyn = $this->recur['everyn'];
- $start = $this->recur['start'];
- $end = $this->recur['end'];
- $term = $this->recur['term'];
- $numocc = isset($this->recur['numoccur']) ? $this->recur['numoccur'] : false;
- $startocc = $this->recur['startocc'];
- $endocc = $this->recur['endocc'];
- $pattern = '';
- $occSingleDayRank = false;
- $occTimeRange = ($startocc != 0 && $endocc != 0);
- switch ($type) {
-
- case 0x0A:
- if ($everyn == 1) {
- $type = dgettext("kopano", "workday");
- $occSingleDayRank = true;
- } else if ($everyn == (24 * 60)) {
- $type = dgettext("kopano", "day");
- $occSingleDayRank = true;
- } else {
- $everyn /= (24 * 60);
- $type = dgettext("kopano", "days");
- $occSingleDayRank = false;
- }
- break;
-
- case 0x0B:
- if ($everyn == 1) {
- $type = dgettext("kopano", "week");
- $occSingleDayRank = true;
- } else {
- $type = dgettext("kopano", "weeks");
- $occSingleDayRank = false;
- }
- break;
-
- case 0x0C:
- if ($everyn == 1) {
- $type = dgettext("kopano", "month");
- $occSingleDayRank = true;
- } else {
- $type = dgettext("kopano", "months");
- $occSingleDayRank = false;
- }
- break;
-
- case 0x0D:
- if ($everyn <= 12) {
- $everyn = 1;
- $type = dgettext("kopano", "year");
- $occSingleDayRank = true;
- } else {
- $everyn = $everyn / 12;
- $type = dgettext("kopano", "years");
- $occSingleDayRank = false;
- }
- break;
- }
-
- $firstoccstartdate = isset($startocc) ? $start + (((int) $startocc) * 60) : $start;
- $firstoccenddate = isset($endocc) ? $end + (((int) $endocc) * 60) : $end;
- $start = gmdate(dgettext("kopano","d-m-Y"), $firstoccstartdate);
- $end = gmdate(dgettext("kopano","d-m-Y"), $firstoccenddate);
- $startocc = gmdate(dgettext("kopano","G:i"), $firstoccstartdate);
- $endocc = gmdate(dgettext("kopano","G:i"), $firstoccenddate);
-
-
-
-
-
-
-
- if ($term == 0x23) {
-
- if ($occTimeRange) {
- if ($occSingleDayRank)
- $pattern = sprintf(dgettext("kopano","Occurs every %s effective %s from %s to %s."), $type, $start, $startocc, $endocc);
- else
- $pattern = sprintf(dgettext("kopano","Occurs every %s %s effective %s from %s to %s."), $everyn, $type, $start, $startocc, $endocc);
- } else {
- if ($occSingleDayRank)
- $pattern = sprintf(dgettext("kopano","Occurs every %s effective %s."), $type, $start);
- else
- $pattern = sprintf(dgettext("kopano","Occurs every %s %s effective %s."), $everyn, $type, $start);
- }
- } else if ($term == 0x22) {
-
- if ($occTimeRange) {
- if ($occSingleDayRank)
- $pattern = sprintf(dngettext("kopano","Occurs every %s effective %s for %s occurence from %s to %s.",
- "Occurs every %s effective %s for %s occurences from %s to %s.", $numocc), $type, $start, $numocc, $startocc, $endocc);
- else
- $pattern = sprintf(dngettext("kopano","Occurs every %s %s effective %s for %s occurence from %s to %s.",
- "Occurs every %s %s effective %s for %s occurences %s to %s.", $numocc), $everyn, $type, $start, $numocc, $startocc, $endocc);
- } else {
- if ($occSingleDayRank)
- $pattern = sprintf(dngettext("kopano","Occurs every %s effective %s for %s occurence.",
- "Occurs every %s effective %s for %s occurences.", $numocc), $type, $start, $numocc);
- else
- $pattern = sprintf(dngettext("kopano","Occurs every %s %s effective %s for %s occurence.",
- "Occurs every %s %s effective %s for %s occurences.", $numocc), $everyn, $type, $start, $numocc);
- }
- } else if ($term == 0x21) {
-
- if ($occTimeRange) {
- if ($occSingleDayRank)
- $pattern = sprintf(dgettext("kopano","Occurs every %s effective %s until %s from %s to %s."), $type, $start, $end, $startocc, $endocc);
- else
- $pattern = sprintf(dgettext("kopano","Occurs every %s %s effective %s until %s from %s to %s."), $everyn, $type, $start, $end, $startocc, $endocc);
- } else {
- if ($occSingleDayRank)
- $pattern = sprintf(dgettext("kopano","Occurs every %s effective %s until %s."), $type, $start, $end);
- else
- $pattern = sprintf(dgettext("kopano","Occurs every %s %s effective %s until %s."), $everyn, $type, $start, $end);
- }
- }
- if (!empty($pattern))
- mapi_setprops($this->message, Array($this->proptags["recurring_pattern"] => $pattern ));
- }
-
- function deleteException($base_date)
- {
-
-
- $new = Array();
-
- foreach($this->recur["deleted_occurences"] as $entry)
- if($entry != $base_date)
- $new[] = $entry;
- $this->recur["deleted_occurences"] = $new;
-
- $new = Array();
-
- foreach($this->recur["changed_occurences"] as $entry) {
- if(!$this->isSameDay($entry["basedate"], $base_date))
- $new[] = $entry;
- else
- $this->deleteExceptionAttachment($this->toGMT($this->tz, $base_date + $this->recur["startocc"] * 60));
- }
-
- $this->recur["changed_occurences"] = $new;
- }
-
-
-
- function createExceptionAttachment($exception_props, $exception_recips = array(), $copy_attach_from = false)
- {
-
- $attachment = mapi_message_createattach($this->message);
- $props = array();
- $props[PR_ATTACHMENT_FLAGS] = 2;
- $props[PR_ATTACHMENT_HIDDEN] = true;
- $props[PR_ATTACHMENT_LINKID] = 0;
- $props[PR_ATTACH_FLAGS] = 0;
- $props[PR_ATTACH_METHOD] = 5;
- $props[PR_DISPLAY_NAME] = "Exception";
- $props[PR_EXCEPTION_STARTTIME] = $this->fromGMT($this->tz, $exception_props[$this->proptags["startdate"]]);
- $props[PR_EXCEPTION_ENDTIME] = $this->fromGMT($this->tz, $exception_props[$this->proptags["duedate"]]);
- mapi_message_setprops($attachment, $props);
-
- $imessage = mapi_attach_openobj($attachment, MAPI_CREATE | MAPI_MODIFY);
- if ($copy_attach_from) {
- $attachmentTable = mapi_message_getattachmenttable($copy_attach_from);
- if($attachmentTable) {
- $attachments = mapi_table_queryallrows($attachmentTable, array(PR_ATTACH_NUM, PR_ATTACH_SIZE, PR_ATTACH_LONG_FILENAME, PR_ATTACHMENT_HIDDEN, PR_DISPLAY_NAME, PR_ATTACH_METHOD));
- foreach($attachments as $attach_props){
- $attach_old = mapi_message_openattach($copy_attach_from, (int) $attach_props[PR_ATTACH_NUM]);
- $attach_newResourceMsg = mapi_message_createattach($imessage);
- mapi_copyto($attach_old, array(), array(), $attach_newResourceMsg, 0);
- mapi_savechanges($attach_newResourceMsg);
- }
- }
- }
- $props = $props + $exception_props;
-
-
-
-
- foreach ($props as $propTag=>$propVal)
- if (mapi_prop_type($propTag) & MV_FLAG && is_null($propVal))
- unset($props[$propTag]);
- mapi_message_setprops($imessage, $props);
- $this->setExceptionRecipients($imessage, $exception_recips, true);
- mapi_message_savechanges($imessage);
- mapi_message_savechanges($attachment);
- }
-
-
-
- function deleteExceptionAttachment($base_date)
- {
- $attachments = mapi_message_getattachmenttable($this->message);
- $attachTable = mapi_table_queryallrows($attachments, Array(PR_ATTACH_NUM));
-
- foreach($attachTable as $attachRow)
- {
- $tempattach = mapi_message_openattach($this->message, $attachRow[PR_ATTACH_NUM]);
- $exception = mapi_attach_openobj($tempattach);
-
- $data = mapi_message_getprops($exception, array($this->proptags["basedate"]));
- if ($this->dayStartOf($this->fromGMT($this->tz, $data[$this->proptags["basedate"]])) == $this->dayStartOf($base_date))
- mapi_message_deleteattach($this->message, $attachRow[PR_ATTACH_NUM]);
- }
- }
-
-
-
- function deleteAttachments()
- {
- $attachments = mapi_message_getattachmenttable($this->message);
- $attachTable = mapi_table_queryallrows($attachments, Array(PR_ATTACH_NUM, PR_ATTACHMENT_HIDDEN));
-
- foreach($attachTable as $attachRow)
- if (isset($attachRow[PR_ATTACHMENT_HIDDEN]) && $attachRow[PR_ATTACHMENT_HIDDEN])
- mapi_message_deleteattach($this->message, $attachRow[PR_ATTACH_NUM]);
- }
-
-
- function getExceptionAttachment($base_date)
- {
-
- $attach_res = Array(RES_AND,
- Array(
- Array(RES_PROPERTY,
- Array(RELOP => RELOP_EQ,
- ULPROPTAG => PR_ATTACH_METHOD,
- VALUE => array(PR_ATTACH_METHOD => ATTACH_EMBEDDED_MSG)
- )
- )
- )
- );
- $attachments = mapi_message_getattachmenttable($this->message);
- $attachRows = mapi_table_queryallrows($attachments, Array(PR_ATTACH_NUM), $attach_res);
- if(is_array($attachRows)) {
- foreach($attachRows as $attachRow)
- {
- $tempattach = mapi_message_openattach($this->message, $attachRow[PR_ATTACH_NUM]);
- $exception = mapi_attach_openobj($tempattach);
-
- $data = mapi_message_getprops($exception, array($this->proptags["basedate"]));
-
- if ($this->isSameDay($this->fromGMT($this->tz,$data[$this->proptags["basedate"]]), $base_date))
- return $tempattach;
- }
- }
- return false;
- }
-
- function processOccurrenceItem(&$items, $start, $end, $basedate, $startocc, $endocc, $tz, $reminderonly)
- {
- $exception = $this->isException($basedate);
- if($exception){
- return false;
- }else{
- $occstart = $basedate + $startocc * 60;
- $occend = $basedate + $endocc * 60;
-
-
- $occstart = $this->toGMT($tz, $occstart);
- $occend = $this->toGMT($tz, $occend);
-
-
- if(($occstart >= $end || $occend <= $start) && !($occstart == $occend && $occstart == $start))
- return;
-
-
-
- $newitem = $this->messageprops;
- $newitem[$this->proptags["startdate"]] = $occstart;
- $newitem[$this->proptags["duedate"]] = $occend;
- $newitem[$this->proptags["commonstart"]] = $occstart;
- $newitem[$this->proptags["commonend"]] = $occend;
- $newitem["basedate"] = $basedate;
- }
-
-
- if($reminderonly && (!isset($newitem[$this->proptags["reminder"]]) || $newitem[$this->proptags["reminder"]] == false))
- return;
-
- $items[] = $newitem;
- }
-
-
- function processExceptionItems(&$items, $start, $end)
- {
- $limit = 0;
- foreach($this->recur["changed_occurences"] as $exception) {
-
-
- $occstart = $this->toGMT($this->tz, $exception["start"]);
- $occend = $this->toGMT($this->tz, $exception["end"]);
-
-
- if($occstart >= $end || $occend <= $start)
- continue;
-
- array_push($items, $this->getExceptionProperties($exception));
- if($limit && (count($items) == $limit))
- break;
- }
- }
-
-
-
- function isException($basedate)
- {
- if($this->isDeleteException($basedate))
- return true;
-
- if($this->getChangeException($basedate) != false)
- return true;
-
- return false;
- }
-
-
- function isDeleteException($basedate)
- {
-
- foreach($this->recur["deleted_occurences"] as $deleted)
- if($this->isSameDay($deleted, $basedate))
- return true;
- return false;
- }
-
-
- function getChangeException($basedate)
- {
-
- foreach($this->recur["changed_occurences"] as $changed)
- if($this->isSameDay($changed["basedate"], $basedate))
- return $changed;
-
- return false;
- }
-
-
- function isSameDay($date1, $date2)
- {
- $time1 = $this->gmtime($date1);
- $time2 = $this->gmtime($date2);
-
- return $time1["tm_mon"] == $time2["tm_mon"] && $time1["tm_year"] == $time2["tm_year"] && $time1["tm_mday"] == $time2["tm_mday"];
- }
-
- function getExceptionProperties($exception)
- {
-
- $item = $this->messageprops;
-
-
- $item["exception"] = true;
- $item["basedate"] = $exception["basedate"];
-
-
- $item[$this->proptags["startdate"]] = $this->toGMT($this->tz, $exception["start"]);
- $item[$this->proptags["duedate"]] = $this->toGMT($this->tz, $exception["end"]);
- $item[$this->proptags["commonstart"]] = $item[$this->proptags["startdate"]];
- $item[$this->proptags["commonend"]] = $item[$this->proptags["duedate"]];
-
- if (isset($exception["subject"]))
- $item[$this->proptags["subject"]] = $exception["subject"];
- if (isset($exception["label"]))
- $item[$this->proptags["label"]] = $exception["label"];
- if (isset($exception["alldayevent"]))
- $item[$this->proptags["alldayevent"]] = $exception["alldayevent"];
- if (isset($exception["location"]))
- $item[$this->proptags["location"]] = $exception["location"];
- if (isset($exception["remind_before"]))
- $item[$this->proptags["reminder_minutes"]] = $exception["remind_before"];
- if (isset($exception["reminder_set"]))
- $item[$this->proptags["reminder"]] = $exception["reminder_set"];
- if (isset($exception["busystatus"]))
- $item[$this->proptags["busystatus"]] = $exception["busystatus"];
- return $item;
- }
-
-
- function setExceptionRecipients($message, $exception_recips, $copy_orig_recips = true)
- {
- if (isset($exception_recips['add']) || isset($exception_recips['remove']) || isset($exception_recips['modify']))
- $this->setDeltaExceptionRecipients($message, $exception_recips, $copy_orig_recips);
- else
- $this->setAllExceptionRecipients($message, $exception_recips);
- }
-
- function setDeltaExceptionRecipients($exception, $exception_recips, $copy_orig_recips)
- {
-
-
-
- if ($copy_orig_recips === true) {
- $origTable = mapi_message_getrecipienttable($this->message);
- $recipientRows = mapi_table_queryallrows($origTable, $this->recipprops);
- mapi_message_modifyrecipients($exception, MODRECIP_ADD, $recipientRows);
- }
-
- $msgprops = mapi_getprops($exception, array(PR_SENT_REPRESENTING_ENTRYID, PR_SENT_REPRESENTING_EMAIL_ADDRESS, PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_ADDRTYPE, PR_SENT_REPRESENTING_SEARCH_KEY, $this->proptags['responsestatus']));
- if (isset($msgprops[$this->proptags['responsestatus']]) && $msgprops[$this->proptags['responsestatus']] != olResponseOrganized)
- $this->addOrganizer($msgprops, $exception_recips['add']);
-
- if (isset($exception_recips['remove'])) {
- foreach ($exception_recips['remove'] as &$recip) {
- if (!isset($recipient[PR_RECIPIENT_FLAGS]) || $recip[PR_RECIPIENT_FLAGS] != (recipReserved | recipExceptionalDeleted | recipSendable))
- $recip[PR_RECIPIENT_FLAGS] = recipSendable | recipExceptionalDeleted;
- else
- $recip[PR_RECIPIENT_FLAGS] = recipReserved | recipExceptionalDeleted | recipSendable;
- $recip[PR_RECIPIENT_TRACKSTATUS] = olResponseNone;
- }
- unset($recip);
- mapi_message_modifyrecipients($exception, MODRECIP_MODIFY, $exception_recips['remove']);
- }
-
- if (isset($exception_recips['add']))
- mapi_message_modifyrecipients($exception, MODRECIP_ADD, $exception_recips['add']);
-
- if (isset($exception_recips['modify']))
- mapi_message_modifyrecipients($exception, MODRECIP_MODIFY, $exception_recips['modify']);
- }
-
- function setAllExceptionRecipients($message, $exception_recips)
- {
- $deletedRecipients = array();
- $useMessageRecipients = false;
- $recipientTable = mapi_message_getrecipienttable($message);
- $recipientRows = mapi_table_queryallrows($recipientTable, $this->recipprops);
- if (empty($recipientRows)) {
- $useMessageRecipients = true;
- $recipientTable = mapi_message_getrecipienttable($this->message);
- $recipientRows = mapi_table_queryallrows($recipientTable, $this->recipprops);
- }
-
- $msgprops = mapi_getprops($message, array(PR_SENT_REPRESENTING_ENTRYID, PR_SENT_REPRESENTING_EMAIL_ADDRESS, PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_ADDRTYPE, PR_SENT_REPRESENTING_SEARCH_KEY, $this->proptags['responsestatus']));
- if (isset($msgprops[$this->proptags['responsestatus']]) && $msgprops[$this->proptags['responsestatus']] != olResponseOrganized)
- $this->addOrganizer($msgprops, $exception_recips);
- if (!empty($exception_recips)) {
- foreach($recipientRows as $key => $recipient) {
- $found = false;
- foreach($exception_recips as $excep_recip)
- if ($recipient[PR_SEARCH_KEY] == $excep_recip[PR_SEARCH_KEY])
- $found = true;
- if (!$found) {
- $foundInDeletedRecipients = false;
-
- if (!empty($deletedRecipients)) {
- foreach($deletedRecipients as $recip) {
- if ($recip[PR_SEARCH_KEY] == $recipient[PR_SEARCH_KEY]){
- $foundInDeletedRecipients = true;
- break;
- }
- }
- }
-
- if (!$foundInDeletedRecipients) {
- if (!isset($recipient[PR_RECIPIENT_FLAGS]) || $recipient[PR_RECIPIENT_FLAGS] != (recipReserved | recipExceptionalDeleted | recipSendable))
- $recipient[PR_RECIPIENT_FLAGS] = recipSendable | recipExceptionalDeleted;
- else
- $recipient[PR_RECIPIENT_FLAGS] = recipReserved | recipExceptionalDeleted | recipSendable;
- $recipient[PR_RECIPIENT_TRACKSTATUS] = olRecipientTrackStatusNone;
- $deletedRecipients[] = $recipient;
- }
- }
-
-
-
-
-
-
- if ($useMessageRecipients === false)
- mapi_message_modifyrecipients($message, MODRECIP_REMOVE, array($recipient));
- }
- $exception_recips = array_merge($exception_recips, $deletedRecipients);
- } else {
- $exception_recips = $recipientRows;
- }
- if (!empty($exception_recips))
-
- mapi_message_modifyrecipients($message, 0, $exception_recips);
- }
-
- function getAllExceptions()
- {
- $result = false;
- if (!empty($this->recur["changed_occurences"])) {
- $result = array();
- foreach($this->recur["changed_occurences"] as $exception)
- $result[] = $exception["basedate"];
- return $result;
- }
- return $result;
- }
-
- function addOrganizer($messageProps, &$recipients, $isException = false)
- {
- $hasOrganizer = false;
-
- foreach ($recipients as $key => $recipient){
- if (isset($recipient[PR_RECIPIENT_FLAGS]) && $recipient[PR_RECIPIENT_FLAGS] == (recipSendable | recipOrganizer))
- $hasOrganizer = true;
- else if ($isException && !isset($recipient[PR_RECIPIENT_FLAGS]))
-
- $recipients[$key][PR_RECIPIENT_FLAGS] = recipSendable | recipExceptionalResponse;
- }
- if (!$hasOrganizer){
-
- $organizer = array();
- $organizer[PR_ENTRYID] = $messageProps[PR_SENT_REPRESENTING_ENTRYID];
- $organizer[PR_DISPLAY_NAME] = $messageProps[PR_SENT_REPRESENTING_NAME];
- $organizer[PR_EMAIL_ADDRESS] = $messageProps[PR_SENT_REPRESENTING_EMAIL_ADDRESS];
- $organizer[PR_RECIPIENT_TYPE] = MAPI_TO;
- $organizer[PR_RECIPIENT_DISPLAY_NAME] = $messageProps[PR_SENT_REPRESENTING_NAME];
- $organizer[PR_ADDRTYPE] = empty($messageProps[PR_SENT_REPRESENTING_ADDRTYPE]) ? 'SMTP' : $messageProps[PR_SENT_REPRESENTING_ADDRTYPE];
- $organizer[PR_RECIPIENT_TRACKSTATUS] = olRecipientTrackStatusNone;
- $organizer[PR_RECIPIENT_FLAGS] = recipSendable | recipOrganizer;
- $organizer[PR_SEARCH_KEY] = $messageProps[PR_SENT_REPRESENTING_SEARCH_KEY];
-
- array_unshift($recipients, $organizer);
- }
- }
- }
-
-
- ?>
|