예제 #1
0
 public function checkLogin()
 {
     //用户登陆检测,若成功,把登陆时间与IP插入数据库
     $verify = $this->_param('verify');
     //$_POST['verify'];
     if ($_SESSION['verify'] != md5($verify)) {
         $this->error('验证码错误!');
     }
     $admin_name = $this->_param('admin_name');
     $admin_pw = $this->_param('admin_pw');
     $m = new Model('admin');
     //查看管理员表中有没有该用户信息 注:管理员与普通用户为2个表!!!
     $where = 'user_name="' . $admin_name . '" AND password="******" AND state=0';
     $res = $m->where($where)->find();
     if (count($res) > 0) {
         //判断是否有管理员信息
         $data['last_login_ip'] = get_client_ip();
         $data['last_login_time'] = time();
         $where = 'id=' . $res['id'];
         $m->where($where)->save($data);
         session_start();
         $_SESSION['username'] = $res['user_name'];
         $_SESSION['islogin'] = 1;
         //$_SESSION['level']=2;
         $this->redirect('Index/main');
     } else {
         $this->error('密码错误或账号不存在或者已经被禁用!', U('Escape/login'));
     }
 }
예제 #2
0
 /**
 +----------------------------------------------------------
 * 根据表单生成查询条件
 * 进行列表过滤
 +----------------------------------------------------------
 * @access protected
 +----------------------------------------------------------
 * @param Model $model 数据对象
 * @param HashMap $map 过滤条件
 * @param string $sortBy 排序
 * @param boolean $asc 是否正序
 +----------------------------------------------------------
 * @return void
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 protected function _list($model, $map, $sortBy = '', $asc = false)
 {
     //排序字段 默认为主键名
     if (isset($_REQUEST['_order'])) {
         $order = $_REQUEST['_order'];
     } else {
         $order = !empty($sortBy) ? $sortBy : $model->getPk();
     }
     //取得满足条件的记录数
     $count = $model->where($map)->count('id');
     if ($count > 0) {
         import("ORG.Util.Page");
         //创建分页对象
         if (!empty($_REQUEST['listRows'])) {
             $listRows = $_REQUEST['listRows'];
         } else {
             $listRows = '';
         }
         $p = new Page($count, $listRows);
         //分页查询数据
         $voList = $model->where($map)->order("" . $order . " desc")->limit($p->firstRow . ',' . $p->listRows)->select();
         //分页跳转的时候保证查询条件
         foreach ($map as $key => $val) {
             if (!is_array($val)) {
                 $p->parameter .= "{$key}=" . urlencode($val) . "&";
             }
         }
         //分页显示
         $page = $p->show();
         //列表排序显示
         $sortImg = $sort;
         //排序图标
         $sortAlt = $sort == 'desc' ? '升序排列' : '倒序排列';
         //排序提示
         //模板赋值显示
         $this->assign('list', $voList);
         $this->assign('order', $order);
         $this->assign('sortImg', $sortImg);
         $this->assign('sortType', $sortAlt);
         $this->assign("page", $page);
     }
     $MagazineType = M("MagazineType");
     $MagazineTypeList = $MagazineType->field('id, name')->select();
     $this->assign('MagazineTypeList', $MagazineTypeList);
     $this->assign('totalCount', $count);
     $this->assign('numPerPage', C('PAGE_LISTROWS'));
     $this->assign('currentPage', !empty($_REQUEST[C('VAR_PAGE')]) ? $_REQUEST[C('VAR_PAGE')] : 1);
     Cookie::set('_currentUrl_', __SELF__);
     return;
 }
예제 #3
0
function getMsgList($parm = array())
{
    $M = new Model('member_msg');
    $pre = C('DB_PREFIX');
    $field = true;
    $orderby = " id DESC";
    if ($parm['pagesize']) {
        //分页处理
        import("ORG.Util.Page");
        $count = $M->where($parm['map'])->count('id');
        $p = new \Org\Util\Page($count, $parm['pagesize']);
        $page = $p->show();
        $Lsql = "{$p->firstRow},{$p->listRows}";
        //分页处理
    } else {
        $page = "";
        $Lsql = "{$parm['limit']}";
    }
    $data = M('member_msg')->field(true)->where($parm['map'])->order($orderby)->limit($Lsql)->select();
    $symbol = C('MONEY_SYMBOL');
    $suffix = C("URL_HTML_SUFFIX");
    foreach ($data as $key => $v) {
    }
    $row = array();
    $row['list'] = $data;
    $row['page'] = $page;
    $row['count'] = $count;
    return $row;
}
예제 #4
0
 public function index()
 {
     $Hot = new Model('Article');
     $listHot = $Hot->where("blar_status=3")->order('blar_create_time desc')->limit(5)->select();
     $this->assign('listHot', $listHot);
     $Order = new Model('Article');
     $listOrder = $Order->where("blar_status<>2")->order('blar_clicks desc, blar_create_time desc')->limit(10)->select();
     $this->assign('listOrder', $listOrder);
     $Article = new Model('Article');
     // 实例化模型类
     import("ORG.Util.Page");
     $count = $Article->where("blar_status<>2")->count();
     $Page = new Page($count, 5);
     $show = $Page->show();
     $list = $Article->where('blar_status<>2')->order('blar_create_time desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
     // 查询数据
     foreach ($list as $key => $art) {
         $blar_id = $art["blar_id"];
         $ViewArTags = new Model('view_ar_tags');
         $result = $ViewArTags->where('blar_id=' . $blar_id)->select();
         if (isset($result) && !empty($result)) {
             $art["tags"] = $result;
         }
         $list[$key] = $art;
     }
     $this->assign('list', $list);
     // 模板变量赋值
     $this->assign('page', $show);
     $this->display();
 }
예제 #5
0
 /**
  * 构造函数
  * 
  * @access public
  * @param mixed $name
  * @param mixed $password
  * @return mixed
  */
 public function __construct($name, $password)
 {
     $safebox = Safebox::getInstance();
     $manager = $safebox->get('manager');
     if (!isset($manager['id']) || $manager['id'] == '' || $manager['name'] != $name) {
         $model = new Model('manager');
         $name = Filter::sql($name);
         $user = $model->where("name='" . $name . "'")->find();
         if (!empty($user)) {
             $key = md5($user['validcode']);
             $password = substr($key, 0, 16) . $password . substr($key, 16, 16);
             if ($user['password'] == md5($password)) {
                 $this->status = 'online';
                 $this->properties = $user;
                 $safebox->set('manager', $this->properties);
             } else {
                 $this->status = 'offline';
                 $this->properties = null;
             }
         } else {
             $this->status = 'offline';
             $this->properties = null;
         }
     } else {
         $this->status = 'online';
         $this->properties = $safebox->get('manager');
     }
 }
