Esempio n. 1
0
 /**
  * @param string $key
  * @throws Exception
  */
 static function save_md_data($key)
 {
     if (!isset(self::$_action_list[$key])) {
         self::_error_and_redirect('不存在此页', '/');
     }
     $actions = self::$_action_list[$key];
     $content = Lib_Request::post_var('content');
     if (trim($content) == '') {
         Lib_Request::flash('error', '提交内容为空');
         Module_HttpRequest_Router::redirect_to($actions[self::URL]);
     }
     $keyword = $actions[self::KEYWORD];
     $model_option = new Model_Option();
     $content = str_replace("\r", '', $content);
     $content = str_replace("\n", '\\n', $content);
     //$content = htmlentities($content);
     $result = $model_option->update_option_by_keyword($keyword, $content);
     if ($result['errno'] != Const_Err_Base::ERR_OK) {
         self::_error_and_redirect(Lib_Helper::format_err_struct($result), $actions[self::URL]);
     } else {
         $help2opcode = ['help_index' => Module_OperationRecord_Main::OPCODE_HELP_INFO, 'help_dev' => Module_OperationRecord_Main::OPCODE_HELP_DEVELOP, 'help_todo' => Module_OperationRecord_Main::OPCODE_HELP_TODO, 'internal_api' => Module_OperationRecord_Main::OPCODE_HELP_INTERNAL, 'open_api' => Module_OperationRecord_Main::OPCODE_HELP_OPEN];
         $opcode = isset($help2opcode[$keyword]) ? $help2opcode[$keyword] : Module_OperationRecord_Main::OPCODE_HELP_INFO;
         Module_OperationRecord_Main::add_record($opcode);
         Lib_Request::flash('保存成功');
         Module_HttpRequest_Router::redirect_to($actions[self::URL]);
     }
 }
Esempio n. 2
0
 /**
  * @param int $current_page
  * @param int $total_size
  * @param int $page_size
  * @param int $mode
  * @return string
  */
 public static function get_pages_html($current_page, $total_size, $page_size = 10, $mode = 1)
 {
     $get_vars = Lib_Request::get_vars();
     $querystr = '';
     if (isset($get_vars['page'])) {
         unset($get_vars['page']);
     }
     if (!empty($get_vars)) {
         foreach ($get_vars as $k => $v) {
             if (empty($v)) {
                 continue;
             }
             $querystr .= $k . "=" . $v . "&";
         }
     }
     $mode = $mode > 0 ? $mode : 1;
     $num = $mode * 2 + 1;
     $current_page = $current_page < 1 ? 1 : $current_page;
     $current_url = Module_HttpRequest_Router::current_url_path();
     $current_url .= "?" . $querystr;
     $pages_html = '';
     $total_pages = ceil($total_size / $page_size);
     $current_page = $current_page > $total_pages ? $total_pages : $current_page;
     $pages_html .= '<ul class="pagination"><li><span>总计' . $total_size . '条记录&nbsp; 共' . $total_pages . '页</span></li></ul>&nbsp; ';
     if ($total_size < $page_size) {
         return $pages_html;
     }
     $pages_html .= '<ul class="pagination">';
     //
     if ($current_page <= 1) {
         $pages_html .= '<li class="disabled"><span>上一页</span></li>';
     } else {
         $pages_html .= '<li><a href="' . $current_url . 'page=' . ($current_page - 1) . '">上一页</a></li>';
     }
     //
     if ($total_pages <= $num + 2) {
         for ($i = 1; $i <= $total_pages; $i++) {
             $pages_html .= $i == $current_page ? '<li class="active"><span>' . $i . '</span></li>' : '<li><a href="' . $current_url . 'page=' . $i . '">' . $i . '</a></li>';
         }
     } else {
         $page_start = $current_page - $mode;
         $page_start = $page_start < 2 ? 2 : $page_start;
         $pages_html .= $current_page == 1 ? '<li class="active"><span>1</span></li>' : '<li><a href="' . $current_url . 'page=1">1</a></li>';
         if ($page_start > 2 && $total_pages > $num) {
             $pages_html .= '<li><span>...</span></li>';
         }
         $num = $page_start + $num;
         for ($i = $page_start; $i < $num; $i++) {
             if ($i > $total_pages) {
                 break;
             }
             $pages_html .= $i == $current_page ? '<li class="active"><span>' . $i . '</span></li>' : '<li><a href="' . $current_url . 'page=' . $i . '">' . $i . '</a></li>';
         }
         if ($num < $total_pages) {
             $pages_html .= '<li><span>...</span></li>';
         }
         if ($num <= $total_pages) {
             $pages_html .= $current_page == $total_pages ? '<li class="active"><span>' . $total_pages . '</span></li>' : '<li><a href="' . $current_url . 'page=' . $total_pages . '">' . $total_pages . '</a></li>';
         }
     }
     //
     if ($current_page >= $total_pages) {
         $pages_html .= '<li class="disabled"><span>下一页</span></li>';
     } else {
         $pages_html .= '<li><a href="' . $current_url . 'page=' . ($current_page + 1) . '">下一页</a></li>';
     }
     $pages_html .= '</ul>';
     return $pages_html;
 }
