/**
  * Creates a new group
  * @param $groupname string Specifies the groupname
  * @param $defaultgroup integer Specfies, if group is default group (optional)
  */
 public function create($groupname, $defaultgroup = 0)
 {
     global $client, $lang;
     $client = Contenido_Security::toInteger($client);
     $lang = Contenido_Security::toInteger($lang);
     $group = new RecipientGroup();
     #$_arrInFilters = array('urlencode', 'htmlspecialchars', 'addslashes');
     $mangledGroupName = $group->_inFilter($groupname);
     $this->setWhere("idclient", $client);
     $this->setWhere("idlang", $lang);
     $this->setWhere("groupname", $mangledGroupName);
     $this->query();
     if ($obj = $this->next()) {
         $groupname = $groupname . md5(rand());
     }
     $item = parent::create();
     $item->set("idclient", $client);
     $item->set("idlang", $lang);
     $item->set("groupname", $groupname);
     $item->set("defaultgroup", $defaultgroup);
     $item->store();
     return $item;
 }
$aFields["name"] = array("field" => "name", "caption" => i18n("Name", $plugin_name), "type" => "base,sort,search");
$aFields["email"] = array("field" => "email", "caption" => i18n("E-Mail", $plugin_name), "type" => "base,sort,search");
$aFields["confirmed"] = array("field" => "confirmed", "caption" => i18n("Confirmed", $plugin_name), "type" => "base");
$aFields["deactivated"] = array("field" => "deactivated", "caption" => i18n("Deactivated", $plugin_name), "type" => "base");
if ($action == "recipientgroup_create" && $perm->have_perm_area_action($area, $action)) {
    $oRGroup = $oRGroups->create(" " . i18n("-- new group --", $plugin_name));
    $_REQUEST["idrecipientgroup"] = $oRGroup->get("idnewsgroup");
    $oPage->setReload();
    $sRefreshLeftTopScript = '<script type="text/javascript">top.content.left.left_top.refreshGroupOption(\'' . $_REQUEST["idrecipientgroup"] . '\', \'add\')</script>';
    $oPage->addScript('refreshlefttop', $sRefreshLeftTopScript);
} elseif ($action == "recipientgroup_delete" && $perm->have_perm_area_action($area, $action)) {
    $oRGroups->delete($_REQUEST["idrecipientgroup"]);
    $sRefreshLeftTopScript = '<script type="text/javascript">top.content.left.left_top.refreshGroupOption(\'' . $_REQUEST["idrecipientgroup"] . '\', \'remove\')</script>';
    $oPage->addScript('refreshlefttop', $sRefreshLeftTopScript);
    $_REQUEST["idrecipientgroup"] = 0;
    $oRGroup = new RecipientGroup();
    $oPage->setReload();
} else {
    $oRGroup->loadByPrimaryKey($_REQUEST["idrecipientgroup"]);
}
if ($oRGroup->virgin == false && $oRGroup->get("idclient") == $client && $oRGroup->get("idlang") == $lang) {
    if ($action == "recipientgroup_save_group" && $perm->have_perm_area_action($area, $action)) {
        // Saving changes
        $aMessages = array();
        $bReload = false;
        $sGroupName = stripslashes($_REQUEST["groupname"]);
        if ($oRGroup->get("groupname") != $sGroupName) {
            $oRGroups->resetQuery();
            $oRGroups->setWhere("groupname", $sGroupName);
            $oRGroups->setWhere("idclient", $client);
            $oRGroups->setWhere("idlang", $lang);