207 lines
6.5 KiB
Perl
Executable File
207 lines
6.5 KiB
Perl
Executable File
package Dojo::Model::Vuelo; use Mojo::File 'path';
|
|
use Mojo::JSON qw(decode_json encode_json);
|
|
use Dojo::Support qw{ log dmph merge_hash load_module get_names};
|
|
use Mojo::Base 'Mojolicious::Controller';
|
|
|
|
|
|
use File::Basename;
|
|
use Encode qw(decode_utf8 encode_utf8);
|
|
use Text::Markdown qw{ markdown };
|
|
use DBI;
|
|
use Dojo::Conf;
|
|
|
|
sub new { bless {}, shift };
|
|
my $data_path = path('lib/Dojo/Model/Data')->make_path;
|
|
#just for fun
|
|
|
|
# Read vdg user ===============================================================
|
|
# mensaje del día:mod,rmod,yt,fb,sc
|
|
sub mod{
|
|
my $q="select nombre,contenido from casa;";
|
|
my %h=map{ $_->{nombre} => $_->{contenido}}@{_read($q)};
|
|
return %h;
|
|
}
|
|
|
|
sub pang_md{
|
|
my $c=shift;
|
|
my %h = map {
|
|
$_=> markdown(decode_utf8($data_path->child('pang/'.$_.'.md')->slurp))
|
|
} ("pang","helen","benjamin");
|
|
return \%h;
|
|
}
|
|
|
|
sub calendar_monthblock {
|
|
return _read ($data_path->child("cal/q1Block.q")->slurp);
|
|
}
|
|
sub calendar_events {
|
|
return _read ($data_path->child("cal/q3Event.q")->slurp);
|
|
}
|
|
|
|
sub event{
|
|
my ($c,$id)=@_;
|
|
return shift @{ _read ($data_path->child("event/qEvent.q")->slurp,$id)};
|
|
}
|
|
sub store{
|
|
return _read ($data_path->child("/store/qStore.q")->slurp);
|
|
}
|
|
sub tv_videos{
|
|
return _read ($data_path->child("/tv/qSeries.q")->slurp); #group,name
|
|
}
|
|
sub tv_series{
|
|
return _read ($data_path->child("/tv/qTable.q")->slurp); #name,order,group
|
|
}
|
|
sub podcast_txt{
|
|
return decode_utf8($data_path->child("/podcast/text.txt")->slurp);
|
|
}
|
|
sub podcast_infoHash{
|
|
return decode_json $data_path->child("/podcast/podcast.json")->slurp;
|
|
}
|
|
|
|
#==============================================================================
|
|
|
|
# Read vdg admin ==============================================================
|
|
sub msg_heads{
|
|
my ($self,@bind)=@_;
|
|
my @empty;
|
|
my $q= $data_path->child("/admin/mensajes/qEntries.q")->slurp;
|
|
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::MSGDB.":".Dojo::Conf::MSGDB_H,Dojo::Conf::MSGDB_UR,Dojo::Conf::MSGDB_URP,{mysql_enable_utf8 => 1});
|
|
return \@empty unless($dbh);
|
|
my $h=$dbh->selectall_arrayref($q,{ Slice => {} },@bind)//"error";
|
|
#((col1=>d1,col2=>d1),(col1=>d2,col2=>d2))
|
|
$dbh->disconnect();
|
|
return $h;
|
|
}
|
|
|
|
sub msg{
|
|
my ($c,@bind)=@_;
|
|
my @empty;
|
|
my $q= $data_path->child("/admin/mensajes/json/qGetInfo.q")->slurp;
|
|
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::MSGDB.":".Dojo::Conf::MSGDB_H,Dojo::Conf::MSGDB_UR,Dojo::Conf::MSGDB_URP,{mysql_enable_utf8 => 1});
|
|
return \@empty unless($dbh);
|
|
my $h=$dbh->selectall_arrayref($q,{ Slice => {} },@bind)//\@empty;
|
|
#((col1=>d1,col2=>d1),(col1=>d2,col2=>d2))
|
|
$dbh->disconnect();
|
|
return shift @$h;
|
|
}
|
|
sub courses{ return _read("select nombre as name, id from curso;")}
|
|
sub course { return shift @{_read($data_path->child("/admin/event/json/qCourse.q")->slurp,pop)}}
|
|
sub places { return _read("select nombre as name, id from lugar;")}
|
|
sub place { return shift @{_read($data_path->child("/admin/event/json/qPlace.q")->slurp,pop)}}
|
|
sub months { return _read("select nombre as name, id from mes;")};
|
|
sub events { return _read($data_path->child("/admin/event/qEprev.q")->slurp)}
|
|
sub eventa { return shift @{_read($data_path->child("/admin/event/json/qEvent.q")->slurp,pop)}}
|
|
# sub eimgList{ return [get_names("public/home/cal/img/")] }
|
|
sub eimgList{
|
|
my $dp = path('public/home/cal/img')->make_path;
|
|
return [ map{ $_->basename} grep{/(jpg|png)$/i}@{$dp->list} ];
|
|
|
|
|
|
}
|
|
#==============================================================================
|
|
# Write vdg user ==============================================================
|
|
sub contact{
|
|
my $c=shift;
|
|
my $q="insert into entrada (nombre,correo,pagina,texto,fecha) values(?,?,?,?,now() )" ;
|
|
my @a=@_;
|
|
#simple method to ignore spam
|
|
return _writemsg($q,@a) unless $a[3]=~m/http|website|\<a/;
|
|
return 0;
|
|
}
|
|
#==============================================================================
|
|
# Write vdg admin ==============================================================
|
|
sub umod{
|
|
my $c=shift;
|
|
my $q="update casa set contenido = ? where nombre = ? ;";
|
|
return _write($q,@_);
|
|
}
|
|
|
|
sub event_del { return _write("delete from evento where id = ?;",pop);}
|
|
sub course_del{ return _write("delete from curso where id = ?;",pop); }
|
|
sub place_del { return _write("delete from lugar where id = ?;",pop); }
|
|
|
|
sub event_up{
|
|
my ($self,@bind)=@_;
|
|
return _write($data_path->child("/admin/event/add/qEup.q")->slurp,@bind);
|
|
}
|
|
sub course_up{
|
|
my ($self,@bind)=@_;
|
|
return _write($data_path->child("/admin/event/add/qCup.q")->slurp,@bind);
|
|
}
|
|
sub place_up{
|
|
my ($self,@bind)=@_;
|
|
return _write($data_path->child("/admin/event/add/qPup.q")->slurp,@bind);
|
|
}
|
|
sub event_ch{
|
|
my ($self,@bind)=@_;
|
|
return _write($data_path->child("/admin/event/change/qEup.q")->slurp,@bind);
|
|
}
|
|
sub course_ch{
|
|
my ($self,@bind)=@_;
|
|
return _write($data_path->child("/admin/event/change/qCup.q")->slurp,@bind);
|
|
}
|
|
sub place_ch{
|
|
my ($self,@bind)=@_;
|
|
return _write($data_path->child("/admin/event/change/qPup.q")->slurp,@bind);
|
|
}
|
|
|
|
#==============================================================================
|
|
|
|
#ayudas =====================================
|
|
sub tst{
|
|
|
|
my $c=shift;
|
|
my $d=$c->param('n');
|
|
log("------log-------");
|
|
log("$d");
|
|
log("------log-------");
|
|
return 0;
|
|
}
|
|
|
|
sub _read{
|
|
my ($q,@bind)=@_;
|
|
my @empty;
|
|
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::VUELODB.":".Dojo::Conf::VUELODB_H,Dojo::Conf::VUELODB_UR,Dojo::Conf::VUELODB_URP, {mysql_enable_utf8 => 1});
|
|
return \@empty unless($dbh);
|
|
my $h=$dbh->selectall_arrayref($q,{ Slice => {} },@bind)//"error";
|
|
$dbh->disconnect();
|
|
#((col1=>d1,col2=>d1),(col1=>d2,col2=>d2))
|
|
return $h;
|
|
}
|
|
|
|
sub _write{
|
|
my ($q,@bind)=@_;
|
|
my (@empty);
|
|
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::VUELODB.":".Dojo::Conf::VUELODB_H,Dojo::Conf::VUELODB_UW,Dojo::Conf::VUELODB_UWP,{mysql_enable_utf8 => 1} );
|
|
return 0 unless($dbh);
|
|
my $h=$dbh->do($q,{ Slice => {} },@bind)//"error";
|
|
$dbh->disconnect();
|
|
log("db write: $h");
|
|
return $h;
|
|
}
|
|
|
|
sub _writemsg{
|
|
my ($q,@bind)=@_;
|
|
my (@empty);
|
|
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::MSGDB.":".Dojo::Conf::MSGDB_H,Dojo::Conf::MSGDB_UW,Dojo::Conf::MSGDB_UWP,{mysql_enable_utf8 => 1});
|
|
return 0 unless($dbh);
|
|
my $h=$dbh->do($q,{ Slice => {} },@bind)//"error";
|
|
$dbh->disconnect();
|
|
log("db write: $h");
|
|
return $h;
|
|
}
|
|
|
|
sub load_md{
|
|
return "" unless
|
|
my $text = path(shift)->slurp;
|
|
return markdown( decode_utf8($text) );
|
|
}
|
|
|
|
sub load_txt{
|
|
return "" unless
|
|
my $text = path(shift)->slurp;
|
|
return decode_utf8($text);
|
|
}
|
|
|
|
1;
|
|
|