Exemple #1
0
 /**
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 protected function getAbTestFormAction(Request $request)
 {
     $dataArray = array('success' => 0, 'html' => '');
     $type = InputHelper::clean($request->request->get('abKey'));
     $emailId = InputHelper::int($request->request->get('emailId'));
     if (!empty($type)) {
         //get the HTML for the form
         /** @var \Mautic\EmailBundle\Model\EmailModel $model */
         $model = $this->factory->getModel('email');
         $email = $model->getEntity($emailId);
         $abTestComponents = $model->getBuilderComponents($email, 'abTestWinnerCriteria');
         $abTestSettings = $abTestComponents['criteria'];
         if (isset($abTestSettings[$type])) {
             $html = '';
             $formType = !empty($abTestSettings[$type]['formType']) ? $abTestSettings[$type]['formType'] : '';
             if (!empty($formType)) {
                 $formOptions = !empty($abTestSettings[$type]['formTypeOptions']) ? $abTestSettings[$type]['formTypeOptions'] : array();
                 $form = $this->get('form.factory')->create('email_abtest_settings', array(), array('formType' => $formType, 'formTypeOptions' => $formOptions));
                 $html = $this->renderView('MauticEmailBundle:AbTest:form.html.php', array('form' => $this->setFormTheme($form, 'MauticEmailBundle:AbTest:form.html.php', 'MauticEmailBundle:FormTheme\\Email')));
             }
             $html = str_replace(array('email_abtest_settings[', 'email_abtest_settings_', 'email_abtest_settings'), array('emailform[variantSettings][', 'emailform_variantSettings_', 'emailform'), $html);
             $dataArray['html'] = $html;
             $dataArray['success'] = 1;
         }
     }
     return $this->sendJsonResponse($dataArray);
 }
Exemple #2
0
 /**
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 protected function setIntegrationFilterAction(Request $request)
 {
     $session = $this->factory->getSession();
     $pluginFilter = InputHelper::int($this->request->get('plugin'));
     $session->set('mautic.integrations.filter', $pluginFilter);
     return $this->sendJsonResponse(array('success' => 1));
 }
 /**
  * @param Request $request
  * @param         $modelName
  * @param         $abSettingsFormName
  * @param         $parentFormName
  * @param         $abFormTemplate
  * @param array   $formThemes
  *
  * @return mixed
  */
 private function getAbTestForm(Request $request, $modelName, $abSettingsFormName, $parentFormName, $abFormTemplate, $formThemes = [])
 {
     $dataArray = ['success' => 0, 'html' => ''];
     $type = InputHelper::clean($request->request->get('abKey'));
     $id = InputHelper::int($request->request->get('id'));
     if (!empty($type)) {
         //get the HTML for the form
         $model = $this->getModel($modelName);
         $entity = $model->getEntity($id);
         $abTestComponents = $model->getBuilderComponents($entity, 'abTestWinnerCriteria');
         $abTestSettings = $abTestComponents['criteria'];
         if (isset($abTestSettings[$type])) {
             $html = '';
             $formType = !empty($abTestSettings[$type]['formType']) ? $abTestSettings[$type]['formType'] : '';
             if (!empty($formType)) {
                 $formOptions = !empty($abTestSettings[$type]['formTypeOptions']) ? $abTestSettings[$type]['formTypeOptions'] : [];
                 $form = $this->get('form.factory')->create($abSettingsFormName, [], ['formType' => $formType, 'formTypeOptions' => $formOptions]);
                 $html = $this->renderView($abFormTemplate, ['form' => $this->setFormTheme($form, $formThemes)]);
             }
             $html = str_replace(["{$abSettingsFormName}[", "{$abSettingsFormName}_", $abSettingsFormName], ["{$parentFormName}[variantSettings][", "{$parentFormName}_variantSettings_", $parentFormName], $html);
             $dataArray['html'] = $html;
             $dataArray['success'] = 1;
         }
     }
     return $this->sendJsonResponse($dataArray);
 }
