Location: PHPKode > projects > iLP System > Release 2.2/upload/_backend/reqs.php
<?php
/**
 * iLP System Offiziere Anfragen
 * 
 * Autor:		Florian "ApoY2k" Peschka
 * Projekt:		iLP System
 * Paket:		apoy2k.ilp.wrynn
 * Lizenz:		CreativeCommons (by-nc-sa)
 * Kontakt:		hide@address.com
 * Version:		2.1.1
 */
 
// Anfragen anzeigen
if (!isset($tpl['url'][1]))
{
	
	// Alle Anfragen suchen
	$get_reqs = $db->query("SELECT ilp_reqs.id AS req_id, ilp_reqs.type, ilp_reqs.date_sent, ilp_reqs.date_read, ilp_reqs.date_edit, ilp_reqs.sent_id, ilp_reqs.read_id, ilp_reqs.edit_id, ilp_reqs.req_values, ilp_req_types.id AS req_type_id, ilp_req_types.name AS req_type, ilp_users.char FROM ilp_reqs, ilp_req_types, ilp_users WHERE ilp_reqs.type = ilp_req_types.id AND ilp_reqs.sent_id = ilp_users.id ORDER BY ilp_reqs.date_edit DESC, ilp_reqs.date_read DESC, ilp_reqs.date_sent DESC");
	
	// Wenn Anfragen gefunden wurden, diese im Template-Array speichern
	if (0 < $get_reqs->rowCount())
	{
		while($row = $get_reqs->fetch(PDO::FETCH_ASSOC))
		{
		
			/**
			 * Statusberechnung der Anfrage
			 * Wenn sie noch nicht gelesen wurde (Feld: date_read leer) – Warteschlange
			 * Wenn sie gelesen aber noch nicht bearbeitet wurde (Feld: date_edit leer) – In Bearbeitung
			 * Wenn sie bearbeitet wurde (Felder: date_read und date_edit gefüllt) – Erledigt
			 */
			if('0000-00-00' != $row['date_read'])
			{
				if ('0000-00-00' != $row['date_edit'])
				{
					$row['status']['icon'] = '_edit';
					$row['status']['desc'] = $lang['reqs']['status']['edit'];
				}
				else
				{
					$row['status']['icon'] = '_open';
					$row['status']['desc'] = $lang['reqs']['status']['read'];
				}
			}
			else
			{
				$row['status']['icon'] = '';
				$row['status']['desc'] = $lang['reqs']['status']['sent'];
			}
						
			// Auflösung der Daten der Anfrage in ein Array, um die Anzeige zu erleichtern
			$row['req_values'] = unserialize($row['req_values']);
			
			// Charakterarray des Benutzers speichern
			$row['char'] = unserialize($row['char']);
			
			// Anfrage in Template-Engine speichern
			$tpl['reqs'][] = $row;
		}
	}
}

