17 require_once SQ_CORE_PACKAGE_PATH.
'/bodycopy/bodycopy_container/bodycopy_container_edit_fns.inc';
40 parent::__construct();
56 $table_rows = $asset->
attr(
'rows');
57 $table_attributes = $asset->
attr(
'attributes');
58 $table_attributes[
'identifier'] = $asset->name;
59 $max_cols = $this->
maxCols($table_rows);
61 case <?php echo $asset->id?> :
65 for ($i = 0; $i < count($table_rows); $i++) {
67 case <?php echo $i?> :
70 if (isset($table_rows[$i][
'cells'])) {
71 for ($x = 0; $x < count($table_rows[$i][
'cells']); $x++) {
72 if (isset($table_rows[$i][
'cells'][$x])) {
73 $table_rows[$i][
'cells'][$x]->printBackendJsData($x);
80 retVal[
"attributes"] =
'<?php echo var_serialise($table_rows[$i]['attributes
'], TRUE)?>';
89 retVal[
"attributes"] =
'<?php echo var_serialise($table_attributes, TRUE)?>';
90 retVal[
"num_cols"] = <?php echo (
int) $max_cols?>;
91 retVal[
"num_rows"] = <?php echo count($table_rows)?>;
117 $containers = Array(Array(
'minorid'=>$bodycopy->id,
'minor_type_code'=>
'bodycopy_table'));
119 $containers = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($bodycopy->id, SQ_LINK_TYPE_2,
'bodycopy_container', FALSE);
123 <script language=
"JavaScript" src=
"<?php echo sq_web_path('data').'/asset_types/bodycopy/js/bodycopy_edit_tables.js'?>"></script>
125 <script language=
"JavaScript" type=
"text/javascript">
126 function serialise_table(bodycopy_name, bodycopy_data, tableid, rowid, cellid) {
127 var form = document.main_form;
128 if (!bodycopy_saved[bodycopy_name] && bodycopy_name != null) {
129 bodycopy_saved[bodycopy_name] =
new Object();
132 if (tableid != null) {
133 if (!bodycopy_saved[bodycopy_name][tableid]) {
134 bodycopy_saved[bodycopy_name][tableid] =
new Object();
138 if (!bodycopy_saved[bodycopy_name][tableid][
'rows']) {
139 bodycopy_saved[bodycopy_name][tableid][
'rows'] =
new Object();
141 if (!bodycopy_saved[bodycopy_name][tableid][
'rows'][rowid] && rowid != null) {
142 bodycopy_saved[bodycopy_name][tableid][
'rows'][rowid] =
new Object();
144 if (cellid != null) {
145 if (!bodycopy_saved[bodycopy_name][tableid][
'rows'][rowid][
'cells']) {
146 bodycopy_saved[bodycopy_name][tableid][
'rows'][rowid][
'cells'] =
new Object();
148 bodycopy_saved[bodycopy_name][tableid][
'rows'][rowid][
'cells'][cellid] = bodycopy_data;
151 bodycopy_saved[bodycopy_name][tableid][
'rows'][rowid][
'attributes'] = bodycopy_data[
'attributes'];
156 bodycopy_saved[bodycopy_name][tableid][
'attributes'] = bodycopy_data[
'attributes'];
161 form.elements[
'bodycopy_saved[' + bodycopy_name +
'][' + tableid +
']'].value = var_serialise(bodycopy_saved[bodycopy_name][tableid]);
166 function get_bodycopy_current_table_data(bodycopy_name, tableid, rowid, cellid) {
167 if (tableid == null) tableid = -1;
168 if (rowid == null) rowid = -1;
169 if (cellid == null) cellid = -1;
170 return bodycopy_current_data[bodycopy_name].get_table_data(tableid, rowid, cellid);
174 function get_bodycopy_<?php echo $prefix?>_current_table_data(tableid, rowid, cellid) {
175 retVal =
new Object();
181 if (count($containers)) {
182 foreach ($containers as $container_data) {
183 if ($container_data[
'minor_type_code'] !=
'bodycopy_table') {
186 $table = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($container_data[
'minorid'], $container_data[
'minor_type_code']);
187 $table_edit = $table->getEditFns();
188 $table_edit->paintBackendJsData($table, $prefix, $i);
194 retVal[
"num_containers"] = <?php echo count($containers); ?>;
204 if (bodycopy_saved &&
205 bodycopy_saved[
"<?php echo $prefix?>"] &&
206 bodycopy_saved[
"<?php echo $prefix?>"][tableid] &&
207 bodycopy_saved[
"<?php echo $prefix?>"][tableid][
"rows"] &&
208 bodycopy_saved[
"<?php echo $prefix?>"][tableid][
"rows"][rowid] &&
209 bodycopy_saved[
"<?php echo $prefix?>"][tableid][
"rows"][rowid][
"cells"] &&
210 bodycopy_saved[
"<?php echo $prefix?>"][tableid][
"rows"][rowid][
"cells"][cellid]) {
211 for (var key in bodycopy_saved[
"<?php echo $prefix?>"][tableid][
"rows"][rowid][
"cells"][cellid]) {
212 retVal[key] = var_serialise(bodycopy_saved[
"<?php echo $prefix?>"][tableid][
"rows"][rowid][
"cells"][cellid][key]);
218 if (bodycopy_data_exists(
new Array(
'<?php echo $prefix?>', tableid,
'rows', rowid,
'attributes'))) {
219 retVal[
"attributes"] = var_serialise(bodycopy_saved[
"<?php echo $prefix?>"][tableid][
"rows"][rowid][
"attributes"]);
225 if (bodycopy_data_exists(
new Array(
'<?php echo $prefix?>', tableid,
'attributes'))) {
226 retVal [
"attributes"] = var_serialise(bodycopy_saved[
"<?php echo $prefix?>"][tableid][
"attributes"]);
237 bodycopy_current_data[
"<?php echo $prefix?>"].get_table_data = get_bodycopy_<?php echo $prefix?>_current_table_data;
257 $table_rows = $asset->
attr(
'rows');
258 $table_attributes = $asset->
attr(
'attributes');
260 $attribute_list =
'';
263 for (reset($table_attributes); $name = key($table_attributes); next($table_attributes)) {
264 $val = $table_attributes[$name];
265 if ($val ==
'')
continue;
266 if ($name ==
'disable_keywords')
continue;
267 if ($name ==
'background') {
268 $file = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($val);
269 if ($file->id) $bgimage = $file->getURL();
272 $attribute_list .=
' '.$name.
'="'.str_replace(
'"',
'"', $val).
'"';
276 $val = clean_div_attribute($asset->
attr(
'name'));
278 $attribute_list .=
' '.
'id="'.$val.
'"';
281 echo
"\n<table{$attribute_list}>\n";
283 for ($i = 0; $i < count($table_rows); $i++) {
284 $attribute_list =
'';
285 foreach ($table_rows[$i][
'attributes'] as $name => $val) {
286 if ($val ==
'')
continue;
287 $attribute_list .=
' '.$name.
'="'.str_replace(
'"',
'"', $val).
'"';
290 echo
"\t<tr{$attribute_list}>\n";
292 for ($x = 0; $x < count($table_rows[$i][
'cells']); $x++) {
293 $table_rows[$i][
'cells'][$x]->paint($asset,
'', $editing, $generating);
317 if (!parent::paintContainer($asset, $o, $prefix)) {
321 $table_rows = $asset->
attr(
'rows');
322 $table_attributes = $asset->
attr(
'attributes');
324 $attribute_list =
'';
325 $popup_attribute_list =
'';
329 if (!empty($table_attributes)) {
330 for (reset($table_attributes); $name = key($table_attributes); next($table_attributes)) {
331 $val = $table_attributes[$name];
332 if ($val ==
'')
continue;
333 if ($name ==
'background') {
334 $file = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($val);
336 $popup_attribute_list .=
' '.$name.
'="'.str_replace(
'"',
'"', $file->attr(
'name')).
'"';
338 $bgimage = $file->getURL();
341 $popup_attribute_list .=
' '.$name.
'="'.str_replace(
'"',
'"', $val).
'"';
344 if ($name ==
'width' && !strstr($val,
'%')) {
345 $val = (int) $val + 20;
347 if ($name ==
'dir') $dir_attribute = $val;
348 $attribute_list .=
' '.$name.
'="'.str_replace(
'"',
'"', $val).
'"';
353 if (!empty($dir_attribute)) {
354 $this->_tmp[
'dir_attr'] = $dir_attribute;
359 $colspans_in_row = FALSE;
360 for ($i = 0; $i < count($table_rows); $i++) {
361 for ($x = 0; $x < count($table_rows[$i][
'cells']); $x++) {
362 if ($table_rows[$i][
'cells'][$x]->colspan() > 1) {
363 $colspans_in_row = TRUE;
367 if ($colspans_in_row)
break;
371 $type_info = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo(
'bodycopy');
374 <table<?php echo $attribute_list?> background=
"<?php echo $bgimage?>" border=
"0" cellpadding=
"0" cellspacing=
"0" style=
"width:100%;">
381 $num_rows = count($table_rows);
382 for ($i = 0; $i < $num_rows; $i++) {
383 $attribute_list =
'';
384 foreach ($table_rows[$i][
'attributes'] as $name => $val) {
385 if ($val ==
'')
continue;
386 $attribute_list .=
' '.$name.
'="'.str_replace(
'"',
'"', $val).
'"';
390 <tr<?php echo $attribute_list?>>
392 $num_cols = count($table_rows[$i][
'cells']);
393 for ($x = 0; $x < $num_cols; $x++) {
394 $cell = $table_rows[$i][
'cells'][$x];
396 <td valign=
"top" colspan=
"<?php echo $cell->colspan(); ?>" style=
"border: 1px dashed #C0C0C0;">
400 $this->
_paintEditingCell($asset, $prefix, $x, $i, $table_rows[$i][
'cells'][$x], $num_cols > 1, $num_rows > 1, !$colspans_in_row);
446 $attribute_list =
'';
447 $table_rows = $asset->
attr(
'rows');
450 foreach ($table_rows[$i][
'attributes'] as $name => $val) {
451 if ($val ==
'')
continue;
452 $attribute_list .=
' '.$name.
'="'.str_replace(
'"',
'"', $val).
'"';
453 if ($name ==
'dir' && !empty($val)) {
454 $dir_attribute = $val;
459 if (empty($dir_attribute) && isset($this->_tmp[
'dir_attr'])) {
460 $dir_attribute = $this->_tmp[
'dir_attr'];
464 <table cellspacing=
"0" cellpadding=
"0" width=
"100%" height=
"100%">
466 <tr style=
"background-color: White; height: 20px;">
472 <td
id=
"<?php echo $prefix.'_table_'.$asset->id;?>" style=
"width: 20px;border-bottom: 1px dashed #C0C0C0;border-right: 1px dashed #C0C0C0;">
475 $popup_attribute_list =
'';
476 $table_attributes = $asset->
attr(
'attributes');
477 if (!empty($table_attributes)) {
478 foreach ($table_attributes as $name => $val) {
479 if ($val ==
'')
continue;
480 if ($name ==
'background')
continue;
481 $popup_attribute_list .=
' '.$name.
'="'.str_replace(
'"',
'"', $val).
'"';
486 $public_userid = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user');
488 $public_read = FALSE;
489 if ($asset->status == SQ_STATUS_LIVE && $asset->
readAccess(Array($public_userid))) {
492 $status_name = get_status_description($asset->status);
493 $status_img = get_asset_status_icon($asset->status);
494 $desc = translate(
'content_type_tooltip_status').
': '.$status_img.
'<b>'.get_status_description($asset->status).
'</b><br />';
495 $desc .= translate(
'content_type_tooltip_public').
': <b>'.($public_read ? translate(
'yes') : translate(
'no')).
'</b><br />';
496 $desc .= (($popup_attribute_list) ? translate(
'current_properties').
':<br>'.$popup_attribute_list :
'');
497 Bodycopy_Edit_Fns::printBodycopyIcon(
'bodycopy_edit_table_properties(\''.$prefix.
'\',
'.$asset->id.',
'.(($asset->status & SQ_SC_STATUS_SAFE_EDITING) ? 'false' : 'true').');
', translate('edit_properties
', $asset->attr('name
')), $desc, 'table_properties
');
508 <td style="border-bottom: 1px dashed #C0C0C0;" id="<?php echo $prefix.'_cell_
'.$asset->id.'_
'.$i.'_
'.$x; ?>">
509 <!-- These next 3 icons float across to the right side -->
510 <span style="float: right;">
513 // prints backend status icons, e.g. htmltidy status
514 $cell->paintCellBackendStatusIcons($asset, $prefix, $asset->id, $i, $x);
517 if (($x+$i) == 0 && $multiCol && $colReorder) {
518 Bodycopy_Edit_Fns::printBodycopyIcon("bodycopy_edit_table_col_order('$prefix
', $asset->id);", translate('reoder_columns_question
', $asset->attr('name
')), '', 'reorder
', '[
'.translate('reorder_columns
').']
');
522 // if there's more than one row, and we
're on the first row, let the col be deleted.
524 Bodycopy_Edit_Fns::printBodycopyIcon("bodycopy_delete_table_col('$prefix
', $asset->id, $x);", translate('delete_column_question
', ($x + 1)), '', 'delete', '[
'.translate('delete_column
').']
');
527 Bodycopy_Edit_Fns::printBodycopyIcon("bodycopy_insert_table_col('$prefix
', $asset->id, $x, false);", translate('insert_new_column_on_right
'), '', 'add
', '[
'.translate('add_column
').' >>]
');
533 Bodycopy_Edit_Fns::printBodycopyIcon("bodycopy_insert_table_col('$prefix
', $asset->id, $x, true);", translate('insert_new_column_on_left
'), '', 'add
', '[<<
'.translate('add_column
').']
');
535 $cell->setDirAttr($dir_attribute);
536 $cell->paintCell($asset, $prefix, $asset->id, $i, $x);
541 <tr valign="top" height="100%" style="height: 100%;" <?php echo $attribute_list?>>
545 <td style="width: 20px;border-right: 1px dashed #C0C0C0;" id="<?php echo $prefix.'_row_
'.$asset->id.'_
'.$i?>" nowrap="nowrap">
547 if ($i == 0 && $multiRow) {
548 Bodycopy_Edit_Fns::printBodycopyIcon("bodycopy_edit_table_row_order('$prefix
', $asset->id);", translate('reorder_rows_question
', $asset->attr('name
')), '', 'reorder
', '[
'.translate('reorder_rows
').']
');
551 Bodycopy_Edit_Fns::printBodycopyIcon("bodycopy_insert_table_row('$prefix
', $asset->id,$i, true);", translate('insert_new_row_above
'), '', 'add
', '[^
'.translate('add_row
').']
');
554 Bodycopy_Edit_Fns::printBodycopyIcon("bodycopy_edit_table_row_properties('$prefix
', $asset->id,$i);", translate('edit_row_question
', ($i + 1)), (($attribute_list) ? translate('current_properties
').':<br>
'.$attribute_list : ''), 'row_properties
', '[
'.translate('edit_row
').']
');
557 Bodycopy_Edit_Fns::printBodycopyIcon("bodycopy_delete_table_row('$prefix
', $asset->id, $i);", translate('delete_row_question
', ($i + 1)), '', 'delete', '[
'.translate('delete_row
').']
');
560 Bodycopy_Edit_Fns::printBodycopyIcon("bodycopy_insert_table_row('$prefix
', $asset->id, $i, false);", translate('insert_new_row_below
'), '', 'add
', '[v
'.translate('add_row
').']
');
565 // a cell paints its own <td> tag
566 $cell->paint($asset, $prefix);
574 }//end _paintEditingCell()
591 public function processContainer(Bodycopy_Table $asset, Backend_Outputter $o, $prefix, $bc_action, $bc_name, Array $bc_data, Array $bc_saved)
593 $updated = parent::processContainer($asset, $o, $prefix, $bc_action, $bc_name, $bc_data, $bc_saved);
596 $rows_updated = FALSE;
597 $rows = $asset->attr('rows
');
600 for ($rowid = 0; $rowid < count($rows); $rowid++) {
601 if (!empty($bc_saved[$prefix][$asset->id]['rows
'][$rowid]['attributes
'])) {
602 // save any changed row attributes
603 foreach ($bc_saved[$prefix][$asset->id]['rows
'][$rowid]['attributes
'] as $name => $value) {
604 $name = strtolower($name);
605 if (!isset($rows[$rowid]['attributes
'][$name]) || $rows[$rowid]['attributes
'][$name] != $value) {
606 $rows[$rowid]['attributes
'][$name] = $value;
607 $rows_updated = TRUE;
612 // only update if we are the table row that submitted the form
613 if ((!empty($bc_data['rowid
']) && $bc_data['rowid
'] == $rowid && $prefix == $bc_name) || isset($bc_saved[$prefix][$asset->id]['rows
'][$rowid])) {
616 $colspan_todo = Array();
618 // check to see if any cells from this row need their colspans changed
619 if (isset($bc_saved[$prefix][$asset->id]['rows
'][$rowid]['cells
'])) {
620 foreach ($bc_saved[$prefix][$asset->id]['rows
'][$rowid]['cells
'] as $cellid => $cell_data) {
622 if (isset($rows[$rowid]['cells
'][$cellid])) {
624 $current_span = $rows[$rowid]['cells
'][$cellid]->colspan();
625 $colspaning = $cell_data['attributes
']['colspan
'];
627 // if the current span is '1
' and the new span is '' then a cell is being created
628 // so we dont want to do anything
629 if ($current_span == 1 && trim($colspaning) == '') {
630 $colspaning = $current_span;
633 // if the user left colspan blank, dont change anything
634 if (trim($colspaning) == '') {
635 $colspaning = $current_span;
636 $bc_saved[$prefix][$asset->id]['rows
'][$rowid]['cells
'][$cellid]['attributes
']['colspan
'] = $current_span;
639 // if the user entered a negative colspan - or '0
', we can assume they want a colspan of '1
'
640 if (intval($colspaning) <= 0) {
642 $bc_saved[$prefix][$asset->id]['rows
'][$rowid]['cells
'][$cellid]['attributes
']['colspan
'] = 1;
649 if ($colspaning != $current_span) {
650 // put this colspan into a todo list that we will do later
651 $colspan_todo[$counter]['cell
'] = $cellid;
652 $colspan_todo[$counter]['colspaning
'] = $colspaning;
653 $colspan_todo[$counter]['current_span
'] = $current_span;
658 // doing the colspan thing
659 if (count($colspan_todo)) {
661 foreach ($colspan_todo as $colspan) {
663 $cellid = $colspan['cell
'];
664 $colspaning = $colspan['colspaning
'];
665 $current_span = $colspan['current_span
'];
667 // if the current span is '1
' and the new span is '' then a cell is being created
668 // so we dont want to do anything
669 if ($current_span == 1 && trim($colspaning) == '') {
670 $colspaning = $current_span;
673 // if the user left colspan blank, dont change anything
674 if (trim($colspaning) == '') {
675 $colspaning = $current_span;
676 $bc_saved[$prefix][$asset->id]['rows
'][$rowid]['cells
'][$cellid]['attributes
']['colspan
'] = $current_span;
679 // if the user entered a negative colspan - or '0
', we can assume they want a colspan of '1
'
680 if (intval($colspaning) <= 0) {
682 $bc_saved[$prefix][$asset->id]['rows
'][$rowid]['cells
'][$cellid]['attributes
']['colspan
'] = 1;
686 if ($colspaning != $current_span) {
688 // make sure there are sufficient cells to create the colspan
689 $spanable_cells = count($rows[$rowid]['cells
']) - ($cellid +1);
690 $needed_cells = ($colspaning - $current_span);
692 if ($spanable_cells < $needed_cells) {
693 // dont end up changing the colspan at all
694 $bc_saved[$prefix][$asset->id]['rows
'][$rowid]['cells
'][$cellid]['attributes
']['colspan
'] = $current_span;
696 if ($colspaning > $current_span && $spanable_cells >= 1) {
697 // check for more colspans first
699 for ($i = ($cellid + 1); $i <= ($cellid + ($colspaning - $current_span)); $i++) {
700 if ($rows[$rowid]['cells
'][$i]->colspan() > 1) {
704 if ($colspan_error == 0) {
705 for ($i = ($cellid + 1); $i <= ($cellid + ($colspaning - $current_span)); $i++) {
706 if ($this->deleteCell($asset, $rows, $rowid, ($cellid+1), TRUE)) {
707 $rows_updated = TRUE;
710 // dont end up changing the colspan at al
711 $bc_saved[$prefix][$asset->id]['rows
'][$rowid]['cells
'][$cellid]['attributes
']['colspan
'] = $current_span;
715 // we are trying to colspan into another colspan
716 // dont end up changing the colspan at all
717 $bc_saved[$prefix][$asset->id]['rows
'][$rowid]['cells
'][$cellid]['attributes
']['colspan
'] = $current_span;
719 } else if ($colspaning < $current_span) {
720 // decreasing the colspan
722 for ($i = 0; $i < ($current_span - $colspaning); $i++) {
723 if ($this->insertCell($asset, $rows, $rowid, $cellid, FALSE, TRUE)) {
724 $rows_updated = TRUE;
727 // dont end up changing the colspan at al
728 $bc_saved[$prefix][$asset->id]['rows
'][$rowid]['cells
'][$cellid]['attributes
']['colspan
'] = $current_span;
738 }//end if we have colspans todo
740 }//end if changing colspans
742 }//end if we are the row that submitted the form
744 // now update the cells
745 for ($i = 0; $i < count($rows[$rowid]['cells
']); $i++) {
746 if ($rows[$rowid]['cells
'][$i]->processCell($asset, $prefix, $asset->id, $rowid, $i, $bc_saved)) {
747 $rows_updated = TRUE;
751 // only set the rows attributes if any of the rows (or cells within) have changed
753 $asset->setAttrValue('rows
',$rows);
760 // check if there is anything for this table to do
761 $skip_table_editing = FALSE;
762 if (empty($bc_data) || !isset($bc_data['tableid
']) || $bc_data['tableid
'] != $asset->id) {
763 // no bodycopy data stuff relating to this table, so check the saved data
764 if (empty($bc_saved[$asset->id])) {
765 // there is nothing for us here
766 $skip_table_editing = TRUE;
771 // process any special actions if we are the table that submitted the form
772 if (!$skip_table_editing && !empty($bc_data) && $bc_data['tableid
'] == $asset->id && $bc_name == $prefix) {
773 switch ($bc_action) {
774 case 'insert_table_row
' :
775 if ($this->insertRow($asset, $bc_data['rowid
'], $bc_data['before
'])) {
780 case 'delete_table_row
' :
781 if ($this->deleteRow($asset, $bc_data['rowid
'])) {
786 case 'edit_table_row_order
' :
787 if ($this->reorderRows($asset, $bc_data['row_order
'])) {
792 case 'insert_table_column
' :
793 if ($this->insertColumn($asset, $bc_data['colid
'], $bc_data['before
'])) {
798 case 'delete_table_column
' :
799 if ($this->deleteColumn($asset, $bc_data['colid
'])) {
804 case 'edit_table_col_order
' :
805 if ($this->reorderColumns($asset, $bc_data['col_order
'])) {
810 }//end if - we are the table that submitted the form
812 if ($updated) $this->generateContentFile($asset);
813 $this->_contentsUpdated($asset);
816 }//end processContainer()
829 public function insertRow(Bodycopy_Table $asset, $rowid, $before=TRUE)
831 $rows = $asset->attr('rows
');
832 $rowid = intval($rowid);
834 // if the row is greater than the number of rows we have set it to the last on
835 if ($rowid > count($rows) - 1) {
836 $rowid = count($rows) - 1;
838 if ($rowid < 0) $rowid = 0;
841 // for the moment we will just use the number of columns that the one we are inserting
843 $num_cols = $this->maxCols($rows[$compareid], FALSE);
845 // if they want to insert after the passed rowid what
846 // they really mean is to insert before the next rowid
847 if (!$before) $rowid++;
849 // move all the rows up one position
850 for ($i = count($rows); $i > $rowid; $i--) {
851 $rows[$i] = $rows[$i - 1];
852 for ($x = 0; $x < count($rows[$i]['cells
']); $x++) {
853 $rows[$i]['cells
'][$x]->updateContentType($asset, $i, $x);
857 if ($rowid <= $compareid) $compareid++;
860 $rows[$rowid] = Array();
861 $rows[$rowid]['attributes
'] = Array();
862 $rows[$rowid]['cells
'] = Array();
864 // create the cells and set their properties to
865 // the properties of the cells above/below
866 for ($i = 0; $i < count($rows[$compareid]['cells
']); $i++) {
867 $rows[$rowid]['cells
'][$i] = new Bodycopy_Table_Cell();
868 foreach ($rows[$compareid]['cells
'][$i]->attributes as $name => $val) {
869 $rows[$rowid]['cells
'][$i]->setAttribute($name,$val);
871 $rows[$rowid]['cells
'][$i]->setContentType($asset, 'content_type_wysiwyg
', $rowid, $i);
874 $asset->setAttrValue('rows
',$rows);
889 public function deleteRow(Bodycopy_Table $asset, $rowid)
891 $rows = $asset->attr('rows
');
893 // make sure it exists
894 if (isset($rows[$rowid]) && count($rows) > 1) {
896 // delete all the cells in the row so they can clean up
897 for ($i = 0; $i < count($rows[$rowid]['cells
']); $i++) {
898 $rows[$rowid]['cells
'][$i]->delete($asset);
901 // move all the rows down one position
902 for ($i = $rowid; $i < count($rows) - 1; $i++) {
903 // let the cells know that they are moving to a new rowid
904 $rows[$i] = $rows[$i + 1];
905 for ($x = 0; $x < count($rows[$i]['cells
']); $x++) {
906 $rows[$i]['cells
'][$x]->updateContentType($asset, $i, $x);
910 // remove the last element
913 $asset->setAttrValue('rows
',$rows);
916 } else if (count($rows) == 1) {
934 public function reorderRows(Bodycopy_Table $asset, Array $row_order)
936 $rows = $asset->attr('rows
');
938 // if there ain't no changes, die
940 foreach ($row_order as $new_place => $old_place) {
941 $changes |= ($new_place != $old_place);
943 if (!$changes)
return FALSE;
946 if (count($rows) != count(array_unique($row_order))) {
950 $new_array = Array();
952 for ($i = 0; $i < count($row_order); $i++) {
953 for ($x = 0; $x < count($rows[$i][
'cells']); $x++) {
954 $rows[$i][
'cells'][$x]->updateContentType($asset, $row_order[$i], $x);
956 $new_array[$i] = $rows[$row_order[$i]];
981 foreach ($col_order as $new_place => $old_place) {
982 $changes |= ($new_place != $old_place);
984 if (!$changes)
return FALSE;
986 $rows = $asset->
attr(
'rows');
988 for ($r = 0; $r < count($rows); $r++) {
990 if (count($rows[$r][
'cells']) != count(array_unique($col_order))) {
994 $new_array = Array();
995 for ($i = 0; $i < count($col_order); $i++) {
996 $rows[$r][
'cells'][$i]->updateContentType($asset, $r, $col_order[$i]);
997 $new_array[$i] = $rows[$r][
'cells'][$col_order[$i]];
1000 $rows[$r][
'cells'] = $new_array;
1021 $rows = $asset->
attr(
'rows');
1025 for ($r = 0; $r < count($rows); $r++) {
1026 if (!$this->
insertCell($asset, $rows, $r, $cellid, $before)) {
1048 $rows = $asset->
attr(
'rows');
1052 for ($r = 0; $r < count($rows); $r++) {
1053 if (!$this->
deleteCell($asset, $rows, $r, $cellid)) {
1084 for ($i = 0; $i < count($rows[$rowid][
'cells']); $i++) {
1085 if ($rows[$rowid][
'cells'][$i]->colspan() > 1) {
1089 if ($colspan_error == 1) {
1092 for ($i = 0; $i < count($rows[$rowid][
'cells']); $i++) {
1093 if ($colspaning >= $cellid)
break;
1094 $colspaning += intval($rows[$rowid][
'cells'][$i]->colspan());
1095 if (intval($rows[$rowid][
'cells'][$i]->colspan()) == 0) {
1098 if ($colspaning <= $cellid) {
1106 for ($i = 0; $i < $real_cellid; $i++) {
1107 $colspaning += intval($rows[$rowid][
'cells'][$i]->colspan());
1108 if (intval($rows[$rowid][
'cells'][$i]->colspan()) == 0) {
1113 if ($real_cellid < 0) $real_cellid = 0;
1120 $dont_do_this = FALSE;
1125 if ($cellid == $real_cellid) {
1126 if ($before) $dont_do_this = TRUE;
1128 if ((($rows[$rowid][
'cells'][$real_cellid]->colspan() + $colspaning) == ($cellid + 1)) && !$before) {
1129 $dont_do_this = TRUE;
1133 if ($cellid == 0 && $before) {
1134 $dont_do_this = TRUE;
1137 $cellid = $real_cellid;
1138 if ($cellid < 0) $cellid = 0;
1141 if ($rows[$rowid][
'cells'][$cellid]->colspan() > 1 && !$dont_do_this) {
1142 $colspaning = $rows[$rowid][
'cells'][$cellid]->colspan() + 1;
1143 $rows[$rowid][
'cells'][$cellid]->setAttribute(
'colspan', $colspaning);
1151 if ($cellid > count($rows[$rowid][
'cells']) - 1) {
1152 $cellid = count($rows[$rowid][
'cells']) - 1;
1154 if ($cellid < 0) $cellid = 0;
1155 $compareid = $cellid;
1159 if (!$before) $cellid++;
1162 for ($i = count($rows[$rowid][
'cells']); $i > $cellid; $i--) {
1163 $rows[$rowid][
'cells'][$i] = $rows[$rowid][
'cells'][$i - 1];
1164 $rows[$rowid][
'cells'][$i]->updateContentType($asset, $rowid, $i);
1167 if ($cellid <= $compareid) $compareid++;
1174 foreach ($rows[$rowid][
'cells'][$compareid]->attributes as $name => $val) {
1175 if (strtolower($name) ==
'colspan')
continue;
1176 $rows[$rowid][
'cells'][$cellid]->setAttribute($name,$val);
1178 $rows[$rowid][
'cells'][$cellid]->setContentType($asset,
'content_type_wysiwyg', $rowid, $cellid);
1204 for ($i = 0; $i < count($rows[$rowid][
'cells']); $i++) {
1205 if ($rows[$rowid][
'cells'][$i]->colspan() > 1) {
1210 if ($colspan_error == 1) {
1213 for ($i = 0; $i < count($rows[$rowid][
'cells']); $i++) {
1214 if ($colspaning >= $cellid)
break;
1215 $colspaning += intval($rows[$rowid][
'cells'][$i]->colspan());
1216 if (intval($rows[$rowid][
'cells'][$i]->colspan()) == 0) {
1219 if ($colspaning <= $cellid) {
1225 $cellid = $real_cellid;
1228 if ($rows[$rowid][
'cells'][$cellid]->colspan() > 1) {
1229 $colspaning = $rows[$rowid][
'cells'][$cellid]->colspan() - 1;
1230 $rows[$rowid][
'cells'][$cellid]->setAttribute(
'colspan', $colspaning);
1237 if ($rows[$rowid][
'cells'][$cellid] && count($rows[$rowid][
'cells']) > 1) {
1239 if (!$rows[$rowid][
'cells'][$cellid]->
delete($table, $rowid, $cellid)) {
1244 for ($i = $cellid; $i < count($rows[$rowid][
'cells']) - 1; $i++) {
1245 $rows[$rowid][
'cells'][$i] = $rows[$rowid][
'cells'][$i + 1];
1246 $rows[$rowid][
'cells'][$i]->updateContentType($table, $rowid, $i);
1250 array_pop($rows[$rowid][
'cells']);
1253 }
else if (count($this->cells) == 1) {
1269 public function maxCols($table_rows, $add_colspans=TRUE)
1272 for ($i = 0; $i < count($table_rows); $i++) {
1274 if (empty($table_rows[$i][
'cells']))
continue;
1275 for ($x = 0; $x < count($table_rows[$i][
'cells']); $x++) {
1276 if ($add_colspans) {
1277 $num += $table_rows[$i][
'cells'][$x]->colspan();
1282 if ($max < $num) $max = $num;