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
| <?php
if ( empty(session_id()) ) session_start();
if ( !defined('DIR_ROOT') )
{
define('DIR_ROOT', $_COOKIE['dir_root']);
}
require_once(DIR_ROOT.'defines.php');
require_once(DIR_ROOT.COMMON_HEAD_PHP);
require_once(DIR_ROOT.MODEL);
if ( !isset($_SESSION['user']['id_subscrib'], $_SESSION['user']['id_user']) )
{
header('Location: '.URL_SITE.INDEX_PAGE);
exit;
}
use moimp\ErrorHandler\ErrorHandler;
use moimp\InputsCtl\InputsCtl;
$objErrors = new ErrorHandler('errors', 'error0');
$objControls= new InputsCtl();
// For easier writing in the restscript
$subscribId = $_SESSION['user']['id_subscrib'];
$userId = $_SESSION['user']['id_user'];
$tab = (int) $_SESSION['displCard']['tab'];
$field = $_GET['field'];
$post = $_POST;
// Select the table to be edited, check values
switch ($tab) {
case 0:
$table = 'dat_customers';
switch ($field)
{
case 'phone':
case 'fax':
//$post[$field] = trim(str_replace([' ','/','*','.','(',')'], '', $post[$field]));
$f = "ctl_$field";
if ( $post[$field] and ! $objControls->$f )
$objErrors->addMessage(FIELD_ERR['dial']);
$post[$field] = setDefaultValue($post[$field], NULL);
break;
case 'zip':
if ( $post[$field] and ! $objControls->ctl_postcode($post[$field], $post['country']) )
$objErrors->addMessage(FIELD_ERR['zip']);
$post[$field] = setDefaultValue($post[$field], NULL);
break;
case 'mail':
if ( $post[$field] and ! $objControls->ctl_email($post[$field]) )
$objErrors->addMessage(FIELD_ERR['email']);
break;
case 'url':
if ( $post[$field] and ! $objControls->ctl_url($post[$field]) )
$objErrors->addMessage(FIELD_ERR['url']);
break;
}
break;
case 1:
$table = 'dat_staff';
// ... code à développer ...
break;
case 2:
$table = '';
break;
// Suite à développer
}
if ( empty($table) )
{
header('Location: '.URL_SITE."frontend/controllers/cardFrame.php");
exit;
}
$defValue = getDefaultValue($table, $field);
$data['id'] = $post['id'];
$data['value'] = ( empty($defValue) ) ? '': setDefaultValue($post[$field], $defValue->defaultValue);
saveSingleData($table, $field, $data);
if ( !empty($objErrors) ) { $_SESSION['errors'] = (string) $objErrors; }
header('Location: '.URL_SITE."frontend/controllers/cardFrame.php"); |
Partager