Beispiel #1
0
 public function publish_item()
 {
     $return = $this->change_state('published', true);
     if ($return == 1) {
         $app = JFactory::getApplication();
         $from = $app->getCfg('mailfrom');
         $fromname = $app->getCfg('fromname');
         $sitename = $app->getCfg('sitename');
         $model = $this->getModel('surveys');
         $id = $app->input->getInt('id');
         $survey = $model->get_survey_details($id);
         if (!empty($survey)) {
             $body = JText::sprintf('COM_COMMUNITYSURVEYS_NOTIF_APPROVAL_BODY', $survey->name, $survey->title, $sitename);
             $title = JText::sprintf('COM_COMMUNITYSURVEYS_NOTIF_APPROVAL_TITLE', $sitename);
             CJFunctions::send_email($from, $fromname, $survey->email, $title, $body, 1);
         }
         echo json_encode(array('data' => 1));
     } else {
         if (!JFactory::getUser()->authorise('core.edit.state', S_APP_NAME)) {
             echo json_encode(array('error' => JText::_('COM_COMMUNITYSURVEYS_NOT_AUTHORIZED')));
         } else {
             $msg = $return == 0 ? JText::_('COM_COMMUNITYSURVEYS_MSG_ERROR') : JText::_('COM_COMMUNITYSURVEYS_MSG_NO_ITEM_SELECTED');
             echo json_encode(array('error' => $msg));
         }
     }
     jexit();
 }
Beispiel #2
0
 public static function send_messages_from_queue($records = 60, $delay = 0, $simulated = true, $force_ids = array())
 {
     if ($simulated) {
         $cjconfig = CJLib::get_cjconfig();
         if ($cjconfig['manual_cron'] == '1') {
             require_once CJLIB_PATH . DS . 'framework' . DS . 'virtualcron.php';
             $delay = $delay > 0 ? $delay : intval($cjconfig['cron_delay']);
             $vcron = new virtualcron($delay, 'virtualcron.txt');
             if (!$vcron->allowAction()) {
                 return false;
             }
         } else {
             return false;
         }
     }
     $db = JFactory::getDbo();
     $app = JFactory::getApplication();
     $from = $app->getCfg('mailfrom');
     $fromname = $app->getCfg('fromname');
     $message_ids = array();
     $sent = array();
     $query = $db->getQuery(true);
     $query->select('id, to_addr, cc_addr, bcc_addr, html, message_id, params')->from('#__corejoomla_messagequeue');
     if (!empty($force_ids)) {
         $query->where('id in (' . implode(',', $force_ids) . ') and status = 0');
     } else {
         $query->where('status = 0');
     }
     $db->setQuery($query, 0, $records);
     $queue_items = array();
     try {
         $queue_items = $db->loadObjectList();
     } catch (Exception $e) {
         return false;
     }
     if (!empty($queue_items)) {
         foreach ($queue_items as $item) {
             $message_ids[] = $item->message_id;
         }
         $message_ids = array_unique($message_ids);
         $query = $db->getQuery(true);
         $query->select('id, asset_id, asset_name, subject, description, params')->from('#__corejoomla_messages')->where('id in (' . implode(',', $message_ids) . ')');
         $db->setQuery($query);
         $messages = array();
         try {
             $messages = $db->loadObjectList('id');
         } catch (Exception $e) {
             return false;
         }
         if (!empty($messages)) {
             $template_path = CJLIB_PATH . DS . 'framework' . DS . 'mail_templates' . DS;
             foreach ($messages as &$message) {
                 $params = json_decode($message->params);
                 if (!empty($params->template) && JFile::exists($template_path . $params->template)) {
                     $template = file_get_contents($template_path . $params->template);
                     if (!empty($params->placeholders)) {
                         foreach ($params->placeholders as $key => $value) {
                             $template = str_replace($key, $value, $template);
                         }
                     }
                     $message->description = str_replace('{description}', $message->description, $template);
                 }
             }
             $ids = array();
             foreach ($queue_items as $item) {
                 $ids[] = $item->id;
                 if (!empty($messages[$item->message_id])) {
                     $description = $messages[$item->message_id]->description;
                     if (!empty($item->params)) {
                         $params = json_decode($item->params);
                         if (!empty($params->placeholders)) {
                             foreach ($params->placeholders as $key => $value) {
                                 $description = str_replace($key, $value, $description);
                             }
                         }
                     }
                     try {
                         $return = CJFunctions::send_email($from, $fromname, $item->to_addr, $messages[$item->message_id]->subject, $description, $item->html, $item->cc_addr, $item->bcc_addr);
                         if ($return === true) {
                             $sent[] = $item->id;
                         }
                     } catch (Exception $e) {
                         // Add logger
                         $date = JFactory::getDate()->format('Y.m.d');
                         JLog::addLogger(array('text_file' => 'com_cjlib.' . $date . '.log.php'), JLog::ALL, 'com_cjlib');
                         JLog::add('Send Messages From Queue - Error: ' . print_r($e, true), JLog::ERROR, 'com_cjlib');
                     }
                 }
             }
             if (!empty($ids)) {
                 $created = JFactory::getDate()->toSql();
                 $query = $db->getQuery(true);
                 $query->update($db->qn('#__corejoomla_messagequeue'))->set($db->qn('status') . ' = 1, processed = ' . $db->q($created))->where('id in (' . implode(',', $ids) . ')');
                 $db->setQuery($query);
                 try {
                     $db->execute();
                 } catch (Exception $e) {
                     return false;
                 }
             }
         }
     }
     return $sent;
 }
