示例#1
0
 public function getmanage()
 {
     $type = $_REQUEST['type'];
     $departmentId = $_REQUEST['departmentId'] + 0;
     if (!in_array($type, array('车辆', '人员', '集装箱', '班列', '设备'))) {
         return_json(true, null, 'targets', array());
     }
     $condition = '1';
     $condition .= empty($departmentId) ? '' : " AND `department_id`='{$departmentId}'";
     $DB = M();
     check_error($DB);
     if ($type == '车辆') {
         $targets = $DB->query("SELECT `id` AS `target_id`, '车辆' AS `target_type`, `number` AS `target_name`, " . "CONCAT('车辆^', `id`, '^', `number`) AS `type_id_name` FROM `vehicle` WHERE " . $condition . " ORDER BY `sequence` ASC");
     } else {
         if ($type == '人员') {
             $targets = $DB->query("SELECT `id` AS `target_id`, '人员' AS `target_type`, `name` AS `target_name`, " . "CONCAT('人员^', `id`, '^', `name`) AS `type_id_name` FROM `employee` WHERE " . $condition . " ORDER BY `sequence` ASC");
         } else {
             if ($type == '集装箱') {
                 $targets = $DB->query("SELECT `id` AS `target_id`, '集装箱' AS `target_type`, `number` AS `target_name`, " . "CONCAT('集装箱^', `id`, '^', `number`) AS `type_id_name` FROM `container` WHERE " . $condition . " ORDER BY `id` ASC");
             } else {
                 if ($type == '班列') {
                     $targets = $DB->query("SELECT `id` AS `target_id`, '班列' AS `target_type`, `number` AS `target_name`, " . "CONCAT('班列^', `id`, '^', `number`) AS `type_id_name` FROM `train` WHERE " . $condition . " ORDER BY `id` ASC");
                 } else {
                     if ($type == '设备') {
                         $targets = $DB->query("SELECT `id` AS `target_id`, '设备' AS `target_type`, `label` AS `target_name`, " . "CONCAT('设备^', `id`, '^', `label`) AS `type_id_name` FROM `device` WHERE " . $condition . " ORDER BY `id` ASC");
                     }
                 }
             }
         }
     }
     check_error($DB);
     //		Log::write("\n".M()->getLastSql(), Log::SQL);
     return_json(true, null, 'targets', $targets);
 }
示例#2
0
 /**
  * allprivilege操作返回所有的权限(即根据系统menu表反查所有权限)
  */
 public function allprivilege()
 {
     $Menu = M('Menu');
     check_error($Menu);
     $privileges = $Menu->field(array('id', 'label' => 'privilege', 'id' => 'menu_id', 'level'))->order('`level` ASC')->select();
     return_json(true, null, 'privileges', $privileges);
 }
 /**
  * all操作返回所有被分组信息
  */
 public function all()
 {
     $Department = M('Department');
     // 		$total = $Department->count(); //0号角色是特殊角色,不在显示之列
     $Department->order('`sequence` ASC');
     //     	$page = $_REQUEST['page'] + 0;
     //     	$limit = $_REQUEST['limit'] + 0;
     //     	if($page && $limit) $Department->limit($limit)->page($page);
     $departments = $Department->select();
     check_error($Department);
     return_json(true, null, 'departments', $departments);
 }
示例#4
0
 public function indepartment()
 {
     $departmentId = $_REQUEST['departmentId'] + 0;
     $condition = empty($departmentId) ? '`department_id`=0 OR `department_id` IS NULL' : "`department_id`='{$departmentId}'";
     $User = M('User');
     check_error($User);
     $users = $User->field(array('id', 'username', 'name'))->where($condition)->order('`id` ASC')->select();
     check_error($User);
     //		Log::write("\n".M()->getLastSql(), Log::SQL);
     foreach ($users as $i => $user) {
         $users[$i]['name'] = empty($user['name']) ? $user['username'] : $user['name'];
     }
     return_json(true, null, 'users', $users);
 }
