Exemplo n.º 1
0
 /**
  * Put an input object of certain type depending of the MySQL Table Feld Type on each data row[n]
  * @param Int $row_to_apply
  */
 public function insert_inputs_on_data_row($create_labels_tags_on_headers = TRUE)
 {
     // Row to apply is constant coz this is CREATE or EDIT and there is allways just 1 set of data to manipulate.
     $row_to_apply = 1;
     /**
      * VALUES
      */
     foreach ($this->db_table_data_filtered[$row_to_apply] as $field => $value) {
         /**
          * Switch on DB field specific TYPES
          */
         switch ($this->db_table->get_field_config($field, 'type')) {
             case 'enum':
                 $input_tag = input_helper::enum_type($this, $field);
                 break;
             case 'text':
                 switch ($this->db_table->get_field_config($field, 'validation')) {
                     case "html":
                         $input_tag = input_helper::text_type($this, $field);
                         break;
                     default:
                         $input_tag = input_helper::text_type($this, $field, FALSE);
                         break;
                 }
                 break;
             default:
                 /**
                  * Switch on K1lib DB Table Config VALIDATION TYPES
                  */
                 switch ($this->db_table->get_field_config($field, 'validation')) {
                     case "file-upload":
                         $input_tag = input_helper::file_upload($this, $field);
                         break;
                     case "password":
                         if (empty($value)) {
                             $input_tag = input_helper::password_type($this, $field, $this->object_state);
                         } else {
                             $input_tag = input_helper::password_type($this, $field, $this->object_state);
                         }
                         break;
                     default:
                         $input_tag = input_helper::default_type($this, $field);
                         break;
                 }
                 break;
         }
         /**
          * LABELS 
          */
         if ($create_labels_tags_on_headers) {
             $label_tag = new \k1lib\html\label($this->db_table_data_filtered[0][$field], $this->encrypt_field_name($field));
             if ($this->db_table->get_field_config($field, 'required') === TRUE) {
                 $label_tag->set_value(" *", TRUE);
             }
             if (isset($this->post_validation_errors[$field])) {
                 $label_tag->set_attrib("class", "is-invalid-label");
             }
             $this->db_table_data_filtered[0][$field] = $label_tag;
         }
         /**
          * ERROR TESTING
          */
         if (isset($this->post_validation_errors[$field])) {
             $div_error = new \k1lib\html\foundation\grid_row(2);
             $div_input = $div_error->col(1)->large(12);
             $div_message = $div_error->col(2)->large(12)->end();
             $span_error = $div_message->append_span("clearfix form-error is-visible");
             $span_error->set_value($this->post_validation_errors[$field]);
             $input_tag->append_to($div_input);
             $input_tag->set_attrib("class", "is-invalid-input", TRUE);
             $div_error->link_value_obj($input_tag);
         }
         /**
          * END ERROR TESTING
          */
         if ($this->db_table->get_field_config($field, 'required') === TRUE) {
             if ($this->enable_foundation_form_check) {
                 $input_tag->set_attrib("required", TRUE);
             }
         }
         $input_tag->set_attrib("k1lib-data-type", $this->db_table->get_field_config($field, 'validation'));
         $input_tag->set_attrib("id", $this->encrypt_field_name($field));
         if (isset($div_error)) {
             $this->apply_html_tag_on_field_filter($div_error, $field);
             unset($div_error);
         } else {
             $this->apply_html_tag_on_field_filter($input_tag, $field);
         }
         unset($input_tag);
     }
 }
