Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
settings.inc
1 <?php
17 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
18 
39 function paintSettings(&$owner, &$o, &$ei, $keywords=NULL)
40 {
41  $root = $ei->findScreen('static_screen_settings');
42  if (is_null($root)) return FALSE;
43 
44  $prefix = $owner->getPrefix();
45 
46  $created = FALSE;
47 
48  if (count($root->children()) == 0) {
49  $o->openSection(translate('no_asset_settings', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)));
50  $o->closeSection();
51  }
52 
53  foreach ($root->section as $section) {
54 
55  // if we are in limbo and this section is not to be printed in limbo - dont print it
56  if (is_null($keywords)) {
57  if (SQ_IN_LIMBO && ((string) $section['name'] === 'limbo_access' || (int) $section['limbo_access'] === 0)) {
58  continue;
59  }
60  }
61 
62  if (!is_null($keywords) && isset($keywords['sections'][strtolower($section->attributes()->name)])) {
63  ob_start();
64  }
65 
66  $o->openSection((is_null($section['display_name'])) ? $section['name'] : $section['display_name']);
67 
68  foreach ($section->children() as $field) {
69  // should we print the note for the field or not
70  $print_note = TRUE;
71 
72  switch (strtolower((string) $field['code'])) {
73  case 'version_current_version' :
74  if ((string) $field['children'][0]['name'] != 'display_name') {
75  $display_name = translate('current_version');
76  } else {
77  $display_name = (string) $field['children'][0]['content'];
78  }
79  $o->openField($display_name);
80  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
81  ob_start();
82  }
83  echo $owner->version;
84  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
85  $ei->_tmp['layout_keyword_replacements'][$keywords['fields'][strtolower((string) $field['code'])]] = ob_get_contents();
86  ob_end_flush();
87  }
88  $o->closeField();
89  break;
90  case 'version_update_version' :
91  // have to have admin access to update the major version
92  if ($owner->adminAccess('all')) {
93  $created = TRUE;
94 
95  if ((string) $field['children'][0]['name'] != 'display_name') {
96  $display_name = translate('update_major_version');
97  } else {
98  $display_name = (string) $field['children'][0]['content'];
99  }
100  $o->openField($display_name);
101  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
102  ob_start();
103  }
104 
105  check_box($prefix.'_version_update_version');
106  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
107  $ei->_tmp['layout_keyword_replacements'][$keywords['fields'][strtolower((string) $field['code'])]] = ob_get_contents();
108  ob_end_flush();
109  }
110  $o->closeField();
111  } else {
112  $print_note = FALSE;
113  }
114  break;
115 
116  case 'date_created_date' :
117  case 'date_published_date' :
118 
119  $date_type = (strtolower((string) $field['code']) === 'date_created_date') ? 'created' : 'published';
120  require_once SQ_FUDGE_PATH.'/datetime_field/datetime_field.inc';
121  $parameters = Array(
122  'min' => '0000-00-00 00:00:00',
123  'max' => '9999-12-31 12:59:59',
124  'allow_circa' => '0',
125  'show' => Array('y', 'm', 'd', 'h', 'i', 's'),
126  'null' => Array('y', 'm', 'd', 'h', 'i', 's'),
127  'style' => Array(
128  'y' => 't',
129  'm' => 's',
130  'd' => 's',
131  'h' => 's',
132  'i' => 's',
133  's' => 's',
134  ),
135  'print_format' => 'l, F jS, Y H:i:s',
136  );
137 
138  if ($date_type == 'created') {
139  $value = (!empty($owner->created)) ? ts_iso8601($owner->created) : '---------- --:--:--';
140  $userid = $owner->created_userid;
141  } else {
142  $value = (!empty($owner->published)) ? ts_iso8601($owner->published) : '---------- --:--:--';
143  $userid = $owner->published_userid;
144  }
145 
146  if ((string) $field['children'][0]['name'] !== 'display_name') {
147  $display_name = translate($date_type.'_date');
148  } else {
149  $display_name = (string) $field['children'][0]['content'];
150  }
151  $o->openField($display_name);
152  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
153  ob_start();
154  }
155 
156  $date_field = new Datetime_Field($prefix.'_date_'.$date_type, $value, $parameters);
157 
158  if ($owner->adminAccess('all')) {
159  $date_field->printField();
160 
161  ?>
162  <script language="javascript">
163  var TIME_UNITS = new Array();
164  <?php
165  $units = Array(
166  'Y' => 'y',
167  'n' => 'm',
168  'j' => 'd',
169  'G' => 'h',
170  'i' => 'i',
171  's' => 's',
172  );
173 
174  foreach ($units as $php_unit => $js_unit) {
175  echo 'TIME_UNITS[\''.$js_unit.'\'] = \''.date($php_unit).'\';';
176  }
177  ?>
178 
179  function setCurrentTime(prefix) {
180  for (u in TIME_UNITS) {
181  var id = prefix + 'value_' + u;
182  var unit = document.getElementById(id);
183 
184  if (unit.type == 'text') {
185  unit.value = TIME_UNITS[u];
186  } else {
187  for (var i = 0; i < unit.options.length; i++) {
188  if (TIME_UNITS[u] == unit.options[i].value) {
189  unit.selectedIndex = i;
190  }
191  }
192  }
193  }
194  }
195  </script>
196  <?php
197  normal_button($prefix.'_set_time_'.$date_type, strtolower(translate('now')), 'setCurrentTime(\''.$prefix.'_date_'.$date_type.'\');');
198  echo '&nbsp;<b>'.strtolower(translate('by')).'</b>&nbsp;';
199  asset_finder($prefix.'_date_'.$date_type.'_userid', $userid, Array('user' => 'D'));
200 
201  } else {
202  $print_note = FALSE;
203  if ($date_field->isEmpty() && $date_type == 'published') {
204  echo translate('never_published');
205  } else {
206  $info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($userid), 'user', FALSE);
207  if (empty($info)) {
208  $info[$userid] = Array('name' => '&lt;unknown&gt;');
209  }
210 
211  echo ucfirst($date_type).' '.strtolower(translate('by')).' '.htmlspecialchars($info[$userid]['name'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).' '.strtolower(translate('on')).' '.date('d M Y H:i:s', strtotime($date_field->value));
212 
213  }
214  }
215  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
216  $ei->_tmp['layout_keyword_replacements'][$keywords['fields'][strtolower((string) $field['code'])]] = ob_get_contents();
217  ob_end_flush();
218  }
219  $o->closeField();
220 
221  break;
222 
223  case 'force_secure' :
224  if ((string) $field['children'][0]['name'] != 'display_name') {
225  $display_name = translate('force_secure');
226  } else {
227  $display_name = $field['children'][0]['content'];
228  }
229  $o->openField($display_name);
230  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
231  ob_start();
232  }
233  $current_langs = $owner->getLanguages();
234  // have to have admin access to set the force secure
235  $options = Array(
236  '0' => 'Allow all protocols',
237  '1' => 'Force secure protocol (HTTPS)',
238  '-' => 'Force insecure protocol (HTTP)',
239  );
240  if ($owner->adminAccess('settings')) {
241  $created = TRUE;
242  combo_box($prefix.'_force_secure', $options, FALSE, $owner->force_secure);
243  //check_box($prefix.'_force_secure', '1', ($owner->force_secure == '1'));
244  } else {
245  echo $options[$owner->force_secure];
246  /* ?>
247  <img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo ($owner->force_secure) ? 'tick' : 'cross'; ?>.gif" width="15" height="15" />
248  <?php */
249  }
250  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
251  $ei->_tmp['layout_keyword_replacements'][$keywords['fields'][strtolower((string) $field['code'])]] = ob_get_contents();
252  ob_end_flush();
253  }
254  $o->closeField();
255  break;
256 
257 
258  case 'intl_languages' :
259 
260  if ($field['children'][0]['name'] != 'display_name') {
261  $display_name = translate('languages');
262  } else {
263  $display_name = $field['children'][0]['content'];
264  }
265 
266  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
267  ob_start();
268  }
269  $o->openSection($display_name);
270 
271  require SQ_FUDGE_PATH.'/standards_lists/languages.inc';
272 
273  if ($owner->writeAccess('settings')) {
274  $created = TRUE;
275  $standards_lists_languages = array_reverse($standards_lists_languages);
276  $standards_lists_languages[''] = '';
277  $standards_lists_languages = array_reverse($standards_lists_languages);
278  $o->openField(translate('add_language'));
279  combo_box($prefix.'_add_intl_language', $standards_lists_languages, FALSE, '');
280  $o->closeField();
281  }
282 
283  $o->openField(translate('current'));
284  $current_langs = $owner->getLanguages();
285  if (!empty($current_langs)) {
286  sort($current_langs);
287  ?>
288  <table class="sq-backend-table" style="width: 0%;">
289  <?php if ($owner->writeAccess('settings')) {
290  ?>
291  <tr>
292  <td class="sq-backend-table-header">&nbsp;</td>
293  <td class="sq-backend-table-header"><b><?php echo translate('delete_question'); ?></b></td>
294  </tr>
295  <?php }
296  ?>
297  <?php
298  foreach ($current_langs as $lang_code) {
299  ?>
300  <tr>
301  <td class="sq-backend-table-cell"><?php echo $standards_lists_languages[$lang_code]; ?></td>
302  <?php if ($owner->writeAccess('settings')) {
303  $created = TRUE;
304  ?>
305  <td class="sq-backend-table-cell" align="center"><?php check_box($prefix.'_rem_intl_language['.$lang_code.']'); ?></td>
306  <?php }
307  ?>
308  </tr>
309  <?php
310  }
311  ?></table><?php
312  } else {
313  echo translate('no_language_set', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
314  }
315 
316  $o->closeField();
317 
318  $o->closeSection();
319  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
320  $ei->_tmp['layout_keyword_replacements'][$keywords['fields'][strtolower((string) $field['code'])]] = ob_get_contents();
321  ob_end_flush();
322  }
323  break;
324 
325  case 'intl_character_set' :
326  if ($field['children'][0]['name'] != 'display_name') {
327  $display_name = translate('character_set');
328  } else {
329  $display_name = $field['children'][0]['content'];
330  }
331 
332  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
333  ob_start();
334  }
335 
336  $o->openSection($display_name);
337  $o->openField('Current');
338  require SQ_FUDGE_PATH.'/standards_lists/character_sets.inc';
339 
340  if ($owner->writeAccess('settings')) {
341  $created = TRUE;
342  $standards_lists_character_sets = array_reverse($standards_lists_character_sets);
343  $standards_lists_character_sets[''] = '** Use System Default **';
344  $standards_lists_character_sets = array_reverse($standards_lists_character_sets);
345  combo_box($prefix.'_intl_character_set', $standards_lists_character_sets, FALSE, $owner->charset);
346  } else {
347  if (isset($standards_lists_character_sets[$owner->charset])) {
348  echo $standards_lists_character_sets[$owner->charset];
349  } else if ($owner->charset == '') {
350  echo translate('no_character_set', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
351  } else {
352  echo '<i>'.translate('no_charactet_set_set', $owner->charset, htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)).'</i>';
353  }
354  }
355  $o->closeField();
356  $o->closeSection();
357  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
358  $ei->_tmp['layout_keyword_replacements'][$keywords['fields'][strtolower((string) $field['code'])]] = ob_get_contents();
359  ob_end_flush();
360  }
361  break;
362 
363  case 'morph_new_type' :
364  if ($field['children'][0]['name'] != 'display_name') {
365  $display_name = translate('new_type');
366  } else {
367  $display_name = $field['children'][0]['content'];
368  }
369 
370  $o->openField($display_name);
371  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
372  ob_start();
373  }
374 
375  if ($owner->adminAccess('all')) {
376  $created = TRUE;
377  if ($owner->status != SQ_STATUS_UNDER_CONSTRUCTION) {
378  // cant morph an asset if it is not under construction
379  echo translate('only_morph_under_construction');
380  } else {
381  $db = MatrixDAL::getDb();
382  $am = $GLOBALS['SQ_SYSTEM']->am;
383  $user = $am->getAsset($GLOBALS['SQ_SYSTEM']->currentUserid());
384 
385  $types = array_merge($am->getTypeAncestors($owner->type()), $am->getTypeDescendants($owner->type()));
386  for ($i = 0; $i < count($types); $i++) {
387  $types[$i] = '\''.$types[$i].'\'';
388  }
389  $type_code_cond = 'IN ('.implode(', ', $types).')';
390 
391  $user_types = $am->getTypeAncestors($user->type());
392  $user_types[] = $user->type();
393  for ($i = 0; $i < count($user_types); $i++) {
394  $user_types[$i] = '\''.$user_types[$i].'\'';
395  }
396  $user_type_cond = 'IN ('.implode(', ', $user_types).')';
397 
398  $sql = 'SELECT type_code
399  FROM sq_ast_typ
400  WHERE allowed_access '.$user_type_cond.'
401  AND type_code '.$type_code_cond;
402 
403  try {
404  $query = MatrixDAL::preparePdoQuery($sql);
405  $result = MatrixDAL::executePdoAssoc($query, 0);
406  } catch (Exception $e) {
407  throw new Exception('Unable to get type codes for these user types: '.$user_types.' due to database error: '.$e->getMessage());
408  }
409 
410  if (empty($result)) {
411  echo translate('no_types_to_morph');
412  } else {
413  $morph_types = Array('' => '');
414  foreach ($result as $type_code) {
415  $code_name = str_replace('_', ' ', $type_code);
416  $code_name = ucwords($code_name);
417  $morph_types[$type_code] = $code_name;
418  }
419  combo_box($prefix.'_morph_new_type', $morph_types, FALSE, '');
420  ?>
421  <table border="0">
422  <tr>
423  <td class="sq-backend-data"><?php echo translate('morph_confirmation'); ?></td>
424  </tr>
425  <tr>
426  <td valign="top"><?php security_key(15, 20, 2); ?></td>
427  </tr>
428  </table>
429  <?php
430  }
431  }//end else
432  } else {
433  echo translate('morph_no_access');
434  }
435 
436  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
437  $ei->_tmp['layout_keyword_replacements'][$keywords['fields'][strtolower((string) $field['code'])]] = ob_get_contents();
438  ob_end_flush();
439  }
440  $o->closeField();
441  break;
442 
444 
445  case 'designs' :
446  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
447  ob_start();
448  }
449  $system_designs = Array(
450  'design::system::frontend' => translate('asset_frontend_design'),
451  'design::system::login' => translate('asset_design_user_no_permissions'),
452  'design::system::password_change' => translate('asset_design_change_password'),
453  );
454  $our_designs = Array(
455  'design::system::frontend' => 0,
456  'design::system::login' => 0,
457  'design::system::password_change' => 0,
458  );
459  $override_designs = Array(
460  'design::system::frontend' => 0,
461  'design::system::login' => 0,
462  'design::system::password_change' => 0,
463  );
464 
465  $our_design_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($owner->id, SQ_LINK_NOTICE, 'design', FALSE);
466 
467  foreach ($our_design_links as $link) {
468  if (preg_match('/^design::(system|user)::.*$/', $link['value'])) {
469  $our_designs[$link['value']] = $link['minorid'];
470  } else if (preg_match('/^override::design::(system|user)::.*$/', $link['value'])) {
471  $design_name = preg_replace('/^override::(.*)$/', '$1', $link['value']);
472  $override_designs[$design_name] = $link['minorid'];
473  }// end if
474  }// end foreach
475 
476  // Get the designs that are associated with our lookups
477  $design_lookups = $owner->getDesignLookups();
478 
479  // If we have a user design that is only effectively set, then we need to add it to the our_designs
480  // array otherwise it doesn't appear below...
481  foreach ($design_lookups as $url => $designs) {
482  foreach ($designs as $design_name => $designid) {
483  if (!isset($our_designs[$design_name])) {
484  $our_designs[$design_name] = 0;
485  }
486  }
487  }
488 
489  // now add the blank one that they can customise
490  $our_designs['design::user::'] = 0;
491 
492  foreach ($our_designs as $design_name => $designid) {
493 
494  $override_designid = array_get_index($override_designs, $design_name, 0);
495  $matches = Array();
496  preg_match('/^design::(system|user)::(.*)$/', $design_name, $matches);
497 
498  $design_type = $matches[1];
499  $design_code = $matches[2];
500  $new_user_design = ($design_type == 'user' && $design_code == '' && !$designid);
501  if ($new_user_design && !$owner->writeAccess('links')) {
502  continue;
503  }
504 
505  if (!$new_user_design) {
506  $display_name = translate('config_display_name', ucwords($design_type), ucwords(str_replace('_', ' ', $design_code)));
507  } else {
508  $display_name = translate('create_new_user_defined_design');
509  }
510 
511  $o->openSection($display_name);
512 
513  if ($new_user_design) {
514  $o->openField(translate('design_code'));
515  text_box($prefix.'_designs['.$design_name.'][name]', '', 20, 30);
516  $o->closeField();
517  } else {
518  $o->openRaw();
519  hidden_field($prefix.'_designs['.$design_name.'][name]', $design_name);
520  $o->closeRaw();
521 
522  if ($design_type == 'user') {
523  $o->openField(translate('design_code'));
524  echo $design_code;
525  $o->closeField();
526  }
527  }
528 
529  if (!$new_user_design) {
530  $effective_designs = Array();
531  foreach ($design_lookups as $url => $designs) {
532  if (empty($designs[$design_name])) continue;
533  $effective_designs[$url] = $designs[$design_name];
534  }
535 
536  $o->openField(translate('current'));
537 
538  if (!empty($effective_designs)) {
539  ?>
540  <table class="sq-backend-table">
541  <tr>
542  <td class="sq-backend-table-header"><?php echo translate('url'); ?></td>
543  <td class="sq-backend-table-header"><?php echo translate('effective_design'); ?></td>
544  </tr>
545  <?php
546  foreach ($effective_designs as $url => $effective_designid) {
547  $effective_design_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($effective_designid));
548  if (empty($effective_design_info)) continue;
549  ?>
550  <tr>
551  <td class="sq-backend-table-cell"><?php echo $url; ?></td>
552  <td class="sq-backend-table-cell"><?php echo get_asset_tag_line($effective_designid); ?></td>
553  </tr>
554  <?php
555  }
556  ?>
557  </table>
558  <?php
559  } else {
560  echo translate('no_effective_designs');
561  }
562 
563  $o->closeField();
564  }//end if
565 
566  $o->openField(($designid) ? translate('change_question') : translate('new_question'));
567 
568  if (!$owner->writeAccess('links')) {
569  echo '<i>';
570  if (!$designid) {
571  echo translate('none');
572  } else {
573  echo get_asset_tag_line($designid);
574  }
575  echo '</i>';
576 
577  } else {
578  $created = TRUE;
579  $buttons = Array('clear');
580  if (!$new_user_design) $buttons[] = 'reset';
581  asset_finder($prefix.'_designs['.$design_name.'][designid]', $designid, Array('design' => 'D'), 'sq_sidenav', FALSE, 'null', $buttons);
582  }
583 
584 
585  if ($design_type == 'system' && isset($system_designs[$design_name])) {
586  $o->note($system_designs[$design_name]);
587  }
588 
589  $o->closeField();
590 
591  $o->openField(translate('override_design_question'));
592 
593  if (!$owner->writeAccess('links')) {
594  echo '<i>';
595  if (!$override_designid) {
596  echo translate('none');
597  } else {
598  echo get_asset_tag_line($override_designid);
599  }
600  echo '</i>';
601 
602  } else {
603  $created = TRUE;
604  $buttons = Array('clear');
605  if (!$new_user_design) $buttons[] = 'reset';
606  asset_finder($prefix.'_designs['.$design_name.'][override]', $override_designid, Array('design' => 'D'), 'sq_sidenav', FALSE, 'null', $buttons);
607  }
608 
609 
610  $o->note(translate('override_design_explanation'));
611 
612 
613  $o->closeField();
614 
615  $o->closeSection();
616  }//end foreach
617 
618  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
619  $ei->_tmp['layout_keyword_replacements'][$keywords['fields'][strtolower((string) $field['code'])]] = ob_get_contents();
620  ob_end_flush();
621  }
622 
623  break;
624 
625  }//end switch
626 
627  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
628  ob_start();
629  }
630  // before printing the note, we make sure that the note element exists and is not empty
631  if ($print_note && (!is_null($field->note)) && (strlen((string)$field->note) > 0)) {
632  $o->openField('&nbsp;');
633  $o->note((string) $field->note);
634  $o->closeField();
635  }
636  if (!is_null($keywords) && isset($keywords['fields'][strtolower((string) $field['code'])])) {
637  $ei->_tmp['layout_keyword_replacements'][$keywords['fields'][strtolower((string) $field['code'])]] .= ob_get_contents();
638  ob_end_flush();
639  }
640 
641  }//end for
642 
643  $o->closeSection();
644 
645  if (!is_null($keywords) && isset($keywords['sections'][strtolower((string) $section['name'])])) {
646  $ei->_tmp['layout_keyword_replacements'][$keywords['sections'][strtolower((string) $section['name'])]] = ob_get_contents();
647  ob_end_flush();
648  }
649 
650  }//end for
651 
652 
653  return $created;
654 
655 }//end paintSettings()
656 
657 
669 function processSettings(&$owner, &$o, &$ei)
670 {
671  $prefix = $owner->getPrefix();
672 
673  // this is an array of assetids that are going to need their lookups updated
674  $assets_affected_lookups = Array();
675 
677  if ($owner->adminAccess('all')) {
678  if (isset($_POST[$prefix.'_version_update_version'])) {
679  if (!$owner->incrementVersion('major')) {
680  trigger_localised_error('SYS0184', E_USER_WARNING, $owner->name);
681  }
682  }
683  }
684 
686  if ($owner->adminAccess('all')) {
687  require_once SQ_FUDGE_PATH.'/datetime_field/datetime_field.inc';
688 
689  foreach (Array('created', 'published') as $date_type) {
690 
691  // check to see if a user was selected for this particular date,
692  // otherwise use the current logged in user
693  if (isset($_POST[$prefix.'_date_'.$date_type.'_userid']['assetid']) && $_POST[$prefix.'_date_'.$date_type.'_userid']['assetid'] != 0) {
694  $userid = $_POST[$prefix.'_date_'.$date_type.'_userid']['assetid'];
695  } else {
696  $userid = $GLOBALS['SQ_SYSTEM']->currentUserid();
697  }
698 
699  $value = '';
700  $parameters = Array(
701  'min' => '0000-00-00 00:00:00',
702  'max' => '9999-12-31 12:59:59',
703  'allow_circa' => '0',
704  'show' => Array('y', 'm', 'd', 'h', 'i', 's'),
705  'null' => Array('y', 'm', 'd', 'h', 'i', 's'),
706  'style' => Array(
707  'y' => 't',
708  'm' => 's',
709  'd' => 's',
710  'h' => 's',
711  'i' => 's',
712  's' => 's',
713  ),
714  'print_format' => 'l, F jS, Y H:i:s',
715  );
716 
717  $date_field = new Datetime_Field($prefix.'_date_'.$date_type, $value, $parameters);
718  $date_field->processField();
719 
720  // if the date is only partially complete, then don't set the date
721  if (!$date_field->isEmpty() && !preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2} ([0-9]{2}\:?){3}$/", $date_field->value)) {
722  continue;
723  }
724 
725  if ($date_type == 'created') {
726  // make sure that the date that is specified is not null for the created date
727  if ($date_field->isEmpty()) {
728  trigger_localised_error('SYS0212', E_USER_WARNING);
729  continue;
730  }
731  $current_date = $owner->created;
732  $current_userid = $owner->created_userid;
733  } else {
734  $current_date = $owner->published;
735  $current_userid = $owner->published_userid;
736  }
737 
738  if ($date_field->value != $current_date || $current_userid != $userid) {
739  $timestamp = (!$date_field->isEmpty()) ? strtotime($date_field->value) : NULL;
740 
741  // the timestamp will be -1 if the date exceeds a 32bit integer
742  if ($timestamp === -1) continue;
743 
744  $owner->setDate($date_type, $timestamp, $userid);
745  }
746  }//end foreach
747  }//end if
748 
749 
751  if ($owner->adminAccess('settings')) {
752  if ($owner->setForceSecure(array_get_index($_POST, $prefix.'_force_secure', 0))) {
753  $assets_affected_lookups[] = $owner->id;
754  }// end if
755  }// end if
756 
757 
759  $current_langs = $owner->getLanguages();
760  $set_languages = Array();
761 
762  if (!isset($_POST[$prefix.'_rem_intl_language'])) {
763  $_POST[$prefix.'_rem_intl_language'] = Array();
764  }
765 
766  // add a new language
767  if (isset($_POST[$prefix.'_add_intl_language']) && !empty($_POST[$prefix.'_add_intl_language'])) {
768  $new_language = $_POST[$prefix.'_add_intl_language'];
769  if (!in_array($new_language, $current_langs)) {
770  $set_languages[] = $new_language;
771  }
772  }
773 
774  // check for delete languages
775  foreach ($current_langs as $lang_code) {
776  if (!isset($_POST[$prefix.'_rem_intl_language'][$lang_code])) {
777  $set_languages[] = $lang_code;
778  }
779  }
780 
781  $owner->setLanguages($set_languages);
782 
783 
785  if (isset($_POST[$prefix.'_intl_character_set'])) {
786  $new_charset = $_POST[$prefix.'_intl_character_set'];
787  $owner->setCharset($new_charset);
788  }
789 
790 
792  if ($owner->adminAccess('all') && $owner->status == SQ_STATUS_UNDER_CONSTRUCTION) {
793  if (isset($_POST[$prefix.'_morph_new_type']) && !empty($_POST[$prefix.'_morph_new_type'])) {
794  // check that the security key was entered correctly
795  if (validate_security_key()) {
796  // errors for morphing will get reported in the morph function
797  $owner->morph($_POST[$prefix.'_morph_new_type']);
798  } else {
799  trigger_localised_error('SYS0214', E_USER_WARNING);
800  }
801  }
802  }
803 
804  $update_design_cascade = FALSE;
806  if (!empty($_POST[$prefix.'_designs']) && $owner->writeAccess('links')) {
807 
808  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
809  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
810  $designs_ok = TRUE;
811  $designs_changed = FALSE;
812 
813  foreach ($_POST[$prefix.'_designs'] as $design_name => $design_data) {
814 
815  $new_designid = $design_data['designid']['assetid'];
816  $new_override_designid = $design_data['override']['assetid'];
817 
818  if ($design_name == 'design::user::') {
819  if (empty($design_data['name'])) continue;
820  $old_designid = 0;
821  $design_name .= strtolower($design_data['name']);
822 
823  if ($GLOBALS['SQ_SYSTEM']->am->getLink($owner->id, SQ_LINK_NOTICE, 'design', FALSE, $design_name)) {
824  trigger_localised_error('SYS0134', E_USER_WARNING, $design_data['name']);
825  continue;
826  }// end if
827 
828  } else {
829  $old_design_link = $GLOBALS['SQ_SYSTEM']->am->getLink($owner->id, SQ_LINK_NOTICE, 'design', FALSE, $design_name);
830  $old_designid = (empty($old_design_link)) ? 0 : $old_design_link['minorid'];
831 
832  $old_override_design_link = $GLOBALS['SQ_SYSTEM']->am->getLink($owner->id, SQ_LINK_NOTICE, 'design', FALSE, 'override::'.$design_name);
833  $old_override_designid = (empty($old_override_design_link)) ? 0 : $old_override_design_link['minorid'];
834 
835  }// end if
836 
837  // if they are the same then there is nothing to do.
838  if ($new_designid != $old_designid) {
839  // if there is an existing entry delete it
840  if ($old_designid) {
841  if (!$owner->deleteLink($old_design_link['linkid'])) {
842  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
843  $designs_ok = FALSE;
844  break;
845  }
846  }
847 
848  if ($new_designid) {
849  $design = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_designid);
850  if (is_null($design) || !$design instanceof Design) {
851  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
852  $designs_ok = FALSE;
853  break;
854  }
855  if (!$owner->createLink($design, SQ_LINK_NOTICE, $design_name)) {
856  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
857  $designs_ok = FALSE;
858  break;
859  }
860  }
861  $update_design_cascade = TRUE;
862  }
863 
864  // same with the overrides
865  if ($new_override_designid != $old_override_designid) {
866  // if there is an existing entry delete it
867  if ($old_override_designid) {
868  if (!$owner->deleteLink($old_override_design_link['linkid'])) {
869  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
870  $designs_ok = FALSE;
871  break;
872  }
873  }
874 
875  if ($new_override_designid) {
876  $design = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_override_designid);
877  if (is_null($design)) {
878  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
879  $designs_ok = FALSE;
880  break;
881  }
882  if (!$owner->createLink($design, SQ_LINK_NOTICE, 'override::'.$design_name)) {
883  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
884  $designs_ok = FALSE;
885  break;
886  }
887  }
888  }
889 
890  $designs_changed = TRUE;
891 
892  }//end foreach
893 
894  if ($designs_ok) {
895  if ($designs_changed) {
896  if ($update_design_cascade == TRUE) {
897  $assets_affected_lookups[] = $owner->id;
898  }//end if
899  }//end if
900  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
901  }//end if
902 
903  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
904 
905  }//end if
906 
907  if (!$owner->updateLookups()) return FALSE;
908  return TRUE;
909 
910 }//end processSettings()
911 
912 
913 ?>