TSession se mantem em nova aba/guia Bom dia! Prezados, tenho uma Datagrid(SystemRegistrationsList) que chama uma nova tela(SystemSubscriptionView), nesta é armazenada o $param[‘key’] em uma TSession na função onView para ser utilizado em outras funções. Porém quando o usuário abre uma nova aba/guia do navegador o valor da TSession se mantem o da última aba/guia aberta. SystemRegistrationsList ...
HL
TSession se mantem em nova aba/guia  
Bom dia!
Prezados, tenho uma Datagrid(SystemRegistrationsList) que chama uma nova tela(SystemSubscriptionView), nesta é armazenada o $param[‘key’] em uma TSession na função onView para ser utilizado em outras funções.

Porém quando o usuário abre uma nova aba/guia do navegador o valor da TSession se mantem o da última aba/guia aberta.

SystemRegistrationsList
 
  1. <?php
  2. /**
  3. * SystemRegistrationsList
  4. *
  5. * @version 1.0
  6. * @package control
  7. * @subpackage ps
  8. * @author Hellton Lacerda
  9. * @copyright Serviço Social da Indústria
  10. * @license http://www.adianti.com.br/framework-license
  11. */
  12. class SystemRegistrationsList extends TPage
  13. {
  14. private $datagrid; // listing
  15. private $pageNavigation;
  16. private $loaded;
  17. /**
  18. * Class constructor
  19. * Creates the page, the form and the listing
  20. */
  21. public function __construct()
  22. {
  23. parent::__construct();
  24. $this->form = new BootstrapFormBuilder('form_search_Registrations');
  25. $this->form->setFormTitle( 'Buscar inscrições' );
  26. $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  27. $this->datagrid->datatable = 'true';
  28. $this->datagrid->width = '100%';
  29. $this->datagrid->setHeight(320);
  30. $notice = new TDataGridColumn('notice', 'Edital', 'center', NULL);
  31. $dtinscricao = new TDataGridColumn('dtinscricao', 'Data inscrição', 'center', NULL);
  32. $dtinscricao->setTransformer(array($this, 'formatDate_01'));
  33. $unit = new TDataGridColumn('unit', 'Unidade', 'center', NULL);
  34. $situacao = new TDataGridColumn('situacao', 'Situação', 'left', NULL);
  35. $order1= new TAction(array($this, 'onReload'));
  36. $order2= new TAction(array($this, 'onReload'));
  37. $order3= new TAction(array($this, 'onReload'));
  38. $order4= new TAction(array($this, 'onReload'));
  39. $order1->setParameter('order', 'notice');
  40. $order2->setParameter('order', 'dtinscricao');
  41. $order3->setParameter('order', 'unit');
  42. $order4->setParameter('order', 'situacao');
  43. $notice->setAction($order1);
  44. $dtinscricao->setAction($order2);
  45. $unit->setAction($order3);
  46. $situacao->setAction($order4);
  47. $this->datagrid->addColumn($notice);
  48. $this->datagrid->addColumn($dtinscricao);
  49. $this->datagrid->addColumn($unit);
  50. $this->datagrid->addColumn($situacao);
  51. $class = 'SystemSubscriptionView';
  52. $action1 = new TDataGridAction(array($class, 'onView'));
  53. $action1->setLabel(('Visualizar edital'));
  54. $action1->setImage('fa:file-text-o fa-fw green');
  55. $action1->setField('id');
  56. // $class = 'SystemRegistrationsForm';
  57. // $action2 = new TDataGridAction(array($class, 'onEdit'));
  58. // $action2->setLabel(('Inscrição'));
  59. // $action2->setImage('fa:pencil-square-o blue fa-lg');
  60. // $action2->setField('id');
  61. $this->datagrid->addAction($action1);
  62. // $this->datagrid->addAction($action2);
  63. // create the datagrid model
  64. $this->datagrid->createModel();
  65. // creates the page navigation
  66. $this->pageNavigation = new TPageNavigation;
  67. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  68. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  69. $panel = new TPanelGroup;
  70. $panel->add($this->datagrid);
  71. $panel->addFooter($this->pageNavigation);
  72. // creates the page structure using a vbox
  73. $container = new TVBox;
  74. $container->style = 'width: 100%';
  75. $container->add($panel);
  76. // add the vbox inside the page
  77. parent::add($container);
  78. }
  79. public function formatDate_01($data_inicio, $object)
  80. {
  81. $data_inicio = new DateTime($data_inicio);
  82. return $data_inicio->format('d/m/Y');
  83. }
  84. public function formatDate_02($data_termino, $object)
  85. {
  86. $data_termino = new DateTime($data_termino);
  87. return $data_termino->format('d/m/Y');
  88. }
  89. function onReload($param = NULL)
  90. {
  91. try
  92. {
  93. TTransaction::open('permission');
  94. $repository = new TRepository('ViewSystemSubscription');
  95. $limit = 10;
  96. $criteria = new TCriteria;
  97. $criteria->add(new TFilter('system_user_id','=',TSession::getValue('userid')));
  98. if (empty($param['order']))
  99. {
  100. $param['order'] = 'dtinscricao';
  101. $param['direction'] = 'asc';
  102. }
  103. $criteria->setProperties($param);
  104. $criteria->setProperty('limit', $limit);
  105. if (TSession::getValue('SystemRegistrationsList_filter_id')) {
  106. $criteria->add(TSession::getValue('SystemRegistrationsList_filter_id'));
  107. }
  108. $objects = $repository->load($criteria, FALSE);
  109. $this->datagrid->clear();
  110. if ($objects)
  111. {
  112. foreach ($objects as $object)
  113. {
  114. $this->datagrid->addItem($object);
  115. }
  116. }
  117. $criteria->resetProperties();
  118. $count= $repository->count($criteria);
  119. $this->pageNavigation->setCount($count);
  120. $this->pageNavigation->setProperties($param);
  121. $this->pageNavigation->setLimit($limit);
  122. TTransaction::close();
  123. $this->loaded = true;
  124. }
  125. catch (Exception $e)
  126. {
  127. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  128. TTransaction::rollback();
  129. }
  130. }
  131. function show()
  132. {
  133. if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  134. {
  135. $this->onReload( func_get_arg(0) );
  136. }
  137. parent::show();
  138. }
  139. function onGenerate($param)
  140. {
  141. $key=$param['key'];
  142. new TMessage('info', 'The name is :'. $key);
  143. $arquivo = './edital/'.$key.'/'.$key.'.pdf';
  144. if (!file_exists($arquivo) OR is_writable($arquivo))
  145. {
  146. parent::openFile($arquivo);
  147. }
  148. else
  149. {
  150. throw new Exception(_t('Permission denied') . ': ' . $arquivo);
  151. }
  152. TApplication::gotoPage('SystemNoticeList');
  153. }
  154. }
  155. ?>


