/**
  * Do the migration.
  *
  * @param DataContainer $dc
  */
 public function onsubmit_callback(DataContainer $dc)
 {
     $sourceIds = array_filter(array_map('intval', $dc->getData('source')));
     $usePersonals = $dc->getData('personals') ? true : false;
     $force = $dc->getData('force') ? true : false;
     if (count($sourceIds)) {
         $source = implode(',', $sourceIds);
         $insertPersonals = '';
         $selectPersonals = '';
         if ($usePersonals) {
             $this->loadDataContainer('orm_avisota_recipient');
             $this->loadDataContainer('tl_member');
             foreach ($GLOBALS['TL_DCA']['orm_avisota_recipient']['fields'] as $fieldName => $fieldConfig) {
                 if (!in_array($fieldName, array('pid', 'tstamp', 'email', 'confirmed', 'addedOn', 'addedBy', 'token')) && isset($fieldConfig['eval']['importable']) && $fieldConfig['eval']['importable'] && isset($GLOBALS['TL_DCA']['tl_member']['fields'][$fieldName])) {
                     $insertPersonals .= ',' . $fieldName;
                     $selectPersonals .= ',IFNULL(m.' . $fieldName . ', "")';
                 }
             }
         }
         $stmt = \Database::getInstance()->prepare("INSERT INTO\n\t\t\t\t\t\torm_avisota_recipient (pid,tstamp,email" . $insertPersonals . ",confirmed,addedOn,addedBy,token)\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t?,r.tstamp,r.email" . $selectPersonals . ",r.active,?,?,r.token\n\t\t\t\t\tFROM\n\t\t\t\t\t\ttl_newsletter_recipients r\n\t\t\t\t\t" . ($usePersonals ? "\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\ttl_member m\n\t\t\t\t\tON\n\t\t\t\t\t\tr.email = m.email\n\t\t\t\t\t" : "") . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tr.pid IN ({$source})\n\t\t\t\t\tAND\n\t\t\t\t\t\tr.email NOT IN (SELECT email FROM orm_avisota_recipient WHERE pid=?)\n\t\t\t\t\t" . ($force ? "" : "\n\t\t\t\t\tAND\n\t\t\t\t\t\tMD5(r.email) NOT IN (SELECT email FROM orm_avisota_recipient_blacklist WHERE pid=?)\n\t\t\t\t\t"))->execute($this->Input->get('id'), time(), $this->User->id, $this->Input->get('id'), $this->Input->get('id'));
         $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['orm_avisota_recipient_migrate']['migrated'], $stmt->affectedRows);
         if ($force) {
             \Database::getInstance()->prepare("DELETE FROM\n\t\t\t\t\t\t\torm_avisota_recipient_blacklist\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tpid=?\n\t\t\t\t\t\tAND\n\t\t\t\t\t\t\temail IN (SELECT MD5(email) FROM orm_avisota_recipient WHERE pid=?)")->execute($this->Input->get('id'), $this->Input->get('id'));
         }
     }
     setcookie('BE_PAGE_OFFSET', 0, 0, '/');
     $this->reload();
 }
 public function getSourceColumnNames(DataContainer $objDC)
 {
     $arrFields = array();
     if ($objDC->getCurrentModel() && $this->Database->tableExists($objDC->getCurrentModel()->getProperty('select_srctable'))) {
         foreach ($this->Database->listFields($objDC->getCurrentModel()->getProperty('select_srctable')) as $arrInfo) {
             if ($arrInfo['type'] != 'index') {
                 $arrFields[$arrInfo['name']] = $arrInfo['name'];
             }
         }
     }
     return $arrFields;
 }
 /**
  * Onload callback for tl_content
  *
  * Add language field to all content palettes
  *
  * @param DataContainer $dc
  */
 public function appendGridComponents(DataContainer $dc = null)
 {
     $dc->loadDataContainer('tl_page');
     $dc->loadDataContainer('tl_content');
     // add grid to all palettes
     foreach ($GLOBALS['TL_DCA']['tl_content']['palettes'] as $key => $value) {
         // if element is '__selector__' OR 'default' OR the palette has already a language key
         if ($key == '__selector__' || $key == 'default' || strpos($value, ',grid(?=\\{|,|;|$)') !== false) {
             continue;
         }
         $GLOBALS['TL_DCA']['tl_content']['palettes'][$key] = $value . ';{grid_legend:hide},grid_xs,grid_sm,grid_md,grid_lg,grid_visible,grid_hidden,col_no_padding,col_centered,col_newline;{grid_order_legend:hide},pull_xs,pull_sm,pull_md,pull_lg,push_xs,push_sm,push_md,push_lg,offset_xs,offset_sm,offset_md,offset_lg';
     }
 }
 /**
  * @param \DataContainer $objDC
  * @return \DataContainer
  */
 public static function translateDCObject(\DataContainer $objDC)
 {
     // Get table
     $strTable = $objDC->current()->getTable();
     // Load current data container
     $objTranslationController = new \TranslationController();
     $objTranslationController->loadDataContainer($strTable);
     if (count($GLOBALS['TL_DCA'][$strTable]['fields']) > 0) {
         foreach ($GLOBALS['TL_DCA'][$strTable]['fields'] as $field => $arrValues) {
             $objDC->{$field} = self::translateField($arrValues['inputType'], $objDC->{$field});
         }
     }
     return $objDC;
 }
