<?php
if (isset ( $_POST ['submit'] ) && $_POST ['check'] == 'payment' && $_POST ['action'] == 'multiple') {
	$userid = $db->get_row ( 'users', array ('email' => $uemail ) );
	
	$paymentvalue = $_POST ['payment'];
	if ($paymentvalue ['radio'] == '') {
		?>
<div class="hide1">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-2" class="gritter-item-wrapper gritter-warning"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">
				<div class="gritter-close" id="gritterremove"
					style="display: inline;"></div>
				<h5>Oops! Select The Radio Button..</h5>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
	} else {
		
		$multiple = $_POST ['multiple'];
		
		$paymentvalue = $_POST ['payment'];
		
		$amount = $paymentvalue ['amount'];
		
		$description = $paymentvalue ['description'];
		$date = $paymentvalue ['date'];
		$payment = $paymentvalue ['radio'];
		if (is_numeric ( $amount )) {
			
			$filename = $_FILES ['my_field'] ['name'];
			
			if ($filename [0] == "" && $filename [1] == "" && $filename [2] == "") {
				
				$querynull = $db->insert ( 'payment', array ('amount' => $amount, 'description' => $description, 'date' => $date, 'payment' => $payment, 'user_id' => $userid ['id'] ) );
				if ($querynull) {
					?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span> Your Record Is Inserted ...
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
				
				} 

				else {
					?>
<div class="hide1">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-2" class="gritter-item-wrapper gritter-warning"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">
				<div class="gritter-close" id="gritterremove"
					style="display: inline;"></div>
				<h5>Oops! There Are Some Problem In Inserted..</h5>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
				
				}
			} else {
				$query = $db->insert ( 'payment', array ('amount' => $amount, 'description' => $description, 'date' => $date, 'payment' => $payment, 'user_id' => $userid ['id'] ) );
				
				$lstid = $db->insert_id;
				
				$cli = (isset ( $argc ) && $argc > 1);
				($cli);
				if ($cli) {
					if (isset ( $argv [1] ))
						$_GET ['file'] = $argv [1];
					print_r ( $_GET ['file'] );
					if (isset ( $argv [2] ))
						$_GET ['dir'] = $argv [2];
					if (isset ( $argv [3] ))
						$_GET ['pics'] = $argv [3];
				}
				
				// set variables
				$dir_dest = (isset ( $_GET ['dir'] ) ? $_GET ['dir'] : 'uploads/files');
				$dir_pics = (isset ( $_GET ['pics'] ) ? $_GET ['pics'] : $dir_dest);
				
				if (! $cli && ! (isset ( $_SERVER ['HTTP_X_FILE_NAME'] ) && isset ( $_SERVER ['CONTENT_LENGTH'] ))) 

				{
					
					$files = array ();
					
					foreach ( $_FILES ['my_field'] as $k => $l ) {
						foreach ( $l as $i => $v ) {
							
							if (! array_key_exists ( $i, $files ))
								$files [$i] = array ();
							
							$files [$i] [$k] = $v;
						}
					}
					
					// now we can loop through $files, and feed each element to
					// the class
					foreach ( $files as $file ) {
						// we instanciate the class for each element of $file
						$name = mt_rand ( 15, 215 ) . "___" . mb_strtolower ( preg_replace ( '/\s+/', '', $file ['name'] ) );
						$file ['name'] = str_replace ( array ('(', ')' ), '', $name );
						$savedname .= $file ['name'] . ',';
						
						$handle = new upload ( $file );
						
						// then we check if the file has been uploaded properly
						// in its *temporary* location in the server (often, it
						// is /tmp)
						
						if ($handle->uploaded) {
							
							// now, we start the upload 'process'. That is, to
							// copy the uploaded file
							// from its temporary location to the wanted
							// location
							// It could be something like
							// $handle->Process('/home/www/my_uploads/');
							$handle->Process ( $dir_dest );
						}
					
					}
					
					$queryupdate = $db->update ( 'payment', array ('files' => $savedname ), array ('id' => $lstid ) );
					if ($query) {
						?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span> Your Record Is Inserted ...
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php }else{?>
<div class="hide1">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-2" class="gritter-item-wrapper gritter-warning"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">
				<div class="gritter-close" id="gritterremove"
					style="display: inline;"></div>
				<h5>Oops! There Is Some Problem In Inserted..</h5>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
					
					}
				}
			
			}
		} else {
			?>
<div class="hide1">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-2" class="gritter-item-wrapper gritter-warning"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">
				<div class="gritter-close" id="gritterremove"
					style="display: inline;"></div>
				<h5>Oops! Your Amount Is Numeric..</h5>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
		
		}
	
	}
}

?>
<?php

$id = $link->hrefquery ();

$getid = $id [1];
if (isset ( $getid )) {
	$query = $db->delete ( 'payment', array ('id' => $getid ) );
	if ($query) {
		?>
<div class="alert">
	<button type="button" class="close" data-dismiss="alert">&times;</button>
	<strong>Cheers!</strong> Record Deleted
</div>
<?php
	
	}

}
?>