Exemple #4
0
 /**
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 protected function getWebsiteSnapshotAction(Request $request)
 {
     $data = ['success' => 0];
     if ($this->get('mautic.security')->isGranted('plugin:focus:items:create')) {
         $website = InputHelper::url($request->request->get('website'));
         if ($website) {
             // Let's try to extract colors from image
             $id = InputHelper::int($request->request->get('id'));
             if (!empty($id)) {
                 // Tell the JS to not populate with default colors
                 $data['ignoreDefaultColors'] = true;
             }
             $snapshotUrl = $this->get('mautic.helper.core_parameters')->getParameter('website_snapshot_url');
             $snapshotKey = $this->get('mautic.helper.core_parameters')->getParameter('website_snapshot_key');
             $http = $this->get('mautic.http.connector');
             $response = $http->get($snapshotUrl . '?url=' . urlencode($website) . '&key=' . $snapshotKey, [], 30);
             if ($response->code === 200) {
                 $package = json_decode($response->body, true);
                 if (isset($package['images'])) {
                     $data['image']['desktop'] = $package['images']['desktop'];
                     $data['image']['mobile'] = $package['images']['mobile'];
                     $palette = $package['palette'];
                     $data['colors'] = ['primaryColor' => $palette[0], 'textColor' => FocusModel::isLightColor($palette[0]) ? '#000000' : '#ffffff', 'buttonColor' => $palette[1], 'buttonTextColor' => FocusModel::isLightColor($palette[1]) ? '#000000' : '#ffffff'];
                     $data['success'] = 1;
                 }
             }
         }
     }
     return $this->sendJsonResponse($data);
 }
 /**
  * Obtains a list of available widget types.
  *
  * @param string $type of the widget
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function getDataAction($type)
 {
     $start = microtime(true);
     $timezone = InputHelper::clean($this->request->get('timezone', null));
     $from = InputHelper::clean($this->request->get('dateFrom', null));
     $to = InputHelper::clean($this->request->get('dateTo', null));
     $dataFormat = InputHelper::clean($this->request->get('dataFormat', null));
     $response = ['success' => 0];
     if ($timezone) {
         $fromDate = new \DateTime($from, new \DateTimeZone($timezone));
         $toDate = new \DateTime($to, new \DateTimeZone($timezone));
     } else {
         $fromDate = new \DateTime($from);
         $toDate = new \DateTime($to);
     }
     $params = ['timeUnit' => InputHelper::clean($this->request->get('timeUnit', 'Y')), 'dateFormat' => InputHelper::clean($this->request->get('dateFormat', null)), 'dateFrom' => $fromDate, 'dateTo' => $toDate, 'limit' => InputHelper::int($this->request->get('limit', null)), 'filter' => $this->request->get('filter', [])];
     $cacheTimeout = InputHelper::int($this->request->get('cacheTimeout', null));
     $widgetHeight = InputHelper::int($this->request->get('height', 300));
     $widget = new Widget();
     $widget->setParams($params);
     $widget->setType($type);
     $widget->setHeight($widgetHeight);
     if ($cacheTimeout === null) {
         $widget->setCacheTimeout($cacheTimeout);
     }
     $this->model->populateWidgetContent($widget);
     $data = $widget->getTemplateData();
     if (!$data) {
         return $this->notFound();
     }
     if ($dataFormat == 'raw') {
         if (isset($data['chartData']['labels']) && isset($data['chartData']['datasets'])) {
             $rawData = [];
             foreach ($data['chartData']['datasets'] as $dataset) {
                 $rawData[$dataset['label']] = [];
                 foreach ($dataset['data'] as $key => $value) {
                     $rawData[$dataset['label']][$data['chartData']['labels'][$key]] = $value;
                 }
             }
             $data = $rawData;
         } elseif (isset($data['raw'])) {
             $data = $data['raw'];
         }
     } else {
         if (isset($data['raw'])) {
             unset($data['raw']);
         }
     }
     $response['cached'] = $widget->isCached();
     $response['execution_time'] = microtime(true) - $start;
     $response['success'] = 1;
     $response['data'] = $data;
     $view = $this->view($response, Codes::HTTP_OK);
     return $this->handleView($view);
 }
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 protected function updateDownloadChartAction(Request $request)
 {
     $assetId = InputHelper::int($request->request->get('assetId'));
     $amount = InputHelper::int($request->request->get('amount'));
     $unit = InputHelper::clean($request->request->get('unit'));
     $dataArray = array('success' => 0);
     // Download stats per time period
     $dataArray['stats'] = $this->factory->getEntityManager()->getRepository('MauticAssetBundle:Download')->getDownloads($assetId, $amount, $unit);
     $dataArray['success'] = 1;
     return $this->sendJsonResponse($dataArray);
 }
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 protected function updateGraphAction(Request $request)
 {
     $reportId = InputHelper::int($request->request->get('reportId'));
     $options = InputHelper::clean($request->request->all());
     $dataArray = array('success' => 0);
     /* @type \Mautic\ReportBundle\Model\ReportModel $model */
     $model = $this->factory->getModel('report');
     $report = $model->getEntity($reportId);
     $options['ignoreTableData'] = true;
     $reportData = $model->getReportData($report, $this->container->get('form.factory'), $options);
     $dataArray['graph'] = $reportData['graphs'][$options['graphName']]['data'];
     $dataArray['success'] = 1;
     return $this->sendJsonResponse($dataArray);
 }
