Location: PHPKode > scripts > GalleryShuffle > v1.0/php/Views/pictures.php
<?php

/**
* PICTURES
**/

class view_pictures extends view_classicView
{
	
	public function getAll()
	{
		
		$model_buffer = $this->model->getAll();
		if($model_buffer) {
		
			$buffer = $this->getPicturesFromModel($model_buffer);
			
		}else{
		
			$buffer = '
						<p class="empty">' . $this->LANG->traduc['warningNoPictures'] . '</p>';
			
		}
		
		$helpContent = '
						<p class="pictureCount">' . count($model_buffer) . ' ' . $this->LANG->traduc['pictures'] . '</p>
						<p class="key">' . $this->LANG->traduc['helpPicturesKey'] . '</p>
						<p class="drag">' . $this->LANG->traduc['helpPicturesDrag'] . '</p>';
		
		return $this->getPanel($buffer, NULL, NULL, $helpContent, 'panelPictures');
		
	}
	
	public function getAllFromAlbum($id)
	{
		
		$buffer = '';
		
		$model_buffer = $this->model->getAllFromAlbum($id);
		if($model_buffer) {
		
			$buffer = $this->getPicturesFromModel($model_buffer);
			
		}else{
		
			$buffer = '
						<p class="empty">' . $this->LANG->traduc['warningNoPicturesInAlbum'] . '</p>';
			
		}
		
		$btnAddHref = FUNCTIONS::getAjaxRequest('pictures_create', 'popup');
		$helpContent = '<p class="pictureCount">' . count($model_buffer) . ' ' . $this->LANG->traduc['pictures'] . ' - <a href="' . FUNCTIONS::getAjaxRequest('pictures_list', 'panel_pictures') . '">' . $this->LANG->traduc['seeAll'] . $this->LANG->traduc['pictures'] . '</a></p><p class="key">' . $this->LANG->traduc['helpPicturesKey'] . '</p><p class="drag">' . $this->LANG->traduc['helpPicturesDrag'] . '</p>';
		
		return $this->getPanel($buffer, $this->LANG->traduc['addPictures'], $btnAddHref, $helpContent, 'panelPictures');
		
	}
	
	public function getPopupUpload()
	{
		
		return $this->getPopup($this->LANG->traduc['uploadPictures'], NULL, '<canvas class="imageSmallBuffer"></canvas><canvas class="imageLargeBuffer"></canvas><div class="fileUploader"><p>' . $this->LANG->traduc['uploadPicturesDropHere'] . '</p></div>');
		
	}
	
	private function getPicturesFromModel($model_buffer)
	{
		
		$buffer = '';
		
		foreach($model_buffer as $key => $value){
			
			$buffer .= $this->getPicture($value['ID'], $value['name'], $value['UID']);
			
		}
		
		return $buffer;
		
	}
	
	public function getPictureById($id)
	{
		$model_buffer = $this->model->getLineById($id);
		return $this->getPicture($id, $model_buffer['name'], $model_buffer['UID']);
		
		return $buffer;
		
	}
	
	private function getPicture($id, $name, $uid)
	{
	
		return '
						<div id="picture_' . $id . '" onmousedown="javascript: panelPictures.pictureStartDrag(event);" onclick="javascript: panelPictures.pictureClick(event); ' . FUNCTIONS::getAjaxRequestEval('pictures_edit:' . $id, 'panel_options') . '"><table><tr><td><img src="' . CONFIG::picturesFolder . 'index.php?img=' . CONFIG::picturesSmallFolder . $uid . CONFIG::picturesExtension . '"/><p>' . FUNCTIONS::troncString($name, 15) . '</p><a href="' . FUNCTIONS::getAjaxRequest('pictures_large:' . $id, 'popup') . '">' . $uid . CONFIG::picturesExtension . '</a></td></tr></table></div>';
			
		
	}
	
