Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.90 KB | None | 0 0
  1. <?php
  2.  
  3. function login(GtkWindow $wndLogin, GtkEntry $txtUser, GtkEntry $txtPass) {
  4.    
  5.     $strUser = $txtUser->get_text();
  6.     $strPass = $txtPass->get_text();
  7.    
  8.     $errors = null;
  9.     if (strlen($strUser) == 0)
  10.         $errors = "Escriba su usuario\r\n";
  11.     if (strlen($strPass) == 0)
  12.         $errors = "Escriba su contraseña\r\n";
  13.     if ($strUser != 'nax' || $strPass != 'nax')
  14.         $errors = "Datos erroneos\r\n";
  15.    
  16.     //si hay errores creamos un alert
  17.     if ($errors !== null) {
  18.         $alert = new GtkMessageDialog($wndLogin, Gtk::DIALOG_MODAL, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, $errors);
  19.         $alert->set_markup("Se encontraron los siguientes errores:\r\n<span foreground='red'>". $errors . '</span>');
  20.         $alert->run();
  21.         $alert->destroy();
  22.     } else {
  23.         showPam($wndLogin);
  24.     }
  25.    
  26. }
  27.  
  28. function showPam(GtkWindow $wndLogin) {
  29.     //Create the new GtkWindow
  30.     $wndPam = new GtkWindow();
  31.     $wndPam->set_title('Pam Window');
  32.     $wndPam->connect_simple('destroy', array('gtk', 'main_quit'));
  33.     $wndPam->resize(800, 700);
  34.    
  35.     //Create a connection to DB
  36.     //$con = mysql_connect('localhost', 'root', '');
  37.     $con = new mysqli;
  38.     /*mysql_select_db('z_test', $con);
  39.    
  40.     $query = mysql_query('SELECT * FROM logeo LIMIT 0,1', $con);
  41.    
  42.     $lblData = new GtkLabel(mysql_fetch_array($query));
  43.    
  44.     $wndPam->add($lblData);
  45.     */
  46.    
  47.    
  48.    
  49.     //Hide the login and show the Pam
  50.     $wndLogin->hide_all();
  51.     $wndPam->show_all();
  52. }
  53.  
  54. /*Creation steps*/
  55.  
  56. //Window Creation
  57. $wndLogin = new GtkWindow();
  58. $wndLogin->set_title('Pam Test');
  59. $wndLogin->connect_simple('destroy', array('gtk', 'main_quit'));
  60.  
  61. //Button Creation
  62. $btnLogin = new GtkButton('_Login');
  63. $btnCancel = new GtkButton('_Cancelar');
  64.  
  65. //Text Creation
  66. $txtUser = new GtkEntry();
  67. $txtPass = new GtkEntry();
  68.  
  69. //Label Creation
  70. $lblUser = new GtkLabel('_Usuario:', true);
  71. $lblPass = new GtkLabel('_Contraseña:', true);
  72. $lblCredit = new GtkLabel('Introduce tus datos');
  73.  
  74. //Mnemonic asign
  75. $lblUser->set_mnemonic_widget($txtUser);
  76. $lblPass->set_mnemonic_widget($txtPass);
  77.  
  78. //Button action asign
  79. $btnCancel->connect_simple('clicked', array($wndLogin, 'destroy'));
  80. $btnLogin->connect_simple('clicked', 'login', $wndLogin, $txtUser, $txtPass);
  81.  
  82. //Create the table
  83. $tbl = new GtkTable(3,2);
  84. $tbl->attach($lblCredit, 0, 2, 0, 1);
  85. $tbl->attach($lblUser, 0, 1, 1, 2);
  86. $tbl->attach($lblPass, 0, 1, 2, 3);
  87. $tbl->attach($txtUser, 1, 2, 1, 2);
  88. $tbl->attach($txtPass, 1, 2, 2, 3);
  89.  
  90.  
  91. //Create button box
  92. $bbox = new GtkHButtonBox();
  93. $bbox->set_layout(Gtk::BUTTONBOX_EDGE);
  94. $bbox->add($btnLogin);
  95. $bbox->add($btnCancel);
  96.  
  97. //Attach de Table and te bbox into a vbox
  98. $vbox = new GtkVBox();
  99. $vbox->pack_start($tbl);
  100. $vbox->pack_start($bbox);
  101.  
  102. //Attack all widgets into the window
  103. $wndLogin->add($vbox);
  104. $wndLogin->show_all();
  105.  
  106. Gtk::main();
  107.  
  108.  
  109.  
  110. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement