Esempio n. 1
0
 public function acyimportHelper()
 {
     acymailing_increasePerf();
     $this->db = JFactory::getDBO();
     JPluginHelper::importPlugin('acymailing');
     $this->dispatcher = JDispatcher::getInstance();
 }
Esempio n. 2
0
 public function acyqueueHelper()
 {
     $this->config = acymailing_config();
     $this->subClass = acymailing_get('class.subscriber');
     $this->listsubClass = acymailing_get('class.listsub');
     $this->listsubClass->checkAccess = false;
     $this->listsubClass->sendNotif = false;
     $this->listsubClass->sendConf = false;
     $this->send_limit = (int) $this->config->get('queue_nbmail', 40);
     acymailing_increasePerf();
     @ini_set('default_socket_timeout', 10);
     @ignore_user_abort(true);
     $timelimit = intval(ini_get('max_execution_time'));
     if (empty($timelimit)) {
         $timelimit = 600;
     }
     $calculatedTimeout = $this->config->get('max_execution_time');
     if (!empty($calculatedTimeout) && $calculatedTimeout < $timelimit) {
         $timelimit = $calculatedTimeout;
     }
     if (!empty($timelimit)) {
         $this->stoptime = time() + $timelimit - 4;
     }
     $this->db = JFactory::getDBO();
 }
Esempio n. 3
0
    function install()
    {
        acymailing_increasePerf();
        $newConfig = new stdClass();
        $newConfig->installcomplete = 1;
        $config = acymailing_config();
        $updateHelper = acymailing_get('helper.update');
        if (!$config->save($newConfig)) {
            $updateHelper->installTables();
            return;
        }
        jimport('joomla.filesystem.folder');
        $frontLanguages = JFolder::folders(JPATH_ROOT . DS . 'language', '-');
        $backLanguages = JFolder::folders(JPATH_ADMINISTRATOR . DS . 'language', '-');
        $installedLanguages = array_unique(array_merge($frontLanguages, $backLanguages));
        if (($key = array_search('en-GB', $installedLanguages)) !== false) {
            unset($installedLanguages[$key]);
        }
        if (!empty($installedLanguages)) {
            $js = 'try{
				var ajaxCall = new Ajax("index.php?option=com_acymailing&ctrl=file&task=installLanguages&tmpl=component&languages=' . implode(',', $installedLanguages) . '",{
					method: "get",
					onComplete: function(responseText, responseXML) {
						container = document.getElementById("acymailing_div");
						container.innerHTML = responseText+container.innerHTML;
					}
				}).request();
			}catch(err){
				new Request({
					url:"index.php?option=com_acymailing&ctrl=file&task=installLanguages&tmpl=component&languages=' . implode(',', $installedLanguages) . '",
					method: "get",
					onSuccess: function(responseText, responseXML) {
						container = document.getElementById("acymailing_div");
						container.innerHTML = responseText+container.innerHTML;
					}
				}).send();
			}';
            $doc = JFactory::getDocument();
            $doc->addScriptDeclaration($js);
        }
        $updateHelper->initList();
        $updateHelper->installTemplates();
        $updateHelper->installNotifications();
        $updateHelper->installMenu();
        $updateHelper->installExtensions();
        $updateHelper->installBounceRules();
        $updateHelper->fixDoubleExtension();
        $updateHelper->addUpdateSite();
        $updateHelper->fixMenu();
        if (ACYMAILING_J30) {
            JFile::move(ACYMAILING_BACK . 'acymailing_j3.xml', ACYMAILING_BACK . 'acymailing.xml');
        }
        $acyToolbar = acymailing::get('helper.toolbar');
        $acyToolbar->setTitle('AcyMailing', 'dashboard');
        $acyToolbar->display();
        $this->_iframe(ACYMAILING_UPDATEURL . 'install&fromversion=' . JRequest::getCmd('fromversion') . '&fromlevel=' . JRequest::getCmd('fromlevel'));
    }