예제 #6
0
 public function item_desc()
 {
     $where = 'type=3 AND status=1';
     $obj = new Model('t_contents');
     $res = $obj->where($where)->find();
     $this->assign('res', $res);
     $this->display();
 }
예제 #7
0
 public function proStatus()
 {
     $project_hash = _get('get.token', null, '/^[a-z0-9]{30}$/');
     if ($project_hash) {
         $obj = new Model('project');
         if ($obj->where("project_hash = '" . $project_hash . "'")->update(array('status' => '1'))) {
             echo 'ok';
         }
     }
 }
예제 #8
0
 /**
  * Perform filter for global
  * 
  * @param  array  $columns
  * @param  string $search
  * @return self
  */
 public function dtPerformGlobalFilter($columns, $search = '')
 {
     $this->dtModel = $this->dtModel->where(function ($query) use($columns, $search) {
         foreach ($columns as $column) {
             if (filter_var($column['searchable'], FILTER_VALIDATE_BOOLEAN) && !in_array($column['name'], $this->dtUnsearchable)) {
                 $query->orWhere(DB::raw($column['name']), 'LIKE', '%' . $search['value'] . '%');
             }
         }
     });
     return $this;
 }
예제 #9
0
 public static function paymentVoucher($voucherTemplate, $userID = null)
 {
     $model = new Model("voucher");
     do {
         $account = strtoupper(CHash::random(10, 'char'));
         $password = strtoupper(CHash::random(10, 'char'));
         $obj = $model->where("account = '{$account}'")->find();
     } while ($obj);
     $start_time = date('Y-m-d H:i:s');
     $end_time = date('Y-m-d H:i:s', strtotime('+' . $voucherTemplate['valid_days'] . ' days'));
     $model->data(array('account' => $account, 'password' => $password, 'name' => $voucherTemplate['name'], 'value' => $voucherTemplate['value'], 'start_time' => $start_time, 'end_time' => $end_time, 'money' => $voucherTemplate['money'], 'is_send' => 1, 'user_id' => $userID))->insert();
 }
예제 #10
0
 function listall()
 {
     $projects = new Model('project');
     @($res = $projects->field('project_name,project_desc,project_hash,time,status')->where("user_hash = '" . $_SESSION['user_hash'] . "'")->select());
     //封装数组处理
     $url = new Model('url');
     foreach ($res as $key => &$value) {
         $value['shellnum'] = $url->where("project_hash = '" . $value['project_hash'] . "'")->count();
         $value['time'] = date('Y-m-d', $value['time']);
     }
     return $res;
 }
예제 #11
0
 public function group_insert()
 {
     $data['name'] = $this->_post('name');
     $data['mem_num'] = $this->_post('mem_num');
     $data['resp'] = $this->_post('resp');
     $data['phone'] = $this->_post('phone');
     $vid = $this->get_volun_id();
     $obj = new Model('t_group');
     $res = $obj->where('resp=\'' . $vid . '\'')->find();
     if (!empty($res)) {
         //更新
         $g_id = $this->_post('g_id');
         $res2 = $obj->where('g_id=' . $g_id)->save($data);
     } else {
         $res2 = $obj->add($data);
     }
     if ($res2) {
         $this->success('组织注册成功', '__APP__/Group/group', 3);
     } else {
         $this->error('组织注册失败', '', 3);
     }
 }
예제 #12
0
 public static function write($user_id, $value, $note)
 {
     if (is_numeric($value)) {
         $model = new Model('customer');
         $customer = $model->where("user_id=" . $user_id)->find();
         if ($customer) {
             if ($value < 0) {
                 if ($customer['point'] < abs($value)) {
                     return array('status' => 'fail', 'msg' => '积分不够扣除!');
                 }
             }
             $new_point = $customer['point'] + $value;
             $model->where("user_id=" . $user_id)->data(array('point' => $new_point))->update();
             $logs = array('user_id' => $user_id, 'value' => $value, 'point' => $new_point, 'note' => $note, 'create_time' => date('Y-m-d H:i:s'));
             $model = new Model('point_log');
             $model->data($logs)->insert();
             return true;
         }
     } else {
         return array('status' => 'fail', 'msg' => '积分必需为数值。');
     }
 }
