Пример #1
0
    function generate_form($id)
    {
        //$this->main_object->init_google_fonts();
        $this->generate_header();
        $message = 'Add slider';
        $admin_url = $this->main_object->admin_url;
        $plugin_url = $this->main_object->url;
        $style2 = array('width' => '140px');
        $style3 = array('width' => '140px', 'margin-left' => '5px !important');
        $new = all_around_visual_elements::generate_button('all_around_add_new_item', 'Add new item', 'black_clear', FALSE, $style2, FALSE);
        $new .= all_around_visual_elements::generate_button('all_around_add_new_from_post', 'Add new from post', 'black_clear', FALSE, $style3, FALSE);
        $new .= all_around_visual_elements::generate_button('all_around_add_new_from_category', 'Add new from category', 'black_clear', FALSE, $style3, TRUE);
        if ($id != 'new') {
            $this->main_object->mvc->load($id);
            $this->main_object->mvc->pre_process_form('all');
            $loaded_items = $this->main_object->mvc->generate_all_sub_items();
            $title_value = $this->main_object->mvc->get_loaded_name();
            $message = 'Edit slider';
        } else {
            $this->main_object->mvc->pre_process_form('all');
            $loaded_items = array();
            $title_value = 'New item';
            //$elements=$this->main_object->mvc->generate_html_form_part('empty_item', 0);
        }
        $status = '<h2 class="all_around_status">' . $message . '<a href="' . $admin_url . '">Cancel</a></h2> <span class="all_around_small_buton" id="all_around_update_notification" style="display: none;"></span>';
        $title = all_around_visual_elements::generate_input('element_name', $title_value, NULL, array('auto_width' => FALSE));
        $ul = all_around_visual_elements::generate_sortable('all_around_sortable', $loaded_items, NULL, 'all_around_primary_sortable');
        $style2 = array('width' => '70px');
        $style_collapsible = array('width' => '280px');
        $buttons = all_around_visual_elements::generate_button('all_around_save_button', 'Save', 'blue', FALSE, $style2, FALSE) . all_around_visual_elements::generate_button('all_around_preview_button', 'Preview', '', FALSE, $style2, TRUE);
        $loader = '<img src="' . $plugin_url . 'images/ajax-loader2.gif" id="all_around_save_loader" style="float: right; margin-right:38px; display: none;">';
        $saved = '<a class="all_around_small_buton" style="float: right; margin-right: 38px; display: none;" id="all_around_save_status">Saved</a>';
        $save = all_around_visual_elements::generate_collapsible('Save' . $saved . $loader, $buttons, $style_collapsible, TRUE);
        $settings_form = $this->main_object->mvc->generate_html_form_part('settings');
        $steps = <<<eod
<h2 class="all_around_status">Step by step:</h2>
<ol class="all_around_steps">
\t<li>
\t\t<h3>Enter some name for this slider, something associative (name will not be shown on page)</h3>
\t</li>
\t<li>
\t\t<h3>Add items</h3>
\t</li>
\t<li>
\t\t<h3>Save it</h3>
\t</li>
\t<li>
\t\t<h3>And go to <a href="{$admin_url}">All Around plugin main page</a></h3>
\t</li>
</ol>
eod;
        $settings_side = $save . $settings_form;
        $element_side = $status . $title . '<br />' . $new . '<br />' . $ul . '<br />' . $steps;
        $view = all_around_visual_elements::generate_form_layout($element_side, $settings_side);
        $hidden = all_around_visual_elements::generate_hidden('element_id', $id);
        $view = all_around_visual_elements::generate_form($hidden . $view, 'form1');
        echo $view;
        $this->close_header();
    }
Пример #2
0
 function generate_html_fields(&$form)
 {
     $html = '';
     foreach ($form as $id => $field) {
         $wrapper = array();
         $style = NULL;
         $class = '';
         $style['auto_width'] = FALSE;
         $generated_html = '';
         if (isset($field['wrapper'])) {
             $wrapper = $field['wrapper'];
         }
         if (isset($field['class'])) {
             $class = $field['class'];
         }
         if (isset($field['if_other_fields'])) {
             foreach ($field['if_other_fields'] as $arr) {
                 //$tarr=explode('_', $field['name']);
                 //$prefix=$tarr[0].'_'.$tarr[1];
                 //$item_number=$tarr[1];
                 $item_number = $this->model->determine_item_number($field['name']);
                 foreach ($arr as $condition => $action) {
                     $condition = explode('=', $condition);
                     $target = $condition[0];
                     $target_value = $condition[1];
                     $action = explode(' ', $action);
                     //if (substr($target,0,7)=='item_*_') $target=$prefix.'_'.substr($target,7);
                     $target_arr =& $this->model->find_target($target, $field['name']);
                     //$this->model->get_field_from_custom_scheme($form, $target);
                     if ($target_arr['value'] == $target_value) {
                         if ($action[0] == 'show_form') {
                             if (substr($action[1], 0, 12) == 'custom_form_') {
                                 $custom_form = intval(substr($action[1], 12));
                                 $generated_html = $this->generate_html_fields($this->model->item_loaded_custom_forms[$item_number][$custom_form]);
                             }
                         }
                     }
                 }
             }
         }
         if (isset($field['not_visible_if'])) {
             foreach ($field['not_visible_if'] as $not_visible_if_array) {
                 //echo '========= '.$not_visible_if_array."<br />";
                 $looking_for_arr = explode('=', $not_visible_if_array);
                 $looking_for = $looking_for_arr[0];
                 $looked_val = $looking_for_arr[1];
                 //echo 'looking_for: '.$looking_for.'<br />'; echo 'looked_val: '.$looked_val.'<br />';
                 if (substr($looking_for, 0, 5) == 'item_') {
                     $looked_arr =& $this->model->find_target($looking_for, $field['name']);
                     if ($looked_arr != NULL) {
                         if ($looked_arr['value'] == $looked_val) {
                             $wrapper['display'] = 'none';
                         }
                     }
                 }
                 if (substr($looking_for, 0, 9) == 'settings_') {
                     //echo 'explain: '.$looking_for." = ".$looked_val."  => ".$this->model->loaded_settings[$looking_for]['value']."<br />";
                     //print_r()
                     if ($this->model->loaded_settings[$looking_for]['value'] == $looked_val) {
                         $wrapper['display'] = 'none';
                     }
                 }
             }
         }
         if (isset($field['if_value'])) {
             $arr = $field['if_value'];
             $events = array();
             foreach ($arr as $value => $expr) {
                 $expr = explode(' ', $expr);
                 $action = $expr[0];
                 $target = $expr[1];
                 $param1 = '';
                 $param2 = '';
                 $tarr = explode('_', $field['name']);
                 $prefix = $tarr[0] . '_' . $tarr[1];
                 if (isset($expr[2])) {
                     $param1 = $expr[2];
                 }
                 if ($action == 'ajax_load_form' && $tarr[0] == 'item') {
                     $param2 = $tarr[1];
                 }
                 if ($tarr[0] == 'item' && substr($target, 0, 7) == 'item_*_') {
                     $target = $prefix . '_' . substr($target, 7);
                 }
                 if ($tarr[0] == 'item' && substr($target, 0, 8) == '.item_*_') {
                     $target = '.' . $prefix . '_' . substr($target, 8);
                 }
                 if ($tarr[0] == 'item' && substr($target, 0, 8) == '#item_*_') {
                     $target = '#' . $prefix . '_' . substr($target, 8);
                 }
                 $target_arr = array('target' => $target, 'param1' => $param1, 'param2' => $param2);
                 $events[$value] = array($action => $target_arr);
             }
             $this->javascript_events[] = array('object' => $field['name'], 'if_value' => $events);
         }
         if (isset($field['style'])) {
             $style = $field['style'];
         }
         if (isset($field['label'])) {
             $wrapper['span'] = $field['label'];
         }
         if (isset($field['group'])) {
             $wrapper['group'] = $field['group'];
             $tarr = explode('_', $field['name']);
             $prefix = $tarr[0] . '_' . $tarr[1];
             if ($tarr[0] == 'item' && substr($field['group'], 0, 7) == 'item_*_') {
                 $wrapper['group'] = $prefix . '_' . substr($wrapper['group'], 7);
             }
         }
         if (isset($field['html_before'])) {
             $html .= $field['html_before'];
         }
         if ($field['type'] == 'image_upload') {
             $default = $this->main_object->url . 'images/no_image.jpg';
             if (isset($field['empty_image'])) {
                 $default = $field['empty_image'];
             }
             $html .= all_around_visual_elements::generate_image($field['name'], $field['value'], $wrapper, $style, $default);
         }
         if ($field['type'] == 'listbox') {
             $html .= all_around_visual_elements::generate_listbox($field['name'], $field['value'], $field['list'], $wrapper, $style);
         }
         if ($field['type'] == 'text') {
             $html .= all_around_visual_elements::generate_textarea($field['name'], $field['value'], $wrapper, $style);
         }
         if ($field['type'] == 'input') {
             $html .= all_around_visual_elements::generate_input($field['name'], $field['value'], $wrapper, $style);
         }
         if ($field['type'] == 'hidden') {
             $html .= all_around_visual_elements::generate_hidden($field['name'], $field['value'], $class);
         }
         if ($field['type'] == 'font') {
             $wrapper2 = $wrapper;
             if ($this->main_object->backend_style == 1) {
                 $wrapper2['margin-bottom'] = '50px';
             }
             if ($this->main_object->backend_style == 2) {
                 $wrapper2['margin-bottom'] = '71px';
             }
             $html .= all_around_visual_elements::generate_button($field['name'] . '_button', $this->convert_font_data_to_label($field['value']), 'black_clear', $wrapper2, $style, FALSE, '', 'all_around_font_button', $field['name']) . all_around_visual_elements::generate_hidden($field['name'], $field['value']);
         }
         if ($field['type'] == 'button') {
             $wrapper2 = $wrapper;
             if ($this->main_object->backend_style == 1) {
                 $wrapper2['margin-bottom'] = '50px';
             }
             if ($this->main_object->backend_style == 2) {
                 $wrapper2['margin-bottom'] = '71px';
             }
             if (isset($field['wrapper'])) {
                 $wrapper2 = $field['wrapper'];
             }
             $html .= all_around_visual_elements::generate_button($field['name'] . '_button', $field['value'], 'black_clear', $wrapper2, $style, TRUE);
         }
         if ($field['type'] == 'color') {
             $html .= all_around_visual_elements::generate_color($field['name'], $field['value'], $wrapper, $style);
         }
         if ($field['type'] == 'checkbox') {
             if (isset($field['without_wrapper_label']) && $field['without_wrapper_label'] == 1 && isset($wrapper['span'])) {
                 unset($wrapper['span']);
                 $wrapper['empty_wrapper'] = 1;
             }
             $html .= all_around_visual_elements::generate_checkbox($field['label'], $field['name'], $field['value'], $wrapper, $style);
         }
         if ($field['type'] == 'number') {
             if (!isset($field['step'])) {
                 $field['step'] = 1;
             }
             $html .= all_around_visual_elements::generate_number($field['name'], $field['value'], $field['min'], $field['max'], $field['unit'], $wrapper, $style, $field['step']);
         }
         if ($field['type'] == 'attached_form') {
             $html .= all_around_visual_elements::generate_div($field['name'], $generated_html, $style);
         }
         if (isset($field['html_after'])) {
             $html .= $field['html_after'];
         }
     }
     return $html;
 }
    function generate_form($id)
    {
        //$this->main_object->init_google_fonts();
        $this->generate_header();
        //echo '<pre>'; print_r ($this->wrapper->get_tags()); echo '</pre>';exit;
        //echo '<pre>'; print_r ($this->wrapper->get_tag_posts(3)); echo '</pre>';exit;
        //echo '<pre>'; print_r($this->wrapper->get_tag_info(3)); echo '</pre>'; exit;
        $message = 'Add slider';
        if (defined('ALL_AROUND_DEMO')) {
            $message = 'Create a slider';
        }
        $admin_url = $this->main_object->admin_url;
        $plugin_url = $this->main_object->url;
        $style3 = array('margin-right' => '5px !important', 'margin-top' => '5px !important');
        $new = all_around_visual_elements::generate_button('all_around_add_new_item', 'Add new item', 'black_clear', FALSE, $style3, FALSE, '', '', '', 0, FALSE);
        $new .= all_around_visual_elements::generate_button('all_around_add_new_from_post', 'Add new from post', 'black_clear', FALSE, $style3, FALSE, '', '', '', 0, FALSE);
        $new .= all_around_visual_elements::generate_button('all_around_add_new_from_category', 'Add new from category', 'black_clear', FALSE, $style3, FALSE, '', '', '', 0, FALSE);
        $new .= all_around_visual_elements::generate_button('all_around_add_new_from_tag', 'Add new from tag', 'black_clear', FALSE, $style3, TRUE, '', '', '', 0, FALSE);
        if ($id != 'new') {
            $this->main_object->mvc->load($id);
            $this->main_object->mvc->pre_process_form('all');
            //echo '<pre>'; print_r($this->main_object->mvc->model->loaded_items[0]['main_link']); echo '</pre>'; exit;
            $loaded_items = $this->main_object->mvc->generate_all_sub_items();
            $title_value = $this->main_object->mvc->get_loaded_name();
            $message = 'Edit slider';
        } else {
            $this->main_object->mvc->pre_process_form('all');
            $loaded_items = array();
            $loaded_items['items'] = array();
            $loaded_items['style'] = array();
            $title_value = 'New slider';
            //$elements=$this->main_object->mvc->generate_html_form_part('empty_item', 0);
        }
        $cancel_url = $admin_url;
        if (defined('ALL_AROUND_DEMO')) {
            $cancel_url = '#';
        }
        $status = '<h2 class="all_around_status">' . $message . '<a href="' . $cancel_url . '">Cancel</a></h2> <span class="all_around_small_buton" id="all_around_update_notification" style="display: none;"></span>';
        $title = all_around_visual_elements::generate_input('element_name', $title_value, NULL, array('auto_width' => FALSE, 'margin-bottom' => '5px'));
        $ul = '';
        $ul = all_around_visual_elements::generate_sortable('all_around_sortable', $loaded_items['items'], NULL, 'all_around_primary_sortable', $loaded_items['style']);
        $style_collapsible = array('width' => '280px');
        $buttons = '';
        if (!defined('ALL_AROUND_DEMO')) {
            $style2 = array('width' => '70px');
            $buttons = all_around_visual_elements::generate_button('all_around_save_button', 'Save', 'blue', FALSE, $style2, FALSE);
            $buttons .= all_around_visual_elements::generate_button('all_around_preview_button', 'Preview', 'center_label', FALSE, $style2, TRUE);
        } else {
            $style2 = array('width' => '120px', 'margin-left' => '55px !important');
            $buttons .= all_around_visual_elements::generate_button('all_around_preview_button', 'Preview', 'blue', FALSE, $style2, TRUE);
        }
        $loader = '<img src="' . $plugin_url . 'images/ajax-loader2.gif" id="all_around_save_loader" style="float: right; margin-right:38px; display: none;">';
        $saved = '<a class="all_around_small_buton" style="float: right; margin-right: 38px; display: none;" id="all_around_save_status">Saved</a>';
        $save_title = 'Save';
        if (defined('ALL_AROUND_DEMO')) {
            $save_title = 'Preview';
        }
        $save = all_around_visual_elements::generate_collapsible($save_title . $saved . $loader, $buttons, $style_collapsible, TRUE);
        $settings_form = $this->main_object->mvc->generate_html_form_part('settings');
        if (!defined('ALL_AROUND_DEMO')) {
            $steps = <<<eod
<h2 class="all_around_status">Step by step:</h2>
<ol class="all_around_steps">
\t<li>
\t\t<h3>Enter some name for this slider, something associative (name will not be shown on page)</h3>
\t</li>
\t<li>
\t\t<h3>Add items</h3>
\t</li>
\t<li>
\t\t<h3>Save it</h3>
\t</li>
\t<li>
\t\t<h3>And go to <a href="{$admin_url}">All Around plugin main page</a></h3>
\t</li>
</ol>
eod;
        } else {
            $steps = <<<eod
<h2 class="all_around_status">Step by step:</h2>
<ol class="all_around_steps">
\t<li>
\t\t<h3>Click on "Add new item" button</h3>
\t</li>
\t<li>
\t\t<h3>Optionally: customize it, or add more items</h3>
\t</li>
\t<li>
\t\t<h3>Click on "Preview" button (in right sidebar)</h3>
\t</li>
</ol>
eod;
        }
        $settings_side = $save . $settings_form;
        $element_side = $status . $title . '<br />' . $new . '<br />' . $ul . '<br />' . $steps;
        $view = all_around_visual_elements::generate_form_layout($element_side, $settings_side);
        $hidden = all_around_visual_elements::generate_hidden('element_id', $id);
        if (defined('ALL_AROUND_DEMO')) {
            $hidden .= all_around_visual_elements::generate_hidden('all_around_demo', 1);
        }
        $view = all_around_visual_elements::generate_form($hidden . $view, 'form1');
        echo $view;
        $this->close_header();
    }