示例#5
0
 function edit_administrator()
 {
     $email_in_db = $this->administrator_model->get_email_administrator($this->input->post('id'));
     if ($email_in_db == $this->input->post('email')) {
         $this->administrator_model->edit_administrator($this->input->post());
         return_json(array('error' => false, 'msg' => $this->lang->line('information_updated')));
     } else {
         if ($this->is_valid_email()) {
             $this->administrator_model->edit_administrator($this->input->post());
             return_json(array('error' => false, 'msg' => $this->lang->line('information_updated')));
         } else {
             return_json(array('error' => true, 'msg' => $this->lang->line('email_registered')));
         }
     }
 }
示例#6
0
 /**
  * cell操作返回指定边界之内的基站
  */
 public function cell()
 {
     $nlat = $_GET['nelat'] + 0;
     $elng = $_GET['nelng'] + 0;
     $slat = $_GET['swlat'] + 0;
     $wlng = $_GET['swlng'] + 0;
     if (empty($nlat) || empty($elng) || empty($slat) || empty($wlng)) {
         return_value_json(false, msg, '边界坐标经度或(和)纬度为空');
     }
     $Cell = M('Cell');
     check_error($Cell);
     $cells = $Cell->field(array('id', 'mcc', 'mnc', 'lac', 'cellid', 'gps_lng', 'gps_lat', 'range', 'offset_lng', 'offset_lat', 'address', 'update_time'))->where("`gps_lng`<{$elng} AND `gps_lng`>{$wlng} AND `gps_lat`<{$nlat} AND `gps_lat`>{$slat}")->limit('250')->select();
     check_error($Cell);
     //		Log::write("\n".M()->getLastSql(), Log::SQL);
     return_json(true, null, 'cells', $cells);
 }
示例#7
0
 public function device()
 {
     $condition = $this->_parseCondition('device');
     $DeviceLog = M('DeviceLog');
     check_error($DeviceLog);
     $total = $DeviceLog->join('`device` on `device`.`id`=`device_log`.`device_id`')->where($condition)->count();
     check_error($DeviceLog);
     $DeviceLog->join('`device` on `device`.`id`=`device_log`.`device_id`')->where($condition)->field('`device_log`.*')->order('`device_log`.`time` ASC, `device_log`.`id` ASC');
     $page = $this->_request('page') + 0;
     $limit = $this->_request('limit') + 0;
     if ($page && $limit) {
         $DeviceLog->limit($limit)->page($page);
     }
     $logs = $DeviceLog->select();
     check_error($DeviceLog);
     return_json(true, $total, 'logs', $logs);
 }
示例#8
0
 /**
  * indepartment操作分页返回指定分组($_POST['department_id']下的司机
  */
 public function indepartment()
 {
     $dpm_id = $this->_request('department_id') + 0;
     $Driver = M('Driver');
     check_error($Driver);
     $total = $Driver->join('`department` on `department`.`id`=`driver`.`department_id`')->where("`department_id`='{$dpm_id}'")->count();
     $Driver->join('`department` on `department`.`id`=`driver`.`department_id`')->field(array('`driver`.`id`', '`driver`.`name`', "CONCAT(LPAD(`department`.`sequence`, 4, '0'), `department`.`name`)" => 'seq_department', '`department`.`id`' => 'department_id', '`department`.`name`' => 'department', '`driver`.`sequence`', 'birthdate', 'sex', 'licence_date', '`driver`.`memo`', '`driver`.`id_card`', '`driver`.`license`', 'CEIL((TO_DAYS(NOW())-TO_DAYS(`driver`.`licence_date`))/365)' => 'driving_age'))->where("`department_id`='{$dpm_id}'")->order('`sequence` ASC');
     $page = $_REQUEST['page'] + 0;
     $limit = $_REQUEST['limit'] + 0;
     if ($page && $limit) {
         $Driver->limit($limit)->page($page);
     }
     $drivers = $Driver->select();
     //		Log::write(M()->getLastSql(), Log::SQL);
     check_error($Driver);
     return_json(true, $total, 'drivers', $drivers);
 }
