Example #1
0
 public function __construct(\k1lib\crudlexs\controller_base $controller_object, array $user_levels_allowed = [])
 {
     parent::__construct($controller_object, $user_levels_allowed);
     $this->redirect_url = isset($_GET['back-url']) ? \k1lib\urlrewrite\get_back_url() : "{$controller_object->get_controller_root_dir()}{$this->controller_object->get_board_list_url_name()}/";
     if ($this->is_enabled) {
         $this->row_keys_text = url::set_url_rewrite_var(url::get_url_level_count(), 'row-keys-text', FALSE);
         $this->read_object = new \k1lib\crudlexs\reading($this->controller_object->db_table, $this->row_keys_text);
     }
 }
Example #2
0
 public function load_db_table_data($blank_data = FALSE)
 {
     $return_data = parent::load_db_table_data($blank_data);
     $url_action = url::set_url_rewrite_var(url::get_url_level_count(), "url_action", FALSE);
     $url_action_on_encoded_field = url::set_url_rewrite_var(url::get_url_level_count(), "url_action_on_encoded_field", FALSE);
     $url_action_on_field = $this->decrypt_field_name($url_action_on_encoded_field);
     if ($url_action == "unlink-uploaded-file") {
         \k1lib\forms\file_uploads::unlink_uploaded_file($this->db_table_data[1][$url_action_on_field]);
         $this->db_table_data[1][$url_action_on_field] = NULL;
         $this->db_table->update_data($this->db_table_data[1], $this->db_table_data_keys[1]);
         \k1lib\html\html_header_go(\k1lib\urlrewrite\get_back_url());
     }
     return $return_data;
 }
Example #3
0
 public static function register_footer($url, $relative = FALSE, $type = "auto")
 {
     trigger_error("Do not use me " . __METHOD__, E_USER_WARNING);
     self::is_enabled(true);
     if (!is_string($url)) {
         \trigger_error("The URL HAS to be a string", E_USER_ERROR);
     }
     if ($type == "auto") {
         $file_extension = \k1lib\common\get_file_extension($url);
     } else {
         $file_extension = $type;
     }
     if (!$file_extension) {
         return FALSE;
     }
     switch ($file_extension) {
         case 'js':
             $code = "<script src=\"%url%\"></script>";
             break;
         case 'css':
             $code = "<link href=\"%url%\" rel=\"stylesheet\">";
             break;
         default:
             \trigger_error("no extension detected on [{$url}] ", E_USER_ERROR);
             return FALSE;
             break;
     }
     if ($relative) {
         $code = str_replace("%url%", \k1lib\urlrewrite\url::do_url($url, [], FALSE), $code);
     } else {
         $code = str_replace("%url%", $url, $code);
     }
     return self::set_place_value("footer", $code);
 }
Example #4
0
 public function read_url_keys_text_for_list($db_table_name, $is_required = TRUE)
 {
     if (isset($this->board_list_object)) {
         /**
          * URL key text management
          */
         $related_url_keys_text = url::set_url_rewrite_var(url::get_url_level_count(), "related_url_keys_text", FALSE);
         if (!empty($related_url_keys_text)) {
             $related_table = $db_table_name;
             $related_db_table = new \k1lib\crudlexs\class_db_table($this->db_table->db, $related_table);
             $related_url_keys_array = \k1lib\sql\table_url_text_to_keys($related_url_keys_text, $related_db_table->get_db_table_config());
             $related_url_keys_text_auth_code = md5(\k1lib\K1MAGIC::get_value() . $related_url_keys_text);
             if (isset($_GET['auth-code']) && $_GET['auth-code'] === $related_url_keys_text_auth_code) {
                 $this->db_table->set_query_filter($related_url_keys_array, TRUE);
                 return $related_url_keys_text;
             } else {
                 $this->board_list_object->set_is_enabled(FALSE);
                 DOM_notification::queue_mesasage(board_base_strings::$error_url_keys_no_auth, "alert", $this->notifications_div_id, \k1lib\common_strings::$error);
                 return FALSE;
             }
         } else {
             if ($is_required) {
                 $this->board_list_object->set_is_enabled(FALSE);
                 DOM_notification::queue_mesasage(board_base_strings::$error_url_keys_no_keys_text, "alert", $this->notifications_div_id, \k1lib\common_strings::$error);
                 return FALSE;
             }
         }
     }
 }
