PHP background management class (modified)

zhaozj2021-02-16  69

Var $ post; var $ me; function int_pk_val () {global $ _GET, $ _ post; if ($ this-> pk_val) return;

IF (! EMPTY ($ _ get ['Edit_ID'])) {$ this-> pk_val = $ _ get ['edit_id']; return;}

IF (! Empty ($ _ post ['id')) {$ this-> pk_val = $ _ post ['id']; return;}}

Function Admin ($ Action, $ TABLE, $ SELECT_SQL) {Global $ _POST, $ Me; / * FOREACH ($ _ Post AS $ Key => $ VAL) {$ _POST [$ Key] = TRIM (NVL ($ VAL)) } * / $ This-> post = $ _ post; $ this-> me = $ me; $ this-> action = $ action; $ this-> table = $ table; $ this-> select_sql = $ SELECT_SQL;

$ this-> INT_PK_VAL ();

Function execute () {if ($ this-> action) $ this-> display (); else {$ action = $ this-> action; $ this -> $ action ();}}

Function Display () {/ * Display Data * / Global $ CFG, $ _ POST, $ ME;

$ where = $ this-> get_where ($ this-> select_sql); $ this-> select_sql. = $ where;

$ P = new SXPAGING ($ this-> SELECT_SQL, NVL ($ _ Post ['Requirepage'), NVL ($ _ Post ['Pagesize')); if ($ this-> html_cmd) $ html_cmd = " "" $ this-> html_cmd; else $ html_cmd = "| ; incrude ("$ cfg-> Dirtpl / admin / header.html "); echo ("

"); $ str = $ p-> getprint ('No', $ this-> caption, 0);

IF ($ STR) $ STR. = $ html_cmd. $ this-> html_query; else {$ str = $ this-> display_no_data ($ where);} Echo ("$ STR"); Echo $ this-> get_query_state () ECHO ("");

INCLUDE ("$ cfg-> dirtpl / admin / footer.html");

Function Add ($ ErrorMsg = '') {Global $ CFG, $ _ POST, $ ME; $ cmd = 'insert'; $ form = ($ this-> array_tpl [? form_add '])? $ THIS-> Array_TPL ['Form']: $ this-> array_tpl ['form_add']; include ($ this-> array_tpl ['header']); include ($ this-> array_tpl ['form_header']); include ($ form); include ($ form); incrude ($ FORM) ); Include ($ this-> array_tpl ['footer']);

Function Insert () {/ * Insert Data * / Global $ CFG, $ _ Post, $ ME, $ DOC_TITLE; $ SQL_ADD = $ THIS-> GET_ADD_SQL (); $ ErrorMsg = $ THIS-> Valid (); if (EMPTY $ ERRORMSG) {$ qi = db_query ($ SQL_ADD); $ PK_VAL = DB_INSERT_ID ($ PK_VAL); set_logs ($ this-> CAPTION, LOG_TYPE_INSERT, $ THIS-> TABLE, $ PK_VAL); $ this-> Go_TO_ME () Return;}

$ this-> add ($ errormsg);

Function Check_operator ($ TABLE, $ PK_VAL) {$ Operator = $ _ session ['session'] ['user'] ['id']; $ sql = "SELECT 1 from $ TABLE $ this-> pk_name = $ pk_val and Operator = $ operator "; $ = db_query ($ SQL); Return DB_FETCH_ARRAY ($ q);} Function Edit ($ ErrorMsg = ') {Global $ CFG, $ _ Post, $ ME, $ _ Get, $ DOC_TITLE; IF (EMPTY ($ this-> pk_val)) DIE ("Edit ID is not, it is a program wrong");

$ Cmd = "update";

$ SQL = "Select * from $ this-> Table where $ this-> pk_name = $ this-> pk_val"; $ qi = db_query ($ sql); $ _POST = DB_FETCH_ARRAY ($ q); if (Empty ($ _ POST ['ID'])) $ _ post ['id'] = $ this-> pk_val; $ form = Empty ($ this-> array_tpl ['form_update'])? $ this-> array_tpl ['form']: $ this-> array_tpl ['form_update']; include ($ this-> array_tpl ['header']); include ($ this-> array_tpl ['form_header']); include ($ form); include ($ this-> Array_TPL ['Footer']);

Function update () {/ * Modify * / Global $ CFG, $ _ POST, $ ME; $ SQL = $ this-> get_update_sql (); $ error (); if (Empty ($ error)) {IF (! $ This-> Check_operator ($ this-> Table, $ this-> pk_val)) {$ ErrorMsg. = "

  • is not the data you added, you are not right to modify!";}} If (! EMPTY ($ ERRORMSG)) {$ this-> Edit ($ ErrorMsg); Die ();} DB_QUERY ($ SQL);

    Set_logs ($ this-> CAPTION, LOG_TYPE_UPDATE, $ THIS-> TABLE, $ this-> pk_val); $ this-> Go_to_me ();

    Function Del ($ CTL_NAME = ', $ TABLE =', $ real_do = 0) {/ * Delete * / Global $ _POST, $ _ session; $ operator = $ _ session ['session'] ['user'] [' ID ']; if (! $ ctl_name) $ CTL_NAME =' del_id '; if ($ table) $ this-> Table = $ table; if (! Empty ($ _ post [$ ctl_name])) {// $ 中号Implode (',', $ _ post [$ ctl_name]); / * $ sql = ''; if ($ real_do) {$ SQL = "delete from $ this-> Table where $ this-> pk_name in ($ IN) "} Else {$ SQL =" Update $ this-> Table set isdeleted = $ operator where $ this-> pk_name in ($ in) ";} DB_QUERY ($ SQL); * / $ can_DELETE_ROWS =" "; Foreach $ _POST [$ CTL_NAME] AS $ PK_VAL) {IF ($ this-> Check_operator ($ this-> table, $ pk_val)) {$ sql = "delete from $ this-> Table where $ this-> pk_name = $ PK_VAL "; DB_QUERY ($ SQL); set_logs ($ this-> CAPTION, LOG_TYPE_DELETE, $ THIS-> Table, $ PK_VAL);} else {$ can_dlete_rows. =" $ Pk_val, ";}}}}}}}}}}} Can_Delete_rows = "Primary button data for $ can_DELETE_ROWS Non you to add, you can't delete!" = $ this-> Valid_Array_Valid (); returnite $ ER ROR_MSG;

    Function Valid_Array_Valid () {/ * Verification Data Validity * / Global $ _POST; $ ERROR_MSG = ""; $ Str = '; $ count = count ($ this-> array_valid); for ($ i = 0; $ i) <$ count; $ i ) {

    $ item = $ this-> array_valid [$ i];

    Switch ($ Item ['Valid']) {CASE 'NUMERIC': IF (! is_Numeric ($ this-> POST [$ Item ['Field'])) $ Error_Msg. = "

  • $ item [Chinese] Not numbers; breaf; default: IF (Empty ($ this-> post [$ item ['Field'])) $ error_msg. = "
  • $ item [Chinese] cannot be empty;" Break;}} IF (! EMPTY ($ error_msg)) $ error_msg. "
    Please check it carefully."; Return $ error_msg;}

    Function get_where ($ sql = ') {global $ _POST; $ where =' '; foreach ($ this-> array_query as $ val) {if (! Empty ($ _ post [$ val)) $ where. = " And ".substr ($ VAL, 2)." Like '% $ _ post [$ val]%' ";} $ where. =" and $ this-> Table.Indeleted! = 1 ";

    IF (EREGI ('WHERE', $ SQL) RETURN $ WHERE;

    Return "where" .substr ($ Where, 4);}

    Function get_order_by () {return '';}

    Function get_add_sql () {global $ _POST, $ _ session; $ FIELDS = IMPLODE (",", $ this-> array_add); $ values ​​= ""; $ operator = $ _ session ['session'] ['user'] [ 'id']; foreach ($ this-> array_add as $ val) {$ val = trim ($ val); $ values. = "'$ _ post [$ val]',";

    $ VALUES = SUBSTR ($ VALUES, 0, Strlen ($ VALUES) -1);

    $ SQL = "INSERT INTO $ THIS-> Table (Operator, $ FIELDS) VALUES ($ Operator, $ VALUES"; RETURN $ SQL;}

    Function get_update_sql () {global $ _POST; $ this-> array_update = Empty ($ this-> array_update)? $ this-> array_add: $ this-> array_update; $ sql = "Update $ this-> Table Set";

    Foreach ($ THIS-> Array_update as $ VAL) {$ VAL = Trim ($ VAL); $ SQL. = "$ VAL = '$ _ POST [$ VAL]',";} $ SQL = Substr ($ SQL, 0 Strlen ($ SQL) -1); $ PK = $ this-> pk_name; $ sql. = "Where $ pk = '$ _ post [$ pk]'"; Return $ SQL;} Function Set_select_sql ($ VAL) { $ this-> select_sql = $ val;} function set_array_add ($ val) {$ this-> array_add = $ val;} function set_array_update ($ val) {$ this-> array_update = $ val;} function set_array_query ($ val) {$ this-> Array_Query = $ VAL;} Function Set_Array_Valid ($ VAL) {$ this-> array_valid = $ val;}

    Function set_oder_by ($ VAL) {$ this-> array_oder_by = $ val;} Function set_caption ($ val) {$ this-> caption = value;} function set_pk_val ($ val) {if (! Empty ($ val)) $ this-> pk_val = $ val;} function set_pk_name ($ VAL) {if (! EMPTY ($ VAL)) $ this-> pk_name = $ val;}

    Function set_html_query ($ val) {Global $ me; $ this-> html_query = $ val; $ this-> html_query. = " < INPUT TYPE = Button value = 'reset' οnclick = / "location = '$ me' /">} Function set_html_cmd ($ val) {$ this-> html_cmd = $ val;} function set_array_tpl ($ val) { $ this-> array_tpl = $ val;}

    Function get_query_state () {global $ _POST; $ js_state = "