Esempio n. 1
0
 private function build_coupon_form($coupon = array(), $id = 0)
 {
     $this->load->model('store/shipping_model');
     $this->load->model('store/products_model');
     $this->load->model('billing/subscription_plan_model');
     // Get the required options
     $coupon_products = isset($coupon['products']) ? $coupon['products'] : array();
     $coupon_plans = isset($coupon['plans']) ? $coupon['plans'] : array();
     $coupon_shipping = isset($coupon['shipping']) ? $coupon['shipping'] : array();
     $coupon_types = $this->coupon_model->get_coupon_types();
     foreach ($coupon_types as $type) {
         $type_options[$type->coupon_type_id] = $type->coupon_type_name;
     }
     $reduction_options = array(0 => '%', 1 => setting('currency_symbol'));
     $products = $this->products_model->get_products();
     $product_options = array();
     $product_options['-1'] = 'not available for any products';
     if (is_array($products)) {
         foreach ($products as $product) {
             $product_options[$product['id']] = $product['name'];
         }
     }
     $plans = $this->subscription_plan_model->get_plans();
     $plan_options = array();
     $plan_options['-1'] = 'not available for any subscriptions';
     if (is_array($plans)) {
         foreach ($plans as $plan) {
             $plan_options[$plan['id']] = $plan['name'];
         }
     }
     $shipping = $this->shipping_model->get_rates();
     $shipping_options = array();
     if (is_array($shipping)) {
         foreach ($shipping as $rate) {
             $shipping_options[$rate['id']] = $rate['name'];
         }
     }
     // Build the form
     $this->load->library('admin_form');
     $form = new Admin_form();
     $form->fieldset('Coupon Information');
     $form->hidden('coupon_id', $id);
     $form->text('Coupon Name', 'coupon_name', isset($coupon['coupon_name']) ? $coupon['coupon_name'] : null, 'Something for you to recognize the coupon by.', TRUE);
     $form->text('Coupon Code', 'coupon_code', isset($coupon['coupon_code']) ? $coupon['coupon_code'] : null, 'The code the customer must enter.', TRUE);
     $form->date('Start Date', 'coupon_start_date', isset($coupon['coupon_start_date']) ? $coupon['coupon_start_date'] : null, null, TRUE, FALSE, FALSE, '8em');
     $form->date('Expiry Date', 'coupon_end_date', isset($coupon['coupon_end_date']) ? $coupon['coupon_end_date'] : null, null, TRUE, FALSE, FALSE, '8em');
     $form->text('Maximum Uses', 'coupon_max_uses', (isset($coupon['coupon_max_uses']) and !empty($coupon['coupon_max_uses'])) ? $coupon['coupon_max_uses'] : null, 'The maximum number of customers that can use the coupon.', FALSE, FALSE, FALSE, '6em');
     $form->checkbox('One Per Customer?', 'coupon_customer_limit', '1', isset($coupon['coupon_customer_limit']) && $coupon['coupon_customer_limit'] == 1 ? TRUE : FALSE, 'Check to limit each customer to a single use.');
     $form->dropdown('Coupon Type', 'coupon_type_id', $type_options, isset($coupon['coupon_type_id']) ? $coupon['coupon_type_id'] : FALSE, FALSE, FALSE, FALSE, FALSE, 'coupon_type');
     $form->fieldset('Price Reduction', array('coupon_reduction'));
     $form->dropdown('Reduction Type', 'coupon_reduction_type', $reduction_options, isset($coupon['coupon_reduction_type']) ? $coupon['coupon_reduction_type'] : FALSE);
     $form->text('Reduction Amount', 'coupon_reduction_amt', isset($coupon['coupon_reduction_amt']) ? $coupon['coupon_reduction_amt'] : null, 'The amount of the discount.', FALSE, FALSE, FALSE, '6em');
     $form->dropdown('Products', 'products[]', $product_options, $coupon_products, TRUE, FALSE, 'Leave all unselected to make available for all products.');
     $form->dropdown('Subscription Plans', 'plans[]', $plan_options, $coupon_plans, TRUE, FALSE, 'Leave all unselected to make available for all subscriptions.');
     $form->fieldset('Free Trial', array('coupon_trial'));
     $form->text('Free Trial Length', 'coupon_trial_length', isset($coupon['coupon_trial_length']) ? $coupon['coupon_trial_length'] : null, null, FALSE, 'in days', FALSE, '6em');
     $form->dropdown('Subscription Plans', 'trial_subs[]', $plan_options, $coupon_plans, TRUE, 'If left blank, will select ALL SUBSCRIPTION PLANS');
     $form->fieldset('Free Shipping', array('coupon_shipping'));
     $form->text('Min. Cart Amount', 'coupon_min_cart_amt', isset($coupon['coupon_min_cart_amt']) ? $coupon['coupon_min_cart_amt'] : null, 'The minimum order amount before the coupon may be used.', FALSE, FALSE, FALSE, '6em');
     $form->dropdown('Shipping Methods', 'ship_rates[]', $shipping_options, $coupon_shipping, TRUE, 'If left blank, will select ALL SHIPPING PLANS');
     return $form;
 }