예제 #13
0
 function ajax_arclist()
 {
     $prefix = !empty($_REQUEST['prefix']) ? (bool) $_REQUEST['prefix'] : true;
     //表过滤防止泄露信息,只允许的表
     if (!in_array($_REQUEST['model'], array('article', 'type', 'ad', 'label', 'link'))) {
         exit;
     }
     if (!empty($_REQUEST['model'])) {
         if ($prefix == true) {
             $model = C('DB_PREFIX') . $_REQUEST['model'];
         } else {
             $model = $_REQUEST['model'];
         }
     } else {
         $model = C('DB_PREFIX') . 'article';
     }
     $order = !empty($_REQUEST['order']) ? inject_check($_REQUEST['order']) : '';
     $num = !empty($_REQUEST['num']) ? inject_check($_REQUEST['num']) : '';
     $where = !empty($_REQUEST['where']) ? inject_check(urldecode($_REQUEST['where'])) : '';
     //使where支持 条件判断,添加不等于的判断
     $page = false;
     if (!empty($_REQUEST['page'])) {
         $page = (bool) $_REQUEST['page'];
     }
     $pagesize = !empty($_REQUEST['pagesize']) ? intval($_REQUEST['pagesize']) : '10';
     //$query     =!empty($_REQUEST['sql'])?$_REQUEST['sql']:'';//太危险不用
     $field = '';
     if (!empty($_REQUEST['field'])) {
         $f_t = explode(',', inject_check($_REQUEST['field']));
         $f_t = array_map('urlencode', $f_t);
         $field = implode(',', $f_t);
     }
     $m = new Model($model, NULL);
     //如果使用了分页,缓存也不生效
     if ($page) {
         import("ORG.Util.Page");
         //这里改成你的Page类
         $count = $m->where($where)->count();
         $total_page = ceil($count / $pagesize);
         $p = new Page($count, $pagesize);
         //如果使用了分页,num将不起作用
         $t = $m->field($field)->where($where)->limit($p->firstRow . ',' . $p->listRows)->order($order)->select();
         //echo $m->getLastSql();
         $ret = array('total_page' => $total_page, 'data' => $t);
     }
     //如果没有使用分页,并且没有 query
     if (!$page) {
         $ret = $m->field($field)->where($where)->order($order)->limit($num)->select();
     }
     $this->ajaxReturn($ret, '返回信息', 1);
 }
예제 #14
0
 /**
  * 构造角色类,考虑到角色的修改,即时有效性,暂不考虑用Session保存
  * 
  * @access public
  * @param mixed $roles
  * @return mixed
  */
 public function __construct($roles = null)
 {
     if ($roles !== null) {
         $key = $this->name . '_' . $roles;
         $model = new Model('roles');
         $result = $model->where("id=" . $roles)->find();
         $this->roles = $result;
         //Session::set($key,$this->roles);
         /*else
         	 {
         		$this->roles=Session::get($key);
         	 }*/
     }
 }
예제 #15
0
 public function mobansave()
 {
     if (!IS_POST) {
         $this->message2('无效请求!', __APP__ . '/Admin');
     }
     $site_template = I('site_template', 'default');
     $data = array();
     $data['site_template'] = $site_template;
     $config_model = new Model('config');
     if (false !== $config_model->where('id=1')->data($data)->save()) {
         $this->message2('模板设置成功!', 'moban');
     } else {
         $this->message2('模板设置失败:' . $config_model->getError(), 'moban');
     }
 }
예제 #16
0
 /**
  * [search description]
  * @param  [type] $related  [description]
  * @param  [type] $search   [description]
  * @param  [type] $type     [description]
  * @param  [type] $field    [description]
  * @param  [type] $per_page [description]
  * @return [type]           [description]
  */
 public function search($related, $search, $type, $field, $per_page)
 {
     $sign = $type == 'equal' ? '=' : 'like';
     if ($type == 'contain') {
         $search = '%' . $search . '%';
     }
     if ($type == 'start') {
         $search = $search . '%';
     }
     if (!is_null($related)) {
         $data = array('related' => $related, 'field' => $field, 'sign' => $sign, 'search' => $search);
         return $this->model->searchHasRelated($data)->paginate($per_page);
     } else {
         return $this->model->where($field, $sign, $search)->orderBy($field, 'asc')->paginate($per_page);
     }
 }
예제 #17
0
 public function findSelectedFilter($filters, $aggregations, $model_filter)
 {
     if (!empty($model_filter)) {
         $values = array();
         $model_ranges = explode("-", $model_filter);
         foreach ($model_ranges as $model_range) {
             $models = Model::where('id', '=', $model_range);
             if ($models->count()) {
                 $title = $models->first()->model;
                 array_push($values, array("title" => $title, "index" => 'model-remove-' . $model_range));
             }
         }
         array_push($filters, array("name" => "Model", "values" => $values, "modal" => "model"));
     }
     return $filters;
 }
예제 #18
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create()
 {
     // load the create form (app/views/items/create.blade.php)
     $spares = Spare::where('state', '=', 1)->get()->toArray();
     foreach ($spares as $key => $value) {
         $spare[$value['id']] = $value['name'];
     }
     $models = Model::where('state', '=', 1)->get()->toArray();
     foreach ($models as $key => $value) {
         $model[$value['id']] = $value['name'];
     }
     $providers = Provider::where('state', '=', 1)->get()->toArray();
     foreach ($providers as $key => $value) {
         $provider[$value['id']] = $value['name'];
     }
     return View::make('itemsin.create')->with('spares', $spare)->with('models', $model)->with('providers', $provider);
 }
 function delurl()
 {
     $urlhash = _get('get.token', null, '/^[a-z0-9]{30}$/');
     if ($urlhash) {
         //获取项目token
         $obj = new Model('url');
         $tokenarr = $obj->field('project_hash')->where("url_hash = '" . $urlhash . "'")->find();
         $token = $tokenarr['project_hash'];
         //项目token查用户hash权限判断
         $buffusers = new Model('project');
         $userhash = $buffusers->field('user_hash')->where("project_hash = '" . $token . "'")->find();
         if ($userhash['user_hash'] != $_SESSION['user_hash']) {
             exit;
         }
         if ($obj->where("url_hash = '" . $urlhash . "'")->del()) {
             $this->_ajaxReturn('删除成功', 'success', 'index.php?m=project&a=listurl&token=' . $token);
         }
     }
 }
