* @copyright 2007-2008 The SquirrelMail Project Team, Alexandros Vellis * @package plugins * @subpackage addressbook_ui_enhancements */ include_once(SM_PATH . 'plugins/addressbook_ui_enhancements/config.php'); /** * Define a special onload() event. This is only for informational messages * that check for various previous POST conditions (e.g addressbook entry added * from abook_take plugin) * @return string */ function addressbook_ui_enhancements_onload_do($onload) { if(isset($_POST['addaddr']) && isset($_POST['addaddr']['SUBMIT']) && isset($_POST['addaddr']['nickname'])) { return "addressbookUiMsg('". sprintf( _("Entry for %s has been Saved Successfully."), htmlspecialchars($_POST['addaddr']['nickname'])) . "', 'info');"; } return ''; } /** * Print introduction / messages placeholder */ function addressbook_ui_enhancements_print_message_box_do() { global $base_uri, $abook, $alist, $color, $abook_help_url, $abook_help_import_url; $abook_entries_count = sizeof($alist); sq_bindtextdomain('addressbook_ui_enhancements', SM_PATH . 'plugins/addressbook_ui_enhancements/locale'); textdomain ('addressbook_ui_enhancements'); echo html_tag( 'table', html_tag( 'tr', html_tag( 'td', "\n". '' . _("Personal Addressbook") . '' . "\n", 'center', $color[0] ) ) , 'center', '', 'width="95%"' ) ."\n"; echo '' . "\n"; $text = ''; // The text changes according to the number of entries if($abook_entries_count < 10) { $text .= '

'. _("Welcome to your personal addressbook.") . '

'; if(!empty($abook_help_import_url)) { $text .= '

'. ' '. sprintf(_("Do you already keep an addressbook in your computer? Export it in CSV format, and import it here. Read the relevant instructions and go to the Addressbook Tools Page."), $abook_help_import_url, $base_uri.'plugins/abook_tools/abook_tools.php'). '

'; } } if(true) { $text .= '

'. ' '. _("Tip: The addressbook is designed to be used not only in the Webmail, but also from any application of your choice, such as Outlook or Thunderbird, from your office or home.") . ' '; if(!empty($abook_help_url)) { $text .= sprintf( _("To learn more, read the instructions on how to access your addressbook from anywhere."), $abook_help_url ); } else { $text .= _("Contact our helpdesk for more information."); } $text .= '

'; } echo html_tag('tr',html_tag('td',$text)); echo "
\n"; echo '
'; // Message box for success messages etc. echo '
'; echo '
'. ''. ' '. _("Refresh Addressbook") . '
'; sq_bindtextdomain('squirrelmail', SM_PATH . 'locale'); textdomain ('squirrelmail'); } /** * Display an addressbook object. * * @param array $entry The LDAP object entry * @param string $pabobject backend:nickname */ function addressbook_ui_enhancements_print_user_profile(&$entry, $pabobject) { global $base_uri, $abookAttrs, $addressbook_ui_enhancements_editable_attrs_layout, $ldq_attributes, $color; sq_bindtextdomain('addressbook_ui_enhancements', SM_PATH . 'plugins/addressbook_ui_enhancements/locale'); textdomain ('addressbook_ui_enhancements'); if(!isset($base_uri)) $base_uri = sqm_baseuri(); $iconBase = '../plugins/famfamfam/icons/'; $out = '
'; $out .= ''; // 1) Main stuff (excluded from groups below) $out .= ''; // 2) Each layout e.g left, right printed out $omit_attrs = array('cn', 'mail', 'givenname', 'sn'); $omit_groups = array('main'); foreach($addressbook_ui_enhancements_editable_attrs_layout as $layout => $groups) { $out .= ''; } $out .= ''; // Edit / Delete links // Ugh, another table row. No way to center these float'ed buttons in CSS. :/ $out .= '
'; if(isset($entry['cn'])) { $header = 'h2'; for($i = 0; $i < $entry['cn']['count']; $i++) { $out .= '<'.$header.' class="fn">'.htmlspecialchars($entry['cn'][$i]).''; $header = 'h3'; } } if(isset($entry['mail'])) { for($i = 0; $i < $entry['mail']['count']; $i++) { $compose_uri = 'src/compose.php?send_to='.urlencode($entry['mail'][$i]); $out .= ''. makeComposeLink($compose_uri, $entry['mail'][$i]) . '
'; } } // TODO: Photo /* $out .= '
'. (isset($entry['photo']) ? // TODO: ''. _(': '' //''. _(' ). */ $out .= '
'; foreach($groups as $group) { if(in_array($group, $omit_groups)) continue; $out .= ''; $attrs = $abookAttrs[$group]; foreach($attrs as $attr) { if(in_array($attr, $omit_attrs)) continue; if(!isset($entry[$attr]) || $entry[$attr]['count'] == 0) continue; // skip empty attrs $out .= ''; } $out .= '
'; switch($attr) { case 'labeleduri': $out .= '' . $ldq_attributes[$attr]['text'] . ': '. ''; for($i = 0; $i < $entry[$attr]['count']; $i++) { $out .= ''. ''. htmlspecialchars($entry[$attr][$i]).'
'; } break; default: $out .= '' . $ldq_attributes[$attr]['text'] . ': '. '
'; $mfClass = ''; // If there is microformat class defined. if(isset($ldq_attributes[$attr]['class'])) { $mfClass = ''; } for($i = 0; $i < $entry[$attr]['count']; $i++) { $out .= $mfClass . str_replace('$', '
', htmlspecialchars($entry[$attr][$i])). (empty($mfClass) ? '' : '
') . '
'; } break; } $out .= '
'; } $out .= '
'. '
'. '
'. ''. ''. '
'; $out .= '
'; textdomain ('squirrelmail'); return $out; } /** * Show the edit form for an addressbook object. * * @param array $entry The LDAP object entry * @param string $pabobject backend:nickname */ function addressbook_ui_enhancements_print_edit_page(&$entry, $pabobject) { global $base_uri, $charset, $addressbook_ui_enhancements_editable_attrs_layout, $abookAttrs, $group_descriptions, $ldq_attributes, $color, $directory_icon_path; if(!isset($base_uri)) $base_uri = sqm_baseuri(); sq_bindtextdomain('addressbook_ui_enhancements', SM_PATH . 'plugins/addressbook_ui_enhancements/locale'); textdomain ('addressbook_ui_enhancements'); $group_descriptions = array( 'main' => _("Main Details"), 'work' => _("Work Information"), 'contact' => _("Contact Details"), 'address' => _("Address"), 'other' => _("Other"), ); $addnew = false; if($pabobject == '1:0') $addnew = true; /* Hack: Calculate first name, if 'cn' is available and 'givenname' does not exist. */ if(!isset($entry['givenname']) && isset($entry['cn']) && isset($entry['sn'])) { global $ldapAbookFullnameTemplate; $entry['givenname'][0] = trim(str_replace($entry['sn'][0], '', $entry['cn'][0])); $entry['givenname']['count'] = 1; } //$out = '
'; $out = ''; $out .= ''; foreach($addressbook_ui_enhancements_editable_attrs_layout as $layout => $groups) { $out .= ''; } $out .= '
'; foreach($groups as $group) { $attrs = $abookAttrs[$group]; $out .= '
'. ''.$group_descriptions[$group].''. '
    '; foreach($attrs as $attr) { if(!isset($entry[$attr]) || $entry[$attr]['count'] == 0 ){ $out .= addressbook_edit_line($pabobject, $attr, '', 0); } else { for($i = 0; $i < $entry[$attr]['count']; $i++) { $out .= addressbook_edit_line($pabobject, $attr, $entry[$attr][$i], $i); /* TODO $out .= ($i > 0 ? ''._(' : '' ); */ } // TODO //$out .= '' . _('; } } $out .= '

