Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_multiple_page_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/page/page_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42 
43  }//end constructor
44 
45 
56  function paintCurrentPages(&$asset, &$o, $prefix)
57  {
58  $asset_ids = $asset->getPageIds();
59  $asset_infos = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($asset_ids);
60  $edit_ids = Array();
61  foreach ($asset_ids as $id) {
62  $edit_ids[$id] = 'contents';
63  }
64  $edit_links = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref($edit_ids);
65  $write_access = $asset->writeAccess('content');
66 
67  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
68 
69  ?>
70  <script type="text/javascript">
71  function sortOrderMoveDown(currentOrder) {
72  if (!document.getElementById) {
73  alert('<?php echo translate('cms_form_no_getelementbyid') ?>');
74  return;
75  }
76  // move a question up a row
77  var form = document.getElementById('main_form');
78 
79  var currentElement = document.getElementById('<?php echo $prefix ?>_order_o' + currentOrder);
80  var nextElement = document.getElementById('<?php echo $prefix ?>_order_o' + (currentOrder + 1));
81 
82  // if there is no next element, then this is the last one; we shouldn't be running
83  if (!nextElement) return;
84 
85  if (!currentElement.innerHTML) {
86  alert('<?php echo translate('cms_form_no_innerhtml') ?>');
87  return;
88  }
89 
90  // switch the question names
91  var temp = currentElement.innerHTML;
92  currentElement.innerHTML = nextElement.innerHTML;
93  nextElement.innerHTML = temp;
94 
95  // switch the question types
96  var currentElement = document.getElementById('<?php echo $prefix ?>_order_t' + currentOrder);
97  var nextElement = document.getElementById('<?php echo $prefix ?>_order_t' + (currentOrder + 1));
98 
99  var temp = currentElement.innerHTML;
100  currentElement.innerHTML = nextElement.innerHTML;
101  nextElement.innerHTML = temp;
102 
103 
104 
105  // switch the 'checked for deletion' parameters
106  temp = form.elements['<?php echo $prefix ?>_delete_page[' + (currentOrder+1) + ']'].checked;
107  form.elements['<?php echo $prefix ?>_delete_page[' + (currentOrder+1) + ']'].checked = form.elements['<?php echo $prefix ?>_delete_page[' + currentOrder + ']'].checked;
108  form.elements['<?php echo $prefix ?>_delete_page[' + currentOrder + ']'].checked = temp;
109 
110  // switch the reorder values
111  temp = form.elements['<?php echo $prefix ?>_order[reorder][' + (currentOrder+1) + ']'].value;
112  form.elements['<?php echo $prefix ?>_order[reorder][' + (currentOrder+1) + ']'].value = form.elements['<?php echo $prefix ?>_order[reorder][' + currentOrder + ']'].value;
113  form.elements['<?php echo $prefix ?>_order[reorder][' + currentOrder + ']'].value = temp;
114 
115  }
116 
117  function sortOrderMoveUp(currentOrder) {
118  // move a question up a row
119  if (!document.getElementById) {
120  alert('<?php echo translate('cms_form_no_getelementbyid') ?>');
121  return;
122  }
123 
124  if (currentOrder == 0) return;
125 
126  var form = document.getElementById('main_form');
127 
128  var currentElement = document.getElementById('<?php echo $prefix ?>_order_o' + currentOrder);
129  var prevElement = document.getElementById('<?php echo $prefix ?>_order_o' + (currentOrder - 1));
130 
131  if (!currentElement.innerHTML) {
132  alert('<?php echo translate('cms_form_no_innerhtml') ?>');
133  return;
134  }
135 
136  // switch the question names
137  var temp = currentElement.innerHTML;
138  currentElement.innerHTML = prevElement.innerHTML;
139  prevElement.innerHTML = temp;
140 
141  // switch the question types
142  var currentElement = document.getElementById('<?php echo $prefix ?>_order_t' + currentOrder);
143  var prevElement = document.getElementById('<?php echo $prefix ?>_order_t' + (currentOrder - 1));
144 
145  var temp = currentElement.innerHTML;
146  currentElement.innerHTML = prevElement.innerHTML;
147  prevElement.innerHTML = temp;
148 
149  // switch the delete checkboxes
150  // temp = form.elements['<?php echo $prefix ?>_delete_page[' + (currentOrder-1) + ']'].checked;
151  // form.elements['<?php echo $prefix ?>_delete_page[' + (currentOrder-1) + ']'].checked = form.elements['<?php echo $prefix ?>_delete_page[' + currentOrder + ']'].checked;
152  // form.elements['<?php echo $prefix ?>_delete_page[' + currentOrder + ']'].checked = temp;
153 
154  temp = form.elements['<?php echo $prefix ?>_delete_page[' + (currentOrder-1) + ']'].checked;
155  form.elements['<?php echo $prefix ?>_delete_page[' + (currentOrder-1) + ']'].checked = form.elements['<?php echo $prefix ?>_delete_page[' + currentOrder + ']'].checked;
156  form.elements['<?php echo $prefix ?>_delete_page[' + currentOrder + ']'].checked = temp;
157 
158  // switch the includes checkboxes
159  temp = form.elements['<?php echo $prefix ?>_order[reorder][' + (currentOrder-1) + ']'].value;
160  form.elements['<?php echo $prefix ?>_order[reorder][' + (currentOrder-1) + ']'].value = form.elements['<?php echo $prefix ?>_order[reorder][' + currentOrder + ']'].value;
161  form.elements['<?php echo $prefix ?>_order[reorder][' + currentOrder + ']'].value = temp;
162 
163  }
164  </script>
165  <table class="sq-backend-table">
166  <tr>
167  <th class="sq-backend-table-header"><?php echo translate('name'); ?></th>
168  <th class="sq-backend-table-header"><?php echo translate('link'); ?></th>
169  <?php
170  if ($write_access) {
171  ?>
172  <th class="sq-backend-table-header"><?php echo translate('delete'); ?>?</th>
173  <th class="sq-backend-table-header"><?php echo translate('move'); ?>?</th>
174  <?php
175  }
176  ?>
177  </tr>
178  <?php
179  if (empty($asset_ids)) {
180  ?>
181  <tr>
182  <td colspan="5" style="text-align: center;"><?php echo translate('currently_no_pages_to_display'); ?></td>
183  </tr>
184  <?php
185  }
186  $i=0;
187  $sort_order = $asset->getPageLinks();
188  foreach ($sort_order as $sort_id => $asset_info) {
189  ?>
190  <tr>
191  <td class="sq-backend-table-cell">
192  <span name="<?php echo $prefix.'_order_o'.$sort_id ?>" id="<?php echo $prefix.'_order_o'.$sort_id ?>"><?php echo $asset_infos[$asset_info['minorid']]['name']; ?></span>
193  <?php hidden_field($prefix.'_order[reorder]['.$sort_id.']', $asset_info['minorid']); ?>
194  </td>
195  <td class="sq-backend-table-cell">
196  <span name="<?php echo $prefix.'_order_t'.$sort_id ?>" id="<?php echo $prefix.'_order_t'.$sort_id ?>"><a href="<?php echo $edit_links[$asset_info['minorid']]; ?>"><?php echo translate('contents'); ?></a></span>
197  </td>
198  <?php
199  if ($write_access) {
200  ?>
201  <td class="sq-backend-table-cell">
202  <?php check_box($prefix.'_delete_page['.$sort_id.']'); ?>
203  </td>
204  <td align="center" width="100" class="sq-backend-table-cell">
205  <?php
206  if ($i != 0) {
207  ?><a href="#" onclick="sortOrderMoveUp(<?php echo $sort_id ?>); return false;"><script type="text/javascript">sq_print_icon("<?php echo sq_web_path('lib').'/web/images/icons/up_arrow.png' ?>", "16", "16", "Move Up");</script></a><?php
208  }
209  if ($i != count($sort_order) -1) {
210  ?><a href="#" onclick="sortOrderMoveDown(<?php echo $sort_id ?>); return false;"><img src="<?php echo sq_web_path('lib').'/web/images/icons/down_arrow.png' ?>" width="16" height="16" border="0"alt="Move Down" /></a><?php
211  }
212  ?>
213  </td>
214  <?php
215  $i++;
216  }
217  ?>
218  </tr>
219  <?php
220  }//end foreach
221  ?>
222  </table>
223  <?php
224 
225  if ($write_access) {
226  ?>
227  <table>
228  <tr>
229  <td>
230  <?php echo translate('create_new_page'); ?>
231  </td>
232  <td>
233  <?php text_box($prefix.'_new_page', '', '50'); ?>
234  </td>
235  </tr>
236  </table>
237  <?php
238  }
239 
240  return TRUE;
241 
242  }//end paintCurrentPages()
243 
244 
255  function processCurrentPages(&$asset, &$o, $prefix)
256  {
257  $write_access = $asset->writeAccess('content');
258 
259  $am = $GLOBALS['SQ_SYSTEM']->am;
260 
261  if (isset($_POST[$prefix.'_order']['reorder'])) {
262  $new_sort_order = $_POST[$prefix.'_order']['reorder'];
263  $new_sort_order_flip = array_flip($new_sort_order);
264  // Get the old sort_order
265  $sort_order = $asset->getPageLinks();
266  $new_paths = Array();
267  $new_paths_next = Array();
268  $switch = TRUE;
269  foreach ($sort_order as $num => $asset_info) {
270  if ($num != $new_sort_order_flip[$asset_info['minorid']]) {
271  $asset->sortOrder($asset_info['linkid'], $sort_order[$new_sort_order_flip[$asset_info['minorid']]]['sort_order'], $switch=FALSE);
272  }
273  }
274  }
275 
276  if (isset($_POST[$prefix.'_delete_page'])) {
277  if (isset($_POST[$prefix.'_order']['reorder'])) {
278  $sort_order_array = $_POST[$prefix.'_order']['reorder'];
279  }
280 
281  // Now we have sort_order_array to match, match them
282  $delete_list = Array();
283  foreach ($sort_order_array as $key => $id) {
284  if (array_get_index($_POST[$prefix.'_delete_page'],$key,NULL)) {
285  $delete_list[$id] = '1';
286  }
287  }
288  }
289 
290  if ($write_access && isset($_POST[$prefix.'_delete_page'])) {
291  // Set the following flag, so the updating of lookups doesnt cause dramas
292  $asset->_tmp['deleting_links'] = TRUE;
293  foreach ($delete_list as $id => $flag) {
294  $doomed_link = $am->getLinkByAsset($asset->id, $id);
295  $am->moveLink($doomed_link['linkid'], $am->getSystemAssetid('trash_folder'), SQ_LINK_TYPE_2, '0');
296  $deleted = $am->getAsset($doomed_link['minorid']);
297  $deleted->saveWebPaths(Array());
298  }
299  }
300  // Restore the flag set above
301  $asset->_tmp['deleting_links'] = FALSE;
302 
303  if ($write_access && isset($_POST[$prefix.'_new_page']) && !empty($_POST[$prefix.'_new_page'])) {
304  $asset->createChildPage($_POST[$prefix.'_new_page']);
305  }
306 
307  $asset->_tmp['no_sort_order_paths'] = TRUE;
308  $asset->linksUpdated();
309 
310  return $write_access;
311 
312  }//end processCurrentPages()
313 
314 
315 }//end class
316 
317 ?>