Esempio n. 4
0
function installAcyMailing()
{
    include_once rtrim(JPATH_ADMINISTRATOR, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_acymailing' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'helper.php';
    acymailing_increasePerf();
    $installClass = new acymailingInstall();
    $installClass->updateJoomailing();
    $installClass->addPref();
    $installClass->updatePref();
    $installClass->updateSQL();
    $installClass->displayInfo();
}
Esempio n. 5
0
 function install()
 {
     acymailing_increasePerf();
     $newConfig = new stdClass();
     $newConfig->installcomplete = 1;
     $config = acymailing_config();
     if (!$config->save($newConfig)) {
         $db = JFactory::getDBO();
         echo '<h2>The installation failed, some tables are missing, we will try to create them now...</h2>';
         $queries = file_get_contents(ACYMAILING_BACK . 'tables.sql');
         $queriesTable = explode("CREATE TABLE", $queries);
         $success = true;
         foreach ($queriesTable as $oneQuery) {
             $oneQuery = trim($oneQuery);
             if (empty($oneQuery)) {
                 continue;
             }
             $db->setQuery("CREATE TABLE " . $oneQuery);
             if (!$db->query()) {
                 echo '<br/><br/><span style="color:red">Error creating table : ' . $db->getErrorMsg() . '</span><br/>';
                 $success = false;
             } else {
                 echo '<br/><span style="color:green">Table successfully created</span>';
             }
         }
         if ($success) {
             echo '<h2>Please install again AcyMailing via the Joomla Extensions manager, the tables are now created so the installation will work</h2>';
         } else {
             echo '<h2>Some tables could not be created, please fix the above issues and then install again AcyMailing.</h2>';
         }
         return;
     }
     $updateHelper = acymailing_get('helper.update');
     $updateHelper->initList();
     $updateHelper->installTemplates();
     $updateHelper->installNotifications();
     $updateHelper->installMenu();
     $updateHelper->installExtensions();
     $updateHelper->installBounceRules();
     $updateHelper->addUpdateSite();
     $updateHelper->fixMenu();
     acymailing_setTitle('AcyMailing', 'acymailing', 'dashboard');
     $this->_iframe(ACYMAILING_UPDATEURL . 'install');
 }
Esempio n. 6
0
function installAcyMailing(){
	$success = true;
	try{
		include_once(rtrim(JPATH_ADMINISTRATOR,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_acymailing'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php');
	}catch(Exception $e){
		$updateHelper = acymailing_get('helper.update');
		$updateHelper->installTables();
		$success = false;
	}

	acymailing_increasePerf();

	$installClass = new acymailingInstall();
	$installClass->updateJoomailing();
	$installClass->addPref();
	$installClass->updatePref();
	$installClass->updateSQL();
	if($success) $installClass->displayInfo();
}
Esempio n. 7
0
 function install()
 {
     acymailing_increasePerf();
     $newConfig = new stdClass();
     $newConfig->installcomplete = 1;
     $config = acymailing_config();
     $updateHelper = acymailing_get('helper.update');
     if (!$config->save($newConfig)) {
         $updateHelper->installTables();
         return;
     }
     jimport('joomla.filesystem.folder');
     $frontLanguages = JFolder::folders(JPATH_ROOT . DS . 'language', '-');
     $backLanguages = JFolder::folders(JPATH_ADMINISTRATOR . DS . 'language', '-');
     $installedLanguages = array_unique(array_merge($frontLanguages, $backLanguages));
     if (($key = array_search('en-GB', $installedLanguages)) !== false) {
         unset($installedLanguages[$key]);
     }
     if (!empty($installedLanguages)) {
         $langText = JText::_('ACY_INSTALL_LANGUAGES');
         if ($langText == 'ACY_INSTALL_LANGUAGES') {
             $langText = 'Click here to install the new language files';
         }
         JHTML::_('behavior.modal', 'a.modal');
         acymailing_display('<a class="modal btn" rel="{handler: \'iframe\', size: {x: 600, y: 250}}" href="' . JURI::base() . 'index.php?option=com_acymailing&ctrl=file&task=installLanguages&tmpl=component&languages=' . implode(',', $installedLanguages) . '">' . $langText . '</a>', 'info');
     }
     $updateHelper->initList();
     $updateHelper->installTemplates();
     $updateHelper->installNotifications();
     $updateHelper->installMenu();
     $updateHelper->installExtensions();
     $updateHelper->installBounceRules();
     $updateHelper->fixDoubleExtension();
     $updateHelper->addUpdateSite();
     $updateHelper->fixMenu();
     if (ACYMAILING_J30) {
         JFile::move(ACYMAILING_BACK . 'acymailing_j3.xml', ACYMAILING_BACK . 'acymailing.xml');
     }
     acymailing_setTitle('AcyMailing', 'acymailing', 'dashboard');
     $this->_iframe(ACYMAILING_UPDATEURL . 'install&fromversion=' . JRequest::getCmd('fromversion'));
 }
Esempio n. 8
0
 function install()
 {
     acymailing_increasePerf();
     $newConfig = new stdClass();
     $newConfig->installcomplete = 1;
     $config = acymailing_config();
     $updateHelper = acymailing_get('helper.update');
     if (!$config->save($newConfig)) {
         $updateHelper->installTables();
         return;
     }
     $updateHelper->initList();
     $updateHelper->installTemplates();
     $updateHelper->installNotifications();
     $updateHelper->installMenu();
     $updateHelper->installExtensions();
     $updateHelper->installBounceRules();
     $updateHelper->fixDoubleExtension();
     $updateHelper->addUpdateSite();
     $updateHelper->fixMenu();
     acymailing_setTitle('AcyMailing', 'acymailing', 'dashboard');
     $this->_iframe(ACYMAILING_UPDATEURL . 'install&fromversion=' . JRequest::getCmd('fromversion'));
 }
Esempio n. 9
0
 function doexport()
 {
     if (!$this->isAllowed('subscriber', 'export')) {
         return;
     }
     JRequest::checkToken() or die('Invalid Token');
     acymailing_increasePerf();
     $filtersExport = JRequest::getVar('exportfilter');
     $listsToExport = JRequest::getVar('exportlists');
     $fieldsToExport = JRequest::getVar('exportdata');
     $fieldsToExportList = JRequest::getVar('exportdatalist');
     $fieldsToExportOthers = JRequest::getVar('exportdataother');
     $inseparator = JRequest::getString('exportseparator');
     $inseparator = str_replace(array('semicolon', 'colon', 'comma'), array(';', ',', ','), $inseparator);
     $exportFormat = JRequest::getString('exportformat');
     if (!in_array($inseparator, array(',', ';'))) {
         $inseparator = ';';
     }
     $exportLists = array();
     if (!empty($filtersExport['subscribed'])) {
         foreach ($listsToExport as $listid => $checked) {
             if (!empty($checked)) {
                 $exportLists[] = (int) $listid;
             }
         }
     }
     $exportFields = array();
     $exportFieldsList = array();
     $exportFieldsOthers = array();
     $selectOthers = '';
     foreach ($fieldsToExport as $fieldName => $checked) {
         if (!empty($checked)) {
             $exportFields[] = acymailing_secureField($fieldName);
         }
     }
     foreach ($fieldsToExportList as $fieldName => $checked) {
         if (!empty($checked)) {
             $exportFieldsList[] = acymailing_secureField($fieldName);
         }
     }
     if (!empty($fieldsToExportOthers)) {
         foreach ($fieldsToExportOthers as $fieldName => $checked) {
             if (!empty($checked)) {
                 $exportFieldsOthers[] = acymailing_secureField($fieldName);
             }
         }
     }
     $selectFields = 's.`' . implode('`, s.`', $exportFields) . '`';
     $config = acymailing_config();
     $newConfig = new stdClass();
     $newConfig->export_fields = implode(',', array_merge($exportFields, $exportFieldsOthers, $exportFieldsList));
     $newConfig->export_lists = implode(',', $exportLists);
     $newConfig->export_separator = JRequest::getString('exportseparator');
     $newConfig->export_format = $exportFormat;
     $filterActive = array();
     foreach ($filtersExport as $filterKey => $value) {
         if ($value == 1) {
             $filterActive[] = $filterKey;
         }
     }
     $newConfig->export_filters = implode(',', $filterActive);
     $config->save($newConfig);
     $where = array();
     if (empty($exportLists)) {
         $querySelect = 'SELECT s.`subid`, ' . $selectFields . ' FROM ' . acymailing_table('subscriber') . ' as s';
     } else {
         $querySelect = 'SELECT DISTINCT s.`subid`, ' . $selectFields . ' FROM ' . acymailing_table('listsub') . ' as a JOIN ' . acymailing_table('subscriber') . ' as s on a.subid = s.subid';
         $where[] = 'a.listid IN (' . implode(',', $exportLists) . ')';
         $where[] = 'a.status = 1';
     }
     if (!empty($filtersExport['confirmed'])) {
         $where[] = 's.confirmed = 1';
     }
     if (!empty($filtersExport['registered'])) {
         $where[] = 's.userid > 0';
     }
     if (!empty($filtersExport['enabled'])) {
         $where[] = 's.enabled = 1';
     }
     if (JRequest::getInt('sessionvalues') and !empty($_SESSION['acymailing']['exportusers'])) {
         $where[] = 's.subid IN (' . implode(',', $_SESSION['acymailing']['exportusers']) . ')';
     }
     $query = $querySelect;
     if (!empty($where)) {
         $query .= ' WHERE (' . implode(') AND (', $where) . ')';
     }
     if (JRequest::getInt('sessionquery')) {
         $currentSession = JFactory::getSession();
         $selectOthers = '';
         if (!empty($exportFieldsOthers)) {
             foreach ($exportFieldsOthers as $oneField) {
                 $selectOthers .= ' , ' . $oneField . ' AS ' . str_replace('.', '_', $oneField);
             }
         }
         $query = 'SELECT DISTINCT s.`subid`, ' . $selectFields . $selectOthers . ' ' . $currentSession->get('acyexportquery');
     }
     $query .= ' ORDER BY s.subid';
     $db = JFactory::getDBO();
     $encodingClass = acymailing_get('helper.encoding');
     $exportHelper = acymailing_get('helper.export');
     $fileName = 'export_' . date('Y-m-d');
     if (!empty($exportLists)) {
         $fileName = '';
         $db->setQuery('SELECT name FROM #__acymailing_list WHERE listid IN (' . implode(',', $exportLists) . ')');
         $allExportedLists = $db->loadObjectList();
         foreach ($allExportedLists as $oneList) {
             $fileName .= '__' . $oneList->name;
         }
         $fileName = trim($fileName, '__');
     }
     $exportHelper->addHeaders($fileName);
     $eol = "\r\n";
     $before = '"';
     $separator = '"' . $inseparator . '"';
     $after = '"';
     $allFields = array_merge($exportFields, $exportFieldsOthers);
     if (!empty($exportFieldsList)) {
         $allFields = array_merge($allFields, $exportFieldsList);
         $selectFields = 'l.`' . implode('`, l.`', $exportFieldsList) . '`';
         $selectFields = str_replace('listname', 'name', $selectFields);
     }
     echo $before . implode($separator, $allFields) . $after . $eol;
     if (acymailing_bytes(ini_get('memory_limit')) > 150000000) {
         $nbExport = 50000;
     } elseif (acymailing_bytes(ini_get('memory_limit')) > 80000000) {
         $nbExport = 15000;
     } else {
         $nbExport = 5000;
     }
     if (!empty($exportFieldsList)) {
         $nbExport = 500;
     }
     $valDep = 0;
     $dateFields = array('created', 'confirmed_date', 'lastopen_date', 'lastclick_date', 'lastsent_date', 'userstats_opendate', 'userstats_senddate', 'urlclick_date', 'hist_date');
     do {
         $db->setQuery($query . ' LIMIT ' . $valDep . ', ' . $nbExport);
         $valDep += $nbExport;
         $allData = $db->loadAssocList();
         if (empty($allData)) {
             break;
         }
         $dataUser = array();
         $subids = array();
         for ($i = 0, $a = count($allData); $i < $a; $i++) {
             $subids[] = (int) $allData[$i]['subid'];
             if (!in_array('subid', $exportFields)) {
                 array_shift($allData[$i]);
             }
             foreach ($allData[$i] as $fieldName => $oneUser) {
                 if (!in_array($fieldName, $dateFields)) {
                     $dataUser[$subids[$i]][$fieldName] = $oneUser;
                 } else {
                     $dataUser[$subids[$i]][$fieldName] = acymailing_getDate($oneUser, '%Y-%m-%d %H:%M:%S');
                 }
             }
         }
         if (!empty($exportFieldsList) && !empty($subids)) {
             $queryList = 'SELECT ' . $selectFields . ', ls.subid FROM #__acymailing_listsub as ls JOIN #__acymailing_list as l ON ls.listid=l.listid JOIN #__acymailing_subscriber as s on ls.subid = s.subid WHERE (ls.status = 1) and ls.subid IN (' . implode(',', $subids) . ')';
             if (!empty($exportLists)) {
                 $queryList .= ' AND ls.listid IN (' . implode(',', $exportLists) . ')';
             }
             $db->setQuery($queryList);
             $resList = $db->loadObjectList();
             $userListid = array();
             $userListname = array();
             foreach ($resList as $listsub) {
                 if (in_array('listid', $exportFieldsList)) {
                     $userListid[$listsub->subid] = empty($userListid[$listsub->subid]) ? $listsub->listid : $userListid[$listsub->subid] . ' - ' . $listsub->listid;
                 }
                 if (in_array('listname', $exportFieldsList)) {
                     $userListname[$listsub->subid] = empty($userListname[$listsub->subid]) ? $listsub->name : $userListname[$listsub->subid] . ' - ' . $listsub->name;
                 }
             }
         }
         foreach ($subids as $subid) {
             if (!empty($exportFieldsList)) {
                 $listDetail = array();
                 if (in_array('listid', $exportFieldsList)) {
                     $listDetail[] = !empty($userListid[$subid]) ? $userListid[$subid] : '';
                 }
                 if (in_array('listname', $exportFieldsList)) {
                     $listDetail[] = !empty($userListname[$subid]) ? $userListname[$subid] : '';
                 }
                 $dataexport = implode($separator, $dataUser[$subid]) . $separator . implode($separator, $listDetail);
             } else {
                 $dataexport = implode($separator, $dataUser[$subid]);
             }
             echo $before . $encodingClass->change($dataexport, 'UTF-8', $exportFormat) . $after . $eol;
         }
     } while (!empty($allData));
     exit;
 }
Esempio n. 10
0
 function doexport()
 {
     if (!$this->isAllowed('subscriber', 'export')) {
         return;
     }
     JRequest::checkToken() or die('Invalid Token');
     acymailing_increasePerf();
     $filtersExport = JRequest::getVar('exportfilter');
     $listsToExport = JRequest::getVar('exportlists');
     $fieldsToExport = JRequest::getVar('exportdata');
     $inseparator = JRequest::getString('exportseparator');
     $inseparator = str_replace(array('semicolon', 'colon', 'comma'), array(';', ',', ','), $inseparator);
     $exportFormat = JRequest::getString('exportformat');
     if (!in_array($inseparator, array(',', ';'))) {
         $inseparator = ';';
     }
     $exportLists = array();
     if (!empty($filtersExport['subscribed'])) {
         foreach ($listsToExport as $listid => $checked) {
             if (!empty($checked)) {
                 $exportLists[] = (int) $listid;
             }
         }
     }
     $exportFields = array();
     foreach ($fieldsToExport as $fieldName => $checked) {
         if (!empty($checked)) {
             $exportFields[] = acymailing_secureField($fieldName);
         }
     }
     $config = acymailing_config();
     $newConfig = new stdClass();
     $newConfig->export_fields = implode(',', $exportFields);
     $newConfig->export_lists = implode(',', $exportLists);
     $newConfig->export_separator = JRequest::getString('exportseparator');
     $newConfig->export_format = $exportFormat;
     $config->save($newConfig);
     $where = array();
     if (empty($exportLists)) {
         $querySelect = 'SELECT s.`' . implode('`,s.`', $exportFields) . '` FROM ' . acymailing_table('subscriber') . ' as s';
     } else {
         $querySelect = 'SELECT DISTINCT s.`' . implode('`,s.`', $exportFields) . '` FROM ' . acymailing_table('listsub') . ' as a JOIN ' . acymailing_table('subscriber') . ' as s on a.subid = s.subid';
         $where[] = 'a.listid IN (' . implode(',', $exportLists) . ')';
         $where[] = 'a.status = 1';
     }
     if (!empty($filtersExport['confirmed'])) {
         $where[] = 's.confirmed = 1';
     }
     if (!empty($filtersExport['registered'])) {
         $where[] = 's.userid > 0';
     }
     if (!empty($filtersExport['enabled'])) {
         $where[] = 's.enabled = 1';
     }
     if (JRequest::getInt('sessionvalues') and !empty($_SESSION['acymailing']['exportusers'])) {
         $where[] = 's.subid IN (' . implode(',', $_SESSION['acymailing']['exportusers']) . ')';
     }
     if (JRequest::getInt('sessionquery')) {
         $currentSession = JFactory::getSession();
         $exportQuery = $currentSession->get('acyexportquery');
         if (!empty($exportQuery)) {
             $where[] = 's.subid IN (' . $exportQuery . ')';
         }
     }
     $query = $querySelect;
     if (!empty($where)) {
         $query .= ' WHERE (' . implode(') AND (', $where) . ')';
     }
     $db = JFactory::getDBO();
     $db->setQuery($query);
     $allData = $db->loadAssocList();
     $encodingClass = acymailing_get('helper.encoding');
     $exportHelper = acymailing_get('helper.export');
     $exportHelper->addHeaders('acymailingexport');
     $eol = "\r\n";
     $before = '"';
     $separator = '"' . $inseparator . '"';
     $after = '"';
     echo $before . implode($separator, $exportFields) . $after . $eol;
     for ($i = 0, $a = count($allData); $i < $a; $i++) {
         if (!empty($allData[$i]['created'])) {
             $allData[$i]['created'] = acymailing_getDate($allData[$i]['created'], '%Y-%m-%d %H:%M:%S');
         }
         echo $before . $encodingClass->change(implode($separator, $allData[$i]), 'UTF-8', $exportFormat) . $after . $eol;
     }
     exit;
 }
Esempio n. 11
0
 function importHelper()
 {
     acymailing_increasePerf();
     $this->db =& JFactory::getDBO();
 }
Esempio n. 12
0
 function doexport()
 {
     if (!$this->isAllowed('subscriber', 'export')) {
         return;
     }
     JRequest::checkToken() or die('Invalid Token');
     acymailing_increasePerf();
     $filtersExport = JRequest::getVar('exportfilter', array(), '', 'array');
     $listsToExport = JRequest::getVar('exportlists');
     $fieldsToExport = JRequest::getVar('exportdata');
     $fieldsToExportList = JRequest::getVar('exportdatalist');
     $fieldsToExportOthers = JRequest::getVar('exportdataother');
     $fieldsToExportGeoloc = JRequest::getVar('exportdatageoloc');
     $inseparator = JRequest::getString('exportseparator');
     $inseparator = str_replace(array('semicolon', 'colon', 'comma'), array(';', ',', ','), $inseparator);
     $exportFormat = JRequest::getString('exportformat');
     if (!in_array($inseparator, array(',', ';'))) {
         $inseparator = ';';
     }
     $exportUnsubLists = array();
     $exportWaitLists = array();
     $exportLists = array();
     if (!empty($filtersExport['subscribed'])) {
         foreach ($listsToExport as $listid => $status) {
             if ($status == -1) {
                 $exportUnsubLists[] = (int) $listid;
             } elseif ($status == 2) {
                 $exportWaitLists[] = (int) $listid;
             } elseif (!empty($status)) {
                 $exportLists[] = (int) $listid;
             }
         }
     }
     $app = JFactory::getApplication();
     if (!$app->isAdmin() && (empty($filtersExport['subscribed']) || empty($exportLists) && empty($exportUnsubLists) && empty($exportWaitLists))) {
         $listClass = acymailing_get('class.list');
         $frontLists = $listClass->getFrontendLists();
         foreach ($frontLists as $frontList) {
             $exportLists[] = (int) $frontList->listid;
         }
     }
     $exportFields = array();
     $exportFieldsList = array();
     $exportFieldsOthers = array();
     $exportFieldsGeoloc = array();
     foreach ($fieldsToExport as $fieldName => $checked) {
         if (!empty($checked)) {
             $exportFields[] = acymailing_secureField($fieldName);
         }
     }
     foreach ($fieldsToExportList as $fieldName => $checked) {
         if (!empty($checked)) {
             $exportFieldsList[] = acymailing_secureField($fieldName);
         }
     }
     if (!empty($fieldsToExportOthers)) {
         foreach ($fieldsToExportOthers as $fieldName => $checked) {
             if (!empty($checked)) {
                 $exportFieldsOthers[] = acymailing_secureField($fieldName);
             }
         }
     }
     if (!empty($fieldsToExportGeoloc)) {
         foreach ($fieldsToExportGeoloc as $fieldName => $checked) {
             if (!empty($checked)) {
                 $exportFieldsGeoloc[] = acymailing_secureField($fieldName);
             }
         }
     }
     $selectFields = 's.`' . implode('`, s.`', $exportFields) . '`';
     $config = acymailing_config();
     $newConfig = new stdClass();
     $newConfig->export_fields = implode(',', array_merge($exportFields, $exportFieldsOthers, $exportFieldsList, $exportFieldsGeoloc));
     $newConfig->export_lists = implode(',', $exportLists);
     $newConfig->export_separator = JRequest::getString('exportseparator');
     $newConfig->export_format = $exportFormat;
     $filterActive = array();
     foreach ($filtersExport as $filterKey => $value) {
         if ($value == 1) {
             $filterActive[] = $filterKey;
         }
     }
     $newConfig->export_filters = implode(',', $filterActive);
     $config->save($newConfig);
     $where = array();
     if (empty($exportLists) && empty($exportUnsubLists) && empty($exportWaitLists)) {
         $querySelect = 'SELECT s.`subid`, ' . $selectFields . ' FROM ' . acymailing_table('subscriber') . ' as s';
     } else {
         $querySelect = 'SELECT DISTINCT s.`subid`, ' . $selectFields . ' FROM ' . acymailing_table('listsub') . ' as a JOIN ' . acymailing_table('subscriber') . ' as s on a.subid = s.subid';
         if (!empty($exportLists)) {
             $conditions[] = 'a.status = 1 AND a.listid IN (' . implode(',', $exportLists) . ')';
         }
         if (!empty($exportUnsubLists)) {
             $conditions[] = 'a.status = -1 AND a.listid IN (' . implode(',', $exportUnsubLists) . ')';
         }
         if (!empty($exportWaitLists)) {
             $conditions[] = 'a.status = 2 AND a.listid IN (' . implode(',', $exportWaitLists) . ')';
         }
         if (count($conditions) == 1) {
             $where[] = $conditions[0];
         } else {
             $where[] = '(' . implode(') OR (', $conditions) . ')';
         }
     }
     if (!empty($filtersExport['confirmed'])) {
         $where[] = 's.confirmed = 1';
     }
     if (!empty($filtersExport['registered'])) {
         $where[] = 's.userid > 0';
     }
     if (!empty($filtersExport['enabled'])) {
         $where[] = 's.enabled = 1';
     }
     if (JRequest::getInt('sessionvalues') and !empty($_SESSION['acymailing']['exportusers'])) {
         $where[] = 's.subid IN (' . implode(',', $_SESSION['acymailing']['exportusers']) . ')';
     }
     if (JRequest::getInt('fieldfilters')) {
         foreach ($_SESSION['acymailing']['fieldfilter'] as $field => $value) {
             $where[] = 's.' . acymailing_secureField($field) . ' LIKE "%' . acymailing_getEscaped($value, true) . '%"';
         }
     }
     $query = $querySelect;
     if (!empty($where)) {
         $query .= ' WHERE (' . implode(') AND (', $where) . ')';
     }
     if (JRequest::getInt('sessionquery')) {
         $currentSession = JFactory::getSession();
         $selectOthers = '';
         if (!empty($exportFieldsOthers)) {
             foreach ($exportFieldsOthers as $oneField) {
                 $selectOthers .= ' , ' . $oneField . ' AS ' . str_replace('.', '_', $oneField);
             }
         }
         $query = 'SELECT DISTINCT s.`subid`, ' . $selectFields . $selectOthers . ' ' . $currentSession->get('acyexportquery');
     }
     $query .= ' ORDER BY s.subid';
     $db = JFactory::getDBO();
     $encodingClass = acymailing_get('helper.encoding');
     $exportHelper = acymailing_get('helper.export');
     $fileName = 'export_' . date('Y-m-d');
     if (!empty($exportLists)) {
         $fileName = '';
         $db->setQuery('SELECT name FROM #__acymailing_list WHERE listid IN (' . implode(',', $exportLists) . ')');
         $allExportedLists = $db->loadObjectList();
         foreach ($allExportedLists as $oneList) {
             $fileName .= '__' . $oneList->name;
         }
         $fileName = trim($fileName, '__');
     }
     $exportHelper->addHeaders($fileName);
     acymailing_displayErrors();
     $eol = "\r\n";
     $before = '"';
     $separator = '"' . $inseparator . '"';
     $after = '"';
     $allFields = array_merge($exportFields, $exportFieldsOthers);
     if (!empty($exportFieldsList)) {
         $allFields = array_merge($allFields, $exportFieldsList);
         $selectFields = 'l.`' . implode('`, l.`', $exportFieldsList) . '`';
         $selectFields = str_replace('listname', 'name', $selectFields);
     }
     if (!empty($exportFieldsGeoloc)) {
         $allFields = array_merge($allFields, $exportFieldsGeoloc);
     }
     $titleLine = $before . implode($separator, $allFields) . $after . $eol;
     $titleLine = str_replace('listid', 'listids', $titleLine);
     echo $titleLine;
     if (acymailing_bytes(ini_get('memory_limit')) > 150000000) {
         $nbExport = 50000;
     } elseif (acymailing_bytes(ini_get('memory_limit')) > 80000000) {
         $nbExport = 15000;
     } else {
         $nbExport = 5000;
     }
     if (!empty($exportFieldsList)) {
         $nbExport = 500;
     }
     $valDep = 0;
     $dateFields = array('created', 'confirmed_date', 'lastopen_date', 'lastclick_date', 'lastsent_date', 'userstats_opendate', 'userstats_senddate', 'urlclick_date', 'hist_date');
     do {
         $db->setQuery($query . ' LIMIT ' . $valDep . ', ' . $nbExport);
         $valDep += $nbExport;
         $allData = $db->loadAssocList('subid');
         if ($allData === false) {
             echo $eol . $eol . 'Error : ' . $db->getErrorMsg();
         }
         if (empty($allData)) {
             break;
         }
         foreach ($allData as $subid => &$oneUser) {
             if (!in_array('subid', $exportFields)) {
                 unset($allData[$subid]['subid']);
             }
             foreach ($dateFields as &$fieldName) {
                 if (isset($allData[$subid][$fieldName])) {
                     $allData[$subid][$fieldName] = acymailing_getDate($allData[$subid][$fieldName], '%Y-%m-%d %H:%M:%S');
                 }
             }
         }
         if (!empty($exportFieldsList) && !empty($allData)) {
             $queryList = 'SELECT ' . $selectFields . ', ls.subid FROM #__acymailing_listsub as ls JOIN #__acymailing_list as l ON ls.listid=l.listid JOIN #__acymailing_subscriber as s on ls.subid = s.subid WHERE (ls.status = 1) and ls.subid IN (' . implode(',', array_keys($allData)) . ')';
             if (!empty($exportLists)) {
                 $queryList .= ' AND ls.listid IN (' . implode(',', $exportLists) . ')';
             }
             $db->setQuery($queryList);
             $resList = $db->loadObjectList();
             foreach ($resList as &$listsub) {
                 if (in_array('listid', $exportFieldsList)) {
                     $allData[$listsub->subid]['listid'] = empty($allData[$listsub->subid]['listid']) ? $listsub->listid : $allData[$listsub->subid]['listid'] . ' - ' . $listsub->listid;
                 }
                 if (in_array('listname', $exportFieldsList)) {
                     $allData[$listsub->subid]['listname'] = empty($allData[$listsub->subid]['listname']) ? $listsub->name : $allData[$listsub->subid]['listname'] . ' - ' . $listsub->name;
                 }
             }
             unset($resList);
         }
         if (!empty($exportFieldsGeoloc) && !empty($allData)) {
             $orderGeoloc = JRequest::getCmd('exportgeolocorder');
             if (strtolower($orderGeoloc) !== 'desc') {
                 $orderGeoloc = 'asc';
             }
             $db->setQuery('SELECT geolocation_subid,' . implode(', ', $exportFieldsGeoloc) . ' FROM (SELECT * FROM #__acymailing_geolocation WHERE geolocation_subid IN (' . implode(',', array_keys($allData)) . ') ORDER BY geolocation_id ' . $orderGeoloc . ') as geoloc GROUP BY geolocation_subid');
             $resGeol = $db->loadObjectList();
             foreach ($resGeol as $geolData) {
                 foreach ($exportFieldsGeoloc as $geolField) {
                     $allData[$geolData->geolocation_subid][$geolField] = $geolField == 'geolocation_created' ? acymailing_getDate($geolData->{$geolField}, '%Y-%m-%d %H:%M:%S') : $geolData->{$geolField};
                 }
             }
             unset($resGeol);
         }
         foreach ($allData as $subid => &$oneUser) {
             $dataexport = implode($separator, $oneUser);
             echo $before . $encodingClass->change($dataexport, 'UTF-8', $exportFormat) . $after . $eol;
         }
         unset($allData);
     } while (true);
     exit;
 }
Esempio n. 13
0
 function doexport()
 {
     if (!$this->isAllowed('subscriber', 'export')) {
         return;
     }
     JRequest::checkToken() or die('Invalid Token');
     acymailing_increasePerf();
     $filtersExport = JRequest::getVar('exportfilter');
     $listsToExport = JRequest::getVar('exportlists');
     $fieldsToExport = JRequest::getVar('exportdata');
     $inseparator = JRequest::getString('exportseparator');
     $exportFormat = JRequest::getString('exportformat');
     if (!in_array($inseparator, array(',', ';'))) {
         $inseparator = ';';
     }
     $exportLists = array();
     if (!empty($filtersExport['subscribed'])) {
         foreach ($listsToExport as $listid => $checked) {
             if (!empty($checked)) {
                 $exportLists[] = (int) $listid;
             }
         }
     }
     $exportFields = array();
     foreach ($fieldsToExport as $fieldName => $checked) {
         if (!empty($checked)) {
             $exportFields[] = acymailing_secureField($fieldName);
         }
     }
     $config = acymailing_config();
     $newConfig = new stdClass();
     $newConfig->export_fields = implode(',', $exportFields);
     $newConfig->export_separator = $inseparator;
     $newConfig->export_format = $exportFormat;
     $config->save($newConfig);
     $where = array();
     if (empty($exportLists)) {
         $querySelect = 'SELECT s.`' . implode('`,s.`', $exportFields) . '` FROM ' . acymailing_table('subscriber') . ' as s';
     } else {
         $querySelect = 'SELECT DISTINCT s.`' . implode('`,s.`', $exportFields) . '` FROM ' . acymailing_table('listsub') . ' as a JOIN ' . acymailing_table('subscriber') . ' as s on a.subid = s.subid';
         $where[] = 'a.listid IN (' . implode(',', $exportLists) . ')';
         $where[] = 'a.status = 1';
     }
     if (!empty($filtersExport['confirmed'])) {
         $where[] = 's.confirmed = 1';
     }
     if (!empty($filtersExport['registered'])) {
         $where[] = 's.userid > 0';
     }
     if (JRequest::getInt('sessionvalues') and !empty($_SESSION['acymailing']['exportusers'])) {
         $where[] = 's.subid IN (' . implode(',', $_SESSION['acymailing']['exportusers']) . ')';
     }
     if (JRequest::getInt('sessionquery')) {
         $currentSession =& JFactory::getSession();
         $exportQuery = $currentSession->get('acyexportquery');
         if (!empty($exportQuery)) {
             $where[] = 's.subid IN (' . $exportQuery . ')';
         }
     }
     $query = $querySelect;
     if (!empty($where)) {
         $query .= ' WHERE (' . implode(') AND (', $where) . ')';
     }
     $db =& JFactory::getDBO();
     $db->setQuery($query);
     $allData = $db->loadAssocList();
     $encodingClass = acymailing_get('helper.encoding');
     @ob_clean();
     header("Pragma: public");
     header("Expires: 0");
     // set expiration time
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     header("Content-Type: application/force-download");
     header("Content-Type: application/octet-stream");
     header("Content-Type: application/download");
     header("Content-Disposition: attachment; filename=acymailingexport.csv;");
     header("Content-Transfer-Encoding: binary");
     $eol = "\r\n";
     $before = '"';
     $separator = '"' . $inseparator . '"';
     $after = '"';
     echo $before . implode($separator, $exportFields) . $after . $eol;
     for ($i = 0, $a = count($allData); $i < $a; $i++) {
         if (!empty($allData[$i]['created'])) {
             $allData[$i]['created'] = acymailing_getDate($allData[$i]['created'], '%Y-%m-%d %H:%M:%S');
         }
         echo $before . $encodingClass->change(implode($separator, $allData[$i]), 'UTF-8', $exportFormat) . $after . $eol;
     }
     exit;
 }