示例#9
0
 function index()
 {
     if (!file_exists('./uploads/tinymce/')) {
         mkdir('./uploads/tinymce/', 0777, true);
     }
     $config['upload_path'] = './uploads/tinymce/';
     $config['allowed_types'] = 'gif|jpg|png';
     $config['max_size'] = 10000;
     // Maximun size 10mb
     $this->load->library('upload', $config);
     if (!$this->upload->do_upload('file')) {
         $error = array('error' => $this->upload->display_errors());
         return_json(array('error' => $error));
     } else {
         $data = array('upload_data' => $this->upload->data());
         return_json(array('error' => false, 'path' => base_url() . 'uploads/tinymce/' . $data['upload_data']['file_name']));
     }
 }
示例#10
0
 /**
  * all操作分页返回所有的监控设备
  */
 public function all()
 {
     $Device = M('Device');
     check_error($Device);
     $total = $Device->count();
     check_error($Device);
     $Device->join('`department` on `department`.`id`=`device`.`department_id`')->join('`location` on `location`.`id`=`device`.`last_location`')->field(array('`device`.`id`', '`device`.`type`', '`device`.`label`', 'interval', 'delay', "CONCAT(LPAD(`department`.`sequence`, 4, '0'), `department`.`name`)" => 'seq_department', '`device`.`department_id`', '`department`.`name`' => 'department', 'weekday0', 'weekday1', 'weekday2', 'weekday3', 'weekday4', 'weekday5', 'weekday6', 'starttime', 'endtime', 'mobile_num', 'bar_id', '`device`.`target_id`', '`device`.`target_type`', '`device`.`target_name`', '`device`.`brand`', '`device`.`model`', '`device`.`system`', '`device`.`buy_date`', '`device`.`memo`', '`location`.`state`', '`location`.`online`'))->order('`department`.`sequence` ASC, `device`.`id`');
     // 		$page = $_REQUEST['page'] + 0;
     // 		$limit = $_REQUEST['limit'] + 0;
     // 		if($page && $limit) $Device->limit($limit)->page($page);
     $devices = $Device->select();
     check_error($Device);
     //		Log::write(M()->getLastSql(), Log::SQL);
     foreach ($devices as $i => $device) {
         $devices[$i]['seq_department'] = empty($device['seq_department']) ? '0000未分组的' : $device['seq_department'];
     }
     return_json(true, $total, 'devices', $devices);
 }
示例#11
0
 function ajax($class, $method)
 {
     $parameters = CL_Router::get_instance()->fetch_parameters();
     if (!controller_exists($class)) {
         header('HTTP/1.0 404 Not Found');
         exit;
     }
     require_once APPPATH . 'controllers/' . $class . '.php';
     $controller = new $class();
     try {
         $res = call_user_func_array(array($controller, $method), array_slice($parameters, 2));
     } catch (CL_Exception $e) {
         header('Content-type: application/json');
         echo json_encode(array('type' => 'error', 'data' => array('errstr' => strip_tags($e->get_message()), 'errtype' => '')));
         exit;
     }
     return_json($res);
 }
示例#12
0
 /**
  * indepartment操作分页返回指定分组($_POST['department_id']下的车辆
  */
 public function indepartment()
 {
     $dpm_id = $this->_request('department_id') + 0;
     $Vehicle = M('Vehicle');
     check_error($Vehicle);
     $total = $Vehicle->join('`department` on `department`.`id`=`vehicle`.`department_id`')->where("`vehicle`.`department_id`='{$dpm_id}'")->count();
     check_error($Vehicle);
     $Vehicle->join('`department` on `department`.`id`=`vehicle`.`department_id`')->join('`driver` on `driver`.`id`=`vehicle`.`driver_id`')->field(array('`vehicle`.`id`', '`vehicle`.`number`', "CONCAT(LPAD(`department`.`sequence`, 4, '0'), `department`.`name`)" => 'seq_department', '`vehicle`.`department_id`', '`department`.`name`' => 'department', '`driver`.`id`' => 'driver_id', '`driver`.`name`' => 'driver', '`vehicle`.`sequence`', 'brand', 'model', 'engine', 'displacement', 'vin', 'ein', 'color', 'load', 'buy_date', '`vehicle`.`memo`'))->where("`vehicle`.`department_id`='{$dpm_id}'")->order('`sequence` ASC');
     $page = $_REQUEST['page'] + 0;
     $limit = $_REQUEST['limit'] + 0;
     if ($page && $limit) {
         $Vehicle->limit($limit)->page($page);
     }
     $vehicles = $Vehicle->select();
     check_error($Vehicle);
     //		Log::write(M()->getLastSql(), Log::SQL);
     foreach ($vehicles as $i => $vehicle) {
         $vehicles[$i]['seq_department'] = empty($vehicle['seq_department']) ? '0000未分组的' : $vehicle['seq_department'];
     }
     return_json(true, $total, 'vehicles', $vehicles);
 }
