<?php
/**
 * Smarty plugin
 *
 * @category Smarty
 * @license /_licenses/untermStrich/agb_normal.pdf
 * @author Christian Koller
 * @copyright 2009 untermStrich
 * @package Smarty
 * @subpackage plugins
 * @version $Id$
*/

/**
 * Smarty {relation_link} function plugin
 * 
 * Use within <p >
 *
 * @param   string  $params     Parameters:
 *                              <ul>
 *                                  <li>relation        object  Relation to create the link for</li>
 *                                  <li>from_persapp    boolean Optional Link from personalappointment</li>
 *                              </ul>
 * @param   object  &$smarty    The smarty object
 * @return   string
 */
function smarty_function_relation_link($params, US_Smarty &$smarty)
{
    if (!isset($params['relation'])) {
        return '';
    } else {
        $relation = $params['relation'];
        $from_persapp = false;
        if (array_key_exists('from_persapp', $params)) {
            $from_persapp = (bool)$params['from_persapp'];
        }
        
        $css_class = 'relation portlettooltip ';
        
        if (!empty($relation->snd_address_id)) {
            $to_class = 'addressesandcontacts';
            $to_id = $relation->snd_address_id;
            $css_class .= 'smallbtns address';
        } elseif ($from_persapp && !empty($relation->address_id)) {
            $to_class = 'addressesandcontacts';
            $to_id = $relation->address_id;
            $css_class .= 'smallbtns address';
        } elseif (!empty($relation->from_personalapp_id)) {
            $to_class = 'personalappointmentplaner';
            $to_id = $relation->from_personalapp_id;
            $css_class .= 'smallbtns appointment';
        }
        
        if (isset($to_class)) {
            return sprintf(
                ' onclick="usComm.loadPage(\'%s\', \'index\', \'view\', %d);" class="%s" ',
                $to_class,
                $to_id,
                $css_class
            );
        }
        
        return 'class="'.$css_class.'"';
    }
}

/* End of function.relation_link.php */