#This file is copyright of Web Orientated Technologies Ltd. and may not be copied, duplicated or modified without the permission of Web Orientated Technologies Ltd. sub read_csv { # returns an array of values in CSV string my ($in) = @_; my (@out) = (); $in =~ s/\"\"//g; push(@out, $+) while $in =~ m{ "([^\"\\]*(?:\\.[^\"\\]*)*)",? # groups the phrase inside the quotes | ([^,]+),? | , }gx; push(@out, 0) if substr($_,-1,1) eq ','; return (@out); } sub ValidateNumberList { #returns 0 if the number list is valid #returns -1 if the number list is not valid my($list)=@_; my ($out) = 0; my ($i,$j) = ''; $list =~ s/\s//g; $list =~ s/\n//g; $list =~ s/\r//g; $j = length($list); for ($i=0; $i < $j; $i++) { my ($temp) = substr($list,$i,1); if ($temp !~ /\d/ && $temp ne '+' && $temp ne ',') { $out = -1; } } return ($out); } sub validate_tel { #returns 0 if the number is valid #returns -1 if the number is not valid my($tel)=@_; my ($out) = 0; my ($i,$j) = ''; $tel =~ s/\s//g; $j = length($tel); for ($i=0; $i < $j; $i++) { my ($temp) = substr($tel,$i,1); if ($temp !~ /\d/ && $temp ne '(' && $temp ne ')' && $temp ne '+') { $out = -1; } } return ($out); } sub encrypt_this { my ($out) = @_; my ($salt) = ''; my (@passset) = (); @passset = ('a'..'z'); $salt = int(rand(10)).@passset[int(rand(27))]; $out = crypt($out,$salt); return ($out); } sub time_to_hour { #Converts a timestamp into a time of the format: hh:mm my ($in) = @_; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$out); if ($in =~ /\D/) { $out = $in; } else { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($in); $year = $year+1900; $mon = $mon+1; $min = sprintf("%.2u",$min); $out = $hour.':'.$min; } return ($out); } sub time_to_date { #Converts a timestamp into a date of the format: DD MMM YYYY my ($in) = @_; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$out); if ($in =~ /\D/) { $out = $in; } else { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($in); $year = $year+1900; $mon = $mon+1; if ($mon == 1) { $mon = 'Jan' } elsif ($mon == 2) { $mon = 'Feb' } elsif ($mon == 3) { $mon = 'Mar' } elsif ($mon == 4) { $mon = 'Apr' } elsif ($mon == 5) { $mon = 'May' } elsif ($mon == 6) { $mon = 'Jun' } elsif ($mon == 7) { $mon = 'Jul' } elsif ($mon == 8) { $mon = 'Aug' } elsif ($mon == 9) { $mon = 'Sep' } elsif ($mon == 10) { $mon = 'Oct' } elsif ($mon == 11) { $mon = 'Nov' } elsif ($mon == 12) { $mon = 'Dec' } else { $mon = 'Unkown' } $out = $mday.' '.$mon.' '.$year; } return ($out); } 1;