示例#13
0
function save($params, $data)
{
    global $message, $api, $base_path;
    $title = $params['title'];
    $bbcode = $params['bbcode'];
    if (strlen($title) < 3 && strlen($bbcode) < 7) {
        if ($api) {
            return_json(array('error' => 'Would not save empty data, sorry'));
        } else {
            $message = 'Would not save empty data, sorry';
        }
        return;
    }
    if (strlen($title) > 250) {
        $spacepos = strrpos($title, ' ');
        $title = substr($title, 0, $spacepos !== false ? $spacepos : 250);
    }
    $db = getdb();
    if ($data && isset($params['key']) && $data['editid'] == $params['key']) {
        // update
        $codeid = $params['id'];
        $editid = $params['key'];
        $sql = !$db ? '' : "update " . DB_TABLE . " set updated=now(), title='" . $db->escape_string($title) . "', bbcode='" . $db->escape_string($bbcode) . "' where codeid = '{$codeid}'";
        cache_remove($codeid, 'code');
        cache_remove(false, 'user');
        // yup, now a lot of users can have their libraries updated
    } else {
        $editid = generate_id(EDIT_HASH_LENGTH);
        $tries = 10;
        do {
            $codeid = generate_id(HASH_LENGTH);
            $exists = get_data($codeid) !== false;
        } while ($exists);
        $sql = !$db ? '' : "insert into " . DB_TABLE . " (created, updated, codeid, editid, title, bbcode) values(now(), now(), '{$codeid}', '{$editid}', '" . $db->escape_string($title) . "', '" . $db->escape_string($bbcode) . "')";
    }
    if ($db) {
        $res = $db->query($sql);
    } else {
        // put code to cache
        $assoc = array('editid' => $editid, 'title' => $title, 'bbcode' => $bbcode);
        cache_put($codeid, 'code', $assoc);
        $res = true;
    }
    if (!$api) {
        if (!$res) {
            $message = 'Failed to insert entry in the database: ' . $db->error;
        } else {
            header("Location: " . $base_path . "/{$codeid}/{$editid}");
            exit;
        }
    } else {
        if (!$res) {
            return_json(array('error' => 'Failed to insert entry in the database: ' . $db->error));
        } else {
            return_json(array('codeid' => $codeid, 'editid' => $editid, 'viewurl' => $base_path . "/{$codeid}", 'editurl' => $base_path . "/{$codeid}/{$editid}"));
        }
        exit;
    }
}
                    break;
                }
            }
            //	If we found a venue let's include it in the EyeEm Photo object params!
            if (!empty($venueId)) {
                $eye_params['venueId'] = $venueId;
                $eye_params['venueServiceName'] = 'foursquare';
            }
        }
        //	Create the EyeEm Photo object
        $photo = $eyeem->postPhoto($eye_params);
        //	Set topics to this very image
        //	Convert Igers #hashtag to EyeEm topic
        if (!empty($_REQUEST['topic'])) {
            $topic = explode(',', $_REQUEST['topic']);
            foreach ($topic as $t) {
                $eyeem->request('/photos/' . $photo->id . '/topics', 'POST', array('name' => $t));
            }
        }
        //	Create the igers2eye array to pass back to the ajax caller
        $mediaList[] = array('id' => $photo->id, 'title' => $photo->title, 'caption' => $photo->caption, 'width' => $photo->width, 'height' => $photo->height, 'thumbUrl' => $photo->thumbUrl, 'photoUrl' => $photo->photoUrl, 'webUrl' => $photo->webUrl, 'venueid' => !empty($venueId) ? $venueId : '', 'latitude' => $photo->latitude, 'longitude' => $photo->longitude, 'topic' => !empty($_REQUEST['topic']) ? $_REQUEST['topic'] : '', 'updated' => $photo->updated, 'instagram_id' => !empty($_REQUEST['igers_id']) ? $_REQUEST['igers_id'] : '', 'timestamp' => $eye_params['timestamp'], 'duplicate' => false);
    } catch (Exception $e) {
        exit(return_json(array(), null, 'Troubles uploading photo to EyeEm! ' . $e->getMessage()));
    }
    //	Remove the now useless uploaded file from my temp folder
    if (file_exists($targetname)) {
        unlink($targetname);
    }
}
exit(return_json($mediaList, null, null));
示例#15
0
 /**
  * 区域班列查询
  */
 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);
 }
