function submit($name, $value, $echo = true, $title = false, $atype = false, $icon = false)
 {
     global $path_to_root;
     $aspect = '';
     if ($atype === null) {
         $aspect = fallback_mode() ? " aspect='fallback'" : " style='display:none;'";
     } elseif (!is_bool($atype)) {
         // necessary: switch uses '=='
         $aspect = "aspect='{$atype}' ";
         $types = explode(' ', $atype);
         foreach ($types as $type) {
             switch ($type) {
                 case 'selector':
                     $aspect = " aspect='selector' rel = '{$value}'";
                     $value = _("Select");
                     if ($icon === false) {
                         $icon = ICON_SUBMIT;
                     }
                     break;
                 case 'default':
                     if ($icon === false) {
                         $icon = ICON_SUBMIT;
                     }
                     break;
                 case 'cancel':
                     if ($icon === false) {
                         $icon = ICON_ESCAPE;
                     }
                     break;
                 case 'nonajax':
                     $atype = false;
             }
         }
     }
     $iconClass = ThemeBootstrap::fontAwesomeIcon($icon ? $icon : $name);
     $submit_str = "<button class=\"btn btn-default " . ($atype ? 'ajaxsubmit' : 'inputsubmit') . "\" type=\"submit\"" . $aspect . " name=\"{$name}\"  id=\"{$name}\" value=\"{$value}\"" . ($title ? " title='{$title}'" : '') . ">";
     if ($iconClass) {
         $submit_str .= "<i class=\"fa {$iconClass}\"></i>";
     }
     $submit_str .= $value . "</button>\n";
     if ($echo) {
         View::get()->addControl(View::controlFromRenderedString(View::CONTROL_BUTTON, '', $submit_str));
     } else {
         return $submit_str;
     }
 }
 function array_selector($name, $selected_id, $items, $options = null)
 {
     global $Ajax;
     $opts = array('spec_option' => false, 'spec_id' => 0, 'select_submit' => false, 'async' => true, 'default' => '', 'multi' => false, 'height' => false, 'sel_hint' => null, 'disabled' => false);
     // ------ merge options with defaults ----------
     if ($options != null) {
         $opts = array_merge($opts, $options);
     }
     $select_submit = $opts['select_submit'];
     $spec_id = $opts['spec_id'];
     $spec_option = $opts['spec_option'];
     $disabled = $opts['disabled'] ? "disabled" : '';
     $multi = $opts['multi'];
     if ($selected_id == null) {
         $selected_id = get_post($name, $opts['default']);
     }
     if (!is_array($selected_id)) {
         $selected_id = array((string) $selected_id);
     }
     // code is generalized for multiple selection support
     if (isset($_POST['_' . $name . '_update'])) {
         if (!$opts['async']) {
             $Ajax->activate('_page_body');
         } else {
             $Ajax->activate($name);
         }
     }
     // ------ make selector ----------
     $selector = $first_opt = '';
     $first_id = false;
     $found = false;
     // if($name=='SelectStockFromList') display_error($sql);
     foreach ($items as $value => $descr) {
         $sel = '';
         if (in_array((string) $value, $selected_id, true)) {
             $sel = 'selected';
             $found = $value;
         }
         if ($first_id === false) {
             $first_id = $value;
             $first_opt = $descr;
         }
         $selector .= "<option {$sel} value='{$value}'>{$descr}</option>\n";
     }
     if ($first_id !== false) {
         $sel = $found === $first_id || $found === false && $spec_option === false ? "selected='selected'" : '';
         $selector = sprintf($first_opt, $sel) . $selector;
     }
     // Prepend special option.
     if ($spec_option !== false) {
         // if special option used - add it
         $first_id = $spec_id;
         $first_opt = $spec_option;
         $sel = $found === false ? 'selected' : '';
         $selector = "<option {$sel} value='{$spec_id}'>{$spec_option}</option>\n" . $selector;
     }
     if ($found === false) {
         $selected_id = array($first_id);
     }
     $_POST[$name] = $multi ? $selected_id : $selected_id[0];
     $selector = "<select autocomplete='off' " . ($multi ? "multiple" : '') . ($opts['height'] !== false ? ' size="' . $opts['height'] . '"' : '') . "{$disabled} name='{$name}" . ($multi ? '[]' : '') . "' class='combo form-control' title='" . $opts['sel_hint'] . "'>" . $selector . "</select>\n";
     $Ajax->addUpdate($name, "_{$name}_sel", $selector);
     $selector = "<span id='_{$name}_sel'>" . $selector . "</span>\n";
     if ($select_submit != false) {
         // if submit on change is used - add select button
         global $_select_button;
         $selector .= sprintf($_select_button, $disabled, user_theme(), fallback_mode() ? '' : 'display:none;', '_' . $name . '_update') . "\n";
     }
     default_focus($name);
     return $selector;
 }