2013-10-29 66 views
0


我開始玩ajaxCRUD這似乎是簡單但有效的類。
我有一個表的用戶是這樣的:ajaxCRUD:關於插入的兩個問題

CREATE TABLE tbl_users (
    usr_id  INT NOT NULL AUTO_INCREMENT , 
    usr_name  VARCHAR(64) NOT NULL DEFAULT '' , 
    usr_surname VARCHAR(64) NOT NULL DEFAULT '' , 
    usr_pwd  VARCHAR(64) NOT NULL , 
    usr_level  INT(1) NOT NULL DEFAULT 0, 
    PRIMARY KEY (usr_id) 
) ENGINE = InnoDB; 

我的PHP代碼:

<?php 
    $tblUsers->omitPrimaryKey(); 

    $tblUsers->displayAs("usr_name", "Nome"); 
    $tblUsers->displayAs("usr_surname", "Cognome"); 
    $tblUsers->displayAs("usr_pwd", "Password"); 
    $tblUsers->displayAs("usr_level", "Livello"); 
    $tblUsers->omitField("usr_pwd"); 

    $tblUsers->modifyFieldWithClass("usr_pwd", "password"); 

    $allowable_vals = array(1 => "USER", 2 => "ADMIN", 3 => "SUPERUSER"); 

    $tblUsers->defineAllowableValues("usr_level", $allowable_vals); 
    $tblUsers->formatFieldWithFunction('usr_level', 'make_usr_level'); 
    $tblUsers->onAddExecuteCallBackFunction("AddCallBack"); 

    $tblUsers->addButtonToRow("Dettagli", "UserDetails.php"); 
    $tblUsers->addButtonToRow("Collega case", "HousesList.php"); 

    $tblUsers->setLimit(30); 

    #my self-defined functions used for formatFieldWithFunction 
    function make_usr_level($val){ 
    return FAUser::LevelToString($val); 
    } 

    function AddCallBack($array) 
    { 
    //these indexes are the fields of the db 
    $success = qr("INSERT INTO tbl_users 
        (usr_id, 
         usr_name, 
         usr_surname, 
         usr_pwd, 
         usr_level) 
        VALUES (NULL, 
          '" . $array[usr_name] . "', 
          '" . $array[usr_surname] . "', 
          AES_ENCRYPT('" . $array[usr_pwd] . "', 
             SHA2('FonteAlma_2013', 512)), 
          " . $array[usr_level] . ");"); 
    } 

    #actually show to the table 
    $tblUsers->showTable(); 

?> 

表顯示正常,並顯示已插入的用戶,但是,當我添加一個新用戶,我得到:

4 - TheGivenName - TheGivenSurname - [BLOB - 7 B] - 0 

所以密碼和用戶級別設置不好。另外,當我將表格中的級別字段編輯爲包含三個級別的組合框時,無論我選擇什麼值,我都會得到0。

我哪裏錯了?

問候。

回答

0

我編碼我的解決方案。

也許這不是最好的/正確的解決方案......但似乎工作。

我添加了一個方法onBeforeAddExecuteCallBackFunction(),它在執行ADD查詢之前被調用。
如果此回調函數返回FALSE,則執行結束(函數doAction返回)。否則繼續。

這是差異文件:

263d262 
< var $onBeforeAddExecuteCallBackFunction; 
352d350 
<  $this->onBeforeAddExecuteCallBackFunction = ''; 
653,657d650 
< function onBeforeAddExecuteCallBackFunction($function_name){ 
<  $this->onBeforeAddExecuteCallBackFunction = $function_name; 
<  $this->ajax_add = false; 
< } 
< 
900,906d892 
<   // Added 
<   if ($this->onBeforeAddExecuteCallBackFunction != '') { 
<   // If the Callback return FALSE, I quit 
<   if (!call_user_func($this->onBeforeAddExecuteCallBackFunction, $submitted_array)) 
<   return; 
<   } 
<