Esempio n. 3
0
 /**
  * @param array $ap_info
  * @param array $nearest_task
  * @return string
  */
 private static function _pre_task_running_mail_msg($ap_info, $nearest_task)
 {
     $msg = '';
     isset($nearest_task['create_time']) && ($msg .= '起始于<span style="color:red;">[' . date("Y-m-d H:i:s", $nearest_task['create_time']) . ']</span>的');
     $msg .= '接入点(' . $ap_info[Module_AccessPoint_Main::FIELD_AP_ID] . ')';
     isset($ap_info['ap_name']) && (isset($nearest_task['_id']) ? $msg .= '<a href="' . Module_HttpRequest_Router::site_url('control_centre/task/list?task_id=') . $nearest_task['_id'] . '" style="font-size:2em;">[' . $ap_info['ap_name'] . ']</a>' . '(任务ID:' . $nearest_task['_id'] . ')' : ($msg .= '[' . $ap_info['ap_name'] . ']'));
     $msg .= '仍在运行,后续任务暂不启动';
     return $msg;
 }
Esempio n. 4
0
 static function task_list_action()
 {
     $task_id = Lib_Request::get_int('task_id');
     $ap_name = Lib_Request::get_var('ap_name');
     $ap_name = trim($ap_name);
     $src_id = Lib_Request::get_var('sub_src');
     $src_id = trim($src_id);
     $status = Lib_Request::get_int('status');
     $time_begin = Lib_Request::get_var('time_begin');
     $time_begin = trim($time_begin);
     $time_end = Lib_Request::get_var('time_end');
     $time_end = trim($time_end);
     $cond = [];
     $search_vars = [];
     $ap_cond = [];
     if (!empty($task_id)) {
         $cond = ['_id' => $task_id];
         $search_vars = ['task_id' => $task_id];
     } else {
         if (strpos($src_id, ',')) {
             $src_ids = explode(',', $src_id);
             $int_src_ids = [];
             foreach ($src_ids as $k => $v) {
                 $int_src_ids[] = intval($v);
             }
             $cond['src_id'] = ['$in' => array_merge($src_ids, $int_src_ids)];
         } elseif (!empty($src_id)) {
             $cond['src_id'] = ['$in' => [$src_id, intval($src_id)]];
         }
         if (!empty($status)) {
             $cond['status'] = $status;
             $search_vars['status'] = $status;
         }
         if (!empty($time_begin) || !empty($time_end)) {
             $time_cond = [];
             if (!empty($time_begin)) {
                 $time_begin = strtotime($time_begin);
                 $time_cond['$gt'] = $time_begin;
             }
             if (!empty($time_end)) {
                 $time_end = strtotime($time_end);
                 $time_cond['$lte'] = $time_end;
             }
             if ($time_begin >= $time_end) {
                 unset($time_cond['$lte']);
             }
             if (!empty($time_cond)) {
                 $cond['create_time'] = $time_cond;
             }
         }
     }
     if (!Module_Account_User::has_perms([Module_Account_Perm::PERM_AP_ADMIN])) {
         $ap_cond['interface_people'] = new MongoRegex("/" . Module_Account_User::get_current_user() . "/");
     }
     if (!empty($ap_name)) {
         $ap_cond = ['ap_name' => new MongoRegex("/" . $ap_name . "/")];
     }
     if (!empty($ap_cond)) {
         $search_vars['ap_name'] = $ap_name;
         $ap_ids = [];
         $int_ap_ids = [];
         $model = new Model_AccessPoint();
         $ap_infos = $model->get_all($ap_cond);
         if ($ap_infos['errno'] == Const_Err_Base::ERR_OK) {
             foreach ($ap_infos['data'] as $k => $ap) {
                 $ap_ids[] = $ap['ap_id'];
                 $int_ap_ids[] = intval($ap['ap_id']);
             }
         }
         $cond['ap_id'] = ['$in' => array_merge($ap_ids, $int_ap_ids)];
     }
     $model_task = new Model_Task();
     $total_num = $model_task->get_tasks_count($cond);
     $current_page = Lib_Request::get_int('page');
     //当前页码,必须
     $total_size = isset($total_num['data']) ? intval($total_num['data']) : 0;
     //总记录数,必须
     $page_size = 15;
     //每页条数,必须
     $skip = ($current_page - 1) * $page_size;
     //跳过记录,必须
     $skip = $skip < 0 ? 0 : $skip;
     $mode = 2;
     //页码模式,决定页码个数,默认1
     $tasks = $model_task->get_all($cond, $page_size, $skip);
     if ($tasks['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(Lib_Helper::format_err_struct($tasks));
         $tasks = [];
         Lib_Request::flash('未获取到任务信息');
     }
     $tasks = $tasks['data'];
     $ap_infos = [];
     $ap_model = new Model_AccessPoint();
     foreach ($tasks as $_k => $_t) {
         $ap_info = $ap_model->get_ap_by_id($_t['ap_id']);
         $ap_info['ap_id'] = $_t['ap_id'];
         if ($ap_info['errno'] !== Const_Err_Base::ERR_OK) {
             Lib_Log::error(Lib_Helper::format_err_struct($ap_info));
             Lib_Request::flash('获取接入点信息失败');
             Module_HttpRequest_Router::redirect_to('/');
         }
         $ap_info = $ap_info[Const_DataAccess::MREK_DATA];
         $ap_infos[$_t['ap_id']] = $ap_info;
     }
     $source_model = new Model_Source();
     $all_sources = $source_model->get_all();
     $sources = $all_sources[Const_DataAccess::MREK_DATA];
     $all_src_type = [];
     foreach ($all_sources['data'] as $k => $v) {
         if (!in_array($v['src_type'], $all_src_type)) {
             $all_src_type[] = $v['src_type'];
         }
     }
     asort($all_src_type);
     $task_status_list = Module_ControlCentre_Main::$task_status_list;
     $pages = Module_View_Template::get_pages_html($current_page, $total_size, $page_size, $mode);
     Module_Page_Main::render('control_centre/task_list', ['ap_info' => $ap_infos, 'tasks' => $tasks, 'sources' => $sources, 'pages' => $pages, 'all_src_type' => $all_src_type, 'status_list' => $task_status_list, 'search_vars' => $search_vars]);
 }
Esempio n. 5
0
<?php

session_start();
require_once dirname(dirname(__FILE__)) . '/app/init.php';
Module_HttpRequest_Router::get_instance()->register_pre_router_hook(['Module_Account_Manager', 'check_perm']);
Module_View_Main::view()->set_template_dir(Da\Sys_App::template_path());
$router = [Module_HttpRequest_Router::get_instance(), 'route'];
if (Da\Sys_Router::get_instance()->register_router($router)) {
    MT::lang(MT::LANG_ZH_CN);
    $dispatch = Da\Sys_Router::get_instance()->dispatch();
    if ($dispatch['errno'] != Da\Sys_Router::ERRNO_OK) {
        echo $dispatch['data'];
        exit;
    }
} else {
    Lib_Log::error('Route rules ' . json_encode($rules) . ' is not callable!');
}
Esempio n. 6
0
 /**
  * @param string $url
  * @param int $id
  * @return array
  */
 private static function _get_flow_data($url, $id = null)
 {
     $data = [];
     $name = Lib_Request::post_var('name');
     $main = Lib_Request::post_var('main');
     $stuff = Lib_Request::post_var('stuff');
     $config = Lib_Request::post_var('config');
     $name = trim($name);
     $main = trim($main);
     $stuff = trim($stuff);
     $config = trim($config);
     $flow_model = new Model_FlowInfo();
     $flash_error = function ($msg, $url) {
         Lib_Request::flash('error', $msg);
         Module_HttpRequest_Router::redirect_to($url);
     };
     if (empty($name)) {
         $flash_error('流程名称不能为空', $url);
     }
     if (!empty($id)) {
         $cond = ['name' => $name, '_id' => ['$ne' => intval($id)]];
     } else {
         $cond = ['name' => $name];
     }
     $flow_info = $flow_model->get_flow_by_cond($cond);
     if ($flow_info['errno'] == Const_Err_Base::ERR_OK && !empty($flow_info['data'])) {
         $flash_error('流程名称存在', $url);
     }
     if (empty($main)) {
         $flash_error('主流程不能为空', $url);
     }
     $mains = self::_get_array_by_str($main);
     $stuffs = self::_get_array_by_str($stuff);
     $configs = self::_get_array_by_str($config);
     $data = ['name' => $name, 'flow' => [Module_FlowManager_Main::FLOW_TYPE_MAIN => $mains, Module_FlowManager_Main::FLOW_TYPE_STUFF => $stuffs, Module_FlowManager_Main::FLOW_TYPE_CONFIG => $configs]];
     return $data;
 }