'; } $out .= '
'; $out .= '
'. '
'. '
'. ''. ''. '' . '
'; textdomain ('squirrelmail'); return $out; } /** * Print add new contact edit form * @return string */ function addressbook_ui_enhancements_print_addnew(&$res, &$pabobject) { global $color; textdomain ('addressbook_ui_enhancements'); $out = html_tag( 'table', html_tag( 'tr', html_tag( 'td', "\n". '' . _("Add a new Contact") . '' . "\n", 'center', $color[0] ) ) , 'center', '', 'width="95%"' ) ."\n". addressbook_ui_enhancements_print_edit_page($res, $pabobject); textdomain ('squirrelmail'); return $out; } /** * Print one form element (Textarea or input box) for the edit entry functionality. * * @return string */ function addressbook_edit_line($pabobject, $attr, $val = '', $index = 0) { global $ldq_attributes, $charset, $directory_icon_path; $out = '
  • '; $out .= '
    '; $out .= (isset($ldq_attributes[$attr]['image'])? ' ' : '') ; $thisId = 'editobject_'.$pabobject.'_'.$attr.'_'.$index; $thisName = 'editobject['.$pabobject.']['.$attr.']['.$index.']"'; if(isset($ldq_attributes[$attr]['input']) && $ldq_attributes[$attr]['input'] == 'textarea') { // freely editable textarea $out .= ''; } else { // Freely editable, Input Box $out .= ''; } if (isset($ldq_attributes[$attr]['inputdesc']) && $index == 0) { $out .= '
    '.$ldq_attributes[$attr]['inputdesc'] . ''; } $out .= '
    '; $out .= '
  • '; return $out; } /** * HTML in-Div for DELETION CONFIRMATION, sent via AJAX. * * @param array $entry The LDAP object entry * @param string $pabobject backend:nickname */ function addressbook_ui_enhancements_print_deletion_confirmation(&$entry, $pabobject) { global $base_uri, $abookAttrs, $ldq_attributes; if(!isset($base_uri)) $base_uri = sqm_baseuri(); $iconBase = $base_uri. 'plugins/famfamfam/icons/'; textdomain ('addressbook_ui_enhancements'); $formatted_name = ( isset($entry['displayname']) ? $entry['displayname'][0] . ' - ' : '' ) . (isset($entry['cn']) ? $entry['cn'][0] : ''); $out = '
    '. '
    '. sprintf( _("Are you sure you want to delete addressbook entry %s?"), $formatted_name). '
    '. ''. ''. ''. '
    '. '
    '; textdomain ('squirrelmail'); return $out; }