Exemple #8
0
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 protected function updateFormFieldsAction(Request $request)
 {
     $formId = InputHelper::int($request->request->get('formId'));
     $dataArray = array('success' => 0);
     $model = $this->factory->getModel('form');
     $entity = $model->getEntity($formId);
     $formFields = $entity->getFields();
     $fields = array();
     foreach ($formFields as $field) {
         if ($field->getType() != 'button') {
             $properties = $field->getProperties();
             $options = array();
             if (!empty($properties['list']['list'])) {
                 $options = $properties['list']['list'];
             }
             $fields[] = array('id' => $field->getId(), 'label' => $field->getLabel(), 'alias' => $field->getAlias(), 'type' => $field->getType(), 'options' => $options);
         }
     }
     $dataArray['fields'] = $fields;
     $dataArray['success'] = 1;
     return $this->sendJsonResponse($dataArray);
 }
 /**
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 protected function reorderAction(Request $request)
 {
     $dataArray = array('success' => 0);
     $order = InputHelper::clean($request->request->get('field'));
     $page = InputHelper::int($request->get('page'));
     $limit = InputHelper::int($request->get('limit'));
     if (!empty($order)) {
         /** @var \Mautic\LeadBundle\Model\FieldModel $model */
         $model = $this->factory->getModel('lead.field');
         $startAt = $page > 1 ? $page * $limit + 1 : 1;
         $model->reorderFieldsByList($order, $startAt);
         $dataArray['success'] = 1;
     }
     return $this->sendJsonResponse($dataArray);
 }
Exemple #10
0
 /**
  * @param Request $request
  *
  * @return JsonResponse
  */
 protected function clearNotificationAction(Request $request)
 {
     $id = InputHelper::int($request->get('id', 0));
     /** @var \Mautic\CoreBundle\Model\NotificationModel $model */
     $model = $this->factory->getModel('core.notification');
     $model->clearNotification($id);
     return $this->sendJsonResponse(array('success' => 1));
 }
Exemple #11
0
 /**
  * Generates JS file for automatic form generation
  *
  * @return Response
  */
 public function generateAction()
 {
     $formId = InputHelper::int($this->request->get('id'));
     $model = $this->factory->getModel('form.form');
     $form = $model->getEntity($formId);
     $js = '';
     if ($form !== null) {
         $status = $form->getPublishStatus();
         if ($status == 'published') {
             $js = $model->getAutomaticJavascript($form);
         }
     }
     $response = new Response();
     $response->setContent($js);
     $response->setStatusCode(Response::HTTP_OK);
     $response->headers->set('Content-Type', 'text/javascript');
     return $response;
 }
Exemple #12
0
 public function embedAction()
 {
     $formId = InputHelper::int($this->request->get('id'));
     $model = $this->getModel('form');
     $form = $model->getEntity($formId);
     if ($form !== null) {
         $status = $form->getPublishStatus();
         if ($status === 'published') {
             if ($this->request->get('video')) {
                 return $this->render('MauticFormBundle:Public:videoembed.html.php', ['form' => $form]);
             }
             $content = $model->getContent($form, false, true);
             return new Response($content);
         }
     }
     return new Response('', Response::HTTP_NOT_FOUND);
 }
 /**
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 protected function toggleLeadCampaignAction(Request $request)
 {
     $dataArray = array('success' => 0);
     $leadId = InputHelper::int($request->request->get('leadId'));
     $campaignId = InputHelper::int($request->request->get('campaignId'));
     $action = InputHelper::clean($request->request->get('campaignAction'));
     if (!empty($leadId) && !empty($campaignId) && in_array($action, array('remove', 'add'))) {
         $leadModel = $this->factory->getModel('lead');
         $campaignModel = $this->factory->getModel('campaign');
         $lead = $leadModel->getEntity($leadId);
         $campaign = $campaignModel->getEntity($campaignId);
         if ($lead !== null && $campaign !== null) {
             $class = "{$action}Lead";
             $campaignModel->{$class}($campaign, $lead, true);
             $dataArray['success'] = 1;
         }
     }
     return $this->sendJsonResponse($dataArray);
 }
Exemple #14
0
 /**
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 protected function updateStatsChartAction(Request $request)
 {
     $emailId = InputHelper::int($request->request->get('emailId'));
     $emailType = InputHelper::clean($request->request->get('emailType'));
     $includeVariants = InputHelper::boolean($request->request->get('includeVariants', false));
     $amount = InputHelper::int($request->request->get('amount'));
     $unit = InputHelper::clean($request->request->get('unit'));
     $dataArray = array('success' => 0);
     /** @var \Mautic\EmailBundle\Model\EmailModel $model */
     $model = $this->factory->getModel('email');
     $dataArray['stats'] = $emailType == 'template' ? $model->getEmailGeneralStats($emailId, $includeVariants, $amount, $unit) : $model->getEmailListStats($emailId, $includeVariants);
     $dataArray['success'] = 1;
     return $this->sendJsonResponse($dataArray);
 }