SystemSubscriptionView
 
  1. <?php
  2. /**
  3. * SystemSubscriptionView
  4. *
  5. * @package control
  6. * @subpackage ps
  7. * @author Hellton Lacerda
  8. * @copyright Serviço Social da Indústria - Paraíba
  9. */
  10. class SystemSubscriptionView extends TPage
  11. {
  12. protected $form;
  13. function __construct()
  14. {
  15. parent::__construct();
  16. $this->form = new BootstrapFormBuilder('form_System_subscription_view');
  17. $this->form->setFormTitle(('Inscrição') );
  18. $id = new TEntry('id');
  19. $user = new TEntry('user');
  20. $cpf = new TEntry('cpf');
  21. $dtnascimento = new TEntry('dtnascimento');
  22. $unit = new TEntry('unit');
  23. $notice = new TEntry('notice');
  24. $dtinscricao = new TDate('dtinscricao');
  25. $nome_resp = new TEntry('nome_resp');
  26. $cpf_resp = new TEntry('cpf_resp');
  27. $empresa_resp = new TEntry('empresa_resp');
  28. $cnpj_resp = new TEntry('cnpj_resp');
  29. $escolaridade = new TCombo('escolaridade');
  30. $estadocivil = new TCombo('estadocivil');
  31. $renda = new TCombo('renda');
  32. $tipo_escola = new TCombo('tipo_escola');
  33. $escolaanterior = new TEntry('escolaanterior');
  34. $nt6lp = new TEntry('nt6lp');
  35. $nt6mt = new TEntry('nt6mt');
  36. $nt6geo = new TEntry('nt6geo');
  37. $nt6his = new TEntry('nt6his');
  38. $nt7lp = new TEntry('nt7lp');
  39. $nt7mt = new TEntry('nt7mt');
  40. $nt7geo = new TEntry('nt7geo');
  41. $nt7his = new TEntry('nt7his');
  42. $nt8lp = new TEntry('nt8lp');
  43. $nt8mt = new TEntry('nt8mt');
  44. $nt8geo = new TEntry('nt8geo');
  45. $nt8his = new TEntry('nt8his');
  46. $ntflp = new TEntry('ntflp');
  47. $ntfmt = new TEntry('ntfmt');
  48. $ntfgeo = new TEntry('ntfgeo');
  49. $ntfhis = new TEntry('ntfhis');
  50. $ntf = new TEntry('ntf');
  51. $situacao = new TCombo('situacao');
  52. $motivo_cancelamento = new TText('motivo_cancelamento');
  53. $situacao->addItems(['A' => 'AGUARDANDO', 'I' => 'INDEFERIDA', 'D' => 'DEFERIDA', 'M' => 'MATRICULADO']);
  54. $id->setEditable(FALSE);
  55. $user->setEditable(FALSE);
  56. $cpf->setEditable(FALSE);
  57. $nome_resp->setEditable(FALSE);
  58. $cpf_resp->setEditable(FALSE);
  59. $empresa_resp->setEditable(FALSE);
  60. $cnpj_resp->setEditable(FALSE);
  61. $unit->setEditable(FALSE);
  62. $notice->setEditable(FALSE);
  63. $nt6lp->setEditable(FALSE);
  64. $nt7lp->setEditable(FALSE);
  65. $nt8lp->setEditable(FALSE);
  66. $nt6mt->setEditable(FALSE);
  67. $nt7mt->setEditable(FALSE);
  68. $nt8mt->setEditable(FALSE);
  69. $nt6geo->setEditable(FALSE);
  70. $nt7geo->setEditable(FALSE);
  71. $nt8geo->setEditable(FALSE);
  72. $nt6his->setEditable(FALSE);
  73. $nt7his->setEditable(FALSE);
  74. $nt8his->setEditable(FALSE);
  75. $ntflp->setEditable(FALSE);
  76. $ntfmt->setEditable(FALSE);
  77. $ntfgeo->setEditable(FALSE);
  78. $ntfhis->setEditable(FALSE);
  79. $ntf->setEditable(FALSE);
  80. $id->setSize('10%');
  81. $user->setSize('100%');
  82. $cpf->setSize('100%');
  83. $nome_resp->setSize('100%');
  84. $cpf_resp->setSize('100%');
  85. $empresa_resp->setSize('100%');
  86. $cnpj_resp->setSize('100%');
  87. $unit->setSize('100%');
  88. $notice->setSize('100%');
  89. $nt6lp->setSize('100%');
  90. $nt7lp->setSize('100%');
  91. $nt8lp->setSize('100%');
  92. $nt6mt->setSize('100%');
  93. $nt7mt->setSize('100%');
  94. $nt8mt->setSize('100%');
  95. $nt6geo->setSize('100%');
  96. $nt7geo->setSize('100%');
  97. $nt8geo->setSize('100%');
  98. $nt6his->setSize('100%');
  99. $nt7his->setSize('100%');
  100. $nt8his->setSize('100%');
  101. $ntflp->setSize('100%');
  102. $ntfmt->setSize('100%');
  103. $ntfgeo->setSize('100%');
  104. $ntfhis->setSize('100%');
  105. $ntf->setSize('100%');
  106. $situacao->addValidation(('situação'), new TRequiredValidator);
  107. $motivo_cancelamento->addValidation(('justificativa'), new TRequiredValidator);
  108. $this->form->addFields( [new TLabel(('Número da inscrição'))], [$id]);
  109. $this->form->addFields( [new TLabel(('CPF do candidato'))], [$cpf], [new TLabel(('Candidato'))], [$user]);
  110. $this->form->addFields( [new TLabel(('CPF do responsável'))], [$cpf_resp], [new TLabel(('Nome completo do responsável'))], [$nome_resp] );
  111. $this->form->addFields( [new TLabel(('CNPJ da empresa a qual o responsável é vinculado'))], [$cnpj_resp], [new TLabel(('Nome da empresa a qual o responsável é vinculado'))], [$empresa_resp]);
  112. $this->form->addFields( [new TLabel(('Unidade'))], [$unit], [new TLabel(('Edital'))], [$notice]);
  113. $this->form->addFields( [new TFormSeparator(('Notas'))]);
  114. $this->form->addFields( [new TLabel(('Língua Portuguesa'))], [$nt6lp], [$nt7lp], [$nt8lp]);
  115. $this->form->addFields( [new TLabel(('Matemática'))], [$nt6mt], [$nt7mt], [$nt8mt]);
  116. $this->form->addFields( [new TLabel(('Geografia'))], [$nt6geo], [$nt7geo], [$nt8geo]);
  117. $this->form->addFields( [new TLabel(('História'))], [$nt6his], [$nt7his], [$nt8his]);
  118. $this->form->addFields( [new TLabel(('uuy'))], [new TLabel((''))]);
  119. $this->form->addFields( [new TFormSeparator(('Médias'))]);
  120. $this->form->addFields( [new TLabel(('Lingua Portuguesa'))], [$ntflp], [new TLabel(('Matemática'))], [$ntfmt]);
  121. $this->form->addFields( [new TLabel(('Geografia'))], [$ntfgeo], [new TLabel(('História'))], [$ntfhis]);
  122. $this->form->addFields( [new TLabel(('<br>'))]);
  123. $this->form->addFields( [new TLabel(('Média Final'))], [$ntf]);
  124. TTransaction::open('permission');
  125. $criteria_group = new TCriteria();
  126. $criteria_group->add(new TFilter('system_user_id', '=', TSession::getValue('userid')));
  127. $repository_user_group = new TRepository('SystemUserGroup');
  128. $user_groups = $repository_user_group->load($criteria_group);
  129. foreach($user_groups as $user_group){
  130. $option_user_group[$user_group->system_group_id] = $user_group->system_group_id;
  131. }
  132. TTransaction::close();
  133. if(in_array('1', $option_user_group )){
  134. $this->form->addFields( [new TLabel(('Situação'))], [$situacao]);
  135. $this->form->addFields( [new TLabel(('Justificativa'))], [$motivo_cancelamento]);
  136. $btn = $this->form->addAction(('Salvar'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  137. $btn->class = 'btn btn-sm btn-primary';
  138. }
  139. $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  140. $this->datagrid->datatable = 'true';
  141. $this->datagrid->width = '100%';
  142. $this->datagrid->setHeight(320);
  143. $id = new TDataGridColumn('id', 'Nº', 'center', null);
  144. $documento = new TDataGridColumn('documento', 'Documento', 'center', null);
  145. $id_documento = new TDataGridColumn('id_documento', 'id_documento', 'center', null);
  146. $order1= new TAction(array($this, 'onReload'));
  147. $order2= new TAction(array($this, 'onReload'));
  148. $order1->setParameter('order', 'id');
  149. $order1->setParameter('order', 'documento');
  150. $id->setAction($order1);
  151. $documento->setAction($order1);
  152. $this->datagrid->addColumn($id);
  153. $this->datagrid->addColumn($documento);
  154. $class = 'SystemSubscriptionView';
  155. $action1 = new TDataGridAction(array($class, 'onGenerate'));
  156. $action1->setLabel(_t('View'));
  157. $action1->setImage('fa:edit');
  158. $action1->setField('id_documento');
  159. $this->datagrid->addAction($action1);
  160. $this->datagrid->createModel();
  161. $panel = new TPanelGroup;
  162. $panel->add($this->datagrid);
  163. $this->datagrid2 = new BootstrapDatagridWrapper(new TDataGrid);
  164. $this->datagrid2->datatable = 'true';
  165. $this->datagrid2->width = '100%';
  166. $this->datagrid2->setHeight(320);
  167. $dtchange = new TDataGridColumn('dtchange', 'Data alteração', 'center', null);
  168. $situacao = new TDataGridColumn('situacao', 'Situação', 'center', null);
  169. $situacao->setTransformer(array($this, 'status'));
  170. $order1 = new TAction(array($this, 'onReload'));
  171. $order2 = new TAction(array($this, 'onReload'));
  172. $order1->setParameter('order', 'dtchange');
  173. $order1->setParameter('order', 'situacao');
  174. $dtchange->setAction($order1);
  175. $situacao->setAction($order1);
  176. $this->datagrid2->addColumn($dtchange);
  177. $this->datagrid2->addColumn($situacao);
  178. $this->datagrid2->createModel();
  179. $panel2 = new TPanelGroup;
  180. $panel2->add($this->datagrid2);
  181. $container = new TVBox;
  182. $container->style = 'wihgt: 100px';
  183. $container->add($this->form);
  184. $container->add($panel);
  185. $container->add($panel2);
  186. parent::add($container);
  187. }
  188. public function status($situacao){
  189. if($situacao == 'D'){
  190. $situacao = 'Deferida';
  191. }
  192. if($situacao == 'I'){
  193. $situacao = 'Indeferida';
  194. }
  195. if($situacao == 'A'){
  196. $situacao = 'Aguardando';
  197. }
  198. if($situacao == 'M'){
  199. $situacao = 'Matriculado';
  200. }
  201. return $situacao;
  202. }
  203. function onReload()
  204. {
  205. $this->datagrid->clear();
  206. $item = new StdClass;
  207. $item->id = '1';
  208. $item->documento = 'Certidão de Nascimento';
  209. $item->id_documento = 'cn_';
  210. $this->datagrid->addItem($item);
  211. $item = new StdClass;
  212. $item->id = '2';
  213. $item->documento = 'CPF do Candidato';
  214. $item->id_documento = 'cpf_cand_';
  215. $this->datagrid->addItem($item);
  216. $item = new StdClass;
  217. $item->id = '3';
  218. $item->documento = 'CPF do Responsável';
  219. $item->id_documento = 'cpf_resp_';
  220. $this->datagrid->addItem($item);
  221. $item = new StdClass;
  222. $item->id = '4';
  223. $item->documento = 'RG do Responsável';
  224. $item->id_documento = 'rg_resp_';
  225. $this->datagrid->addItem($item);
  226. $item = new StdClass;
  227. $item->id = '5';
  228. $item->documento = 'Carteira de Trabalho do Responsável';
  229. $item->id_documento = 'ct_resp_';
  230. $this->datagrid->addItem($item);
  231. $item = new StdClass;
  232. $item->id = '6';
  233. $item->documento = 'Comprovante de Residência';
  234. $item->id_documento = 'cr_';
  235. $this->datagrid->addItem($item);
  236. $item = new StdClass;
  237. $item->id = '7';
  238. $item->documento = 'Anexo I';
  239. $item->id_documento = 'avali_nt_';
  240. $this->datagrid->addItem($item);
  241. TTransaction::open('permission');
  242. $criteria_subscription = new TCriteria();
  243. $criteria_subscription->add(new TFilter('system_subscription_id', '=', TSession::getValue('subscription')));
  244. var_dump(TSession::getValue('subscription'));
  245. $repository_historical_subscription = new TRepository('SystemHistoricalSubscription');
  246. $historical_subscriptions = $repository_historical_subscription->load($criteria_subscription);
  247. $this->datagrid2->clear();
  248. if($historical_subscriptions){
  249. foreach($historical_subscriptions as $historical_subscription){
  250. $this->datagrid2->addItem($historical_subscription);
  251. }
  252. }
  253. TTransaction::close();
  254. }
  255. public function onGenerate($param){
  256. $key = $param['key'];
  257. $subscription = TSession::getValue('subscription');
  258. $subscription_array = TSession::getValue('subscription_array');
  259. $arquivo = './doc_alunos/'.$subscription.'/'.$key.''.$subscription.'.pdf';
  260. if (!file_exists($arquivo) OR is_writable($arquivo))
  261. {
  262. parent::openFile($arquivo);
  263. }
  264. else
  265. {
  266. throw new Exception(_t('Permission denied') . ': ' . $arquivo);
  267. }
  268. $this->form->setData($subscription_array);
  269. }
  270. public function onView($param)
  271. {
  272. try
  273. {
  274. TSession::setValue('subscription',$param['key']);
  275. TTransaction::open('permission');
  276. $criteria_subscription = new TCriteria;
  277. $criteria_subscription->add(new TFilter('id', '=',$param['key']));
  278. $repository_subscription = new TRepository('ViewSystemSubscription');
  279. $subscriptions = $repository_subscription->load($criteria_subscription);
  280. foreach($subscriptions as $subscription){
  281. $subscription;
  282. }
  283. TSession::setValue('subscription_array', $subscription);
  284. $this->form->setData($subscription);
  285. TTransaction::close();
  286. }
  287. catch (Exception $e)
  288. {
  289. new TMessage('error', $e->getMessage());
  290. }
  291. }
  292. public function onSave($param)
  293. {
  294. try
  295. {
  296. $object = $this->form->getData('ViewSystemSubscription');
  297. $this->form->validate();
  298. TTransaction::open('permission');
  299. $subscription = new SystemSubscription($object->id);
  300. $subscription->situacao = $object->situacao;
  301. $subscription->motivo_cancelamento = $object->motivo_cancelamento;
  302. $subscription->store();
  303. $historical_subscription = new SystemHistoricalSubscription();
  304. $historical_subscription->situacao = $object->situacao;
  305. $historical_subscription->justificativa = $object->motivo_cancelamento;
  306. $historical_subscription->dtchange = date('Y-m-d H:i:s');
  307. $historical_subscription->system_subscription_id = $object->id;
  308. $historical_subscription->system_user_id = TSession::getValue('userid');
  309. $historical_subscription->store();
  310. TTransaction::close();
  311. new TMessage('info', 'Inscrição atualizada com sucesso.');
  312. TApplication::gotoPage('SystemSubscriptionList');
  313. }
  314. catch (Exception $e)
  315. {
  316. new TMessage('error', $e->getMessage());
  317. TTransaction::rollback();
  318. }
  319. }
  320. function show()
  321. {
  322. if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  323. {
  324. $this->onReload( func_get_arg(0) );
  325. }
  326. parent::show();
  327. }
  328. }
  329. ?>


Segue vídeo (www.screencast.com/t/RpcZtz9j) demostrando o problema.

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (2)


FC

O comportamento está correto a sessão somente se acaba quando fecha o navegador.
MA

Conseguiu resolver o problema?
Caso sim, como foi resolvido?