예제 #20
0
 public function article()
 {
     $id = I('id', NULL);
     if (empty($id)) {
         $this->message2('未指定文章!', 'index');
     }
     $model = new Model('article');
     $article = $model->where('id=' . $id)->find();
     if ($article['article_keyword'] != '') {
         $this->assign('seo_keyword', $article['article_keyword']);
     }
     if ($article['article_desc'] != '') {
         $this->assign('seo_desc', $article['article_desc']);
     }
     $config = M('config')->where('id=1')->find();
     $this->assign('seo_title', $article['article_name'] . '-' . $config['sitename']);
     $this->assign('article', $article);
     $this->display();
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
     $f2 = new CustomFieldset(['name' => "Asset with MAC Address"]);
     $f2->timestamps = false;
     //when this model was first created, it had no timestamps. But later on it gets them.
     if (!$f2->save()) {
         throw new Exception("couldn't save customfieldset");
     }
     $macid = DB::table('custom_fields')->insertGetId(['name' => "MAC Address", 'format' => CustomField::$PredefinedFormats['MAC'], 'element' => 'text']);
     if (!$macid) {
         throw new Exception("Can't save MAC Custom field: {$macid}");
     }
     $f2->fields()->attach($macid, ['required' => false, 'order' => 1]);
     Model::where(["show_mac_address" => true])->update(["fieldset_id" => $f2->id]);
     DB::statement("ALTER TABLE assets CHANGE mac_address _snipeit_mac_address varchar(255)");
     $ans = Schema::table("models", function (Blueprint $table) {
         $table->renameColumn('show_mac_address', 'deprecated_mac_address');
     });
 }
예제 #22
0
 public static function callerporder($order_no)
 {
     $url = 'http://192.168.1.28:8088/quanpinMIS/doAPI.iss';
     $ordermodel = new Model("order");
     $pushordermodel = new Model("push_order");
     $pushorderhismodel = new Model("push_order_his");
     $orderconet = $ordermodel->where("order_no=" . $order_no)->find();
     $pushordermodel->data(array('order_id' => $orderconet['id'], 'order_no' => $order_no, 'express_id' => 0, 'tracking_no' => null, 'push_flg' => 1, 'push_type' => 1, 'ins_dt' => Filter::str(date('Y-m-d H:i:s')), 'upd_dt' => Filter::str(date('Y-m-d H:i:s'))))->inserttoerp();
     $pushorderhismodel->data(array('order_id' => $orderconet['id'], 'order_no' => $order_no, 'express_id' => 0, 'tracking_no' => null, 'push_flg' => 1, 'push_type' => 1, 'ins_dt' => Filter::str(date('Y-m-d H:i:s')), 'upd_dt' => Filter::str(date('Y-m-d H:i:s'))))->inserttoerp();
     //        $param = array("order_no" => $order_no, "id" => $orderconet['id']);
     //        $returnVal = Http::doPost($url, $param);
     //        $returnObj = json_decode($returnVal);
     //        if ($returnObj->returnVal == "OK") {
     if (1) {
         $pushordermodel->data(array('push_flg' => 0))->where("order_no=" . $order_no)->updatetoerp();
         $pushorderhismodel->data(array('order_id' => $orderconet['id'], 'order_no' => $order_no, 'express_id' => 0, 'tracking_no' => null, 'push_flg' => 0, 'push_type' => 1, 'ins_dt' => Filter::str(date('Y-m-d H:i:s')), 'upd_dt' => Filter::str(date('Y-m-d H:i:s'))))->inserttoerp();
     } else {
         // 请求失败
     }
 }
예제 #23
0
 public function register()
 {
     $data['usrname'] = _get('post.username', null, '/[a-zA-Z0-9]{4,12}/');
     $data['usrpass'] = _get('post.password');
     //codier@qq.com
     $data['email'] = _get('post.email', null, '/^[-\\w]+@[-\\w]+(\\.[-\\w]+){0,2}(\\.\\w{0,3})$/');
     $data['time'] = time();
     //加密用户数据
     $data['user_hash'] = _md5($data['usrpass'], $data['time'], -25);
     $data['usrpass'] = _md5($data['usrpass'], 'codier', -20);
     $users = new Model('users');
     //检测用户名是否已经存在
     if ($users->where("usrname = '" . $data['usrname'] . "'")->count()) {
         $this->_ajaxReturn('用户名已存在', 'prompt');
     } else {
         if ($users->insert($data)) {
             $this->_ajaxReturn('注册成功', 'success', 'index.php?m=index&a=index');
         } else {
         }
     }
 }