Ejemplo n.º 5
0
 /**
  * Onload callback for tl_content
  *
  * Add language field to all content palettes
  *
  * @param DataContainer $dc
  */
 public function appendLanguageInput(DataContainer $dc = null)
 {
     $this->loadLanguageFile('tl_content');
     $dc->loadDataContainer('tl_page');
     $dc->loadDataContainer('tl_content');
     // add language section to all palettes
     foreach ($GLOBALS['TL_DCA']['tl_content']['palettes'] as $key => $value) {
         // if element is '__selector__' OR 'default' OR the palette has already a language key
         if ($key == '__selector__' || $key == 'default' || strpos($value, ',language(?=\\{|,|;|$)') !== false) {
             continue;
         }
         $GLOBALS['TL_DCA']['tl_content']['palettes'][$key] = $value . ';{i18nl10n_legend:hide},language';
     }
 }
 /**
  *
  *
  * @param DataContainer $dc
  */
 public function onsubmit_callback(DataContainer $dc)
 {
     $categoryId = $dc->getData('category');
     $subject = $dc->getData('subject');
     $draftId = $dc->getData('draft');
     $newsletterDraft = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_message_draft WHERE id=?")->execute($draftId);
     if ($newsletterDraft->next()) {
         $newsletterDraftData = $newsletterDraft->row();
         // remove unwanted fields
         unset($newsletterDraftData['id'], $newsletterDraftData['tstamp'], $newsletterDraftData['title'], $newsletterDraftData['description'], $newsletterDraftData['alias']);
         // set pid
         $newsletterDraftData['pid'] = $categoryId;
         // set subject
         $newsletterDraftData['subject'] = $subject;
         // call hook
         // TODO AvisotaHelper::callHook('prepareNewsletterCreateFromDraft', array(&$arrRow));
         $value = '';
         for ($i = 0; $i < count($newsletterDraftData); $i++) {
             if ($i > 0) {
                 $value .= ',';
             }
             $value .= '?';
         }
         $newsletter = \Database::getInstance()->prepare("INSERT INTO orm_avisota_message (" . implode(",", array_keys($newsletterDraftData)) . ") VALUES ({$value})")->execute($newsletterDraftData);
         $newsletterId = $newsletter->insertId;
         $content = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_message_draft_content WHERE pid=?")->execute($draftId);
         while ($content->next()) {
             $newsletterDraftData = $content->row();
             // remove unwanted fields
             unset($newsletterDraftData['id'], $newsletterDraftData['tstamp']);
             // set pid
             $newsletterDraftData['pid'] = $newsletterId;
             // call hook
             // TODO AvisotaHelper::callHook('prepareNewsletterContentCreateFromDraft', array(&$arrRow));
             // prevent pid changing
             $newsletterDraftData['pid'] = $newsletterId;
             $value = '';
             for ($i = 0; $i < count($newsletterDraftData); $i++) {
                 if ($i > 0) {
                     $value .= ',';
                 }
                 $value .= '?';
             }
             $newsletter = \Database::getInstance()->prepare("INSERT INTO orm_avisota_message_content (" . implode(",", array_keys($newsletterDraftData)) . ") VALUES ({$value})")->execute($newsletterDraftData);
         }
         $_SESSION['TL_INFO'][] = $GLOBALS['TL_LANG']['orm_avisota_message_create_from_draft']['created'];
         $this->redirect('contao/main.php?do=avisota_newsletter&table=orm_avisota_message_content&id=' . $newsletterId);
     }
 }
 public function __construct($strTable, $arrModule = array())
 {
     parent::__construct();
     // Check the request token (see #4007)
     if (isset($_GET['act'])) {
         if (!isset($_GET['rt']) || !\RequestToken::validate(\Input::get('rt'))) {
             $this->Session->set('INVALID_TOKEN_URL', \Environment::get('request'));
             $this->redirect('contao/confirm.php');
         }
     }
     $this->intId = \Input::get('id');
     // Check whether the table is defined
     if (!$strTable || !isset($GLOBALS['TL_DCA'][$strTable])) {
         $this->log('Could not load the data container configuration for "' . $strTable . '"', 'DC_Table __construct()', TL_ERROR);
         trigger_error('Could not load the data container configuration', E_USER_ERROR);
     }
     $this->strTable = $strTable;
     $this->arrModule = $arrModule;
     // Call onload_callback (e.g. to check permissions)
     if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onload_callback'])) {
         foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onload_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $this->{$callback[0]}->{$callback[1]}($this);
             }
         }
     }
 }
Ejemplo n.º 8
0
	/**
	 * Initialize the object
	 * @param string
	 */
	public function __construct($strTable)
	{
		parent::__construct();
		$this->intId = $this->Input->get('id');

		// Check whether the table is defined
		if ($strTable == '' || !isset($GLOBALS['TL_DCA'][$strTable])) 
		{
			$this->log('Could not load data container configuration for "' . $strTable . '"', 'DC_File __construct()', TL_ERROR);
			trigger_error('Could not load data container configuration', E_USER_ERROR);
		}

		// Build object from global configuration array
		$this->strTable = $strTable;

		// Call onload_callback (e.g. to check permissions)
		if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onload_callback']))
		{
			foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onload_callback'] as $callback)
			{
				if (is_array($callback))
				{
					$this->import($callback[0]);
					$this->$callback[0]->$callback[1]($this);
				}
			}
		}
	}
