PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/MailMerge/Step3.php

https://bitbucket.org/cviolette/sugarcrm
PHP | 209 lines | 140 code | 30 blank | 39 comment | 16 complexity | 6fd5c95815add4d7286ab4a6ac315f03 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. require_once ('include/JSON.php');
  38. require_once('modules/MailMerge/modules_array.php');
  39. require_once('modules/MailMerge/merge_query.php');
  40. global $app_strings;
  41. global $app_list_strings;
  42. global $mod_strings;
  43. global $current_user;
  44. global $odd_bg;
  45. global $even_bg;
  46. global $sugar_version, $sugar_config;
  47. global $locale;
  48. $xtpl = new XTemplate('modules/MailMerge/Step3.html');
  49. $xtpl->assign("MOD", $mod_strings);
  50. $xtpl->assign("APP", $app_strings);
  51. if(!isset($_SESSION['MAILMERGE_MODULE']))
  52. {
  53. if(isset($_POST['mailmerge_module']))
  54. {
  55. $_SESSION['MAILMERGE_MODULE'] = $_POST['mailmerge_module'];
  56. }
  57. }
  58. if(isset($_POST['contains_contact_info'])){
  59. $_SESSION['MAILMERGE_CONTAINS_CONTACT_INFO'] = $_POST['contains_contact_info'];
  60. }
  61. if(!isset($_SESSION["MAILMERGE_DOCUMENT_ID"]))
  62. {
  63. if(!empty($_POST['document_id']))
  64. {
  65. $_SESSION['MAILMERGE_DOCUMENT_ID'] = $_POST['document_id'];
  66. }
  67. }
  68. $document_id = $_SESSION["MAILMERGE_DOCUMENT_ID"];
  69. $document = new Document();
  70. $document->retrieve($document_id);
  71. $_SESSION["MAILMERGE_TEMPLATE"] = $document->document_name;
  72. if(!empty($_POST['selected_objects']))
  73. {
  74. $selObjs = urldecode($_POST['selected_objects']);
  75. $_SESSION['SELECTED_OBJECTS_DEF'] = $selObjs;
  76. }
  77. else
  78. {
  79. $selObjs = $_SESSION['SELECTED_OBJECTS_DEF'];
  80. }
  81. $sel_obj = array();
  82. parse_str(html_entity_decode($selObjs, ENT_QUOTES),$sel_obj);
  83. $step_num = 3;
  84. $xtpl->assign("PREV_STEP", '2');
  85. $xtpl->assign("STEP_NUM", "Step 3:");
  86. $popup_request_data = array ('call_back_function' => 'set_return', 'form_name' => 'EditView', 'field_to_name_array' => array ('id' => 'rel_id', 'name' => 'rel_name',),);
  87. $json = getJSONobj();
  88. // must urlencode to put into the filter request string
  89. // because IE gets an out of memory error when it is passed
  90. // as the usual object literal
  91. $encoded_popup_request_data = urlencode($json->encode($popup_request_data));
  92. $modules = $modules_array;
  93. $xtpl->assign("MAILMERGE_MODULE_OPTIONS", get_select_options_with_id($modules, '0'));
  94. $change_parent_button = "<input title='".$app_strings['LBL_SELECT_BUTTON_TITLE']."' tabindex='2' type='button' class='button' value='".$app_strings['LBL_SELECT_BUTTON_LABEL']."' name='button' onclick='open_popup(document.EditView.rel_type.value, 600, 400, \"&request_data=$encoded_popup_request_data\", true, false, {});' />";
  95. $change_parent_button = "<input title='".$app_strings['LBL_SELECT_BUTTON_TITLE']."' tabindex='2' type='button' class='button' value='".$app_strings['LBL_SELECT_BUTTON_LABEL']."' name='button' onclick='open_popup(document.EditView.parent_type.value, 600, 400, \"&request_data=$encoded_popup_request_data\", true, false, {});' />";
  96. $xtpl->assign("CHANGE_PARENT_BUTTON", $change_parent_button);
  97. $relModule = $_SESSION['MAILMERGE_CONTAINS_CONTACT_INFO'];
  98. $xtpl->assign("STEP3_HEADER", "Set ".get_singular_bean_name($relModule)." Association");
  99. $select = "Select id, name from contacts";
  100. global $beanList, $beanFiles;
  101. $class_name = $beanList[$relModule];
  102. require_once($beanFiles[$class_name]);
  103. $seed = new $class_name();
  104. if(isset($_SESSION['MAILMERGE_SKIP_REL']) && $_SESSION['MAILMERGE_SKIP_REL'])
  105. {
  106. $disabled = 'disabled';
  107. }
  108. else
  109. {
  110. $disabled = '';
  111. }
  112. $oddRow = true;
  113. foreach($sel_obj as $key => $value)
  114. {
  115. $value = str_replace("##", "&", $value);
  116. $value = stripslashes($value);
  117. $code = md5($key);
  118. $popup_request_data = array ('call_back_function' => 'set_return', 'form_name' => 'EditView', 'field_to_name_array' => array ('id' => 'rel_id_'.$code, 'name' => 'rel_name_'.$code,),);
  119. $encoded_popup_request_data = urlencode($json->encode($popup_request_data));
  120. $fullQuery = get_merge_query($seed, $_SESSION['MAILMERGE_MODULE'], $key);
  121. $result = $seed->db->limitQuery($fullQuery, 0, 1, true, "Error performing limit query");
  122. $full_name = '';
  123. $contact_id = '';
  124. if($row = $seed->db->fetchByAssoc($result, 0)) {
  125. if($relModule == "Contacts") {
  126. $full_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
  127. } else {
  128. $full_name = $row['name'];
  129. }
  130. $contact_id = $row['id'];
  131. }
  132. $umodule =urlencode($_SESSION['MAILMERGE_MODULE']);
  133. $ukey = urlencode($key);
  134. $change_parent_button = "<input title='{$app_strings['LBL_SELECT_BUTTON_TITLE']}' tabindex='2' type='button' class='button' value='{$app_strings['LBL_SELECT_BUTTON_LABEL']}'
  135. name='button' onclick='open_popup(document.EditView.rel_type_{$code}.value, 600, 400,
  136. \"&html=mail_merge&rel_module=$umodule&id=$ukey&request_data=$encoded_popup_request_data\", true, false, {});' $disabled/>";
  137. $items = array(
  138. 'ID' => $key,
  139. 'NAME' => $value,
  140. 'CODE' => $code,
  141. 'TYPE_OPTIONS' => get_select_options_with_id($modules, '0'),
  142. 'CHANGE_RELATIONSHIP' => $change_parent_button,
  143. 'CONTACT_ID' => $contact_id,
  144. 'CONTACT_NAME' => $full_name,
  145. 'REL_MODULE' => $_SESSION['MAILMERGE_CONTAINS_CONTACT_INFO'],
  146. );
  147. $xtpl->assign("MAILMERGE", $items);
  148. if($oddRow)
  149. {
  150. //todo move to themes
  151. $xtpl->assign("ROW_COLOR", 'oddListRow');
  152. $xtpl->assign("BG_COLOR", $odd_bg);
  153. }
  154. else
  155. {
  156. //todo move to themes
  157. $xtpl->assign("ROW_COLOR", 'evenListRow');
  158. $xtpl->assign("BG_COLOR", $even_bg);
  159. }
  160. $oddRow = !$oddRow;
  161. $xtpl->parse("main.items.row");
  162. }
  163. $xtpl->parse("main.items");
  164. $xtpl->parse("main");
  165. $xtpl->out("main");
  166. function generateSelect($seed, $relModule){
  167. $lowerRelModule = strtolower($relModule);
  168. if($seed->load_relationship($lowerRelModule)){
  169. $params = array();
  170. $params['join_table_alias'] = 'r1';
  171. $params['join_table_link_alias'] = 'r2';
  172. $params['join_type'] = 'LEFT JOIN';
  173. $join = $seed->$lowerRelModule->getJoin($params);
  174. $select = "SELECT {$seed->table_name}.* FROM {$seed->table_name} ".$join;
  175. return $select;
  176. }
  177. return "";
  178. }
  179. ?>