18 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
41 parent::__construct();
58 $name = $asset->
attr(
'shadow_name');
61 text_box(
'shadow_name', !empty($name) ? $name :
'', 80);
63 if (!empty($name)) echo $name;
83 if (!$asset->
writeAccess(
'attributes'))
return FALSE;
86 $name = $asset->
attr(
'shadow_name');
87 if (!empty($_POST[
'shadow_name'])) {
88 $new_name = $_POST[
'shadow_name'];
90 if ($name != $new_name) {
112 $shadow_asset = $asset->
getAsset($asset->id.
':0');
113 if (is_null($shadow_asset)) {
114 echo
'<strong>'.translate(
'data_source_no_keywords').
'</strong>';
117 $keywords = $shadow_asset->getAvailableKeywords();
120 <table
class=
"sq-backend-table">
122 <th><?php echo translate(
'keyword');?></th>
123 <th><?php echo translate(
'description');?></th>
126 foreach ($keywords as $key => $desc) {
129 if ($key ==
'data_source_record_set_shadow_asset_name' || $key ==
'ds__shadow_asset_name') {
130 unset($keywords[$key]);
133 if (strpos($key,
'data_source_record_set') === FALSE && strpos($key,
'ds__') === FALSE) {
134 unset($keywords[$key]);
140 <td><?php echo
'%'.$key.
'%';?> </td>
141 <td><?php echo $desc; ?> </td>
149 return $write_access;
186 $filters = $asset->attr(
'record_filters');
187 $wa = $asset->writeAccess(
'attributes');
189 <table
class ="sq-backend-table" border=
"1" style=
"margin-bottom: 7px">
191 <th width=
"20%"><?php echo translate(
'data_source_filter_name'); ?></th>
192 <th width=
"45%"><?php echo translate(
'data_source_value_to_match'); ?></th>
193 <th><?php echo translate(
'data_source_match_type'); ?></th>
194 <th><?php echo translate(
'data_source_match_case'); ?></th>
198 <th><?php echo translate(
'delete'); ?></th>
205 $match_options = Array(
206 'exact' =>
'String match - Exact',
207 'contains' =>
'String match - Contains',
208 'regex' =>
'Regex match',
210 $case_options = Array(
211 'ignore_case' =>
'No',
212 'match_case' =>
'Yes',
215 foreach ($filters as $index => $field_data) {
216 $field_name = $field_data[
'name'];
217 $field_value = $field_data[
'value'];
218 $match_type = $field_data[
'match_type'];
219 $match_case = $field_data[
'match_case'];
226 text_box($prefix.
'_filter['.$index.
'][name]', $field_name, 30);
235 text_box($prefix.
'_filter['.$index.
'][value]', $field_value, 80);
244 combo_box($prefix.
'_filter['.$index.
'][match_type]', $match_options, FALSE, $match_type);
246 echo $match_options[$match_type];
253 combo_box($prefix.
'_filter['.$index.
'][match_case]', $case_options, FALSE, $match_case);
255 echo $case_options[$match_case];
262 check_box($prefix.
'_filter['.$index.
'][delete]');
275 label(translate(
'data_source_new_filter'), $prefix.
'_new_filter_name');
277 text_box($prefix.
'_new_filter_name',
'', 25);
280 $o->sectionNote(translate(
'data_source_dynamic_keywords_node'));
299 if (!$asset->writeAccess(
'attributes'))
return FALSE;
301 $updated_filters = Array();
302 if (isset($_POST[$prefix.
'_filter'])) {
303 foreach($_POST[$prefix.
'_filter'] as $index => $filter_data) {
304 if (isset($filter_data[
'delete'])) {
307 $filter_name = trim($filter_data[
'name']);
308 $filter_value = $filter_data[
'value'];
309 $match_type = $filter_data[
'match_type'];
310 $match_case = $filter_data[
'match_case'];
313 if ($match_type ==
'regex' && !empty($filter_value)) {
314 $valid_regex = @preg_match(
'/'.str_replace(
'/',
'\/',$filter_value).
'/',
'test');
315 if ($valid_regex === FALSE) {
316 trigger_localised_error(
'DATA0007', E_USER_WARNING, $filter_value);
321 $updated_filters[] = Array(
322 'name' => $filter_name,
323 'value' => $filter_value,
324 'match_type' => $match_type,
325 'match_case' => $match_case,
330 if (!empty($_POST[$prefix.
'_new_filter_name'])) {
331 $updated_filters[] = Array(
332 'name' => trim($_POST[$prefix.
'_new_filter_name']),
334 'match_type' =>
'contains',
335 'match_case' =>
'ignore_case',
339 return $asset->setAttrValue(
'record_filters', $updated_filters);
355 $result = $asset->getResultSet();
356 return !empty($result);
373 $write_access = $asset->writeAccess(
'attributes');
375 $var_list = $asset->attr(
'dynamic_vars');
379 echo
'<table class="sq-backend-table">';
381 echo
'<th>Name</th>';
382 echo
'<th>Default Value</th>';
384 echo
'<th width="10%" align="right" style="border-left: dotted 1px grey;">Delete</th>';
387 foreach ($var_list as $var => $value) {
388 $var_id = base64_encode($var);
393 text_box($prefix.
'_var_name['.$var_id.
']', $var);
398 echo
'<td valign="top" align="left">';
399 $value = urldecode($value);
401 text_box($prefix.
'_var_value['.$var_id.
']', urlencode($value));
403 echo urlencode($value);
407 echo
'<td style="border-left: dotted 1px grey;">';
408 check_box($prefix.
'_delete_var['.$var_id.
']');
415 echo
'<tr class="new-data-row">';
416 echo
'<th colspan="3" align="left">';
417 echo
'<em style="color:#666">Add New Variables Below</em>';
421 echo
'<tr class="new-data-row">';
423 text_box($prefix.
'_new_dynamic_data_name[]', NULL);
426 text_box($prefix.
'_new_dynamic_data_value[]', NULL);
428 echo
'<td style="border-left: dotted 1px grey;">';
436 $o->sectionNote(translate(
'data_source_variable_section_note'));
440 $o->openSection(
'Data Mappings');
442 $map = $asset->getAttribute(
'parameter_map');
444 $parameter_names = $map->getParameters();
446 foreach ($var_list as $var_name => $default) {
447 $map->setParameter($var_name,
'Variable: '.$var_name);
450 $map->paint($prefix.
'_parameter_map', !$write_access);
453 $o->sectionNote(translate(
'data_source_mappings_section_note'));
455 return $write_access;
472 $var_name_pattern =
'/^[a-zA-Z_\-0-9\.]+$/';
474 $write_access = $asset->writeAccess(
'attributes');
475 if (!$write_access)
return FALSE;
477 $to_delete = array_get_index($_REQUEST, $prefix.
'_delete_var', Array());
478 $var_value = array_get_index($_REQUEST, $prefix.
'_var_value', Array());
479 $var_name = array_get_index($_REQUEST, $prefix.
'_var_name', Array());
481 $var_list = $asset->attr(
'dynamic_vars');
483 $map = $asset->getAttribute(
'parameter_map');
485 $parameter_names = $map->getParameters();
486 foreach ($var_list as $name => $default) {
487 $map->setParameter($name,
'Variable: '.$name);
490 $map->process($prefix.
'_parameter_map');
492 foreach ($var_value as $hash => $value) {
493 $name = base64_decode($hash);
494 if (isset($to_delete[$hash])) {
495 unset($var_list[$name]);
497 if (in_array($name, $parameter_names)) {
498 $map->unsetParameter($name);
503 $value = urldecode($value);
504 $var_list[$name] = urlencode($value);
507 $new_var_list = Array();
508 $rename_success = FALSE;
511 foreach ($var_name as $hash => $new_name) {
512 $new_name = trim($new_name);
514 if (empty($new_name)) {
515 $rename_success = FALSE;
516 trigger_error(
'Variable name cannot be empty. No variables were renamed.', E_USER_NOTICE);
521 $new_name_is_valid = preg_match($var_name_pattern, $new_name);
522 if (!$new_name_is_valid) {
523 $rename_success = FALSE;
524 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);
528 $name = base64_decode($hash);
531 if (!isset($var_list[$name]))
continue;
533 if (isset($new_var_list[$new_name])) {
534 $rename_success = FALSE;
535 trigger_error(
'Could not rename variables because variable name "'.htmlentities($new_name).
'" already exists', E_USER_NOTICE);
539 if ($new_name != $name) {
540 if (in_array($name, $parameter_names)) {
541 $map->moveParameter($name, $new_name);
543 $rename_success = TRUE;
546 $new_var_list[$new_name] = $var_list[$name];
551 if ($rename_success) $var_list = $new_var_list;
553 $new_names = array_get_index($_REQUEST, $prefix.
'_new_dynamic_data_name', Array());
554 if (!empty($new_names)) {
556 foreach ($new_names as $seq_number => $new_var_name) {
557 $new_var_name = trim($new_var_name);
559 $new_var_value = array_get_index($_REQUEST[$prefix.
'_new_dynamic_data_value'], $seq_number,
'');
560 if (empty($new_var_name)) {
561 if (!empty($new_var_value)) {
562 trigger_error(
'New variable name cannot be empty', E_USER_WARNING);
568 $new_name_is_valid = preg_match($var_name_pattern, $new_var_name);
569 if (!$new_name_is_valid) {
570 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);
574 if (isset($var_list[$new_var_name])) {
575 trigger_error(
'Variable Name "'.htmlentities($new_var_name).
'" is already in use', E_USER_WARNING);
578 $new_var_value = urldecode($new_var_value);
579 $var_list[$new_var_name] = urlencode($new_var_value);
580 $map->setParameter($new_var_name,
'Variable: '.$new_var_name);
584 $asset->setAttrValue(
'dynamic_vars', $var_list);
585 $asset->setAttrValue(
'parameter_map', unserialize($map->value));