Ejemplo n.º 9
0
 /**
  * Array mit Options
  * @return <type> Array
  */
 public function getCL(DataContainer $dc)
 {
     $elements = array();
     $objDC = $this->Database->prepare("SELECT id,pid,name,label FROM tl_form_field WHERE type=?")->execute('xdependentcalendarfields');
     $elements['none'] = $GLOBALS['TL_LANG']['tl_form_field']['xdependstart'];
     while ($objDC->next()) {
         //Formularname auslesen
         $objFN = $this->Database->prepare("SELECT title FROM tl_form WHERE id=?")->execute($objDC->pid);
         $ergobjFN = $objFN->fetchAssoc();
         if ($objDC->id != $dc->__get('id')) {
             if ($objDC->name != "") {
                 $elements[$ergobjFN['title']][$objDC->id] = $objDC->label;
             }
         }
     }
     return $elements;
 }
 /**
  * Do the import.
  *
  * @param DataContainer $dc
  */
 public function onsubmit_callback(DataContainer $dc)
 {
     $recipientId = $dc->getData('recipient');
     if ($recipientId != $this->Input->get('id')) {
         $this->redirect('contao/main.php?do=avisota_recipient&amp;table=orm_avisota_recipient_notify&amp;act=edit&amp;id=' . $recipientId);
     }
     $confirmations = $dc->getData('confirmations');
     $notifications = $dc->getData('notifications');
     $overdue = $dc->getData('overdue');
     $recipient = new AvisotaIntegratedRecipient(array('id' => $recipientId));
     $recipient->load();
     if (is_array($confirmations) && count($confirmations)) {
         $recipient->sendSubscriptionConfirmation($confirmations);
     }
     if (is_array($notifications) && count($notifications)) {
         $recipient->sendRemind($notifications, true);
     }
     if (is_array($overdue) && count($overdue)) {
         $recipient->sendRemind($overdue, true);
     }
 }
 /**
  * Do the import.
  *
  * @param DataContainer $dc
  */
 public function onsubmit_callback(DataContainer $dc)
 {
     $source = $dc->getData('source');
     $upload = $dc->getData('upload');
     $emails = $dc->getData('emails');
     $totalCount = 0;
     if (is_array($source)) {
         foreach ($source as $csvFile) {
             $file = new File($csvFile);
             $this->removeRecipients($file->getContent(), $totalCount);
         }
     }
     if ($upload) {
         $this->removeRecipients(file_get_contents($upload['tmp_name']), $totalCount);
     }
     if ($emails) {
         $this->removeRecipients($emails, $totalCount);
     }
     $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['orm_avisota_recipient_remove']['confirm'], $totalCount);
     setcookie('BE_PAGE_OFFSET', 0, 0, '/');
     $this->reload();
 }
Ejemplo n.º 12
0
 public function saveTagsFromDefaults(\DataContainer $dc)
 {
     $arrDefaults = $dc->getDefaults();
     $arrDca = $dc->getDca();
     if (empty($arrDefaults)) {
         return false;
     }
     foreach ($arrDefaults as $strField => $varDefault) {
         $arrData = $arrDca['fields'][$strField];
         if (!is_array($arrData) || $arrData['inputType'] != 'tag') {
             continue;
         }
         $arrValues = trimsplit(',', $varDefault);
         $blnTag = false;
         if (!is_array($arrValues) || empty($arrValues)) {
             $blnTag = false;
         } else {
             $objTags = TagModel::findByIdAndTable($dc->activeRecord->id, $dc->table);
             $arrSavedTags = array();
             if ($objTags !== null) {
                 $arrSavedTags = $objTags->fetchEach('tag');
                 $blnTag = true;
             }
             $arrNewTags = array_diff($arrValues, $arrSavedTags);
             if (is_array($arrNewTags) && !empty($arrNewTags)) {
                 $blnTag = true;
                 foreach ($arrNewTags as $strTag) {
                     $objModel = new TagModel();
                     $objModel->tag = $strTag;
                     $objModel->from_table = $dc->table;
                     $objModel->tid = $dc->activeRecord->id;
                     $objModel->save();
                 }
             }
         }
         $dc->activeRecord->{$strField} = $blnTag;
         $dc->activeRecord->save();
     }
 }
 public function generate()
 {
     if (TL_MODE == 'BE') {
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### FRONTENDEDIT FORM VALIDATOR ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;
         return $objTemplate->parse();
     }
     \DataContainer::loadDataContainer($this->formHybridDataContainer);
     \System::loadLanguageFile($this->formHybridDataContainer);
     $this->noIdBehavior = 'redirect';
     return parent::generate();
 }
 public function generate()
 {
     if (TL_MODE == 'BE') {
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### FORMHYBRID READER ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;
         return $objTemplate->parse();
     }
     \DataContainer::loadDataContainer($this->formHybridDataContainer);
     \System::loadLanguageFile($this->formHybridDataContainer);
     $this->strWrapperId .= $this->id;
     $this->dca = $GLOBALS['TL_DCA'][$this->formHybridDataContainer];
     // Set the item from the auto_item parameter
     if (!isset($_GET['items']) && \Config::get('useAutoItem') && isset($_GET['auto_item'])) {
         \Input::setGet('items', \Input::get('auto_item'));
     }
     $this->intId = $this->intId ?: (\Input::get('items') ?: \Input::get('id'));
     if ($this->addExistanceConditions) {
         $arrConditions = deserialize($this->existanceConditions, true);
         $strItemClass = \Model::getClassFromTable($this->formHybridDataContainer);
         if (!empty($arrConditions)) {
             $arrColumns = array();
             $arrValues = array();
             foreach ($arrConditions as $arrCondition) {
                 $arrColumns[] = $arrCondition['field'] . '=?';
                 $arrValues[] = $this->replaceInsertTags($arrCondition['value']);
             }
             if (($objItem = $strItemClass::findOneBy($arrColumns, $arrValues)) !== null) {
                 $this->intId = $objItem->id;
             }
         }
     }
     // Do not index or cache the page if no item has been specified
     if (!$this->intId) {
         /** @var \PageModel $objPage */
         global $objPage;
         $objPage->noSearch = 1;
         $objPage->cache = 0;
     }
     return parent::generate();
 }
 public function generate()
 {
     if (TL_MODE == 'BE') {
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### FORMHYBRID LIST ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;
         return $objTemplate->parse();
     }
     \DataContainer::loadDataContainer($this->formHybridDataContainer);
     \System::loadLanguageFile($this->formHybridDataContainer);
     $this->dca = $GLOBALS['TL_DCA'][$this->formHybridDataContainer];
     $this->strWrapperId .= $this->id;
     $this->strTemplate = $this->customTpl ?: ($this->strTemplate ?: ($this->isTableList ? 'mod_formhybrid_list_table' : 'mod_formhybrid_list'));
     $this->itemTemplate = $this->itemTemplate ?: ($this->isTableList ? 'formhybrid_list_item_table_default' : 'formhybrid_list_item_default');
     return parent::generate();
 }