Example #5
0
 /**
  * @return \k1lib\html\div|boolean
  */
 public function exec_board()
 {
     if (!$this->is_enabled) {
         return FALSE;
     }
     /**
      * HTML DB TABLE
      */
     if ($this->data_loaded) {
         if ($this->apply_label_filter) {
             $this->list_object->apply_label_filter();
         }
         if ($this->apply_field_label_filter) {
             $this->list_object->apply_field_label_filter();
         }
         if (\k1lib\forms\file_uploads::is_enabled()) {
             $this->list_object->apply_file_uploads_filter();
         }
         // IF NOT previous link applied this will try to apply ONLY on keys if are present on show-list filter
         if (!$this->list_object->get_link_on_field_filter_applied()) {
             $get_vars = ["auth-code" => "--authcode--", "back-url" => $_SERVER['REQUEST_URI']];
             $this->list_object->apply_link_on_field_filter(url::do_url("../{$this->controller_object->get_board_read_url_name()}/--rowkeys--/", $get_vars), crudlexs_base::USE_KEY_FIELDS);
         }
         // Show stats BEFORE
         if ($this->stats_enable && ($this->where_to_show_stats == self::SHOW_BEFORE_TABLE || $this->where_to_show_stats == self::SHOW_BEFORE_AND_AFTER_TABLE)) {
             $this->list_object->do_pagination()->append_to($this->board_content_div);
             $this->list_object->do_row_stats()->append_to($this->board_content_div);
         }
         /**
          * HTML OBJECT
          */
         $list_content_div = $this->list_object->do_html_object();
         $list_content_div->append_to($this->board_content_div);
         // Show stats AFTER
         if ($this->stats_enable && ($this->where_to_show_stats == self::SHOW_AFTER_TABLE || $this->where_to_show_stats == self::SHOW_BEFORE_AND_AFTER_TABLE)) {
             $this->list_object->do_row_stats()->append_to($this->board_content_div);
             $this->list_object->do_pagination()->append_to($this->board_content_div);
         }
         return $this->board_content_div;
     } else {
         $this->list_object->do_html_object()->append_to($this->board_content_div);
         return $this->board_content_div;
     }
 }
Example #6
0
 public function finish_board($do_redirect = TRUE, $custom_redirect = FALSE)
 {
     if ($this->sql_action_result !== NULL) {
         if ($custom_redirect === FALSE) {
             if (isset($_GET['back-url'])) {
                 $url_to_go = urldecode($_GET['back-url']);
             } else {
                 $get_params = ["auth-code" => "--authcode--"];
                 $url_to_go = url::do_url("{$this->controller_object->get_controller_root_dir()}{$this->controller_object->get_board_read_url_name()}/--rowkeys--/?", $get_params);
             }
         } else {
             $url_to_go = url::do_url($custom_redirect);
         }
         $this->update_object->post_update_redirect($url_to_go, $do_redirect);
     }
 }
Example #7
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;
 }
