Exemplo n.º 1
0
 /**
  * @return string
  */
 protected function makeWrapper()
 {
     $tpl = new Mtpl($this->theme_location . '/html/form/wrappers/control.html');
     if (!empty($this->attributes['id'])) {
         $label_for = ' for="' . $this->attributes['id'] . '"';
     } else {
         $label_for = '';
     }
     $name = !empty($this->attributes['name']) ? $this->attributes['name'] : '';
     $tpl->assign('[RESOURCE]', $this->resource);
     $tpl->assign('[NAME]', $name);
     $tpl->assign('[LABEL_FOR]', $label_for);
     $tpl->assign('[LABEL]', $this->label);
     if ($this->required) {
         $tpl->touchBlock('req');
     }
     if (!empty($this->out)) {
         $tpl->out->assign('[OUT]', $this->out);
     }
     return $tpl->render();
 }
Exemplo n.º 2
0
 /**
  * Создание таблицы
  * @return void
  */
 protected function make()
 {
     $tpl = new Mtpl($this->theme_location . '/html/table.html');
     $tpl->assign('[TPL_DIR]', $this->theme_src);
     if (!empty($this->search)) {
         $search_value = !empty($this->sessData['search']) ? $this->sessData['search'] : array();
         if (!empty($search_value) && count($search_value)) {
             $tpl->search->clear->assign('[RESOURCE]', $this->resource);
             $tpl->search->clear->assign('[TPL_DIR]', $this->theme_src);
         }
         $tpl->search->assign('[RESOURCE]', $this->resource);
         $tpl->search->assign('[TPL_DIR]', $this->theme_src);
         foreach ($this->search as $key => $search) {
             if ($search instanceof Search) {
                 $control_value = isset($search_value[$key]) ? $search_value[$key] : '';
                 switch ($search->getType()) {
                     case 'text':
                         $tpl->search->field->text->assign("[ID]", "search-{$this->resource}-{$key}");
                         $tpl->search->field->text->assign("[NAME]", "search[{$key}]");
                         $tpl->search->field->text->assign("[VALUE]", $control_value);
                         $tpl->search->field->text->assign("[IN_TEXT]", $search->getIn());
                         break;
                     case 'radio':
                         $data = $search->getData();
                         if (!empty($data)) {
                             $data = array('' => $this->getLocution('All')) + $data;
                             foreach ($data as $radio_value => $radio_title) {
                                 $tpl->search->field->radio->assign("[ID]", "search-{$this->resource}-{$key}");
                                 $tpl->search->field->radio->assign("[NAME]", "search[{$key}]");
                                 $tpl->search->field->radio->assign("[VALUE]", $radio_value);
                                 $tpl->search->field->radio->assign("[TITLE]", $radio_title);
                                 $tpl->search->field->radio->assign("[IN_TEXT]", $search->getIn());
                                 $is_checked = $control_value == $radio_value ? 'checked="checked"' : '';
                                 $tpl->search->field->radio->assign("[IS_CHECKED]", $is_checked);
                                 $tpl->search->field->radio->reassign();
                             }
                         }
                         break;
                     case 'checkbox':
                         $data = $search->getData();
                         if (!empty($data)) {
                             foreach ($data as $checkbox_value => $checkbox_title) {
                                 $tpl->search->field->checkbox->assign("[ID]", "search-{$this->resource}-{$key}");
                                 $tpl->search->field->checkbox->assign("[NAME]", "search[{$key}][]");
                                 $tpl->search->field->checkbox->assign("[VALUE]", $checkbox_value);
                                 $tpl->search->field->checkbox->assign("[TITLE]", $checkbox_title);
                                 $tpl->search->field->checkbox->assign("[IN_TEXT]", $search->getIn());
                                 $is_checked = is_array($control_value) && in_array($checkbox_value, $control_value) ? 'checked="checked"' : '';
                                 $tpl->search->field->checkbox->assign("[IS_CHECKED]", $is_checked);
                                 $tpl->search->field->checkbox->reassign();
                             }
                         }
                         break;
                     case 'date':
                         $tpl->search->field->date->assign("[ID]", "search-{$this->resource}-{$key}");
                         $tpl->search->field->date->assign("[NAME_FROM]", "search[{$key}][0]");
                         $tpl->search->field->date->assign("[NAME_TO]", "search[{$key}][1]");
                         $tpl->search->field->date->assign("[VALUE_FROM]", isset($control_value[0]) ? $control_value[0] : '');
                         $tpl->search->field->date->assign("[VALUE_TO]", isset($control_value[1]) ? $control_value[1] : '');
                         $tpl->search->field->date->assign("[IN_TEXT]", $search->getIn());
                         break;
                     case 'datetime':
                         $tpl->search->field->datetime->assign("[ID]", "search-{$this->resource}-{$key}");
                         $tpl->search->field->datetime->assign("[NAME_FROM]", "search[{$key}][0]");
                         $tpl->search->field->datetime->assign("[NAME_TO]", "search[{$key}][1]");
                         $tpl->search->field->datetime->assign("[VALUE_FROM]", isset($control_value[0]) ? $control_value[0] : '');
                         $tpl->search->field->datetime->assign("[VALUE_TO]", isset($control_value[1]) ? $control_value[1] : '');
                         $tpl->search->field->datetime->assign("[IN_TEXT]", $search->getIn());
                         break;
                     case 'select':
                         $data = $search->getData();
                         $options = array('' => '') + $data;
                         $tpl->search->field->select->assign("[ID]", "search-{$this->resource}-{$key}");
                         $tpl->search->field->select->assign("[NAME]", "search[{$key}]");
                         $tpl->search->field->select->assign("[IN_TEXT]", $search->getIn());
                         $tpl->search->field->select->fillDropDown("[ID]", $options, $control_value);
                         break;
                     case 'multiselect':
                         $data = $search->getData();
                         $tpl->search->field->multiselect->assign("[ID]", "search-{$this->resource}-{$key}");
                         $tpl->search->field->multiselect->assign("[NAME]", "search[{$key}][]");
                         $tpl->search->field->multiselect->assign("[IN_TEXT]", $search->getIn());
                         $tpl->search->field->multiselect->fillDropDown("[ID]", $data, $control_value);
                         break;
                 }
                 $tpl->search->field->assign("[#]", $key);
                 $tpl->search->field->assign("[OUT_TEXT]", $search->getOut());
                 $tpl->search->field->assign('[CAPTION]', $search->getCaption());
                 $tpl->search->field->reassign();
             }
         }
     }
     if ($this->add_url) {
         $tpl->add_button->assign('[URL]', $this->add_url);
     }
     if ($this->show_delete && $this->delete_url != '') {
         $delete_msg = $this->getLocution('Are you sure you want to delete this post?');
         $no_select_msg = $this->getLocution('You must select at least one record');
         $tpl->del_button->assign('[DELETE_ACTION]', "combine.table.del('{$this->resource}', '{$delete_msg}',  '{$no_select_msg}', '{$this->delete_url}')");
     }
     $token = sha1(uniqid());
     $this->session->table->__csrf_token = $token;
     $tpl->assign('[TOKEN]', $token);
     $tpl->assign('[RESOURCE]', $this->resource);
     $tpl->assign('[BUTTONS]', implode('', $this->buttons));
     foreach ($this->columns as $key => $column) {
         if ($column instanceof Column) {
             if ($column->isSorting()) {
                 if (isset($this->sessData['order']) && $this->sessData['order'] == $key + 1) {
                     if ($this->sessData['order_type'] == "ASC") {
                         $tpl->header->cell->sort->order_asc->assign('[SRC]', $this->theme_src . '/img/asc.gif');
                     } elseif ($this->sessData['order_type'] == "DESC") {
                         $tpl->header->cell->sort->order_desc->assign('[SRC]', $this->theme_src . '/img/desc.gif');
                     }
                 }
                 $width = $column->getAttr('width');
                 if ($width) {
                     $tpl->header->cell->sort->assign('<th', "<th width=\"{$width}\"");
                 }
                 $tpl->header->cell->sort->assign('[COLUMN_NUMBER]', $key + 1);
                 $tpl->header->cell->sort->assign('[CAPTION]', $column->getTitle());
             } else {
                 $width = $column->getAttr('width');
                 if ($width) {
                     $tpl->header->cell->no_sort->assign('<th', "<th width=\"{$width}\"");
                 }
                 $tpl->header->cell->no_sort->assign('[CAPTION]', $column->getTitle());
             }
             $tpl->header->cell->reassign();
         }
     }
     if ($this->show_checkboxes == true) {
         $tpl->header->touchBlock('checkboxes');
     }
     $this->fetchData();
     $tpl->assign('[TOTAL_RECORDS]', ($this->round_record_count ? '~' : '') . $this->record_count);
     if (!empty($this->data)) {
         $row_index = 1;
         $row_number = $this->current_page > 1 ? ($this->current_page - 1) * $this->records_per_page + 1 : 1;
         foreach ($this->data as $row) {
             if (!$row instanceof Row) {
                 $row = new Row($row);
             }
             $tpl->row->assign('[ID]', $row->id);
             $tpl->row->assign('[#]', $row_number);
             if ($this->edit_url) {
                 $edit_url = $this->replaceTCOL($row, $this->edit_url);
                 $row->setAppendAttr('class', 'edit-row');
                 if (strpos($edit_url, 'javascript:') === 0) {
                     $row->setAppendAttr('onclick', substr($edit_url, 11));
                 } else {
                     $row->setAppendAttr('onclick', "combine.table.load('{$edit_url}');");
                 }
             }
             foreach ($this->columns as $column) {
                 if ($column instanceof Column) {
                     $cell = $row->{$column->getField()};
                     $value = $cell->getValue();
                     switch ($column->getType()) {
                         case 'text':
                             $tpl->row->col->assign('[VALUE]', htmlspecialchars($value));
                             break;
                         case 'number':
                             $value = strrev($value);
                             $value = (string) preg_replace('/(\\d{3})(?=\\d)(?!\\d*\\.)/', '$1;psbn&', $value);
                             $value = strrev($value);
                             $tpl->row->col->assign('[VALUE]', $value);
                             break;
                         case 'html':
                             $tpl->row->col->assign('[VALUE]', htmlspecialchars_decode($value));
                             break;
                         case 'date':
                             $date = $value ? date($this->date_mask, strtotime($value)) : '';
                             $tpl->row->col->assign('[VALUE]', $date);
                             break;
                         case 'datetime':
                             $date = $value ? date($this->datetime_mask, strtotime($value)) : '';
                             $tpl->row->col->assign('[VALUE]', $date);
                             break;
                         case 'status':
                             if ($value == 'Y' || $value == 1) {
                                 $img = "<img src=\"{$this->theme_src}/img/lightbulb_on.png\" alt=\"[#on#]\" title=\"[#on#]/[#off#]\" data-value=\"{$value}\"/>";
                             } else {
                                 $img = "<img src=\"{$this->theme_src}/img/lightbulb_off.png\" alt=\"[#off#]\" title=\"[#on#]/[#off#]\" data-value=\"{$value}\"/>";
                             }
                             $tpl->row->col->assign('[VALUE]', $img);
                             break;
                     }
                     // Атрибуты ячейки
                     $column_attributes = $cell->getAttribs();
                     $attributes = array();
                     foreach ($column_attributes as $attr => $value) {
                         $attributes[] = "{$attr}=\"{$value}\"";
                     }
                     $implode_attributes = implode(' ', $attributes);
                     $implode_attributes = $implode_attributes ? ' ' . $implode_attributes : '';
                     $tpl->row->col->assign('<td>', "<td{$implode_attributes}>");
                     if (end($this->columns) != $column) {
                         $tpl->row->col->reassign();
                     }
                 }
             }
             $attribs = $row->getAttribs();
             if (!empty($attribs)) {
                 $attribs_string = '';
                 foreach ($attribs as $name => $attr) {
                     $attribs_string .= " {$name}=\"{$attr}\"";
                 }
                 $tpl->row->assign('<tr', '<tr ' . $attribs_string);
             }
             if ($this->show_checkboxes) {
                 $tpl->row->checkboxes->assign('[ID]', $row->id);
                 $tpl->row->checkboxes->assign('[RESOURCE]', $this->resource);
                 $tpl->row->checkboxes->assign('[#]', $row_index);
                 $row_index++;
             }
             $row_number++;
             $tpl->row->reassign();
         }
     } else {
         $tpl->touchBlock('no_rows');
     }
     // Pagination
     $count_pages = ceil($this->record_count / $this->records_per_page);
     $tpl->pages->assign('[CURRENT_PAGE]', $this->current_page);
     $tpl->pages->assign('[COUNT_PAGES]', $count_pages);
     if ($count_pages > 1 || $this->records_per_page > 25) {
         $tpl->pages->touchBlock('gotopage');
         $tpl->pages->touchBlock('per_page');
         if ($this->current_page > 1) {
             $tpl->pages->prev->assign('[PREV_PAGE]', $this->current_page - 1);
         }
         if ($this->current_page < $count_pages) {
             $tpl->pages->next->assign('[NEXT_PAGE]', $this->current_page + 1);
         }
     }
     $tpl->pages->fillDropDown('records-per-page-[RESOURCE]', array('25' => '25', '50' => '50', '100' => '100', '0' => $this->getLocution('All')), $this->records_per_page == 1000000000 ? 0 : $this->records_per_page);
     // Перевод
     if (!empty($this->locutions[$this->lang])) {
         foreach ($this->locutions[$this->lang] as $locution => $translate) {
             $tpl->assign("[#{$locution}#]", $translate);
         }
     }
     $this->HTML .= $tpl->render();
 }
