PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/MailMerge/Step4.php

https://bitbucket.org/cviolette/sugarcrm
PHP | 153 lines | 87 code | 23 blank | 43 comment | 14 complexity | 596be6f63149d0858b4e00406a9daa28 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  3. /*********************************************************************************
  4. * SugarCRM Community Edition is a customer relationship management program developed by
  5. * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU Affero General Public License version 3 as published by the
  9. * Free Software Foundation with the addition of the following permission added
  10. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  11. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  12. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License along with
  20. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  21. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. * 02110-1301 USA.
  23. *
  24. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  25. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  26. *
  27. * The interactive user interfaces in modified source and object code versions
  28. * of this program must display Appropriate Legal Notices, as required under
  29. * Section 5 of the GNU Affero General Public License version 3.
  30. *
  31. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  32. * these Appropriate Legal Notices must retain the display of the "Powered by
  33. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  34. * technical reasons, the Appropriate Legal Notices must display the words
  35. * "Powered by SugarCRM".
  36. ********************************************************************************/
  37. /*
  38. * Created on Oct 4, 2005
  39. *
  40. * To change the template for this generated file go to
  41. * Window - Preferences - PHPeclipse - PHP - Code Templates
  42. */
  43. global $app_strings;
  44. global $app_list_strings;
  45. global $mod_strings;
  46. global $current_user;
  47. global $locale;
  48. $xtpl = new XTemplate('modules/MailMerge/Step4.html');
  49. $xtpl->assign("MOD", $mod_strings);
  50. $xtpl->assign("APP", $app_strings);
  51. if(!empty($_POST['document_id']))
  52. {
  53. $_SESSION['MAILMERGE_DOCUMENT_ID'] = $_POST['document_id'];
  54. }
  55. $document_id = $_SESSION['MAILMERGE_DOCUMENT_ID'];
  56. $revision = new DocumentRevision();
  57. $revision->retrieve($document_id);
  58. //$document = new Document();
  59. //$document->retrieve($document_id);
  60. if(!empty($_POST['selected_objects']))
  61. {
  62. $selObjs = urldecode($_POST['selected_objects']);
  63. $_SESSION['SELECTED_OBJECTS_DEF'] = $selObjs;
  64. }
  65. $selObjs = $_SESSION['SELECTED_OBJECTS_DEF'];
  66. $sel_obj = array();
  67. parse_str(stripslashes(html_entity_decode($selObjs, ENT_QUOTES)),$sel_obj);
  68. foreach($sel_obj as $key=>$value)
  69. {
  70. $sel_obj[$key] = stripslashes($value);
  71. }
  72. $relArray = array();
  73. //build relationship array
  74. foreach($sel_obj as $key=>$value)
  75. {
  76. $id = 'rel_id_'.md5($key);
  77. if(isset($_POST[$id]) && !empty($_POST[$id]))
  78. {
  79. $relArray[$key] = $_POST[$id];
  80. }
  81. }
  82. $builtArray = array();
  83. if(count($relArray) > 0)
  84. {
  85. $_SESSION['MAILMERGE_RELATED_CONTACTS'] = $relArray;
  86. $relModule = $_SESSION['MAILMERGE_CONTAINS_CONTACT_INFO'];
  87. global $beanList, $beanFiles;
  88. $class_name = $beanList[$relModule ];
  89. require_once($beanFiles[$class_name]);
  90. $seed = new $class_name();
  91. foreach($sel_obj as $key=>$value)
  92. {
  93. $builtArray[$key] = $value;
  94. if(isset($relArray[$key]))
  95. {
  96. $seed->retrieve($relArray[$key]);
  97. $name = "";
  98. if($relModule == "Contacts"){
  99. $name = $locale->getLocaleFormattedName($seed->first_name,$seed->last_name);
  100. }
  101. else{
  102. $name = $seed->name;
  103. }
  104. $builtArray[$key] = str_replace('##', '&', $value)." (".$name.")";
  105. }
  106. }
  107. }
  108. else
  109. {
  110. $builtArray = $sel_obj;
  111. }
  112. $xtpl->assign("MAILMERGE_MODULE", $_SESSION['MAILMERGE_MODULE']);
  113. $xtpl->assign("MAILMERGE_DOCUMENT_ID", $document_id);
  114. $xtpl->assign("MAILMERGE_TEMPLATE", $revision->filename." (rev. ".$revision->revision.")");
  115. $xtpl->assign("MAILMERGE_SELECTED_OBJECTS", get_select_options_with_id($builtArray,'0'));
  116. $xtpl->assign("MAILMERGE_SELECTED_OBJECTS_DEF", urlencode($selObjs));
  117. $step_num = 4;
  118. if(isset($_SESSION['MAILMERGE_SKIP_REL']) && $_SESSION['MAILMERGE_SKIP_REL'] || !isset($_SESSION['MAILMERGE_RELATED_CONTACTS']) || empty($_SESSION['MAILMERGE_RELATED_CONTACTS']))
  119. {
  120. $xtpl->assign("PREV_STEP", "2");
  121. $step_num = 3;
  122. }
  123. else
  124. {
  125. $xtpl->assign("PREV_STEP", "3");
  126. }
  127. $xtpl->assign("STEP_NUM", "Step ".$step_num.":");
  128. $xtpl->parse("main");
  129. $xtpl->out("main");
  130. ?>