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