Location: PHPKode > projects > Wombat Open Source > wombat/calendar/cal_events_edit_action.php
<?
/* 
		WOMBAT Open Source
		Small business simple project management and customer relation management tool.

		Version		:
		Last Update	:

		Copyright (C) 2001-2003 Outdare Internet Service B.V.

		Wombat is free software; you can redistribute it and/or modify it 
		under the terms of the GNU General Public License as published by the 
		Free Software Foundation; either version 2 of the License, 
		or (at your option) any later version.

		Wombat is distributed in the hope that it will be useful, 
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
		See the GNU General Public License for more details.
		(LICENSE file)

		You should have received a copy of the GNU General Public License 
		along with this program; if not, write to :

		Free Software Foundation, Inc., 
		59 Temple Place, Suite 330,
		Boston, MA 02111-1307 USA

		File Description : Sumbit/process changes made to project into the Database.
		
*/
include("../inc/local.inc.php");
include("../inc/wombat.inc.php");

	
if(isset($_POST['add_ppl']))
	$lb_add = true;
else
	$lb_add = false;

if(isset($_POST['del_ppl']))
	$lb_del = true;
else
	$lb_del = false;
	
@$event_type = $_POST['event_type'];
@$description = $_POST['desc'];
@$startdate = $_POST['startdate'];
@$starttime = $_POST['starttime'];
@$public = $_POST['pub'];
@$duration = $_POST['duration'];
@$subject = $_POST['subject'];
@$event_id = $_POST['event_id'];
@$fs_min = $_POST['fs_min'];
@$fs_hour = $_POST['fs_hour'];
@$fs_day = $_POST['fs_day'];
@$fs_month = $_POST['fs_month'];
@$fs_year = $_POST['fs_year'];
@$fs_author = $_POST['fs_author'];
@$emp_id = $gs_tdrn_id;
@$del_these = $_POST['del_these'];
@$add_these = $_POST['add_these'];
@$rec = $_POST['rec'];
@$counter = $_POST['counter'];
@$apply_change = $_POST['apply_change'];
#processing data


@$la_date = explode('-', $startdate);
@$startdate1 = $la_date[2].'-'.$la_date[1].'-'.$la_date[0];
#@$norm_date = $la_date[0].'-'.$la_date[1].'-'.$la_date[2];


$timestamp1 = date('Y-m-d H:i:s', mktime($fs_hour,$fs_min,0,$la_date[1],$la_date[0],$la_date[2]));
$start_time = mktime($fs_hour,$fs_min,0,$la_date[1],$la_date[0],$la_date[2]);
$end_time = $start_time+($duration *3600);

$timestamp2 = date('Y-m-d H:i:s', $end_time);

