Exemple #1
0
    private function parseField($field, $TEMPLATE)
    {
        if (in_array($field['f_sname'], $this->read_only)) {
            $value = $this->obj->__get($field['f_sname']);
            page::assign('value', $value);
            if ($field['f_type'] == 90 || $field['f_type'] == 95 || $field['f_type'] == 105) {
                page::assign('val', $this->obj->__get('_' . $field['f_sname']));
            } else {
                page::assign('val', $value);
            }
            $value = page::parse($TEMPLATE['read_only']);
            page::assign('content', $value);
            return page::parse($TEMPLATE['field_standart']);
        }
        // Определяем значение поля
        if (isset($_SESSION['SAVING_POST']) && ($field['f_type'] < 70 || $field['f_type'] > 85) && isset($_SESSION['SAVING_POST'][$field['f_sname']])) {
            $value = $_SESSION['SAVING_POST'][$field['f_sname']];
        } else {
            if ($field['f_type'] == 105) {
                $value = $this->obj->__get('_' . $field['f_sname']);
            } else {
                $value = $this->obj->__get($field['f_sname']);
            }
        }
        page::assign('field.value', $value);
        // Для страниц, для кнопки "Показать \ скрыть доп. поля"
        if ($this->obj instanceof ormPage && in_array($field['f_sname'], $this->page_fields)) {
            $sh_page = isset($_SESSION['SH_FIELDS']) && $_SESSION['SH_FIELDS'] == 'show' ? '' : ' style="display:none;"';
            page::assign('sh_page', $sh_page);
        } else {
            page::assign('sh_page', '');
        }
        // Специальная обработка данных
        if ($field['f_type'] == 50) {
            page::assign('element', ui::CheckBox($field['f_sname'], 1, $value));
        } else {
            if ($field['f_type'] == 32) {
                if (empty($value) || $value == '0000-00-00 00:00:00') {
                    page::assign('field.date', '');
                    page::assign('field.time', '00:00');
                } else {
                    page::assign('field.date', date('d.m.Y', strtotime($value)));
                    page::assign('field.time', date('H:i', strtotime($value)));
                }
            } else {
                if ($field['f_type'] == 25) {
                    $time = empty($value) || $value == '0000-00-00' ? '' : date('d.m.Y', strtotime($value));
                    page::assign('field.date', $time);
                } else {
                    if ($field['f_type'] == 30) {
                        $time = empty($value) ? '' : date('H:i:s', strtotime($value));
                        page::assign('field.time', $time);
                    } else {
                        if ($field['f_type'] == 70 || $field['f_type'] == 75 || $field['f_type'] == 80 || $field['f_type'] == 85) {
                            if (system::$isAdmin) {
                                page::assign('element', ui::loadFile($field['f_sname'], $value));
                            } else {
                                page::fParse('element', $TEMPLATE['upload_file_field']);
                            }
                        } else {
                            if ($field['f_type'] == 73) {
                                page::assign('element', ui::listFile($field['f_sname'], $value));
                            } else {
                                if ($field['f_type'] == 90 || $field['f_type'] == 95) {
                                    // Выпадающий список или Список со множественным выбором
                                    // Получаем список объектов справочника
                                    page::assign('field.sname', $field['f_sname']);
                                    $data = ormObjects::getObjectsByClass($field['f_list_id']);
                                    $multi = $field['f_type'] == 95 ? 'selectbox_multi' : 'selectbox_template';
                                    $empty = !$field['f_required'] ? '&nbsp;' : '';
                                    if (system::$isAdmin) {
                                        page::assign('element', ui::SelectBox($field['f_sname'], $data, $value, 400, $empty, '', $multi));
                                        if ($field['f_quick_add']) {
                                            page::fParse('plus', $TEMPLATE['field_' . $field['f_type'] . '_plus']);
                                        } else {
                                            page::assign('plus', '');
                                        }
                                    } else {
                                        page::assign('element', ui::SelectBox($field['f_sname'], $data, $value, 200, $empty, '', $multi));
                                    }
                                } else {
                                    if ($field['f_type'] == 97) {
                                        // Подчиненный справочник
                                        // Получаем список объектов справочника
                                        $sel = new ormSelect($field['f_list_id']);
                                        $sel->where('parents', '=', $this->obj->id);
                                        // Выводим мультиформу для добавления и редактирования
                                        $form = new ormMultiForm('subject_list_' . $field['f_id']);
                                        $form->setData($sel);
                                        $form->insideForm();
                                        $re = $form->getHTML();
                                        //  echo $re;
                                        page::assign('element', $re);
                                    } else {
                                        if ($field['f_type'] == 100) {
                                            // Связь с объектом
                                            page::assign('element', ui::objectLinks($this->obj, $field['f_id']));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        page::assign('field.id', $field['f_id']);
        page::assign('field.name', $field['f_name']);
        page::assign('field.hint', $field['f_hint']);
        page::assign('field.sname', $field['f_sname']);
        page::fParse('field.dotted', !empty($field['f_hint']) ? 'dotted' : '');
        if (empty($field['f_max_size'])) {
            $field['f_max_size'] = $field['f_type'] == 60 ? 200 : 100;
        }
        page::assign('field.max_size', $field['f_max_size']);
        // Генерируем яву (создаем правила проверки для элементов формы)
        if ($field['f_required'] && ($field['f_type'] == 35 && $this->obj->id == '' || $field['f_type'] != 35)) {
            $msg = str_replace('%title%', $field['f_name'], lang::get('CONSTR_BASE_FIELD_E2'));
            if ($field['f_type'] == 60) {
                // HTML - редактор
                $this->addit_function .= page::parse('
  					function checkValue%field.sname%(){
  					 	var value = CKEDITOR.instances["%field.sname%"].getData();
    					return (value != "") ? true : [[ "cke_%field.sname%", "' . $msg . '" ]];
					}
  				');
                $this->java .= page::parse('rules.push("function,checkValue%field.sname%");');
            } else {
                if ($field['f_type'] == 100) {
                    // Выбор объекта
                    $this->addit_function .= page::parse('
  					function checkObjectLinks%field.sname%(){
  						var count = $("#objectsLinkList_%field.sname% > li").length;
    					return (count > 0) ? true : [[ %field.sname%, "' . $msg . '" ]];
					}
  				');
                    $this->java .= page::parse('rules.push("function,checkObjectLinks%field.sname%");');
                } else {
                    if ($field['f_type'] == 32) {
                        // Каледарь и время
                        $this->java .= page::parse('rules.push("required,%field.sname%_date,' . $msg . '");');
                    } else {
                        $this->java .= page::parse('rules.push("required,%field.sname%,' . $msg . '");');
                    }
                }
            }
            $zvezd = 'chek';
        } else {
            $zvezd = '';
        }
        page::assign('field.zvezd', $zvezd);
        if ($field['f_type'] == 15) {
            $this->java .= page::parse('rules.push("valid_email,%field.sname%,' . lang::get('CONSTR_BASE_FIELD_E3') . '");');
        }
        if ($field['f_type'] == 20) {
            $this->java .= page::parse('rules.push("reg_exp,%field.sname%,^(((f|ht){1}tp:/)*/[-a-zA-Z0-9@:%_\\+.~#?&//=]+)*$|^\\/{1}, ' . lang::get('CONSTR_BASE_FIELD_E4') . '");');
        }
        if ($field['f_type'] == 40) {
            $this->java .= page::parse('rules.push("digits_only,%field.sname%,' . lang::get('CONSTR_BASE_FIELD_E6') . '");');
        }
        if ($field['f_type'] == 45) {
            $this->java .= page::parse('rules.push("float_only,%field.sname%,' . lang::get('CONSTR_BASE_FIELD_E7') . '");');
        }
        if ($field['f_type'] == 47) {
            $this->java .= page::parse('rules.push("price_only,%field.sname%,' . lang::get('CONSTR_BASE_FIELD_E8') . '");');
        }
        if (isset($TEMPLATE['field_' . $field['f_type']])) {
            return page::parse($TEMPLATE['field_' . $field['f_type']]);
        } else {
            return str_replace('%title%', $field['f_sname'], lang::get('CONSTR_BASE_FIELD_E5'));
        }
    }