diff --git a/lib/Dojo.pm b/lib/Dojo.pm
index 107ab65..fb3a2d9 100755
--- a/lib/Dojo.pm
+++ b/lib/Dojo.pm
@@ -69,6 +69,7 @@ use Dojo::Model::Users;
$admin->any('eventos')->to('home#admin_eventos');
$admin->any('eventos/:type'=> [type=>['e','p','c']])->to('home#admin_eventos');
$admin->any('mensajes')->to('home#admin_mensajes');
+ $admin->any('tienda')->to('home#admin_tienda');
$admin->any('json/:dreq/:id')->to('home#admin_json');
# =============================================================================
diff --git a/lib/Dojo/Controller/Home.pm b/lib/Dojo/Controller/Home.pm
index 035b314..b7f2a1d 100755
--- a/lib/Dojo/Controller/Home.pm
+++ b/lib/Dojo/Controller/Home.pm
@@ -1,11 +1,48 @@
package Dojo::Controller::Home;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Template;
-#use Dojo::Support qw{ log dmph merge_hash load_module get_names};
use Dojo::Support qw{ log get_names};
+# estos son paypal=======:w
+use LWP::UserAgent;
+use HTTP::Request::Common;
+use JSON;
+use Data::Dumper;
+#=========================
sub tst{
my $c=shift;
- $c->render(text=> $c->config->{radio}{'channel'});
+ #credentials====
+ my $client='AQdZ1JJL-GNBgGTI3W6cXChmj6MnZsInRGlWeHw1kbGiE_49eTtZ2fPvEq9ersU2y6O5WpxccdsyAQw7';
+ my $secter='EBn8CNOCrJbVZ_fNllXB7oUIm9_vhtqrJMm2zSBGbxSyiiych3cHOIWOLAD5NVw4Z3dmNhmsHQwPsrZ0';
+ my $pauth='https://api.sandbox.paypal.com/v1/oauth2/token/';
+ my $porder='https://api.sandbox.paypal.com/v2/checkout/orders/2';
+ #=================
+ #pre auth ====
+my $ua = LWP::UserAgent->new;
+my $req=POST $pauth, ["grant_type"=>"client_credentials"];
+$req->authorization_basic($client,$secter);
+$req->content_type('application/x-www-form-urlencoded');
+my $res=$ua->request($req);
+log("paypal pre auth error! $res->status_line") unless ($res->is_success );
+my $json = JSON->new->utf8;
+my $r=$json->decode($res->decoded_content);
+#==============
+
+
+my $ub = LWP::UserAgent->new;
+$ub->default_header('Authorization'=> 'Bearer ' . $r->{access_token} );
+my $resb=$ub->get($porder);
+log("paypal checkout error!") unless ($resb->is_success );
+
+my $jsonb = JSON->new->utf8;
+my $s=$jsonb->decode($resb->decoded_content);
+
+
+
+
+
+ $c->stash(res=>" $r->{expires_in} $s->{name}");
+ $c->stash(layout=>'default');
+ #$c->render(text=> $c->config->{radio}{'channel'});
}
# User ========================================================================
@@ -185,6 +222,14 @@ sub bcast{
$c->stash(template=>"home/admin/event");
$c->stash(layout=>"admin");
}
+ sub admin_tienda{
+ my $c=shift;
+ $c->stash(u=>$c->dbv->user_heads);
+ $c->stash(s=>$c->dbv->store_heads);
+ $c->stash(template=>"home/admin/tienda");
+ $c->stash(layout=>"admin");
+
+ }
sub admin_json{
my $c=shift;
@@ -192,6 +237,8 @@ sub bcast{
my $req = $c->param('dreq');
my $json = "304";
$json = $c->dbv->msg($id) if $req=~/mensaje/;
+ $json = $c->dbv->user($id) if $req=~/usuarios/;
+ $json = $c->dbv->astore($id) if $req=~/tienda/;
$json = $c->dbv->course($id) if $req=~/course/;
$json = $c->dbv->place($id) if $req=~/place/;
$json = $c->dbv->eventa($id) if $req=~/event/;
diff --git a/lib/Dojo/Model/Data/admin/tienda/json/qStore.q b/lib/Dojo/Model/Data/admin/tienda/json/qStore.q
new file mode 100644
index 0000000..82f26e5
--- /dev/null
+++ b/lib/Dojo/Model/Data/admin/tienda/json/qStore.q
@@ -0,0 +1,4 @@
+select
+ a.id,a.nombre,a.existencia,a.imagen,a.precio,a.activo,a.descripcion,date(a.vigencia) as vigencia,b.nombre as entrega
+from tienda as a inner join entrega as b where a.entrega_id=b.id
+and a.id=?;
diff --git a/lib/Dojo/Model/Data/admin/tienda/json/qUsers.q b/lib/Dojo/Model/Data/admin/tienda/json/qUsers.q
new file mode 100755
index 0000000..7cd1b29
--- /dev/null
+++ b/lib/Dojo/Model/Data/admin/tienda/json/qUsers.q
@@ -0,0 +1,4 @@
+select
+correo,telefono as tel, observacion as obs,date(ultima) as ultima
+from usuario where id=?;
+
diff --git a/lib/Dojo/Model/Data/admin/tienda/qStore.q b/lib/Dojo/Model/Data/admin/tienda/qStore.q
new file mode 100644
index 0000000..707bff3
--- /dev/null
+++ b/lib/Dojo/Model/Data/admin/tienda/qStore.q
@@ -0,0 +1,3 @@
+select
+ id,nombre,existencia,precio,activo
+from tienda order by id;
diff --git a/lib/Dojo/Model/Data/admin/tienda/qUsers.q b/lib/Dojo/Model/Data/admin/tienda/qUsers.q
new file mode 100755
index 0000000..6c1d65c
--- /dev/null
+++ b/lib/Dojo/Model/Data/admin/tienda/qUsers.q
@@ -0,0 +1,4 @@
+select
+id,usuario,nombre
+from usuario order by usuario;
+
diff --git a/lib/Dojo/Model/Vuelo.pm b/lib/Dojo/Model/Vuelo.pm
index 1926b5b..031f974 100755
--- a/lib/Dojo/Model/Vuelo.pm
+++ b/lib/Dojo/Model/Vuelo.pm
@@ -1,6 +1,6 @@
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 Dojo::Support qw{ log dmph} ;
use Mojo::Base 'Mojolicious::Controller';
@@ -83,6 +83,22 @@ sub podcast_infoHash{
$dbh->disconnect();
return shift @$h;
}
+
+ 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)}}
+
+
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;")}
@@ -94,9 +110,8 @@ sub podcast_infoHash{
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{
@@ -104,7 +119,7 @@ sub contact{
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|\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;
+}
sub load_md{
return "" unless
diff --git a/public/home/admin/tienda/tienda.css b/public/home/admin/tienda/tienda.css
new file mode 100755
index 0000000..86e7cc2
--- /dev/null
+++ b/public/home/admin/tienda/tienda.css
@@ -0,0 +1,29 @@
+section.messages{
+ justify-content:end;
+}
+article.select{
+ flex:1;
+ overflow:auto;
+ min-width:200px;
+ max-width:400px;
+
+}
+select.entry{
+ margin:10px;
+ min-height:400px;
+}
+option.entry{
+ margin:10px;
+}
+article.view{
+ flex:1;
+ min-width:200px;
+ max-width:500px;
+ padding-right: 40px;
+}
+article.view p{}
+div.spcr{
+ background-color:gray;
+ height:3px;
+ width:30px;
+}
diff --git a/public/home/admin/tienda/tienda.js b/public/home/admin/tienda/tienda.js
new file mode 100755
index 0000000..535e5d8
--- /dev/null
+++ b/public/home/admin/tienda/tienda.js
@@ -0,0 +1,23 @@
+
+d3.select("select#suser").on("change",function(){
+ var uid=d3.select("select#suser").node().value;
+ d3.json("/admin/json/usuarios/"+uid ,function(d){
+ if(d !=undefined) {if(d != 0){
+ d3.select("p#correo").text(d.correo);
+ d3.select("p#tel").text(d.tel);
+ d3.select("p#obs").text(d.obs);
+ d3.select("p#ultima").text(d.ultima);
+ }}});
+});
+
+d3.select("select#sentry").on("change",function(){
+ var tid=d3.select("select#sentry").node().value;
+ d3.json("/admin/json/tienda/"+tid ,function(d){
+ if(d !=undefined) {if(d != 0){
+ d3.select("p#imagen").text(d.imagen);
+ d3.select("p#precio").text(d.precio);
+ d3.select("p#descripcion").text(d.descripcion);
+ d3.select("p#vigencia").text(d.vigencia);
+ d3.select("p#entrega").text(d.entrega);
+ }}});
+});
diff --git a/templates/home/admin/tienda.html.ep b/templates/home/admin/tienda.html.ep
new file mode 100755
index 0000000..0b369fc
--- /dev/null
+++ b/templates/home/admin/tienda.html.ep
@@ -0,0 +1,62 @@
+% stash css=>["/home/admin/admin.css","/home/admin/tienda/tienda.css"];
+% stash js=>["/home/admin/tienda/tienda.js"];
+ correo tel obs ultima nombre correo mensaje nombre correo mensaje mensaje mensaje nombre correo mensaje <%= url_for("$controller/$action/img") %>
+ <%= url_for("$controller/$action/img") %>
+ %= url_for->path('/meself')
+
-%= url_for->path('/meself')
+<%= $res %>
+
-% foreach (@{$ilist}) { -<%= $_ %> -% } -