Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function login(GtkWindow $wndLogin, GtkEntry $txtUser, GtkEntry $txtPass) {
- $strUser = $txtUser->get_text();
- $strPass = $txtPass->get_text();
- $errors = null;
- if (strlen($strUser) == 0)
- $errors = "Escriba su usuario\r\n";
- if (strlen($strPass) == 0)
- $errors = "Escriba su contraseña\r\n";
- if ($strUser != 'nax' || $strPass != 'nax')
- $errors = "Datos erroneos\r\n";
- //si hay errores creamos un alert
- if ($errors !== null) {
- $alert = new GtkMessageDialog($wndLogin, Gtk::DIALOG_MODAL, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, $errors);
- $alert->set_markup("Se encontraron los siguientes errores:\r\n<span foreground='red'>". $errors . '</span>');
- $alert->run();
- $alert->destroy();
- } else {
- showPam($wndLogin);
- }
- }
- function showPam(GtkWindow $wndLogin) {
- //Create the new GtkWindow
- $wndPam = new GtkWindow();
- $wndPam->set_title('Pam Window');
- $wndPam->connect_simple('destroy', array('gtk', 'main_quit'));
- $wndPam->resize(800, 700);
- //Create a connection to DB
- //$con = mysql_connect('localhost', 'root', '');
- $con = new mysqli;
- /*mysql_select_db('z_test', $con);
- $query = mysql_query('SELECT * FROM logeo LIMIT 0,1', $con);
- $lblData = new GtkLabel(mysql_fetch_array($query));
- $wndPam->add($lblData);
- */
- //Hide the login and show the Pam
- $wndLogin->hide_all();
- $wndPam->show_all();
- }
- /*Creation steps*/
- //Window Creation
- $wndLogin = new GtkWindow();
- $wndLogin->set_title('Pam Test');
- $wndLogin->connect_simple('destroy', array('gtk', 'main_quit'));
- //Button Creation
- $btnLogin = new GtkButton('_Login');
- $btnCancel = new GtkButton('_Cancelar');
- //Text Creation
- $txtUser = new GtkEntry();
- $txtPass = new GtkEntry();
- //Label Creation
- $lblUser = new GtkLabel('_Usuario:', true);
- $lblPass = new GtkLabel('_Contraseña:', true);
- $lblCredit = new GtkLabel('Introduce tus datos');
- //Mnemonic asign
- $lblUser->set_mnemonic_widget($txtUser);
- $lblPass->set_mnemonic_widget($txtPass);
- //Button action asign
- $btnCancel->connect_simple('clicked', array($wndLogin, 'destroy'));
- $btnLogin->connect_simple('clicked', 'login', $wndLogin, $txtUser, $txtPass);
- //Create the table
- $tbl = new GtkTable(3,2);
- $tbl->attach($lblCredit, 0, 2, 0, 1);
- $tbl->attach($lblUser, 0, 1, 1, 2);
- $tbl->attach($lblPass, 0, 1, 2, 3);
- $tbl->attach($txtUser, 1, 2, 1, 2);
- $tbl->attach($txtPass, 1, 2, 2, 3);
- //Create button box
- $bbox = new GtkHButtonBox();
- $bbox->set_layout(Gtk::BUTTONBOX_EDGE);
- $bbox->add($btnLogin);
- $bbox->add($btnCancel);
- //Attach de Table and te bbox into a vbox
- $vbox = new GtkVBox();
- $vbox->pack_start($tbl);
- $vbox->pack_start($bbox);
- //Attack all widgets into the window
- $wndLogin->add($vbox);
- $wndLogin->show_all();
- Gtk::main();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement