Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
search_page_edit_fns.inc
1 <?php
17 require_once SQ_PACKAGES_PATH.'/cms/listing_engine/listing_engine_edit_fns.inc';
18 
30 {
31 
32 
37  function __construct()
38  {
39  parent::__construct();
40  $this->static_screens['details']['lock_type'] = 'content';
41  $this->static_screens['details']['force_unlock'] = FALSE;
42 
43  }//end constructor
44 
45 
59  function paintRootAsset(&$asset, &$o, $prefix, $category='', $read_only=FALSE)
60  {
61  $link_value = 'root';
62  if (!empty($category)) $link_value .= '_'.$category;
63  $root_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'asset', FALSE, $link_value);
64 
65  if ($read_only) {
66  $write_access = FALSE;
67  } else {
68  $write_access = $asset->writeAccess('links');
69  }
70 
71  if (!$write_access) {
72  $root_asset = NULL;
73  if (!empty($root_link)) {
74  $root_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($root_link['minorid']);
75  }
76  if (!is_null($root_asset)) {
77  echo $root_asset->name.' (Id: #'.$root_asset->id.')';
78  } else {
79  echo translate('sch_no_root_node_selected');
80  }
81  } else {
82  asset_finder($prefix.'_rootid', (!empty($root_link)) ? $root_link['minorid'] : '');
83  }
84 
85  return $write_access;
86 
87  }//end paintRootAsset()
88 
89 
100  function processRootAsset(&$asset, &$o, $prefix)
101  {
102  if (!isset($_POST[$prefix.'_rootid']['assetid'])) {
103  return FALSE;
104  }
105  $new_root = $_POST[$prefix.'_rootid']['assetid'];
106 
107  // getting existing root link
108  $link_value = 'root';
109  $root_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', FALSE, $link_value);
110 
111  // dont process anything if the root node has not changed
112  if (!empty($root_link) && $root_link['minorid'] == $new_root) {
113  return FALSE;
114  }
115 
116  $ok = TRUE;
117 
118  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
119  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
120 
121  // deleting old root link if any found...
122  if (!empty($root_link) && !$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($root_link['linkid'])) {
123  $ok = FALSE;
124  } else if ($new_root) {
125  $root = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_root);
126  if (!is_null($root)) {
127  if (!$asset->createLink($root, SQ_LINK_NOTICE, $link_value)) {
128  $ok = FALSE;
129  trigger_localised_error('SCH0012', E_USER_WARNING, $root->name, $root->id);
130  }
131  }
132  }
133 
134  if ($ok) {
135  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
136  } else {
137  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
138  }
139 
140  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
141  return $ok;
142 
143  }//end processRootAsset()
144 
145 
156  function paintFields(&$asset, &$o, $prefix)
157  {
158  $write_access = $asset->writeAccess('all');
159  $fields = $asset->attr('fields');
160 
161  $query_types = Array(
162  'none' => '-- '.ucfirst(translate('sch_page_add_data_source').' --'),
163  'include_all' => ucfirst(translate('include_all')),
164  'standard' => ucfirst(translate('sch_page_datatype_standard')),
165  'asset_attrib' => ucfirst(translate('sch_page_datatype_attribute')),
166  'metadata' => ucfirst(translate('sch_page_datatype_metadata')),
167  );
168 
169  ?>
170  <table class ="sq-backend-table" border="1" style="margin-bottom: 7px">
171  <tr>
172  <th rowspan="2"><?php echo translate('name'); ?></th>
173  <th colspan="<?php echo $write_access ? 3 : 2; ?>"><?php echo translate('sch_page_data_sources'); ?></th>
174  <th rowspan="2"><?php echo translate('sch_page_word_logic'); ?></th>
175  <?php
176  if ($write_access) {
177  ?>
178  <th rowspan="2"><?php echo translate('delete'); ?></th>
179  <?php
180  }
181  ?>
182  </tr>
183  <tr>
184  <th><?php echo translate('type');?></th>
185  <th <?php if (!$write_access) echo 'colspan=2';?>><?php echo translate('details');?> </th>
186  <?php
187  if ($write_access) {
188  ?>
189  <th><?php echo translate('delete'); ?></th>
190  <?php
191  }
192  ?>
193  </tr>
194  <?php
195 
196  foreach ($fields as $field_name => $field_data) {
197  if ($field_data['exclude_field']) continue;
198 
199  $field_datasources = $field_data['data_sources'];
200  if ((!empty($field_datasources)) && ($field_datasources[0]['type'] == 'exclude')) {
201  continue;
202  }
203  if ($write_access) $field_datasources[] = 'new';
204  foreach ($field_datasources as $index => $field_datasource) {
205  ?>
206  <tr>
207  <?php
208  if ($index == 0) {
209  ?>
210  <td rowspan="<?php echo count($field_datasources);?>"> <?php echo $field_data['name'] ?></td>
211  <?php
212  }
213  ?>
214  <td class="sq-backend-data" style="padding: 4px;">
215  <?php
216  if ($field_datasource == 'new') {
217  if ($write_access) {
218  combo_box($prefix.'_fields['.$field_name.'][new_data_source_type]', $query_types, FALSE,'none');
219  }
220  } else {
221  $type = array_get_index($field_datasource, 'type');
222  echo $query_types[$type];
223  }
224  ?>
225  </td>
226  <td>
227  <?php
228  if ($field_datasource != 'new') {
229  switch ($type) {
230 
231  case 'asset_attrib':
232  if (!isset($field_datasource['params'])) {
233  $field_datasources[$index]['params'] = Array();
234  }
235  $search_types = $asset->attr('types');
236  $search_type = array_get_index($field_datasources[$index]['params'], 'asset_type', '0');
237  $type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo(array_keys($search_types), 'name');
238  if ($write_access) {
239  $options = Array('' => '-- '.translate('select_asset_type').' --');
240  foreach (array_keys($search_types) as $this_type) {
241  $options[$this_type] = $type_names[$this_type];
242  }
243  combo_box($prefix.'_fields['.$field_name.'][data_sources]['.$index.'][params][asset_type]', $options, FALSE, $search_type);
244  } else {
245  echo '<strong>'.translate('asset_type').':</strong> ';
246 
247  // check to see if any of the assets have been selected
248  // else dont bother about printing its details
249  if ($search_type !== '0') {
250  echo sq_print_icon($GLOBALS['SQ_SYSTEM']->am->getAssetIconURL($search_type), 16, 16, $type_names[$search_type], $type_names[$search_type], ' align="absmiddle"');
251  echo $type_names[$search_type];
252  } else {
253  echo translate('no_asset_selected');
254  }
255  }
256  // printing out attribute selection combo box
257  if (!isset($field_datasource['params']['attrid']) || empty($search_type)) {
258  $selected_attr = '';
259  } else {
260  $selected_attr = $field_datasource['params']['attrid'];
261  }
262  if (!empty($search_type)) {
263  $asset_type_attrs = $GLOBALS['SQ_SYSTEM']->am->getAssetTypeAttributes($search_type, Array('attrid', 'name'));
264  if ($write_access) {
265  $type_attrs = Array('' => '-- '.translate('select_attribute').' --');
266  foreach ($asset_type_attrs as $attr_id => $attr_name) {
267  $type_attrs[$attr_id] = $attr_name['name'];
268  }
269  combo_box($prefix.'_fields['.$field_name.'][data_sources]['.$index.'][params][attrid]', $type_attrs, FALSE, $selected_attr);
270  } else if ($selected_attr != '') {
271  echo '<br /><strong>'.translate('attribute').':</strong> '.$asset_type_attrs[$selected_attr]['name'];
272  }
273  }
274 
275  if (!empty($selected_attr)) {
276 
277  $attr_info = $GLOBALS['SQ_SYSTEM']->am->getAttributeInfo(Array($selected_attr));
278  $attr_info = $attr_info[$selected_attr];
279 
280  if (($attr_info['type'] == 'int') || ($attr_info['type'] == 'float')) {
281  $current_search = array_get_index($field_datasource['params'], 'numeric_search', 'exact');
282  ?><br/><?php
283  if ($write_access) {
284  radio_button($prefix.'_fields['.$field_name.'][data_sources]['.$index.'][params][numeric_search]', 'exact', ($current_search == 'exact'));
285  echo translate('sch_page_numeric_search_exact');
286  ?><br/><?php
287 
288  radio_button($prefix.'_fields['.$field_name.'][data_sources]['.$index.'][params][numeric_search]', 'range', ($current_search == 'range'));
289  echo translate('sch_page_numeric_search_range');
290  ?><br/><?php
291 
292  radio_button($prefix.'_fields['.$field_name.'][data_sources]['.$index.'][params][numeric_search]', 'custom', ($current_search == 'custom'));
293  echo translate('sch_page_numeric_search_custom');
294  ?><br/><?php
295  } else {
296  ?><strong><?php echo translate('sch_page_numeric_search_style'); ?></strong> <?php
297  echo translate('sch_page_numeric_search_'.$current_search);
298  }
299 
300  if ($current_search == 'custom') {
301  $custom_ranges = array_get_index($field_datasource['params'], 'custom_num_search', Array());
302  $custom_ranges[] = Array();
303  ?><table class="sq-backend-table" style="width:90%">
304  <thead>
305  <tr>
306  <th class="sq-backend-table-header">Range Name</th>
307  <th class="sq-backend-table-header">Minimum</th>
308  <th class="sq-backend-table-header">Maximum</th>
309  </tr>
310  </thead>
311  <tbody>
312  <?php
313  foreach ($custom_ranges as $key => $custom_range) {
314  if ($key != max(array_keys($custom_ranges)) && (empty($custom_range) || (empty($custom_range['name']) && empty($custom_range['min']) && empty($custom_range['max'])))) {
315  continue;
316  }
317 
318  ?><tr><td class="sq-backend-table-cell"><?php
319  if ($write_access) {
320  echo text_box($prefix.'_fields['.$field_name.'][data_sources]['.$index.'][params][custom_num_search]['.$key.'][name]', array_get_index($custom_range, 'name', ''), 20);
321  } else {
322  echo array_get_index($custom_range, 'name', '');
323  }
324  ?></td><td class="sq-backend-table-cell"><?php
325  if ($write_access) {
326  echo text_box($prefix.'_fields['.$field_name.'][data_sources]['.$index.'][params][custom_num_search]['.$key.'][min]', array_get_index($custom_range, 'min', ''), 7);
327  } else {
328  echo array_get_index($custom_range, 'min', '');
329  }
330  ?></td><td class="sq-backend-table-cell"><?php
331  if ($write_access) {
332  echo text_box($prefix.'_fields['.$field_name.'][data_sources]['.$index.'][params][custom_num_search]['.$key.'][max]', array_get_index($custom_range, 'max', ''), 7);
333  } else {
334  echo array_get_index($custom_range, 'max', '');
335  }
336  ?></td></tr><?php
337  }
338  ?></tbody></table><?php
339  }//end if
340 
341  }//end if
342  }//end if
343  ?>
344  <?php
345  break;
346 
347  case 'metadata':
348  if (!isset($field_datasource['params'])) {
349  $field_datasource['params'] = Array();
350  }
351  $metadata_field = array_get_index($field_datasource['params'], 'assetid', '0');
352  if ($write_access) {
353  asset_finder($prefix.'_fields['.$field_name.'][data_sources]['.$index.'][params][metadata_field]', $metadata_field, Array('metadata_field' => 'D'));
354  } else {
355  if ($metadata_field > 0) {
356  $field_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($metadata_field);
357  if (!is_null($metadata_field)) {
358  echo get_asset_tag_line($field_asset->id);
359  } else {
360  echo translate('sch_page_no_metadata_field_specified');
361  }
362  } else {
363  echo translate('sch_page_no_metadata_field_specified');
364  }
365  }
366  break;
367 
368  case 'standard':
369  if (!isset($field_datasource['params'])) {
370  $field_datasources[$index]['params'] = Array();
371  }
372  if (isset($field_datasource['params']['field'])) {
373  $selected_attr_name = $field_datasource['params']['field'];
374  } else {
375  $selected_attr_name = '';
376  }
377  if ($write_access) {
378  $type_attrs = Array('' => '-- '.translate('select_attribute').' --');
379  $sm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('search_manager');
380  $attributes = $sm->standard_date_fields + $sm->standard_text_fields;
381  combo_box($prefix.'_fields['.$field_name.'][data_sources]['.$index.'][params][field]', $attributes, FALSE, $selected_attr_name);
382  } else if ($selected_attr_name != '') {
383  echo translate('sch_page_field').': '.$selected_attr_name;
384  }
385  break;
386 
387  case 'include_all':
388  echo '&nbsp;';
389  hidden_field($prefix.'_fields['.$field_name.'][data_sources]['.$index.'][params]', '');
390  break;
391 
392  }//end switch
393  }//end if
394  ?>
395  </td>
396  <?php
397  if ($write_access) {
398  // Delete Data Source Cell
399  ?>
400  <td class="sq-backend-data">
401  <?php
402  if ($field_datasource != 'new') {
403  check_box($prefix.'_fields['.$field_name.'][data_sources]['.$index.'][delete]');
404  }
405  ?>
406  </td>
407  <?php
408  }
409  if ($index == 0) {
410  // Word Logic Cell
411  ?>
412  <td rowspan="<?php echo count($field_datasources);?>">
413  <?php
414  $word_logic_options = Array('AND' => translate('sch_page_all_words'), 'OR' => translate('sch_page_any_word'));
415  if ($write_access) {
416  combo_box($prefix.'_fields['.$field_name.'][word_logic]', $word_logic_options, FALSE, array_get_index($field_data, 'word_logic', 'AND'), 0, 'title="'.translate('sch_page_word_logic_exp').'"');
417  } else {
418  echo array_get_index($field_data, 'word_logic', 'AND');
419  }
420  ?>
421  </td>
422  <?php
423  }
424 
425  if (($index == 0) && $write_access) {
426  // Delete field overall cell
427  ?>
428  <td rowspan="<?php echo count($field_datasources);?>">
429  <?php
430  check_box($prefix.'_fields['.$field_name.'][delete]');
431  ?>
432  </td>
433  <?php
434  }
435  ?>
436  <?php
437  }//end foreach
438  }//end foreach
439  ?>
440  </tr>
441 
442  </table>
443  <?php
444  if ($write_access) {
445  label(translate('sch_page_new_search_field'), $prefix.'_new_field_name');
446  echo '&nbsp;';
447  text_box($prefix.'_new_field_name', '', 15);
448  }
449  return TRUE;
450 
451  }//end paintFields()
452 
453 
464  function processFields(&$asset, &$o, $prefix)
465  {
466  $old_fields = $asset->attr('fields');
467 
468  $new_fields = Array();
469 
470  if (isset($_POST[$prefix.'_fields'])) {
471  foreach ($_POST[$prefix.'_fields'] as $field_name => $field) {
472  if (!isset($field['delete'])) {
473  $new_fields[$field_name]['name'] = $old_fields[$field_name]['name'];
474  $new_fields[$field_name]['word_logic'] = $field['word_logic'];
475  $field_datasources = array_get_index($field, 'data_sources', Array());
476  $new_fields[$field_name]['data_sources'] = Array();
477  $new_fields[$field_name]['exclude_field'] = FALSE;
478  foreach ($field_datasources as $i => $field_datasource) {
479  if (!isset($field_datasource['delete'])) {
480  $new_datasource = Array();
481  $new_datasource['type'] = $old_fields[$field_name]['data_sources'][$i]['type'];
482  if ($new_datasource['type'] != 'metadata') {
483  $new_datasource['params'] = $field_datasource['params'];
484  } else {
485  $new_datasource['params']['assetid'] = $field_datasource['params']['metadata_field']['assetid'];
486  }
487  $new_fields[$field_name]['data_sources'][] = $new_datasource;
488  }
489  }
490  if (!empty($field['new_data_source_type']) && $field['new_data_source_type'] != 'none') {
491  $new_datasource = Array();
492  $new_datasource['type'] = $field['new_data_source_type'];
493  $new_datasource['params'] = Array();
494  $new_fields[$field_name]['data_sources'][] = $new_datasource;
495  }
496  }
497  }
498  }
499 
500  if (!empty($_POST[$prefix.'_new_field_name'])) {
501  $safe_name = strtolower(str_replace(' ', '_', $_POST[$prefix.'_new_field_name']));
502 
503  // If field already, don't overwrite it
504  if (!isset($old_fields[$safe_name])) {
505  $new_fields[$safe_name]['name'] = $_POST[$prefix.'_new_field_name'];
506  $new_fields[$safe_name]['data_sources'] = Array();
507  $new_fields[$safe_name]['exclude_field'] = FALSE;
508  }
509  }
510 
511  foreach ($old_fields as $field_name => $field) {
512  if ($field['exclude_field']) {
513  $new_fields[$field_name] = $field;
514  }
515  }//end foreach
516 
517  return $asset->setAttrValue('fields', $new_fields);
518 
519  }//end processFields()
520 
521 
532  function paintExcludeFields(&$asset, &$o, $prefix) {
533 
534  $write_access = $asset->writeAccess('all');
535  $fields = $asset->attr('fields');
536  $query_types = Array(
537  'none' => '-- '.ucfirst(translate('sch_page_add_data_source').' --'),
538  'include_all' => ucfirst(translate('include_all')),
539  'standard' => ucfirst(translate('sch_page_datatype_standard')),
540  'asset_attrib' => ucfirst(translate('sch_page_datatype_attribute')),
541  'metadata' => ucfirst(translate('sch_page_datatype_metadata')),
542  );
543 
544  ?>
545  <table class ="sq-backend-table" border="1" style="margin-bottom: 7px">
546  <tr>
547  <th rowspan="2"><?php echo translate('name'); ?></th>
548  <th colspan="<?php echo $write_access ? 3 : 2; ?>"><?php echo translate('sch_page_data_sources'); ?></th>
549  <th rowspan="2"><?php echo translate('sch_page_word_logic'); ?></th>
550  <?php
551  if ($write_access) {
552  ?>
553  <th rowspan="2"><?php echo translate('delete'); ?></th>
554  <?php
555  }
556  ?>
557  </tr>
558  <tr>
559  <th><?php echo translate('type');?></th>
560  <th <?php if (!$write_access) echo 'colspan=2';?>><?php echo translate('details');?> </th>
561  <?php
562  if ($write_access) {
563  ?>
564  <th><?php echo translate('delete'); ?></th>
565  <?php
566  }
567  ?>
568  </tr>
569  <?php
570  foreach ($fields as $field_name => $field_data) {
571  if (!$field_data['exclude_field']) continue;
572  $field_datasources = $field_data['data_sources'];
573  if ((!empty($field_datasources)) && ($field_datasources[0]['type'] == 'exclude')) {
574  continue;
575  }
576  if ($write_access) $field_datasources[] = 'new';
577  foreach ($field_datasources as $index => $field_datasource) {
578  ?>
579  <tr>
580  <?php
581  if ($index == 0) {
582  ?>
583  <td rowspan="<?php echo count($field_datasources);?>"> <?php echo $field_data['name'] ?></td>
584  <?php
585  }
586  ?>
587  <td class="sq-backend-data" style="padding: 4px;">
588  <?php
589  if ($field_datasource == 'new') {
590  if ($write_access) {
591  combo_box($prefix.'_exclude_fields['.$field_name.'][new_data_source_type]', $query_types, FALSE,'none');
592  }
593  } else {
594  $type = array_get_index($field_datasource, 'type');
595  echo $query_types[$type];
596  }
597  ?>
598  </td>
599  <td>
600  <?php
601  if ($field_datasource != 'new') {
602  switch ($type) {
603 
604  case 'asset_attrib':
605  if (!isset($field_datasource['params'])) {
606  $field_datasources[$index]['params'] = Array();
607  }
608  $search_types = $asset->attr('types');
609  $search_type = array_get_index($field_datasources[$index]['params'], 'asset_type', '0');
610  $type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo(array_keys($search_types), 'name');
611  if ($write_access) {
612  $options = Array('' => '-- '.translate('select_asset_type').' --');
613  foreach (array_keys($search_types) as $this_type) {
614  $options[$this_type] = $type_names[$this_type];
615  }
616  combo_box($prefix.'_exclude_fields['.$field_name.'][data_sources]['.$index.'][params][asset_type]', $options, FALSE, $search_type);
617  } else {
618  echo '<strong>'.translate('asset_type').':</strong> ';
619  echo sq_print_icon($GLOBALS['SQ_SYSTEM']->am->getAssetIconURL($search_type), 16, 16, $type_names[$search_type], $type_names[$search_type], ' align="absmiddle"');
620  echo $type_names[$search_type];
621  }
622  // printing out attribute selection combo box
623  if (!isset($field_datasource['params']['attrid']) || empty($search_type)) {
624  $selected_attr = '';
625  } else {
626  $selected_attr = $field_datasource['params']['attrid'];
627  }
628  if (!empty($search_type)) {
629  $asset_type_attrs = $GLOBALS['SQ_SYSTEM']->am->getAssetTypeAttributes($search_type, Array('attrid', 'name'));
630  if ($write_access) {
631  $type_attrs = Array('' => '-- '.translate('select_attribute').' --');
632  foreach ($asset_type_attrs as $attr_id => $attr_name) {
633  $type_attrs[$attr_id] = $attr_name['name'];
634  }
635  combo_box($prefix.'_exclude_fields['.$field_name.'][data_sources]['.$index.'][params][attrid]', $type_attrs, FALSE, $selected_attr);
636  } else if ($selected_attr != '') {
637  echo '<br /><strong>'.translate('attribute').':</strong> '.$asset_type_attrs[$selected_attr]['name'];
638  }
639  }
640 
641  if (!empty($selected_attr)) {
642 
643  $attr_info = $GLOBALS['SQ_SYSTEM']->am->getAttributeInfo(Array($selected_attr));
644  $attr_info = $attr_info[$selected_attr];
645 
646  if (($attr_info['type'] == 'int') || ($attr_info['type'] == 'float')) {
647  $current_search = array_get_index($field_datasource['params'], 'numeric_search', 'exact');
648  ?><br/><?php
649  if ($write_access) {
650  radio_button($prefix.'_exclude_fields['.$field_name.'][data_sources]['.$index.'][params][numeric_search]', 'exact', ($current_search == 'exact'));
651  echo translate('sch_page_numeric_search_exact');
652  ?><br/><?php
653 
654  radio_button($prefix.'_exclude_fields['.$field_name.'][data_sources]['.$index.'][params][numeric_search]', 'range', ($current_search == 'range'));
655  echo translate('sch_page_numeric_search_range');
656  ?><br/><?php
657 
658  radio_button($prefix.'_exclude_fields['.$field_name.'][data_sources]['.$index.'][params][numeric_search]', 'custom', ($current_search == 'custom'));
659  echo translate('sch_page_numeric_search_custom');
660  ?><br/><?php
661  } else {
662  ?><strong><?php echo translate('sch_page_numeric_search_style'); ?></strong> <?php
663  echo translate('sch_page_numeric_search_'.$current_search);
664  }
665 
666  if ($current_search == 'custom') {
667  $custom_ranges = array_get_index($field_datasource['params'], 'custom_num_search', Array());
668  $custom_ranges[] = Array();
669  ?><table class="sq-backend-table" style="width:90%">
670  <thead>
671  <tr>
672  <th class="sq-backend-table-header">Range Name</th>
673  <th class="sq-backend-table-header">Minimum</th>
674  <th class="sq-backend-table-header">Maximum</th>
675  </tr>
676  </thead>
677  <tbody>
678  <?php
679  foreach ($custom_ranges as $key => $custom_range) {
680  if ($key != max(array_keys($custom_ranges)) && (empty($custom_range) || (empty($custom_range['name']) && empty($custom_range['min']) && empty($custom_range['max'])))) {
681  continue;
682  }
683 
684  ?><tr><td class="sq-backend-table-cell"><?php
685  if ($write_access) {
686  echo text_box($prefix.'_exclude_fields['.$field_name.'][data_sources]['.$index.'][params][custom_num_search]['.$key.'][name]', array_get_index($custom_range, 'name', ''), 20);
687  } else {
688  echo array_get_index($custom_range, 'name', '');
689  }
690  ?></td><td class="sq-backend-table-cell"><?php
691  if ($write_access) {
692  echo text_box($prefix.'_exclude_fields['.$field_name.'][data_sources]['.$index.'][params][custom_num_search]['.$key.'][min]', array_get_index($custom_range, 'min', ''), 7);
693  } else {
694  echo array_get_index($custom_range, 'min', '');
695  }
696  ?></td><td class="sq-backend-table-cell"><?php
697  if ($write_access) {
698  echo text_box($prefix.'_exclude_fields['.$field_name.'][data_sources]['.$index.'][params][custom_num_search]['.$key.'][max]', array_get_index($custom_range, 'max', ''), 7);
699  } else {
700  echo array_get_index($custom_range, 'max', '');
701  }
702  ?></td></tr><?php
703  }
704  ?></tbody></table><?php
705  }//end if
706 
707  }//end if
708  }//end if
709  ?>
710  <?php
711  break;
712 
713  case 'metadata':
714  if (!isset($field_datasource['params'])) {
715  $field_datasource['params'] = Array();
716  }
717  $metadata_field = array_get_index($field_datasource['params'], 'assetid', '0');
718  if ($write_access) {
719  asset_finder($prefix.'_exclude_fields['.$field_name.'][data_sources]['.$index.'][params][metadata_field]', $metadata_field, Array('metadata_field' => 'D'));
720  } else {
721  if ($metadata_field > 0) {
722  $field_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($metadata_field);
723  if (!is_null($metadata_field)) {
724  echo get_asset_tag_line($field_asset->id);
725  } else {
726  echo translate('sch_page_no_metadata_field_specified');
727  }
728  } else {
729  echo translate('sch_page_no_metadata_field_specified');
730  }
731  }
732  break;
733 
734  case 'standard':
735  if (!isset($field_datasource['params'])) {
736  $field_datasources[$index]['params'] = Array();
737  }
738  if (isset($field_datasource['params']['field'])) {
739  $selected_attr_name = $field_datasource['params']['field'];
740  } else {
741  $selected_attr_name = '';
742  }
743  if ($write_access) {
744  $type_attrs = Array('' => '-- '.translate('select_attribute').' --');
745  $sm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('search_manager');
746  $attributes = $sm->standard_date_fields + $sm->standard_text_fields;
747  combo_box($prefix.'_exclude_fields['.$field_name.'][data_sources]['.$index.'][params][field]', $attributes, FALSE, $selected_attr_name);
748  } else if ($selected_attr_name != '') {
749  echo translate('sch_page_field').': '.$selected_attr_name;
750  }
751  break;
752 
753  case 'include_all':
754  echo '&nbsp;';
755  hidden_field($prefix.'_exclude_fields['.$field_name.'][data_sources]['.$index.'][params]', '');
756  break;
757 
758  }//end switch
759  }//end if
760  ?>
761  </td>
762  <?php
763  if ($write_access) {
764  // Delete Data Source Cell
765  ?>
766  <td class="sq-backend-data">
767  <?php
768  if ($field_datasource != 'new') {
769  check_box($prefix.'_exclude_fields['.$field_name.'][data_sources]['.$index.'][delete]');
770  }
771  ?>
772  </td>
773  <?php
774  }
775  if ($index == 0) {
776  // Word Logic Cell
777  ?>
778  <td rowspan="<?php echo count($field_datasources);?>">
779  <?php
780  $word_logic_options = Array('AND' => translate('sch_page_all_words'), 'OR' => translate('sch_page_any_word'));
781  if ($write_access) {
782  combo_box($prefix.'_exclude_fields['.$field_name.'][word_logic]', $word_logic_options, FALSE, array_get_index($field_data, 'word_logic', 'AND'), 0, 'title="'.translate('sch_page_word_logic_exp').'"');
783  } else {
784  echo array_get_index($field_data, 'word_logic', 'AND');
785  }
786  ?>
787  </td>
788  <?php
789  }
790 
791  if (($index == 0) && $write_access) {
792  // Delete field overall cell
793  ?>
794  <td rowspan="<?php echo count($field_datasources);?>">
795  <?php
796  check_box($prefix.'_exclude_fields['.$field_name.'][delete]');
797  ?>
798  </td>
799  <?php
800  }
801  ?>
802  <?php
803  }//end foreach
804  }//end foreach
805  ?>
806  </tr>
807 
808  </table>
809  <?php
810  if ($write_access) {
811  label(translate('sch_page_new_exclude_field'), $prefix.'_new_exclude_field_name');
812  echo '&nbsp;';
813  text_box($prefix.'_new_exclude_field_name', '', 15);
814  }
815 
816  return TRUE;
817 
818  }//end paintExcludeFields()
819 
820 
831  function processExcludeFields(&$asset, &$o, $prefix)
832  {
833  //return true;
834  $old_fields = $asset->attr('fields');
835 
836  $new_fields = Array();
837  if (isset($_POST[$prefix.'_exclude_fields'])) {
838  foreach ($_POST[$prefix.'_exclude_fields'] as $field_name => $field) {
839  if (!isset($field['delete'])) {
840  $new_fields[$field_name]['name'] = $old_fields[$field_name]['name'];
841  $new_fields[$field_name]['word_logic'] = $field['word_logic'];
842  $field_datasources = array_get_index($field, 'data_sources', Array());
843  $new_fields[$field_name]['data_sources'] = Array();
844  $new_fields[$field_name]['exclude_field'] = TRUE;
845  foreach ($field_datasources as $i => $field_datasource) {
846  if (!isset($field_datasource['delete'])) {
847  $new_datasource = Array();
848  $new_datasource['type'] = $old_fields[$field_name]['data_sources'][$i]['type'];
849  if ($new_datasource['type'] != 'metadata') {
850  $new_datasource['params'] = $field_datasource['params'];
851  } else {
852  $new_datasource['params']['assetid'] = $field_datasource['params']['metadata_field']['assetid'];
853  }
854  $new_fields[$field_name]['data_sources'][] = $new_datasource;
855  }
856  }
857  if (!empty($field['new_data_source_type']) && $field['new_data_source_type'] != 'none') {
858  $new_datasource = Array();
859  $new_datasource['type'] = $field['new_data_source_type'];
860  $new_datasource['params'] = Array();
861  $new_fields[$field_name]['data_sources'][] = $new_datasource;
862  }
863  }
864  }
865  }
866 
867 
868 
869  if (!empty($_POST[$prefix.'_new_exclude_field_name'])) {
870  $safe_name = strtolower(str_replace(' ', '_', $_POST[$prefix.'_new_exclude_field_name']));
871  // If field already, don't overwrite it
872  if (!isset($old_fields[$safe_name])) {
873  $new_fields[$safe_name]['name'] = $_POST[$prefix.'_new_exclude_field_name'];
874  $new_fields[$safe_name]['data_sources'] = Array();
875  $new_fields[$safe_name]['exclude_field'] = TRUE;
876  }
877  }
878 
879  foreach ($old_fields as $field_name => $field) {
880  if (!$field['exclude_field']) {
881  $new_fields[$field_name] = $field;
882  }
883  }//end foreach
884 
885  return $asset->setAttrValue('fields', $new_fields);
886 
887  }//end processExcludeFields()
888 
889 
900  function paintStyles(&$asset, &$o, $prefix)
901  {
902 
903  $write_access = $asset->writeAccess('attributes');
904  $search_styles = $asset->attr('search_styles');
905  $fields = $asset->attr('fields');
906  foreach ($fields as $field) {
907  $field_datasources = $field['data_sources'];
908  $type = NULL;
909  foreach ($field_datasources as $field_datasource) {
910  if (isset($field_datasource['type'])) {
911  $type = $field_datasource['type'];
912  }
913  if ($type == 'asset_attrib') {
914 
915  if (!isset($field_datasource['params']['attrid'])) {
916  continue;
917  }
918  $attribute = $GLOBALS['SQ_SYSTEM']->am->getAttribute($field_datasource['params']['attrid']);
919  if (is_null($attribute)) continue;
920 
921  // if this is a boolean or selection field, we want to make sure blank options are allowed
922  if ($attribute->type() == 'boolean' || $attribute->type() == 'selection') {
923  $attribute->_params['allow_empty'] = TRUE;
924  }
925 
926  if (!empty($search_styles) && isset($search_styles[$attribute->id])) {
927  $attribute->_edit_params = $search_styles[$attribute->id];
928  }
929 
930  echo '<p>';
931  $attribute->paintEditParams($prefix.'_'.$attribute->id, $write_access);
932  echo '</p>';
933 
934  }//end if asset attribute
935  }
936  }//end foreach fields
937 
938  return $write_access;
939 
940  }//end paintStyles()
941 
942 
953  function processStyles(&$asset, &$o, $prefix)
954  {
955  // need to have write access to make any changes
956  if (!$asset->writeAccess('attributes')) return FALSE;
957 
958  $search_styles = Array();
959 
960  $fields = $asset->attr('fields');
961 
962  foreach ($fields as $fieldname => $field) {
963  $field_datasources = $field['data_sources'];
964  $type = NULL;
965  foreach ($field_datasources as $field_datasource) {
966  if (isset($field_datasource['type'])) {
967  $type = $field_datasource['type'];
968  }
969  if ($type == 'asset_attrib') {
970 
971  if (empty($field_datasource['params']['attrid'])) {
972  continue;
973  }
974  $attribute = $GLOBALS['SQ_SYSTEM']->am->getAttribute($field_datasource['params']['attrid']);
975  $search_styles[$attribute->id] = $attribute->processEditParams($prefix.'_'.$attribute->id);
976  }
977  }
978  }
979 
980  $asset->setAttrValue('search_styles', $search_styles);
981 
982  return TRUE;
983 
984  }//end processStyles()
985 
986 
987 //-- CATEGORIES --//
988 
989 
1000  function paintCategories(&$asset, &$o, $prefix)
1001  {
1002  ?>
1003  <style type="text/css">
1004  table.category-set {
1005  margin-bottom: 10px;
1006  }
1007  table.category-set th.title {
1008  font-size: 90%;
1009  }
1010  table.category-set th.delete {
1011  vertical-align: middle;
1012  width: 15ex;
1013  }
1014  table.category-set th.delete input {
1015  margin: 0px 4px;
1016  }
1017  table.category-set table.sq-backend-table {
1018  margin-left: 15px;
1019  margin-top: 2px;
1020  }
1021  table.category-set table.sq-backend-table th {
1022  font-weight: normal;
1023  }
1024  table.category-set table.sq-backend-table td {
1025  white-space: nowrap;
1026  }
1027  </style>
1028  <script type="text/javascript"><!--
1029  //<![CDATA[
1030  function handleDefaultStatusClick(elt)
1031  {
1032  var td = elt.parentNode;
1033  while (td.tagName != 'TD') {
1034  td = td.parentNode;
1035  }
1036  var selects = td.getElementsByTagName('SELECT');
1037  with (selects[0].style) {
1038  display = (display == 'none') ? '' : 'none';
1039  }
1040  }
1041 
1042  function handleDefaultRootClick(elt)
1043  {
1044  var td = elt.parentNode;
1045  while (td.tagName != 'TD') {
1046  td = td.parentNode;
1047  }
1048  var divs = td.getElementsByTagName('DIV');
1049  with (divs[0].style) {
1050  display = (display == 'none') ? '' : 'none';
1051  }
1052  }
1053  //]]> -->
1054  </script>
1055  <?php
1056  $sets = $asset->attr('categories');
1057  $wa = $asset->writeAccess('attributes');
1058  foreach ($sets as $name => $set_data) {
1059  ?>
1060  <table class="sq-backend-table category-set">
1061  <tr>
1062  <th class="title"><?php echo $name; ?></th>
1063  <th class="delete">
1064  <?php
1065  if ($wa) {
1066  $msg = translate('search_page_confirm_cat_delete');
1067  check_box($prefix.'_category_sets_to_delete[]', $name, FALSE, "return confirm('$msg')", 'id="'.$prefix.'_category_sets_to_delete_'.$name.'"');
1068  label(translate('delete'), $prefix.'_category_sets_to_delete_'.$name);
1069  }
1070  ?>
1071  </th>
1072  </tr>
1073  <tr>
1074  <td colspan="2">
1075  <?php
1076  if ($wa) {
1077  label(translate('search_cat_unselected_text').': ', $prefix.'_category_'.$name.'_unselected_text');
1078  echo '&nbsp;';
1079  text_box($prefix.'_category_'.$name.'_unselected_text', $set_data['unselected_text']);
1080  } else {
1081  echo translate('search_cat_unselected_text');
1082  echo $set_data['unselected_text'];
1083  }
1084  ?>
1085  </td>
1086  </tr>
1087  <tr>
1088  <td colspan="2">
1089  <?php
1090  echo translate('options').':';
1091  $this->_paintCategoryOptions($asset, $prefix.'_category_'.$name.'_options', $name, $set_data['options'], $wa);
1092  ?>
1093  </td>
1094  </tr>
1095  </table>
1096  <?php
1097  }//end foreach
1098 
1099  }//end paintCategories()
1100 
1101 
1114  function _paintCategoryOptions(&$asset, $prefix, $set_name, $options, $wa)
1115  {
1116  ?>
1117  <table class="sq-backend-table">
1118  <tr>
1119  <th><?php echo translate('name'); ?></th>
1120  <th style="width: 35ex"><?php echo translate('statuses'); ?></th>
1121  <th style="width: 60ex"><?php echo translate('root_node'); ?></th>
1122  <?php
1123  if ($wa) {
1124  ?>
1125  <th style="width: 7ex"><?php echo translate('delete'); ?></th>
1126  <?php
1127  }
1128  ?>
1129  </tr>
1130  <?php
1131  foreach ($options as $code_name => $option) {
1132  ?>
1133  <tr>
1134  <td>
1135  <?php
1136  if ($wa) {
1137  text_box($prefix.'_'.$code_name.'_full_name', $option['full_name']);
1138  } else {
1139  echo $option['full_name'];
1140  }
1141  ?>
1142  </td>
1143  <td>
1144  <?php
1145  $customised = isset($option['statuses']);
1146  $current_stats = array_get_index($option, 'statuses', Array());
1147  if ($wa) {
1148  check_box($prefix.'_'.$code_name.'_statuses_default', '1', !$customised, 'handleDefaultStatusClick(this)');
1149  label('Use Default', $prefix.'_'.$code_name.'_statuses_default');
1150  } else {
1151  echo '<img src="'.sq_web_path('lib').'/web/images/'.($customised ? 'cross' : 'tick').'.gif" />';
1152  echo translate('use_default');
1153  }
1154  $this->_paintStatusChooser($prefix.'_'.$code_name.'_statuses', $current_stats, $wa, $customised);
1155  ?>
1156  </td>
1157  <td>
1158  <?php
1159  $customised = isset($option['root_assetid']);
1160  $current_root = 0;
1161  if ($customised) {
1162  $link_value = 'root_'.$set_name.'_'.$code_name;
1163  $root_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', FALSE, $link_value);
1164  $current_root = $root_link['minorid'];
1165  }
1166  if ($wa) {
1167  check_box($prefix.'_'.$code_name.'_root_default', '1', !$customised, 'handleDefaultRootClick(this)');
1168  label('Use Default', $prefix.'_'.$code_name.'_root_default');
1169  } else {
1170  echo '<img src="'.sq_web_path('lib').'/web/images/'.($customised ? 'cross' : 'tick').'.gif" />';
1171  echo translate('use_default');
1172  }
1173  $this->_paintAssetChooser($prefix.'_'.$code_name.'_root', $current_root, $wa, $customised);
1174  ?>
1175  </td>
1176  <?php
1177  if ($wa) {
1178  ?>
1179  <td>
1180  <?php
1181  check_box($prefix.'_to_delete[]', $code_name, FALSE);
1182  ?>
1183  </td>
1184  <?php
1185  }
1186  ?>
1187  </tr>
1188  <?php
1189  }//end foreach
1190  if ($wa) {
1191  ?>
1192  <tr>
1193  <td>
1194  <?php text_box($prefix.'__new__full_name', ''); ?>
1195  </td>
1196  <td>
1197  <?php
1198  check_box($prefix.'__new__statuses_default', '1', TRUE, 'handleDefaultStatusClick(this)');
1199  label('Use Default', $prefix.'__new__statuses_default');
1200  $this->_paintStatusChooser($prefix.'__new__statuses', Array(), TRUE, FALSE);
1201  ?>
1202  </td>
1203  <td>
1204  <?php
1205  check_box($prefix.'__new__root_default', '1', TRUE, 'handleDefaultRootClick(this)');
1206  label('Use Default', $prefix.'__new__root_default');
1207  $this->_paintAssetChooser($prefix.'__new__root', '', TRUE, FALSE);
1208  ?>
1209  </td>
1210  <td>&nbsp</td>
1211  </tr>
1212  <?php
1213  }
1214  ?>
1215  </table>
1216  <?php
1217 
1218  }//end _paintCategoryOptions()
1219 
1220 
1232  function _paintStatusChooser($name, $current_values, $editable=TRUE, $visible=TRUE)
1233  {
1234  if (!$editable && !$visible) {
1235  return;
1236  }
1237  $style = $visible ? '' : 'display: none';
1238  echo '<br />';
1239 
1240  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
1241  if ($editable) {
1242  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
1243  $statuses = get_constant_values('SQ_STATUS');
1244  $options = Array();
1245  foreach ($statuses as $constant => $value) {
1246  $options[$value] = get_status_description($value);
1247  }
1248  combo_box($name, $options, TRUE, $current_values, '', 'style="'.$style.'"');
1249  } else {
1250  if (empty($current_values)) {
1251  echo translate('sch_page_no_status_selected');
1252  } else {
1253  ?><ul style="margin: 1px 15px;"><?php
1254  foreach ($current_values as $status) {
1255  $status_name = get_status_description($status);
1256  $status_colour = get_status_colour($status);
1257  echo '<li>';
1258  echo '<img src="'.sq_web_path('lib').'/web/images/blank.gif" width="10" height="10" alt="'.$status_name.'" title="'.$status_name.'" align="absmiddle" style="margin: 2px; border: 1px solid #ccc; background-color: '.$status_colour.'" /> ';
1259  echo $status_name;
1260  echo '</li>';
1261  }
1262  ?></ul><?php
1263  }
1264  }
1265 
1266  }//end _paintStatusChooser()
1267 
1268 
1280  function _paintAssetChooser($name, $current_value, $editable=TRUE, $visible=TRUE)
1281  {
1282  if (!$editable && !$visible) {
1283  return;
1284  }
1285  echo '<div style="'.($visible ? '' : 'display: none').'">';
1286  if ($editable) {
1287  asset_finder($name, $current_value);
1288  } else {
1289  echo get_asset_tag_line($current_value);
1290  }
1291  echo '</div>';
1292 
1293  }//end _paintAssetChooser()
1294 
1295 
1306  function processCategories(&$asset, &$o, $prefix)
1307  {
1308  $cats = $asset->attr('categories');
1309 
1310  // Any categories to delete?
1311  if (!empty($_POST[$prefix.'_category_sets_to_delete'])) {
1312  foreach ($_POST[$prefix.'_category_sets_to_delete'] as $delete_name) {
1313  // delete notice links for removed category
1314  if (isset($cats[$delete_name]['options']) && !empty($cats[$delete_name]['options'])) {
1315  foreach ($cats[$delete_name]['options'] as $option_delete_name => $option_content) {
1316  $old_link_value = 'root_'.$delete_name.'_'.$option_delete_name;
1317  $root_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE, '', FALSE, 'major', $old_link_value);
1318 
1319  $ok = TRUE;
1320  foreach ($root_links as $root_link) {
1321  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($root_link['linkid'])) {
1322  $ok = FALSE;
1323  }
1324  }
1325 
1326  }
1327  // bug fix for #3884 Search page category - unable to delete
1328  // if the option attribute in empty that doesnt mean we cannot
1329  // delete the search category for it
1330  } else if (isset($cats[$delete_name]['options']) && empty($cats[$delete_name]['options'])){
1331  $ok = TRUE;
1332  }
1333  if($ok) unset($cats[$delete_name]);
1334  }
1335  }
1336 
1337  // Categories to edit?
1338  foreach ($cats as $name => $cat_data) {
1339  $cat_data['unselected_text'] = $_POST[$prefix.'_category_'.$name.'_unselected_text'];
1340  $cat_data['options'] = $this->_processCategoryOptions($asset, $prefix.'_category_'.$name.'_options', $name, $cat_data['options']);
1341  $cats[$name] = $cat_data;
1342  }
1343 
1344  return $asset->setAttrValue('categories', $cats);
1345 
1346  }//end processCategories()
1347 
1348 
1362  function _processCategoryOptions(&$asset, $prefix, $set_name, $old_options)
1363  {
1364  $new_options = Array();
1365  //delete unwanted category
1366  if (isset($_POST[$prefix.'_to_delete'])) {
1367  foreach ($_POST[$prefix.'_to_delete'] as $delete_name) {
1368  $old_link_value = 'root_'.$set_name.'_'.$delete_name;
1369  $root_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE, '', FALSE, 'major', $old_link_value);
1370  // delete notice links for removed category
1371  $ok = TRUE;
1372  foreach ($root_links as $root_link) {
1373  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($root_link['linkid'])) {
1374  $ok = FALSE;
1375  }
1376  }
1377  if($ok) unset($old_options[$delete_name]);
1378  }
1379  }
1380  foreach ($old_options as $code_name => $old_option) {
1381  $new_option = Array();
1382  $new_option['full_name'] = $_POST[$prefix.'_'.$code_name.'_full_name'];
1383  if (empty($new_option['full_name'])) {
1384  // can't change the name to blank, thankyou
1385  $new_option['full_name'] = $old_option['full_name'];
1386  }
1387 
1388  if (empty($_POST[$prefix.'_'.$code_name.'_statuses_default']) && !empty($_POST[$prefix.'_'.$code_name.'_statuses'])) {
1389  $new_option['statuses'] = $_POST[$prefix.'_'.$code_name.'_statuses'];
1390  }
1391 
1392  $new_code_name = preg_replace('/[^a-zA-Z0-9 ]/', '', $new_option['full_name']);
1393  $new_code_name = preg_replace('/( )+/', '_', $new_code_name);
1394  $new_code_name = strtolower($new_code_name);
1395 
1396  if (empty($_POST[$prefix.'_'.$code_name.'_root_default'])) {
1397  $new_option['root_assetid'] = '';
1398  $new_root = $_POST[$prefix.'_'.$code_name.'_root']['assetid'];
1399  // get the existing root link
1400  $old_link_value = 'root_'.$set_name.'_'.$code_name;
1401  $new_link_value = 'root_'.$set_name.'_'.$new_code_name;
1402  $root_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', FALSE, $old_link_value);
1403  if (empty($root_link) || ($old_link_value != $new_link_value) || $root_link['minorid'] != $new_root) {
1404  // the root or required link value has changed, so update the link
1405  $ok = TRUE;
1406  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
1407  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
1408  // delete old root link if any found...
1409  if (!empty($root_link) && !$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($root_link['linkid'])) {
1410  $ok = FALSE;
1411  } else if ($new_root) {
1412  $root = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_root);
1413  if (!is_null($root)) {
1414  if (!$asset->createLink($root, SQ_LINK_NOTICE, $new_link_value)) {
1415  $ok = FALSE;
1416  trigger_localised_error('SCH0012', E_USER_WARNING, $root->name, $root->id);
1417  }
1418  }
1419  }
1420  if ($ok) {
1421  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
1422  } else {
1423  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
1424  }
1425  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
1426  }
1427  }//end if
1428  $new_options[$new_code_name] = $new_option;
1429 
1430  }//end foreach
1431 
1432  if (!empty($_POST[$prefix.'__new__full_name'])) {
1433  $new_option['full_name'] = $_POST[$prefix.'__new__full_name'];
1434  if (empty($_POST[$prefix.'__new__statuses_default'])) {
1435  $new_option['statuses'] = array_get_index($_POST, $prefix.'__new__statuses', Array());
1436  }
1437  $new_code_name = preg_replace('/[^a-zA-Z0-9 ]/', '', $new_option['full_name']);
1438  $new_code_name = preg_replace('/( )+/', '_', $new_code_name);
1439  $new_code_name = strtolower($new_code_name);
1440  $link_value = 'root_'.$set_name.'_'.$new_code_name;
1441  if (empty($_POST[$prefix.'__new__root_default']) && !empty($_POST[$prefix.'__new__root']['assetid'])) {
1442  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
1443  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
1444  $new_root = $_POST[$prefix.'__new__root']['assetid'];
1445  $root = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_root);
1446  if (!is_null($root)) {
1447  if (!$asset->createLink($root, SQ_LINK_NOTICE, $link_value)) {
1448  trigger_localised_error('SCH0012', E_USER_WARNING, $root->name, $root->id);
1449  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
1450  } else {
1451  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
1452  $new_option['root_assetid'] = '';
1453  }
1454  }
1455  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
1456  }
1457  $new_options[$new_code_name] = $new_option;
1458  }
1459  return $new_options;
1460 
1461  }//end _processCategoryOptions()
1462 
1463 
1474  function paintAddCategory(&$asset, &$o, $prefix)
1475  {
1476  if ($asset->writeAccess('attributes')) {
1477  label(translate('name').': ', $prefix.'_new_category');
1478  text_box($prefix.'_new_category', '');
1479  return TRUE;
1480  }
1481 
1482  }//end paintAddCategory()
1483 
1484 
1495  function processAddCategory(&$asset, &$o, $prefix)
1496  {
1497  if ($asset->writeAccess('attributes')) {
1498  if (!empty($_POST[$prefix.'_new_category'])) {
1499  $cats = $asset->attr('categories');
1500  $safe_name = preg_replace('/[^a-zA-Z0-9 ]/', '', $_POST[$prefix.'_new_category']);
1501  $safe_name = preg_replace('/( )+/', '_', $safe_name);
1502  $safe_name = strtolower($safe_name);
1503  if (isset($cats[$safe_name])) {
1504  trigger_error('New Category Set could not be added: A category set called "'.$safe_name.'" already exists. Try another name');
1505  return FALSE;
1506  }
1507  $cats[$safe_name] = Array('unselected_text' => '', 'options' => Array());
1508  $asset->setAttrValue('categories', $cats);
1509  return TRUE;
1510  }
1511  }
1512  return FALSE;
1513 
1514  }//end processAddCategory()
1515 
1516 
1517 //-- FORMS --//
1518 
1519 
1530  function paintCustomiseSearchForms(&$asset, &$o, $prefix)
1531  {
1532  $write_access = $asset->writeAccess('links');
1533 
1534  $search_bodycopy_link = $asset->getFormatBodycopyLink('search_form');
1535  $sis_bodycopy_link = $asset->getFormatBodycopyLink('sis_form'); // search in search
1536  $search_customised = !empty($search_bodycopy_link) && $search_bodycopy_link['link_type'] != SQ_LINK_TYPE_3;
1537  $sis_customised = !empty($sis_bodycopy_link) && $sis_bodycopy_link['link_type'] != SQ_LINK_TYPE_3;
1538 
1539  ?>
1540  <table>
1541  <tr>
1542  <td><?php echo translate('sch_page_customise_search_form') ?></td>
1543  <td>
1544  <?php
1545  if (!$write_access) {
1546  echo ($search_customised) ? translate('yes') : translate('no');
1547  } else {
1548  check_box($prefix.'_search_form', 1, $search_customised);
1549  }
1550  ?>
1551  </td>
1552  </tr>
1553  <tr>
1554  <td><?php echo translate('sch_page_customise_sis_form') ?></td>
1555  <td>
1556  <?php
1557  if (!$write_access) {
1558  echo ($sis_customised) ? translate('yes') : translate('no');
1559  } else {
1560  check_box($prefix.'_sis_form', 1, $sis_customised);
1561  }
1562  ?>
1563  </td>
1564  </tr>
1565  </table>
1566  <?php
1567 
1568  return $write_access;
1569 
1570  }//end paintCustomiseSearchForms()
1571 
1572 
1583  function processCustomiseSearchForms(&$asset, &$o, $prefix)
1584  {
1585  $format_folder =& $asset->getFormatFolder();
1586 
1587  $forms = Array(
1588  translate('sch_page_default_search') => 'search_form',
1589  translate('sch_page_sis') => 'sis_form',
1590  );
1591 
1592  $bodycopies_visible = FALSE;
1593 
1594  foreach ($forms as $form_name => $value) {
1595  if (isset($_POST[$prefix.'_'.$value])) {
1596 
1597  if (is_null($format_folder)) {
1598  // create the folder if it does not exist
1599 
1600  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
1601  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
1602  $GLOBALS['SQ_SYSTEM']->am->includeAsset('folder');
1603  $format_folder = new Folder();
1604  $copy_link = Array('asset' => &$asset, 'value' => 'format_folder', 'link_type' => SQ_LINK_TYPE_2, 'is_dependant' => 1, 'is_exclusive' => 1);
1605 
1606  $format_folder->setAttrValue('name', 'Search Forms');
1607 
1608  if (!$format_folder->create($copy_link)) {
1609  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
1610  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
1611  trigger_localised_error('SCH0013', E_USER_WARNING);
1612  return FALSE;
1613  }
1614  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
1615  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
1616  }
1617 
1618  $bodycopy =& $asset->getFormatBodycopy($value);
1619 
1620  if (is_null($bodycopy)) {
1621 
1622  // if there is no bodycopy here, then we want to create it
1623  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
1624  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
1625  $GLOBALS['SQ_SYSTEM']->am->includeAsset('bodycopy');
1626  $bodycopy = new Bodycopy();
1627  $copy_link = Array('asset' => &$format_folder, 'value' => $value, 'link_type' => SQ_LINK_TYPE_2, 'is_dependant' => 1, 'is_exclusive' => 1);
1628 
1629  $bodycopy->setAttrValue('name', $form_name);
1630 
1631  if (!$bodycopy->create($copy_link)) {
1632  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
1633  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
1634  trigger_localised_error('SCH0014', E_USER_WARNING, $form_name);
1635  return FALSE;
1636  }
1637  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
1638  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
1639  } else {
1640  $bodycopy_link = $asset->getFormatBodycopyLink($value);
1641  if ($bodycopy_link['link_type'] != SQ_LINK_TYPE_2) {
1642  if (!$GLOBALS['SQ_SYSTEM']->am->updateLink($bodycopy_link['linkid'], SQ_LINK_TYPE_2)) {
1643  trigger_localised_error('SCH0014', E_USER_WARNING, $form_name);
1644  return FALSE;
1645  }
1646  }
1647  }
1648  $bodycopies_visible = TRUE;
1649 
1650  } else {
1651  $bodycopy_link = $asset->getFormatBodycopyLink($value);
1652  if (!empty($bodycopy_link['link_type']) && $bodycopy_link['link_type'] != SQ_LINK_TYPE_3) {
1653  if (!$GLOBALS['SQ_SYSTEM']->am->updateLink($bodycopy_link['linkid'], SQ_LINK_TYPE_3)) {
1654  trigger_localised_error('SCH0015', E_USER_WARNING, $form_name);
1655  return FALSE;
1656  }
1657  }
1658  }//end if isset
1659  }//end foreach
1660 
1661 
1662  // if none of the bodycopies are visible, the hide the folder as well
1663  $folder_link_type = SQ_LINK_TYPE_3;
1664  if ($bodycopies_visible) {
1665  $folder_link_type = SQ_LINK_TYPE_2;
1666  }
1667 
1668  $folder_link = $asset->getFormatFolderLink();
1669  if (!empty($folder_link['link_type']) && $folder_link['link_type'] != $folder_link_type) {
1670  if (!$GLOBALS['SQ_SYSTEM']->am->updateLink($folder_link['linkid'], $folder_link_type)) {
1671  trigger_localised_error('SCH0016', E_USER_WARNING);
1672  return FALSE;
1673  }
1674  }
1675 
1676  return FALSE;
1677 
1678  }//end processCustomiseSearchForms()
1679 
1680 
1691  function paintThesaurusAsset(&$asset, &$o, $prefix)
1692  {
1693  $link_value = 'thesaurus';
1694  $root_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'asset', FALSE, $link_value);
1695 
1696  $write_access = $asset->writeAccess('links');
1697 
1698  if (!$write_access) {
1699  $root_asset = NULL;
1700  if (!empty($root_link)) {
1701  echo get_asset_tag_line($root_link['minorid']);
1702  } else {
1703  echo translate('sch_page_no_thesaurus_asset_selected');
1704  }
1705  } else {
1706  asset_finder($prefix.'_thesaurusid', (!empty($root_link)) ? $root_link['minorid'] : '', Array('thesaurus' => 'D'));
1707  }
1708 
1709  return $write_access;
1710 
1711  }//end paintThesaurusAsset()
1712 
1713 
1724  function processThesaurusAsset(&$asset, &$o, $prefix)
1725  {
1726  if (!isset($_POST[$prefix.'_thesaurusid']['assetid'])) {
1727  return FALSE;
1728  }
1729  $new_root = $_POST[$prefix.'_thesaurusid']['assetid'];
1730 
1731  // getting existing root link
1732  $link_value = 'thesaurus';
1733  $root_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', FALSE, $link_value);
1734 
1735  // dont process anything if the root node has not changed
1736  if (!empty($root_link) && $root_link['minorid'] == $new_root) {
1737  return FALSE;
1738  }
1739 
1740  $ok = TRUE;
1741 
1742  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
1743  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
1744 
1745  // deleting old root link if any found...
1746  if (!empty($root_link) && !$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($root_link['linkid'])) {
1747  $ok = FALSE;
1748  } else if ($new_root) {
1749  $root = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_root);
1750 
1751  if (!is_null($root)) {
1752  if (!$asset->createLink($root, SQ_LINK_NOTICE, $link_value)) {
1753  $ok = FALSE;
1754  trigger_localised_error('SCH0017', E_USER_WARNING, $root->name, $root->id);
1755  }
1756  }
1757  }
1758 
1759  if ($ok) {
1760  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
1761  } else {
1762  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
1763  }
1764 
1765  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
1766  return $ok;
1767 
1768  }//end processThesaurusAsset()
1769 
1770 
1781  function paintAutoSynonymSearch(&$asset, &$o, $prefix)
1782  {
1783  $search_fields = array_keys($asset->attr('fields'));
1784  $keyed_search_fields = Array();
1785  foreach ($search_fields as $field) {
1786  $keyed_search_fields[$field] = $field;
1787  }
1788 
1789  $write_access = $asset->writeAccess('attributes');
1790 
1791  // No search fields present
1792  if (empty($search_fields)) {
1793  echo translate('sch_auto_syn_error_no_search_fields');
1794  return FALSE;
1795  }
1796 
1797  // Thesaurus asset not installed (why? it's in the core...)
1798  if (!$this->thesaurusInstalled($asset, $prefix)) {
1799  echo translate('sch_auto_syn_error_thesaurus_not_installed');
1800  return FALSE;
1801  }
1802 
1803  $link_value = 'thesaurus';
1804  $root_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'asset', FALSE, $link_value);
1805 
1806  // No thesaurus asset set
1807  if (empty($root_link)) {
1808  echo translate('sch_auto_syn_error_no_thesaurus_set');
1809  return FALSE;
1810  }
1811 
1812  $field = $asset->attr('auto_synonym_search_field');
1813 
1814  if ($write_access) {
1815  check_box($prefix.'_auto_synonym_search_enabled', 1, !empty($field), 'form.elements["'.$prefix.'_auto_synonym_search_field"].disabled = !this.checked; form.elements["'.$prefix.'_enable_multi_word_synonym_lookups"].disabled = !this.checked; return TRUE;');
1816  echo translate('sch_auto_syn_enable');
1817  $o->closeField();
1818 
1819  $o->openField(translate('sch_auto_syn_use_search_field'));
1820  combo_box($prefix.'_auto_synonym_search_field', $keyed_search_fields, FALSE, $field, 0, empty($field) ? 'disabled="disabled"' : '');
1821  } else {
1822  if (empty($field)) {
1823  echo translate('sch_auto_syn_not_enabled');
1824  } else {
1825  echo translate('sch_auto_syn_enabled_using_field', $field);
1826  }
1827  }
1828 
1829  return FALSE;
1830 
1831  }//end paintAutoSynonymSearch()
1832 
1833 
1844  function processAutoSynonymSearch(&$asset, &$o, $prefix)
1845  {
1846  // If the check box was not enabled, then store a blank string
1847  if (empty($_POST[$prefix.'_auto_synonym_search_enabled'])) {
1848  $asset->setAttrValue('auto_synonym_search_field', '');
1849  return TRUE;
1850  }
1851 
1852  // Otherwise
1853  if (!empty($_POST[$prefix.'_auto_synonym_search_field'])) {
1854  $asset->setAttrValue('auto_synonym_search_field', $_POST[$prefix.'_auto_synonym_search_field']);
1855  return TRUE;
1856  }
1857 
1858  return FALSE;
1859 
1860  }//end processAutoSynonymSearch()
1861 
1862 
1873  function paintEnableMultiWordSynonymLookups(&$asset, &$o, $prefix)
1874  {
1875  $search_fields = array_keys($asset->attr('fields'));
1876  $keyed_search_fields = Array();
1877  foreach ($search_fields as $field) {
1878  $keyed_search_fields[$field] = $field;
1879  }
1880 
1881  $write_access = $asset->writeAccess('attributes');
1882 
1883  // No search fields present
1884  if (empty($search_fields)) {
1885  return FALSE;
1886  }
1887 
1888  // Thesaurus asset not installed (why? it's in the core...)
1889  if (!$this->thesaurusInstalled($asset, $prefix)) {
1890  return FALSE;
1891  }
1892 
1893  $link_value = 'thesaurus';
1894  $root_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'asset', FALSE, $link_value);
1895 
1896  // No thesaurus asset set
1897  if (empty($root_link)) {
1898  return FALSE;
1899  }
1900 
1901  $enable_multi_words = $asset->attr('enable_multi_word_synonym_lookups');
1902 
1903  $o->openField(translate('sch_enable_multi_word_synonym_lookups'));
1904  if ($write_access) {
1905  check_box($prefix.'_enable_multi_word_synonym_lookups', 1, $enable_multi_words, '');
1906  echo translate('sch_enable_multi_word_synonym_lookups');
1907  } else {
1908  echo '<img src="'.sq_web_path('lib').'/web/images/'.(empty($enable_multi_words) ? 'cross' : 'tick').'.gif" />';
1909  }
1910  echo '<br />';
1911  echo translate('sch_enable_multi_word_synonym_lookups_note');
1912 
1913  return FALSE;
1914 
1915  }//end paintEnableMultiWordSynonymLookups()
1916 
1917 
1928  function processEnableMultiWordSynonymLookups(&$asset, &$o, $prefix)
1929  {
1930  if (empty($_POST[$prefix.'_enable_multi_word_synonym_lookups'])) {
1931  $asset->setAttrValue('enable_multi_word_synonym_lookups', FALSE);
1932  } else {
1933  $asset->setAttrValue('enable_multi_word_synonym_lookups', TRUE);
1934 
1935  }
1936 
1937  return TRUE;
1938 
1939  }//end processEnableMultiWordSynonymLookups()
1940 
1941 
1951  function thesaurusInstalled(&$asset, $prefix)
1952  {
1953  return $GLOBALS['SQ_SYSTEM']->am->installed('thesaurus');
1954 
1955  }//end thesaurusInstalled()
1956 
1957 
1958 //-- SORTING --//
1959 
1960 
1971  function _paintExtraSortOptions(&$asset, &$o, $prefix)
1972  {
1973 
1974  parent::_paintExtraSortOptions($asset, $o, $prefix);
1975  $wa = $asset->writeAccess('attributes');
1976  $o->openField(translate('sch_page_relevance'));
1977  $rel_enabled = FALSE;
1978  foreach ($asset->attr('sort_by') as $v) {
1979  if (array_get_index($v['params'], 'field') == 'score') {
1980  $rel_enabled = TRUE;
1981  break;
1982  }
1983  }
1984  if ($wa) {
1985  check_box($prefix.'_enable_rel', '1', $rel_enabled);
1986  label(translate('sch_page_enable_relevance'), $prefix.'_enable_rel');
1987  } else {
1988  $filename = $rel_enabled ? 'tick' : 'cross';
1989  echo '<img src="'.sq_web_path('lib').'/web/images/'.$filename.'.gif" /> ';
1990  echo translate('sch_page_enable_relevance');
1991  }
1992  $o->closeField();
1993 
1994  }//end _paintExtraSortOptions()
1995 
1996 
2007  function _processExtraSortOptions(&$asset, &$o, $prefix)
2008  {
2009  $res = parent::_processExtraSortOptions($asset, $o, $prefix);
2010  $val = $asset->attr('sort_by');
2011  if (isset($_POST[$prefix.'_submitted'])) {
2012  $want_rel = !empty($_POST[$prefix.'_enable_rel']);
2013  $rel_index = FALSE;
2014  foreach ($val as $i => $v) {
2015  if (array_get_index($v['params'], 'field') == 'score') {
2016  $rel_index = $i;
2017  break;
2018  }
2019  }
2020  if (($rel_index !== FALSE) && !$want_rel) {
2021  unset($val[$rel_index]);
2022  } else if (($rel_index === FALSE) && $want_rel) {
2023  $val[] = Array(
2024  'name' => translate('sch_page_relevance'),
2025  'type' => '',
2026  'params' => Array('field' => 'score'),
2027  );
2028  }
2029  $res = $asset->setAttrValue('sort_by', $val) || $res;
2030  }//end if
2031  return $res;
2032 
2033  }//end _processExtraSortOptions()
2034 
2035 
2036 //-- SAVED SEARCH --//
2037 
2038 
2049  function paintSavedSearch(&$asset, &$o, $prefix)
2050  {
2051  // Not much extra functionality here, just need to add the search fields to the _params
2052  // of parameter map, then show the results
2053  $wa = $asset->writeAccess('attributes');
2054  $pmap = $asset->getAttribute('stored_query_session');
2055  $current_params = $pmap->_params;
2056  // Add in the search fields
2057  $fields = $asset->attr('fields');
2058  foreach ($fields as $fieldname => $fieldvalue) {
2059  $current_params['parameters'][$fieldname] = 'Search Field: '.$fieldname;
2060  }
2061  $pmap->_params = $current_params;
2062  if ($wa) {
2063  $pmap->paint($prefix);
2064  } else {
2065  $pmap->paint($prefix, TRUE);
2066  }
2067 
2068  }//end paintSavedSearch()
2069 
2070 
2081  function processSavedSearch(&$asset, &$o, $prefix)
2082  {
2083  $wa = $asset->writeAccess('attributes');
2084  $pmap = $asset->getAttribute('stored_query_session');
2085  if ($wa) {
2086  $pmap->process($prefix);
2087  $asset->setAttrValue('stored_query_session', $pmap->value);
2088  $asset->saveAttributes();
2089  }
2090 
2091  return TRUE;
2092 
2093  }//end processSavedSearch()
2094 
2095 
2096 }//end class
2097 
2098 ?>