public function del()
 {
     if ($this->db->remove()) {
         View::ajax(array('code' => 0, 'message' => '删除成功'));
     } else {
         View::ajax(array('code' => 1, 'message' => $this->db->getError()));
     }
 }
Exemple #2
0
 public function post()
 {
     if ($this->db->store()) {
         $json = ['message' => 'success'];
     } else {
         $json = ['message' => $this->db->getError()];
     }
     View::ajax($json);
 }
Exemple #3
0
 public function update()
 {
     if ($this->db->update()) {
         $json = ['message' => '更新成功'];
     } else {
         $json = ['message' => $this->db->getError()];
     }
     View::ajax($json);
 }
 /**
  * Callback que se ejecuta antes de los métodos de todos los controladores
  */
 protected final function initialize()
 {
     /**
      * Si el método de entrada es ajax, el tipo de respuesta es sólo la vista
      */
     if (Input::isAjax()) {
         View::template(null);
     }
     /**
      * Verifico que haya iniciado sesión
      */
     if (!MkcAuth::isLogged()) {
         //Verifico que no genere una redirección infinita
         if ($this->controller_name != 'login' && ($this->action_name != 'entrar' && $this->action_name != 'salir')) {
             MkcMessage::warning('No has iniciado sesión o ha caducado.');
             //Verifico que no sea una ventana emergente
             if ($this->module_name == 'reporte') {
                 View::error();
                 //TODO: crear el método error()
             } else {
                 MkcRedirect::toLogin('sistema/login/entrar/');
             }
             return false;
         }
     } else {
         if (MkcAuth::isLogged() && $this->controller_name != 'login') {
             $acl = new MkcAcl();
             //Cargo los permisos y templates
             if (APP_UPDATE && Session::get('perfil_id') != Perfil::SUPER_USUARIO) {
                 //Solo el super usuario puede hacer todo
                 if ($this->module_name != 'dashboard' && $this->controller_name != 'index') {
                     $msj = 'Estamos en labores de actualización y mantenimiento.';
                     $msj .= '<br />';
                     $msj .= 'El servicio se reanudará dentro de ' . APP_UPDATE_TIME;
                     if (Input::isAjax()) {
                         View::update();
                     } else {
                         MkcMessage::info($msj);
                         MkcRedirect::to("dashboard");
                     }
                     return FALSE;
                 }
             }
             if (!$acl->check(Session::get('perfil_id'))) {
                 MkcMessage::error('Tu no posees privilegios para acceder a <b>' . Router::get('route') . '</b>');
                 Input::isAjax() ? View::ajax() : View::select(NULL);
                 return false;
             }
             if (!defined('SKIN')) {
                 define('SKIN', Session::get('tema'));
             }
         }
     }
 }
 public function selectTpl()
 {
     $tpl = Q('tpl');
     if (!is_dir('template/' . $tpl)) {
         View::ajax(array('error' => 1, 'message' => '模板不存在'));
     } else {
         $config = new \Admin\Model\Config();
         $config->editOne('style', array('value' => $tpl));
         View::ajax(array('errcode' => 0));
     }
 }
 public function selectTmp()
 {
     $tmp = Q('tmp');
     if (!is_dir('template/' . $tmp)) {
         View::ajax(['errcode' => 0, 'message' => '模板不存在']);
     } else {
         $config = new \Sadmin2\Model\Config();
         if ($config->editOne('style', array('value' => $tmp))) {
             View::ajax(['errcode' => 1]);
         } else {
             View::ajax(['errcode' => 0, 'message' => $this->getError()]);
         }
     }
     // $config = new \Sadmin2\Model\Config;
     // $config->editOne('style',array('value'=>$tmp));
 }
 /**
  * HTML to add to the view and return as a AJAX response.
  *
  * @param string $html HTML to load into the view.
  */
 public function ajax($html)
 {
     \View::ajax();
     \View::html($html);
     \View::serve();
 }
 /**
  * Método para verificar la conexión de la bd
  */
 public function test()
 {
     if (!Input::isAjax()) {
         DwMessage::error('Acceso incorrecto para la verificación del sistema.');
         return DwRedirect::toRoute('module: dashboard', 'controller: index');
     }
     if (!Input::hasPost('development') or !Input::hasPost('production')) {
         DwMessage::error('Oops!. No hemos recibido algún parámetro de configuración.');
     } else {
         if (Input::hasPost('development')) {
             Sistema::testConnection(Input::post('development'), 'development', true);
         }
         if (Input::hasPost('production')) {
             Sistema::testConnection(Input::post('production'), 'production', true);
         }
     }
     View::ajax();
 }
 public function delAdd()
 {
     $data = $this->db->where('add_id', Q('add_id'))->delete();
     View::ajax(array('code' => 0));
 }
Exemple #10
0
 /**
  * Ajax输出
  *
  * @param        $data 数据
  * @param string $type 数据类型 text html xml json
  */
 protected function ajax($data, $type = "JSON")
 {
     View::ajax($data, $type);
 }
 /**
  * Método para descargar
  */
 public function descargar($key = '')
 {
     if (!($id = DwSecurity::isValidKey($key, 'descargar_backup', 'int'))) {
         return View::ajax();
     }
     $backup = new Backup();
     if (!$backup->find_first($id)) {
         DwMessage::get('id_no_found');
         return DwRedirect::toAction('listar');
     }
     $file = APP_PATH . 'temp/backup/' . $backup->archivo;
     if (!is_file($file)) {
         DwMessage::warning('No hemos podido localizar el archivo. Por favor contacta al administrador del sistema.');
         DwAudit::error("No se ha podido encontrar la copia de seguridad {$backup->archivo} en el sistema");
         return DwRedirect::toAction('listar');
     }
     View::template(NULL);
     $this->backup = $backup;
 }
 public function getNum()
 {
     $sto = new \Home\Model\Stock();
     $stock = $sto->getNum(Q('stock_attr'), Q('goods_id'));
     View::ajax($stock);
 }
 /**
  * Método para restaurar
  */
 public function restaurar($key = '')
 {
     if (!Input::isAjax()) {
         Flash::error('Método incorrecto para restaurar el sistema.');
         return Redirect::toAction('listar');
     }
     if (!($id = Security::getKey($key, 'restaurar_backup', 'int'))) {
         return View::ajax();
     }
     $pass = Input::post('password');
     $usuario = Usuario::getUsuarioLogueado();
     if ($usuario->password != sha1($pass)) {
         Flash::error('Acceso incorrecto al sistema. Tu no tienes los permisos necesarios para realizar esta acción.');
         return View::ajax();
     }
     if ($backup = Backup::restoreBackup($id)) {
         Flash::valid('El sistema se ha restaurado satisfactoriamente con la copia de seguridad <b>' . $backup->archivo . '</b>');
     } else {
         Flash::error('Se ha producido un error interno al restaurar el sistema. Por favor contacta al administrador.');
     }
     return View::ajax();
 }
 public function delCart()
 {
     $id = Q('id');
     unset($_SESSION['cart'][$id]);
     $price = 0;
     foreach ($_SESSION['cart'] as $k => $v) {
         $price += $v['buy_num'] * $v['goods_price'];
     }
     View::ajax(array('code' => 0, 'num' => sizeof($_SESSION['cart']), 'total_price' => $price));
 }
 public function getNum()
 {
     $stock = $this->db->getNum(Q('stock_attr'), Q('goods_id'));
     View::ajax($stock);
 }