/** * Function to get customfield entries * @param string $module - Module name * return array $cflist - customfield entries */ function getCFListEntries($fields, $multifieldid, $tab_mod_strings) { global $adb; global $theme; global $mod_strings; global $app_strings; $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; //$dbQuery = "select fieldid,columnname,fieldlabel,uitype,displaytype from ec_field where tabid=".$tabid." and generatedtype=2 order by sequence"; $count = 1; $cflist = array(); for ($i = 0; $i < count($fields); $i++) { $eachfield = $fields[$i]; $cf_element = array(); $cf_element['no'] = $count; $multifieldlabel = $eachfield["fieldlabel"]; if (isset($_REQUEST["multifieldlabel{$count}"]) && $_REQUEST["multifieldlabel{$count}"] != '') { $multifieldlabel = $_REQUEST["multifieldlabel{$count}"]; } //Add for use mod_string field label if (!empty($multifieldlabel) && !empty($tab_mod_strings[$multifieldlabel])) { $multifieldlabel = $tab_mod_strings[$multifieldlabel]; } $cf_element['label'] = "<input name='multifieldlabel{$count}' id='multifieldlabel{$count}' type='text' value='{$multifieldlabel}'>"; $optionsval = getMultiFieldOptions($multifieldid, $count, 0, 1); $fld_type_name = "\n <select id='multifieldvalue{$count}' name='multifieldvalue{$count}' onchange='updateChildOptions(\"{$multifieldid}\",\"{$count}\");'>{$optionsval}</select>\n <img src='{$image_path}editfield.gif' border='0' style='cursor:pointer;' onClick='getCreateCustomFieldForm(\"{$multifieldid}\",\"{$count}\",\"\",this);' alt='批量增加' title='批量增加'/> \n <img src='{$image_path}RolesEdit.gif' border='0' style='cursor:pointer;' onClick='getEditCustomFieldForm(\"{$multifieldid}\",\"{$count}\",\"\",this);' alt='修改下拉框选项' title='修改下拉框选项'/> \n "; $cf_element['type'] = $fld_type_name; $typeofdata = $eachfield["typeofdata"]; if (strpos($typeofdata, "~O") !== false) { $checkedstr = ""; } else { $checkedstr = "checked"; } $cf_element['tool'] = "<input type='checkbox' name='multifieldcheck{$count}' {$checkedstr} value='1'>"; $cflist[] = $cf_element; $count++; } return $cflist; }
<?php require_once 'include/database/PearDatabase.php'; require_once 'include/CustomFieldUtil.php'; require_once 'include/utils/MultiFieldUtils.php'; $multifieldid = $_REQUEST["multifieldid"]; $level = $_REQUEST["level"]; $parentfieldid = $_REQUEST["parentfieldid"]; global $adb; $options = getMultiFieldOptions($multifieldid, $level + 1, $parentfieldid, 2); if (empty($options)) { die; } $resstr = "<script>"; foreach ($options as $eachopt) { $fieldname = $eachopt[0]; $optvalue = $eachopt[1]; //$resstr.="alert('$optvalue');"; $resstr .= "\$('{$fieldname}').update('{$optvalue}');"; } $resstr .= "</script>"; echo $resstr;
<?php require_once 'include/database/PearDatabase.php'; require_once 'include/CustomFieldUtil.php'; require_once 'include/utils/MultiFieldUtils.php'; $multifieldid = $_REQUEST["multifieldid"]; $level = $_REQUEST["level"]; $parentfieldid = $_REQUEST["parentfieldid"]; global $adb; $optionsval = getMultiFieldOptions($multifieldid, $level + 1, $parentfieldid, 1); echo $optionsval;
function getMultiFieldOptions($multifieldid, $level, $parentid, $type) { global $adb; $optionsstr = ""; if ($type == 1) { $optionsstr = "<option value=''>--未选择--</option>"; $multifieldinfo = getMultiFieldInfo($multifieldid, false); $tablename = $multifieldinfo["tablename"]; if ($level == 1) { $sql = "select * from {$tablename} where thelevel=1 order by sortorderid asc"; $result = $adb->getList($sql); foreach ($result as $row) { $optval = $row["actualfieldid"]; $opttxt = $row["actualfieldname"]; $optionsstr .= "<option value='{$optval}'>{$opttxt}</option>"; } } else { $sql = "select * from {$tablename} where thelevel={$level} and parentfieldid='{$parentid}' order by sortorderid asc"; $result = $adb->getList($sql); foreach ($result as $row) { $optval = $row["actualfieldid"]; $opttxt = $row["actualfieldname"]; $optionsstr .= "<option value='{$optval}'>{$opttxt}</option>"; } } } elseif ($type == 2) { $optionsstr = array(); $strinopts = ""; $multifieldinfo = getMultiFieldInfo($multifieldid); $tablename = $multifieldinfo["tablename"]; $totallevel = $multifieldinfo["totallevel"]; if ($level > $totallevel) { return null; } if ($level == 1) { $sql = "select * from {$tablename} where thelevel=1 order by sortorderid asc"; $result = $adb->getList($sql); $firstcall = true; $firstoptid = null; foreach ($result as $row) { $optval = $row["actualfieldid"]; $opttxt = $row["actualfieldname"]; $strinopts .= '<option relvalue="' . $optval . '" value="' . $opttxt . '">' . $opttxt . '</option>'; if ($firstcall) { $firstoptid = $optval; } $firstcall = false; } $optionsstr[] = array($multifieldinfo["fields"][$level - 1]["fieldname"], $strinopts); if (!empty($firstoptid) && $level < $totallevel) { $childopts = getMultiFieldOptions($multifieldid, $level + 1, $firstoptid, $type); $optionsstr = array_merge($optionsstr, $childopts); } } else { $sql = "select * from {$tablename} where thelevel={$level} and parentfieldid='{$parentid}' order by sortorderid asc"; $result = $adb->getList($sql); $firstcall = true; $firstoptid = null; foreach ($result as $row) { $optval = $row["actualfieldid"]; $opttxt = $row["actualfieldname"]; $strinopts .= '<option relvalue="' . $optval . '" value="' . $opttxt . '">' . $opttxt . '</option>'; if ($firstcall) { $firstoptid = $optval; } $firstcall = false; } $optionsstr[] = array($multifieldinfo["fields"][$level - 1]["fieldname"], $strinopts); if (!empty($firstoptid) && $level < $totallevel) { $childopts = getMultiFieldOptions($multifieldid, $level + 1, $firstoptid, $type); $optionsstr = array_merge($optionsstr, $childopts); } elseif (empty($firstoptid) && $level < $totallevel) { $childopts = array(); $childopts[] = array($multifieldinfo["fields"][$level]["fieldname"], ""); $optionsstr = array_merge($optionsstr, $childopts); } } } return $optionsstr; }