예제 #24
0
 public function changeOwnerUpdate($id)
 {
     // FIND OLD VEHICLE AND CREATE RESPECTIVE LOGS
     $oldVehicle = Vehicle::find($id);
     /*
     	// IF VEHICLE STATUS IS CHANGED, ADD OLD STATUS IN LOG AND UPDATE DATA
     	if($oldVehiclesStatus != $newVehiclesStatus){
     		LogVehicleStatus::create(['log_vehicle_status_vehicle_id' => $id, 'log_vehicle_status_vehicle_status_id' => $oldVehiclesStatus]);
     	}
     
     	// IF VEHICLE COLOR IS CHANGED, ADD OLD COLOR IN LOG AND UPDATE DATA
     	if($oldvehicleColor != $newVehicleColor){
     		LogVehicleColor::create(['log_vehicle_color_vehicle_id' => $id, 'log_vehicle_color_color_id' => $oldvehicleColor]);
     	}
     
     	// IF VEHICLE USE TYPE IS CHANGED, ADD OLD USE TYPE IN LOG AND UPDATE DATA
     	if($oldVehicleUseType != $newVehicleUseType){
     		$oldRegistrations_no = $oldVehicle->registration->registrations_no;
     		LogVehicleUseType::create(['log_vehicle_use_type_vehicle_id' => $id, 'log_vehicle_use_type_use_type' => $oldVehicleUseType, 'log_vehicle_use_type_registration_no' => $oldRegistrations_no]);
     	}
     
     *
     	// TAKE LOG OF ODOMETER
     	$vehicles_odometer = trim(Input::get('vehicles_odometer'));
     	$oldOdometer = Vehicle::find($id)->vehicles_odometer;
     	LogVehicleOdometer::create(['log_vehicle_odometer_vehicle_id' => $id, 'log_vehicle_odometer_old_odometer' => $oldOdometer]);
     */
     //VEHICLE DATA
     $vehicles_year = trim(Input::get('vehicles_year'));
     $vehicles_make_id = trim(Input::get('vehicles_make_id'));
     $vehicles_name_trim = trim(Input::get('vehicles_name_trim'));
     $vehicles_name_trim_ar = explode(',', $vehicles_name_trim);
     $model_name = trim($vehicles_name_trim_ar[0]);
     if (count($vehicles_name_trim_ar) > 1) {
         $model_trim = trim($vehicles_name_trim_ar[1]);
     } else {
         $model_trim = "";
     }
     $vehicles_body = trim(Input::get('vehicles_body'));
     if ($vehicles_body == -1) {
         $vehicles_body = "";
     }
     $vehicles_weight_kg = trim(Input::get('vehicles_weight_kg'));
     // BEGIN VEHICLE
     // IF VEHICLE BODY IS NOT BLANK THEN ADD BODY, ELSE IGNORE IT TO MAKE IT NULL
     if ($vehicles_body != "") {
         $vehicle = Input::only(['vehicles_vin', 'vehicles_year', 'vehicles_make_id', 'vehicles_name_trim', 'vehicles_body', 'vehicles_weight_kg', 'vehicles_use_type', 'vehicles_use_type', 'vehicles_class', 'vehicles_color', 'vehicles_status', 'vehicles_odometer']);
     } else {
         $vehicle = Input::only(['vehicles_vin', 'vehicles_year', 'vehicles_make_id', 'vehicles_name_trim', 'vehicles_weight_kg', 'vehicles_use_type', 'vehicles_use_type', 'vehicles_class', 'vehicles_color', 'vehicles_status', 'vehicles_odometer']);
     }
     //$validator_vehicle = Validator::make($vehicle, Vehicle::$rules);
     //if($validator_vehicle->passes()){
     // GETTING AND ADDING MODEL ID
     // IF BODY IS NULL
     if ($vehicles_body == "") {
         // GETTING MODEL
         $vehicle['vehicles_model_id'] = Model::where('model_year', $vehicles_year)->where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->whereNull('model_body')->first()->id;
     } else {
         $vehicle['vehicles_model_id'] = Model::where('model_year', $vehicles_year)->where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->where('model_body', $vehicles_body)->first()->id;
     }
     // INSERT VEHICLE DATA AND GET ID
     $vehicle_inserted_id = Vehicle::create($vehicle)->id;
     //}else
     //	return Redirect::route('vehicle.create')->withErrors($validator_vehicle)->withInput();
     // END VEHICLE
     // ASSOCTIATE NEW VEHICLE AND THEN DELETE OLD VEHICLE DATA
     $old_vehicle = Vehicle::find($id);
     // ASSOCIATE NEW VEHICLE WITH OLD VEHICLE
     $old_vehicle->update(['vehicles_transfer' => $vehicle_inserted_id]);
     // DELETE INSURANCE
     if ($old_vehicle->insurance) {
         $old_vehicle->insurance->delete();
     }
     // DELETE LIEN
     if ($old_vehicle->lien) {
         $old_vehicle->lien->delete();
     }
     // DELETE REGISTRATION
     $old_vehicle->registration->delete();
     // DELETE VEHICLE
     $old_vehicle->delete();
     // BEGIN OWNERS
     $owners_index = Input::get('owners_index');
     $owners_index_arr = array_filter(explode(',', $owners_index));
     // LOOP THROUGH EACH OWNER AND ASSOCIATE WITH DRIVERS
     foreach ($owners_index_arr as $owners_index_id) {
         $drivers_license_no = Input::get('drivers_license_no' . $owners_index_id);
         if (trim($drivers_license_no) != "") {
             $drivers_status = Driver::where('drivers_license_no', $drivers_license_no)->first();
             // IF DRIVER DOESN'T EXISTS, CREATE DRIVER
             if ($drivers_status == NULL) {
                 $owner_info['drivers_fname'] = Input::get('drivers_fname' . $owners_index_id);
                 $owner_info['drivers_mname'] = Input::get('drivers_mname' . $owners_index_id);
                 $owner_info['drivers_lname'] = Input::get('drivers_lname' . $owners_index_id);
                 $owner_info['drivers_nin'] = Input::get('drivers_nin' . $owners_index_id);
                 $owner_info['drivers_license_no'] = Input::get('drivers_license_no' . $owners_index_id);
                 $owner_info['drivers_street'] = Input::get('drivers_street' . $owners_index_id);
                 $owner_info['drivers_city'] = Input::get('drivers_city' . $owners_index_id);
                 $owner_info['drivers_po_box'] = Input::get('drivers_po_box' . $owners_index_id);
                 $owner_info['drivers_country'] = Input::get('drivers_country' . $owners_index_id);
                 $owner_info['drivers_cell1'] = Input::get('drivers_cell1' . $owners_index_id);
                 $owner_info['drivers_cell2'] = Input::get('drivers_cell2' . $owners_index_id);
                 $owner_info['drivers_email'] = Input::get('drivers_email' . $owners_index_id);
                 $owner_info['drivers_driving_status'] = Input::get('drivers_driving_status' . $owners_index_id);
                 $insert_owner_into_driver_table = Driver::create($owner_info);
                 $owner_ids[] = $insert_owner_into_driver_table->id;
             } else {
                 $owner_ids[] = Driver::where('drivers_license_no', $drivers_license_no)->first()->id;
             }
         }
     }
     // LINK VEHICLE WITH OWNERS
     if (!empty($owner_ids)) {
         foreach ($owner_ids as $owner_ids_fet) {
             $owner_ids_fet = (int) $owner_ids_fet;
             //VehicleDriverOwner::create(['vehicle_driver_owners_vehicle_id' => $vehicle_inserted_id, 'vehicle_driver_owners_driver_id' => $owner_ids_fet]);
             Vehicle::find($vehicle_inserted_id)->owners()->attach($owner_ids_fet);
         }
     }
     // END OWNERS
     //BEGIN AUTHORIZED DRIVERS
     $authorized_index = Input::get('authorized_index');
     // IF AUTHORIZED DRIVERS EXIST, ASSOCIATE WITH DRIVERS.(CHECKING USING LICENSE)
     if ($authorized_index != "") {
         $authorized_index_arr = explode(',', $authorized_index);
         foreach ($authorized_index_arr as $authorized_index_id) {
             $authorized_license_no = Input::get('authorized_license_no' . $authorized_index_id);
             $authorized_status = Driver::where('drivers_license_no', $authorized_license_no)->first();
             //IF DRIVER DOESN'T EXISTS, CREATE DRIVER
             if ($authorized_status == NULL) {
                 $authorized_info['drivers_fname'] = Input::get('authorized_fname' . $authorized_index_id);
                 $authorized_info['drivers_mname'] = Input::get('authorized_mname' . $authorized_index_id);
                 $authorized_info['drivers_lname'] = Input::get('authorized_lname' . $authorized_index_id);
                 $authorized_info['drivers_nin'] = Input::get('authorized_nin' . $authorized_index_id);
                 $authorized_info['drivers_license_no'] = Input::get('authorized_license_no' . $authorized_index_id);
                 $authorized_info['drivers_street'] = Input::get('authorized_street' . $authorized_index_id);
                 $authorized_info['drivers_city'] = Input::get('authorized_city' . $authorized_index_id);
                 $authorized_info['drivers_po_box'] = Input::get('authorized_po_box' . $authorized_index_id);
                 $authorized_info['drivers_country'] = Input::get('authorized_country' . $authorized_index_id);
                 $authorized_info['drivers_cell1'] = Input::get('authorized_cell1' . $authorized_index_id);
                 $authorized_info['drivers_cell2'] = Input::get('authorized_cell2' . $authorized_index_id);
                 $authorized_info['drivers_email'] = Input::get('authorized_email' . $authorized_index_id);
                 $authorized_info['drivers_driving_status'] = Input::get('authorized_driving_status' . $authorized_index_id);
                 $insert_authorized_into_driver_table = Driver::create($authorized_info);
                 $authorized_ids[] = $insert_authorized_into_driver_table->id;
             } else {
                 $authorized_ids[] = Driver::where('drivers_license_no', $authorized_license_no)->first()->id;
             }
         }
         // LINK VEHICLE WITH AUTHORIZED DRIVERS
         foreach ($authorized_ids as $authorized_ids_fet) {
             $authorized_ids_fet = (int) $authorized_ids_fet;
             //VehicleDriverAuthorized::create(['vehicle_driver_authorized_vehicle_id' => $vehicle_inserted_id, 'vehicle_driver_authorized_driver_id' => $authorized_ids_fet]);
             Vehicle::find($vehicle_inserted_id)->authorizedDrivers()->attach($authorized_ids_fet);
         }
     }
     // END AUTHORIZED DRIVERS
     // BEGIN INSURANCE
     if (Input::get('insurances_company') != "") {
         $insurance_arr = new Insurance(Input::only('insurances_company', 'insurances_policy_no', 'insurances_exp_date', 'insurances_agent_fname', 'insurances_agent_lname', 'insurances_agent_cell', 'insurances_agent_city', 'insurances_agent_email'));
         //$insurance_arr['insurances_vehicle_id'] = $vehicle_inserted_id;
         //Insurance::create($insurance_arr);
         Vehicle::find($vehicle_inserted_id)->insurance()->save($insurance_arr);
     }
     // END INSURANCE
     // BEGIN LIEN HOLDER
     if (Input::get('lien_index')) {
         $lien_arr = new Lien(Input::only('liens_collateral_id', 'liens_collateral_value', 'liens_bank_name', 'liens_bank_branch', 'liens_bank_street', 'liens_bank_city'));
         //$lien_arr['liens_vehicle_id'] = $vehicle_inserted_id;
         //Lien::create($lien_arr);
         Vehicle::find($vehicle_inserted_id)->lien()->save($lien_arr);
     }
     // END LIEN HOLDER
     // BEGIN FILES
     $files_col = Input::file();
     $files_count = count(array_filter($files_col['files']));
     // IF FILES EXISTS
     if ($files_count) {
         foreach ($files_col['files'] as $files) {
             $filename_ar = explode('.', $files->getClientOriginalName());
             $document_ext = end($filename_ar);
             $path = public_path() . '/vehicledata/documents';
             // GENERATE RANDOM FILE NAME AND ADD EXTENSION
             $randName = md5(rand() * time());
             $document_name = $randName . '.' . $document_ext;
             // MOVE FILE AND ENTRY INTO DATABASE
             if ($files->move($path, $document_name)) {
                 //Document::create(['documents_vehicle_id' => $vehicle_inserted_id, 'documents_name' => $document_name]);
                 Vehicle::find($vehicle_inserted_id)->documents()->save(new Document(['documents_name' => $document_name]));
             }
         }
     }
     // END FILES
     // BEGIN REGISTRATION
     if (isset($vehicle_inserted_id) && $vehicle_inserted_id != "") {
         $registrations_vehicle_id = $vehicle_inserted_id;
         $registrations_no = Input::get('registrations_no');
         $registrations_licence_plate_no = Input::get('registrations_licence_plate_no');
         if ($registrations_no != "" && $registrations_licence_plate_no != "" && $registrations_vehicle_id != "") {
             $vehicles_use_type = Input::get('vehicles_use_type');
             $vehicles_class = Input::get('vehicles_class');
             if ($vehicles_use_type != "" && $vehicles_class != "") {
                 $vehicles_use_type_table_name = VehicleUseType::find($vehicles_use_type)->vehicle_use_types_table_name;
                 //REGISTRATION FEES
                 $vehicles_class_col_name = $vehicles_use_type_table_name . '_total';
                 $registrations_fees = DB::table($vehicles_use_type_table_name)->find($vehicles_class)->{$vehicles_class_col_name};
                 // INCREMENT REGISTRATION SEQUENCE
                 $vehicles_sequence_col_name = $vehicles_use_type_table_name . '_sequence';
                 $currentSequence = DB::table($vehicles_use_type_table_name)->find($vehicles_class)->{$vehicles_sequence_col_name};
                 $newSequence = $currentSequence + 1;
                 DB::table($vehicles_use_type_table_name)->where('id', $vehicles_class)->update([$vehicles_sequence_col_name => $newSequence]);
                 $registration_ar = compact('registrations_vehicle_id', 'registrations_no', 'registrations_licence_plate_no', 'registrations_fees');
                 //Registration::create($registration_ar);
                 Vehicle::find($vehicle_inserted_id)->registration()->save(new Registration($registration_ar));
                 // TAKE LOGS
                 $newVehiclesStatus = Input::get('vehicles_status');
                 $newVehicleColor = Input::get('vehicles_color');
                 $newVehicleUseType = Input::get('vehicles_use_type');
                 $newVehiclesRegistrationNo = Input::get('registrations_no');
                 $vehicles_odometer = Input::get('vehicles_odometer');
                 LogVehicleStatus::create(['log_vehicle_status_vehicle_id' => $registrations_vehicle_id, 'log_vehicle_status_vehicle_status_id' => $newVehiclesStatus]);
                 LogVehicleColor::create(['log_vehicle_color_vehicle_id' => $registrations_vehicle_id, 'log_vehicle_color_color_id' => $newVehicleColor]);
                 LogVehicleUseType::create(['log_vehicle_use_type_vehicle_id' => $registrations_vehicle_id, 'log_vehicle_use_type_use_type' => $newVehicleUseType, 'log_vehicle_use_type_registration_no' => $newVehiclesRegistrationNo]);
                 LogVehicleOdometer::create(['log_vehicle_odometer_vehicle_id' => $registrations_vehicle_id, 'log_vehicle_odometer_old_odometer' => $vehicles_odometer, 'log_vehicle_odometer_status' => 1]);
                 return Redirect::route('vehicle.print', [$registrations_vehicle_id]);
             }
         }
     } else {
         echo "Nothing is saved because fields are not filled";
         die;
     }
     // END REGISTRATION
 }