示例#16
0
 /**
  * 声音报警 和 窗口报警
  * 根据用户的session里的用户id,返回该用户当前应该接收到的报警
  * 返回:
  * array(
  * 	'total': 
  * 	'alarms': [{
  * 		'id': //报警id 
  * 		'start_time': 
  * 		'msg':
  * 		'sound': 
  * 		'window':
  * 		'window_countdown': //窗口剩余次数(包括此次)
  *  }]
  * )
  */
 public function alarm()
 {
     if (!session('logined')) {
         return_json(true, 0, 'alarms', array());
     }
     $user = session('user');
     //		Log::write("\nUSER:"******"SET sql_mode = 'NO_UNSIGNED_SUBTRACTION'");
     $alarms = $Alarm->join('`rule` ON `rule`.`id`=`alarm`.`rule_id`')->join('INNER JOIN `alarm_receiver` ON `alarm_receiver`.`rule_id`=`alarm`.`rule_id`')->field(array('`alarm`.`id`', '`alarm`.`start_time`', '`alarm`.`msg`', '`rule`.`sound` AND `alarm_receiver`.`sound`' => 'sound', '`rule`.`window` AND `alarm_receiver`.`window` AND (`rule`.`window_repeat`-`alarm`.`window_count`>0)' => 'window', '`rule`.`window_repeat`-`alarm`.`window_count`' => 'window_countdown'))->where("`alarm_receiver`.`receiver_id`='" . $user['userId'] . "' " . "AND `alarm`.`checked`='0' " . "AND ((`alarm_receiver`.`window`='1' AND `rule`.`window`='1' AND (`rule`.`window_repeat`-`alarm`.`window_count`)>0) " . ")")->select();
     check_error($Alarm);
     //		Log::write("\n".M()->getLastSql(), Log::SQL);
     $ids = array();
     foreach ($alarms as $key => $alarm) {
         $ids[] = $alarm['id'];
     }
     if (!empty($ids)) {
         $Alarm->execute("UPDATE `alarm` SET `last_window`='" . date('Y-m-d H:i:s') . "', `window_count`=`window_count`+1 " . "WHERE `id` IN (" . implode(",", $ids) . ")");
     }
     return_json(true, null, 'alarms', $alarms);
 }
示例#17
0
 function edit_configuration()
 {
     $this->configuration_model->edit_configuration($this->input->post());
     return_json(array('msg' => $this->lang->line('configuration_updated')));
 }
 public function location()
 {
     $DataImportLocation = M('DataImportLocation1');
     check_error($DataImportLocation);
     $total = $DataImportLocation->count();
     $DataImportLocation->order('`id` ASC');
     $page = $_REQUEST['page'] + 0;
     $limit = $_REQUEST['limit'] + 0;
     if ($page && $limit) {
         $DataImportLocation->limit($limit)->page($page);
     }
     $locations = $DataImportLocation->select();
     return_json(true, $total, 'locations', $locations);
 }
示例#19
0
 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);
 }