Beispiel #3
0
 function finalize_survey()
 {
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     if (!$user->authorise('core.create', S_APP_NAME)) {
         CJFunctions::throw_error(JText::_('MSG_UNAUTHORIZED'), 401);
     } else {
         $model = JModelLegacy::getInstance('survey', 'CommunitySurveysModel');
         $id = JRequest::getInt('id', 0);
         $survey = $model->get_survey_details($id, true);
         $itemid = CJFunctions::get_active_menu_id();
         if ($survey->published == 3) {
             $status = $user->authorise('core.autoapprove', S_APP_NAME) ? 1 : 2;
             if (!$model->finalize_survey($id, $status)) {
                 $error = S_DEBUG_ENABLED ? $model->getError() : '';
                 $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=surveys&task=list' . $itemid, false), JText::_('MSG_ERROR_PROCESSING') . $error);
             } else {
                 $config = JComponentHelper::getParams(S_APP_NAME);
                 if (!$user->authorise('core.autoapprove', S_APP_NAME)) {
                     if ($config->get('admin_new_survey_notification', 1) == 1) {
                         $from = $app->getCfg('mailfrom');
                         $fromname = $app->getCfg('fromname');
                         $admin_emails = $model->get_admin_emails($params->get('admin_user_groups', 8));
                         if (!empty($admin_emails)) {
                             CJFunctions::send_email($from, $fromname, $admin_emails, JText::_('MSG_MAIL_PENDING_REVIEW_SUBJECT'), JText::_('MSG_MAIL_PENDING_REVIEW_BODY'), 1);
                         }
                     }
                     $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=surveys&task=list' . $itemid, false), JText::_('MSG_SENT_FOR_REVIEW'));
                 } else {
                     $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=surveys&task=list' . $itemid, false), JText::_('MSG_SUCCESSFULLY_SAVED'));
                 }
             }
         } else {
             $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=surveys&task=list' . $itemid, false), JText::_('MSG_SUCCESSFULLY_SAVED'));
         }
     }
 }
Beispiel #4
0
 function finalize_survey()
 {
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     $model = $this->getModel('survey');
     $id = JRequest::getInt('id', 0);
     $itemid = CJFunctions::get_active_menu_id();
     $survey = $model->get_survey_details($id, true);
     if ($user->authorise('core.create', S_APP_NAME . '.category.' . $survey->catid) || $user->authorise('core.manage', S_APP_NAME)) {
         if ($survey->published == 3) {
             $status = $user->authorise('core.autoapprove', S_APP_NAME . '.category.' . $survey->catid) ? 1 : 2;
             if (!$model->finalize_survey($id, $status)) {
                 $error = S_DEBUG_ENABLED ? $model->getError() : '';
                 $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=list' . $itemid, false), JText::_('MSG_ERROR_PROCESSING') . $error);
             } else {
                 $config = JComponentHelper::getParams(S_APP_NAME);
                 if (!$user->authorise('core.autoapprove', S_APP_NAME . '.category.' . $survey->catid)) {
                     if ($config->get('admin_new_survey_notification', 1) == 1) {
                         $from = $app->getCfg('mailfrom');
                         $fromname = $app->getCfg('fromname');
                         $params = JComponentHelper::getParams(S_APP_NAME);
                         $admin_emails = $model->get_admin_emails($params->get('admin_user_groups', 8));
                         if (!empty($admin_emails)) {
                             CJFunctions::send_email($from, $fromname, $admin_emails, JText::_('MSG_MAIL_PENDING_REVIEW_SUBJECT'), JText::_('MSG_MAIL_PENDING_REVIEW_BODY'), 1);
                         }
                     }
                     $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=list' . $itemid, false), JText::_('MSG_SENT_FOR_REVIEW'));
                 } else {
                     if ($survey->private_survey == 0) {
                         $link = JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=take_survey&id=' . $survey->id . ":" . $survey->alias . $itemid);
                         CJFunctions::stream_activity($config->get('activity_stream_type', 'none'), $user->id, array('command' => A_APP_NAME . '.new_survey', 'component' => S_APP_NAME, 'title' => JText::sprintf('TXT_CREATED_SURVEY', $link, $survey->title), 'href' => $link, 'description' => $survey->introtext, 'length' => $config->get('stream_character_limit', 256), 'icon' => 'components/' . S_APP_NAME . '/assets/images/icon-16-survey.png', 'group' => 'Surveys'));
                     }
                     $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=list' . $itemid, false), JText::_('MSG_SUCCESSFULLY_SAVED'));
                 }
             }
         } else {
             $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=list' . $itemid, false), JText::_('MSG_SUCCESSFULLY_SAVED'));
         }
     } else {
         $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey' . $survey_itemid, false), JText::_('MSG_UNAUTHORIZED'));
     }
 }