if(isset($event_id)&&$apply_change == "")
{
	?>
	<script> alert("Please specify how the changes should be applied to this reccuring event") 
	history.back()
	</script>
	<?
}
else 
{

	if (!isset($event_id))
	{
		if($rec >0)
		{
			for($i=0;$i<$counter;$i++)
			{
				$ls_events = "INSERT INTO cal_events (subject) VALUES ('$subject')";
				$li_resultevents = do_sql($ls_events);
				$event_id[$i] = mysql_insert_id();
			}
			for($i=0;$i<$counter;$i++)
			{
				$ls_adduser = "INSERT INTO assign_event (emp_id, event_id) VALUES ($gs_tdrn_id, ".$event_id[$i].")";
				$li_add = do_sql($ls_adduser);
			}

			$ls_add_events = "INSERT INTO reccurence (event_id, rec_type) VALUES (".$event_id[0].", $rec)";
			$li_add = do_sql($ls_add_events);
			$rec_id = mysql_insert_id();

			for($i=1;$i<$counter;$i++)
			{
				$ls_add_events = "INSERT INTO reccurence (rec_id, event_id, rec_type) VALUES (".$rec_id." , ".$event_id[$i].", $rec)";
				$li_add = do_sql($ls_add_events);
			}

		}
		else
		{
			$ls_events = "INSERT INTO cal_events (subject) VALUES ('$subject')";
			$li_resultevents = do_sql($ls_events);
			$event_id = mysql_insert_id();
			$ls_adduser = "INSERT INTO assign_event (emp_id, event_id) VALUES ($gs_tdrn_id, $event_id)";
			$li_add = do_sql($ls_adduser);
		}
	}



	if($rec == 1)
	{	
	
		if($apply_change == 1)
		{
			$group_rec_id = do_sql("SELECT rec_id FROM reccurence where event_id = $event_id");
			$group_rec_id_array = mysql_fetch_array($group_rec_id);
			$grouprec_id = $group_rec_id_array['rec_id'];
			$group_ids_sql = "Select event_id from reccurence where rec_id =$grouprec_id ";
			$group_ids_ex = do_sql($group_ids_sql);		
		
			$timestamp = mktime($fs_hour,$fs_min,0,$la_date[1],$la_date[0],$la_date[2]);
			$timest = $timestamp;
			while($group_ids=mysql_fetch_array($group_ids_ex))
			{   if($group_ids['event_id'] >= $event_id)
				{
					$ls_project = "UPDATE cal_events SET  start='$timestamp1', end='$timestamp2' WHERE id = '".$group_ids['event_id']."'";
					do_sql($ls_project);
					$timest = $timest + (3600*24);
					$timestamp1 = date('Y-m-d H:i:s', $timest);
					$end_time = $timest+($duration * 3600);
					$timestamp2 = date('Y-m-d H:i:s', $end_time);
				}
				$ls_project = "UPDATE cal_events SET eventtype='$event_type', emp_id='$emp_id', description='$description', public='$public', subject='$subject', author='$fs_author', occurences ='$rec' WHERE id = '".$group_ids['event_id']."'";
				do_sql($ls_project);
		  	}	
		
		
		}
		else
		{
			if($apply_change == 0)
			{
				$ls_project = "UPDATE cal_events SET eventtype='$event_type', emp_id='$emp_id', description='$description', start='$timestamp1', end='$timestamp2', public='$public', subject='$subject', author='$fs_author', occurences ='$rec'  WHERE id = '$event_id'";
				do_sql($ls_project);		
			}
			else
			{
				$timestamp = mktime($fs_hour,$fs_min,0,$la_date[1],$la_date[0],$la_date[2]);
				$timest = $timestamp;
				for($count=0;$count<$counter;$count++)
				{
					$ls_project = "UPDATE cal_events SET eventtype='$event_type', emp_id='$emp_id', description='$description', start='$timestamp1', end='$timestamp2', public='$public', subject='$subject', author='$fs_author', occurences ='$rec' WHERE id = '".$event_id[$count]."'";
			
					do_sql($ls_project);

					$timest = $timest + (3600*24);
					$timestamp1 = date('Y-m-d H:i:s', $timest);
					$end_time = $timest+($duration * 3600);
					$timestamp2 = date('Y-m-d H:i:s', $end_time);
		  		}
			}
		}
	}
	else 
	{	if($rec == 2)
		{		
			if($apply_change == 1)
			{
				$group_rec_id = do_sql("SELECT rec_id FROM reccurence where event_id = $event_id");
				$group_rec_id_array = mysql_fetch_array($group_rec_id);
				$grouprec_id = $group_rec_id_array['rec_id'];
				$group_ids_sql = "Select event_id from reccurence where rec_id =$grouprec_id ";
				$group_ids_ex = do_sql($group_ids_sql);		
		
				$timestamp = mktime($fs_hour,$fs_min,0,$la_date[1],$la_date[0],$la_date[2]);
				$timest = $timestamp;
				while($group_ids=mysql_fetch_array($group_ids_ex))
				{
					if($group_ids['event_id'] >= $event_id)
					{
						$ls_project = "UPDATE cal_events SET start='$timestamp1', end='$timestamp2' WHERE id = '".$group_ids['event_id']."'";
						do_sql($ls_project);
						$timest = $timest + (3600*24*7);
						$timestamp1 = date('Y-m-d H:i:s', $timest);
						$end_time = $timest+($duration * 3600);
						$timestamp2 = date('Y-m-d H:i:s', $end_time);
		  			}	
					$ls_project = "UPDATE cal_events SET eventtype='$event_type', emp_id='$emp_id', description='$description', public='$public', subject='$subject', author='$fs_author', occurences ='$rec' WHERE id = '".$group_ids['event_id']."'";
					do_sql($ls_project);
				}		
			}
			else
			{
				if($apply_change == 0)
				{
					$ls_project = "UPDATE cal_events SET eventtype='$event_type', emp_id='$emp_id', description='$description', start='$timestamp1', end='$timestamp2', public='$public', subject='$subject', author='$fs_author', occurences ='$rec'  WHERE id = '$event_id'";
					do_sql($ls_project);	
				}
				else
				{			
					$timestamp = mktime($fs_hour,$fs_min,0,$la_date[1],$la_date[0],$la_date[2]);
					$timest = $timestamp;
					for($count=0;$count<$counter;$count++)
					{	if(isset($event_id1))
						$ls_project = "UPDATE cal_events SET eventtype='$event_type', emp_id='$emp_id', description='$description', start='$timestamp1', end='$timestamp2', public='$public', subject='$subject', author='$fs_author', occurences ='$rec' WHERE id = '".$event_id1[$count]."'";
						else 
						$ls_project = "UPDATE cal_events SET eventtype='$event_type', emp_id='$emp_id', description='$description', start='$timestamp1', end='$timestamp2', public='$public', subject='$subject', author='$fs_author' , occurences ='$rec' WHERE id = '".$event_id[$count]."'";
						do_sql($ls_project);

						$timest = $timest + (3600*24*7);
						$timestamp1 = date('Y-m-d H:i:s', $timest);
						$end_time = $timest+($duration * 3600);
						$timestamp2 = date('Y-m-d H:i:s', $end_time);
					}
				}
			}
		}
		else
		{
			$ls_project = "UPDATE cal_events SET eventtype='$event_type', emp_id='$emp_id', description='$description', start='$timestamp1', end='$timestamp2', public='$public', subject='$subject', author='$fs_author', occurences ='$rec'  WHERE id = '$event_id'";
			do_sql($ls_project);
		}	
	}
	
	
	
	if($lb_add)
	{	if($rec>0)
		{   	if($apply_change == 1) //if we have to change all the reccuring sets
				{	
				
					if(is_array($add_these))
					{
						$group_rec_id = do_sql("SELECT rec_id FROM reccurence where event_id = $event_id");
						$group_rec_id_array = mysql_fetch_array($group_rec_id);
						$grouprec_id = $group_rec_id_array['rec_id'];
						$group_ids_sql = "Select event_id from reccurence where rec_id =$grouprec_id ";
						$group_ids_ex = do_sql($group_ids_sql);				
				
						while (list ($key, $tdrn_id) = each ($add_these)) 
						{	while($group_ids = mysql_fetch_array($group_ids_ex))
							{	$ls_assign = "INSERT INTO assign_event (emp_id, event_id) VALUES ($tdrn_id, ".$group_ids['event_id'].")";
								$li_resultassign = do_sql( $ls_assign);
							}	
						}				
					}
				}
				else
				{
					if($apply_change == 0)
					{	
						if(is_array($add_these))
						{
							while (list ($key, $tdrn_id) = each ($add_these)) 
							{	$ls_assign = "INSERT INTO assign_event (emp_id, event_id) VALUES ($tdrn_id, $event_id)";
								$li_resultassign = do_sql( $ls_assign);
							}
						}
					}
					else
					{	
						if(is_array($add_these))
						{
							while (list ($key, $tdrn_id) = each ($add_these)) 
							{	
								for($a=0;$a<$counter;$a++)
								{	
									$ls_assign = "INSERT INTO assign_event (emp_id, event_id) VALUES ($tdrn_id, ".$event_id[$a].")";
									$li_resultassign = do_sql( $ls_assign);
								}	
							}		
						}	
					}
				}
			
		}
		else
		{
			if(is_array($add_these))
			{
				while (list ($key, $tdrn_id) = each ($add_these)) 
				{
					$ls_assign = "INSERT INTO assign_event (emp_id, event_id) VALUES ($tdrn_id, $event_id)";
					$li_resultassign = do_sql( $ls_assign);
				}
			}
		}
	}
	

	
	if ($lb_del)
	{	
		if($rec>0)
		{   
			if(is_array($del_these))
			{	
				if($apply_change == 1) //if we have to change all the reccuring sets
				{	$group_rec_id_del = do_sql("SELECT rec_id FROM reccurence where event_id = $event_id");
					$group_rec_id_array_del = mysql_fetch_array($group_rec_id_del);
					$grouprec_id_del = $group_rec_id_array_del['rec_id'];
					$group_ids_sql_del = "Select event_id from reccurence where rec_id =$grouprec_id_del ";
					$group_ids_ex_del = do_sql($group_ids_sql_del);				
				
					while (list ($key, $tdrn_id) = each ($del_these))
					{	#echo "test"." ";
						while($group_ids_del = mysql_fetch_array($group_ids_ex_del)) 
						{	
							#echo $group_ids_del['event_id']." ";
							#echo $tdrn_id." ";
							$ls_assign = "DELETE FROM assign_event WHERE event_id = '".$group_ids_del['event_id']."' and emp_id = '$tdrn_id'";
							$li_resultassign = do_sql( $ls_assign);
						}	
					}				
				}
				else
				{
					if($apply_change == 0)
					{	while (list ($key, $tdrn_id) = each ($del_these)) 
						{	$ls_assign = "DELETE FROM assign_event WHERE event_id = '$event_id' and emp_id = '$tdrn_id'";
							$li_resultassign = do_sql( $ls_assign);
						}
					}
					else
					{	while (list ($key, $tdrn_id) = each ($del_these)) 
						{	for($a=0;$a<$counter;$a++)
							{	$ls_assign = "DELETE FROM assign_event WHERE event_id = '".$event_id[$a]."' and emp_id = '$tdrn_id'";
								$li_resultassign = do_sql( $ls_assign);
							}	
						}			
					}
				}
			}
		}
		else
		{
			if(is_array($del_these))
			{
				while (list ($key, $tdrn_id) = each ($del_these)) 
				{
				$ls_assign = "DELETE FROM assign_event WHERE event_id = '$event_id' and emp_id = '$tdrn_id'";
				$li_resultassign = do_sql( $ls_assign);
				}
			}
		}
	}
	

	$ls_message="<br>";
	$ls_message .= $words['cal_ev_edited'];

	$_SESSION['message'] = $ls_message;
	
	if(is_array($event_id))
		header("Location:cal_events_edit.php?event_id=$event_id[0]");
	else
		header("Location:cal_events_edit.php?event_id=$event_id");
}

?>
Return current item: Wombat Open Source