2019-03-14 03:19:54 -06:00
|
|
|
package Dojo::Model::Vuelo; use Mojo::File 'path';
|
2018-07-13 19:06:08 -05:00
|
|
|
use Mojo::JSON qw(decode_json encode_json);
|
2019-03-28 04:06:59 -06:00
|
|
|
use Dojo::Support qw{ log dmph} ;
|
2018-07-20 05:16:47 -05:00
|
|
|
use Mojo::Base 'Mojolicious::Controller';
|
|
|
|
|
|
2018-07-13 19:06:08 -05:00
|
|
|
|
|
|
|
|
use File::Basename;
|
2018-08-15 02:47:30 -05:00
|
|
|
use Encode qw(decode_utf8 encode_utf8);
|
2018-07-13 19:06:08 -05:00
|
|
|
use Text::Markdown qw{ markdown };
|
|
|
|
|
use DBI;
|
|
|
|
|
use Dojo::Conf;
|
|
|
|
|
|
|
|
|
|
sub new { bless {}, shift };
|
2019-03-12 19:20:30 -06:00
|
|
|
my $data_path = path('lib/Dojo/Model/Data')->make_path;
|
2018-08-16 03:26:43 +00:00
|
|
|
#just for fun
|
2018-07-13 19:06:08 -05:00
|
|
|
|
2018-07-20 05:16:47 -05:00
|
|
|
# Read vdg user ===============================================================
|
2019-03-12 19:20:30 -06:00
|
|
|
# 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;
|
|
|
|
|
}
|
2018-07-20 05:16:47 -05:00
|
|
|
|
2019-03-12 19:20:30 -06:00
|
|
|
sub pang_md{
|
|
|
|
|
my $c=shift;
|
2019-03-14 03:19:54 -06:00
|
|
|
my %h = map {
|
|
|
|
|
$_=> markdown(decode_utf8($data_path->child('pang/'.$_.'.md')->slurp))
|
|
|
|
|
} ("pang","helen","benjamin");
|
2019-03-12 19:20:30 -06:00
|
|
|
return \%h;
|
|
|
|
|
}
|
2018-07-20 05:16:47 -05:00
|
|
|
|
2019-03-12 19:20:30 -06:00
|
|
|
sub calendar_monthblock {
|
|
|
|
|
return _read ($data_path->child("cal/q1Block.q")->slurp);
|
|
|
|
|
}
|
|
|
|
|
sub calendar_events {
|
|
|
|
|
return _read ($data_path->child("cal/q3Event.q")->slurp);
|
|
|
|
|
}
|
2018-07-20 05:16:47 -05:00
|
|
|
|
2019-03-12 19:20:30 -06:00
|
|
|
sub event{
|
|
|
|
|
my ($c,$id)=@_;
|
|
|
|
|
return shift @{ _read ($data_path->child("event/qEvent.q")->slurp,$id)};
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
2019-03-14 03:19:54 -06:00
|
|
|
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;
|
|
|
|
|
}
|
2018-07-27 18:55:22 -05:00
|
|
|
|
2018-07-20 05:16:47 -05:00
|
|
|
#==============================================================================
|
|
|
|
|
|
|
|
|
|
# Read vdg admin ==============================================================
|
|
|
|
|
sub msg_heads{
|
|
|
|
|
my ($self,@bind)=@_;
|
|
|
|
|
my @empty;
|
2019-03-14 03:19:54 -06:00
|
|
|
my $q= $data_path->child("/admin/mensajes/qEntries.q")->slurp;
|
2018-08-15 07:59:04 +00:00
|
|
|
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});
|
2018-07-20 05:16:47 -05:00
|
|
|
return \@empty unless($dbh);
|
2018-08-16 03:18:46 +00:00
|
|
|
my $h=$dbh->selectall_arrayref($q,{ Slice => {} },@bind)//"error";
|
2018-07-20 05:16:47 -05:00
|
|
|
#((col1=>d1,col2=>d1),(col1=>d2,col2=>d2))
|
|
|
|
|
$dbh->disconnect();
|
|
|
|
|
return $h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub msg{
|
|
|
|
|
my ($c,@bind)=@_;
|
|
|
|
|
my @empty;
|
2019-03-14 03:19:54 -06:00
|
|
|
my $q= $data_path->child("/admin/mensajes/json/qGetInfo.q")->slurp;
|
2018-08-15 07:59:04 +00:00
|
|
|
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});
|
2018-07-20 05:16:47 -05:00
|
|
|
return \@empty unless($dbh);
|
2018-08-16 03:18:46 +00:00
|
|
|
my $h=$dbh->selectall_arrayref($q,{ Slice => {} },@bind)//\@empty;
|
2018-07-20 05:16:47 -05:00
|
|
|
#((col1=>d1,col2=>d1),(col1=>d2,col2=>d2))
|
|
|
|
|
$dbh->disconnect();
|
|
|
|
|
return shift @$h;
|
|
|
|
|
}
|
2019-03-28 04:06:59 -06:00
|
|
|
|
|
|
|
|
sub user_heads{
|
|
|
|
|
return _readgrulla($data_path->child("admin/tienda/qUsers.q")->slurp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub store_heads{
|
|
|
|
|
return _readgrulla($data_path->child("admin/tienda/qStore.q")->slurp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub user {
|
|
|
|
|
return shift @{_readgrulla($data_path->child("admin/tienda/json/qUsers.q")->slurp,pop)}}
|
|
|
|
|
|
|
|
|
|
sub astore {
|
|
|
|
|
return shift @{_readgrulla($data_path->child("/admin/tienda/json/qStore.q")->slurp,pop)}}
|
|
|
|
|
|
|
|
|
|
|
2018-07-20 05:16:47 -05:00
|
|
|
sub courses{ return _read("select nombre as name, id from curso;")}
|
2019-03-14 03:19:54 -06:00
|
|
|
sub course { return shift @{_read($data_path->child("/admin/event/json/qCourse.q")->slurp,pop)}}
|
2018-07-20 05:16:47 -05:00
|
|
|
sub places { return _read("select nombre as name, id from lugar;")}
|
2019-03-14 03:19:54 -06:00
|
|
|
sub place { return shift @{_read($data_path->child("/admin/event/json/qPlace.q")->slurp,pop)}}
|
2018-07-20 05:16:47 -05:00
|
|
|
sub months { return _read("select nombre as name, id from mes;")};
|
2019-03-14 03:19:54 -06:00
|
|
|
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)}}
|
2019-03-14 04:12:19 -06:00
|
|
|
# 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} ];
|
|
|
|
|
}
|
2019-03-28 04:06:59 -06:00
|
|
|
|
2018-07-20 05:16:47 -05:00
|
|
|
#==============================================================================
|
2018-08-15 05:07:04 +00:00
|
|
|
# Write vdg user ==============================================================
|
2019-03-12 19:20:30 -06:00
|
|
|
sub contact{
|
|
|
|
|
my $c=shift;
|
|
|
|
|
my $q="insert into entrada (nombre,correo,pagina,texto,fecha) values(?,?,?,?,now() )" ;
|
|
|
|
|
my @a=@_;
|
|
|
|
|
#simple method to ignore spam
|
2020-01-15 23:42:58 -06:00
|
|
|
return _writemsg($q,@a) unless $a[3]=~m/http|website|\<a|feedback|forms|suscribe|advertise|newsletter|promotion|Madam|Sir/;
|
2019-03-12 19:20:30 -06:00
|
|
|
return 0;
|
2018-08-15 05:07:04 +00:00
|
|
|
}
|
|
|
|
|
#==============================================================================
|
2018-07-20 05:16:47 -05:00
|
|
|
# Write vdg admin ==============================================================
|
2019-03-14 03:19:54 -06:00
|
|
|
sub umod{
|
|
|
|
|
my $c=shift;
|
|
|
|
|
my $q="update casa set contenido = ? where nombre = ? ;";
|
|
|
|
|
return _write($q,@_);
|
|
|
|
|
}
|
2018-07-20 05:16:47 -05:00
|
|
|
|
2019-03-14 03:19:54 -06:00
|
|
|
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);
|
|
|
|
|
}
|
2018-07-20 05:16:47 -05:00
|
|
|
|
|
|
|
|
#==============================================================================
|
2018-07-13 19:06:08 -05:00
|
|
|
|
2018-07-20 05:16:47 -05:00
|
|
|
#ayudas =====================================
|
|
|
|
|
sub tst{
|
2018-07-19 03:45:46 -05:00
|
|
|
|
2018-07-18 16:04:47 -05:00
|
|
|
my $c=shift;
|
2018-07-20 05:16:47 -05:00
|
|
|
my $d=$c->param('n');
|
|
|
|
|
log("------log-------");
|
|
|
|
|
log("$d");
|
|
|
|
|
log("------log-------");
|
|
|
|
|
return 0;
|
2018-07-19 03:45:46 -05:00
|
|
|
}
|
|
|
|
|
|
2018-07-13 19:06:08 -05:00
|
|
|
sub _read{
|
2018-07-18 04:28:26 -05:00
|
|
|
my ($q,@bind)=@_;
|
2018-07-20 05:16:47 -05:00
|
|
|
my @empty;
|
2018-08-15 02:47:30 -05:00
|
|
|
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});
|
2018-07-13 19:06:08 -05:00
|
|
|
return \@empty unless($dbh);
|
2018-08-16 03:18:46 +00:00
|
|
|
my $h=$dbh->selectall_arrayref($q,{ Slice => {} },@bind)//"error";
|
2018-07-13 19:06:08 -05:00
|
|
|
$dbh->disconnect();
|
2018-07-20 05:16:47 -05:00
|
|
|
#((col1=>d1,col2=>d1),(col1=>d2,col2=>d2))
|
2018-07-13 19:06:08 -05:00
|
|
|
return $h;
|
|
|
|
|
}
|
2018-07-20 05:16:47 -05:00
|
|
|
|
2018-07-18 04:28:26 -05:00
|
|
|
sub _write{
|
2018-07-20 05:16:47 -05:00
|
|
|
my ($q,@bind)=@_;
|
2018-07-18 04:28:26 -05:00
|
|
|
my (@empty);
|
2018-08-15 07:59:04 +00:00
|
|
|
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} );
|
2018-07-18 04:28:26 -05:00
|
|
|
return 0 unless($dbh);
|
2018-08-16 03:18:46 +00:00
|
|
|
my $h=$dbh->do($q,{ Slice => {} },@bind)//"error";
|
2018-07-18 04:28:26 -05:00
|
|
|
$dbh->disconnect();
|
2018-07-20 05:16:47 -05:00
|
|
|
log("db write: $h");
|
2018-07-18 04:28:26 -05:00
|
|
|
return $h;
|
|
|
|
|
}
|
2018-07-13 19:06:08 -05:00
|
|
|
|
2018-08-15 05:07:04 +00:00
|
|
|
sub _writemsg{
|
|
|
|
|
my ($q,@bind)=@_;
|
|
|
|
|
my (@empty);
|
2018-08-15 07:59:04 +00:00
|
|
|
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});
|
2018-08-15 05:07:04 +00:00
|
|
|
return 0 unless($dbh);
|
2018-08-16 03:18:46 +00:00
|
|
|
my $h=$dbh->do($q,{ Slice => {} },@bind)//"error";
|
2018-08-15 05:07:04 +00:00
|
|
|
$dbh->disconnect();
|
|
|
|
|
log("db write: $h");
|
|
|
|
|
return $h;
|
|
|
|
|
}
|
2019-03-28 04:06:59 -06:00
|
|
|
sub _readgrulla{
|
|
|
|
|
my ($q,@bind)=@_;
|
|
|
|
|
my @empty;
|
|
|
|
|
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::GRULLADB.":".Dojo::Conf::GRULLADB_H,Dojo::Conf::GRULLADB_UR,Dojo::Conf::GRULLADB_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 _writegrulla{
|
|
|
|
|
my ($q,@bind)=@_;
|
|
|
|
|
my (@empty);
|
|
|
|
|
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::GRULLADB.":".Dojo::Conf::GRULLADB_H,Dojo::Conf::GRULLADB_UW,Dojo::Conf::GRULLADB_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;
|
|
|
|
|
}
|
2018-08-15 05:07:04 +00:00
|
|
|
|
2018-07-13 19:06:08 -05:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-17 23:26:10 +00:00
|
|
|
1;
|
|
|
|
|
|