public static function importBis() { @set_time_limit(0); $returnMessage = ''; //If memory_limit less than 128M $limit = jnews::convertToBytes(@ini_get('memory_limit')); if ($limit < jnews::convertToBytes('128M')) { @ini_set('memory_limit', '128M'); } $allAvailableListsA = JRequest::getVar('sub_list_id', ''); $list2SubcribeToA = JRequest::getVar('subscribed', ''); $filename = $_FILES['importfile']['name']; if (!empty($filename)) { //if we import a file //the flag is true coz we add subscribers in frontend through rows $saveSubsInRows = true; $path = JNEWS_JPATH_ROOT_NO_ADMIN . $GLOBALS[JNEWS . 'upload_url']; $path = str_replace(array('/', '\\'), DS, $path); if (!is_writable($path)) { $returnMessage .= '<br/>The file could not be imported because the folder is not writable.'; $returnMessage .= '<br/>Please make sure the path "' . JNEWS_JPATH_ROOT_NO_ADMIN . $GLOBALS[JNEWS . 'upload_url'] . '" is writable'; return $returnMessage; } if (!@move_uploaded_file($_FILES['importfile']['tmp_name'], $path . $filename)) { $path .= DS; if (!@move_uploaded_file($_FILES['importfile']['tmp_name'], $path . $filename)) { $returnMessage .= _JNEWS_ERROR_MOVING_UPLOAD; $returnMessage .= '<br/>Please make sure the path "' . JNEWS_JPATH_ROOT_NO_ADMIN . $GLOBALS[JNEWS . 'upload_url'] . '" is writable'; return $returnMessage; } } $import = file_get_contents($path . $filename); $import = str_replace(array("\r\n", "\r"), "\n", $import); $allLinesA = explode("\n", $import); } else { //if we add subscribers in frontend through rows //the flag is true coz we add subscribers in frontend through rows $saveSubsInRows = true; //we get the number of rows $rows = JRequest::getVar('count', ''); $nRows = intval($rows) - 1; if ($nRows == 0) { $nRows = intval($GLOBALS[JNEWS . 'create_newsubsrows']); } //we get the value of each element from the rows for ($count = 1; $count <= $nRows; $count++) { $allLinesA[$count] = JRequest::getVar('name' . $count, '') . ', ' . JRequest::getVar('email' . $count, '') . ', ' . JRequest::getVar('receive_html' . $count, '') . ', ' . JRequest::getVar('confirmed' . $count, '') . ', ' . JRequest::getVar('column1' . $count, '') . ', ' . JRequest::getVar('column2' . $count, '') . ', ' . JRequest::getVar('column3' . $count, '') . ', ' . JRequest::getVar('column4' . $count, '') . ', ' . JRequest::getVar('column5' . $count, ''); } } if (empty($allLinesA)) { return false; } $db = JFactory::getDBO(); $insertQuery = ''; $selectQuery = ''; $firstValue = true; $time = time(); $totalInsert = 0; $allSubscribersIDA = array(); foreach ($allLinesA as $line) { $line = trim($line); if (empty($line)) { continue; } $line = str_replace(';', ',', $line); $subscriberA = explode(',', $line); $email = trim($subscriberA[1], ' "\''); if (!jNews_Subscribers::validEmail($email)) { if (!$saveSubsInRows) { //if import of file is done echo '<br />' . jnews::printM('red', _JNEWS_EMAIL_INVALID . ': ' . $email); continue; } else { continue; } } if ($GLOBALS[JNEWS . 'level'] > 2) { $column4 = !empty($subscriberA[4]) ? mysql_escape_string(trim($subscriberA[4], '"')) : ''; $column5 = !empty($subscriberA[5]) ? mysql_escape_string(trim($subscriberA[5], '"')) : ''; $column6 = !empty($subscriberA[6]) ? mysql_escape_string(trim($subscriberA[6], '"')) : ''; $column7 = !empty($subscriberA[7]) ? mysql_escape_string(trim($subscriberA[7], '"')) : ''; $column8 = !empty($subscriberA[8]) ? mysql_escape_string(trim($subscriberA[8], '"')) : ''; $ip = !empty($subscriberA[9]) ? mysql_escape_string(trim($subscriberA[9], '"')) : ''; } $comfirmation = $GLOBALS[JNEWS . 'require_confirmation'] ? 0 : (int) trim($subscriberA[3], ' "\''); // i need to know if exist user $db = JFactory::getDBO(); $quer = "SELECT id FROM `#__jnews_subscribers` WHERE `email` = '{$email}'"; $db->setQuery($quer); $res = $db->loadResult(); if ($res) { //i need to update $isResiveHtml = (int) trim($subscriberA[2], ' "\''); $querUpdate = "UPDATE `#__jnews_subscribers` SET confirmed = '{$comfirmation}', receive_html= '{$isResiveHtml}',column1 = '{$column4}', column2 = '{$column5}', column3 = '{$column5}', column4 = '{$column7}', column5= '{$column8}',ip = '{$ip}' WHERE `email` = '{$email}'"; $db->setQuery($querUpdate); $db->query(); if (!empty($allAvailableListsA) && !empty($list2SubcribeToA)) { foreach ($list2SubcribeToA as $oneneedList => $noneed) { $listId = $allAvailableListsA[$oneneedList]; // $query = "INSERT IGNORE `#__jnews_listssubscribers` (`list_id`,`subscriber_id`,`subdate`) VALUES ({$listId}, {$res}, {$time})"; $db->setQuery($query); $db->query(); } } continue; } if (!$firstValue) { $insertQuery .= ','; } /*$insertQuery .= '(\''. htmlentities(trim($subscriberA[0],' "\'') ) . '\',\''.$email.'\','.$comfirmation.','.(int)trim($subscriberA[2],' "\'').',\''.$time.'\',\''.$column4.'\',\''.$column5.'\',\''.$column6.'' . '\',\''.$column7.'\',\''.$column8.'\',\''.$ip.'\')';*/ $insertQuery .= '(\'' . addslashes(trim($subscriberA[0], ' "\'')) . '\',\'' . $email . '\',' . $comfirmation . ',' . (int) trim($subscriberA[2], ' "\'') . ',\'' . $time . '\',\'' . $column4 . '\',\'' . $column5 . '\',\'' . $column6 . '' . '\',\'' . $column7 . '\',\'' . $column8 . '\',\'' . $ip . '\')'; if (!$firstValue) { $selectQuery .= ','; } $selectQuery .= '\'' . $email . '\''; $firstValue = false; $totalInsert++; if ($totalInsert % 50 == 0) { if (empty($insertQuery)) { continue; } $db = JFactory::getDBO(); $query = 'INSERT IGNORE `#__jnews_subscribers` (`name`,`email`,`confirmed`,`receive_html`,`subscribe_date`,`column1`,`column2`,`column3`,`column4`,`column5`,`ip`) VALUES ' . $insertQuery; $db->setQuery($query); $db->query(); $firstValue = true; $insertQuery = ''; //get the id of the subscribers $query = 'SELECT `id` FROM `#__jnews_subscribers` WHERE `email` IN (' . $selectQuery . ')'; $db->setQuery($query); $loadResultArray = $db->loadObjectList(); $resultsSubClA = jnews::convertObjectList2Array($loadResultArray); $allSubscribersIDA = array_merge($allSubscribersIDA, $resultsSubClA); $selectQuery = ''; } else { if (empty($insertQuery)) { return false; } $db = JFactory::getDBO(); $query = 'INSERT IGNORE `#__jnews_subscribers` (`name`,`email`,`confirmed`,`receive_html`,`subscribe_date`,`column1`,`column2`,`column3`,`column4`,`column5`,`ip`) VALUES ' . $insertQuery; $db->setQuery($query); $db->query(); } } //send confirmation email if required if ($GLOBALS[JNEWS . 'require_confirmation'] && !empty($list2SubcribeToA)) { $list4Message = $allAvailableListsA[key($list2SubcribeToA)]; $myList = jNews_Lists::getOneList($list4Message); $myList->subscribemessage = trim($myList->subscribemessage); if (empty($myList->subscribemessage) || substr_count($myList->subscribemessage, '{tag:confirm}') < 1) { $Sub_TAG = '{tag:confirm}'; //'[CONFIRM]'; } else { $Sub_TAG = ''; } $mailing = new stdClass(); if (!empty($myList->subscribemessage)) { $mailing->htmlcontent = $myList->subscribemessage; $mailing->textonly = $myList->subscribemessage; } else { // default message $mailing->textonly = 'Please confirm your subscription to our website by clicking on the following link.'; $mailing->htmlcontent = '<br />' . $mailing->textonly . '<br /><br />'; } $mailing->textonly .= $Sub_TAG; $mailing->htmlcontent .= $Sub_TAG; //insert the mailing in the mailing table $mailing->mailing_type = 1; $mailing->template_id = 0; $mailing->senddate = $time; $mailing->subject = _JNEWS_SUBSCRIBE_SUBJECT_MESS; $mailing->attachments = ''; $mailing->images = ''; $mailing->published = 1; $mailing->html = 1; $mailing->visible = 0; $mailing->fromname = ''; $mailing->fromemail = ''; $mailing->frombounce = ''; $mailing->author_id = 0; $mailing->delay = 0; $mailing->follow_up = 0; $mailing->cat_id = 0; $mailing->delay_min = 0; $mailing->delay_max = 0; $mailing->notify_id = 0; $mailing->next_date = 0; $mailing->start_date = $time - 2; $mailing->issue_nb = 0; $mailing->createdate = $time; $mailing->acc_level = 0; $mailingID = jNews_Mailing::insertMailingData($mailing); //enter the emails in the queue $query = 'INSERT IGNORE INTO `#__jnews_queue` (`subscriber_id`,`mailing_id`,`send_date`,`priority`) '; $query .= 'SELECT `id`,' . intval($mailingID) . ',' . $time . ',1'; $query .= ' FROM `#__jnews_subscribers` '; $query .= 'WHERE `subscribe_date`=' . $time . ' AND `confirmed`=0'; $db->setQuery($query); $db->query(); } if (!empty($selectQuery)) { //get the id of the subscribers $query = 'SELECT `id` FROM `#__jnews_subscribers` WHERE `email` IN (' . $selectQuery . ')'; $db->setQuery($query); $loadResultArray = $db->loadObjectList(); $resultsSubClA = jnews::convertObjectList2Array($loadResultArray); $allSubscribersIDA = array_merge($allSubscribersIDA, $resultsSubClA); } if (!empty($allAvailableListsA)) { //if lists in checkbox are not empty if (empty($list2SubcribeToA)) { jnews::printM('red', 'You need to select at least one list. Emails have been imported but not subscribed.'); if ($GLOBALS[JNEWS . 'require_confirmation']) { return 'The confirmation email cannot be sent because there is not list selected to subscribe the users.'; } else { return _JNEWS_IMPORT_FINISHED; } } foreach ($list2SubcribeToA as $oneselected => $vval) { $seleeected[] = $allAvailableListsA[$oneselected]; } foreach ($list2SubcribeToA as $oneneedList => $noneed) { $listId = $allAvailableListsA[$oneneedList]; // $query = 'INSERT IGNORE `#__jnews_listssubscribers` (`list_id`,`subscriber_id`,`subdate`) VALUES '; $firstTime = true; if (!empty($allSubscribersIDA)) { foreach ($allSubscribersIDA as $oneSubcriber) { if (!$firstTime) { $query .= ','; } $query .= '(' . $listId . ',' . $oneSubcriber . ',' . $time . ')'; $firstTime = false; if (jNews_Lists::getListType($listId) == 2) { //we add directly the imported subscribers to the queue if they are imported to an autoresponder type of list jNews_ListsSubs::subscribeARtoQueue($oneSubcriber, $listId); // } else { if (jNews_Lists::getListType($listId) == 1) { $arrayFollowUp = jNews_Subscribers::followInSelected($listId); if (!$arrayFollowUp) { continue; } foreach ($arrayFollowUp as $onefollow_id) { if (in_array($onefollow_id, $seleeected)) { continue; } $query .= ',(' . $onefollow_id . ',' . $oneSubcriber . ',' . $time . ')'; jNews_ListsSubs::subscribeARtoQueue($oneSubcriber, $onefollow_id); } } } } $db->setQuery($query); $db->query(); } } } else { //otherwise we get the value from dropdown box $listId = JRequest::getVar('opted_list', ''); if ($listId) { $query = 'INSERT IGNORE `#__jnews_listssubscribers` (`list_id`,`subscriber_id`,`subdate`) VALUES '; $firstTime = true; if (!empty($allSubscribersIDA)) { foreach ($allSubscribersIDA as $oneSubcriber) { if (!$firstTime) { $query .= ','; } $query .= '(' . $listId . ',' . $oneSubcriber . ',' . $time . ')'; $firstTime = false; if (jNews_Lists::getListType($listId) == 2) { //we add directly the imported subscribers to the queue if they are imported to an autoresponder type of list jNews_ListsSubs::subscribeARtoQueue($oneSubcriber, $listId); } else { if (jNews_Lists::getListType($listId) == 1) { $arrayFollowUp = jNews_Subscribers::followInSelected($listId); if (!$arrayFollowUp) { continue; } foreach ($arrayFollowUp as $onefollow_id) { if (in_array($onefollow_id, $seleeected)) { continue; } $query .= ',(' . $onefollow_id . ',' . $oneSubcriber . ',' . $time . ')'; jNews_ListsSubs::subscribeARtoQueue($oneSubcriber, $onefollow_id); } } } } $db->setQuery($query); $db->query(); } } } if ($saveSubsInRows) { //if adding subscribers in frontend through rows jnews::printM('green', count($allSubscribersIDA) . ' subscribers successfully added!'); } else { //otherwise we import subscribers jnews::printM('green', count($allSubscribersIDA) . ' subscribers successfully imported!'); } return _JNEWS_IMPORT_FINISHED; }
public static function mailingEdit($subscriberId, $mailingId, $listId, $listType = '', $action, $grantCAnAccess = false) { global $my, $Itemid; $issue_nb = JRequest::getVar('issue_nb', '0'); $my = JFactory::getUser(); if (version_compare(JVERSION, '1.6.0', '>=')) { //j16 $usergid = JAccess::getGroupsByUser($my->id, false); $my->gid = $usergid[0]; } $accessGrant = false; if (!empty($my->id)) { $ownedlists = jNews_Lists::getOwnedlists($my->id); } $new = 0; if (class_exists('jNews_Pro')) { if ($issue_nb == 0) { $issue_nb = jNews_Mailing::countMailings($listId, ''); $issue_nb++; } if ($listId > 0) { $list = jNews_Lists::getOneList($listId); $mailing = jNews_Mailing::getOneMailing($list, $mailingId, $issue_nb, $new); $acc_level = $list->acc_level; } else { if (!empty($ownedlists)) { $list = jNews_Lists::getOneList($listId); $mailing = jNews_Mailing::getOneMailing($list, $mailingId, $issue_nb, $new); $acc_level = $list->acc_level; } else { $listId = jNews_Lists::getIDacclevel($my->gid); $list = jNews_Lists::getOneList($listId); $mailing = jNews_Mailing::getOneMailing($list, $mailingId, $issue_nb, $new); $acc_level = $list->acc_level; } } $id = 0; if ($GLOBALS[JNEWS . 'enable_jsub']) { if (!empty($my->id)) { $ownedlists = jNews_Lists::getOwnedlists($my->id); } if (!empty($ownedlists)) { $id = $my->id; } } if (jnews::checkPermissions($acc_level)) { $accessGrant = true; } } else { if ($subscriberId != 0 && jnews::checkPermissions('admin')) { $accessGrant = true; } } if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) { if (class_exists('jNews_Social') && !$GLOBALS[JNEWS . 'enable_jsub']) { $accessGrant = true; } } if ($accessGrant || $grantCAnAccess) { if ($issue_nb == 0) { $issue_nb = jNews_Mailing::countMailings($listId, ''); $issue_nb++; } if (empty($mailing)) { if ($mailingId > 0) { $mailing = jNews_Mailing::getOneMailing('', $mailingId, $issue_nb, $new); } else { if ($listId > 0) { $list = jNews_Lists::getOneList($listId); $mailing = jNews_Mailing::getOneMailing($list, $mailingId, $issue_nb, $new); } else { return false; } } } $mainLink = 'option=' . JNEWS_OPTION . '&act=mailing&listid=' . $listId . '&listype=' . $listType . '&Itemid=' . $Itemid; $mainLink = jNews_Tools::completeLink($mainLink, false, false); $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION); //$forms['main'] = '<form method="post" enctype="multipart/form-data" action="'. $mainLink . '" onsubmit="submitbutton();return false;" name="adminForm" id="adminForm">'."\n\r"; $forms['main'] = '<form method="post" enctype="multipart/form-data" action="' . $mainLink . '" name="adminForm" id="adminForm">' . "\n\r"; $forms['main'] .= '<input type="hidden" name="Itemid" value="' . $Itemid . '" />'; $show = jNews_ListType::showType($mailing->mailing_type, 'editmailing'); $menuA = null; if ($GLOBALS[JNEWS . 'level'] > 1) { //menu object start here //to create the template menu $listype = JRequest::getInt('listype', 0, 'request'); $menuTag = new stdClass(); $menuTag->link = 'administrator/' . jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=tags', true, false, true); if ($listype == 7) { $delaymax = JRequest::getInt('delay_max', 0, 'request'); $notifyID = JRequest::getInt('notify_id', 0, 'request'); $catid = JRequest::getVar('cat_id', 0, 'request'); $menuTag->link = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=tags&listype=' . $listype . '&cat_id=' . $catid . '&delay_max=' . $delaymax . '¬ify_id=' . $notifyID, false, false, true); } else { $menuTag->link = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=tags', false, false, true); } $menuTag->popup = new stdClass(); $menuTag->popup->isPop = true; $menuTag->popup->rel = true; $menuTag->popup->x = 750; $menuTag->popup->y = 500; $menuTag->action = 'tags'; $menuTag->title = _JNEWS_MAILING_TAG; //to create the template menu $menuTemplate = new stdClass(); $menuTemplate->link = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=templates&task=assign', false, false, true); $menuTemplate->popup = new stdClass(); $menuTemplate->popup->isPop = true; $menuTemplate->popup->rel = true; $menuTemplate->popup->x = 640; $menuTemplate->popup->y = 480; $menuTemplate->action = 'template'; $menuTemplate->title = _JNEWS_LIST_T_TEMPLATE; //to create cancel menu $menuCancel = new stdClass(); $menuCancel->popup = new stdClass(); $menuCancel->popup->isPop = false; $menuCancel->link = '#'; $menuCancel->action = 'cancel'; $menuCancel->onclick = new stdClass(); $menuCancel->onclick->custom = false; $menuCancel->onclick->js = ''; $menuCancel->title = _JNEWS_CANCEL; //to create save menu $linksave = 'option=' . JNEWS_OPTION . '&act=mailing&listid=' . $listId . '&listype=' . $listType . '&Itemid=' . $Itemid; if ($listId == 0) { $linksave = 'option=' . JNEWS_OPTION . '&act=mailing&listype=' . $listType . '&Itemid=' . $Itemid; } $linksave = jNews_Tools::completeLink($linksave, false); $menuSave = new stdClass(); $menuSave->popup = new stdClass(); $menuSave->popup->isPop = false; $menuSave->link = '#'; $menuSave->action = 'save'; $menuSave->onclick = new stdClass(); $menuSave->onclick->custom = false; $menuSave->onclick->js = ''; $menuSave->title = _JNEWS_SAVE; //to create preview menu $menuPreview = new stdClass(); $menuPreview->popup = new stdClass(); $menuPreview->popup->isPop = false; $menuPreview->link = '#'; $menuPreview->action = 'savepreview'; $menuPreview->onclick = new stdClass(); $menuPreview->onclick->custom = false; $menuPreview->onclick->js = ''; $menuPreview->title = 'Preview'; //to create send menu $menuSend = new stdClass(); $menuSend->popup = new stdClass(); $menuSend->popup->isPop = true; $menuSend->popup->rel = true; $menuSend->popup->x = 750; $menuSend->popup->y = 500; $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=sendready&mailingid=' . $mailingId . '&listype=' . $listType, true, false, true); $menuSend->link = $linkBut; $menuSend->action = 'sendready'; $menuSend->onclick = new stdClass(); $menuSend->onclick->custom = false; $menuSend->onclick->js = ""; $menuSend->title = _JNEWS_MENU_SEND; //to create the divider $menuDivider = new stdClass(); $menuDivider->divider = true; $menuA = array(); if (empty($mailingId)) { $menuA['template'] = $menuTemplate; } $menuA['tags'] = $menuTag; $menuA['divider1'] = $menuDivider; $menuA['preview'] = $menuPreview; $menuA['save'] = $menuSave; if ($listType == 1 && $mailingId != 0) { $menuA['send'] = $menuSend; } $menuA['divider'] = $menuDivider; $menuA['cancel'] = $menuCancel; } frontHTML::formStart(_JNEWS_EDIT_A . @constant($GLOBALS[JNEWS . 'listname' . $mailing->mailing_type]), $mailing->html, 'edit_mailing', $menuA); jNews_MailingsHTML::editMailing($mailing, $new, $listId, $forms, $show, $listType); $go[] = jnews::makeObj('act', $action); $go[] = jnews::makeObj('listype', $listType); frontHTML::formEnd(_CMN_SAVE . ' ' . @constant($GLOBALS[JNEWS . 'listname' . $mailing->mailing_type]), $go); } else { echo jnews::printM('red', _NOT_AUTH); } return true; }
function mailing($action, $task, $listId, $listType, $mailingId, $message) { $showMailings = false; $db = JFactory::getDBO(); switch ($task) { case 'edit': $issue_nb = JRequest::getInt('issue_nb', 1); $mailingType = JRequest::getVar('listype'); $isEdit = JRequest::getVar('isEdit', true); $mySess = JFactory::getSession(); $mySess->set('listype', $mailingType, 'LType'); if (!empty($listId)) { $list = jNews_Lists::getOneList($listId); } else { $list = jNews_Lists::getListFirstEntry(); } $new = empty($mailingId) || $mailingId == 0 ? true : false; $mailing = jNews_Mailing::getOneMailing($list, $mailingId, $issue_nb, $new, false, true); $mailing->mailing_type = $mailingType; // if(empty($isEdit)) $isEdit = true; // set default mailing parameters $my = JFactory::getUser(); $subscribers = jNews_Subscribers::getSubscriberInfoFromUserId($my->id); if (!isset($subscribers)) { $subscribers = new stdClass(); } $subscribers->name = isset($subscribers->name) ? $subscribers->name : ''; $subscribers->email = isset($subscribers->email) ? $subscribers->email : ''; // $mailing->fromname = ( !isset( $mailing->fromname ) || empty( $mailing->fromname ) ) ? $subscribers->name : $mailing->fromname; // $mailing->fromemail = ( !isset( $mailing->fromemail ) || empty( $mailing->fromemail ) ) ? $subscribers->email : $mailing->fromemail; // $mailing->frombounce = ( !isset( $mailing->frombounce ) || empty( $mailing->frombounce ) ) ? $GLOBALS[JNEWS.'sendmail_from'] : $mailing->frombounce; $show = jNews_ListType::showType($mailing->mailing_type, 'editmailing'); if ($mailing->published != 1 or $mailing->mailing_type != 1 or isset($show['admin']) and $show['admin']) { $forms['main'] = " <form action='index.php' method='post' enctype='multipart/form-data' name='adminForm' id=\"adminForm\">"; jNews_Mailing::_header($task, $action, $mailing->mailing_type, $message, 'edit'); jNews_MailingsHTML::editMailing($mailing, $new, $listId, $forms, $show, $isEdit); $go[] = jnews::makeObj('act', $action); backHTML::formEnd($go); } else { $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">"; jNews_Mailing::_header($task, $action, $mailing->mailing_type, $message); //backHTML::formStart(); jNews_MailingsHTML::viewMailing($mailing, $forms); $go[] = jnews::makeObj('act', 'mailing'); $go[] = jnews::makeObj('task', 'viewmailing'); $go[] = jnews::makeObj('mailingid', $mailing->id); backHTML::formEnd($go); } break; case 'new': case 'add': // check if atleast one list exist and published // if false then restrict entry $mailingType = JRequest::getVar('listype'); $type = $mailingType == 2 ? 2 : 1; $result = jNews_Lists::checkListNotEmpty($type); if (!$result) { if ($type == 2) { $disp = addslashes(_JNEWS_CHECKCAMPAIGNFOUND); } else { $disp = addslashes(_JNEWS_CHECKLISTFOUND); } echo "<script> alert('" . $disp . "'); window.history.go(-1);</script>\n"; break; } $mailingType = JRequest::getVar('listype'); if (empty($listId)) { $listId = JRequest::getVar('listid'); } if (!empty($listId)) { $mailingType = jNews_Lists::getListType($listId) == 2 ? 2 : 1; } JRequest::setVar('listype', $mailingType); $total = jNews_Mailing::countMailings($listId, $mailingType); $total++; jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&task=edit&mailingid=0&issue_nb=' . $total . '&listype=' . $mailingType . '&listid=' . $listId . '&isEdit=0'); //mariap break; case 'saveSend': JRequest::checkToken() or die('Invalid Token'); $mySess = JFactory::getSession(); $mailingType = $mySess->get('listype', '', 'LType'); $status = checkMailingSave($mailingType); if (!$status) { return false; } jNews_Mailing::saveMailing($mailingId, $listId); case 'sendready': //we update the senddate of the newsletter jNews_Mailing::updatesenddate($mailingId); jNews_MailingsHTML::sendReady($mailingId, $listId, $listType); break; case 'generate': if (class_exists('jNews_Auto')) { $still = false; $message = jnews::printYN(jNews_Auto::processQueue(true, true, $still, true), 'Queue processed', _JNEWS_ERROR); jNews_Auto::displayStatus(); } return; break; case 'send': $queueC = new jNews_Queue(); $queueC->checkForNewsletters($mailingId); $queueCount = jNews_Queue::getQueueCount($mailingId); $totalSub = JRequest::setVar('totalsend', $queueCount); $linkURL = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=continuesend&mailingid=' . $mailingId . '&totalsend=' . $totalSub, true, false, true); jNews_Tools::redirect($linkURL); break; case 'continuesend': $queueC = new jNews_Queue(); //we update the senddate of the mailing to be now to be able to continue the sending and send it after we click continue // $queueC->updateSenddateToNow($mailingId); $totalSend = JRequest::getVar('totalsend', 0, '', 'int'); $alreadySent = JRequest::getVar('alreadysent', 0, '', 'int'); $queueC->start = $alreadySent; $queueC->total = $totalSend; $queueC->pause = $GLOBALS[JNEWS . 'pause_time']; $queueC->sendQueue(false, $mailingId, false, true); ob_start(); exit; break; case 'testspam': if (empty($message)) { $message = _JNEWS_MESSAGE_NOT; } $mailingId = $mailingId == 0 ? jNews_Mailing::getLastMailingId() : $mailingId; $my = JFactory::getUser(); if ($listId > 0) { $archivemailing = jNews_Mailing::getMailingView($mailingId, $listId); } else { $archivemailing = jNews_Mailing::getMailingView($mailingId); } $mailing = new stdClass(); $receivers = new stdClass(); $receivers->email = '*****@*****.**'; $receivers->name = $archivemailing->fromname; $receivers->receive_html = 1; $receivers->id = jNews_Subscribers::getSubscriberIdFromUserId($my->id); //if email are different we dont replace because we want to make sure the spam cehck count the fact that //sender and bounce back are different if ($archivemailing->fromemail == $archivemailing->frombounce) { $archivemailing->frombounce = $my->email; } $archivemailing->fromemail = $my->email; $mailerC = new jNews_ProcessMail(); $status = $mailerC->send($archivemailing, $receivers); $message = jnews::printYN($status, _JNEWS_SPAMTEXT_MESSAGE_SENT_SUCCESSFULLY, $message); $link = 'http://www.joobi.co/index.php?option=com_jlinks&controller=redirect&link=SpamCheck&alt=jnewsdoc_glossary'; $iFrame = '<iframe src="' . $link . '" width="100%" height="680px" scrolling="auto"></iframe>'; echo $iFrame; break; case 'savePreview': JRequest::checkToken() or die('Invalid Token'); $status = checkMailingSave($mailingType); if (!$status) { return false; } if ($mailingType == 7) { $mailing = JRequest::getVar('mailing', ''); $ContentStatus = checkTag(); if (!$ContentStatus) { return false; } } jNews_Mailing::saveMailing($mailingId, $listId); case 'preview': $emailaddress = JRequest::getVar('emailaddress', ''); $mailingId = $mailingId == 0 ? jNews_Mailing::getLastMailingId() : $mailingId; if (!empty($emailaddress)) { $status = jNews_Mailing::sendTestEmail($mailingId, $listId); if (empty($message)) { $message = _JNEWS_MESSAGE_NOT; } $message = jnews::printYN($status, _JNEWS_MESSAGE_SENT_SUCCESSFULLY, $message); } if ($listId > 0) { $archivemailing = jNews_Mailing::getMailingView($mailingId, $listId); } else { $archivemailing = jNews_Mailing::getMailingView($mailingId); } $doc = JFactory::getDocument(); $css = '.icon-48-preview{ background-image:url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'header/preview.png)}'; $doc->addStyleDeclaration($css, $type = 'text/css'); $title = _JNEWS_PREVIEW_TITLE . ': ' . $archivemailing->subject; backHTML::_header(_JNEWS_PREVIEW_TITLE, 'preview.png', $message, $task, $action); //new view for the preview mailing echo '<table cellpadding="0" cellspacing="2" border="0" width="100%"><tr><td width="40%">'; jNews_MailingsHTML::previewMailingHTML($mailingId, $listId, $listType, $archivemailing->html); echo '</td><td width="60%">'; $forms['main'] = ''; $list = jNews_Lists::getOneList($archivemailing->list_id); $textonly = ''; $mailerC = new jNews_ProcessMail(); $queueInfo = new stdClass(); $queueInfo->mailingid = $mailingId; $queueInfo->listid = @$listId; $mailerC->getContent($archivemailing->images, $archivemailing->html, $archivemailing->textonly, $archivemailing->subject, false, true, $queueInfo); //new $archivemailing->subject if ($archivemailing->html == 1) { if (empty($template_id)) { $template_id = $archivemailing->template_id; } if (!empty($template_id)) { jNews_Templates::includeStyles($archivemailing->htmlcontent, $template_id); } } else { $archivemailing->textonly = jNews_ProcessMail::htmlToText($archivemailing->textonly); } //new view for the preview mailing jNews_MailingsHTML::viewHeading($archivemailing); echo '</td></tr><tr><td colspan="2">'; jNews_MailingsHTML::viewMailing($archivemailing, $forms); echo '</td></tr></tbody></table>'; if ($mailingId == 0) { JRequest::setVar('mailingid', $mailingId); } break; case 'view': $mailingType = JRequest::getVar('listype'); if (!empty($mailingType)) { $mySess = JFactory::getSession(); $mySess->set('listype', $mailingType, 'LType'); } if ($mailingId != 0) { if ($listId > 0) { $archivemailing = jNews_Mailing::getMailingView($mailingId, $listId); } else { $archivemailing = jNews_Mailing::getMailingView($mailingId); } if (empty($template_id)) { $template_id = $archivemailing->template_id; } if (!empty($template_id)) { jNews_Templates::includeStyles($archivemailing->htmlcontent, $template_id); } $forms['main'] = "<form action='index.php?option=" . JNEWS_OPTION . "&act=mailing&listype=" . $listType . "&listid=" . $listId . "' method='post' name='adminForm' id=\"adminForm\">"; jNews_Mailing::_header($task, $action, $listType, $message); backHTML::formStart('show_mailing', 0, ''); jNews_MailingsHTML::viewMailing($archivemailing, $forms); $go[] = jnews::makeObj('act', 'mailing'); $go[] = jnews::makeObj('task', 'viewmailing'); $go[] = jnews::makeObj('listId', $archivemailing->list_id); //listid to listId--original backHTML::formEnd($go); } break; case 'deletequeue': //implement here what are we going to do with the delete queueu column on the mailing $mailingID = JRequest::getVar('mailingid'); $mailingType = JRequest::getVar('listype'); if (!empty($mailingID)) { $db = JFactory::getDBO(); $db->setQuery('DELETE FROM `#__jnews_queue` WHERE `mailing_id` = ' . $mailingID); $db->query(); $message = jnews::printYN(true, _JNEWS_MAILING_QUEUE_DELETED, _JNEWS_ERROR); } else { $message = jnews::printYN(false, _JNEWS_MAILING_QUEUE_DELETED, _JNEWS_ERROR); } jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType, $message); break; case 'deleteMailing': JRequest::checkToken() or die('Invalid Token'); $d['mailing'] = jNews_Mailing::getOneMailing('', $mailingId, '', $new); $message = jnews::printYN(jNews_Mailing::delete($d), @constant($GLOBALS[JNEWS . 'listname' . $d['mailing']->list_type]) . '"' . $d['mailing']->subject . '"' . _JNEWS_SUCCESS_DELETED, _JNEWS_ERROR); $showMailings = true; break; case 'cancel': $url = 'index.php?option=' . JNEWS_OPTION . '&act=mailing&mailingid=' . $mailingId; $url .= (!empty($listId) ? '&listid=' . $listId : '') . '&listype=' . $mailingType; jNews_Tools::redirect($url); break; case 'copy': JRequest::checkToken() or die('Invalid Token'); $message = jnews::printYN(jNews_Mailing::copyMailing($mailingId), _JNEWS_MAILING_COPY, _JNEWS_ERROR); $showMailings = true; break; case 'cancelMailing': $showMailings = true; break; case 'publishMailing': JRequest::checkToken() or die('Invalid Token'); $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new); $message = jnews::printYN(jNews_Mailing::publishMailing($mailingId), @constant($GLOBALS[JNEWS . 'listname' . $mailing->mailing_type]) . ' ' . _JNEWS_PUBLISHED, _JNEWS_ERROR); $mailingType = jNews_Mailing::getMailingInfoz($mailingId); jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType); break; case 'unpublishMailing': JRequest::checkToken() or die('Invalid Token'); $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new); $message = jnews::printYN(jNews_Mailing::unpublishMailing($mailingId), @constant($GLOBALS[JNEWS . 'listname' . $mailing->mailing_type]) . ' ' . _JNEWS_UNPUBLISHED, _JNEWS_ERROR); $mailingType = jNews_Mailing::getMailingInfoz($mailingId); jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType . '&listid=' . $listId); break; case 'cpanel': backHTML::controlPanel(); break; case 'save': JRequest::checkToken() or die('Invalid Token'); $subject = JRequest::getVar('subject', ''); if (empty($subject)) { echo "<script> alert('subject needs to be not empty'); window.history.go(-1);</script>\n"; return false; } if (!isset($mailingType)) { $mySess = JFactory::getSession(); $mailingType = $mySess->get('listype', '', 'LType'); } $status = checkMailingSave($mailingType); if ($mailingType == 7) { $mailing = JRequest::getVar('mailing', ''); $ContentStatus = checkTag(); if (!$ContentStatus) { return false; } } if (!$status) { return false; } $message = jnews::printYN(jNews_Mailing::saveMailing($mailingId, $listId), _JNEWS_MAILING_SAVED, _JNEWS_ERROR); if (!empty($mailingtype)) { jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType . '&listid=' . $listId); } else { jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType . '&listid=' . $listId); $showMailings = true; unset($GLOBALS["task"]); unset($_REQUEST["task"]); } break; case 'apply': JRequest::checkToken() or die('Invalid Token'); $mailingid = JRequest::getVar('mailingid', '0'); if (!isset($mailingType)) { $mySess = JFactory::getSession(); $mailingType = $mySess->get('listype', '', 'LType'); } $status = checkMailingSave($mailingType); if ($mailingType == 7) { $mailing = JRequest::getVar('mailing', ''); $ContentStatus = checkTag(); if (!$ContentStatus) { return false; } } if (!$status) { return false; } $message = jnews::printYN(jNews_Mailing::saveMailing($mailingId, $listId), _JNEWS_MAILING_SAVED, _JNEWS_ERROR); $mailingid = $mailingid == 0 ? jNews_Mailing::getLastMailingId() : $mailingid; if (!empty($mailingtype)) { jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&task=edit&listype=' . $mailingType . '&mailingid=' . $mailingid . '&listid=' . $listId); } else { jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&task=edit&listype=' . $mailingType . '&mailingid=' . $mailingid . '&listid=' . $listId); $showMailings = true; unset($GLOBALS["task"]); unset($_REQUEST["task"]); } break; case 'show': $id = JRequest::getVar('mailingid'); $mySess = JFactory::getSession(); $mailingType = JRequest::getVar('listype', 0); $listId = JRequest::getVar('listid', 0); $link = 'index.php?option=' . JNEWS_OPTION . '&act=mailing&listype=' . $mailingType . '&listid=' . $listId; jNews_Tools::redirect($link); $showMailings = true; break; case 'toggle': $listid = JRequest::getVar('listid'); $column = JRequest::getVar('col'); $mailingid = JRequest::getVar('mailingid'); if (!empty($mailingid) && !empty($column)) { $passObj = new stdClass(); $passObj->tableName = '#__jnews_mailings'; $passObj->columnName = $column; $passObj->whereColumn = 'id'; $passObj->whereColumnValue = $mailingid; jnews::toggle($passObj); } if ($listType == 1) { jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listid=' . $listid . '&listype=1'); } else { jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=mailing&listid=' . $listid . '&listype=2'); } break; default: $showMailings = true; break; } if ($showMailings) { if (empty($listType)) { $listType = JRequest::getVar('listype', 0); } if (empty($listId)) { $listId = JRequest::getVar('listid', 0); } $paginationStart = JRequest::getVar('pg'); if (!empty($paginationStart)) { $limitstart = 0; $limitend = $paginationStart; } else { $app = JFactory::getApplication(); $limitstart = $app->getUserStateFromRequest('limitstart', 'limitstart', 0, 'int'); $limitend = $app->getUserStateFromRequest('limit', 'limit', 0, 'int'); } $limittotal = jNews_Mailing::countMailings(0, $listType); $setLimit = new stdClass(); $setLimit->total = !empty($limittotal) ? $limittotal : 0; $setLimit->start = !empty($limitstart) ? $limitstart : 0; $setLimit->end = !empty($limitend) ? $limitend : $limittotal; if ($setLimit->total == $setLimit->end) { $setLimit->start = 0; } jNews_Mailing::showMailings($task, $action, $listId, $listType, $message, true, _JNEWS_MENU_MAILING, $setLimit); } return true; }
public static function deleteList($listId) { $db = JFactory::getDBO(); $total = 0; $xf = new jNews_Config(); $list = jNews_Lists::getOneList($listId); $query = 'DELETE FROM `#__jnews_lists` WHERE `id` = ' . $listId; $db->setQuery($query); $db->query(); //delete mailings in listmailings where listid=listid $query = 'DELETE FROM `#__jnews_listmailings` WHERE `list_id` = ' . $listId; $db->setQuery($query); $db->query(); //delete listsubscribers in listsubscribers where listid=listid $query = 'DELETE FROM `#__jnews_listssubscribers` WHERE `list_id` = ' . $listId; $db->setQuery($query); $db->query(); //delete entries in the followup $query = 'DELETE FROM `#__jnews_followup` WHERE `followup_id` = ' . $listId; //for autoresponders $query .= ' OR `list_id`=' . $listId; //for lists $db->setQuery($query); $db->query(); return true; }
public static function sendTestEmail($mailingId, $listId) { $list = new stdClass(); $new = null; $mailing = jNews_Mailing::getOneMailing($list, $mailingId, '', $new); if ($listId > 0) { $list = jNews_Lists::getOneList($listId); } else { $list = jNews_Lists::getOneList($mailing->list_id); } $previewemailaddress = JRequest::getVar('emailaddress', ''); $previewname = JRequest::getVar('name', ''); $previewhtml = JRequest::getVar('html', '0'); $receivers = new stdClass(); $my = JFactory::getUser(); $d['email'] = trim($previewemailaddress); $infos = jNews_Subscribers::getSubscriberIdFromEmail($d); if (empty($infos['subscriberId'])) { $d['email'] = $my->email; $infos = jNews_Subscribers::getSubscriberIdFromEmail($d); } if (!empty($infos['subscriberId'])) { $receivers = jNews_Subscribers::getSubscribersFromId(array($infos['subscriberId'])); } else { $receivers->id = 0; } $receivers->email = $previewemailaddress; $receivers->name = $previewname; $receivers->receive_html = $previewhtml; $mailerC = new jNews_ProcessMail(); return $mailerC->send($mailing, $receivers); }
/** * This public static function is to get the listId(s) subscribed by users(s) during new subscription * @param redirect - this is a param passed from the module to do redirect of the page after subscription */ public static function getListidsSubscribedInfo($subscriberId, $modlistids = null, $redirect = false) { $subscriber = ''; $subsListInfo = new stdClass(); $subsListInfo->user_id = $subscriberId; $status = true; $db = JFactory::getDBO(); $acl = JFactory::getACL(); $my = JFactory::getUser(); $listIds = JRequest::getVar('listid', '0'); if (!$redirect && $modlistids != null) { $listIds = $modlistids; } if (!empty($listIds)) { $accessName = ''; $userid = JRequest::getInt('userid'); $idslists = explode(",", $listIds); if ($modlistids != null) { unset($idslists[0]); } foreach ($idslists as $i => $listId) { $listId = intval($listId); if ($listId <= 0) { break; } $list = jNews_Lists::getOneList($listId); if (empty($list)) { echo jnews::printM('red', 'List not defined for ID:' . $listId); continue; } $listIds = explode(',', $list->acc_id); if (version_compare(JVERSION, '1.6.0', '<')) { //j15 $usergid = $my->gid; } else { //j16 $usergid = JAccess::getGroupsByUser($my->id, false); } if (is_array($listIds)) { if (is_array($usergid)) { $canAccess = array_intersect($usergid, $listIds); if (empty($canAccess)) { $status = false; } } else { if (!in_array($usergid, $listIds)) { $status = false; } } } else { if (is_array($usergid)) { $canAccess = array_intersect($usergid, $listIds); if (empty($canAccess)) { $status = false; } } else { if ($usergid != $listIds) { $status = false; } } } //alex added ! if (!$status) { echo jnews::printM('red', JNEWS_NO_LIST_PERM); } $subsListInfo->sub_list_id[$i] = $listId; $subsListInfo->subscribed[$i] = 1; $subsListInfo->acc_level[$i] = $list->acc_id; } } else { $subsListInfo->sub_list_id = JRequest::getVar('sub_list_id', 0); $subsListInfo->subscribed = JRequest::getVar('subscribed', 0); if ($subsListInfo->subscribed == 0) { $subsListInfo->subscribed = array(); if (!empty($subsListInfo->sub_list_id)) { foreach ($subsListInfo->sub_list_id as $key => $value) { $subsListInfo->subscribed[$key] = 0; } } } $subsListInfo->acc_level = JRequest::getInt('acc_level', 29); if (!empty($subsListInfo->sub_list_id)) { foreach ($subsListInfo->sub_list_id as $key => $value) { if (empty($subsListInfo->subscribed[$key]) || $subsListInfo->subscribed[$key] == 0) { $subsListInfo->subscribed[$key] = 0; } } } } if (!empty($subsListInfo->subscribed) && $subsListInfo->user_id > 0) { jNews_ListsSubs::updateSubscriptionToLists($subsListInfo); } return true; }