예제 #1
0
 public function forgot()
 {
     $content = '';
     $token_handler = new security();
     $token_handler->set_token();
     $token = $token_handler->get_token();
     $register_form = "\n        <form action='?controller=users&action=reset' method='post'>\n          Username: <input type='text' name='username' placeholder='ex: john' autofocus>\n            <br>\n          email: <input type='text' name='email'>\n          <br><br>\n          <input type='submit' value='reset'>\n          <input type='hidden' value='{$token}' name='token'>\n        </form>\n\n        ";
     $content .= $register_form;
     $output['content'] = $content;
     $output['page'] = 'views/forgot.php';
     return $output;
 }
예제 #2
0
 public function login()
 {
     // 1st time (&submit is not set) or error=true - just show form and/or error message
     // 2nd time (&submit==yes) - check
     // if ok, redirect to home
     // if not, set $content to error message and just show form again
     if (!isset($_SESSION['log'])) {
         $_SESSION['log'] = new timestamp("login");
     }
     $content = "";
     $output['page'] = 'views/login/index.php';
     //$header = 'CSS AEC-Foyer Lataste ADTJK System V2.0';
     $token_handler = new security();
     $token_handler->set_token();
     $token = $token_handler->get_token();
     $login_form = "\n        <form action='?controller=login&action=submit' method='post'>\n          Username: <input type='text' name='username' placeholder='ex: john' autofocus>\n            <br>\n          Password: <input type='password' name='password'>\n          <br><br>\n          <input type='submit' value='login'>\n          <input type='hidden' value='{$token}' name='token'>\n        </form>\n\n        ";
     $current_year = date("Y");
     $footer = "CSS AEC-Foyer Lataste ADTJK Copyright {$current_year} All Rights Reserved - Webmaster: ivan.bragatto@gmail.com";
     // $output ['header']     = $header;
     $output['login_form'] = $login_form;
     $output['content'] = $content;
     $output['footer'] = $footer;
     return $output;
 }
예제 #3
0
 public function set_top_form($top_form)
 {
     //  form: add record form on top: field names, field labels, drop_down menu name (from previous $drop_down set method)
     //  follows the $main_table columns order
     // Also, set_drop_down method does not 'select' value retrieved from DB.
     //
     $html = "<tr>";
     $html .= "<form action='{$top_form['action']}' method='{$top_form['method']}' id='{$top_form['id']}'>";
     $i = 0;
     $autofocus = '';
     foreach ($top_form['elements'] as $key => $bla) {
         //echo 'key: '.$key.'<br>';
         foreach ($bla as $key2 => $key3) {
             $i++;
             // $key2: value position inside numbered array
             //echo '.....key2:'.$key2.'<br>';
             //echo '.....key3:'.$key3.'<br>';
             $value = '';
             switch ($key2) {
                 case 'text':
                     if ($i == 1) {
                         $autofocus = 'autofocus';
                     }
                     if (isset($this->form_values)) {
                         $value = $this->form_values[$key3];
                     }
                     $html .= '<td>' . "<div " . $top_form['div'] . ">";
                     $html .= "<input type='text' name='{$key3}' value='{$value}' {$autofocus}>";
                     $html .= "</td></div>";
                     $i++;
                     break;
                 case 'date':
                     if ($i == 1) {
                         $autofocus = 'autofocus';
                     }
                     if (isset($this->form_values)) {
                         $value = $this->form_values[$key3];
                     }
                     $html .= '<td>' . "<div " . $top_form['div'] . ">";
                     $html .= "<input type='date' name='{$key3}' value='{$value}' {$autofocus}>";
                     $html .= "</td></div>";
                     $i++;
                     break;
                 case 'drop_down':
                     $html .= '<td>' . "<div " . $top_form['div'] . ">";
                     $html .= $this->drop_down[$key3];
                     $html .= "</td></div>";
                     break;
                 case 'submit':
                     $html .= "<td><div ";
                     if (isset($top_form['div_button'])) {
                         $html .= $top_form['div_button'];
                     } else {
                         $html .= $top_form['div'];
                     }
                     $html .= ">";
                     $html .= "<input type='submit' value='{$key3}'>";
                     $html .= "</td></div>";
                     break;
                 case 'check_box':
                     // check_box works just like drop_down; needs a proper function to pre make html
                     $html .= '<td>' . "<div " . $top_form['div'] . ">";
                     $html .= $this->check_box[$key3];
                     $html .= "</td></div>";
                     break;
                 case 'label':
                     $html .= '<td>' . "<div " . $top_form['div'] . ">";
                     $html .= $this->form_values[$key3];
                     $html .= "</td></div>";
                     break;
                 case 'hidden':
                     foreach ($key3 as $hidden_name => $hidden_value) {
                         $html .= "<input type='hidden' name='{$hidden_name}' value='{$hidden_value}'>";
                     }
                     break;
                 default:
                     $html .= '<td></td>';
                     break;
             }
         }
     }
     // TODO: insert token check here
     if (!isset($this->token)) {
         $token_handler = new security();
         $token_handler->set_token();
         $this->token = $token_handler->get_token();
     }
     //echo $_SESSION['token'];
     //die();
     // TODO: troubleshoot: if multiple forms at the same time, token check might fail since each form
     // will have produced its own token, but only one will be checked - make an array of tokens then iterate?
     $html .= "<input type='hidden' name='token' value = '{$this->token}'>";
     $html .= "</form>";
     if (isset($_GET['id'])) {
         $id = $_GET['id'];
     }
     if (isset($top_form['action_links'])) {
         $action_links = $top_form['action_links'];
         $html .= "<td><div class='small_link_button'>";
         foreach ($action_links as $row) {
             //var_dump($row);
             $html .= "<a href='" . $row[1] . $id . "&token=" . $this->token . "'>" . $row[0] . "</a>";
         }
         $html .= "</div></td>";
     }
     $html .= "</tr>";
     $this->top_form = $html;
 }