Exemplo n.º 1
0
    protected function displayMassSeoSearchForm()
    {
        $id_search = Tools::getValue('id_search');
        $search = AdvancedSearchClass::getSearch($id_search, false, false);
        $criterions_groups_indexed = AdvancedSearchClass::getCriterionsGroupsIndexedForSEO($id_search, $this->_cookie->id_lang);
        $this->_startForm(array('id' => 'seoMassSearchForm'));
        $this->_displayTitle($this->l('Massive add of products pages'));
        $this->_showInfo($this->l('Select your criteria'));
        $this->_html .= '<div id="seoSearchPanelCriteriaTabs">
   		 <ul>';
        foreach ($criterions_groups_indexed as $key => $criterions_group_indexed) {
            $this->_html .= '<li><a href="#seoSearchPanelCriteriaTabs-' . $key . '">' . htmlentities($criterions_group_indexed['name'], ENT_COMPAT, 'UTF-8') . '</a></li>';
        }
        $this->_html .= '</ul>';
        foreach ($criterions_groups_indexed as $key => $criterions_group_indexed) {
            $this->_html .= '<div id="seoSearchPanelCriteriaTabs-' . $key . '" class="seoSearchPanelCriteriaTabsContent" style="height:150px;overflow:auto;text-align:left;">';
            $this->_html .= '<input type="hidden" name="id_criterion_group" value="' . (int) $criterions_group_indexed['id_criterion_group'] . '" style="margin-left:4px;" /><input type="checkbox" value="0" style="margin-left:4px;" onclick="enableAllCriterion4MassSeo(this);" /> &nbsp; <small>' . $this->l('Check all') . '</small><br /><br />';
            $this->_html .= '<ul class="ui-helper-reset ui-sortable">';
            if ($criterions_group_indexed['range'] == 1) {
                if ($criterions_group_indexed['criterion_group_type'] == 'price') {
                    $default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
                    $criterions_group_indexed['range_sign'] = $default_currency->sign;
                    $rangeSignLeft = $default_currency->getSign('left');
                    $rangeSignRight = $default_currency->getSign('right');
                } else {
                    $rangeSignLeft = '';
                    $rangeSignRight = ' ' . $criterions_group_indexed['range_sign'];
                }
                $ranges = explode(',', $criterions_group_indexed['range_interval']);
                $criterions = array();
                foreach ($ranges as $krange => $range) {
                    $rangeUp = isset($ranges[$krange + 1]) ? $ranges[$krange + 1] : '';
                    $range1 = $range . '-' . $rangeUp;
                    $range2 = ($rangeUp ? $this->l('From') : $this->l('More than')) . ' ' . $rangeSignLeft . $range . $rangeSignRight . ($rangeUp ? ' ' . $this->l('to') . ' ' . $rangeSignLeft . $rangeUp . $rangeSignRight : '');
                    $selected_criteria_groups_type = AdvancedSearchClass::getCriterionGroupsTypeAndDisplay($id_search, array($criterions_group_indexed['id_criterion_group']));
                    $criterions[] = array('id_criterion' => $range1, 'value' => $range2);
                }
                if ($criterions && sizeof($criterions)) {
                    foreach ($criterions as $row) {
                        $this->_html .= '<li class="ui-state-default massSeoSearchCriterion" id="criterion_' . $criterions_group_indexed['id_criterion_group'] . '_' . $row['id_criterion'] . '" title="' . htmlentities($row['value'], ENT_COMPAT, 'UTF-8') . '" onclick="enableCriterion4MassSeo(this);">';
                        $this->_html .= '<input type="checkbox" name="criteria[' . (int) $criterions_group_indexed['id_criterion_group'] . '][]" value="' . $criterions_group_indexed['id_criterion_group'] . '_' . $row['id_criterion'] . '" onclick="enableCriterion4MassSeo($jqPm( this ).parent(\'li\'));" /> &nbsp; ';
                        $this->_html .= htmlentities($row['value'], ENT_COMPAT, 'UTF-8');
                        $this->_html .= '</li>';
                    }
                }
            } elseif ($criterions_group_indexed['criterion_group_type'] == 'price') {
                $default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
                $price_range = AdvancedSearchClass::getPriceRangeForSearchBloc($search[0], $criterions_group_indexed['id_criterion_group_linked'], (int) $default_currency->id, $this->getCurrentCustomerGroupId(), 0, $count_product = false, $selected_criterion = array(), $selected_criteria_groups_type = array());
                $this->_html .= '<li class="ui-state-default massSeoSearchCriterion massSeoSearchCriterionPrice" id="criterion_price' . (isset($price_range[0]['min_price']) ? '-' . (int) $price_range[0]['min_price'] . '-' . (int) $price_range[0]['max_price'] : '') . '" title="' . $this->l('From') . ' ' . (int) $price_range[0]['min_price'] . ' ' . $this->l('to') . ' ' . Tools::displayPrice((int) $price_range[0]['max_price'], $default_currency) . '"  onclick="enableCriterion4MassSeo(this);" style="height:50px;">';
                $this->_html .= '<input type="checkbox" id="massSeoSearchCriterionPriceInput" name="criteria[' . (int) $criterions_group_indexed['id_criterion_group'] . '][]" value="' . $criterions_group_indexed['id_criterion_group'] . '_' . (isset($price_range[0]['min_price']) ? (double) $price_range[0]['min_price'] . '-' . (double) $price_range[0]['max_price'] : '') . '" onclick="enableCriterion4MassSeo($jqPm( this ).parent(\'li\'));" /> &nbsp; ';
                $this->_html .= $this->l('Choose your price range bellow : ') . '<br />';
                $this->_html .= '<div id="PM_ASSeoPriceRange" style="width:30%;margin-left:10px;margin-top:10px;float:left"></div>';
                $this->_html .= '<span id="PM_ASPriceRangeValue" style="width:35%;display:block;margin-top:10px;float:left;font-size:11px;margin-left:10px;">' . (int) $price_range[0]['min_price'] . ' - ' . Tools::displayPrice((int) $price_range[0]['max_price'], $default_currency) . '</span>';
                $this->_html .= '<select id="id_currency" name="id_currency" style="float:left;margin-left:10px;width:50px;margin-top:10px;">';
                foreach (Currency::getCurrencies() as $row) {
                    $this->_html .= '<option value="' . (int) $row['id_currency'] . '" ' . ($default_currency->id == $row['id_currency'] ? 'selected="selected"' : '') . '>' . $row['sign'] . '</option>';
                }
                $this->_html .= '</select>';
                $this->_html .= '<script type="text/javascript">
            $jqPm( "#id_currency" ).change(function() {
              var id_currency = $jqPm(this).val();
              $jqPm.ajax( {
                type : "GET",
                url : "' . $this->_base_config_url . '&pm_load_function=displaySeoPriceSlider&id_search=' . (int) $criterions_group_indexed['id_search'] . '&id_criterion_group_linked=' . (int) $criterions_group_indexed['id_criterion_group_linked'] . '&id_currency="+id_currency,
                dataType : "script"
              });
            });
            $jqPm( "#PM_ASSeoPriceRange" ).slider({
              range: true,
              min: ' . (int) $price_range[0]['min_price'] . ',
              max: ' . (int) $price_range[0]['max_price'] . ',
                values: [ ' . (int) $price_range[0]['min_price'] . ', ' . (int) $price_range[0]['max_price'] . ' ],
              slide: function( event, ui) {
                $jqPm( "#PM_ASPriceRangeValue" ).html( "" + ui.values[0] + " - " + "' . $default_currency->getSign('left') . '" + ui.values[1] + "' . $default_currency->getSign('right') . '" );
                $jqPm( "#massSeoSearchCriterionPriceInput" ).val(' . $criterions_group_indexed['id_criterion_group'] . ' + "_" + ui.values[ 0 ] + "-" + ui.values[ 1 ] );
                $jqPm( ".seoSearchCriterionPriceSortable" ).attr("id", "criterion_price-" + ui.values[ 0 ] + "-" + ui.values[ 1 ] );
                $jqPm( ".seoSearchCriterionPriceSortable" ).attr("title", "' . $this->l('From') . ' " + ui.values[ 0 ] + " ' . $this->l('to') . ' " + "' . $default_currency->getSign('left') . '" + ui.values[1] + "' . $default_currency->getSign('right') . '" );
              }
            });
          </script>';
                $this->_html .= '</li>';
            } elseif ($criterions_group_indexed['display_type'] == 5) {
                $range = AdvancedSearchClass::getCriterionsRange($search[0], $criterions_group_indexed['id_criterion_group'], $this->_cookie->id_lang, false, array(), array(), false, false, false, $criterions_group_indexed);
                $this->_html .= '<li class="ui-state-default massSeoSearchCriterion seoSearchCriterionRangeSortable' . $criterions_group_indexed['id_criterion_group'] . '" id="criterion_' . (int) $criterions_group_indexed['id_criterion_group'] . '_' . (double) $range[0]['min'] . '-' . (double) $range[0]['max'] . '" title="' . $this->l('From') . ' ' . (double) $range[0]['min'] . ' ' . $this->l('to') . ' ' . (double) $range[0]['max'] . ' (' . $criterions_group_indexed['range_sign'] . ')"  onclick="enableCriterion4MassSeo(this);" style="height:50px;">';
                $this->_html .= '<input type="checkbox" id="massSeoSearchCriterionRangeInput' . (int) $criterions_group_indexed['id_criterion_group'] . '" name="criteria[' . (int) $criterions_group_indexed['id_criterion_group'] . '][]" value="' . $criterions_group_indexed['id_criterion_group'] . '_' . (int) $criterions_group_indexed['id_criterion_group'] . '_' . (double) $range[0]['min'] . '-' . (double) $range[0]['max'] . '" onclick="enableCriterion4MassSeo($jqPm( this ).parent(\'li\'));" /> &nbsp; ';
                $this->_html .= $this->l('Choose your range bellow : ') . '<br />';
                $this->_html .= '<div id="PM_ASSeoRange' . $criterions_group_indexed['id_criterion_group'] . '" style="width:30%;margin-left:10px;float:left"></div>';
                $this->_html .= '<span id="PM_ASRangeValue' . $criterions_group_indexed['id_criterion_group'] . '" style="width:35%;display:block;float:left;font-size:11px;margin-left:10px;">' . (double) $range[0]['min'] . ' - ' . (double) $range[0]['max'] . ' (' . $criterions_group_indexed['range_sign'] . ')</span>';
                $this->_html .= '<script type="text/javascript">
				$jqPm( "#PM_ASSeoRange' . $criterions_group_indexed['id_criterion_group'] . '" ).slider({
				range: true,
				min: ' . (double) $range[0]['min'] . ',
				max: ' . (double) $range[0]['max'] . ',
				values: [ ' . (double) $range[0]['min'] . ', ' . (double) $range[0]['max'] . ' ],
				slide: function( event, ui) {
				$jqPm( "#PM_ASRangeValue' . $criterions_group_indexed['id_criterion_group'] . '" ).html( "" + ui.values[ 0 ] + " - " + ui.values[ 1 ]  + " (' . $criterions_group_indexed['range_sign'] . ')" );
				$jqPm( "#massSeoSearchCriterionRangeInput' . (int) $criterions_group_indexed['id_criterion_group'] . '" ).val(' . $criterions_group_indexed['id_criterion_group'] . ' + "_" + ui.values[ 0 ] + "-" + ui.values[ 1 ] );
				$jqPm( ".seoSearchCriterionRangeSortable' . $criterions_group_indexed['id_criterion_group'] . '" ).attr("id", "criterion_' . $criterions_group_indexed['id_criterion_group'] . '_" + ui.values[ 0 ] + "-" + ui.values[ 1 ] );
				$jqPm( ".seoSearchCriterionRangeSortable' . $criterions_group_indexed['id_criterion_group'] . '" ).attr("title", "' . $this->l('From') . ' " + ui.values[ 0 ] + " ' . $this->l('to') . ' " + ui.values[ 1 ] + " (' . $criterions_group_indexed['range_sign'] . ')" );
			}
			});
			</script>';
                $this->_html .= '</li>';
            } else {
                $criterions = AdvancedSearchClass::getCriterionsFromCriterionGroup($criterions_group_indexed['criterion_group_type'], $criterions_group_indexed['id_criterion_group_linked'], $criterions_group_indexed['id_search'], $criterions_group_indexed['sort_by'], $criterions_group_indexed['sort_way'], $this->_cookie->id_lang);
                if ($criterions && sizeof($criterions)) {
                    foreach ($criterions as $row) {
                        $this->_html .= '<li class="ui-state-default massSeoSearchCriterion" id="criterion_' . (int) $row['id_criterion'] . '" title="' . htmlentities($row['value'], ENT_COMPAT, 'UTF-8') . '" onclick="enableCriterion4MassSeo(this);">';
                        $this->_html .= '<input type="checkbox" name="criteria[' . (int) $criterions_group_indexed['id_criterion_group'] . '][]" value="' . (int) $criterions_group_indexed['id_criterion_group'] . '_' . (int) $row['id_criterion'] . '" onclick="enableCriterion4MassSeo($jqPm( this ).parent(\'li\'));" /> &nbsp; ';
                        $this->_html .= htmlentities($row['value'], ENT_COMPAT, 'UTF-8');
                        $this->_html .= '</li>';
                    }
                }
            }
            $this->_html .= '</ul></div>';
        }
        $this->_html .= '</div>';
        $this->_showInfo($this->l('Reorder criteria groups for making human reading expressions'));
        $this->_html .= '<div id="seoMassSearchPanelCriteriaGroupsTabs">
    <ul style="width:835px;min-height:50px;" class="ui-helper-reset ui-sortable">';
        foreach ($criterions_groups_indexed as $key => $criterions_group_indexed) {
            $this->_html .= '<li class="ui-state-default seoSearchCriterionSortable ui-state-disabled seoSearchCriterionGroupSortable" id="criterion_group_' . (int) $criterions_group_indexed['id_criterion_group'] . '" style="display:none;"><a href="#seoSearchPanelCriteriaTabs-' . $key . '">' . htmlentities($criterions_group_indexed['name'], ENT_COMPAT, 'UTF-8') . '</a></li>';
        }
        $this->_html .= '</ul></div>
    <input type="hidden" name="id_search" id="id_search" value="' . (int) $id_search . '" />
    <input type="hidden" name="criteria_groups" id="massSeoSearchCriterionGroupsInput" />';
        $this->_pmClear();
        $this->_html .= '<script type="text/javascript">
      var msgMaxCriteriaForMass = "' . $this->l('You can not select more than three groups of criteria') . '";
      var msgNoSeoCriterion = "' . $this->l('You must choose at least one criterion to use this option') . '";
              $jqPm(document).ready(function() {
                  $jqPm("#seoSearchPanelCriteriaTabs").tabs({cache:false});
                  $jqPm("#seoMassSearchPanelCriteriaGroupsTabs ul").sortable({
            items: "li:not(.ui-state-disabled)",
            placeholder: "ui-state-highlight seoSearchCriterionSortable",
            sort: function() {
              $jqPm( this ).removeClass( "ui-state-default" );
            },
                    update: function(event, ui) {
              massSeoSearchCriteriaGroupUpdate();
                  }
          });
        });
          </script>';
        $this->_showInfo($this->l('Then, you can click bellow to automaticaly generate friendly strings and urls'));
        $this->_displaySubmit($this->l('Generate SEO pages'), 'submitMassSeoSearchForm');
        $this->_pmClear();
        $this->_endForm(array('id' => 'seoMassSearchForm'));
    }