Ejemplo n.º 16
0
 /**
  * Return an object property
  *
  * @param string $strKey
  *
  * @return mixed
  */
 public function __get($strKey)
 {
     switch ($strKey) {
         case 'path':
             return $this->strPath;
             break;
         case 'extension':
             return $this->strExtension;
             break;
         case 'createNewVersion':
             return $this->blnCreateNewVersion;
             break;
         case 'isDbAssisted':
             return $this->blnIsDbAssisted;
             break;
     }
     return parent::__get($strKey);
 }
Ejemplo n.º 17
0
 /**
  * Import the back end user object
  */
 public function __construct()
 {
     parent::__construct();
     $this->import('BackendUser', 'User');
 }
Ejemplo n.º 18
0
 /**
  * Retrieves all view data from the view and the viewManager
  *
  * @return array
  */
 public function getData()
 {
     $data = parent::getData();
     $global = $this->viewManager->getData();
     return array_merge($global, $data);
 }
Ejemplo n.º 19
0
 /**
  * Return an object property
  * @param string
  * @return mixed
  */
 public function __get($strKey)
 {
     switch ($strKey) {
         case 'path':
             return $this->strPath;
             break;
         case 'extension':
             return $this->strExtension;
             break;
         default:
             return parent::__get($strKey);
             break;
     }
 }
Ejemplo n.º 20
0
 public function __construct($strTable, array &$arrDCA = null, $blnOnloadCallback = true)
 {
     // Set start timer
     $this->intTimerStart = microtime(true);
     $this->intQueryCount = count($GLOBALS['TL_DEBUG']);
     // Call parent
     parent::__construct();
     // Callback
     $strTable = $this->getTablenameCallback($strTable);
     // Basic vars Init
     $this->strTable = $strTable;
     // in contao 3 the second constructor parameter is the backend module array.
     // Therefore we have to check if the passed argument is indeed a valid DCA.
     if ($arrDCA != null && $arrDCA['config']) {
         $this->arrDCA = $arrDCA;
     } else {
         $this->arrDCA =& $GLOBALS['TL_DCA'][$this->strTable];
     }
     // Check whether the table is defined
     if (!strlen($this->strTable) || !count($this->arrDCA)) {
         $this->log('Could not load data container configuration for "' . $strTable . '"', 'DC_Table __construct()', TL_ERROR);
         trigger_error('Could not load data container configuration', E_USER_ERROR);
     }
     // Import
     $this->import('Encryption');
     // Switch user for FE / BE support
     switch (TL_MODE) {
         case 'FE':
             $this->import('FrontendUser', 'User');
             break;
         default:
         case 'BE':
             $this->import('BackendUser', 'User');
             break;
     }
     // Load
     $this->checkPostGet();
     $this->loadProviderAndHandler();
     // Check for forcemode
     if ($this->arrDCA['config']['forceEdit']) {
         $this->blnForceEdit = true;
         $this->intId = 1;
     }
     // SH: We need the buttons here, because the onloadCallback is (the only) one
     // to remove buttons.
     $this->loadDefaultButtons();
     // Callback
     if ($blnOnloadCallback == true) {
         $this->objCallbackClass->onloadCallback($strTable);
     }
     // execute AJAX request, called from Backend::getBackendModule
     // we have to do this here, as otherwise the script will exit as it only checks for DC_Table and DC_File decendant classes. :/
     if ($_POST && $this->Environment->isAjaxRequest) {
         $this->getControllerHandler()->executePostActions();
     }
 }
