Exemplo n.º 1
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;
             }
         }
     }
 }
Exemplo n.º 2
0
 public static function get_user_hash($user_login = null)
 {
     if (empty($user_login)) {
         $user_login = self::$user_login;
     }
     if (self::$use_ip_in_userhash) {
         return md5($user_login . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'] . \k1lib\K1MAGIC::get_value());
     } else {
         return md5($user_login . $_SERVER['HTTP_USER_AGENT'] . \k1lib\K1MAGIC::get_value());
     }
 }
Exemplo n.º 3
0
 /**
  * 
  * @param \k1lib\crudlexs\class_db_table $db_table
  * @param array $field_links_array
  * @param string $title
  * @param string $board_root
  * @param string $board_create
  * @param string $board_read
  * @param boolean $show_create
  * @return \k1lib\html\div|boolean
  */
 public function create_related_list(class_db_table $db_table, $field_links_array, $title, $board_root, $board_create, $board_read, $board_list, $use_back_url = FALSE, $clear_url = FALSE)
 {
     $table_alias = \k1lib\db\security\db_table_aliases::encode($db_table->get_db_table_name());
     $detail_div = new \k1lib\html\div();
     $this->related_list = $this->do_related_list($db_table, $field_links_array, $board_root, $board_read);
     if (!empty($this->related_list)) {
         $current_row_keys_text = $this->read_object->get_row_keys_text();
         $current_row_keys_text_auth_code = md5(\k1lib\K1MAGIC::get_value() . $current_row_keys_text);
         $detail_div->set_class("k1lib-related-data-list {$table_alias}");
         $related_title = $detail_div->append_h4($title, "{$table_alias}");
         $detail_div->append_div("related-messaje");
         if ($data_loaded) {
             $get_vars = ["auth-code" => $current_row_keys_text_auth_code, "back-url" => $_SERVER['REQUEST_URI']];
             $all_data_url = url::do_url(APP_URL . $board_root . "/" . $board_list . "/{$current_row_keys_text}/", $get_vars, FALSE);
             $this->related_html_object_show_all_data = \k1lib\html\get_link_button($all_data_url, board_read_strings::$button_all_data, "tiny");
             if ($this->related_show_all_data) {
                 $related_title->set_value($this->related_html_object_show_all_data, TRUE);
             }
         }
         if ($use_back_url) {
             $get_vars = ["auth-code" => $current_row_keys_text_auth_code, "back-url" => $_SERVER['REQUEST_URI']];
             $create_url = url::do_url(APP_URL . $board_root . "/" . $board_create . "/{$current_row_keys_text}/", $get_vars, TRUE);
         } else {
             $get_vars = ["auth-code" => $current_row_keys_text_auth_code];
             $create_url = url::do_url(APP_URL . $board_root . "/" . $board_create . "/{$current_row_keys_text}/", $get_vars, TRUE, ['back-url'], FALSE);
         }
         $this->related_html_object_show_new = \k1lib\html\get_link_button($create_url, board_list_strings::$button_new, "tiny");
         if ($this->related_show_new) {
             $related_title->set_value($this->related_html_object_show_new, TRUE);
         }
         $this->related_list->do_html_object()->append_to($detail_div);
         $this->related_html_table_object = $this->related_list->get_html_table();
         if ($db_table->get_total_rows() > $this->related_rows_to_show) {
             $this->related_list->do_pagination()->append_to($detail_div);
             $this->related_list->do_row_stats()->append_to($detail_div);
         }
         listing::$rows_per_page = $actual_rows_per_page;
     }
     // TODO: NONSENSE line !
     //        $this->set_related_show_new(TRUE);
     return $detail_div;
 }
Exemplo n.º 4
0
 public function apply_html_tag_on_field_filter(\k1lib\html\tag $tag_object, $fields_to_change = crudlexs_base::USE_KEY_FIELDS, $custom_field_value = null)
 {
     if ($this->get_state()) {
         if (empty($this->db_table_data) || !is_array($this->db_table_data)) {
             trigger_error(__METHOD__ . " " . object_base_strings::$error_no_table_data, E_USER_NOTICE);
             return FALSE;
         } else {
             if ($fields_to_change == crudlexs_base::USE_KEY_FIELDS) {
                 $fields_to_change = \k1lib\sql\get_db_table_keys_array($this->db_table->get_db_table_config());
             } elseif ($fields_to_change == crudlexs_base::USE_ALL_FIELDS) {
                 $fields_to_change = $this->db_table_data[0];
             } elseif ($fields_to_change == crudlexs_base::USE_LABEL_FIELDS) {
                 $fields_to_change = \k1lib\sql\get_db_table_label_fields($this->db_table->get_db_table_config());
                 if (empty($fields_to_change)) {
                     $fields_to_change = \k1lib\sql\get_db_table_keys_array($this->db_table->get_db_table_config());
                 }
             } elseif (empty($fields_to_change)) {
                 $fields_to_change = $this->db_table_data[0];
             } else {
                 if (!is_array($fields_to_change) && is_string($fields_to_change)) {
                     $fields_to_change = array($fields_to_change);
                 }
             }
             $table_constant_fields = $this->db_table->get_constant_fields();
             foreach ($fields_to_change as $field_to_change) {
                 foreach ($this->db_table_data_filtered as $index => $row_data) {
                     if ($index === 0) {
                         continue;
                     }
                     if (!array_key_exists($field_to_change, $row_data)) {
                         trigger_error(__METHOD__ . "The field to change ({$field_to_change}) do no exist ", E_USER_NOTICE);
                         continue;
                     } else {
                         // Let's clone the $tag_object to reuse it properly
                         $tag_object_original = clone $tag_object;
                         $custom_field_value_original = $custom_field_value;
                         if ($this->skip_blanks_on_filters && empty($row_data[$field_to_change])) {
                             continue;
                         }
                         $tag_object->set_value($row_data[$field_to_change]);
                         if (is_object($tag_object)) {
                             $a_tags = [];
                             $tag_value = null;
                             if (get_class($tag_object) == "k1lib\\html\\a") {
                                 $tag_href = $tag_object->get_attribute("href");
                                 $tag_value = $tag_object->get_value();
                             } elseif (get_class($tag_object) == "k1lib\\html\\img") {
                                 $tag_href = $tag_object->get_attribute("src");
                                 $tag_value = $tag_object->get_attribute("alt");
                             } else {
                                 // Let's try to get an A object from this object searching for it
                                 $a_tags = $tag_object->get_elements_by_tag("a");
                                 if (count($a_tags) === 1) {
                                     $tag_href = $a_tags[0]->get_attribute("href");
                                     $tag_value = $a_tags[0]->get_value();
                                 } else {
                                     // TODO: CHECK THIS! - WTF line
                                     //                                    $tag_href = $tag_object->get_value();
                                     $tag_href = NULL;
                                 }
                             }
                             if (!empty($this->db_table_data_keys) && !empty($tag_href)) {
                                 if (is_array($custom_field_value)) {
                                     foreach ($custom_field_value as $key => $field_value) {
                                         if (isset($row_data[$field_value])) {
                                             $custom_field_value[$key] = $this->db_table_data[$index][$field_value];
                                         }
                                         if (isset($table_constant_fields[$field_value])) {
                                             $custom_field_value[$key] = $table_constant_fields[$field_value];
                                         }
                                     }
                                     $custom_field_value = implode("--", $custom_field_value);
                                 }
                                 $key_array_text = \k1lib\sql\table_keys_to_text($this->db_table_data_keys[$index], $this->db_table->get_db_table_config());
                                 $auth_code = md5(\k1lib\K1MAGIC::get_value() . $key_array_text);
                                 /**
                                  * HREF STR_REPLACE
                                  */
                                 $tag_href = str_replace("--rowkeys--", $key_array_text, $tag_href);
                                 $tag_href = str_replace("--fieldvalue--", $row_data[$field_to_change], $tag_href);
                                 // TODO: Why did I needed this ? WFT Line
                                 $actual_custom_field_value = str_replace("--fieldvalue--", $row_data[$field_to_change], $custom_field_value);
                                 $tag_href = str_replace("--customfieldvalue--", $actual_custom_field_value, $tag_href);
                                 $tag_href = str_replace("--authcode--", $auth_code, $tag_href);
                                 $tag_href = str_replace("--fieldauthcode--", md5(\k1lib\K1MAGIC::get_value() . ($actual_custom_field_value ? $actual_custom_field_value : $row_data[$field_to_change])), $tag_href);
                                 /**
                                  * VALUE STR_REPLACE
                                  */
                                 $tag_value = str_replace("--rowkeys--", $key_array_text, $tag_value);
                                 $tag_value = str_replace("--fieldvalue--", $row_data[$field_to_change], $tag_value);
                                 $tag_value = str_replace("--customfieldvalue--", $actual_custom_field_value, $tag_value);
                                 $tag_value = str_replace("--authcode--", $auth_code, $tag_value);
                                 $tag_value = str_replace("--fieldauthcode--", md5(\k1lib\K1MAGIC::get_value() . ($actual_custom_field_value ? $actual_custom_field_value : $row_data[$field_to_change])), $tag_value);
                                 if (get_class($tag_object) == "k1lib\\html\\a") {
                                     $tag_object->set_attrib("href", $tag_href);
                                     $tag_object->set_value($tag_value);
                                 }
                                 if (get_class($tag_object) == "k1lib\\html\\img") {
                                     $tag_object->set_attrib("src", $tag_href);
                                 }
                                 // get-elements-by-tags fix
                                 foreach ($a_tags as $a_tag) {
                                     $a_tag->set_attrib("href", $tag_href);
                                     $a_tag->set_value($tag_value);
                                 }
                             }
                         } else {
                             trigger_error("Not a HTML_TAG Object", E_USER_WARNING);
                         }
                         $this->db_table_data_filtered[$index][$field_to_change] = $tag_object;
                         // Clean it... $tag_object
                         unset($tag_object);
                         // Let's clone the original to re use it
                         $tag_object = clone $tag_object_original;
                         $custom_field_value = $custom_field_value_original;
                     }
                 }
             }
             return TRUE;
         }
     } else {
         return FALSE;
     }
 }
Exemplo n.º 5
0
/**
 * Check a incomming MAGIC VALUE 
 * @param String $name The name with it was stored
 * @param String $value_to_check Received var
 * @return boolean
 */
function check_magic_value($name, $value_to_check)
{
    if (\k1lib\session\session_plain::on_session()) {
        if ($value_to_check == "") {
            die("The magic value never can be empty!");
        } else {
            if (isset($_SESSION[\k1lib\common\get_magic_name($name)])) {
                $secret = $_SESSION[\k1lib\common\get_magic_name($name)];
                $client_magic = md5(\k1lib\K1MAGIC::get_value() . $secret);
                if ($client_magic == $value_to_check) {
                    return $client_magic;
                } else {
                    return FALSE;
                }
            } else {
                return FALSE;
            }
        }
    } else {
        trigger_error("Magic system REQUIRES the session system to be enabled and a session started", E_USER_ERROR);
    }
}