]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/DynamicFields/templates/Fields/TemplateRelatedTextField.php
Release 6.5.0
[Github/sugarcrm.git] / modules / DynamicFields / templates / Fields / TemplateRelatedTextField.php
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  
39 require_once('modules/DynamicFields/templates/Fields/TemplateField.php');
40 class TemplateRelatedTextField extends TemplateText{
41     var $type = 'relate';
42     //ext1 is the name field
43     //ext2 is the related module
44     
45     function get_html_edit(){
46         $this->prepare();
47         $name = $this->name .'_name';
48         $value_name = strtoupper('{'.$name.'}');
49         $id = $this->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'>";
52     }
53
54     function get_html_detail(){
55         $name = $this->name .'_name';
56         $value_name = strtoupper('{'.$name.'}');
57         $id = $this->name ;
58         $value_id = strtoupper('{'.$id .'}');
59         
60         return "<a href='index.php?module=$this->ext2&action=DetailView&record={$value_id}'>{$value_name}</a>" ;    
61     }
62     
63     function get_html_list(){
64         if(isset($this->bean)){
65             $name = $this->bean->object_name . '.'. $this->ext1;
66         }else{
67             $name = $this->ext1;    
68         }
69         return '{'. strtoupper($name) . '}';    
70     }
71
72     function get_html_search(){
73         $searchable=array();
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>";   
78         }
79         //return 'NOT AVAILABLE';
80         return $this->get_html_edit();
81     }   
82
83     function get_xtpl_search(){
84         $searchable=array();
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'];
89             $team_list = '';
90             foreach(get_team_array() as $id=>$team){
91                 $selected = '';
92                 
93                 if(!empty($_REQUEST[$name]) && is_array($_REQUEST[$name]) && in_array($id, $_REQUEST[$name])){
94                     $selected = 'selected';
95                 }
96                 $team_list .= "<option  $selected value='$id'>$team</option>";
97             }
98             $returnXTPL[strtoupper($name). '_FILTER'] = $team_list;
99         } else {
100             $id = $this->name;
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(
107                                         'id' => $this->name,
108                                         $this->ext1 => $name,
109                                     ),
110             );
111         
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;
116
117             if(isset( $_REQUEST[$name])){
118                $returnXTPL[strtoupper($name)] =  $_REQUEST[$name];
119             }
120             if(isset( $_REQUEST[$id])){
121                $returnXTPL[strtoupper($id)] =  $_REQUEST[$id];
122             }
123         }
124         return $returnXTPL; 
125     }
126
127
128     function get_xtpl_edit(){
129     global $beanList;
130         
131         $name = $this->name .'_name';
132         $id = $this->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(
139             'id' => $this->name,
140             $this->ext1 => $name,
141         ),
142         );
143         
144         //$GLOBALS['log']->fatal($this->bean);
145       
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;
150
151         if(isset($beanList[$module]) && isset($this->bean->$id)){
152             if(!isset($this->bean->$name)){
153                 $mod_field = $this->ext1;
154                 global $beanFiles;
155                 
156                 $class = $beanList[$module];
157             
158                 require_once($beanFiles[$class]);
159                 $mod = new $class();
160                 $mod->retrieve($this->bean->$id);
161                 if(isset($mod->$mod_field)){
162                     $this->bean->$name = $mod->$mod_field;  
163                 }   
164             }
165             
166             
167             $returnXTPL[strtoupper($id)] = $this->bean->$id;
168         }
169         if(isset($this->bean->$name)){
170             $returnXTPL[strtoupper($name)] = $this->bean->$name;
171         }
172         if(isset($this->bean->$id)) {
173             $returnXTPL[strtoupper($id)] = $this->bean->$id;
174         }
175         
176         
177         return $returnXTPL; 
178     }
179     
180     function get_xtpl_detail(){
181         return $this->get_xtpl_edit();
182     }
183     
184     function get_related_info(){
185             
186     }
187     
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';
196         } else {
197                 $def['rname'] = 'name';
198         }
199         $def['quicksearch'] = 'enabled';
200         $def['studio'] = 'visible';
201         $def['source'] = 'non-db';
202         return $def;    
203     }
204     
205     function delete($df){
206         parent::delete($df);
207         
208         $id = new TemplateId();
209         $id->name = $this->ext3;
210         $id->delete($df);
211     }
212     
213     function save($df){
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();
220                 $id->len = 36;
221                 $id->label = 'LBL_LIST_RELATED_TO';
222                 $count = 0;
223                 $basename = strtolower(get_singular_bean_name($this->ext2)).'_id' ;
224                 $idName = $basename.'_c' ;
225                 
226                 while ( $df->fieldExists($idName, 'id') )
227                 {
228                     $idName = $basename.++$count.'_c' ;
229                 }
230                 $id->name = $idName ;
231                         $id->reportable = false;                                
232                 $id->save($df);
233                 
234                 // record the id field's name, and save
235                 $this->ext3 = $id->name;
236         }
237         
238         parent::save($df);
239     }
240     
241     function get_db_add_alter_table($table){
242         return "";
243     }
244     
245     function get_db_delete_alter_table($table) {
246         return "";
247     }
248     
249     function get_db_modify_alter_table($table){
250         return "";
251     }
252     
253 }
254
255
256 ?>