/** * Return select list of groups * * @param string $selected Id group preselected * @param string $htmlname Field name in form * @param int $show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue * @param string $exclude Array list of groups id to exclude * @param int $disabled If select list must be disabled * @param string $include Array list of groups id to include * @param int $enableonly Array list of groups id to be enabled. All other must be disabled * @return void */ function select_dolgroups($selected = '', $htmlname = 'groupid', $show_empty = 0, $exclude = '', $disabled = 0, $include = '', $enableonly = '') { global $conf, $user, $langs; $out = ''; $object = new UserGroup($db); $result = $object->getView("list"); if (count($result->rows) && is_array($exclude)) { foreach ($result->rows as $key => $obj) { if (in_array($obj->value->name, $exclude, true)) { unset($result->rows[$key]); } } } $i = 0; if (count($result->rows)) { $out .= '<select class="flat" name="' . $htmlname . '"' . ($disabled ? ' disabled="disabled"' : '') . '>'; if ($show_empty) { $out .= '<option value="-1"' . ($selected == -1 ? ' selected="selected"' : '') . '> </option>' . "\n"; } foreach ($result->rows as $obj) { $disableline = 0; if (is_array($enableonly) && count($enableonly) && !in_array($obj->value->name, $enableonly)) { $disableline = 1; } $out .= '<option value="' . $obj->value->name . '"'; if ($disableline) { $out .= ' disabled="disabled"'; } if (is_object($selected) && $selected->id == $obj->value->name || !is_object($selected) && $selected == $obj->value->name) { $out .= ' selected="selected"'; } $out .= '>'; $out .= $obj->value->name; $out .= '</option>'; $i++; } } else { $out .= '<select class="flat" name="' . $htmlname . '" disabled="disabled">'; $out .= '<option value="">' . $langs->trans("None") . '</option>'; } $out .= '</select>'; return $out; }
$object = new UserGroup($db); /* * View */ if ($_GET['json'] == "list") { $output = array( "sEcho" => intval($_GET['sEcho']), "iTotalRecords" => 0, "iTotalDisplayRecords" => 0, "aaData" => array() ); try { $result = $object->getView("list"); } catch (Exception $exc) { print $exc->getMessage(); } //print_r ($result); $iTotal = count($result->rows); $output["iTotalRecords"] = $iTotal; $output["iTotalDisplayRecords"] = $iTotal; foreach ($result->rows as $aRow) { $output["aaData"][] = $aRow->value; } header('Content-type: application/json');