示例#20
0
 private function _getTrackings()
 {
     $deviceIds = $_GET['deviceIds'];
     $startTime = $_GET['startTime'];
     $endTime = $_GET['endTime'];
     $condition = array();
     if (empty($deviceIds)) {
         return_value_json(false, 'msg', '系统出错:设备编号为空');
     }
     $condition['_string'] = "`device`.`id` IN ({$deviceIds}) ";
     if (empty($startTime)) {
         return_value_json(false, 'msg', '系统出错:开始时间为空');
     }
     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 `location`.`time`>'{$startTime}' ";
     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 `location`.`time`<'{$endTime}'";
     }
     $Device = M('Device');
     check_error($Device);
     $devicetrackings = $Device->join("`vehicle` on (`vehicle`.`id`=`device`.`target_id` AND `device`.`target_type`='车辆')")->join('`department` on `department`.`id`=`vehicle`.`department_id`')->join('`driver` on `driver`.`id`=`vehicle`.`driver_id`')->join('`location` on `location`.`device_id`=`device`.`id`')->field(array('`device`.`id`', '`device`.`type`', '`device`.`label`', 'interval', 'delay', '`device`.`mobile_num`', '`device`.`target_type`', '`device`.`target_id`', '`device`.`target_name`', '`vehicle`.`department_id`', '`department`.`name`' => 'department', '`driver`.`id`' => 'driver_id', '`driver`.`name`' => 'driver', '`vehicle`.`id`' => 'vehicle_id', '`vehicle`.`number`', 'last_location', '`location`.`id`' => 'location_id', '`location`.`time`', 'state', 'online', 'baidu_lat', 'baidu_lng', 'speed', 'direction', '`location`.`address`', 'mcc', 'mnc', 'lac', 'cellid', '`location`.`range`'))->where($condition)->order('`device`.`id` ASC, `location`.`time` ASC')->select();
     check_error($Device);
     //		Log::write("\n".M()->getLastSql(), Log::SQL);
     $this->_fixNullOnline($devicetrackings);
     $trackings = $this->_parseTrackingsData($devicetrackings);
     return_json(true, null, 'trackings', $trackings);
 }
