public static function display_extras($options) { $owner_id = isset($options['owner_id']) && $options['owner_id'] ? (int) $options['owner_id'] : false; $owner_table = isset($options['owner_table']) && $options['owner_table'] ? $options['owner_table'] : false; $layout = isset($options['layout']) && $options['layout'] ? $options['layout'] : false; $allow_new = true; if (isset($options['allow_new']) && !$options['allow_new']) { $allow_new = false; } $allow_edit = !isset($options['allow_edit']) || isset($options['allow_edit']) && $options['allow_edit']; if (!module_security::is_page_editable()) { $allow_edit = false; } // todo ^^ flow this permission check through to the "save" section. $html = ''; if ($owner_table) { $default_fields = self::get_defaults($owner_table); // we have all that we need to display some extras!! yey!! if ($owner_id) { $extra_items = self::get_extras(array('owner_table' => $owner_table, 'owner_id' => $owner_id)); $extra_items = self::sort_extras($extra_items, $default_fields); } else { $extra_items = array(); } foreach ($extra_items as $extra_item) { $extra_id = $extra_item['extra_id']; $id = 'extra_' . preg_replace('#\\W+#', '_', $extra_item['extra_key']); ob_start(); ?> <tr id="extra_<?php echo $extra_id; ?> "> <th <?php if (module_config::can_i('edit', 'Settings') && self::can_i('edit', 'Extra Fields') && isset($default_fields[$extra_item['extra_key']]['field_type'])) { echo ' data-settings-url="' . module_extra::link_open_extra_default($default_fields[$extra_item['extra_key']]['extra_default_id'], false) . '"'; } ?> > <?php if ($allow_edit) { ?> <span class="extra_field_key" onclick="$(this).hide(); $(this).parent().find('input').show();"><?php echo htmlspecialchars($extra_item['extra_key']); ?> </span> <input type="text" name="extra_<?php echo $owner_table; ?> _field[<?php echo $extra_id; ?> ][key]" value="<?php echo htmlspecialchars($extra_item['extra_key']); ?> " class="extra_field" style="display:none;"> <?php } else { echo htmlspecialchars($extra_item['extra_key']); ?> <input type="hidden" name="extra_<?php echo $owner_table; ?> _field[<?php echo $extra_id; ?> ][key]" value="<?php echo htmlspecialchars($extra_item['extra_key']); ?> "> <?php } ?> </th> <td> <?php if ($allow_edit) { $field_type = 'text'; if (isset($default_fields[$extra_item['extra_key']]['field_type'])) { $field_type = $default_fields[$extra_item['extra_key']]['field_type']; } if (!$field_type) { $field_type = 'text'; } $form_element = array('type' => $field_type, 'name' => 'extra_' . $owner_table . '_field[' . $extra_id . '][val]', 'value' => $extra_item['extra'], 'class' => 'extra_value_input', 'id' => $id); if ($field_type == 'select') { $form_element['options'] = array(); if (isset($default_fields[$extra_item['extra_key']]['options']) && is_array($default_fields[$extra_item['extra_key']]['options']) && isset($default_fields[$extra_item['extra_key']]['options']['select'])) { foreach (explode("\n", $default_fields[$extra_item['extra_key']]['options']['select']) as $val) { $val = trim($val); if ($val === '') { continue; } $form_element['options'][$val] = $val; } } } module_form::generate_form_element($form_element); } else { echo nl2br($extra_item['extra']); } /* <input type="text" name="extra_<?php echo $owner_table;?>_field[<?php echo $extra_id;?>][val]" id="<?php echo $id;?>" class="extra_value_input" value="<?php echo htmlspecialchars($extra_item['extra']);?>"> */ ?> </td> </tr> <?php $html .= ob_get_clean(); } if (module_security::is_page_editable() && $allow_new) { $extra_id = 'new'; ob_start(); // check if there are any "more" fields to add $more_fields_available = $allow_new; //if(!$more_fields_available){ foreach ($default_fields as $default_id => $default) { // check this key islany already existing. foreach ($extra_items as $extra_item) { if ($extra_item['extra_key'] == $default['key']) { unset($default_fields[$default_id]); continue 2; } } $more_fields_available = true; } //} if ($more_fields_available) { ?> <tr id="extra_<?php echo $owner_table; ?> _options_<?php echo $extra_id; ?> " <?php if (!module_config::c('hide_extra', 1)) { ?> style="display:none;"<?php } ?> > <th> </th> <td> <a href="#" onclick="$('#extra_<?php echo $owner_table; ?> _options_<?php echo $extra_id; ?> ').hide();$('#extra_<?php echo $owner_table; ?> _holder_<?php echo $extra_id; ?> ').show(); return false;"><?php _e('more fields »'); ?> </a> </td> </tr> <?php } // more fields available ?> <?php if (count($default_fields) || $allow_new) { ?> <tbody id="extra_<?php echo $owner_table; ?> _holder_<?php echo $extra_id; ?> " <?php if (module_config::c('hide_extra', 1)) { ?> style="display:none;"<?php } ?> > <!-- show all other options here from this $owner_table --> <?php $defaultid = 0; foreach ($default_fields as $default) { $defaultid++; $id = 'extra_' . preg_replace('#\\W+#', '_', $default['key']); ?> <tr> <th> <?php if ($allow_edit) { ?> <span class="extra_field_key" onclick="$(this).hide(); $(this).parent().find('input').show();"><?php echo htmlspecialchars($default['key']); ?> </span> <input type="text" name="extra_<?php echo $owner_table; ?> _field[new<?php echo $defaultid; ?> ][key]" value="<?php echo htmlspecialchars($default['key']); ?> " class="extra_field" style="display:none;"> <?php } else { echo htmlspecialchars($default['key']); ?> <input type="hidden" name="extra_<?php echo $owner_table; ?> _field[new<?php echo $defaultid; ?> ][key]" value="<?php echo htmlspecialchars($default['key']); ?> "> <?php } ?> </th> <td> <?php $field_type = $default['field_type']; if (!$field_type) { $field_type = 'text'; } $form_element = array('type' => $field_type, 'name' => 'extra_' . $owner_table . '_field[new' . $defaultid . '][val]', 'value' => '', 'class' => 'extra_value_input', 'id' => $id); if ($field_type == 'select') { $form_element['options'] = array(); if (isset($default['options']) && is_array($default['options']) && isset($default['options']['select'])) { foreach (explode("\n", $default['options']['select']) as $val) { $val = trim($val); if ($val === '') { continue; } $form_element['options'][$val] = $val; } } } module_form::generate_form_element($form_element); /*<input type="text" name="extra_<?php echo $owner_table;?>_field[new<?php echo $defaultid;?>][val]" id="<?php echo $id;?>" value="<?php ?>">*/ ?> </td> </tr> <?php } ?> <?php if ($allow_new) { ?> <tr id="extra_<?php echo $extra_id; ?> "> <th> <input type="text" name="extra_<?php echo $owner_table; ?> _field[<?php echo $extra_id; ?> ][key]" value="<?php ?> " class="extra_field"> </th> <td> <input type="text" name="extra_<?php echo $owner_table; ?> _field[<?php echo $extra_id; ?> ][val]" value="<?php ?> "> <?php _h('Enter anything you like in this blank field. eg: Passwords, Links, Notes, etc..'); ?> </td> </tr> <?php } ?> </tbody> <?php } // defaults / allow new $html .= ob_get_clean(); } // is page editable } // pass it out for a hook // this is really only used in the security module. if (function_exists('hook_filter_var')) { $html = hook_filter_var('extra_fields_output', $html, $owner_table, $owner_id); } else { $result = hook_handle_callback('extra_fields_output', $html, $owner_table, $owner_id); if ($result && count($result)) { foreach ($result as $r) { $html = $r; // bad. handle multiple hooks. } } } print $html; }
$yn = get_yes_no(); foreach ($extra_defaults as $owner_table => $owner_table_defaults) { foreach ($owner_table_defaults as $owner_table_default) { ?> <tr class="<?php echo $c++ % 2 ? "odd" : "even"; ?> "> <td> <?php echo htmlspecialchars($owner_table); ?> </td> <td class="row_action" nowrap=""> <?php echo module_extra::link_open_extra_default($owner_table_default['extra_default_id'], true); ?> </td> <td> <?php echo isset($visibility_types[$owner_table_default['display_type']]) ? $visibility_types[$owner_table_default['display_type']] : 'N/A'; ?> </td> <td> <?php echo htmlspecialchars($owner_table_default['order']); ?> </td> <td> <?php echo isset($owner_table_default['searchable']) ? htmlspecialchars($yn[$owner_table_default['searchable']]) : '';