Exemple #15
0
 /**
  * Contacts a user
  *
  * @param int $objectId
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function contactAction($objectId)
 {
     $model = $this->getModel('user.user');
     $user = $model->getEntity($objectId);
     //user not found
     if ($user === null) {
         return $this->postActionRedirect(array('returnUrl' => $this->generateUrl('mautic_dashboard_index'), 'contentTemplate' => 'MauticUserBundle:User:contact', 'flashes' => array(array('type' => 'error', 'msg' => 'mautic.user.user.error.notfound', 'msgVars' => array('%id%' => $objectId)))));
     }
     $action = $this->generateUrl('mautic_user_action', array('objectAction' => 'contact', 'objectId' => $objectId));
     $form = $this->createForm(new FormType\ContactType(), array(), array('action' => $action));
     $currentUser = $this->factory->getUser();
     if ($this->request->getMethod() == 'POST') {
         $formUrl = $this->request->request->get('contact[returnUrl]', '', true);
         $returnUrl = $formUrl ? urldecode($formUrl) : $this->generateUrl('mautic_dashboard_index');
         $valid = false;
         if (!($cancelled = $this->isFormCancelled($form))) {
             if ($valid = $this->isFormValid($form)) {
                 $subject = InputHelper::clean($form->get('msg_subject')->getData());
                 $body = InputHelper::clean($form->get('msg_body')->getData());
                 $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($currentUser->getEmail(), $currentUser->getName())->setTo($user->getEmail(), $user->getName())->setBody($body);
                 $this->get('mailer')->send($message);
                 $reEntity = $form->get('entity')->getData();
                 if (empty($reEntity)) {
                     $bundle = $object = 'user';
                     $entityId = $user->getId();
                 } else {
                     $bundle = $object = $reEntity;
                     if (strpos($reEntity, ':')) {
                         list($bundle, $object) = explode(':', $reEntity);
                     }
                     $entityId = $form->get('id')->getData();
                 }
                 $serializer = $this->get('jms_serializer');
                 $details = $serializer->serialize(array('from' => $currentUser->getName(), 'to' => $user->getName(), 'subject' => $subject, 'message' => $body), 'json');
                 $log = array('bundle' => $bundle, 'object' => $object, 'objectId' => $entityId, 'action' => 'communication', 'details' => $details, 'ipAddress' => $this->factory->getIpAddressFromRequest());
                 $this->getModel('core.auditLog')->writeToLog($log);
                 $this->addFlash('mautic.user.user.notice.messagesent', array('%name%' => $user->getName()));
             }
         }
         if ($cancelled || $valid) {
             return $this->redirect($returnUrl);
         }
     } else {
         $reEntityId = InputHelper::int($this->request->get('id'));
         $reSubject = InputHelper::clean($this->request->get('subject'));
         $returnUrl = InputHelper::clean($this->request->get('returnUrl', $this->generateUrl('mautic_dashboard_index')));
         $reEntity = InputHelper::clean($this->request->get('entity'));
         $form->get('entity')->setData($reEntity);
         $form->get('id')->setData($reEntityId);
         $form->get('returnUrl')->setData($returnUrl);
         if (!empty($reEntity) && !empty($reEntityId)) {
             $model = $this->getModel($reEntity);
             $entity = $model->getEntity($reEntityId);
             if ($entity !== null) {
                 $subject = $model->getUserContactSubject($reSubject, $entity);
                 $form->get('msg_subject')->setData($subject);
             }
         }
     }
     return $this->delegateView(array('viewParameters' => array('form' => $form->createView(), 'user' => $user), 'contentTemplate' => 'MauticUserBundle:User:contact.html.php', 'passthroughVars' => array('route' => $action, 'mauticContent' => 'user')));
 }
 /**
  * @param $type
  * @param $userId
  */
 protected function toggleChatSettingAction(Request $request)
 {
     $chatType = $request->request->get('chatType');
     $setting = $request->request->get('setting');
     $enabled = InputHelper::boolean($request->request->get('enabled'));
     $id = InputHelper::int($request->request->get('id'));
     $success = 0;
     $updateSettings = array();
     /** @var \MauticAddon\MauticChatBundle\Model\ChatModel $model */
     $model = $this->factory->getModel('addon.mauticChat.chat');
     $settings = $model->getSettings($chatType);
     /** @var \MauticAddon\MauticChatBundle\Model\ChannelModel $channelModel */
     $channelModel = $this->factory->getModel('addon.mauticChat.channel');
     if ($chatType == 'channels' && $setting == 'archived') {
         $channel = $channelModel->getEntity($id);
         if ($channel != null) {
             if ($this->factory->getSecurity()->hasEntityAccess(true, false, $channel->getCreatedBy())) {
                 $success = 1;
                 if ($enabled) {
                     $channelModel->archiveChannel($id);
                     $updateSettings['visible'] = false;
                 } else {
                     $channelModel->unarchiveChannel($id);
                 }
             }
         }
     } elseif ($chatType == 'channels' && $setting == 'subscribed') {
         $channel = $channelModel->getEntity($id);
         if ($channel != null) {
             $success = 1;
             if ($enabled) {
                 $channelModel->subscribeToChannel($channel);
                 $updateSettings['visible'] = true;
             } else {
                 $channelModel->unsubscribeFromChannel($channel);
                 $updateSettings['visible'] = false;
             }
         }
     } else {
         $updateSettings[$setting] = $enabled;
     }
     foreach ($updateSettings as $setting => $enabled) {
         if (isset($settings[$setting])) {
             $success = 1;
             if (!$enabled && in_array($id, $settings[$setting])) {
                 $key = array_search($id, $settings[$setting]);
                 if ($key !== false) {
                     unset($settings[$setting][$key]);
                 }
             } elseif ($enabled && !in_array($id, $settings[$setting])) {
                 $settings[$setting][] = $id;
             }
         }
     }
     if (!empty($updateSettings)) {
         $model->setSettings($settings, $chatType);
     }
     return $this->sendJsonResponse(array('success' => $success, 'settings' => $updateSettings));
 }
