PageRenderTime 60ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/kb_tv_migrate/mod1/index.php

https://github.com/michael-cannon/typo3-extensions
PHP | 1246 lines | 804 code | 94 blank | 348 comment | 94 complexity | 97784d03dae5a00b53f3c58d0fc379f9 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2004 Bernhard Kraft (kraftb@kraftb.at)
  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. * Module 'TV Migrate' for the 'kb_tv_migrate' extension.
  26. *
  27. * @author Bernhard Kraft <kraftb@kraftb.at>
  28. */
  29. /**
  30. * [CLASS/FUNCTION INDEX of SCRIPT]
  31. *
  32. *
  33. *
  34. * 104: class tx_kbtvmigrate_module1 extends t3lib_SCbase
  35. * 112: function init()
  36. * 129: function menuConfig()
  37. * 146: function main()
  38. * 212: function printContent()
  39. * 223: function moduleContent()
  40. * 307: function error($type)
  41. *
  42. * SECTION: OUTPUT
  43. * 358: function printColmapForm($similar)
  44. * 435: function printDSTOForm($similar)
  45. *
  46. * SECTION: SAVE
  47. * 532: function saveColmapToDB($similar, $data)
  48. * 618: function saveDSTOConfToPageheaders($similar, $data)
  49. *
  50. * SECTION: ARRAY MODIFICATION
  51. * 695: function rec_setDataArByDSTO($treePart, &$dataAr)
  52. * 715: function rec_simplifyDSTOInTree(&$treePart)
  53. * 768: function rec_setDSTOTree(&$treePart, $setPages, $ds, $to)
  54. * 789: function setUsedT3Columns(&$similar)
  55. * 819: function pagesWithSameDSTO_possible($combos)
  56. * 907: function dsto_compare($row, $dsto)
  57. * 927: function array_compare($a, $b)
  58. *
  59. * SECTION: TO/DS METHODS
  60. * 958: function getDS($row)
  61. * 973: function getTO($row)
  62. * 990: function getDSName($ds_id)
  63. * 1004: function getTOName($to_id)
  64. * 1019: function getDSTOCombinations($id, &$combos)
  65. *
  66. * SECTION: TEMPLATE METHODS
  67. * 1064: function getTemplateCombinations($id)
  68. * 1080: function getTemplateCombination(&$combos, $row)
  69. * 1098: function rec_getTemplateCombination(&$combos, $rows)
  70. *
  71. * SECTION: Record methods
  72. * 1119: function getPageTree($id)
  73. *
  74. * SECTION: STORAGE FOLDERS AND TEMPLATES
  75. * 1149: function findingStorageFolderIds()
  76. * 1183: function getStorageFolders()
  77. *
  78. * SECTION: EXTRA METHODS
  79. * 1212: function getItemLabel($items, $val)
  80. *
  81. * TOTAL FUNCTIONS: 29
  82. * (This index is automatically created/updated by the extension "extdeveval")
  83. *
  84. */
  85. // DEFAULT initialization of a module [BEGIN]
  86. unset($MCONF);
  87. require ('conf.php');
  88. require ($BACK_PATH.'init.php');
  89. require ($BACK_PATH.'template.php');
  90. $LANG->includeLLFile('EXT:kb_tv_migrate/mod1/locallang.php');
  91. #include ('locallang.php');
  92. require_once (PATH_t3lib.'class.t3lib_scbase.php');
  93. require_once (PATH_t3lib.'class.t3lib_treeview.php');
  94. require_once (PATH_t3lib.'class.t3lib_tceforms.php');
  95. require_once (PATH_t3lib.'class.t3lib_tcemain.php');
  96. require_once (t3lib_extMgm::extPath('templavoila').'class.tx_templavoila_xmlrelhndl.php');
  97. require_once (t3lib_extMgm::extPath('kb_tv_migrate').'class.tx_kbtvmigrate_xmlrelhndl.php');
  98. $BE_USER->modAccess($MCONF,1); // This checks permissions and exits if the users has no permission for entry.
  99. // DEFAULT initialization of a module [END]
  100. class tx_kbtvmigrate_module1 extends t3lib_SCbase {
  101. var $pageinfo;
  102. /**
  103. * Initializes the object
  104. *
  105. * @return void
  106. */
  107. function init() {
  108. global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
  109. parent::init();
  110. /*
  111. if (t3lib_div::_GP('clear_all_cache')) {
  112. $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
  113. }
  114. */
  115. set_time_limit(600);
  116. }
  117. /**
  118. * Adds items to the ->MOD_MENU array. Used for the function menu selector.
  119. *
  120. * @return void
  121. */
  122. function menuConfig() {
  123. global $LANG;
  124. $this->MOD_MENU = Array (
  125. 'function' => Array (
  126. '1' => $LANG->getLL('menu_about'),
  127. '2' => $LANG->getLL('menu_set_page_type'),
  128. '3' => $LANG->getLL('menu_insert_content_elements'),
  129. )
  130. );
  131. parent::menuConfig();
  132. }
  133. /**
  134. * Main function of the module. Write the content to $this->content
  135. *
  136. * @return void
  137. */
  138. function main() {
  139. global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
  140. $this->foldOut = isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['kb_tv_migrate']['foldOut'])?$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['kb_tv_migrate']['foldOut']:1;
  141. // Access check!
  142. // The page will show only if there is a valid page and if this page may be viewed by the user
  143. $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
  144. $access = is_array($this->pageinfo) ? 1 : 0;
  145. if (($this->id && $access) || ($BE_USER->user['admin'] && !$this->id)) {
  146. // Draw the header.
  147. $this->doc = t3lib_div::makeInstance('mediumDoc');
  148. $this->doc->backPath = $BACK_PATH;
  149. $this->doc->form='<form action="'.t3lib_div::linkThisScript(array('kb_tv_migrate' => '')).'" method="POST" target="_self" enctype="multipart/form-data">';
  150. // JavaScript
  151. $this->doc->JScode = '
  152. ###JS_REPLACE###
  153. <script language="javascript" type="text/javascript" src="../res/jsfunc.js"></script>'.chr(10);
  154. $this->doc->JScode .= $this->doc->getDynTabMenuJScode();
  155. $this->doc->postCode='
  156. <script language="javascript" type="text/javascript">
  157. var please_select = "'.$LANG->getLL('please_select').'";
  158. var select_ds_first = "'.$LANG->getLL('select_ds_first').'"
  159. script_ended = 1;
  160. if (top.fsMod) top.fsMod.recentIds["web"] = '.intval($this->id).';
  161. </script>
  162. ';
  163. $headerSection = $this->doc->getHeader('pages',$this->pageinfo,$this->pageinfo['_thePath']).'<br>'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.path').': '.t3lib_div::fixed_lgd_pre($this->pageinfo['_thePath'],50);
  164. $this->content.=$this->doc->startPage($LANG->getLL('title'));
  165. $this->content.=$this->doc->header($LANG->getLL('title'));
  166. $this->content.=$this->doc->spacer(5);
  167. $this->content.=$this->doc->section('',$this->doc->funcMenu($headerSection,t3lib_BEfunc::getFuncMenu($this->id,'SET[function]',$this->MOD_SETTINGS['function'],$this->MOD_MENU['function'])));
  168. $this->content.=$this->doc->divider(5);
  169. // Render content:
  170. $this->moduleContent();
  171. // ShortCut
  172. if ($BE_USER->mayMakeShortcut()) {
  173. $this->content.=$this->doc->spacer(20).$this->doc->section('',$this->doc->makeShortcutIcon('id',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name']));
  174. }
  175. $this->content.=$this->doc->spacer(10);
  176. $this->content = str_replace('###JS_REPLACE###', $this->JSreplacement, $this->content);
  177. } else {
  178. // If no access or if ID == zero
  179. $this->doc = t3lib_div::makeInstance('mediumDoc');
  180. $this->doc->backPath = $BACK_PATH;
  181. $this->content.=$this->doc->startPage($LANG->getLL('title'));
  182. $this->content.=$this->doc->header($LANG->getLL('title'));
  183. $this->content.=$this->doc->spacer(5);
  184. $this->content.=$this->doc->spacer(10);
  185. }
  186. }
  187. /**
  188. * Prints out the module HTML
  189. *
  190. * @return void
  191. */
  192. function printContent() {
  193. $this->content.=$this->doc->endPage();
  194. echo $this->content;
  195. }
  196. /**
  197. * Generates the module content
  198. *
  199. * @return void
  200. */
  201. function moduleContent() {
  202. global $LANG;
  203. switch((string)$this->MOD_SETTINGS['function']) {
  204. case 1:
  205. $content = $LANG->getLL('about_text');
  206. $this->content.=$this->doc->section('About this extension',$content,0,1);
  207. break;
  208. case 2:
  209. $content= '';
  210. if (!intval($this->id)) {
  211. $content .= '<h1>Please select a page</h1><p>To start converting a site to Templa Voila please select the Root-Page of the site</p>';
  212. } else {
  213. $combos = $this->getTemplateCombinations($this->id);
  214. $this->getDSTOCombinations($this->id, $combos);
  215. $similarPages = $this->pagesWithSameDSTO_possible($combos);
  216. $data = t3lib_div::_GP('kb_tv_migrate');
  217. if (is_array($data['dsto'])&&count($data['dsto'])) {
  218. $ok = $this->saveDSTOConfToPageheaders($similarPages, $data['dsto']);
  219. if ($ok) {
  220. $content = '<h3>Save complete !!!</h3>
  221. <p>
  222. The data was saved sucessfully to the page headers. Have a look at your page headers
  223. and see if everything is set as expected.
  224. </p>'.chr(10);
  225. } else {
  226. $content = '<h3>Error occured while saving</h3>
  227. <p>
  228. While saving the DS/TO configuration to the page headers there occured an error.<br />
  229. The specific error message is : <br />
  230. <br />
  231. <i>ERROR: '.$this->errorMsg.'</i>
  232. <br />
  233. <br />
  234. Please consult the Erros section of the manual on this specific error. If you don\'t find
  235. anything in there you can search the web or write a mail to the extension author.
  236. </p>'.chr(10);
  237. }
  238. } else {
  239. $content .= $this->printDSTOForm($similarPages);
  240. }
  241. }
  242. $this->content.=$this->doc->section('Used Template Combinations',$content,0,1);
  243. break;
  244. case 3:
  245. $content='';
  246. if (!intval($this->id)) {
  247. $content .= '<h1>Please select a page</h1><p>To start converting a site to Templa Voila please select the Root-Page of the site</p>';
  248. } else {
  249. $combos = $this->getTemplateCombinations($this->id);
  250. $this->getDSTOCombinations($this->id, $combos);
  251. $sameDSTO = $this->pagesWithSameDSTO_set($combos);
  252. $this->setUsedT3Columns($sameDSTO);
  253. if (!$sameDSTO&&strlen($this->errorMsg)) {
  254. $content = $this->error(2);
  255. } else {
  256. $data = t3lib_div::_GP('kb_tv_migrate');
  257. if (is_array($data['colmap'])&&count($data['colmap'])) {
  258. $ok = $this->saveColmapToDB($sameDSTO, $data['colmap']);
  259. if ($ok) {
  260. $content = '<h3>Save complete !!!</h3>
  261. <p>
  262. The data was saved sucessfully to the tt_content table. Have a look at your Templa Voila
  263. pages and see if everything is inserted as expected.
  264. </p>'.chr(10);
  265. } else {
  266. $content = $this->error(1);
  267. }
  268. } else {
  269. $content .= $this->printColmapForm($sameDSTO);
  270. }
  271. }
  272. }
  273. $this->content.=$this->doc->section('Column Mapping',$content,0,1);
  274. break;
  275. }
  276. }
  277. /**
  278. * Returns an error message
  279. *
  280. * @param integer The type of error
  281. * @return string The error message
  282. */
  283. function error($type) {
  284. switch ($type) {
  285. case 1:
  286. $content = '<h3>Error occurred while saving</h3>
  287. <p>
  288. While inserting the content elements into the Templa Voila columns there occurred an error.<br />
  289. The specific error message is : <br />
  290. <br />
  291. <i>ERROR: '.$this->errorMsg.'</i>
  292. <br />
  293. <br />
  294. Please consult the Erros section of the manual on this specific error. If you don\'t find
  295. anything in there you can search the web or write a mail to the extension author.
  296. </p>'.chr(10);
  297. break;
  298. case 2:
  299. $content = '<h3>Error occurred while checking DS/TO</h3>
  300. <p>
  301. While checking the validity of the DS/TO configuration some error occurred : <br />
  302. <br />
  303. <i>ERROR: '.$this->errorMsg.'</i>
  304. <br />
  305. <br />
  306. Please consult the Erros section of the manual on this specific error. If you don\'t find
  307. anything in there you can search the web or write a mail to the extension author.
  308. </p>'.chr(10);
  309. break;
  310. default:
  311. $content = '<h3>Unspecified Error occurred</h3>
  312. <p>
  313. An unspecified error occurred while performing some operation. This should not happen.
  314. </p>'.chr(10);
  315. break;
  316. }
  317. return $content;
  318. }
  319. /*******************************************
  320. *
  321. * OUTPUT
  322. *
  323. * This methods perform operations on the data arrays
  324. *
  325. *******************************************/
  326. /**
  327. * Returns an the form for defining the column mapping
  328. *
  329. * @param array Data array
  330. * @return string HTML
  331. */
  332. function printColmapForm($similar) {
  333. global $LANG;
  334. $content = '';
  335. $menuItems = array();
  336. $selectId = 0;
  337. $JS .= 'var selectVals = Array();'.chr(10);
  338. $JS .= 'var validTO = Array();'.chr(10);
  339. $JS .= 'var validTAB = Array();'.chr(10);
  340. $JS .= 'var validALL = 0;'.chr(10);
  341. $tab = 0;
  342. foreach ($similar as $main => $main_ar) {
  343. foreach ($main_ar as $sub => $similar_ar) {
  344. $JS .= 'validTO['.$tab.'] = Array();'.chr(10);
  345. $JS .= 'validTAB['.$tab.'] = 0;'.chr(10);
  346. $HTML = '';
  347. $HTML .= '<div class="bgColor4">'.chr(10);
  348. foreach ($similar_ar as $cnt => $data) {
  349. $JS .= 'selectVals['.$selectId.'] = Array();'.chr(10);
  350. $JS .= 'validTO['.$tab.']['.$selectId.'] = 0;'.chr(10);
  351. $HTML .= '<h2>Pages with same TS/DO configuration:</h2>'.chr(10);
  352. $HTML .= '<ul>'.chr(10);
  353. foreach ($data['PAGES'] as $uid => $row) {
  354. $HTML .= '<li>'.t3lib_BEfunc::getRecordTitle('pages', $row).' ('.$uid.')</li>'.chr(10);
  355. }
  356. $HTML .= '</ul>'.chr(10);
  357. $HTML .= '<p>Please select now which colum should get mapped to which TV column. You can just choose TV columns which are mapped in the TO selected for those pages. Content Elements get just inserted if they aren\'t in the TV column already. If more than one T3 column gets mapped to the same TV column then Content Elements from the lower (in this form) mapping will be above the elements of the higher (in this form) mapping.</p>'.chr(10);
  358. $HTML .= '<table cellspacing="8" cellpadding="0" border="0">'.chr(10);
  359. foreach ($data['T3_COLUMNS'] as $t3Col) {
  360. $getLabel = $this->getItemLabel($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'], $t3Col);
  361. $HTML .= '<tr>
  362. <td align="right" style="font-weight: bold;">
  363. '.$LANG->getLL('t3col_label').' "'.$LANG->sL($getLabel).'" ==> '.$LANG->getLL('tvcol_label').' :
  364. </td>
  365. <td>
  366. <select id="select_'.$selectId.'_col" name="kb_tv_migrate[colmap]['.rawurlencode($main).']['.rawurlencode($sub).']['.$cnt.']['.$t3Col.']">
  367. <option value="">'.$LANG->getLL('no_target_column').'</option>'.chr(10);
  368. foreach ($data['TV_COLUMNS'] as $field => $fieldAr) {
  369. $HTML .= '<option value="'.$field.'">'.$fieldAr['tx_templavoila']['title'].'</option>'.chr(10);
  370. }
  371. $HTML .='</select>
  372. </td>
  373. </tr>';
  374. }
  375. $HTML .= '</table>'.chr(10);
  376. $selectId++;
  377. } // EOF: foreach ($similar_ar as $cnt => $data) {
  378. $HTML .= '</div>'.chr(10);
  379. $mainTitle = ($main=='_DEFAULT')?'DEFAULT':$main;
  380. $subTitle = ($sub=='_DEFAULT')?'DEFAULT':$sub;
  381. $menuItem = array(
  382. 'label' => $mainTitle.' / '.$subTitle,
  383. 'description' => 'Pages with this MAIN / SUB Template',
  384. 'linkTitle' => 'Pages with this MAIN / SUB Template',
  385. 'content' => $HTML,
  386. 'stateIcon' => -1,
  387. );
  388. $menuItems[] = $menuItem;
  389. $tab++;
  390. } // EOF: foreach ($main_ar as $sub => $similar_ar) {
  391. } // EOF: foreach ($similar as $main => $main_ar) {
  392. $content .= $this->doc->getDynTabMenu($menuItems, 'kb_tv_migrate', $this->foldOut?1:-1, $this->foldOut?true:false);
  393. $content .= '<input type="submit" name="submit" value="Save this Column-Mapping" id="submit" style="border: 1px solid #333333; padding: 4px 10px 4px 10px; margin: 20px 0px 0px 20px; font-weight: bold; font-size: 15px; width: 300px;" class="bgColor6" onClick="return confirm(\''.$LANG->getLL('confirm_mapping').'\')">';
  394. $this->JSreplacement = $this->doc->wrapScriptTags($JS);
  395. return $content;
  396. } // EOF: function printForm($similar) {
  397. /**
  398. * Returns an the form for defining DS/TO configuration
  399. *
  400. * @param array Data array
  401. * @return string HTML
  402. */
  403. function printDSTOForm($similar) {
  404. global $LANG;
  405. $content = '';
  406. $menuItems = array();
  407. $selectId = 0;
  408. $JS .= 'var selectVals = Array();'.chr(10);
  409. $JS .= 'var validTO = Array();'.chr(10);
  410. $JS .= 'var validTAB = Array();'.chr(10);
  411. $JS .= 'var validALL = 0;'.chr(10);
  412. $tab = 0;
  413. foreach ($similar as $main => $main_ar) {
  414. foreach ($main_ar as $sub => $similar_ar) {
  415. $JS .= 'validTO['.$tab.'] = Array();'.chr(10);
  416. $JS .= 'validTAB['.$tab.'] = 0;'.chr(10);
  417. $HTML = '';
  418. $HTML .= '<div class="bgColor4">'.chr(10);
  419. foreach ($similar_ar as $cnt => $data) {
  420. $JS .= 'selectVals['.$selectId.'] = Array();'.chr(10);
  421. $JS .= 'validTO['.$tab.']['.$selectId.'] = 0;'.chr(10);
  422. $HTML .= '<h2>Pages with same possible TS/DO configurations:</h2>'.chr(10);
  423. $HTML .= '<ul>'.chr(10);
  424. foreach ($data['PAGES'] as $uid => $row) {
  425. $HTML .= '<li>'.t3lib_BEfunc::getRecordTitle('pages', $row).' ('.$uid.')</li>'.chr(10);
  426. }
  427. $HTML .= '</ul>'.chr(10);
  428. $HTML .= '<p>Please select now which DS/TO those pages should get assinged. If you wish to make finer grained decisions on which DS/TO to use please select it manually afterwards</p>'.chr(10);
  429. $HTML .= '<table cellspacing="8" cellpadding="0" border="0">
  430. <tr>
  431. <td align="right" style="font-weight: bold;">
  432. '.$LANG->getLL('ds_label').' :
  433. </td>
  434. <td>
  435. <select id="select_'.$selectId.'_ds" name="kb_tv_migrate[dsto]['.rawurlencode($main).']['.rawurlencode($sub).']['.$cnt.'][ds]" onChange="updateTOselect('.$selectId.'); updateValid('.$selectId.', '.$tab.'); return false;">
  436. <option value="0">'.$LANG->getLL('please_select').'</option>'.chr(10);
  437. foreach ($data['DSTO_OPTIONS'] as $ds => $to_ar) {
  438. $HTML .= '<option value="'.$ds.'">'.$this->getDSName($ds).'</option>'.chr(10);
  439. $JS .= 'selectVals['.$selectId.']['.$ds.'] = Array();'.chr(10);
  440. foreach ($to_ar as $to => $val) {
  441. if (!intval($val)) continue;
  442. $JS .= 'selectVals['.$selectId.']['.$ds.']['.$to.'] = "'.$this->getTOName($to).'";'.chr(10);
  443. }
  444. } // EOF: foreach ($data['DSTO_OPTIONS'] as $ds => $to_ar) {
  445. $HTML .='</select>
  446. </td>
  447. </tr>
  448. <tr>
  449. <td align="right" style="font-weight: bold;">
  450. '.$LANG->getLL('to_label').' :
  451. </td>
  452. <td>
  453. <select id="select_'.$selectId.'_to" name="kb_tv_migrate[dsto]['.rawurlencode($main).']['.rawurlencode($sub).']['.$cnt.'][to]" onChange="updateValid('.$selectId.', '.$tab.')">
  454. <option value="0">'.$LANG->getLL('select_ds_first').'</option>
  455. </select>
  456. </td>
  457. </tr>
  458. </table>'.chr(10);
  459. $selectId++;
  460. } // EOF: foreach ($similar_ar as $cnt => $data) {
  461. $HTML .= '</div>'.chr(10);
  462. $mainTitle = ($main=='_DEFAULT')?'DEFAULT':$main;
  463. $subTitle = ($sub=='_DEFAULT')?'DEFAULT':$sub;
  464. $menuItem = array(
  465. 'label' => $mainTitle.' / '.$subTitle,
  466. 'description' => 'Pages with this MAIN / SUB Template',
  467. 'linkTitle' => 'Pages with this MAIN / SUB Template',
  468. 'content' => $HTML,
  469. 'stateIcon' => 2,
  470. );
  471. $menuItems[] = $menuItem;
  472. $tab++;
  473. } // EOF: foreach ($main_ar as $sub => $similar_ar) {
  474. } // EOF: foreach ($similar as $main => $main_ar) {
  475. $content .= '<form action="'.t3lib_div::linkThisScript(array('kb_tv_migrate' => '')).'" method="POST" enctype="multipart/form-data" target="_self">'.chr(10);
  476. $content .= $this->doc->getDynTabMenu($menuItems, 'kb_tv_migrate', $this->foldOut?1:-1, $this->foldOut?true:false);
  477. $content .= '<input type="submit" name="submit" value="Save TO/DS Configuration to Pageheaders" id="submit" style="border: 1px solid #333333; padding: 4px 10px 4px 10px; margin: 20px 0px 0px 20px; font-weight: bold; font-size: 15px; width: 400px; display: none;" class="bgColor6">';
  478. $content .= '</form>'.chr(10);
  479. $this->JSreplacement = $this->doc->wrapScriptTags($JS);
  480. return $content;
  481. } // EOF: function printForm($similar) {
  482. /*******************************************
  483. *
  484. * SAVE
  485. *
  486. * This methods store the submitted data in the database
  487. *
  488. *******************************************/
  489. /**
  490. * Applies the column mapping to the page headers. Inserts references to the content elements of the T3 columns
  491. *
  492. * @param array Data array
  493. * @param array Submitted data
  494. * @return bool true on success, false on error
  495. */
  496. function saveColmapToDB($similar, $data) {
  497. if (!is_array($data)) {
  498. $this->errorMsg = 'Variable expected to be array but was from different type (11)';
  499. return false;
  500. }
  501. foreach ($data as $main => $main_ar) {
  502. if (!is_array($main_ar)) {
  503. $this->errorMsg = 'Variable expected to be array but was from different type (12)';
  504. return false;
  505. }
  506. foreach ($main_ar as $sub => $data_ar) {
  507. if (!is_array($data_ar)) {
  508. $this->errorMsg = 'Variable expected to be array but was from different type (13)';
  509. return false;
  510. }
  511. if (!is_array($similar[$main][$sub])) {
  512. $this->errorMsg = 'Posted path not found in pagestructure array (14)';
  513. return false;
  514. }
  515. foreach ($data_ar as $cnt => $conf_ar) {
  516. if (!is_array($conf_ar)) {
  517. $this->errorMsg = 'Variable expected to be array but was from different type (15)';
  518. return false;
  519. }
  520. if (!is_array($similar[$main][$sub][$cnt])) {
  521. $this->errorMsg = 'Posted path not found in pagestructure array (16)';
  522. return false;
  523. }
  524. $t3Cols = implode(',', $similar[$main][$sub][$cnt]['T3_COLUMNS']);
  525. $tvCols = implode(',', array_keys($similar[$main][$sub][$cnt]['TV_COLUMNS']));
  526. foreach($conf_ar as $t3Col => $tvCol) {
  527. $tvCol = trim($tvCol);
  528. if (!strlen($tvCol)) continue;
  529. $t3Col = intval($t3Col);
  530. if (!t3lib_div::inList($t3Cols, $t3Col)) {
  531. $this->errorMsg = 'Posted T3 column not valid for this section (17)';
  532. return false;
  533. }
  534. if (!t3lib_div::inList($tvCols, $tvCol)) {
  535. $this->errorMsg = 'Posted TV column not valid for this section (18)';
  536. return false;
  537. }
  538. if (strlen($tvCol)) {
  539. $similar[$main][$sub][$cnt]['MAPPING'][$t3Col] = $tvCol;
  540. }
  541. }
  542. } // EOF: foreach ($data_ar as $cnt => $conf_ar) {
  543. } // EOF: foreach ($main_ar as $sub => $data_ar) {
  544. } // EOF: foreach ($data as $main => $main_ar) {
  545. // Insert references to the content elements into the TV XML records
  546. $xmlhandler = t3lib_div::makeInstance('tx_kbtvmigrate_xmlrelhndl');
  547. foreach ($similar as $main => $mainAr) {
  548. foreach ($mainAr as $sub => $subAr) {
  549. foreach ($subAr as $cnt => $dataAr) {
  550. foreach ($dataAr['PAGES'] as $uid => $pageRow) {
  551. if (is_array($dataAr['MAPPING'])&&count($dataAr['MAPPING'])) {
  552. $xml = t3lib_div::xml2array($pageRow['tx_templavoila_flex']);
  553. $xml = is_array($xml) ? $xml : array();
  554. foreach ($dataAr['MAPPING'] as $t3Col => $tvCol) {
  555. $records = t3lib_BEfunc::getRecordsByField('tt_content', 'pid', $pageRow['uid'], ' AND colPos='.$t3Col.' '.t3lib_BEfunc::BEenableFields('tt_content'), '', ' sorting DESC');
  556. if (is_array($records)&&count($records)) {
  557. $elements = $xml['data']['sDEF']['lDEF'][$tvCol]['vDEF'];
  558. $xmlTarget = 'pages:'.$pageRow['uid'].':sDEF:lDEF:'.$tvCol.':vDEF:0';
  559. foreach ($records as $contentRow) {
  560. // Add if not already in list
  561. if (!t3lib_div::inList($elements, $contentRow['uid'])) {
  562. $xmlhandler->pasteRecord('ref', 'tt_content|'.$contentRow['uid'], $xmlTarget);
  563. }
  564. } // EOF: foreach ($records as $contentRow) {
  565. } // EOF: if (is_array($records)&&count($records)) {
  566. } // EOF: foreach ($dataAr['MAPPING'] as $t3Col => $tvCol) {
  567. } // EOF: if (is_array($dataAr['MAPPING'])&&count()) {
  568. } // EOF: foreach ($dataAr['PAGES'] as $uid => $pageRow) {
  569. } // EOF: foreach ($subAr as $cnt => $dataAr) {
  570. } // EOF: foreach ($mainAr as $sub => $subAr) {
  571. } // EOF: foreach ($similar as $main => $mainAr) {
  572. return true;
  573. } // EOF: function saveColmapToDB($similar, $data) {
  574. /**
  575. * Saves the new DS/TO configuration to the page headers
  576. *
  577. * @param array Data array
  578. * @param array Submitted data
  579. * @return bool true on success, false on error
  580. */
  581. function saveDSTOConfToPageheaders($similar, $data) {
  582. if (!is_array($data)) {
  583. $this->errorMsg = 'Variable expected to be array but was from different type (1)';
  584. return false;
  585. }
  586. $tree = $this->getPageTree($this->id);
  587. foreach ($data as $main => $main_ar) {
  588. if (!is_array($main_ar)) {
  589. $this->errorMsg = 'Variable expected to be array but was from different type (2)';
  590. return false;
  591. }
  592. foreach ($main_ar as $sub => $data_ar) {
  593. if (!is_array($data_ar)) {
  594. $this->errorMsg = 'Variable expected to be array but was from different type (3)';
  595. return false;
  596. }
  597. if (!is_array($similar[$main][$sub])) {
  598. $this->errorMsg = 'Posted path not found in pagestructure array (4)';
  599. return false;
  600. }
  601. foreach ($data_ar as $cnt => $conf_ar) {
  602. if (!is_array($conf_ar)) {
  603. $this->errorMsg = 'Variable expected to be array but was from different type (5)';
  604. return false;
  605. }
  606. if (!(isset($conf_ar['ds'])&&isset($conf_ar['to']))) {
  607. $this->errorMsg = 'Expected Key in array not set (6)';
  608. return false;
  609. }
  610. if (!isset($similar[$main][$sub][$cnt])) {
  611. $this->errorMsg = 'Combination index not set in pagestructure array (7)';
  612. return false;
  613. }
  614. if (!intval($similar[$main][$sub][$cnt]['DSTO_OPTIONS'][$conf_ar['ds']][$conf_ar['to']])) {
  615. $this->errorMsg = 'Posted DS/TO combination not valid for this Main/Sub Template combination (8)';
  616. return false;
  617. }
  618. $pages = array();
  619. foreach ($similar[$main][$sub][$cnt]['PAGES'] as $uid => $row) {
  620. $pages[] = $uid;
  621. }
  622. $pages = implode(',', $pages);
  623. $this->rec_setDSTOTree($tree, $pages, $conf_ar['ds'], $conf_ar['to']);
  624. } // EOF: foreach ($data_ar as $cnt => $conf_ar) {
  625. } // EOF: foreach ($main_ar as $sub => $data_ar) {
  626. } // EOF: foreach ($data as $main => $main_ar) {
  627. $err = $this->rec_simplifyDSTOInTree($tree);
  628. if (strlen($err)) {
  629. $this->errorMsg = $err;
  630. return false;
  631. }
  632. $dataAr = array();
  633. $this->rec_setDataArByDSTO($tree, $dataAr);
  634. $tcemain = t3lib_div::makeInstance('t3lib_TCEmain');
  635. $tcemain->start($dataAr, array());
  636. $tcemain->process_datamap();
  637. return true;
  638. } // EOF: function saveDSTOConfToPageheaders($similar, $data) {
  639. /*******************************************
  640. *
  641. * ARRAY MODIFICATION
  642. *
  643. * This methods perform operations on the data arrays
  644. *
  645. *******************************************/
  646. /**
  647. * Sets the data array which get's passed to TCAmain by the values of the templavoila DS/TO configuration fields
  648. * Gets called recursive
  649. *
  650. * @param array Tree part
  651. * @param array TCAmain datamap array
  652. * @return void
  653. */
  654. function rec_setDataArByDSTO($treePart, &$dataAr) {
  655. $dataAr['pages'][$treePart['row']['uid']]['tx_templavoila_ds'] = $treePart['row']['tx_templavoila_ds'];
  656. $dataAr['pages'][$treePart['row']['uid']]['tx_templavoila_to'] = $treePart['row']['tx_templavoila_to'];
  657. $dataAr['pages'][$treePart['row']['uid']]['tx_templavoila_next_ds'] = $treePart['row']['tx_templavoila_next_ds'];
  658. $dataAr['pages'][$treePart['row']['uid']]['tx_templavoila_next_to'] = $treePart['row']['tx_templavoila_next_to'];
  659. if (is_array($treePart['childs'])&&count($treePart['childs'])) {
  660. foreach ($treePart['childs'] as $cnt => $data) {
  661. $this->rec_setDataArByDSTO($treePart['childs'][$cnt], $dataAr);
  662. }
  663. }
  664. }
  665. /**
  666. * Simplifies the DS/TO structure. In overall it checks how many of the sub-pages of a page are set to specific DS/TO combinations and finds the max set one. Then it sets the Sub-Page DS and TO on this page to the determined value and set all DS/TO settings of the subpages which match this combination to 0
  667. * Gets called recursive
  668. *
  669. * @param array Tree part
  670. * @return void
  671. */
  672. function rec_simplifyDSTOInTree(&$treePart) {
  673. $childDSTO = array();
  674. if (is_array($treePart['childs'])&&count($treePart['childs'])) {
  675. foreach ($treePart['childs'] as $cnt => $data) {
  676. $childDSTO[$data['row']['tx_templavoila_ds']][$data['row']['tx_templavoila_to']][] = $data['row']['uid'];
  677. }
  678. }
  679. $max = 0;
  680. $maxDS = 0;
  681. $maxTO = 0;
  682. if (is_array($childDSTO)&&count($childDSTO)) {
  683. foreach ($childDSTO as $ds => $ds_ar) {
  684. foreach ($ds_ar as $to => $to_ar) {
  685. if (($cnt = count($to_ar))>$max) {
  686. $max = $cnt;
  687. $maxDS = $ds;
  688. $maxTO = $to;
  689. }
  690. }
  691. }
  692. }
  693. if ($max) {
  694. if (!$maxDS||!$maxTO) {
  695. return 'For some reason there is a max TS/DO number of childs in this row but has invalid maxDS or maxTO (9)';
  696. }
  697. $treePart['row']['tx_templavoila_next_ds'] = $maxDS;
  698. $treePart['row']['tx_templavoila_next_to'] = $maxTO;
  699. foreach ($treePart['childs'] as $cnt => $data) {
  700. if (($data['row']['tx_templavoila_ds']==$maxDS)&&($data['row']['tx_templavoila_to']==$maxTO)) {
  701. $treePart['childs'][$cnt]['row']['tx_templavoila_ds'] = 0;
  702. $treePart['childs'][$cnt]['row']['tx_templavoila_to'] = 0;
  703. }
  704. }
  705. }
  706. // Call recursive
  707. if (is_array($treePart['childs'])&&count($treePart['childs'])) {
  708. foreach ($treePart['childs'] as $cnt => $data) {
  709. $this->rec_simplifyDSTOInTree($treePart['childs'][$cnt]);
  710. }
  711. }
  712. return '';
  713. }
  714. /**
  715. * Sets DS/TO recursive in the tree on the given pages.
  716. * Gets called recursive
  717. *
  718. * @param array Tree data
  719. * @param string Set DS/TO to the given values on this pages
  720. * @param integer UID of DS record
  721. * @param integer UID of TO record
  722. * @return void
  723. */
  724. function rec_setDSTOTree(&$treePart, $setPages, $ds, $to) {
  725. if (t3lib_div::inList($setPages, $treePart['row']['uid'])) {
  726. $treePart['row']['tx_templavoila_ds'] = $ds;
  727. $treePart['row']['tx_templavoila_to'] = $to;
  728. $treePart['row']['tx_templavoila_next_ds'] = 0;
  729. $treePart['row']['tx_templavoila_next_to'] = 0;
  730. }
  731. if (is_array($treePart['childs'])&&count($treePart['childs'])) {
  732. foreach ($treePart['childs'] as $key => $child) {
  733. $this->rec_setDSTOTree($treePart['childs'][$key], $setPages, $ds, $to);
  734. }
  735. }
  736. }
  737. /**
  738. * Sets the T3 Columns used in the by reference passed data array
  739. * Extracts data from TSConfig
  740. *
  741. * @param array Template/DS/TO Combinations (passed by reference)
  742. * @return bool true on success
  743. */
  744. function setUsedT3Columns(&$similar) {
  745. if (!is_array($similar)) return false;
  746. foreach ($similar as $main => $main_ar) {
  747. if (!is_array($main_ar)) return false;
  748. foreach ($main_ar as $sub => $sub_ar) {
  749. if (!is_array($sub_ar)) return false;
  750. foreach ($sub_ar as $cnt => $data_ar) {
  751. if (!is_array($data_ar)) return false;
  752. $usedCols = array();
  753. foreach ($data_ar['PAGES'] as $uid => $row) {
  754. $TSconfig = t3lib_BEfunc::getPagesTSconfig($uid);
  755. $colPos_list = $TSconfig['mod.']['SHARED.']['colPos_list'];
  756. if (!strlen($colPos_list)) $colPos_list = '1,0,2,3';
  757. $usedCols = array_merge($usedCols, t3lib_div::intExplode(',', $colPos_list));
  758. $usedCols = array_unique($usedCols);
  759. }
  760. sort($usedCols);
  761. $similar[$main][$sub][$cnt]['T3_COLUMNS'] = $usedCols;
  762. } // EOF: foreach ($sub_ar as $cnt => $data_ar) {
  763. } // EOF: foreach ($main_ar as $sub => $sub_ar) {
  764. } // EOF: foreach ($similar as $main => $main_ar) {
  765. return true;
  766. }
  767. /**
  768. * Returns pages on which the same DS/TO combination is possible
  769. *
  770. * @param array Template Combinations
  771. * @return array Template + DS/TO Combinations
  772. */
  773. function pagesWithSameDSTO_possible($combos) {
  774. $similar = array();
  775. foreach ($combos as $main => $main_ar) {
  776. foreach ($main_ar as $sub => $pages_ar) {
  777. foreach ($pages_ar as $uid => $row) {
  778. $found = 0;
  779. if (is_array($similar[$main][$sub])) {
  780. foreach ($similar[$main][$sub] as $cnt => $data) {
  781. if (!$this->array_compare($row['_DSTO_OPTIONS'], $data['DSTO_OPTIONS'])) {
  782. $similar[$main][$sub][$cnt]['PAGES'][$row['uid']] = $row;
  783. $found = 1;
  784. break;
  785. }
  786. }
  787. }
  788. if (!$found) {
  789. $similar[$main][$sub][] = array(
  790. 'DSTO_OPTIONS' => $row['_DSTO_OPTIONS'],
  791. 'PAGES' => array($row['uid'] => $row),
  792. );
  793. }
  794. }
  795. }
  796. }
  797. return $similar;
  798. }
  799. /**
  800. * Returns pages on which the same DS/TO combination is set
  801. *
  802. * @param array Template Combinations
  803. * @return array Template + DS/TO Combinations
  804. */
  805. function pagesWithSameDSTO_set(&$combos) {
  806. $similar = array();
  807. foreach ($combos as $main => $main_ar) {
  808. foreach ($main_ar as $sub => $pages_ar) {
  809. foreach ($pages_ar as $uid => $row) {
  810. $found = 0;
  811. if (is_array($similar[$main][$sub])) {
  812. foreach ($similar[$main][$sub] as $cnt => $data) {
  813. if (!$this->dsto_compare($row, $data['DSTO_DATA'])) {
  814. $similar[$main][$sub][$cnt]['PAGES'][$row['uid']] = $row;
  815. $found = 1;
  816. break;
  817. }
  818. if (strlen($this->errorMsg)) {
  819. return false;
  820. }
  821. }
  822. }
  823. if (!$found) {
  824. $ds = $this->getDS($row);
  825. $to = $this->getTO($row);
  826. $toRec = t3lib_BEfunc::getRecord('tx_templavoila_tmplobj', $to);
  827. $dsRec = t3lib_BEfunc::getRecord('tx_templavoila_datastructure', $ds);
  828. $dsXML = t3lib_div::xml2array($dsRec['dataprot']);
  829. $mapping = unserialize($toRec['templatemapping']);
  830. $TVcols = array();
  831. foreach ($mapping['MappingInfo']['ROOT']['el'] as $field => $fieldAr) {
  832. if ($dsXML['ROOT']['el'][$field]['tx_templavoila']['eType']=='ce') {
  833. $TVcols[$field] = $dsXML['ROOT']['el'][$field];
  834. }
  835. }
  836. $similar[$main][$sub][] = array(
  837. 'DSTO_DATA' => array(
  838. 'ds' => $ds,
  839. 'to' => $to,
  840. ),
  841. 'TV_COLUMNS' => $TVcols,
  842. 'PAGES' => array($row['uid'] => $row),
  843. );
  844. }
  845. }
  846. }
  847. }
  848. return $similar;
  849. }
  850. /**
  851. * Compares if two DS/TO settings are the same.
  852. * Gets called recursive.
  853. *
  854. * @param array Page row
  855. * @param array Stored DS/TO settings
  856. * @return integer 0 if the settings are equal NOT 0 if different
  857. */
  858. function dsto_compare($row, $dsto) {
  859. $this_ds = $this->getDS($row);
  860. $this_to = $this->getTO($row);
  861. if (!($this_ds&&$this_to)) {
  862. $this->errorMsg = 'DS or TO not set for page "'.t3lib_BEfunc::getRecordTitle('pages', $row).'" ('.$row['uid'].') ! (10)';
  863. return -1;
  864. }
  865. if ($this_ds!=$dsto['ds']) return -1;
  866. if ($this_to!=$dsto['to']) return -1;
  867. return 0;
  868. }
  869. /**
  870. * Compares if two arrays are the same.
  871. * Gets called recursive.
  872. *
  873. * @param array First array
  874. * @param array Second array
  875. * @return integer 0 if the array are equal NOT 0 if different
  876. */
  877. function array_compare($a, $b) {
  878. if (is_array($a)&&is_array($b)) {
  879. foreach ($a as $key => $val) {
  880. if (!isset($b[$key])) return -1;
  881. if (is_array($a[$key])&&is_array($b[$key])) {
  882. if ($this->array_compare($a[$key], $b[$key])) {
  883. return -1;
  884. }
  885. } else {
  886. if ($a[$key]!==$b[$key]) return -1;
  887. }
  888. }
  889. } else {
  890. return -1;
  891. }
  892. return 0;
  893. }
  894. /*******************************************
  895. *
  896. * TO/DS METHODS
  897. *
  898. *******************************************/
  899. /**
  900. * Returns the DS name of a given page row
  901. *
  902. * @param array Page row
  903. * @return string Datastructure name
  904. */
  905. function getDS($row) {
  906. $this_ds = intval($row['tx_templavoila_ds']);
  907. if (!$this_ds) {
  908. $parent = t3lib_BEfunc::getRecord('pages', $row['pid']);
  909. $this_ds = intval($parent['tx_templavoila_next_ds']);
  910. }
  911. return $this_ds;
  912. }
  913. /**
  914. * Returns the TO name of a given page row
  915. *
  916. * @param array Page row
  917. * @return string Template Object name
  918. */
  919. function getTO($row) {
  920. $this_to= intval($row['tx_templavoila_to']);
  921. if (!$this_to) {
  922. $parent = t3lib_BEfunc::getRecord('pages', $row['pid']);
  923. $this_to = intval($parent['tx_templavoila_next_to']);
  924. }
  925. return $this_to;
  926. }
  927. /**
  928. * Returns the Title of a Datastructure
  929. *
  930. * @param integer Datastructure Id
  931. * @return string Datastructure Name
  932. */
  933. var $DScache = array();
  934. function getDSName($ds_id) {
  935. if (!isset($DScache[$ds_id])) {
  936. $DScache[$ds_id] = t3lib_BEfunc::getRecord('tx_templavoila_datastructure', $ds_id);
  937. }
  938. return t3lib_BEfunc::getRecordTitle('tx_templavoila_datastructure', $DScache[$ds_id]);
  939. }
  940. /**
  941. * Returns the Title of a TO
  942. *
  943. * @param integer Template Object Id
  944. * @return string Template Object Name
  945. */
  946. var $TOcache = array();
  947. function getTOName($to_id) {
  948. if (!isset($TOcache[$to_id])) {
  949. $TOcache[$to_id] = t3lib_BEfunc::getRecord('tx_templavoila_tmplobj', $to_id);
  950. }
  951. return t3lib_BEfunc::getRecordTitle('tx_templavoila_tmplobj', $TOcache[$to_id]);
  952. }
  953. /**
  954. * Returns all DS/TO combinations
  955. *
  956. * @param integer Root Id
  957. * @param array Template combinations
  958. * @return array Template + DS/TO combinations
  959. */
  960. function getDSTOCombinations($id, &$combos) {
  961. $tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
  962. t3lib_div::loadTCA('pages');
  963. $initfields_ds = $tceforms->initItemArray($GLOBALS['TCA']['pages']['columns']['tx_templavoila_ds']);
  964. $initfields_to = $tceforms->initItemArray($GLOBALS['TCA']['pages']['columns']['tx_templavoila_to']);
  965. $this->findingStorageFolderIds();
  966. $storage_folders = $this->getStorageFolders();
  967. foreach ($combos as $main => $sub_ar) {
  968. foreach ($sub_ar as $sub => $pages_ar) {
  969. foreach ($pages_ar as $uid => $row) {
  970. $TSconfig = $tceforms->setTSconfig('pages',$row);
  971. $selItems_ds = $tceforms->addSelectOptionsToItemArray($initfields_ds, $GLOBALS['TCA']['pages']['columns']['tx_templavoila_ds'], $TSconfig, 'tx_templavoila_ds');
  972. foreach ($selItems_ds as $dsAr) {
  973. if (!($ds = intval($dsAr[1]))) continue;
  974. $selItems_to = array();
  975. foreach ($storage_folders as $storage_folder) {
  976. $TSconfigTmp = $TSconfig;
  977. $TSconfigTmp['_THIS_ROW']['tx_templavoila_ds'] = $ds;
  978. $TSconfigTmp['_STORAGE_PID'] = $storage_folder['uid'];
  979. $selItems_to = array_merge($selItems_to, $tceforms->addSelectOptionsToItemArray($initfields_to, $GLOBALS['TCA']['pages']['columns']['tx_templavoila_to'], $TSconfigTmp, 'tx_templavoila_to'));
  980. }
  981. foreach ($selItems_to as $toAr) {
  982. if (!($to = intval($toAr[1]))) continue;
  983. $combos[$main][$sub][$uid]['_DSTO_OPTIONS'][$ds][$to] = 1;
  984. }
  985. } // EOF: foreach ($selItems_ds as $dsAr) {
  986. } // EOF: foreach ($pages_ar as $uid => $row) {
  987. } // EOF: foreach ($sub_ar as $sub => $pages_ar) {
  988. } // EOF: foreach ($combos as $main => $sub_ar) {
  989. } // EOF: function getDSTOCombinations($id, &$combos) {
  990. /*******************************************
  991. *
  992. * TEMPLATE METHODS
  993. *
  994. *******************************************/
  995. /**
  996. * Returns all template combinations
  997. *
  998. * @param integer Root Id
  999. * @return array Template combinations
  1000. */
  1001. function getTemplateCombinations($id) {
  1002. $tree = $this->getPageTree($id);
  1003. $templateCombinations = array();
  1004. $this->getTemplateCombination($templateCombinations, $tree['row']);
  1005. $this->rec_getTemplateCombination($templateCombinations, $tree['childs']);
  1006. return $templateCombinations;
  1007. }
  1008. /**
  1009. * Returns a single template combination
  1010. *
  1011. * @param array All combination (passed by reference)
  1012. * @param array Page row
  1013. * @return void
  1014. */
  1015. function getTemplateCombination(&$combos, $row) {
  1016. $main_tmpl = $row['tx_rlmptmplselector_main_tmpl'];
  1017. if (!strlen($main_tmpl)) $main_tmpl = '_DEFAULT';
  1018. if (!strcmp($main_tmpl, '0')) $main_tmpl = '_DEFAULT';
  1019. $ca_tmpl = $row['tx_rlmptmplselector_ca_tmpl'];
  1020. if (!strlen($ca_tmpl)) $ca_tmpl = '_DEFAULT';
  1021. if (!strcmp($ca_tmpl, '0')) $ca_tmpl = '_DEFAULT';
  1022. $combos[$main_tmpl][$ca_tmpl][$row['uid']] = $row;
  1023. }
  1024. /**
  1025. * Sets first parameter to all possible template combinations.
  1026. * Gets called recursive.
  1027. *
  1028. * @param array All combination (passed by reference)
  1029. * @param array Actual part of tree
  1030. * @return void
  1031. */
  1032. function rec_getTemplateCombination(&$combos, $rows) {
  1033. foreach ($rows as $row) {
  1034. $this->getTemplateCombination($combos, $row['row']);
  1035. $this->rec_getTemplateCombination($combos, $row['childs']);
  1036. }
  1037. }
  1038. /*******************************************
  1039. *
  1040. * Record methods
  1041. *
  1042. *******************************************/
  1043. /**
  1044. * Returns an page tree
  1045. *
  1046. * @param integer Root Id
  1047. * @return array Page tree
  1048. */
  1049. function getPageTree($id) {
  1050. $row = t3lib_BEfunc::getRecord('pages', $id);
  1051. if (is_array($row)) {
  1052. $tmpChilds = t3lib_BEfunc::getRecordsByField('pages', 'pid', $row['uid'], ' AND doktype<200', '', 'sorting');
  1053. $childs = array();
  1054. if (is_array($tmpChilds) && count($tmpChilds)) {
  1055. foreach ($tmpChilds as $key => $child) {
  1056. if (!intval($child['uid'])) continue;
  1057. $childs[] = $this->getPageTree($child['uid']);
  1058. }
  1059. }
  1060. return array('row' => $row, 'childs' => $childs);
  1061. } else {
  1062. return false;
  1063. }
  1064. }
  1065. /****************************************
  1066. *
  1067. * STORAGE FOLDERS AND TEMPLATES
  1068. *
  1069. * This methods return the Storage folders and existing Templates
  1070. *
  1071. ****************************************/
  1072. /**
  1073. * Generates $this->storageFolders with available sysFolders linked to as storageFolders for the user
  1074. *
  1075. * @return void Modification in $this->storageFolders array
  1076. */
  1077. function findingStorageFolderIds() {
  1078. global $TYPO3_DB;
  1079. // Init:
  1080. $readPerms = $GLOBALS['BE_USER']->getPagePermsClause(1);
  1081. $this->storageFolders=array();
  1082. // Looking up all references to a storage folder:
  1083. $res = $TYPO3_DB->exec_SELECTquery (
  1084. 'uid,storage_pid',
  1085. 'pages',
  1086. 'storage_pid>0'.t3lib_BEfunc::deleteClause('pages')
  1087. );
  1088. while($row = $TYPO3_DB->sql_fetch_assoc($res)) {
  1089. if ($GLOBALS['BE_USER']->isInWebMount($row['storage_pid'],$readPerms)) {
  1090. $storageFolder = t3lib_BEfunc::getRecord('pages',$row['storage_pid'],'uid,title');
  1091. if ($storageFolder['uid']) {
  1092. $this->storageFolders[$storageFolder['uid']] = $storageFolder['title'];
  1093. }
  1094. }
  1095. }
  1096. // Compopsing select list:
  1097. $sysFolderPIDs = array_keys($this->storageFolders);
  1098. $sysFolderPIDs[]=0;
  1099. $this->storageFolders_pidList = implode(',',$sysFolderPIDs);
  1100. }
  1101. /**
  1102. * Returns an array containing all storage folders
  1103. *
  1104. * @return array Storage folders
  1105. */
  1106. function getStorageFolders() {
  1107. $folders = array();
  1108. $ids = t3lib_div::trimExplode(',', $this->storageFolders_pidList, 1);
  1109. foreach ($ids as $id) {
  1110. if (intval($id)) {
  1111. $row = t3lib_BEfunc::getRecord('pages', $id);
  1112. if (is_array($row)) {
  1113. $folders[] = $row;
  1114. }
  1115. }
  1116. }
  1117. return $folders;
  1118. }
  1119. /****************************************
  1120. *
  1121. * EXTRA METHODS
  1122. *
  1123. * Some methods we need
  1124. *
  1125. ****************************************/
  1126. /**
  1127. * Returns an label of a TCA 'group' items entry of a specific value
  1128. *
  1129. * @param array Items from TCA configuration
  1130. * @param mixed Value
  1131. * @return string Label
  1132. */
  1133. function getItemLabel($items, $val) {
  1134. if (is_array($items)&&count($items)) {
  1135. foreach ($items as $item) {
  1136. if ($item[1]==$val) return $item[0];
  1137. }
  1138. }
  1139. return '[INVALID VALUE]';
  1140. }
  1141. }
  1142. if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/kb_tv_migrate/mod1/index.php']) {
  1143. include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/kb_tv_migrate/mod1/index.php']);
  1144. }
  1145. // Make instance:
  1146. $SOBE = t3lib_div::makeInstance('tx_kbtvmigrate_module1');
  1147. $SOBE->init();
  1148. // Include files?
  1149. foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
  1150. $SOBE->main();
  1151. $SOBE->printContent();
  1152. ?>