]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/MVC/View/views/view.metadata.php
Release 6.5.0
[Github/sugarcrm.git] / include / MVC / View / views / view.metadata.php
1 <?php
2
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('include/DetailView/DetailView2.php');
40
41 class ViewMetadata extends SugarView{
42         var $type ='detail';
43         var $dv;
44         
45         
46         
47         function displayCheckBoxes($name,$values, $selected =array(), $attr=''){
48                 echo "<div $attr style='overflow:auto;float:left;width:200px;height:200px' >";
49                 foreach($values as $value){
50                         $checked = in_array($value, $selected)? " checked=checked ": " ";
51                         echo "<div style='padding:2px'><input type='checkbox' name='$name' value='$value' $checked> $value</div>";
52                 }
53                 echo "</div>";
54         }
55         
56         function displaySelect($name,$values, $selected ='', $attr=''){
57                 echo "<select name='$name' $attr>";
58                 foreach($values as $value){
59                         $checked = $value == $selected? " selected=selected ": " ";
60                         echo "<option value='$value' $checked> $value</option>";
61                 }
62                 echo "</select>";
63         }
64         
65         
66         
67          function displayTextBoxes($values, $attr=''){
68                 echo "<div $attr style='overflow:auto;float:left;width:400px;height:200px' >";
69                 foreach($values as $value){
70                         $postvalue = !empty($_POST[$value])? $_POST[$value]: '';
71                         echo "<div style='padding:2px;width:150px;float:left'>$value</div>  <input type='text' name='$value' value='$postvalue'> ";
72                 }
73                 echo "</div>";
74         }
75         
76         
77         
78         function printValue($value, $depth=0){
79                 echo "<pre>";
80                 print_r($value);
81                 echo "</pre>";
82                 
83         }
84         
85         function display(){
86                 $do = !empty($_REQUEST['do'])?$_REQUEST['do']:'';
87                 echo "<form method='post'>";
88                 echo "<div><h2>I want to learn about ";
89                 
90                 $this->displaySelect('do', array('Nothing', 'Modules','Fields', 'Field Attributes', 'Relationships'), $do, 'onchange="toggleLearn(this.value)"');
91                 echo "<input type='submit' value='Learn' class='button'></h2></div>";
92                 $modules = !empty($_REQUEST['modules'])?$_REQUEST['modules']:array();
93                 if(empty($modules) && !empty($_REQUEST['module']) && $_REQUEST['module'] != 'Home'){
94                         $modules = array(       $_REQUEST['module']);
95                 }
96                 $this->displayCheckBoxes('modules[]', VardefBrowser::getModules(), $modules, ' id="_modules" ');
97                 $attributes = !empty($_REQUEST['attributes'])?$_REQUEST['attributes']:array();
98                 $allAttributes = array_keys(VardefBrowser::findFieldAttributes());
99                 sort($allAttributes);
100                 $this->displayCheckBoxes('attributes[]', $allAttributes, $attributes, ' id="_attributes" ');
101                 $this->displayTextBoxes($allAttributes, ' id="_fields" ');
102                 echo "</form>";
103                                 echo <<<EOQ
104                 <script>
105                         function toggleLearn(value){
106                                 document.getElementById('_modules').style.display = 'None';     
107                                 document.getElementById('_attributes').style.display = 'None';  
108                                 document.getElementById('_fields').style.display = 'None';      
109                                 if(value == 'Modules' || value == 'Relationships'){
110                                         document.getElementById('_modules').style.display = ''; 
111                                 }
112                                 if(value == 'Fields'){
113                                         document.getElementById('_modules').style.display = '';
114                                         document.getElementById('_fields').style.display = '';
115                                 }       
116                                 if(value == 'Field Attributes'){
117                                         document.getElementById('_modules').style.display = '';
118                                         document.getElementById('_attributes').style.display = '';
119                                 }       
120                         }
121                         toggleLearn('$do');
122                         
123                 </script>
124                 
125 EOQ;
126                 echo "<div width='100%'></div><div><div style='float:left'>";
127                 switch ($do){
128                         case 'Modules':
129                                 $this->printValue(VardefBrowser::findVardefs( $modules));       
130                                 break;
131                         case 'Field Attributes':
132                                 $this->printValue(VardefBrowser::findFieldAttributes($attributes, $modules));
133                                 break;
134                         case 'Fields':
135                                 $searchFor = array();
136                                 foreach($allAttributes as $at){
137                                         if(!empty($_POST[$at])){
138                                                 $searchFor[$at] = $_POST[$at];
139                                         }       
140                                 }
141                                 
142                                 $this->printValue(VardefBrowser::findFieldsWithAttributes($searchFor, $modules));
143                                 break;
144                         default:
145                                 echo <<<EOQ
146                                 <div style='border:1px solid;width:100%;text-align:center;-moz-border-radius: 5px;border-radius: 5px;'>
147                                         <h2 style='text-decoration: line-through'>All you ever wanted to know about Vardefs in 30 minutes</h2>
148                                         <h2 style='text-decoration: line-through'>All you ever wanted to know about Vardef Fields and Relationships in 30 minutes</h1>
149                                         <h2 style='text-decoration: line-through'>All you ever wanted to know about Vardef Fields in 30 minutes</h2>
150                                         <h2 >Something about Vardefs in 30 minutes</h2>
151                                 </div>
152                                 
153                                 <div style='border:1px solid;width:100%;-moz-border-radius: 5px;border-radius: 5px;'>
154                                         <h4>What you need to know</h4>
155                                         <pre>
156 Vardefs are where we define information about the fields for a module. 
157                                         
158 It also specifies 75% of the information on relationships. 
159                                         
160 There are also special attributes that can enable additional functionality for a module. 
161                                         
162 It's broken down into:
163         <b>fields:</b> The fields of a module (most of these are stored in the database)
164         
165         <b>indices:</b> The indicies on the database
166         
167         <b>relationships:</b> The relationships for this module
168         
169         <b>templates:</b> the functionality/fields this module inherits from SugarObjects(located in include/SugarObjects). 
170                 In a vardef these are specified by the third argument in VardefManager::createVardef
171                 For Example - <b>VardefManager::createVardef('Contacts','Contact', array('default', 'assignable','team_security','person'));</b>
172                 would add the fields for team security to contacts and make it an object that can be assigned to users.
173                 The 'person' value would indicate that that Contacts subclasses Person and gains all the fields/attributes that 'Person' 
174                 would get. Since person extends basic it would also gain all the fields/attributes of basic as well.
175                                           
176                                          
177                 The SugarObjects that a module can extend are <b>'basic', 'company', 'file', 'issue', 'person'</b>. 
178                 These are the same objects you can build off of in ModuleBuilder. 
179                 Adding a new SugarObject to include/SugarObjects/templates is the way 
180                 to add modules to ModuleBuilder
181                                          
182                 Besides extending base objects, a module can also implement functionality defined in SugarObjects. 
183                 You can currenty implement <b>'assignable' and 'team_security'</b>. 
184                 
185                 
186         <b>attributes:</b>
187                 <b>[table] (string) (required)</b> The database table where this module stores it's data - any custom fields will be stored in a new table 
188                         with '_cstm' appended to the table name. The field id_c in the custom table will be the same value as id in the primary table
189                         allowing us to join the two tables together. 
190                 
191                 <b>[comment] (string) (optional)</b> is a description of the module
192                 
193                 <b>[unified_search] (bool)(optional)</b> is global search (the search in the upper right corner on the screen) available for this module
194                 
195                 <b>[unified_search_default_enabled] (bool)(optional)</b> is this module available by default in global search
196                 
197                 <b>[optimistic_locking] (bool) (optional)</b> optimistic locking is the concept that on save if the record modifiy time (date_modified)
198                          is newer than the the modify time of the record when it was loaded to edit (this time is stored in the session). 
199                 
200                 <b>[favorites] (bool) (optional)</b> should favorites be enabled for this module. Favorites are indicated by the stars next to a record 
201                         on lists and deail views. It makes it easier for users to indicate what is important to them right now. It also allows them to filter
202                         by favorites.  
203                         
204                 <b>[duplicate_merge] (bool) (optional)</b> is systematic merging allowed between records of this module or not. This option is available from 
205                         the menu on list views. A user needs to select 2 records on the list view using the checkboxes, and then they can select merge from the actions
206                         menu.
207                         
208                 <b>[audited] (bool) (optional)</b> auditing allows for the tracking of any changes to specified fields. In order to enable auditing you need to enable
209                         it at both the module level and the field level. It will create an audit table for the module with the '_audit' appended to the table name.
210                         
211                 <b>[custom_fields] (bool) (automatic) </b> if the module has custom fields this will be set to true
212                 
213                         
214                 
215                 
216                 
217                                          
218                                          
219
220                                           
221                                         
222                                         
223                                         </pre>
224                                 </div>
225                                 
226                                 <div>
227                                 
228                                 </div>
229                                 
230 EOQ;
231                                         
232                         
233                 }
234                 echo "</div><div style='float:right'>Help Text</div></div>";
235                 
236                 
237                 //$this->printValue(VardefBrowser::findFieldsWithAttributes(array('type'=>'id'), $modules));
238                 
239         
240                 
241                 
242                 
243         }
244
245 }
246
247 class VardefBrowser{
248
249         function __construct(){
250                 
251         }
252         
253         static function getModules(){
254                 $modules = array();
255                 foreach($GLOBALS['beanList'] as $module=>$object){
256                         $object = BeanFactory::getObjectName($module);
257                         VardefManager::loadVardef($module, $object);
258                         if(empty($GLOBALS['dictionary'][$object]['fields'] ))continue;
259                         $modules[] = $module;
260                 }
261                 sort($modules);
262                 return $modules;
263         
264                 
265         }
266         
267         static function findFieldsWithAttributes($attributes, $modules=null){
268                 $fields = array();
269                 if(empty($modules))$modules = VardefBrowser::getModules();
270                 foreach($modules as $module){
271                         if(!empty($GLOBALS['beanList'][$module])){
272                                 $object = $GLOBALS['beanList'][$module];
273                                 if($object == 'aCase')$object = 'Case';
274                                 VardefManager::loadVardef($module, $object);
275                                 if(empty($GLOBALS['dictionary'][$object]['fields'] ))continue;
276                                 foreach($GLOBALS['dictionary'][$object]['fields'] as $name=>$def){
277                                         $match = true;
278                                         foreach($attributes as $k=>$v){
279                                                 $alt = false;
280                                                 if($k == 'type'){
281                                                         $alt = 'dbType';        
282                                                 }
283                                                 if($v == 'true' && !empty($def[$k])){
284                                                         continue;
285                                                 }
286                                                 if((empty($def[$k]) || $def[$k] != $v) && (empty($alt) || empty($def[$alt]) || $def[$alt] != $v )){
287                                                         $match = false; 
288                                                 }
289                                         }
290                                         if($match){
291                                                 $fields[$module][$object][$name] = $def;
292                                         }
293                                         
294                                 }
295                                 
296                         }       
297                 }
298                 return $fields;                 
299         }
300         
301                 static function findVardefs($modules=null){
302                         $defs = array();
303                         if(empty($modules))$modules = VardefBrowser::getModules();
304                         foreach($modules as $module){
305                                 if(!empty($GLOBALS['beanList'][$module])){
306                                         $object = $GLOBALS['beanList'][$module];
307                                         if($object == 'aCase')$object = 'Case';
308                                         VardefManager::loadVardef($module, $object);
309                                         if(empty($GLOBALS['dictionary'][$object]['fields'] ))continue;
310                                         $defs[$module][$object] = $GLOBALS['dictionary'][$object];
311                                 }
312                         }
313                         return $defs;
314                 }
315         
316         
317                 static function findFieldAttributes($attributes=array(), $modules=null, $byModule=false, $byType=false){
318                 $fields = array();
319                 if(empty($modules))$modules = VardefBrowser::getModules();
320                 foreach($modules as $module){
321                         if(!empty($GLOBALS['beanList'][$module])){
322                                 $object = $GLOBALS['beanList'][$module];
323                                 if($object == 'aCase')$object = 'Case';
324                                 VardefManager::loadVardef($module, $object);
325                                 if(empty($GLOBALS['dictionary'][$object]['fields'] ))continue;
326                                 foreach($GLOBALS['dictionary'][$object]['fields'] as $name=>$def){
327                                         $fieldAttributes = (!empty($attributes))? $attributes:array_keys($def);
328                                         foreach($fieldAttributes as $k){
329                                                 if(isset($def[$k])){
330                                                         $v  = var_export($def[$k], true);
331                                                         $key = is_array($def[$k])?null:$def[$k];
332                                                         if($k == 'type'){
333                                                                 if(isset($def['dbType'])){
334                                                                         $v = var_export($def['dbType'], true);  
335                                                                 }       
336                                                         }
337                                                         if($byModule){
338                                                                 $fields[$module][$object][$def['type']][$k][$key] = $v;
339                                                         }else{
340                                                                 if($byType){
341                                                                         $fields[$def['type']][$k][$key] = $v;   
342                                                                 }else{
343                                                                         if(!is_array($def[$k])){
344                                                                                 if(isset($fields[$k][$key])){
345                                                                                         $fields[$k][$key]['refs']++;
346                                                                                 }else{
347                                                                                         $fields[$k][$key] = array('attribute'=>$v, 'refs'=>1);          
348                                                                                 }
349                                                                         }else{
350                                                                                 $fields[$k]['_array'][] = $def[$k];     
351
352                                                                         }
353                                                                 }
354                                                         }
355                                                         
356                                                         
357                                                 }
358                                                 
359                                         }
360                                         
361                                         
362                                 
363                                 }
364                                 
365                         }       
366                 }
367                 return $fields;                 
368         }
369         
370         
371
372 }