Location: PHPKode > projects > iLP System > Release 2.2/upload/_backend/eventtypes.php
<?php
/**
 * iLP System Offiziere Ereignisarten
 * 
 * Autor:		Florian "ApoY2k" Peschka
 * Projekt:		iLP System
 * Paket:		apoy2k.ilp.wrynn
 * Lizenz:		CreativeCommons (by-nc-sa)
 * Kontakt:		hide@address.com
 * Version:		2.1.1
 */

// Ereignisarten bearbeiten
if (!isset($tpl['url'][1]))
{
	
	// Zusätzliche Header laden
	$tpl['headincludes'][] = 'events.list';
	
	// Alle Ereignisarten suchen
	$get_types = $db->query("SELECT * FROM ilp_event_types");

	$get_events = $db->prepare("SELECT id FROM ilp_events WHERE type = ?");
	
	// Ereignisse der einzelnen Arten zählen
	while ($row = $get_types->fetch(PDO::FETCH_ASSOC))
	{
		$get_events->execute(array($row['id']));
		$row['count'] = $get_events->rowCount();
		$tpl['types'][] = $row;
	}

}

// Ereignisart erstellen
elseif (isset($tpl['url'][1]) && 'add' == $tpl['url'][1])
{
	
	if (isset($tpl['url'][2]) && 'do' == $tpl['url'][2])
	{
		
		// Prüfung der Eingaben
		if (isset($_POST['addtype_name']) && '' != $_POST['addtype_name'])
		{
			
			// Wenn ein Bild angegeben wurde, dessen Daten prüfen und ggf. hochladen
			if ('' != $_FILES['addtype_icon']['tmp_name'])
			{
				// Daten prüfen
				$icon_data = getimagesize($_FILES['addtype_icon']['tmp_name']);
				
				if (false != $icon_data)
				{
					if (10240 >= $_FILES['addtype_icon']['size'])
					{
						if (32 >= $icon_data[0] && 32 >= $icon_data[1])
						{
							// Bildnamen erstellen
							$icon_name = 'event_'.urlencode($_FILES['addtype_icon']['name']);
							$icon_file = BASEDIR_IMAGES.'/icons/'.$icon_name;
							
							// Bild hochladen
							move_uploaded_file($_FILES['addtype_icon']['tmp_name'], $icon_file)
							 or die ('cannot upload image: '.$icon_file.' – '.$_FILES['addtype_icon']['error']);
						}
						else
						{
							$tpl['error']['message'] = $lang['types']['dimension_error'];
							$tpl['error']['ref'] = 'eventtypes;add';
						}
					}
					else
					{
						$tpl['error']['message'] = $lang['types']['size_error'];
						$tpl['error']['ref'] = 'eventtypes;add';
					}
				}
				else
				{
					$tpl['error']['action'] = 'Bild hochladen';
					$tpl['error']['actor']	= $tpl['user']['login'].' – ID: '.$tpl['user']['id'];
					$tpl['error']['location'] = 'eventtypes.php:52';
					$tpl['error']['result'] = 'Fehler beim Ermitteln der Bilddaten';
					$tpl['error']['level']	= '0 (base-php)';
				}
				
			}
			
			else
			{
				$icon_name = 'event_none.png';
			}
			
			// Ereignisart erstellen
			if (isset($icon_name))
			{
				writeLog($tpl['user']['id'], $tpl['user']['id'], 'officer_create_eventtype', array('eventtype_name' => $_POST['addtype_name']));
				$db->query("INSERT INTO ilp_event_types (`name`, icon) VALUES ('".$_POST['addtype_name']."', '".$icon_name."')");
				header('Location: index.php?ilp='.ilpUrlEncode('eventtypes'));
			}
		}
		else
		{
			$tpl['error']['message'] = $lang['error']['incomplete'];
			$tpl['error']['ref'] = 'eventtypes;add';
		}
	}
	
	else
	{
		
		// Zusätzliche Header laden
		$tpl['headincludes'][] = 'eventtypes.add.form';
	}
	
}

