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-2013 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 ********************************************************************************/
40 * EdtiViewMetaParser.php
41 * This is a utility file that attempts to provide support for parsing pre 5.0 SugarCRM
42 * QuickCreate.html files and produce a best guess editviewdefs.php file equivalent.
47 require_once('include/SugarFields/Parsers/MetaParser.php');
49 class QuickCreateMetaParser extends MetaParser {
51 function QuickCreateMetaParser() {
52 $this->mView = 'QuickCreate';
58 * @param $filePath The file path of the HTML file to parse
59 * @param $vardefs The module's vardefs
60 * @param $moduleDir The module's directory
61 * @param $merge boolean value indicating whether or not to merge the parsed contents
62 * @param $masterCopy The file path of the mater copy of the metadata file to merge against
63 * @return String format of metadata contents
65 function parse($filePath, $vardefs = array(), $moduleDir = '', $merge=false, $masterCopy=null) {
68 $contents = file_get_contents($filePath);
70 // The contents are not well formed so we add this section to make it easier to parse
71 $contents = $this->trimHTML($contents) . '</td></tr></table>';
74 $forms = $this->getElementsByType("form", $contents);
75 $tables = $this->getElementsByType("table", $forms[0] . "</td></tr></table>");
76 $mainrow = $this->getElementsByType("tr", $tables[1]);
77 $rows = substr($mainrow[0], strpos($mainrow[0], "</tr>"));
78 $tablerows = $this->getElementsByType("tr", $rows);
80 foreach($tablerows as $trow) {
83 $tablecolumns = $this->getElementsByType("td", $trow);
87 foreach($tablecolumns as $tcols) {
89 $sugarAttrLabel = $this->getTagAttribute("sugar", $tcols, "'^slot[^b]+$'");
90 $sugarAttrValue = $this->getTagAttribute("sugar", $tcols, "'slot[0-9]+b$'");
92 // If there wasn't any slot numbering/lettering then just default to expect label->vallue pairs
93 $sugarAttrLabel = count($sugarAttrLabel) != 0 ? $sugarAttrLabel : ($slot % 2 == 0) ? true : false;
94 $sugarAttrValue = count($sugarAttrValue) != 0 ? $sugarAttrValue : ($slot % 2 == 1) ? true : false;
100 $spanValue = strtolower($this->getElementValue("span", $tcols));
101 if(empty($spanValue)) {
102 $spanValue = strtolower($this->getElementValue("slot", $tcols));
104 if(empty($spanValue)) {
105 $spanValue = strtolower($this->getElementValue("td", $tcols));
108 //Get all the editable form elements' names
109 $formElementNames = $this->getFormElementsNames($spanValue);
110 $customField = $this->getCustomField($formElementNames);
117 if(!empty($customField)) {
118 // If it's a custom field we just set the name
119 $name = $customField;
121 } else if(empty($formElementNames) && preg_match_all('/[\{]([^\}]*?)[\}]/s', $spanValue, $matches, PREG_SET_ORDER)) {
122 // We are here if the $spanValue did not contain a form element for editing.
123 // We will assume that it is read only (since there were no edit form elements)
126 // If there is more than one matching {} value then try to find the right one to key off
127 // based on vardefs.php file. Also, use the entire spanValue as customCode
128 if(count($matches) > 1) {
129 $name = $matches[0][1];
130 $customCode = $spanValue;
131 foreach($matches as $pair) {
132 if(preg_match("/^(mod[\.]|app[\.]).*?/s", $pair[1])) {
133 $customCode = str_replace($pair[1], '$'.strtoupper($pair[1]), $customCode);
134 } else if(!empty($vardefs[$pair[1]])) {
136 $customCode = str_replace($pair[1], '$fields.'.$pair[1].'.value', $customCode);
140 //If it is only a label, skip
141 if(preg_match("/^(mod[\.]|app[\.]).*?/s", $matches[0][1])) {
143 } else if(preg_match("/^[\$].*?/s", $matches[0][1])) {
144 $name = '{' . strtoupper($matches[0][1]) . '}';
146 $name = $matches[0][1];
151 } else if(is_array($formElementNames)) {
153 if(count($formElementNames) == 1) {
154 if(!empty($vardefs[$formElementNames[0]])) {
155 $name = $formElementNames[0];
159 foreach($formElementNames as $elementName) {
160 // What we are doing here is saying that we will add all your fields assuming
161 // there are none that are of type relate or link. However, if we find such a type
162 // we'll take the first one found and assume that is the field you want (the SugarFields
163 // library will handle rendering the popup and select and clear buttons for you).
164 if(isset($vardefs[$elementName])) {
165 $type = $vardefs[$elementName]['type'];
166 if($type != 'relate' && $type != 'link') {
167 $fields[] = $elementName;
168 $name = $elementName;
171 $name = $elementName;
180 if(preg_match("/<textarea/si", $spanValue)) {
181 //special case for textarea form elements (add the displayParams)
182 $displayParams = array();
183 $displayParams['rows'] = $this->getTagAttribute("rows", $spanValue);
184 $displayParams['cols'] = $this->getTagAttribute("cols", $spanValue);
186 if(!empty($displayParams['rows']) && !empty($displayParams['cols'])) {
188 $field['name'] = $name;
189 $field['displayParams'] = $displayParams;
194 } else if($readOnly) {
196 $field['name'] = $name;
197 $field['type'] = 'readonly';
198 if(isset($customCode)) {
199 $field['customCode'] = $customCode;
204 if(isset($fields) || isset($customCode)) {
206 $field['name'] = $name;
208 $field['fields'] = $fields;
210 if(isset($customCode)) {
211 $field['customCode'] = $customCode;
216 $emptyCount = $name == '' ? $emptyCount + 1 : $emptyCount;
219 } //if-else if-else block
220 } //if($sugarAttrValue)
223 // One last final check. If $emptyCount does not equal Array $col count, don't add
224 if($emptyCount != count($col)) {
229 $templateMeta = array();
230 $templateMeta['form']['buttons'] = 'button';
232 preg_match_all("/(<input[^>]*?)>/si", $tables[0], $matches);
234 foreach($matches[0] as $button) {
235 $buttons[] = array('customCode'=>$button);
237 $templateMeta['form']['buttons'] = $buttons;
239 $formElements = $this->getFormElements($contents);
240 $hiddenInputs = array();
241 foreach($formElements as $elem) {
242 $type = $this->getTagAttribute("type", $elem);
243 if(preg_match('/hidden/si',$type, $matches)) {
244 $name = $this->getTagAttribute("name", $elem);
245 $value = $this->getTagAttribute("value", $elem);
246 $index = stripos($value, '$REQUEST');
247 $value = !empty($index) ? '$smarty.request.' . substr($value, 10) : $value;
248 $hiddenInputs[] = '<input id="' . $name . '" name="' . $name . '" value="' . $value . '">';
252 $templateMeta['form']['hidden'] = $hiddenInputs;
253 $templateMeta['widths'] = array(array('label' => '10', 'field' => '30'), array('label' => '10', 'field' => '30'));
254 $templateMeta['maxColumns'] = 2;
257 $panels['default'] = $metarow;
258 $panels = $this->appplyRules($moduleDir, $panels);
259 return $this->createFileContents($moduleDir, $panels, $templateMeta, $filePath);