private function View() { $GLOBALS['BreadcrumEntries'][GetLang('ManageImages')] = 'index.php?ToDo=manageImages'; // Display within the template $this->template->Assign('PageTitle', 'Manage Images'); $this->template->Assign('PageIntro', 'ManageCatIntro'); $this->template->Assign('CreateItem', 'CreateCategory'); $this->template->Assign('DisplayFilters', 0); $this->template->Assign('MaxFileSize', GetMaxUploadSize()); $currentPage = max((int)@$_GET['page'], 1); if(isset($_GET['perpage'])){ $perPage = (int)$_GET['perpage']; }elseif(isset($_SESSION['imageManagerPagingPerPage']) && (int)$_SESSION['imageManagerPagingPerPage'] > 0){ $perPage = (int)$_SESSION['imageManagerPagingPerPage']; }elseif(isset($_COOKIE['imageManagerPagingPerPage']) && (int)$_COOKIE['imageManagerPagingPerPage'] > 0){ $perPage = (int)$_COOKIE['imageManagerPagingPerPage']; }else{ $perPage = ITEMS_PER_PAGE; } $validSort = array("name.asc", "name.desc", "modified.asc", "modified.desc", "size.asc", "size.desc"); $sortby = ''; if(isset($_GET['sortby'])){ $sortby = $_GET['sortby']; }elseif(isset($_SESSION['imageManagerSortBy'])){ $sortby = $_SESSION['imageManagerSortBy']; }elseif(isset($_COOKIE['imageManagerSortBy'])){ $sortby = $_COOKIE['imageManagerSortBy']; } if(empty($sortby) || !in_array($sortby, $validSort, true)){ $sortby = 'name.asc'; } setcookie('imageManagerSortBy', $sortby, time()+(60*60*24*365), '/'); $_SESSION['imageManagerSortBy'] = $sortby; $sortBits = explode('.', $sortby); $sortField = $sortBits[0]; $sortDirection = $sortBits[1]; $this->template->Assign('Sort'.ucfirst(isc_strtolower($sortField)).ucfirst(isc_strtolower($sortDirection)), "selected=\"selected\""); setcookie('imageManagerPagingPerPage', $perPage, time()+(60*60*24*365), '/'); $_SESSION['imageManagerPagingPerPage'] = $perPage; $imageDir = new ISC_IMAGEDIR($sortDirection, $sortField); $dirCount = $imageDir->CountDirItems(); if($imageDir->CountDirItems() == 0){ $this->template->Assign('hasImages', false); }else{ $this->template->Assign('hasImages', true); } $imageDir->sortField = $sortField; $imageDir->sortDirection = $sortDirection; if ($perPage > 0) { $imageDir->start = ($perPage * $currentPage) - $perPage; $imageDir->finish = ($perPage * $currentPage); } $numPages = 1; if ($perPage == 0) { $this->template->Assign('PerPageAllSelected', "selected=\"selected\""); } else { $numPages = ceil($dirCount / $perPage); $this->template->Assign('paging', $this->GetNav($currentPage, $dirCount, $perPage)); $this->template->Assign('PerPage'.$perPage.'Selected', "selected=\"selected\""); } $this->template->Assign('PageNumber', $currentPage); $this->template->Assign('sessionid', SID); // authentication checks the token stored in the cookie, however the flash uploader doesn't send cookies so we need to store the token in the session and then retrieve it $_SESSION['STORESUITE_CP_TOKEN'] = $_COOKIE['STORESUITE_CP_TOKEN']; if ($numPages > 1) { $this->template->Assign('ImagesTitle', sprintf(GetLang('imageManagerCurrentImages'), $imageDir->start+1, min($imageDir->finish, $dirCount), $dirCount)); } else { $this->template->Assign('ImagesTitle', sprintf(GetLang('imageManagerCurrentImagesSingle'), $dirCount, $dirCount)); } // generate list of images $images = $imageDir->GetImageDirFiles(); $imagesList = ""; foreach ($images as $image) { $image_name = isc_html_escape($image['name']); $image_size = isc_html_escape(Store_Number::niceSize($image['size'])); $imagesList .= sprintf("AdminImageManager.AddImage('%s', '%s', '%s', '%s', '%s', '%s', '%s');\n", isc_html_escape($image['name']), isc_html_escape($image['url']), isc_html_escape(Store_Number::niceSize($image['size'])), $image['width'], $image['height'], $image['origheight'] . " x " . $image['origwidth'], $image['id'] ); } $this->template->Assign("imagesList", $imagesList); $this->template->Assign("sessionid", session_id()); if (!empty($images)) { $this->template->Assign('hideHasNoImages', 'none'); } else { $this->template->Assign('hideImages', 'none'); } $this->engine->PrintHeader(); $this->template->display('imgman.view.tpl'); $this->engine->PrintFooter(); }
private function getSourceImageManager() { GetLib('class.json'); GetLib('class.imagedir'); if(isset($_GET['page'])) { $currentPage = (int)$_GET['page']; } else { $currentPage = 1; } $perPage = 10; $start = ($currentPage * $perPage) - $perPage; $paging = ''; $message = ''; $imageDir = new ISC_IMAGEDIR(); $dirCount = $imageDir->CountDirItems(); if($imageDir->CountDirItems() == 0){ ISC_JSON::output(GetLang('ProductImagesNoImagesImageManager'), true, array('images' => array(), 'paging' => $paging,)); die(); } if ($perPage > 0) { $imageDir->start = ($perPage * $currentPage) - $perPage; $imageDir->finish = ($perPage * $currentPage); } $numPages = ceil($dirCount / $perPage); $search = ''; if(isset($_GET['searchterm']) && !empty($_GET['searchterm'])) { $search = $_GET['searchterm']; } // generate list of images $images = $imageDir->GetImageDirFiles(); $imagesList = ""; foreach ($images as $image) { $imageName = $image['name']; if ($search && strpos($imageName, $search) === false) { // if search term is provided and does not match name continue; } if(strlen($imageName) > 21) { $imageName = isc_substr($imageName, 0, 21) . '...'; } $returnImages[] = array( 'url' => 'uploaded_images/' . $image['name'], 'id' => 'imagemanager_' . md5($image['name']), 'productname' => isc_html_escape($imageName), 'zoom' => $image['url'], 'zoomwidth' => $image['width'], 'zoomheight' => $image['height'], 'thumbwidth' => $image['width'] * 0.65, 'thumbheight' => $image['height'] * 0.65, ); } if($dirCount > $perPage) { $pagingUrl = 'remote.php?remoteSection=products&w=getsourceimagemanager'; if($search) { $pagingURL .= "&searchterm=" . urlencode($search); } $paging = sprintf("(%s %d of %d) ", GetLang('Page'), $currentPage, $numPages); $paging .= BuildPagination($dirCount, $perPage, $currentPage, $pagingUrl); } ISC_JSON::output($message, true, array('images' => $returnImages, 'paging' => $paging, /*'query' => $query*/ )); exit; }