php Data Validation Processing of all business rules such as save to D

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/***
Data Validation
Processing of all business rules such as save to Database through Persistent Object or Redirect to first Page
***/
//www.phpro.org/tutorials/Model-View-Controller-MVC.html\\
if (isset($_POST['par'])) {
//checkout after popup window opened and submit is pressed
include_once 'checkout_timetolive_after_SB.inc.php';
}
else if (isset($_POST['continue'])) {
$validator = new validator();
$validation = $validator->validation($_POST);
if ($validation==0) {
$row = array();
$time = time();
/**
* The following format does not work
* Should check later $preferences_EB2 = new preferences_EB();
*/
$preferences_EB = new preferences_EB('guests');
$preferences_EB2 = new preferences_EB('guests_preferences');
foreach ($_POST[SET2] as $pref_key => $pref_value) {
$batch = array();
/**
* To check if name1 and name2 is empty then do not save
*/
if (!(empty($pref_value['name1']) && empty($pref_value['name2']))) {
$arr = split('_', $pref_key);
$batch['create_datetime'] = $time;
$batch['activity_id'] = $activity_id;
$batch['partner_id'] = $arr[0];
$batch['cr_id'] = $arr[1];
$batch['uid'] = $arr[2];
foreach ($pref_value as $storage_key => $storage_value) {
$batch[$storage_key] = $storage_value;
}
} //if empty
print '<pre>';
print_r($batch);
/**
* To check if record already exists
*/
$prefs_check = $preferences_EB->check_Record($activity_id);
if ($prefs_check) {
$buffer['activity_id'] = $activity_id;
$buffer['partner_id'] = $arr[0];
$buffer['cr_id'] = $arr[1];
$buffer['uid'] = $arr[2];
$result = $preferences_EB->update_Selected_Composite($batch, $buffer);
$guests_id = $preferences_EB->read_guests_id($arr);
/**
* deletes guests_preferences record
* for current guest record
*/
if ($guests_id) {
$preferences_EB2->remove_guest_preferences('guests_id', $guests_id);
}
}
else {
print 'here';
print '<pre>';
print_r($batch);
$guests_id = $preferences_EB->save_Record($batch);
}
/**
* save into guests_preferences table
* if prefs array has records
*/
if ($guests_id && isset($pref_value['prefs'])) {
foreach ($pref_value['prefs'] as $p_key => $p_val) {
$prefs['guests_id'] = $guests_id;
$prefs['preference'] = $p_key;
$gd_id = $preferences_EB2->save_Record($prefs);
}
}
} //foreach $_POST[SET2]
exit;
/**
* reset some session variables
* which is not used any more before continuing
*/
unset($_SESSION[SET2]['continue']);
unset($_SESSION[SET2]['provisions']);
unset($_SESSION[SET2]['errors']);
unset($_SESSION[PLATFORM]['preferences_err_messages']);
$valid = true;
}
else {
$_SESSION[SET2]['continue'] = false;
$_SESSION[SET2]['provisions'] = $validator->provisions;
$_SESSION[SET2]['errors'] = $validator->errors;
$_SESSION[PLATFORM]['preferences_err_messages'] = ERR_TERM_1;
$valid = false;
}
// checkout time-to-live business logic
include_once 'checkout_timetolive_engine_SB.inc.php';
}
$LoggerManager->log('info', '"router information" "method referrer validation" "'.$method.' '.$referrer.' '.$validation);
$router = new router();
$forwarder = $router->delegate($method, $referrer, $validation);
header("Location: ".$forwarder.".php");
?>