«Кактус CMS» поможет быстро создать и легко редактировать веб-сайт

Универсальный редактор таблиц

В версии 2.1 "Кактус CMS" разработан универсальный редактор таблиц, который призван облегчить создание админ части модулей. Автор думает, что написание CMS надо было начинать именно с написания такого редактора. Рекомендуется использовать этот редактор в первую очередь, с помощью него реализуется типовой функционал админ модуля.

 

Что умеет редактор?

  • отображать таблицу
  • удалять записи
  • создавать новые
  • редактировать записи
  • имеет всяческие настройки отображения
  • может отображать и редактировать дочерние таблицы
  • даёт возможность написать свои действия и обработчики
  • загружать картинки
  • и всякое прочее, список умений постоянно совершенствуется...

А что просит взамен редактор?

  • опишите откуда брать данные 

 

Вот MySQL табличка, для которой дальше будет пример использования редактора.В таблице `test_cities`находится списокгородов для записей в таблице `test`.

CREATE TABLE IF NOT EXISTS `test` (
`id_test` int(11) NOT NULL auto_increment,
`name` varchar(20) collate cp1251_bin NOT NULL default '',
`surname` varchar(20) collate cp1251_bin NOT NULL default '',
`active` tinyint(1) NOT NULL default '0',
`comment` mediumtext collate cp1251_bin NOT NULL,
`flag` char(1) collate cp1251_bin NOT NULL default '',
`id_city` int(11) NOT NULL default '0',
`photo` varchar(50) collate cp1251_bin NOT NULL default '',
`id_name` int(11) default NULL,
PRIMARY KEY (`id_test`)
) ENGINE=InnoDB

CREATE TABLE IF NOT EXISTS `test_cities` (
`id_city` int(11) NOT NULL auto_increment,
`name` varchar(20) collate cp1251_bin NOT NULL default '',
PRIMARY KEY (`id_city`)
) ENGINE=InnoDB

 

 

Пример кода PHP файла, "admin.php", в нем просто описывается структура таблички

<? $_TITLE = "Test"; include $_SERVER["DOCUMENT_ROOT"]."/admin/header.php";?>
<?
$table_editor = array(
"back_button_url" => "admin.php",
"DEBUG" => 0,
);


$table = array(
"table_name" => "test",
"pk" => "id_test",
"fields" => array(
array(
"field" => "name",
"name" => "Имя",
"type" => "text",
),
array(
"field" => "surname",
"name" => "Фамилия",
"type" => "text",
),
array(
"field" => "active",
"name" => "Включен",
"type" => "checkbox",
),
array(
"field" => "comment",
"name" => "Коментарий",
"type" => "textarea",
),
array(
"field" => "flag",
"name" => "Рост",
"type" => "fixedlist",
"fixedlist" => array(
"1" => "Низкий рост",
"2" => "Ниже среднего",
"3" => "Выше среднего",
"4" => "Высокий",
),
),
array(
"field" => "id_city",
"name" => "Город",
"type" => "join",
"join_table" => "test_cities",
"join_key" => "id_city",
"join_field" => "name",
),
array(
"field" => "photo",
"name" => "Фото",
"type" => "file",
"upload_dir" => "modules/test/images",
"display_image" => true,
),
array(
"field" => "id_name",
"name" => "Языковая строчка",
"type" => "langvalue",
),
),
"order_by" => "name",
);

include $_SERVER["DOCUMENT_ROOT"]."/admin/table_editor.php";

?>
<? include $_SERVER["DOCUMENT_ROOT"]."/admin/footer.php";?>

 

И вот что вышло. Отображение данных.

 

Форма редактирования записи, с выбором файла, выбором значения из другой таблички и т.д.

 

 

 

 

Описание всех возможных полей и их значений.
 

$table_editor = array(
"back_button_url" => "admin.php", // URL для стрелки назад
"hide_table_on_edit" => true, //hide table with data when editing or inserting
"hide_table" => true, //hide table, used for direct insertion of table editor
"edittable_width" => 450, //width for editing table
"icons_prefix" => "/modules/struct", //if you want to use custom images placed somewhere else
"disable_edit" => true, //disable editing of rows
"disable_delete" => false //disbale deleting rows
"disable_insert" => true, //disables insert icon
);
$table = array(
"table_name" => "test", //tablename
"pk" => "id_test", //PK
"fields" => array( //array of fields
array(
REQUIRED:
"field" => "name", //name of field
"name" => "Имя", //title
"type" =>
"text" простое текстовое поле
"checkbox" булевое поле да/нет
"textarea" текст
"fixedlist" список предопределённых значений
"join" значения выбираются из другой таблицы
"file" загрузка файла
"date" дата
"datetime" дата и вреся
"wysiwyg" текст в визуальном редакторе
"callback" для отобрадения поля используется функция
"join_for_select" выборка поля просто для отображения, например ещё из третьей таблицы
"langvalue" многязыковая строчка
"langtext" многязыковой текст


OPTIONAL:
"style" => "font-wight: bold" //css
"hide_in_table" => true, //hide this field from showing in table, but can edit
"default_value" => "some text value" //for text fields


FOR TYPES
"fixedlist" => array(
"1" => "Низкий рост",
"2" => "Ниже среднего",
"3" => "Выше среднего",
"4" => "Высокий",
),

//join
"join_table" => "test_cities", //table to join
"join_key" => "id_city",
"join_field" => "name",
"alias" => "parent", //optional, alias for table (if selfreferenced)

//file
"upload_dir" => "modules/test/images",
"display_image" => true,
"resize_width" => 170, //if you want to resize image thereafter, specify this parameter
"resize_height" => 170,

//wysiwyg
"wysiwyg_width" => "100%",
"wysiwyg_height" => 200,

//callback
"function" => "calc_smallfile", //declared function($row)

//join_for_select
"field" => "nick",
"name" => "Пользователь",
"type" => "join_for_select",
"join_table" => "users",
"join_clause" => "users.id_user=blog.id_user",



"parent_sql" => "id_country='{$_REQUEST["id_country"]}'", //which means that a record will have parent key and table will be filtered
"order_field" => "n", //not the same as order. it allows to move recotrd up and down. howevewr the "order_by" should be the same. "n" filed be setted upon creation

),



$custom_actions = array(
"email_password" => array(
"function" => "email_password", //previously declared function($pk)
or
"href" => "url", //href to some php file, will pass pk
"icon" => "/admin/modules/books/email.png",
"title" => "Отослать e-mail с паролем", //title for image button
"onclick" => "return confirm('Отослать e-mail с паролем?');" //onclick javascript
),
);



$custom_editfields = array( //Кастомные поля при редактировании, обработку их писать самому надо if ($_REQUEST["action"]=="...")....
array(
"title" => "Теги:",
"function" => "custom_field", //function($row), собствеено выводит поле для редактирования в формк
"function_action" => "custom_field_callback", //function() вызывается сразу же после редактирования
),
);