public function index()
    {
        if (!Input::has('page')) {
            $pageNum = 1;
        } else {
            $pageNum = (int) Input::get('page');
        }
        $admin_id = Auth::admin()->get()->id;
        $arrCategories = [];
        $name = '';
        $take = $this->take;
        $skip = floor(($pageNum - 1) * $take);
        $images = VIImage::select('id', 'name', 'short_name', 'description', 'keywords', 'artist', 'model', 'gender', 'age_from', 'age_to', 'number_people', DB::raw('(SELECT COUNT(*)
																							FROM notifications
																				         	WHERE notifications.item_id = images.id
																				         		AND notifications.item_type = "Image"
																								AND notifications.admin_id = ' . $admin_id . '
																								AND notifications.read = 0 ) as new'))->withType('main')->with('categories')->with('collections');
        if (Input::has('categories')) {
            $arrCategories = (array) Input::get('categories');
            $images->whereHas('categories', function ($query) use($arrCategories) {
                $query->whereIn('id', $arrCategories);
            });
        }
        if (Input::has('name')) {
            $name = Input::get('name');
            $nameStr = '*' . $name . '*';
            $images->search($nameStr);
        }
        $images = $images->take($take)->skip($skip)->orderBy('id', 'desc')->get();
        $arrImages = [];
        if (!$images->isempty()) {
            $arrImages = $arrRemoveNew = [];
            foreach ($images as $image) {
                $image->path = URL . '/pic/large-thumb/' . $image->short_name . '-' . $image->id . '.jpg';
                $image->dimension = $image->width . 'x' . $image['height'];
                if ($image->new) {
                    $arrRemoveNew[] = $image->id;
                }
                $arrImages[$image->id] = $image;
                foreach (['arrCategories' => ['name' => 'categories', 'id' => 'id'], 'arrCollections' => ['name' => 'collections', 'id' => 'id']] as $key => $value) {
                    $arr = [];
                    foreach ($image->{$value}['name'] as $v) {
                        $arr[] = $v[$value['id']];
                    }
                    $arrImages[$image->id][$key] = $arr;
                }
                unset($arr);
            }
            if (!empty($arrRemoveNew)) {
                Notification::whereIn('item_id', $arrRemoveNew)->where('item_type', 'Image')->where('admin_id', $admin_id)->update(['read' => 1]);
            }
        }
        if (Request::ajax()) {
            return $arrImages;
        }
        $this->layout->title = 'Images';
        $this->layout->content = View::make('admin.images-all')->with(['images' => $arrImages, 'pageNum' => $pageNum, 'categories' => Category::getSource(), 'name' => $name, 'arrCategories' => $arrCategories, 'collections' => Collection::getSource(), 'apiKey' => Configure::getApiKeys()]);
    }