# ----------------------------------------------------------------
# Plugin for PreCreateForm()
sub PreCreateForm()
{
   my $cSessionId;

   if($oSessionGL->getState("IsAdmin"))
   {
      $cSessionId = '%';
      &MySetVal("State Work", "BtnUpd", i18n("Update (Admin)"));
   }
   else
   {
      $cSessionId = &GetAttr("SessionId");

      &MySetVal("Layout Field session_id", "NoUndef", "1");
   }

   $plSelect = $oDbSessionGL->SqlSelect
       ("SELECT
             session_id, key_value
         FROM
             wwwdb_state
         WHERE
             key_name   =    'login'   AND
             session_id LIKE ?
         ORDER BY
             key_value",
        $cSessionId);

   &MySetVal("Layout Field session_id", "Values",
             join "\n", map
             {
                my $cRest = $_->[1];
                $cRest =~ s/(.*),.*$/$1/;

                $_ = $_->[0] . "\\," . $cRest;
             } @$plSelect);

   $oDbSessionGL->setDebugLvl(5);
   $plSelect = $oDbSessionGL->SqlSelect
       ("SELECT DISTINCT
             key_value, label
         FROM
             wwwdb_lookup
         WHERE
             lang      = ?         AND
             (key_name = ?   OR
              key_name = 'UserAtt')
         ORDER BY
              key_value",
        &GetAttr("Lang"),
        ($oSessionGL->getState("IsAdmin")?
         "AdmAtt":
         "UserAtt"));

   &MySetVal("Layout Field key_name", "Values",
             join "\n", map
             {
                $_->[0] . "\\," . $_->[1] . " (" . $_->[0] . ")";
             } @$plSelect);

   return;
}


sub Check_wwwdb_state ()
{
   # Set time-stamp
   &SetField("last_change",
             $oDbSessionGL->DateToDb(scalar(localtime())));

}



sub PreBtnNew()
{
   # Delete th current record, because we want to insert it now again
   $oDbSessionGL->SqlDo
       ("DELETE FROM wwwdb_state
         WHERE
             session_id  = ? AND
             key_name    = ?",
        &GetField("session_id"),
        &GetField("key_name"));

}


1;
