protected function getOutput()
 {
     $id = $this->getArg('id', 0, true);
     if (!in_array($this->getContext(), ['module', 'action']) || !is_numeric($id) || $id < 1 || $id > 20) {
         return false;
     }
     $value = $this->getContextData()->getValue('value' . $id);
     if ($this->hasArg('isset') && $this->getArg('isset')) {
         return $value ? 'true' : 'false';
     }
     if ($this->hasArg('widget') && $this->getArg('widget')) {
         if (!$this->environmentIs(self::ENV_INPUT)) {
             return false;
         }
         $select = new rex_category_select();
         if ($this->hasArg('multiple') && $this->getArg('multiple')) {
             $select->setName('REX_INPUT_VALUE[' . $id . '][]');
             $select->setMultiple();
             $select->setSelected(rex_var::toArray($value));
         } else {
             $select->setName('REX_INPUT_VALUE[' . $id . ']');
             $select->setSelected($value);
         }
         if ($this->hasArg('root') && $this->getArg('root')) {
             $select->setRootId(explode(',', $this->getArg('root')));
         }
         $widget = '<div class="rex-select-style">' . $select->get() . '</div>';
         if ($this->hasArg('output') && $this->getArg('output')) {
             $label = $this->hasArg('label') ? $this->getArg('label') : '';
             $widget = Dao::getForm($widget, $label, $this->getArg('output'));
         }
         return self::quote($widget);
     }
     return self::quote(htmlspecialchars($value));
 }
}
$html_block = array();
$values = array();
$values[1] = rex_var::toArray('REX_VALUE[1]');
$values[1]['media_1'] = 'REX_MEDIA[id=1 output=1]';
$values[1]['link_intern'] = 'REX_LINK[id=1 output="id"]';
$values[1]['medialist_1'] = 'REX_MEDIALIST[id=1 output=1]';
$values[2] = rex_var::toArray('REX_VALUE[2]');
$values[2]['media_1'] = 'REX_MEDIA[id=2 output=1]';
$values[2]['link_intern'] = 'REX_LINK[id=2 output="id"]';
$values[2]['medialist_1'] = 'REX_MEDIALIST[id=2 output=1]';
$values[3] = rex_var::toArray('REX_VALUE[3]');
$values[3]['media_1'] = 'REX_MEDIA[id=3 output=1]';
$values[3]['link_intern'] = 'REX_LINK[id=3 output="id"]';
$values[3]['medialist_1'] = 'REX_MEDIALIST[id=3 output=1]';
$values[4] = rex_var::toArray('REX_VALUE[4]');
$values[4]['media_1'] = 'REX_MEDIA[id=4 output=1]';
$values[4]['link_intern'] = 'REX_LINK[id=4 output="id"]';
$values[4]['medialist_1'] = 'REX_MEDIALIST[id=4 output=1]';
if ($grid == '12') {
    unset($values[2]);
    unset($values[3]);
    unset($values[4]);
}
if ($grid == '6_6' || $grid == '8_4' || $grid == '4_8') {
    unset($values[3]);
    unset($values[4]);
}
if ($grid == '4_4_4' || $grid == '6_3_3' || $grid == '3_6_3' || $grid == '3_3_6') {
    unset($values[4]);
}
    protected function getOutput()
    {
        $id = $this->getArg('id', 0, true);
        if (!in_array($this->getContext(), ['module', 'action']) || !is_numeric($id) || $id < 1 || $id > 20) {
            return false;
        }
        $value = $this->getContextData()->getValue('value' . $id);
        if ($this->hasArg('isset') && $this->getArg('isset')) {
            return $value ? 'true' : 'false';
        }
        if ($this->hasArg('widget') && $this->getArg('widget')) {
            if (!$this->environmentIs(self::ENV_INPUT)) {
                return false;
            }
            $value = rex_var::toArray($value);
            echo '<pre>';
            print_r($value);
            echo '</pre>';
            $initHeadRows = $this->hasArg('trows') ? $this->getArg('trows') : self::$initHeadRows;
            $initFootRows = $this->hasArg('frows') ? $this->getArg('frows') : self::$initFootRows;
            $initBodyRows = $this->hasArg('rows') ? $this->getArg('rows') : self::$initBodyRows;
            $initCols = $this->hasArg('cols') ? $this->getArg('cols') : self::$initCols;
            $initTitleCols = $this->hasArg('tcols') ? $this->getArg('tcols') : self::$initTitleCols;
            if (count($value) == 0) {
                $appendCols = array_fill(1, $initCols, '');
                if ($initHeadRows > 0) {
                    $value['thead'] = array_fill(1, $initHeadRows, $appendCols);
                }
                if ($initFootRows > 0) {
                    $value['tfoot'] = array_fill(1, $initFootRows, $appendCols);
                }
                $value['tbody'] = array_fill(1, $initBodyRows, $appendCols);
            }
            $table = '';
            $table .= '<table id="toolbox">
				<tbody>
					<tr>
						<td>
							<span class="btn btn-apply" onclick="redips.merge()" title="Merge marked table cells horizontally and verically">Merge</span>
						</td>
						<td>
							<span class="btn btn-apply" onclick="redips.split(\'h\')" title="Split marked table cell horizontally">Split H</span>
							<span class="btn btn-apply" onclick="redips.split(\'v\')" title="Split marked table cell vertically">Split V</span>
						</td>
						<td>
							<span class="btn btn-apply" onclick="redips.row(\'insert\')" title="Add table row">Row +</span>
							<span class="btn btn-apply" onclick="redips.row(\'delete\')" title="Delete table row">Row -</span>
						</td>
						<td>
							<span class="btn btn-apply" onclick="redips.column(\'insert\')" title="Add table column">Col +</span>
							<span class="btn btn-apply" onclick="redips.column(\'delete\')" title="Delete table column">Col -</span>
						</td>
					</tr>
				</tbody>
			</table>';
            $table .= '<table id="dao-table" class="dao-table table table-bordered">';
            $rows = isset($value['thead']) ? $value['thead'] : [];
            $table .= $this->getTableGroup($id, 'thead', $rows, $initHeadRows, $initCols);
            $rows = isset($value['tfoot']) ? $value['tfoot'] : [];
            $table .= $this->getTableGroup($id, 'tfoot', $rows, $initFootRows, $initCols);
            $rows = $value['tbody'];
            $table .= $this->getTableGroup($id, 'tbody', $rows, $initBodyRows, $initCols, $initTitleCols);
            $table .= '</table>';
            $table .= '
            <script>

//$(document).on("rex:ready", function (event, container) {
//jQuery(function($) {
getCellCoords = function (table) {
		var matrix = [],
			matrixrow,
			lookup = {},
			c,			// current cell
			ri,			// row index
			rowspan,
			colspan,
			firstAvailCol,
			tr,			// TR collection
			i, j, k, l;	// loop variables
		// set HTML collection of table rows
		tr = table.rows;
		// open loop for each TR element
		for (i = 0; i < tr.length; i++) {
			// open loop for each cell within current row
			for (j = 0; j < tr[i].cells.length; j++) {
				// define current cell
				c = tr[i].cells[j];
				// set row index
				ri = c.parentNode.rowIndex;
				// define cell rowspan and colspan values
				rowspan = c.rowSpan || 1;
				colspan = c.colSpan || 1;
				// if matrix for row index is not defined then initialize array
				matrix[ri] = matrix[ri] || [];
				// find first available column in the first row
				for (k = 0; k < matrix[ri].length + 1; k++) {
					if (typeof(matrix[ri][k]) === "undefined") {
						firstAvailCol = k;
						break;
					}
				}
				// set cell coordinates and reference to the table cell
				lookup[ri + "-" + firstAvailCol] = c;
				for (k = ri; k < ri + rowspan; k++) {
					matrix[k] = matrix[k] || [];
					matrixrow = matrix[k];
					for (l = firstAvailCol; l < firstAvailCol + colspan; l++) {
						matrixrow[l] = "x";
					}
				}
			}
		}
		return lookup;
	};

    // create redips container
    var redips = {};
    var tbl = document.getElementById("dao-table");
    var id = ' . $id . ';


    // REDIPS.table initialization
    redips.init = function () {
        // define reference to the REDIPS.table object
        var rt = REDIPS.table;
        // activate onmousedown event listener on cells within table with id="mainTable"
        rt.onmousedown(tbl, true);
        // show cellIndex (it is nice for debugging)
        // rt.cell_index(false);
        // define background color for marked cell
        rt.color.cell = "#9BB3DA";
        redips.updateTable("init");
    };


    // function merges table cells
    redips.merge = function () {
        // first merge cells horizontally and leave cells marked
        REDIPS.table.merge("h", false);
        // and then merge cells vertically and clear cells (second parameter is true by default)
        REDIPS.table.merge("v", false);
        redips.updateTable("merge");
    };


    // function splits table cells if colspan/rowspan is greater then 1
    // mode is "h" or "v" (cells should be marked before)
    redips.split = function (mode) {
        REDIPS.table.split(mode);
        redips.updateTable("split");
    };


    // insert/delete table row
    redips.row = function (type) {
        REDIPS.table.row(tbl, type);
        redips.updateTable(type);
    };


    // insert/delete table column
    redips.column = function (type) {
        REDIPS.table.column(tbl, type);
        redips.updateTable(type);
    };


    redips.updateTable = function (type) {
        console.log(getCellCoords(tbl));
        if (tbl.tHead !== null && tbl.tHead.rows.length > 0) {
            var thead_tr = tbl.tHead.rows;
            redips.updateCell(type, "thead", thead_tr);
        }

        if (tbl.tBodies !== null && tbl.tBodies[0].rows.length > 0) {
            var tbody_tr = tbl.tBodies[0].rows;
            redips.updateCell(type, "tbody", tbody_tr);
        }

        if (tbl.tFoot !== null && tbl.tFoot.rows.length > 0) {
            var tfoot_tr = tbl.tFoot.rows;
            redips.updateCell(type, "tfoot", tfoot_tr);
        }

    }
    redips.updateCell = function (type, group, rows) {
        // local variable
        var r, c, numberOfRows, numberOfCells, cell, cellContent;
        numberOfRows = rows.length;
        // loop through all TD elements
        for (r = 0; r < numberOfRows; r++) {
            numberOfCells = rows[r].cells.length;
            // loop through all TD elements
            var $cIndex = -1;
            for (c = 0; c < numberOfCells; c++) {
                cell = rows[r].cells[c];
                $cIndex++;
                if (cell.colSpan > 1) {
                    $cIndex = $cIndex + cell.colSpan - 1;
                }

                // ignore thead and tfoot
                // no merge and split
                if (group == "thead" || group == "tfoot") {
                    REDIPS.table.cell_ignore(cell);
                }

                if (type == "init" || type == "insert" || type == "split") {
                    if (cell.innerHTML == "") {
                        //cell.innerHTML += \'<input type="hidden" name="REX_INPUT_VALUE[\'+ id + \'][\'+ group + \'][\'+ r + \'][\'+ c + \'][colspan]" value="\' + cell.colSpan + \'" />\';
                        //cell.innerHTML += \'<input type="hidden" name="REX_INPUT_VALUE[\'+ id + \'][\'+ group + \'][\'+ r + \'][\'+ c + \'][rowspan]" value="\' + cell.rowSpan + \'" />\';
                        cell.innerHTML += \'<textarea name="REX_INPUT_VALUE[\'+ id + \'][\'+ group + \'][\'+ r + \'][\'+ $cIndex + \'][cell]"></textarea>\';
                    }
                }
                if (type == "merge" && cell.redips && cell.redips.selected === true) {
                    var textarea = cell.getElementsByTagName("TEXTAREA");
                    var j;
                    var content = "";
                    for (j = 0; j < textarea.length; j++) {
                        content += textarea[j].value;
                    }
                    cell.innerHTML = "";
                    //cell.innerHTML += \'<input title="" name="REX_INPUT_VALUE[\'+ id + \'][\'+ group + \'][\'+ r + \'][\'+ c + \'][colspan]" value="\' + cell.colSpan + \'" type="hidden" />\';
                    //cell.innerHTML += \'<input    name="REX_INPUT_VALUE[\'+ id + \'][\'+ group + \'][\'+ r + \'][\'+ c + \'][rowspan]" value="\' + cell.rowSpan + \'" type="hidden" />\';
                    cell.innerHTML += \'<textarea name="REX_INPUT_VALUE[\'+ id + \'][\'+ group + \'][\'+ r + \'][\'+ $cIndex + \'][cell]">\' + content + \'</textarea>\';
                    REDIPS.table.mark(false, cell);
                }

                cellContent = cell.getElementsByTagName("TEXTAREA")[0].outerHTML;
                cell.innerHTML = "";
                cell.innerHTML += \'<input name="REX_INPUT_VALUE[\'+ id + \'][\'+ group + \'][\'+ r + \'][\'+ $cIndex + \'][colspan]" value="\' + cell.colSpan + \'" type="hidden" />\';
                cell.innerHTML += \'<input name="REX_INPUT_VALUE[\'+ id + \'][\'+ group + \'][\'+ r + \'][\'+ $cIndex + \'][rowspan]" value="\' + cell.rowSpan + \'" type="hidden" />\';
                cell.innerHTML += cellContent;


                /*
                // if table cell is selected
                if (td[i].redips && td[i].redips.selected === true) {
                    // set value from selected item to the cell content
                    td[i].innerHTML = "text";
                    // unselect TD
                    REDIPS.table.mark(false, td[i]);
                }
                */
            }
        }
    }

    // add onload event listener
    if (window.addEventListener) {
        window.addEventListener("load", redips.init, false);
    }
    else if (window.attachEvent) {
        window.attachEvent("onload", redips.init);
    }
    $(document).on("rex:ready", function (event, container) {
        redips.init();
    });
//});
            </script>';
            $widget = $table;
            if ($this->hasArg('output') && $this->getArg('output')) {
                $label = $this->hasArg('label') ? $this->getArg('label') : '';
                $widget = Dao::getForm($widget, $label, $this->getArg('output'));
            }
            return self::quote($widget);
        }
        return self::quote(htmlspecialchars($value));
    }
 protected function getOutput()
 {
     $id = $this->getArg('id', 0, true);
     if (!in_array($this->getContext(), ['module', 'action']) || !is_numeric($id) || $id < 1 || $id > 20) {
         return false;
     }
     $valueArray = rex_var::toArray($this->getContextData()->getValue('value' . $id));
     $value = isset($valueArray['value']) ? $valueArray['value'] : '';
     $clang = isset($valueArray['clang']) ? $valueArray['clang'] : '';
     $label = isset($valueArray['label']) ? $valueArray['label'] : '';
     if ($this->hasArg('isset') && $this->getArg('isset')) {
         return $value ? 'true' : 'false';
     }
     if ($this->hasArg('widget') && $this->getArg('widget')) {
         if (!$this->environmentIs(self::ENV_INPUT)) {
             return false;
         }
         $args = [];
         if (!$this->hasArg('linkmap')) {
             $args['linkmap'] = true;
         }
         if (!$this->hasArg('url')) {
             $args['url'] = false;
         }
         if (!$this->hasArg('text')) {
             $args['text'] = false;
         }
         foreach (['category', 'linkmap', 'url', 'text'] as $key) {
             if ($this->hasArg($key)) {
                 $args[$key] = $this->getArg($key);
             }
         }
         $widget = self::getWidget($id, 'REX_INPUT_VALUE[' . $id . '][value]', $valueArray, $args);
         $label = $this->hasArg('label') ? $this->getArg('label') : '';
         $widget = Dao::getForm($widget, $label, $this->getArg('output'));
         return self::quote($widget);
     } elseif ($this->hasArg('output') && $this->getArg('output')) {
         if (is_numeric($value)) {
             if ($label == '') {
                 $art = rex_article::get($value);
                 if ($art instanceof rex_article) {
                     $label = $art->getName();
                 }
             }
             $value = rex_getUrl($value, $clang);
         } else {
             if ($label == '') {
                 $label = $value;
             }
         }
         if ($this->getArg('output') == 'link') {
             $class = '';
             if ($this->hasArg('class')) {
                 $class = ' class="' . $this->getArg('class') . '"';
             }
             return self::quote('<a' . $class . ' href="' . $value . '">' . $label . '</a>');
         } else {
             return self::quote($value);
         }
     }
     return self::quote(json_encode($valueArray));
 }
 protected function getOutput()
 {
     $id = $this->getArg('id', 0, true);
     if (!in_array($this->getContext(), ['module', 'action']) || !is_numeric($id) || $id < 1 || $id > 20) {
         return false;
     }
     $value = $this->getContextData()->getValue('value' . $id);
     if ($this->hasArg('isset') && $this->getArg('isset')) {
         return $value ? 'true' : 'false';
     }
     if ($this->hasArg('widget') && $this->getArg('widget')) {
         if (!$this->environmentIs(self::ENV_INPUT)) {
             return false;
         }
         $select = new rex_select();
         if ($this->hasArg('multiple') && $this->getArg('options')) {
             $select->setName('REX_INPUT_VALUE[' . $id . '][]');
             $select->setMultiple();
             $select->setSelected(rex_var::toArray($value));
         } else {
             $select->setName('REX_INPUT_VALUE[' . $id . ']');
             $select->setSelected($value);
         }
         if ($this->hasArg('options') && $this->getArg('options')) {
             $options = $this->getArg('options');
             if (rex_sql::getQueryType($options) == 'SELECT') {
                 $select->addSqlOptions($options);
             } else {
                 $groups = explode('|', $options);
                 if (count($groups)) {
                     foreach ($groups as $group) {
                         $parseGroup = explode(':', $group);
                         $groupOptions = $parseGroup[0];
                         if (count($parseGroup) == 2) {
                             $select->addOptgroup($parseGroup[0]);
                             $groupOptions = $parseGroup[1];
                         }
                         if (rex_sql::getQueryType($groupOptions) == 'SELECT') {
                             $select->addSqlOptions($groupOptions);
                         } else {
                             $groupOptions = explode(',', $groupOptions);
                             if (count($groupOptions)) {
                                 foreach ($groupOptions as $groupOption) {
                                     $optionPair = explode('=', $groupOption);
                                     if (count($optionPair) == 1) {
                                         $select->addOption($optionPair[0], $optionPair[0]);
                                     } elseif (count($optionPair) == 2) {
                                         $select->addOption($optionPair[0], $optionPair[1]);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $widget = '<div class="rex-select-style">' . $select->get() . '</div>';
         if ($this->hasArg('output') && $this->getArg('output')) {
             $label = $this->hasArg('label') ? $this->getArg('label') : '';
             $widget = Dao::getForm($widget, $label, $this->getArg('output'));
         }
         return self::quote($widget);
     }
     return self::quote(htmlspecialchars($value));
 }