Пример #1
0
 public static function getControl($name, $params = array())
 {
     $control = '';
     $instance = self::getInstance();
     $type = isset($params['type']) ? $params['type'] : false;
     if ($type && ($d = $instance->getDimension($type))) {
         $unit = '';
         if (!isset($params['value'])) {
             $params['value'] = array();
         }
         $params['value'] = array_merge(array('value' => '0', 'unit' => $unit), $params['value']);
         waHtmlControl::addNamespace($params, $name);
         $control .= waHtmlControl::getControl(waHtmlControl::INPUT, 'value', $r = array_merge($params, array('value' => $params['value']['value'])));
         if ($params['options'] = self::getUnits($type)) {
             unset($params['title']);
             $control .= waHtmlControl::getControl(waHtmlControl::SELECT, 'unit', $t = array_merge($params, array('value' => $params['value']['unit'])));
         }
     } else {
         $control .= '—';
     }
     return $control;
 }
    public static function controlReplaceMap($name, $params = array())
    {
        foreach ($params as $field => $param) {
            if (preg_match('/(wrapper|title|description)/', $field)) {
                unset($params[$field]);
            }
        }
        if (!isset($params['value']) || !is_array($params['value'])) {
            $params['value'] = array();
        }
        waHtmlControl::addNamespace($params, $name);
        $columns = array('search' => waHtmlControl::INPUT, 'replace' => waHtmlControl::INPUT, 'is_regexp' => waHtmlControl::CHECKBOX);
        if (!empty($params['value']) && isset($params['value']['search'])) {
            foreach ($params['value']['search'] as $id => $value) {
                if (empty($value)) {
                    foreach ($columns as $column => $type) {
                        if (isset($params['value'][$column][$id])) {
                            unset($params['value'][$column][$id]);
                        }
                    }
                }
            }
        } else {
            $params['value'] = array();
        }
        if (empty($params['value']['search']) || !count($params['value']['search'])) {
            foreach ($columns as $column => $type) {
                $params['value'][$column][] = false;
            }
        }
        $strings = array('search' => _wp('Search for'), 'replace' => _wp('Replace with'), 'regexp' => _wp('Reg Exp<br /> (advanced)'), 'remove' => _wp('Remove the rule'), 'add' => _wp('Add a rule'));
        $control = <<<HTML

<script>
function blog_import_html_control_replace_add(element, eventObject) {
    var row = \$(element).parents('table').find('tbody tr:last');
    if(row){
    \trow = row.clone().insertAfter(row);
    \trow.find(':text').val('');
    \trow.find(':checked').attr('checked',false);
    }
    return false;
}
function blog_import_html_control_replace_remove(element, eventObject) {
var row = \$(element).parents('tr');
    if(\$(element).parents('table').find('tbody tr').length > 1) {
    \trow.remove();
    } else {
    \trow.find(':text').val('');
    \trow.find(':checked').attr('checked',false);
    }
    return false;
}
</script>
<table class="zebra">
\t<thead>
\t\t<tr>
        \t<td>{$strings['search']}</td>
        \t<td>{$strings['replace']}</td>
        \t<td>{$strings['regexp']}</td>
\t\t\t<td>&nbsp;</td>
        </tr>
\t</thead>
\t<tfoot>
\t\t<tr>
\t\t\t<td colspan="4">
\t\t\t\t<a href="#" class="inline-link" onClick="return blog_import_html_control_replace_add(this,event)"><i class="icon16 add"></i><b><i>{$strings['add']}</i></b></a>
\t\t\t</td>
\t\t</tr>
\t</tfoot>
\t<tbody>
HTML;
        foreach ($params['value']['search'] as $id => $value) {
            $control .= "\n\t\t<tr>";
            foreach ($columns as $field => $type) {
                $column_params = $params;
                $column_params['value'] = isset($params['value'][$field][$id]) ? $params['value'][$field][$id] : null;
                waHtmlControl::addNamespace($column_params, $field);
                $control .= "\n\t\t\t<td class='align-center'>" . waHtmlControl::getControl($type, '', $column_params) . "</td>";
            }
            $control .= <<<HTML

\t\t\t<td>
\t\t\t\t<a href="#" class="inline-link" onClick="return blog_import_html_control_replace_remove(this,event)"><i class="icon16 delete" title="{$strings['remove']}"></i></a>
\t\t\t</td>
HTML;
            $control .= "\n\t\t</tr>";
        }
        $control .= '</tbody></table>';
        return $control;
    }
