<?
switch($_GET["action"]) {
	case 'save': save_curr_contact(); break;
	default: break;
}

function save_curr_contact() {
	$messages = array();
	$translation = \DynCom\mysyde\common\classes\Registry::get("translation");
	$birthday = new DateTime($_POST["input_birthday"]);
  	$query = "UPDATE main_contact SET
      email = '" . $_POST['input_email'] . "', 
      address = '" . $_POST['input_address'] . "',
      post_code = '" . $_POST['input_post_code'] . "',
      city = '" . $_POST['input_city'] . "',
      phone_no = '" . $_POST['input_phone_no'] . "',
	  birthday = '".$birthday->format('Y-m-d')."'
      WHERE id = '" . $GLOBALS['main_contact']['id'] . "' LIMIT 1";
	@mysqli_query($GLOBALS['mysql_con'],$query);
	$messages[] = "<div class=\"successbox\">".$translation->get("password_change_success")."</div>\n";
	$host  = $_SERVER['HTTP_HOST'];
	$uri   = $_SERVER["REDIRECT_URL"];
	echo "<script type='text/javascript'>window.location.href = 'https://".$host.$uri."';</script>";

}


function save_portal_login_group($user_id){
    $pdo = new PDO("mysql:host=".$GLOBALS['myservername'].";dbname=".$GLOBALS['mydb'], $GLOBALS['mylogin'], $GLOBALS['mypass']);
    $statement_contact = $pdo->prepare("SELECT * FROM portal_login_group WHERE portal_login_id = :portal_login_id");
    $statement_contact->execute(array(':portal_login_id' => $user_id));
    $res_contact = $statement_contact->fetchall(PDO::FETCH_ASSOC);
    foreach ($res_contact as $key_contact => $value_contact) {

        $phone_no = $_POST['input_phone_no_'.$value_contact['portal_group_id']];
        $email = $_POST['input_email_'.$value_contact['portal_group_id']];
        $department_id = $_POST['department_'.$value_contact['portal_group_id']];
        $role_id = $_POST['role_'.$value_contact['portal_group_id']];

        $update_contact = $pdo->prepare("UPDATE portal_login_group SET phone_no = :phone_no, email = :email, department_id = :department_id, role_id = :role_id WHERE id = :id");
        $update_contact->execute(array(':phone_no' => $phone_no, ':email' => $email, ':department_id' => $department_id, ':role_id' => $role_id, ':id' => $value_contact['id']));
    }
}
?>