00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00083 class tslib_feTCE {
00084
00085 var $extScripts=array();
00086 var $extScriptsConf=array();
00087 var $newData=array();
00088 var $extraList = 'pid';
00089
00100 function start($data,$FEData) {
00101 reset($data);
00102 while(list($table,$id_arr)=each($data)) {
00103 t3lib_div::loadTCA($table);
00104 if (is_array($id_arr)) {
00105 $sep=$FEData[$table.'.']['separator']?$FEData[$table.'.']['separator']:chr(10);
00106 reset($id_arr);
00107 while(list($id,$field_arr)=each($id_arr)) {
00108 $this->newData[$table][$id]=Array();
00109 if (strstr($id,'NEW')) {
00110
00111 if ($FEData[$table.'.']['default.']) {
00112 $this->newData[$table][$id] = $FEData[$table.'.']['default.'];
00113 }
00114 if ($FEData[$table.'.']['autoInsertPID']) {
00115 $this->newData[$table][$id]['pid'] = intval($GLOBALS['TSFE']->page['uid']);
00116 }
00117
00118 if (is_array($field_arr)) {
00119 reset($field_arr);
00120 while(list($field,$value)=each($field_arr)) {
00121 if ($FEData[$table.'.']['allowNew.'][$field]) {
00122 if (is_array($value)) {
00123 $this->newData[$table][$id][$field] = implode($sep,$value);
00124 } else {
00125 $this->newData[$table][$id][$field] = $value;
00126 }
00127 }
00128 }
00129 }
00130
00131 $dPC_field = $FEData[$table.'.']['doublePostCheck'];
00132 if (is_array($this->newData[$table][$id]) && $dPC_field) {
00133 $doublePostCheckKey = $this->calcDoublePostKey($this->newData[$table][$id]);
00134 if ($this->checkDoublePostExist($table,$dPC_field,$doublePostCheckKey)) {
00135 unset($this->newData[$table][$id]);
00136 $GLOBALS['TT']->setTSlogMessage('"FEData": Submitted record to table $table was doublePosted (key: $doublePostCheckKey). Nothing saved.',2);
00137 } else {
00138 $this->newData[$table][$id][$dPC_field] = $doublePostCheckKey;
00139 $this->extraList.=','.$dPC_field;
00140 }
00141 }
00142 } else {
00143
00144 if (is_array($field_arr)) {
00145 reset($field_arr);
00146 while(list($field,$value)=each($field_arr)) {
00147 if ($FEData[$table.'.']['allowEdit.'][$field]) {
00148 if (is_array($value)) {
00149 $this->newData[$table][$id][$field] = implode($sep,$value);
00150 } else {
00151 $this->newData[$table][$id][$field] = $value;
00152 }
00153 }
00154 }
00155 }
00156
00157 if (is_array($FEData[$table.'.']['overrideEdit.'])) {
00158 reset($FEData[$table.'.']['overrideEdit.']);
00159 while(list($field,$value)=each($FEData[$table.'.']['overrideEdit.'])) {
00160 $this->newData[$table][$id][$field] = $value;
00161 }
00162 }
00163 }
00164 if ($FEData[$table.'.']['userIdColumn']) {
00165 $this->newData[$table][$id][$FEData[$table.'.']['userIdColumn']] = intval($GLOBALS['TSFE']->fe_user->user['uid']);
00166 }
00167 }
00168 $incFile = $GLOBALS['TSFE']->tmpl->getFileName($FEData[$table.'.']['processScript']);
00169 if ($incFile) {
00170 $this->extScripts[$table]=$incFile;
00171 $this->extScriptsConf[$table]=$FEData[$table.'.']['processScript.'];
00172 }
00173 }
00174 }
00175 }
00176
00187 function checkDoublePostExist($table,$doublePostField,$key) {
00188 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, $doublePostField.'='.intval($key));
00189 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00190 return $row[0];
00191 }
00192
00200 function calcDoublePostKey($array) {
00201 ksort($array);
00202 $doublePostCheckKey = hexdec(substr(md5(serialize($array)),0,8));
00203 return $doublePostCheckKey;
00204 }
00205
00212 function includeScripts() {
00213 reset($this->extScripts);
00214 while(list($incFile_table,$incFile)=each($this->extScripts)) {
00215 if (@is_file($incFile) && $GLOBALS['TSFE']->checkFileInclude($incFile)) {
00216 include($incFile);
00217 $GLOBALS['TT']->setTSlogMessage('Included '.$incFile,0);
00218 } else $GLOBALS['TT']->setTSlogMessage('"'.$incFile.'" was not found!',2);
00219 }
00220 }
00221
00232 function execNEWinsert($table, $dataArr) {
00233 $extraList=$this->extraList;
00234 if ($GLOBALS['TCA'][$table]['ctrl']['tstamp']) {$field=$GLOBALS['TCA'][$table]['ctrl']['tstamp']; $dataArr[$field]=time(); $extraList.=','.$field;}
00235 if ($GLOBALS['TCA'][$table]['ctrl']['crdate']) {$field=$GLOBALS['TCA'][$table]['ctrl']['crdate']; $dataArr[$field]=time(); $extraList.=','.$field;}
00236 if ($GLOBALS['TCA'][$table]['ctrl']['cruser_id']) {$field=$GLOBALS['TCA'][$table]['ctrl']['cruser_id']; $dataArr[$field]=0; $extraList.=','.$field;}
00237
00238 unset($dataArr['uid']); // uid can never be set
00239 $insertFields = array();
00240
00241 foreach($dataArr as $f => $v) {
00242 if (t3lib_div::inList($extraList,$f) || isset($GLOBALS['TCA'][$table]['columns'][$f])) {
00243 $insertFields[$f] = $v;
00244 }
00245 }
00246
00247 $GLOBALS['TYPO3_DB']->exec_INSERTquery($table, $insertFields);
00248 }
00249
00258 function clear_cacheCmd($cacheCmd) {
00259 $cacheCmd = intval($cacheCmd);
00260 if ($cacheCmd) {
00261 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', 'page_id='.intval($cacheCmd));
00262 if ($cacheCmd == intval($GLOBALS['TSFE']->id)) { // Setting no_cache true if the cleared-cache page is the current page!
00263 $GLOBALS['TSFE']->set_no_cache();
00264 }
00265 }
00266 }
00267
00274 function getConf($table) {
00275 return $this->extScriptsConf[$table];
00276 }
00277 }
00278
00279
00280
00281 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_fetce.php']) {
00282 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_fetce.php']);
00283 }
00284
00285 ?>