You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

show.inc 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/addressbook/show.inc |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 2005-2013, The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | Show contact details |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. // Get contact ID and source ID from request
  21. $cids = rcmail_get_cids();
  22. $source = key($cids);
  23. $cid = $cids ? array_shift($cids[$source]) : null;
  24. // Initialize addressbook source
  25. $CONTACTS = rcmail_contact_source($source, true);
  26. $SOURCE_ID = $source;
  27. // read contact record (or get the one defined in 'save' action)
  28. if ($cid && ($record = ($CONTACT_RECORD ?: $CONTACTS->get_record($cid, true)))) {
  29. $OUTPUT->set_env('readonly', $CONTACTS->readonly || $record['readonly']);
  30. $OUTPUT->set_env('cid', $record['ID']);
  31. // remember current search request ID (if in search mode)
  32. if ($search = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GET)) {
  33. $OUTPUT->set_env('search_request', $search);
  34. }
  35. }
  36. // get address book name (for display)
  37. rcmail_set_sourcename($CONTACTS);
  38. $OUTPUT->add_handlers(array(
  39. 'contacthead' => 'rcmail_contact_head',
  40. 'contactdetails' => 'rcmail_contact_details',
  41. 'contactphoto' => 'rcmail_contact_photo',
  42. ));
  43. $OUTPUT->send('contact');
  44. function rcmail_contact_head($attrib)
  45. {
  46. global $CONTACTS, $RCMAIL;
  47. // check if we have a valid result
  48. if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
  49. $RCMAIL->output->show_message('contactnotfound', 'error');
  50. return false;
  51. }
  52. $form = array(
  53. 'head' => array( // section 'head' is magic!
  54. 'name' => $RCMAIL->gettext('contactnameandorg'),
  55. 'content' => array(
  56. 'prefix' => array('type' => 'text'),
  57. 'firstname' => array('type' => 'text'),
  58. 'middlename' => array('type' => 'text'),
  59. 'surname' => array('type' => 'text'),
  60. 'suffix' => array('type' => 'text'),
  61. 'name' => array('type' => 'text'),
  62. 'nickname' => array('type' => 'text'),
  63. 'organization' => array('type' => 'text'),
  64. 'department' => array('type' => 'text'),
  65. 'jobtitle' => array('type' => 'text'),
  66. ),
  67. ),
  68. );
  69. unset($attrib['name']);
  70. return rcmail_contact_form($form, $record, $attrib);
  71. }
  72. function rcmail_contact_details($attrib)
  73. {
  74. global $CONTACTS, $RCMAIL, $CONTACT_COLTYPES;
  75. // check if we have a valid result
  76. if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
  77. return false;
  78. }
  79. $i_size = $attrib['size'] ?: 40;
  80. $form = array(
  81. 'contact' => array(
  82. 'name' => $RCMAIL->gettext('properties'),
  83. 'content' => array(
  84. 'email' => array('size' => $i_size, 'render_func' => 'rcmail_render_email_value'),
  85. 'phone' => array('size' => $i_size),
  86. 'address' => array(),
  87. 'website' => array('size' => $i_size, 'render_func' => 'rcmail_render_url_value'),
  88. 'im' => array('size' => $i_size),
  89. ),
  90. ),
  91. 'personal' => array(
  92. 'name' => $RCMAIL->gettext('personalinfo'),
  93. 'content' => array(
  94. 'gender' => array('size' => $i_size),
  95. 'maidenname' => array('size' => $i_size),
  96. 'birthday' => array('size' => $i_size),
  97. 'anniversary' => array('size' => $i_size),
  98. 'manager' => array('size' => $i_size),
  99. 'assistant' => array('size' => $i_size),
  100. 'spouse' => array('size' => $i_size),
  101. ),
  102. ),
  103. );
  104. if (isset($CONTACT_COLTYPES['notes'])) {
  105. $form['notes'] = array(
  106. 'name' => $RCMAIL->gettext('notes'),
  107. 'content' => array(
  108. 'notes' => array('type' => 'textarea', 'label' => false),
  109. ),
  110. );
  111. }
  112. if ($CONTACTS->groups) {
  113. $form['groups'] = array(
  114. 'name' => $RCMAIL->gettext('groups'),
  115. 'content' => rcmail_contact_record_groups($record['ID']),
  116. );
  117. }
  118. return rcmail_contact_form($form, $record);
  119. }
  120. function rcmail_render_email_value($email)
  121. {
  122. global $RCMAIL;
  123. return html::a(array(
  124. 'href' => 'mailto:' . $email,
  125. 'onclick' => sprintf("return %s.command('compose','%s',this)", rcmail_output::JS_OBJECT_NAME, rcube::JQ($email)),
  126. 'title' => $RCMAIL->gettext('composeto'),
  127. 'class' => 'email',
  128. ), rcube::Q($email));
  129. }
  130. function rcmail_render_url_value($url)
  131. {
  132. $prefix = preg_match('!^(http|ftp)s?://!', $url) ? '' : 'http://';
  133. return html::a(array(
  134. 'href' => $prefix . $url,
  135. 'target' => '_blank',
  136. 'class' => 'url',
  137. ), rcube::Q($url));
  138. }
  139. function rcmail_contact_record_groups($contact_id)
  140. {
  141. global $RCMAIL, $CONTACTS, $GROUPS;
  142. $GROUPS = $CONTACTS->list_groups();
  143. if (empty($GROUPS)) {
  144. return '';
  145. }
  146. $members = $CONTACTS->get_record_groups($contact_id);
  147. $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0));
  148. $checkbox = new html_checkbox(array('name' => '_gid[]',
  149. 'class' => 'groupmember', 'disabled' => $CONTACTS->readonly));
  150. foreach ($GROUPS as $group) {
  151. $gid = $group['ID'];
  152. $table->add(null, $checkbox->show($members[$gid] ? $gid : null,
  153. array('value' => $gid, 'id' => 'ff_gid' . $gid)));
  154. $table->add(null, html::label('ff_gid' . $gid, rcube::Q($group['name'])));
  155. }
  156. $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC)));
  157. $hiddenfields->add(array('name' => '_cid', 'value' => $contact_id));
  158. $form_start = $RCMAIL->output->request_form(array(
  159. 'name' => "form", 'method' => "post",
  160. 'task' => $RCMAIL->task, 'action' => 'save',
  161. 'request' => 'save.'.intval($contact_id),
  162. 'noclose' => true), $hiddenfields->show());
  163. $form_end = '</form>';
  164. $RCMAIL->output->add_gui_object('editform', 'form');
  165. $RCMAIL->output->add_label('addingmember', 'removingmember');
  166. return $form_start . html::tag('fieldset', 'contactfieldgroup contactgroups', $table->show()) . $form_end;
  167. }