1f8449bfd628e4a05d1a83604f2710428f4ca3d5
[TYPO3CMS/Extensions/powermailCond.git] / lib / class.tx_powermailcond_ajaxWriteInSession_eid.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Alexander 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 require_once(PATH_t3lib . 'class.t3lib_befunc.php');
26 require_once(PATH_t3lib . 'stddb/tables.php');
27 require_once(t3lib_extMgm::extPath('cms', 'ext_tables.php'));
28 require_once(PATH_tslib . 'class.tslib_pibase.php');
29 require_once(t3lib_extMgm::extPath('powermail_cond') . 'lib/class.tx_powermailcond_div.php'); // load div class
30
31 /**
32 * This class is for storing values to the session on every fieldchange (via AJAX)
33 *
34 * @author Alex Kellner <alexander.kellner@in2code.de>, in2code.
35 * @package TYPO3
36 * @subpackage tx_powermailcond_ajaxWriteInSession_eid
37 */
38 class tx_powermailcond_ajaxWriteInSession_eid extends tslib_pibase {
39
40 public $extKey = 'powermail_cond'; // Extension key
41 public $prefixId = 'tx_powermailcond_pi1';
42 private $debug = false;
43
44 /**
45 * Write values to session - main method called via AJAX
46 * Call this with index.php?id=97&eID=powermailcond_ajax&tx_powermailcond_pi1[uid]=5&tx_powermailcond_pi1[value]=test
47 *
48 * @return void
49 */
50 public function main() {
51 // config
52 $this->getCObj(); // enable TSFE globals
53 $GLOBALS['TSFE']->sesData = tslib_eidtools::initFeUser();
54 $piVars = t3lib_div::_GP($this->prefixId); // GET param
55 $uids = t3lib_div::trimExplode('_', $piVars['uid']);
56 $uid = intval($uids[0]); // uid of current field
57 $value = htmlspecialchars($piVars['value']); // value from current field
58 $this->div = t3lib_div::makeInstance('tx_powermailcond_div'); // Create new instance for div class
59 $ttcontent_uid = $this->div->getTtcontentUid($uid); // get tt_content uid to current field
60
61 // start
62 if ($uid == 0) {
63 return false;
64 }
65 if (isset($uids[1])) { // second level
66 $oldSession = array();
67 $arr['uid' . $uid] = $GLOBALS['TSFE']->fe_user->sesData['powermail_' . $ttcontent_uid]['uid' . $uid];
68 $arr['uid' . $uid][$uids[1]] = $value;
69 $this->div->saveInSession($arr, 'powermail_' . $ttcontent_uid); // save values to session
70 } else { // first level
71 $arr = array(
72 'uid' . $uid => $value
73 );
74 $this->div->saveInSession($arr, 'powermail_' . $ttcontent_uid); // save values to session
75 }
76
77 if ($this->debug) {
78 t3lib_div::debug($arr, 'powermail_' . $ttcontent_uid);
79 }
80 }
81
82 /**
83 * Get tt_content UID from field UID
84 *
85 * @param integer $fuid: UID of tx_powermail_fields
86 * @return integer $uid: tt_content UID
87 */
88 private function getTtcontentUid($fuid) {
89 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery ( // DB query
90 'tt_content.uid',
91 'tx_powermail_fieldsets LEFT JOIN tx_powermail_fields ON tx_powermail_fieldsets.uid = tx_powermail_fields.fieldset LEFT JOIN tt_content ON tx_powermail_fieldsets.tt_content = tt_content.uid',
92 'tx_powermail_fields.uid = ' . intval($fuid),
93 '',
94 '',
95 1
96 );
97 if (!$res) { // If there is a result
98 return false;
99 }
100
101 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
102 return $row['uid'];
103 }
104
105 /**
106 * Initialize cObj and TSFE Globals
107 *
108 * @return object cObj
109 */
110 private function getCObj() {
111 $this->div = t3lib_div::makeInstance('tx_powermailcond_div'); // Create new instance for div class
112 $userObj = tslib_eidtools::initFeUser();
113 $temp_TSFEclassName = t3lib_div::makeInstance('tslib_fe');
114 $GLOBALS['TSFE'] = new $temp_TSFEclassName($TYPO3_CONF_VARS, 32, 0, true);
115 $GLOBALS['TSFE']->connectToDB();
116 $GLOBALS['TSFE']->fe_user = $userObj;
117 $GLOBALS['TSFE']->id = t3lib_div::_GET('id');
118 $GLOBALS['TSFE']->determineId();
119 $GLOBALS['TSFE']->getCompressedTCarray();
120 $GLOBALS['TSFE']->initTemplate();
121 $GLOBALS['TSFE']->getConfigArray();
122 $GLOBALS['TSFE']->includeTCA();
123
124 return t3lib_div::makeInstance('tslib_cObj');
125 }
126
127 }
128
129 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/powermail_cond/lib/class.tx_powermailcond_ajaxWriteInSession_eid.php']) {
130 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/powermail_cond/lib/class.tx_powermailcond_ajaxWriteInSession_eid.php']);
131 }
132
133 $SOBE = t3lib_div::makeInstance('tx_powermailcond_ajaxWriteInSession_eid'); // make instance
134 echo $SOBE->main(); // print content
135 ?>