mView = 'QuickCreate'; } /** * parse * * @param $filePath The file path of the HTML file to parse * @param $vardefs The module's vardefs * @param $moduleDir The module's directory * @param $merge boolean value indicating whether or not to merge the parsed contents * @param $masterCopy The file path of the mater copy of the metadata file to merge against * @return String format of metadata contents **/ function parse($filePath, $vardefs = array(), $moduleDir = '', $merge=false, $masterCopy=null) { global $app_strings; $contents = file_get_contents($filePath); // The contents are not well formed so we add this section to make it easier to parse $contents = $this->trimHTML($contents) . ''; $moduleName = ''; $forms = $this->getElementsByType("form", $contents); $tables = $this->getElementsByType("table", $forms[0] . ""); $mainrow = $this->getElementsByType("tr", $tables[1]); $rows = substr($mainrow[0], strpos($mainrow[0], "")); $tablerows = $this->getElementsByType("tr", $rows); foreach($tablerows as $trow) { $emptyCount = 0; $tablecolumns = $this->getElementsByType("td", $trow); $col = array(); $slot = 0; foreach($tablecolumns as $tcols) { $sugarAttrLabel = $this->getTagAttribute("sugar", $tcols, "'^slot[^b]+$'"); $sugarAttrValue = $this->getTagAttribute("sugar", $tcols, "'slot[0-9]+b$'"); // If there wasn't any slot numbering/lettering then just default to expect label->vallue pairs $sugarAttrLabel = count($sugarAttrLabel) != 0 ? $sugarAttrLabel : ($slot % 2 == 0) ? true : false; $sugarAttrValue = count($sugarAttrValue) != 0 ? $sugarAttrValue : ($slot % 2 == 1) ? true : false; $slot++; if($sugarAttrValue) { $spanValue = strtolower($this->getElementValue("span", $tcols)); if(empty($spanValue)) { $spanValue = strtolower($this->getElementValue("slot", $tcols)); } if(empty($spanValue)) { $spanValue = strtolower($this->getElementValue("td", $tcols)); } //Get all the editable form elements' names $formElementNames = $this->getFormElementsNames($spanValue); $customField = $this->getCustomField($formElementNames); $name = ''; $readOnly = false; $fields = null; $customCode = null; if(!empty($customField)) { // If it's a custom field we just set the name $name = $customField; } else if(empty($formElementNames) && preg_match_all('/[\{]([^\}]*?)[\}]/s', $spanValue, $matches, PREG_SET_ORDER)) { // We are here if the $spanValue did not contain a form element for editing. // We will assume that it is read only (since there were no edit form elements) // If there is more than one matching {} value then try to find the right one to key off // based on vardefs.php file. Also, use the entire spanValue as customCode if(count($matches) > 1) { $name = $matches[0][1]; $customCode = $spanValue; foreach($matches as $pair) { if(preg_match("/^(mod[\.]|app[\.]).*?/s", $pair[1])) { $customCode = str_replace($pair[1], '$'.strtoupper($pair[1]), $customCode); } else if(!empty($vardefs[$pair[1]])) { $name = $pair[1]; $customCode = str_replace($pair[1], '$fields.'.$pair[1].'.value', $customCode); } } //foreach } else { //If it is only a label, skip if(preg_match("/^(mod[\.]|app[\.]).*?/s", $matches[0][1])) { continue; } else if(preg_match("/^[\$].*?/s", $matches[0][1])) { $name = '{' . strtoupper($matches[0][1]) . '}'; } else { $name = $matches[0][1]; } } $readOnly = true; } else if(is_array($formElementNames)) { if(count($formElementNames) == 1) { if(!empty($vardefs[$formElementNames[0]])) { $name = $formElementNames[0]; } } else { $fields = array(); foreach($formElementNames as $elementName) { // What we are doing here is saying that we will add all your fields assuming // there are none that are of type relate or link. However, if we find such a type // we'll take the first one found and assume that is the field you want (the SugarFields // library will handle rendering the popup and select and clear buttons for you). if(isset($vardefs[$elementName])) { $type = $vardefs[$elementName]['type']; if($type != 'relate' && $type != 'link') { $fields[] = $elementName; $name = $elementName; } else { unset($fields); $name = $elementName; break; } } } } //if-else } // Build the entry if(preg_match("/