function get_views()
 {
     $wpshop_attribute_links = array();
     $active_nb = wpshop_attributes_set::getElement('', "'moderated','valid'");
     $deleted_nb = wpshop_attributes_set::getElement('', "'deleted'");
     $wpshop_attribute_links['wpshop_attribute_groups_links wpshop_attribute_groups_links_valid' . (empty($_REQUEST['attribute_groups_status']) ? ' current' : '')] = '<a href="' . admin_url('admin.php?page=' . wpshop_attributes_set::getEditionSlug()) . '" >' . __('Attribute groups', 'wpshop') . ' (' . count($active_nb) . ')</a>';
     $wpshop_attribute_links['wpshop_attribute_groups_links wpshop_attribute_groups_links_deleted' . (!empty($_REQUEST['attribute_groups_status']) && $_REQUEST['attribute_groups_status'] == 'deleted' ? ' current' : '')] = '<a href="' . admin_url('admin.php?page=' . wpshop_attributes_set::getEditionSlug() . '&attribute_groups_status=deleted') . '" >' . __('Trashed attribute groups', 'wpshop') . ' (' . count($deleted_nb) . ')</a>';
     return $wpshop_attribute_links;
 }
Exemplo n.º 2
0
 /**
  * Display a form allowing to create an entity from frontend with a shortcode
  * @param array $shortcode_args The different parameters for the shortocde: the field list for the form, different parameters for the entity to create
  */
 public static function wpshop_entities_shortcode($shortcode_args)
 {
     global $wpshop_account, $wpdb;
     $output = $form_content = '';
     if (get_current_user_id() > 0) {
         if (!empty($_POST['quick_entity_add_button'])) {
             $attributes = array();
             foreach ($_POST['attribute'] as $attribute_type => $attribute) {
                 foreach ($attribute as $attribute_code => $attribute_value) {
                     $attributes[$attribute_code] = $attribute_value;
                 }
             }
             $result = wpshop_products::addProduct($_POST['wp_fields']['post_title'], '', $attributes, 'complete');
         }
         if (empty($shortcode_args['attribute_set_id']) || empty($shortcode_args['post_type'])) {
             $output = __('This form page is invalid because no set or type or content is defined. Please contact administrator with this error message', 'wpshop');
         } else {
             $entity_identifier = wpshop_entities::get_entity_identifier_from_code($shortcode_args['post_type']);
             $attribute_set_def = wpshop_attributes_set::getElement($shortcode_args['attribute_set_id'], "'valid'");
             if (empty($entity_identifier) || empty($attribute_set_def) || $entity_identifier != $attribute_set_def->entity_id) {
                 $output = __('This form page is invalid because type and set are not linked. Please contact administrator with this error message', 'wpshop');
             } else {
                 /** Display wordpress fields */
                 foreach (explode(', ', $shortcode_args['fields']) as $field_name) {
                     $label = '';
                     switch ($field_name) {
                         case 'post_title':
                             switch ($shortcode_args['post_type']) {
                                 case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
                                     $label = __('Product title', 'wpshop');
                                     break;
                                 default:
                                     $label = __('Name', 'wpshop');
                                     break;
                             }
                             $field_type = 'text';
                             break;
                         case 'post_thumbnail':
                             switch ($shortcode_args['post_type']) {
                                 case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
                                     $label = __('Product picture', 'wpshop');
                                     break;
                                 default:
                                     $label = __('Default picture', 'wpshop');
                                     break;
                             }
                             $field_type = 'file';
                             break;
                     }
                     if (!empty($label)) {
                         $template_part = 'quick_entity_wp_internal_field_' . $field_type;
                         $tpl_component = array();
                         $tpl_component['WP_FIELD_NAME'] = $field_name;
                         $tpl_component['WP_FIELD_VALUE'] = '';
                         $input = wpshop_display::display_template_element($template_part, $tpl_component);
                         unset($tpl_component);
                         $template_part = 'quick_entity_wp_internal_field_output';
                         $tpl_component = array();
                         $tpl_component['ENTITY_TYPE_TO_CREATE'] = $shortcode_args['post_type'];
                         $tpl_component['WP_FIELD_NAME'] = $field_name;
                         $tpl_component['WP_FIELD_LABEL'] = $label;
                         $tpl_component['WP_FIELD_INPUT'] = $input;
                         $form_content .= wpshop_display::display_template_element($template_part, $tpl_component);
                         unset($tpl_component);
                     }
                 }
                 /** Display attributes fields	*/
                 $query = $wpdb->prepare("\nSELECT ATT.code\nFROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATT\n\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATTR_DET ON ((ATTR_DET.status = 'valid') AND (ATTR_DET.attribute_id = ATT.id) AND (ATTR_DET.entity_type_id = ATT.entity_id))\n\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_GROUP . " AS ATT_GROUP ON ((ATT_GROUP.status = 'valid') AND (ATT_GROUP.attribute_set_id = ATTR_DET.attribute_set_id) AND (ATT_GROUP.id = ATTR_DET.attribute_group_id))\nWHERE ATT.is_used_in_quick_add_form = %s\n\tAND ATT.status= %s\n\tAND ATT.entity_id = %d\n\tAND ATTR_DET.attribute_set_id = %d\nGROUP BY ATT.code\nORDER BY ATT_GROUP.position, ATTR_DET.position", 'yes', 'valid', wpshop_entities::get_entity_identifier_from_code($shortcode_args['post_type']), $shortcode_args['attribute_set_id']);
                 $attribute_for_creation = $wpdb->get_results($query);
                 foreach ($attribute_for_creation as $attribute) {
                     $attr_field = wpshop_attributes::display_attribute($attribute->code, 'frontend');
                     $form_content .= $attr_field['field'];
                 }
                 /**	Check if there are extra parameters	*/
                 if (!empty($shortcode_args['extra_element'])) {
                     $extra_element = explode(', ', $shortcode_args['extra_element']);
                     foreach ($extra_element as $element) {
                         $element_def = explode('!#wps#!', $element);
                         $element_type = $element_def[0];
                         $element_id = $element_def[1];
                         if ($element_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS) {
                             $form_content .= '<div class="wpshop_entity_address_container">';
                             // 								$form_content .= $wpshop_account->display_form_fields($element_id, null, 'not');
                             $form_content .= '</div><div class="wpshop_cls"></div>';
                         }
                     }
                 }
             }
         }
         $template_part = 'quick_entity_add_form';
         $tpl_component = array();
         $tpl_component['ENTITY_TYPE'] = $shortcode_args['post_type'];
         $tpl_component['ENTITY_ATTRIBUTE_SET_ID'] = !empty($shortcode_args['attribute_set_id']) ? $shortcode_args['attribute_set_id'] : 0;
         $tpl_component['NEW_ENTITY_FORM_DETAILS'] = $form_content;
         $tpl_component['ENTITY_QUICK_ADDING_FORM_NONCE'] = wp_create_nonce("wpshop_add_new_entity_ajax_nonce");
         $tpl_component['ENTITY_QUICK_ADD_BUTTON_TEXT'] = __($shortcode_args['button_text'], 'wpshop');
         /*	Ajout de la boite permettant d'ajouter des valeurs aux attributs de type liste deroulante a la volee	*/
         $dialog_title = __('New value', 'wpshop');
         $dialog_identifier = 'new_value_for_entity';
         $dialog_input_identifier = 'wpshop_new_attribute_option_value';
         ob_start();
         include WPSHOP_TEMPLATES_DIR . 'admin/add_new_element_dialog.tpl.php';
         $tpl_component['DIALOG_BOX'] = ob_get_contents();
         ob_end_clean();
         $tpl_component['DIALOG_BOX'] .= '<input type="hidden" name="wpshop_attribute_type_select_code" value="" id="wpshop_attribute_type_select_code" />';
         $tpl_component['DIALOG_BOX'] = '';
         $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'wpshop');
         echo $output;
     } else {
         echo $wpshop_account->display_login_form();
     }
 }
 /**
  * ACCOUNT - Edit account informations data
  */
 function account_informations_form()
 {
     global $wpdb;
     $output = '';
     if (get_current_user_id() != 0) {
         // Customer ID data
         $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
         $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, get_current_user_id());
         $cid = $wpdb->get_var($query);
         $fields_to_output = $signup_fields = array();
         $password_attribute = $signup_form_attributes = array();
         $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
         $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id);
         $customer_entity_id = $wpdb->get_var($query);
         $attributes_set = wpshop_attributes_set::getElement($customer_entity_id);
         $account_attributes = wpshop_attributes_set::getAttributeSetDetails(!empty($attributes_set->id) ? $attributes_set->id : '', "'valid'");
         $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d', $attributes_set->id);
         $customer_attributes_sections = $wpdb->get_results($query);
         foreach ($customer_attributes_sections as $k => $customer_attributes_section) {
             if (!empty($account_attributes[$customer_attributes_section->id])) {
                 foreach ($account_attributes[$customer_attributes_section->id]['attribut'] as $attribute) {
                     $signup_fields[] = $attribute;
                 }
             }
         }
         ob_start();
         require wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_form");
         $output = ob_get_contents();
         ob_end_clean();
     }
     return $output;
 }
