/** * 登陆,如果失败,返回失败原因(用户名或者密码不正确),如果成功,返回用户信息, * 附带返回系统服务器时间戳 */ public function login() { //查user表 $User = M('User'); check_error($User); $user = $User->field(array('id' => 'userId', 'username' => 'userName', 'name', 'role_id' => 'roleId', 'role'))->where(array('username' => safe_post_param('username'), '_string' => "`password`=MD5('" . safe_post_param('password') . "')"))->find(); if (!empty($user)) { //根据权限查菜单 $Menu = M('Menu'); check_error($Menu); $menu = $Menu->join('`role_privilege` on `menu`.`id`=`role_privilege`.`menu_id`')->join('`user` on `user`.`role_id`=`role_privilege`.`role_id`')->field(array('`menu`.`id`', 'level', 'label', 'icon', 'widget', 'show', 'big_icon'))->where("`user`.`id`='" . $user['userId'] . "'")->order('`level` ASC')->select(); check_error($Menu); //保存session session('logined', true); session('user', $user); session('menu', $menu); //设置返回数据 $data = array(); $data['serverTime'] = time(); $data['user'] = $user; $data['menu'] = $menu; //保存日志 R('Log/adduserlog', array('登录', '登录成功', '成功')); //返回结果:用户数据+服务器时间 return_value_json(true, 'data', $data); } else { //保存日志 R('Log/adduserlog', array('登录', '登录失败:用户名或者密码不正确', '失败:权限不够', '用户名:' . safe_post_param('username'))); return_value_json(false, 'msg', '用户名或者密码不正确'); } }
function check_error($model) { $error = get_error($model); if (!empty($error)) { return_value_json(false, 'msg', $error); } }
public function getfile() { $file = $this->_request('file'); $session_file_state = session('file'); if ($session_file_state[$file] == 'ok') { return_value_json(true, 'file', EXPORT_TEMP_PATH . $file); } else { if ($session_file_state[$file]['doing']) { if (!empty($session_file_state[$file]['percent'])) { return_value_json(true, 'percent', $session_file_state[$file]['percent']); } else { return_value_json(true, 'doing', true); } } else { if (is_string($session_file_state[$file])) { return_value_json(false, 'msg', $session_file_state[$file]); } else { $session_file_state[$file] += 1; if ($session_file_state[$file] > 20) { return_value_json(false, 'msg', '操作超时'); } else { session('file', $session_file_state); return_value_json(true); } } } } }
public function log($data) { $Sms = M('Sms'); check_error($Sms); $Sms->create($data); check_error($Sms); if (false === $Sms->add()) { return_value_json(false, 'msg', get_error($Sms)); } }
/** * convert操作将返回指定GPS坐标的百度坐标 */ public function convert() { $lat = $_POST['lat'] + 0; $lng = $_POST['lng'] + 0; if (empty($lat) || empty($lng)) { return_value_json(false, msg, 'GPS坐标经度或(和)纬度为空'); } $Interface = A('Interface'); $baidu = $Interface->getBaiduCoordinate($lat, $lng); return_value_json(true, 'data', array_merge($baidu, $_POST)); }
public function import() { $CellDao = M('Cell'); $data_json = get_magic_quotes_gpc() ? stripslashes($_POST['data']) : $_POST['data']; $data = json_decode($data_json); if ($data) { $result = $CellDao->addAll($data); if ($result === false) { $dbError = $CellDao->getDbError(); $modelError = $CellDao->getError(); $error = empty($dbError) && empty($modelError) ? '未知错误' : (empty($dbError) ? $modelError : $dbError); Log::write("出错了" . $error); return_value_json(false, 'msg', '插入数据出错:' . $error); } else { return_value_json(true); } } else { Log::write("数据格式不正确:" . $data_json); return_value_json(false, 'msg', '数据格式不正确'); } }
public function log($data) { if (false === $this->addAll($data)) { return_value_json(false, 'msg', get_error($this)); } }
public function locatetest() { if (!$this->_ping()) { return_value_json(false, 'msg', '似乎电子铅封连接失败,请尝试在系统设置里面重启电子铅封服务'); } $lngmin = $_POST['lngmin'] + 0; $lngmax = $_POST['lngmax'] + 0; $latmin = $_POST['latmin'] + 0; $latmax = $_POST['latmax'] + 0; if ($latmin >= $latmax) { return_value_json(false, 'msg', '纬度设置不对'); } if ($lngmin >= $lngmax) { return_value_json(false, 'msg', '经度设置不对'); } $ids = $_POST['ids']; $ids = explode(",", $ids); $total = $locked = 0; foreach ($ids as $id) { if (is_numeric($id)) { if ($this->_locateSeal($id + 0, $latmin, $latmax, $lngmin, $lngmax)) { $locked++; } $total++; } } $return_data = array('relocated' => $locked, 'total' => $total); return_value_json(true, "data", $return_data); }
private function _parseCondition($table) { $condition = array('_string' => '1'); $startTime = $this->_request('startTime'); if (!empty($startTime)) { if (strlen($startTime) != 19) { return_value_json(false, 'msg', '系统出错:开始时间格式不正确,可以不填写开始时间,如果填写,请填写正确的时间'); } $startTime = str_ireplace("T", " ", $startTime); if (strtotime($startTime) === false) { return_value_json(false, 'msg', '系统出错:开始时间字符串无法解释成时间,可以不填写开始时间,如果填写,请填写正确的时间'); } $condition['_string'] .= " AND `{$table}_log`.`time`>='{$startTime}'"; } $endTime = $this->_request('endTime'); if (!empty($endTime)) { if (strlen($endTime) != 19) { return_value_json(false, 'msg', '系统出错:开始时间格式不正确,可以不填写开始时间,如果填写,请填写正确的时间'); } $endTime = str_ireplace("T", " ", $endTime); if (strtotime($endTime) === false) { return_value_json(false, 'msg', '系统出错:开始时间字符串无法解释成时间,可以不填写开始时间,如果填写,请填写正确的时间'); } $condition['_string'] .= " AND `{$table}_log`.`time`<='{$endTime}'"; } $departmentId = $this->_request('departmentId') + 0; if (!empty($departmentId)) { $condition['_string'] .= " AND `{$table}`.`department_id`='{$departmentId}'"; } $id = $this->_request("{$table}Id") + 0; if (!empty($id)) { $condition['_string'] .= " AND `{$table}_log`.`{$table}_id`='{$id}'"; } $operation = $this->_request('operation'); if (!empty($operation)) { $condition['_string'] .= " AND `{$table}_log`.`operation` LIKE '%{$operation}%'"; } $resultType = $this->_request('resultType'); if (!empty($resultType)) { $condition['_string'] .= " AND `{$table}_log`.`result_type`='{$resultType}'"; } $filters = $_REQUEST['filter']; if (!empty($filters)) { $condition['_string'] .= ' AND (' . $this->_getFiltersCondition($filters) . ')'; } return $condition; }
public function delete() { if (!$this->isPost()) { return_value_json(false, 'msg', '非法的调用'); } $devices = json_decode(file_get_contents("php://input")); if (!is_array($devices)) { $devices = array($devices); } $Device = D('Device'); check_error($Device); foreach ($devices as $device) { if (false === $Device->where("`id`='" . $device->id . "'")->delete()) { //保存日志 R('Log/adduserlog', array('删除监控设备资料', '删除监控设备资料:' . get_error($Device), '失败:系统错误', '监控设备:' . $device->label . ',失败原因:' . get_error($Device))); return_value_json(false, 'msg', '删除监控设备[' . $device->label . ']时出错:' + get_error($Device)); } //保存日志 R('Log/adduserlog', array('删除监控设备资料', '删除监控设备资料成功', '成功', '监控设备:' . $device->label)); } return_value_json(true); }
public function getlatestlocationforoverlay() { $req_number = $this->_request('number'); if (empty($req_number)) { return_value_json(false, "msg", "手机号码为空,暂时只能对手机进行立刻定位"); } $device_id = $this->_request('device_id') + 0; if (empty($device_id)) { return_value_json(false, "msg", "非法调用:设备id为空"); } $locateResult = $this->_getLatestLocation($req_number); if ($locateResult === true) { //定位成功 //根据device_id查找最后的定位,并返回,以便Overlay能自行更新自己 R('Tracking/single', array($device_id)); } else { if (is_string($locateResult)) { //定位失败 return_value_json(false, "msg", $locateResult); } else { return_value_json(false, "msg", "未能获得定位结果,定位也许失败,请用定位中心中“刷新”按钮查看已获得的最新位置"); } } }
/** * delete操作根据post数据删除一个用户角色,一并删除相关的角色权限。 */ public function delete() { if (!$this->isPost()) { return_value_json(false, 'msg', '非法的调用'); } $roles = json_decode(file_get_contents("php://input")); if (!is_array($roles)) { $roles = array($roles); } $Role = M('Role'); check_error($Role); $RolePrivilege = M('RolePrivilege'); check_error($RolePrivilege); foreach ($roles as $role) { //删除角色 if (false === $Role->where("`id`='" . $role->id . "'")->delete()) { //保存日志 R('Log/adduserlog', array('删除角色', '删除角色失败', '失败:系统错误', '删除角色[' . $role->name . ']时出错:' + get_error($Role))); return_value_json(false, 'msg', '删除角色[' . $role->name . ']时出错:' + get_error($Role)); } //删除角色权限 if (false === $RolePrivilege->where("`role_id`='" . $role->id . "'")->delete()) { //保存日志 R('Log/adduserlog', array('删除角色', '删除角色失败', '失败:系统错误', '删除角色[' . $role->name . ']的权限时出错:' + get_error($Role))); return_value_json(false, 'msg', '删除角色[' . $role->name . ']的权限时出错:' + get_error($Role)); } //保存日志 R('Log/adduserlog', array('删除角色', '删除角色成功', '成功', '角色名称:' . $role->name)); } return_value_json(true); }
/** * reorder操作根据POST['data']数据更新数据库里的sequence字段的值。 * POST['data'] 的格式为 ID:旧:新,ID:旧:新,ID:旧:新,.... */ public function reorder() { if (!$this->isPost()) { return_value_json(false, 'msg', '非法的调用'); } //数据检查 $data = safe_post_param('data'); if (empty($data)) { return_value_json(false, 'msg', '系统出错:重新排序内容为空'); } $oldnews = explode(",", $data); $Driver = M('Driver'); foreach ($oldnews as $oldnew) { $a = explode(":", $oldnew); if (count($a) != 3) { continue; } $data = array('sequence' => $a[2]); $Driver->where("`id`='" . $a[0] . "'")->data($data)->save(); } //保存日志 R('Log/adduserlog', array('调整司机排列顺序', '调整司机排列顺序成功', '成功', '')); return_value_json(true); }
public function deleteselected() { if (!$this->isPost()) { return_value_json(false, 'msg', '非法的调用'); } if (!isset($_POST['ids'])) { return_value_json(false, 'msg', '系统错误:需要删除的记录请求为空'); } else { $Alarm = M('Alarm'); check_error($Alarm); $total = $Alarm->where("`id` IN (" . $_POST['ids'] . ")")->delete(); if ($total === false) { return_value_json(false, "msg", get_error($Alarm)); } else { return_value_json(true, "msg", "共删除了 " . $total . " 条报警记录"); } } }
/** * 查找单个设备最后的定位 * @param int $device_id 设备id */ public function single($device_id) { if (empty($device_id) || !is_int($device_id)) { return_value_json(false, "msg", "非法的调用:设备id为空"); } //先找到相关的设备 $Device = M('Device'); check_error($Device); $device = $Device->find($device_id); if (empty($device)) { return_value_json(false, "msg", "无法查找到相关的设备"); } $condition = array('_string' => "`device`.`id`='{$device_id}'"); $fields = array('`device`.`id`', '`device`.`type`', '`device`.`label`', 'interval', 'delay', '`device`.`mobile_num`', '`device`.`target_type`', '`device`.`target_id`', '`device`.`target_name`', '`department`.`id`' => 'department_id', '`department`.`name`' => 'department', 'last_location', '`location`.`time`', 'state', 'online', '`location`.`range`', 'baidu_lat', 'baidu_lng', 'speed', 'direction', '`location`.`address`'); if ($device['target_type'] == '车辆') { $Device->join("`vehicle` on `vehicle`.`id`=`device`.`target_id`")->join('`driver` on `driver`.`id`=`vehicle`.`driver_id`'); array_merge($fields, array('`driver`.`id`' => 'driver_id', '`driver`.`name`' => 'driver', '`vehicle`.`id`' => 'vehicle_id', '`vehicle`.`number`')); } else { if ($device['target_type'] == '人员') { $Device->join("`employee` on `employee`.`id`=`device`.`target_id`"); array_merge($fields, array('`employee`.`id`' => 'employee_id', '`employee`.`name`', '`employee`.`post`')); } else { if ($device['target_type'] == '班列') { $Device->join("`train` on `train`.`id`=`device`.`target_id`"); array_merge($fields, array('`train`.`id`' => 'train_id', '`train`.`number`', '`train`.`due_date`')); } else { if ($device['target_type'] == '集装箱') { $Device->join("`container` on `container`.`id`=`device`.`target_id`"); array_merge($fields, array('`container`.`id`' => 'container_id', '`container`.`number`')); } else { return_value_json(false, "msg", "无法查找到相关的设备:设备类型不正确"); } } } } $tracking = $Device->join('`department` on `department`.`id`=`device`.`department_id`')->join('`location` on `location`.`id`=`device`.`last_location`')->field($fields)->where($condition)->find(); check_error($Device); return_value_json(true, 'tracking', $tracking); }
/** * 区域班列查询 */ public function inarea() { //先获取到参数 $starttime = $this->_get('starttime'); $endtime = $this->_get('endtime'); $points = json_decode($_GET['area']); if (empty($starttime)) { return_value_json(false, 'msg', '系统出错:开始时间为空'); } if (strlen($starttime) != 19 || strtotime($starttime) === false) { return_value_json(false, 'msg', '系统出错:开始时间格式不正确'); } if (!empty($endtime) && (strlen($endtime) != 19 || strtotime($endtime) === false)) { return_value_json(false, 'msg', '系统出错:结束时间格式不正确'); } if (empty($points) || !is_array($points) || count($points) < 2) { return_value_json(false, 'msg', '系统出错:多边形端点数量不够'); } foreach ($points as $index => $point) { $points[$index] = (array) $point; //把对象转成数组 } //首先查询数据库里指定时间内所有的定位信息 $Location = M('Location'); check_error($Location); $condition = array('_string' => " `location`.`time`>='{$starttime}' AND `train`.`number` IS NOT NULL "); if (!empty($endtime)) { $condition['_string'] .= " AND `location`.`time`<='{$endtime}' "; } $Location->join('`device` on `device`.`id`=`location`.`device_id`')->join("`train` on (`train`.`id`=`device`.`target_id` AND `device`.`target_type`='班列')")->join('`department` on `department`.`id`=`train`.`department_id`')->field(array('`location`.`id`', '`department`.`id`' => 'department_id', '`department`.`name`' => 'department', '`train`.`id`' => 'train_id', '`train`.`number`', '`train`.`due_date`', '`train`.`due_time`', '`location`.`device_id`', '`device`.`type`', '`device`.`label`', '`location`.`time`', 'state', 'online', '`location`.`address`', 'baidu_lat', 'baidu_lng', 'speed', 'direction', 'mcc', 'mnc', 'lac', 'cellid', '`location`.`range`'))->where($condition)->order('`department`.`sequence`, `train`.`id`, `time` ASC'); //先按班列id,然后按时间顺序 // $page = $_REQUEST['page'] + 0; // $limit = $_REQUEST['limit'] + 0; // if($page && $limit) $Location->limit($limit)->page($page); //这里不用数据库的分页,而是用我们自己的分页(目前没法分页了) $locations = $Location->select(); check_error($Location); $total = 0; $results = array(); $curTrain = null; //当前在区域内的班列 $alreadyIn = false; //目前是否已经在区域内 $lastLocation = null; foreach ($locations as $location) { $in = Geometry::geoPointInPolygon(array('lat' => $location['baidu_lat'], 'lng' => $location['baidu_lng']), $points); //TODO 考虑当前点与上一个定位点的轨迹线段是否切割多边形? if ($in) { if ($alreadyIn && $curTrain != $location['train_id']) { //已经在区域内,但是现在来了个不同的车(原来的车不知道跑哪里去了,这个车不知道是从哪里来的) //那么我们认为前车的离开点就是他轨迹的最后一个点,并且它现在离开区域了 $lastTrainLocationsCount = count($results[$total - 1]['locations']); if ($lastTrainLocationsCount > 0) { $results[$total - 1]['time_out'] = $results[$total - 1]['locations'][$lastTrainLocationsCount - 1]['time']; $results[$total - 1]['duration'] = $this->_getFriendlyDurationText($results[$total - 1]['time_in'], $results[$total - 1]['time_out']); $alreadyIn = false; $curTrain = null; } } if (!$alreadyIn && $curTrain === null) { //首次进入 $alreadyIn = true; $curTrain = $location['train_id']; $results[] = array('id' => $location['id'], 'department_id' => $location['department_id'], 'department' => $location['department'], 'train_id' => $location['train_id'], 'number' => $location['number'], 'device_id' => $location['device_id'], 'label' => $location['label'], 'time_in' => $location['time'], 'time_out' => '', 'duration' => '', 'locations' => array(), 'first_isout' => false, 'last_isout' => false); $total++; if ($lastLocation !== null && $lastLocation['train_id'] == $location['train_id']) { $results[$total - 1]['locations'][] = $lastLocation; $results[$total - 1]['first_isout'] = true; } } $results[$total - 1]['locations'][] = $location; } else { //出了区域 if ($alreadyIn) { if ($curTrain != $location['train_id']) { //原来的车不知道跑哪里去了 $lastTrainLocationsCount = count($results[$total - 1]['locations']); if ($lastTrainLocationsCount > 0) { $results[$total - 1]['time_out'] = $results[$total - 1]['locations'][$lastTrainLocationsCount - 1]['time']; } else { //这是不可能的。 $results[$total - 1]['time_out'] = $location['time']; } } else { //记录班列离开的点 $results[$total - 1]['time_out'] = $location['time']; $results[$total - 1]['locations'][] = $location; $results[$total - 1]['last_isout'] = true; } $results[$total - 1]['duration'] = $this->_getFriendlyDurationText($results[$total - 1]['time_in'], $results[$total - 1]['time_out']); $alreadyIn = false; $curTrain = null; } } $lastLocation = $location; } return_json(true, $total, 'results', $results); }
public function pingEsealConnection($return = false) { $ret = false; $setting = $this->get(true); if (!empty($setting['ESEAL_port']) && !empty($setting['ESEAL_ip'])) { $socket_client = stream_socket_client('tcp://' . $setting['ESEAL_ip'] . ':' . $setting['ESEAL_port'], $errno, $errstr, 30); if ($socket_client !== false) { fwrite($socket_client, 'PING'); $ret = fread($socket_client, 1024); fclose($socket_client); $ret = strtotime($ret) === false ? false : $ret; } } if ($return) { return $ret; } if ($ret === false) { return_value_json(false, 'msg', '服务器在两秒内没有回复,也许连接失败'); } else { return_value_json(true, 'data', $ret); } }
public function delete() { if (!$this->isPost()) { return_value_json(false, 'msg', '非法的调用'); } $vehicles = json_decode(file_get_contents("php://input")); if (!is_array($vehicles)) { $vehicles = array($vehicles); } $Vehicle = D('Vehicle'); foreach ($vehicles as $vehicle) { if (false === $Vehicle->where("`id`='" . $vehicle->id . "'")->delete()) { //保存日志 R('Log/adduserlog', array('删除车辆资料', '删除车辆资料失败', '失败:系统错误', '删除车辆[' . $vehicle->number . ']时出错:' . get_error($Vehicle))); return_value_json(false, 'msg', '删除车辆[' . $vehicle->number . ']时出错:' . get_error($Vehicle)); } //保存日志 R('Log/adduserlog', array('删除车辆资料', '删除车辆资料成功', '成功', '车牌号码:' . $vehicle->number)); } return_value_json(true); }
/** * 获取最新定位 * 相当于在旧网站上点击了“立即定位”,然后得到位置,发送请求给GPS接口,然后返回结果 */ public function getlatestlocation() { $num = $this->_request('number'); if (empty($num)) { return_value_json(false, 'msg', '待定位手机号码为空'); } $DataImportNumber = M('DataImportNumber1'); $number = $DataImportNumber->where(array('number' => $num))->find(); if (empty($number)) { return_value_json(false, 'msg', '即时定位暂时只支持手机定位数据导入方式,您现在看到的定位信息也许有时间延迟'); } //以临时cookie登陆旧系统 set_time_limit(0); $setting = $this->_getSetting(); if (!$setting['logined']) { $this->login(false); } M()->execute("UPDATE `data_import1` SET `logined`='1', `last_login`='" . date('Y-m-d H:i:s') . "'"); }
public function changepassword() { $oldpassword = $_POST['oldpassword']; $newpassword = $_POST['newpassword']; if (empty($oldpassword) || empty($newpassword)) { return_value_json(false, "msg", "旧密码或者新密码不能为空"); } $user = session('user'); if (empty($user) || empty($user['userId'])) { return_value_json(false, "msg", "用户尚未登陆,不能修改密码"); } //更新前先进行MD5加密 $oldpassword = md5($oldpassword); $newpassword = md5($newpassword); $result = M()->execute("UPDATE `user` SET `password`='{$newpassword}' WHERE `id`='{$user['userId']}' AND `password`='{$oldpassword}'"); if ($result) { return_value_json(true); } else { return_value_json(false, 'msg', '旧密码错误'); } }
private function coordinateTransfer($lat, $lng, $from = 0, $to = 4) { $url = "http://api.map.baidu.com/ag/coord/convert?from={$from}&to={$to}&x={$lng}&y={$lat}"; $json = file_get_contents($url); $coord = json_decode($json); if (!isset($coord) || !isset($coord->error) || !isset($coord->x) || !isset($coord->y)) { //TODO保存日志 return_value_json(false, 'msg', '百度坐标转换接口调用返回异常,也许是网络问题。'); } if ($coord->error) { //TODO保存日志 return_value_json(false, 'msg', '坐标转换出错:' . $coord->error); } return array('lng' => base64_decode($coord->x), 'lat' => base64_decode($coord->y)); }
public function getbyid() { $id = $_REQUEST['id'] + 0; if (empty($id)) { return_value_json(false, "msg", "系统错误:区域id为空或者为0"); } $PathArea = M('PathArea'); check_error($PathArea); $PathArea->join('`point` on `point`.`path_area_id`=`path_area`.`id`')->field(array('`path_area_id`', 'type', 'label', 'memo', 'distance', '`point`.`id`' => 'point_id', 'latitude', 'longitude', 'sequence'))->where("`type`='路径' AND `path_area_id`={$id}")->order('`path_area`.`id` ASC, `sequence` ASC'); $pathsAndPoints = $PathArea->select(); check_error($PathArea); $paths = array(); $curPathId = null; $curPoints = array(); $counter = -1; foreach ($pathsAndPoints as $pathAndPoint) { if ($pathAndPoint['path_area_id'] != $curPathId) { $curPathId = $pathAndPoint['path_area_id']; ++$counter; $paths[$counter] = array('id' => $pathAndPoint['path_area_id'], 'type' => $pathAndPoint['type'], 'label' => $pathAndPoint['label'], 'memo' => $pathAndPoint['memo'], 'distance' => $pathAndPoint['distance']); $paths[$counter]['points'] = array(); } $paths[$counter]['points'][] = array('id' => $pathAndPoint['point_id'], 'path_area_id' => $pathAndPoint['path_area_id'], 'latitude' => $pathAndPoint['latitude'], 'longitude' => $pathAndPoint['longitude'], 'sequence' => $pathAndPoint['sequence']); } $page = $_REQUEST['page'] + 0; $limit = $_REQUEST['limit'] + 0; if ($page && $limit) { $paths_pages = array_chunk($paths, $limit); $paths = $paths_pages[$page - 1]; } return_json(true, null, 'paths', $paths); }
public function save() { if (!$this->isPost()) { return_value_json(false, 'msg', '非法的调用'); } $Rule = M('Rule'); check_error($Rule); $Rule->create(); check_error($Rule); $sql = "1"; $dest = ""; if ($_POST['valid_time'] == 'given') { //特定时间 $dest = "特定时间:"; $hastime = false; if (!empty($_POST['valid']) && strtotime($_POST['valid']) !== false) { //有起效时间 $sql .= " AND NOW()>'{$_POST['valid']}'"; $dest .= "生效时间:" . $_POST['valid'] . "。"; $hastime = true; } if (!empty($_POST['invalid']) && strtotime($_POST['invalid']) !== false) { //有起效时间 $sql .= " AND NOW()<'{$_POST['invalid']}'"; $dest .= "失效时间:" . $_POST['invalid'] . "。"; $hastime = true; } if (!$hastime) { $dest .= "未指定格式正确的生效时间或者失效时间。"; } } else { if ($_POST['valid_time'] == 'specific') { //指定时间 $dest = "指定时间:"; $daysInWeek = array(); $daysInWeekArray = array('一', '二', '三', '四', '五', '六', '日'); $daysInWeekDest = array(); for ($i = 0; $i < 7; $i++) { if (!empty($_POST['weekday' . $i])) { $daysInWeek[] = $i; $daysInWeekDest[] = $daysInWeekArray[$i]; } } if (!empty($daysInWeek)) { $sql .= " AND WEEKDAY(NOW()) IN (" . implode(",", $daysInWeek) . ")"; $dest .= "星期" . implode("、", $daysInWeekDest) . "。"; } } else { //启用即有效 $dest = "启用即有效。"; } } if (!empty($_POST['valid_time_inday'])) { $times = explode(",", $_POST['times']); $goodTimes = array(); foreach ($times as $time) { $fromto = $this->_parseTime($time); if ($fromto) { $goodTimes[] = $time; $sql .= " AND (HOUR(NOW())>'{$fromto['fromhour']}' " . "\tOR (HOUR(NOW())='{$fromto['fromhour']}' " . "\t\tAND MINUTE(NOW())>='{$fromto['fromminute']}'))" . " AND (HOUR(NOW())<'{$fromto['tohour']}' " . "\tOR (HOUR(NOW())='{$fromto['tohour']}' " . "\t\tAND MINUTE(NOW())<='{$fromto['tominute']}'))"; } } if (!empty($goodTimes)) { $dest .= "仅在以下时间有效:" . implode(",", $goodTimes); } } $Rule->valid_time_discription = $dest; $Rule->valid_time_sql = $sql; $id = 0; if ($_POST['action'] == 'add') { $id = $Rule->add(); } else { $Rule->save(); $id = $_POST['id'] + 0; } check_error($Rule); $this->_updateRuleTarget($id, $_POST['selected_targets']); $this->_updateAlarmReceiver($id, $_POST['selected_receivers']); return_value_json(true); }