Example #1
0
 function action_email_wikipage($input)
 {
     Services_Exception_Disabled::check('feature_wiki');
     Services_Exception_Denied::checkGlobal('admin_users');
     $check = Services_Exception_BadRequest::checkAccess();
     //first pass - show confirm popup
     if (!empty($check['ticket'])) {
         $users = $input->asArray('checked');
         if (count($users) > 0) {
             //provide redirect if js is not enabled
             $referer = Services_Utilities_Controller::noJsPath();
             return ['title' => tra('Send wiki page content by email to selected users'), 'confirmAction' => $input->action->word(), 'confirmController' => 'user', 'customMsg' => tra('For these selected users:'), 'items' => $users, 'extra' => ['referer' => $referer], 'ticket' => $check['ticket'], 'modal' => '1', 'confirm' => 'y'];
         } else {
             throw new Services_Exception(tra('No users were selected. Please select one or more users.'), 409);
         }
         //after confirm submit - perform action and return success feedback
     } elseif ($check === true && $_SERVER['REQUEST_METHOD'] === 'POST') {
         $wikiTpl = $input['wikiTpl'];
         $tikilib = TikiLib::lib('tiki');
         $pageinfo = $tikilib->get_page_info($wikiTpl);
         if (!$pageinfo) {
             throw new Services_Exception_NotFound(tra('Page not found'));
         }
         if (empty($pageinfo['description'])) {
             throw new Services_Exception(tra('The page does not have a description, which is mandatory to perform this action.'));
         }
         $bcc = $input['bcc'];
         include_once 'lib/webmail/tikimaillib.php';
         $mail = new TikiMail();
         if (!empty($bcc)) {
             if (!validate_email($bcc)) {
                 throw new Services_Exception(tra('Invalid bcc email address.'));
             }
             $mail->setBcc($bcc);
             $bccmsg = tr('and blind copied to %0', $bcc);
         }
         $foo = parse_url($_SERVER['REQUEST_URI']);
         $machine = $tikilib->httpPrefix(true) . dirname($foo['path']);
         $machine = preg_replace('!/$!', '', $machine);
         // just in case
         global $smarty, $user;
         $smarty->assign_by_ref('mail_machine', $machine);
         $users = json_decode($input['items'], true);
         $logslib = TikiLib::lib('logs');
         foreach ($users as $mail_user) {
             $smarty->assign_by_ref('user', $mail_user);
             $mail->setUser($mail_user);
             $mail->setSubject($pageinfo['description']);
             $text = $smarty->fetch('wiki:' . $wikiTpl);
             if (empty($text)) {
                 throw new Services_Exception(tra('The template page has no text or it cannot be extracted.'));
             }
             $mail->setHtml($text);
             if (!$mail->send($this->lib->get_user_email($mail_user))) {
                 $errormsg = tra('Unable to send mail');
                 if (Perms::get()->admin) {
                     $mailerrors = print_r($mail->errors, true);
                     $errormsg .= $mailerrors;
                 }
                 throw new Services_Exception($errormsg);
             } else {
                 if (!empty($bcc)) {
                     $logmsg = sprintf(tra('Mail sent to user %s'), $mail_user);
                 }
                 $logmsg = !empty($bccmsg) ? $logmsg . ' ' . $bccmsg : $logmsg;
                 if (!empty($msg)) {
                     $logslib->add_log('adminusers', $logmsg, $user);
                 }
             }
             $smarty->assign_by_ref('user', $user);
         }
         //return to page
         //if javascript is not enabled
         $extra = json_decode($input['extra'], true);
         if (!empty($extra['referer'])) {
             $this->access->redirect($extra['referer'], tra('Page sent'), null, 'feedback');
         }
         $msg = count($users) === 1 ? tr('The page %0 has been emailed to the following user:'******'The page %0 has been emailed to the following users:', $wikiTpl);
         $toMsg = !empty($bcc) ? tr('And blind copied to %0.', $bcc) : '';
         return ['extra' => 'post', 'feedback' => ['ajaxtype' => 'feedback', 'ajaxheading' => tra('Success'), 'ajaxitems' => $users, 'ajaxmsg' => $msg, 'ajaxtoMsg' => $toMsg, 'modal' => '1']];
     }
 }
Example #2
0
 /**
  * Utility used by action_archive_topic and action_unarchive_topic since the code for both is similar
  * @param $input
  * @param $type
  * @return array
  * @throws Exception
  */
 private function archiveUnarchive($input, $type)
 {
     $forumId = $input->forumId->int();
     $this->checkPerms($forumId);
     $check = Services_Exception_BadRequest::checkAccess();
     if (!empty($check['ticket'])) {
         if ($input['comments_parentId']) {
             $topicId = $input->comments_parentId->int();
             $items = $this->getTopicTitles([$topicId]);
             //provide redirect if js is not enabled
             $referer = Services_Utilities_Controller::noJsPath();
             return ['FORWARD' => ['controller' => 'access', 'action' => 'confirm', 'title' => tr('Please confirm %0', tra($type)), 'confirmAction' => $type . '_topic', 'confirmController' => 'forum', 'customVerb' => tra($type), 'customObject' => tra('thread'), 'items' => $items, 'extra' => ['comments_parentId' => $topicId, 'referer' => $referer], 'ticket' => $check['ticket'], 'modal' => '1']];
         } else {
             throw new Services_Exception(tr('No threads were selected. Please select the threads you wish to %0.', tra($type)), 409);
         }
     } elseif ($check === true && $_SERVER['REQUEST_METHOD'] === 'POST') {
         //perform archive/unarchive
         $items = json_decode($input['items'], true);
         $extra = json_decode($input['extra'], true);
         $fn = $type . '_thread';
         $this->lib->{$fn}($extra['comments_parentId']);
         //return to page
         $typedone = $type == 'archive' ? tra('archived') : tra('unarchived');
         //if javascript is not enabled
         $extra = json_decode($input['extra'], true);
         if (!empty($extra['referer'])) {
             $this->access->redirect($extra['referer'], tr('Topic(s) %0', $typedone), null, 'feedback');
         }
         if (count($items) == 1) {
             $msg = tr('The following thread has been %0:', $typedone);
         } else {
             $msg = tr('The following thread have been %0:', $typedone);
         }
         return ['extra' => 'post', 'feedback' => ['ajaxtype' => 'feedback', 'ajaxheading' => tra('Success'), 'ajaxitems' => $items, 'ajaxmsg' => $msg]];
     }
 }