Пример #3
0
    public function settingRedirectControl($name, $params = array())
    {
        $control = '';
        $default_rule = array('pattern' => '', 'regex' => false, 'replacement' => '');
        if (!isset($params['value']) || !is_array($params['value'])) {
            $params['value'] = array();
        }
        $params['value'][] = $default_rule;
        unset($params['options']);
        foreach ($params as $field => $param) {
            if (strpos($field, 'wrapper')) {
                unset($params[$field]);
            }
        }
        waHtmlControl::addNamespace($params, $name);
        $template = <<<HTML
<tr>
    <td>%s</td>
    <td><span class="hint">%s</span></td>
    <td>%s</td>
    <td>&rarr;</td>
    <td>%s</td>
    <td><a href="#/redirect/delete/" class="inline-link js-action"><i class="icon16 delete"></i></a></td>
</tr>
HTML;
        $params = array_merge($params, array('description' => null, 'title_wrapper' => false, 'title' => null));
        $control .= "<table class = \"zebra\">";
        $control .= "<tfoot>";
        $control .= sprintf('<tr><td colspan="6"><a href="#/redirect/add/" class="inline-link js-action"><i class="icon16 add"></i> %s</a></td></tr>', _wp('Add rule'));
        $frontend_urls = $this->getFrontendUrls();
        if (false) {
            $urls = array();
            foreach ($frontend_urls as &$frontend_url) {
                $frontend_url = htmlspecialchars($frontend_url, ENT_QUOTES, waHtmlControl::$default_charset);
                $urls[] = sprintf('<span class="hint">%s</span>', $frontend_url);
                unset($frontend_url);
            }
            $control .= sprintf('<tr><td colspan="6"> %s</td></tr>', implode('<br/>', $urls));
        }
        $control .= "</tfoot>";
        $control .= "<tbody>";
        $redirect_template = '<span class="hint">%s</span>';
        foreach ($params['value'] as $id => $rule) {
            $rule_params = $params;
            waHtmlControl::addNamespace($rule_params, $id);
            $value = isset($params['value'][$id]) ? $params['value'][$id] : $default_rule;
            $pattern = waHtmlControl::getControl(waHtmlControl::INPUT, 'pattern', array_merge($rule_params, array('description' => sprintf('<span class="hint">%s</span>', reset($frontend_urls)), 'value' => ifset($value['pattern'], ''), 'placeholder' => '/auxpage/*/', 'class' => 'long')));
            $regex = waHtmlControl::getControl(waHtmlControl::CHECKBOX, 'regex', array_merge($rule_params, array('title' => 'regex', 'value' => ifset($value['regex']))));
            $redirect = $this->redirectCustom($value['pattern'], true);
            if ($redirect === null) {
                $hint = sprintf($redirect_template, '—');
            } else {
                $hint = sprintf($redirect_template, htmlspecialchars($redirect, ENT_QUOTES, waHtmlControl::$default_charset));
            }
            $replacement = waHtmlControl::getControl(waHtmlControl::INPUT, 'replacement', array_merge($rule_params, array('placeholder' => '/*/', 'value' => ifset($value['replacement'], ''), 'description' => $hint)));
            $control .= sprintf($template, '<i class="icon16 sort"></i>', $regex, $pattern, $replacement);
        }
        $control .= "</tbody>";
        $control .= "</table><script type='text/javascript'>";
        $control .= <<<JS
\$('table.zebra ').sortable({
                distance: 5,
                opacity: 0.75,
                items: '>tbody>tr',
                axis: 'y',
                containment: 'parent',
                handle:'i.sort',
                tolerance: 'pointer'
            });
JS;
        $control .= '</script>';
        return $control;
    }
 /**
  * Формирует HTML-код пользовательского элемента управления с идентификатором 'RegionRatesControl'.
  *
  * @see waHtmlControl::getControl()
  * @param string $name Идентификатор элемента управления
  * @param array $params Параметры элемента управления
  * @return string
  */
 public static function settingRegionRatesControl($name, $params = array())
 {
     foreach ($params as $field => $param) {
         if (strpos($field, 'wrapper')) {
             unset($params[$field]);
         }
     }
     if (empty($params['value']) || !is_array($params['value'])) {
         $params['value'] = array();
     }
     $control = '';
     waHtmlControl::addNamespace($params, $name);
     $rm = new waRegionModel();
     if ($regions = $rm->getByCountry('rus')) {
         $control .= "<table class=\"zebra\"><thead>";
         $control .= "<tr class=\"gridsheader\"><th colspan=\"3\">";
         $control .= htmlentities('Распределите регионы по тарифным поясам Почты России', ENT_QUOTES, 'utf-8');
         $control .= "</th>";
         $control .= "<th>Только авиа</th>";
         $control .= "</th></tr></thead><tbody>";
         $params['control_wrapper'] = '<tr><td>%s</td><td>&rarr;</td><td>%s</td><td>%s</td></tr>';
         $params['title_wrapper'] = '%s';
         $params['description_wrapper'] = '%s';
         $params['options'] = array();
         $params['options'][0] = _wp('*** пояс не выбран ***');
         for ($region = 1; $region <= 5; $region++) {
             $params['options'][$region] = sprintf(_wp('Пояс %d'), $region);
         }
         $avia_params = $params;
         $avia_params['control_wrapper'] = '%2$s';
         $avia_params['description_wrapper'] = false;
         $avia_params['title_wrapper'] = false;
         foreach ($regions as $region) {
             $name = 'zone';
             $id = $region['code'];
             if (empty($params['value'][$id])) {
                 $params['value'][$id] = array();
             }
             $params['value'][$id] = array_merge(array($name => 0, 'avia_only' => false), $params['value'][$id]);
             $region_params = $params;
             waHtmlControl::addNamespace($region_params, $id);
             $avia_params = array('namespace' => $region_params['namespace'], 'control_wrapper' => '%2$s', 'description_wrapper' => false, 'title_wrapper' => false, 'value' => $params['value'][$id]['avia_only']);
             $region_params['value'] = max(0, min(5, $params['value'][$id][$name]));
             $region_params['description'] = waHtmlControl::getControl(waHtmlControl::CHECKBOX, 'avia_only', $avia_params);
             $region_params['title'] = $region['name'];
             if ($region['code']) {
                 $region_params['title'] .= " ({$region['code']})";
             }
             $control .= waHtmlControl::getControl(waHtmlControl::SELECT, 'zone', $region_params);
         }
         $control .= "</tbody>";
         $control .= "</table>";
     } else {
         $control .= 'Для Российской Федерации не указаны регионы. Добавьте хотя бы один регион в настройках стран и регионов.';
     }
     return $control;
 }