Exemplo n.º 2
0
 /**
  * 
  * @return \k1lib\html\div
  */
 public function do_pagination()
 {
     $div_pagination = new \k1lib\html\div("k1lib-crudlexs-list-pagination clearfix", $this->get_object_id() . "-pagination");
     $div_scroller = $div_pagination->append_div("float-left pagination-scroller");
     $div_page_chooser = $div_pagination->append_div("float-left pagination-rows");
     if ($this->db_table_data && self::$rows_per_page <= $this->total_rows) {
         $page_get_var_name = $this->get_object_id() . "-page";
         $rows_get_var_name = $this->get_object_id() . "-rows";
         $this_url = APP_URL . \k1lib\urlrewrite\url::get_this_url() . "#" . $this->get_object_id() . "-pagination";
         if ($this->actual_page > 2) {
             $this->page_first = url::do_url($this_url, [$page_get_var_name => 1, $rows_get_var_name => self::$rows_per_page]);
         } else {
             $this->page_first = "#";
         }
         if ($this->actual_page > 1) {
             $this->page_previous = url::do_url($this_url, [$page_get_var_name => $this->actual_page - 1, $rows_get_var_name => self::$rows_per_page]);
         } else {
             $this->page_previous = "#";
         }
         if ($this->actual_page < $this->total_pages) {
             $this->page_next = url::do_url($this_url, [$page_get_var_name => $this->actual_page + 1, $rows_get_var_name => self::$rows_per_page]);
         } else {
             $this->page_next = "#";
         }
         if ($this->actual_page <= $this->total_pages - 2) {
             $this->page_last = url::do_url($this_url, [$page_get_var_name => $this->total_pages, $rows_get_var_name => self::$rows_per_page]);
         } else {
             $this->page_last = "#";
         }
         /**
          * HTML UL- LI construction
          */
         $ul = new \k1lib\html\ul("pagination k1lib-crudlexs " . $this->get_object_id());
         $ul->append_to($div_scroller);
         // First page LI
         $li = $ul->append_li();
         //    function append_a($href = NULL, $label = NULL, $target = NULL, $alt = NULL, $class = NULL, $id = NULL) {
         $a = $li->append_a($this->page_first, "‹‹", "_self", "k1lib-crudlexs-first-page");
         if ($this->page_first == "#") {
             $a->set_attrib("class", "disabled");
         }
         // Previuos page LI
         $li = $ul->append_li("");
         $a = $li->append_a($this->page_previous, "‹", "_self", "k1lib-crudlexs-previous-page");
         if ($this->page_previous == "#") {
             $a->set_attrib("class", "disabled");
         }
         /**
          * Page GOTO selector
          */
         $page_selector = new \k1lib\html\select("goto_page", "k1lib-crudlexs-page-goto", $this->get_object_id() . "-page-goto");
         $page_selector->set_attrib("onChange", "use_select_option_to_url_go(this)");
         for ($i = 1; $i <= $this->total_pages; $i++) {
             $option_url = url::do_url($this_url, [$page_get_var_name => $i, $rows_get_var_name => self::$rows_per_page]);
             $option = $page_selector->append_option($option_url, $i, $this->actual_page == $i ? TRUE : FALSE);
         }
         $ul->append_li()->append_child($page_selector);
         // Next page LI
         $li = $ul->append_li("");
         $a = $li->append_a($this->page_next, "›", "_self", "k1lib-crudlexs-next-page");
         if ($this->page_next == "#") {
             $a->set_attrib("class", "disabled");
         }
         // Last page LI
         $li = $ul->append_li("");
         $a = $li->append_a($this->page_last, "››", "_self", "k1lib-crudlexs-last-page");
         if ($this->page_last == "#") {
             $a->set_attrib("class", "disabled");
         }
         /**
          * PAGE ROWS selector
          */
         $num_rows_selector = new \k1lib\html\select("goto_page", "k1lib-crudlexs-page-goto", $this->get_object_id() . "-page-rows-goto");
         $num_rows_selector->set_attrib("onChange", "use_select_option_to_url_go(this)");
         foreach (self::$rows_per_page_options as $num_rows) {
             if ($num_rows <= $this->total_rows) {
                 $option_url = url::do_url($this_url, [$page_get_var_name => 1, $rows_get_var_name => $num_rows]);
                 $option = $num_rows_selector->append_option($option_url, $num_rows, self::$rows_per_page == $num_rows ? TRUE : FALSE);
             } else {
                 break;
             }
         }
         if ($this->total_rows <= self::$rows_limit_to_all) {
             $option_url = url::do_url($this_url, [$page_get_var_name => 1, $rows_get_var_name => $this->total_rows]);
             $option = $num_rows_selector->append_option($option_url, $this->total_rows, self::$rows_per_page == $this->total_rows ? TRUE : FALSE);
         }
         $label = new \k1lib\html\label("Show", $this->get_object_id() . "-page-rows-goto");
         $label->set_attrib("style", "display:inline");
         $label->append_to($div_page_chooser);
         $num_rows_selector->append_to($div_page_chooser);
     }
     return $div_pagination;
 }