// Ereignisart bearbeiten
elseif (isset($tpl['url'][1]) && 'edit' == $tpl['url'][1])
{
	if (isset($tpl['url'][2]) && 'do' == $tpl['url'][2])
	{
		
		// Prüfung der Eingaben
		if (isset($_POST['edittype_name']) && '' != $_POST['edittype_name'])
		{
			
			// Wenn ein Bild angegeben wurde, dessen Daten prüfen und ggf. hochladen
			if ('' != $_FILES['edittype_icon']['tmp_name'])
			{
				// Daten prüfen
				$icon_data = getimagesize($_FILES['edittype_icon']['tmp_name']);
				
				if (false != $icon_data)
				{
					if (10240 >= $_FILES['edittype_icon']['size'])
					{
						if (32 >= $icon_data[0] && 32 >= $icon_data[1])
						{
							// Bildnamen erstellen
							$icon_name = 'event_'.urlencode($_FILES['edittype_icon']['name']);
							$icon_file = 'icons/'.$icon_name;
							
							// Bild hochladen
							move_uploaded_file($_FILES['edittype_icon']['tmp_name'], BASEDIR_IMAGES.$icon_file)
							 or die ('cannot upload image to backend: '.BASEDIR_IMAGES.$icon_file);
							
							// Altes Bild löschen
							if ('event_none.png' != $_POST['edittype_old_icon'])
							{
								file_exists('../images/icons/'.$_POST['edittype_old_icon']) ? unlink('../images/icons/'.$_POST['edittype_old_icon']) : null;
							}
							
							if (!file_exists(BASEDIR_IMAGES.$icon_file))
							{
								$tpl['error']['action'] = 'Bild hochladen';
								$tpl['error']['actor'] = $tpl['user']['login'].' – ID: '.$tpl['user']['id'];
								$tpl['error']['location'] = 'eventtyes.php:156';
								$tpl['error']['result'] = 'Fehler beim Hochladen';
								$tpl['error']['level'] = '0 (base-php)';
							}
						}
						else
						{
							$tpl['error']['message'] = $lang['types']['dimension_error'];
							$tpl['error']['ref'] = 'eventtypes;edit;'.$_POST['edittype_type_id'];
						}
					}
					else
					{
						$tpl['error']['message'] = $lang['types']['size_error'];
						$tpl['error']['ref'] = 'eventtypes;edit;'.$_POST['edittype_type_id'];
					}
				}
				else
				{
					$tpl['error']['action'] = 'Bild hochladen';
					$tpl['error']['actor']	= $tpl['user']['login'].' – ID: '.$tpl['user']['id'];
					$tpl['error']['location'] = 'eventtypes.php:135';
					$tpl['error']['result'] = 'Fehler beim Ermitteln der Bilddaten';
					$tpl['error']['level']	= '0 (base-php)';
				}
				
			}
			
			else
			{
				$icon_name = $_POST['edittype_old_icon'];
			}
			
			// Ereignisart bearbeiten
			if (isset($icon_name))
			{
				$edittype = $db->prepare("UPDATE ilp_event_types SET `name` = ?, icon = ? WHERE id = ?");
				$edittype->execute(array($_POST['edittype_name'], $icon_name, $_POST['edittype_type_id']));
				
				if (1 == $edittype->rowCount() || '00000' == $edittype->errorCode())
				{
					writeLog($tpl['user']['id'], $tpl['user']['id'], 'officer_edit_eventtype', array('eventtype_id' => $_POST['edittype_type_id'], 'name' => $_POST['edittype_name']));
					header('Location: index.php?ilp='.ilpUrlEncode('eventtypes;edit;'.$_POST['edittype_type_id']));
				}
				else
				{
					$tpl['error']['action'] = 'Ereignisart bearbeiten';
					$tpl['error']['actor']	= $tpl['user']['login'].' – ID: '.$tpl['user']['id'];
					$tpl['error']['location'] = 'eventtypes.php:199';
					$tpl['error']['result'] = serialize($edittype->errorInfo());
					$tpl['error']['level']	= '0 (base-php)';
				}
			}
			else
			{
				$tpl['error']['action'] = 'Ereignisart bearbeiten';
				$tpl['error']['actor']	= $tpl['user']['login'].' – ID: '.$tpl['user']['id'];
				$tpl['error']['location'] = 'eventtypes.php:194';
				$tpl['error']['result'] = 'Bildname wurde nicht gesetzt';
				$tpl['error']['level']	= '0 (base-php)';
			}
		}
	}
	else
	{
		
		// Zusätzliche Header laden
		$tpl['headincludes'][] = 'eventtypes.edit.form';
		
		// Ereignisart suchen
		$get_type = $db->prepare("SELECT * FROM ilp_event_types WHERE id = ?");
		$get_type->execute(array($tpl['url'][2]));
		$tpl['type'] = $get_type->fetch(PDO::FETCH_ASSOC);
		
		// Ereignisse dieser Art zählen
		$get_events = $db->prepare("SELECT id FROM ilp_events WHERE type = ?");
		$get_events->execute(array($tpl['url'][2]));
		$tpl['type']['count'] = $get_events->rowCount();
	}
}

// Ereignisart löschen
elseif (isset($tpl['url'][1]) && 'delete' == $tpl['url'][1] && isset($tpl['url'][2]) && 'do' == $tpl['url'][2])
{
	
	// Prüfung, ob die Bestätigung richtig eingegeben wurde
	if ($lang['page']['delete'] == $_POST['deletetype_confirm'])
	{
		
		// Ereignisbild ermitteln und löschen
		$get_icon = $db->query("SELECT icon FROM ilp_event_types WHERE id = ".$_POST['deletetype_type_id']);
		$type = $get_icon->fetch(PDO::FETCH_ASSOC);
		
		if ('event_none.png' != $type['icon']) unlink('../images/icons/'.$type['icon']);
		
		// Ereignisart löschen
		writeLog($tpl['user']['id'], $tpl['user']['id'], 'officer_delete_eventtype', array('eventtype_id' => $_POST['deletetype_type_id']));
		$db->query("DELETE FROM ilp_event_types WHERE id = ".$_POST['deletetype_type_id']);
		header('Location: index.php?ilp='.ilpUrlEncode('eventtypes'));
	}
	else
	{
		$tpl['error']['message'] = $lang['types']['delete']['confirm']['error'];
		$tpl['error']['ref'] = 'eventtypes;edit;'.$_POST['deletetype_type_id'];
	}
}
?>
Return current item: iLP System