Ejemplo n.º 21
0
 /**
  * 
  * @param \ifirma\DataContainer $container
  * @param array $keysToFilter
  * @return array
  */
 public static function filterSupportedKeys(DataContainer $container, $keysToFilter)
 {
     return array_filter($keysToFilter, function ($value) use($container) {
         return in_array($value, $container->getSupportedKeys());
     });
 }
Ejemplo n.º 22
0
 /**
  * Ajax actions that do require a data container object
  * @param object
  */
 public function executePostActions(DataContainer $dc)
 {
     header('Content-Type: text/html; charset=' . $GLOBALS['TL_CONFIG']['characterSet']);
     switch ($this->strAction) {
         // Load nodes of the page structure tree
         case 'loadStructure':
             echo json_encode(array('content' => $dc->ajaxTreeView($this->strAjaxId, intval($this->Input->post('level'))), 'token' => REQUEST_TOKEN));
             exit;
             break;
             // Load nodes of the file manager tree
         // Load nodes of the file manager tree
         case 'loadFileManager':
             echo json_encode(array('content' => $dc->ajaxTreeView($this->Input->post('folder', true), intval($this->Input->post('level'))), 'token' => REQUEST_TOKEN));
             exit;
             break;
             // Load nodes of the page tree
         // Load nodes of the page tree
         case 'loadPagetree':
             $arrData['strTable'] = $dc->table;
             $arrData['id'] = strlen($this->strAjaxName) ? $this->strAjaxName : $dc->id;
             $arrData['name'] = $this->Input->post('name');
             $objWidget = new $GLOBALS['BE_FFL']['pageTree']($arrData, $dc);
             echo json_encode(array('content' => $objWidget->generateAjax($this->strAjaxId, $this->Input->post('field'), intval($this->Input->post('level'))), 'token' => REQUEST_TOKEN));
             exit;
             break;
             // Load nodes of the file tree
         // Load nodes of the file tree
         case 'loadFiletree':
             $arrData['strTable'] = $dc->table;
             $arrData['id'] = strlen($this->strAjaxName) ? $this->strAjaxName : $dc->id;
             $arrData['name'] = $this->Input->post('name');
             $objWidget = new $GLOBALS['BE_FFL']['fileTree']($arrData, $dc);
             // Load a particular node
             if ($this->Input->post('folder', true) != '') {
                 echo json_encode(array('content' => $objWidget->generateAjax($this->Input->post('folder', true), $this->Input->post('field'), intval($this->Input->post('level'))), 'token' => REQUEST_TOKEN));
                 exit;
                 break;
             }
             // Reload the whole tree
             $this->import('BackendUser', 'User');
             $tree = '';
             // Set a custom path
             if (strlen($GLOBALS['TL_DCA'][$dc->table]['fields'][$this->Input->post('field')]['eval']['path'])) {
                 $tree = $objWidget->generateAjax($GLOBALS['TL_DCA'][$dc->table]['fields'][$this->Input->post('field')]['eval']['path'], $this->Input->post('field'), intval($this->Input->post('level')));
             } elseif ($this->User->isAdmin) {
                 $tree = $objWidget->generateAjax($GLOBALS['TL_CONFIG']['uploadPath'], $this->Input->post('field'), intval($this->Input->post('level')));
             } else {
                 foreach ($this->eliminateNestedPaths($this->User->filemounts) as $node) {
                     $tree .= $objWidget->generateAjax($node, $this->Input->post('field'), intval($this->Input->post('level')), true);
                 }
             }
             echo json_encode(array('content' => $tree, 'token' => REQUEST_TOKEN));
             exit;
             break;
             // Upload files via FancyUpload
         // Upload files via FancyUpload
         case 'fancyUpload':
             $dc->move(true);
             exit;
             break;
             // Feature/unfeature an element
         // Feature/unfeature an element
         case 'toggleFeatured':
             if (class_exists($dc->table, false)) {
                 $dca = new $dc->table();
                 if (method_exists($dca, 'toggleFeatured')) {
                     $dca->toggleFeatured($this->Input->post('id'), $this->Input->post('state') == 1 ? true : false);
                 }
             }
             echo json_encode(array('token' => REQUEST_TOKEN));
             exit;
             break;
             // Toggle subpalettes
         // Toggle subpalettes
         case 'toggleSubpalette':
             if ($dc instanceof DC_Table) {
                 if ($this->Input->get('act') == 'editAll') {
                     $this->strAjaxId = preg_replace('/.*_([0-9a-zA-Z]+)$/i', '$1', $this->Input->post('id'));
                     $this->Database->prepare("UPDATE " . $dc->table . " SET " . $this->Input->post('field') . "='" . (intval($this->Input->post('state') == 1) ? 1 : '') . "' WHERE id=?")->execute($this->strAjaxId);
                     if ($this->Input->post('load')) {
                         echo json_encode(array('content' => $dc->editAll($this->strAjaxId, $this->Input->post('id')), 'token' => REQUEST_TOKEN));
                         exit;
                         break;
                     }
                 } else {
                     $this->Database->prepare("UPDATE " . $dc->table . " SET " . $this->Input->post('field') . "='" . (intval($this->Input->post('state') == 1) ? 1 : '') . "' WHERE id=?")->execute($dc->id);
                     if ($this->Input->post('load')) {
                         echo json_encode(array('content' => $dc->edit(false, $this->Input->post('id')), 'token' => REQUEST_TOKEN));
                         exit;
                         break;
                     }
                 }
             } elseif ($dc instanceof DC_File) {
                 $val = intval($this->Input->post('state') == 1) ? true : false;
                 $this->Config->update("\$GLOBALS['TL_CONFIG']['" . $this->Input->post('field') . "']", $val);
                 if ($this->Input->post('load')) {
                     $GLOBALS['TL_CONFIG'][$this->Input->post('field')] = $val;
                     echo json_encode(array('content' => $dc->edit(false, $this->Input->post('id')), 'token' => REQUEST_TOKEN));
                     exit;
                     break;
                 }
             }
             echo json_encode(array('token' => REQUEST_TOKEN));
             exit;
             break;
             // HOOK: pass unknown actions to callback functions
         // HOOK: pass unknown actions to callback functions
         default:
             if (isset($GLOBALS['TL_HOOKS']['executePostActions']) && is_array($GLOBALS['TL_HOOKS']['executePostActions'])) {
                 foreach ($GLOBALS['TL_HOOKS']['executePostActions'] as $callback) {
                     $this->import($callback[0]);
                     $this->{$callback}[0]->{$callback}[1]($this->strAction, $dc);
                 }
             }
             echo json_encode(array('token' => REQUEST_TOKEN));
             exit;
             break;
     }
 }
 /**
  * Do the export.
  *
  * @param DataContainer $dc
  */
 public function onsubmit_callback(DataContainer $dc)
 {
     // Get delimiter
     switch ($dc->getData('delimiter')) {
         case 'semicolon':
             $delimiter = ';';
             break;
         case 'tabulator':
             $delimiter = "\t";
             break;
         case 'linebreak':
             $delimiter = "\n";
             break;
         default:
             $delimiter = ',';
             break;
     }
     // Get enclosure
     switch ($dc->getData('enclosure')) {
         case 'single':
             $enclosure = '\'';
             break;
         default:
             $enclosure = '"';
             break;
     }
     // Get fields
     $fields = $dc->getData('fields');
     // Get field labels
     $labels = array();
     foreach ($fields as $field) {
         switch ($field) {
             default:
                 $fieldConfig = $GLOBALS['TL_DCA']['orm_avisota_recipient']['fields'][$field];
                 if (empty($fieldConfig['label'][0])) {
                     $labels[] = $field;
                 } else {
                     $labels[] = $fieldConfig['label'][0] . ' [' . $field . ']';
                 }
                 break;
         }
     }
     $this->Session->set('AVISOTA_EXPORT', array('delimiter' => $dc->getData('delimiter'), 'enclosure' => $dc->getData('enclosure'), 'fields' => $dc->getData('fields')));
     // search for the list
     $list = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_mailing_list WHERE id=?")->execute($this->Input->get('id'));
     if (!$list->next()) {
         $this->log('The recipient list ID ' . $this->Input->get('id') . ' does not exists!', 'orm_avisota_recipient_export', TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     // create temporary file
     $temporaryPathname = substr(tempnam(TL_ROOT . '/system/tmp', 'recipients_export_') . '.csv', strlen(TL_ROOT) + 1);
     // create new file object
     $temporaryFile = new File($temporaryPathname);
     // open file handle
     $temporaryFile->write('');
     // write the headline
     fputcsv($temporaryFile->handle, $labels, $delimiter, $enclosure);
     // write recipient rows
     $recipient = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_recipient WHERE pid=?")->execute($this->Input->get('id'));
     while ($recipient->next()) {
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 default:
                     $row[] = $recipient->{$field};
             }
         }
         fputcsv($temporaryFile->handle, $row, $delimiter, $enclosure);
     }
     // close file handle
     $temporaryFile->close();
     // create temporary zip file
     $zipFile = $temporaryPathname . '.zip';
     // create a zip writer
     $zip = new ZipWriter($zipFile);
     // add the temporary csv
     $zip->addFile($temporaryPathname, $list->title . '.csv');
     // close the zip
     $zip->close();
     // create new file object
     $zip = new File($zipFile);
     // Open the "save as …" dialogue
     header('Content-Type: ' . $zip->mime);
     header('Content-Transfer-Encoding: binary');
     header('Content-Disposition: attachment; filename="' . $list->title . '.zip"');
     header('Content-Length: ' . $zip->filesize);
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Expires: 0');
     // send the zip file
     $resFile = fopen(TL_ROOT . '/' . $zipFile, 'rb');
     fpassthru($resFile);
     fclose($resFile);
     // delete temporary files
     $temporaryFile->delete();
     $zip->delete();
     exit;
 }
