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-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 require_once('modules/DynamicFields/templates/Fields/TemplateField.php');
40 class TemplateRelatedTextField extends TemplateText{
42 //ext1 is the name field
43 //ext2 is the related module
45 function get_html_edit(){
47 $name = $this->name .'_name';
48 $value_name = strtoupper('{'.$name.'}');
50 $value_id = strtoupper('{'.$id .'}');
51 return "<input type='text' name='$name' id='$name' size='".$this->size."' readonly value='$value_name'><input type='button' onclick='open_popup(\"{". strtoupper($this->name). "_MODULE}\", 600, 400,\" \", true, false, {ENCODED_". strtoupper($this->name). "_POPUP_REQUEST_DATA})' type='button' class='button' value='{APP.LBL_SELECT_BUTTON_LABEL}' ><input type='hidden' name='$id' value='$value_id'>";
54 function get_html_detail(){
55 $name = $this->name .'_name';
56 $value_name = strtoupper('{'.$name.'}');
58 $value_id = strtoupper('{'.$id .'}');
60 return "<a href='index.php?module=$this->ext2&action=DetailView&record={$value_id}'>{$value_name}</a>" ;
63 function get_html_list(){
64 if(isset($this->bean)){
65 $name = $this->bean->object_name . '.'. $this->ext1;
69 return '{'. strtoupper($name) . '}';
72 function get_html_search(){
74 $def = $this->bean->field_name_map[$this->name];
75 if(!empty($def['id_name']) && in_array($def['id_name'], $searchable)){
76 $name = $def['id_name'];
77 return "<select size='3' name='{$name}[]' tabindex='1' multiple='multiple'>{".strtoupper($name). "_FILTER}</select>";
79 //return 'NOT AVAILABLE';
80 return $this->get_html_edit();
83 function get_xtpl_search(){
85 $def = $this->bean->field_name_map[$this->name];
86 $returnXTPL = array();
87 if(!empty($def['id_name']) && in_array($def['id_name'], $searchable)){
88 $name = $def['id_name'];
90 foreach(get_team_array() as $id=>$team){
93 if(!empty($_REQUEST[$name]) && is_array($_REQUEST[$name]) && in_array($id, $_REQUEST[$name])){
94 $selected = 'selected';
96 $team_list .= "<option $selected value='$id'>$team</option>";
98 $returnXTPL[strtoupper($name). '_FILTER'] = $team_list;
101 $name = $this->name .'_name';
102 $module = $this->ext2;
103 $popup_request_data = array(
104 'call_back_function' => 'set_return',
105 'form_name' => 'search_form',
106 'field_to_name_array' => array(
108 $this->ext1 => $name,
112 $json = getJSONobj();
113 $encoded_popup_request_data = $json->encode($popup_request_data);
114 $returnXTPL['ENCODED_'.strtoupper($id).'_POPUP_REQUEST_DATA'] = $encoded_popup_request_data;
115 $returnXTPL[strtoupper($id).'_MODULE'] = $module;
117 if(isset( $_REQUEST[$name])){
118 $returnXTPL[strtoupper($name)] = $_REQUEST[$name];
120 if(isset( $_REQUEST[$id])){
121 $returnXTPL[strtoupper($id)] = $_REQUEST[$id];
128 function get_xtpl_edit(){
131 $name = $this->name .'_name';
133 $module = $this->ext2;
134 $returnXTPL = array();
135 $popup_request_data = array(
136 'call_back_function' => 'set_return',
137 'form_name' => 'EditView',
138 'field_to_name_array' => array(
140 $this->ext1 => $name,
144 //$GLOBALS['log']->fatal($this->bean);
146 $json = getJSONobj();
147 $encoded_contact_popup_request_data = $json->encode($popup_request_data);
148 $returnXTPL['ENCODED_'.strtoupper($id).'_POPUP_REQUEST_DATA'] = $encoded_contact_popup_request_data;
149 $returnXTPL[strtoupper($id).'_MODULE'] = $module;
151 if(isset($beanList[$module]) && isset($this->bean->$id)){
152 if(!isset($this->bean->$name)){
153 $mod_field = $this->ext1;
156 $class = $beanList[$module];
158 require_once($beanFiles[$class]);
160 $mod->retrieve($this->bean->$id);
161 if(isset($mod->$mod_field)){
162 $this->bean->$name = $mod->$mod_field;
167 $returnXTPL[strtoupper($id)] = $this->bean->$id;
169 if(isset($this->bean->$name)){
170 $returnXTPL[strtoupper($name)] = $this->bean->$name;
172 if(isset($this->bean->$id)) {
173 $returnXTPL[strtoupper($id)] = $this->bean->$id;
180 function get_xtpl_detail(){
181 return $this->get_xtpl_edit();
184 function get_related_info(){
188 function get_field_def(){
189 $def = parent::get_field_def();
190 $def['id_name'] = $this->ext3;
191 $def['ext2'] = $this->ext2;
192 $def['module'] = $def['ext2'];
193 //Special case for documents, which use a document_name rather than name
194 if ($def['module'] == "Documents") {
195 $def['rname'] = 'document_name';
197 $def['rname'] = 'name';
199 $def['quicksearch'] = 'enabled';
200 $def['studio'] = 'visible';
201 $def['source'] = 'non-db';
205 function delete($df){
208 $id = new TemplateId();
209 $id->name = $this->ext3;
214 // create the new ID field associated with this relate field - this will hold the id of the related record
215 // this field must have a unique name as the name is used when constructing quicksearches and when saving the field
216 //Check if we have not saved this field so we don't create two ID fields.
217 //Users should not be able to switch the module after having saved it once.
218 if (!$df->fieldExists($this->name)) {
219 $id = new TemplateId();
221 $id->label = 'LBL_LIST_RELATED_TO';
223 $basename = strtolower(get_singular_bean_name($this->ext2)).'_id' ;
224 $idName = $basename.'_c' ;
226 while ( $df->fieldExists($idName, 'id') )
228 $idName = $basename.++$count.'_c' ;
230 $id->name = $idName ;
233 // record the id field's name, and save
234 $this->ext3 = $id->name;
240 function get_db_add_alter_table($table){
244 function get_db_delete_alter_table($table) {
248 function get_db_modify_alter_table($table){