Esempio n. 2
0
    function copy($id)
    {
        $this->load->model('content_model');
        $content = $this->content_model->get_content($id, TRUE);
        $this->load->model('content_type_model');
        $type = $this->content_type_model->get_content_type($content['type_id']);
        $this->load->library('admin_form');
        if ($type['is_standard'] == TRUE) {
            // we require Title, URL Path, and Topic fields
            $title = new Admin_form();
            $title->fieldset('Standard Page Elements');
            $title->text('Title', 'title', $content['title'], FALSE, TRUE, FALSE, TRUE);
            // if we are using the base_url in the current URL, chances are we want to keep it for future URL's
            if (isset($type['base_url']) and !empty($type['base_url']) and strpos($content['url_path'], $type['base_url']) === 0) {
                $title->hidden('base_url', $type['base_url']);
            }
            $title->text('URL Path', 'url_path', $content['url_path'], 'If you leave this blank, it will be auto-generated from the Title above.', FALSE, 'e.g., /about/contact_us', FALSE, '500px');
            // we will build the rest of the sidebar form with form_builder because we want to use it's cool
            // fieldtypes and better API
            $this->load->model('topic_model');
            $topics = $this->topic_model->get_tiered_topics();
            $options = array();
            foreach ($topics as $data) {
                $options[] = array('name' => $data['name'], 'value' => $data['id']);
            }
            $this->load->library('custom_fields/form_builder');
            $topics = $this->form_builder->add_field('multicheckbox');
            $topics->options($options)->name('topics')->label('Topics');
            $date = $this->form_builder->add_field('datetime')->name('date')->label('Publish Date');
            $end_date = $this->form_builder->add_field('datetime')->name('end_date')->label('Unpublish Date')->value($content['end_date']);
            $status = $this->form_builder->add_field('text')->readonly('readonly')->name('status')->label('Status')->value($content['status']);
            // editing, assign values
            $topics->value($content['topics']);
            //print_r($content['date']);
            $date->value($content['date']);
            $title = $title->display();
            $standard = $this->form_builder->output_admin();
        } else {
            $standard = FALSE;
            $title = FALSE;
        }
        if ($type['is_privileged'] == TRUE) {
            // we require a member group access privileges dropdown
            $this->load->model('users/usergroup_model');
            $groups = $this->usergroup_model->get_usergroups();
            $options = array();
            $options[] = array('name' => 'Public / Any Member Group', 'value' => '0');
            foreach ($groups as $group) {
                $options[] = array('name' => $group['name'], 'value' => $group['id']);
            }
            $this->load->library('custom_fields/form_builder');
            $this->form_builder->reset();
            $privileges = $this->form_builder->add_field('multicheckbox');
            $privileges->name('privileges')->options($options)->default_value(0)->label('Allowed Membership Groups')->help('If a group or groups is selected, this content will require the user be in this group to view it.  This enables you to 
					   charge for subscriptions and products that move the user to this group.')->value($content['privileges']);
            $privileges = $this->form_builder->output_admin();
        } else {
            $privileges = FALSE;
        }
        // handle custom fields
        $this->load->model('custom_fields_model');
        $custom_fieldset = new Admin_form();
        $custom_fields = $this->custom_fields_model->get_custom_fields(array('group' => $type['custom_field_group_id']));
        if (empty($custom_fields)) {
            $custom_fields = FALSE;
        } else {
            $custom_fieldset->fieldset('Custom Product Data');
            $custom_fieldset->custom_fields($custom_fields, $content);
            $custom_fields = $custom_fieldset->display();
        }
        $data = array('title' => $title, 'standard' => $standard, 'privileges' => $privileges, 'custom_fields' => $custom_fields, 'type' => $type, 'form_title' => 'Copy Content', 'form_action' => site_url('admincp/publish/post/new/'), 'invalid' => $this->input->get('invalid') ? TRUE : FALSE, 'errors' => $this->session->flashdata('errors'));
        $this->load->view('create_post', $data);
    }