Exemplo n.º 3
0
 /**
  * @return string
  */
 protected function makeControl()
 {
     $tpl = new Mtpl($this->theme_location . '/html/form/controls/upload.html');
     if (!empty($this->files)) {
         foreach ($this->files as $file) {
             if (!empty($file['download_url'])) {
                 $tpl->file->link->assign('[DOWNLOAD_URL]', $file['download_url']);
                 $tpl->file->link->assign('[NAME]', $file['name']);
                 if (!empty($file['size'])) {
                     $tpl->file->link->size->assign('[SIZE_HUMAN]', $this->formatSizeHuman($file['size']));
                 }
             } else {
                 $tpl->file->text->assign('[NAME]', $file['name']);
                 if (!empty($file['size'])) {
                     $tpl->file->text->size->assign('[SIZE_HUMAN]', $this->formatSizeHuman($file['size']));
                 }
             }
             if ($file['preview_url']) {
                 $tpl->file->img->assign('[PREVIEW_URL]', $file['preview_url']);
                 $tpl->file->img->assign('[ALT]', $file['name']);
             }
             $file_type = !empty($file['type']) && strpos($file['type'], 'image') !== false ? 'image' : 'doc';
             $tpl->file->assign('[ID]', $file['id']);
             $tpl->file->assign('[KEY]', uniqid());
             $tpl->file->assign('[TYPE]', $file_type);
             $tpl->file->reassign();
         }
     }
     if (!isset($this->attributes['id'])) {
         $this->attributes['id'] = "control-" . uniqid();
     }
     if ($this->required) {
         $this->attributes['required'] = 'required';
         if ($this->required_message) {
             $this->attributes['data-required-message'] = $this->required_message;
         }
     }
     $attributes = array();
     if (!empty($this->attributes)) {
         foreach ($this->attributes as $attr_name => $value) {
             $attributes[] = "{$attr_name}=\"{$value}\"";
         }
     }
     $is_multiple = $this->file_limit == 0 || $this->file_limit > 1;
     if ($this->size_limit == 0) {
         $this->size_limit = $this->getMaxFileSize();
     }
     if ($is_multiple) {
         $tpl->touchBlock('control_buttons');
     }
     $tpl->assign('[ATTRIBUTES]', implode(' ', $attributes));
     $tpl->assign('[THEME_SRC]', $this->theme_src);
     $tpl->assign('[ID]', $this->attributes['id']);
     $tpl->assign('[NAME]', $this->attributes['name']);
     $tpl->assign('[LANG]', $this->lang);
     $tpl->assign('[ACCEPT]', $this->accept);
     $tpl->assign('[SIZE_LIMIT]', $this->size_limit);
     $tpl->assign('[FILE_LIMIT]', $this->file_limit);
     $tpl->assign('[AUTOSTART]', $this->autostart ? 'true' : 'false');
     $tpl->assign('[MULTIPLE]', $is_multiple ? 'multiple' : '');
     // Перевод
     if (!empty($this->locutions[$this->lang])) {
         foreach ($this->locutions[$this->lang] as $locution => $translate) {
             $tpl->assign("[#{$locution}#]", $translate);
         }
     }
     return $tpl->render();
 }