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