示例#21
0
function response($request)
{
    global $smtp_config;
    parse_str($request, $request);
    $response = new stdClass();
    $action = getSafe($request, 'action', 'page');
    $news_file = 'server_data/news.json';
    $news = file_get_contents($news_file);
    $news = json_decode($news);
    $images = file_get_contents('server_data/images.json');
    $images = json_decode($images);
    $tariffs = file_get_contents('server_data/tariffs.json');
    $tariffs = json_decode($tariffs);
    if (!$news || !$images) {
        $response->type = 'error';
        $response->message = 'Server files errors!';
        return_json($response);
    }
    $NPP = 6;
    // news per page
    $NN = count($news->news);
    // news number
    switch ($action) {
        case 'tariffs':
            $ttype = getSafe($request, 'ttype', false);
            $response->type = 'success';
            $response->data = new stdClass();
            if (!$ttype) {
                $response->data->tariffs = $tariffs->tariffs;
            } else {
                $response->data->tariffs = $tariffs->tariffs->{$ttype};
            }
            break;
        case 'captcha':
            $request = $_POST;
            $reset = getSafe($request, 'reset', false);
            $captcha = getSafe($request, 'captcha');
            session_start();
            if ($reset) {
                session_destroy();
                $response->type = 'success';
            } else {
                if ($_SESSION['code'] == $captcha) {
                    $response->type = 'success';
                } else {
                    $response->type = 'error';
                }
                $response->code = $_SESSION['code'];
            }
            break;
        case 'mail':
            $request = $_POST;
            $subject = 'Сообщение с сайта УНИКО';
            $message = getSafe($request, 'message');
            $headers = 'From: unico@vgg.ru' . "\r\n" . "Content-Type: text; charset=utf-8";
            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->Host = $smtp_config['host'];
            $mail->SMTPAuth = true;
            $mail->Port = $smtp_config['port'];
            $mail->Username = $smtp_config['username'];
            $mail->Password = $smtp_config['password'];
            $mail->CharSet = 'UTF-8';
            $mail->SetFrom(FROM_MAIL, 'Унико');
            $mail->Subject = $subject;
            $mail->isHtml(false);
            $mail->Body = $message;
            $addresses = explode(' ', UNICO_MAIL);
            foreach ($addresses as $address) {
                $mail->AddAddress($address);
            }
            if ($mail->Send()) {
                $response->type = 'success';
            } else {
                $response->type = 'error';
            }
            break;
        case 'igroups':
            $response->type = 'success';
            $response->data = new stdClass();
            $response->data->groups = $images->groups;
            break;
        case 'images':
            $group = getSafe($request, 'g');
            if ($group) {
                foreach ($images->groups as $i) {
                    if ($i->id == $group) {
                        $group = $i;
                        break;
                    }
                }
            }
            $response->type = 'success';
            $response->data = new stdClass();
            $images_output = array();
            foreach ($images->images as $i) {
                if (is_object($group)) {
                    if (!in_array($i->id, $group->images)) {
                        continue;
                    }
                }
                $i->image = GALLERY_PATH . '/' . $i->image;
                $images_output[] = $i;
            }
            $response->data->images = $images_output;
            break;
        case 'groups':
            $response->type = 'success';
            $response->data = new stdClass();
            $response->data->groups = $news->groups;
            break;
        case 'hot':
            $response->type = 'success';
            $response->data = new stdClass();
            $response->data->hots = $news->hots;
            break;
        case 'item':
            $current_item = $request['n'];
            $response->type = 'success';
            $response->data = new stdClass();
            foreach ($news->news as $item) {
                if ($item->id == $current_item) {
                    $current_item = $item;
                    break;
                }
            }
            if (empty($current_item)) {
                $current_item = $news->news[0];
            }
            $current_item->text = implode(' ', $current_item->text);
            $current_item->url = 'action=page';
            $response->data->news = array($current_item);
            break;
        case 'index':
            $news_output = array();
            foreach ($news->index as $id) {
                foreach ($news->news as $n) {
                    if ($n->id == $id) {
                        $n->text = implode(' ', $n->text);
                        if (strlen($n->text) > 300) {
                            $n->text = mb_substr($n->text, 0, 300, 'utf8') . "...";
                        }
                        $n->url = "news.php?action=item&n={$id}";
                        $news_output[] = $n;
                        break;
                    }
                }
            }
            $response->type = 'success';
            $response->data = new stdClass();
            $response->data->news = $news_output;
            break;
        case 'news_all':
            $response->data = $news;
            $response->file = $news_file;
            break;
        case 'page':
            $current_page = getSafe($request, 'n', 1);
            $search = getSafe($request, 's');
            $group = getSafe($request, 'g');
            if ($group) {
                foreach ($news->groups as $n) {
                    if ($n->id == $group) {
                        $group = $n;
                        break;
                    }
                }
            }
            $response->type = 'success';
            $response->data = new stdClass();
            $news_output = array();
            foreach ($news->news as $n) {
                $n->text = implode(' ', $n->text);
                if ($search) {
                    if (strpos($n->title, $search) === false && strpos($n->text, $search) === false) {
                        continue;
                    }
                } else {
                    if (is_object($group)) {
                        if (!in_array($n->id, $group->news)) {
                            continue;
                        }
                    }
                }
                if (strlen($n->text) > 300) {
                    $n->text = mb_substr($n->text, 0, 300, 'utf8') . "...";
                }
                $n->url = 'action=item&n=' . $n->id;
                $news_output[] = $n;
            }
            $response->data->current_page = $current_page;
            $response->data->pages = ceil(count($news_output) / $NPP);
            usort($news_output, "cmp");
            $news_output = array_slice($news_output, ($current_page - 1) * $NPP, $NPP);
            $response->data->news = $news_output;
            break;
        default:
            $response->type = 'error';
            $response->message = 'There is no such action';
            break;
    }
    return_json($response);
    return $response;
}
示例#22
0
 /**
  * Index method
  *
  * @access   public
  * @param    void
  * @return   void
  */
 public function index()
 {
     $result['error'] = __("No results found!");
     return_json($result);
     exit;
 }
示例#23
0
 function recover_password()
 {
     $data['email'] = $this->input->post('email');
     $data['hash'] = urlencode(substr(base64_encode(openssl_random_pseudo_bytes('30')), 0, 22));
     $data['hash'] = strtr($data['hash'], array('+' => '.', '/' => '.', '%' => '.'));
     $user = $this->auth_model->get_user_by_email($data['email']);
     if ($user) {
         $data['id'] = $user->id;
         $data['name'] = $user->name;
         $this->auth_model->recover_password($data['email'], $data['hash']);
         $this->load->library('email', config_mail());
         $this->email->set_mailtype("html");
         $this->email->from('*****@*****.**', 'Auto Forms');
         $this->email->to($data['email']);
         $this->email->subject('Reset password - Auto_Foms');
         $this->email->message($this->load->view('mail/recover_password', $data, true));
         $this->email->send();
         return_json(array('error' => false, 'msg' => $this->lang->line('send_recover_email')));
     } else {
         return_json(array('error' => true, 'msg' => $this->lang->line('email_not_registered')));
     }
 }
