Jelajahi Sumber

Last commit

Gabriel Badano 4 tahun lalu
induk
melakukan
38aa31f533

+ 77 - 21
assets/css/startmin.css

@@ -19,7 +19,7 @@ body {
     background-color: #fff;
 }
 
-@media(min-width:768px) {
+@media (min-width: 768px) {
     #page-wrapper {
         position: inherit;
         margin-left: 250px;
@@ -57,11 +57,11 @@ body {
     min-height: 50px;
 }
 
-.navbar-top-links>li>a {
+.navbar-top-links > li > a {
     color: #999;
 }
 
-.navbar-top-links>li>a:hover, .navbar-top-links>li>a:focus, .navbar-top-links>.open>a, .navbar-top-links>.open>a:hover, .navbar-top-links>.open>a:focus {
+.navbar-top-links > li > a:hover, .navbar-top-links > li > a:focus, .navbar-top-links > .open > a, .navbar-top-links > .open > a:hover, .navbar-top-links > .open > a:focus {
     color: #fff;
     background-color: #222;
 }
@@ -132,13 +132,13 @@ body {
     content: "\f104";
 }
 
-.sidebar .active>a>.fa.arrow:before {
+.sidebar .active > a > .fa.arrow:before {
     content: "\f107";
 }
 
 .sidebar .nav-second-level li,
 .sidebar .nav-third-level li {
-    border-bottom: 0!important;
+    border-bottom: 0 !important;
 }
 
 .sidebar .nav-second-level li a {
@@ -149,7 +149,7 @@ body {
     padding-left: 52px;
 }
 
-@media(min-width:768px) {
+@media (min-width: 768px) {
     .sidebar {
         z-index: 1;
         position: absolute;
@@ -275,7 +275,7 @@ table.dataTable thead .sorting:after {
     content: "\f0dc";
     float: right;
     font-family: fontawesome;
-    color: rgba(50,50,50,.5);
+    color: rgba(50, 50, 50, .5);
 }
 
 .btn-circle {
@@ -310,7 +310,7 @@ table.dataTable thead .sorting:after {
     padding-top: 10px;
     padding-bottom: 10px;
     border: 1px solid #ddd;
-    background-color: #eee!important;
+    background-color: #eee !important;
 }
 
 .show-grid {
@@ -381,6 +381,7 @@ table.dataTable thead .sorting:after {
     padding-top: 20px;
     padding-bottom: 20px;
 }
+
 .hero-widget .icon {
     display: block;
     font-size: 96px;
@@ -388,6 +389,7 @@ table.dataTable thead .sorting:after {
     margin-bottom: 10px;
     text-align: center;
 }
+
 .hero-widget .value {
     display: block;
     height: 64px;
@@ -395,27 +397,37 @@ table.dataTable thead .sorting:after {
     line-height: 64px;
     font-style: normal;
 }
-.hero-widget label { font-size: 17px; }
-.hero-widget .options { margin-top: 10px; }
+
+.hero-widget label {
+    font-size: 17px;
+}
+
+.hero-widget .options {
+    margin-top: 10px;
+}
 
 /* Tabbed Panels */
-.panel.tabbed-panel .panel-heading{
+.panel.tabbed-panel .panel-heading {
     padding-top: 5px;
     padding-right: 5px;
     padding-bottom: 0;
 }
-.panel.tabbed-panel .panel-heading .panel-title{
+
+.panel.tabbed-panel .panel-heading .panel-title {
     padding: 9px 0;
     font-size: 1em;
     line-height: 1em;
 }
-.panel.tabbed-panel .nav-tabs{
+
+.panel.tabbed-panel .nav-tabs {
     border-bottom: none;
 }
-.panel.tabbed-panel .nav-tabs > li > a{
+
+.panel.tabbed-panel .nav-tabs > li > a {
     line-height: 1em;
 }
-.panel.tabbed-panel .nav-justified{
+
+.panel.tabbed-panel .nav-justified {
     margin-bottom: -1px;
 }
 
@@ -424,6 +436,7 @@ table.dataTable thead .sorting:after {
 .tabbed-panel.panel-default .nav-tabs > li > a:focus {
     color: #777;
 }
+
 .tabbed-panel.panel-default .nav-tabs > .open > a,
 .tabbed-panel.panel-default .nav-tabs > .open > a:hover,
 .tabbed-panel.panel-default .nav-tabs > .open > a:focus,
@@ -433,6 +446,7 @@ table.dataTable thead .sorting:after {
     background-color: #ddd;
     border-color: transparent;
 }
+
 .tabbed-panel.panel-default .nav-tabs > li.active > a,
 .tabbed-panel.panel-default .nav-tabs > li.active > a:hover,
 .tabbed-panel.panel-default .nav-tabs > li.active > a:focus {
@@ -441,17 +455,21 @@ table.dataTable thead .sorting:after {
     border-color: #ddd;
     border-bottom-color: transparent;
 }
+
 .tabbed-panel.panel-default .nav-tabs > li.dropdown .dropdown-menu {
     background-color: #f5f5f5;
     border-color: #ddd;
 }
+
 .tabbed-panel.panel-default .nav-tabs > li.dropdown .dropdown-menu > li > a {
     color: #777;
 }
+
 .tabbed-panel.panel-default .nav-tabs > li.dropdown .dropdown-menu > li > a:hover,
 .tabbed-panel.panel-default .nav-tabs > li.dropdown .dropdown-menu > li > a:focus {
     background-color: #ddd;
 }
+
 .tabbed-panel.panel-default .nav-tabs > li.dropdown .dropdown-menu > .active > a,
 .tabbed-panel.panel-default .nav-tabs > li.dropdown .dropdown-menu > .active > a:hover,
 .tabbed-panel.panel-default .nav-tabs > li.dropdown .dropdown-menu > .active > a:focus {
@@ -464,6 +482,7 @@ table.dataTable thead .sorting:after {
 .tabbed-panel.panel-primary .nav-tabs > li > a:focus {
     color: #fff;
 }
+
 .tabbed-panel.panel-primary .nav-tabs > .open > a,
 .tabbed-panel.panel-primary .nav-tabs > .open > a:hover,
 .tabbed-panel.panel-primary .nav-tabs > .open > a:focus,
@@ -473,6 +492,7 @@ table.dataTable thead .sorting:after {
     background-color: #3071a9;
     border-color: transparent;
 }
+
 .tabbed-panel.panel-primary .nav-tabs > li.active > a,
 .tabbed-panel.panel-primary .nav-tabs > li.active > a:hover,
 .tabbed-panel.panel-primary .nav-tabs > li.active > a:focus {
@@ -481,29 +501,33 @@ table.dataTable thead .sorting:after {
     border-color: #428bca;
     border-bottom-color: transparent;
 }
+
 .tabbed-panel.panel-primary .nav-tabs > li.dropdown .dropdown-menu {
     background-color: #428bca;
     border-color: #3071a9;
 }
+
 .tabbed-panel.panel-primary .nav-tabs > li.dropdown .dropdown-menu > li > a {
     color: #fff;
 }
+
 .tabbed-panel.panel-primary .nav-tabs > li.dropdown .dropdown-menu > li > a:hover,
 .tabbed-panel.panel-primary .nav-tabs > li.dropdown .dropdown-menu > li > a:focus {
     background-color: #3071a9;
 }
+
 .tabbed-panel.panel-primary .nav-tabs > li.dropdown .dropdown-menu > .active > a,
 .tabbed-panel.panel-primary .nav-tabs > li.dropdown .dropdown-menu > .active > a:hover,
 .tabbed-panel.panel-primary .nav-tabs > li.dropdown .dropdown-menu > .active > a:focus {
     background-color: #4a9fe9;
 }
 
-
 .tabbed-panel.panel-success .nav-tabs > li > a,
 .tabbed-panel.panel-success .nav-tabs > li > a:hover,
 .tabbed-panel.panel-success .nav-tabs > li > a:focus {
     color: #3c763d;
 }
+
 .tabbed-panel.panel-success .nav-tabs > .open > a,
 .tabbed-panel.panel-success .nav-tabs > .open > a:hover,
 .tabbed-panel.panel-success .nav-tabs > .open > a:focus,
@@ -513,6 +537,7 @@ table.dataTable thead .sorting:after {
     background-color: #d6e9c6;
     border-color: transparent;
 }
+
 .tabbed-panel.panel-success .nav-tabs > li.active > a,
 .tabbed-panel.panel-success .nav-tabs > li.active > a:hover,
 .tabbed-panel.panel-success .nav-tabs > li.active > a:focus {
@@ -521,17 +546,21 @@ table.dataTable thead .sorting:after {
     border-color: #d6e9c6;
     border-bottom-color: transparent;
 }
+
 .tabbed-panel.panel-success .nav-tabs > li.dropdown .dropdown-menu {
     background-color: #dff0d8;
     border-color: #d6e9c6;
 }
+
 .tabbed-panel.panel-success .nav-tabs > li.dropdown .dropdown-menu > li > a {
     color: #3c763d;
 }
+
 .tabbed-panel.panel-success .nav-tabs > li.dropdown .dropdown-menu > li > a:hover,
 .tabbed-panel.panel-success .nav-tabs > li.dropdown .dropdown-menu > li > a:focus {
     background-color: #d6e9c6;
 }
+
 .tabbed-panel.panel-success .nav-tabs > li.dropdown .dropdown-menu > .active > a,
 .tabbed-panel.panel-success .nav-tabs > li.dropdown .dropdown-menu > .active > a:hover,
 .tabbed-panel.panel-success .nav-tabs > li.dropdown .dropdown-menu > .active > a:focus {
@@ -544,6 +573,7 @@ table.dataTable thead .sorting:after {
 .tabbed-panel.panel-info .nav-tabs > li > a:focus {
     color: #31708f;
 }
+
 .tabbed-panel.panel-info .nav-tabs > .open > a,
 .tabbed-panel.panel-info .nav-tabs > .open > a:hover,
 .tabbed-panel.panel-info .nav-tabs > .open > a:focus,
@@ -553,6 +583,7 @@ table.dataTable thead .sorting:after {
     background-color: #bce8f1;
     border-color: transparent;
 }
+
 .tabbed-panel.panel-info .nav-tabs > li.active > a,
 .tabbed-panel.panel-info .nav-tabs > li.active > a:hover,
 .tabbed-panel.panel-info .nav-tabs > li.active > a:focus {
@@ -561,17 +592,21 @@ table.dataTable thead .sorting:after {
     border-color: #bce8f1;
     border-bottom-color: transparent;
 }
+
 .tabbed-panel.panel-info .nav-tabs > li.dropdown .dropdown-menu {
     background-color: #d9edf7;
     border-color: #bce8f1;
 }
+
 .tabbed-panel.panel-info .nav-tabs > li.dropdown .dropdown-menu > li > a {
     color: #31708f;
 }
+
 .tabbed-panel.panel-info .nav-tabs > li.dropdown .dropdown-menu > li > a:hover,
 .tabbed-panel.panel-info .nav-tabs > li.dropdown .dropdown-menu > li > a:focus {
     background-color: #bce8f1;
 }
+
 .tabbed-panel.panel-info .nav-tabs > li.dropdown .dropdown-menu > .active > a,
 .tabbed-panel.panel-info .nav-tabs > li.dropdown .dropdown-menu > .active > a:hover,
 .tabbed-panel.panel-info .nav-tabs > li.dropdown .dropdown-menu > .active > a:focus {
@@ -584,6 +619,7 @@ table.dataTable thead .sorting:after {
 .tabbed-panel.panel-warning .nav-tabs > li > a:focus {
     color: #8a6d3b;
 }
+
 .tabbed-panel.panel-warning .nav-tabs > .open > a,
 .tabbed-panel.panel-warning .nav-tabs > .open > a:hover,
 .tabbed-panel.panel-warning .nav-tabs > .open > a:focus,
@@ -593,6 +629,7 @@ table.dataTable thead .sorting:after {
     background-color: #faebcc;
     border-color: transparent;
 }
+
 .tabbed-panel.panel-warning .nav-tabs > li.active > a,
 .tabbed-panel.panel-warning .nav-tabs > li.active > a:hover,
 .tabbed-panel.panel-warning .nav-tabs > li.active > a:focus {
@@ -601,17 +638,21 @@ table.dataTable thead .sorting:after {
     border-color: #faebcc;
     border-bottom-color: transparent;
 }
+
 .tabbed-panel.panel-warning .nav-tabs > li.dropdown .dropdown-menu {
     background-color: #fcf8e3;
     border-color: #faebcc;
 }
+
 .tabbed-panel.panel-warning .nav-tabs > li.dropdown .dropdown-menu > li > a {
     color: #8a6d3b;
 }
+
 .tabbed-panel.panel-warning .nav-tabs > li.dropdown .dropdown-menu > li > a:hover,
 .tabbed-panel.panel-warning .nav-tabs > li.dropdown .dropdown-menu > li > a:focus {
     background-color: #faebcc;
 }
+
 .tabbed-panel.panel-warning .nav-tabs > li.dropdown .dropdown-menu > .active > a,
 .tabbed-panel.panel-warning .nav-tabs > li.dropdown .dropdown-menu > .active > a:hover,
 .tabbed-panel.panel-warning .nav-tabs > li.dropdown .dropdown-menu > .active > a:focus {
@@ -624,6 +665,7 @@ table.dataTable thead .sorting:after {
 .tabbed-panel.panel-danger .nav-tabs > li > a:focus {
     color: #a94442;
 }
+
 .tabbed-panel.panel-danger .nav-tabs > .open > a,
 .tabbed-panel.panel-danger .nav-tabs > .open > a:hover,
 .tabbed-panel.panel-danger .nav-tabs > .open > a:focus,
@@ -633,6 +675,7 @@ table.dataTable thead .sorting:after {
     background-color: #ebccd1;
     border-color: transparent;
 }
+
 .tabbed-panel.panel-danger .nav-tabs > li.active > a,
 .tabbed-panel.panel-danger .nav-tabs > li.active > a:hover,
 .tabbed-panel.panel-danger .nav-tabs > li.active > a:focus {
@@ -641,17 +684,21 @@ table.dataTable thead .sorting:after {
     border-color: #ebccd1;
     border-bottom-color: transparent;
 }
+
 .tabbed-panel.panel-danger .nav-tabs > li.dropdown .dropdown-menu {
     background-color: #f2dede; /* bg color */
     border-color: #ebccd1; /* border color */
 }
+
 .tabbed-panel.panel-danger .nav-tabs > li.dropdown .dropdown-menu > li > a {
     color: #a94442; /* normal text color */
 }
+
 .tabbed-panel.panel-danger .nav-tabs > li.dropdown .dropdown-menu > li > a:hover,
 .tabbed-panel.panel-danger .nav-tabs > li.dropdown .dropdown-menu > li > a:focus {
     background-color: #ebccd1; /* hover bg color */
 }
+
 .tabbed-panel.panel-danger .nav-tabs > li.dropdown .dropdown-menu > .active > a,
 .tabbed-panel.panel-danger .nav-tabs > li.dropdown .dropdown-menu > .active > a:hover,
 .tabbed-panel.panel-danger .nav-tabs > li.dropdown .dropdown-menu > .active > a:focus {
@@ -659,9 +706,6 @@ table.dataTable thead .sorting:after {
     background-color: #a94442; /* active bg color */
 }
 
-
-
-
 .navbar-top-links li span.title {
     padding: 3px 20px;
     display: block;
@@ -706,7 +750,7 @@ a:hover, a:focus {
     border-color: #337ab7;
 }
 
-.btn-primary.active, .btn-primary.focus, .btn-primary:active, .btn-primary:focus, .btn-primary:hover, .open>.dropdown-toggle.btn-primary {
+.btn-primary.active, .btn-primary.focus, .btn-primary:active, .btn-primary:focus, .btn-primary:hover, .open > .dropdown-toggle.btn-primary {
     background-color: #337ab7;
     border-color: #337ab7;
 }
@@ -760,7 +804,7 @@ select:focus {
     display: inline;
 }
 
-@media(max-width:768px) {
+@media (max-width: 768px) {
 
     .contracted .sidebar {
         width: 100%;
@@ -801,3 +845,15 @@ select:focus {
 .navbar-brand {
     padding: 20px 15px 0;
 }
+
+.modal .acciones {
+    padding: 15px 0 0;
+    border-top: solid 1px #e6e6e6;
+    margin: 7px 0 0;
+}
+
+.dropdown-menu {
+    max-height: 50vh;
+    overflow-y: auto;
+    top: calc(100% - 2px);
+}

+ 2 - 2
protected/business/business1/config/config.php

@@ -3,8 +3,8 @@
 return array(
 
     'DB_SERVER' => 'localhost',
-    'DB_USER'   => 'root',
+    'DB_USER'   => '',
     'DB_PASS'   => '',
-    'DB_DB'     => 'webapp',
+    'DB_DB'     => '',
 
 );

+ 5 - 3
protected/business/business1/controllers/ejemplo.php

@@ -2,7 +2,9 @@
 
 namespace business\controllers;
 
-use \oxusmedia\webAppMulti\controller;
+use app\models\GeneralModel;
+use business\models\BusinessModel;
+use oxusmedia\webAppMulti\controller;
 
 class ejemplo extends controller
 {
@@ -13,10 +15,10 @@ class ejemplo extends controller
         $this->titulo = 'Página de negocio';
 
         // invocar model de carpeta protected/models
-        new \GeneralModel();
+        new GeneralModel();
 
         // invocar model de carpeta models del business
-        new \business\models\BusinessModel();
+        new BusinessModel();
 
         $this->render('index');
     }

+ 3 - 1
protected/business/business1/views/ejemplo/index.php

@@ -1,6 +1,8 @@
 
 <?php $this->renderInclude("header");?>
 
-    <p>Esta es una página de ejemplo de un negocio!</p>
+<p>Esta es una página de ejemplo de un negocio!</p>
+
+<pre><?php print_r(\app\models\CuentaSel::getSelected());?></pre>
 
 <?php $this->renderInclude("footer");?>

+ 1 - 1
protected/config/config.php

@@ -7,7 +7,7 @@ return array(
 
     'DEBUG'            => true,
 
-    'LOGIN_WITH_EMAIL' => false,
+    'LOGIN_WITH_EMAIL' => true,
 
     'DB_SERVER'        => 'localhost',
     'DB_USER'          => '',

+ 21 - 0
protected/controllers/cuenta.php

@@ -0,0 +1,21 @@
+<?php
+
+use oxusmedia\webAppMulti\controller;
+
+class cuenta extends controller
+{
+    public function select($params)
+    {
+        $this->webApp()->requireLoginRedir();
+
+        if (isset($params['id'])) {
+
+            app\models\CuentaSel::select($params['id']);
+
+            $this->redirect($_SERVER["HTTP_REFERER"]);
+
+        }
+
+    }
+
+}

+ 3 - 3
protected/controllers/site.php

@@ -36,7 +36,7 @@ class site extends controller
 
                     $param = $form->getAtributes();
 
-                    if ($this->webApp()->login($param["usuario"], $param["contrasena"], $param["business"])) {
+                    if ($this->webApp()->login($param["email"], $param["contrasena"], $param["business"])) {
 
                         $this->redirect($this->webApp()->getSite());
 
@@ -66,9 +66,9 @@ class site extends controller
             array(
                 new column(array(
                     new input('business', array(
-                        'label' => 'Negocio'
+                        'label' => 'Agencia'
                     )),
-                    new input('usuario'),
+                    new input('email'),
                     new password('contrasena', array(
                         'label' => 'Contraseña',
                     ))

+ 217 - 69
protected/controllers/usuario.php

@@ -1,9 +1,14 @@
 <?php
 
+use app\models\AgenciaRole;
+use app\models\CuentaRole;
+
 use oxusmedia\webAppMulti\webApp;
 use oxusmedia\webAppMulti\controller;
 use oxusmedia\webApp\grid;
 use oxusmedia\webApp\form;
+use oxusmedia\webApp\tabs;
+use oxusmedia\webApp\tab;
 use oxusmedia\webApp\column;
 use oxusmedia\webApp\input;
 use oxusmedia\webApp\hidden;
@@ -35,11 +40,6 @@ class usuario extends controller
             ->setJsonUrl($this->getMethodUrl('data'))
             ->setUniqueIdFields('id')
             ->setColModel(array(
-                array(
-                    'name'   => 'usuario',
-                    'width'  => 150,
-                    'format' => grid::FMT_STRING
-                ),
                 array(
                     'name'   => 'nombre',
                     'width'  => 200,
@@ -54,7 +54,7 @@ class usuario extends controller
                     'name'          => 'role',
                     'width'         => 150,
                     'format'        => grid::FMT_SELECT,
-                    'formatoptions' => array('value' => $this->getRoleDescription())
+                    'formatoptions' => array('value' => AgenciaRole::getDescripcion())
                 ),
                 array(
                     'name'   => 'ultimoLogin',
@@ -62,7 +62,7 @@ class usuario extends controller
                     'format' => grid::FMT_DATETIME
                 )
             ))
-            ->setDefaultSortName('usuario')
+            ->setDefaultSortName('nombre')
             ->setDefaultSortOrder('asc')
             ->setActions(array(
                 new gridActionButton(gridActionButton::ADD, $this->webApp()->getSite() . 'usuario/add'),
@@ -73,57 +73,58 @@ class usuario extends controller
         return $grid;
     }
 
-    private function getRoleDescription($role = null)
-    {
-        $arr = array(
-            webApp::ROLE_ADMIN  => 'Administrador',
-            webApp::ROLE_EDITOR => 'Editor',
-            webApp::ROLE_USER   => 'Usuario'
-        );
-
-        if ($role == null)
-            return $arr;
-        elseif (isset($arr[$role]))
-            return $arr[$role];
-
-        return false;
-    }
-
     public function add()
     {
         $this->webApp()->requireLogin();
 
         $form = new form('usuario', array(
 
-            new column(array(
+            new tabs('tabs', array(
 
-                new input('usuario', array(
-                    'rules' => array(
-                        'required' => true
-                    )
-                )),
+                new tab('datos', array(
 
-                new input('email', array(
-                    'rules' => array(
-                        'required' => true,
-                        'email'    => true
-                    )
-                )),
+                    new column(array(
 
-                new password('pass', array(
-                    'label' => 'Contraseña',
-                    'rules' => array(
-                        'required' => true
-                    )
-                )),
+                        new input('email', array(
+                            'rules' => array(
+                                'required' => true,
+                                'email'    => true
+                            )
+                        )),
 
-                new input('nombre', array(
-                    'rules' => array(
-                        'required' => true
-                    )
+                        new password('pass', array(
+                            'label' => 'Contraseña',
+                            'rules' => array(
+                                'required' => true
+                            )
+                        )),
+
+                        new input('nombre', array(
+                            'rules' => array(
+                                'required' => true
+                            )
+                        )),
+
+                        new select('role', AgenciaRole::getDescripcion(), array(
+                            'label'       => 'Rol en agencia',
+                            'htmlOptions' => array(
+                                'onchange' => "changeRol($(this).val());"
+                            )
+                        ))
+
+                    ))
+
+                ), array(
+                    'title' => 'Datos del usuario'
                 )),
 
-                new select('role', $this->getRoleDescription())
+                new tab('cuentas', array(
+
+                    new column($this->getCuentasRoleSelect($col2)),
+
+                    new column($col2)
+
+                ))
 
             ))
 
@@ -143,8 +144,24 @@ class usuario extends controller
 
                 $param['pass'] = md5($param['pass']);
 
+                $ctasRoles = $this->getCuentasRoles($param);
+
                 $this->db()->insert('usuarios', $param);
 
+                $id = $this->db()->insertId();
+
+                foreach ($ctasRoles as $cta => $role) {
+
+                    if ($role != CuentaRole::ROLE_NONE)
+
+                        $this->db()->insert('usuarioscuentas', array(
+                            'usuario_id' => $id,
+                            'cuenta_id'  => $cta,
+                            'role'       => $role
+                        ));
+
+                }
+
                 $this->returnJson(array(
                     'error' => 0
                 ));
@@ -153,7 +170,9 @@ class usuario extends controller
 
         } else {
 
-            echo $form->render();
+            $this->render('form', array(
+                'form' => $form
+            ));
 
         }
 
@@ -169,33 +188,61 @@ class usuario extends controller
 
         if ($usuario) {
 
+            $htmlOptionsAgenciaRole = array(
+                'onchange' => "changeRol($(this).val());"
+            );
+
+            if ($usuario->usuario == 'admin')
+                $htmlOptionsAgenciaRole['disabled'] = 'disabled';
+
             $form = new form('usuario', array(
 
-                new column(array(
+                new tabs('tabs', array(
 
-                    new hidden('id'),
+                    new tab('datos', array(
 
-                    new input('email', array(
-                        'rules' => array(
-                            'required' => true,
-                            'email'    => true
-                        )
-                    )),
+                        new column(array(
 
-                    new password('pass', array(
-                        'label'       => 'Contraseña',
-                        'htmlOptions' => array(
-                            'placeholder' => 'dejar vacío para no cambiar la contraseña'
-                        )
-                    )),
+                            new hidden('id'),
 
-                    new input('nombre', array(
-                        'rules' => array(
-                            'required' => true
-                        )
+                            new input('email', array(
+                                'rules' => array(
+                                    'required' => true,
+                                    'email'    => true
+                                )
+                            )),
+
+                            new password('pass', array(
+                                'label'       => 'Contraseña',
+                                'htmlOptions' => array(
+                                    'placeholder' => 'dejar vacío para no cambiar la contraseña'
+                                )
+                            )),
+
+                            new input('nombre', array(
+                                'rules' => array(
+                                    'required' => true
+                                )
+                            )),
+
+                            new select('role', AgenciaRole::getDescripcion(), array(
+                                'label'       => 'Rol en agencia',
+                                'htmlOptions' => $htmlOptionsAgenciaRole
+                            ))
+
+                        ))
+
+                    ), array(
+                        'title' => 'Datos del usuario'
                     )),
 
-                    new select('role', $this->getRoleDescription(), $usuario->usuario == 'admin' ? array('htmlOptions' => array('disabled' => 'disabled')) : null)
+                    new tab('cuentas', array(
+
+                        new column($this->getCuentasRoleSelect($col2)),
+
+                        new column($col2)
+
+                    ))
 
                 ))
 
@@ -218,23 +265,74 @@ class usuario extends controller
                     else
                         unset($param['pass']);
 
+                    $ctasRoles = $this->getCuentasRoles($param);
+
                     $this->db()->update('usuarios', $param,
                         array(
                             'id' => $param['id']
                         )
                     );
 
+                    foreach ($ctasRoles as $ctaId => $role) {
+
+                        if ($role == CuentaRole::ROLE_NONE) {
+
+                            $this->db()->delete('usuarioscuentas',
+                                array(
+                                    'usuario_id' => $usuario->id,
+                                    'cuenta_id'  => $ctaId
+                                )
+                            );
+
+                        }else{
+
+                            $this->db()->insert('usuarioscuentas', array(
+                                'usuario_id' => $usuario->id,
+                                'cuenta_id'  => $ctaId,
+                                'role'       => $role
+                            ), true);
+
+                            if ($this->db()->affectedRows() == 0)
+
+                                $this->db()->update('usuarioscuentas',
+                                    array(
+                                        'role' => $role
+                                    ),
+                                    array(
+                                        'usuario_id' => $usuario->id,
+                                        'cuenta_id'  => $ctaId
+                                    )
+                                );
+
+                        }
+
+                    }
+
                     $this->returnJson(array(
                         'error' => 0
                     ));
 
                 }
 
-            }else{
+            } else {
+
+                $cuentas = $this->db()->query('SELECT cuentas.*, usuarioscuentas.role FROM cuentas LEFT JOIN usuarioscuentas ON usuarioscuentas.cuenta_id = cuentas.id WHERE usuarioscuentas.usuario_id = :usuario_id', array(
+                    'usuario_id' => $usuario->id
+                ));
 
                 $form->setAtributes($usuario);
 
-                echo $form->render();
+                $ctasRoles = array();
+
+                while ($cta = $this->db()->getRow($cuentas))
+
+                    $ctasRoles['cuentarole_' . $cta->id] = $cta->role;
+
+                $form->setAtributes($ctasRoles);
+
+                $this->render('form', array(
+                    'form' => $form
+                ));
 
             }
 
@@ -256,6 +354,10 @@ class usuario extends controller
 
             if (!$usuario) {
 
+                $db->query('DELETE FROM usuarioscuentas WHERE usuario_id IN(:ids)', array(
+                    'ids' => implode(',', $_POST['id'])
+                ));
+
                 $db->query('DELETE FROM usuarios WHERE id IN(:ids)', array(
                     'ids' => implode(',', $_POST['id'])
                 ));
@@ -264,7 +366,7 @@ class usuario extends controller
                     'error' => 0
                 ));
 
-            }else{
+            } else {
 
                 $this->returnJson(array(
                     'error'   => 1,
@@ -358,4 +460,50 @@ class usuario extends controller
         ));
     }
 
+    private function getCuentasRoleSelect(&$col2)
+    {
+        $cuentas = $this->db()->query('SELECT * FROM cuentas ORDER BY cuenta');
+
+        $col1 = array();
+        $col2 = array();
+        $n    = 0;
+
+        while ($c = $this->db()->getRow($cuentas)) {
+
+            $n++;
+
+            $permiso = new select('cuentarole_' . $c->id . '', CuentaRole::getDescripcion(), array(
+                'label' => $c->cuenta
+            ));
+
+            if ($n % 2 != 0)
+                $col1[] = $permiso;
+            else
+                $col2[] = $permiso;
+
+        }
+
+        return $col1;
+
+    }
+
+    private function getCuentasRoles(&$param)
+    {
+        $arr = array();
+
+        foreach ($param as $f => $v) {
+
+            if (strpos($f, 'cuentarole_') !== false) {
+
+                $arr[str_replace('cuentarole_', '', $f)] = $v;
+
+                unset($param[$f]);
+
+            }
+
+        }
+
+        return $arr;
+    }
+
 }

+ 27 - 0
protected/models/AgenciaRole.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\models;
+
+class AgenciaRole
+{
+    const
+        ROLE_ADMIN = 'A',
+        ROLE_USER  = 'U'
+    ;
+
+    static public function getDescripcion($role = null)
+    {
+        $arr = array(
+            self::ROLE_ADMIN => 'Administrador',
+            self::ROLE_USER  => 'Usuario'
+        );
+
+        if ($role == null)
+            return $arr;
+        elseif (isset($arr[$role]))
+            return $arr[$role];
+
+        return false;
+    }
+
+}

+ 34 - 0
protected/models/Cuenta.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace app\models;
+
+use oxusmedia\webAppMulti\webApp;
+
+class Cuenta
+{
+    public $id, $cuenta, $role;
+
+    public function __construct($id = null)
+    {
+        if ($id != null) {
+
+            $cuenta = webApp::app()->db()->queryRow('SELECT * FROM cuentas WHERE id = :id', array(
+                'id' => $id
+            ));
+
+            if ($cuenta) {
+
+                $this->id     = $cuenta->id;
+                $this->cuenta = $cuenta->nombre;
+                $this->role   = $cuenta->role;
+
+                return true;
+            }
+
+        }
+
+        return false;
+
+    }
+
+}

+ 29 - 0
protected/models/CuentaRole.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace app\models;
+
+class CuentaRole
+{
+    const
+        ROLE_NONE   = 'N',
+        ROLE_VIEWER = 'V',
+        ROLE_ADMIN  = 'A'
+    ;
+
+    static public function getDescripcion($role = null)
+    {
+        $arr = array(
+            self::ROLE_NONE   => 'Sin acceso',
+            self::ROLE_VIEWER => 'Ver reportes',
+            self::ROLE_ADMIN  => 'Administrar'
+        );
+
+        if ($role == null)
+            return $arr;
+        elseif (isset($arr[$role]))
+            return $arr[$role];
+
+        return false;
+    }
+
+}

+ 60 - 0
protected/models/CuentaSel.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace app\models;
+
+use oxusmedia\webAppMulti\webApp;
+
+class CuentaSel
+{
+    static public function select($id)
+    {
+        $cuenta = webApp::app()->db()->queryRow('SELECT cuentas.*, usuarioscuentas.role FROM usuarioscuentas LEFT JOIN cuentas ON cuentas.id = usuarioscuentas.cuenta_id WHERE usuarioscuentas.usuario_id = :usuario_id AND usuarioscuentas.cuenta_id = :cuenta_id', array(
+            'usuario_id' => webApp::app()->getUsuarioId(),
+            'cuenta_id'  => $id,
+        ));
+
+        if ($cuenta and $cuenta->role != CuentaRole::ROLE_NONE) {
+
+            $_SESSION['cuenta_sel_id'] = $cuenta->id;
+
+            return true;
+
+        }
+
+        return false;
+
+    }
+
+    static public function getSelected()
+    {
+        static $cuentaSel;
+
+        if ($cuentaSel)
+            return $cuentaSel;
+
+        if (isset($_SESSION['cuenta_sel_id'])) {
+
+            $cuenta = webApp::app()->db()->queryRow('SELECT cuentas.*, usuarioscuentas.role FROM usuarioscuentas LEFT JOIN cuentas ON cuentas.id = usuarioscuentas.cuenta_id WHERE usuarioscuentas.usuario_id = :usuario_id AND usuarioscuentas.cuenta_id = :cuenta_id', array(
+                'usuario_id' => webApp::app()->getUsuarioId(),
+                'cuenta_id'  => $_SESSION['cuenta_sel_id']
+            ));
+
+            if ($cuenta) {
+
+                $cuentaSel = new Cuenta();
+
+                $cuentaSel->id     = $_SESSION['cuenta_sel_id'];
+                $cuentaSel->cuenta = $cuenta->cuenta;
+                $cuentaSel->role   = webApp::app()->getRole() == webApp::ROLE_ADMIN ? webApp::ROLE_ADMIN : $cuenta->role;
+
+                return $cuentaSel;
+
+            }
+
+        }
+
+        return false;
+
+    }
+
+}

+ 2 - 0
protected/models/GeneralModel.php

@@ -1,5 +1,7 @@
 <?php
 
+namespace app\models;
+
 class GeneralModel
 {
 

+ 60 - 0
protected/models/Usuario.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace app\models;
+
+use oxusmedia\webAppMulti\webApp;
+
+class Usuario
+{
+    public $id, $nombre, $email, $role;
+
+    public function __construct($id = null)
+    {
+        if ($id == null)
+            $id = webApp::app()->getUsuarioId();
+
+        $usuario = webApp::app()->db()->queryRow('SELECT * FROM usuarios WHERE id = :id', array(
+            'id' => $id
+        ));
+
+        if ($usuario) {
+
+            $this->id     = $usuario->id;
+            $this->nombre = $usuario->nombre;
+            $this->email  = $usuario->email;
+            $this->role   = $usuario->role;
+
+            return true;
+        }
+
+        return false;
+
+    }
+
+    public function getCuentas()
+    {
+        $db = webApp::app()->db();
+
+        $cuentas = $db->query('SELECT cuentas.*, usuarioscuentas.role FROM usuarioscuentas LEFT JOIN cuentas ON usuarioscuentas.cuenta_id = cuentas.id WHERE usuarioscuentas.usuario_id = :usuario_id ORDER BY cuenta', array(
+            'usuario_id' => $this->id
+        ));
+
+        $ctas = array();
+
+        while ($cuenta = $db->getRow($cuentas)) {
+
+            $cta = new Cuenta();
+
+            $cta->id     = $cuenta->id;
+            $cta->cuenta = $cuenta->cuenta;
+            $cta->role   = $this->role == webApp::ROLE_ADMIN ? webApp::ROLE_ADMIN : $cuenta->role;
+
+            $ctas[] = $cta;
+
+        }
+
+        return $ctas;
+
+    }
+
+}

+ 2 - 0
protected/views/_includes/head.php

@@ -3,6 +3,8 @@
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 
+<base href="<?php echo $this->webApp()->getSite();?>">
+
 <link rel="shortcut icon" href="<?php echo $this->webApp()->getUrlAssets();?>images/favicon.ico" type="image/x-icon">
 <link rel="icon" href="<?php echo $this->webApp()->getUrlAssets();?>images/favicon.ico" type="image/x-icon">
 

+ 12 - 2
protected/views/_includes/menu.php

@@ -17,15 +17,25 @@
 
     <!-- Top Navigation: Right Menu -->
     <ul class="nav navbar-right navbar-top-links">
+        <li class="dropdown">
+            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+                <i class="fa fa-line-chart fa-fw"></i> <?php echo !app\models\CuentaSel::getSelected()->id ? 'Seleccionar cuenta...' : app\models\CuentaSel::getSelected()->cuenta;?> <b class="caret"></b>
+            </a>
+            <ul class="dropdown-menu dropdown-cuenta">
+                <?php $usu = new app\models\Usuario(); foreach ($usu->getCuentas() as $cuenta) { ?>
+                    <li><a href="cuenta/select?id=<?php echo $cuenta->id;?>"><?php echo $cuenta->cuenta;?></a></li>
+                <?php } ?>
+            </ul>
+        </li>
         <li class="dropdown">
             <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                 <i class="fa fa-user fa-fw"></i> <?php echo $this->webApp()->getUsuario();?> <b class="caret"></b>
             </a>
             <ul class="dropdown-menu dropdown-user">
                 <li class="divider"></li>
-                <li><a href="<?php echo $this->webApp()->getSite();?>usuario/miperfil"><i class="fa fa-user fa-fw"></i> Mi perfil</a></li>
+                <li><a href="usuario/miperfil"><i class="fa fa-user fa-fw"></i> Mi perfil</a></li>
                 <li class="divider"></li>
-                <li><a href="<?php echo $this->webApp()->getSite();?>site/logout"><i class="fa fa-sign-out fa-fw"></i> Cerrar sesión</a></li>
+                <li><a href="site/logout"><i class="fa fa-sign-out fa-fw"></i> Cerrar sesión</a></li>
             </ul>
         </li>
     </ul>

+ 19 - 0
protected/views/usuario/form.php

@@ -0,0 +1,19 @@
+
+<?php echo $form->render();?>
+
+<script>
+
+    $(document).ready(function(){
+        $('#role').change();
+    });
+
+    function changeRol(role)
+    {
+        if (role == '<?php echo \app\models\AgenciaRole::ROLE_ADMIN;?>') {
+            $('.nav-tabs li:last').hide();
+        }else{
+            $('.nav-tabs li:last').show();
+        }
+    }
+
+</script>