@@ 307-397 (lines=91) @@ | ||
304 | $letterObj->setVar('letter_submitter', Request::getInt('letter_submitter', 0)); |
|
305 | $letterObj->setVar('letter_created', Request::getInt('letter_created', time())); |
|
306 | ||
307 | if ($helper->getHandler('Letter')->insert($letterObj)) { |
|
308 | $letter_id = $letterObj->getVar('letter_id'); |
|
309 | // update existing_attachments |
|
310 | $existing_attachments_mode = Request::getArray('existing_attachments_mode', []); |
|
311 | foreach ($existing_attachments_mode as $attachment_id => $attachment_mode) { |
|
312 | $attachmentObj = $helper->getHandler('Attachment')->get($attachment_id); |
|
313 | $attachmentObj->setVar('attachment_mode', $attachment_mode); |
|
314 | $helper->getHandler('Attachment')->insert($attachmentObj); |
|
315 | } |
|
316 | // upload attachments |
|
317 | $uploadedFiles = []; |
|
318 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
319 | $uploaddir = XOOPS_UPLOAD_PATH . $helper->getConfig('xn_attachment_path') . $letterId . '/'; |
|
320 | // check upload_dir |
|
321 | if (!is_dir($uploaddir)) { |
|
322 | $indexFile = XOOPS_UPLOAD_PATH . '/index.html'; |
|
323 | if (!mkdir($uploaddir, 0777) && !is_dir($uploaddir)) { |
|
324 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $uploaddir)); |
|
325 | } |
|
326 | chmod($uploaddir, 0777); |
|
327 | copy($indexFile, $uploaddir . 'index.html'); |
|
328 | } |
|
329 | $new_attachments_mode = Request::getArray('new_attachments_mode', []); |
|
330 | for ($upl = 0; $upl < $helper->getConfig('xn_maxattachments'); ++$upl) { |
|
331 | $uploader = new \XoopsMediaUploader($uploaddir, $helper->getConfig('xn_mimetypes'), $helper->getConfig('xn_maxsize'), null, null); |
|
332 | if ($uploader->fetchMedia(@$_POST['xoops_upload_file'][$upl])) { |
|
333 | //$uploader->setPrefix("xn_") ; keep original name |
|
334 | $uploader->fetchMedia($_POST['xoops_upload_file'][$upl]); |
|
335 | if (!$uploader->upload()) { |
|
336 | $errors = $uploader->getErrors(); |
|
337 | redirect_header('<script>javascript:history.go(-1)</script>', 3, $errors); |
|
338 | } else { |
|
339 | preg_match('/ne\w_attachment_index=([0-9]+)/', $_POST['xoops_upload_file'][$upl], $matches); |
|
340 | $index = $matches[1]; |
|
341 | $uploadedFiles[] = [ |
|
342 | 'name' => $uploader->getSavedFileName(), |
|
343 | 'type' => $uploader->getMediaType(), |
|
344 | 'size' => $uploader->getMediaSize(), |
|
345 | 'mode' => $new_attachments_mode[$index], |
|
346 | ]; |
|
347 | } |
|
348 | } |
|
349 | } |
|
350 | // create items in attachments |
|
351 | foreach ($uploadedFiles as $file) { |
|
352 | $attachmentObj = $helper->getHandler('Attachment')->create(); |
|
353 | $attachmentObj->setVar('attachment_letter_id', $letterId); |
|
354 | $attachmentObj->setVar('attachment_name', $file['name']); |
|
355 | $attachmentObj->setVar('attachment_type', $file['type']); |
|
356 | $attachmentObj->setVar('attachment_submitter', $xoopsUser->uid()); |
|
357 | $attachmentObj->setVar('attachment_created', time()); |
|
358 | $attachmentObj->setVar('attachment_size', $file['size']); |
|
359 | $attachmentObj->setVar('attachment_mode', $file['mode']); |
|
360 | ||
361 | $helper->getHandler('Attachment')->insert($attachmentObj); |
|
362 | } |
|
363 | // create item in protocol |
|
364 | $protocolObj = $helper->getHandler('Protocol')->create(); |
|
365 | $protocolObj->setVar('protocol_letter_id', $letterId); |
|
366 | $protocolObj->setVar('protocol_subscriber_id', 0); |
|
367 | $protocolObj->setVar('protocol_success', true); |
|
368 | $action = Request::getInt('letter_action', _XNEWSLETTER_LETTER_ACTION_VAL_NO); |
|
369 | switch ($action) { |
|
370 | case _XNEWSLETTER_LETTER_ACTION_VAL_PREVIEW: |
|
371 | $redirectUrl = "?op=show_preview&letter_id={$letterId}"; |
|
372 | break; |
|
373 | case _XNEWSLETTER_LETTER_ACTION_VAL_SEND: |
|
374 | $redirectUrl = "sendletter.php?op=send_letter&letter_id={$letterId}"; |
|
375 | break; |
|
376 | case _XNEWSLETTER_LETTER_ACTION_VAL_SENDTEST: |
|
377 | $redirectUrl = "sendletter.php?op=send_test&letter_id={$letterId}"; |
|
378 | break; |
|
379 | default: |
|
380 | $redirectUrl = '?op=list_letters'; |
|
381 | break; |
|
382 | } |
|
383 | $protocolObj->setVar('protocol_status', _AM_XNEWSLETTER_LETTER_ACTION_SAVED); // old style |
|
384 | $protocolObj->setVar('protocol_status_str_id', _XNEWSLETTER_PROTOCOL_STATUS_SAVED); // new from v1.3 |
|
385 | $protocolObj->setVar('protocol_status_vars', []); // new from v1.3 |
|
386 | $protocolObj->setVar('protocol_submitter', $xoopsUser->uid()); |
|
387 | $protocolObj->setVar('protocol_created', time()); |
|
388 | ||
389 | if ($helper->getHandler('Protocol')->insert($protocolObj)) { |
|
390 | // create protocol is ok |
|
391 | redirect_header($redirectUrl, 3, _AM_XNEWSLETTER_FORMOK); |
|
392 | } else { |
|
393 | $GLOBALS['xoopsTpl']->assign('error', $protocolObj->getHtmlErrors()); |
|
394 | } |
|
395 | } else { |
|
396 | $GLOBALS['xoopsTpl']->assign('error', $letterObj->getHtmlErrors()); |
|
397 | } |
|
398 | break; |
|
399 | case 'clone_letter': |
|
400 | case 'copy_letter': |
@@ 482-572 (lines=91) @@ | ||
479 | $letterObj->setVar('letter_submitter', Request::getInt('letter_submitter', 0)); |
|
480 | $letterObj->setVar('letter_created', Request::getInt('letter_created', time())); |
|
481 | ||
482 | if ($helper->getHandler('Letter')->insert($letterObj)) { |
|
483 | $letter_id = $letterObj->getVar('letter_id'); |
|
484 | // update existing_attachments |
|
485 | $existing_attachments_mode = Request::getArray('existing_attachments_mode', []); |
|
486 | foreach ($existing_attachments_mode as $attachment_id => $attachment_mode) { |
|
487 | $attachmentObj = $helper->getHandler('Attachment')->get($attachment_id); |
|
488 | $attachmentObj->setVar('attachment_mode', $attachment_mode); |
|
489 | $helper->getHandler('Attachment')->insert($attachmentObj); |
|
490 | } |
|
491 | // upload attachments |
|
492 | $uploadedFiles = []; |
|
493 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
494 | $uploaddir = XOOPS_UPLOAD_PATH . $helper->getConfig('xn_attachment_path') . $letter_id . '/'; |
|
495 | // check upload_dir |
|
496 | if (!is_dir($uploaddir)) { |
|
497 | $indexFile = XOOPS_UPLOAD_PATH . '/index.html'; |
|
498 | if (!mkdir($uploaddir, 0777) && !is_dir($uploaddir)) { |
|
499 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $uploaddir)); |
|
500 | } |
|
501 | chmod($uploaddir, 0777); |
|
502 | copy($indexFile, $uploaddir . 'index.html'); |
|
503 | } |
|
504 | $new_attachments_mode = Request::getArray('new_attachments_mode', []); |
|
505 | for ($upl = 0; $upl < $helper->getConfig('xn_maxattachments'); ++$upl) { |
|
506 | $uploader = new \XoopsMediaUploader($uploaddir, $helper->getConfig('xn_mimetypes'), $helper->getConfig('xn_maxsize'), null, null); |
|
507 | if ($uploader->fetchMedia(@$_POST['xoops_upload_file'][$upl])) { |
|
508 | //$uploader->setPrefix("xn_") ; keep original name |
|
509 | $uploader->fetchMedia($_POST['xoops_upload_file'][$upl]); |
|
510 | if (!$uploader->upload()) { |
|
511 | $errors = $uploader->getErrors(); |
|
512 | redirect_header('<script>javascript:history.go(-1)</script>', 3, $errors); |
|
513 | } else { |
|
514 | preg_match('/ne\w_attachment_index=([0-9]+)/', $_POST['xoops_upload_file'][$upl], $matches); |
|
515 | $index = $matches[1]; |
|
516 | $uploadedFiles[] = [ |
|
517 | 'name' => $uploader->getSavedFileName(), |
|
518 | 'type' => $uploader->getMediaType(), |
|
519 | 'size' => $uploader->getMediaSize(), |
|
520 | 'mode' => $new_attachments_mode[$index], |
|
521 | ]; |
|
522 | } |
|
523 | } |
|
524 | } |
|
525 | // create items in attachments |
|
526 | foreach ($uploadedFiles as $file) { |
|
527 | $attachmentObj = $helper->getHandler('Attachment')->create(); |
|
528 | $attachmentObj->setVar('attachment_letter_id', $letter_id); |
|
529 | $attachmentObj->setVar('attachment_name', $file['name']); |
|
530 | $attachmentObj->setVar('attachment_type', $file['type']); |
|
531 | $attachmentObj->setVar('attachment_submitter', $xoopsUser->uid()); |
|
532 | $attachmentObj->setVar('attachment_created', time()); |
|
533 | $attachmentObj->setVar('attachment_size', $file['size']); |
|
534 | $attachmentObj->setVar('attachment_mode', $file['mode']); |
|
535 | ||
536 | $helper->getHandler('Attachment')->insert($attachmentObj); |
|
537 | } |
|
538 | // create item in protocol |
|
539 | $protocolObj = $helper->getHandler('Protocol')->create(); |
|
540 | $protocolObj->setVar('protocol_letter_id', $letter_id); |
|
541 | $protocolObj->setVar('protocol_subscriber_id', 0); |
|
542 | $protocolObj->setVar('protocol_success', true); |
|
543 | $action = Request::getInt('letter_action', _XNEWSLETTER_LETTER_ACTION_VAL_NO); |
|
544 | switch ($action) { |
|
545 | case _XNEWSLETTER_LETTER_ACTION_VAL_PREVIEW: |
|
546 | $redirectUrl = "?op=show_preview&letter_id={$letter_id}"; |
|
547 | break; |
|
548 | case _XNEWSLETTER_LETTER_ACTION_VAL_SEND: |
|
549 | $redirectUrl = "sendletter.php?op=send_letter&letter_id={$letter_id}"; |
|
550 | break; |
|
551 | case _XNEWSLETTER_LETTER_ACTION_VAL_SENDTEST: |
|
552 | $redirectUrl = "sendletter.php?op=send_test&letter_id={$letter_id}"; |
|
553 | break; |
|
554 | default: |
|
555 | $redirectUrl = '?op=list_letters'; |
|
556 | break; |
|
557 | } |
|
558 | $protocolObj->setVar('protocol_status', _AM_XNEWSLETTER_LETTER_ACTION_SAVED); |
|
559 | $protocolObj->setVar('protocol_status_str_id', _XNEWSLETTER_PROTOCOL_STATUS_SAVED); // new from v1.3 |
|
560 | $protocolObj->setVar('protocol_status_vars', []); // new from v1.3 |
|
561 | $protocolObj->setVar('protocol_submitter', $xoopsUser->uid()); |
|
562 | $protocolObj->setVar('protocol_created', time()); |
|
563 | ||
564 | if ($helper->getHandler('Protocol')->insert($protocolObj)) { |
|
565 | // create protocol is ok |
|
566 | redirect_header($redirectUrl, 3, _AM_XNEWSLETTER_FORMOK); |
|
567 | } else { |
|
568 | $GLOBALS['xoopsTpl']->assign('error', 'Error create protocol: ' . $protocolObj->getHtmlErrors()); |
|
569 | } |
|
570 | } else { |
|
571 | $GLOBALS['xoopsTpl']->assign('error', 'Error create letter: ' . $protocolObj->getHtmlErrors()); |
|
572 | } |
|
573 | break; |
|
574 | case 'copy_letter': |
|
575 | case 'clone_letter': |