Example #1
0
 /**
  * Writes the html output of the form element
  * 
  * @access protected
  * @return string
  */
 protected function _write_options($key, $val)
 {
     $selected = '';
     $key = (string) $key;
     if (isset($this->value)) {
         if (is_array($this->value)) {
             foreach ($this->value as $s_val) {
                 $s_val = (string) $s_val;
                 if ($key === $s_val) {
                     $selected = ' selected="selected"';
                     break;
                 }
             }
         } else {
             if ($key == $this->value and !$this->_selected_already) {
                 $selected = ' selected="selected"';
                 $this->_selected_already = TRUE;
             }
         }
     }
     return "\t\t<option value=\"" . Form::prep($key) . "\" label=\"" . $val . "\"" . $selected . ">" . Form::prep($val) . "</option>\n";
 }
Example #2
0
 public function select()
 {
     $value = $this->input->get_post('selected', TRUE);
     $filter = rawurldecode($this->input->get_post('filter', TRUE));
     // Convert wild-cards to RegEx
     $filter = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $filter));
     $this->js_controller_params['method'] = 'select';
     $this->load->helper('array');
     $this->load->helper('form');
     $this->load->library('form_builder');
     $pages = $this->fuel->pages->options_list();
     $pdfs = $this->fuel->assets->dir_files('pdf', TRUE);
     if (!empty($pdfs) and !empty($_GET['pdfs'])) {
         $options[lang('page_select_pages')] = array_combine($pages, $pages);
         $options[lang('page_select_pdfs')] = array_combine($pdfs, $pdfs);
     } else {
         $options = array_combine($pages, $pages);
     }
     // apply filter
     if (!empty($filter)) {
         $filter_callback = create_function('$a', 'return preg_match(\'#^' . $filter . '$#\', $a);');
         $options = array_filter($options, $filter_callback);
     }
     // just return the options as json
     $fields['General'] = array('type' => 'fieldset', 'class' => 'tab');
     if (isset($_GET['options'])) {
         if (isset($_GET['format']) and strtolower($_GET['format']) == 'json') {
             json_headers();
             echo json_encode($options);
             return;
         } else {
             $str = '';
             if (isset($_GET['first_option'])) {
                 $first_option = $this->input->get('first_option', TRUE);
                 $str .= "<option value=\"\" label=\"" . Form::prep($first_option, FALSE) . "\">" . Form::prep($first_option, FALSE) . "</option>\n";
             }
             foreach ($options as $key => $val) {
                 $str .= "<option value=\"" . Form::prep($key, FALSE) . "\" label=\"" . Form::prep($val, FALSE) . "\">" . Form::prep($val, FALSE) . "</option>\n";
             }
             echo $str;
             return;
         }
     }
     $select_label = lang('form_label_page');
     $display_label_select = FALSE;
     if (isset($_GET['input'])) {
         $fields['input'] = array('value' => $this->input->get_post('input', TRUE), 'label' => lang('form_label_url'), 'size' => 100);
         $select_label = lang('form_label_or_select');
         $display_label_select = TRUE;
     }
     $fields['url_select'] = array('value' => $this->input->get_post('url_select', TRUE), 'label' => $select_label, 'type' => 'select', 'options' => $options, 'first_option' => lang('label_select_one'), 'display_label' => $display_label_select);
     $fields['Advanced'] = array('type' => 'fieldset', 'class' => 'tab');
     if (isset($_GET['target'])) {
         $target_options = array('' => '', '_blank' => '_blank', '_parent' => '_parent', '_top' => '_top');
         $fields['target'] = array('value' => $this->input->get_post('target', TRUE), 'label' => lang('form_label_target'), 'type' => 'select', 'options' => array('' => '', '_blank' => '_blank'));
         $fields['url_select']['display_label'] = TRUE;
     }
     if (isset($_GET['title'])) {
         $fields['title'] = array('value' => $this->input->get_post('title', TRUE), 'label' => lang('form_label_title'));
         $fields['url_select']['display_label'] = TRUE;
     }
     if (isset($_GET['class'])) {
         $fields['class'] = array('value' => $this->input->get_post('class', TRUE), 'label' => lang('form_label_class'));
         $fields['url_select']['display_label'] = TRUE;
     }
     $fields['selected'] = array('type' => 'hidden', 'value' => $this->input->get_post('selected', TRUE));
     $this->form_builder->submit_value = NULL;
     $this->form_builder->use_form_tag = FALSE;
     $this->form_builder->set_fields($fields);
     $this->form_builder->display_errors = FALSE;
     $vars['form'] = $this->form_builder->render();
     $this->fuel->admin->set_inline(TRUE);
     $crumbs = array('' => $this->module_name, lang('pages_select_action'));
     $this->fuel->admin->set_panel_display('notification', FALSE);
     $this->fuel->admin->set_titlebar($crumbs);
     $this->fuel->admin->render('modal_select', $vars, '', FUEL_FOLDER);
 }