Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
calendar_event_multi_date_edit_fns.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 require_once SQ_PACKAGES_PATH.'/calendar/calendar_events/calendar_event_single/calendar_event_single_edit_fns.inc';
20 require_once SQ_PACKAGES_PATH.'/calendar/calendar_events/calendar_event_recurring/calendar_event_recurring_edit_fns.inc';
21 
22 
33 {
34 
35 
41  {
42  $this->Asset_Edit_Fns();
43  $this->_tmp['single_edit_fns'] = new Calendar_Event_Single_Edit_Fns();
44  $this->_tmp['rec_edit_fns'] = new Calendar_Event_Recurring_Edit_Fns();
45 
46  }//end constructor
47 
48 
59  function paintDates(&$asset, &$o, $prefix)
60  {
61  $wa = $asset->writeAccess('attributes');
62  ?>
63  <style type="text/css">
64  td.single table td, td.recurring table td {
65  border: 0px;
66  padding: 1px;
67  }
68  </style>
69 
70  <table border="1" cellspacing="0" cellpadding="4" class="sq-backend-table">
71  <thead>
72  <tr>
73  <th>Type</th>
74  <th>Details</th>
75  <?php
76  if ($wa) {
77  ?>
78  <th>Delete</th>
79  <?php
80  }
81  ?>
82  </tr>
83  </thead>
84  <tbody>
85  <?php
86  if ($asset->id) {
87  $children = $GLOBALS['SQ_SYSTEM']->am->getChildren($asset->id, Array('calendar_event_single', 'calendar_event_recurring'));
88  foreach ($children as $id => $type) {
89  $_type = $type[0]['type_code'];
90  $event_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($id, $_type);
91  $this->_printDateRow($prefix, $event_asset, $o, $wa);
92  }
93  }
94  if ($wa) $this->_printDateTemplate($prefix, $o);
95  ?>
96  </tbody>
97  </table>
98  <?php
99  if ($wa) {
100  ?>
101  <script type="text/javascript" src="<?php echo sq_web_path('data'); ?>/asset_types/calendar_event_multi_date/js/dates_chooser.js"></script>
102  <?php
103  normal_button('', 'More Dates...', 'addDate()');
104  }
105 
106  }//end paintDates()
107 
108 
120  function _printDateRow($prefix, $event_asset, $o, $write_access)
121  {
122  if ($write_access) {
123  $GLOBALS['SQ_SYSTEM']->am->acquireLock($event_asset->id, 'attributes');
124  } else {
125  $GLOBALS['SQ_SYSTEM']->am->releaseLock($event_asset->id, 'attributes');
126  }
127  $type_name = str_replace('calendar_event_', '', $event_asset->type());
128  if (is_a($event_asset, 'calendar_event_single') || is_a($event_asset, 'calendar_event_recurring')) {
129  ?>
130  <tr>
131  <td>
132  <a href="<?php echo $event_asset->getBackendHref('details'); ?>">
133  <?php echo ucfirst($type_name); ?> Instance #<?php echo $event_asset->id; ?>
134  </a>
135  </td>
136  <td class="<?php echo $type_name; ?>">
137  <?php
138  if (is_a($event_asset, 'calendar_event_single')) {
139  $this->_tmp['single_edit_fns']->paintSingleStartEndChooser($event_asset, $o, $prefix.'_existing_'.$event_asset->id);
140  } else if (is_a($event_asset, 'calendar_event_recurring')) {
141  // recurring
142  $this->_tmp['rec_edit_fns']->paintRecurringStartEndChooser($event_asset, $o, $prefix.'_existing_'.$event_asset->id);
143  if ($write_access) {
144  echo '<br />Recurs<br />';
145  $this->_tmp['rec_edit_fns']->paintFrequencyField($event_asset, $o, $prefix.'_existing_'.$event_asset->id);
146  } else {
147  echo ', and then ';
148  ob_start();
149  $this->_tmp['rec_edit_fns']->paintFrequencyField($event_asset, $o, $prefix.'_existing_'.$event_asset->id);
150  $res = ob_get_clean();
151  echo strtolower($res{0}).substr($res, 1); // I want lcfirst!!
152  }
153  }
154  ?>
155  </td>
156  <td style="display: none"></td>
157  <?php
158  if ($write_access) {
159  ?>
160  <td><?php check_box($prefix.'_existing_'.$event_asset->id.'_delete'); ?></td>
161  <?php
162  }
163  ?>
164  </tr>
165  <?php
166  }//end if
167 
168  }//end _printDateRow()
169 
170 
180  function _printDateTemplate($prefix, $o)
181  {
182  $GLOBALS['SQ_SYSTEM']->am->includeAsset('calendar_event_recurring');
183  $fake_rec_event = new Calendar_Event_Recurring();
184  $GLOBALS['SQ_SYSTEM']->am->includeAsset('calendar_event_single');
185  $fake_single_event = new Calendar_Event_Single();
186  ?>
187  <tr id="template" style="display: none">
188  <td style="white-space: nowrap; vertical-align: top">
189  <?php
190  radio_button($prefix.'_new_type_template', 'single', TRUE, 'setEventType(this)', 'id="'.$prefix.'_new_type_template_single"');
191  label('Single Instance', $prefix.'_new_type_template_single');
192  echo '<br />';
193  radio_button($prefix.'_new_type_template', 'recurring', FALSE, 'setEventType(this)', 'id="'.$prefix.'_new_type_template_recurring"');
194  label('Recurring Instance', $prefix.'_new_type_template_recurring');
195  echo '<br />';
196  ?>
197  </td>
198  <td class="single">
199  <?php
200  $this->_tmp['single_edit_fns']->paintSingleStartEndChooser($fake_single_event, $o, $prefix.'_new_single_template');
201  ?>
202  </td>
203  <td class="recurring" style="display: none">
204  <?php
205  $this->_tmp['rec_edit_fns']->paintRecurringStartEndChooser($fake_rec_event, $o, $prefix.'_new_recurring_template');
206  echo '<br />Recurs<br />';
207  $this->_tmp['rec_edit_fns']->paintFrequencyField($fake_rec_event, $o, $prefix.'_new_recurring_template');
208  ?>
209  </td>
210  <td>
211  <?php sq_print_icon(sq_web_path('lib').'/web/images/icons/delete.png', 16, 16, 'Delete New Row', 'Delete New Row', 'onclick="if (confirm(\'Delete new instance?\')) deleteRow(this)" style="cursor: pointer"'); ?>
212  </td>
213  </tr>
214  <?php
215 
216  }//end _printDateTemplate()
217 
218 
229  function processDates(&$asset, &$o, $prefix)
230  {
231  if ($asset->id) {
232  // Existing instances
233  if (!$asset->writeAccess('attributes')) return FALSE;
234  $children = $GLOBALS['SQ_SYSTEM']->am->getChildren($asset->id, Array('calendar_event_single', 'calendar_event_recurring'));
235  foreach ($children as $id => $type) {
236 
237  if (strpos($id, ':') !== FALSE) continue;
238 
239  if (isset($_POST[$prefix.'_existing_'.$id.'_delete'])) {
240  if ($GLOBALS['SQ_SYSTEM']->am->trashAsset($id)) {
241  $instance = $GLOBALS['SQ_SYSTEM']->am->getAsset($id);
242  $instance->saveWebPaths(Array(), FALSE);
243  }
244  } else {
245  $type = $type[0]['type_code'];
246  $event_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($id, $type);
247  $need_save = FALSE;
248  if ($type == 'calendar_event_single') {
249  $need_save |= $this->_tmp['single_edit_fns']->processSingleStartEndChooser($event_asset, $o, $prefix.'_existing_'.$event_asset->id);
250  } else {
251  // recurring event
252  $need_save |= $this->_tmp['rec_edit_fns']->processRecurringStartEndChooser($event_asset, $o, $prefix.'_existing_'.$event_asset->id);
253  $need_save |= $this->_tmp['rec_edit_fns']->processFrequencyField($event_asset, $o, $prefix.'_existing_'.$event_asset->id);
254  }
255  if ($need_save) {
256  $GLOBALS['SQ_SYSTEM']->am->acquireLock($event_asset->id, 'attributes');
257  $event_asset->saveAttributes();
258  }
259  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($id);
260  }
261  }
262  }
263 
264  //if we are going to manipulate asset while is safe edit, let us first save its links beforehand
265  if ($asset->status & SQ_SC_STATUS_SAFE_EDITING) {
266  if (!file_exists($asset->data_path.'/.safe_edit_before')) {
267  $child_events = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_3, Array('calendar_event_single', 'calendar_event_recurring'), FALSE);
268  file_put_contents($asset->data_path.'/.safe_edit_before', serialize($child_events));
269  }
270  }
271 
272  // New instances
273  $i = 0;
274  $GLOBALS['SQ_SYSTEM']->am->includeAsset('calendar_event_single');
275  $GLOBALS['SQ_SYSTEM']->am->includeAsset('calendar_event_recurring');
276  while (isset($_POST[$prefix.'_new_type_'.$i])) {
277  if (!empty($_POST[$prefix.'_new_type_'.$i])) {
278  switch ($_POST[$prefix.'_new_type_'.$i]) {
279  case 'single':
280  $new_asset = new Calendar_Event_Single();
281  $this->_tmp['single_edit_fns']->processSingleStartEndChooser($new_asset, $o, $prefix.'_new_single_'.$i);
282  break;
283 
284  case 'recurring':
285  $new_asset = new Calendar_Event_Recurring();
286  $this->_tmp['rec_edit_fns']->processRecurringStartEndChooser($new_asset, $o, $prefix.'_new_recurring_'.$i);
287  $this->_tmp['rec_edit_fns']->processFrequencyField($new_asset, $o, $prefix.'_new_recurring_'.$i);
288  break;
289  }
290  $new_asset->setAttrValue('name', $asset->attr('name'));
291  $link = Array(
292  'asset' => &$asset,
293  'link_type' => SQ_LINK_TYPE_3,
294  'value' => '',
295  'sort_order' => -1,
296  'is_dependant' => TRUE,
297  'is_exclusive' => TRUE,
298  );
299  if ($asset->id) {
300  $new_asset->create($link);
301  //we are done creating asset instance, lets make sure bug # 4168 doesnt occur
302  if ($asset->status & SQ_SC_STATUS_SAFE_EDITING) {
303  if ($new_asset->status != SQ_STATUS_EDITING) {
304  // Drop to a run level to force the status change to SQ_STATUS_EDITING (saveSystemVersion() so it can go back to LIVE)
305  $GLOBALS['SQ_SYSTEM']->setRunLevel(191);
306  $new_asset->saveSystemVersion();
307  $new_asset->processStatusChange(SQ_STATUS_EDITING, FALSE);
308  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
309  }
310  }
311  } else {
312  // line it up for creation after the parent asset is created
313  $asset->addPendingChild($new_asset, $link);
314  }
315  }//end if
316  $i++;
317  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($new_asset);
318  }//end while
319 
320  //adding all the new instances, save the current links to file
321  if ($asset->status & SQ_SC_STATUS_SAFE_EDITING){
322  $child_events = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_3, Array('calendar_event_single', 'calendar_event_recurring'), FALSE);
323  file_put_contents($asset->data_path.'/.safe_edit_after', serialize($child_events));
324  }
325 
326  }//end processDates()
327 
328 
339  function redirectToBodycopy(&$asset, &$o, $prefix)
340  {
341  // get the bodycopy attached to us
342  $bodycopy_link = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, 'major', NULL, '1', '0');
343  $bodycopy = $GLOBALS['SQ_SYSTEM']->am->getAsset($bodycopy_link[0]['minorid'], 'bodycopy');
344 
345  if (is_null($bodycopy)) {
346  trigger_localised_error('CORE0016', E_USER_ERROR, $asset->name);
347  return FALSE;
348  }
349 
350  // redirect to the bodycopy's edit contents screen
351  $o->setRedirect($bodycopy->getBackendHref('contents'));
352 
353  // fudge the navigation history a little so when they click on the link to ger back to the
354  // page it doesnt take them to the edit contents screen and then redirect them again
355  $_SESSION['sq_nav_history'][(count($_SESSION['sq_nav_history']) - 1)]['screen'] = 'details';
356 
357  return FALSE;
358 
359  }//end redirectToBodycopy()
360 
361 
362 }//end class
363 
364 ?>