public function delete() { $cids = JRequest::getVar('cid', array()); $unsets = array(); if (!empty($cids)) { foreach ($cids as $idx => $cid) { $newsletter = NewsletterHelper::get($cid); if ($newsletter['used_as_static'] == 1 || !$newsletter['saveable']) { $unsets[] = $cids[$idx]; unset($cids[$idx]); } } JRequest::setVar('cid', $cids); } if (count($unsets) > 0) { $deleteLink = '<a class="micro-button" href="' . JRoute::_('index.php?option=com_newsletter&task=newsletters.deletehard&' . JSession::getFormToken() . '=1&cid=' . implode(',', $unsets)) . '"> X </a>'; JFactory::getApplication()->enqueueMessage(sprintf(JText::_('COM_NEWSLETTER_SOME_COULDNOT_DELETE'), count($unsets), $deleteLink), 'message'); } if (count($cids) > 0) { parent::delete(); } $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); }
/** * Displays the view. * * @param string $tpl the template name * * @return void * @since 1.0 */ public function display($tpl = null) { $isNew = !JRequest::getInt('newsletter_id', false); if ($isNew && !AclHelper::actionIsAllowed('newsletter.add') || !$isNew && !AclHelper::actionIsAllowed('newsletter.edit')) { $msg = $isNew ? 'JLIB_APPLICATION_ERROR_CREATE_RECORD_NOT_PERMITTED' : 'JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'; JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_newsletter&view=newsletters', false), JText::_($msg), 'error'); return; } //TODO: Need to move css/js to SetDocument JHTML::stylesheet('media/com_newsletter/css/admin.css'); JHTML::stylesheet('media/com_newsletter/css/newsletter.css'); JHTML::script('media/com_newsletter/js/migur/js/core.js'); JHTML::script('media/com_newsletter/js/migur/js/ajax.js'); JHTML::script('media/com_newsletter/js/migur/js/widgets.js'); JHTML::script('media/com_newsletter/js/migur/js/moodialog/MooDialog.js'); JHTML::script('media/com_newsletter/js/migur/js/moodialog/MooDialog.Request.js'); JHTML::script('media/com_newsletter/js/migur/js/moodialog/MooDialog.IFrame.js'); JHTML::stylesheet('media/com_newsletter/js/migur/js/moodialog/css/MooDialog.css'); JHTML::script('media/com_newsletter/js/migur/js/autocompleter/Observer.js'); JHTML::script('media/com_newsletter/js/migur/js/autocompleter/Autocompleter.js'); JHTML::script('media/com_newsletter/js/migur/js/autocompleter/Autocompleter.Local.js'); JHTML::stylesheet('media/com_newsletter/js/migur/js/autocompleter/css/Autocompleter.css'); JHTML::script('media/com_newsletter/js/migur/js/guide.js'); JHTML::stylesheet('media/com_newsletter/css/guide.css'); //TODO: Bulk-code. Need to refactor. JavascriptHelper::addObject('comParams', JComponentHelper::getParams('com_newsletter')->toArray()); $nId = JRequest::getInt('newsletter_id'); $script = $this->get('Script'); $this->script = $script; // Get main form and data for newsletter $this->form = $this->get('Form', 'newsletter'); $this->newsletter = $this->get('Item'); $smtpModel = JModel::getInstance('SMtpProfile', 'NewsletterModelEntity'); // Let's add J! profile $smtpp = $smtpModel->loadJoomla(); JavascriptHelper::addObject('joomlaDe', JComponentHelper::getParams('com_newsletter')->toArray()); // get the SmtpProfiles data $smtpprofilesManager = JModel::getInstance('smtpprofiles', 'NewsletterModel'); $this->assignRef('smtpprofiles', $smtpprofilesManager->getAllItems('withDefault')); // get all the Extensions $this->modules = MigurModuleHelper::getSupported(array('withoutInfo' => true)); $this->plugins = MigurPluginHelper::getSupported(array('withoutInfo' => true), 'com_newsletter.newsletter'); // get the Extensions used in this newsletter $model = JModel::getInstance('newsletterext', 'NewsletterModel'); $this->usedExts = $model->getExtensionsBy($nId); // Get a list of all templates $this->setModel(JModel::getInstance('templates', 'NewsletterModel')); $model = $this->getModel('templates'); $templs = $model->getItems(); $path = JPATH_COMPONENT . '/extensions/templates/'; $filenames = JFolder::files($path, '^.*\\.xml$'); if ($filenames === false) { JError::raiseError(500, implode("\n", array("Path {$path} not found"))); } $this->templates = (object) array('items' => array(), 'path' => $path); $this->htmlTemplateId = null; foreach ($templs as $item) { $xml = new JSimpleXML(); $xml->loadFile($path . $item->template); $str = trim($xml->document->template[0]->_data); $str = preg_replace('/<style.*>.*<\\/style>/s', '', $str); $str = str_replace('<position', '<div class="drop container-draggables"', $str); $id = strtolower(str_replace('.', '-', $item->template) . '-' . $item->t_style_id); $item->id = $id; $item->filename = $item->template; $item->template = $str; $this->templates->items[] = $item; if ($this->newsletter->t_style_id == $item->t_style_id) { $this->htmlTemplateId = $id; $this->t_style_id = $item->t_style_id; } unset($xml); } //attachments $this->attItems = array(); $this->dynamicData = array('Name' => '[username]', 'Email' => '[useremail]', 'Site name' => '[sitename]', 'Subscription key' => '[subscription key]', 'Unsubscription link' => '[unsubscription link]', 'Confirmation link' => '[confirmation link]'); $this->attItemslistDirn = "a.filename"; $this->attItemslistOrder = "asc"; // getting of an xml from // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } // We don't need toolbar in the modal window. if ($this->getLayout() !== 'modal') { $this->addToolbar(); } $this->downloads = (array) DownloadHelper::getByNewsletterId($nId); JavascriptHelper::addObject('dataStorage', (object) array('htmlTemplate' => (object) array('template' => (object) array('id' => $this->htmlTemplateId), 'extensions' => (array) $this->usedExts), 'templates' => (array) $this->templates->items, 'modules' => (array) $this->modules, 'plugins' => (array) $this->plugins, 'newsletter' => NewsletterHelper::get($nId))); // Set the document $this->setDocument(); parent::display($tpl); }
/** * Bulk save method for saving of newsletter * or copying of several ones. * * @return type */ public function save() { $task = JRequest::getString('task'); if (!empty($task) && strpos($task, 'save2copy') !== false) { // Actualy on this step will be performed // the checking for NEWSLETTER.ADD permission. It's ok if (!$this->allowSave()) { $this->setError(JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED')); $this->setMessage($this->getError(), 'error'); $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $this->getRedirectToListAppend(), false)); return false; } $nIds = JRequest::getVar('cid', array()); if (!empty($nIds)) { $table = JTable::getInstance('Newsletter', 'NewsletterTable'); $relTable = JTable::getInstance('Newsletterext', 'NewsletterTable'); $downTable = JTable::getInstance('Downloads', 'NewsletterTable'); foreach ($nIds as $nId) { // Copying the newsletter... $table->load($nId); $data = $table->getProperties(); // reset $table->reset(); $table->set($table->getKeyName(), null); unset($data['newsletter_id']); $data['name'] .= '(copy)'; $data['sent_started'] = ''; $data['alias'] = NewsletterHelper::getFreeAlias($data['alias']); // bind if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // Store data. if (!$table->store()) { $this->setError($table->getError()); return false; } $newNid = $table->get($table->getKeyName()); // Copy extensions... $exts = $relTable->getRowsBy($nId); if (!empty($exts)) { foreach ($exts as $ext) { // reset $relTable->reset(); $relTable->set($relTable->getKeyName(), null); unset($ext[$relTable->getKeyName()]); $ext['newsletter_id'] = $newNid; // bind if (!$relTable->bind($ext)) { $this->setError($relTable->getError()); return false; } // Store data. if (!$relTable->store()) { $this->setError($relTable->getError()); return false; } } } // Copy downloads... $exts = $downTable->getRowsBy($nId); if (!empty($exts)) { foreach ($exts as $ext) { // reset $downTable->reset(); $downTable->set($downTable->getKeyName(), null); unset($ext[$downTable->getKeyName()]); $ext['newsletter_id'] = $newNid; // bind if (!$downTable->bind($ext)) { $this->setError($downTable->getError()); return false; } // Store data. if (!$downTable->store()) { $this->setError($downTable->getError()); return false; } } } // Clean the cache. $cache = JFactory::getCache($this->option); $cache->clean(); } $message = JText::_('COM_NEWSLETTER_NEWSLETTER_COPY_SUCCESS'); $this->setRedirect(JRoute::_('index.php?option=com_newsletter&view=newsletters&form=newsletters', false), $message, 'message'); return true; } else { $message = JText::_('COM_NEWSLETTER_SELECT_AT_LEAST_ONE_ITEM'); $this->setRedirect(JRoute::_('index.php?option=com_newsletter&view=newsletters&form=newsletters', false), $message, 'error'); return true; } return parent::save(); } else { $nsid = JRequest::getVar('newsletter_id', '0'); $type = JRequest::getVar('task'); $context = JRequest::getString('context', 'html'); // save new newsletter (create it) or autosave an existing letter $data = JRequest::getVar('jform', array(), 'post', 'array'); // If the type is not changeable then replace type as now (for success validation). if (!empty($nsid)) { // Get newsletter's extended info $nl = NewsletterHelper::get($nsid); if (!$nl['type_changeable']) { $data['type'] = $nl['type']; JRequest::setVar('jform', $data, 'post'); } // Check if we can change the newsletter if (!$nl['saveable']) { $error = JText::_('COM_NEWSLETTER_CANNOT_SAVE_NEWSLETTER'); if ($context == 'json') { echo json_encode(array('state' => $error, 'newsletter_id' => $nsid)); jexit(); } else { JFactory::getApplication()->enqueueMessage($error, 'error'); $this->setRedirect(JRoute::_('index.php?option=com_newsletter&view=newsletter&layout=edit&newsletter_id=' . $nsid, false)); return; } } } else { if (empty($data['alias'])) { $data['alias'] = 'newsletter'; } // Get newsletters with similar aliases $data['alias'] = NewsletterHelper::getFreeAlias($data['alias']); } if (parent::save()) { $nsid = $this->newsletterId; $htmlTpl = (object) json_decode($data['htmlTpl']); $plugins = (array) json_decode($data['plugins']); $htmlTpl->extensions = array_merge($htmlTpl->extensions, $plugins); $newExtsModel = $this->getModel('newsletterext'); if ($newExtsModel->rebindExtensions($htmlTpl->extensions, $nsid)) { } else { $error = $newExtsModel->getError(); } } else { $error = $this->getError(); } if ($context == 'json') { $this->setRedirect(null); if (empty($error)) { $error = JFactory::getApplication()->getMessageQueue(); } echo json_encode(array('state' => !empty($error) ? $error : 'ok', 'newsletter_id' => $nsid, 'alias' => $data['alias'])); jexit(); } } }