Пример #5
0
    public function getCsvmapControl($name, $params = array())
    {
        $targets = ifset($params['options'], array());
        ifset($params['value'], array());
        $html = '';
        if (!empty($params['validate'])) {
            $html .= $this->validateSourceFields($params['validate']);
        }
        $title = _w('CSV columns');
        $description = ifempty($params['description'], _w('Properties'));
        $html .= <<<HTML
<table class="zebra">
  <thead>
    <tr class="white heading small">
        <th>{$title}</th>
        <th>&nbsp;</th>
        <th>{$description}</th>
    </tr>
  </thead>
HTML;
        $default = array('value' => -1, 'title' => '', 'description' => '', 'title_wrapper' => '%s', 'description_wrapper' => '<span class="hint">(%s)</span>', 'control_wrapper' => '
<tr>
    <td>%2$s</td>
    <td>→</td>
    <td>%1$s%3$s</td>
</tr>', 'translate' => false, 'options' => array(-1 => array('value' => -1, 'title' => sprintf('-- %s --', _w('No associated column')), 'style' => 'font-style:italic;')));
        waHtmlControl::addNamespace($params, $name);
        $params = array_merge($params, $default);
        if ($this->header) {
            foreach ($this->header as $id => $column) {
                $params['options'][] = array('value' => $id, 'title' => $column, 'description' => sprintf(_w('CSV columns numbers %s'), implode(', ', explode(':', $id))));
            }
        }
        $group = null;
        while ($target = array_shift($targets)) {
            if (!isset($target['group'])) {
                $target['group'] = array('title' => '');
            } elseif (!is_array($target['group']) && $target['group']) {
                $target['group'] = array('title' => $target['group']);
            }
            $params_target = array_merge($params, array('title' => $target['title'], 'description' => ifset($target['description']), 'control' => ifset($target['control'])));
            if ($target['group'] && !$group || $target['group']['title'] !== $group) {
                if ($group) {
                    $html .= '</tbody>';
                }
                $group = $target['group']['title'];
                $group_name = htmlentities(ifset($target['group']['title'], ' '), ENT_NOQUOTES, waHtmlControl::$default_charset);
                $class = '';
                if (!empty($target['group']['class'])) {
                    $class = sprintf(' class="%s"', htmlentities($target['group']['class'], ENT_QUOTES, waHtmlControl::$default_charset));
                }
                $html .= <<<HTML
<tbody {$class}><tr><th colspan="3">{$group_name}</th></tr>
HTML;
            }
            if (empty($params_target['control'])) {
                self::findSimilar($params_target, null, array('similar' => false));
            }
            $control = waHtmlControl::getControl(waHtmlControl::SELECT, $target['value'], $params_target);
            if (!empty($params_target['control'])) {
                $_type = ifempty($params_target['control']['control'], waHtmlControl::INPUT);
                $_control = waHtmlControl::getControl($_type, $target['value'], ifempty($params_target['control']['params'], array()));
                $control = preg_replace('@</td></tr>$@', $_control, $control) . '</td></tr>';
            }
            $html .= $control;
        }
        if ($group) {
            $html .= '</tbody>';
        }
        $html .= '</table>';
        return $html;
    }