function calculate_tpl($method, $tpl)
 {
     $this->method = $method;
     switch ($method) {
         case 'add':
             $return = $this->add();
             switch ($return) {
                 case 0:
                     //por defecto
                     break;
                 case -1:
                     //Errores al intentar añadir datos
                     for ($i = 0; $i < count($this->fields_list->array_error); $i += 2) {
                         $tpl->assign("error_" . $this->fields_list->array_error[$i], $this->fields_list->array_error[$i + 1]);
                     }
                     break;
                 default:
                     //Si se ha añadido
                     $this->method = "list";
                     $clients = new clients();
                     $tpl = $this->listar($tpl);
                     $clients->get_list_clients($_SESSION['ident_corp']);
                     $tpl->assign("clients", $clients->clients_list);
                     $tpl->assign("message", "&nbsp;<br>Contacto a&ntilde;adido correctamente<br>&nbsp;");
                     break;
             }
             $tpl->assign("objeto", $this);
             break;
         case 'list':
             $clients = new clients();
             $tpl = $this->listar($tpl);
             $clients->get_list_clients($_SESSION['ident_corp']);
             $tpl->assign("clients", $clients->clients_list);
             $tpl->assign("objeto", $this);
             break;
         case 'modify':
             $this->read($_GET['id']);
             $return = $this->modify();
             switch ($return) {
                 case 0:
                     //por defecto
                     $this->birthday = $this->fields_list->change_date($this->birthday, "es");
                     break;
                 case -1:
                     //Errores al intentar añadir datos
                     for ($i = 0; $i < count($this->fields_list->array_error); $i += 2) {
                         $tpl->assign("error_" . $this->fields_list->array_error[$i], $this->fields_list->array_error[$i + 1]);
                     }
                     break;
                 default:
                     //Si se ha añadido
                     $this->method = "list";
                     $clients = new clients();
                     $tpl = $this->listar($tpl);
                     $clients->get_list_clients($_SESSION['ident_corp']);
                     $tpl->assign("clients", $clients->clients_list);
                     $tpl->assign("objeto", $this);
                     $tpl->assign("message", "&nbsp;<br>Contacto modificado correctamente<br>&nbsp;");
                     break;
             }
             $tpl->assign("objeto", $this);
             break;
         case 'delete':
             $this->read($_GET['id']);
             if ($this->remove($_GET['id']) == 0) {
                 $tpl->assign("message", $this->contactos);
             } else {
                 $this->contacts_list = "";
                 $this->method = "list";
                 $clients = new clients();
                 $tpl = $this->listar($tpl);
                 $clients->get_list_clients($_SESSION['ident_corp']);
                 $tpl->assign("clients", $clients->clients_list);
                 $tpl->assign("message", "&nbsp;<br>Contacto borrado correctamente<br>&nbsp;");
             }
             $tpl->assign("objeto", $this);
             break;
         case 'view':
             $tpl = $this->view($_GET['id'], $tpl);
             $_SESSION['id_contact'] = $this->id_contact;
             break;
         default:
             if ($_SESSION['ident_corp'] != 0) {
                 $this->method = 'list';
                 $clients = new clients();
                 $tpl = $this->listar($tpl);
                 $clients->get_list_clients($_SESSION['ident_corp']);
                 $tpl->assign("clients", $clients->clients_list);
                 $tpl->assign("objeto", $this);
             } else {
                 $tpl->assign('plantilla', 'error_corp.tpl');
                 return $tpl;
             }
             break;
     }
     $tpl->assign('plantilla', 'contacts_' . $this->method . '.tpl');
     return $tpl;
 }
 function view($id, $tpl)
 {
     /*
     	Cosas que faltan por hacer:
     		De forma general, mirar los permisos del usuario que vaya a acceder aqui, para saber si tiene permisos de borrar editar ver etc...
     		Averiguar como pasar el numero de registros, si va a ser a grupos a grupos, si va a ser a modulos, a modulos
     		Order By (y mantener la búsqueda en el caso de que hubiera hecha una y averiguar la "pestaña" a la que hace referencia)
     		Busquedas
     */
     $cadena = '';
     // Leemos la empresa y se lo pasamos a la plantilla
     $this->read($id);
     $tpl->assign('objeto', $this);
     //listado de empleados
     $tabla_empleados = new table(false);
     $empleados = new emps();
     if ($empleados->get_list_emps($_SESSION['ident_corp']) == 0) {
         $per = new permissions();
         $per->get_permissions_list('corps');
         $cadena = $cadena . $tabla_empleados->tabla_vacia('emps', $per->add);
         $variables_empleados = $tabla_empleados->nombres_variables;
     } else {
         $per = new permissions();
         $per->get_permissions_list('corps');
         $cadena = $cadena . $tabla_empleados->make_tables('emps', $empleados->emps_list, array('Nombre', 20, 'Primer Apellido', 20, 'Segundo Apellido', 20), array('id_emp', 'name', 'last_name', 'last_name2'), $_SESSION['num_regs'], $per->permissions_module, $per->add);
         $variables_empleados = $tabla_empleados->nombres_variables;
     }
     //Productos
     $products = new products(false);
     $tabla_productos = new table(false);
     if ($products->get_list_products_corps($_SESSION['ident_corp']) == 0) {
         $per = new permissions();
         $per->get_permissions_list('corps');
         $cadena = $cadena . $tabla_productos->tabla_vacia('products', $per->add);
         $variables_products = $tabla_productos->nombres_variables;
     } else {
         $per = new permissions();
         $per->get_permissions_list('corps');
         $cadena = $cadena . $tabla_productos->make_tables('products', $products->products_list, array('Nombre', 20, 'Nombre Web', 40), array('id_product', 'name', 'name_web'), $_SESSION['num_regs'], $per->permissions_module, $per->add);
         $variables_products = $tabla_productos->nombres_variables;
     }
     //servicios
     $services = new services(false);
     $tabla_servicios = new table(false);
     if ($services->get_list_services_corp($_SESSION['ident_corp']) == 0) {
         $per = new permissions();
         $per->get_permissions_list('corps');
         $cadena = $cadena . $tabla_servicios->tabla_vacia('services', $per->add);
         $variables_services = $tabla_servicios->nombres_variables;
     } else {
         $per = new permissions();
         $per->get_permissions_list('corps');
         $cadena = $cadena . $tabla_servicios->make_tables('services', $services->services_list, array('Nombre', 20, 'Nombre Web', 40), array('id_service', 'name', 'name_web'), $_SESSION['num_regs'], $per->permissions_module, $per->add);
         $variables_services = $tabla_servicios->nombres_variables;
     }
     //clientes
     $clients = new clients(false);
     $tabla_clientes = new table(false);
     if ($clients->get_list_clients($_SESSION['ident_corp']) == 0) {
         $per = new permissions();
         $per->get_permissions_list('clients');
         $cadena = $cadena . $tabla_clientes->tabla_vacia('clients', $per->add);
         $variables_clients = $tabla_clientes->nombres_variables;
     } else {
         $per = new permissions();
         $per->get_permissions_list('corps');
         $cadena = $cadena . $tabla_clientes->make_tables('clients', $clients->clients_list, array('Nombre', 20, 'Nombre Completo', 40, 'Tel&eacute;fono', 20), array('id_client', 'name', 'full_name', 'phone'), 10, $per->permissions_module, $per->add);
         $variables_clients = $tabla_clientes->nombres_variables;
     }
     //Rellenamos de forma provisional las variables con un "no se puede mostrar"
     $facturaspen = new table(false);
     $facturascob = new table(false);
     $gestionalm = new table(false);
     $partes = new table(false);
     $cadena = $cadena . $facturaspen->dont_show('facturaspen');
     $cadena = $cadena . $facturascob->dont_show('facturascob');
     $cadena = $cadena . $gestionalm->dont_show('gestionalm');
     $cadena = $cadena . $partes->dont_show('partes');
     $variables_facturaspen = $facturaspen->nombres_variables;
     $variables_facturascob = $facturascobs->nombres_variables;
     $variables_gestionalm = $gestionalm->nombres_variables;
     $variables_partes = $partes->nombres_variables;
     $i = 0;
     while ($i < count($variables_empleados) + count($variables_clients) + count($variables_facturaspen) + count($variables_facturascob) + count($variables_products) + count($variables_services) + count($variables_gestionalm) + count($variables_partes)) {
         for ($j = 0; $j < count($variables_empleados); $j++) {
             $variables[$i] = $variables_empleados[$j];
             $i++;
         }
         for ($j = 0; $j < count($variables_clients); $j++) {
             $variables[$i] = $variables_clients[$j];
             $i++;
         }
         for ($j = 0; $j < count($variables_facturaspen); $j++) {
             $variables[$i] = $variables_facturaspen[$j];
             $i++;
         }
         for ($j = 0; $j < count($variables_facturascob); $j++) {
             $variables[$i] = $variables_facturascob[$j];
             $i++;
         }
         for ($j = 0; $j < count($variables_products); $j++) {
             $variables[$i] = $variables_products[$j];
             $i++;
         }
         for ($j = 0; $j < count($variables_services); $j++) {
             $variables[$i] = $variables_services[$j];
             $i++;
         }
         for ($j = 0; $j < count($variables_gestionalm); $j++) {
             $variables[$i] = $variables_gestionalm[$j];
             $i++;
         }
         for ($j = 0; $j < count($variables_partes); $j++) {
             $variables[$i] = $variables_partes[$j];
             $i++;
         }
     }
     //Se comprueba si hay permiso para borrar o modificar
     $permisos_mod_del = new permissions();
     $permisos_mod_del->get_permissions_modify_delete('corps');
     $tpl->assign('acciones', $permisos_mod_del->per_mod_del);
     $tpl->assign('variables', $variables);
     $tpl->assign('cadena', $cadena);
     //
     return $tpl;
 }