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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. // Disable qr-code if php-gd or Endroid's QrCode is not installed
  39. $OUTPUT->set_env('qrcode', function_exists('imagecreate') && class_exists('Endroid\QrCode\QrCode'));
  40. $OUTPUT->add_label('qrcode');
  41. $OUTPUT->add_handlers(array(
  42. 'contacthead' => 'rcmail_contact_head',
  43. 'contactdetails' => 'rcmail_contact_details',
  44. 'contactphoto' => 'rcmail_contact_photo',
  45. ));
  46. $OUTPUT->send('contact');
  47. function rcmail_contact_head($attrib)
  48. {
  49. global $CONTACTS, $RCMAIL;
  50. // check if we have a valid result
  51. if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
  52. $RCMAIL->output->show_message('contactnotfound', 'error');
  53. return false;
  54. }
  55. $form = array(
  56. 'head' => array( // section 'head' is magic!
  57. 'name' => $RCMAIL->gettext('contactnameandorg'),
  58. 'content' => array(
  59. 'prefix' => array('type' => 'text'),
  60. 'firstname' => array('type' => 'text'),
  61. 'middlename' => array('type' => 'text'),
  62. 'surname' => array('type' => 'text'),
  63. 'suffix' => array('type' => 'text'),
  64. 'name' => array('type' => 'text'),
  65. 'nickname' => array('type' => 'text'),
  66. 'organization' => array('type' => 'text'),
  67. 'department' => array('type' => 'text'),
  68. 'jobtitle' => array('type' => 'text'),
  69. ),
  70. ),
  71. );
  72. unset($attrib['name']);
  73. return rcmail_contact_form($form, $record, $attrib);
  74. }
  75. function rcmail_contact_details($attrib)
  76. {
  77. global $CONTACTS, $RCMAIL, $CONTACT_COLTYPES;
  78. // check if we have a valid result
  79. if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
  80. return false;
  81. }
  82. $i_size = $attrib['size'] ?: 40;
  83. $form = array(
  84. 'contact' => array(
  85. 'name' => $RCMAIL->gettext('properties'),
  86. 'content' => array(
  87. 'email' => array('size' => $i_size, 'render_func' => 'rcmail_render_email_value'),
  88. 'phone' => array('size' => $i_size),
  89. 'address' => array(),
  90. 'website' => array('size' => $i_size, 'render_func' => 'rcmail_render_url_value'),
  91. 'im' => array('size' => $i_size),
  92. ),
  93. ),
  94. 'personal' => array(
  95. 'name' => $RCMAIL->gettext('personalinfo'),
  96. 'content' => array(
  97. 'gender' => array('size' => $i_size),
  98. 'maidenname' => array('size' => $i_size),
  99. 'birthday' => array('size' => $i_size),
  100. 'anniversary' => array('size' => $i_size),
  101. 'manager' => array('size' => $i_size),
  102. 'assistant' => array('size' => $i_size),
  103. 'spouse' => array('size' => $i_size),
  104. ),
  105. ),
  106. );
  107. if (isset($CONTACT_COLTYPES['notes'])) {
  108. $form['notes'] = array(
  109. 'name' => $RCMAIL->gettext('notes'),
  110. 'content' => array(
  111. 'notes' => array('type' => 'textarea', 'label' => false),
  112. ),
  113. );
  114. }
  115. if ($CONTACTS->groups) {
  116. $form['groups'] = array(
  117. 'name' => $RCMAIL->gettext('groups'),
  118. 'content' => rcmail_contact_record_groups($record['ID']),
  119. );
  120. }
  121. return rcmail_contact_form($form, $record);
  122. }
  123. function rcmail_render_email_value($email)
  124. {
  125. global $RCMAIL;
  126. return html::a(array(
  127. 'href' => 'mailto:' . $email,
  128. 'onclick' => sprintf("return %s.command('compose','%s',this)", rcmail_output::JS_OBJECT_NAME, rcube::JQ($email)),
  129. 'title' => $RCMAIL->gettext('composeto'),
  130. 'class' => 'email',
  131. ), rcube::Q($email));
  132. }
  133. function rcmail_render_url_value($url)
  134. {
  135. $prefix = preg_match('!^(http|ftp)s?://!', $url) ? '' : 'http://';
  136. return html::a(array(
  137. 'href' => $prefix . $url,
  138. 'target' => '_blank',
  139. 'class' => 'url',
  140. ), rcube::Q($url));
  141. }
  142. function rcmail_contact_record_groups($contact_id)
  143. {
  144. global $RCMAIL, $CONTACTS, $GROUPS;
  145. $GROUPS = $CONTACTS->list_groups();
  146. if (empty($GROUPS)) {
  147. return '';
  148. }
  149. $members = $CONTACTS->get_record_groups($contact_id);
  150. $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0));
  151. $checkbox = new html_checkbox(array('name' => '_gid[]',
  152. 'class' => 'groupmember', 'disabled' => $CONTACTS->readonly));
  153. foreach ($GROUPS as $group) {
  154. $gid = $group['ID'];
  155. $table->add(null, $checkbox->show($members[$gid] ? $gid : null,
  156. array('value' => $gid, 'id' => 'ff_gid' . $gid)));
  157. $table->add(null, html::label('ff_gid' . $gid, rcube::Q($group['name'])));
  158. }
  159. $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC)));
  160. $hiddenfields->add(array('name' => '_cid', 'value' => $contact_id));
  161. $form_start = $RCMAIL->output->request_form(array(
  162. 'name' => "form", 'method' => "post",
  163. 'task' => $RCMAIL->task, 'action' => 'save',
  164. 'request' => 'save.'.intval($contact_id),
  165. 'noclose' => true), $hiddenfields->show());
  166. $form_end = '</form>';
  167. $RCMAIL->output->add_gui_object('editform', 'form');
  168. $RCMAIL->output->add_label('addingmember', 'removingmember');
  169. return $form_start . html::tag('fieldset', 'contactfieldgroup contactgroups', $table->show()) . $form_end;
  170. }