[sork] new features @ vacation

horde at humbapa.ch horde at humbapa.ch
Fri Dec 19 02:53:28 PST 2003


Zitat von Jan Schneider <jan at horde.org>:

> Zitat von horde at humbapa.ch:
>
> > hi all
> >
> > I made some changes to the vacation-module:
> > - hordeauth can also be set to "full" (the username will be used
> >   unmodified, see gollem/config/backends.php)
> > - subject and message are now 2 formfields
> > - sql-driver: create new entry in table "vacation" if no record was
> >   found
> >
> > todo:
> > - update the translation-part for the subject-formfield
> > - update the forwards-, ldap- and qmail-drivers if needed (the subject is
> >   still part of the message, I did not change the parameterlist of any
> > function)
> >
> > is it possible to submit this changes to the horde-cvs-repository?
> > if so, what is the best way to do this?
>
> Send a unified diff to the dev@ mailing list or here.

3 files (vacation/main.php, vacation/templates/main/main.inc,
vacation/lib/Driver/sql.php): unified diff to cvs (2003-12-19)


diff -u vacation/main.php vacation/main.php.new
--- vacation/main.php   2003-12-19 11:12:42.000000000 +0100
+++ vacation/main.php.new       2003-12-19 10:00:32.000000000 +0100
@@ -17,11 +17,15 @@

 // Get the current login username and realm.
 $split = explode('@', Auth::getAuth());
-$user = @$split[0];
 $realm = @$split[1];
 if (empty($realm)) {
     $realm = 'default';
 }
+if ($driver->getParam('hordeauth', $realm)==="full") {
+    $user = Auth::getAuth();
+} else {
+    $user = @$split[0];
+}

 $submit = Util::getFormData('submit', false);

@@ -52,7 +56,9 @@
     switch ($vacationmode) {
     case 'set':
         $alias = Util::getFormData('alias', '');
+       $vacationsubject = trim(Util::getFormData('subject', false));
         $vacationmsg = Util::getFormData('mess', false);
+        $vacationmsg = "Subject: $vacationsubject\n".$vacationmsg;
         if (!$vacationmsg) {
             $notification->push(_("You must give a vacation message."),
                                 'horde.warning');
@@ -96,9 +102,21 @@
 $pass = Auth::getCredential('password');
 if ($driver->isEnabled($user, $realm, $pass)) {
     $curmessage = $driver->currentMessage($user, $realm, $pass);
+    if (preg_match("/^Subject: ([^\n]+)\n(.+)$/s", $curmessage, $m='')) {
+       $cursubject = $m[1];
+       $curmessage = $m[2];
+    } else {
+       $cursubject = '';
+    }
     $notification->push(_("Your vacation notice is currently
enabled."), 'horde.success');
 } else {
     $curmessage = $conf['vacation']['default'];
+    if (preg_match("/^Subject: ([^\n]+)\n(.+)$/s", $curmessage, $m='')) {
+        $cursubject = $m[1];
+        $curmessage = $m[2];
+    } else {
+        $cursubject = '';
+    }
 }

 $title = _("Change Vacation Notices");


diff -u vacation/templates/main/main.inc vacation/templates/main/main.inc.new
--- vacation/templates/main/main.inc    2003-12-19 11:12:43.000000000 +0100
+++ vacation/templates/main/main.inc.new        2003-12-16 12:28:43.000000000
+0100
@@ -47,6 +47,13 @@

 <div>
 <br />
+<?php echo _("Subject:") ?>
+<br />
+<input name="subject" type="text" size="70" value="<?php echo htmlspecialchars
($cursubject) ?>">
+</div>
+
+<div>
+<br />
 <?php echo _("Message:") ?>
 <br />
 <textarea name="mess" rows="8" cols="70"><?php echo htmlspecialchars
($curmessage) ?></textarea>


diff -u vacation/lib/Driver/sql.php vacation/lib/Driver/sql.php.new
--- vacation/lib/Driver/sql.php 2003-12-19 11:12:42.000000000 +0100
+++ vacation/lib/Driver/sql.php.new     2003-12-19 09:59:54.000000000 +0100
@@ -40,19 +40,15 @@
         /* _connect() will die with Horde::fatal() upon failure. */
         $this->_connect();

-        // Split message into parts to get subject.
-        $myarray = explode("\n", $message);
-
         /* Determine if $message contains Subject: and if it does
          * split it. */
-        if (strstr($myarray[0], 'Subject:')) {
-            $mysubject = $myarray[0];
-            $myarray[0] = '';
-            $mymessage = implode('', $myarray);
-        } else {
-            $mysubject = '';
+       if (preg_match("/^Subject: ([^\n]+)\n(.+)$/s", $message, $m='')) {
+           $mysubject = $m[1];
+           $mymessage = $m[2];
+       } else {
+           $mysubject = '';
             $mymessage = $message;
-        }
+       }

         /* Build the SQL query. */
         $query = 'UPDATE ' . $this->params['table'];
@@ -141,10 +137,10 @@
         $this->_connect();

         /* Build the SQL query. */
-        $query = 'SELECT ' . $this->params['vacation'] . ' . AS vacation, ' .
$this->params['message'] . ' AS message';
+        $query = 'SELECT ' . $this->params['vacation'] . ' AS vacation, ' .
$this->params['message'] . ' AS message, ' . $this->params['subject'] . ' AS
subject ';
         $query .= ' FROM ' . $this->params['table'];
         $query .= ' WHERE ' . $this->params['user_col'] . ' = ' . $this->_db-
>quote($user);
-        $query .= ' AND password = ' . $this->_db->quote(md5($password));
+        $query .= ' AND ' . $this->params['pass_col'] . ' = ' . $this->_db-
>quote(md5($password));

         /* Execute the query. */
         $result = $this->_db->query($query);
@@ -154,8 +150,14 @@

             if (is_array($row)) {
                 $this->_disconnect();
+               $row["message"] = "Subject: $row[subject]\n".$row["message"];
                 return $row;
             } else {
+               $result->free();
+               $query = 'INSERT INTO ' . $this->params['table'];
+                $query .= ' ( ' . $this->params['user_col'] . ' ,  ' . $this-
>params['pass_col'] . ' ) ';
+                $query .= ' VALUES ( ' . $this->_db->quote($user) . ' ,  ' .
$this->_db->quote(md5($password)) . ' ) ';
+                $result = $this->_db->query($query);
                 $this->_disconnect();
-                $result->free();
                 return false;
             }
         }


g. martin luethi


More information about the sork mailing list