Location: PHPKode > projects > Content*Builder > contentbuilder/plugins/article2/artMedia.inc.php
<?php
	/*
	* Rechte überprüfen
	*/
	if($articlePerms->hasEditPermission($id) && $articlePerms->hasUploadPermission($id)) {
	
		/* Array's ausserhalb der Schleife definieren, um PHP 4.3 Bug zu verhindern */
		$typeListName = array();
		$typeListID   = array();
	
		/* Medien Sprachdateien einbinden */
		if(file_exists($lang_path.$lang_pf."/plugin/media.lang.php")) {
			include($lang_path.$lang_pf."/plugin/media.lang.php");
		} else {
			include($lang_path."en/plugin/media.lang.php");
		}
		
		$tpl->assign( "mediaMessages", $media);
		
		// Limitierung der Anzahl der Uploadboxen
		if(!empty($_REQUEST[limit]))  { $limit = $_REQUEST[limit]; }  else { $limit = 4; }
		
		// Ermittlung der Branch ID
		if(!empty($_REQUEST[bid]))  { $bid = $_REQUEST[bid]; }
	
		/*
		* Wenn Artikel ID gesetzt, auslesen und Medien ID herausfinden
		* Ansonsten Fehler, da man dann kein Medienverzeichnis zum Uploaden
		* finden kann
		*/
		$errorNoID = true;
		if(!empty($id)) {
			$articleQuery = mysql_query("SELECT * FROM ".TABLE."_art_general WHERE ide = '$id'");
			if(mysql_num_rows($articleQuery) != 0) {
				$errorNoID = false;
				$article = mysql_fetch_object($articleQuery);
			}
			
			$title   = $article->title;
			$mediaID = $article->mediaID;
			$iconID  = $article->iconID;
			
			if(empty($mediaID) || $mediaID == "0") {
				// Media Branch für Artikel bekommen
				$mediaBranch = $artOption->getSingleOption("generalMedia");
				$mediaWrite  = $myMedia->checkMediaID($mediaBranch, "art");
				if($mediaWrite) {
					$artBid = $myMedia->addSubBranch(array($mediaBranch => $title));
					$update = mysql_query("UPDATE ".TABLE."_art_general SET mediaID = '$artBid' WHERE ide = '$id'");
				}
				$mediaID = $artBid;
			}
		}
		
		if($errorNoID == true) {
			$error[] = $amError["no-id"];
		}
		
		$myMedia  = new MediaManagement();
		
		/*
		* Smarty Template für das Medien Management ableiten
		*/
		$mediaTPL = new Smarty;
		$mediaTPL->template_dir = CB_TEMPLATE_DIR;
		$mediaTPL->compile_dir  = CB_TEMPLATE_DIR."compiled/";
		
		$myMedia->mediaText = $media;
		$myMedia->setUserID($cbUserID);
		$myMedia->setLimit($limit);				
		$myMedia->setBranchID($mediaID);
		$myMedia->setOptionObject($cbOption);
		$myMedia->setTemplateObject($mediaTPL);
		
		$myMedia->tpl->assign("PHP_SELF", $PHP_SELF);
		$myMedia->tpl->assign("URLIDENT", $config['urlIdent']);
		$myMedia->tpl->assign("PLUGINLOCATION", $pluginLocation);
		$myMedia->tpl->assign("SID", "&".SID);
		$myMedia->tpl->assign("SUB", $sub);
		$myMedia->tpl->assign("BID", $branchID);
		
		if(ereg("(^[1-9]?[0-9]*$)", $mediaID) && !$error) {
			$myMedia->tpl->assign("BID", $bid);
			$myMedia->setIdBox(array("id" => $id));
					
			$tpl->assign("BID", $bid);
			$tpl->assign("ID", $id);
			
			/* Löschbefehl ans Objekt weiter geben */
			if(!empty($_POST[artdelbox])) {
				$myMedia->deleteFiles($_POST[artdelbox]);
			}
		
			/* Online / Offline Status setzen */
			$myMedia->setFileStatus($onbox, $offbox);
			
			if(isset($unmainbox)) {
				foreach($unmainbox as $k => $v) {
					$dquery = mysql_query("UPDATE ".TABLE."_art_general SET iconID = '' WHERE ide = '$id'");
				}
			}
			
			if(isset($mainbox)) {
				foreach($mainbox as $k => $v) {
					$dquery = mysql_query("UPDATE ".TABLE."_art_general SET iconID = '$v' WHERE ide = '$id'");
					$iconID = "$v";
				}
			}
			
			if ($action == "add") {
				if(empty($uploadbutton)) {
					/*
					* Upload Form ausgeben
					*/
					$myMedia->mediaTypeID = $mediaType;
					$myMedia->packUploadTemplate();
					$myMedia->tpl->assign("back_form", 
						array ( "BACKSUB"  => "artModify",
								"TXT_BACK" => $media[back]
						)
					);
					$myMedia->activateTemplate("upload_heading_set");
					$myMedia->activateTemplate("upload_title_set");
					$myMedia->activateTemplate("upload_description_set");
					$myMedia->activateTemplate("upload_keywords_set");
					$myMedia->tpl->assign("back_form_set", "1");
					$mainPluginContent[] = $myMedia->fetchTemplate("upload_form_set");
				} else {
					/*
					* Files ins Medienverzeichnis verschieben
					*/
					$myMedia->mediaTypeID = $mediaType;
					$myMedia->addFileValues(
						array ( "title"       => $_POST[title],
								"description" => $_POST[description],
								"keywords"    => $_POST[keywords]
						)
					);
					$moveResult = &$myMedia->moveFiles();
					if(is_array($moveResult)) {
						foreach($moveResult as $k => $v) {
							$error[] = $v->getMessage();
						}
					}
					$display = "overview";
				}
			} else {$display = "overview";}
			
			if(!empty($fileID)) {
				if(empty($updateButton)) {
					$myMedia->packUpdateTemplate($fileID);
					$myMedia->activateTemplate("upload_heading_set");
					$myMedia->activateTemplate("upload_title_set");
					$myMedia->activateTemplate("upload_description_set");
					$myMedia->activateTemplate("upload_keywords_set");
					$myMedia->tpl->assign("ADDITIONALID", "&id=$id");
					$mainPluginContent[] = $myMedia->fetchTemplate("update_form_set");
					$display = "nothing";
				} else {
					$myMedia->updateFileValues($fileID, 
						array ( "title"       => $_POST[title],
								"description" => $_POST[description],
								"keywords"    => $_POST[keywords]
						)
					);
					$display = "overview";
				}
			}
			
			/*
			* Übersicht aller Dateien im Medienverzeichnis ausgeben
			*/
			if($display == "overview") {
				$myMedia->mediaTypeID = $mediaType;
				foreach($myMedia->typeArray as $k => $v) {
					$typeListName[] = $v;
					$typeListID[]   = $k;
				}
				
				$iconTypeID   = $artOption->getSingleOption("iconTypeID");
				$imageTypeID  = $artOption->getSingleOption("imageTypeID");
				$generalMedia = $artOption->getSingleOption("generalMedia");
	
				$noUploads = 1;
				$fileList = array();
				$fileQuery = mysql_query("SELECT fileID, typeID, branchID, userid, filename, options, insertdate, parameter FROM ".TABLE."_mm_files WHERE branchID = '$myMedia->branchID' OR branchID = '$generalMedia' ORDER BY branchID, filename ASC");
				while($fileRow = mysql_fetch_object($fileQuery)) {
					$date = $myMedia->getDate($fileRow->insertdate);
					if(FILE_OPTION_ONLINE & $fileRow->options) { $selected = ""; } else { $selected = "checked"; }
					if($fileRow->branchID == $generalMedia) { 
						$branchType = $amText["generalBranch"]; 
					} else { 
						$branchType = $amText["articleBranch"]; 
					}
					if($fileRow->typeID == $iconTypeID) { 
						if($fileRow->fileID == $iconID) {
							$iconSelected = "checked";
						} else { 
							$iconSelected = ""; 
						}
						$typeName = "icon"; 
						$iconsFound = true;
					} else { 
						$typeName = "file"; 
						$filesFound = true;
					}
					
					$files[$typeName]['id'][]      = $fileRow->fileID;
					$files[$typeName]['name'][]    = $fileRow->filename;
					$files[$typeName]['type'][]    = $myMedia->typeArray[$fileRow->typeID];
					$files[$typeName]['user'][]    = $myMedia->userArray[$fileRow->userid];
					$files[$typeName]['date'][]    = $date;
					$files[$typeName]['bType'][]   = $branchType;
					$files[$typeName]['mainSel'][] = $iconSelected;
					$files[$typeName]['checked'][] = $selected;
					$noUploads = 0;
				} // while
				
				$tpl->assign("filetypes",
					array(  "NAME"    => $typeListName,
							"VALUE"   => $typeListID
					)
				);
				$tpl->assign("fileoverview",
					array(  "TXT_FILENAME"        => $myMedia->mediaText['fileName'],
							"TXT_FILETYPE"        => $myMedia->mediaText['typeName'],
							"TXT_UPLOADED_BY"     => $myMedia->mediaText['uploadedBy'],
							"TXT_UPLOADED_AT"     => $myMedia->mediaText['uploadedAt'],
							"TXT_BRANCH_TYPE"     => $amText["branchType"],
							"TXT_ONLINE"          => $myMedia->mediaText['online'],
							"TXT_ADD"             => $myMedia->mediaText['add'],
							"FILES_SET"           => $noUploads
					)
				);
				if($iconsFound) {
					$tpl->assign("iconListTpl_set", "1");
					$tpl->assign("iconList",
						array( "FID"               => $files['icon']['id'],
							   "NAME"              => $files['icon']['name'],
							   "TYPE"              => $files['icon']['type'],
							   "DATE"              => $files['icon']['date'],
							   "CHECKED"           => $files['icon']['checked'],
							   "BRANCH_TYPE"       => $files['icon']['bType'],
							   "MAINCHECKED"       => $files['icon']['mainSel'],
							   "BY"                => $files['icon']['user']
						)
					);
				}
				if($filesFound) {
					$tpl->assign("fileListTpl_set", "1");
					$tpl->assign("fileList",
						array( "FID"               => $files['file']['id'],
							   "NAME"              => $files['file']['name'],
							   "TYPE"              => $files['file']['type'],
							   "DATE"              => $files['file']['date'],
							   "BRANCH_TYPE"       => $files['file']['bType'],
							   "CHECKED"           => $files['file']['checked'],
							   "BY"                => $files['file']['user']
						)
					);
				}
				
				$tpl->assign("media",
					array(  "IDNAME"   => "id",
							"IDVALUE"  => $id
					)
				);
				
				$tpl->assign("back_form_set", 1);
							
				if(!$noUploads) {
					$tpl->assign("submitBox_set", "1");
				}
				$tpl->assign("fileoverview_set", "1");
				
				$mainPluginContent[]  = $tpl->fetch($config['templates']."artMedia.template", null, "pluginArt2".$cbUserID);
			}	
		}
	}
	
	if(count($error) > 0) {
		$tpl->assign("errorSet", "1");
		$tpl->assign("errorList", $error);
	}
	$mainMessageContent[] = $tpl->fetch($config['templates']."messages.template", null, "pluginArt2".$cbUserID);
?>
Return current item: Content*Builder