Exemple #17
0
 /**
  * Updates list filters, order, limit
  *
  * @return void
  */
 protected function setListFilters()
 {
     $session = $this->get('session');
     $name = InputHelper::clean($this->request->query->get('name'));
     if (!empty($name)) {
         if ($this->request->query->has('orderby')) {
             $orderBy = InputHelper::clean($this->request->query->get('orderby'), true);
             $dir = $session->get("mautic.{$name}.orderbydir", 'ASC');
             $dir = $dir == 'ASC' ? 'DESC' : 'ASC';
             $session->set("mautic.{$name}.orderby", $orderBy);
             $session->set("mautic.{$name}.orderbydir", $dir);
         }
         if ($this->request->query->has('limit')) {
             $limit = InputHelper::int($this->request->query->get('limit'));
             $session->set("mautic.{$name}.limit", $limit);
         }
         if ($this->request->query->has('filterby')) {
             $filter = InputHelper::clean($this->request->query->get("filterby"), true);
             $value = InputHelper::clean($this->request->query->get("value"), true);
             $filters = $session->get("mautic.{$name}.filters", array());
             if ($value == '') {
                 if (isset($filters[$filter])) {
                     unset($filters[$filter]);
                 }
             } else {
                 $filters[$filter] = array('column' => $filter, 'expr' => 'like', 'value' => $value, 'strict' => false);
             }
             $session->set("mautic.{$name}.filters", $filters);
         }
     }
 }
 /**
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 protected function updateStatsChartAction(Request $request)
 {
     $emailId = InputHelper::int($request->request->get('emailId'));
     $amount = InputHelper::int($request->request->get('amount'));
     $unit = InputHelper::clean($request->request->get('unit'));
     $dataArray = array('success' => 0);
     $dataArray['stats'] = $this->factory->getModel('email')->getEmailGeneralStats($emailId, $amount, $unit);
     $dataArray['success'] = 1;
     return $this->sendJsonResponse($dataArray);
 }