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('include/DetailView/DetailView2.php');
41 class ViewMetadata extends SugarView{
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>";
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>";
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'> ";
78 function printValue($value, $depth=0){
86 $do = !empty($_REQUEST['do'])?$_REQUEST['do']:'';
87 echo "<form method='post'>";
88 echo "<div><h2>I want to learn about ";
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']);
96 $this->displayCheckBoxes('modules[]', VardefBrowser::getModules(), $modules, ' id="_modules" ');
97 $attributes = !empty($_REQUEST['attributes'])?$_REQUEST['attributes']:array();
98 $allAttributes = array_keys(VardefBrowser::findFieldAttributes());
100 $this->displayCheckBoxes('attributes[]', $allAttributes, $attributes, ' id="_attributes" ');
101 $this->displayTextBoxes($allAttributes, ' id="_fields" ');
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 = '';
112 if(value == 'Fields'){
113 document.getElementById('_modules').style.display = '';
114 document.getElementById('_fields').style.display = '';
116 if(value == 'Field Attributes'){
117 document.getElementById('_modules').style.display = '';
118 document.getElementById('_attributes').style.display = '';
126 echo "<div width='100%'></div><div><div style='float:left'>";
129 $this->printValue(VardefBrowser::findVardefs( $modules));
131 case 'Field Attributes':
132 $this->printValue(VardefBrowser::findFieldAttributes($attributes, $modules));
135 $searchFor = array();
136 foreach($allAttributes as $at){
137 if(!empty($_POST[$at])){
138 $searchFor[$at] = $_POST[$at];
142 $this->printValue(VardefBrowser::findFieldsWithAttributes($searchFor, $modules));
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>
153 <div style='border:1px solid;width:100%;-moz-border-radius: 5px;border-radius: 5px;'>
154 <h4>What you need to know</h4>
156 Vardefs are where we define information about the fields for a module.
158 It also specifies 75% of the information on relationships.
160 There are also special attributes that can enable additional functionality for a module.
162 It's broken down into:
163 <b>fields:</b> The fields of a module (most of these are stored in the database)
165 <b>indices:</b> The indicies on the database
167 <b>relationships:</b> The relationships for this module
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.
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
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>.
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.
191 <b>[comment] (string) (optional)</b> is a description of the module
193 <b>[unified_search] (bool)(optional)</b> is global search (the search in the upper right corner on the screen) available for this module
195 <b>[unified_search_default_enabled] (bool)(optional)</b> is this module available by default in global search
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).
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
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
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.
211 <b>[custom_fields] (bool) (automatic) </b> if the module has custom fields this will be set to true
234 echo "</div><div style='float:right'>Help Text</div></div>";
237 //$this->printValue(VardefBrowser::findFieldsWithAttributes(array('type'=>'id'), $modules));
249 function __construct(){
253 static function getModules(){
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;
267 static function findFieldsWithAttributes($attributes, $modules=null){
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){
278 foreach($attributes as $k=>$v){
283 if($v == 'true' && !empty($def[$k])){
286 if((empty($def[$k]) || $def[$k] != $v) && (empty($alt) || empty($def[$alt]) || $def[$alt] != $v )){
291 $fields[$module][$object][$name] = $def;
301 static function findVardefs($modules=null){
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];
317 static function findFieldAttributes($attributes=array(), $modules=null, $byModule=false, $byType=false){
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){
330 $v = var_export($def[$k], true);
331 $key = is_array($def[$k])?null:$def[$k];
333 if(isset($def['dbType'])){
334 $v = var_export($def['dbType'], true);
338 $fields[$module][$object][$def['type']][$k][$key] = $v;
341 $fields[$def['type']][$k][$key] = $v;
343 if(!is_array($def[$k])){
344 if(isset($fields[$k][$key])){
345 $fields[$k][$key]['refs']++;
347 $fields[$k][$key] = array('attribute'=>$v, 'refs'=>1);
350 $fields[$k]['_array'][] = $def[$k];