} else { echo ajax_make_res('error', 'Произошла неизвестная ошибка', 'Ошибка!'); } })); add_action(array('code' => 'ajax_update_option', 'rule' => 'admin_ajax, admin_settings', 'category' => 'admin', 'function' => function ($params = null) { $ID = null; if (isset($params['button']['pre']['value']) && $params['button']['pre']['type'] == 'ID') { $ID = $params['button']['pre']['value']; } if (isset($params['window']['input'])) { $params = $params['window']['input']; } if ($params) { foreach ($params as $key => $item) { if (is_object($item) || is_array($item)) { $params[$key] = json_val_encode($item); } } } if ($params !== null && $ID && update_option($ID, $params, true)) { echo ajax_make_res('reload', "Опция {$params['code']} успешно обновлена", 'Успех!'); } else { echo ajax_make_res(array('status' => 'error', 'body' => 'Проверьте правильность заполненных полей', 'title' => 'Ошибка!', 'error' => true)); } })); add_action(array('code' => 'ajax_get_option', 'rule' => 'admin_ajax, admin_settings', 'category' => 'admin', 'function' => function ($params = null) { if (isset($params['button'])) { $params = $params['button']; } if (isset($params['pre']['value']) && $params['pre']['type'] == 'ID') { $params = $params['pre']['value'];
function delete_module($dir, $full = false) { $active = get_option('active_modules'); $path = ABSPATH . '/' . MODULES . '/' . $dir; if (is_dir($path) && file_exists($path . '/main.php')) { if (($key = array_multi_search($dir, $active, 0)) !== null) { unset($active[$key]); sort($active); if (file_exists($path . '/uninstall.php')) { require_once $path . '/uninstall.php'; } return update_option('active_modules', json_val_encode($active)); } if ($full) { return delete_folder($path); } } return false; }
function update_rules($ID, $arr, $group = true) { global $DETDB; if (check_json($arr)) { $arr = json_decode($arr, true); } if (($param = set_ID($ID)) && is_jsoned($arr)) { $custom = array(); foreach ($arr as $item) { if (is_string($item)) { $custom[] = $item; } } $custom = json_val_encode($custom); if ($group) { return $DETDB->update('users_groups', 'rules', $custom, "WHERE {$param}='{$ID}'"); } else { return $DETDB->update('users', 'rules', $custom, "WHERE {$param}='{$ID}'"); } } return false; }
function show_calendar_events($params = array()) { global $DETDB; $custom = array('links' => false, 'type' => 'month', 'month' => isset($_GET['month']) && is_numeric($_GET['month']) ? $_GET['month'] : date('m'), 'year' => isset($_GET['year']) && is_numeric($_GET['year']) ? $_GET['year'] : date('Y'), 'start' => '', 'end' => '', 'show' => 'table', 'exclude_ID' => null, 'limit' => 100); $query = null; if (is_merged($params)) { $custom = set_merge($custom, $params); if ($custom['start']) { $custom['start'] = date('Y-m-d H:i', strtotime($custom['start'])); } if ($custom['end']) { $custom['end'] = date('Y-m-d H:i', strtotime($custom['end'])); } $custom['year'] = is_numeric($custom['year']) && checkdate('01', '01', $custom['year']) ? $custom['year'] : date('Y'); $custom['month'] = is_numeric($custom['month']) && checkdate($custom['month'], '01', $custom['year']) ? $custom['month'] : date('m'); if ($custom['type'] == 'month') { $query = array(array('param' => 'MONTH(date_start)', 'value' => $custom['month']), array('param' => 'YEAR(date_start)', 'value' => $custom['year'])); } else { $query = array(array('param' => 'date_end', 'value' => $custom['start'], 'relation' => '>='), array('param' => 'date_start', 'value' => $custom['end'], 'relation' => '<=')); } if ($custom['exclude_ID'] && !is_array($custom['exclude_ID'])) { $custom['exclude_ID'] = array($custom['exclude_ID']); } if ($custom['exclude_ID']) { foreach ($custom['exclude_ID'] as $item) { $query[] = array('param' => 'ID', 'value' => $item, 'relation' => '!='); } } } $events = $query ? $DETDB->select(array('table' => 'calendar_events', 'cols' => '*', 'cond' => $query, 'order_by' => 'date_start', 'order_type' => 'ASC', 'limit' => $custom['limit'])) : null; ?> <?php if ($events && count($events) > 0 && $custom['show'] == 'table') { ?> <table class="table table-striped table-hover table-bordered" width="100%"> <thead> <tr> <th width="7%">Дата</th> <th width="7%">Время</th> <th>Наименование мероприятия</th> <th width="18%">Место проведения</th> <th width="14%">Ответственный</th> </tr> </thead> <tbody> <?php foreach ($events as $item) { ?> <?php $start = strtotime($item->date_start); $end = strtotime($item->date_end); ?> <tr class="field"> <td> <?php echo date('d', $start); if ($end && $end > 0 && date('d', $start) != date('d', $end)) { echo ' - ' . date('d', $end); } ?> </td> <td> <?php if ($item->date_params && check_json($item->date_params)) { $item->date_params = json_decode($item->date_params, true); if (count($item->date_params) == 2) { $item->date_params = !$item->date_params[0]; } } else { $item->date_params = true; } if ($start && $item->date_params) { echo date('G.i', $start); if ($end && $end > 0 && $start && $end != $start) { echo ' - ' . date('G.i', $end); } } ?> </td> <td><?php echo $item->name; ?> <?php if ($custom['links']) { ?> <p class="controls"> <a href="<?php echo get_page_link('calendar_event_add') . '&event_id=' . $item->ID; ?> ">Редактировать</a> | <a class="table-delete button-control" data-set-action="delete_calendar_event" data-id="<?php echo $item->ID; ?> ">Удалить</a> </p> <?php } ?> </td> <td><?php echo $item->place; ?> </td> <td><?php echo $item->worker; ?> </td> </tr> <?php } ?> </tbody> <tfoot> <tr> <th>Дата</th> <th>Время</th> <th>Наименование мероприятия</th> <th>Место проведения</th> <th>Ответственный</th> </tr> </tfoot> </table> <?php } elseif ($custom['show'] == 'json') { ?> <?php echo json_val_encode($events); ?> <?php } else { ?> <p>Нет событий, выбранных за данный период.</p> <?php } ?> <?php }
function ajax_make_res($param = 'success', $body = '', $title = '', $data = '', $error = false) { $custom = array('status' => '', 'body' => $body, 'title' => $title, 'data' => $data, 'error' => $error); if (is_merged($param)) { $custom = set_merge($custom, $param); } else { $custom['status'] = $param; } if ($custom['error']) { $custom['body'] .= get_output_result_messages('error', true); } unset($custom['error']); return json_val_encode($custom); }