Ejemplo n.º 24
0
    /**
     * Return a checkbox to delete session data
     * @param object
     * @return string
     */
    public function sessionField(DataContainer $dc)
    {
        if ($this->Input->post('FORM_SUBMIT') == 'tl_user') {
            $arrPurge = $this->Input->post('purge');
            if (is_array($arrPurge)) {
                $this->import('Automator');
                if (in_array('purge_session', $arrPurge)) {
                    $this->Session->setData(array());
                    $_SESSION['TL_CONFIRM'][] = $GLOBALS['TL_LANG']['tl_user']['sessionPurged'];
                }
                if (in_array('purge_html', $arrPurge)) {
                    $this->Automator->purgeHtmlFolder();
                    $_SESSION['TL_CONFIRM'][] = $GLOBALS['TL_LANG']['tl_user']['htmlPurged'];
                }
                if (in_array('purge_temp', $arrPurge)) {
                    $this->Automator->purgeTempFolder();
                    $_SESSION['TL_CONFIRM'][] = $GLOBALS['TL_LANG']['tl_user']['tempPurged'];
                }
            }
        }
        return '
<div>
  <fieldset class="tl_checkbox_container">
    <legend>' . $GLOBALS['TL_LANG']['tl_user']['session'][0] . '</legend>
    <input type="checkbox" id="check_all_purge" class="tl_checkbox" onclick="Backend.toggleCheckboxGroup(this, \'ctrl_purge\')"> <label for="check_all_purge" style="color:#a6a6a6;"><em>' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</em></label><br>
    <input type="checkbox" name="purge[]" id="opt_purge_0" class="tl_checkbox" value="purge_session" onfocus="Backend.getScrollOffset();"> <label for="opt_purge_0">' . $GLOBALS['TL_LANG']['tl_user']['sessionLabel'] . '</label><br>
    <input type="checkbox" name="purge[]" id="opt_purge_1" class="tl_checkbox" value="purge_html" onfocus="Backend.getScrollOffset();"> <label for="opt_purge_1">' . $GLOBALS['TL_LANG']['tl_user']['htmlLabel'] . '</label><br>
    <input type="checkbox" name="purge[]" id="opt_purge_2" class="tl_checkbox" value="purge_temp" onfocus="Backend.getScrollOffset();"> <label for="opt_purge_2">' . $GLOBALS['TL_LANG']['tl_user']['tempLabel'] . '</label>
  </fieldset>' . $dc->help() . '
</div>';
    }