예제 #25
0
 /**
  * 根据表单生成查询条件
  * 进行列表过滤
  * @param Model $model 数据对象
  * @param HashMap $map 过滤条件
  * @param string $sortBy 排序
  * @param boolean $asc 是否正序
  */
 protected function _list($model, $map = array(), $sortBy = '', $asc = false)
 {
     //排序字段 默认为主键名
     if (!empty($_REQUEST['_order'])) {
         $order = $_REQUEST['_order'];
     } else {
         $order = !empty($sortBy) ? $sortBy : $model->getPk();
     }
     //排序方式默认按照倒序排列
     //接受 sort参数 0 表示倒序 非0都 表示正序
     if (!empty($_REQUEST['_sort'])) {
         $sort = $_REQUEST['_sort'] == 'asc' ? 'asc' : 'desc';
     } else {
         $sort = $asc ? 'asc' : 'desc';
     }
     //取得满足条件的记录数
     $count = $model->where($map)->count();
     //每页显示的记录数
     if (!empty($_REQUEST['numPerPage'])) {
         $listRows = $_REQUEST['numPerPage'];
     } else {
         $listRows = '10';
     }
     //设置当前页码
     if (!empty($_REQUEST['pageNum'])) {
         $nowPage = $_REQUEST['pageNum'];
     } else {
         $nowPage = 1;
     }
     $_GET['p'] = $nowPage;
     //创建分页对象
     import("ORG.Util.Page");
     $p = new Page($count, $listRows);
     //分页查询数据
     //$list = $model->where($map)->order($order . ' ' . $sort)->select();
     $model = D('Comment');
     $list = $model->where($map)->relation(true)->order($order . ' ' . $sort)->limit($p->firstRow . ',' . $p->listRows)->select();
     //回调函数,用于数据加工,如将用户id,替换成用户名称
     if (method_exists($this, '_tigger_list')) {
         $this->_tigger_list($list);
     }
     //分页跳转的时候保证查询条件
     foreach ($map as $key => $val) {
         if (!is_array($val)) {
             $p->parameter .= "{$key}=" . urlencode($val) . "&";
         }
     }
     //分页显示
     $page = $p->show();
     //列表排序显示
     $sortImg = $sort;
     //排序图标
     $sortAlt = $sort == 'desc' ? '升序排列' : '倒序排列';
     //排序提示
     $sort = $sort == 'desc' ? 1 : 0;
     //排序方式
     //模板赋值显示
     $this->assign('list', $list);
     $this->assign('sort', $sort);
     $this->assign('order', $order);
     $this->assign('sortImg', $sortImg);
     $this->assign('sortType', $sortAlt);
     $this->assign("page", $page);
     $this->assign("search", $search);
     //搜索类型
     $this->assign("values", $_POST['values']);
     //搜索输入框内容
     $this->assign("totalCount", $count);
     //总条数
     $this->assign("numPerPage", $p->listRows);
     //每页显多少条
     $this->assign("currentPage", $nowPage);
     //当前页码
 }