// Anfragedetails anzeigen & bearbeiten
elseif (isset($tpl['url'][1]) && 'edit' == $tpl['url'][1])
{
	if (isset($tpl['url'][2]) && 'do' == $tpl['url'][2])
	{
		if ('' != $_POST['editreq_message'])
		{
			
			// Anfrage als erledigt markieren
			writeLog($tpl['user']['id'], $tpl['user']['id'], 'officer_edit_req', array('req_id' => $_POST['editreq_req_id']));
			$editreq = $db->prepare("UPDATE ilp_reqs SET date_edit = CURDATE(), edit_id = ".$tpl['user']['id'].", req_answer = ? WHERE id = ".$_POST['editreq_req_id']);
			$editreq->execute(array($_POST['editreq_message']));
			
			if (1 == $editreq->rowCount())
			{
				header('Location: index.php?ilp='.ilpUrlEncode('reqs'));
			}
			else
			{
				$tpl['error']['action'] = 'Anfrage bearbeiten';
				$tpl['error']['actor']	= $tpl['user']['login'].' – ID: '.$tpl['user']['id'];
				$tpl['error']['location'] = 'reqs.php:76';
				$tpl['error']['result'] = serialize($eitreq->errorInfo());
				$tpl['error']['level']	= '0 (base-php)';
			}
		}
		else
		{
			$tpl['error']['message'] = $lang['error']['incomplete'];
			$tpl['error']['ref'] = 'reqs;edit;'.$_POST['editreq_req_id'];
		}
	}
	else
	{
		
		// Zusätzliche Header laden
		$tpl['headincludes'][] = 'reqs.edit.form';
		
		// Angegebene Anfrage suchen
		$get_req = $db->prepare("SELECT ilp_reqs.id AS req_id, ilp_reqs.date_sent, ilp_reqs.date_read, ilp_reqs.date_edit, ilp_reqs.sent_id, ilp_reqs.read_id, ilp_reqs.edit_id, ilp_reqs.req_values, ilp_reqs.req_msg, ilp_reqs.req_answer, ilp_req_types.name AS req_type_name, ilp_req_types.id AS req_type, ilp_reqs.req_values, ilp_users.char FROM ilp_reqs, ilp_req_types, ilp_users WHERE ilp_reqs.type = ilp_req_types.id AND ilp_reqs.sent_id = ilp_users.id AND ilp_reqs.id = ?");
		$get_req->execute(array($tpl['url'][2]));
		
		// Wenn eine Anfrage gefunden wurde, diese in die Template-Engine speichern
		if (1 == $get_req->rowCount())
		{
			$row = $get_req->fetch(PDO::FETCH_ASSOC);

			// Daten der Anfrage entschlüsseln
			$row['req_values'] = unserialize($row['req_values']);
			
			// Charakterarray des Benutzers entschlüsseln
			$row['char'] = unserialize($row['char']);
					
			if('0000-00-00' != $row['date_read'])
			{
				
				// Je nach Status der Anfrage die eingetragenen Benutzer-IDs suchen und deren Namen speichern
				$get_stat_name = $db->prepare("SELECT ilp_users.id, ilp_users.char FROM ilp_users, ilp_reqs WHERE ilp_reqs.read_id = ilp_users.id AND ilp_reqs.id = ?");
				$get_stat_name->execute(array($row['req_id']));
				$stat_name = $get_stat_name->fetch();
				
				$row['read_name'] = $stat_name;
				$row['read_name']['char'] = unserialize($stat_name['char']);
				$row['status'] = $lang['reqs']['status']['read'];
				
				if ('0000-00-00' != $row['date_edit'])
				{
					// Je nach Status der Anfrage die eingetragenen Benutzer-IDs suchen und deren Namen speichern
					$get_stat_name = $db->prepare("SELECT ilp_users.id, ilp_users.char FROM ilp_users, ilp_reqs WHERE ilp_reqs.edit_id = ilp_users.id AND ilp_reqs.id = ?");
					$get_stat_name->execute(array($row['req_id']));
					$stat_name = $get_stat_name->fetch();
					
					$row['edit_name'] = $stat_name;
					$row['edit_name']['char'] = unserialize($stat_name['char']);
					$row['status'] = $lang['reqs']['status']['edit'];
				}
			}
			else
			{
				$row['status'] = $lang['reqs']['status']['sent'];
				
				// Anfrage als gelesen markieren
				writeLog($tpl['user']['id'], $tpl['user']['id'], 'officer_read_req', array('req_id' => $row['req_id']));
				$db->query("UPDATE ilp_reqs SET date_read = CURDATE(), read_id = ".$tpl['user']['id']." WHERE id = ".$row['req_id']);
			}
			
			$tpl['req'] = $row;
		}
		else
		{
			$tpl['error']['action'] = 'Anfrage anzeigen';
			$tpl['error']['actor'] = $tpl['user']['login'].' – ID: '.$tpl['user']['id'];
			$tpl['error']['location'] = 'reqs.php:106';
			$tpl['error']['result'] = var_dump($get_req->errorInfo());
			$tpl['error']['level'] = '0 (base-php)';
		}
	}
}
?>
 
Return current item: iLP System