Pokus o preklad username na userid
authorThomas Mudrunka <tomas@mudrunka.cz>
Fri, 24 Feb 2012 19:07:15 +0000 (20:07 +0100)
committerThomas Mudrunka <tomas@mudrunka.cz>
Fri, 24 Feb 2012 19:07:15 +0000 (20:07 +0100)
index.php
lib/Sklad_Auth.class/internal.php
lib/Sklad_Auth.class/lms.php

index b10f8f1963157600ccfd9f32fe96a4d1c3deae18..d6c7e5750e1476c26f199601a45b9852e67e9f3c 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -600,19 +600,30 @@ class Sklad_DB extends PDO {
                return $result;
        }
 
-       function translate_query_results($result) {
+       function translate_query_results(&$result) {
                $translate_cols = array('status_name', 'item_valid_till'); //TODO: Hardcoded
                foreach($result as $key => $row) {
                        foreach($translate_cols as $col) if(isset($result[$key][$col])){
                                $result[$key][$col] = T($result[$key][$col]);
                        }
                }
-               return $result;
+       }
+
+       function load_backend_data_to_query_results(&$result) {
+               $translate_cols = array(
+                       'item_author' => 'return($this->auth->get_username_by_id($result[$key][$col]));'
+               ); //TODO: Hardcoded
+               foreach($result as $key => $row) {
+                       foreach($translate_cols as $col => $backend) if(isset($result[$key][$col])){
+                               $result[$key][$col] = eval($backend);
+                       }
+               }
        }
 
        function safe_query_fetch($sql, $fatal=true, $fetch_flags = PDO::FETCH_ASSOC, $translate=true) {
                $result = $this->safe_query($sql, $fatal)->fetchAll($fetch_flags);
-               if($translate) $result = $this->translate_query_results($result);
+               $this->load_backend_data_to_query_results($result);
+               if($translate) $this->translate_query_results($result);
                return $result;
        }
 
index 9739aa3ed2f170f55085e2e4c969543224eeed2d..8e4f160f319d14c37a9685e69de1c3089ee9f6de 100755 (executable)
@@ -37,4 +37,8 @@ class Sklad_Auth extends Sklad_Auth_common { //FAKE!
                }
                return false;
        }
+
+       function get_username_by_id($id) {
+               return("USER($id)");
+       }
 }
index 7994b44d5585c7843e579197d7de6295c3c04594..3308c0204752af3300c131865f4d8d8fa9f2792d 100755 (executable)
@@ -48,4 +48,21 @@ class Sklad_Auth extends Sklad_Auth_common {
                return true;
 
        }
+
+  function get_username_by_id($id) {
+               $LMS_CONFIG = (array)parse_ini_file('/etc/lms/lms.ini', true);
+
+               $dblink = @mysql_connect($LMS_CONFIG['database']['host'], $LMS_CONFIG['database']['user'], $LMS_CONFIG['database']['password']);
+               mysql_select_db($LMS_CONFIG['database']['database'], $dblink);
+
+               mysql_query("SET NAMES utf8");
+
+               $lQ = mysql_query("SELECT name FROM users WHERE id='".$id."' AND deleted=0");
+               $lA = mysql_fetch_array($lQ, MYSQL_ASSOC);
+               @mysql_close($dblink);
+
+               if(!is_array($lA)) return "USER($id)";
+
+               return($lA['name']);
+  }
 }
This page took 0.156826 seconds and 4 git commands to generate.