Ejemplo n.º 25
0
 /**
  * Return an object property
  *
  * @param string $strKey
  *
  * @return mixed
  */
 public function __get($strKey)
 {
     switch ($strKey) {
         case 'id':
             return $this->intId;
             break;
         case 'parentTable':
             return $this->ptable;
             break;
         case 'childTable':
             return $this->ctable;
             break;
         case 'rootIds':
             return $this->root;
             break;
         case 'createNewVersion':
             return $this->blnCreateNewVersion;
             break;
     }
     return parent::__get($strKey);
 }
Ejemplo n.º 26
0
 /**
  * Return an object property
  * @param string
  * @return mixed
  */
 public function __get($strKey)
 {
     switch ($strKey) {
         case 'id':
             return $this->intId;
             break;
         case 'parentTable':
             return $this->ptable;
             break;
         case 'childTable':
             return $this->ctable;
             break;
         case 'rootIds':
             return $this->root;
             break;
         case 'createNewVersion':
             return $this->blnCreateNewVersion;
             break;
         case 'strFormFilterValue':
             return $this->strFormFilterValue;
             break;
         case 'arrFieldConfig':
             return $this->arrFieldConfig;
             break;
         default:
             return parent::__get($strKey);
             break;
     }
 }
 /**
  * Do the import.
  *
  * @param DataContainer $dc
  */
 public function onsubmit_callback(DataContainer $dc)
 {
     $source = $dc->getData('source');
     $upload = $dc->getData('upload');
     // Get delimiter
     switch ($dc->getData('delimiter')) {
         case 'semicolon':
             $delimiter = ';';
             break;
         case 'tabulator':
             $delimiter = "\t";
             break;
         case 'linebreak':
             $delimiter = "\n";
             break;
         default:
             $delimiter = ',';
             break;
     }
     // Get enclosure
     switch ($dc->getData('enclosure')) {
         case 'single':
             $enclosure = '\'';
             break;
         default:
             $enclosure = '"';
             break;
     }
     // Get columns
     $rawColumns = $dc->getData('columns');
     $overwrite = $dc->getData('overwrite') ? true : false;
     $force = $dc->getData('force') ? true : false;
     $this->Session->set('AVISOTA_IMPORT', array('delimiter' => $dc->getData('delimiter'), 'enclosure' => $dc->getData('enclosure'), 'columns' => $dc->getData('columns')));
     if ($this->validateFieldSelectorArray($rawColumns)) {
         $columns = array();
         foreach ($rawColumns as $row) {
             $columns[$row['values']['colnum']] = $row['values']['field'];
         }
         $startTime = time();
         $totalCount = 0;
         $overwriteCount = 0;
         $skipCount = 0;
         $invalidCount = 0;
         if (is_array($source)) {
             foreach ($source as $csvFile) {
                 $file = new File($csvFile);
                 if ($file->extension != 'csv') {
                     $_SESSION['TL_ERROR'][] = sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $file->extension);
                     continue;
                 }
                 $this->importRecipients($file->handle, $delimiter, $enclosure, $columns, $overwrite, $force, $startTime, $totalCount, $overwriteCount, $skipCount, $invalidCount);
                 $file->close();
             }
         }
         if ($upload) {
             $resFile = fopen($upload['tmp_name'], 'r');
             $this->importRecipients($resFile, $delimiter, $enclosure, $columns, $overwrite, $force, $startTime, $totalCount, $overwriteCount, $skipCount, $invalidCount);
             fclose($resFile);
         }
         if ($totalCount > 0) {
             $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['orm_avisota_recipient_import']['confirmed'], $totalCount);
         }
         if ($overwriteCount > 0) {
             $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['orm_avisota_recipient_import']['overwritten'], $overwriteCount);
         }
         if ($skipCount > 0) {
             $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['orm_avisota_recipient_import']['skipped'], $skipCount);
         }
         if ($invalidCount > 0) {
             $_SESSION['TL_INFO'][] = sprintf($GLOBALS['TL_LANG']['orm_avisota_recipient_import']['invalid'], $invalidCount);
         }
     }
     setcookie('BE_PAGE_OFFSET', 0, 0, '/');
     $this->reload();
 }