示例#24
0
 public function alltest()
 {
     $sealtests = session('sealtests');
     if (empty($sealtests)) {
         $sealtests = array('sealtests' => array());
     }
     return_json(true, null, 'sealtests', $sealtests['sealtests']);
 }
function authentication_forgot()
{
    global $mysqli;
    $out = array();
    $email = @$_POST['email'];
    $new_password = @$_POST['password'];
    // see if there is an entry with that email
    $stmt = $mysqli->prepare("SELECT id, email, display_name FROM users WHERE email = ?");
    $stmt->bind_param("s", $email);
    $stmt->execute();
    $stmt->store_result();
    if ($stmt->num_rows == 1) {
        $stmt->bind_result($user_id, $email, $display_name);
        $stmt->fetch();
        // if there is set the MD5 of the new password
        $password_hash = md5($new_password);
        $validation_token = authentication_generate_access_token();
        $stmt2 = $mysqli->prepare("UPDATE users SET validation_token = ?, password_new = ? WHERE `id` = ?");
        $stmt2->bind_param('ssi', $validation_token, $password_hash, $user_id);
        $stmt2->execute();
        // send an email to ask for email validation again.
        $activate_password_link = get_server_uri() . 'activate_password.php?t=' . $validation_token;
        ob_start();
        include '../email_templates/new_password.php';
        $body = ob_get_contents();
        ob_end_clean();
        enqueue_email('new_password', $email, $display_name, 'Ten Breaths Map: New Password', $body);
        $out['success'] = true;
    } else {
        $out['success'] = false;
    }
    return_json($out);
}
示例#26
0
function search_tweets($query, $itr = 0, $find_cards = FALSE, $realtime = TRUE)
{
    $search = 'search';
    $return = scrape_spit($query, $search, $find_cards, $itr, $realtime);
    return return_json($return);
}
示例#27
0
 function delete_task()
 {
     $this->task_model->delete_task($this->input->post('id'));
     return_json(array('msg' => $this->lang->line('task_deleted')));
 }
 function delete_file()
 {
     $this->administrable_table_model->delete_files_gallery($this->input->post('id'));
     return_json(array('msg' => $this->lang->line('file_deleted')));
 }
                }
                //	Latitude & Longitude
                $location['lat'] = $photo->getLocation()->getLat();
                $location['lon'] = $photo->getLocation()->getLng();
                //	Location Name
                if ($photo->getLocation()->getName()) {
                    $location['name'] = $photo->getLocation()->getName();
                }
            }
            $caption = $photo->getCaption();
            $currentMedia = array('id' => $photo->getId(), 'caption' => !empty($caption) ? $photo->getCaption()->getText() : '', 'tags' => $photo->getTags()->toArray(), 'location' => $location, 'link' => $photo->getLink(), 'image' => array('ico' => $photo->getThumbnail(), 'low' => $photo->getLowRes(), 'std' => $photo->getStandardRes()), 'created' => $photo->getCreatedTime());
            if (DEBUG) {
                //	In DEBUG mode save the user ID in the media attributes
                $currentMedia['userid'] = !empty($userId) ? $userId : '00000000';
            }
            $mediaList[] = $currentMedia;
        }
        //	Get Next pagination Id
        $max_id = $media->getNextMaxId();
    } catch (\Instagram\Core\ApiException $e) {
        $error = $_POST['error_message'];
    }
} catch (\Instagram\Core\ApiException $e) {
    if ($e->getType() == $e::TYPE_NOT_ALLOWED) {
        exit(return_json(array(), null, 'This user is PRIVATE and media cannot be accessed!'));
    } else {
        throw $e;
    }
}
exit(return_json($mediaList, $max_id, $error));
示例#30
0
文件: Api.php 项目: smtion/crowdfund
 public function get_shops()
 {
     $this->load->model('admin/shop_model', 'm', TRUE);
     $shops = $this->m->get_shops();
     return_json($shops);
 }