Beispiel #5
0
 private function finalize_response($survey, $response_id, $redirect = true)
 {
     $user = JFactory::getUser();
     $itemid = CJFunctions::get_active_menu_id();
     $model = $this->getModel('survey');
     $app = JFactory::getApplication();
     if ($model->finalize_response($survey->id, $response_id)) {
         $params = JComponentHelper::getParams(S_APP_NAME);
         $userdisplayname = $params->get('user_display_name', 'name');
         SurveyHelper::award_points($params, $survey->created_by, 2, $response_id, JText::sprintf('TXT_RESPONDED_SURVEY', $survey->username, $survey->title));
         SurveyHelper::award_points($params, $user->id, 3, $response_id, JText::sprintf('TXT_RESPONDED_SURVEY', $user->{$userdisplayname}, $survey->title));
         $menuid = CJFunctions::get_active_menu_id(true, 'index.php?option=' . S_APP_NAME . '&view=survey');
         $link = $survey->private_survey == 1 ? $survey->title : JHtml::link(JRoute::_('index.php?option=' . S_APP_NAME . '&view=response&task=take_survey&id=' . $survey->id . ":" . $survey->alias . $menuid), $survey->title);
         CJFunctions::stream_activity($params->get('activity_stream_type', 'none'), $user->id, array('command' => 'com_communitysurveys.response', 'component' => S_APP_NAME, 'title' => JText::sprintf('TXT_RESPONDED_SURVEY', '{actor}', $link), 'description' => $survey->introtext, 'length' => $params->get('stream_character_limit', 256), 'icon' => 'components/' . S_APP_NAME . '/assets/images/icon-16-surveys.png', 'group' => 'Surveys'));
         if ($survey->notification == 1 && $params->get('new_response_notification', 1) == 1) {
             $from = $app->getCfg('mailfrom');
             $fromname = $app->getCfg('fromname');
             $link = JRoute::_('index.php?option=' . S_APP_NAME . '&view=reports&task=dashboard&id=' . $survey->id . ':' . $survey->alias . $itemid, false, -1);
             $body = '';
             if ($survey->anonymous == 1) {
                 $body = JText::sprintf('EMAIL_NEW_RESPONSE_ANONYMOUS_BODY', $survey->username, $survey->title, $link, $app->getCfg('sitename'));
             } else {
                 $body = JText::sprintf('EMAIL_NEW_RESPONSE_BODY', $survey->username, $user->username, $survey->title, $link, $app->getCfg('sitename'));
             }
             if ($params->get('embed_pdf_report', 1) == 1) {
                 // All validations done, write data now
                 require_once JPATH_COMPONENT_SITE . '/helpers/reports.php';
                 $generator = new SurveyReports();
                 $filePath = JPATH_ROOT . '/tmp/survey_' . $survey->id . '_' . date('dmYHis') . '.pdf';
                 $pdfData = $model->get_reponse_data_for_csv($survey->id, array($response_id), true);
                 $generator->generatePdfReport($pdfData, 'F', $params, $filePath);
                 CJFunctions::send_email($from, $fromname, $survey->email, JText::_('EMAIL_NEW_RESPONSE_TITLE'), $body, 1, null, null, $filePath);
             } else {
                 CJFunctions::send_email($from, $fromname, $survey->email, JText::_('EMAIL_NEW_RESPONSE_TITLE'), $body, 1, null, null);
             }
         }
         if ($redirect) {
             if (empty($survey->redirect_url)) {
                 if ($survey->public_permissions == '1' && $user->authorise('core.results', S_APP_NAME)) {
                     $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=response&task=view_result&id=' . $survey->id . ':' . $survey->alias . '&rid=' . $response_id . $itemid, false), JText::_('MSG_SURVEY_COMPLETE'));
                 } else {
                     $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=response&task=end_message&id=' . $survey->id . ':' . $survey->alias . $itemid, false), JText::_('MSG_SURVEY_COMPLETE'));
                 }
             } else {
                 $this->setRedirect($survey->redirect_url, JText::_('MSG_SURVEY_COMPLETE'));
             }
         } else {
             return true;
         }
     } else {
         $msg = S_DEBUG_ENABLED ? JText::_('MSG_ERROR_PROCESSING') . $model->getError() : JText::_('MSG_ERROR_PROCESSING');
         if ($redirect) {
             $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=take_survey&id=' . $survey->id . $itemid, false), $msg);
         } else {
             return false;
         }
     }
 }