/** * Generate the widget and return it as string * * @return string */ public function generate() { $arrButtons = array('copy', 'drag', 'up', 'down', 'delete'); $strCommand = 'cmd_' . $this->strField; // Change the order if (\Input::get($strCommand) && is_numeric(\Input::get('cid')) && \Input::get('id') == $this->currentRecord) { $this->import('Database'); switch (\Input::get($strCommand)) { case 'copy': $this->varValue = array_duplicate($this->varValue, \Input::get('cid')); break; case 'up': $this->varValue = array_move_up($this->varValue, \Input::get('cid')); break; case 'down': $this->varValue = array_move_down($this->varValue, \Input::get('cid')); break; case 'delete': $this->varValue = array_delete($this->varValue, \Input::get('cid')); break; } $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord); $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', \Environment::get('request')))); } // Make sure there is at least an empty array if (!is_array($this->varValue) || empty($this->varValue)) { $this->varValue = array(''); } // Initialize the tab index if (!\Cache::has('tabindex')) { \Cache::set('tabindex', 1); } $tabindex = \Cache::get('tabindex'); $return = '<ul id="ctrl_' . $this->strId . '" class="tl_listwizard" data-tabindex="' . $tabindex . '">'; // Add input fields for ($i = 0, $c = count($this->varValue); $i < $c; $i++) { $return .= ' <li><input type="text" name="' . $this->strId . '[]" class="tl_text" tabindex="' . $tabindex++ . '" value="' . specialchars($this->varValue[$i]) . '"' . $this->getAttributes() . '> '; // Add buttons foreach ($arrButtons as $button) { $class = $button == 'up' || $button == 'down' ? ' class="button-move"' : ''; if ($button == 'drag') { $return .= \Image::getHtml('drag.gif', '', 'class="drag-handle" title="' . sprintf($GLOBALS['TL_LANG']['MSC']['move']) . '"'); } else { $return .= '<a href="' . $this->addToUrl('&' . $strCommand . '=' . $button . '&cid=' . $i . '&id=' . $this->currentRecord) . '"' . $class . ' title="' . specialchars($GLOBALS['TL_LANG']['MSC']['lw_' . $button]) . '" onclick="Backend.listWizard(this,\'' . $button . '\',\'ctrl_' . $this->strId . '\');return false">' . \Image::getHtml($button . '.gif', $GLOBALS['TL_LANG']['MSC']['lw_' . $button], 'class="tl_listwizard_img"') . '</a> '; } } $return .= '</li>'; } // Store the tab index \Cache::set('tabindex', $tabindex); return $return . ' </ul>'; }
/** * Generate the widget and return it as string * * @return string */ public function generate() { $this->import('Database'); $arrButtons = array('edit', 'copy', 'delete', 'enable', 'drag', 'up', 'down'); $strCommand = 'cmd_' . $this->strField; // Change the order if (\Input::get($strCommand) && is_numeric(\Input::get('cid')) && \Input::get('id') == $this->currentRecord) { switch (\Input::get($strCommand)) { case 'copy': $this->varValue = array_duplicate($this->varValue, \Input::get('cid')); break; case 'up': $this->varValue = array_move_up($this->varValue, \Input::get('cid')); break; case 'down': $this->varValue = array_move_down($this->varValue, \Input::get('cid')); break; case 'delete': $this->varValue = array_delete($this->varValue, \Input::get('cid')); break; } } // Get all modules of the current theme $objModules = $this->Database->prepare("SELECT id, name, type FROM tl_module WHERE pid=(SELECT pid FROM " . $this->strTable . " WHERE id=?) ORDER BY name")->execute($this->currentRecord); // Add the articles module $modules[] = array('id' => 0, 'name' => $GLOBALS['TL_LANG']['MOD']['article'][0], 'type' => 'article'); if ($objModules->numRows) { $modules = array_merge($modules, $objModules->fetchAllAssoc()); } $GLOBALS['TL_LANG']['FMD']['article'] = $GLOBALS['TL_LANG']['MOD']['article']; // Add the module type (see #3835) foreach ($modules as $k => $v) { $v['type'] = $GLOBALS['TL_LANG']['FMD'][$v['type']][0]; $modules[$k] = $v; } $objRow = $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE id=?")->limit(1)->execute($this->currentRecord); // Show all columns and filter in PageRegular (see #3273) $cols = array('header', 'left', 'right', 'main', 'footer'); $arrSections = trimsplit(',', $objRow->sections); // Add custom page sections if (!empty($arrSections) && is_array($arrSections)) { $cols = array_merge($cols, $arrSections); } // Get the new value if (\Input::post('FORM_SUBMIT') == $this->strTable) { $this->varValue = \Input::post($this->strId); } // Make sure there is at least an empty array if (!is_array($this->varValue) || !$this->varValue[0]) { $this->varValue = array(''); } else { $arrCols = array(); // Initialize the sorting order foreach ($cols as $col) { $arrCols[$col] = array(); } foreach ($this->varValue as $v) { $arrCols[$v['col']][] = $v; } $this->varValue = array(); foreach ($arrCols as $arrCol) { $this->varValue = array_merge($this->varValue, $arrCol); } } // Save the value if (\Input::get($strCommand) || \Input::post('FORM_SUBMIT') == $this->strTable) { $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord); // Reload the page if (is_numeric(\Input::get('cid')) && \Input::get('id') == $this->currentRecord) { $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', \Environment::get('request')))); } } // Initialize the tab index if (!\Cache::has('tabindex')) { \Cache::set('tabindex', 1); } $tabindex = \Cache::get('tabindex'); // Add the label and the return wizard $return = '<table id="ctrl_' . $this->strId . '" class="tl_modulewizard"> <thead> <tr> <th>' . $GLOBALS['TL_LANG']['MSC']['mw_module'] . '</th> <th>' . $GLOBALS['TL_LANG']['MSC']['mw_column'] . '</th> <th> </th> </tr> </thead> <tbody class="sortable" data-tabindex="' . $tabindex . '">'; // Add the input fields for ($i = 0, $c = count($this->varValue); $i < $c; $i++) { $options = ''; // Add modules foreach ($modules as $v) { $options .= '<option value="' . specialchars($v['id']) . '"' . static::optionSelected($v['id'], $this->varValue[$i]['mod']) . '>' . $v['name'] . ' [' . $v['type'] . ']</option>'; } $return .= ' <tr> <td><select name="' . $this->strId . '[' . $i . '][mod]" class="tl_select tl_chosen" tabindex="' . $tabindex++ . '" onfocus="Backend.getScrollOffset()" onchange="Backend.updateModuleLink(this)">' . $options . '</select></td>'; $options = ''; // Add columns foreach ($cols as $v) { $options .= '<option value="' . specialchars($v) . '"' . static::optionSelected($v, $this->varValue[$i]['col']) . '>' . (isset($GLOBALS['TL_LANG']['COLS'][$v]) && !is_array($GLOBALS['TL_LANG']['COLS'][$v]) ? $GLOBALS['TL_LANG']['COLS'][$v] : $v) . '</option>'; } $return .= ' <td><select name="' . $this->strId . '[' . $i . '][col]" class="tl_select_column" tabindex="' . $tabindex++ . '" onfocus="Backend.getScrollOffset()">' . $options . '</select></td> <td>'; // Add buttons foreach ($arrButtons as $button) { $class = $button == 'up' || $button == 'down' ? ' class="button-move"' : ''; if ($button == 'edit') { $return .= ' <a href="contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->varValue[$i]['mod'] . '&popup=1&rt=' . REQUEST_TOKEN . '&nb=1" title="' . specialchars($GLOBALS['TL_LANG']['tl_layout']['edit_module']) . '" class="module_link" ' . ($this->varValue[$i]['mod'] > 0 ? '' : ' style="display:none"') . ' onclick="Backend.openModalIframe({\'width\':768,\'title\':\'' . specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['tl_layout']['edit_module'])) . '\',\'url\':this.href});return false">' . \Image::getHtml('edit.gif') . '</a>' . \Image::getHtml('edit_.gif', '', 'class="module_image"' . ($this->varValue[$i]['mod'] > 0 ? ' style="display:none"' : '')); } elseif ($button == 'drag') { $return .= ' ' . \Image::getHtml('drag.gif', '', 'class="drag-handle" title="' . sprintf($GLOBALS['TL_LANG']['MSC']['move']) . '"'); } elseif ($button == 'enable') { $return .= ' ' . \Image::getHtml($this->varValue[$i]['enable'] ? 'visible.gif' : 'invisible.gif', '', 'class="mw_enable" title="' . sprintf($GLOBALS['TL_LANG']['MSC']['mw_enable']) . '"') . '<input name="' . $this->strId . '[' . $i . '][enable]" type="checkbox" class="tl_checkbox mw_enable" value="1" tabindex="' . $tabindex++ . '" onfocus="Backend.getScrollOffset()"' . ($this->varValue[$i]['enable'] ? ' checked' : '') . '>'; } else { $return .= ' <a href="' . $this->addToUrl('&' . $strCommand . '=' . $button . '&cid=' . $i . '&id=' . $this->currentRecord) . '"' . $class . ' title="' . specialchars($GLOBALS['TL_LANG']['MSC']['mw_' . $button]) . '" onclick="Backend.moduleWizard(this,\'' . $button . '\',\'ctrl_' . $this->strId . '\');return false">' . \Image::getHtml($button . '.gif', $GLOBALS['TL_LANG']['MSC']['mw_' . $button], 'class="tl_listwizard_img"') . '</a>'; } } $return .= '</td> </tr>'; } // Store the tab index \Cache::set('tabindex', $tabindex); return $return . ' </tbody> </table>'; }
/** * Generate the widget and return it as string * * @return string */ public function generate() { $arrColButtons = array('ccopy', 'cmovel', 'cmover', 'cdelete'); $arrRowButtons = array('rcopy', 'rdrag', 'rup', 'rdown', 'rdelete'); $strCommand = 'cmd_' . $this->strField; // Change the order if (\Input::get($strCommand) && is_numeric(\Input::get('cid')) && \Input::get('id') == $this->currentRecord) { $this->import('Database'); switch (\Input::get($strCommand)) { case 'ccopy': for ($i = 0, $c = count($this->varValue); $i < $c; $i++) { $this->varValue[$i] = array_duplicate($this->varValue[$i], \Input::get('cid')); } break; case 'cmovel': for ($i = 0, $c = count($this->varValue); $i < $c; $i++) { $this->varValue[$i] = array_move_up($this->varValue[$i], \Input::get('cid')); } break; case 'cmover': for ($i = 0, $c = count($this->varValue); $i < $c; $i++) { $this->varValue[$i] = array_move_down($this->varValue[$i], \Input::get('cid')); } break; case 'cdelete': for ($i = 0, $c = count($this->varValue); $i < $c; $i++) { $this->varValue[$i] = array_delete($this->varValue[$i], \Input::get('cid')); } break; case 'rcopy': $this->varValue = array_duplicate($this->varValue, \Input::get('cid')); break; case 'rup': $this->varValue = array_move_up($this->varValue, \Input::get('cid')); break; case 'rdown': $this->varValue = array_move_down($this->varValue, \Input::get('cid')); break; case 'rdelete': $this->varValue = array_delete($this->varValue, \Input::get('cid')); break; } $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord); $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', \Environment::get('request')))); } // Make sure there is at least an empty array if (!is_array($this->varValue) || empty($this->varValue)) { $this->varValue = array(array('')); } // Initialize the tab index if (!\Cache::has('tabindex')) { \Cache::set('tabindex', 1); } $tabindex = \Cache::get('tabindex'); // Begin the table $return = '<div id="tl_tablewizard"> <table id="ctrl_' . $this->strId . '" class="tl_tablewizard"> <thead> <tr>'; // Add column buttons for ($i = 0, $c = count($this->varValue[0]); $i < $c; $i++) { $return .= ' <td style="text-align:center; white-space:nowrap">'; // Add column buttons foreach ($arrColButtons as $button) { $return .= '<a href="' . $this->addToUrl('&' . $strCommand . '=' . $button . '&cid=' . $i . '&id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['tw_' . $button]) . '" onclick="Backend.tableWizard(this,\'' . $button . '\',\'ctrl_' . $this->strId . '\');return false">' . \Image::getHtml(substr($button, 1) . '.gif', $GLOBALS['TL_LANG']['MSC']['tw_' . $button], 'class="tl_tablewizard_img"') . '</a> '; } $return .= '</td>'; } $return .= ' <td></td> </tr> </thead> <tbody class="sortable" data-tabindex="' . $tabindex . '">'; // Add rows for ($i = 0, $c = count($this->varValue); $i < $c; $i++) { $return .= ' <tr>'; // Add cells for ($j = 0, $d = count($this->varValue[$i]); $j < $d; $j++) { $return .= ' <td class="tcontainer"><textarea name="' . $this->strId . '[' . $i . '][' . $j . ']" class="tl_textarea noresize" tabindex="' . $tabindex++ . '" rows="' . $this->intRows . '" cols="' . $this->intCols . '"' . $this->getAttributes() . '>' . specialchars($this->varValue[$i][$j]) . '</textarea></td>'; } $return .= ' <td style="white-space:nowrap">'; // Add row buttons foreach ($arrRowButtons as $button) { $class = $button == 'rup' || $button == 'rdown' ? ' class="button-move"' : ''; if ($button == 'rdrag') { $return .= \Image::getHtml('drag.gif', '', 'class="drag-handle" title="' . sprintf($GLOBALS['TL_LANG']['MSC']['move']) . '"'); } else { $return .= '<a href="' . $this->addToUrl('&' . $strCommand . '=' . $button . '&cid=' . $i . '&id=' . $this->currentRecord) . '"' . $class . ' title="' . specialchars($GLOBALS['TL_LANG']['MSC']['tw_' . $button]) . '" onclick="Backend.tableWizard(this,\'' . $button . '\',\'ctrl_' . $this->strId . '\');return false">' . \Image::getHtml(substr($button, 1) . '.gif', $GLOBALS['TL_LANG']['MSC']['tw_' . $button], 'class="tl_tablewizard_img"') . '</a> '; } } $return .= '</td> </tr>'; } // Store the tab index \Cache::set('tabindex', $tabindex); $return .= ' </tbody> </table> </div> <script>Backend.tableWizardResize()</script>'; return $return; }
/** * Generate the widget and return it as string * @return string */ public function generate() { $arrButtons = array('copy', 'up', 'down', 'delete'); $strCommand = 'cmd_' . $this->strField; // Change the order if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) { $this->import('Database'); switch ($this->Input->get($strCommand)) { case 'copy': $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid')); break; case 'up': $this->varValue = array_move_up($this->varValue, $this->Input->get('cid')); break; case 'down': $this->varValue = array_move_down($this->varValue, $this->Input->get('cid')); break; case 'delete': $this->varValue = array_delete($this->varValue, $this->Input->get('cid')); break; } $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord); $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', $this->Environment->request))); } // Make sure there is at least an empty array if (!is_array($this->varValue) || count($this->varValue) < 1) { $this->varValue = array(''); } $tabindex = 0; $return .= '<ul id="ctrl_' . $this->strId . '" class="tl_listwizard">'; // Add input fields for ($i = 0; $i < count($this->varValue); $i++) { $return .= ' <li><input type="text" name="' . $this->strId . '[]" class="tl_text" tabindex="' . ++$tabindex . '" value="' . specialchars($this->varValue[$i]) . '"' . $this->getAttributes() . '> '; // Add buttons foreach ($arrButtons as $button) { $return .= '<a href="' . $this->addToUrl('&' . $strCommand . '=' . $button . '&cid=' . $i . '&id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['lw_' . $button]) . '" onclick="Backend.listWizard(this, \'' . $button . '\', \'ctrl_' . $this->strId . '\'); return false;">' . $this->generateImage($button . '.gif', $GLOBALS['TL_LANG']['MSC']['lw_' . $button], 'class="tl_listwizard_img"') . '</a> '; } $return .= '</li>'; } return $return . ' </ul>'; }
/** * Generate the widget and return it as string * @return string */ public function generate() { // load the callback data if there's any (do not do this in __set() already because then we don't have access to currentRecord) if (is_array($this->arrCallback)) { $this->import($this->arrCallback[0]); $this->columnFields = $this->{$this->arrCallback[0]}->{$this->arrCallback[1]}($this); } // use BE script in FE for now $GLOBALS['TL_JAVASCRIPT']['mcw'] = $GLOBALS['TL_CONFIG']['debugMode'] ? 'system/modules/multicolumnwizard/html/js/multicolumnwizard_be_src.js' : 'system/modules/multicolumnwizard/html/js/multicolumnwizard_be.js'; $GLOBALS['TL_CSS']['mcw'] = $GLOBALS['TL_CONFIG']['debugMode'] ? 'system/modules/multicolumnwizard/html/css/multicolumnwizard_src.css' : 'system/modules/multicolumnwizard/html/css/multicolumnwizard.css'; $this->strCommand = 'cmd_' . $this->strField; // Change the order if ($this->Input->get($this->strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) { switch ($this->Input->get($this->strCommand)) { case 'copy': $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid')); break; case 'up': $this->varValue = array_move_up($this->varValue, $this->Input->get('cid')); break; case 'down': $this->varValue = array_move_down($this->varValue, $this->Input->get('cid')); break; case 'delete': $this->varValue = array_delete($this->varValue, $this->Input->get('cid')); break; } // Save in File if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer'] == 'File') { $this->Config->update(sprintf("\$GLOBALS['TL_CONFIG']['%s']", $this->strField), serialize($this->varValue)); // Reload the page $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($this->strCommand, '/') . '=[^&]*/i', '', $this->Environment->request))); } else { if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer'] == 'Table') { if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['save_callback'])) { $dataContainer = 'DC_' . $GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer']; // If less than 3.X, we must load the class by hand. if (version_compare(VERSION, '3.0', '<')) { require_once sprintf('%s/system/drivers/%s.php', TL_ROOT, $dataContainer); } $dc = new $dataContainer($this->strTable); $dc->field = $objWidget->id; $dc->inputName = $objWidget->id; foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['save_callback'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1](serialize($this->varValue), $dc); } } else { $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord); } // Reload the page $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($this->strCommand, '/') . '=[^&]*/i', '', $this->Environment->request))); } else { // What to do here? } } } $arrUnique = array(); $arrDatepicker = array(); $arrColorpicker = array(); $arrTinyMCE = array(); $arrHeaderItems = array(); foreach ($this->columnFields as $strKey => $arrField) { // Store unique fields if ($arrField['eval']['unique']) { $arrUnique[] = $strKey; } // Store date picker fields if ($arrField['eval']['datepicker']) { $arrDatepicker[] = $strKey; } // Store color picker fields if ($arrField['eval']['colorpicker']) { $arrColorpicker[] = $strKey; } // Store tiny mce fields if ($arrField['eval']['rte'] && strncmp($arrField['eval']['rte'], 'tiny', 4) === 0) { foreach ($this->varValue as $row => $value) { $tinyId = 'ctrl_' . $this->strField . '_row' . $row . '_' . $strKey; $GLOBALS['TL_RTE']['tinyMCE'][$tinyId] = array('id' => $tinyId, 'file' => 'tinyMCE', 'type' => null); } $arrTinyMCE[] = $strKey; } if ($arrField['inputType'] == 'hidden') { continue; } } $intNumberOfRows = max(count($this->varValue), 1); // always show the minimum number of rows if set if ($this->minCount && $intNumberOfRows < $this->minCount) { $intNumberOfRows = $this->minCount; } $arrItems = array(); $arrHiddenHeader = array(); // Add input fields for ($i = 0; $i < $intNumberOfRows; $i++) { $this->activeRow = $i; $strHidden = ''; // Walk every column foreach ($this->columnFields as $strKey => $arrField) { $strWidget = ''; $blnHiddenBody = false; if ($arrField['eval']['hideHead'] == true) { $arrHiddenHeader[$strKey] = true; } // load row specific data (useful for example for default values in different rows) if (isset($this->arrRowSpecificData[$i][$strKey])) { $arrField = array_merge($arrField, $this->arrRowSpecificData[$i][$strKey]); } $objWidget = $this->initializeWidget($arrField, $i, $strKey, $this->varValue[$i][$strKey]); // load errors if there are any if (!empty($this->arrWidgetErrors[$strKey][$i])) { foreach ($this->arrWidgetErrors[$strKey][$i] as $strErrorMsg) { $objWidget->addError($strErrorMsg); } } if ($objWidget === null) { continue; } elseif (is_string($objWidget)) { $strWidget = $objWidget; } elseif ($arrField['inputType'] == 'hidden') { $strHidden .= $objWidget->generate(); continue; } elseif ($arrField['eval']['hideBody'] == true || $arrField['eval']['hideHead'] == true) { if ($arrField['eval']['hideBody'] == true) { $blnHiddenBody = true; } $strWidget = $objWidget->parse(); } else { $datepicker = ''; $colorpicker = ''; $tinyMce = ''; // Datepicker if ($arrField['eval']['datepicker']) { $rgxp = $arrField['eval']['rgxp']; $format = $GLOBALS['TL_CONFIG'][$rgxp . 'Format']; switch ($rgxp) { case 'datim': $time = ",\n timePicker:true"; break; case 'time': $time = ",\n timePickerOnly:true"; break; default: $time = ''; break; } $datepicker = ' <img src="system/modules/multicolumnwizard/html/img/datepicker.gif" width="20" height="20" alt="" id="toggle_' . $objWidget->id . '" style="vertical-align:-6px;"> <script> window.datepicker_' . $this->strName . '_' . $strKey . ' = new DatePicker(\'#ctrl_' . $objWidget->id . '\', { allowEmpty:true, toggleElements:\'#toggle_' . $objWidget->id . '\', pickerClass:\'datepicker_dashboard\', format:\'' . $format . '\', inputOutputFormat:\'' . $format . '\', positionOffset:{x:130,y:-185}' . $time . ', startDay:' . $GLOBALS['TL_LANG']['MSC']['weekOffset'] . ', days:[\'' . implode("','", $GLOBALS['TL_LANG']['DAYS']) . '\'], dayShort:' . $GLOBALS['TL_LANG']['MSC']['dayShortLength'] . ', months:[\'' . implode("','", $GLOBALS['TL_LANG']['MONTHS']) . '\'], monthShort:' . $GLOBALS['TL_LANG']['MSC']['monthShortLength'] . ' }); </script>'; $datepicker = $this->getMcWDatePickerString($objWidget->id, $strKey, $rgxp); /* $datepicker = '<script> window.addEvent(\'domready\', function() { ' . sprintf($this->getDatePickerString(), 'ctrl_' . $objWidget->strId) . ' }); </script>'; */ } // Color picker if ($arrField['eval']['colorpicker']) { // Support single fields as well (see #5240) //$strKey = $arrData['eval']['multiple'] ? $this->strField . '_0' : $this->strField; $colorpicker = ' ' . \Image::getHtml('pickcolor.gif', $GLOBALS['TL_LANG']['MSC']['colorpicker'], 'style="vertical-align:top;cursor:pointer" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['colorpicker']) . '" id="moo_' . $objWidget->id . '"') . ' <script> window.addEvent("domready", function() { new MooRainbow("moo_' . $objWidget->id . '", { id: "ctrl_' . $objWidget->id . '", startColor: ((cl = $("ctrl_' . $objWidget->id . '").value.hexToRgb(true)) ? cl : [255, 0, 0]), imgPath: "assets/mootools/colorpicker/' . $GLOBALS['TL_ASSETS']['COLORPICKER'] . '/images/", onComplete: function(color) { $("ctrl_' . $objWidget->id . '").value = color.hex.replace("#", ""); } }); }); </script>'; } // Tiny MCE if ($arrField['eval']['rte'] && strncmp($arrField['eval']['rte'], 'tiny', 4) === 0) { $tinyMce = $this->getMcWTinyMCEString($objWidget->id, $arrField); $arrField['eval']['tl_class'] .= ' tinymce'; } // Add custom wizard if (is_array($arrField['wizard'])) { $wizard = ''; $dataContainer = 'DC_' . $GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer']; // If less than 3.X, we must load the class by hand. if (version_compare(VERSION, '3.0', '<')) { require_once sprintf('%s/system/drivers/%s.php', TL_ROOT, $dataContainer); } $dc = new $dataContainer($this->strTable); $dc->field = $objWidget->id; $dc->inputName = $objWidget->id; $dc->value = $objWidget->value; foreach ($arrField['wizard'] as $callback) { $this->import($callback[0]); $wizard .= $this->{$callback}[0]->{$callback}[1]($dc, $objWidget); } $objWidget->wizard = $wizard; } $strWidget = $objWidget->parse() . $datepicker . $colorpicker . $tinyMce; } // Build array of items if ($arrField['eval']['columnPos'] != '') { $arrItems[$i][$objWidget->columnPos]['entry'] .= $strWidget; $arrItems[$i][$objWidget->columnPos]['valign'] = $arrField['eval']['valign']; $arrItems[$i][$objWidget->columnPos]['tl_class'] = $arrField['eval']['tl_class']; $arrItems[$i][$objWidget->columnPos]['hide'] = $blnHiddenBody; } else { $arrItems[$i][$strKey] = array('entry' => $strWidget, 'valign' => $arrField['eval']['valign'], 'tl_class' => $arrField['eval']['tl_class'], 'hide' => $blnHiddenBody); } } } $strOutput = ''; if ($this->blnTableless) { $strOutput = $this->generateDiv($arrUnique, $arrDatepicker, $arrColorpicker, $strHidden, $arrItems, $arrHiddenHeader); } else { if ($this->columnTemplate != '') { $strOutput = $this->generateTemplateOutput($arrUnique, $arrDatepicker, $arrColorpicker, $strHidden, $arrItems, $arrHiddenHeader); } else { $strOutput = $this->generateTable($arrUnique, $arrDatepicker, $arrColorpicker, $strHidden, $arrItems, $arrHiddenHeader); } } return $strOutput; }
/** * Generate the widget and return it as string * @return string */ public function generate() { if (is_array($GLOBALS['TL_JAVASCRIPT'])) { array_insert($GLOBALS['TL_JAVASCRIPT'], 1, 'system/modules/MultiTextWizard/html/js/multitext.js'); } else { $GLOBALS['TL_JAVASCRIPT'] = array('system/modules/MultiTextWizard/html/js/multitext.js'); } $arrButtons = array('rnew', 'rcopy', 'rup', 'rdown', 'rdelete'); $strCommand = 'cmd_' . $this->strField; $emptyarray = array(); for ($i = 0; $i < count($this->arrColumns); $i++) { array_push($emptyarray, ''); } // Change the order if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) { $this->import('Database'); switch ($this->Input->get($strCommand)) { case 'rnew': array_insert($this->varValue, $this->Input->get('cid') + 1, array($emptyarray)); break; case 'rcopy': $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid')); break; case 'rup': $this->varValue = array_move_up($this->varValue, $this->Input->get('cid')); break; case 'rdown': $this->varValue = array_move_down($this->varValue, $this->Input->get('cid')); break; case 'rdelete': $this->varValue = array_delete($this->varValue, $this->Input->get('cid')); break; } $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord); $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', $this->Environment->request))); } // Make sure there is at least an empty array if (!is_array($this->varValue) || !$this->varValue[0]) { $this->varValue = array($emptyarray); } $objTemplate = new BackendTemplate($this->strMultitextTemplate); $objTemplate->strId = $this->strId; $objTemplate->attributes = $this->getAttributes(); $objTemplate->arrColumns = $this->arrColumns; $objTemplate->varValue = $this->varValue; $objTemplate->arrMultiErrors = $this->arrMultiErrors; $buttons = array(); $hasTitles = array_key_exists('buttonTitles', $this->arrConfiguration) && is_array($this->arrConfiguration['buttonTitles']); foreach ($arrButtons as $button) { $buttontitle = $hasTitles && array_key_exists($button, $this->arrConfiguration['buttonTitles']) ? $this->arrConfiguration['buttonTitles'][$button] : $GLOBALS['TL_LANG'][$this->strTable][$button][0]; array_push($buttons, array('href' => $this->addToUrl('&' . $strCommand . '=' . $button . '&cid=%s&id=' . $this->currentRecord), 'title' => specialchars($buttontitle), 'onclick' => 'MultiText.multitextWizard(this, \'' . $button . '\', \'ctrl_' . $this->strId . '\'); return false;', 'img' => $this->generateImage(substr($button, 1) . '.gif', $GLOBALS['TL_LANG'][$this->strTable][$button][0], 'class="tl_multitextwizard_img"'))); } $objTemplate->arrButtons = $buttons; return $objTemplate->parse(); }
/** * Generate the widget and return it as string * @return string */ public function generate() { $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/isotope/html/backend.js'; if (!is_array($this->varValue)) { $this->varValue = array(array('name' => 'gallery'), array('name' => 'thumbnail'), array('name' => 'medium'), array('name' => 'large')); } $arrButtons = array('copy', 'delete'); $strCommand = 'cmd_' . $this->strField; // Change the order if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) { switch ($this->Input->get($strCommand)) { case 'copy': $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid')); break; case 'delete': $this->varValue = array_delete($this->varValue, $this->Input->get('cid')); break; } } // Begin table $return .= '<table class="tl_imagewatermarkwizard" id="ctrl_' . $this->strId . '"> <thead> <tr> <th>' . $GLOBALS['TL_LANG'][$this->strTable]['iwName'] . '</th> <th>' . $GLOBALS['TL_LANG'][$this->strTable]['iwWidth'] . '</th> <th>' . $GLOBALS['TL_LANG'][$this->strTable]['iwHeight'] . '</th> <th>' . $GLOBALS['TL_LANG'][$this->strTable]['iwMode'] . '</th> <th>' . $GLOBALS['TL_LANG'][$this->strTable]['iwWatermark'] . '</th> <th>' . $GLOBALS['TL_LANG'][$this->strTable]['iwPosition'] . '</th> <th> </th> </tr> </thead> <tbody>'; foreach ($this->varValue as $i => $size) { $arrModes = array(); $arrPositions = array(); foreach ($this->arrOptions as $arrOption) { $arrModes[] = sprintf('<option value="%s"%s>%s</option>', specialchars($arrOption['value']), is_array($this->varValue[$i]) && $this->varValue[$i]['mode'] == $arrOption['value'] ? ' selected="selected"' : '', $arrOption['label']); } foreach (array('tl', 'tc', 'tr', 'bl', 'bc', 'br', 'cc') as $option) { $arrPositions[] = sprintf('<option value="%s"%s>%s</option>', specialchars($option), is_array($this->varValue[$i]) && $this->varValue[$i]['position'] == $option ? ' selected="selected"' : '', $GLOBALS['TL_LANG'][$this->strTable][$option]); } $filepicker = $this->generateImage('pickfile.gif', $GLOBALS['TL_LANG']['MSC']['filepicker'], 'style="vertical-align:top; cursor:pointer;" onclick="Backend.pickFile(this.getPrevious())"'); $return .= ' <tr> <td><input type="text" name="' . $this->strName . '[' . $i . '][name]" id="' . $this->strId . '_name_' . $i . '" class="tl_text_4" value="' . specialchars($this->varValue[$i]['name']) . '""></td> <td><input type="text" name="' . $this->strName . '[' . $i . '][width]" id="' . $this->strId . '_width_' . $i . '" class="tl_text_4" value="' . specialchars($this->varValue[$i]['width']) . '""></td> <td><input type="text" name="' . $this->strName . '[' . $i . '][height]" id="' . $this->strId . '_height_' . $i . '" class="tl_text_4" value="' . specialchars($this->varValue[$i]['height']) . '""></td> <td><select name="' . $this->strName . '[' . $i . '][mode]" id="' . $this->strId . '_mode_' . $i . '" class="tl_select_interval" onfocus="Backend.getScrollOffset();">' . implode(' ', $arrModes) . '</select></td> <td><input type="text" name="' . $this->strName . '[' . $i . '][watermark]" id="' . $this->strId . '_watermark_' . $i . '" class="tl_text_2" value="' . specialchars($this->varValue[$i]['watermark']) . '"">' . $filepicker . '</td> <td><select name="' . $this->strName . '[' . $i . '][position]" id="' . $this->strId . '_position_' . $i . '" class="tl_select_unit" onfocus="Backend.getScrollOffset();">' . implode(' ', $arrPositions) . '</select></td>'; $return .= ' <td>'; foreach ($arrButtons as $button) { $return .= '<a href="' . $this->addToUrl('&' . $strCommand . '=' . $button . '&cid=' . $i . '&id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['wz_' . $button]) . '" onclick="Isotope.imageWatermarkWizard(this, \'' . $button . '\', \'ctrl_' . $this->strId . '\'); return false;">' . $this->generateImage($button . '.gif', $GLOBALS['TL_LANG'][$this->strTable]['wz_' . $button], 'class="tl_listwizard_img"') . '</a> '; } $return .= '</td> </tr>'; } return $return . ' </tbody> </table>'; }
/** * Generate the widget and return it as string * @return string */ public function generate() { // load the callback data if there's any (do not do this in __set() already because then we don't have access to currentRecord) if (is_array($this->arrCallback)) { $this->import($this->arrCallback[0]); $this->columnFields = $this->{$this->arrCallback[0]}->{$this->arrCallback[1]}($this); } $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/multicolumnwizard/html/js/multicolumnwizard_' . strtolower(TL_MODE) . '.js'; $GLOBALS['TL_CSS'][] = 'system/modules/multicolumnwizard/html/css/multicolumnwizard.css'; $this->strCommand = 'cmd_' . $this->strField; // Change the order if ($this->Input->get($this->strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) { switch ($this->Input->get($this->strCommand)) { case 'copy': $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid')); break; case 'up': $this->varValue = array_move_up($this->varValue, $this->Input->get('cid')); break; case 'down': $this->varValue = array_move_down($this->varValue, $this->Input->get('cid')); break; case 'delete': $this->varValue = array_delete($this->varValue, $this->Input->get('cid')); break; } if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer'] == 'File') { $this->Config->update(sprintf("\$GLOBALS['TL_CONFIG']['%s']", $this->strField), serialize($this->varValue)); } else { if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['save_callback'])) { $dataContainer = 'DC_' . $GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer']; require_once sprintf('%s/system/drivers/%s.php', TL_ROOT, $dataContainer); $dc = new $dataContainer($this->strTable); $dc->field = $objWidget->id; $dc->inputName = $objWidget->id; foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['save_callback'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1](serialize($this->varValue), $dc); } } else { $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord); } } // Reload the page $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($this->strCommand, '/') . '=[^&]*/i', '', $this->Environment->request))); } $arrUnique = array(); $arrDatepicker = array(); $arrHeaderItems = array(); foreach ($this->columnFields as $strKey => $arrField) { // Store unique fields if ($arrField['eval']['unique']) { $arrUnique[] = $strKey; } // Store date picker fields if ($arrField['eval']['datepicker']) { $arrDatepicker[] = $strKey; } if ($arrField['inputType'] == 'hidden') { continue; } } $intNumberOfRows = max(count($this->varValue), 1); // always show the minimum number of rows if set if ($this->minCount && $intNumberOfRows < $this->minCount) { $intNumberOfRows = $this->minCount; } $arrItems = array(); // Add input fields for ($i = 0; $i < $intNumberOfRows; $i++) { $this->activeRow = $i; $strHidden = ''; // Walk every column foreach ($this->columnFields as $strKey => $arrField) { $strWidget = ''; // load row specific data (useful for example for default values in different rows) if (isset($this->arrRowSpecificData[$i][$strKey])) { $arrField = array_merge($arrField, $this->arrRowSpecificData[$i][$strKey]); } $objWidget = $this->initializeWidget($arrField, $i, $strKey, $this->varValue[$i][$strKey]); // load errors if there are any if (!empty($this->arrWidgetErrors[$strKey][$i])) { foreach ($this->arrWidgetErrors[$strKey][$i] as $strErrorMsg) { $objWidget->addError($strErrorMsg); } } if ($objWidget === null) { continue; } elseif (is_string($objWidget)) { $strWidget = $objWidget; } elseif ($arrField['inputType'] == 'hidden') { $strHidden .= $objWidget->generate(); continue; } else { $datepicker = ''; // Datepicker if ($arrField['eval']['datepicker']) { $rgxp = $arrField['eval']['rgxp']; $format = $GLOBALS['TL_CONFIG'][$rgxp . 'Format']; switch ($rgxp) { case 'datim': $time = ",\n timePicker:true"; break; case 'time': $time = ",\n timePickerOnly:true"; break; default: $time = ''; break; } $datepicker = ' <img src="plugins/datepicker/icon.gif" width="20" height="20" alt="" id="toggle_' . $objWidget->id . '" style="vertical-align:-6px;"> <script> window.datepicker_' . $this->strName . '_' . $strKey . ' = new DatePicker(\'#ctrl_' . $objWidget->id . '\', { allowEmpty:true, toggleElements:\'#toggle_' . $objWidget->id . '\', pickerClass:\'datepicker_dashboard\', format:\'' . $format . '\', inputOutputFormat:\'' . $format . '\', positionOffset:{x:130,y:-185}' . $time . ', startDay:' . $GLOBALS['TL_LANG']['MSC']['weekOffset'] . ', days:[\'' . implode("','", $GLOBALS['TL_LANG']['DAYS']) . '\'], dayShort:' . $GLOBALS['TL_LANG']['MSC']['dayShortLength'] . ', months:[\'' . implode("','", $GLOBALS['TL_LANG']['MONTHS']) . '\'], monthShort:' . $GLOBALS['TL_LANG']['MSC']['monthShortLength'] . ' }); </script>'; $datepicker = $this->getMcWDatePickerString($objWidget->id, $strKey, $rgxp); /* $datepicker = '<script> window.addEvent(\'domready\', function() { ' . sprintf($this->getDatePickerString(), 'ctrl_' . $objWidget->strId) . ' }); </script>'; */ } // Add custom wizard if (is_array($arrField['wizard'])) { $wizard = ''; $dataContainer = 'DC_' . $GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer']; require_once sprintf('%s/system/drivers/%s.php', TL_ROOT, $dataContainer); $dc = new $dataContainer($this->strTable); $dc->field = $objWidget->id; $dc->inputName = $objWidget->id; foreach ($arrField['wizard'] as $callback) { $this->import($callback[0]); $wizard .= $this->{$callback}[0]->{$callback}[1]($dc, $objWidget); } $objWidget->wizard = $wizard; } $strWidget = $objWidget->parse() . $datepicker; } // Build array of items if ($arrField['eval']['columnPos'] != '') { $arrItems[$i][$objWidget->columnPos]['entry'] .= $strWidget; $arrItems[$i][$objWidget->columnPos]['valign'] = $arrField['eval']['valign']; $arrItems[$i][$objWidget->columnPos]['tl_class'] = $arrField['eval']['tl_class']; } else { $arrItems[$i][$strKey] = array('entry' => $strWidget, 'valign' => $arrField['eval']['valign'], 'tl_class' => $arrField['eval']['tl_class']); } } } return $this->blnTableless ? $this->generateDiv($arrUnique, $arrDatepicker, $strHidden, $arrItems) : $this->generateTable($arrUnique, $arrDatepicker, $strHidden, $arrItems); }
/** * Generate the widget and return it as string * @return string */ public function generate() { $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/isotope/html/backend.js'; $this->import('Database'); //allows us to set which buttons can be enabled for this widget. /*foreach($this->enabledFunctions as $v) { $arrButtons[] = $v; }*/ $strCommand = 'cmd_' . $this->strField; // Change the order if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) { switch ($this->Input->get($strCommand)) { case 'copy': $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid')); break; case 'up': $this->varValue = array_move_up($this->varValue, $this->Input->get('cid')); break; case 'down': $this->varValue = array_move_down($this->varValue, $this->Input->get('cid')); break; case 'delete': $this->varValue = array_delete($this->varValue, $this->Input->get('cid')); break; } } $objTaxClasses = $this->Database->execute("SELECT id, name FROM tl_iso_tax_class"); if ($objTaxClasses->numRows) { $arrTaxClasses = $objTaxClasses->fetchAllAssoc(); } if (!is_array($arrTaxClasses) || !count($arrTaxClasses)) { $arrTaxClasses = array(''); } // Get new value if ($this->Input->post('FORM_SUBMIT') == $this->strTable) { $varValue = $this->Input->post($this->strId); } // Make sure there is at least an empty array if (!is_array($this->varValue) || !$this->varValue[0]) { //$this->varValue = array(''); } else { /*foreach($this->varValue as $v) { }*/ } // Save the value if ($this->Input->get($strCommand) || $this->Input->post('FORM_SUBMIT') == $this->strTable) { $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord); // Reload the page if (is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) { $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', $this->Environment->request))); } } // Add label and return wizard $return .= '<table class="tl_optionwizard" id="ctrl_' . $this->strId . '"> <thead>'; if (is_array($this->varValue) && count($this->varValue)) { $return .= ' <tr> <th><strong>' . $GLOBALS['TL_LANG'][$this->strTable]['opLabel'] . '</strong></th> <th><strong>' . $GLOBALS['TL_LANG'][$this->strTable]['opPrice'] . '</strong></th> <th><strong>' . $GLOBALS['TL_LANG'][$this->strTable]['opTaxClass'] . '</strong></th> <th> </th> </tr> </thead> <tbody>'; // Add rows for ($i = 0; $i < count($this->varValue); $i++) { $arrRow = array(); $arrRow = $this->varValue[$i]; $blnEditable = false; if (is_array($arrRow)) { $blnEditable = true; } else { continue; } $return .= '<tr>'; $return .= ' <td>' . $this->varValue[$i]['label'] . '<input type="hidden" name="' . $this->strId . '[' . $i . '][label]" id="' . $this->strId . '_label_' . $i . '" value="' . $this->varValue[$i]['label'] . '"></td>'; $return .= ' <td>' . ($blnEditable ? '<input type="text" name="' . $this->strId . '[' . $i . '][total_price]" id="' . $this->strId . '_total_price_' . $i . '" class="tl_text_3" value="' . specialchars(round($this->varValue[$i]['total_price'], 2)) . '">' : round($this->varValue[$i]['total_price'], 2)) . '</td>'; $options = ''; $options = '<option value=""' . $this->optionSelected(NULL, $this->varValue[$i]['tax_class']) . '>-</option>'; // Add Tax Classes foreach ($arrTaxClasses as $v) { $options .= '<option value="' . specialchars($v['id']) . '"' . $this->optionSelected($v['id'], $this->varValue[$i]['tax_class']) . '>' . $v['name'] . '</option>'; if ($v['id'] == $this->varValue[$i]['tax_class']) { $strTaxLabel = $v['name']; } } $return .= ' <td>' . ($blnEditable ? '<select name="' . $this->strId . '[' . $i . '][tax_class]" class="tl_select_2" onfocus="Backend.getScrollOffset();">' . $options . '</select>' : $strTaxLabel) . '</td>'; $return .= '<td>'; if (is_array($arrButtons)) { foreach ($arrButtons as $button) { $return .= '<a href="' . $this->addToUrl('&' . $strCommand . '=' . $button . '&cid=' . $i . '&id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['wz_' . $button]) . '" onclick="Isotope.surchargeWizard(this, \'' . $button . '\', \'ctrl_' . $this->strId . '\'); return false;">' . $this->generateImage($button . '.gif', $GLOBALS['TL_LANG'][$this->strTable]['wz_' . $button], 'class="tl_listwizard_img"') . '</a> '; } } else { $return .= ' '; } $return .= ' </td> </tr>'; } } else { $return .= ' <tr> <th> </th> </tr> </thead> <tbody> <tr> <td>' . $GLOBALS['TL_LANG']['MSC']['noSurcharges'] . '</td> </tr>'; } return $return . ' </tbody> </table>'; }
/** * Generate the widget and return it as string * @return string */ public function generate() { $arrColButtons = array('ccopy', 'cmovel', 'cmover', 'cdelete'); $arrRowButtons = array('rcopy', 'rup', 'rdown', 'rdelete'); $strCommand = 'cmd_' . $this->strField; // Change the order if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) { $this->import('Database'); switch ($this->Input->get($strCommand)) { case 'ccopy': for ($i = 0; $i < count($this->varValue); $i++) { $this->varValue[$i] = array_duplicate($this->varValue[$i], $this->Input->get('cid')); } break; case 'cmovel': for ($i = 0; $i < count($this->varValue); $i++) { $this->varValue[$i] = array_move_up($this->varValue[$i], $this->Input->get('cid')); } break; case 'cmover': for ($i = 0; $i < count($this->varValue); $i++) { $this->varValue[$i] = array_move_down($this->varValue[$i], $this->Input->get('cid')); } break; case 'cdelete': for ($i = 0; $i < count($this->varValue); $i++) { $this->varValue[$i] = array_delete($this->varValue[$i], $this->Input->get('cid')); } break; case 'rcopy': $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid')); break; case 'rup': $this->varValue = array_move_up($this->varValue, $this->Input->get('cid')); break; case 'rdown': $this->varValue = array_move_down($this->varValue, $this->Input->get('cid')); break; case 'rdelete': $this->varValue = array_delete($this->varValue, $this->Input->get('cid')); break; } $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord); $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', $this->Environment->request))); } // Make sure there is at least an empty array if (!is_array($this->varValue) || count($this->varValue) < 1) { $this->varValue = array(array('')); } // Begin table $return .= '<div id="tl_tablewizard"> <table id="ctrl_' . $this->strId . '" class="tl_tablewizard"> <tbody> <tr>'; // Add column buttons for ($i = 0; $i < count($this->varValue[0]); $i++) { $return .= ' <td style="text-align:center; white-space:nowrap;">'; // Add column buttons foreach ($arrColButtons as $button) { $return .= '<a href="' . $this->addToUrl('&' . $strCommand . '=' . $button . '&cid=' . $i . '&id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['tw_' . $button]) . '" onclick="Backend.tableWizard(this, \'' . $button . '\', \'ctrl_' . $this->strId . '\'); return false;">' . $this->generateImage(substr($button, 1) . '.gif', $GLOBALS['TL_LANG']['MSC']['tw_' . $button], 'class="tl_tablewizard_img"') . '</a> '; } $return .= '</td>'; } $return .= ' <td></td> </tr>'; $tabindex = 0; // Add rows for ($i = 0; $i < count($this->varValue); $i++) { $return .= ' <tr>'; // Add cells for ($j = 0; $j < count($this->varValue[$i]); $j++) { $return .= ' <td class="tcontainer"><textarea name="' . $this->strId . '[' . $i . '][' . $j . ']" class="tl_textarea" tabindex="' . ++$tabindex . '" rows="' . $this->intRows . '" cols="' . $this->intCols . '"' . $this->getAttributes() . '>' . specialchars($this->varValue[$i][$j]) . '</textarea></td>'; } $return .= ' <td style="white-space:nowrap;">'; // Add row buttons foreach ($arrRowButtons as $button) { $return .= '<a href="' . $this->addToUrl('&' . $strCommand . '=' . $button . '&cid=' . $i . '&id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['tw_' . $button]) . '" onclick="Backend.tableWizard(this, \'' . $button . '\', \'ctrl_' . $this->strId . '\'); return false;">' . $this->generateImage(substr($button, 1) . '.gif', $GLOBALS['TL_LANG']['MSC']['tw_' . $button], 'class="tl_tablewizard_img"') . '</a> '; } $return .= '</td> </tr>'; } $return .= ' </tbody> </table> </div> <script> Backend.tableWizardResize(); </script>'; return $return; }
/** * Generate the widget and return it as string * @return string */ public function generate() { // load the callback data if there's any (do not do this in __set() already because then we don't have access to currentRecord) if (is_array($this->arrCallback)) { $this->import($this->arrCallback[0]); $this->columnFields = $this->{$this->arrCallback[0]}->{$this->arrCallback[1]}($this); } $this->strCommand = 'cmd_' . $this->strField; // TODO: Actions if ($this->Input->get($this->strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) { switch ($this->Input->get($this->strCommand)) { case 'copy': $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid')); break; case 'up': $this->varValue = array_move_up($this->varValue, $this->Input->get('cid')); break; case 'down': $this->varValue = array_move_down($this->varValue, $this->Input->get('cid')); break; case 'delete': $this->varValue = array_delete($this->varValue, $this->Input->get('cid')); break; } // Save in File if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer'] == 'File') { $this->Config->update(sprintf("\$GLOBALS['TL_CONFIG']['%s']", $this->strField), serialize($this->varValue)); // Reload the page $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($this->strCommand, '/') . '=[^&]*/i', '', $this->Environment->request))); } else { if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer'] == 'Table') { if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['save_callback'])) { $dataContainer = 'DC_' . $GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer']; // If less than 3.X, we must load the class by hand. if (version_compare(VERSION, '3.0', '<')) { require_once sprintf('%s/system/drivers/%s.php', TL_ROOT, $dataContainer); } $dc = new $dataContainer($this->strTable); $dc->field = $objWidget->id; $dc->inputName = $objWidget->id; foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['save_callback'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1](serialize($this->varValue), $dc); } } else { $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord); } // Reload the page $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($this->strCommand, '/') . '=[^&]*/i', '', $this->Environment->request))); } else { // What to do here? } } } $arrUnique = array(); $arrDatepicker = array(); $arrTinyMCE = array(); $arrHeaderItems = array(); foreach ($this->columnFields as $strKey => $arrField) { // Store unique fields if ($arrField['eval']['unique']) { $arrUnique[] = $strKey; } // Store date picker fields if ($arrField['eval']['datepicker']) { $arrDatepicker[] = $strKey; } // Store tiny mce fields if ($arrField['eval']['rte'] && strncmp($arrField['eval']['rte'], 'tiny', 4) === 0) { foreach ($this->varValue as $row => $value) { $tinyId = 'ctrl_' . $this->strField . '_row' . $row . '_' . $strKey; $GLOBALS['TL_RTE']['tinyMCE'][$tinyId] = array('id' => $tinyId, 'file' => 'tinyMCE', 'type' => null); } $arrTinyMCE[] = $strKey; } if ($arrField['inputType'] == 'hidden') { continue; } } $intNumberOfRows = max(count($this->varValue), 1); // always show the minimum number of rows if set if ($this->minCount && $intNumberOfRows < $this->minCount) { $intNumberOfRows = $this->minCount; } $arrHidden = array(); $arrItems = array(); $arrHiddenHeader = array(); // Add input fields for ($i = 0; $i < $intNumberOfRows; $i++) { $this->activeRow = $i; $strHidden = ''; // Walk every column foreach ($this->columnFields as $strKey => $arrField) { $strWidget = ''; $blnHiddenBody = false; if ($arrField['eval']['hideHead'] == true) { $arrHiddenHeader[$strKey] = true; } // load row specific data (useful for example for default values in different rows) if (isset($this->arrRowSpecificData[$i][$strKey])) { $arrField = array_merge($arrField, $this->arrRowSpecificData[$i][$strKey]); } // styles not needed in frontend, done per css unset($arrField['eval']['style']); $objWidget = $this->initializeWidget($arrField, $i, $strKey, $this->varValue[$i][$strKey]); // load errors if there are any if (!empty($this->arrWidgetErrors[$strKey][$i])) { foreach ($this->arrWidgetErrors[$strKey][$i] as $strErrorMsg) { $objWidget->addError($strErrorMsg); } } if ($objWidget === null) { continue; } elseif ($arrField['inputType'] == 'hidden') { $arrHidden[] = $objWidget; continue; } $arrItems[$i][$strKey] = array('field' => $objWidget); } } if ($this->formTemplate != '') { $strOutput = $this->generateTemplateOutput($arrUnique, $arrDatepicker, $arrHidden, $arrItems, $arrHiddenHeader); } else { $strOutput = $this->generateTable($arrUnique, $arrDatepicker, $arrHidden, $arrItems, $arrHiddenHeader); } return $strOutput; }
/** * Generate the widget and return it as string * @return string */ public function generate() { $this->import('Database'); $arrButtons = array('copy', 'up', 'down', 'delete'); $strCommand = 'cmd_' . $this->strField; // Change the order if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) { switch ($this->Input->get($strCommand)) { case 'copy': $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid')); break; case 'up': $this->varValue = array_move_up($this->varValue, $this->Input->get('cid')); break; case 'down': $this->varValue = array_move_down($this->varValue, $this->Input->get('cid')); break; case 'delete': $this->varValue = array_delete($this->varValue, $this->Input->get('cid')); break; } } // Get all modules of the current theme $objModules = $this->Database->prepare("SELECT id, name, type FROM tl_module WHERE pid=(SELECT pid FROM " . $this->strTable . " WHERE id=?) ORDER BY name")->execute($this->currentRecord); // Add the articles module $modules[] = array('id' => 0, 'name' => $GLOBALS['TL_LANG']['MOD']['article'][0], 'type' => 'article'); if ($objModules->numRows) { $modules = array_merge($modules, $objModules->fetchAllAssoc()); } $GLOBALS['TL_LANG']['FMD']['article'] = $GLOBALS['TL_LANG']['MOD']['article']; // Add the module type (see #3835) foreach ($modules as $k => $v) { $v['type'] = $GLOBALS['TL_LANG']['FMD'][$v['type']][0]; $modules[$k] = $v; } $objRow = $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE id=?")->limit(1)->execute($this->currentRecord); // Show all columns and filter in PageRegular (see #3273) $cols = array('header', 'left', 'right', 'main', 'footer'); $arrSections = deserialize($objRow->sections); // Add custom page sections if (is_array($arrSections) && !empty($arrSections)) { $cols = array_merge($cols, $arrSections); } // Get the new value if ($this->Input->post('FORM_SUBMIT') == $this->strTable) { $this->varValue = $this->Input->post($this->strId); } // Make sure there is at least an empty array if (!is_array($this->varValue) || !$this->varValue[0]) { $this->varValue = array(''); } else { // Initialize the sorting order foreach ($cols as $col) { $arrCols[$col] = array(); } foreach ($this->varValue as $v) { $arrCols[$v['col']][] = $v; } $this->varValue = array(); foreach ($arrCols as $arrCol) { $this->varValue = array_merge($this->varValue, $arrCol); } } // Save the value if ($this->Input->get($strCommand) || $this->Input->post('FORM_SUBMIT') == $this->strTable) { $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord); // Reload the page if (is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) { $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', $this->Environment->request))); } } // Add label and return wizard $return .= '<table id="ctrl_' . $this->strId . '" class="tl_modulewizard"> <thead> <tr> <th>' . $GLOBALS['TL_LANG']['MSC']['mw_module'] . '</th> <th> </th> <th>' . $GLOBALS['TL_LANG']['MSC']['mw_column'] . '</th> <th> </th> </tr> </thead> <tbody>'; // Load the tl_article language file $this->loadLanguageFile('tl_article'); $tabindex = 0; // Add the input fields for ($i = 0; $i < count($this->varValue); $i++) { $options = ''; // Add modules foreach ($modules as $v) { $options .= '<option value="' . specialchars($v['id']) . '"' . $this->optionSelected($v['id'], $this->varValue[$i]['mod']) . '>' . $v['name'] . ' // ' . $v['type'] . '</option>'; } $return .= ' <tr> <td><select name="' . $this->strId . '[' . $i . '][mod]" class="tl_select tl_chosen" tabindex="' . ++$tabindex . '" onfocus="Backend.getScrollOffset()" onchange="Backend.updateModuleLink(this)">' . $options . '</select></td> <td><a href="contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->varValue[$i]['mod'] . '" title="' . specialchars($GLOBALS['TL_LANG']['tl_layout']['edit_module']) . '" class="module_link" style="display:' . ($this->varValue[$i]['mod'] > 0 ? 'inline' : 'none') . '">' . $this->generateImage('edit.gif') . '</a>' . $this->generateImage('edit_.gif', '', 'class="module_image" style="display:' . ($this->varValue[$i]['mod'] > 0 ? 'none' : 'inline') . '"') . '</td>'; $options = ''; // Add columns foreach ($cols as $v) { $options .= '<option value="' . specialchars($v) . '"' . $this->optionSelected($v, $this->varValue[$i]['col']) . '>' . (isset($GLOBALS['TL_LANG']['tl_article'][$v]) && !is_array($GLOBALS['TL_LANG']['tl_article'][$v]) ? $GLOBALS['TL_LANG']['tl_article'][$v] : $v) . '</option>'; } $return .= ' <td><select name="' . $this->strId . '[' . $i . '][col]" class="tl_select_column" tabindex="' . ++$tabindex . '" onfocus="Backend.getScrollOffset()">' . $options . '</select></td> <td>'; // Add buttons foreach ($arrButtons as $button) { $return .= '<a href="' . $this->addToUrl('&' . $strCommand . '=' . $button . '&cid=' . $i . '&id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['mw_' . $button]) . '" onclick="Backend.moduleWizard(this,\'' . $button . '\',\'ctrl_' . $this->strId . '\');return false">' . $this->generateImage($button . '.gif', $GLOBALS['TL_LANG']['MSC']['mw_' . $button], 'class="tl_listwizard_img"') . '</a> '; } $return .= '</td> </tr>'; } return $return . ' </tbody> </table>'; }