Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trim_saved_search_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_CORE_PACKAGE_PATH.'/data_source/data_source/data_source_edit_fns.inc';
19 
33 {
34 
35  public $dsn = NULL;
36  public $result = NULL;
37  public $fields = Array();
38  public $selected_fields = Array();
39  public $group_by = Array();
40  public $conn = NULL;
41 
42 
47  function __construct()
48  {
49  parent::__construct();
50  $this->static_screens['details']['force_unlock'] = FALSE;
51 
52  }//end constructor
53 
54 
55  //-- Dynamic Data --//
56 
57 
68  function paintGeneralOptions(&$asset, &$o, $prefix)
69  {
70 
71  require_once SQ_PACKAGES_PATH.'/trim/lib/trim_common.inc';
72  $write_access = $asset->writeAccess('attributes');
73 
74  $var_list = $asset->attr('dynamic_vars');
75 
76  // MAYBE: detect keywords in SQL and inject them into variables
77 
78  $var_list_classified = Array (
79  'Search Parent Container' => Array (
80  'search_parent_container',
81  ),
82  'General Search Options' => Array (
83  'search_parent_container',
84  'fileTypes',
85  'limit',
86  'search_sort_1',
87  'search_sort_2',
88  'search_sort_3',
89  'sort_1_descending',
90  'sort_2_descending',
91  'sort_3_descending',
92  ),
93  );
94 
95  foreach ($var_list_classified as $name => $options) {
96  ?>
97  <table class="sq-backend-table">
98  <tr>
99  <th style="width:200px;"><?php echo $name; ?></th>
100  <th>Default Value</th>
101  </tr>
102  <?php
103  foreach ($options as $var) {
104  if (!isset($var_list[$var])) continue;
105  //these options moved out
106  $value = $var_list[$var];
107  $var_id = base64_encode($var);
108 
109  ?> <tr>
110  <td>
111  <?php
112  if ($write_access) {
113  echo ucwords(str_replace('_', ' ', urlencode($var)));
114  } else {
115  echo ucwords(str_replace('_', ' ', urlencode($var)));
116  }
117  ?> </td>
118  <td valign="top" align="left">
119  <?php
120 
121  $list = Array();
122 
123  $search_sort = FALSE;
124  if (strpos(urlencode($var), 'search_sort') !== FALSE) {
125  $search_sort = TRUE;
126  $list['None'] = 'None';
128  } else if (urlencode($var) == 'search_date_range_type') {
130  }//end if
131 
132  if ($write_access) {
133  if ($search_sort) {
134  combo_box($prefix.'_var_value['.$var_id.']', $list, FALSE, $value, 0, ' style="width:200px;"');
135  } else if (is_array($value)) {
136  $not_multiple = (bool) (strpos(urlencode($var), 'search_sort') === FALSE);
137  combo_box($prefix.'_var_value['.$var_id.']', $list, $not_multiple, $value, 8, ' style="width:200px;"', 40);
138  } else if ( strpos(urlencode($var), 'descending') !== FALSE || strpos(urlencode($var), 'use_expanded_number') !== FALSE) {
139  combo_box($prefix.'_var_value['.$var_id.']', Array (TRUE => 'Yes', FALSE => 'No'), FALSE, $value);
140  } else {
141  text_box($prefix.'_var_value['.$var_id.']', $value, '','',FALSE, 'style="width:200px;"');
142  }
143  } else {
144  if (is_array($value)) {
145  ?><ul style="position:relative;left:-41px;list-style:none;"><?php
146  foreach ($value as $key => $val) {
147  echo '<li>'.$val.'</li>';
148  }//end foreach
149  ?></ul><?php
150  } else if ( strpos(urlencode($var), 'descending') !== FALSE || strpos(urlencode($var), 'use_expanded_number') !== FALSE) {
151  echo ($value) ? 'Yes' : 'No';
152  } else {
153  echo $value;
154  }//end else
155  }
156  ?> </td>
157  </tr>
158  <?php
159  unset($var_list[$var]);
160 
161  }//end foreach
162 
163  }//end foreach
164 
165  ?> </table> <?php
166 
167 
168 
169  $o->sectionNote(translate('trim_ds_search_default_options_note'));
170 
171  return $write_access;
172 
173  }//end paintGeneralOptions()
174 
175 
183  function paintDataMapping(&$asset, &$o, $prefix)
184  {
185  $write_access = $asset->writeAccess('attributes');
186  $var_list = $asset->attr('dynamic_vars');
187 
188  $o->openSection('Data Mappings');
189  $o->openRaw();
190  $map = $asset->getAttribute('parameter_map');
191 
192  $parameter_names = $map->getParameters();
193 
194  foreach ($var_list as $var_name => $default) {
195  $map->setParameter($var_name, 'Variable: '.$var_name);
196  }
197 
198  $map->paint($prefix.'_parameter_map', !$write_access);
199  $o->closeRaw();
200 
201  $o->sectionNote(translate('trim_ds_search_default_options_note'));
202 
203  return $write_access;
204 
205  }//end paintDataMapping()
206 
207 
215  function processDataMapping(&$asset, &$o, $prefix)
216  {
217  $write_access = $asset->writeAccess('attributes');
218  if (!$write_access) return FALSE;
219  $var_name_pattern = '/^[a-zA-Z_\-0-9\.]+$/';
220  $var_list = $asset->attr('dynamic_vars');
221 
222  $map = $asset->getAttribute('parameter_map');
223 
224  $map->process($prefix.'_parameter_map');
225 
226  $asset->setAttrValue('parameter_map', unserialize($map->value));
227 
228  return $write_access;
229 
230  }//end processDataMapping()
231 
232 
243  function processGeneralOptions(&$asset, &$o, $prefix)
244  {
245  $var_name_pattern = '/^[a-zA-Z_\-0-9\.]+$/';
246 
247  $write_access = $asset->writeAccess('attributes');
248  if (!$write_access) return FALSE;
249 
250  $to_delete = array_get_index($_REQUEST, $prefix.'_delete_var', Array());
251  $var_value = array_get_index($_REQUEST, $prefix.'_var_value', Array());
252  $var_name = array_get_index($_REQUEST, $prefix.'_var_name', Array());
253 
254  $var_list = $asset->attr('dynamic_vars');
255 
256  $map = $asset->getAttribute('parameter_map');
257 
258  $parameter_names = $map->getParameters();
259  foreach ($var_list as $name => $default) {
260  $map->setParameter($name, 'Variable: '.$name);
261  }
262 
263  foreach ($var_value as $hash => $value) {
264  $name = base64_decode($hash);
265  if (isset($to_delete[$hash])) {
266  unset($var_list[$name]);
267 
268  continue;
269  }
270 
271  $var_list[$name] = $value;
272  }
273 
274  $new_var_list = Array();
275  $rename_success = FALSE;
276 
277  // now we rename variables
278  foreach ($var_name as $hash => $new_name) {
279  $new_name = trim($new_name);
280 
281  if (empty($new_name)) {
282  $rename_success = FALSE;
283  trigger_error('Variable name cannot be empty. No variables were renamed.', E_USER_NOTICE);
284  break;
285  }
286 
287  // check new name against regex
288  $new_name_is_valid = preg_match($var_name_pattern, $new_name);
289  if (!$new_name_is_valid) {
290  $rename_success = FALSE;
291  trigger_error('Variable name ['.htmlentities($new_name).'] contains characters that are not allowed. Can only use letters (A-Za-z), digits(0-9), underscore (_), dash (-) and dot (.)', E_USER_NOTICE);
292  break;
293  }
294 
295  $name = base64_decode($hash);
296 
297  // skip the deleted vars
298  if (!isset($var_list[$name])) continue;
299 
300  if (isset($new_var_list[$new_name])) {
301  $rename_success = FALSE;
302  trigger_error('Could not rename variables because variable name "'.htmlentities($new_name).'" already exists', E_USER_NOTICE);
303  break;
304  }
305 
306  if ($new_name != $name) {
307  if (in_array($name, $parameter_names)) {
308  $map->moveParameter($name, $new_name);
309  }
310  $rename_success = TRUE;
311  }
312 
313  $new_var_list[$new_name] = $var_list[$name];
314 
315  }//end foreach
316 
317 
318  if ($rename_success) $var_list = $new_var_list;
319 
320  $new_names = array_get_index($_REQUEST, $prefix.'_new_dynamic_data_name', Array());
321  if (!empty($new_names)) {
322 
323  foreach ($new_names as $seq_number => $new_var_name) {
324  $new_var_name = trim($new_var_name);
325 
326  $new_var_value = array_get_index($_REQUEST[$prefix.'_new_dynamic_data_value'], $seq_number, '');
327  if (empty($new_var_name)) {
328  if (!empty($new_var_value)) {
329  trigger_error('New variable name cannot be empty', E_USER_WARNING);
330  }
331  continue;
332  }
333 
334  // check new name against regex
335  $new_name_is_valid = preg_match($var_name_pattern, $new_var_name);
336  if (!$new_name_is_valid) {
337  trigger_error('Variable name "'.htmlentities($new_var_name).'" contains characters that are not allowed. Can only use letters (A-Za-z), digits(0-9), underscore (_), dash (-) and dot (.)', E_USER_NOTICE);
338  continue;
339  }
340 
341  if (isset($var_list[$new_var_name])) {
342  trigger_error('Variable Name "'.htmlentities($new_var_name).'" is already in use', E_USER_WARNING);
343  continue;
344  }
345 
346  $var_list[$new_var_name] = $new_var_value;
347  $map->setParameter($new_var_name, 'Variable: '.$new_var_name);
348  }
349  }
350 
351  $asset->setAttrValue('dynamic_vars', $var_list);
352  $asset->setAttrValue('parameter_map', unserialize($map->value));
353 
354  return TRUE;
355 
356  }//end processGeneralOptions()
357 
358 
359 
368  function paintWsdlUrl(&$asset, &$o, $prefix)
369  {
370  $write_access = $asset->writeAccess('attributes');
371  $wsdl = $asset->attr('wsdl');
372  if ($write_access) {
373  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
374  text_box($prefix.'_wsdl_url', $wsdl, '35');
375  } else {
376  echo $wsdl;
377  }//end else if
378 
379  return $write_access;
380 
381  }//end paintWsdlUrl()
382 
383 
392  function processWsdlUrl(&$asset, &$o, $prefix)
393  {
394  if (!$asset->writeAccess('attributes')) return FALSE;
395 
396  $new_name = NULL;
397  $old_wsdl = $asset->attr('wsdl');
398  if (!empty($_POST[$prefix.'_wsdl_url'])) {
399  $new_wsdl = trim($_POST[$prefix.'_wsdl_url']);
400  if ($old_wsdl != $new_wsdl) {
401  $res = $asset->setAttrValue('wsdl', $new_wsdl);
402  return TRUE;
403  } else {
404  return FALSE;
405  }
406  }
407  return TRUE;
408 
409  }//end processWsdlUrl()
410 
411 
422  function paintConnectorLink(&$asset, &$o, $prefix)
423  {
424  // get root links
425  $connector_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'trim_connector', FALSE, 'trim_connector');
426  if (empty($connector_link)) {
427  $connector_asset_id = NULL;
428  } else {
429  $connector_asset_id = $connector_link['minorid'];
430  }
431 
432  if ($asset->writeAccess('links')) {
433  asset_finder($prefix.'_connector_node', $connector_asset_id, Array('trim_connector'=>'D'));
434  } else {
435  if (empty($connector_asset_id)) {
436  echo 'No connector selected';
437  } else {
438  echo get_asset_tag_line($connector_asset_id);
439  }
440  }
441  return TRUE;
442 
443  }//end paintConnectorLink()
444 
445 
456  function processConnectorLink(&$asset, &$o, $prefix)
457  {
458  $new_connector_id = @$_REQUEST[$prefix.'_connector_node']['assetid'];
459 
460  if (!$asset->writeAccess('links')) {
461  trigger_error('You do not have write access to change the connector link', E_USER_WARNING);
462  return FALSE;
463  }
464 
465  $current_connector_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'trim_connector', FALSE, 'trim_connector');
466  $current_connector_asset_id = @$current_connector_link['minorid'];
467 
468  if (!empty($current_connector_link)) {
469  // if the new connector id is not null and is equal to the current
470  // connector asset id then return
471  if ((!empty($new_connector_id)) && ($current_connector_asset_id === $new_connector_id)) {
472  return TRUE;
473  } else {
474  // else means that we want to create a new link or we want to
475  // clear the link
476  $GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($current_connector_link['linkid']);
477 
478  // if the new connector id is empty means we want to clear the
479  // link we got nothing else to do so return TRUE
480  if (empty($new_connector_id)) return TRUE;
481  }
482  }
483 
484  if (!empty($new_connector_id)) {
485  $new_connector_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_connector_id);
486  $result_id = $GLOBALS['SQ_SYSTEM']->am->createAssetLink($asset, $new_connector_asset, SQ_LINK_NOTICE, 'trim_connector');
487 
488  if (empty($result_id)) {
489  trigger_error('Could not link the connector to this asset', E_USER_WARNING);
490  return FALSE;
491  }
492 
493  }
494 
495  return TRUE;
496 
497  }//end processConnectorLink()
498 
499 
510  function paintSynchCheck(&$asset, &$o, $prefix)
511  {
512  $wa = $asset->writeAccess('attributes');
513  $o->openRaw();
514  //
515  ?>
516  <script type="text/javascript" src="<?php echo sq_web_path('data').'/asset_types/trim_saved_search/js/ajax.js' ?>">
517  </script>
518  <div>
519  <table style="width:auto;border-spacing:0px;" border="0">
520  <tr>
521  <td width="90"><span style="font-weight:bold;">Check Update</span></td>
522  <td width="150"><span id="update_text">Not Checked</span></td>
523  <td><?php if ($wa) normal_button($prefix.'_update', 'Check for Updates', 'sendRequest(\''.$asset->getURL().'?check_update=1\', \'updateCheckInterface\');'); ?></td>
524  <td><?php if ($wa) normal_button($prefix.'_synch', 'Synchronize Now', 'sendRequest(\''.$asset->getURL().'?synch_now=1\', \'updateSynchInterface\');'); ?></td>
525  <td><img id="trim_saved_search_loader" src="<?php echo sq_web_path('data').'/asset_types/trim_saved_search/images/loader.gif'?>" style="display:none;" height="20" width"20" /></td>
526  </tr>
527  </table>
528  </div>
529 
530  <?php
531  $o->closeRaw();
532 
533 
534  }//end paintSynchCheck()
535 
536 
547  function processSynchCheck(&$asset, &$o, $prefix)
548  {
549 
550  }//end processSynchCheck()
551 
552 
563  function paintRetrieveFields(&$asset, &$o, $prefix)
564  {
565  $wa = $asset->writeAccess('attributes');
566  $fields = $asset->attr('retrieved_fields');
567  $standard_fields = isset ($fields['standard_fields']) ? count($fields['standard_fields']) : 0;
568  $additional_fields = isset ($fields['additional_fields']) ? count($fields['additional_fields']) : 0;
569  $record_types = isset ($fields['record_types']) ? count($fields['record_types']) : 0;
570  ?>
571  <table>
572  <tr>
573  <td>
574  <?php
575  if (!empty($_POST[$prefix.'_retrieve'])) echo '<span style="color:green;">';
576  echo (empty($fields) ? 'Empty' : $standard_fields.' standard fields, '.$additional_fields.' additional fields and '.$record_types.' record types retrieved');
577  if (!empty($_POST[$prefix.'_retrieve'])) echo '</span>';
578  ?>
579  </td>
580  <td>
581  <?php
582  if ($wa) submit_button($prefix.'_retrieve', 'Retrieve Now', '');
583  ?>
584  </td>
585  </tr>
586  </table>
587  <?php
588  return $wa;
589 
590  }//end paintSynchCheck()
591 
592 
603  function processRetrieveFields(&$asset, &$o, $prefix)
604  {
605  if (!$asset->writeAccess('attributes')) return FALSE;
606  $connection = $asset->getConnection();
607 
608  if (!empty($_POST[$prefix.'_retrieve']) && !empty($connection)) {
609  // get all fields form TRIM server
610  $st_fields = Array();
611  $udf_fields = Array();
612  $fields_type = Array();
613  try {
614  $client = new SoapClient($connection['wsdl'], $connection['authentication']);
615  $data = $client->ListProperties(Array('ObjectName' => 'Record'));
616  foreach ($data->ListPropertiesResult->PropertyDescription as $field) {
617  if (preg_match('/^udf:/', (String) $field->Name)) {
618  $udf_fields[(String) $field->Name] = ((String) $field->Caption);
619  }
620  else {
621  $st_fields[(String) $field->Name] = ((String) $field->Caption);
622  }
623  // record fields type
624  $fields_type[(String) $field->Name] = (String) $field->Type;
625  // add custom matrix fields in correct order
626  if((String) $field->Name == 'recContents') $st_fields['recContainerTitle'] = 'Container Title';
627  }
628 
629 
630  } catch (SoapFault $e) {
631  trigger_error($e->getMessage(), E_USER_WARNING);
632  return FALSE;
633  }//end if
634 
635 
636  //retrieve record types info
637  $record_types = TRIM_Common::getAllRecordTypes($connection);
638  $asset->setAttrValue('retrieved_fields', Array('standard_fields' => $st_fields, 'additional_fields' => $udf_fields, 'field_types' => $fields_type, 'record_types' => $record_types));
639 
640  }
641  return TRUE;
642  }//end processRetrieveFields()
643 
644 
655  function paintSearchFields(&$asset, &$o, $prefix)
656  {
657  $write_access = $asset->writeAccess('attributes');
658  $var_list = $asset->attr('dynamic_vars');
659  $search_groups = isset($var_list['search_clauses']['search_groups']) ? $var_list['search_clauses']['search_groups'] : Array();
660  $global_logic = isset($var_list['search_clauses']['global_logic']) ? $var_list['search_clauses']['global_logic'] : 'AND';
661 
662  //get possible search fields
663  $available_fields = Array('none' => '-- '.ucfirst(translate('trim_ds_search_add_search_field').' --'));
664  $list = $asset->getRetrievedFields('additional');
665  $available_fields += TRIM_Common::getRecordStringSearchClauseType() + $list;
666 
667  //work out total rows
668  $total_rows = 0;
669  foreach($search_groups as $group_data) {
670  $total_rows += count($group_data['content']);
671  if ($write_access) $total_rows ++;
672  }
673 
674  ?>
675  <table class ="sq-backend-table" border="1" style="margin-bottom: 7px; ">
676  <tr>
677  <th rowspan="2"><?php echo translate('trim_ds_search_groups'); ?></th>
678  <th colspan="<?php echo $write_access ? 3 : 2; ?>"><?php echo translate('trim_ds_search_search_fields'); ?></th>
679  <th rowspan="2"><?php echo translate('trim_ds_search_logic_group'); ?></th>
680  <?php
681  if ($write_access) {
682  ?>
683  <th rowspan="2"><?php echo translate('delete'); ?></th>
684  <?php
685  }
686  ?>
687  <th rowspan="2"><?php echo translate('trim_ds_search_logic_global'); ?></th>
688  </tr>
689  <tr>
690  <th><?php echo translate('name');?></th>
691  <th><?php echo translate('keyword');?> </th>
692  <?php
693  if ($write_access) {
694  ?>
695  <th><?php echo translate('delete'); ?></th>
696  <?php
697  }
698  ?>
699  </tr>
700  <?php
701  foreach ($search_groups as $group_index => $group_data) {
702  if ($write_access) $group_data['content'][] = Array('caption' => 'new');
703 
704  foreach ($group_data['content'] as $field_index => $field_data) {
705  ?>
706  <tr>
707  <?php
708  if ($field_index == 0) {
709  ?>
710  <td rowspan="<?php echo (count($group_data['content'])); ?>">Group <?php echo ($group_index+1); ?></td>
711  <?php
712  }
713  ?>
714  <td class="sq-backend-data" style="padding: 4px;">
715  <?php
716  if ($field_data['caption'] == 'new') {
717  if ($write_access) {
718  $count = count($group_data['content']);
719  combo_box($prefix.'_fields['.$group_index.']['.$count.'][new_search_field]', $available_fields, FALSE,'none');
720  }
721  } else {
722  echo $field_data['caption'];
723  //display field type
724  $field_type = $asset->getRetrievedFieldType($field_data['name']);
725  echo (empty($field_type) ? '' : ' ('.$field_type.')');
726  }
727  ?>
728  </td>
729  <td>
730  <?php
731  if ($field_data['caption'] != 'new') {
732  if($write_access)
733  text_box($prefix.'_fields['.$group_index.']['.$field_index.'][keyword]', $field_data['keyword'], '35');
734  else
735  echo $field_data['keyword'];
736  }//end if
737  ?>
738  </td>
739  <?php
740  if ($write_access) {
741  // Delete field Cell
742  ?>
743  <td class="sq-backend-data">
744  <?php
745  if ($field_data['caption'] != 'new') {
746  check_box($prefix.'_fields['.$group_index.']['.$field_index.'][delete]');
747  }
748  ?>
749  </td>
750  <?php
751  }
752  if ($field_index == 0) {
753  // Logic Cell
754  ?>
755  <td rowspan="<?php echo count($group_data['content']);?>" style="vertical-align:middle; text-align:center;">
756  <?php
757  $group_logic_options = Array('AND' => translate('trim_ds_search_logic_and'), 'OR' => translate('trim_ds_search_logic_or'));
758  if ($write_access) {
759  combo_box($prefix.'_fields['.$group_index.'][group_logic]', $group_logic_options, FALSE, array_get_index($group_data, 'group_logic', 'AND'), 0, 'title="'.translate('trim_ds_search_group_logic_note').'"');
760  } else {
761  echo array_get_index($group_data, 'group_logic', 'AND');
762  }
763  ?>
764  </td>
765  <?php
766  }
767 
768  if (($field_index == 0) && $write_access) {
769  // Delete field overall cell
770  ?>
771  <td rowspan="<?php echo count($group_data['content']);?>">
772  <?php
773  check_box($prefix.'_fields['.$group_index.'][delete]');
774  ?>
775  </td>
776  <?php
777  }
778 
779  if ($group_index == 0 && $field_index == 0) {
780  // Global Logic Cell
781  ?>
782  <td rowspan="<?php echo $total_rows; ?>" style="vertical-align:middle; text-align:center;">
783  <?php
784  $global_logic_options = Array('AND' => translate('trim_ds_search_logic_and'), 'OR' => translate('trim_ds_search_logic_or'));
785  if ($write_access) {
786  combo_box($prefix.'_fields[global_logic]', $global_logic_options, FALSE, $global_logic, 0, 'title="'.translate('trim_ds_search_global_logic_note').'"');
787  } else {
788  echo $global_logic;
789  }
790  ?>
791  </td>
792  <?php
793  }
794 
795  ?>
796  </tr>
797 
798  <?php
799  }//end foreach
800  }//end foreach */
801  ?>
802  </tr>
803 
804  </table>
805  <?php
806  if ($write_access) {
807  echo ('<div class="sq-backend-smallprint">'.translate('trim_ds_search_add_search_field_group').'</div>');
808  $count = count($search_groups);
809  combo_box($prefix.'_fields['.$count.'][new_search_group]', $available_fields, FALSE,'none');
810  }
811  return TRUE;
812 
813  }//end paintSearchFields()
814 
815 
826  function processSearchFields(&$asset, &$o, $prefix)
827  {
828 
829  if (!$asset->writeAccess('attributes')) return FALSE;
830  $var_list = $asset->attr('dynamic_vars');
831  $search_groups = Array();
832  $global_logic = '';
833 
834  $available_fields = Array();
835  $list = $asset->getRetrievedFields('additional');
836  $available_fields = TRIM_Common::getRecordStringSearchClauseType() + $list;
837 
838  if (isset($_POST[$prefix.'_fields'])) {
839  // set global logic
840  if(isset($_POST[$prefix.'_fields']['global_logic'])) {
841  $global_logic = $_POST[$prefix.'_fields']['global_logic'];
842  unset($_POST[$prefix.'_fields']['global_logic']);
843  }
844  else {
845  $global_logic = 'AND';
846  }
847 
848  foreach ($_POST[$prefix.'_fields'] as $group_index => $group) {
849  // set group logic
850  if(isset($group['group_logic'])) {
851  $group_logic = $group['group_logic'];
852  unset($group['group_logic']);
853  }
854  else {
855  $group_logic = 'AND';
856  }
857 
858 
859  if(isset($group['delete'])) continue;
860  if(isset($field['new_search_group']) && $field['new_search_group'] === 'none') continue;
861  if(isset($group['new_search_group']) && $group['new_search_group'] != 'none') {
862  // build a search field with a new group
863  $new_group = Array();
864  $field_name = $group['new_search_group'];
865  $field_caption = isset($available_fields[$field_name]) ? $available_fields[$field_name] : '';
866  $new_group['group_logic'] = 'AND';
867  $new_group['content'][] = Array('name' => $field_name, 'caption' => $field_caption, 'keyword' => '');
868 
869  }
870  else {
871  $new_group = Array();
872  $new_group['group_logic'] = $group_logic;
873  $new_group['content'] = Array();
874 
875  foreach ($group as $field_index => $field) {
876  if(isset($field['delete'])) continue;
877  if(isset($field['new_search_field']) && $field['new_search_field'] === 'none') continue;
878  if(isset($field['new_search_field']) && $field['new_search_field'] != 'none') {
879  //build new field
880  $field_name = $field['new_search_field'];
881  $field_caption = isset($available_fields[$field_name]) ? $available_fields[$field_name] : '';
882  $keyword = '';
883  }
884  else {
885  // process normal fields
886  $old_field = $var_list['search_clauses']['search_groups'][$group_index]['content'][$field_index];
887  $field_name = $old_field['name'];
888  $field_caption = $old_field['caption'];
889  $keyword = $field['keyword'];
890  }
891  $new_group['content'][] = Array('name' => $field_name, 'caption' => $field_caption, 'keyword' => $keyword);
892  }
893  }
894  if(!empty($new_group['content'])) $search_groups[] = $new_group;
895  }
896  }
897  $var_list['search_clauses']['search_groups'] = $search_groups;
898  $var_list['search_clauses']['global_logic'] = $global_logic;
899 
900  return ($asset->setAttrValue('dynamic_vars', $var_list));
901 
902  }//end processSearchFields()
903 
904 
905 
916  function paintResultFields(&$asset, &$o, $prefix)
917  {
918  $write_access = $asset->writeAccess('attributes');
919  $var_list = $asset->attr('dynamic_vars');
920  $result_fields = isset($var_list['result_fields']) ? $var_list['result_fields'] : Array();
921 
922  //get possible search fields
923  $available_fields = Array('none' => '-- '.ucfirst(translate('trim_ds_search_add_result_field').' --'));
924  $list = $asset->getRetrievedFields('all');
925  $available_fields += !empty($list) ? $list : TRIM_Common::getRecordProperties();
926 
927 
928  ?>
929  <table class ="sq-backend-table" border="1" style="margin-bottom: 7px; ">
930 
931  <tr>
932  <th><?php echo translate('name');?></th>
933  <th><?php echo translate('type');?> </th>
934  <th><?php echo translate('field_category');?> </th>
935  <?php
936  if ($write_access) {
937  ?>
938  <th><?php echo translate('delete'); ?></th>
939  <?php
940  }
941  ?>
942  </tr>
943  <?php
944  foreach ($result_fields as $name => $caption) {
945  ?>
946  <tr>
947  <td class="sq-backend-data" style="padding: 4px;">
948  <?php
949  echo $caption;
950  ?>
951  </td>
952  <td>
953  <?php
954  $field_type = $asset->getRetrievedFieldType($name);
955  echo (empty($field_type) ? '' : $field_type);
956  ?>
957  </td>
958  <td>
959  <?php
960  echo(preg_match('/^udf:/', $name) ? translate('field_additional') : translate('field_standard'));
961  ?>
962  </td>
963  <?php
964  if ($write_access) {
965  // Delete field Cell
966  ?>
967  <td class="sq-backend-data">
968  <?php
969  check_box($prefix.'_result_fields['.$name.'][delete]');
970  ?>
971  </td>
972  <?php
973  }
974 
975 
976  }//end foreach
977  ?>
978  </tr>
979  </table>
980  <?php
981  if ($write_access) {
982  echo ('<div class="sq-backend-smallprint">'.translate('trim_ds_search_result_field_note').'</div>');
983  combo_box($prefix.'_result_fields[new]', $available_fields, FALSE,'none');
984  }
985 
986  return TRUE;
987 
988  }//end paintResultFields()
989 
990 
1001  function processResultFields(&$asset, &$o, $prefix)
1002  {
1003 
1004  if (!$asset->writeAccess('attributes')) return FALSE;
1005  $var_list = $asset->attr('dynamic_vars');
1006  $result_fields = isset($var_list['result_fields']) ? $var_list['result_fields'] : Array();
1007 
1008 
1009  //get possible search fields
1010  $list = $asset->getRetrievedFields('all');
1011  $available_fields = !empty($list) ? $list : TRIM_Common::getRecordProperties();
1012 
1013  if (isset($_POST[$prefix.'_result_fields'])) {
1014  foreach ($_POST[$prefix.'_result_fields'] as $field => $value) {
1015  if (isset($field['delete']) && isset($result_fields[$field])) {
1016  unset($result_fields[$field]);
1017  }
1018  }
1019  if(isset($_POST[$prefix.'_result_fields']['new']) && $_POST[$prefix.'_result_fields']['new'] !== 'none') {
1020  $new_field = $_POST[$prefix.'_result_fields']['new'];
1021  $field_caption = isset($available_fields[$new_field]) ? $available_fields[$new_field] : '';
1022  $result_fields[$new_field] = $field_caption;
1023  }
1024  }
1025 
1026  $var_list['result_fields'] = $result_fields;
1027  return ($asset->setAttrValue('dynamic_vars', $var_list));
1028 
1029  }//end processResultFields()
1030 
1031 
1032 
1043  function paintRecordTypeFilter(&$asset, &$o, $prefix)
1044  {
1045  $write_access = $asset->writeAccess('attributes');
1046  $retrieved = $asset->attr('retrieved_fields');
1047  $available_record_types = Array('none' => '-- '.ucfirst(translate('trim_ds_search_add_record_type').' --'));
1048  $available_record_types += isset($retrieved['record_types']) ? $retrieved['record_types'] : Array();
1049 
1050  $var_list = $asset->attr('dynamic_vars');
1051  $record_types = isset($var_list['record_type_filter']) ? $var_list['record_type_filter'] : Array();
1052 
1053 
1054  ?>
1055  <table class ="sq-backend-table" border="1" style="margin-bottom: 7px; width:300px;">
1056 
1057  <tr>
1058  <th><?php echo translate('name');?></th>
1059  <?php
1060  if ($write_access) {
1061  ?>
1062  <th><?php echo translate('delete'); ?></th>
1063  <?php
1064  }
1065  ?>
1066  </tr>
1067  <?php
1068  foreach ($record_types as $uri => $name) {
1069  ?>
1070  <tr>
1071  <td class="sq-backend-data" style="padding: 4px;">
1072  <?php
1073  echo $name;
1074  ?>
1075  </td>
1076 
1077  <?php
1078  if ($write_access) {
1079  // Delete field Cell
1080  ?>
1081  <td class="sq-backend-data">
1082  <?php
1083  check_box($prefix.'_record_type_filter['.$uri.'][delete]');
1084  ?>
1085  </td>
1086  <?php
1087  }
1088 
1089 
1090  }//end foreach
1091  ?>
1092  </tr>
1093  </table>
1094  <?php
1095  if ($write_access) {
1096  echo ('<div class="sq-backend-smallprint">'.translate('trim_ds_search_record_type_filter_note').'</div>');
1097  combo_box($prefix.'_record_type_filter[new]', $available_record_types, FALSE,'none');
1098  if(count($available_record_types) ==1 ) {
1099  echo ('<div class="sq-backend-smallprint">'.translate('trim_ds_search_record_type_filter_no_record_type').'</div>');
1100  }
1101  }
1102 
1103  return TRUE;
1104 
1105  }//end paintRecordTypeFilter()
1106 
1107 
1118  function processRecordTypeFilter(&$asset, &$o, $prefix)
1119  {
1120 
1121  if (!$asset->writeAccess('attributes')) return FALSE;
1122  $var_list = $asset->attr('dynamic_vars');
1123  $record_types = isset($var_list['record_type_filter']) ? $var_list['record_type_filter'] : Array();
1124 
1125 
1126  //get possible record types
1127  $retrieved = $asset->attr('retrieved_fields');
1128  $available_record_types = isset($retrieved['record_types']) ? $retrieved['record_types'] : Array();
1129 
1130  if (isset($_POST[$prefix.'_record_type_filter'])) {
1131  foreach ($_POST[$prefix.'_record_type_filter'] as $field => $value) {
1132  if (isset($value['delete']) && isset($record_types[$field])) {
1133  unset($record_types[$field]);
1134  }
1135  }
1136  if(isset($_POST[$prefix.'_record_type_filter']['new']) && $_POST[$prefix.'_record_type_filter']['new'] !== 'none') {
1137  $new_uri = $_POST[$prefix.'_record_type_filter']['new'];
1138  $record_name = isset($available_record_types[$new_uri]) ? $available_record_types[$new_uri] : '';
1139  $record_types[$new_uri] = $record_name;
1140  }
1141  }
1142 
1143  $var_list['record_type_filter'] = $record_types;
1144  return ($asset->setAttrValue('dynamic_vars', $var_list));
1145 
1146  }//end processResultFields()
1147 
1148 }//end class
1149 ?>