lib: replace shift my @_ (pt2)

This commit is contained in:
Milan
2023-05-19 18:00:29 +02:00
parent 3a1a118eeb
commit fe857c6f65
32 changed files with 203 additions and 332 deletions

View File

@@ -12,7 +12,7 @@ use Apache2::Connection ();
use Apache2::Const -compile => qw(FORBIDDEN OK); use Apache2::Const -compile => qw(FORBIDDEN OK);
sub handler { sub handler {
my $r = shift; my ($r) = @_;
my $DAYS = 24 * 60 * 60; my $DAYS = 24 * 60 * 60;
my $OK = Apache2::Const::OK; my $OK = Apache2::Const::OK;

View File

@@ -14,9 +14,7 @@ use Date::Calc;
our @EXPORT_OK = qw(get_cache configure_cache put_cache get_list check_params); our @EXPORT_OK = qw(get_cache configure_cache put_cache get_list check_params);
sub get_list($$) { sub get_list($$) {
my $config = shift; my ($config, $request) = @_;
my $request = shift;
my $params = $request->{params}->{checked}; my $params = $request->{params}->{checked};
#customize prefiltered request parameters #customize prefiltered request parameters
@@ -63,10 +61,7 @@ sub get_list($$) {
} }
sub get_menu($$$$) { sub get_menu($$$$) {
my $config = shift; my ($config, $request, $date, $results) = @_;
my $request = shift;
my $date = shift;
my $results = shift;
my $params = $request->{params}->{checked}; my $params = $request->{params}->{checked};
@@ -89,9 +84,7 @@ sub get_menu($$$$) {
} }
sub get_calendar($$$) { sub get_calendar($$$) {
my $config = shift; my ($config, $request, $date) = @_;
my $request = shift;
my $date = shift;
my $params = $request->{params}->{checked}; my $params = $request->{params}->{checked};
@@ -114,8 +107,7 @@ sub get_calendar($$$) {
} }
sub get_newest_comments($$) { sub get_newest_comments($$) {
my $config = shift; my ($config, $request) = @_;
my $request = shift;
my $params = { my $params = {
template => 'comments_newest.html', template => 'comments_newest.html',

View File

@@ -3,7 +3,7 @@ use warnings;
use strict; use strict;
sub durationToSeconds($) { sub durationToSeconds($) {
my $duration = shift; my ($duration) = @_;
if ( $duration =~ /(\d+):(\d\d):(\d\d).(\d\d)/ ) { if ( $duration =~ /(\d+):(\d\d):(\d\d).(\d\d)/ ) {
return $1 * 3600 + $2 * 60 + $3 + $4 / 100; return $1 * 3600 + $2 * 60 + $3 + $4 / 100;
@@ -12,10 +12,7 @@ sub durationToSeconds($) {
} }
sub formatDuration($$$;$) { sub formatDuration($$$;$) {
my $audioDuration = shift; my ($audioDuration, $eventDuration, $value, $mouseOver) = @_;
my $eventDuration = shift;
my $value = shift;
my $mouseOver = shift;
return '' unless $audioDuration; return '' unless $audioDuration;
return '' unless $eventDuration; return '' unless $eventDuration;
@@ -52,7 +49,8 @@ sub formatDuration($$$;$) {
} }
sub formatChannels($) { sub formatChannels($) {
my $channels = shift; my ($channels) = @_;
return '' unless $channels; return '' unless $channels;
my $class = "ok"; my $class = "ok";
$class = "error" if $channels != 2; $class = "error" if $channels != 2;
@@ -60,7 +58,8 @@ sub formatChannels($) {
} }
sub formatSamplingRate($) { sub formatSamplingRate($) {
my $samplingRate = shift; my ($samplingRate) = @_;
return '' unless $samplingRate; return '' unless $samplingRate;
my $class = "ok"; my $class = "ok";
$class = "error" if $samplingRate != 44100; $class = "error" if $samplingRate != 44100;
@@ -68,7 +67,8 @@ sub formatSamplingRate($) {
} }
sub formatBitrate($) { sub formatBitrate($) {
my $bitrate = shift; my ($bitrate) = @_;
return '' unless $bitrate; return '' unless $bitrate;
my $class = 'ok'; my $class = 'ok';
$class = 'warn' if $bitrate >= 200; $class = 'warn' if $bitrate >= 200;
@@ -77,7 +77,8 @@ sub formatBitrate($) {
} }
sub formatBitrateMode($) { sub formatBitrateMode($) {
my $mode = shift; my ($mode) = @_;
return '' unless $mode; return '' unless $mode;
my $class = 'ok'; my $class = 'ok';
$class = 'error' if $mode ne 'CBR'; $class = 'error' if $mode ne 'CBR';
@@ -85,9 +86,9 @@ sub formatBitrateMode($) {
} }
sub formatLoudness { sub formatLoudness {
my $value = shift; my ($value, $prefix, $round) = @_;
my $prefix = shift || ''; $prefix ||= '';
my $round = shift || ''; $round ||= '';
return '' unless $value; return '' unless $value;
$value = sprintf( "%.1f", $value ); $value = sprintf( "%.1f", $value );
@@ -103,8 +104,7 @@ sub formatLoudness {
} }
sub formatFile{ sub formatFile{
my $file = shift; my ($file, $event_id) = @_;
my $event_id = shift;
return '' unless $file; return '' unless $file;

View File

@@ -24,8 +24,7 @@ sub get_columns($) {
# get playout entries # get playout entries
sub get($$) { sub get($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my $date_range_include = 0; my $date_range_include = 0;
$date_range_include = 1 $date_range_include = 1

View File

@@ -27,8 +27,7 @@ sub get_cached_or_render($$$) {
} }
sub get($$) { sub get($$) {
my $config = shift; my ($config, $request) = @_;
my $request = shift;
my $params = $request->{params}->{checked}; my $params = $request->{params}->{checked};
my $language = $config->{date}->{language} || 'en'; my $language = $config->{date}->{language} || 'en';
@@ -315,8 +314,8 @@ sub get_calendar_weeks($$$) {
} }
sub getWeeksOfMonth($$) { sub getWeeksOfMonth($$) {
my $thisYear = shift; my ($thisYear, $thisMonth) = @_;
my $thisMonth = shift;
my $thisDay = 1; my $thisDay = 1;
# get weekday of 1st of month # get weekday of 1st of month

View File

@@ -70,8 +70,7 @@ sub get_cached_or_render($$$;$) {
} }
sub get($$) { sub get($$) {
my $config = shift; my ($config, $request) = @_;
my $request = shift;
my $params = $request->{params}->{checked}; my $params = $request->{params}->{checked};
my $dbh = db::connect( $config, $request ); my $dbh = db::connect( $config, $request );
@@ -81,9 +80,7 @@ sub get($$) {
} }
sub get_query($$$) { sub get_query($$$) {
my $dbh = shift; my ($dbh, $config, $request) = @_;
my $config = shift;
my $request = shift;
my $params = $request->{params}->{checked}; my $params = $request->{params}->{checked};
@@ -229,9 +226,7 @@ sub render($$$$) {
#check if comment exists already #check if comment exists already
sub check ($$$) { sub check ($$$) {
my $dbh = shift; my ($dbh, $config, $comment) = @_;
my $config = shift;
my $comment = shift;
my $query = qq{ my $query = qq{
select id select id
@@ -259,9 +254,7 @@ sub check ($$$) {
#used for insert #used for insert
sub get_level($$$) { sub get_level($$$) {
my $dbh = shift; my ($dbh, $config, $comment) = @_;
my $config = shift;
my $comment = shift;
my $parent_id = $comment->{parent_id}; my $parent_id = $comment->{parent_id};
return 0 unless defined $parent_id; return 0 unless defined $parent_id;
@@ -294,9 +287,7 @@ sub get_level($$$) {
} }
sub get_by_event($$$) { sub get_by_event($$$) {
my $dbh = shift; my ($dbh, $config, $request) = @_;
my $config = shift;
my $request = $_[0];
my $params = $request->{params}->{checked}->{comment}; my $params = $request->{params}->{checked}->{comment};
@@ -336,9 +327,7 @@ sub get_by_event($$$) {
} }
sub get_by_time($$$) { sub get_by_time($$$) {
my $dbh = shift; my ($dbh, $config, $comment) = @_;
my $config = shift;
my $comment = shift;
my $where = ''; my $where = '';
my $bind_values = []; my $bind_values = [];
@@ -375,10 +364,7 @@ sub get_by_time($$$) {
} }
sub get_events($$$$) { sub get_events($$$$) {
my $dbh = shift; my ($dbh, $config, $request, $comments) = @_;
my $config = shift;
my $request = shift;
my $comments = shift;
my $params = $request->{params}->{checked}->{comment}; my $params = $request->{params}->{checked}->{comment};
@@ -438,9 +424,7 @@ sub get_events($$$$) {
} }
sub insert ($$$) { sub insert ($$$) {
my $dbh = shift; my ($dbh, $config, $comment) = @_;
my $config = shift;
my $comment = shift;
$comment->{level} = comments::get_level( $dbh, $config, $comment ); $comment->{level} = comments::get_level( $dbh, $config, $comment );
@@ -461,9 +445,7 @@ sub insert ($$$) {
} }
sub set_lock_status ($$$) { sub set_lock_status ($$$) {
my $dbh = shift; my ($dbh, $config, $comment) = @_;
my $config = shift;
my $comment = shift;
my $id = $comment->{id}; my $id = $comment->{id};
my $lock_status = $comment->{set_lock_status}; my $lock_status = $comment->{set_lock_status};
@@ -489,9 +471,7 @@ sub set_lock_status ($$$) {
} }
sub set_news_status($$$) { sub set_news_status($$$) {
my $dbh = shift; my ($dbh, $config, $comment) = @_;
my $config = shift;
my $comment = shift;
my $id = $comment->{id}; my $id = $comment->{id};
my $news_status = $comment->{set_news_status}; my $news_status = $comment->{set_news_status};
@@ -505,9 +485,7 @@ sub set_news_status($$$) {
} }
sub update_comment_count ($$$) { sub update_comment_count ($$$) {
my $dbh = shift; my ($dbh, $config, $comment) = @_;
my $config = shift;
my $comment = shift;
my $query = qq{ my $query = qq{
select count(id) count select count(id) count
@@ -530,9 +508,7 @@ sub update_comment_count ($$$) {
} }
sub sort_childs { sub sort_childs {
my $node = shift; my ($node, $nodes, $sorted_nodes) = @_;
my $nodes = shift;
my $sorted_nodes = shift;
#push node into list of sorted nodes #push node into list of sorted nodes
push @{$sorted_nodes}, $node; push @{$sorted_nodes}, $node;
@@ -549,8 +525,7 @@ sub sort_childs {
#precondition: results are presorted by creation date (by sql) #precondition: results are presorted by creation date (by sql)
sub sort($$) { sub sort($$) {
my $config = shift; my ($config, $results) = @_;
my $results = shift;
#define parent nodes #define parent nodes
my $nodes = {}; my $nodes = {};
@@ -578,8 +553,7 @@ sub sort($$) {
} }
sub check_params ($$) { sub check_params ($$) {
my $config = shift; my ($config, $params) = @_;
my $params = shift;
my $comment = {}; my $comment = {};
$comment->{event_start} = ''; $comment->{event_start} = '';

View File

@@ -14,7 +14,7 @@ my $config = undef;
sub get($) { sub get($) {
my $filename = shift; my ($filename) = @_;
return read_config($filename); return read_config($filename);
} }
@@ -25,7 +25,7 @@ sub getFromScriptLocation() {
} }
sub read_config { sub read_config {
my $file = $_[0]; my ($file) = @_;
my $vars = {}; my $vars = {};
my @stack = (); my @stack = ();

View File

@@ -13,8 +13,7 @@ our @EXPORT_OK =
#convert creole wiki text to event #convert creole wiki text to event
sub extractEventFromWikiText($;$) { sub extractEventFromWikiText($;$) {
my $params = shift; my ($params, $event) = @_;
my $event = shift;
$event = {} unless defined $event; $event = {} unless defined $event;
my $title = $params->{title} || ''; my $title = $params->{title} || '';
@@ -111,7 +110,7 @@ s/\{\{\s*thumbs\/+(.*?)\s*\|\s*(.*?)\s*\}\}/\[\[$local_media_url\/images\/$1\|\{
} }
sub eventToWikiText($$) { sub eventToWikiText($$) {
my $event = shift; my ($event) = @_;
my $local_media_url = $event->{local_media_url} || ''; my $local_media_url = $event->{local_media_url} || '';
$event->{program} =~ s/^\s+|\s+$//g; $event->{program} =~ s/^\s+|\s+$//g;
@@ -163,8 +162,7 @@ s/\[\[.*?\/+media\/+images\/+(.*?)\s*\|.*?\{\{.*?\/+media\/+thumbs\/+(.*?)\s*\|\
#extrace meta tags from comment text #extrace meta tags from comment text
sub extractMeta ($$) { sub extractMeta ($$) {
my $comments = shift; my ($comments, $meta) = @_;
my $meta = shift;
$meta = [] unless defined $meta; $meta = [] unless defined $meta;
@@ -202,7 +200,8 @@ sub extractMeta ($$) {
#remove meta tags from comment text #remove meta tags from comment text
sub removeMeta($) { sub removeMeta($) {
my $comments = shift || ''; my ($comments) = @_;
$comments ||= '';
my $result = ''; my $result = '';
for my $line ( split( /\n/, $comments ) ) { for my $line ( split( /\n/, $comments ) ) {
@@ -216,7 +215,7 @@ sub removeMeta($) {
#add meta tags to comment text #add meta tags to comment text
sub metaToWiki { sub metaToWiki {
my $meta = shift; my ($meta) = @_;
my $result = ''; my $result = '';
for my $pair (@$meta) { for my $pair (@$meta) {

View File

@@ -150,8 +150,7 @@ sub put($$$) {
# deprecated # deprecated
sub quote($$) { sub quote($$) {
my $dbh = shift; my ($dbh, $sql) = @_;
my $sql = shift;
$sql =~ s/\_/\\\_/g; $sql =~ s/\_/\\\_/g;
return $dbh->quote($sql); return $dbh->quote($sql);
@@ -159,9 +158,7 @@ sub quote($$) {
#subtract hours, deprecated(!) #subtract hours, deprecated(!)
sub shift_date_by_hours($$$) { sub shift_date_by_hours($$$) {
my $dbh = shift; my ($dbh, $date, $offset) = @_;
my $date = shift;
my $offset = shift;
my $query = 'select date(? - INTERVAL ? HOUR) date'; my $query = 'select date(? - INTERVAL ? HOUR) date';
my $bind_values = [ $date, $offset ]; my $bind_values = [ $date, $offset ];
@@ -171,9 +168,7 @@ sub shift_date_by_hours($$$) {
#add minutes, deprecated(!) #add minutes, deprecated(!)
sub shift_datetime_by_minutes($$$) { sub shift_datetime_by_minutes($$$) {
my $dbh = shift; my ($dbh, $datetime, $offset) = @_;
my $datetime = shift;
my $offset = shift;
my $query = "select ? + INTERVAL ? MINUTE date"; my $query = "select ? + INTERVAL ? MINUTE date";
my $bind_values = [ $datetime, $offset ]; my $bind_values = [ $datetime, $offset ];

View File

@@ -113,8 +113,7 @@ sub insert($$) {
# insert event # insert event
sub insert_by_event_id ($$){ sub insert_by_event_id ($$){
my $config = shift; my ($config, $options) = @_;
my $options = shift;
return undef unless defined $options->{project_id}; return undef unless defined $options->{project_id};
return undef unless defined $options->{studio_id}; return undef unless defined $options->{studio_id};

View File

@@ -482,11 +482,10 @@ sub add_recurrence_dates {
} }
sub calc_dates { sub calc_dates {
my $config = shift; my ($config, $result, $params, $previous_result, $time_diff) = @_;
my $result = shift; $params ||= {};
my $params = shift || {}; $previous_result ||= {};
my $previous_result = shift || {}; $time_diff ||= '';
my $time_diff = shift || '';
$result->{utc_offset} = $time_diff; $result->{utc_offset} = $time_diff;
$result->{time_zone} = $config->{date}->{time_zone}; $result->{time_zone} = $config->{date}->{time_zone};
@@ -643,7 +642,6 @@ sub set_listen_key{
sub set_upload_status($$){ sub set_upload_status($$){
my ($config, $event) = @_; my ($config, $event) = @_;
print STDERR "set upload_status=$event->{upload_status} for ".$event->{event_id}."\n";
return undef unless defined $event->{event_id}; return undef unless defined $event->{event_id};
return undef unless defined $event->{upload_status}; return undef unless defined $event->{upload_status};
my $bindValues = [ $event->{upload_status}, $event->{event_id}, $event->{upload_status} ]; my $bindValues = [ $event->{upload_status}, $event->{event_id}, $event->{upload_status} ];
@@ -1500,9 +1498,7 @@ sub get_by_image ($$$) {
# deleting an event is currently disabled # deleting an event is currently disabled
sub delete ($$$) { sub delete ($$$) {
return; return;
my $request = shift; my ($request, $config, $event_id) = @_;
my $config = shift;
my $event_id = shift;
my $params = $request->{params}->{checked}; my $params = $request->{params}->{checked};
my $dbh = db::connect($config); my $dbh = db::connect($config);

View File

@@ -19,8 +19,7 @@ my $sql_columns = [
]; ];
sub get($$) { sub get($$) {
my $config = shift; my ($config, $options) = @_;
my $options = shift;
my @cond = (); my @cond = ();
my $bind_values = []; my $bind_values = [];
@@ -99,8 +98,7 @@ sub get($$) {
} }
sub insert_or_update($$) { sub insert_or_update($$) {
my $dbh = shift; my ($dbh, $image) = @_;
my $image = shift;
$image->{name} = 'new' if $image->{name} eq ''; $image->{name} = 'new' if $image->{name} eq '';
my $entry = get_by_filename( $dbh, $image->{filename} ); my $entry = get_by_filename( $dbh, $image->{filename} );
@@ -112,8 +110,7 @@ sub insert_or_update($$) {
} }
sub insert ($$) { sub insert ($$) {
my $dbh = shift; my ($dbh, $image) = @_;
my $image = shift;
my @sql_columns = @$sql_columns; my @sql_columns = @$sql_columns;
@@ -154,8 +151,7 @@ sub insert ($$) {
} }
sub update($$) { sub update($$) {
my $dbh = shift; my ($dbh, $image) = @_;
my $image = shift;
unless ( defined $image->{studio_id} ) { unless ( defined $image->{studio_id} ) {
print STDERR "missing studio_id at images::update\n"; print STDERR "missing studio_id at images::update\n";
@@ -213,8 +209,7 @@ sub update($$) {
} }
sub delete($$) { sub delete($$) {
my $dbh = shift; my ($dbh, $image) = @_;
my $image = shift;
unless ( defined $image->{project_id} ) { unless ( defined $image->{project_id} ) {
print STDERR "missing project_id at images::delete\n"; print STDERR "missing project_id at images::delete\n";
@@ -252,11 +247,7 @@ sub delete($$) {
# deactivated # deactivated
sub delete_files($$$$$) { sub delete_files($$$$$) {
my $config = $_[0]; my ($config, $local_media_dir, $filename, $action_result, $errors) = @_;
my $local_media_dir = $_[1];
my $filename = $_[2];
my $action_result = $_[3];
my $errors = $_[4];
return undef; return undef;
@@ -320,8 +311,7 @@ sub delete_file ($$$$) {
} }
sub getPath { sub getPath {
my $config = shift; my ($config, $options) = @_;
my $options = shift;
my $dir = $config->{locations}->{local_media_dir}; my $dir = $config->{locations}->{local_media_dir};
return undef unless defined $dir; return undef unless defined $dir;
@@ -340,8 +330,7 @@ sub getPath {
} }
sub getInternalPath ($$) { sub getInternalPath ($$) {
my $config = shift; my ($config, $options) = @_;
my $options = shift;
my $dir = $config->{locations}->{local_media_dir}; my $dir = $config->{locations}->{local_media_dir};
return undef unless defined $dir; return undef unless defined $dir;
@@ -360,14 +349,16 @@ sub getInternalPath ($$) {
} }
sub normalizeName (;$) { sub normalizeName (;$) {
my $name = shift; my ($name) = @_;
return undef unless defined $name; return undef unless defined $name;
$name =~ s/.*\///g; $name =~ s/.*\///g;
return $name; return $name;
} }
sub readFile($) { sub readFile($) {
my $path = shift; my ($path) = @_;
my $content = ''; my $content = '';
print STDERR "read '$path'\n"; print STDERR "read '$path'\n";
@@ -382,8 +373,7 @@ sub readFile($) {
} }
sub writeFile ($$) { sub writeFile ($$) {
my $path = shift; my ($path, $content) = @_;
my $content = shift;
print STDERR "save '$path'\n"; print STDERR "save '$path'\n";
open my $fh, '> :raw', $path or return { error => 'could not save image. ' . $! . " $path" }; open my $fh, '> :raw', $path or return { error => 'could not save image. ' . $! . " $path" };
@@ -394,7 +384,8 @@ sub writeFile ($$) {
} }
sub deleteFile($) { sub deleteFile($) {
my $path = shift; my ($path) = @_;
return { error => "source '$path' does not exist" } unless -e $path; return { error => "source '$path' does not exist" } unless -e $path;
#unlink $path; #unlink $path;
@@ -403,9 +394,7 @@ sub deleteFile($) {
} }
sub copyFile ($$$) { sub copyFile ($$$) {
my $source = shift; my ($source, $target, $errors) = @_;
my $target = shift;
my $errors = shift;
my $read = images::readFile($source); my $read = images::readFile($source);
return $read if defined $read->{error}; return $read if defined $read->{error};
@@ -415,8 +404,7 @@ sub copyFile ($$$) {
} }
sub publish($$) { sub publish($$) {
my $config = shift; my ($config, $filename) = @_;
my $filename = shift;
print STDERR "publish\n"; print STDERR "publish\n";
return undef unless defined $config; return undef unless defined $config;
@@ -435,8 +423,7 @@ sub publish($$) {
} }
sub depublish ($$) { sub depublish ($$) {
my $config = shift; my ($config, $filename) = @_;
my $filename = shift;
print STDERR "depublish\n"; print STDERR "depublish\n";
return undef unless defined $config; return undef unless defined $config;
@@ -468,8 +455,7 @@ sub checkLicence ($$) {
} }
sub setEventLabels($$) { sub setEventLabels($$) {
my $dbh = shift; my ($dbh, $image) = @_;
my $image = shift;
unless ( defined $image->{project_id} ) { unless ( defined $image->{project_id} ) {
print STDERR "missing project_id at images::setEventLabels\n"; print STDERR "missing project_id at images::setEventLabels\n";
@@ -495,8 +481,7 @@ sub setEventLabels($$) {
} }
sub setSeriesLabels($$) { sub setSeriesLabels($$) {
my $dbh = shift; my ($dbh, $image) = @_;
my $image = shift;
unless ( defined $image->{project_id} ) { unless ( defined $image->{project_id} ) {
print STDERR "missing project_id at images::setSeriesLabels\n"; print STDERR "missing project_id at images::setSeriesLabels\n";

View File

@@ -17,8 +17,7 @@ our @EXPORT_OK = qw(get getJavascript);
# user : get from user settings # user : get from user settings
# loc : add to existing localization, optional # loc : add to existing localization, optional
sub get($$) { sub get($$) {
my $config = shift; my ($config, $options) = @_;
my $options = shift;
#get pot file #get pot file
unless ( defined $options->{file} ) { unless ( defined $options->{file} ) {
@@ -63,8 +62,7 @@ sub get($$) {
} }
sub read_po_file($$) { sub read_po_file($$) {
my $po_file = shift; my ($po_file, $loc) = @_;
my $loc = shift;
unless ( -e $po_file ) { unless ( -e $po_file ) {
print STDERR "po file $po_file does not exist\n"; print STDERR "po file $po_file does not exist\n";
@@ -99,7 +97,7 @@ sub read_po_file($$) {
} }
sub getJavascript ($){ sub getJavascript ($){
my $loc = shift; my ($loc) = @_;
my $out = '<script>'; my $out = '<script>';
$out .= "var loc={};\n"; $out .= "var loc={};\n";

View File

@@ -23,7 +23,7 @@ sub error($$) {
} }
sub load_file($) { sub load_file($) {
my $filename = shift; my ($filename) = @_;
my $content = ''; my $content = '';
if ( -e $filename ) { if ( -e $filename ) {
@@ -36,8 +36,7 @@ sub load_file($) {
} }
sub save_file($$) { sub save_file($$) {
my $filename = shift; my ($filename, $content) = @_;
my $content = shift;
#check if directory is writeable #check if directory is writeable
if ( $filename =~ /^(.+?)\/[^\/]+$/ ) { if ( $filename =~ /^(.+?)\/[^\/]+$/ ) {
@@ -57,8 +56,7 @@ sub save_file($$) {
} }
sub append_file($$) { sub append_file($$) {
my $filename = shift; my ($filename, $content) = @_;
my $content = shift;
unless ( ( defined $filename ) && ( $filename ne '' ) && ( -e $filename ) ) { unless ( ( defined $filename ) && ( $filename ne '' ) && ( -e $filename ) ) {
print STDERR "cannot append, file '$filename' does not exist\n"; print STDERR "cannot append, file '$filename' does not exist\n";

View File

@@ -19,14 +19,14 @@ our @EXPORT_OK =
qw(fix_line_ends html_to_creole creole_to_html creole_to_plain plain_to_ical ical_to_plain ical_to_xml html_to_plain fix_utf8 uri_encode compress base26); qw(fix_line_ends html_to_creole creole_to_html creole_to_plain plain_to_ical ical_to_plain ical_to_xml html_to_plain fix_utf8 uri_encode compress base26);
sub fix_line_ends ($) { sub fix_line_ends ($) {
my $s = shift; my ($s) = @_;
$s =~ s/\r?\n|\r/\n/g; $s =~ s/\r?\n|\r/\n/g;
return $s; return $s;
} }
# convert 1..26 to a..z, 27 to aa, inspired by ConvertAA # convert 1..26 to a..z, 27 to aa, inspired by ConvertAA
sub base26($) { sub base26($) {
my $num = shift; my ($num) = @_;
return '' if $num <= 0; return '' if $num <= 0;
my $s = ""; my $s = "";
@@ -39,7 +39,7 @@ sub base26($) {
} }
sub html_to_creole($) { sub html_to_creole($) {
my $s = shift; my ($s) = @_;
#remove elements #remove elements
$s =~ s/\<\!\-\-[\s\S]*?\-\-\>//gi; $s =~ s/\<\!\-\-[\s\S]*?\-\-\>//gi;
@@ -153,7 +153,7 @@ sub markdown_to_html($){
} }
sub creole_to_plain($) { sub creole_to_plain($) {
my $s = shift; my ($s) = @_;
$s =~ s/\<p\>/\n/gi; $s =~ s/\<p\>/\n/gi;
$s =~ s/\{\{\{((\W+|\w+)+?)\}\}\}/<blockquote>$1<\/blockquote>/g; $s =~ s/\{\{\{((\W+|\w+)+?)\}\}\}/<blockquote>$1<\/blockquote>/g;
@@ -174,7 +174,8 @@ sub creole_to_plain($) {
} }
sub html_to_plain ($) { sub html_to_plain ($) {
my $s = shift; my ($s) = @_;
return '' unless defined $s; return '' unless defined $s;
my $tree = HTML::Parse::parse_html( '<body>' . $s . '</body>' ); my $tree = HTML::Parse::parse_html( '<body>' . $s . '</body>' );
my $formatter = HTML::FormatText->new( leftmargin => 0, rightmargin => 2000 ); my $formatter = HTML::FormatText->new( leftmargin => 0, rightmargin => 2000 );
@@ -381,7 +382,7 @@ my %entity = (
my $entities = join( '|', keys %entity ); my $entities = join( '|', keys %entity );
sub encode_xml_element($) { sub encode_xml_element($) {
my $text = shift; my ($text) = @_;
my $encoded_text = ''; my $encoded_text = '';
@@ -394,7 +395,7 @@ sub encode_xml_element($) {
} }
sub encode_xml_element_text ($) { sub encode_xml_element_text ($) {
my $text = shift; my ($text) = @_;
$text =~ s/&(?!(#[0-9]+|#x[0-9a-fA-F]+|\w+);)/&amp;/g; $text =~ s/&(?!(#[0-9]+|#x[0-9a-fA-F]+|\w+);)/&amp;/g;
$text =~ s/&($entities);/$entity{$1}/g; $text =~ s/&($entities);/$entity{$1}/g;
@@ -405,7 +406,8 @@ sub encode_xml_element_text ($) {
} }
sub escapeHtml($) { sub escapeHtml($) {
my $s = shift; my ($s) = @_;
return HTML::Entities::encode_entities( $s, q{&<>"'} ); return HTML::Entities::encode_entities( $s, q{&<>"'} );
} }

View File

@@ -17,7 +17,7 @@ sub isJson () {
} }
sub get ($) { sub get ($) {
my $r = shift; my ($r) = @_;
my $tmp_dir = '/var/tmp/'; my $tmp_dir = '/var/tmp/';
my $upload_limit = 1000 * 1024; my $upload_limit = 1000 * 1024;

View File

@@ -23,8 +23,7 @@ sub get_columns ($) {
} }
sub get ($$) { sub get ($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
@@ -83,8 +82,7 @@ sub insert ($$) {
} }
sub delete ($$) { sub delete ($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my @conditions = (); my @conditions = ();
my @bind_values = (); my @bind_values = ();
@@ -157,9 +155,7 @@ sub sendToken ($$) {
} }
sub changePassword ($$$) { sub changePassword ($$$) {
my $config = shift; my ($config, $request, $userName) = @_;
my $request = shift;
my $userName = shift;
my $params = $request->{params}->{checked}; my $params = $request->{params}->{checked};
my $permissions = $request->{permissions}; my $permissions = $request->{permissions};
@@ -194,7 +190,7 @@ sub changePassword ($$$) {
} }
sub isPasswordInvalid($) { sub isPasswordInvalid($) {
my $password = shift; my ($password) = @_;
unless ( defined $password || $password eq '' ) { unless ( defined $password || $password eq '' ) {
return "The password must not be empty."; return "The password must not be empty.";
} }

View File

@@ -29,8 +29,7 @@ sub get_columns ($) {
# get all series_dates for studio_id and series_id within given time range # get all series_dates for studio_id and series_id within given time range
# calculate start_date, end_date, weeday, day from start and end(datetime) # calculate start_date, end_date, weeday, day from start and end(datetime)
sub get ($;$) { sub get ($;$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
@@ -107,8 +106,7 @@ sub get ($;$) {
#check if event is scheduled (on permission check) #check if event is scheduled (on permission check)
sub is_event_scheduled($$) { sub is_event_scheduled($$) {
my $request = shift; my ($request, $options) = @_;
my $options = shift;
return 0 unless defined $options->{project_id}; return 0 unless defined $options->{project_id};
return 0 unless defined $options->{studio_id}; return 0 unless defined $options->{studio_id};
@@ -131,8 +129,7 @@ sub is_event_scheduled($$) {
#get all series for given studio_id, time range and search #get all series for given studio_id, time range and search
sub get_series($;$) { sub get_series($;$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my $date_range_include = 0; my $date_range_include = 0;
$date_range_include = 1 $date_range_include = 1
@@ -251,8 +248,7 @@ sub get_series($;$) {
} }
sub addSeriesScheduleAttributes ($$) { sub addSeriesScheduleAttributes ($$) {
my $config = shift; my ($config, $entries) = @_;
my $entries = shift;
# get series schedule ids used at entries # get series schedule ids used at entries
my $scheduleIds = { map { $_->{series_schedule_id} => 1 } @$entries }; my $scheduleIds = { map { $_->{series_schedule_id} => 1 } @$entries };
@@ -360,8 +356,7 @@ sub update($$) {
} }
sub get_schedule_dates($$) { sub get_schedule_dates($$) {
my $schedule = shift; my ($schedule, $options) = @_;
my $options = shift;
my $is_exclude = $options->{exclude} || 0; my $is_exclude = $options->{exclude} || 0;
my $dates = []; my $dates = [];
@@ -389,13 +384,8 @@ sub get_schedule_dates($$) {
} }
sub get_week_of_month_dates ($$$$$$$) { sub get_week_of_month_dates ($$$$$$$) {
my $start = shift; # datetime string my ($start, $end, $duration, $week, $weekday, $frequency, $nextDay) = @_;
my $end = shift; # datetime string #datetime, datetime, minutes, every nth week of month, weekday [1..7], every 1st,2nd,3th time, add 24 hours to start, (for night hours at last weekday of month)
my $duration = shift; # in minutes
my $week = shift; # every nth week of month
my $weekday = shift; # weekday [1..7]
my $frequency = shift; # every 1st,2nd,3th time
my $nextDay = shift; # add 24 hours to start, (for night hours at last weekday of month)
return undef if $start eq ''; return undef if $start eq '';
return undef if $end eq ''; return undef if $end eq '';
@@ -440,8 +430,7 @@ sub get_week_of_month_dates ($$$$$$$) {
#add duration to a single date #add duration to a single date
sub get_single_date ($$) { sub get_single_date ($$) {
my $start_datetime = shift; my ($start_datetime, $duration) = @_;
my $duration = shift;
my @start = @{ time::datetime_to_array($start_datetime) }; my @start = @{ time::datetime_to_array($start_datetime) };
return unless @start >= 6; return unless @start >= 6;
@@ -460,11 +449,8 @@ sub get_single_date ($$) {
#calculate all dates between start_datetime and end_date with duration(minutes) and frequency(days) #calculate all dates between start_datetime and end_date with duration(minutes) and frequency(days)
sub get_dates($$$$) { sub get_dates($$$$) {
my $start_datetime = shift; my ($start_datetime, $end_date, $duration, $frequency) = @_;
my $end_date = shift; # in minutes, in days
my $duration = shift; # in minutes
my $frequency = shift; # in days
#print "start_datetime:$start_datetime end_date:$end_date duration:$duration frequency:$frequency\n";
my @start = @{ time::datetime_to_array($start_datetime) }; my @start = @{ time::datetime_to_array($start_datetime) };
return unless @start >= 6; return unless @start >= 6;
@@ -537,8 +523,7 @@ sub delete ($$) {
# get all series dates where no event has been created for # get all series dates where no event has been created for
sub getDatesWithoutEvent ($$) { sub getDatesWithoutEvent ($$) {
my $config = shift; my ($config, $options) = @_;
my $options = shift;
return unless defined $options->{project_id}; return unless defined $options->{project_id};
return unless defined $options->{studio_id}; return unless defined $options->{studio_id};

View File

@@ -30,8 +30,7 @@ sub get_columns ($) {
#map schedule id to id #map schedule id to id
sub get($$) { sub get($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);

View File

@@ -25,8 +25,7 @@ sub get_columns ($){
# get all studio_timeslot_dates for studio_id within given time range # get all studio_timeslot_dates for studio_id within given time range
# calculate start_date, end_date, weeday, day from start and end(datetime) # calculate start_date, end_date, weeday, day from start and end(datetime)
sub get ($$){ sub get ($$){
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my $date_range_include = 0; my $date_range_include = 0;
$date_range_include = 1 if ( defined $condition->{date_range_include} ) && ( $condition->{date_range_include} == 1 ); $date_range_include = 1 if ( defined $condition->{date_range_include} ) && ( $condition->{date_range_include} == 1 );
@@ -171,10 +170,8 @@ sub update {
# calculate all start/end datetimes between start_date and stop_date with a frequency(days) # calculate all start/end datetimes between start_date and stop_date with a frequency(days)
# returns list of hashs with start and end # returns list of hashs with start and end
sub get_dates { sub get_dates {
my $start_datetime = shift; # start my ($start_datetime, $end_datetime, $stop_date, $frequency) = @_;
my $end_datetime = shift; # start #days
my $stop_date = shift; # limit recurring events
my $frequency = shift; # in days
my @start = @{ time::datetime_to_array($start_datetime) }; my @start = @{ time::datetime_to_array($start_datetime) };
return unless @start >= 6; return unless @start >= 6;
@@ -284,8 +281,7 @@ sub delete {
# time based filter to check if studio is assigned to an studio at a given time range # time based filter to check if studio is assigned to an studio at a given time range
# return 1 if there is a schedule date starting before start and ending after end # return 1 if there is a schedule date starting before start and ending after end
sub can_studio_edit_events { sub can_studio_edit_events {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my @conditions = (); my @conditions = ();
my @bind_values = (); my @bind_values = ();
@@ -348,8 +344,7 @@ sub can_studio_edit_events {
# returns hashref with start and end of merged slot # returns hashref with start and end of merged slot
# returns undef if not slot could be found # returns undef if not slot could be found
sub getMergedDays { sub getMergedDays {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my @conditions = (); my @conditions = ();
my @bind_values = (); my @bind_values = ();

View File

@@ -14,7 +14,7 @@ use studio_timeslot_dates();
our @EXPORT_OK = qw(get_columns get insert update delete); our @EXPORT_OK = qw(get_columns get insert update delete);
sub get_columns($) { sub get_columns($) {
my $config = shift; my ($config) = @_;
my $dbh = db::connect($config); my $dbh = db::connect($config);
return db::get_columns_hash( $dbh, 'calcms_studio_timeslot_schedule' ); return db::get_columns_hash( $dbh, 'calcms_studio_timeslot_schedule' );
@@ -22,8 +22,7 @@ sub get_columns($) {
#map schedule id to id #map schedule id to id
sub get($$) { sub get($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
@@ -62,8 +61,7 @@ sub get($$) {
} }
sub insert($$) { sub insert($$) {
my $config = shift; my ($config, $entry) = @_;
my $entry = shift;
return unless defined $entry->{project_id}; return unless defined $entry->{project_id};
return unless defined $entry->{studio_id}; return unless defined $entry->{studio_id};
@@ -77,8 +75,7 @@ sub insert($$) {
#schedule id to id #schedule id to id
sub update($$) { sub update($$) {
my $config = shift; my ($config, $entry) = @_;
my $entry = shift;
return unless defined $entry->{project_id}; return unless defined $entry->{project_id};
return unless defined $entry->{studio_id}; return unless defined $entry->{studio_id};
@@ -112,8 +109,7 @@ sub update($$) {
#map schedule id to id #map schedule id to id
sub delete ($$){ sub delete ($$){
my $config = shift; my ($config, $entry) = @_;
my $entry = shift;
return unless defined $entry->{schedule_id}; return unless defined $entry->{schedule_id};

View File

@@ -133,8 +133,8 @@ sub check_studio($$) {
} }
sub check ($$) { sub check ($$) {
my $config = shift; my ($config, $options) = @_;
my $options = shift;
return "missing studio_id" unless defined $options->{studio_id}; return "missing studio_id" unless defined $options->{studio_id};
return "Please select a studio" if ( $options->{studio_id} eq '-1' ); return "Please select a studio" if ( $options->{studio_id} eq '-1' );
return "Please select a studio" if ( $options->{studio_id} eq '' ); return "Please select a studio" if ( $options->{studio_id} eq '' );

View File

@@ -120,8 +120,8 @@ sub initTemplate($) {
sub setRelativeUrls; sub setRelativeUrls;
sub setRelativeUrls { sub setRelativeUrls {
my $params = shift; my ($params, $depth) = @_;
my $depth = shift || 0; $depth ||= 0;
return unless defined $params; return unless defined $params;
@@ -164,10 +164,9 @@ sub setRelativeUrls {
} }
sub check($;$$) { sub check($;$$) {
my $config = shift; my ($config, $template, $default) = @_;
my $template = shift || '';
my $default = shift;
$template ||= '';
if ( $template =~ /json\-p/ ) { if ( $template =~ /json\-p/ ) {
$template =~ s/[^a-zA-Z0-9\-\_\.]//g; $template =~ s/[^a-zA-Z0-9\-\_\.]//g;
$template =~ s/\.{2,99}/\./g; $template =~ s/\.{2,99}/\./g;

View File

@@ -79,28 +79,33 @@ sub getDurations() {
} }
sub getWeekdayNames(;$) { sub getWeekdayNames(;$) {
my $language = shift || 'en'; my ($language) = @_;
$language ||= 'en';
return $NAMES->{$language}->{weekdays}; return $NAMES->{$language}->{weekdays};
} }
sub getWeekdayNamesShort(;$) { sub getWeekdayNamesShort(;$) {
my $language = shift || 'en'; my ($language) = @_;
$language ||= 'en';
return $NAMES->{$language}->{weekdays_abbr}; return $NAMES->{$language}->{weekdays_abbr};
} }
sub getMonthNames(;$) { sub getMonthNames(;$) {
my $language = shift || 'en'; my ($language) = @_;
$language ||= 'en';
return $NAMES->{$language}->{months}; return $NAMES->{$language}->{months};
} }
sub getMonthNamesShort(;$) { sub getMonthNamesShort(;$) {
my $language = shift || 'en'; my ($language) = @_;
$language ||= 'en';
return $NAMES->{$language}->{months_abbr}; return $NAMES->{$language}->{months_abbr};
} }
sub getWeekdayIndex(;$) { sub getWeekdayIndex(;$) {
my $weekday = shift || ''; my ($weekday) = @_;
$weekday ||= '';
return $WEEKDAY_INDEX->{$weekday}; return $WEEKDAY_INDEX->{$weekday};
} }
@@ -130,7 +135,7 @@ sub getWeekdays {
#deprecated, for wordpress sync #deprecated, for wordpress sync
sub format_datetime(;$) { sub format_datetime(;$) {
my $datetime = shift; my ($datetime) = @_;
return $datetime if ( $datetime eq '' ); return $datetime if ( $datetime eq '' );
return add_hours_to_datetime( $datetime, 0 ); return add_hours_to_datetime( $datetime, 0 );
} }
@@ -184,40 +189,35 @@ sub datetime_to_rfc822($) {
#get seconds from epoch #get seconds from epoch
sub datetime_to_utc($$) { sub datetime_to_utc($$) {
my $datetime = shift; my ($datetime, $time_zone) = @_;
my $time_zone = shift;
$datetime = get_datetime( $datetime, $time_zone ); $datetime = get_datetime( $datetime, $time_zone );
return $datetime->epoch(); return $datetime->epoch();
} }
# get full utc datetime including timezone offset # get full utc datetime including timezone offset
sub datetime_to_utc_datetime($$) { sub datetime_to_utc_datetime($$) {
my $datetime = shift; my ($datetime, $time_zone) = @_;
my $time_zone = shift;
$datetime = get_datetime( $datetime, $time_zone ); $datetime = get_datetime( $datetime, $time_zone );
return $datetime->format_cldr("yyyy-MM-ddTHH:mm:ssZZZZZ"); return $datetime->format_cldr("yyyy-MM-ddTHH:mm:ssZZZZZ");
} }
#add hours to datetime string #add hours to datetime string
sub add_hours_to_datetime($;$) { sub add_hours_to_datetime($;$) {
my $datetime = shift; my ($datetime, $hours) = @_;
my $hours = shift;
$hours = 0 unless defined $hours; $hours = 0 unless defined $hours;
return time_to_datetime( datetime_to_time($datetime) + ( 3600 * $hours ) ); return time_to_datetime( datetime_to_time($datetime) + ( 3600 * $hours ) );
} }
#add minutes to datetime string #add minutes to datetime string
sub add_minutes_to_datetime($;$) { sub add_minutes_to_datetime($;$) {
my $datetime = shift; my ($datetime, $minutes) = @_;
my $minutes = shift;
$minutes = 0 unless defined $minutes; $minutes = 0 unless defined $minutes;
return time_to_datetime( datetime_to_time($datetime) + ( 60 * $minutes ) ); return time_to_datetime( datetime_to_time($datetime) + ( 60 * $minutes ) );
} }
#add days to datetime string #add days to datetime string
sub add_days_to_datetime($;$) { sub add_days_to_datetime($;$) {
my $datetime = shift; my ($datetime, $days) = @_;
my $days = shift;
$days = 0 unless defined $days; $days = 0 unless defined $days;
my $time = datetime_to_array($datetime); my $time = datetime_to_array($datetime);
@@ -226,8 +226,7 @@ sub add_days_to_datetime($;$) {
} }
sub add_days_to_date($;$) { sub add_days_to_date($;$) {
my $datetime = shift; my ($datetime, $days) = @_;
my $days = shift;
$days = 0 unless defined $days; $days = 0 unless defined $days;
my $date = date_to_array($datetime); my $date = date_to_array($datetime);
( $date->[0], $date->[1], $date->[2] ) = Date::Calc::Add_Delta_Days( $date->[0] + 0, $date->[1] + 0, $date->[2] + 0, $days ); ( $date->[0], $date->[1], $date->[2] ) = Date::Calc::Add_Delta_Days( $date->[0] + 0, $date->[1] + 0, $date->[2] + 0, $days );
@@ -236,7 +235,7 @@ sub add_days_to_date($;$) {
# convert unix time to datetime format # convert unix time to datetime format
sub time_to_datetime(;$) { sub time_to_datetime(;$) {
my $time = shift; my ($time) = @_;
$time = time() unless ( defined $time ) && ( $time ne '' ); $time = time() unless ( defined $time ) && ( $time ne '' );
my @t = localtime($time); my @t = localtime($time);
return sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0] ); return sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0] );
@@ -244,7 +243,7 @@ sub time_to_datetime(;$) {
# convert unix time to date format # convert unix time to date format
sub time_to_date(;$) { sub time_to_date(;$) {
my $time = shift; my ($time) = @_;
$time = time() unless ( defined $time ) && ( $time ne '' ); $time = time() unless ( defined $time ) && ( $time ne '' );
my @t = localtime($time); my @t = localtime($time);
return sprintf( '%04d-%02d-%02d', $t[5] + 1900, $t[4] + 1, $t[3] ); return sprintf( '%04d-%02d-%02d', $t[5] + 1900, $t[4] + 1, $t[3] );
@@ -252,7 +251,8 @@ sub time_to_date(;$) {
# convert datetime to a array of date/time values # convert datetime to a array of date/time values
sub datetime_to_array(;$) { sub datetime_to_array(;$) {
my $datetime = $_[0] || ''; my ($datetime) = @_;
$datetime ||= '';
if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)([T\s]+(\d+)\:(\d+)(\:(\d+))?)?/ ) { if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)([T\s]+(\d+)\:(\d+)(\:(\d+))?)?/ ) {
my $year = $1; my $year = $1;
my $month = $2; my $month = $2;
@@ -279,58 +279,55 @@ sub datetime_to_date(;$) {
#convert datetime array or single value to datetime string #convert datetime array or single value to datetime string
sub array_to_datetime(;$) { sub array_to_datetime(;$) {
my $date = shift; my ($date, $month, $day, $hour, $minute, $second) = @_;
if ( ref($date) eq 'ARRAY' ) { if ( ref($date) eq 'ARRAY' ) {
return sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $date->[0], $date->[1], $date->[2], $date->[3], $date->[4], $date->[5] ); return sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $date->[0], $date->[1], $date->[2], $date->[3], $date->[4], $date->[5] );
} }
my $month = shift;
my $day = shift; $hour ||= '0';
my $hour = shift || '0'; $minute ||= '0';
my $minute = shift || '0'; $second ||= '0';
my $second = shift || '0';
return sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $date, $month, $day, $hour, $minute, $second ); return sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $date, $month, $day, $hour, $minute, $second );
} }
#convert date array or single values to date string #convert date array or single values to date string
sub array_to_date($;$$) { sub array_to_date($;$$) {
my $date = shift; my ($date, $month, $day) = @_;
if ( ref($date) eq 'ARRAY' ) { if ( ref($date) eq 'ARRAY' ) {
return sprintf( "%04d-%02d-%02d", $date->[0], $date->[1], $date->[2] ); return sprintf( "%04d-%02d-%02d", $date->[0], $date->[1], $date->[2] );
} }
my $month = shift;
my $day = shift;
return sprintf( "%04d-%02d-%02d", $date, $month, $day ); return sprintf( "%04d-%02d-%02d", $date, $month, $day );
} }
sub array_to_time(;$) { sub array_to_time(;$) {
my $date = shift; my ($date, $minute, $second) = @_;
if ( ref($date) eq 'ARRAY' ) { if ( ref($date) eq 'ARRAY' ) {
return sprintf( "%02d:%02d:%02d", $date->[3], $date->[4], $date->[5] ); return sprintf( "%02d:%02d:%02d", $date->[3], $date->[4], $date->[5] );
} }
my $minute = shift || 0; $minute ||= '0';
my $second = shift || 0; $second ||= '0';
return sprintf( "%02d:%02d:%02d", $date, $minute, $second ); return sprintf( "%02d:%02d:%02d", $date, $minute, $second );
} }
sub array_to_time_hm(;$) { sub array_to_time_hm(;$) {
my $date = shift; my ($date, $minute) = @_;
if ( ref($date) eq 'ARRAY' ) { if ( ref($date) eq 'ARRAY' ) {
return sprintf( "%02d:%02d", $date->[3], $date->[4] ); return sprintf( "%02d:%02d", $date->[3], $date->[4] );
} }
my $minute = shift || 0; $minute ||= '0';
return sprintf( "%02d:%02d", $date, $minute ); return sprintf( "%02d:%02d", $date, $minute );
} }
# get number of days between two days # get number of days between two days
sub days_between($$) { sub days_between($$) {
my $today = $_[0]; my ($today, $date) = @_;
my $date = $_[1];
my $delta_days = eval { Date::Calc::Delta_Days( $today->[0], $today->[1], $today->[2], $date->[0], $date->[1], $date->[2] ) }; my $delta_days = eval { Date::Calc::Delta_Days( $today->[0], $today->[1], $today->[2], $date->[0], $date->[1], $date->[2] ) };
return $delta_days; return $delta_days;
} }
sub dayOfYear($) { sub dayOfYear($) {
my $datetime = $_[0]; my ($datetime) = @_;
if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)/ ) { if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)/ ) {
my $year = $1; my $year = $1;
my $month = $2; my $month = $2;
@@ -342,9 +339,7 @@ sub dayOfYear($) {
# get duration in minutes # get duration in minutes
sub get_duration($$$) { sub get_duration($$$) {
my $start = shift; my ($start, $end, $timezone) = @_;
my $end = shift;
my $timezone = shift;
$start = time::get_datetime( $start, $timezone ); $start = time::get_datetime( $start, $timezone );
$end = time::get_datetime( $end, $timezone ); $end = time::get_datetime( $end, $timezone );
my $duration = $end->epoch() - $start->epoch(); my $duration = $end->epoch() - $start->epoch();
@@ -353,9 +348,8 @@ sub get_duration($$$) {
# get duration in seconds # get duration in seconds
sub get_duration_seconds($$;$) { sub get_duration_seconds($$;$) {
my $start = shift; my ($start, $end, $timezone) = @_;
my $end = shift; $timezone ||= 'UTC';
my $timezone = shift || 'UTC';
unless ( defined $start ) { unless ( defined $start ) {
print STDERR "time::get_duration_seconds(): start is missing\n"; print STDERR "time::get_duration_seconds(): start is missing\n";
@@ -395,7 +389,7 @@ sub date_to_array($) {
# parse date string and return date string # parse date string and return date string
# pass 'today', return '' on parse error # pass 'today', return '' on parse error
sub date_cond($) { sub date_cond($) {
my $date = shift; my ($date) = @_;
return '' if ( $date eq '' ); return '' if ( $date eq '' );
if ( $date =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) { if ( $date =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) {
@@ -411,7 +405,7 @@ sub date_cond($) {
#parse time and return time string hh:mm:ss #parse time and return time string hh:mm:ss
#return hh:00 if time is 'now' #return hh:00 if time is 'now'
sub time_cond($) { sub time_cond($) {
my $time = shift; my ($time) = @_;
return '' if ( $time eq '' ); return '' if ( $time eq '' );
if ( $time =~ /(\d\d?)\:(\d\d?)(\:(\d\d))?/ ) { if ( $time =~ /(\d\d?)\:(\d\d?)(\:(\d\d))?/ ) {
@@ -432,7 +426,7 @@ sub time_cond($) {
#parse date and time string and return yyyy-mm-ddThh:mm:ss #parse date and time string and return yyyy-mm-ddThh:mm:ss
sub datetime_cond($) { sub datetime_cond($) {
my $datetime = shift; my ($datetime) = @_;
return '' if ( $datetime eq '' ); return '' if ( $datetime eq '' );
( my $date, my $time ) = split /[ T]/, $datetime; ( my $date, my $time ) = split /[ T]/, $datetime;
@@ -445,7 +439,7 @@ sub datetime_cond($) {
} }
sub check_date($) { sub check_date($) {
my $date = shift; my ($date) = @_;
return "" if ( !defined $date ) || ( $date eq '' ); return "" if ( !defined $date ) || ( $date eq '' );
if ( $date =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) { if ( $date =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) {
@@ -460,7 +454,7 @@ sub check_date($) {
} }
sub check_time($) { sub check_time($) {
my $time = shift; my ($time) = @_;
return "" if ( !defined $time ) || ( $time eq '' ); return "" if ( !defined $time ) || ( $time eq '' );
return $time if ( $time eq 'now' ) || ( $time eq 'future' ); return $time if ( $time eq 'now' ) || ( $time eq 'future' );
if ( $time =~ /(\d\d?)\:(\d\d?)/ ) { if ( $time =~ /(\d\d?)\:(\d\d?)/ ) {
@@ -470,7 +464,7 @@ sub check_time($) {
} }
sub check_datetime($) { sub check_datetime($) {
my $date = shift; my ($date) = @_;
return "" if ( !defined $date ) || ( $date eq '' ); return "" if ( !defined $date ) || ( $date eq '' );
if ( $date =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)[T ](\d\d?)\:(\d\d?)/ ) { if ( $date =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)[T ](\d\d?)\:(\d\d?)/ ) {
@@ -480,7 +474,7 @@ sub check_datetime($) {
} }
sub check_year_month($) { sub check_year_month($) {
my $date = shift; my ($date) = @_;
return -1 unless defined $date; return -1 unless defined $date;
return $date if ( $date eq '' ); return $date if ( $date eq '' );
if ( $date =~ /(\d\d\d\d)\-(\d\d?)/ ) { if ( $date =~ /(\d\d\d\d)\-(\d\d?)/ ) {
@@ -491,9 +485,8 @@ sub check_year_month($) {
#TODO: remove config dependency #TODO: remove config dependency
sub date_time_format($$;$) { sub date_time_format($$;$) {
my $config = shift; my ($config, $datetime, $language) = @_;
my $datetime = shift; $language ||= $config->{date}->{language} || 'en';
my $language = shift || $config->{date}->{language} || 'en';
if ( defined $datetime && $datetime =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)[\sT](\d\d?\:\d\d?)/ ) { if ( defined $datetime && $datetime =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)[\sT](\d\d?\:\d\d?)/ ) {
my $time = $4; my $time = $4;
my $day = $3; my $day = $3;
@@ -509,9 +502,8 @@ sub date_time_format($$;$) {
#format datetime to date string #format datetime to date string
#TODO: remove config dependency #TODO: remove config dependency
sub date_format($$;$) { sub date_format($$;$) {
my $config = shift; my ($config, $datetime, $language) = @_;
my $datetime = shift; $language ||= $config->{date}->{language} || 'en';
my $language = shift || $config->{date}->{language} || 'en';
if ( defined $datetime && $datetime =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) { if ( defined $datetime && $datetime =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) {
my $day = $3; my $day = $3;
@@ -525,7 +517,7 @@ sub date_format($$;$) {
#format datetime to time string #format datetime to time string
sub time_format($) { sub time_format($) {
my $datetime = shift; my ($datetime) = @_;
if ( defined $datetime && $datetime =~ /(\d\d?\:\d\d?)/ ) { if ( defined $datetime && $datetime =~ /(\d\d?\:\d\d?)/ ) {
return $1; return $1;
} }
@@ -534,7 +526,7 @@ sub time_format($) {
#get offset from given time_zone #get offset from given time_zone
sub utc_offset($) { sub utc_offset($) {
my $time_zone = shift; my ($time_zone) = @_;
my $datetime = DateTime->now(); my $datetime = DateTime->now();
$datetime->set_time_zone($time_zone); $datetime->set_time_zone($time_zone);
@@ -571,8 +563,7 @@ sub get_event_date($) {
#get datetime object from datetime string #get datetime object from datetime string
sub get_datetime(;$$) { sub get_datetime(;$$) {
my $datetime = shift; my ($datetime, $timezone) = @_;
my $timezone = shift;
return unless defined $datetime; return unless defined $datetime;
return if $datetime eq ''; return if $datetime eq '';
@@ -599,10 +590,8 @@ sub get_datetime(;$$) {
#get list of nth weekday in month from start to end #get list of nth weekday in month from start to end
sub get_nth_weekday_in_month(;$$$$) { sub get_nth_weekday_in_month(;$$$$) {
my $start = shift; # datetime string my ($start, $end, $nth, $weekday) = @_;
my $end = shift; # datetime string #datetime, datetime, every nth week of month, weekday [1..7,'Mo'-'Su','Mo'-'Fr']
my $nth = shift; # every nth week of month
my $weekday = shift; # weekday [1..7,'Mo'-'Su','Mo'-'Fr']
return [] unless defined $start; return [] unless defined $start;
return [] unless defined $end; return [] unless defined $end;

View File

@@ -526,8 +526,7 @@ sub get_role_id ($$) {
# assign a role to an user (for a studio) # assign a role to an user (for a studio)
sub assign_user_role($$) { sub assign_user_role($$) {
my $config = shift; my ($config, $options) = @_;
my $options = shift;
return undef unless defined $options->{project_id}; return undef unless defined $options->{project_id};
return undef unless defined $options->{studio_id}; return undef unless defined $options->{studio_id};
@@ -767,8 +766,7 @@ sub setDefaultProject ($$) {
} }
sub setDefaultStudio($$) { sub setDefaultStudio($$) {
my $params = shift; my ($params, $user_presets) = @_;
my $user_presets = shift;
$params->{studio_id} = $user_presets->{studio_id} $params->{studio_id} = $user_presets->{studio_id}
if ( !defined $params->{authAction} ) || ( $params->{authAction} eq '' ) || ( $params->{authAction} eq 'login' ); if ( !defined $params->{authAction} ) || ( $params->{authAction} eq '' ) || ( $params->{authAction} eq 'login' );
@@ -802,7 +800,7 @@ sub set_template_permissions ($$) {
#print error message #print error message
sub permissions_denied($) { sub permissions_denied($) {
my $message = shift; my ($message) = @_;
$message =~ s/_/ /g; $message =~ s/_/ /g;
print '<div class="error">Sorry! Missing permissions to ' . $message . '</div>' . "\n"; print '<div class="error">Sorry! Missing permissions to ' . $message . '</div>' . "\n";
print STDERR 'Sorry! Missing permissions to ' . $message . "\n"; print STDERR 'Sorry! Missing permissions to ' . $message . "\n";
@@ -823,7 +821,7 @@ sub print_warn($) {
} }
sub print_error ($) { sub print_error ($) {
my $message = shift; my ($message) = @_;
print STDERR "ERROR:" . $message . "\n"; print STDERR "ERROR:" . $message . "\n";
print '<div class="error" head>' print '<div class="error" head>'
. '<span class="ui-icon ui-icon-alert" style="float:left"></span>&nbsp;' . '<span class="ui-icon ui-icon-alert" style="float:left"></span>&nbsp;'

View File

@@ -17,8 +17,7 @@ sub get_columns($) {
} }
sub get ($$) { sub get ($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my @conditions = (); my @conditions = ();
my @bind_values = (); my @bind_values = ();
@@ -49,9 +48,7 @@ sub get ($$) {
} }
sub insert_or_update($$){ sub insert_or_update($$){
my $config = shift; my ($config, $entry) = @_;
my $entry = shift;
print STDERR Dumper $entry;
if ( get($config, $entry) ){ if ( get($config, $entry) ){
update ($config, $entry); update ($config, $entry);
} else { } else {

View File

@@ -17,8 +17,7 @@ sub get_columns($) {
} }
sub get ($$) { sub get ($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my @conditions = (); my @conditions = ();
my @bind_values = (); my @bind_values = ();

View File

@@ -19,8 +19,7 @@ sub get_columns($) {
} }
sub get ($$) { sub get ($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my @conditions = (); my @conditions = ();
my @bind_values = (); my @bind_values = ();

View File

@@ -66,8 +66,7 @@ our $defaultColors = [
]; ];
sub getColors($$) { sub getColors($$) {
my $config = shift; my ($config, $conditions) = @_;
my $conditions = shift;
return unless defined $conditions->{user}; return unless defined $conditions->{user};
my $user = $conditions->{user}; my $user = $conditions->{user};
@@ -101,8 +100,8 @@ sub getColors($$) {
} }
sub getColorCss ($$) { sub getColorCss ($$) {
my $config = shift; my ($config, $conditions) = @_;
my $conditions = shift;
return unless defined $conditions->{user}; return unless defined $conditions->{user};
my $shift = 20; my $shift = 20;
@@ -139,8 +138,7 @@ sub get_columns($) {
} }
sub get ($$) { sub get ($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);

View File

@@ -15,8 +15,7 @@ sub get_columns($) {
} }
sub get ($$) { sub get ($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
@@ -64,8 +63,7 @@ sub get ($$) {
} }
sub get_stats($$) { sub get_stats($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
@@ -184,9 +182,7 @@ sub update ($$) {
} }
sub increase ($$$) { sub increase ($$$) {
my $config = shift; my ($config, $usecase, $options) = @_;
my $usecase = shift;
my $options = shift;
return undef unless defined $usecase; return undef unless defined $usecase;
return undef unless defined $options->{project_id}; return undef unless defined $options->{project_id};
@@ -219,7 +215,7 @@ sub increase ($$$) {
} }
sub get_active_users{ sub get_active_users{
my $config = shift; my ($config) = @_;
my $dbh = db::connect($config); my $dbh = db::connect($config);

View File

@@ -28,8 +28,7 @@ sub get_columns($) {
# get all work_dates for studio_id and schedule_id within given time range # get all work_dates for studio_id and schedule_id within given time range
# calculate start_date, end_date, weeday, day from start and end(datetime) # calculate start_date, end_date, weeday, day from start and end(datetime)
sub get ($$) { sub get ($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my $date_range_include = 0; my $date_range_include = 0;
$date_range_include = 1 $date_range_include = 1
@@ -197,8 +196,7 @@ sub update($$) {
} }
sub get_schedule_dates($$) { sub get_schedule_dates($$) {
my $schedule = shift; my ($schedule, $options) = @_;
my $options = shift;
my $is_exclude = $options->{exclude} || 0; my $is_exclude = $options->{exclude} || 0;
my $dates = []; my $dates = [];
@@ -221,12 +219,8 @@ sub get_schedule_dates($$) {
} }
sub get_week_of_month_dates($$$$$$) { sub get_week_of_month_dates($$$$$$) {
my $start = shift; # datetime string my ($start, $end, $duration, $week, $weekday, $frequency) = @_;
my $end = shift; # datetime string # datetime, datetime, minutes, every nth week of month, weekday [1..7], every 1st,2nd,3th time
my $duration = shift; # in minutes
my $week = shift; # every nth week of month
my $weekday = shift; # weekday [1..7]
my $frequency = shift; # every 1st,2nd,3th time
return undef if $start eq ''; return undef if $start eq '';
return undef if $end eq ''; return undef if $end eq '';
@@ -265,8 +259,7 @@ sub get_week_of_month_dates($$$$$$) {
#add duration to a single date #add duration to a single date
sub get_single_date($$) { sub get_single_date($$) {
my $start_datetime = shift; my ($start_datetime, $duration) = @_;
my $duration = shift;
my @start = @{ time::datetime_to_array($start_datetime) }; my @start = @{ time::datetime_to_array($start_datetime) };
return unless @start >= 6; return unless @start >= 6;
@@ -285,11 +278,8 @@ sub get_single_date($$) {
#calculate all dates between start_datetime and end_date with duration(minutes) and frequency(days) #calculate all dates between start_datetime and end_date with duration(minutes) and frequency(days)
sub get_dates($$$$) { sub get_dates($$$$) {
my $start_datetime = shift; my ($start_datetime, $end_date, $duration, $frequency) = @_;
my $end_date = shift; #duration in seconds, frequency in minutes
my $duration = shift; # in minutes
my $frequency = shift; # in days
#print "start_datetime:$start_datetime end_date:$end_date duration:$duration frequency:$frequency\n";
my @start = @{ time::datetime_to_array($start_datetime) }; my @start = @{ time::datetime_to_array($start_datetime) };
return unless @start >= 6; return unless @start >= 6;

View File

@@ -28,8 +28,7 @@ sub get_columns($) {
#map schedule id to id #map schedule id to id
sub get($$) { sub get($$) {
my $config = shift; my ($config, $condition) = @_;
my $condition = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);