/** * Implementation for the customer meta box */ public static function bottom_customer_meta_box($post, $metabox) { $custom = get_post_custom($post->ID); // fill a new array with the existing values // very annoying conversions, but we could live with that. $meta_array = array(); foreach (self::$fields as $key => $args) { if (!empty($custom[$key]) && is_array($custom[$key])) { $custom_value = $custom[$key][0]; if (is_serialized($custom_value)) { // I don't like the @ either, but sometimes it's just making the output safe. $custom_value = maybe_unserialize($custom_value); if (is_array($custom_value)) { $custom_value = $custom_value[0]; } } $meta_array[$key] = $custom_value; } } $_POST = array_merge($_POST, $meta_array); wp_nonce_field('customer_nonce_save', 'customer_nonce'); ?> <div id="dx-customer-meta-wrapper"> <table class="form-table"> <tbody> <?php foreach (self::$fields as $item => $attributes) { echo DX_Form_Helper::html_element($item, $attributes, 'POST'); } ?> </tbody> </table> </div> <?php }
/** * Add field for displaying customers on the Invoice form * * @param $type field type (text, dx_invoicer_form_field, select, textarea...) * @param $item the item name * @param $attributes array with attributes * @param $method HTTP method where data is stored * @param $section_prefix a prefix for the section, if any * @param $id_prefix a prefix for IDs, if any */ public function add_custom_templates($type, $item, $attributes, $method, $section_prefix, $id_prefix) { if ($type == 'dx_custom_templates') { //extract( $attributes ); extract(array_merge($attributes, DX_Form_Helper::get_element_attributes($item, $attributes, $method))); $label = !empty($label) ? $label : ""; $type = !empty($type) ? $type : ""; $name = !empty($name) ? $name : ""; $value = !empty($value) ? $value : ""; $text = !empty($text) ? $text : ""; $id = !empty($id) ? $id : ""; $class = !empty($class) ? $class : ""; $style = !empty($style) ? $style : ""; $desc = !empty($desc) ? $desc : ""; $initial_rows = 0; $current_user_id = get_current_user_id(); $files = DX_INV_DIR . "/templates"; $dir = ""; $pred = scandir($files); foreach ($pred as $key => $rowvalue) { if (!in_array($rowvalue, array(".", ".."))) { if (is_dir($dir . DIRECTORY_SEPARATOR . $rowvalue)) { $result[$rowvalue] = dirToArray($dir . DIRECTORY_SEPARATOR . $rowvalue); } else { $result[] = $rowvalue; } } } ob_start(); ?> <tr> <th scope="row"> <label for="<?php echo $id_prefix . $id; ?> "><?php echo $text; ?> </label> </th> <td><select name="<?php echo $name; ?> " id="<?php echo $id_prefix . $id; ?> " <?php echo $type == 'multiselect' ? 'multiple="multiple"' : ''; ?> > <option id="dx_empty_customer" value=""><?php _e('Pick an existing template', 'dxinvoice'); ?> </option> <?php foreach ($result as $singlefile) { ?> <option value="<?php echo $singlefile; ?> " <?php selected($singlefile, $value); ?> ><?php echo $singlefile; ?> </option> <?php } ?> </select><br /> <span class="description"><?php echo __('Add template if not exist.', 'dxinvoice'); ?> </span> </td> </tr> <?php $output = ob_get_clean(); echo apply_filters('dx_invoice_filter_invoices_table', $output); } }
/** * Implementation for the arguments meta box */ public static function bottom_invoice_meta_box($post, $metabox) { $custom = get_post_custom($post->ID); // fill a new array with the existing values // very annoying conversions, but we could live with that. $meta_array = array(); foreach (self::$fields as $key => $args) { if (!empty($custom[$key]) && is_array($custom[$key])) { $custom_value = $custom[$key][0]; if (is_serialized($custom_value)) { // I don't like the @ either, but sometimes it's just making the output safe. $custom_value = maybe_unserialize($custom_value); if (is_array($custom_value)) { $custom_value = $custom_value[0]; } } $meta_array[$key] = $custom_value; } else { if ($key == '_invoice_number') { $invoice_title = get_option('dx_invoice_options'); $increment = !empty($invoice_title['increment']) ? $invoice_title['increment'] : 1; $meta_array[$key] = !empty($invoice_title['invoice_num']) ? $invoice_title['invoice_num'] + $increment : 1; // Check existing $my_query = new WP_Query(array('post_type' => DX_INV_POST_TYPE, 'post__not_in' => array($post->ID), 'meta_query' => array(array('key' => '_invoice_number', 'value' => $meta_array[$key])))); if (count($my_query->posts) != 0) { global $wpdb; $query = "SELECT max(meta_value) FROM wp_postmeta WHERE meta_key='_invoice_number'"; $the_max = $wpdb->get_var($query); $meta_array[$key] = $the_max + $increment; } } } } $_POST = array_merge($_POST, $meta_array); wp_nonce_field('invoice_nonce_save', 'invoice_nonce'); ?> <div id="dx-invoice-meta-wrapper"> <table class="form-table"> <tbody> <?php foreach (self::$fields as $item => $attributes) { echo DX_Form_Helper::html_element($item, $attributes, 'POST'); } ?> </tbody> </table> </div> <?php }