Exemplo n.º 4
0
<?php

if (!empty($address_meta) && !empty($address_meta['_wpshop_address_attribute_set_id']) && !empty($address_meta['_wpshop_address_attribute_set_id'][0])) {
    ?>
	<?php 
    $address_attribute_set = wpshop_attributes_set::getElement($address_meta['_wpshop_address_attribute_set_id'][0]);
    ?>
	<a target="_wps_attribute_set_edition_page" href="<?php 
    echo admin_url('admin.php?page=wpshop_attribute_group&action=edit&id=' . $address_attribute_set->id);
    ?>
" ><?php 
    echo $address_attribute_set->name;
    ?>
</a>
<?php 
} else {
    ?>
	<div class="wps-alert-info"><?php 
    _e('No type setted for address', 'wpshop');
    ?>
</div>
<?php 
}
 /**
  * Récupération des groupes et/ou sous-groupes d'attributs pour une entité donnée
  *
  * @param integer $entity_id Identifiant de l'entité dont on veut récupérer la liste des groupes et/ou sous-groupes
  * @param string $table Permet de définir quel est l'élément en cours d'édition
  * @param string $page_code Code de la page courante
  * @param boolean $complete_tree Si ce paramètre est à vrai alors on affiche les sous-groupes, dans le cas contraire on affiche uniquement les groupes
  *
  * @return string Le code html permettant d'afficher la liste des groupes et/ou sous-groupes d'attributs
  */
 public static function get_attribute_set_complete_list($entity_id, $table, $page_code, $complete_tree = true)
 {
     $the_input = __('There is no attribute set for this entity', 'wpshop');
     $attr_set_list = wpshop_attributes_set::getElement($entity_id, "'valid'", 'entity_id', 'all');
     if (!empty($attr_set_list)) {
         $the_input = '<select name="' . $table . '[set_section]" class="wpshop_' . $page_code . '_set_section" >';
         if (!$complete_tree) {
             $the_input .= '<option value="0">' . __('None', 'wpshop') . '</option>';
         }
         foreach ($attr_set_list as $attr_set_index => $attr_set) {
             if (!empty($attr_set->id)) {
                 $attribute_set_details = wpshop_attributes_set::getAttributeSetDetails($attr_set->id, "'valid'");
                 if (!empty($attribute_set_details)) {
                     if ($complete_tree) {
                         $the_input .= '<optgroup label="' . __($attr_set->name, 'wpshop') . '" >';
                         foreach ($attribute_set_details as $set_details) {
                             $selected = $attr_set->default_set == 'yes' && $set_details['is_default_group'] == 'yes' ? ' selected="selected"' : '';
                             $the_input .= '<option' . $selected . ' value="' . $attr_set->id . '_' . $set_details['id'] . '">' . __($set_details['name'], 'wpshop') . '</option>';
                         }
                         $the_input .= '</optgroup>';
                     } else {
                         $the_input .= '<option value="' . $attr_set->id . '">' . __($attr_set->name, 'wpshop') . '</option>';
                     }
                 }
             }
         }
         $the_input .= '</select>';
     }
     return $the_input;
 }