e83d38e531bbde244cb01ea308bc8b8a0e0544fb
[TYPO3CMS/Extensions/powermailCond.git] / lib / class.tx_powermailcond_fields_be.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Alex Kellner <alexander.kellner@in2code.de>, in2code.
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Class/Function which manipulates the item-array for table/field tx_powermailcond_rules_fieldname.
27 *
28 * @author Alex Kellner <alexander.kellner@in2code.de>, in2code.
29 * @package TYPO3
30 * @subpackage tx_powermailcond_fields_be
31 */
32 class tx_powermailcond_fields_be {
33
34 /**
35 * show all fields in the backend
36 *
37 * @param array $params: Params
38 * @param object $pObj: Parent Object
39 * @return void
40 */
41 public function fieldname(&$params, $pObj) {
42 $where = '1';
43 if (isset($params['config']['itemsProcFuncValue'])) { // additional where clause
44 $where = 'formtype IN (' . $params['config']['itemsProcFuncValue'] . ')';
45 }
46 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
47 $select = 'uid, title',
48 $from = 'tx_powermail_fields',
49 $where .= ' AND pid = ' . intval($params['row']['pid']) . ' AND hidden = 0 AND deleted = 0',
50 $groupBy = '',
51 $orderBy = 'sorting',
52 $limit = ''
53 );
54 if ($res) {
55 $params['items'][] = array('powermail Fields', '--div--');
56 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
57 $params['items'][] = array($pObj->sL($row['title']) . ' (' . $row['uid'] . ')', $row['uid']);
58 }
59 }
60
61 if (isset($params['config']['itemsProcFunc_addFieldsets'])) { // add fieldsets to selection
62 $params['items'] = array_merge((array) $params['items'], $this->getFieldsets($params['row']['pid'])); // add some fieldsets
63 }
64 }
65
66 /**
67 * give me all fieldsets in an array
68 *
69 * @param integer $pid: Page ID
70 * @return array $arr: all fieldsets with its name and the fieldset uid
71 */
72 public function getFieldsets($pid) {
73 $arr = array();
74 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
75 $select = 'uid, title',
76 $from = 'tx_powermail_fieldsets',
77 $where .= 'pid = ' . intval($pid) . ' AND hidden = 0 AND deleted = 0',
78 $groupBy = '',
79 $orderBy = 'sorting',
80 $limit = ''
81 );
82 if ($res) {
83 $arr[] = array('powermail Fieldsets', '--div--');
84 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
85 $arr[] = array($row['title'] . ' (' . $row['uid'] . ')', 'fieldset:' . $row['uid']);
86 }
87 }
88 return $arr;
89 }
90
91 /**
92 * List values of a powermail selectorbox
93 *
94 * @param array $params: Params
95 * @param object $pObj: Parent Object
96 * @return void
97 */
98 public function valuesFromPowermailSelectbox(&$params, $pObj) {
99 // Get targetField UID
100 $gParams = t3lib_div::_GET('edit');
101 $gParams2 = $gParams['tx_powermailcond_conditions'];
102 foreach ((array) $gParams2 as $uid => $actions) {
103 $thisConditionsUid = $uid;
104 }
105 $targetField = $pObj->cachedTSconfig['tx_powermailcond_conditions:' . $thisConditionsUid]['_THIS_ROW']['targetField'];
106
107 // Read values from powermail
108 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
109 $select = 'flexform',
110 $from = 'tx_powermail_fields',
111 $where = 'uid = ' . intval($targetField),
112 $groupBy = '',
113 $orderBy = '',
114 $limit = '1'
115 );
116 if ($res) {
117 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
118 }
119
120 // Change xml to a readable format
121 $arr = (array) t3lib_div::xml2array($row['flexform']);
122 $optionlist = $arr['data']['sDEF']['lDEF']['options']['vDEF'];
123 $options = t3lib_div::trimExplode("\n", $optionlist, 1);
124
125 // write params
126 foreach ((array) $options as $option) {
127 $params['items'][] = array(htmlspecialchars($option), htmlspecialchars($option));
128 }
129 }
130 }
131
132
133
134 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/powermail_cond/class.tx_powermailcond_fields_be.php']) {
135 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/powermail_cond/class.tx_powermailcond_fields_be.php']);
136 }
137
138 ?>