Convert cnew1.php to functions