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;
		}
Example #2
0
	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();
	}
Example #3
0
	/**
	* Handler for accepting a new product images from the image manager or other products
	*
	* @param ISC_ADMIN_REMOTE $remote
	*/
	public function remoteUseSourceImages(ISC_ADMIN_REMOTE $remote)
	{
		GetLib('class.imagedir');
		$db = $GLOBALS["ISC_CLASS_DB"];

		$sourceImages = @$_POST['images'];

		$tags = array();
		$errors = array();
		$images = array();

		$productId = false;
		$productHash = false;

		if (isset($_POST['product'])) {
			$productId = (int)@$_POST['product'];
			if (!isId($productId) || !ProductExists($productId)) {
				$errors[] = GetLang('ProductDoesntExist');
			}
		} else if (isset($_POST['hash']) && $_POST['hash']) {
			$productHash = $_POST['hash'];
		} else {
			$errors[] = GetLang('ProductDoesntExist');
		}

		if (empty($errors) && count($sourceImages)) {
			// only proceed if they had images selected
			$imageDir = new ISC_IMAGEDIR();

			foreach ($sourceImages as $imageId) {

				if(substr($imageId, 0, strlen('productimage_')) == 'productimage_') {
					// image from another product
					$productImageId = (int)str_replace('productimage_', '', $imageId);
					$productImage = new ISC_PRODUCT_IMAGE($productImageId);
					$sourceFilePath = $productImage->getAbsoluteSourceFilePath();
					$originalFilename = $productImage->getFileName();

				} elseif (substr($imageId, 0, strlen('imagemanager_')) == 'imagemanager_') {
					// image from the image manager
					$imageManagerId = str_replace('imagemanager_', '', $imageId);
					$originalFilename = $imageDir->findFileNameById($imageManagerId);
					$sourceFilePath = $imageDir->GetImagePath() . '/' . $originalFilename;

				} else {
					// not a valid selection
					continue;
				}

				try {
					if ($productHash) {
						$image = ISC_PRODUCT_IMAGE::importImage($sourceFilePath, $originalFilename, $productHash, true, false);
					} else {
						$image = ISC_PRODUCT_IMAGE::importImage($sourceFilePath, $originalFilename, $productId, false, false);
					}
				} catch (ISC_PRODUCT_IMAGE_IMPORT_INVALIDIMAGEFILE_EXCEPTION $exception) {
					$errors[] = $url . ": " . $exception->getMessage() . ' ' . GetLang('ProductImageInvalidFileFromSource');
					continue;
				} catch (ISC_PRODUCT_IMAGE_IMPORT_EXCEPTION $exception) {
					// these exceptions should have language-powered messages so are safe to return to the user
					$errors[] = $url . ": " . $exception->getMessage();
					continue;
				} catch (Exception $exception) {
					// other unknown error
					$errors[] = $url . ': ' . GetLang('ProductImageProcessUnknownError');
					continue;
				}

				// all done, add to list of successful images
				$images[] = $image;
			}
		}

		foreach ($images as /*ISC_PRODUCT_IMAGE*/$image) {
			$json = array(
				'id' => $image->getProductImageId(),
				'product' => $image->getProductId(),
				'hash' => $image->getProductHash(),
				'preview' => $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL, true),
				'zoom' => $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_ZOOM, true),
				'description' => $image->getDescription(),
				'baseThumbnail' => $image->getIsThumbnail(),
				'sort' => $image->getSort(),
			);

			$tags[] = $remote->MakeXMLTag('image', isc_json_encode($json), true);
		}

		foreach ($errors as $message) {
			$tags[] = $remote->MakeXMLTag('error', $message, true);
		}

		$remote->SendXMLHeader();
		$remote->SendXMLResponse($tags);
		die();
	}