[5341] | 1 | <?php |
---|
[6027] | 2 | |
---|
| 3 | require_once ROOTPATH . '/modules/calendar/constants.php'; |
---|
| 4 | require_once ROOTPATH . '/modules/calendar/interceptors/Helpers.php'; |
---|
| 5 | require_once ROOTPATH . '/plugins/icalcreator/iCalcreator.class.php'; |
---|
| 6 | require_once ROOTPATH . '/api/parseTPL.php'; |
---|
| 7 | |
---|
| 8 | class Notifications extends Helpers { |
---|
| 9 | |
---|
| 10 | public function formatNotification(&$uri, &$params, &$data, $original) { |
---|
| 11 | switch ($params['type']) { |
---|
| 12 | case 'suggestion': |
---|
| 13 | self::formatSuggestion($params); |
---|
| 14 | break; |
---|
| 15 | case 'suggestionResponse': |
---|
| 16 | self::formatSuggestionResponse($params); |
---|
| 17 | break; |
---|
[5514] | 18 | } |
---|
[6027] | 19 | } |
---|
[5514] | 20 | |
---|
[6027] | 21 | /** |
---|
| 22 | * Analisa o commit do conceito participant e encaminha cada participant para seu devido metodo de notrificação |
---|
| 23 | * |
---|
| 24 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 25 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 26 | * @sponsor Caixa Econômica Federal |
---|
| 27 | * @author Cristiano Corrêa Schmidt |
---|
| 28 | * @return void |
---|
| 29 | * @access public |
---|
| 30 | */ |
---|
| 31 | public function commitParticipant(&$uri, &$result, &$data, $original) { |
---|
| 32 | if (Config::regGet('noAlarm') !== false) |
---|
| 33 | return; //Escapa notificações caso a flag de noAlarm esteja ativa. |
---|
[5514] | 34 | |
---|
[6027] | 35 | $organizers = array(); //Cache Organizadores |
---|
| 36 | $schedulables = array(); //Cache Schedulables |
---|
| 37 | |
---|
| 38 | foreach ($data as $i => $concept) { |
---|
| 39 | if ($concept['concept'] === 'participant') { |
---|
| 40 | if ($concept['method'] == 'create') |
---|
| 41 | $created[] = $concept['id']; |
---|
| 42 | else if ($concept['method'] == 'update') |
---|
| 43 | $updated[] = $concept['id']; |
---|
| 44 | } |
---|
[6177] | 45 | else if ($concept['concept'] === 'schedulable') { //Caso exista schedulable no commit antecipa o carregamento do owner |
---|
[6027] | 46 | $schedulables[$concept['id']] = Controller::read(array('concept' => 'schedulable', 'id' => $concept['id']), false, array('deepness' => '2')); |
---|
| 47 | foreach ($schedulables[$concept['id']]['participants'] as $i => $v) //salva em $organizers as informações do organizador |
---|
| 48 | if (($v['isOrganizer'] === '1') && ($organizers[$concept['id']] = $v)) |
---|
| 49 | break; |
---|
| 50 | }else if ($concept['concept'] === 'schedulableToAttachment') { |
---|
| 51 | $relationAttachment = Controller::find(array('concept' => 'schedulableToAttachment'), false, array('filter' => array('=', 'id', $concept['id']))); |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | foreach ($relationAttachment as $key => $value) { |
---|
| 56 | if (!array_key_exists('attachments', $schedulables[$value['schedulable']])) |
---|
| 57 | $schedulables[$value['schedulable']]['attachments'] = array(); |
---|
| 58 | |
---|
| 59 | $temp = Controller::find(array('concept' => 'attachment'), false, array('filter' => array('=', 'id', $value['attachment']))); |
---|
| 60 | array_push($schedulables[$value['schedulable']]['attachments'], $temp[0]); |
---|
[5947] | 61 | } |
---|
[6027] | 62 | } |
---|
| 63 | } |
---|
[5947] | 64 | |
---|
[6027] | 65 | if (isset($created)) { |
---|
| 66 | $psCreated = Controller::find(array('concept' => 'participant'), false, array('deepness' => '1', 'filter' => array('IN', 'id', $created))); |
---|
| 67 | foreach ($psCreated as $i => $pCreated) { |
---|
| 68 | if ($pCreated['isOrganizer'] == '1') |
---|
| 69 | continue; //escapa organizador |
---|
| 70 | $schedulable = isset($schedulables[$pCreated['schedulable']]) ? $schedulables[$pCreated['schedulable']] : Controller::read(array('concept' => 'schedulable', 'id' => $pCreated['schedulable']), false, array('deepness' => '2')); |
---|
[6177] | 71 | if (!self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id'])) |
---|
[6027] | 72 | continue; //Escapa eventos do passado |
---|
[5341] | 73 | |
---|
[6027] | 74 | $organizer = isset($organizers[$pCreated['schedulable']]) ? $organizers[$pCreated['schedulable']] : self::getOrganizer($pCreated['schedulable']); |
---|
| 75 | |
---|
| 76 | if ($pCreated['delegatedFrom'] != 0) { |
---|
| 77 | self::participantDelegated($pCreated, $schedulable, $organizer); |
---|
| 78 | continue; |
---|
[5514] | 79 | } |
---|
| 80 | |
---|
[6027] | 81 | switch ($pCreated['status']) { |
---|
| 82 | case STATUS_CONFIRMED: |
---|
| 83 | self::participantStatusChange($pCreated['id'], $schedulable, $organizer, STATUS_ACCEPTED); |
---|
| 84 | break; |
---|
| 85 | case STATUS_UNANSWERED: |
---|
| 86 | self::participantCreated($pCreated['id'], $schedulable, false, false, $organizer); |
---|
| 87 | break; |
---|
[5514] | 88 | } |
---|
[6027] | 89 | } |
---|
[5514] | 90 | } |
---|
[6027] | 91 | |
---|
| 92 | if (isset($updated)) { |
---|
| 93 | $psUpdated = Controller::find(array('concept' => 'participant'), false, array('deepness' => '1', 'filter' => array('IN', 'id', $updated))); |
---|
| 94 | foreach ($psUpdated as $i => $pUpdated) { |
---|
| 95 | if ($pUpdated['isOrganizer'] == '1') |
---|
| 96 | continue; //escapa organizador |
---|
| 97 | $schedulable = isset($schedulables[$pUpdated['schedulable']]) ? $schedulables[$pUpdated['schedulable']] : Controller::read(array('concept' => 'schedulable', 'id' => $pUpdated['schedulable']), false, array('deepness' => '2')); |
---|
[6177] | 98 | if (!self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id'])) |
---|
[6027] | 99 | continue; //Escapa eventos do passado |
---|
| 100 | |
---|
| 101 | foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador |
---|
| 102 | if (($v['isOrganizer'] === '1') && ($organizer = $v)) |
---|
| 103 | break; |
---|
| 104 | |
---|
| 105 | if ($pUpdated['delegatedFrom'] != 0) { |
---|
| 106 | self::participantDelegatedStatusChange($pUpdated, $schedulable, $organizer, $pUpdated['status']); |
---|
| 107 | } else if ($pUpdated['status'] != STATUS_UNANSWERED && $pUpdated['status'] != STATUS_DELEGATED) |
---|
| 108 | self::participantStatusChange($pUpdated['id'], $schedulable, $organizer, $pUpdated['status']); |
---|
| 109 | } |
---|
[5514] | 110 | } |
---|
[6027] | 111 | } |
---|
| 112 | |
---|
| 113 | public function formatSuggestion(&$params) { |
---|
| 114 | |
---|
| 115 | $schedulable = Controller::read(array('concept' => 'schedulable', 'id' => $params['schedulable']), null, array('deepness' => '2')); |
---|
| 116 | |
---|
| 117 | foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador |
---|
| 118 | if (($v['isOrganizer'] === '1') && ($organizer = $v)) |
---|
| 119 | break; |
---|
| 120 | |
---|
| 121 | $method = 'COUNTER'; |
---|
| 122 | $notificationType = 'Sugestão de horário'; |
---|
| 123 | $part = 'other'; |
---|
| 124 | |
---|
| 125 | $schedulableReference = $schedulable; |
---|
| 126 | |
---|
[6038] | 127 | $referenceSuggestion = array('startTime' => strtotime($params['startTime'] . ' ' . $schedulable['timezone']) . '000', |
---|
| 128 | 'endTime' => strtotime($params['endTime'] . ' ' . $schedulable['timezone']) . '000', |
---|
[6027] | 129 | 'allDay' => $params['allDay'] |
---|
| 130 | ); |
---|
[6038] | 131 | |
---|
[6027] | 132 | $schedulable = array_merge($schedulable, $referenceSuggestion); |
---|
| 133 | |
---|
| 134 | self::mountStruture(false, $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | $timezone = new DateTimeZone('UTC'); |
---|
| 138 | $sTime = new DateTime('@' . (int) ($schedulableReference['startTime'] / 1000), $timezone); |
---|
| 139 | $eTime = new DateTime('@' . (int) ($schedulableReference['endTime'] / 1000), $timezone); |
---|
| 140 | |
---|
| 141 | if (isset($schedulableReference['timezone'])) { |
---|
| 142 | $sTime->setTimezone(new DateTimeZone($schedulableReference['timezone'])); |
---|
| 143 | $eTime->setTimezone(new DateTimeZone($schedulableReference['timezone'])); |
---|
[5514] | 144 | } |
---|
[6027] | 145 | |
---|
| 146 | $data['nowStartDate'] = date_format($sTime, 'd/m/Y'); |
---|
| 147 | $data['nowStartTime'] = ($schedulableReference['allDay']) ? '' : date_format($sTime, 'H:i'); |
---|
| 148 | $data['nowEndDate'] = date_format($eTime, 'd/m/Y'); |
---|
| 149 | $data['nowEndTime'] = ($schedulableReference['allDay']) ? '' : date_format($eTime, 'H:i'); |
---|
| 150 | $data['userRequest'] = Config::me('uid'); |
---|
| 151 | |
---|
| 152 | $ical2 = $ical; |
---|
| 153 | $ical2['type'] = 'text/calendar'; |
---|
| 154 | $ical2['name'] = 'thunderbird.ics'; |
---|
| 155 | $params['attachments'][] = $ical2; |
---|
| 156 | $params['attachments'][] = $ical; |
---|
| 157 | $params['isHtml'] = true; |
---|
| 158 | $params['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/notify_suggestion_body.tpl'); |
---|
| 159 | $params['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl'); |
---|
| 160 | ; |
---|
| 161 | $params['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>'; |
---|
| 162 | $params['to'] = $organizer['user']['mail']; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | public function formatSuggestionResponse(&$params) { |
---|
| 166 | $schedulable = $params['schedulable']; |
---|
| 167 | foreach ($schedulable['participants'] as $i => $v) {//salva em $organizer as informações do organizador |
---|
| 168 | if ($v['isOrganizer'] === '1') |
---|
| 169 | $organizer = $v; |
---|
| 170 | if ($v['user']['mail'] == Config::me('mail')) |
---|
| 171 | $me = $v; |
---|
| 172 | } |
---|
| 173 | $method = 'DECLINECOUNTER'; |
---|
| 174 | $notificationType = 'Sugestão de horário'; |
---|
| 175 | $part = 'other'; |
---|
| 176 | |
---|
| 177 | $schedulable['participants'] = array(); |
---|
| 178 | array_push($schedulable['participants'], $me, $organizer); |
---|
| 179 | |
---|
| 180 | self::mountStruture(false, $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); |
---|
| 181 | |
---|
| 182 | if ($params['status'] == 'DECLINECOUNTER') |
---|
| 183 | $data['status'] = 'não pode ser aceito'; |
---|
| 184 | $ical2 = $ical; |
---|
| 185 | $ical2['type'] = 'text/calendar'; |
---|
| 186 | $ical2['name'] = 'thunderbird.ics'; |
---|
| 187 | $params['attachments'][] = $ical2; |
---|
| 188 | $params['attachments'][] = $ical; |
---|
| 189 | $params['isHtml'] = true; |
---|
| 190 | $params['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/notify_suggestion_response_body.tpl'); |
---|
| 191 | $params['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl'); |
---|
| 192 | ; |
---|
| 193 | $params['to'] = $params['from']; |
---|
| 194 | $params['from'] = $params['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>'; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | public static function _getAttendeeById($attendeId, $schedulable) { |
---|
| 198 | foreach ($schedulable['participants'] as $id => $dv) |
---|
| 199 | if ($dv['id'] == $attendeId) |
---|
| 200 | return $dv; |
---|
| 201 | } |
---|
| 202 | |
---|
[5947] | 203 | /** |
---|
[6027] | 204 | * Prepara para criação de email de delegação |
---|
| 205 | * |
---|
| 206 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 207 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 208 | * @sponsor Caixa Econômica Federal |
---|
| 209 | * @author Adriano Coutinho da Silva |
---|
| 210 | * @return void |
---|
| 211 | * @access public |
---|
| 212 | */ |
---|
| 213 | public static function participantDelegated(&$partID, &$schedulable, &$organizer) { |
---|
[5947] | 214 | |
---|
[6027] | 215 | $delegatedParams = array(); |
---|
[5947] | 216 | |
---|
[6027] | 217 | $delegatedFrom = self::_getAttendeeById($partID['delegatedFrom'], $schedulable); |
---|
| 218 | $delegatedParams['delegatedFrom'] = $delegatedFrom['user']['uid']; |
---|
| 219 | |
---|
| 220 | self::participantCreated($partID['id'], $schedulable, STATUS_DELEGATED, $delegatedParams); |
---|
| 221 | |
---|
| 222 | $delegatedTo = self::_getAttendeeById($partID['id'], $schedulable); |
---|
| 223 | $delegatedParams['delegated'] = $delegatedTo['user']['uid']; |
---|
| 224 | |
---|
| 225 | self::participantStatusChange($partID['delegatedFrom'], $schedulable, $organizer, STATUS_DELEGATED, $delegatedParams); |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | /** |
---|
| 229 | * Monta o email de resposta que sera enviado ao delegatedFrom |
---|
| 230 | * |
---|
| 231 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 232 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 233 | * @sponsor Caixa Econômica Federal |
---|
| 234 | * @author Cristiano Corrêa Schmidt |
---|
| 235 | * @return void |
---|
| 236 | * @access public |
---|
| 237 | */ |
---|
| 238 | public static function participantDelegatedStatusChange(&$partID, &$schedulable, $organizer, &$type = false) { |
---|
| 239 | |
---|
| 240 | $delegatedParams = array(); |
---|
| 241 | |
---|
| 242 | $delegated = self::_getAttendeeById($partID['id'], $schedulable); |
---|
| 243 | $delegatedParams['delegated'] = $delegated['user']['uid']; |
---|
| 244 | |
---|
| 245 | switch ($partID['status']) { |
---|
| 246 | case STATUS_ACCEPTED: |
---|
| 247 | $delegatedParams['status'] = 'aceitou'; |
---|
| 248 | break; |
---|
| 249 | case STATUS_TENTATIVE: |
---|
| 250 | $delegatedParams['status'] = 'marcou como tentativa'; |
---|
| 251 | break; |
---|
| 252 | case STATUS_CANCELLED: |
---|
| 253 | $delegatedParams['status'] = 'rejeitou'; |
---|
| 254 | break; |
---|
[5947] | 255 | case STATUS_DELEGATED: |
---|
[6027] | 256 | $delegatedParams['status'] = 'delegou para um novo participante'; |
---|
| 257 | break; |
---|
| 258 | } |
---|
| 259 | //notifica o organizador a resposta do delegado |
---|
| 260 | self::participantStatusChange($partID['delegatedFrom'], $schedulable, $organizer, $type, $delegatedParams); |
---|
[5947] | 261 | |
---|
[6027] | 262 | $method = 'REQUEST'; |
---|
| 263 | $notificationType = 'Resposta Delegação'; |
---|
| 264 | $part = 'attendees'; |
---|
| 265 | self::mountStruture($partID['delegatedFrom'], $schedulable, $type, $data, $subject, $ical, $part, $method, $notificationType); |
---|
[5947] | 266 | |
---|
[6027] | 267 | $data = array_merge($data, $delegatedParams); |
---|
| 268 | |
---|
| 269 | self::sendMail($data, $ical, $part['user']['mail'], $subject, 'notify_response_delegated_status_body'); |
---|
[5514] | 270 | } |
---|
| 271 | |
---|
[6027] | 272 | public static function mountStruture($partID, &$schedulable, $type = false, &$data, &$subject, &$ical, &$part = false, &$method, &$notificationType, $regSet = false) { |
---|
[5947] | 273 | |
---|
[6027] | 274 | if ((Config::regGet('ical://' . $schedulable['id'] . '/' . $method) === false) || ($method == 'CANCEL')) { //Verifica se o ical ja não esta no reg |
---|
| 275 | $schedulable['URI']['concept'] = 'schedulable'; |
---|
| 276 | $ical['source'] = Controller::format(array('service' => 'iCal'), array($schedulable), array('method' => $method)); |
---|
| 277 | $ical['type'] = 'text/plain'; |
---|
| 278 | $ical['name'] = 'outlook.ics'; |
---|
| 279 | if ($regSet) |
---|
| 280 | Config::regSet('ical://' . $schedulable['id'] . '/' . $method, $ical); |
---|
| 281 | } |
---|
| 282 | else |
---|
| 283 | $ical = Config::regGet('ical://' . $schedulable['id'] . '/' . $method); |
---|
[6038] | 284 | |
---|
[6034] | 285 | if (!is_numeric($schedulable['endTime'])) |
---|
[6038] | 286 | $schedulable['startTime'] = self::parseTimeDate($schedulable['startTime'], $schedulable['timezone']); |
---|
[5514] | 287 | |
---|
[6038] | 288 | if (!is_numeric($schedulable['endTime'])) { |
---|
| 289 | $schedulable['endTime'] = self::parseTimeDate($schedulable['endTime'], $schedulable['timezone']); |
---|
| 290 | |
---|
| 291 | if ($schedulable['allDay']) |
---|
| 292 | $schedulable['endTime'] = $schedulable['endTime'] + 86400000; |
---|
[6034] | 293 | } |
---|
[6038] | 294 | |
---|
[6027] | 295 | $timezone = new DateTimeZone('UTC'); |
---|
| 296 | $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), $timezone); |
---|
| 297 | $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), $timezone); |
---|
[6038] | 298 | |
---|
[6027] | 299 | if (isset($schedulable['timezone'])) { |
---|
| 300 | $sTime->setTimezone(new DateTimeZone($schedulable['timezone'])); |
---|
| 301 | $eTime->setTimezone(new DateTimeZone($schedulable['timezone'])); |
---|
[5514] | 302 | } |
---|
[6027] | 303 | |
---|
| 304 | $data = array('startDate' => date_format($sTime, 'd/m/Y'), |
---|
| 305 | 'startTime' => ($schedulable['allDay']) ? '' : date_format($sTime, 'H:i'), |
---|
| 306 | 'endDate' => date_format($eTime, 'd/m/Y'), |
---|
| 307 | 'endTime' => ($schedulable['allDay']) ? '' : date_format($eTime, 'H:i'), |
---|
| 308 | 'eventTitle' => $schedulable['summary'], |
---|
| 309 | 'eventLocation' => $schedulable['location'], |
---|
| 310 | 'timezone' => ($schedulable['timezone']) ? $schedulable['timezone'] : 'UTC'); |
---|
| 311 | $temp = $part; |
---|
| 312 | $part = false; |
---|
| 313 | |
---|
| 314 | switch ($temp) { |
---|
| 315 | case 'attendees': |
---|
| 316 | $attList = '<UL> '; |
---|
| 317 | foreach ($schedulable['participants'] as $i => $v) { |
---|
| 318 | if ($part === false && $v['id'] == $partID) |
---|
| 319 | $part = $v; |
---|
| 320 | |
---|
| 321 | $attList .= ' <LI> ' . (isset($v['user']['name']) ? $v['user']['name'] : $v['user']['mail']); |
---|
| 322 | } |
---|
| 323 | $attList .= '</UL>'; |
---|
| 324 | $data['participants'] = $attList; |
---|
| 325 | break; |
---|
| 326 | case 'me': |
---|
| 327 | $part = self::_getAttendeeById($partID, $schedulable); |
---|
| 328 | $data['participant'] = isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail']; |
---|
| 329 | break; |
---|
| 330 | case 'othersAttendees': |
---|
| 331 | $data['participants'] = '<UL> '; |
---|
| 332 | foreach ($schedulable['participants'] as $ii => $participant) { |
---|
| 333 | if (Config::me('mail') !== $participant['user']['mail']) |
---|
| 334 | $part[] = $participant['user']['mail']; |
---|
| 335 | |
---|
| 336 | $data['participants'] .= ' <LI> ' . (isset($participant['user']['name']) ? $participant['user']['name'] : $participant['user']['mail']); |
---|
| 337 | } |
---|
| 338 | break; |
---|
| 339 | } |
---|
| 340 | $subject['notificationType'] = $notificationType; |
---|
| 341 | $subject['eventTitle'] = mb_convert_encoding($schedulable['summary'], 'ISO-8859-1', 'ISO-8859-1,UTF-8'); |
---|
| 342 | $subject['startDate'] = date_format($sTime, 'd/m/Y'); |
---|
| 343 | $subject['startTime'] = ($schedulable['allDay']) ? '' : date_format($sTime, 'H:i'); |
---|
| 344 | $subject['endDate'] = date_format($eTime, 'd/m/Y'); |
---|
| 345 | $subject['endTime'] = ($schedulable['allDay']) ? '' : date_format($eTime, 'H:i'); |
---|
| 346 | $subject['participant'] = Config::me('uid'); |
---|
| 347 | } |
---|
| 348 | |
---|
[5514] | 349 | /** |
---|
[6027] | 350 | * Monta o email de convite que sera enviado ao participant |
---|
| 351 | * |
---|
| 352 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 353 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 354 | * @sponsor Caixa Econômica Federal |
---|
| 355 | * @author Cristiano Corrêa Schmidt |
---|
| 356 | * @return void |
---|
| 357 | * @access public |
---|
| 358 | */ |
---|
| 359 | public static function participantCreated(&$partID, &$schedulable, $type = false, $delegatedParams = false, $organizer = false) { |
---|
[5947] | 360 | $method = 'REQUEST'; |
---|
[6027] | 361 | $notificationType = 'Convite de Calendario'; |
---|
[5947] | 362 | $part = 'attendees'; |
---|
[6027] | 363 | self::mountStruture($partID, $schedulable, $type, $data, $subject, $ical, $part, $method, $notificationType, true); |
---|
[5947] | 364 | |
---|
[6027] | 365 | if ($delegatedParams) |
---|
| 366 | $data = array_merge($data, $delegatedParams); |
---|
[5947] | 367 | |
---|
[6027] | 368 | self::sendMail($data, $ical, $part['user']['mail'], $subject, !$delegatedParams ? 'notify_create_body' : 'notify_create_delegated_body', $organizer); |
---|
[5341] | 369 | } |
---|
[6027] | 370 | |
---|
[5341] | 371 | /** |
---|
[6027] | 372 | * Monta o email de aceito que sera enviado ao organizador |
---|
| 373 | * |
---|
| 374 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 375 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 376 | * @sponsor Caixa Econômica Federal |
---|
| 377 | * @author Cristiano Corrêa Schmidt |
---|
| 378 | * @return void |
---|
| 379 | * @access public |
---|
| 380 | */ |
---|
| 381 | public static function participantStatusChange(&$partID, &$schedulable, &$organizer, $type, $delegatedParams = false) { |
---|
| 382 | $method = 'REPLY'; |
---|
[5947] | 383 | $notificationType = 'Convite Aceito'; |
---|
| 384 | $part = 'me'; |
---|
[5514] | 385 | |
---|
[6027] | 386 | self::mountStruture($partID, $schedulable, $type, $data, $subject, $ical, $part, $method, $notificationType, true); |
---|
[5947] | 387 | |
---|
[6027] | 388 | if ($delegatedParams) { |
---|
| 389 | $data = array_merge($data, $delegatedParams); |
---|
| 390 | $tplDelegated = 'notify_delegated_status_body'; |
---|
[5947] | 391 | } |
---|
| 392 | |
---|
[6027] | 393 | switch ($type) { |
---|
| 394 | case STATUS_ACCEPTED: |
---|
| 395 | $tpl = !$delegatedParams ? 'notify_accept_body' : $tplDelegated; |
---|
| 396 | $subject['notificationType'] = 'Convite Aceito'; |
---|
| 397 | break; |
---|
| 398 | case STATUS_TENTATIVE: |
---|
| 399 | $tpl = !$delegatedParams ? 'notify_attempt_body' : $tplDelegated; |
---|
| 400 | $subject['notificationType'] = 'Convite aceito provisoriamente'; |
---|
| 401 | break; |
---|
| 402 | case STATUS_CANCELLED: |
---|
| 403 | $tpl = !$delegatedParams ? 'notify_reject_body' : $tplDelegated; |
---|
| 404 | $subject['notificationType'] = 'Convite rejeitado'; |
---|
| 405 | break; |
---|
| 406 | case STATUS_DELEGATED: |
---|
| 407 | if ($delegatedParams) |
---|
| 408 | $data = array_merge($data, $delegatedParams); |
---|
| 409 | $tpl = 'notify_delegated_body'; |
---|
| 410 | $subject['notificationType'] = 'Convite delegado'; |
---|
| 411 | break; |
---|
| 412 | } |
---|
[5341] | 413 | |
---|
[6027] | 414 | self::sendMail($data, $ical, $organizer['user']['mail'], $subject, $tpl, false); |
---|
[5341] | 415 | } |
---|
[6027] | 416 | |
---|
[5341] | 417 | /** |
---|
[6027] | 418 | * Monta o body e envia o email |
---|
| 419 | * |
---|
| 420 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 421 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 422 | * @sponsor Caixa Econômica Federal |
---|
| 423 | * @author Cristiano Corrêa Schmidt |
---|
| 424 | * @return void |
---|
| 425 | * @access public |
---|
| 426 | */ |
---|
| 427 | private static function sendMail(&$data, &$ical, $to, &$subject, $template, $from = false) { |
---|
| 428 | $ical2 = $ical; |
---|
| 429 | $ical2['type'] = 'text/calendar'; |
---|
| 430 | $ical2['name'] = 'thunderbird.ics'; |
---|
| 431 | $mail['attachments'][] = $ical2; |
---|
| 432 | $mail['attachments'][] = $ical; |
---|
| 433 | $mail['isHtml'] = true; |
---|
| 434 | $mail['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/' . $template . '.tpl'); |
---|
| 435 | $mail['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl'); |
---|
| 436 | ; |
---|
| 437 | $mail['from'] = $from ? ('"' . $from['user']['name'] . '" <' . $from['user']['mail'] . '>') : ('"' . Config::me('cn') . '" <' . Config::me('mail') . '>'); |
---|
| 438 | $mail['to'] = $to; |
---|
| 439 | Controller::create(array('service' => 'SMTP'), $mail); |
---|
[5341] | 440 | } |
---|
[6027] | 441 | |
---|
[5341] | 442 | /** |
---|
[6027] | 443 | * Monta o email de cancelado que sera enviado a todos os participantes |
---|
| 444 | * |
---|
| 445 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 446 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 447 | * @sponsor Caixa Econômica Federal |
---|
| 448 | * @author Cristiano Corrêa Schmidt |
---|
| 449 | * @return void |
---|
| 450 | * @access public |
---|
| 451 | */ |
---|
| 452 | public function deleteEvent(&$uri, &$result, &$params, $original) { |
---|
| 453 | $schedulable = Controller::read(array('concept' => 'schedulable', 'id' => $uri['id']), null, array('deepness' => '2')); |
---|
[6177] | 454 | if ((Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id']))) { |
---|
[5947] | 455 | $method = 'CANCEL'; |
---|
| 456 | $notificationType = 'Cancelamento de Calendario'; |
---|
| 457 | $part = 'othersAttendees'; |
---|
[6027] | 458 | self::mountStruture($uri['id'], $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); |
---|
| 459 | |
---|
| 460 | if (count($part) > 0) |
---|
| 461 | self::sendMail($data, $ical, implode(',', $part), $subject, 'notify_cancel_body'); |
---|
| 462 | } |
---|
[5341] | 463 | } |
---|
[6027] | 464 | |
---|
[5341] | 465 | /** |
---|
[6027] | 466 | * Monta o email de cancelado que sera enviado ao participant deleteado |
---|
| 467 | * |
---|
| 468 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 469 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 470 | * @sponsor Caixa Econômica Federal |
---|
| 471 | * @author Cristiano Corrêa Schmidt |
---|
| 472 | * @return void |
---|
| 473 | * @access public |
---|
| 474 | */ |
---|
| 475 | public function deleteParticipant(&$uri, &$result, &$params, $original) { |
---|
| 476 | |
---|
| 477 | $participant = Controller::read(array('concept' => 'participant', 'id' => $uri['id']), null, array('deepness' => '1')); |
---|
| 478 | $schedulable = Controller::read(array('concept' => 'schedulable', 'id' => $participant['schedulable'])); |
---|
| 479 | |
---|
[6177] | 480 | if ((Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id']))) { |
---|
[5947] | 481 | $method = 'CANCEL'; |
---|
| 482 | $notificationType = 'Cancelamento de Calendario'; |
---|
| 483 | $part = 'others'; |
---|
[6027] | 484 | self::mountStruture(false, $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); |
---|
[5947] | 485 | |
---|
[6027] | 486 | self::sendMail($data, $ical, $participant['user']['mail'], $subject, 'notify_cancel_body'); |
---|
| 487 | } |
---|
[5341] | 488 | } |
---|
[6027] | 489 | |
---|
[5341] | 490 | /** |
---|
[6027] | 491 | * Faz um diff do update se ouve realmente uma alteração envia um email a todos os participants |
---|
| 492 | * |
---|
| 493 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 494 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 495 | * @sponsor Caixa Econômica Federal |
---|
| 496 | * @author Cristiano Corrêa Schmidt |
---|
| 497 | * @return void |
---|
| 498 | * @access public |
---|
| 499 | */ |
---|
[6190] | 500 | public function updateEvent(&$uri, $params, &$criteria, $original) { |
---|
[6027] | 501 | $schedulableOld = Controller::read(array('concept' => 'schedulable', 'id' => $uri['id']), null, array('deepness' => '2')); |
---|
| 502 | $schedulable = $schedulableOld; |
---|
| 503 | $alt = false; |
---|
[5514] | 504 | |
---|
[6027] | 505 | foreach ($params as $i => $v) //Verifica se ouve alteração no evento |
---|
| 506 | if (isset($schedulableOld[$i]) && $schedulableOld[$i] != $v && $i != 'participants') { |
---|
| 507 | $schedulable[$i] = $v; |
---|
| 508 | $alt = true; |
---|
| 509 | } |
---|
[6190] | 510 | |
---|
[6177] | 511 | if (($alt === true) && (Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id']))) { |
---|
[5947] | 512 | $method = 'REQUEST'; |
---|
[6027] | 513 | $notificationType = 'Modificação de Calendario'; |
---|
[6038] | 514 | $part = 'othersAttendees'; |
---|
[6027] | 515 | self::mountStruture($uri['id'], $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); |
---|
[5341] | 516 | |
---|
[6027] | 517 | if (isset($part) && $part && count($part) > 0) |
---|
| 518 | self::sendMail($data, $ical, implode(',', $part), $subject, 'notify_modify_body'); |
---|
| 519 | } |
---|
[5341] | 520 | } |
---|
[6038] | 521 | |
---|
| 522 | static private function parseTimeDate($time, $timezone) { |
---|
| 523 | return strtotime($time . ' ' . $timezone) . '000'; |
---|
| 524 | } |
---|
| 525 | |
---|
[6036] | 526 | } |
---|
[6038] | 527 | |
---|
[5341] | 528 | ?> |
---|