\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
\part{User Contributed Preferences}
\textbf{This information is valid for Horde 3 only. See <a href="https://wiki.horde.org/CustomizingPreferences">CustomizingPreferences</a> for Horde 4 and later.}

Perhaps the greatest feature of Horde and all of it's modules is the flexibility to adapt to a myriad of different uses and I would expect that eventually, a more integrated system of managing 'defaults' will become part of the code but at this moment in time, the only way to effect settings system wide is to edit the various prefs.php file inside each module.

I thought it would be interesting to share what people do to the various preferences and it would make a handy reference to point people towards if they ask on the various lists.

The methodology of capturing some of these 'strings' of values is that I usually create the setup exactly how I want it for my  'Administrator' user and then copy the values out of the SQL database and paste them into the appropriate spot in the prefs.php file.


\noindent\rule{\textwidth}{1pt}
\subsection{Default Identity}
\subsubsection{LDAP}
I have created some hooks for capturing the users Identity and Email address to automatically set their Default identity the  first time that they log in. These hooks assume LDAP backend and should be instructive for someone wanting to create their own custom hooks...this wasn't easy to figure out.

The first modification I did to hooks.php was to add the following (don't forget to add the \texttt{'hook' => 'true',} to \texttt{\$prefs['from\_addr']}).

<pre><code class="language-php">
if (!function\_exists('\_prefs\_hook\_from\_addr')) \{
    function \_prefs\_hook\_from\_addr(\$user = null)
    \{
        \$domain\_name = 'azapple.com';
        \$ldapServer = 'localhost';
        \$ldapPort = '389';
        \$searchBase = 'ou=People,dc=azapple,dc=com';
        \$ds = @ldap\_connect(\$ldapServer, \$ldapPort);

        if (is\_null(\$user)) \{
            \$user = Auth::getAuth();
        \}

        \$uid = Auth::getBareAuth();
        \$binddn = 'uid=' . \$uid . ',' . \$searchBase;
        \$bindpw = Auth::getCredential('password');

        if (@ldap\_bind(\$ds, \$binddn, \$bindpw)) \{
            \$searchResult = @ldap\_search(\$ds, \$searchBase, 'uid=' . \$uid);
        \}

        \$information = @ldap\_get\_entries(\$ds, \$searchResult);

        // derive the email address if possible
        if (\$information['count'] > 0) \{
            if (\$information[0]['mail'][0] != '') \{
                \$emailname = \$information[0]['mail'][0];
            \} else \{
                \$emailname = \$information[0]['uid'][0] . '@' . \$domain\_name;
            \}
        \}

        ldap\_close(\$ds);

        return \$emailname;
    \}
\}
</code></pre>
\paragraph{Fullname \#1}
The second modification I did to hooks.php was to add the following (don't forget to add the \texttt{'hook' => 'true',} to \texttt{\$prefs['fullname']}).

<pre><code class="language-php">
if (!function\_exists('\_prefs\_hook\_fullname')) \{
    function \_prefs\_hook\_fullname(\$user = null)
    \{
        \$ldapServer = 'localhost';
        \$ldapPort = '389';
        \$searchBase = 'ou=People,dc=azapple,dc=com';
        \$ds = @ldap\_connect(\$ldapServer, \$ldapPort);

        if (is\_null(\$user)) \{
            \$user = Auth::getAuth();
        \}

        \$uid = Auth::getBareAuth();
        \$binddn = 'uid=' . \$uid . ',' . \$searchBase;
        \$bindpw = Auth::getCredential('password');

        if (@ldap\_bind(\$ds, \$binddn, \$bindpw)) \{
            \$searchResult = @ldap\_search(\$ds, \$searchBase, 'uid=' . \$uid);
        \}

        \$information = @ldap\_get\_entries(\$ds, \$searchResult);

        // derive the email address if possible
        if (\$information['count'] > 0) \{
            if (\$information[0]['cn'][0] != '') \{
                \$name = \$information[0]['cn'][0];
            \} else \{
                \$name = \$information[0]['gecos'][0];
            \}
        \}

        ldap\_close(\$ds);

        return \$name;
    \}
\}
</code></pre>
CW


\noindent\rule{\textwidth}{1pt}
\paragraph{Fullname \#2}
Another way to construct full name from givenName and sn

<pre><code class="language-php">
if (!function\_exists('\_prefs\_hook\_fullname')) \{
    function \_prefs\_hook\_fullname(\$user = null)
    \{   
        \$ldapServer = '127.0.0.1';
        \$ldapPort = '389';
        \$searchBase = 'ou=OU\_Extern,O=ARNHEM';

        \$ds = @ldap\_connect(\$ldapServer, \$ldapPort);

        if (is\_null(\$user)) \{
            \$user = Auth::getAuth();
        \}
        \$searchResult = @ldap\_search(\$ds, \$searchBase, 'cn=' . \$user);
        \$information = @ldap\_get\_entries(\$ds, \$searchResult);
        if (\$information['count'] > 0) \{
            \$name = '';
            if (\$information[0]['givenName'][0] != '') \{
                \$name = \$information[0]['givenName'][0];
            \}
            if (\$information[0]['sn'][0] !='') \{
                \$name = \$name . \$information[0]['sn'][0];
            \}
            if (\$name == '') \{
                \$name = \$information[0]['cn'][0];
            \}
        \}

        ldap\_close(\$ds);

        return (empty(\$name) ? \$user : \$name);
    \}
\}
</code></pre>

\noindent\rule{\textwidth}{1pt}
\paragraph{Fullname \#3}
This function uses horde's LDAP config to pull the fullname from the LDAP directory.

<pre><code class="language-php">
if (\$GLOBALS['conf']['auth']['driver'] == 'ldap' \&\& !function\_exists('\_prefs\_hook\_fullname')) \{
    function \_prefs\_hook\_fullname(\$uid = null)
    \{
        global \$conf;

        if (is\_null(\$uid)) \{
            \$uid = Auth::getAuth();
        \}

        \$ds = @ldap\_connect(\$conf['auth']['params']['hostspec']);
        @ldap\_set\_option(\$ds, LDAP\_OPT\_PROTOCOL\_VERSION, \$conf['auth']['params']['version']);
        @ldap\_bind(\$ds, \$conf['auth']['params']['binddn'], \$conf['auth']['params']['password']);
        \$searchResult = @ldap\_search(\$ds, \$conf['auth']['params']['basedn'], \$conf['auth']['params']['uid'] . '=' . \$uid);
        \$information = @ldap\_get\_entries(\$ds, \$searchResult);
        ldap\_close(\$ds);

        return \$information[0]['displayname'][0];
    \}
\}
</code></pre>

\noindent\rule{\textwidth}{1pt}
\paragraph{Fullname \#4}
Here are some cleaned up hook functions, for populating from\_addr and fullname:

<pre><code class="language-php">
if (!function\_exists('\_prefs\_hook\_from\_addr')) \{
    function \_prefs\_hook\_from\_addr(\$uid = null)
    \{
        global \$conf;
        \$domain\_name = 'yourdomain'; // could also use \$conf['mailer']['params']['localhost']
        \$ldapServer = 'yourdirectoryserver';
        \$ldapPort = '389';
        \$searchBase = 'yoursearchbase';
        \$ds = @ldap\_connect(\$ldapServer, \$ldapPort);
       
        if (is\_null(\$uid) \{
            \$uid = Auth:getAuth();
        \}

        // If your search scope is more than one, substitute ldap\_search for ldap\_list
        if (@ldap\_bind(\$ds)) \{
            \$searchResult = @ldap\_list(\$ds, \$searchBase, \$conf['auth']['params']['uid'] . '=' . \$uid);
        \}

        \$information = @ldap\_get\_entries(\$ds, \$searchResult);

        // derive the email address if possible
        if (\$information[0]['mail'][0] != '') \{
            \$emailname = \$information[0]['mail'][0];
        \} else \{
            \$emailname = \$information[0]['uid'][0] . '@' . \$domain\_name;
        \}

        ldap\_close(\$ds);

        return \$emailname;
    \}
\}
</code></pre>
<pre><code class="language-php">
if (!function\_exists('\_prefs\_hook\_fullname')) \{
   function \_prefs\_hook\_fullname(\$uid = null)
   \{
        global \$conf;
        \$ldapServer = 'yourdirectoryserver';
        \$ldapPort = '389';
        \$searchBase = 'yoursearchbase';
        \$ds = @ldap\_connect(\$ldapServer, \$ldapPort);

        if (is\_null(\$uid)) \{
            \$uid = Auth::getAuth();
        \}

        if (@ldap\_bind(\$ds)) \{
            \$searchResult = @ldap\_list(\$ds, \$searchBase, 'uid=' . \$uid);
        \}

        \$information = @ldap\_get\_entries(\$ds, \$searchResult);

        // Get the cn or GECOS value; could also pull givenName + sn but that usually == cn
        if (\$information[0]['cn'][0] != '') \{
            \$name = \$information[0]['cn'][0];
        \} else \{
            \$name = \$information[0]['gecos'][0];
        \}

        ldap\_close(\$ds);

        return \$name;
    \}
\}
</code></pre>
KMM


\noindent\rule{\textwidth}{1pt}
\subsubsection{Active Directory 2003}
I've made some modifications of KMM's hooks, and inserted new one for the identity's name - ID.<br />
To work, you have to add the 'hook' => 'true', to \$prefs['id'] , to \$prefs['fullname'] , and to \$prefs['from\_addr'] in the prefs.php file.<br />
More info:

\begin{itemize}
\item Theese hooks were modified and tested for the "Active Directory" enviroment on the Windows 2003 (+SP2) server/domain.


\item Horde was set to authenticate against the same "Active Directory", so conf.php does have all necessary information that may be used later in the hooks.


\item Hooks variables containing ldap connection information can be directed to mentioned conf.php .


\end{itemize}
<pre><code class="language-php">
if (!function\_exists('\_prefs\_hook\_id')) \{
   function \_prefs\_hook\_id(\$uid = null)
   \{
        global \$conf;
        \$ldapServer = \$conf['auth']['params']['hostspec'];	// will read server info from the conf.php, but can be changed to simple IP address or FQDN if necessary = server.domain.com .
        \$ldapPort = '3268';
        \$binddn = \$conf['auth']['params']['binddn'];		// will read the binddn user from the conf.php required to authenticate against ldap. can be changed to 'user@domain.com' .
        \$bindpw = \$conf['auth']['params']['password'];		// will read the \$binddn user's password from the conf.php required to authenticate against ldap. can be changed to simple text = 'PASSWORD' .
        \$searchBase = \$conf['auth']['params']['basedn'];	// will read the \$basedn from the conf.php, but can be changed to = 'ou=SomeOrgUnit,dc=domain,dc=com' .
        \$ds = ldap\_connect(\$ldapServer, \$ldapPort);
        ldap\_set\_option(\$ds, LDAP\_OPT\_PROTOCOL\_VERSION, 3);	// specify the LDAP protocol to use the version 3 .
        ldap\_set\_option(\$ds, LDAP\_OPT\_REFERRALS, 0);		// to be able to perform the searches on Windows 2003 Server Active Directory, this option must be set.

        if (is\_null(\$uid)) \{
            \$uid = Auth::getAuth();
        \}

        if (ldap\_bind(\$ds, \$binddn, \$bindpw)) \{
            \$searchResult = ldap\_search(\$ds, \$searchBase, \$conf['auth']['params']['uid'] . '=' . \$uid);
        \}

        \$information = ldap\_get\_entries(\$ds, \$searchResult);

        // Get the cn or GECOS value; could also pull givenName + sn but that usually == cn
        if (\$information[0]['cn'][0] != '') \{
            \$id = \$information[0]['cn'][0];
        \} else \{
            \$id = \$information[0]['gecos'][0];
        \}

        ldap\_close(\$ds);

        return \$id;
    \}
\}
</code></pre>
<pre><code class="language-php">
if (!function\_exists('\_prefs\_hook\_fullname')) \{
   function \_prefs\_hook\_fullname(\$uid = null)
   \{
        global \$conf;
        \$ldapServer = \$conf['auth']['params']['hostspec'];	// will read server info from the conf.php, but can be changed to simple IP address or FQDN if necessary = server.domain.com .
        \$ldapPort = '3268';
        \$binddn = \$conf['auth']['params']['binddn'];		// will read the binddn user from the conf.php required to authenticate against ldap. can be changed to 'user@domain.com' .
        \$bindpw = \$conf['auth']['params']['password'];		// will read the \$binddn user's password from the conf.php required to authenticate against ldap. can be changed to simple text = 'PASSWORD' .
        \$searchBase = \$conf['auth']['params']['basedn'];	// will read the \$basedn from the conf.php, but can be changed to = 'ou=SomeOrgUnit,dc=domain,dc=com' .
        \$ds = ldap\_connect(\$ldapServer, \$ldapPort);
        ldap\_set\_option(\$ds, LDAP\_OPT\_PROTOCOL\_VERSION, 3);	// specify the LDAP protocol to use the version 3 .
        ldap\_set\_option(\$ds, LDAP\_OPT\_REFERRALS, 0);		// to be able to perform the searches on Windows 2003 Server Active Directory, this option must be set.

        if (is\_null(\$uid)) \{
            \$uid = Auth::getAuth();
        \}

        if (ldap\_bind(\$ds, \$binddn, \$bindpw)) \{
            \$searchResult = ldap\_search(\$ds, \$searchBase, \$conf['auth']['params']['uid'] . '=' . \$uid);
        \}

        \$information = ldap\_get\_entries(\$ds, \$searchResult);

        // Get the cn or GECOS value; could also pull givenName + sn but that usually == cn
        if (\$information[0]['cn'][0] != '') \{
            \$name = \$information[0]['cn'][0];
        \} else \{
            \$name = \$information[0]['gecos'][0];
        \}

        ldap\_close(\$ds);

        return \$name;
    \}
\}
</code></pre>
<pre><code class="language-php">
if (!function\_exists('\_prefs\_hook\_from\_addr')) \{
    function \_prefs\_hook\_from\_addr(\$uid = null)
    \{
        global \$conf;
        \$domain\_name = 'domain.com';
        \$ldapServer = \$conf['auth']['params']['hostspec'];	// will read server info from the conf.php, but can be changed to simple IP address or FQDN if necessary = server.domain.com .
//        \$ldapPort = '3268';
        \$binddn = \$conf['auth']['params']['binddn'];		// will read the binddn user from the conf.php required to authenticate against ldap. can be changed to 'user@domain.com' .
        \$bindpw = \$conf['auth']['params']['password'];		// will read the \$binddn user's password from the conf.php required to authenticate against ldap. can be changed to simple text = 'PASSWORD' .
        \$searchBase = \$conf['auth']['params']['basedn'];	// will read the \$basedn from the conf.php, but can be changed to = 'ou=SomeOrgUnit,dc=domain,dc=com' .
        \$ds = ldap\_connect(\$ldapServer, \$ldapPort);
        ldap\_set\_option(\$ds, LDAP\_OPT\_PROTOCOL\_VERSION, 3);	// specify the LDAP protocol to use the version 3 .
        ldap\_set\_option(\$ds, LDAP\_OPT\_REFERRALS, 0);		// to be able to perform the searches on Windows 2003 Server Active Directory, this option must be set.

        if (is\_null(\$uid)) \{
            \$uid = Auth::getAuth();
        \}

        // If your search scope is more than one, substitute ldap\_search for ldap\_list
        if (ldap\_bind(\$ds, \$binddn, \$bindpw)) \{
            \$searchResult = ldap\_search(\$ds, \$searchBase, \$conf['auth']['params']['uid'] . '=' . \$uid);
        \}

        \$information = ldap\_get\_entries(\$ds, \$searchResult);

        // derive the email address if possible
        if (\$information[0]['mail'][0] != '') \{
            \$emailname = \$information[0]['mail'][0];
        \} else \{
            \$emailname = \$information[0]['uid'][0] . '@' . \$domain\_name;
        \}

        ldap\_close(\$ds);

        return \$emailname;
    \}
\}
</code></pre>
Daniel


\noindent\rule{\textwidth}{1pt}
\subsubsection{IMAP \#1}
For the environments where users are authenticated against IMAP server and all users have at least one email address  with the same domain name like others in the form <a href="https://wiki.horde.org/mailto:username@domain.name">username@domain.name</a>, you can create a hook which adds this implicit address to the default identity. This can be usefull for Horde modules like WHUPS operate with default e-mail addresses of users. I didn't use preference hook for "from\_addr" because what I really needed is not the default address for new identities, but the value for the default identity, even when the identity already exists. From prefs hook I was unable to write to other preferences (do not know why), so I created a postauthentication hook which does everything needed. The only thing I have not resolved is how to tell the preferences cache to update the data immediatelly. But in the database everything is stored so this resolves at the next login automatically.

The code works following way: if you have no default identity yet, it is created for you. If you have no e-mail address in the default identity, it is stored there as a composition of your username and default domain name (more complicated algorithms can be used here as well).

<pre><code class="language-php">
require\_once('Horde/Identity.php');
if (!function\_exists('\_horde\_hook\_postauthenticate')) \{
     function \_horde\_hook\_postauthenticate(\$userID, \$credential, \$realm)
     \{
         \$name = "\$userID";
         if (is\_null(\$name)) \{
             \$name = Auth::getAuth();
         \}
         if (!empty(\$name)) \{
             \$users\_identities = \&Identity::singleton('none',"\$name");
             \$users\_identities->init();
             \$users\_identity\_default\_from\_addr = \$users\_identities->getValue('from\_addr');
             if (empty(\$users\_identity\_default\_from\_addr)) \{
                 // use your own algorithm here or at least cahnge te domain name to the real value
                 \$mail = "\$name" . "@example.domain.com"; 
                 // store default identity changes
                 \$users\_identities->setValue('from\_addr',"\$mail");
                 \$users\_identities->save();
             \} else \{
                 \$mail = "\$users\_identity\_default\_from\_addr";
             \}
             // If no email address is found, then the login name will
             // be used.
             return (empty(\$mail) ? '' : \$mail);
         \}
         return '';
     \}
\}
</code></pre>
David Komanek


\noindent\rule{\textwidth}{1pt}
\subsubsection{IMAP \#2}
Here is a preference hook using "from\_addr" you can use to construct the mail address by using the login.<br />
This tip is from user "TKRIN" and has been found on TKRIN website: <a href="http://www.tkrin.net/96/trackback/">http://www.tkrin.net/96/trackback/</a>

These changes will automatically fill in the domain portion of the e-mail address in the Default Identity and lock it down so users can not change their e-mail address on the server.

1 ? Edit config/hooks.php and add the following hook:

<pre><code class="language-php">
if (!function\_exists('\_prefs\_hook\_from\_addr')) \{
  function \_prefs\_hook\_from\_addr(\$user = null)
  \{
    if (is\_null(\$user)) \{
      \$user = Auth::getAuth();
    \}
    if (!empty(\$user)) \{
      \$user = Auth::getAuth();
      // Here you can add your own code to rework \$user and create the mail address from the user login
      \$mail = "\$user" . "@example.com";
      return (empty(\$mail) ? '' : \$mail);
    \}
    return '';
  \}
\}
</code></pre>
2 ? Edit config/prefs.php and change

<pre><code class="language-php">
\$\_prefs['from\_addr'] = array(
  'value' => '',
  'locked' => true,
  'shared' => true,
  'type' => 'text',
  'desc' => \_("Your From: address:")
);
</code></pre>
to

<pre><code class="language-php">
\$\_prefs['from\_addr'] = array(
  'value' => '',
  'locked' => true,
  'hook' => true,
  'shared' => true,
  'type' => 'text',
  'desc' => \_("Your From: address:")
);
</code></pre>
Mathieu RV


\noindent\rule{\textwidth}{1pt}
add your customizations here...


\noindent\rule{\textwidth}{1pt}
\subsection{Horde}
\subsubsection{Labels / Colors}
I have created entries for common categories and common colors for the categories and labels. I am figuring that the entire yellow->orange range is available for people to use for their own purposes and making appointment types in the blue range, personal items in the green spectrum and finally the group categories in red.

<pre><code class="language-php">
// categories
\$\_prefs['categories'] = array(
    'value' => 'Appointment - In Office|Appointment - Out of Office|Company Event|Personal Event|Personal Task|Task - Administrative Group|Task - IT Group|Task - Sales Group|Training|Vacation Schedule|Vendor meeting|Holiday',
    'locked' => false,
    'shared' => true,
    'type' => 'implicit'
);
</code></pre>
<pre><code class="language-php">
// category colors
\$\_prefs['category\_colors'] = array(
    'value' => '1:Appointment - Out of Office|2:Company Event|3:Holiday|4:Personal Event|5:Personal Task|6:Task - Administrative Group|7:Task - IT Group|8:Task - Sales Group|9:Training|10:Vacation Schedule|11:Vendor meeting|12:\_default\_|13:\_unfiled\_|14:1|15:2|16:3|17:4|18:5|19:6|20:7|21:8|22:9|23:10|24:11|25:12|26:13|27:14|28:15|29:16|30:17|31:18|32:19|33:20|34:21|35:22|36:23|37:24|38:25|39:26|40:27|41:28|42:29|43:30|44:31|45:32|46:33|47:34|48:35|49:36|50:37|51:38|52:39|53:40|54:41|55:42|56:43|57:44|58:45|59:46|60:47|61:48|62:49|63:50|64:51|65:52|66:53|67:54|68:55|69:56|70:57|71:58|72:59|73:60|74:61|75:62|76:63|77:64|78:65|79:66|80:67|81:68|82:69|83:70|84:71|85:72|86:73|87:74|88:75|89:76|90:77|91:78|92:79|93:80|94:81|95:82|96:83|97:84|98:85|99:86|100:87|101:88|102:89|103:90|104:91|105:92|106:93|107:94|108:95|109:96|110:97|111:98|112:99|113:100|114:101|115:102|116:103|117:104|118:105|119:106|120:107|121:108|122:109|123:110|124:111|125:112|126:113|127:114|128:115|129:116|130:117|131:118|132:119|133:120|134:121|135:122|136:123|137:124|138:125|139:126|140:127|141:128|142:129|143:130|144:131|145:132|146:133|147:134|148:135|149:136|150:137|151:138|152:139|153:140|154:141|155:142|156:143|157:144|158:145|159:146|160:147|161:148|162:149|163:150|164:151|165:152|166:153|167:154|168:155|169:156|170:157|171:158|172:159|173:160|174:161|175:162|176:163|177:164|178:165|179:166|180:167|181:168|182:169|183:170|184:171|185:172|186:173|187:174|188:175|189:176|190:177|191:178|192:179|193:180|194:181|195:194|208:|Appointment - In Office:\#0000aa|Appointment - Out of Office:\#0000ff|Company Event:\#1d1dff|Holiday:\#7d7d7d|Personal Event:\#7dff7d|Personal Task:\#9dff9d|Task - Administrative Group:\#ff5f5f|Task - IT Group:\#ff7f7f|Task - Sales Group:\#ff9f9f|Training:\#adadff|Vacation Schedule:\#9d9d9d|Vendor meeting:\#7d7dff|\_default\_:\#FFFFFF|\_unfiled\_:\#DDDDDD',
    'locked' => false,
    'shared' => true,
    'type' => 'implicit'
);
</code></pre>
Next - and certainly what I think is the most important customization of all possible, is the portal page itself...the main Horde page. This is the sizzle of the steak. This gets people's attention. Of course the weather is for my neck of the woods...

<pre><code class="language-php">
// the layout of the portal page.
\$\_prefs['portal\_layout'] = array(
    'value' => 'a:4:\{i:0;a:2:\{i:0;a:4:\{s:3:"app";s:5:"horde";s:6:"height";i:1;s:5:"width";i:1;s:6:"params";a:2:\{s:4:"type";s:7:"fortune";s:6:"params";a:2:\{s:6:"offend";s:0:"";s:7:"fortune";a:1:\{i:0;s:8:"fortunes";\}\}\}\}i:1;a:4:\{s:3:"app";s:5:"horde";s:6:"height";i:1;s:5:"width";i:1;s:6:"params";a:2:\{s:4:"type";s:4:"moon";s:6:"params";a:2:\{s:5:"phase";s:7:"current";s:10:"hemisphere";s:8:"northern";\}\}\}\}i:1;a:2:\{i:0;a:4:\{s:3:"app";s:9:"kronolith";s:6:"height";i:1;s:5:"width";i:1;s:6:"params";a:2:\{s:4:"type";s:7:"summary";s:6:"params";a:1:\{s:8:"calendar";s:5:"\_\_all";\}\}\}i:1;a:4:\{s:3:"app";s:5:"horde";s:6:"height";i:1;s:5:"width";i:1;s:6:"params";a:2:\{s:4:"type";s:13:"weatherdotcom";s:6:"params";a:3:\{s:8:"location";s:22:"Phoenix, AZ (USAZ0166)";s:5:"units";s:8:"standard";s:4:"days";s:1:"3";\}\}\}\}i:2;a:2:\{i:0;a:4:\{s:3:"app";s:3:"nag";s:6:"height";i:1;s:5:"width";i:1;s:6:"params";a:2:\{s:4:"type";s:7:"summary";s:6:"params";a:9:\{s:8:"show\_pri";s:2:"on";s:12:"show\_actions";s:2:"on";s:8:"show\_due";s:2:"on";s:13:"show\_tasklist";s:2:"on";s:11:"show\_alarms";s:2:"on";s:13:"show\_category";s:2:"on";s:12:"show\_overdue";s:2:"on";s:14:"show\_completed";s:2:"on";s:15:"show\_categories";a:1:\{i:0;s:7:"unfiled";\}\}\}\}i:1;a:4:\{s:3:"app";s:3:"imp";s:6:"height";i:1;s:5:"width";i:1;s:6:"params";a:2:\{s:4:"type";s:7:"summary";s:6:"params";a:1:\{s:11:"show\_unread";s:2:"on";\}\}\}\}i:3;a:2:\{i:0;a:4:\{s:3:"app";s:5:"horde";s:6:"height";i:1;s:5:"width";i:1;s:6:"params";a:2:\{s:4:"type";s:7:"sunrise";s:6:"params";a:2:\{s:10:"\_\_location";s:13:"United States";s:8:"location";s:15:"33.434:-112.051";\}\}\}i:1;s:5:"empty";\}\} \}',
    'locked' => false,
    'shared' => false,
    'type' => 'implicit'
);
</code></pre>
CW


\noindent\rule{\textwidth}{1pt}
\subsubsection{Single Sign On}
Here is an example of the use of \_prefs\_change\_hook\_

We are using a CAS SSO as an Auth Method. So we don't have any horde login page. So what?. Remember that in the login page, you can select which mail frontend you want to use and also get rid of sidebar if dimp is selected. It tooks time to understand how to do that. post\_authenticate can't do the job as user prefs are not loaded.

So:<br />
We have to  leave show\_sidebar unlock, but people can't modify. To do that, we don't display the value in prefs.php

<pre><code class="language-php">
\$prefGroups['display'] = array(
    'column' => \_("Other Information"),
    'label' => \_("Display Options"),
    'desc' => \_("Set your startup application, color scheme, page refreshing, and other display options."),
    'members' => array('initial\_application', 'show\_last\_login', 'theme',
                     \#  'summary\_refresh\_time', 'show\_sidebar', 'sidebar\_width', \# DOM
                       'summary\_refresh\_time',  'sidebar\_width',
                       'moz\_sidebar', 'menu\_view', 'menu\_refresh\_time',
                       'widget\_accesskey')
); 
</code></pre>
To select dimp, we need a change in registry.php

<pre><code class="language-php">
\$this->applications['dimp'] = array(
    'fileroot' => dirname(\_\_FILE\_\_) . '/../dimp',
    'webroot' => \$this->applications['horde']['webroot'] . '/dimp',
    'name' => \_("Dynamic Mail"),
    'status' => 'active',
    'target' => '\_parent',
);
</code></pre>
And then, the change hook:

<pre><code class="language-php">
if (!function\_exists('\_prefs\_change\_hook\_initial\_application')) \{
     function \_prefs\_change\_hook\_initial\_application()
     \{
         \$initapp=\$GLOBALS['prefs']->getValue('initial\_application');
         if (strcmp(\$initapp,'dimp')==0)\{
            \$GLOBALS['prefs']->setValue('show\_sidebar',false);
         \}
         else \{
            \$GLOBALS['prefs']->setValue('show\_sidebar',true);
         \}
     \}
\}
</code></pre>
Dominique LALOT


\noindent\rule{\textwidth}{1pt}
add your customizations here...


\noindent\rule{\textwidth}{1pt}
\subsection{IMP}
\subsubsection{Mailboxes polling}
I haven't done much with IMP but all my users have these mailboxes and I want them to be 'polled' for new mail when they log on to system (especially the public mail - if there is any 'unseen' mail).

<pre><code class="language-php">
// list of folders to poll for new mail
\$\_prefs['nav\_poll'] = array(
    'value' => 'a:7:\{s:5:"INBOX";b:1;s:19:"INBOX.Deleted Items";b:1;s:12:"INBOX.Drafts";b:1;s:16:"INBOX.Sent Items";b:1;s:13:"INBOX.SPAMBOX";b:1;s:14:"INBOX.VIRUSBOX";b:1;s:6:"public";b:1;\}',
    'locked' => false,
    'shared' => false,
    'type' => 'implicit');
</code></pre>
CW


\noindent\rule{\textwidth}{1pt}
\subsubsection{Default folders}
This function makes sure that the default "Special" folders exist when a user logs in.

<pre><code class="language-php">
if (!function\_exists('\_imp\_hook\_postlogin')) \{
    function \_imp\_hook\_postlogin(\$actionID, \$isLogin)
    \{
        \$folderlist = \$GLOBALS['registry']->callByPackage('imp', 'folderlist', array());

        \$folder = \$GLOBALS['prefs']->getValue('drafts\_folder');
        if (!in\_array(\$folder, array\_keys(\$folderlist))) \{
            \$result = \$GLOBALS['registry']->callByPackage('imp', 'createFolder', array('folder' => \$folder));
        \}

        \$folder = \$GLOBALS['prefs']->getValue('sent\_mail\_folder');
        if (!in\_array(\$folder, array\_keys(\$folderlist))) \{
            \$result = \$GLOBALS['registry']->callByPackage('imp', 'createFolder', array('folder' => \$folder));
        \}

        \$folder = \$GLOBALS['prefs']->getValue('spam\_folder');
        if (!in\_array(\$folder, array\_keys(\$folderlist))) \{
            \$result = \$GLOBALS['registry']->callByPackage('imp', 'createFolder', array('folder' => \$folder));
        \}

        \$folder = \$GLOBALS['prefs']->getValue('trash\_folder');
        if (!in\_array(\$folder, array\_keys(\$folderlist))) \{
            \$result = \$GLOBALS['registry']->callByPackage('imp', 'createFolder', array('folder' => \$folder));
        \}

    \}
\}
</code></pre>
Ben Chavet


\noindent\rule{\textwidth}{1pt}
add your customizations here...


\noindent\rule{\textwidth}{1pt}
\subsection{Ingo}
\subsubsection{Default filters}
Ingo is very clever and it gives you some defaults automatically, but I want to redirect mail already tagged as spam or virus (virus removed naturally) into their respective folders which I have already created for them in my imap configuration. Thus, the default rules additions.

<pre><code class="language-php">
// filter rules
\$\_prefs['rules'] = array(
    'value' => 'a:6:\{i:0;a:2:\{s:4:"name";s:9:"Whitelist";s:6:"action";i:9;\}i:1;a:3:\{s:4:"name";s:8:"Vacation";s:6:"action";i:8;s:7:"disable";b:1;\}i:2;a:2:\{s:4:"name";s:9:"Blacklist";s:6:"action";i:7;\}i:3;a:2:\{s:4:"name";s:7:"Forward";s:6:"action";i:10;\}i:4;a:7:\{s:4:"name";s:9:"SPAM Flag";s:7:"combine";s:1:"1";s:10:"conditions";a:1:\{i:0;a:4:\{s:5:"field";s:11:"X-Spam-FLAG";s:4:"type";i:1;s:5:"match";s:8:"contains";s:5:"value";s:3:"YES";\}\}s:12:"action-value";s:13:"INBOX.SPAMBOX";s:6:"action";s:1:"2";s:4:"stop";s:1:"1";s:5:"flags";i:0;\}i:5;a:7:\{s:4:"name";s:10:"VIRUS Flag";s:7:"combine";s:1:"1";s:10:"conditions";a:1:\{i:0;a:4:\{s:5:"field";s:12:"X-Virus-FLAG";s:4:"type";i:1;s:5:"match";s:8:"contains";s:5:"value";s:3:"YES";\}\}s:12:"action-value";s:14:"INBOX.VIRUSBOX";s:6:"action";s:1:"2";s:4:"stop";s:1:"1";s:5:"flags";i:0;\}\}',
    'locked' => false,
    'shared' => false,
    'type' => 'implicit'
);
</code></pre>
CW


\noindent\rule{\textwidth}{1pt}
add your customizations here...


\noindent\rule{\textwidth}{1pt}
\subsection{Kronolith}
\subsubsection{Default calendar}
I have an "events calendar" that all of my users have read-only access to.  This hook makes sure they see that calendar by default.   I had previously just put the pref value in prefs.php, but then a new user's default calendar would not be created and they would not have a "New Event" link in their menu.  (don't forget to add the \texttt{'hook' => 'true'} to \texttt{\$prefs['display\_cals']}).

<pre><code class="language-php">
if (!function\_exists('\_prefs\_hook\_display\_cals')) \{
    function \_prefs\_hook\_display\_cals(\$uid = null)
    \{
        require\_once 'Horde/Share.php';

        if (is\_null(\$uid)) \{
            \$uid = Auth::getAuth();
        \}

        \$kronolith\_shares = \&Horde\_Share::singleton('kronolith');
        if (!\$kronolith\_shares->exists(\$uid)) \{
            require\_once 'Horde/Identity.php';
            \$identity = \&Identity::singleton();
            \$name = \$identity->getValue('fullname');
            if (trim(\$name) == '') \{
                \$name = Auth::removeHook(\$uid);
            \}
            \$share = \$kronolith\_shares->newShare(\$uid);
            \$share->set('name', sprintf(\_("\%s's Calendar"), \$name));
            \$kronolith\_shares->addShare(\$share);
        \}

        return 'a:2:\{i:0;s:' . strlen(\$uid) . ':"' . \$uid . '";i:1;s:32:"ac2bc478568fa773d9a7530b1a71398b";\}';
    \}
\}
</code></pre>
The following compliments the previous function by providing a default \texttt{fb\_cals} pref.

<pre><code class="language-php">
if (!function\_exists('\_prefs\_hook\_fb\_cals')) \{
    function \_prefs\_hook\_fb\_cals(\$uid = null)
    \{
        if (is\_null(\$uid)) \{
            \$uid = Auth::getAuth();
        \}

        \$kronolith\_shares = \&Horde\_Share::singleton('kronolith');
        if (!\$kronolith\_shares->exists(\$uid)) \{
            require\_once 'Horde/Identity.php';
            \$identity = \&Identity::singleton();
            \$name = \$identity->getValue('fullname');
            if (trim(\$name) == '') \{
                \$name = Auth::removeHook(\$uid);
            \}
            \$share = \$kronolith\_shares->newShare(\$uid);
            \$share->set('name', sprintf(\_("\%s's Calendar"), \$name));
            \$kronolith\_shares->addShare(\$share);
        \}

        return 'a:1:\{i:0;s:' . strlen(\$uid) . ':"' . \$uid . '";\}';
    \}
\}
</code></pre>

\noindent\rule{\textwidth}{1pt}
add your customizations here...


\noindent\rule{\textwidth}{1pt}
\subsection{Mnemo}
add your customizations here...


\noindent\rule{\textwidth}{1pt}
\subsection{Nag}
add your customizations here...


\noindent\rule{\textwidth}{1pt}
\subsection{Turba}
\subsubsection{LDAP: Multiple names}
To make sure only the first name listed in LDAP shows up for people with multiple names (the user has more than one CN):

<pre><code class="language-php">
if (!function\_exists('\_turba\_hook\_decode\_name')) \{
    function \_turba\_hook\_decode\_name(\$attribute, \$turbaObject)
    \{
        if (!is\_a(\$turbaObject->driver, 'Turba\_Driver\_ldap')) \{
            return \$attribute;
        \}

        // Return the first name in LDAP
        \$names = explode(', ', \$attribute);
        return \$names[0];
    \}
\}
</code></pre>

\noindent\rule{\textwidth}{1pt}
add your customizations here...


\noindent\rule{\textwidth}{1pt}
\end{document}