Example #8
0
 static function default_type(creating $crudlex_obj, $field)
 {
     $field_encrypted = $crudlex_obj->encrypt_field_name($field);
     if (!empty($crudlex_obj->db_table->get_field_config($field, 'refereced_table_name')) && self::$do_fk_search_tool && array_search($field, self::$fk_fields_to_skip) === FALSE) {
         $div_input_group = new \k1lib\html\div("input-group");
         $input_tag = new \k1lib\html\input("text", $field_encrypted, NULL, "k1lib-input-insert input-group-field");
         if (!empty($crudlex_obj->db_table->get_field_config($field, 'placeholder'))) {
             $input_tag->set_attrib("placeholder", $crudlex_obj->db_table->get_field_config($field, 'placeholder'));
         } else {
             $input_tag->set_attrib("placeholder", input_helper_strings::$input_fk_placeholder);
         }
         $input_tag->set_attrib("k1lib-data-group-" . $crudlex_obj->db_table->get_field_config($field, 'refereced_table_name'), TRUE);
         $input_tag->append_to($div_input_group);
         $div_input_group_button = new \k1lib\html\div("input-group-button");
         $div_input_group_button->append_to($div_input_group);
         /**
          * FK TABLE EXTRACTOR
          */
         $refereced_column_config = $crudlex_obj->db_table->get_field_config($field, 'refereced_column_config');
         //            while (!empty($refereced_column_config['refereced_column_config'])) {
         ////                $refereced_column_config = $refereced_column_config['refereced_column_config'];
         //            }
         $this_table = $crudlex_obj->db_table->get_db_table_name();
         $this_table_alias = \k1lib\db\security\db_table_aliases::encode($this_table);
         $fk_table = $refereced_column_config['table'];
         $fk_table_alias = \k1lib\db\security\db_table_aliases::encode($fk_table);
         //            $crudlex_obj->set_do_table_field_name_encrypt();
         $static_values = $crudlex_obj->db_table->get_constant_fields();
         $static_values_enconded = $crudlex_obj->encrypt_field_names($static_values);
         $search_button = new \k1lib\html\input("button", "search", "&#xf18d;", "button fi-page-search fk-button");
         $search_button->set_attrib("style", "font-family:foundation-icons");
         $url_params = ["back-url" => $_SERVER['REQUEST_URI']];
         $url_params = array_merge($static_values_enconded, $url_params);
         $url_to_search_fk_data = url::do_url(self::$url_to_search_fk_data . "{$fk_table_alias}/list/{$this_table_alias}/", $url_params);
         $search_button->set_attrib("onclick", "javascript:use_select_row_keys(this.form,'{$url_to_search_fk_data}')");
         $search_button->append_to($div_input_group_button);
         $div_input_group->link_value_obj($input_tag);
         return $div_input_group;
     } elseif (strstr("date,date-past,date-future", $crudlex_obj->db_table->get_field_config($field, 'validation')) !== FALSE) {
         $div_input_group = new \k1lib\html\div("input-group");
         $input_tag = new \k1lib\html\input("text", $field_encrypted, NULL, "k1lib-input-insert input-group-field datepicker");
         $input_tag->set_attrib("placeholder", input_helper_strings::$input_date_placeholder);
         $input_tag->set_attrib("k1lib-data-datepickup", TRUE);
         $input_tag->append_to($div_input_group);
         $div_input_group_button = new \k1lib\html\div("input-group-button");
         $div_input_group_button->append_to($div_input_group);
         $search_button = new \k1lib\html\a("#", "", "_self", "button fi-calendar");
         $search_button->append_to($div_input_group_button);
         $div_input_group->link_value_obj($input_tag);
         return $div_input_group;
     } else {
         $input_tag = new \k1lib\html\input("text", $field_encrypted, NULL, "k1lib-input-insert");
         $input_tag->set_attrib("placeholder", $crudlex_obj->db_table->get_field_config($field, 'placeholder'));
         return $input_tag;
     }
 }
Example #9
0
 public function apply_link_on_field_filter($link_to_apply, $fields_to_change = null, $custom_field_value = null, $href_target = null)
 {
     if ($this->get_state()) {
         $this->link_on_field_filter_applied = true;
         $a_tag = new \k1lib\html\a(url::do_url($link_to_apply), "", $href_target);
         $a_tag->set_attrib("class", "k1lib-link-filter", TRUE);
         if (empty($fields_to_change)) {
             $fields_to_change = crudlexs_base::USE_KEY_FIELDS;
         }
         return $this->apply_html_tag_on_field_filter($a_tag, $fields_to_change, $custom_field_value);
     } else {
         return FALSE;
     }
 }
Example #10
0
 public function related_apply_link_read_field($field_links_array, $board_root, $board_read, $clear_url = FALSE)
 {
     if ($this->related_list->get_db_table_data()) {
         if ($clear_url) {
             $get_vars = [];
         } else {
             $get_vars = ["auth-code" => "--authcode--", "back-url" => $_SERVER['REQUEST_URI']];
         }
         $link_row_url = url::do_url(APP_URL . $board_root . "/" . $board_read . "/--rowkeys--/", $get_vars);
         $this->related_list->apply_link_on_field_filter($link_row_url, $field_links_array);
         return TRUE;
     } else {
         return FALSE;
     }
 }