public function action_search_blog()
 {
     $auth = Auth::check();
     if ($auth and is_numeric(AUTHORID)) {
         //LOAD JS LIBS
         Asset::container('footer')->add('ias', 'bundles/cms/js/jquery.ias.js', 'jquery');
         Asset::container('footer')->add('blogs', 'bundles/cms/js/sections/blogs_list.js', 'cms');
         if (Input::has('q')) {
             $q = Input::get('q');
             $this->layout->header_data = array('title' => $q);
             $this->layout->top_data = array('search' => '/cms/blog/search', 'q' => $q);
             // CHECK IF DATE
             if (substr_count($q, '/') >= 2) {
                 // CHECK IF DATE RANGE
                 if (substr_count($q, '/') == 4 and substr_count($q, ' ') == 1) {
                     $date_arr = explode(' ', $q);
                     $from = date2Db($date_arr[0]) . ' 00:00:00';
                     $to = date2Db($date_arr[1]) . ' 23:59:59';
                     // FROM DATE $from TO DATE $to
                     $data = CmsBlog::with('user')->where_lang(LANG)->where('datetime_on', '>=', $from)->where('datetime_on', '<=', $to)->order_by('datetime_on', 'asc')->order_by('name', 'asc')->order_by('slug', 'asc')->order_by('title', 'asc')->paginate(Config::get('cms::settings.pag'));
                 } else {
                     // FROM DATE XX
                     $data = CmsBlog::with('user')->where_lang(LANG)->where('datetime_on', 'LIKE', date2Db($q) . '%')->order_by('datetime_on', 'asc')->order_by('name', 'asc')->order_by('slug', 'asc')->order_by('title', 'asc')->paginate(Config::get('cms::settings.pag'));
                 }
             } else {
                 //GET PAGE DATA
                 $data = CmsBlog::with('user')->where_lang(LANG)->where('name', 'LIKE', '%' . $q . '%')->or_where('slug', 'LIKE', '%' . $q . '%')->or_where('title', 'LIKE', '%' . $q . '%')->order_by('datetime_on', 'asc')->order_by('name', 'asc')->order_by('slug', 'asc')->order_by('title', 'asc')->paginate(Config::get('cms::settings.pag'));
             }
             $this->layout->content = View::make('cms::interface.pages.blog_list')->with('data', $data)->with('lang', '');
         } else {
             $this->layout->header_data = array('title' => LL('cms::title.blogs', CMSLANG));
             $this->layout->top_data = array('search' => '/cms/blog/search', 'q' => '');
             //GET PAGE DATA
             $data = CmsBlog::with('user')->where_lang(LANG)->order_by('updated_at', 'desc')->order_by('created_at', 'desc')->paginate(Config::get('cms::settings.pag'));
             $this->layout->content = View::make('cms::interface.pages.blog_list')->with('data', $data)->with('lang', LANG);
         }
     }
 }
 public function post_save_banner()
 {
     $auth = Auth::check();
     if ($auth) {
         $input = Input::get();
         //GRAB DATA
         $banner = new CmsBanner();
         if (!empty($input['banner_id'])) {
             $banner = CmsBanner::find($input['banner_id']);
         }
         //VALIDATION CHECK
         $rules = array('banner_name' => 'required|alpha_dash|between:2,20|unique_lang:' . $input['banner_id'] . ',' . $input['banner_lang'] . ',banners,name');
         $messages = array('required' => LL('cms::validation.required', CMSLANG)->get(), 'between' => LL('cms::validation.between.string', CMSLANG)->get(), 'alpha_dash' => LL('cms::validation.alpha_dash', CMSLANG)->get(), 'unique_lang' => LL('cms::validation.unique', CMSLANG)->get());
         $validation = Validator::make($input, $rules, $messages);
         if ($validation->fails()) {
             return json_encode($validation->errors);
         }
         $banner->name = strtolower($input['banner_name']);
         $banner->lang = $input['banner_lang'];
         $banner->save();
         //DELETE CACHE
         if (CACHE) {
             Cache::forget('img_banner_' . strtolower($input['banner_name']));
         }
         $bid = $banner->id;
         if (Input::get('file_id') !== '') {
             $files = Input::get('file_id');
             $url = Input::get('url');
             $date_off = Input::get('date_off');
             $is_blank = Input::get('is_blank', array());
             if (is_array($files)) {
                 // Empty template
                 $template = '';
                 foreach ($files as $key => $fid) {
                     $check = DB::table('files_banners')->where_cmsfile_id($fid)->where_cmsbanner_id($bid)->first();
                     $blank = array_key_exists($key, $is_blank) ? 1 : 0;
                     if (empty($date_off[$key])) {
                         $off_date = dateTimeFuture(date("Y-m-d H:i:s"), 'P5Y');
                     } else {
                         $off_date = date2Db(substr($date_off[$key], 0, 10));
                     }
                     if (empty($check)) {
                         $add_array = array('url' => $url[$key], 'date_off' => $off_date, 'is_blank' => $blank, 'order_id' => 1000000);
                         $banner->files()->attach($fid, $add_array);
                     } else {
                         $update_array = array('url' => $url[$key], 'date_off' => $off_date, 'is_blank' => $blank);
                         DB::table('files_banners')->where_cmsfile_id($fid)->where_cmsbanner_id($bid)->update($update_array);
                     }
                     $img = CmsFile::find($fid);
                     // Template returned
                     $template .= '<li id="' . $bid . '_' . $fid . '" class="span1">';
                     $template .= '<a class="thumbnail fancy" rel="tooltip" data-original-title="' . $img->name . '" href="' . BASE . $img->path . '">';
                     $template .= '<img src="' . BASE . $img->thumb . '" />';
                     $template .= '</a>';
                     $template .= '</li>';
                 }
                 //DELETE NOT IN
                 DB::table('files_banners')->where_cmsbanner_id($bid)->where_not_in('cmsfile_id', $files)->delete();
             }
             $response = 'success';
             $msg = LL('cms::ajax_resp.banner_save_success', CMSLANG)->get();
             $backurl = $input['back_url'];
             // Inject container
             $inject = 'ul.sortable';
             $detach = true;
         } else {
             //DELETE ALL GALLERY_ID
             DB::table('files_banners')->where_cmsbanner_id($bid)->delete();
             $response = 'success';
             $msg = LL('cms::ajax_resp.banner_save_success', CMSLANG)->get();
             $backurl = $input['back_url'];
             $template = '';
             $inject = '';
             $detach = true;
         }
     } else {
         $response = 'error';
         $msg = LL('cms::ajax_resp.banner_save_error', CMSLANG)->get();
         $backurl = '#';
         $template = '';
         $inject = '';
         $detach = true;
     }
     $data = array('auth' => $auth, 'cls' => 'banner_id', 'id' => $bid, 'response' => $response, 'message' => $msg, 'backurl' => $backurl, 'detach' => $detach, 'inject' => $inject, 'template' => $template);
     return json_encode($data);
 }