Ejemplo n.º 28
0
 /**
  * @param \DataContainer $dc
  * @return array
  */
 protected function getParameters(\DataContainer $dc)
 {
     if (!$dc->activeRecord) {
         return array();
     }
     $dc->loadDataContainer($dc->table);
     $strType = $this->getType($dc);
     $arrParameters = array();
     $arrFields = $GLOBALS['TL_DCA'][$dc->table]['fields'];
     if (is_array($arrFields)) {
         foreach ($arrFields as $strField => $arrField) {
             if (isset($dc->activeRecord->{$strField})) {
                 $arrParameters[$strField] = $this->renderParameterValue($dc->table, $this->getAccountLanguage($dc), $strField, $dc->activeRecord->{$strField});
             }
         }
     }
     // Replace the password, because it's generated new
     $arrParameters['password'] = $this->getPostPassword($dc->id);
     // HOOK: replaceAccountMailParameters
     if (isset($GLOBALS['TL_HOOKS']['replaceAccountMailParameters']) && is_array($GLOBALS['TL_HOOKS']['replaceAccountMailParameters'])) {
         foreach ($GLOBALS['TL_HOOKS']['replaceAccountMailParameters'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $arrParameters = $this->{$callback}[0]->{$callback}[1]($strType, $arrParameters, $dc);
             } elseif (is_callable($callback)) {
                 $arrParameters = $callback($strType, $arrParameters, $dc);
             }
         }
     }
     return $arrParameters;
 }
Ejemplo n.º 29
0
    /**
     * Return a checkbox to delete session data
     *
     * @param DataContainer $dc
     *
     * @return string
     */
    public function sessionField(DataContainer $dc)
    {
        if (Input::post('FORM_SUBMIT') == 'tl_user') {
            $arrPurge = Input::post('purge');
            if (is_array($arrPurge)) {
                $this->import('Automator');
                if (in_array('purge_session', $arrPurge)) {
                    $this->Session->setData(array());
                    Message::addConfirmation($GLOBALS['TL_LANG']['tl_user']['sessionPurged']);
                }
                if (in_array('purge_images', $arrPurge)) {
                    $this->Automator->purgeImageCache();
                    Message::addConfirmation($GLOBALS['TL_LANG']['tl_user']['htmlPurged']);
                }
                if (in_array('purge_pages', $arrPurge)) {
                    $this->Automator->purgePageCache();
                    Message::addConfirmation($GLOBALS['TL_LANG']['tl_user']['tempPurged']);
                }
            }
        }
        return '
<div>
  <fieldset class="tl_checkbox_container">
    <legend>' . $GLOBALS['TL_LANG']['tl_user']['session'][0] . '</legend>
    <input type="checkbox" id="check_all_purge" class="tl_checkbox" onclick="Backend.toggleCheckboxGroup(this, \'ctrl_purge\')"> <label for="check_all_purge" style="color:#a6a6a6"><em>' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</em></label><br>
    <input type="checkbox" name="purge[]" id="opt_purge_0" class="tl_checkbox" value="purge_session" onfocus="Backend.getScrollOffset()"> <label for="opt_purge_0">' . $GLOBALS['TL_LANG']['tl_user']['sessionLabel'] . '</label><br>
    <input type="checkbox" name="purge[]" id="opt_purge_1" class="tl_checkbox" value="purge_images" onfocus="Backend.getScrollOffset()"> <label for="opt_purge_1">' . $GLOBALS['TL_LANG']['tl_user']['htmlLabel'] . '</label><br>
    <input type="checkbox" name="purge[]" id="opt_purge_2" class="tl_checkbox" value="purge_pages" onfocus="Backend.getScrollOffset()"> <label for="opt_purge_2">' . $GLOBALS['TL_LANG']['tl_user']['tempLabel'] . '</label>
  </fieldset>' . $dc->help() . '
</div>';
    }
Ejemplo n.º 30
0
 /**
  * Return an object property
  *
  * @param string
  *
  * @return mixed
  */
 public function __get($strKey)
 {
     // legacy: support 'formHybrid' prefix
     if (FormConfiguration::isLegacyKey($strKey)) {
         $strKey = FormConfiguration::getKey($strKey);
     }
     // parent getter must be dominant, otherwise intId will taken from arrData
     // tl_calendar_events::adjustTime callback make usage of $dc->id instead of $dc->activeRecord->id
     if (($strParent = parent::__get($strKey)) != '') {
         return $strParent;
     }
     switch ($strKey) {
         // Fallback for old formHybrid modules
         case 'objModel':
             return $this->objModule;
             break;
         default:
             if (isset($this->arrData[$strKey])) {
                 return $this->arrData[$strKey];
             }
     }
 }