function Show() { if (!empty($GLOBALS['_POST'])) { $actions = get('actions', '', 'p'); if ($actions) { return $this->{$actions}(); } } $this->SetValues(); require_once core('ajax_table'); $data['thisname'] = $this->name; $data['root'] = is_root(); $this->AddStrings($data); $_tables = sql_getRows('SHOW tables'); foreach ($_tables as $key => $val) { $tables[$val] = $val; } $_transactions = sql_getColumn('SELECT distinct action FROM ' . $this->table . ' ORDER BY action'); foreach ($_transactions as $key => $val) { $transactions[$val] = $val; } $where = ''; if ($this->from_date && $this->to_date) { $where = ' UNIX_TIMESTAMP(date)>=' . $this->from_date . ' AND UNIX_TIMESTAMP(date)<=' . $this->to_date; } $data['table'] = ajax_table(array('columns' => array(array('select' => 'user', 'display' => 'user', 'width' => '1px', 'flags' => FLAG_SORT | FLAG_SEARCH), array('select' => 'object', 'display' => 'object', 'width' => '1px', 'flags' => FLAG_SORT | FLAG_FILTER | FLAG_SEARCH, 'filter_type' => 'array', 'filter_value' => array('' => '-- все --') + $tables, 'filter_rule' => 'find_in_set'), array('select' => 'action', 'display' => 'action', 'width' => '1px', 'flags' => FLAG_SORT | FLAG_FILTER | FLAG_SEARCH, 'filter_type' => 'array', 'filter_value' => array('' => '-- все --') + $transactions), array('select' => 'description', 'display' => 'description', 'type' => 'description', 'flags' => FLAG_SEARCH), array('select' => 'date', 'display' => 'date', 'type' => 'datetime', 'width' => '100px', 'flags' => FLAG_SORT)), 'from' => $this->table, 'where' => $where, 'orderby' => 'date DESC', 'params' => array('page' => $this->name, 'do' => 'show'), 'dblclick' => '', 'click' => ''), $this); $data['navig'] = $this->NavigForm(); return $this->parse($data, $this->name . '.tmpl'); }
public function __construct() { $sql = "SHOW TABLES LIKE 'acl_%'"; $tables = sql_getColumn($sql); try { // Роли if (in_array($this->_table_roles, $tables)) { $roles = $this->getList('roles'); if ($roles) { $this->createRoles($roles); } } // Ресурсы if (in_array($this->_table_resources, $tables)) { $resources = $this->getList('resources'); if ($resources) { $this->createResources($resources); } } // Действия if (in_array($this->_table_actions, $tables)) { $actions = $this->getList('actions'); if ($actions) { $this->createActions($actions); } } // Установка прав if (in_array($this->_table_permissions, $tables)) { $permissions = sql_getRows("SELECT * FROM {$this->_table_permissions}"); if ($permissions) { $this->setPermissions($permissions); } } } catch (Exception $e) { } }
/** * Вернуть все текущие роли пользователя * @param $root_id * @return array */ function getRoles($root_id = '') { static $user_roles; if (!isset($user_roles)) { $user_roles = array(); } $root_id = $root_id ? $root_id : ROOT_ID; if (!isset($user_roles[$this->_id][$root_id])) { $user_roles[$this->_id][$root_id] = sql_getColumn("SELECT role_id FROM {$this->_table_roles} WHERE user_id={$this->_id} AND root_id=" . $root_id); } return $user_roles[$this->_id][$root_id]; }
/** * Копирование сайта * @return string */ function editCopy() { $ids = (array) get('id', array(), 'g'); if (!$ids) { echo "<script type='text/javascript'>location.href = '/admin/?page=" . $this->name . "';</script>"; } set_time_limit(60); sql_query('BEGIN'); foreach ($ids as $key => $id) { // Получаем данные по сайту $data = sql_getRow("SELECT * FROM sites WHERE id=" . $id); unset($data['id']); $number = sql_getValue("SELECT COUNT(id) FROM sites WHERE name LIKE '" . $data['name'] . "%'"); $data['name'] .= "_" . $number; // Копируем эти данные в новую строку $new_site_id = sql_insert('sites', $data); if (!is_int($new_site_id)) { sql_query('ROLLBACK'); echo $this->str('error') . ': ' . $new_site_id; die; } // Копируем языки $langs = sql_getRows("SELECT name, descr, locale, charset, priority, root_id FROM sites_langs WHERE pid=" . $id); if (!empty($langs)) { foreach ($langs as $lang_row) { $old_root = $lang_row['root_id']; $new_root_id = (int) sql_getValue("SELECT MIN(root_id) FROM tree WHERE 1") - 1; if ($new_root_id <= 0) { $new_root_id = (int) sql_getValue("SELECT MAX(id) FROM tree WHERE 1") + 1; } $lang_row['pid'] = $new_site_id; $lang_row['root_id'] = $new_root_id; $new_lang_id = sql_insert('sites_langs', $lang_row); if (!is_int($new_lang_id)) { sql_query('ROLLBACK'); echo $this->str('error') . ': ' . $new_lang_id; die; } // Создаем в дереве корневой элемент $tree_row = sql_getRow("SELECT * FROM tree WHERE id=" . $old_root); if (!$tree_row) { sql_query('ROLLBACK'); echo 'no row in tree for root_id=' . $old_root; die; } $tree_row['id'] = $tree_row['pid'] = $tree_row['root_id'] = $new_root_id; $tree_row['pids'] = '/' . $new_root_id . '/'; $tree_row['priority'] = (int) sql_getValue("SELECT MAX(priority) FROM tree WHERE id=pid") + 1; $_id = sql_insert('tree', $tree_row); if (!is_int($_id)) { sql_query('ROLLBACK'); echo $this->str('error') . ': ' . $_id; die; } // Копируем разделы $this->table = 'tree'; $rows = sql_getColumn("SELECT id FROM tree WHERE pid=" . $old_root . " AND id<>pid"); if ($rows) { foreach ($rows as $row) { $this->CopyTree($row, $new_root_id, true); } } $this->Validate(0, '', 0, array(), $new_root_id); $this->table = 'sites'; } } } sql_query('COMMIT'); touch_cache('sites'); touch_cache('tree'); return "<script type='text/javascript'>location.href = '/admin/?page=" . $this->name . "';</script>"; }
/** * Строит форму простого окна * * @return html */ function ElemForm($tabname = "") { //устанавливаем title для окна мультиэлема if (isset($this->elem_fields['title'])) { $title =& $this->elem_fields['title']; $title = $this->str($title); } $obj = $this->getObject(); //обрабатываем объект для построения формы foreach ($this->elem_fields['columns'] as $key => $val) { //определяем, бралось ли поле c AS или етсь ли пробелы в названии поля $asKey = explode(' ', $key); if ($asKey[0] == $key) { if (isset($obj['object'][$key])) { if ($val['type'] == 'autosuggest') { $field = $val['langselect'] ? "IF ({$val['field']}_" . lang() . " <> '', {$val['field']}_" . lang() . ", {$val['field']}_" . LANG_DEFAULT . ")" : $val['field']; if (!$val['multiply']) { $this->elem_fields['columns'][$key]['value'] = is_numeric($obj['object'][$key]) ? sql_getValue("SELECT {$field} FROM {$val['table']} WHERE id = '{$obj['object'][$key]}'") : $obj['object'][$key]; } else { if ($obj['object'][$key]) { $values = sql_getColumn("SELECT {$field} FROM {$val['table']} WHERE id IN ({$obj['object'][$key]})"); } $this->elem_fields['columns'][$key]['value'] = $values ? implode(', ', $values) : $obj['object'][$key]; } } else { $this->elem_fields['columns'][$key]['value'] = $obj['object'][$key]; } } else { if ($val['type'] == 'text_range') { $this->elem_fields['columns'][$key]['value0'] = $obj['object'][$key . '0']; $this->elem_fields['columns'][$key]['value1'] = $obj['object'][$key . '1']; } } } else { if ($obj['object']) { if (isset($obj['object'][$asKey[2]])) { //переопределяем ключ массива $temp_elem_fields = array(); $temp_elem_data = $this->elem_fields['columns'][$key]; foreach ($this->elem_fields['columns'] as $mkey => $mval) { if ($mkey == $key) { unset($this->elem_fields['columns'][$key]); $temp_elem_fields[$asKey[2]] = $temp_elem_data; continue; } $temp_elem_fields[$mkey] = $mval; } unset($this->elem_fields['columns']); $this->elem_fields['columns'] = $temp_elem_fields; $key = $asKey[2]; if (isset($obj['object'][$key])) { $this->elem_fields['columns'][$key]['value'] = $obj['object'][$key]; } } } } $this->elem_fields['columns'][$key]['tab'] = $tabname; $elem_id_str = $tabname ? '[' . $tabname . ']' : ''; if ($elem_id_str) { $elem_id_str = isset($obj['elem_id']) ? $elem_id_str . '[' . $obj['elem_id'] . ']' : $elem_id_str . ''; } $this->elem_fields['columns'][$key]['name'] = 'fld' . $elem_id_str . '[' . $key . ']'; $this->elem_fields['columns'][$key]['display']['elem'] = 'fld' . ($tabname ? '[' . $tabname . ']' : '') . '[' . $key . ']'; if (isset($obj['elem_id'])) { $this->elem_fields['columns'][$key]['display']['elem_id'] = $obj['elem_id']; } } $obj['type'] = isset($this->elem_fields['type']) ? $this->elem_fields['type'] : $this->elem_type; if (isset($this->elem_fields['tmp'])) { $obj['tmp'] = $this->elem_fields['tmp']; } if ($this->debug) { pr($this->elem_fields); } $obj['obj'] = form($this->elem_fields, $this); $this->AddStrings($obj); return Parse($obj, OBJECT_EDITOR_MODULE . '/elems.tmpl'); }
/** /* Выборка id подразделов /* /**/ function getChilds($id) { $tree =& Registry::get('TTreeUtils'); $ids = sql_getColumn('SELECT id FROM tree WHERE pid=' . $id . ' AND visible > 0'); foreach ($ids as $key => $val) { $ids = array_merge($ids, $this->getChilds($val)); } return $ids; }
function delObjects() { $clients_ids = $_POST['id']; if (!$clients_ids) { return "<script>alert('Ќет выбранных клиентов!');</script>"; } $objects_ids = sql_getColumn('SELECT id FROM objects WHERE client_id IN ("' . join('", "', $clients_ids) . '")'); if (!$objects_ids) { return "<script>alert('ќбъекты дл¤ выбранных клиентов не найдены!');</script>"; } $sql = "DELETE FROM objects WHERE id IN ('" . join("', '", $objects_ids) . "')"; sql_query($sql); $err = sql_getError(); if (!empty($err)) { return "<script>alert('ќшибка: " . e($err) . "');</script>"; } require_once 'modules/objects_func.php'; objects_deleteImages($objects_ids); touch_cache('objects'); return "<script>alert('”спешно удалено!'); window.parent.location.reload();</script>"; }
/** * ‘ункци¤ формирует выражение WHERE в зависимости от переданных ей параметров * * @param array $res - все параметры из адресной строки */ function generateQuery($res, $obj_types) { global $settings; $sql = ""; $sql .= " AND obj_type_id='room'"; //------------------------------------------------------------------------ // нижн¤¤ и верхн¤¤ границы стоимости if (isset($res['price_dollar']) && $res['price_dollar'] > 0) { $price = $settings['prices'][$res['price_dollar']]; list($pricedown, $priceup) = explode(' - ', $price); $pricedown = str_replace(array('$', ' '), '', $pricedown); $pricedown = doubleval($pricedown); $priceup = str_replace(array('$', ' '), '', $priceup); $priceup = doubleval($priceup); $sql .= " AND (o.price_dollar>=" . $pricedown . " AND o.price_dollar<=" . $priceup . ")"; } if (isset($res['price1']) && $res['price1'] > 0) { $price = str_replace(array('$', ' ', 'у.е.'), '', $this->prices[$res['price1']]); $sql .= " AND (o.price_dollar>=" . $price . ")"; } if (isset($res['price2']) && $res['price2'] > 0) { $price = str_replace(array('$', ' ', 'у.е.'), '', $this->prices[$res['price2']]); $sql .= " AND (o.price_dollar<=" . $price . ")"; } //------------------------------------------------------------------------ // кол-во комнат if (isset($res['room']) && $res['room'] > -1) { if ($res['room'] == '6') { $sql .= " AND o.room >=5"; } else { $sql .= " AND o.room = " . $res['room']; } } if (isset($res['room1']) && $res['room1'] > -1) { if ($res['room1'] == '6') { $sql .= " AND (o.room>=5)"; } else { $sql .= " AND (o.room>=" . $res['room1'] . ")"; } } if (isset($res['room2']) && $res['room2'] > -1) { if ($res['room2'] == '6' && (!isset($res['room1']) || $res['room1'] == -1)) { $sql .= " AND (o.room>=5)"; } elseif ($res['room2'] != '6') { $sql .= " AND (o.room<=" . $res['room2'] . ")"; } } //------------------------------------------------------------------------ // округ if (isset($res['district_id']) && !empty($res['district_id'])) { $childs = $this->getChilds('obj_locat_districts', 'ORDER BY name', $res['district_id']); $districts = array(); $this->getChildsList($childs, $districts); $districts[$res['district_id']] = 1; $sql .= " AND o.district_id IN (" . implode(',', array_keys($districts)) . ")"; } if (isset($res['raion']) && is_array($res['raion']) && !empty($res['raion'])) { $parents = sql_getColumn('SELECT DISTINCT pid FROM obj_locat_districts WHERE id IN (' . implode(',', $res['raion']) . ')'); if ($parents) { $res['raion'] = array_merge($res['raion'], $parents); } $sql .= " AND o.district_id IN (" . implode(',', $res['raion']) . ")"; } //------------------------------------------------------------------------ // рынок if (isset($res['market']) && !empty($res['market']) && $res['market'] != '-1') { $sql .= " AND o.market = '" . $res['market'] . "' "; } //------------------------------------------------------------------------ // лот if (isset($res['lot_id']) && !empty($res['lot_id']) && $res['lot_id'] != 'не важно') { $sql .= " AND o.lot_id = '" . $res['lot_id'] . "' "; } //------------------------------------------------------------------------ // метро if (isset($res['metro']) && !empty($res['metro'])) { $sql .= " AND o.metro_id IN(" . implode(", ", $res['metro']) . ") "; } //------------------------------------------------------------------------ // направление if (isset($res['direction']) && $res['direction'] != 0) { $sql .= " AND o.direction = '" . $res['direction'] . "' "; } //------------------------------------------------------------------------ // тип объекта if (isset($res['type']) && $res['type'] != 0) { if (!empty($obj_types[$res['type']])) { $sql .= " AND o.obj_type_id IN (" . implode(", ", $obj_types[$res['type']]) . ") "; } } //------------------------------------------------------------------------ //площадь if (isset($res['total_area1']) && $res['total_area1'] > 0) { $sql .= " AND (o.total_area>=" . $res['total_area1'] . ")"; } if (isset($res['total_area2']) && $res['total_area2'] > 0) { $sql .= " AND (o.total_area<=" . $res['total_area2'] . ")"; } if (isset($res['living_area1']) && $res['living_area1'] > 0) { $sql .= " AND (o.living_area>=" . $res['living_area1'] . ")"; } if (isset($res['living_area2']) && $res['living_area2'] > 0) { $sql .= " AND (o.living_area<=" . $res['living_area2'] . ")"; } if (isset($res['kitchen_area1']) && $res['kitchen_area1'] > 0) { $sql .= " AND (o.kitchen_area>=" . $res['kitchen_area1'] . ")"; } if (isset($res['kitchen_area2']) && $res['kitchen_area2'] > 0) { $sql .= " AND (o.kitchen_area<=" . $res['kitchen_area2'] . ")"; } //------------------------------------------------------------------------ //этаж if (isset($res['storey1']) && $res['storey1'] > 0) { $sql .= " AND (o.storey>=" . $res['storey1'] . ")"; } if (isset($res['storey2']) && $res['storey2'] > 0) { $sql .= " AND (o.storey<=" . $res['storey2'] . ")"; } if (isset($res['storeys_number1']) && $res['storeys_number1'] > 0) { $sql .= " AND (o.storeys_number>=" . $res['storeys_number1'] . ")"; } if (isset($res['storeys_number2']) && $res['storeys_number2'] > 0) { $sql .= " AND (o.storeys_number<=" . $res['storeys_number2'] . ")"; } //------------------------------------------------------------------------ //адрес if (!empty($res['address'])) { $sql .= " AND o.address LIKE '%" . e(strip_tags($res['address'])) . "%'"; } //------------------------------------------------------------------------ //москва или область if (isset($res['moscow']) && in_array($res['moscow'], array('0', '1'))) { $sql .= " AND o.moscow=" . (int) $res['moscow']; } return $sql; }
/** * Расстановка priority * @param $pid * @param $col_name * @param $table */ function EnumPriority($pid, $col_name, $table, $col_name2 = 'id', $priority_field = 'priority') { $counter = 1; $rows = sql_getColumn("SELECT " . $col_name2 . " FROM " . $table . " WHERE " . $col_name . "=" . $pid . " ORDER BY IF(" . $priority_field . ">0, " . $priority_field . ", 999999)"); foreach ($rows as $id) { sql_query("UPDATE " . $table . " SET " . $priority_field . "=" . $counter . " WHERE " . $col_name2 . "=" . $id); $counter++; } }
function CopyTree($src, $trg, $top = true) { static $counter = array(); static $next_id = 0; // запишем что мы уже перенесли (для отмены рекурсии) $counter[] = $trg; // Если в данный элемент уже копировали, отменяем (для отмены рекурсии) if (in_array($src, $counter)) { return; } # Берем source $src_row = sql_getRow("SELECT * FROM " . $this->table . " WHERE id='" . $src . "'"); if (!$next_id) { $status = sql_getRow("SHOW TABLE STATUS LIKE '" . $this->table . "'"); $next_id = $status['Auto_increment']; } else { $next_id++; } # Обрабатываем unset($src_row['id']); $src_row['pid'] = $trg; $root_id = sql_getValue("SELECT root_id FROM " . $this->table . " WHERE id='" . (int) $trg . "'"); # Вставляем $src_row['dir'] = ''; if ($src_row['page'] && (!is_numeric($src_row['page']) || $src_row['page'] == '404')) { $src_row['page'] = preg_replace('/(.*?)\\d*$/', '\\1', $src_row['page']); $count = sql_getValue('SELECT COUNT(1) FROM ' . $this->table . ' WHERE page = "' . $src_row['page'] . '" AND root_id="' . $root_id . '" AND pid="' . $trg . '"'); $src_row['page'] = $count ? $src_row['page'] . $count : $src_row['page']; } else { $src_row['page'] = $next_id; } $src_row['dir'] = 'tmp_' . count($counter); $src_row['root_id'] = $root_id; $columns = sql_getRows("SHOW columns FROM tree"); foreach ($columns as $col) { if ($col['Null'] == 'YES' && !$src_row[$col['Field']]) { unset($src_row[$col['Field']]); } } $trg = sql_insert($this->table, $src_row); // копируем все элементы $src_cfg = $GLOBALS['cfg']['types'][$src_row['root_id']][$src_row['type']]; foreach ($src_cfg['elements'] as $elem) { $tables = sql_getRows("SHOW tables LIKE '" . $elem . "'"); if ($tables) { $src_elems = sql_getRows("SELECT * FROM " . $elem . " WHERE pid=" . $src); $columns = sql_getRows("SHOW columns FROM " . $elem); $auto_increment_column = $this->isAutoIncrement($columns); foreach ($src_elems as $src_elem) { // Удаляем id только если он не нужен, т.е. если колонка id auto_increment // Иначе нужно оставить, например, в случае копирования elem_product if ($auto_increment_column) { $auto_increment_column_value = $src_elem[$auto_increment_column]; unset($src_elem[$auto_increment_column]); } $src_elem['pid'] = $trg; $new_elem_id = sql_insert($elem, $src_elem); if (!is_int($new_elem_id)) { // error } if ($elem == 'elem_form') { $form_elems = sql_getRows("SELECT * FROM elem_form_elems WHERE pid=" . $auto_increment_column_value); if ($form_elems) { foreach ($form_elems as $f) { $save_f_id = $f['id']; $f['pid'] = $new_elem_id; unset($f['id']); $f_data = array(); foreach ($f as $k2 => $v2) { $f_data['`' . $k2 . '`'] = $v2; } $__id = sql_insert('elem_form_elems', $f_data); if (is_int($__id)) { $form_values = sql_getRows("SELECT * FROM elem_form_values WHERE pid=" . $save_f_id); if ($form_values) { foreach ($form_values as $f2) { $f2['pid'] = $__id; unset($f2['id']); sql_insert('elem_form_values', $f2); } } } } } } } } } # Ищем дочерние ветви и запускаем заново эту функцию $rows = sql_getColumn("SELECT id FROM " . $this->table . " WHERE pid=" . $src); if ($rows) { foreach ($rows as $row) { $this->CopyTree($row, $trg, false); } } }