From 2eb7924098dca4812307784f5dcce46692bf2b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3na=20Lore?= Date: Fri, 25 Mar 2016 11:02:15 +0100 Subject: [PATCH] Use Ajax API to change dropdowns. --- e107_admin/users_extended.php | 241 ++++++++++++++++++++++++++-------- 1 file changed, 183 insertions(+), 58 deletions(-) diff --git a/e107_admin/users_extended.php b/e107_admin/users_extended.php index c0cb55bcb..19caea648 100755 --- a/e107_admin/users_extended.php +++ b/e107_admin/users_extended.php @@ -9,32 +9,152 @@ */ require_once('../class2.php'); + if (!getperms('4')) { e107::redirect('admin'); exit; } + + +include_lan(e_LANGUAGEDIR . e_LANGUAGE . '/admin/lan_' . e_PAGE); + +if(varset($_GET['mode']) == "ajax") +{ + // Construct action string. + $action = varset($_GET['mode']) . '/' . varset($_GET['action']); + + switch($action) + { + case 'ajax/changeTable': + $tableName = varset($_POST['table_db'], null); + + if($tableName) + { + $sql = e107::getDb(); + + $sub_action = ''; + + if(e_QUERY) + { + $tmp = explode(".", e_QUERY); + $action = $tmp[0]; + $sub_action = varset($tmp[1], ''); + $id = varset($tmp[2], 0); + unset($tmp); + } + + if($sql->select('user_extended_struct', '*', "user_extended_struct_id = '{$sub_action}'")) + { + $current = $sql->fetch(); + } + else + { + $current = 'new'; + } + + $currVal = $current['user_extended_struct_values']; + $curVals = explode(",", varset($currVal)); + + // Ajax URL for "Table" dropdown. + $ajaxGetTableSrc = e_SELF . '?mode=ajax&action=changeTable'; + + $text = ""; + + if($_POST['table_db'] || $curVals[0]) + { + // Field ID. + $text .= ""; + } + + $text .= "
"; + $text .= EXTLAN_62 . "\n"; + $text .= "
" . EXTLAN_63 . ""; + $text .= "
"; + + // Display Value. + $text .= EXTLAN_64 . ""; + $text .= "
"; + + // Order. + $text .= LAN_ORDER . ""; + $text .= "
"; + + + $ajax = e107::getAjax(); + $commands = array(); + $commands[] = $ajax->commandInsert('#db_mode', 'html', $text); + $ajax->response($commands); + exit; + } + + break; + } +} + if (isset($_POST['cancel'])) { header('location:'.e_SELF); exit; } + if (isset($_POST['cancel_cat'])) { header("location:".e_SELF."?cat"); exit; } +function js() +{ - include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE); - - - function js() - { - - //FIXME - include_once(e_LANGUAGEDIR.e_LANGUAGE."/lan_user_extended.php"); - $text = " + //FIXME + include_once(e_LANGUAGEDIR . e_LANGUAGE . "/lan_user_extended.php"); + $text = " function changeHelp(type) { @@ -44,19 +164,19 @@ if (isset($_POST['cancel_cat'])) "; - for($i=1; $i<=9; $i++) - { - $type_const = "UE_LAN_{$i}"; - $help_const = "\"".str_replace("/","\/","EXTLAN_HELP_{$i}")."\""; - $text .= " + for($i = 1; $i <= 9; $i++) + { + $type_const = "UE_LAN_{$i}"; + $help_const = "\"" . str_replace("/", "\/", "EXTLAN_HELP_{$i}") . "\""; + $text .= " if(type == \"{$i}\") { - xtype=\"".defset($type_const)."\"; - what=\"".defset($help_const)."\"; + xtype=\"" . defset($type_const) . "\"; + what=\"" . defset($help_const) . "\"; }"; - } + } - $text .= " + $text .= " // document.getElementById('ue_type').innerHTML=''+xtype+''; // document.getElementById('ue_help').innerHTML=''+what+''; @@ -69,15 +189,12 @@ if (isset($_POST['cancel_cat'])) } // ]]> } + "; + return $text; +} -"; - - return $text; - } - - - e107::js('inline', js()); +e107::js('inline', js()); @@ -630,12 +747,16 @@ if(E107_DEBUG_LEVEL > 0 ) - $db_hide = ($current['user_extended_struct_type'] == 4) ? "visible" : "none"; + $db_hide = ($current['user_extended_struct_type'] == 4) ? "block" : "none"; - $text .= "
\n"; - $text .= "
"; - $text .= EXTLAN_62." @@ -1351,13 +1472,13 @@ class users_ext function show_extended($current = '') // Show Add fields List. { global $ue, $curtype,$mySQLdefaultdb, $action, $sub_action; - + $sql = e107::getDb(); $frm = e107::getForm(); $ns = e107::getRender(); $tp = e107::getParser(); - - + + if($current == 'new') { $mode = 'new'; @@ -1469,12 +1590,16 @@ class users_ext - $db_hide = ($current['user_extended_struct_type'] == 4) ? "visible" : "none"; + $db_hide = ($current['user_extended_struct_type'] == 4) ? "block" : "none"; - $text .= "
\n"; - $text .= "
"; + $text .= EXTLAN_62 . ""; + $text .= " - + ".ADMIN_EDIT_ICON." ".$frm->submit_image('eudel['.$name.']',$id, 'delete', LAN_DELETE.' [ ID: '.$id.' ]', array('class' => 'action delete btn btn-default'.$delcls)); - + // ." $text .= "
"; - $text .= EXTLAN_62." - + - +
"; + $text .= EXTLAN_62 . ""; + $text .= "
".EXTLAN_63."
".EXTLAN_31.": @@ -1811,7 +1936,7 @@ class users_ext
".EXTLAN_32."
".EXTLAN_5." @@ -1861,7 +1986,7 @@ class users_ext } $var['main']['text'] = EXTLAN_34; $var['main']['link'] = e_SELF; - + $var['pre']['text'] = EXTLAN_45; $var['pre']['link'] = e_SELF."?pre"; @@ -1871,7 +1996,7 @@ class users_ext $var['cat']['text'] = EXTLAN_35; $var['cat']['link'] = e_SELF."?cat"; - + show_admin_menu(EXTLAN_9, $action, $var); } @@ -1905,7 +2030,7 @@ class users_ext $ns = e107::getRender(); $tp = e107::getParser(); $sql = e107::getDb(); - + // Get list of current extended fields $curList = $ue->user_extended_get_fieldlist(); @@ -1993,7 +2118,7 @@ class users_ext $val = (!$active) ? EXTLAN_59 : EXTLAN_60; $type = (!$active) ? 'activate' : 'deactivate'; $style = (!$active) ? 'other' : 'delete'; - + $txt .= " "; $txt .= $frm->admin_button($type."[".$var['user_extended_struct_name']."]", $val, $style ); @@ -2102,7 +2227,7 @@ class users_ext // $user->show_options($action); $ac = e_QUERY; $action = vartrue($ac,'main'); - + users_ext::show_options($action); if($action == 'editext' || $action == 'continue') {