	public function getEditForm($id) 
	{
		
		$model_buffer = $this->model->getLineById($id);
		$uid = uniqid();
		
		$imageDimensions = getimagesize(CONFIG::picturesFolder . CONFIG::picturesLargeFolder . $model_buffer['UID'] . CONFIG::picturesExtension);
		$imageSize = round(filesize(CONFIG::picturesFolder . CONFIG::picturesLargeFolder . $model_buffer['UID'] . CONFIG::picturesExtension) / 1000);
		$imageSizeUnit = "Ko";
		if($imageSize >= 1000){
			$imageSize = round($imageSize / 1000, 2);
			$imageSizeUnit = "Mo";
		}
		
		$buffer = '
					<table id="picture_form_' . $uid . '"><tr>
						<td>
							<label for="picture_title_' . $uid . '">' . $this->LANG->traduc['title'] . ' :</label><input name="title" id="picture_title_' . $uid . '" size="30" value="' . $model_buffer['name'] . '"/>
						</td>
						<td>
							<p><b>' . $this->LANG->traduc['dimensions'] . ' : </b>' . $imageDimensions[0] . 'x' . $imageDimensions[1] . '&nbsp;px</p><p><b>' . $this->LANG->traduc['size'] . ' : </b>' . $imageSize . '&nbsp;' . $imageSizeUnit . '</p>
						</td>
						<td class="horizontalMargin">&nbsp;</td>
						<td class="btnSave" onClick="' . FUNCTIONS::getAjaxRequest('pictures_editfinish:' . $id, 'panel_pictures', 'picture_form_' . $uid) . '">' . $this->LANG->traduc['save'] . '</td>
						<td class="btnTrash" onClick="' . FUNCTIONS::getAjaxRequest('pictures_delete:' . $id, 'popup') . '">&nbsp;</td>
					</tr></table>';
		
		return $buffer;
		
	}
	
	public function getMultipleEditForm($ids){
		
		$buffer = '
					<table><tr>
						<td class="imageList cellTableHorizontalScrolls"><div class="horizontalScroll"><table><tr>';
					
		foreach($ids as $key => $value){
		
			$modelBuffer = $this->model->getLineById($value);
			
			$buffer .= '
							<td><img title="' . $modelBuffer['name'] . '" src="' . CONFIG::picturesFolder . 'index.php?img=' . CONFIG::picturesSmallFolder . $modelBuffer['UID'] . CONFIG::picturesExtension . '" /><p>' . $modelBuffer['name'] . '</p></td>';
						
		}	
		
		$buffer .= '
						</tr></table></div></td>
						<td class="btnTrash" onClick="' . FUNCTIONS::getAjaxRequest('pictures_multipledelete', 'popup') . '">&nbsp;</td>
					</tr></table>';
		
		return $buffer;
	
	}
	
	public function getPopupDelete($id) 
	{
		
		$model_buffer = $this->model->getLineById($id);
		
		$subject = $this->LANG->traduc['warningDeletePictureSubject'] . '"' . $model_buffer['name'] . '" ?';
		$text = '<img src="' . CONFIG::picturesFolder . 'index.php?img=' . CONFIG::picturesSmallFolder . $model_buffer['UID'] . CONFIG::picturesExtension . '" />';
		$btnHref = FUNCTIONS::getAjaxRequestEval('pictures_deletefinish:' . $id, 'panel_pictures');
		
		return $this->getPopup($subject, $text, NULL, $this->LANG->traduc['delete'], $btnHref);
	
	}
	
	public function getPopupMultipleDelete() 
	{
	
		$btnHref = FUNCTIONS::getAjaxRequestEval('pictures_multipledeletefinish', 'panel_pictures');
		
		return $this->getPopup($this->LANG->traduc['warningMultipleDeletePictureSubject'], NULL, NULL, $this->LANG->traduc['delete'], $btnHref);
	
	}
	
	public function getPopupLargeImage($id) 
	{
		
		$model_buffer = $this->model->getLineById($id);
		
		$text = '<img class="popupLargeImage" src="' . CONFIG::picturesFolder . 'index.php?img=' . CONFIG::picturesLargeFolder . $model_buffer['UID'] . CONFIG::picturesExtension . '" />';
		
		return $this->getPopup($model_buffer['name'], $text);
	
	}
	
}

?>
Return current item: GalleryShuffle