예제 #26
0
 public function where($condition, $parse = null)
 {
     if (is_array($condition)) {
         $condition = array_merge(array('appid' => $this->oApp['id'], 'status' => 0), $condition);
     }
     return parent::where($condition, $parse);
 }
 /**
  +----------------------------------------------------------
 * 根据表单生成查询条件
 * 进行列表过滤
  +----------------------------------------------------------
 * @access protected
  +----------------------------------------------------------
 * @param Model $model 数据对象
 * @param HashMap $map 过滤条件
 * @param string $sortBy 排序
 * @param boolean $asc 是否正序
  +----------------------------------------------------------
 * @return void
  +----------------------------------------------------------
 * @throws ThinkExecption
  +----------------------------------------------------------
 */
 protected function _list($model, $map, $sortBy = '', $asc = false)
 {
     //排序字段 默认为主键名
     if (isset($_REQUEST['_order'])) {
         $order = $_REQUEST['_order'];
     } else {
         $order = !empty($sortBy) ? $sortBy : $model->getPk();
     }
     //排序方式默认按照倒序排列
     //接受 sost参数 0 表示倒序 非0都 表示正序
     if (isset($_REQUEST['_sort'])) {
         $sort = $_REQUEST['_sort'] ? 'asc' : 'desc';
     } else {
         $sort = $asc ? 'asc' : 'desc';
     }
     //取得满足条件的记录数
     $count = $model->where($map)->count('id');
     if ($count > 0) {
         import("@.ORG.Util.Page");
         //创建分页对象
         if (!empty($_REQUEST['listRows'])) {
             $listRows = $_REQUEST['listRows'];
         } else {
             $listRows = '';
         }
         $p = new Page($count, $listRows);
         //分页查询数据
         $voList = $model->where($map)->order("`" . $order . "` " . $sort)->limit($p->firstRow . ',' . $p->listRows)->select();
         //echo $model->getlastsql();
         //分页跳转的时候保证查询条件
         foreach ($map as $key => $val) {
             if (!is_array($val)) {
                 $p->parameter .= "{$key}=" . urlencode($val) . "&";
             }
         }
         //分页显示
         $page = $p->show();
         //列表排序显示
         $sortImg = $sort;
         //排序图标
         $sortAlt = $sort == 'desc' ? '升序排列' : '倒序排列';
         //排序提示
         $sort = $sort == 'desc' ? 1 : 0;
         //排序方式
         //模板赋值显示
         $this->assign('list', $voList);
         $this->assign('sort', $sort);
         $this->assign('order', $order);
         $this->assign('sortImg', $sortImg);
         $this->assign('sortType', $sortAlt);
         $this->assign("page", $page);
     }
     cookie('_currentUrl_', __SELF__);
     return;
 }
 /**
  * 
  * 分页方法
  * @param $Model 数据库对象
  * @param $num 每页的数据条数
  * @param $where 选择数据的条件
  * @param $field 选择的字段
  * @param $data_list 模板中数据集的变量名
  * @param $show_list 模板中分类的变量名
  * @param $error_info 读取失败或结果为空时的模板变量
  * $param $join 
  */
 protected function pagingList(Model $Model, $num, $where, $field, $data_list, $show_list, $error_info, $join, $order)
 {
     if (empty($order)) {
         //$order="ctime";
     }
     import('ORG.Util.Page');
     $count = $Model->where($where)->count();
     $Page = new Page($count, $num);
     $show = $Page->show();
     $Model->query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION'");
     $list = $Model->where($where)->field($field)->order($order)->join($join)->limit($Page->firstRow . ',' . $Page->listRows)->select();
     //
     $Page->setConfig("", $value);
     if ($list) {
         //dump($list);
         //dump($show);
         //dump($Model->getLastSql());
         $this->assign($data_list, $list);
         // 赋值数据集
         $this->assign($show_list, $show);
         // 赋值分页输出
     } elseif (is_null($list)) {
         //dump($Model->getLastSql());
         $this->assign($error_info, "记录为空!");
     } else {
         //dump($Model->getLastSql());
         $this->assign($error_info, "读取错误!");
     }
 }
예제 #29
0
 public function setAccess()
 {
     $role_id = I('role_id');
     $access = I('access');
     //print_r($access);exit;
     $m = new Model('admin_access');
     $m->where('role_id=' . $role_id)->delete();
     $data = array();
     foreach ($access as $val) {
         $arr = explode('_', $val);
         $data[] = array('role_id' => $role_id, 'node_id' => $arr[0], 'level' => $arr[1]);
     }
     if ($m->addAll($data)) {
         $this->alert_jump('配置成功', U('Admin/access', array('id' => $role_id)));
     } else {
         $this->alert_back('配置失败');
     }
 }
예제 #30
0
 public function first($field, $value)
 {
     return $this->model->where($field, $value)->first();
 }