public function importLists() { $model = $this->getModel(); $WsImport = new MailUpWsImport(); $xmlLists = $WsImport->GetNlLists(); if ($xmlLists) { $xml = $model->xmltostring($xmlLists); var_dump($xml); if ($xml) { $count = 1; foreach ($xml->List as $list) { $groups = array(); foreach ($list->Groups->Group as $tmp) { $groups[(string) $tmp["idGroup"]] = array('idGroup' => (string) $tmp["idGroup"], 'groupName' => (string) $tmp["groupName"]); } $selectLists[$count] = array('value' => (string) $list['idList'], 'label' => (string) $list['listName'], 'guid' => (string) $list['listGUID'], "groups" => $groups); $count++; } } else { JError::raiseWarning(500, JText::_('COM_MAILUP_ERROR_IMPORTING_LISTS')); } } else { JError::raiseWarning(500, JText::_('COM_MAILUP_ERROR_IMPORTING_LISTS')); } $groups_to_delete = array(); $lists_to_delete = array(); foreach ($selectLists as $list) { $lists_to_delete[] = $list['value']; // SE LA LISTA CONTIENE GRUPPI LI INSERISCO NELLA TABELLA GRUPPI if (is_array($list['groups'])) { foreach ($list['groups'] as $group) { $groups_to_delete[] = $group['idGroup']; $result_group = $model->selectGroups($group['idGroup']); if ($result_group == 0) { $model->insertGroup($group['groupName'], $list['value'], $group['idGroup']); } else { $model->updateGroup($group['groupName'], $list['value'], $group['idGroup']); } } } $result_list = $model->selectLists($list['value']); if ($result_list == 0) { $model->insertList($list['label'], $list['value'], $list['guid']); } else { $model->updateList($list['label'], $list['value']); } } // ELIMINO LE LISTE E I GRUPPI NON PRESENTI NELL'ARRAY PERCHE' NON ESISTONO PIÙ SU MAILUP $lists_to_delete = implode(",", $lists_to_delete); $groups_to_delete = implode(",", $groups_to_delete); $model->deleteListsGroups($lists_to_delete, $groups_to_delete); $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); }
public function saveAction() { try { $post = $this->getRequest()->getPost(); unset($post["form_key"]); require_once dirname(__FILE__) . "/../../Model/MailUpWsImport.php"; $wsImport = new MailUpWsImport(); $wsImport->saveFieldMapping($post); } catch (Exception $e) { $errorMessage = $this->__('Error: unable to save current filter'); Mage::getSingleton('adminhtml/session')->addError($errorMessage); } $observer = Mage::getModel("mailup/observer"); $observer->configCheck(); $this->_redirect('*/*'); }
/** * Show Current Processes */ public function processesAction() { require_once dirname(dirname(__FILE__)) . "/Model/MailUpWsImport.php"; require_once dirname(dirname(__FILE__)) . "/Model/Wssend.php"; $wsimport = new MailUpWsImport(); var_dump($wsimport->getProcessDetail(array())); }
/** * Get an array of all lists, and their groups! * * @param string $storeId * @return array */ public function getDataArray($storeId) { $selectLists = array(); // If cache is set, use that if (isset($this->_cache[$storeId])) { return $this->_cache[$storeId]; } // If login details not set, return empty list if (!$this->_config()->getUrlConsole($storeId) || !$this->_config()->getUsername($storeId) || !$this->_config()->getPassword($storeId)) { if (Mage::getStoreConfig('mailup_newsletter/mailup/enable_log', $storeId)) { Mage::log('Login details not complete - cannot retrieve lists'); } return $selectLists; } // Attempt login (return empty if fails) $wsSend = new MailUpWsSend($storeId); $accessKey = $wsSend->loginFromId(); if ($accessKey === false) { if (Mage::getStoreConfig('mailup_newsletter/mailup/enable_log', $storeId)) { Mage::log('Login failed - cannot retrieve lists'); } return $selectLists; } // Attempt to make call to get lists from API require_once dirname(__DIR__) . "/MailUpWsImport.php"; $wsImport = new MailUpWsImport($storeId); $xmlString = $wsImport->GetNlList(); if (!$xmlString) { if (Mage::getStoreConfig('mailup_newsletter/mailup/enable_log', $storeId)) { Mage::log('MailUpWsImport got empty response when fetching lists even though login succeeded'); } return $selectLists; } // Try to decode response. If <Lists> is not in selection, then return $xmlString = html_entity_decode($xmlString); $startLists = strpos($xmlString, '<Lists>'); // On XML error, $startLists will fail if ($startLists === false) { if (Mage::getStoreConfig('mailup_newsletter/mailup/enable_log', $storeId)) { Mage::log('MailUpWsImport got error response when fetching lists'); } return $selectLists; } // Extract lists and their groups from <List> section of response $endPos = strpos($xmlString, '</Lists>'); $endLists = $endPos + strlen('</Lists>') - $startLists; $xmlLists = substr($xmlString, $startLists, $endLists); $xmlLists = str_replace("&", "&", $xmlLists); $xml = simplexml_load_string($xmlLists); foreach ($xml->List as $list) { $groups = array(); foreach ($list->Groups->Group as $tmp) { $groups[(string) $tmp["idGroup"]] = (string) $tmp["groupName"]; } $selectLists[(string) $list['idList']] = array('idList' => (string) $list['idList'], 'listName' => (string) $list['listName'], 'listGUID' => (string) $list['listGUID'], "groups" => $groups); } // Cache results as this is a success $this->_cache[$storeId] = $selectLists; return $selectLists; }
/** * Delete a Filter Hint */ public function deleteFilterHintAction() { $this->checkRunningImport(); try { $post = $this->getRequest()->getPost(); $MailUpWsImport = Mage::getModel('mailup/ws'); $wsImport = new MailUpWsImport(); $wsImport->deleteFilterHint($post['filter_name']); } catch (Exception $e) { $errorMessage = $this->__('Error: unable to delete the filter'); Mage::getSingleton('adminhtml/session')->addError($errorMessage); } $this->_redirect('*/*'); }
/** * Get ListGuid (Alphanumeric code associated to a distribution list) for given list * * @param $listId * @return false|string */ public function getListGuid($listId) { $wsImport = new MailUpWsImport(); $xmlString = $wsImport->GetNlList(); if (!$xmlString) { return $this; } $xmlString = html_entity_decode($xmlString); $startLists = strpos($xmlString, '<Lists>'); $endPos = strpos($xmlString, '</Lists>'); $endLists = $endPos + strlen('</Lists>') - $startLists; $xmlLists = substr($xmlString, $startLists, $endLists); $xmlLists = str_replace("&", "&", $xmlLists); $xml = simplexml_load_string($xmlLists); $listGUID = false; foreach ($xml->List as $list) { if ($list['idList'] == $listId) { $listGUID = $list["listGUID"]; break; } } return $listGUID; }
/** * Config Check * * @return type */ public function configCheck() { $url_console = Mage::getStoreConfig('mailup_newsletter/mailup/url_console'); $user = Mage::getStoreConfig('mailup_newsletter/mailup/username_ws'); $password = Mage::getStoreConfig('mailup_newsletter/mailup/password_ws'); $list = Mage::getStoreConfig('mailup_newsletter/mailup/list'); if (!strlen($url_console) or !strlen($user) or !strlen($password) or !strlen($list)) { $url = Mage::getModel('adminhtml/url'); $url = $url->getUrl("mailup/adminhtml_configuration"); $message = Mage::helper("mailup")->__('MailUp configuration is not complete'); $message = str_replace("href=''", "href='{$url}'", $message); Mage::getSingleton('adminhtml/session')->addWarning($message); return; } $wsimport = new MailUpWsImport(); $mapping = $wsimport->getFieldsMapping(); if (empty($mapping)) { $url = Mage::getModel('adminhtml/url'); $url = $url->getUrl("mailup/adminhtml_configuration"); $message = Mage::helper("mailup")->__('MailUp fields mapping is not complete'); $message = str_replace("href=''", "href='{$url}'", $message); Mage::getSingleton('adminhtml/session')->addWarning($message); return; } }