我想获得一些帮助,进行一个foreach循环,该循环将帮助每个用户执行下面的完整php代码。
1-这是变量
<?php
include('config.php');
header('Content-Type:text/json;charset=utf-8');
ini_set("error_reporting","E_ALL & ~E_NOTICE");
// $check receive value 1,2 or for
// 1 = reschedule (reschedule time / date / coach / place)
// 2 = delete (delete the class into contract)
// 3 = cancel
//Init Value when you get the value from the calendar
$init_element = $_POST['init_element'];
$init_date = $_POST['init_date'];
$init_starttime = $_POST['init_starttime'];
$init_endtime = $_POST['init_endtime'];
$init_coachname = $_POST['init_coachname'];
$init_place = $_POST['init_place'];
//Value to process the data after selected from popup
$element = $_POST['element']; // POST 合同,快课预定了,快课为预定
$check = $_POST['check']; // POST 1 for reschedule , 2 for delete , 3 for cancel
$id = $_POST['id']; // id of the contract, fastclass pay or fastclass
$contract_id = $_POST['contract_id']; // contract_id get from contract_buffer table for contract
$companyname = $_POST['companyname'];
$date = $_POST['date']; // the date to modify
$start_time = $_POST['start_time']; // the start time to modify
$end_time = $_POST['end_time']; // end time to modify
$time = $starttime.'-'.$endtime;
$place = $_POST['place']; // place to modify
$coachname = $_POST['coachname']; // coachname to modify
$username_grab = $_POST['username'];
$username = implode(",", $username_grab);
$repeat = $_POST['repeat']; // POST 1 when repeat is ticking , 0 if it's empty
$returnValue = array();
2-下面的代码是我想循环的
if (!empty($init_date)){
$sql = "select * from contract_buffer where username = '$username' and coachname = '$init_coachname' and date = '$init_date' and start_time = '$init_starttime' and end_time = '$init_endtime'"; // get element times for substraction
$res = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($res)){
$init_cid = $row['contract_id'];
}
//---------------------------------------------------------------------------------------- Process contract rescheduled with repeat ok
if ($element == 合同){
if ($check == 1){
if ($repeat == 1){
if(!empty($init_cid)){
$sql2 = "UPDATE contract_buffer
SET start_time = '$start_time' , end_time = '$end_time' , coachname = '$coachname' , place = '$place'
WHERE contract_id = '$init_cid' and date >= '$init_date'";
mysqli_query($conn, $sql2);
$returnValue['status'] = "200";
$returnValue["message"] = "Success! All your class have been rescheduled from the date you have mentionned";
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "Sorry a problem have been detected when you try repeat reschuling. Error"." ".$init_cid;
}
//---------------------------------------------------------------------------------------- Process contract rescheduled without repeat ok
}else{
if(!empty($init_cid)){
$sql3 = "UPDATE contract_buffer
SET date = '$date' , start_time = '$start_time' , end_time = '$end_time' , coachname = '$coachname' , place = '$place'
WHERE contract_id = '$init_cid' and date = '$init_date'";
mysqli_query($conn, $sql3);
$returnValue['status'] = "200";
$returnValue["message"] = "Success! The class for"." ".$username." ".$init_cid." "."have been rescheduled.";
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "username = ".$username." "."coachname = ".$init_coachname." "."date = ".$init_date." "."start time = ".$init_starttime." "."end time = ".$init_endtime;
}
}
//---------------------------------------------------------------------------------------- Process with deleting contract class ok
}elseif ($check == 2) {
if(!empty($init_cid)){
$sql4 = "select * from contruct where str = '$init_cid'"; // take of one class to the times counts ok
$res4 = mysqli_query($conn,$sql4);
while($row = mysqli_fetch_array($res4)){
$times_up = $row["times"];
$times = $times_up - 1;
$condition = 1;
// update number of time into contruct table
$sql5 = "UPDATE contruct
SET times = '$times'
WHERE str = '$init_cid'";
mysqli_query($conn, $sql5);
}
//---------------------------------------------------------------------------------------- Process deleting class after counting ok
if($condition == 1){
$sql6 = "DELETE FROM contract_buffer WHERE username = '$username' and coachname = '$init_coachname' and date = '$init_date' and start_time = '$init_starttime' and end_time = '$init_endtime'";
mysqli_query($conn, $sql6);
$returnValue['status'] = "200";
$returnValue['message'] = "Sucess your class have been deleted";
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "Sorry your class can be delete. Please check with administrator at ";
}
//---------------------------------------------------------------------------------------- Return check problem if have condition 2 isn't properly verified ok
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "Sorry server problem won't return value. Please check with administrator at ";
}
//---------------------------------------------------------------------------------------- Process for cancel and add 7 days contract ok
}else{
if(!empty($init_cid)){
$sql7 = "select * from contruct where str = '$init_cid'";
$res7 = mysqli_query($conn,$sql7);
while($row = mysqli_fetch_array($res7)){
$e_date = $row["end_date"];
$convert_date = strtotime($e_date);
$days = 7;
$final = ($days * 84600) + 84600;
$end_init = $convert_date + $final;
$end_date = gmdate("Y-m-d", $end_init);
$sql8 = "select MAX(date) as maxdate from contract_buffer where contract_id = '$init_cid'"; // get the max date to be store
$res8 = mysqli_query($conn,$sql8);
while($row = mysqli_fetch_array($res8)){
$mxdate = $row['maxdate'];
$mxdate_7 = date('Y-m-d', strtotime($mxdate. ' + 7 days')); // add the 7 days to the last one
}
}
//---------------------------------------------------------------------------------------- Process for update the date + 7days
if(!empty($init_cid)){
$sql9 = "UPDATE contract_buffer
SET date = '$mxdate_7'
WHERE username = '$username' and coachname = '$init_coachname' and date = '$init_date' and start_time = '$init_starttime' and end_time = '$init_endtime'";
mysqli_query($conn, $sql9);
$returnValue['status'] = "200";
$returnValue["message"] = "Update 7 days have been worked.";
$control = 1;
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "Update of the max date doesn't work. Please check with administrator at ";
}
//---------------------------------------------------------------------------------------- Process for change status of buffer class for not showing
if($control == 1){
$sql10 = "UPDATE contruct
SET end_date = '$end_date'
WHERE str = '$init_cid'";
mysqli_query($conn, $sql10);
$returnValue['status'] = "200";
$returnValue['message'] = "Class have been successfully rescheduled 7 days after the end date.";
$status = 0;
if(!empty($init_cid)){
$sql11 = "UPDATE contract_buffer
SET status = '$status'
WHERE username = '$username' and coachname = '$init_coachname' and date = '$init_date' and start_time = '$init_starttime' and end_time = '$init_endtime'";
mysqli_query($conn, $sql11); // to check something here maybe shall more attention when tested
$returnValue['status'] = "200";
$returnValue["message"] = "Success! your class have been canceled";
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "Your class can't be canceled. Please check with administrator at ";
}
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "haven't been canceled - Server problem. Please check with administrator at ";
}
//---------------------------------------------------------------------------------------- Process for showing if class can't cancel
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "Sorry your class can be canceled. Please check with administrator at ";
}
}
//---------------------------------------------------------------------------------------- Process for rescheduled pay fastclass ok
}elseif ($element == 快课预定了) {
if ($check == 1){
if(!empty($id)){
$sql12 = "UPDATE user_fast_class
SET date = '$date' , startime = '$start_time' , endtime = '$end_time' , coachname = '$coachname'
WHERE id = '$id'";
mysqli_query($conn, $sql12);
$status = 200;
//----------------------------------------------------------------------------------------
if ($status = 200){
$sql20 = "select * from company_fast_class where coachname = '$init_coachname' and date = '$init_date' and start_time = '$init_starttime' and end_time = '$init_endtime' and place = '$init_place'";
$res20 = mysqli_query($conn,$sql20);
while($row = mysqli_fetch_array($res20)){
$f_price = $row['price'];
$f_type = $row['type'];
$f_numbers = $row['numbers'];
$f_publishtime = date("Y-m-d");
}
$sql21 = "insert into company_fast_class(company_name,coachname,date,start_time,end_time,price,type,publish_time,numbers,place)
values('$companyname','$coachname','$date','$start_time','$end_time','$f_price','$f_type','$f_publishtime','$f_numbers','$place')";
mysqli_query($conn, $sql21);
//---------------------------------------------------------------------------------------- fetch fastclass id to modify row
$sql22 = "select * from company_fast_class where coachname = '$coachname' and date = '$date' and start_time = '$start_time' and end_time = '$end_time' and place = '$place'";
$res22 = mysqli_query($conn,$sql22);
while($row = mysqli_fetch_array($res22)){
$f_id = $row['id'];
}
//---------------------------------------------------------------------------------------- update in the final tab
$sql23 = "UPDATE user_fast_class
SET fastclass_id = '$f_id'
WHERE id = '$id'";
mysqli_query($conn, $sql23);
$returnValue['status'] = "200";
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "No value returned. Please check with administrator at ";
}
$returnValue['status'] = "200";
$returnValue["message"] = "successfully operated"." ".$f_id;
//----------------------------------------------------------------------------------------
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "Sorry the booking fastclass can't be rescheduled. Please check with administrator at ";
}
//---------------------------------------------------------------------------------------- Process for delete pay fastclass ok
}elseif ($check == 2) {
if(!empty($id)){
$sql13 = "DELETE FROM user_fast_class WHERE id = '$id'";
mysqli_query($conn, $sql13);
$returnValue['status'] = "200";
$returnValue["message"] = "The paid fastclass have been successfully deleted";
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "Sorry the booking fastclass can't be deleted. Please check with administrator at ";
}
//---------------------------------------------------------------------------------------- Process for cancel pay fastclass ok
}else{
if(!empty($id)){
$sql9 = "DELETE FROM user_fast_class WHERE id = '$id'";
mysqli_query($conn, $sql9);
$returnValue['status'] = "200";
$returnValue["message"] = "The paid fastclass have been successfully canceled";
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "Sorry the booking fastclass can't be canceled. Please check with administrator at ";
}
}
//---------------------------------------------------------------------------------------- Process for reschedule unpay fastclass ok
}else{
if ($check == 1){
if (!empty($id)){
$sql14 = "UPDATE company_fast_class
SET date = '$date' , start_time = '$start_time' , end_time = '$end_time' , coachname = '$coachname' , place = '$place'
WHERE id = '$id'";
mysqli_query($conn, $sql14);
$returnValue['status'] = "200";
$returnValue["message"] = "Success your the fastclass have been rescheduled";
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "Sorry something wrong happened when rescheluded the fastclass. Please check with administrator at ";
}
//---------------------------------------------------------------------------------------- Process for delete unpay fastclass ok
}elseif ($check == 2) {
if (!empty($id)){
$sql15 = "DELETE FROM company_fast_class WHERE id = '$id'";
mysqli_query($conn, $sql15);
$returnValue['status'] = "200";
$returnValue["message"] = "The fastclass have been successfully deleted";
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "Sorry something wrong happened when deleted the fastclass. Please check with administrator at ";
}
//---------------------------------------------------------------------------------------- Process for cancel unpay fastclass ok
}else{
if (!empty($id)){
$sql16 = "DELETE FROM company_fast_class WHERE id = '$id'";
mysqli_query($conn, $sql16);
$returnValue['status'] = "200";
$returnValue["message"] = "The fastclass have been successfully canceled";
}else{
$returnValue['status'] = "400";
$returnValue["message"] = "Sorry something wrong happened when canceled the fastclass. Please check with administrator at ";
}
}
}
//---------------------------------------------------------------------------------------- process if the first condition have been not respected ok
}else{
$returnValue['status'] = "400";
$returnValue['message'] = "Please fill all the form";
}
echo json_encode($returnValue);
?>
代码进入我的日历,显示不同类型的类。当人们想要管理班级和预定班级的用户时。他们可以在弹出窗口中选择用户,然后执行重新计划,取消或删除。我可以为一个用户做,但是如果我选择多个用户,我就做不到。
感谢您的帮助
致谢