1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 12:20:44 +02:00

Use Ajax API to change dropdowns.

This commit is contained in:
Lóna Lore
2016-03-25 11:02:15 +01:00
parent 91e504c220
commit 2eb7924098

View File

@@ -9,31 +9,151 @@
*/
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 = "<table style='width:70%;margin-left:0;'><tr><td>";
$text .= EXTLAN_62 . "</td><td style='70%'>\n";
$text .= "<select name='table_db' style='width:99%' class='tbox e-ajax' data-src='{$ajaxGetTableSrc}'>";
$text .= "<option value='' class='caption'>" . EXTLAN_61 . "</option>";
$result = e107::getDb()->tables();
foreach($result as $row2)
{
$fld = $row2;
$selected = (varset($_POST['table_db'], '') == $fld || $curVals[0] == $fld) ? " selected='selected'" : "";
$text .= "<option value=\"" . $fld . "\" $selected>" . $fld . "</option>\n";
}
$text .= "</select></td></tr>";
if($_POST['table_db'] || $curVals[0])
{
// Field ID.
$text .= "<tr><td>" . EXTLAN_63 . "</td><td>";
$text .= "<select style='width:99%' class='tbox e-select' name='field_id'>";
$text .= "<option value='' class='caption'>" . EXTLAN_61 . "</option>";
$table_list = ($_POST['table_db']) ? $_POST['table_db'] : $curVals[0];
if($sql->gen("DESCRIBE " . MPREFIX . "{$table_list}"))
{
while($row3 = $sql->fetch())
{
$field_name = $row3['Field'];
$selected = ($curVals[1] == $field_name) ? " selected='selected' " : "";
$text .= "<option value=\"$field_name\" $selected>" . $field_name . "</option>";
}
}
$text .= "</select></td></tr><tr><td>";
// Display Value.
$text .= EXTLAN_64 . "</td><td>";
$text .= "<select style='width:99%' class='tbox e-select' name='field_value'>";
$text .= "<option value='' class='caption'>" . EXTLAN_61 . "</option>";
$table_list = ($_POST['table_db']) ? $_POST['table_db'] : $curVals[0];
if($sql->gen("DESCRIBE " . MPREFIX . "{$table_list}"))
{
while($row3 = $sql->fetch())
{
$field_name = $row3['Field'];
$selected = ($curVals[2] == $field_name) ? " selected='selected' " : "";
$text .= "<option value=\"$field_name\" $selected>" . $field_name . "</option>";
}
}
$text .= "</select></td></tr><tr><td>";
// Order.
$text .= LAN_ORDER . "</td><td>";
$text .= "<select style='width:99%' class='tbox e-select' name='field_order'>";
$text .= "<option value='' class='caption'>" . EXTLAN_61 . "</option>";
$table_list = ($_POST['table_db']) ? $_POST['table_db'] : $curVals[0];
if($sql->gen("DESCRIBE " . MPREFIX . "{$table_list}"))
{
while($row3 = $sql->fetch())
{
$field_name = $row3['Field'];
$selected = ($curVals[3] == $field_name) ? " selected='selected' " : "";
$text .= "<option value=\"$field_name\" $selected>" . $field_name . "</option>";
}
}
$text .= "</select></td></tr>";
}
$text .= "</table>";
$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;
}
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
function js()
{
function js()
{
//FIXME
include_once(e_LANGUAGEDIR.e_LANGUAGE."/lan_user_extended.php");
include_once(e_LANGUAGEDIR . e_LANGUAGE . "/lan_user_extended.php");
$text = "
@@ -44,15 +164,15 @@ if (isset($_POST['cancel_cat']))
";
for($i=1; $i<=9; $i++)
for($i = 1; $i <= 9; $i++)
{
$type_const = "UE_LAN_{$i}";
$help_const = "\"".str_replace("/","\/","EXTLAN_HELP_{$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) . "\";
}";
}
@@ -69,15 +189,12 @@ if (isset($_POST['cancel_cat']))
}
// ]]>
}
";
";
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 .= "<div id='db_mode' style='display:$db_hide'>\n";
$text .= "<table style='width:70%;margin-left:0px'><tr><td>";
$text .= EXTLAN_62."</td><td style='70%'><select style='width:99%' class='tbox e-select' name='table_db' onchange=\"this.form.submit()\" >
<option value='' class='caption'>".EXTLAN_61."</option>\n";
// Ajax URL for "Table" dropdown.
$ajaxGetTableSrc = e_SELF . '?mode=ajax&action=changeTable';
$text .= "<div id='db_mode' style='display:{$db_hide}'>";
$text .= "<table style='width:70%;margin-left:0;'><tr><td>";
$text .= EXTLAN_62 . "</td><td style='70%'>";
$text .= "<select name='table_db' style='width:99%' class='tbox e-ajax' data-src='{$ajaxGetTableSrc}'>";
$text .= "<option value='' class='caption'>" . EXTLAN_61 . "</option>";
$result = e107::getDb()->tables();
@@ -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 .= "<div id='db_mode' style='display:$db_hide'>\n";
$text .= "<table style='width:70%;margin-left:0px'><tr><td>";
$text .= EXTLAN_62."</td><td style='70%'><select style='width:99%' class='tbox e-select' name='table_db' onchange=\"this.form.submit()\" >
<option value='' class='caption'>".EXTLAN_61."</option>\n";
// Ajax URL for "Table" dropdown.
$ajaxGetTableSrc = e_SELF . '?mode=ajax&action=changeTable';
$text .= "<div id='db_mode' style='display:{$db_hide}'>";
$text .= "<table style='width:70%;margin-left:0;'><tr><td>";
$text .= EXTLAN_62 . "</td><td style='70%'>";
$text .= "<select name='table_db' style='width:99%' class='tbox e-ajax' data-src='{$ajaxGetTableSrc}'>";
$text .= "<option value='' class='caption'>" . EXTLAN_61 . "</option>";
$result = e107::getDb()->tables();