Add php files

This commit is contained in:
2025-05-12 15:44:39 +00:00
parent c951760058
commit 82d5804ac4
9534 changed files with 2638137 additions and 0 deletions

View File

@@ -0,0 +1,115 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* SugarFieldAddress.php
* SugarFieldAddress translates and displays fields from a vardef definition into different formats
* for EditViews and DetailViews. A sample invocation from a Meta-Data file is as follows:
*
* array (
* 'name' => 'primary_address_street',
* 'type' => 'address',
* 'displayParams'=>array('key'=>'primary'),
* ),
*
* Where name is set to the field for ACL verification, type is set to 'address'
* to override the default field type and the displayParams array includes the key
* for the address field. Assumptions are made that the vardefs.php contains address
* elements with the corresponding names. There is the optional displayParam index
* 'copy' that accepts as value the key of the other address fields. In our
* example we may enable copying from the primary address fields with:
*
* array (
* 'name' => 'altaddress_street',
* 'type' => 'address',
* 'displayParams'=>array('key'=>'alt', 'copy'=>'primary'),
* ),
*
*/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldAddress extends SugarFieldBase {
function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
global $app_strings;
if(!isset($displayParams['key'])) {
$GLOBALS['log']->debug($app_strings['ERR_ADDRESS_KEY_NOT_SPECIFIED']);
$this->ss->trigger_error($app_strings['ERR_ADDRESS_KEY_NOT_SPECIFIED']);
return;
}
//Allow for overrides. You can specify a Smarty template file location in the language file.
if(isset($app_strings['SMARTY_ADDRESS_DETAILVIEW'])) {
$tplCode = $app_strings['SMARTY_ADDRESS_DETAILVIEW'];
return $this->fetch($tplCode);
}
global $current_language;
if(isset($current_language) && file_exists('include/SugarFields/Fields/Address/' . $current_language . '.DetailView.tpl')) {
return $this->fetch('include/SugarFields/Fields/Address/' . $current_language . '.DetailView.tpl');
} else {
return $this->fetch('include/SugarFields/Fields/Address/DetailView.tpl');
} //if-else
}
function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
global $app_strings;
if(!isset($displayParams['key'])) {
$GLOBALS['log']->debug($app_strings['ERR_ADDRESS_KEY_NOT_SPECIFIED']);
$this->ss->trigger_error($app_strings['ERR_ADDRESS_KEY_NOT_SPECIFIED']);
return;
}
//Allow for overrides. You can specify a Smarty template file location in the language file.
if(isset($app_strings['SMARTY_ADDRESS_EDITVIEW'])) {
$tplCode = $app_strings['SMARTY_ADDRESS_EDITVIEW'];
return $this->fetch($tplCode);
}
global $current_language;
if(isset($current_language) && file_exists('include/SugarFields/Fields/Address/' . $current_language . '.EditView.tpl')) {
return $this->fetch('include/SugarFields/Fields/Address/' . $current_language . '.EditView.tpl');
} else {
return $this->fetch('include/SugarFields/Fields/Address/EditView.tpl');
} //if-else
}
}
?>

View File

@@ -0,0 +1,342 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* SugarFieldBase translates and displays fields from a vardef definition into different formats
* including DetailView, ListView, EditView. It also provides Search Inputs and database queries
* to handle searching
*
*/
class SugarFieldBase {
var $ss; // Sugar Smarty Object
var $hasButton = false;
function SugarFieldBase($type) {
$this->type = $type;
$this->ss = new Sugar_Smarty();
}
function fetch($path){
$additional = '';
if(!$this->hasButton && !empty($this->button)){
$additional .= '<input type="button" class="button" ' . $this->button . '>';
}
if(!empty($this->buttons)){
foreach($this->buttons as $v){
$additional .= ' <input type="button" class="button" ' . $v . '>';
}
}
if(!empty($this->image)){
$additional .= ' <img ' . $this->image . '>';
}
return $this->ss->fetch($path) . $additional;
}
function findTemplate($view){
static $tplCache = array();
if ( isset($tplCache[$this->type][$view]) ) {
return $tplCache[$this->type][$view];
}
$lastClass = get_class($this);
$classList = array($this->type,str_replace('SugarField','',$lastClass));
while ( $lastClass = get_parent_class($lastClass) ) {
$classList[] = str_replace('SugarField','',$lastClass);
}
$tplName = '';
foreach ( $classList as $className ) {
$tplName = 'include/SugarFields/Fields/'. $className .'/'. $view .'.tpl';
if ( file_exists('custom/'.$tplName) ) {
$tplName = 'custom/'.$tplName;
break;
}
if ( file_exists($tplName) ) {
break;
}
}
$tplCache[$this->type][$view] = $tplName;
return $tplName;
}
public function formatField($rawField, $vardef){
// The base field doesn't do any formatting, so override it in subclasses for more specific actions
return $rawField;
}
public function unformatField($formattedField, $vardef){
// The base field doesn't do any formatting, so override it in subclasses for more specific actions
return $formattedField;
}
function getSmartyView($parentFieldArray, $vardef, $displayParams, $tabindex = -1, $view){
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch($this->findTemplate($view));
}
function getListViewSmarty($parentFieldArray, $vardef, $displayParams, $col) {
// FIXME: Rework the listview to use two-pass rendering like the DetailView
$tabindex = 1;
$isArray = is_array($parentFieldArray);
$fieldName = $vardef['name'];
if ( $isArray ) {
$fieldNameUpper = strtoupper($fieldName);
if ( isset($parentFieldArray[$fieldNameUpper])) {
$parentFieldArray[$fieldName] = $this->formatField($parentFieldArray[$fieldNameUpper],$vardef);
} else {
$parentFieldArray[$fieldName] = '';
}
} else {
if ( isset($parentFieldArray->$fieldName) ) {
$parentFieldArray->$fieldName = $this->formatField($parentFieldArray->$fieldName,$vardef);
} else {
$parentFieldArray->$fieldName = '';
}
}
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex, false);
$this->ss->left_delimiter = '{';
$this->ss->right_delimiter = '}';
$this->ss->assign('col',$vardef['name']);
return $this->fetch($this->findTemplate('ListView'));
}
/**
* Returns a smarty template for the DetailViews
*
* @param parentFieldArray string name of the variable in the parent template for the bean's data
* @param vardef vardef field defintion
* @param displayParam parameters for display
* available paramters are:
* * labelSpan - column span for the label
* * fieldSpan - column span for the field
*/
function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
return"<span id='{$vardef['name']}'>" . $this->getSmartyView($parentFieldArray, $vardef, $displayParams, $tabindex, 'DetailView') . '</span>';
}
// 99% of all fields will just format like a listview, but just in case, it's here to override
function getChangeLogSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
return $this->formatField($parentFieldArray[$vardef['name']],$vardef);
}
function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
if(!empty($vardef['function']['returns']) && $vardef['function']['returns'] == 'html'){
$type = $this->type;
$this->type = 'Base';
$result= $this->getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
$this->type = $type;
return $result;
}
return $this->getSmartyView($parentFieldArray, $vardef, $displayParams, $tabindex, 'EditView');
}
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
if(!empty($vardef['auto_increment']))$vardef['len']=255;
return $this->getSmartyView($parentFieldArray, $vardef, $displayParams, $tabindex, 'EditView');
}
function getPopupViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex){
if (is_array($displayParams) && !isset($displayParams['formName']))
$displayParams['formName'] = 'popup_query_form';
else if (empty($displayParams))
$displayParams = array('formName' => 'popup_query_form');
return $this->getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
}
public function getEmailTemplateValue($inputField, $vardef, $displayParams = array(), $tabindex = 0){
// This does not return a smarty section, instead it returns a direct value
return $this->formatField($inputField,$vardef);
}
function displayFromFunc( $displayType, $parentFieldArray, $vardef, $displayParams, $tabindex ) {
if ( ! is_array($vardef['function']) ) {
$funcName = $vardef['function'];
$includeFile = '';
$onListView = false;
$returnsHtml = false;
} else {
$funcName = $vardef['function']['name'];
$includeFile = '';
if ( isset($vardef['function']['include']) ) {
$includeFile = $vardef['function']['include'];
}
if ( isset($vardef['function']['onListView']) && $vardef['function']['onListView'] == true ) {
$onListView = true;
} else {
$onListView = false;
}
if ( isset($vardef['function']['returns']) && $vardef['function']['returns'] == 'html' ) {
$returnsHtml = true;
} else {
$returnsHtml = false;
}
}
if ( $displayType == 'ListView'
|| $displayType == 'popupView'
|| $displayType == 'searchView'
|| $displayType == 'wirelessEditView'
|| $displayType == 'wirelessDetailView'
|| $displayType == 'wirelessListView'
) {
// Traditionally, before 6.0, additional functions were never called, so this code doesn't get called unless the vardef forces it
if ( $onListView ) {
if ( !empty($includeFile) ) {
require_once($includeFile);
}
return $funcName($parentFieldArray, $vardef['name'], $parentFieldArray[$vardef['name']], $displayType);
} else {
$displayTypeFunc = 'get'.$displayType.'Smarty';
return $this->$displayTypeFunc($parentFieldArray, $vardef, $displayParams, $tabindex);
}
} else {
if ( !empty($displayParams['idName']) ) {
$fieldName = $displayParams['idName'];
} else {
$fieldName = $vardef['name'];
}
if ( $returnsHtml ) {
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
$tpl = $this->findTemplate($displayType.'Function');
if ( $tpl == '' ) {
// Can't find a function template, just use the base
$tpl = $this->findTemplate('DetailViewFunction');
}
return "<span id='{$vardef['name']}'>" . $this->fetch($tpl) . '</span>';
} else {
return '{sugar_run_helper include="'.$includeFile.'" func="'.$funcName.'" bean=$bean field="'.$fieldName.'" value=$fields.'.$fieldName.'.value displayType="'.$displayType.'"}';
}
}
}
function getEditView() {
}
function getSearchInput() {
}
function getQueryLike() {
}
function getQueryIn() {
}
/**
* Setup function to assign values to the smarty template, should be called before every display function
*/
function setup($parentFieldArray, $vardef, $displayParams, $tabindex, $twopass=true) {
$this->button = '';
$this->buttons = '';
$this->image = '';
if ($twopass){
$this->ss->left_delimiter = '{{';
$this->ss->right_delimiter = '}}';
}
$this->ss->assign('parentFieldArray', $parentFieldArray);
$this->ss->assign('vardef', $vardef);
$this->ss->assign('tabindex', $tabindex);
//for adding attributes to the field
if(!empty($displayParams['field'])){
$plusField = '';
foreach($displayParams['field'] as $key=>$value){
$plusField .= ' ' . $key . '="' . $value . '"';//bug 27381
}
$displayParams['field'] = $plusField;
}
//for adding attributes to the button
if(!empty($displayParams['button'])){
$plusField = '';
foreach($displayParams['button'] as $key=>$value){
$plusField .= ' ' . $key . '="' . $value . '"';
}
$displayParams['button'] = $plusField;
$this->button = $displayParams['button'];
}
if(!empty($displayParams['buttons'])){
$plusField = '';
foreach($displayParams['buttons'] as $keys=>$values){
foreach($values as $key=>$value){
$plusField[$keys] .= ' ' . $key . '="' . $value . '"';
}
}
$displayParams['buttons'] = $plusField;
$this->buttons = $displayParams['buttons'];
}
if(!empty($displayParams['image'])){
$plusField = '';
foreach($displayParams['image'] as $key=>$value){
$plusField .= ' ' . $key . '="' . $value . '"';
}
$displayParams['image'] = $plusField;
$this->image = $displayParams['image'];
}
$this->ss->assign('displayParams', $displayParams);
}
/**
* This should be called when the bean is saved. The bean itself will be passed by reference
* @param SugarBean bean - the bean performing the save
* @param array params - an array of paramester relevant to the save, most likely will be $_REQUEST
*/
public function save(&$bean, $params, $field, $properties, $prefix = ''){
if ( isset($params[$prefix.$field]) ) {
if(isset($properties['len']) && isset($properties['type']) && 'varchar' == $properties['type']){
$bean->$field = trim($this->unformatField($params[$prefix.$field],$properties));
}
else {
$bean->$field = $this->unformatField($params[$prefix.$field],$properties);
}
}
}
}
?>

View File

@@ -0,0 +1,89 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldBool extends SugarFieldBase {
/**
*
* @return The html for a drop down if the search field is not 'my_items_only' or a dropdown for all other fields.
* This strange behavior arises from the special needs of PM. They want the my items to be checkboxes and all other boolean fields to be dropdowns.
* @author Navjeet Singh
* @param $parentFieldArray -
**/
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
if( preg_match("/current_user_only.*/", $vardef['name']) || preg_match("/empty.*/", $vardef['name'])){
return $this->fetch('include/SugarFields/Fields/Bool/EditView.tpl');
}else{
if( preg_match("/isHidden.*/", $vardef['name']) || preg_match("/empty.*/", $vardef['name'])){
return $this->fetch('include/SugarFields/Fields/Bool/EditView.tpl');
}else{
return $this->fetch('include/SugarFields/Fields/Bool/SearchView.tpl');
}
}
}
public function getEmailTemplateValue($inputField, $vardef, $displayParams = array(), $tabindex = 0){
global $app_list_strings;
// This does not return a smarty section, instead it returns a direct value
if ( $inputField == 'bool_true' || $inputField == true ) {
return $app_list_strings['checkbox_dom']['1'];
} else {
return $app_list_strings['checkbox_dom']['2'];
}
}
public function unformatField($formattedField, $vardef){
if ( empty($formattedField) ) {
$unformattedField = false;
return $unformattedField;
}
if ( $formattedField == '0' || $formattedField == 'off' || $formattedField == 'false' || $formattedField == 'no' ) {
$unformattedField = false;
} else {
$unformattedField = true;
}
return $unformattedField;
}
}
?>

View File

@@ -0,0 +1,221 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldCollection extends SugarFieldBase {
var $tpl_path;
function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$nolink = array('Users');
if(in_array($vardef['module'], $nolink)){
$displayParams['nolink']=true;
}else{
$displayParams['nolink']=false;
}
$json = getJSONobj();
$displayParamsJSON = $json->encode($displayParams);
$vardefJSON = $json->encode($vardef);
$this->ss->assign('displayParamsJSON', '{literal}'.$displayParamsJSON.'{/literal}');
$this->ss->assign('vardefJSON', '{literal}'.$vardefJSON.'{/literal}');
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
if(empty($this->tpl_path)){
$this->tpl_path = 'include/SugarFields/Fields/Collection/DetailView.tpl';
}
return $this->fetch($this->tpl_path);
}
function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex, $searchView = false) {
if($searchView){
$form_name = 'search_form';
}else{
$form_name = 'EditView';
}
$json = getJSONobj();
$displayParamsJSON = $json->encode($displayParams);
$vardefJSON = $json->encode($vardef);
$this->ss->assign('required', !empty($vardef['required']));
$this->ss->assign('displayParamsJSON', '{literal}'.$displayParamsJSON.'{/literal}');
$this->ss->assign('vardefJSON', '{literal}'.$vardefJSON.'{/literal}');
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
if(!$searchView) {
if(empty($this->tpl_path)){
$this->tpl_path = 'include/SugarFields/Fields/Collection/EditView.tpl';
}
return $this->fetch($this->tpl_path);
}
}
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$this->getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex, true);
}
/**
* This should be called when the bean is saved. The bean itself will be passed by reference
* @param SugarBean bean - the bean performing the save
* @param array params - an array of paramester relevant to the save, most likely will be $_REQUEST
*/
public function save(&$bean, $params, $field, $properties, $prefix = ''){
if(isset($_POST["primary_" . $field . "_collection"])){
$save = false;
$value_name = $field . "_values";
$link_field = array();
// populate $link_field from POST
foreach($_POST as $name=>$value){
if(strpos($name, $field . "_collection_") !== false){
$num = substr($name, -1);
if(is_numeric($num)){
settype($num, 'int');
if(strpos($name, $field . "_collection_extra_") !== false){
$extra_field = substr($name, $field . "_collection_extra_" . $num);
$link_field[$num]['extra_field'][$extra_field]=$value;
}else if ($name == $field . "_collection_" . $num){
$link_field[$num]['name']=$value;
}else if ($name == "id_" . $field . "_collection_" . $num){
$link_field[$num]['id']=$value;
}
}
}
}
// Set Primary
if(isset($_POST["primary_" . $field . "_collection"])){
$primary = $_POST["primary_" . $field . "_collection"];
settype($primary, 'int');
$link_field[$primary]['primary']=true;
}
// Create or update record and take care of the extra_field
require('include/modules.php');
require_once('data/Link.php');
$class = load_link_class($bean->field_defs[$field]);
$link_obj = new $class($bean->field_defs[$field]['relationship'], $bean, $bean->field_defs[$field]);
$module = $link_obj->getRelatedModuleName();
$beanName = $beanList[$module];
require_once($beanFiles[$beanName]);
foreach($link_field as $k=>$v){
$save = false;
$update_fields = array();
$obj = new $beanName();
if(!isset($link_field[$k]['name']) || empty($link_field[$k]['name'])){
// There is no name so it is an empty record -> ignore it!
unset($link_field[$k]);
break;
}
if(!isset($link_field[$k]['id']) || empty($link_field[$k]['id']) || (isset($_POST[$field . "_new_on_update"]) && $_POST[$field . "_new_on_update"] === 'true')){
// Create a new record
if(isset($_POST[$field . "_allow_new"]) && ($_POST[$field . "_allow_new"] === 'false' || $_POST[$field . "_allow_new"] === false)){
// Not allow to create a new record so remove from $link_field
unset($link_field[$k]);
break;
}
if(!isset($link_field[$k]['id']) || empty($link_field[$k]['id'])){
// There is no ID so it is a new record
$save = true;
$obj->name=$link_field[$k]['name'];
}else{
// We duplicate an existing record because new_on_update is set
$obj->retrieve($link_field[$k]['id']);
$obj->id='';
$obj->name = $obj->name . '_DUP';
}
}else{
// id exist so retrieve the data
$obj->retrieve($link_field[$k]['id']);
}
// Update the extra field for the new or the existing record
if(isset($v['extra_field']) && is_array($v['extra_field'])){
// Retrieve the changed fields
if(isset($_POST["update_fields_{$field}_collection"]) && !empty($_POST["update_fields_{$field}_collection"])){
$JSON = getJSONobj();
$update_fields = $JSON->decode(html_entity_decode($_POST["update_fields_{$field}_collection"]));
}
// Update the changed fields
foreach($update_fields as $kk=>$vv){
if(!isset($_POST[$field . "_allow_update"]) || ($_POST[$field . "_allow_update"] !== 'false' && $_POST[$field . "_allow_update"] !== false)){
//allow to update the extra_field in the record
if(isset($v['extra_field'][$kk]) && $vv == true){
$extra_field_name = str_replace("_".$field."_collection_extra_".$k,"",$kk);
if($obj->$extra_field_name != $v['extra_field'][$kk]){
$save = true;
$obj->$extra_field_name=$v['extra_field'][$kk];
}
}
}
}
}
// Save the new or updated record
if($save){
if(!$obj->ACLAccess('save')){
ACLController::displayNoAccess(true);
sugar_cleanup(true);
}
$obj->save();
$link_field[$k]['id']=$obj->id;
}
}
// Save new relationship or delete deleted relationship
if(!empty($link_field)){
if($bean->load_relationship($field)){
$oldvalues = $bean->$field->get(true);
$role_field = $bean->$field->_get_link_table_role_field($bean->$field->_relationship_name);
foreach($link_field as $new_v){
if(!empty($new_v['id'])){
if(!empty($role_field)){
if(isset($new_v['primary']) && $new_v['primary']){
$bean->$field->add($new_v['id'], array($role_field=>'primary'));
}else{
$bean->$field->add($new_v['id'], array($role_field=>'NULL'));
}
}else{
$bean->$field->add($new_v['id'], array());
}
}
}
foreach($oldvalues as $old_v){
$match = false;
foreach($link_field as $new_v){
if($new_v['id'] == $old_v['id']){
$match = true;
}
}
if(!$match){
$bean->$field->delete($bean->id, $old_v['id']);
}
}
}
}
}
}
}
?>

View File

@@ -0,0 +1,499 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Collection/SugarFieldCollection.php');
class ViewSugarFieldCollection{
var $ss; // Sugar Smarty Object
var $bean;
var $bean_id;
var $name;
var $value_name;
var $displayParams; // DisplayParams for the collection field (defined in the metadata)
var $vardef; // vardef of the collection field.
var $related_module; // module name of the related module
var $module_dir; // name of the module where the collection field is.
var $numFields;
var $json;
var $tpl_path;
var $extra_var;
var $skipModuleQuickSearch = false;
var $field_to_name_array; //mapping of fields for the return of the select popup
var $showSelectButton = true;
var $hideShowHideButton = false;
var $action_type;
var $form_name;
function ViewSugarFieldCollection($fill_data = true){
$this->json = getJSONobj();
if($fill_data){
$this->displayParams = $this->json->decode(html_entity_decode($_REQUEST['displayParams']));
$this->vardef = $this->json->decode(html_entity_decode($_REQUEST['vardef']));
$this->module_dir = $_REQUEST['module_dir'];
$this->action_type = $_REQUEST['action_type'];
$this->name = $this->vardef['name'];
$this->value_name = $this->name . '_values';
$this->numFields = 1;
$this->ss = new Sugar_Smarty();
$this->edit_tpl_path = 'include/SugarFields/Fields/Collection/CollectionEditView.tpl';
$this->detail_tpl_path = 'include/SugarFields/Fields/Collection/CollectionDetailView.tpl';
$this->extra_var = array();
$this->field_to_name_array = array();
}
}
/*
* Retrieve the related module and load the bean and the relationship
* call retrieve values()
*/
function setup(){
if(!class_exists('Relationship')){
}
$rel = new Relationship();
if(!empty($this->vardef['relationship'])){
$rel->retrieve_by_name($this->vardef['relationship']);
}
if($rel->relationship_type == 'many-to-many'){
if($rel->lhs_module == $this->module_dir){
$this->related_module = $rel->rhs_module;
$module_dir = $rel->lhs_module;
}else if($rel->rhs_module == $this->module_dir){
$this->related_module = $rel->lhs_module;
$module_dir = $rel->rhs_module;
}else{
die("this field has no relationships mapped with this module");
}
if($module_dir != $this->module_dir){
die('These modules do not match : '. $this->module_dir . ' and ' . $module_dir);
}
if(isset($GLOBALS['beanList'][$this->module_dir])){
$class = $GLOBALS['beanList'][$this->module_dir];
if(file_exists($GLOBALS['beanFiles'][$class])){
$this->bean = loadBean($this->module_dir);
$this->bean->retrieve($_REQUEST['bean_id']);
if($this->bean->load_relationship($this->vardef['name'])){
$this->retrieve_values();
}else{
die('failed to load the relationship');
}
}else{
die('class file do not exist');
}
}else{
die($this->module_dir . ' is not in the beanList.');
}
}
else{
die("the relationship is not a many-to-many");
}
}
/*
* Retrieve the values from the DB using the get method of the link class
* Organize and save the value into the bean
*/
function retrieve_values(){
if(empty($this->bean->{$this->value_name}) && isset($this->bean->{$this->name})){
$values = array();
$values = $this->bean->{$this->name}->get(true);
$role_field = $this->bean->{$this->name}->_get_link_table_role_field($this->bean->{$this->name}->_relationship_name);
foreach($values as $v){
$role = '';
foreach($v as $kk=>$vv){
if($kk == $role_field){
$role=$vv;
}
}
if($role == 'primary'){
$primary_id = $v['id'];
}else{
$secondary_ids[] = array('id'=>$v['id'], 'role'=>$role);
}
}
$this->bean->{$this->value_name} = array('role_field'=>$role_field);
if(isset($primary_id) || isset($secondary_ids)){
if(!isset($primary_id)){
$primary_id = $secondary_ids[0]['id'];
unset($secondary_ids[0]);
}
if(isset($GLOBALS['beanList'][ $this->related_module])){
$class = $GLOBALS['beanList'][$this->related_module];
if(file_exists($GLOBALS['beanFiles'][$class])){
$mod = loadBean($this->module_dir);
$mod->relDepth = $this->bean->relDepth + 1;
$mod->retrieve($primary_id);
if (isset($mod->name)) {
$this->bean->{$this->value_name}=array_merge($this->bean->{$this->value_name}, array('primary'=>array('id'=>$primary_id, 'name'=>$mod->name)));
}
$secondaries = array();
if(isset($secondary_ids)){
foreach($secondary_ids as $v){
if($mod->retrieve($v['id'])){
if (isset($mod->name)){
$secondaries['secondaries'][]=array('id'=>$v['id'], 'name'=>$mod->name);
}
}
}
}
$this->bean->{$this->value_name}=array_merge($this->bean->{$this->value_name}, $secondaries);
if(isset($field['additionalFields'])){
foreach($field['additionalFields'] as $field=>$to){
if(isset($mod->$field)){
$this->bean->$to = $mod->$field;
}
}
}
}
}
}
}
}
/*
* redirect to the good process method.
*/
function process(){
if($this->action_type == 'editview'){
$this->process_editview();
}else if($this->action_type == 'detailview'){
$this->process_detailview();
}
}
function process_detailview(){
}
/*
* Build the DisplayParams array
*/
function process_editview(){
if(isset($this->bean->{$this->value_name}['secondaries'])){
$this->numFields=count($this->bean->{$this->value_name}['secondaries'])+1;
}
if(!isset($this->displayParams['readOnly'])) {
$this->displayParams['readOnly'] = '';
} else {
$this->displayParams['readOnly'] = $this->displayParams['readOnly'] == false ? '' : 'READONLY';
}
// If there is extra field to show.
if(isset($this->displayParams['collection_field_list'])){
require_once('include/SugarFields/SugarFieldHandler.php');
$sfh = new SugarFieldHandler();
vardefmanager::loadVardef($this->related_module, $GLOBALS['beanList'][$this->related_module]);
foreach($this->displayParams['collection_field_list'] as $k=>$v){
$javascript='';
$collection_field_vardef = $GLOBALS['dictionary'][$GLOBALS['beanList'][$this->related_module]]['fields'][$v['name']];
// For each extra field the params which are not displayParams will be consider as params to override the vardefs values.
foreach($v as $k_override=>$v_override){
if($k_override != 'displayParams'){
$collection_field_vardef[$k_override] = $v_override;
}
}
// If relate field : enable quick search by creating the sqs_object array.
if($collection_field_vardef['type'] == 'relate'){
require_once('include/TemplateHandler/TemplateHandler.php');
$tph = new TemplateHandler();
$javascript = $tph->createQuickSearchCode(array($collection_field_vardef['name']=>$collection_field_vardef), array($v), $this->form_name);
$javascript = str_replace('<script language="javascript">'."if(typeof sqs_objects == 'undefined'){var sqs_objects = new Array;}sqs_objects['{$collection_field_vardef['name']}']=","",$javascript);
$javascript = substr($javascript, 0, -10);//remove ";</script>"
$javascriptPHP = $this->json->decode($javascript);
foreach($javascriptPHP['populate_list'] as $kk=>$vv){
$javascriptPHP['populate_list'][$kk] .= "_" . $this->vardef['name'] . "_collection_extra_0";
}
foreach($javascriptPHP['required_list'] as $kk=>$vv){
$javascriptPHP['required_list'][$kk] .= "_" . $this->vardef['name'] . "_collection_extra_0";
}
foreach($javascriptPHP['field_list'] as $kk=>$vv){
if($vv == 'id'){
$javascriptPHP['populate_list'][$kk];
}
}
$javascript = $this->json->encode($javascriptPHP);
$javascript = "<script language='javascript'>if(typeof sqs_objects == 'undefined'){var sqs_objects = new Array;}sqs_objects['{$collection_field_vardef['name']}_" . $this->vardef['name'] . "_collection_extra_0']=".$javascript.';</script>';
}
$collection_field_vardef['name'] .= "_" . $this->vardef['name'] . "_collection_extra_0";
if(isset($collection_field_vardef['id_name'])){
$collection_field_vardef['id_name'] .= "_" . $this->vardef['name'] . "_collection_extra_0";
}
if(isset($this->displayParams['allow_update']) && ($this->displayParams['allow_update'] === false || $this->displayParams['allow_update'] === 'false')){
$this->displayParams['allow_update']='false';
$v['displayParams']['field']['disabled']='';
}else{
$this->displayParams['allow_update']='true';
if(!isset($v['displayParams'])){
$v['displayParams']=array();
}
}
$viewtype='EditView';
$name = $collection_field_vardef['name'];
// Rearranging the array with name as key instaead of number. This is required for displaySmarty() to assign the good variable.
$this->displayParams['collection_field_list'][$name]['vardefName'] = $this->displayParams['collection_field_list'][$k]['name'];
$this->displayParams['collection_field_list'][$name]['name'] = $name;
if($collection_field_vardef['type'] == 'relate'){
$this->displayParams['collection_field_list'][$name]['id_name'] = $collection_field_vardef['id_name'];
$this->displayParams['collection_field_list'][$name]['module'] = $collection_field_vardef['module'];
}
$this->displayParams['collection_field_list'][$name]['label'] = "{sugar_translate label='{$collection_field_vardef['vname']}' module='{$this->related_module}'}";//translate($collection_field_vardef['vname'], $this->related_module);
$this->displayParams['collection_field_list'][$name]['field'] = $sfh->displaySmarty('displayParams.collection_field_list', $collection_field_vardef, $viewtype, $v['displayParams'], 1);
$this->displayParams['collection_field_list'][$name]['field'] .= '{literal}'.$javascript;
// Handle update_field array ONCHANGE
$this->displayParams['collection_field_list'][$name]['field'] .= <<<FRA
<script language='javascript'>
var oldonchange = '';
if(typeof(document.getElementById('{$collection_field_vardef['name']}').attributes.onchange) != 'undefined')
{
oldonchange=document.getElementById('{$collection_field_vardef['name']}').attributes.onchange.value;
}
FRA;
$this->displayParams['collection_field_list'][$name]['field'] .= "eval(\"document.getElementById('{$collection_field_vardef['name']}').onchange = function onchange(event){collection['{$this->vardef['name']}'].update_fields.{$collection_field_vardef['name']}=true;";
if($collection_field_vardef['type'] == 'relate'){
// If relate add the ID field to the array
$this->displayParams['collection_field_list'][$name]['field'] .= "collection['{$this->vardef['name']}'].update_fields.{$collection_field_vardef['id_name']}=true;";
}
$this->displayParams['collection_field_list'][$name]['field'] .= "document.getElementById('update_fields_{$this->vardef['name']}_collection').value = JSON.stringifyNoSecurity(collection['{$this->vardef['name']}'].update_fields);\" + oldonchange + \"};\");</script>{/literal}";
//we need to get rid of the old value;
unset($this->displayParams['collection_field_list'][$k]);
}
}
if(!isset($this->displayParams['class'])) $this->displayParams['class']='';
if(isset($this->displayParams['allow_new']) && ($this->displayParams['allow_new'] === false || $this->displayParams['allow_new'] === 'false')){
$this->displayParams['allow_new']='false';
$this->displayParams['class']=str_replace('sqsNoAutofill','',$this->displayParams['class']);
}else{
$this->displayParams['allow_new']='true';
$this->displayParams['class'].=' sqsNoAutofill';
}
if(isset($this->displayParams['new_on_update']) && ($this->displayParams['new_on_update'] !== false || $this->displayParams['new_on_update'] !== 'false' || $this->displayParams['new_on_update'] !== 'FALSE' || $this->displayParams['new_on_update'] !== '0')){
$this->displayParams['new_on_update']='true';
}else{
$this->displayParams['new_on_update']='false';
}
}
/*
* Init the template with the variables
*/
function init_tpl(){
foreach($this->extra_var as $k=>$v){
$this->ss->assign($k,$v);
}
if($this->action_type == 'editview'){
$this->ss->assign('quickSearchCode',$this->createQuickSearchCode());
$this->createPopupCode();// this code populate $this->displayParams with popupdata.
$this->tpl_path = $this->edit_tpl_path;
}else if($this->action_type == 'detailview'){
$this->tpl_path = $this->detail_tpl_path;
}
$this->ss->assign('displayParams',$this->displayParams);
$this->ss->assign('vardef',$this->vardef);
$this->ss->assign('module',$this->related_module);
$this->ss->assign('values',$this->bean->{$this->value_name});
$this->ss->assign('showSelectButton',$this->showSelectButton);
$this->ss->assign('hideShowHideButton',$this->hideShowHideButton);
$this->ss->assign('APP',$GLOBALS['app_strings']);
}
/*
* Display the collection field after retrieving the cached row.
*/
function display(){
$cacheRowFile = $GLOBALS['sugar_config']['cache_dir'] . 'modules/'. $this->module_dir . '/collections/'. $this->name . '.tpl';
if(!$this->checkTemplate($cacheRowFile)){
$dir = dirname($cacheRowFile);
if(!file_exists($dir)) {
mkdir_recursive($dir, null, true);
}
$cacheRow = $this->ss->fetch('include/SugarFields/Fields/Collection/CollectionEditViewRow.tpl');
file_put_contents($cacheRowFile, $cacheRow);
}
$this->ss->assign('cacheRowFile', $cacheRowFile);
return $this->ss->fetch($this->tpl_path);
}
/*
* Check if the template is cached
* return a bool
*/
function checkTemplate($cacheRowFile){
if(!empty($GLOBALS['sugar_config']['developerMode']) || !empty($_SESSION['developerMode'])){
return false;
}
return file_exists($cacheRowFile);
}
/*
* Create the quickSearch code for the collection field.
* return the javascript code which define sqs_objects.
*/
function createQuickSearchCode($returnAsJavascript = true){
$sqs_objects = array();
require_once('include/QuickSearchDefaults.php');
$qsd = new QuickSearchDefaults();
$qsd->setFormName($this->form_name);
for($i=0; $i<$this->numFields; $i++){
$name1 = "{$this->form_name}_{$this->name}_collection_{$i}";
if(!$this->skipModuleQuickSearch && preg_match('/(Campaigns|Teams|Users|Contacts|Accounts)/si', $this->related_module, $matches)) {
if($matches[0] == 'Users'){
$sqs_objects[$name1] = $qsd->getQSUser();
} else if($matches[0] == 'Campaigns') {
$sqs_objects[$name1] = $qsd->getQSCampaigns();
} else if($matches[0] == 'Users'){
$sqs_objects[$name1] = $qsd->getQSUser();
} else if($matches[0] == 'Accounts') {
$nameKey = "{$this->name}_collection_{$i}";
$idKey = "id_{$this->name}_collection_{$i}";
//There are billingKey, registerKey and additionalFields entries you can define in editviewdefs.php
//entry to allow quick search to autocomplete fields with a suffix value of the
//billing/registerKey value (i.e. 'billingKey' => 'primary' in Contacts will populate
//primary_XXX fields with the Account's billing address values).
//addtionalFields are key/value pair of fields to fill from Accounts(key) to Contacts(value)
$billingKey = isset($this->displayParams['billingKey']) ? $this->displayParams['billingKey'] : null;
$registerKey = isset($this->displayParams['registerKey']) ? $this->displayParams['registerKey'] : null;
$additionalFields = isset($this->displayParams['additionalFields']) ? $this->displayParams['additionalFields'] : null;
$sqs_objects[$name1] = $qsd->getQSAccount($nameKey, $idKey, $billingKey, $registerKey, $additionalFields);
} else if($matches[0] == 'Contacts'){
$sqs_objects[$name1] = $qsd->getQSContact($name1, "id_".$name1);
}
$temp_array = array('field_list'=>array(),'populate_list'=>array());
foreach($sqs_objects[$name1]['field_list'] as $k=>$v){
if(!in_array($v, array('name','id'))){
$sqs_objects[$name1]['primary_field_list'][]=$v;
$sqs_objects[$name1]['primary_populate_list'][]=$sqs_objects[$name1]['populate_list'][$k];
}else{
$temp_array['field_list'][]=$v;
$temp_array['populate_list'][]=$sqs_objects[$name1]['populate_list'][$k];
}
}
$sqs_objects[$name1]['field_list'] = $temp_array['field_list'];
$sqs_objects[$name1]['populate_list'] = $temp_array['populate_list'];
if(isset($this->displayParams['collection_field_list'])){
foreach($this->displayParams['collection_field_list'] as $v){
$sqs_objects[$name1]['populate_list'][]= $v['vardefName']."_".$this->name."_collection_extra_".$i;
$sqs_objects[$name1]['field_list'][] = $v['vardefName'];
}
}
}else {
$sqs_objects[$name1] = $qsd->getQSParent($this->related_module);
$sqs_objects[$name1]['populate_list'] = array("{$this->vardef['name']}_collection_{$i}", "id_{$this->vardef['name']}_collection_{$i}");
$sqs_objects[$name1]['field_list'] = array('name', 'id');
if(isset($this->displayParams['collection_field_list'])){
foreach($this->displayParams['collection_field_list'] as $v){
$sqs_objects[$name1]['populate_list'][] = $v['vardefName']."_".$this->name."_collection_extra_".$i;
$sqs_objects[$name1]['field_list'][] = $v['vardefName'];
}
}
if(isset($this->displayParams['field_to_name_array'])){
foreach($this->displayParams['field_to_name_array'] as $k=>$v){
/*
* "primary_populate_list" and "primary_field_list" are used when the field is selected as a primary.
* At this time the JS function changePrimary() will copy "primary_populate_list" and "primary_field_list"
* into "populate_list" and "field_list" and remove the values from all the others which are secondaries.
* "primary_populate_list" and "primary_field_list" contain the fields which has to be populated outside of
* the collection field. For example the "Address Information" are populated with the "billing address" of the
* selected account in a contact editview.
*/
$sqs_objects[$name1]['primary_populate_list'][] = $v;
$sqs_objects[$name1]['primary_field_list'][] = $k;
}
}else if(isset($field['field_list']) && isset($field['populate_list'])){
$sqs_objects[$name1]['primary_populate_list'] = array_merge($sqs_objects[$name1]['populate_list'], $field['field_list']);
$sqs_objects[$name1]['primary_field_list'] = array_merge($sqs_objects[$name1]['field_list'], $field['populate_list']);
}else{
$sqs_objects[$name1]['primary_populate_list'] = array();
$sqs_objects[$name1]['primary_field_list'] = array();
}
}
}
$id = "{$this->form_name}_{$this->name}_collection_0";
if(!empty($sqs_objects) && count($sqs_objects) > 0) {
foreach($sqs_objects[$id]['field_list'] as $k=>$v){
$this->field_to_name_array[$v] = $sqs_objects[$id]['populate_list'][$k];
}
if($returnAsJavascript){
$quicksearch_js = '<script language="javascript">';
$quicksearch_js.= "if(typeof sqs_objects == 'undefined'){var sqs_objects = new Array;}";
foreach($sqs_objects as $sqsfield=>$sqsfieldArray){
$quicksearch_js .= "sqs_objects['$sqsfield']={$this->json->encode($sqsfieldArray)};";
}
return $quicksearch_js .= '</script>';
}else{
return $sqs_objects;
}
}
return '';
}
/*
* Always call createQuickSearchCode() before createPopupCode() to define field_to_name_array
*/
function createPopupCode(){
// TODO the 'select' button is not fully working. We should use the sqs_objects in open_popup instead of the parameter.
if(isset($this->field_to_name_array) && !empty($this->field_to_name_array)){
$call_back_function = 'set_return';
if(isset($this->displayParams['formName'])) {
$form = $this->displayParams['formName'];
} else if($this->action_type == 'editview'){
$form = 'EditView';
} else if($this->action_type == 'quickcreate'){
$form = "QuickCreate_{$this->module_dir}";
}
if(isset($this->displayParams['call_back_function'])) {
$call_back_function = $this->displayParams['call_back_function'];
}
$popup_request_data= array(
'call_back_function' => $call_back_function,
'form_name' => $form,
'field_to_name_array' => $this->field_to_name_array,
);
//Make sure to replace {{ and }} with spacing in between because Smarty template parsing will treat {{ or }} specially
$this->displayParams['popupData'] = '{literal}'. str_replace(array('{{', '}}'), array('{ {', '} }'), $this->json->encode($popup_request_data)) . '{/literal}';
}
}
}
?>

View File

@@ -0,0 +1,42 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Collection/ViewSugarFieldCollection.php');
$view = new ViewSugarFieldCollection();
$view->setup();
$view->process();
$view->init_tpl();
echo $view->display();
?>

View File

@@ -0,0 +1,59 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Float/SugarFieldFloat.php');
class SugarFieldCurrency extends SugarFieldFloat {
function getListViewSmarty($parentFieldArray, $vardef, $displayParams, $col) {
$tabindex = 1;
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex, false);
$this->ss->left_delimiter = '{';
$this->ss->right_delimiter = '}';
$this->ss->assign('col',strtoupper($vardef['name']));
if(is_object($parentFieldArray) ){
if(!empty($parentFieldArray->currency_id)) {
$this->ss->assign('currency_id',$parentFieldArray->currency_id);
}
} else if (!empty($parentFieldArray['CURRENCY_ID'])) {
$this->ss->assign('currency_id',$parentFieldArray['CURRENCY_ID']);
} else if (!empty($parentFieldArray['currency_id'])) {
$this->ss->assign('currency_id',$parentFieldArray['currency_id']);
}
return $this->fetch($this->findTemplate('ListView'));
}
}

View File

@@ -0,0 +1,115 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldDatetime extends SugarFieldBase {
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
// Create Smarty variables for the Calendar picker widget
if(!isset($displayParams['showMinutesDropdown'])) {
$displayParams['showMinutesDropdown'] = false;
}
if(!isset($displayParams['showHoursDropdown'])) {
$displayParams['showHoursDropdown'] = false;
}
if(!isset($displayParams['showNoneCheckbox'])) {
$displayParams['showNoneCheckbox'] = false;
}
if(!isset($displayParams['showFormats'])) {
$displayParams['showFormats'] = false;
}
if(!isset($displayParams['hiddeCalendar'])) {
$displayParams['hiddeCalendar'] = false;
}
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
//jchi , bug #24557 , 10/31/2008
if(isset($vardef['name']) && ($vardef['name'] == 'date_entered' || $vardef['name'] == 'date_modified')){
return $this->fetch('include/SugarFields/Fields/Base/DetailView.tpl');
}
//end
return $this->fetch('include/SugarFields/Fields/Datetime/SearchView.tpl');
}
function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
// Create Smarty variables for the Calendar picker widget
if(!isset($displayParams['showMinutesDropdown'])) {
$displayParams['showMinutesDropdown'] = false;
}
if(!isset($displayParams['showHoursDropdown'])) {
$displayParams['showHoursDropdown'] = false;
}
if(!isset($displayParams['showNoneCheckbox'])) {
$displayParams['showNoneCheckbox'] = false;
}
if(!isset($displayParams['showFormats'])) {
$displayParams['showFormats'] = false;
}
if(!isset($displayParams['hiddeCalendar'])) {
$displayParams['hiddeCalendar'] = false;
}
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
//jchi , bug #24557 , 10/31/2008
if(isset($vardef['name']) && ($vardef['name'] == 'date_entered' || $vardef['name'] == 'date_modified')){
return $this->fetch('include/SugarFields/Fields/Base/DetailView.tpl');
}
//end
return $this->fetch('include/SugarFields/Fields/Datetime/EditView.tpl');
}
public function save(&$bean, &$inputData, &$field, &$def, $prefix = '') {
global $timedate;
if ( !isset($inputData[$prefix.$field]) ) {
return;
}
$offset = strlen(trim($inputData[$prefix.$field])) < 11 ? false : true;
$bean->$field = $timedate->to_db_date($inputData[$prefix.$field], $offset);
}
}
?>

View File

@@ -0,0 +1,109 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldDatetimecombo extends SugarFieldBase {
function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
// Create Smarty variables for the Calendar picker widget
if(!isset($displayParams['showMinutesDropdown'])) {
$displayParams['showMinutesDropdown'] = false;
}
if(!isset($displayParams['showHoursDropdown'])) {
$displayParams['showHoursDropdown'] = false;
}
if(!isset($displayParams['showNoneCheckbox'])) {
$displayParams['showNoneCheckbox'] = false;
}
if(!isset($displayParams['showFormats'])) {
$displayParams['showFormats'] = false;
}
global $timedate;
$displayParams['dateFormat'] = $timedate->get_cal_date_format();
$displayParams['timeFormat'] = $timedate->get_user_time_format();
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Datetimecombo/EditView.tpl');
}
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
// Create Smarty variables for the Calendar picker widget
if(!isset($displayParams['showMinutesDropdown'])) {
$displayParams['showMinutesDropdown'] = false;
}
if(!isset($displayParams['showHoursDropdown'])) {
$displayParams['showHoursDropdown'] = false;
}
if(!isset($displayParams['showNoneCheckbox'])) {
$displayParams['showNoneCheckbox'] = false;
}
if(!isset($displayParams['showFormats'])) {
$displayParams['showFormats'] = false;
}
global $timedate;
$displayParams['dateFormat'] = $timedate->get_cal_date_format();
$displayParams['timeFormat'] = $timedate->get_user_time_format();
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Datetimecombo/SearchView.tpl');
}
public function save(&$bean, &$inputData, &$field, &$def, $prefix = '') {
global $timedate;
if ( !isset($inputData[$prefix.$field]) ) {
//$bean->$field = '';
return;
}
if(strpos($inputData[$prefix.$field], ' ') > 0) {
$bean->$field = $timedate->to_db($inputData[$prefix.$field]);
} else {
$GLOBALS['log']->error('Field ' . $prefix.$field . ' expecting datetime format, but got value: ' . $inputData[$prefix.$field]);
//Default to assume date format value
$bean->$field = $timedate->to_db_date($inputData[$prefix.$field]);
}
}
}
?>

View File

@@ -0,0 +1,54 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldDownload extends SugarFieldBase {
function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$vardef['value'] = urlencode(basename($vardef['value']));
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Download/DetailView.tpl');
}
function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$vardef['value'] = urlencode(basename($vardef['value']));
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Download/EditView.tpl');
}
}
?>

View File

@@ -0,0 +1,106 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldEnum extends SugarFieldBase {
function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
if(!empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html'){
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return "<span id='{$vardef['name']}'>" . $this->fetch('include/SugarFields/Fields/Enum/DetailViewFunction.tpl') . '</span>';
}else{
return parent::getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
}
}
function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
if(empty($displayParams['size'])) {
$displayParams['size'] = 6;
}
if(isset($vardef['function']) && !empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html'){
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Enum/EditViewFunction.tpl');
}else{
return parent::getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
}
}
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
if(empty($displayParams['size'])) {
$displayParams['size'] = 6;
}
if(!empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html'){
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Enum/EditViewFunction.tpl');
}else{
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Enum/SearchView.tpl');
}
}
function displayFromFunc( $displayType, $parentFieldArray, $vardef, $displayParams, $tabindex ) {
if ( isset($vardef['function']['returns']) && $vardef['function']['returns'] == 'html' ) {
return parent::displayFromFunc($displayType, $parentFieldArray, $vardef, $displayParams, $tabindex);
}
$displayTypeFunc = 'get'.$displayType.'Smarty';
return $this->$displayTypeFunc($parentFieldArray, $vardef, $displayParams, $tabindex);
}
public function formatField($rawField, $vardef){
global $app_list_strings;
if(!empty($vardef['options'])){
$option_array_name = $vardef['options'];
if(!empty($app_list_strings[$option_array_name][$rawField])){
return $app_list_strings[$option_array_name][$rawField];
}else {
return $rawField;
}
} else {
return $rawField;
}
}
}
?>

View File

@@ -0,0 +1,103 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once ('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldFile extends SugarFieldBase
{
function getDataForDetaiLView ()
{}
function getDetailViewSmarty ($parentFieldArray, $vardef, $displayParams,
$tabindex)
{
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/File/DetailView.tpl');
}
public function save (&$bean, $params, $field, $properties, $prefix = '')
{
global $sugar_config;
// only save relation here
// file save on ajax request crm/uploadAjaxFile.php
if ($_POST[$field . '_newname'] != '') {
var_dump($_POST[$field . '_newname']);
if($bean->id==''){
$bean->id = create_guid();
$bean->new_with_id = true;
}
$bean->$field='';
foreach ($_POST[$field . '_newname'] as $key => $value) {
$target_file = $sugar_config['upload_dir'] . basename($value);
if (file_exists($target_file)) {
$Revision = new DocumentRevision();
$Revision->retrieve($value);
if($Revision->id==''){
$Revision = new DocumentRevision();
$Revision->change_log = 'test';
$Revision->revision = 1;
$Revision->document_id = $bean->id;
$Revision->filename = $_POST[$field . '_orginal'][$key];
$Revision->file_ext = pathinfo(
$_POST[$field . '_orginal'][$key],
PATHINFO_EXTENSION);
$Revision->file_mime_type = $_POST[$field . '_type'][$key];
$Revision->save();
// change id bc $Revision->id=$value; bug
$GLOBALS['db']->query(
"update document_revisions set id='" . $value .
"' where id='" . $Revision->id . "'");
$success = true;
$bean->$field.=$_POST[$field . '_orginal'][$key].':'.$_POST[$field . '_newname'][$key].':'.$_POST[$field . '_type'][$key].';';
} else {
$bean->$field.=$_POST[$field . '_orginal'][$key].':'.$_POST[$field . '_newname'][$key].':'.$_POST[$field . '_type'][$key].';';
}
}
}
echo 'nowe: '.$bean->$field;
// die();
}
}
}
?>

View File

@@ -0,0 +1,67 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Int/SugarFieldInt.php');
class SugarFieldFloat extends SugarFieldInt {
public function formatField($rawField, $vardef){
// A null precision uses the user prefs / system prefs by default
$precision = null;
if ( isset($vardef['precision']) ) {
$precision = $vardef['precision'];
}
if ( $rawField === '' || $rawField === NULL ) {
return '';
}
if($vardef['name']=='QUANTITY' || 'STATE'==$vardef['name']){
return $rawField;
} else {
return format_number($rawField,$precision,$precision);
}
}
public function unformatField($formattedField, $vardef){
if ( $formattedField === '' || $formattedField === NULL ) {
return '';
}
return (float)unformat_number($formattedField);
}
}

View File

@@ -0,0 +1,45 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldFullname extends SugarFieldBase {
function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Fullname/DetailView.tpl');
}
}
?>

View File

@@ -0,0 +1,72 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldHtml extends SugarFieldBase {
function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex){
$vardef['value'] = $this->getVardefValue($vardef);
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Html/DetailView.tpl');
}
function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex){
$vardef['value'] = $this->getVardefValue($vardef);
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Html/DetailView.tpl');
}
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$vardef['value'] = $this->getVardefValue($vardef);
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Html/DetailView.tpl');
}
function getVardefValue($vardef){
if(empty($vardef['value'])){
if(!empty($vardef['default']))
return from_html($vardef['default']);
elseif(!empty($vardef['default_value']))
return from_html($vardef['default_value']);
} else {
return from_html($vardef['value']);
}
}
}
?>

View File

@@ -0,0 +1,71 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
require_once('modules/Currencies/Currency.php');
class SugarFieldInt extends SugarFieldBase {
public function formatField($rawField, $vardef){
if ( !empty($vardef['disable_num_format']) ) {
return $rawField;
}
if ( $rawField === '' || $rawField === NULL ) {
return '';
}
return format_number($rawField,0,0);
}
public function unformatField($formattedField, $vardef){
if ( $formattedField === '' || $formattedField === NULL ) {
return '';
}
return (int)unformat_number($formattedField);
}
public function unformatSearchRequest(&$inputData, &$field) {
$field['value'] = $this->unformatField($field['value'],$field);
}
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
// Use the basic field type for searches, no need to format/unformat everything... for now
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Int/SearchForm.tpl');
}
}

View File

@@ -0,0 +1,66 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldMultienum extends SugarFieldBase {
function setup($parentFieldArray, $vardef, $displayParams, $tabindex, $twopass=true) {
if ( !isset($vardef['options_list']) && isset($vardef['options']) && !is_array($vardef['options'])) {
$vardef['options_list'] = $GLOBALS['app_list_strings'][$vardef['options']];
}
return parent::setup($parentFieldArray, $vardef, $displayParams, $tabindex, $twopass);
}
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
if(!empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html'){
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Multienum/EditViewFunction.tpl');
}else{
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Multienum/SearchView.tpl');
}
}
public function save(&$bean, $params, $field, $properties, $prefix = ''){
if ( isset($params[$prefix.$field]) ) {
if($params[$prefix.$field][0] === '' && !empty($params[$prefix.$field][1]) ) {
unset($params[$prefix.$field][0]);
}
$bean->$field = encodeMultienumValue($params[$prefix.$field]);
}
}
}

View File

@@ -0,0 +1,128 @@
<?php
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldNew_phone extends SugarFieldBase
{
public function formatField($rawField, $vardef)
{
if (empty($rawField)) return $rawField;
$fields = explode('^|^', $rawField);
$params = array('',0,0,'');
foreach($fields as $field)
{
$params = explode('^,^', $field);
if (intval($params[1]) == 1) return $params[0];
}
return $params[0];
}
function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex)
{
global $app_strings;
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/New_phone/DetailView.tpl');
}
function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex)
{
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/New_phone/EditView.tpl');
}
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex)
{
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/New_phone/SearchView.tpl');
}
public function save(&$bean, $params, $field, $properties, $prefix = '')
{
global $module;
$prefix = $module . 'phoneFlag';
$phones = array();
//сохраняем номер телефона
foreach ($params as $key => $val)
{
if (strpos($key, $prefix . '0_') === 0)
{
$new_key = intval(str_replace($prefix . '0_', '', $key));
if (empty($val)) continue; //Это пустая запись не будем сохранять ее
if (!isset($first_key)) $first_key = $new_key;
$phones[$new_key] = array(
0 => $val,
1 => 0,
2 => 0,
3 => '',
4 => $this->only_digit($val),
);
}
}
//сохраняем селект атрибуты
foreach ($params as $key => $val)
{
if (strpos($key, $prefix . '3_') === 0)
{
$new_key = intval(str_replace($prefix . '3_', '', $key));
if (empty($val)) continue; //Это пустая запись не будем сохранять ее
if (isset($phones[$new_key]) AND !empty($phones[$new_key])) $phones[$new_key][3] = $val;
}
}
if (!empty($phones))
{
//Основной
if (isset($params[$prefix . '1']))
{
$key = intval($params[$prefix . '1']);
if (isset($phones[$key])) $phones[$key][1] = 1;
else $phones[$first_key][1] = 1;
}
else
{
$phones[$first_key][1] = 1;
}
// Все чекбокс атрибуты
for ($i = 2; $i <= 2; $i++) // он у нас только один (не звонить), но вообще сделано универсально, можно добавить атрибуты
{
if (isset($params[$prefix . $i]) and is_array($params[$prefix . $i]))
{
foreach ($params[$prefix . $i] as $value)
{
$intval = intval($value);
if (isset($phones[$intval])) $phones[$intval][$i] = 1;
}
}
}
$ext_phone = array();
foreach ($phones as $key => $val)
{
$ext_phone[] = join('^,^', $val);
}
$bean->$field = join('^|^', $ext_phone);
}
else
{
$bean->$field = '';
}
}
private function only_digit($phone)
{
$pattern = '/[^0-9]*/';
return preg_replace($pattern, '', $phone);
}
}
?>

View File

@@ -0,0 +1,121 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldParent extends SugarFieldBase {
function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$nolink = array('Users', 'Teams');
if(in_array($vardef['module'], $nolink)){
$this->ss->assign('nolink', true);
}else{
$this->ss->assign('nolink', false);
}
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Parent/DetailView.tpl');
}
function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$form_name = 'EditView';
if(isset($displayParams['formName'])) {
$form_name = $displayParams['formName'];
}
$popup_request_data = array(
'call_back_function' => 'set_return',
'form_name' => $form_name,
'field_to_name_array' => array(
'id' => $vardef['id_name'],
'name' => $vardef['name'],
),
);
global $app_list_strings;
$parent_types = $app_list_strings['record_type_display'];
$disabled_parent_types = ACLController::disabledModuleList($parent_types,false, 'list');
foreach($disabled_parent_types as $disabled_parent_type){
if($disabled_parent_type != $focus->parent_type){
unset($parent_types[$disabled_parent_type]);
}
}
asort($parent_types);
$json = getJSONobj();
$displayParams['popupData'] = '{literal}'.$json->encode($popup_request_data).'{/literal}';
$displayParams['disabled_parent_types'] = '<script>var disabledModules='. $json->encode($disabled_parent_types).';</script>';
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Parent/EditView.tpl');
}
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$form_name = 'search_form';
if(isset($displayParams['formName'])) {
$form_name = $displayParams['formName'];
}
$this->ss->assign('form_name', $form_name);
$popup_request_data = array(
'call_back_function' => 'set_return',
'form_name' => $form_name,
'field_to_name_array' => array(
'id' => $vardef['id_name'],
'name' => $vardef['name'],
),
);
global $app_list_strings;
$parent_types = $app_list_strings['record_type_display'];
$disabled_parent_types = ACLController::disabledModuleList($parent_types,false, 'list');
foreach($disabled_parent_types as $disabled_parent_type){
if($disabled_parent_type != $focus->parent_type){
unset($parent_types[$disabled_parent_type]);
}
}
$json = getJSONobj();
$displayParams['popupData'] = '{literal}'.$json->encode($popup_request_data).'{/literal}';
$displayParams['disabled_parent_types'] = '<script>var disabledModules='. $json->encode($disabled_parent_types).';</script>';
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Parent/SearchView.tpl');
}
}
?>

View File

@@ -0,0 +1,44 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldReadonly extends SugarFieldBase {
function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
return $this->getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
}
}
?>

View File

@@ -0,0 +1,256 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldRelate extends SugarFieldBase {
function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$nolink = array('Users', 'Teams');
if(in_array($vardef['module'], $nolink)){
$this->ss->assign('nolink', true);
}else{
$this->ss->assign('nolink', false);
}
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Relate/DetailView.tpl');
}
function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
if(!empty($vardef['function']['returns']) && $vardef['function']['returns'] == 'html'){
return parent::getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
}
$call_back_function = 'set_return';
if(isset($displayParams['call_back_function'])) {
$call_back_function = $displayParams['call_back_function'];
}
$form_name = 'EditView';
if(isset($displayParams['formName'])) {
$form_name = $displayParams['formName'];
}
//Special Case for accounts; use the displayParams array and retrieve
//the key and copy indexes. 'key' is the suffix of the field we are searching
//the Account's address with. 'copy' is the suffix we are copying the addresses
//form fields into.
if(isset($vardef['module']) && preg_match('/Accounts/si',$vardef['module'])
&& isset($displayParams['key']) && isset($displayParams['copy'])) {
if(isset($displayParams['key']) && is_array($displayParams['key'])) {
$database_key = $displayParams['key'];
} else {
$database_key[] = $displayParams['key'];
}
if(isset($displayParams['copy']) && is_array($displayParams['copy'])) {
$form = $displayParams['copy'];
} else {
$form[] = $displayParams['copy'];
}
if(count($database_key) != count($form)) {
global $app_list_strings;
$this->ss->trigger_error($app_list_strings['ERR_SMARTY_UNEQUAL_RELATED_FIELD_PARAMETERS']);
} //if
$copy_phone = isset($displayParams['copyPhone']) ? $displayParams['copyPhone'] : true;
$field_to_name = array();
$field_to_name['id'] = $vardef['id_name'];
$field_to_name['name'] = $vardef['name'];
$address_fields = array('_address_street', '_address_city', '_address_state', '_address_postalcode', '_address_country');
$count = 0;
foreach($form as $f) {
foreach($address_fields as $afield) {
$field_to_name[$database_key[$count] . $afield] = $f . $afield;
}
$count++;
}
$popup_request_data = array(
'call_back_function' => $call_back_function,
'form_name' => $form_name,
'field_to_name_array' => $field_to_name,
);
if($copy_phone) {
$popup_request_data['field_to_name_array']['phone_office'] = 'phone_work';
}
} elseif(isset($displayParams['field_to_name_array'])) {
$popup_request_data = array(
'call_back_function' => $call_back_function,
'form_name' => $form_name,
'field_to_name_array' => $displayParams['field_to_name_array'],
);
} else {
$popup_request_data = array(
'call_back_function' => $call_back_function,
'form_name' => $form_name,
'field_to_name_array' => array(
'id' => (empty($displayParams['idName']) ? $vardef['id_name'] : ($displayParams['idName'] . '_' . $vardef['id_name'])) ,
((empty($vardef['rname'])) ? 'name' : $vardef['rname']) => (empty($displayParams['idName']) ? $vardef['name'] : $displayParams['idName']),
),
);
}
$json = getJSONobj();
$displayParams['popupData'] = '{literal}'.$json->encode($popup_request_data). '{/literal}';
if(!isset($displayParams['readOnly'])) {
$displayParams['readOnly'] = '';
} else {
$displayParams['readOnly'] = $displayParams['readOnly'] == false ? '' : 'READONLY';
}
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Relate/EditView.tpl');
}
function getPopupViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex){
$displayParams['clearOnly'] = true;
return $this->getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
}
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$call_back_function = 'set_return';
if(isset($displayParams['call_back_function'])) {
$call_back_function = $displayParams['call_back_function'];
}
$form_name = 'search_form';
if(isset($displayParams['formName'])) {
$form_name = $displayParams['formName'];
}
if(!empty($vardef['rname']) && $vardef['rname'] == 'user_name'){
$displayParams['useIdSearch'] = true;
}
//Special Case for accounts; use the displayParams array and retrieve
//the key and copy indexes. 'key' is the suffix of the field we are searching
//the Account's address with. 'copy' is the suffix we are copying the addresses
//form fields into.
if(isset($vardef['module']) && preg_match('/Accounts/si',$vardef['module'])
&& isset($displayParams['key']) && isset($displayParams['copy'])) {
if(isset($displayParams['key']) && is_array($displayParams['key'])) {
$database_key = $displayParams['key'];
} else {
$database_key[] = $displayParams['key'];
}
if(isset($displayParams['copy']) && is_array($displayParams['copy'])) {
$form = $displayParams['copy'];
} else {
$form[] = $displayParams['copy'];
}
if(count($database_key) != count($form)) {
global $app_list_strings;
$this->ss->trigger_error($app_list_strings['ERR_SMARTY_UNEQUAL_RELATED_FIELD_PARAMETERS']);
} //if
$copy_phone = isset($displayParams['copyPhone']) ? $displayParams['copyPhone'] : true;
$field_to_name = array();
$field_to_name['id'] = $vardef['id_name'];
$field_to_name['name'] = $vardef['name'];
$address_fields = array('_address_street', '_address_city', '_address_state', '_address_postalcode', '_address_country');
$count = 0;
foreach($form as $f) {
foreach($address_fields as $afield) {
$field_to_name[$database_key[$count] . $afield] = $f . $afield;
}
$count++;
}
$popup_request_data = array(
'call_back_function' => $call_back_function,
'form_name' => $form_name,
'field_to_name_array' => $field_to_name,
);
if($copy_phone) {
$popup_request_data['field_to_name_array']['phone_office'] = 'phone_work';
}
} elseif(isset($displayParams['field_to_name_array'])) {
$popup_request_data = array(
'call_back_function' => $call_back_function,
'form_name' => $form_name,
'field_to_name_array' => $displayParams['field_to_name_array'],
);
} else {
$popup_request_data = array(
'call_back_function' => $call_back_function,
'form_name' => $form_name,
'field_to_name_array' => array(
'id' => $vardef['id_name'],
((empty($vardef['rname'])) ? 'name' : $vardef['rname']) => $vardef['name'],
),
);
}
$json = getJSONobj();
$displayParams['popupData'] = '{literal}'.$json->encode($popup_request_data). '{/literal}';
if(!isset($displayParams['readOnly'])) {
$displayParams['readOnly'] = '';
} else {
$displayParams['readOnly'] = $displayParams['readOnly'] == false ? '' : 'READONLY';
}
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
return $this->fetch('include/SugarFields/Fields/Relate/SearchView.tpl');
}
function formatField($rawField, $vardef) {
if ('contact_name' == $vardef['name']){
$default_locale_name_format = $GLOBALS['current_user']->getPreference('default_locale_name_format');
$default_locale_name_format = trim(preg_replace('/s/i', '', $default_locale_name_format));
$new_field = '';
$names = array();
$temp = explode(' ', $rawField);
if ( !isset($temp[1]) ) {
$names['f'] = '';
$names['l'] = $temp[0];
}
elseif ( !empty($temp) ) {
$names['f'] = $temp[0];
$names['l'] = $temp[1];
}
for($i=0;$i<strlen($default_locale_name_format);$i++){
$new_field .= array_key_exists($default_locale_name_format{$i}, $names) ? $names[$default_locale_name_format{$i}] : $default_locale_name_format{$i};
}
}
else $new_field = $rawField;
return $new_field;
}
}
?>

View File

@@ -0,0 +1,80 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldText extends SugarFieldBase {
function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$displayParams['nl2br'] = true;
$displayParams['htmlescape'] = true;
$displayParams['url2html'] = true;
return parent::getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
}
function getClassicEditView($field_id='description', $value='', $prefix='', $rich_text=false, $maxlength='', $tabindex=1, $cols=80, $rows=4) {
$this->ss->assign('prefix', $prefix);
$this->ss->assign('field_id', $field_id);
$this->ss->assign('value', $value);
$this->ss->assign('tabindex', $tabindex);
$displayParams = array();
$displayParams['textonly'] = $rich_text ? false : true;
$displayParams['maxlength'] = $maxlength;
$displayParams['rows'] = $rows;
$displayParams['cols'] = $cols;
$this->ss->assign('displayParams', $displayParams);
if(isset($GLOBALS['current_user'])) {
$height = $GLOBALS['current_user']->getPreference('text_editor_height');
$width = $GLOBALS['current_user']->getPreference('text_editor_width');
$height = isset($height) ? $height : '300px';
$width = isset($width) ? $width : '95%';
$this->ss->assign('RICH_TEXT_EDITOR_HEIGHT', $height);
$this->ss->assign('RICH_TEXT_EDITOR_WIDTH', $width);
} else {
$this->ss->assign('RICH_TEXT_EDITOR_HEIGHT', '100px');
$this->ss->assign('RICH_TEXT_EDITOR_WIDTH', '95%');
}
if(file_exists('custom/include/SugarFields/Fields/Text/ClassicEditView.tpl')) {
return $this->ss->fetch('custom/include/SugarFields/Fields/Text/ClassicEditView.tpl');
} else {
return $this->ss->fetch('include/SugarFields/Fields/Text/ClassicEditView.tpl');
}
}
}
?>

View File

@@ -0,0 +1,50 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
class SugarFieldUsername extends SugarFieldBase {
function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
$this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
global $current_language;
if(isset($current_language) && file_exists('include/SugarFields/Fields/Username/' . $current_language . '.DetailView.tpl')) {
return $this->fetch('include/SugarFields/Fields/Username/' . $current_language . '.DetailView.tpl');
} else {
return $this->fetch('include/SugarFields/Fields/Username/DetailView.tpl');
} //if-else
}
}
?>

View File

@@ -0,0 +1,335 @@
<?php
if (!defined('sugarEntry') || !sugarEntry)
die('Not A Valid Entry Point');
/* * *******************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
* ****************************************************************************** */
/**
* CreateViewMetaParser.php
* This is a utility file that attempts to provide support for parsing pre 5.0 SugarCRM
* CreateView.html files and produce a best guess editviewdefs.php file equivalent.
*
* @author Collin Lee
*/
require_once('include/SugarFields/Parsers/MetaParser.php');
class CreateViewMetaParser extends MetaParser {
function CreateViewMetaParser() {
$this->mView = 'CreateView';
}
/**
* 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);
$contents = $this->trimHTML($contents);
$contents = $this->stripFlavorTags($contents);
$moduleName = '';
$contents = $this->fixDuplicateTrTags($contents);
$contents = $this->fixRowsWithMissingTr($contents);
$tables = $this->getElementsByType("table", $contents);
$formElements = $this->getFormElements($tables[0]);
$hiddenInputs = array();
foreach ($formElements as $elem) {
$type = $this->getTagAttribute("type", $elem);
if (preg_match('/hidden/si', $type)) {
$name = $this->getTagAttribute("name", $elem);
$value = $this->getTagAttribute("value", $elem);
$hiddenInputs[$name] = $value;
}
}
// Get the second table in the page and onward
$tables = array_slice($tables, 1);
$panels = array();
$tableCount = 0;
$addedElements = array();
$maxTableCountNum = 0;
$tableCount = 0;
foreach ($tables as $table) {
$table = $this->fixTablesWithMissingTr($table);
$toptr = $this->getElementsByType("tr", $table);
foreach ($toptr as $tr) {
$tabledata = $this->getElementsByType("table", $tr);
$data = array();
$panelKey = $tableCount == 0 ? "default" : '';
foreach ($tabledata as $t) {
$vals = array_values($this->getElementsByType("tr", $t));
if (preg_match_all('/<h4[^>]*?>.*?(\{MOD\.|\{APP\.)(LBL_[^\}]*?)[\}].*?<\/h4>/s', $vals[0], $matches, PREG_SET_ORDER)) {
array_shift($vals);
$panelKey = count($matches[0]) == 3 ? strtolower($matches[0][2]) : $panelKey;
}
//If $panelKey is empty use the maxTableCountNum value
if (empty($panelKey)) {
$panels[$maxTableCountNum++] = $vals;
} else {
$panels[$panelKey] = $vals;
}
} //foreach
$tableCount++;
} //foreach;
} //foreach
foreach ($panels as $id => $tablerows) {
$metarow = array();
foreach ($tablerows as $trow) {
$emptyCount = 0;
$tablecolumns = $this->getElementsByType("td", $trow);
$col = array();
$slot = 0;
foreach ($tablecolumns as $tcols) {
$hasRequiredLabel = false;
//Get the sugar attribute value in the span elements of each table row
$sugarAttrLabel = $this->getTagAttribute("sugar", $tcols, "'^slot[^b]+$'");
//If there was no sugar attribute, try id (some versions of CreateView.html used this instead)
if (empty($sugarAttrLabel)) {
$sugarAttrLabel = $this->getTagAttribute("id", $tcols, "'^slot[^b]+$'");
}
//Check if this field is required
if (!empty($sugarAttrLabel)) {
$hasRequiredLabel = $this->hasRequiredSpanLabel($tcols);
}
$sugarAttrValue = $this->getTagAttribute("sugar", $tcols, "'slot[0-9]+b$'");
//If there was no sugar attribute, try id (some versions of CreateView.html used this instead)
if (empty($sugarAttrValue)) {
$sugarAttrValue = $this->getTagAttribute("id", $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 = $this->getElementValue("span", $tcols);
if (empty($spanValue)) {
$spanValue = $this->getElementValue("slot", $tcols);
}
if (empty($spanValue)) {
$spanValue = $this->getElementValue("td", $tcols);
}
//Get all the editable form elements' names
$formElementNames = $this->getFormElementsNames($spanValue);
$customField = $this->getCustomField($formElementNames);
$name = '';
$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[\.]).*?/i", $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.' . strtolower($pair[1]) . '.value', $customCode);
} else {
$phpName = $this->findAssignedVariableName($pair[1], $filePath);
$customCode = str_replace($pair[1], '$fields.' . strtolower($phpName) . '.value', $customCode);
} //if-else
}
} //foreach
} else {
//If it is only a label, skip
if (preg_match("/^(mod[\.]|app[\.]).*?/i", $matches[0][1])) {
continue;
}
$name = strtolower($matches[0][1]);
}
} else if (is_array($formElementNames)) {
if (count($formElementNames) == 1) {
if (!empty($vardefs[$formElementNames[0]])) {
$name = $formElementNames[0];
} else {
// Try to use the CreateView.php file to find author's intent
$name = $this->findAssignedVariableName($formElementNames[0], $filePath);
//If it's still empty, just use the entire block as customCode
if (empty($vardefs[$name])) {
//Replace any { characters just in case
$customCode = str_replace('{', '{$', $spanValue);
}
} //if-else
} else {
//If it is an Array of form elements, it is likely the _id and _name relate field combo
$relateName = $this->getRelateFieldName($formElementNames);
if (!empty($relateName)) {
$name = $relateName;
} else {
//One last attempt to scan $formElementNames for one vardef field only
$name = $this->findSingleVardefElement($formElementNames, $vardefs);
if (empty($name)) {
$fields = array();
$name = $formElementNames[0];
foreach ($formElementNames as $elementName) {
if (isset($vardefs[$elementName])) {
$fields[] = $elementName;
} else {
$fields[] = $this->findAssignedVariableName($elementName, $filePath);
} //if-else
} //foreach
} //if
} //if-else
} //if-else
}
// Build the entry
if (preg_match("/<textarea/si", $spanValue)) {
//special case for textarea form elements (add the displayParams)
$displayParams = array();
$displayParams['rows'] = $this->getTagAttribute("rows", $spanValue);
$displayParams['cols'] = $this->getTagAttribute("cols", $spanValue);
if (!empty($displayParams['rows']) && !empty($displayParams['cols'])) {
$field = array();
$field['name'] = $name;
$field['displayParams'] = $displayParams;
} else {
$field = $name;
}
} else {
if (isset($fields) || isset($customCode)) {
$field = array();
$field['name'] = $name;
if (isset($fields)) {
$field['fields'] = $fields;
}
if (isset($customCode)) {
$field['customCode'] = $customCode;
$field['description'] = 'This field was auto generated';
}
} else {
$emptyCount = $name == '' ? $emptyCount + 1 : $emptyCount;
$field = $name;
}
} //if-else if-else block
$addedField = is_array($field) ? $field['name'] : $field;
if (empty($addedField) || empty($addedElements[$addedField])) {
//Add the meta-data definition for required fields
if ($hasRequiredLabel) {
if (is_array($field)) {
if (isset($field['displayParams']) && is_array($field['displayParams'])) {
$field['displayParams']['required'] = true;
} else {
$field['displayParams'] = array('required' => true);
}
} else {
$field = array('name' => strtolower($field), 'displayParams' => array('required' => true));
}
}
$col[] = is_array($field) ? $field : strtolower($field);
$addedElements[$addedField] = $addedField;
}
} //if($sugarAttValue)
} //foreach
// One last final check. If $emptyCount does not equal Array $col count, don't add
if ($emptyCount != count($col)) {
if ($hasRequiredLabel) {
if (is_array($col)) {
if (isset($col['displayParams'])) {
$col['displayParams']['required'] = true;
} else {
$col['displayParams'] = array('required' => true);
}
} else {
$col = array('name' => strtolower($col), 'displayParams' => array('required' => true));
}
}
$metarow[] = $col;
} //if
} //foreach
$panels[$id] = $metarow;
} //foreach
$this->mCustomPanels = $panels;
$panels = $this->applyPreRules($moduleDir, $panels);
$templateMeta = array();
if ($merge && !empty($masterCopy) && file_exists($masterCopy)) {
$panels = $this->mergePanels($panels, $vardefs, $moduleDir, $masterCopy);
$templateMeta = $this->mergeTemplateMeta($templateMeta, $moduleDir, $masterCopy);
}
$panels = $this->applyRules($moduleDir, $panels);
return $this->createFileContents($moduleDir, $panels, $templateMeta, $filePath);
}
}

View File

@@ -0,0 +1,191 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* DetailViewMetaParser.php
* This is a utility file that attempts to provide support for parsing pre 5.0 SugarCRM
* DetailView.html files and produce a best guess detailviewdefs.php file equivalent.
*
* @author Collin Lee
*/
require_once('include/SugarFields/Parsers/MetaParser.php');
/**
* DetailViewMetaParser.php
* This class is responsible for handling the parsing of DetailView.html files from
* SugarCRM versions prior to 5.x. It will make a best guess of translating the
* HTML file to a metadata format.
*
* @author Collin Lee
*/
class DetailViewMetaParser extends MetaParser {
function DetailViewMetaParser() {
$this->mView = 'DetailView';
}
/**
* 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) {
// Grab file contents
$contents = file_get_contents($filePath);
// Remove \n,\r characters to allow for better text parsing
$contents = $this->trimHTML($contents);
$contents = $this->stripFlavorTags($contents);
// Notes DetailView.html file is messed up
if($moduleDir == 'Notes') {
$contents = str_replace('{PAGINATION}<tr><td>', '{PAGINATION}', $contents);
$contents = str_replace('</td></tr></table><script>', '</table><script>', $contents);
$contents = str_replace("<tr><div id='portal_flag_row' name='portal_flag_row' style='display:none'>", "<div id='portal_flag_row' name='portal_flag_row' style='display:none'>", $contents);
}
$contents = $this->fixDuplicateTrTags($contents);
$contents = $this->fixRowsWithMissingTr($contents);
// Get all the tables
$tables = $this->getElementsByType("table", $contents);
// Skip the first one
$tables = array_slice($tables, 1);
$panels = array();
$tableCount = 0;
$metarow = array();
foreach($tables as $table) {
$table = $this->fixTablesWithMissingTr($table);
$tablerows = $this->getElementsByType("tr", $table);
foreach($tablerows as $trow) {
$metacolumns = array();
$columns = $this->getElementsByType("td", $trow);
$columns = array_reverse($columns, true);
foreach($columns as $tcols) {
$sugarAttrValue = $this->getTagAttribute("sugar", $tcols, "'slot[0-9]+b$'");
if(empty($sugarAttrValue)) {
continue;
}
$def = '';
$field = $this->getElementValue("span", $tcols);
//If it's a space, simply add a blank string
if($field == '&nbsp;') {
$metacolumns[] = "";
} else if(!empty($field)) {
preg_match_all('/[\{]([^\}].*?)[\}]/s', $field, $matches, PREG_SET_ORDER);
if(!empty($matches)) {
if(count($matches) > 1) {
$def = array();
$def['name'] = preg_match('/_c$/i', $matches[0][1]) ? $matches[0][1] : strtolower($matches[0][1]);
foreach($matches as $m) {
if(isset($vardefs[strtolower($m[1])])) {
$def['name'] = strtolower($m[1]);
}
}
$field = preg_replace('/<\{tag\.[a-z_]*?\}/i', '<a', $field);
$field = preg_replace('/<\/\{tag\.[a-z_]*?\}>/i', '</a>', $field);
foreach($matches as $tag[1]) {
if(preg_match("/^(mod[\.]|app[\.]).*?/i", $tag[1][1])) {
$field = str_replace($tag[1][1], '$'.$tag[1][1], $field);
} else {
$theField = preg_match('/_c$/i', $tag[1][1]) ? $tag[1][1] : strtolower($tag[1][1]);
if(!empty($vardefs[$theField])) {
$field = str_replace($tag[1][1], '$fields.'. $theField.'.value', $field);
} else {
$phpName = $this->findAssignedVariableName($tag[1][1], $filePath);
$field = str_replace($tag[1][1], '$fields.'. $theField.'.value', $field);
} //if-else
}
}
$def['customCode'] = $field;
$def['description'] = 'This field was auto generated';
} else {
$def = strtolower($matches[0][1]);
}
} //if
$metacolumns[] = $def;
} //if
} //foreach($tablecolumns as $tcols)
$metarow[] = array_reverse($metacolumns);
} //foreach($tablerows as $trow)
$id = $tableCount == 0 ? 'default' : $tableCount;
$tableCount++;
$panels[$id] = $metarow;
} //foreach($tables as $table)
$this->mCustomPanels = $panels;
$panels = $this->applyPreRules($moduleDir, $panels);
$templateMeta = array();
if($merge && !empty($masterCopy) && file_exists($masterCopy)) {
$panels = $this->mergePanels($panels, $vardefs, $moduleDir, $masterCopy);
$templateMeta = $this->mergeTemplateMeta($templateMeta, $moduleDir, $masterCopy);
}
$panels = $this->applyRules($moduleDir, $panels);
return $this->createFileContents($moduleDir, $panels, $templateMeta, $filePath);
}
}
?>

View File

@@ -0,0 +1,341 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* EdtiViewMetaParser.php
* This is a utility file that attempts to provide support for parsing pre 5.0 SugarCRM
* EditView.html files and produce a best guess editviewdefs.php file equivalent.
*
* @author Collin Lee
*/
require_once('include/SugarFields/Parsers/MetaParser.php');
class EditViewMetaParser extends MetaParser {
function EditViewMetaParser() {
$this->mView = 'EditView';
}
/**
* 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);
$contents = $this->trimHTML($contents);
$contents = $this->stripFlavorTags($contents);
$moduleName = '';
$contents = $this->fixDuplicateTrTags($contents);
$contents = $this->fixRowsWithMissingTr($contents);
$tables = $this->getElementsByType("table", $contents);
$formElements = $this->getFormElements($tables[0]);
$hiddenInputs = array();
foreach($formElements as $elem) {
$type = $this->getTagAttribute("type", $elem);
if(preg_match('/hidden/si',$type)) {
$name = $this->getTagAttribute("name", $elem);
$value = $this->getTagAttribute("value", $elem);
$hiddenInputs[$name] = $value;
}
}
// Get the second table in the page and onward
$tables = array_slice($tables, 1);
$panels = array();
$tableCount = 0;
$addedElements = array();
$maxTableCountNum = 0;
$tableCount = 0;
foreach($tables as $table) {
$table = $this->fixTablesWithMissingTr($table);
$toptr = $this->getElementsByType("tr", $table);
foreach($toptr as $tr) {
$tabledata = $this->getElementsByType("table", $tr);
$data = array();
$panelKey = $tableCount == 0 ? "default" : '';
foreach($tabledata as $t) {
$vals = array_values($this->getElementsByType("tr", $t));
if(preg_match_all('/<h4[^>]*?>.*?(\{MOD\.|\{APP\.)(LBL_[^\}]*?)[\}].*?<\/h4>/s', $vals[0], $matches, PREG_SET_ORDER)) {
array_shift($vals);
$panelKey = count($matches[0]) == 3 ? strtolower($matches[0][2]) : $panelKey;
}
//If $panelKey is empty use the maxTableCountNum value
if(empty($panelKey)) {
$panels[$maxTableCountNum++] = $vals;
} else {
$panels[$panelKey] = $vals;
}
} //foreach
$tableCount++;
} //foreach;
} //foreach
foreach($panels as $id=>$tablerows) {
$metarow = array();
foreach($tablerows as $trow) {
$emptyCount = 0;
$tablecolumns = $this->getElementsByType("td", $trow);
$col = array();
$slot = 0;
foreach($tablecolumns as $tcols) {
$hasRequiredLabel = false;
//Get the sugar attribute value in the span elements of each table row
$sugarAttrLabel = $this->getTagAttribute("sugar", $tcols, "'^slot[^b]+$'");
//If there was no sugar attribute, try id (some versions of EditView.html used this instead)
if(empty($sugarAttrLabel)) {
$sugarAttrLabel = $this->getTagAttribute("id", $tcols, "'^slot[^b]+$'");
}
//Check if this field is required
if(!empty($sugarAttrLabel)) {
$hasRequiredLabel = $this->hasRequiredSpanLabel($tcols);
}
$sugarAttrValue = $this->getTagAttribute("sugar", $tcols, "'slot[0-9]+b$'");
//If there was no sugar attribute, try id (some versions of EditView.html used this instead)
if(empty($sugarAttrValue)) {
$sugarAttrValue = $this->getTagAttribute("id", $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 = $this->getElementValue("span", $tcols);
if(empty($spanValue)) {
$spanValue = $this->getElementValue("slot", $tcols);
}
if(empty($spanValue)) {
$spanValue = $this->getElementValue("td", $tcols);
}
//Get all the editable form elements' names
$formElementNames = $this->getFormElementsNames($spanValue);
$customField = $this->getCustomField($formElementNames);
$name = '';
$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[\.]).*?/i", $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.'.strtolower($pair[1]).'.value', $customCode);
} else {
$phpName = $this->findAssignedVariableName($pair[1], $filePath);
$customCode = str_replace($pair[1], '$fields.'.strtolower($phpName).'.value', $customCode);
} //if-else
}
} //foreach
} else {
//If it is only a label, skip
if(preg_match("/^(mod[\.]|app[\.]).*?/i", $matches[0][1])) {
continue;
}
$name = strtolower($matches[0][1]);
}
} else if(is_array($formElementNames)) {
if(count($formElementNames) == 1) {
if(!empty($vardefs[$formElementNames[0]])) {
$name = $formElementNames[0];
} else {
// Try to use the EdtiView.php file to find author's intent
$name = $this->findAssignedVariableName($formElementNames[0], $filePath);
//If it's still empty, just use the entire block as customCode
if(empty($vardefs[$name])) {
//Replace any { characters just in case
$customCode = str_replace('{', '{$', $spanValue);
}
} //if-else
} else {
//If it is an Array of form elements, it is likely the _id and _name relate field combo
$relateName = $this->getRelateFieldName($formElementNames);
if(!empty($relateName)) {
$name = $relateName;
} else {
//One last attempt to scan $formElementNames for one vardef field only
$name = $this->findSingleVardefElement($formElementNames, $vardefs);
if(empty($name)) {
$fields = array();
$name = $formElementNames[0];
foreach($formElementNames as $elementName) {
if(isset($vardefs[$elementName])) {
$fields[] = $elementName;
} else {
$fields[] = $this->findAssignedVariableName($elementName, $filePath);
} //if-else
} //foreach
} //if
} //if-else
} //if-else
}
// Build the entry
if(preg_match("/<textarea/si", $spanValue)) {
//special case for textarea form elements (add the displayParams)
$displayParams = array();
$displayParams['rows'] = $this->getTagAttribute("rows", $spanValue);
$displayParams['cols'] = $this->getTagAttribute("cols", $spanValue);
if(!empty($displayParams['rows']) && !empty($displayParams['cols'])) {
$field = array();
$field['name'] = $name;
$field['displayParams'] = $displayParams;
} else {
$field = $name;
}
} else {
if(isset($fields) || isset($customCode)) {
$field = array();
$field['name'] = $name;
if(isset($fields)) {
$field['fields'] = $fields;
}
if(isset($customCode)) {
$field['customCode'] = $customCode;
$field['description'] = 'This field was auto generated';
}
} else {
$emptyCount = $name == '' ? $emptyCount + 1 : $emptyCount;
$field = $name;
}
} //if-else if-else block
$addedField = is_array($field) ? $field['name'] : $field;
if(empty($addedField) || empty($addedElements[$addedField])) {
//Add the meta-data definition for required fields
if($hasRequiredLabel) {
if(is_array($field)) {
if(isset($field['displayParams']) && is_array($field['displayParams'])) {
$field['displayParams']['required']=true;
} else {
$field['displayParams'] = array('required'=>true);
}
} else {
$field = array('name'=>strtolower($field), 'displayParams'=>array('required'=>true));
}
}
$col[] = is_array($field) ? $field : strtolower($field);
$addedElements[$addedField] = $addedField;
}
} //if($sugarAttValue)
} //foreach
// One last final check. If $emptyCount does not equal Array $col count, don't add
if($emptyCount != count($col)) {
if($hasRequiredLabel) {
if(is_array($col)) {
if(isset($col['displayParams'])) {
$col['displayParams']['required']=true;
} else {
$col['displayParams']=array('required'=>true);
}
} else {
$col = array('name'=>strtolower($col), 'displayParams'=>array('required'=>true));
}
}
$metarow[] = $col;
} //if
} //foreach
$panels[$id] = $metarow;
} //foreach
$this->mCustomPanels = $panels;
$panels = $this->applyPreRules($moduleDir, $panels);
$templateMeta = array();
if($merge && !empty($masterCopy) && file_exists($masterCopy)) {
$panels = $this->mergePanels($panels, $vardefs, $moduleDir, $masterCopy);
$templateMeta = $this->mergeTemplateMeta($templateMeta, $moduleDir, $masterCopy);
}
$panels = $this->applyRules($moduleDir, $panels);
return $this->createFileContents($moduleDir, $panels, $templateMeta, $filePath);
}
}
?>

View File

@@ -0,0 +1,810 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* MetaParser.php
*
* This is a utility base file to parse HTML
* @author Collin Lee
*/
class MetaParser {
var $mPHPFile;
var $mView;
var $mModule;
var $mCustomPanels;
function MetaParser() {
}
function parse() {
return "NOT AVAILABLE";
}
/**
* getFormContents
* Parses for contents enclosed within <form>...</form> tags
*/
function getFormContents($contents, $all = true) {
if($all) {
preg_match_all("'(<form[^>]*?>)(.*?)(</form[^>]*?>)'si", $contents, $matches);
return $matches;
}
preg_match("'(<form[^>]*?>)(.*?)(</form[^>]*?>)'si", $contents, $matches);
return $this->convertToTagElement($matches);
//return $matches;
}
/**
* getFormElements
* Parses for input, select, textarea types from string content
* @param $contents The String contents to parse
* @return $matches Array of matches of PREG_SET_ORDER
*/
function getFormElements($contents) {
preg_match_all("'(<[ ]*?)(textarea|input|select)([^>]*?)(>)'si", $contents, $matches, PREG_PATTERN_ORDER);
$elems = array();
foreach($matches[3] as $match) {
$elems[] = $match;
}
return $elems;
}
/**
* getFormElementsNames
* Parses for the name values of input, select, textarea types from string content
* @param $contents The String contents to parse
* @return $matches Array of name/value pairs
*/
function getFormElementsNames($contents) {
preg_match_all("'(<[ ]*?)(textarea|input|select)[^>]*?name=[\'\"]([^\'\"]*?)(\[\])?(_basic)?[\'\"]([^>]*?>)'si", $contents, $matches, PREG_PATTERN_ORDER);
return !empty($matches[3]) ? $matches[3] : null;
}
/**
* getTagAttribute
* Returns the name/value of a tag attribute where name is set to $name
* @param $name The name of the attribute
* @param $contents The contents to parse
* @param $filter Option regular expression to filter value
* @return Array of name/value for matching attribute
*/
function getTagAttribute($name, $contents, $filter = '') {
//$exp = "'".$name."[ ]*?=[ ]*?[\'\"]([a-zA-Z0-9\_\[\]]*)[\'\"]'si";
$exp = "'".$name."[\s]*?=[\s]*?[\'\"]([^\'^\"]*?)[\'\"]'si";
preg_match_all($exp, $contents, $matches, PREG_SET_ORDER);
if(empty($filter)) {
return !empty($matches[0][1]) ? $matches[0][1] : '';
}
$filtered = array();
foreach($matches as $tag) {
if(preg_match($filter, $tag[1])) {
$filtered[] = $tag;
}
}
return $filtered;
}
/**
* getTables
* Returns an Array of the tables found in the file. If $tableClass parameter
* is supplied, it'll return only those tables that have a matching class attribute
* equal to $tableClass
* @param $tableClass Optional table class parameter value
* @return Array of table elements found
*/
function getTables($tableClass = null, $contents) {
preg_match_all("'(<table[^>]*?>)(.*?)(</table[^>]*?>)'si", $contents, $matches, PREG_SET_ORDER);
if($tableClass == null) {
return $matches;
}
$tables = array();
foreach($matches as $key => $table) {
if(strpos($table[1], $tableClass) > 0) {
$tables[] = $table;
}
}
return $this->convertToTagElement($tables);
}
/**
* getElementsByType
*
* Returns an Array of all elements matching type. It will match
* for the outermost tags. For example given contents:
* "<tr><td>Text <table><tr><td>a</td></tr></table></td></tr>"
* and method call getElementsByType("<td>", $contents) returns
* "<td>Text <table><tr><td>a</td></tr></table></td>"
*
* @param $type The type of element to parse out and return
* @return a tag element format Array
*/
function getElementsByType($type, $contents) {
$x = strlen($contents);
$mark = 0;
$count = 0;
$stag1 = "<" . trim($type, " <>") . '>';
$stag2 = "<" . trim($type, " <>") . ' ';
$etag = "</".$type.">";
$sincrement = strlen($stag1);
$eincrement = strlen($etag);
$sarr = array();
$values = array();
while($count < $x) {
$stok = substr($contents, $count, $sincrement);
$etok = substr($contents, $count, $eincrement);
if($stok == $stag1 || $stok == $stag2) {
//Reset mark;
if(count($sarr) == 0) {
$mark = $count;
}
$sarr[] = $count;
} else if($etok == $etag) {
array_shift($sarr);
if(count($sarr) == 0) {
$val = substr($contents, $mark, ($count - $mark) + $eincrement);
$values[] = $val;
$mark = $count;
}
}
$count++;
}
$count = 0;
return $values;
}
/**
* getElementValue
*
*/
function getElementValue($type, $contents, $filter = "(.*?)") {
$exp = "'<".$type."[^>]*?>".$filter."</".$type."[^>]*?>'si";
preg_match($exp, $contents, $matches);
return isset($matches[1]) ? $matches[1] : '';
}
function stripComments($contents) {
return preg_replace("'(<!--.*?-->)'si", "", $contents);
}
/**
* stripFlavorTags
* This method accepts the file contents and uses the $GLOBALS['sugar_flavor'] value
* to remove the flavor tags in the file contents if present. If $GLOBALS['sugar_flavor']
* is not set, it defaults to PRO flavor
* @param $contents The file contents as a String value
* @param $result The file contents with non-matching flavor tags and their nested comments removed
*/
function stripFlavorTags($contents) {
$flavor = isset($GLOBALS['sugar_flavor']) ? $GLOBALS['sugar_flavor'] : 'PRO';
$isPro = ($flavor == 'ENT' || $flavor == 'PRO') ? true : false;
if($isPro) {
$contents = preg_replace('/<!-- BEGIN: open_source -->.*?<!-- END: open_source -->/', '', $contents);
} else {
$contents = preg_replace('/<!-- BEGIN: pro -->.*?<!-- END: pro -->/', '', $contents);
}
return $contents;
}
/**
* getMaxColumns
* Returns the highest number of <td>...</td> blocks within a <tr>...</tr> block.
* @param $contents The table contents to parse
* @param $filter Optional filter to parse for an attribute within the td block.
* @return The maximum column count
*/
function getMaxColumns($contents, $filter) {
preg_match_all("'(<tr[^>]*?>)(.*?)(</tr[^>]*?>)'si", $contents, $matches, PREG_SET_ORDER);
$max = 0;
foreach($matches as $tableRows) {
$count = substr_count($tableRows[2], $filter);
if($count > $max) {
$max = $count;
}
}
return $max;
}
function convertToTagElement($matches) {
$elements = array();
foreach($matches as $data) {
// We need 4 because the 1,2,3 indexes make up start,body,end
if(count($data) == 4) {
$element = array();
$element['start'] = $data[1];
$element['body'] = $data[2];
$element['end'] = $data[3];
$elements[] = $element;
}
}
return empty($elements) ? $matches : $elements;
}
/*
* trimHTML
* This function removes the \r (return), \n (newline) and \t (tab) markup from string
*/
function trimHTML($contents) {
$contents = str_replace(array("\r"), array(""), $contents);
$contents = str_replace(array("\n"), array(""), $contents);
$contents = str_replace(array("\t"), array(""), $contents);
return $contents;
}
/**
* getJavascript
*
* This method parses the given $contents String and grabs all <script...>...</script> blocks.
* The method also converts values enclosed within "{...}" blocks that may need to be converted
* to Smarty syntax.
*
* @param $contents The HTML String contents to parse
*
* @return $javascript The formatted script blocks or null if none found
*/
function getJavascript($contents, $addLiterals = true) {
$javascript = null;
//Check if there are Javascript blocks of code to process
preg_match_all("'(<script[^>]*?>)(.*?)(</script[^>]*?>)'si", $contents, $matches, PREG_PATTERN_ORDER);
if(empty($matches)) {
return $javascript;
}
foreach($matches[0] as $scriptBlock) {
$javascript .= "\n" . $scriptBlock;
} //foreach
$javascript = substr($javascript, 1);
//Remove stuff first
//1) Calendar.setup {..} blocks
$javascript = preg_replace('/Calendar.setup[\s]*[\(][^\)]*?[\)][\s]*;/si', '', $javascript);
//Find all blocks that may need to be replaced with Smarty syntax
preg_match_all("'([\{])([a-zA-Z0-9_]*?)([\}])'si", $javascript, $matches, PREG_PATTERN_ORDER);
if(!empty($matches)) {
$replace = array();
foreach($matches[0] as $xTemplateCode) {
if(!isset($replace[$xTemplateCode])) {
$replace[$xTemplateCode] = str_replace("{", "{\$", $xTemplateCode);
} //if
} //foreach
$javascript = str_replace(array_keys($replace), array_values($replace), $javascript);
} //if
if(!$addLiterals) {
return $javascript;
}
return $this->parseDelimiters($javascript);
}
function parseDelimiters($javascript) {
$newJavascript = '';
$scriptLength = strlen($javascript);
$count = 0;
$inSmartyVariable = false;
while($count < $scriptLength) {
if($inSmartyVariable) {
$start = $count;
$numOfChars = 1;
while(isset($javascript[$count]) && $javascript[$count] != '}') {
$count++;
$numOfChars++;
}
$newJavascript .= substr($javascript, $start, $numOfChars);
$inSmartyVariable = false;
} else {
$char = $javascript[$count];
$nextChar = ($count + 1 >= $scriptLength) ? '' : $javascript[$count + 1];
if($char == "{" && $nextChar == "$") {
$inSmartyVariable = true;
$newJavascript .= $javascript[$count];
} else if($char == "{") {
$newJavascript .= " {ldelim} ";
} else if($char == "}") {
$newJavascript .= " {rdelim} ";
} else {
$newJavascript .= $javascript[$count];
}
}
$count++;
} //while
return $newJavascript;
}
/**
* findAssignedVariableName
* This method provides additional support in attempting to parse the module's corresponding
* PHP file for either the EditView or DetailView. In the event that the subclasses cannot
* find a matching vardefs.php entry in the HTML file, this method can be called to parse the
* PHP file to see if the assignment was made using the bean's variable. If so, we return
* this variable name.
*
* @param $name The tag name found in the HTML file for which we want to search
* @param $filePath The full file path for the HTML file
* @return The variable name found in PHP file, original $name variable if not found
*/
function findAssignedVariableName($name, $filePath) {
if($this->mPHPFile == "INVALID") {
return $name;
}
if(!isset($this->mPHPFile)) {
if(preg_match('/(.*?)(DetailView).html$/', $filePath, $matches)) {
$dir = $matches[1];
} else if(preg_match('/(.*?)(EditView).html$/', $filePath, $matches)) {
$dir = $matches[1];
}
if(!isset($dir) || !is_dir($dir)) {
$this->mPHPFile = "INVALID";
return $name;
}
$filesInDir = $this->dirList($dir);
$phpFile = $matches[2].'.*?[\.]php';
foreach($filesInDir as $file) {
if(preg_match("/$phpFile/", $file)) {
$this->mPHPFile = $matches[1] . $file;
break;
}
}
if(!isset($this->mPHPFile) || !file_exists($this->mPHPFile)) {
$this->mPHPFile = "INVALID";
return $name;
}
}
$phpContents = file_get_contents($this->mPHPFile);
$uname = strtoupper($name);
if(preg_match("/xtpl->assign[\(][\"\']".$uname."[\"\'][\s]*?,[\s]*?[\$]focus->(.*?)[\)]/si", $phpContents, $matches)) {
return $matches[1];
}
return $name;
}
/**
* dirList
* Utility method to list all the files in a given directory.
*
* @param $directory The directory to scan
* @return $results The files in the directory that were found
*/
function dirList ($directory) {
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// keep going until all files in directory have been read
while ($file = readdir($handler)) {
// if $file isn't this directory or its parent,
// add it to the results array
if ($file != '.' && $file != '..')
$results[] = $file;
}
// tidy up: close the handler
closedir($handler);
return $results;
}
/**
* isCustomField
* This method checks the mixed variable $elementNames to see if it is a custom field. A custom
* field is simply defined as a field that ends with "_c". If $elementNames is an Array
* any matching custom field value will result in a true evaluation
* @param $elementNames Array or String value of form element name(s).
* @return String name of custom field; null if none found
*/
function getCustomField($elementNames) {
if(!isset($elementNames) || (!is_string($elementNames) && !is_array($elementNames))) {
return null;
}
if(is_string($elementNames)) {
if(preg_match('/(.+_c)(_basic)?(\[\])?$/', $elementNames, $matches)) {
return count($matches) == 1 ? $matches[0] : $matches[1];
}
return null;
}
foreach($elementNames as $name) {
if(preg_match('/(.+_c)(_basic)?(\[\])?$/', $name, $matches)) {
return count($matches) == 1 ? $matches[0] : $matches[1];
}
}
return null;
}
function applyPreRules($moduleDir, $panels) {
if(file_exists("include/SugarFields/Parsers/Rules/".$moduleDir."ParseRule.php")) {
require_once("include/SugarFields/Parsers/Rules/".$moduleDir."ParseRule.php");
$class = $moduleDir."ParseRule";
$parseRule = new $class();
$panels = $parseRule->preParse($panels, $this->mView);
}
return $panels;
}
function applyRules($moduleDir, $panels) {
return $this->applyPostRules($moduleDir, $panels);
}
function applyPostRules($moduleDir, $panels) {
//Run module specific rules
if(file_exists("include/SugarFields/Parsers/Rules/".$moduleDir."ParseRule.php")) {
require_once("include/SugarFields/Parsers/Rules/".$moduleDir."ParseRule.php");
$class = $moduleDir."ParseRule";
$parseRule = new $class();
$panels = $parseRule->parsePanels($panels, $this->mView);
}
//Now run defined rules
require_once("include/SugarFields/Parsers/Rules/ParseRules.php");
$rules = ParseRules::getRules();
foreach($rules as $rule) {
if(!file_exists($rule['file'])) {
$GLOBALS['log']->error("Cannot run rule for " . $rule['file']);
continue;
} //if
require_once($rule['file']);
$runRule = new $rule['class'];
$panels = $runRule->parsePanels($panels, $this->mView);
} //foreach
return $panels;
}
function createFileContents($moduleDir, $panels, $templateMeta=array(), $htmlFilePath) {
$header = "<?php\n\n";
if(empty($templateMeta)) {
$header .= "\$viewdefs['$moduleDir']['$this->mView'] = array(
'templateMeta' => array('maxColumns' => '2',
'widths' => array(
array('label' => '10', 'field' => '30'),
array('label' => '10', 'field' => '30')
),
),";
} else {
$header .= "\$viewdefs['$moduleDir']['$this->mView'] = array(
'templateMeta' =>" . var_export($templateMeta, true) . ",";
}
//Replace all the @sq (single quote tags that may have been inserted)
$header = preg_replace('/\@sq/', "'", $header);
/*
$contents = file_get_contents($htmlFilePath);
$javascript = $this->getJavascript($contents, true);
if(!empty($javascript)) {
$javascript = str_replace("'", "\\'", $javascript);
$header .= "\n 'javascript' => '" . $javascript . "',\n";
} //if
*/
$header .= "\n 'panels' =>";
$footer = "
\n
);
?>";
$metadata = '';
$body = var_export($panels, true);
$metadata = $header . $body . $footer;
$metadata = preg_replace('/(\d+)[\s]=>[\s]?/',"",$metadata);
return $metadata;
}
/**
* mergePanels
* This function merges the $panels Array against the $masterCopy's meta data definition
* @param $panels meta data Array to merge
* @param $moduleDir Directory name of the module
* @param $masterCopy file path to the meta data master copy
* @return Array of merged $panel definition
*/
function mergePanels($panels, $vardefs, $moduleDir, $masterCopy) {
require($masterCopy);
$masterpanels = $viewdefs[$moduleDir][$this->mView]['panels'];
$hasMultiplePanels = $this->hasMultiplePanels($masterpanels);
if(!$hasMultiplePanels) {
$keys = array_keys($viewdefs[$moduleDir][$this->mView]['panels']);
if(!empty($keys) && count($keys) == 1) {
if(strtolower($keys[0]) == 'default') {
$masterpanels = array('default'=>$viewdefs[$moduleDir][$this->mView]['panels'][$keys[0]]);
} else {
$firstPanel = array_values($viewdefs[$moduleDir][$this->mView]['panels']);
$masterpanels = array('default'=> $firstPanel[0]);
}
} else {
$masterpanels = array('default'=>$viewdefs[$moduleDir][$this->mView]['panels']);
}
}
foreach($masterpanels as $name=>$masterpanel) {
if(isset($panels[$name])) {
// Get all the names in the panel
$existingElements = array();
$existingLocation = array();
foreach($panels[$name] as $rowKey=>$row) {
foreach($row as $colKey=>$column) {
if(is_array($column) && !empty($column['name'])) {
$existingElements[$column['name']] = $column['name'];
$existingLocation[$column['name']] = array("panel"=>$name, "row"=>$rowKey, "col"=>$colKey);
} else if(!is_array($column) && !empty($column)) {
$existingElements[$column] = $column;
$existingLocation[$column] = array("panel"=>$name, "row"=>$rowKey, "col"=>$colKey);
}
} //foreach
} //foreach
// Now check against the $masterCopy
foreach($masterpanel as $rowKey=>$row) {
$addRow = array();
foreach($row as $colKey=>$column) {
if(is_array($column) && isset($column['name'])) {
$id = $column['name'];
} else if(!is_array($column) && !empty($column)) {
$id = $column;
} else {
continue;
}
if(empty($existingElements[$id])) {
//Only add if
// 1) if it is a required field (as defined in metadata)
// 2) or if it has a customLabel and customCode (a very deep customization)
if((is_array($column) && !empty($column['displayParams']['required'])) ||
(is_array($column) && !empty($column['customCode']) && !empty($column['customLabel']))) {
$addRow[] = $column;
}
} else {
//Use definition from master copy instead
$panels[$existingLocation[$id]['panel']][$existingLocation[$id]['row']][$existingLocation[$id]['col']] = $column;
}
} //foreach
// Add it to the $panels
if(!empty($addRow)) {
$panels[$name][] = $addRow;
}
} //foreach
} else {
$panels[$name] = $masterpanel;
}
} //foreach
// We're not done yet... go through the $panels Array now and try to remove duplicate
// or empty panels
foreach($panels as $name=>$panel) {
if(count($panel) == 0 || !isset($masterpanels[$name])) {
unset($panels[$name]);
}
} //foreach
return $panels;
}
/**
* mergeTemplateMeta
* This function merges the $templateMeta Array against the $masterCopy's meta data definition
* @param $templateMeta meta data Array to merge
* @param $moduleDir Directory name of the module
* @param $masterCopy file path to the meta data master copy
* @return Array of merged $templateMeta definition
*/
function mergeTemplateMeta($templateMeta, $moduleDir, $masterCopy) {
require($masterCopy);
$masterTemplateMeta = $viewdefs[$moduleDir][$this->mView]['templateMeta'];
if(isset($masterTemplateMeta['javascript'])) {
//Insert the getJSPath code back into src value
$masterTemplateMeta['javascript'] = preg_replace('/src\s*=\s*[\'\"].*?(modules\/|include\/)([^\.]*?\.js)([^\'\"]*?)[\'\"]/i', 'src="@sq . getJSPath(@sq${1}${2}@sq) . @sq"', $masterTemplateMeta['javascript']);
// BEGIN SUGAR INT
//$GLOBALS['log']->fatal(var_export($masterTemplateMeta['javascript'], true));
// END SUGAR INT
}
return $masterTemplateMeta;
}
function hasRequiredSpanLabel($html) {
if(empty($html)) {
return false;
}
return preg_match('/\<(div|span) class=(\")?required(\")?\s?>\*<\/(div|span)>/si', $html);
}
function hasMultiplePanels($panels) {
if(!isset($panels) || empty($panels) || !is_array($panels)) {
return false;
}
if(is_array($panels) && (count($panels) == 0 || count($panels) == 1)) {
return false;
}
foreach($panels as $panel) {
if(!empty($panel) && !is_array($panel)) {
return false;
} else {
foreach($panel as $row) {
if(!empty($row) && !is_array($row)) {
return false;
} //if
} //foreach
} //if-else
} //foreach
return true;
}
function getRelateFieldName($mixed='') {
if(!is_array($mixed)) {
return '';
} else if(count($mixed) == 2){
$id = '';
$name = '';
foreach($mixed as $el) {
if(preg_match('/_id$/', $el)) {
$id = $el;
} else if(preg_match('/_name$/', $el)) {
$name = $el;
}
}
return (!empty($id) && !empty($name)) ? $name : '';
}
return '';
}
function getCustomPanels() {
return $this->mCustomPanels;
}
/**
* fixTablesWithMissingTr
* This is a very crude function to fix instances where files declared a table as
* <table...><td> instead of <table...><tr><td>. Without this helper function, the
* parsing could messed up.
*
*/
function fixTablesWithMissingTr($tableContents) {
if(preg_match('/(<table[^>]*?[\/]?>\s*?<td)/i', $tableContents, $matches)) {
return preg_replace('/(<table[^>]*?[\/]?>\s*?<td)/i', '<table><tr><td', $tableContents);
}
return $tableContents;
}
/**
* fixRowsWithMissingTr
* This is a very crude function to fix instances where files have an </tr> tag immediately followed by a <td> tag
*/
function fixRowsWithMissingTr($tableContents) {
if(preg_match('/(<\/tr[^>]*?[\/]?>\s*?<td)/i', $tableContents, $matches)) {
return preg_replace('/(<\/tr[^>]*?[\/]?>\s*?<td)/i', '</tr><tr><td', $tableContents);
}
return $tableContents;
}
/**
* fixDuplicateTrTags
* This is a very crude function to fix instances where files have two consecutive <tr> tags
*/
function fixDuplicateTrTags($tableContents) {
if(preg_match('/(<tr[^>]*?[\/]?>\s*?<tr)/i', $tableContents, $matches)) {
return preg_replace('/(<tr[^>]*?[\/]?>\s*?<tr)/i', '<tr', $tableContents);
}
return $tableContents;
}
/**
* findSingleVardefElement
* Scans array of form elements to see if just one is a vardef element and, if so,
* return that vardef name
*/
function findSingleVardefElement($formElements=array(), $vardefs=array()) {
if(empty($formElements) || !is_array($formElements)) {
return '';
}
$found = array();
foreach($formElements as $el) {
if(isset($vardefs[$el])) {
$found[] = $el;
}
}
return count($found) == 1 ? $found[0] : '';
}
}
?>

View File

@@ -0,0 +1,265 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* EdtiViewMetaParser.php
* This is a utility file that attempts to provide support for parsing pre 5.0 SugarCRM
* QuickCreate.html files and produce a best guess editviewdefs.php file equivalent.
*
* @author Collin Lee
*/
require_once('include/SugarFields/Parsers/MetaParser.php');
class QuickCreateMetaParser extends MetaParser {
function QuickCreateMetaParser() {
$this->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) . '</td></tr></table>';
$moduleName = '';
$forms = $this->getElementsByType("form", $contents);
$tables = $this->getElementsByType("table", $forms[0] . "</td></tr></table>");
$mainrow = $this->getElementsByType("tr", $tables[1]);
$rows = substr($mainrow[0], strpos($mainrow[0], "</tr>"));
$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("/<textarea/si", $spanValue)) {
//special case for textarea form elements (add the displayParams)
$displayParams = array();
$displayParams['rows'] = $this->getTagAttribute("rows", $spanValue);
$displayParams['cols'] = $this->getTagAttribute("cols", $spanValue);
if(!empty($displayParams['rows']) && !empty($displayParams['cols'])) {
$field = array();
$field['name'] = $name;
$field['displayParams'] = $displayParams;
} else {
$field = $name;
}
$col[] = $field;
} else if($readOnly) {
$field = array();
$field['name'] = $name;
$field['type'] = 'readonly';
if(isset($customCode)) {
$field['customCode'] = $customCode;
} //if
$col[] = $field;
} else {
if(isset($fields) || isset($customCode)) {
$field = array();
$field['name'] = $name;
if(isset($fields)) {
$field['fields'] = $fields;
}
if(isset($customCode)) {
$field['customCode'] = $customCode;
}
$col[] = $field;
} else {
$emptyCount = $name == '' ? $emptyCount + 1 : $emptyCount;
$col[] = $name;
}
} //if-else if-else block
} //if($sugarAttrValue)
} //foreach
// One last final check. If $emptyCount does not equal Array $col count, don't add
if($emptyCount != count($col)) {
$metarow[] = $col;
} //if
} //foreach
$templateMeta = array();
$templateMeta['form']['buttons'] = 'button';
preg_match_all("/(<input[^>]*?)>/si", $tables[0], $matches);
$buttons = array();
foreach($matches[0] as $button) {
$buttons[] = array('customCode'=>$button);
}
$templateMeta['form']['buttons'] = $buttons;
$formElements = $this->getFormElements($contents);
$hiddenInputs = array();
foreach($formElements as $elem) {
$type = $this->getTagAttribute("type", $elem);
if(preg_match('/hidden/si',$type, $matches)) {
$name = $this->getTagAttribute("name", $elem);
$value = $this->getTagAttribute("value", $elem);
$index = stripos($value, '$REQUEST');
$value = !empty($index) ? '$smarty.request.' . substr($value, 10) : $value;
$hiddenInputs[] = '<input id="' . $name . '" name="' . $name . '" value="' . $value . '">';
}
} //foreach
$templateMeta['form']['hidden'] = $hiddenInputs;
$templateMeta['widths'] = array(array('label' => '10', 'field' => '30'), array('label' => '10', 'field' => '30'));
$templateMeta['maxColumns'] = 2;
$panels = array();
$panels['default'] = $metarow;
$panels = $this->appplyRules($moduleDir, $panels);
return $this->createFileContents($moduleDir, $panels, $templateMeta, $filePath);
}
}
?>

View File

@@ -0,0 +1,67 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class AccountsParseRule extends BaseRule {
function AccountsParseRule() {
}
function preParse($panels, $view) {
if($view == 'DetailView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^parent_id$/')) {
$panels[$name][$rowCount][$key] = 'parent_name';
} else if($this->matches($column, '/_address_(street|country)$/') && is_array($column) && isset($column['customCode'])) {
if(preg_match('/\{\$fields\.push_contacts_(billing|register)\.value\}/', $column['customCode'], $m)) {
$column['customCode'] = str_replace('{$fields.push_contacts_'. $m[1].'.value}', '{$custom_code_'.$m[1].'}', $column['customCode']);
$panels[$name][$rowCount][$key] = $column;
}
}
} //foreach
} //foreach
} //foreach
}
return $panels;
}
}
?>

View File

@@ -0,0 +1,77 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class ActivitiesParseRule extends BaseRule {
function ActivitiesParseRule() {
}
function preParse($panels, $view) {
if($view == 'DetailView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^duration_minutes$/')) {
$panels[$name][$rowCount][$key] = 'duration_hours';
} else if($this->matches($column, '/^time_start$/')) {
$panels[$name][$rowCount][$key] = 'date_start';
}
} //foreach
} //foreach
} //foreach
}
return $panels;
}
function parsePanels($panels, $view) {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^duration_minutes$/si')) {
$panels[$name][$rowCount][$key] = '';
}
} //foreach
} //foreach
} //foreach
return $panels;
}
}
?>

View File

@@ -0,0 +1,153 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* AddressRule.php
*
* This is a utility base class to provide further refinement when converting
* pre 5.x files to the new meta-data rules. Address fields defined in the
* address panel will be removed as the new metadata definition will be merged later.
* If the address fields are outside the address panel, we will keep them as is, but
* ensure that they are not defined as Arrays.
* @author Collin Lee
*/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class AddressRule extends BaseRule {
function AddressRule() {
}
function parsePanels($panels, $view) {
$searchedAddressPanel = array();
foreach($panels as $name=>$panel) {
$isAddressPanel = $name == 'lbl_address_information';
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/_address_(city|state|country|postalcode)$/si')) {
if($view == 'DetailView' && !is_array($column)) {
$panels[$name][$rowCount][$key] = '';
} else if($view == 'DetailView' && $this->matches($column, '/_address_country$/') && is_array($column)) {
$match = $this->getMatch($column, '/(.*?)_address_country$/');
$panels[$name][$rowCount][$key]['name'] = $match[1] . '_address_street';
$panels[$name][$rowCount][$key]['label'] = 'LBL_' . strtoupper($match[1]) . '_ADDRESS';
} else if($view == 'EditView' && $isAddressPanel) {
$field = is_array($column) ? $column['name'] : $column;
preg_match('/^(.*?)_address_/si', $field, $matches);
if(empty($searchedAddressPanel[$matches[1]])) {
$intact = $this->hasAddressFieldsIntact($panel, $matches[1]);
//now we actually have to go back in and replace the street field
if(!$intact) {
$panels = $this->removeStreetFieldOverride($panels, $matches[1]);
}
$addressFieldsIntact[$matches[1]] = $intact;
$searchedAddressPanel[$matches[1]] = true;
}
//Only remove in address panel if the street field is in there by itself
if($addressFieldsIntact[$matches[1]]) {
$panels[$name][$rowCount][$key] = '';
}
}
} else if($this->matches($column, '/^push_.*?_(register|billing)$/si')) {
$panels[$name][$rowCount][$key] = '';
}
} //foreach
} //foreach
} //foreach
return $panels;
}
/**
* hasAddressFieldsIntact
* This function checks to see if the address fields for the given street key is
* intact. This means that all five fields (street, city, state, country and postalcode)
* have not been moved from the address panel
*
* @param $addressPanel Array of address panel contents
* @param $suffix The address suffix (billing, register, primary, alternate) to check for
* @return boolean
*/
function hasAddressFieldsIntact($addressPanel, $suffix) {
$expression = '/^' . $suffix . '_address_(street|city|state|country|postalcode)$/si';
$count = 0;
foreach($addressPanel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, $expression)) {
$count++;
}
}
}
return $count == 5;
}
/**
* removeStreetFieldOverride
* This function scans the panels and locates the street address field for the given key
* and replaces the Array definition (from the merging process) with a String value.
* @param $panels Array of the view's panels
* @param $street String key value of the street to search for
* @returns $panels Array of view's panels with street value substituted
*/
function removeStreetFieldOverride($panels, $street) {
$expression = '/^' . $street . '_address_street$/si';
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, $expression)) {
$panels[$name][$rowCount][$key] = $street . '_address_street';
}
}
}
}
return $panels;
}
}
?>

View File

@@ -0,0 +1,94 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* BaseRule.php
*
* This is a utility base class to provide further refinement when converting
* pre 5.x files to the new meta-data rules.
* @author Collin Lee
*/
class BaseRule {
function BaseRule() {
}
function preParse($panels, $view) {
return $panels;
}
function postParse($panels, $view) {
return $this->parsePanels($panels, $view);
}
function parsePanels($panels, $view) {
return $panels;
}
function isCustomField($mixed) {
if(is_array($mixed) && isset($mixed['name']) && preg_match('/.*?_c$/s', $mixed['name'])) {
return true;
} else if(!is_array($mixed) && isset($mixed) && preg_match('/.*?_c$/s', $mixed)) {
return true;
}
return false;
}
function matches($mixed, $regExp) {
if(is_array($mixed) && isset($mixed['name']) && preg_match($regExp, $mixed['name'])) {
return true;
} else if(!is_array($mixed) && isset($mixed) && preg_match($regExp, $mixed)) {
return true;
}
return false;
}
function getMatch($mixed, $regExp) {
if(is_array($mixed) && isset($mixed['name']) && preg_match($regExp, $mixed['name'], $matches)) {
return $matches;
} else if(!is_array($mixed) && isset($mixed) && preg_match($regExp, $mixed, $matches)) {
return $matches;
}
return null;
}
}
?>

View File

@@ -0,0 +1,62 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class BugsParseRule extends BaseRule {
function BugsParseRule() {
}
function preParse($panels, $view) {
if($view == 'DetailView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^release$/')) {
$panels[$name][$rowCount][$key] = 'found_in_release';
}
} //foreach
} //foreach
} //foreach
} //if
return $panels;
}
}
?>

View File

@@ -0,0 +1,68 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/ActivitiesParseRule.php');
class CallsParseRule extends ActivitiesParseRule {
function CallsParseRule() {
}
function preParse($panels, $view) {
$panels = parent::preParse($panels, $view);
if($view == 'EditView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^direction$/si')) {
$panels[$name][$rowCount][$key] = 'status';
}
} //foreach
} //foreach
} //foreach
} //if
return $panels;
}
function parsePanels($panels, $view) {
$panels = parent::parsePanels($panels, $view);
return $panels;
}
}
?>

View File

@@ -0,0 +1,74 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class CampaignsParseRule extends BaseRule {
function CampaignsParseRule() {
}
function preParse($panels, $view) {
if($view == 'EditView') {
$frequencyAdded = false;
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if(empty($column) && !$frequencyAdded) {
//Add the frequency label
$panels[$name][$rowCount][$key] = 'frequency';
$frequencyAdded = true;
} else if($this->matches($column, '/^deleted$/')) {
//This is to fix the error where the Created By field
//in Campaigns EditView.html actually references the deleted field
//We will just remove the field since you shouldn't be able to edit this information anyway
$panels[$name][$rowCount][$key] = '';
}
} //foreach
} //foreach
} //foreach
//If all the row/columns were taken up, then add frequency as a last row
if(!$frequencyAdded) {
$panels['default'][][] = 'frequency';
}
}
return $panels;
}
}
?>

View File

@@ -0,0 +1,81 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class ContactsParseRule extends BaseRule {
function ContactsParseRule() {
}
function preParse($panels, $view) {
if($view == 'DetailView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^(last_)?name$/')) {
$panels[$name][$rowCount][$key] = 'full_name';
}
} //foreach
} //foreach
} //foreach
}
return $panels;
}
function parsePanels(& $panels, $view) {
if($view == 'EditView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/portal_password1/si')) {
$panels[$name][$rowCount][$key] = array('name'=>'portal_password1', 'type'=>'password', 'customCode'=>'<input id="portal_password1" name="portal_password1" type="password" size="32" maxlength="32" value="{$fields.portal_password.value}">', 'label'=>'LBL_PORTAL_PASSWORD');
}
} //foreach
} //foreach
} //foreach
}
return $panels;
}
}
?>

View File

@@ -0,0 +1,62 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class ContractsParseRule extends BaseRule {
function ContractsParseRule() {
}
function preParse($panels, $view) {
if($view == 'EditView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^expiration_notice_date$/')) {
$panels[$name][$rowCount][$key] = 'expiration_notice';
}
} //foreach
} //foreach
} //foreach
} //if
return $panels;
}
}
?>

View File

@@ -0,0 +1,96 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class DocumentsParseRule extends BaseRule {
function DocumentsParseRule() {
}
function preParse($panels, $view) {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^related_doc_id$/')) {
$panels[$name][$rowCount][$key] = 'related_doc_name';
} else if($this->matches($column, '/^related_doc_rev_id$/')) {
$panels[$name][$rowCount][$key] = ($view == 'EditView') ? 'related_doc_rev_number' : 'related_doc_name';
} else if($this->matches($column, '/^user_date_format$/')) {
$panels[$name][$rowCount][$key] = 'active_date';
} else if($this->matches($column, '/^is_template_checked$/')) {
$panels[$name][$rowCount][$key] = 'is_template';
} else if($this->matches($column, '/^last_rev_creator$/')) {
$panels[$name][$rowCount][$key] = 'last_rev_created_name';
} else if($this->matches($column, '/^last_rev_date$/')) {
$panels[$name][$rowCount][$key] = 'last_rev_create_date';
} else if($this->matches($column, '/^save_file$/')) {
$panels[$name][$rowCount][$key] = 'filename';
} else if($this->matches($column, '/^subcategory$/')) {
$panels[$name][$rowCount][$key] = 'subcategory_id';
} else if($this->matches($column, '/^category$/')) {
$panels[$name][$rowCount][$key] = 'category_id';
} else if($this->matches($column, '/^related_document_version$/')) {
$panels[$name][$rowCount][$key] = 'related_doc_rev_number';
}
} //foreach
} //foreach
} //foreach
return $panels;
}
function parsePanels(& $panels, $view) {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/related_doc_id/si') ||
$this->matches($column, '/related_doc_rev_id/si') ||
$this->matches($column, '/latest_revision/si') ||
$this->matches($column, '/file_name/si')) {
$panels[$name][$rowCount][$key] = '';
}
} //foreach
} //foreach
} //foreach
return $panels;
}
}
?>

View File

@@ -0,0 +1,121 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* EmailAddressRule.php
*
* This is a utility base class to provide further refinement when converting
* pre 5.x files to the new meta-data rules. We basically scan for email1 or
* email2 defined outside of the email address panel and remove it.
*
* @author Collin Lee
*/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class EmailAddressRule extends BaseRule {
function EmailAddressRule() {
}
function parsePanels(& $panels, $view) {
if($view == 'DetailView') {
foreach($panels as $name=>$panel) {
if(preg_match('/lbl_email_addresses/si', $name)) {
continue;
}
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->isCustomField($column)) {
continue;
} else if(is_array($column) && !empty($column['name']) && preg_match('/^email(s|2)$/si', $column['name']) && !isset($column['type'])) {
$panels[$name][$rowCount][$key] = '';
} else if($this->matches($column, '/^email[1]_link$/si')) {
$panels[$name][$rowCount][$key] = 'email1';
} else if($this->matches($column, '/^email[2]_link$/si')) {
$panels[$name][$rowCount][$key] = '';
} else if(!is_array($column) && !empty($column)) {
if(preg_match('/^email(s|2)$/si', $column) ||
preg_match('/^invalid_email$/si', $column) ||
preg_match('/^email_opt_out$/si', $column) ||
preg_match('/^primary_email$/si', $column)) {
$panels[$name][$rowCount][$key] = '';
}
}
} //foreach
} //foreach
} //foreach
} else if($view == 'EditView') {
foreach($panels as $name=>$panel) {
if(preg_match('/lbl_email_addresses/si', $name)) {
continue;
}
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->isCustomField($column)) {
continue;
}
if($this->matches($column, '/email(s)*?([1|2])*?/si')) {
$panels[$name][$rowCount][$key] = '';
}
} //foreach
} //foreach
} //foreach
}
return $panels;
}
}
?>

View File

@@ -0,0 +1,90 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* EmptyRowRule.php
*
* This is a utility base class to provide further refinement when converting
* pre 5.x files to the new meta-data rules. This rule goes through the panels
* and deletes rows for which there are no fields.
*
* @author Collin Lee
*/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class EmptyRowRule extends BaseRule {
function EmptyRowRule() {
}
function parsePanels($panels, $view) {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
$emptyCount = 0;
foreach($row as $key=>$column) {
if(is_array($column) && (!isset($column['name']) || empty($column['name']))) {
$emptyCount++;
} else if(!is_array($column) && (!isset($column) || empty($column))) {
$emptyCount++;
}
} //foreach
// If we have unset everything, then just remove the whole row entirely
if($emptyCount == count($row)) {
unset($panels[$name][$rowCount]);
continue;
} else if(count($row) > 2) {
foreach($row as $key=>$column) {
if(empty($column) || $column == '') {
unset($panels[$name][$rowCount][$key]);
}
}
}
} //foreach
} //foreach
return $panels;
}
}
?>

View File

@@ -0,0 +1,65 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class LeadsParseRule extends BaseRule {
function LeadsParseRule() {
}
function preParse($panels, $view) {
if($view == 'DetailView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^lead_view_c$/')) {
$panels[$name][$rowCount][$key] = 'full_name';
}
} //foreach
} //foreach
} //foreach
}
return $panels;
}
}
?>

View File

@@ -0,0 +1,64 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/ActivitiesParseRule.php');
class MeetingsParseRule extends ActivitiesParseRule {
function MeetingsParseRule() {
}
function preParse($panels, $view) {
$panels = parent::preParse($panels, $view);
if($view == 'DetailView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
//Fix issue of not having parent_name in Meetings vardefs.php in pre 5.x versions
if($this->matches($column, '/^tag.parent$/') || $this->matches($column, '/^parent_id$/')) {
$panels[$name][$rowCount][$key] = 'parent_name';
}
} //foreach
} //foreach
} //foreach
}
return $panels;
}
}
?>

View File

@@ -0,0 +1,64 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class NotesParseRule extends BaseRule {
function NotesParseRule() {
}
function preParse($panels, $view) {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^related_doc_id$/')) {
$panels[$name][$rowCount][$key] = 'related_doc_name';
} else if($this->matches($column, '/^related_doc_rev_id$/')) {
$panels[$name][$rowCount][$key] = ($view == 'EditView') ? 'related_doc_rev_number' : 'related_doc_name';
} else if($this->matches($column, '/^filelink$/')) {
$panels[$name][$rowCount][$key] = 'filename';
}
} //foreach
} //foreach
} //foreach
return $panels;
}
}
?>

View File

@@ -0,0 +1,62 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class OpportunitiesParseRule extends BaseRule {
function OpportunitiesParseRule() {
}
function preParse($panels, $view) {
if($view == 'DetailView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if ($this->matches($column, '/^type$/i')) {
$panels[$name][$rowCount][$key] = 'opportunity_type';
}
} //foreach
} //foreach
} //foreach
} //if
return $panels;
}
}
?>

View File

@@ -0,0 +1,70 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* ParseRule.php
*
* This is a utility base class to provide further refinement when converting
* pre 5.x files to the new meta-data rules.
* @author Collin Lee
*/
class ParseRules {
function ParseRules() {
}
/**
* getRules
* Return Array of rules to run
*
*/
function getRules() {
$rules = array();
$rules[] = array("class"=>"UndefinedVardefRule", "file"=>"include/SugarFields/Parsers/Rules/UndefinedVardefRule.php");
$rules[] = array("class"=>"VariableCleanupRule", "file"=>"include/SugarFields/Parsers/Rules/VariableCleanupRule.php");
$rules[] = array("class"=>"VariableSubstitutionRule", "file"=>"include/SugarFields/Parsers/Rules/VariableSubstitutionRule.php");
$rules[] = array("class"=>"AddressRule", "file"=>"include/SugarFields/Parsers/Rules/AddressRule.php");
$rules[] = array("class"=>"EmailAddressRule", "file"=>"include/SugarFields/Parsers/Rules/EmailAddressRule.php");
$rules[] = array("class"=>"EmptyRowRule", "file"=>"include/SugarFields/Parsers/Rules/EmptyRowRule.php");
return $rules;
}
}
?>

View File

@@ -0,0 +1,68 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class ProductsParseRule extends BaseRule {
function ProductsParseRule() {
}
function preParse($panels, $view) {
if($view == 'DetailView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if ($this->matches($column, '/^url$/i')) {
$panels[$name][$rowCount][$key] = 'website';
} else if ($this->matches($column, '/^manufacturer$/i')) {
$panels[$name][$rowCount][$key] = 'manufacturer_name';
} else if ($this->matches($column, '/^category$/i')) {
$panels[$name][$rowCount][$key] = 'category_name';
} else if ($this->matches($column, '/^type$/i')) {
$panels[$name][$rowCount][$key] = 'type_name';
}
} //foreach
} //foreach
} //foreach
} //if
return $panels;
}
}
?>

View File

@@ -0,0 +1,130 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class QuotesParseRule extends BaseRule {
function QuotesParseRule() {
}
function preParse($panels, $view) {
if($view == 'DetailView') {
foreach($panels as $name=>$panel) {
if($name == 'default') {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/billing_address_country/')) {
$column['label'] = 'LBL_BILL_TO';
$column['name'] = 'billing_address_street';
$panels[$name][$rowCount][$key] = $column;
} else if($this->matches($column, '/register_address_country/')) {
$column['label'] = 'LBL_SHIP_TO';
$column['name'] = 'register_address_street';
$panels[$name][$rowCount][$key] = $column;
} else if($this->matches($column, '/^date_quote_closed$/')) {
$panels[$name][$rowCount][$key] = 'date_quote_expected_closed';
} else if($this->matches($column, '/^tag\.opportunity$/')) {
$panels[$name][$rowCount][$key] = 'opportunity_name';
}
} //foreach
} //foreach
} //if
} //foreach
}
if($view == 'EditView') {
$processedBillToPanel = false;
foreach($panels as $name=>$panel) {
// This panel is an exception in that it has nested tables...
if($name == 'lbl_bill_to' && !$processedBillToPanel) {
$billToPanel = $panel;
$newBillPanel = array();
foreach($billToPanel as $subpanel) {
$col = array();
foreach($subpanel as $rowCount=>$row) {
if(!is_array($row)) {
if(!$this->matches($row, '/^(register|billing)_address_(street|city|state|country|postalcode)$/si')) {
$col[] = $row;
}
} else {
foreach($row as $key=>$column) {
if(is_array($column)) {
continue;
}
if($this->matches($column, '/^(billing|register)_(account|contact)_name$/')) {
$match = $this->getMatch($column, '/^(billing|register)_(account|contact)_name$/');
$col[$match[0]] = $match[0];
} else if(!$this->matches($column, '/^(register|billing)_address_(street|city|state|country|postalcode)$/si')) {
$col[] = $column;
}
} //foreach
}
} //foreach
if(!empty($col)) {
$newBillPanel[] = $col;
}
} //foreach
$panels['lbl_bill_to'] = $newBillPanel;
$processedBillToPanel = true;
continue;
} //if
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
//We are just going to clean up address fields since we have
//to insert a new address panel anyway
if($this->matches($column, '/^(register|billing)_address_(street|city|state|country|postalcode)$/si')) {
$panels[$name][$rowCount][$key] = '';
}
} //foreach
} //foreach
} //foreach
}
return $panels;
}
}
?>

View File

@@ -0,0 +1,74 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* UndefinedVardefRule.php
*
* This is a utility base class to provide further refinement when converting
* pre 5.x files to the new meta-data rules.
*
* @author Collin Lee
*/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class UndefinedVardefRule extends BaseRule {
function UndefinedVardefRule() {
}
function parsePanels($panels, $view) {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if(is_array($column) && isset($column['name']) && empty($column['name'])) {
$panels[$name][$rowCount][$key] = '';
} else if(!is_array($column) && isset($column['name']) && empty($column['name'])) {
$panels[$name][$rowCount][$key] = '';
}
} //foreach
} //foreach
} //foreach
return $panels;
}
}
?>

View File

@@ -0,0 +1,105 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* VariableCleanupRule.php
*
* This is a utility base class to provide further refinement when converting
* pre 5.x files to the new meta-data rules.
*
* @author Collin Lee
*/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class VariableCleanupRule extends BaseRule {
function VariableCleanupRule() {
}
function parsePanels($panels, $view) {
if($view == 'DetailView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
//This converts variable ended with "_c_checked" to just "_c" (for checkboxes in DetailView)
if(!is_array($column) && isset($column) && preg_match('/(.*?)_c_checked$/s', $column, $matches)) {
if(count($matches) == 2) {
$panels[$name][$rowCount][$key] = $matches[1] . "_c";
}
} else if($this->matches($column, '/^parent_id$/si')) {
$panels[$name][$rowCount][$key] = '';
} else if($this->matches($column, '/^assigned_user_id$/si')) {
$panels[$name][$rowCount][$key] = '';
}
} //foreach
} //foreach
} //foreach
} else if ($view == 'EditView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^(.*?)_c\[\]$/s')) {
//This converts multienum variables named with [] suffix back to normal and removes custom code
$val = $this->getMatch($column, '/^(.*?)_c\[\]$/s');
$panels[$name][$rowCount][$key] = $val[1] . '_c';
} else if($this->matches($column, '/^parent_id$/si')) {
//Remove parent_id field (replaced with parent_name from master copy)
$panels[$name][$rowCount][$key] = '';
} else if($this->matches($column, '/^assigned_user_id$/si')) {
//Remove assigned_user_id field (replaced with assigned_user_name from master copy)
$panels[$name][$rowCount][$key] = '';
} else if($this->matches($column, '/^RADIOOPTIONS_/si')) {
//This converts radioenum variables
$val = $this->getMatch($column, '/^RADIOOPTIONS_(.*)?$/si');
$panels[$name][$rowCount][$key] = $val[1];
}
} //foreach
} //foreach
} //foreach
}
return $panels;
}
}
?>

View File

@@ -0,0 +1,136 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* VariableSubstitutionRule.php
*
* This is a utility base class to provide further refinement when converting
* pre 5.x files to the new meta-data rules. This rule substitutes the current
* definitions will the standard meta-data ones.
*
* @author Collin Lee
*/
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
class VariableSubstitutionRule extends BaseRule {
function VariableSubstitutionRule() {
}
function parsePanels($panels, $view) {
if($view == 'DetailView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^date_entered$/') || $this->matches($column, '/^created_by$/')) {
$panels[$name][$rowCount][$key] = array (
'name' => 'date_entered',
'customCode' => '{$fields.date_entered.value} {$APP.LBL_BY} {$fields.created_by_name.value}',
'label' => 'LBL_DATE_ENTERED',
);
} else if($this->matches($column, '/^team.*?(_name)?$/s')) {
$panels[$name][$rowCount][$key] = 'team_name';
} else if($this->matches($column, '/^date_modified$/') || $this->matches($column, '/^modified_by$/')) {
$panels[$name][$rowCount][$key] = array (
'name' => 'date_modified',
'customCode' => '{$fields.date_modified.value} {$APP.LBL_BY} {$fields.modified_by_name.value}',
'label' => 'LBL_DATE_MODIFIED',
);
} else if($this->matches($column, '/^assigned.*?(_to|_name|_link)$/s')) {
//Remove "assigned_to" variable... this will be replaced with "assigned_to"
$panels[$name][$rowCount][$key] = 'assigned_user_name';
} else if($this->matches($column, '/^vcard_link$/')) {
$panels[$name][$rowCount][$key] = array (
'name' => 'full_name',
'customCode' => '{$fields.full_name.value}&nbsp;&nbsp;<input type="button" class="button" name="vCardButton" value="{$MOD.LBL_VCARD}" onClick="document.vcard.submit();">',
'label' => 'LBL_NAME',
);
} else if($this->matches($column, '/^parent_type$/si')) {
$panels[$name][$rowCount][$key] = 'parent_name';
} else if($this->matches($column, '/^account_id$/')) {
$panels[$name][$rowCount][$key] = 'account_name';
} else if($this->matches($column, '/^contact_id$/')) {
$panels[$name][$rowCount][$key] = 'contact_name';
} else if($this->matches($column, '/^reports_to_id$/')) {
$panels[$name][$rowCount][$key] = 'report_to_name';
} else if($this->matches($column, '/^reminder_time$/')) {
$panels[$name][$rowCount][$key] = array(
'name'=>'reminder_checked',
'fields'=>array('reminder_checked', 'reminder_time')
);
} else if($this->matches($column, '/^currency(_name)*$/')) {
$panels[$name][$rowCount][$key] = 'currency_id';
} else if($this->matches($column, '/^quote_id$/')) {
$panels[$name][$rowCount][$key] = 'quote_name';
}
} //foreach
} //foreach
} //foreach
} else if($view == 'EditView') {
foreach($panels as $name=>$panel) {
foreach($panel as $rowCount=>$row) {
foreach($row as $key=>$column) {
if($this->matches($column, '/^salutation$/si') && is_array($column) && isset($column['fields']) && count($column['fields']) == 2) {
//Change salutation field to salutation + first_name'
$panels[$name][$rowCount][$key] = array (
'name' => 'first_name',
'customCode' => '{html_options name="salutation" options=$fields.salutation.options selected=$fields.salutation.value}&nbsp;<input name="first_name" size="25" maxlength="25" type="text" value="{$fields.first_name.value}">',
);
} else if($this->matches($column, '/^parent_type$/si')) {
$panels[$name][$rowCount][$key] = 'parent_name';
} else if($this->matches($column, '/^currency(_name)$/')) {
$panels[$name][$rowCount][$key] = 'currency_id';
} else if($this->matches($column, '/^quote_id$/')) {
$panels[$name][$rowCount][$key] = 'quote_name';
} else if($this->matches($column, '/^account_id$/')) {
$panels[$name][$rowCount][$key] = 'account_name';
} else if($this->matches($column, '/^contact_id$/')) {
$panels[$name][$rowCount][$key] = 'contact_name';
}
} //foreach
} //foreach
} //foreach
}
return $panels;
}
}
?>

View File

@@ -0,0 +1,269 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/SugarFields/Parsers/MetaParser.php');
class SearchFormMetaParser extends MetaParser {
function SearchFormMetaParser() {
$this->mView = 'Search';
}
/**
* parse
* @param $mixed
* @return $obj A MetaDataBean instance
**/
function parse($filePath, $vardefs = array(), $moduleDir = '', $merge=false, $masterCopy=null) {
$contents = file_get_contents($filePath);
$contents = $this->trimHTML($contents);
// Get the second table in the page and onward
$tables = $this->getElementsByType("table", $contents);
//basic search table
$basicSection = $this->processSection("basic", $tables[0], $filePath, $vardefs);
$advancedSection = $this->processSection("advanced", $tables[1], $filePath, $vardefs);
if(file_exists($masterCopy)) {
require($masterCopy);
$layouts = $searchdefs[$moduleDir]['layout'];
if(isset($layouts['basic_search'])) {
$basicSection = $this->mergeSection($basicSection, $layouts['basic_search']);
$basicSection = $this->applyRules($moduleDir, $basicSection);
}
if(isset($layouts['advanced_search'])) {
$advancedSection = $this->mergeSection($advancedSection, $layouts['advanced_search']);
$advancedSection = $this->applyRules($moduleDir, $advancedSection);
}
} //if
$header = "<?php\n\n";
$header .= "\$searchdefs['$moduleDir'] = array(
'templateMeta' => array('maxColumns' => '3', 'widths' => array('label' => '10', 'field' => '30')),
'layout' => array(
\n\t'basic_search' =>";
$header .= "\t" . var_export($basicSection, true);
$header .= "\n\t,'advanced_search' =>";
$header .= "\t" . var_export($advancedSection, true);
$header .= "
),\n
);
?>";
$header = preg_replace('/(\d+)[\s]=>[\s]?/',"",$header);
return $header;
}
function mergeSection($section, $masterSection) {
// Get all the names in the panel
$existingElements = array();
$existingLocation = array();
foreach($section as $rowKey=>$row) {
if(is_array($row) && !empty($row['name'])) {
$existingElements[$row['name']] = $row['name'];
$existingLocation[$row['name']] = array("row"=>$rowKey);
} else if(!is_array($row) && !empty($row)) {
$existingElements[$row] = $row;
$existingLocation[$row] = array("row"=>$rowKey);
}
} //foreach
// Now check against the $masterCopy
foreach($masterSection as $row) {
$addEntry = '';
$id = is_array($row) ? $row['name'] : $row;
/*
if(!isset($existingElements[$id])) {
//$addEntry = $row;
}
*/
if(isset($existingElements[$id])) {
//Use master copy instead
$section[$existingLocation[$id]['row']] = $row;
}
// Add it to the $panels
/*
if(!empty($addEntry)) {
$section[] = $addEntry;
}
*/
} //foreach
return $section;
}
function processSection($section, $table, $filePath, $vardefs=array()) {
$toptr = $this->getElementsByType("tr", $table);
if(!is_array($toptr) || empty($toptr)) {
$GLOBALS['log']->error("Could not process top row (<tr>) for $section section");
$GLOBALS['log']->error($table);
return array();
}
$tabledata = $this->getElementsByType("table", $toptr[0]);
if(empty($tabledata)) {
$GLOBALS['log']->error("Error: HTML format for SearchForm.html not as expected, results may not be accurate");
$GLOBALS['log']->error($toptr[0]);
$tabledata[0] = "<table>{$table}</table>";
}
if(is_array($tabledata) && !empty($tabledata[0])) {
$rows = $this->getElementsByType("tr", $tabledata[0]);
} else {
$rows = $toptr[0];
}
if(!is_array($rows)) {
return array();
}
$metarow = array();
foreach($rows as $trow) {
$tablecolumns = $this->getElementsByType("td", $trow);
$emptyCount = 0;
$metacolumn = array();
$col = null;
foreach($tablecolumns as $tcols) {
$spanValue = strtolower($this->getElementValue("span", $tcols));
$spanValue2 = strtolower($this->getElementValue("slot", $tcols));
$spanValue = !empty($spanValue2) ? $spanValue2 : $spanValue;
$spanValue3 = strtolower($this->getElementValue("td", $tcols));
$spanValue = !empty($spanValue3) ? $spanValue3 : $spanValue;
//Get all the editable form elements' names
$formElementNames = $this->getFormElementsNames($spanValue);
$customField = $this->getCustomField($formElementNames);
$name = '';
$fields = null;
$customCode = null;
if(!empty($customField)) {
// If it's a custom field we just set the name
$name = $customField;
} else if(is_array($formElementNames) && count($formElementNames) == 1
&& (isset($vardefs[$formElementNames[0]]) || $formElementNames[0] == 'current_user_only')) {
$name = $formElementNames[0];
}
//Skip and continue if $name is empty
if(empty($name)) {
continue;
}
// Build the entry
if(preg_match("/<textarea/si", $spanValue)) {
//special case for textarea form elements (add the displayParams)
$displayParams = array();
$displayParams['rows'] = $this->getTagAttribute("rows", $spanValue);
$displayParams['cols'] = $this->getTagAttribute("cols", $spanValue);
if(!empty($displayParams['rows']) && !empty($displayParams['cols'])) {
$field = array();
$field['name'] = $name;
$field['displayParams'] = $displayParams;
} else {
$field = $name;
}
$col = $field;
} else {
if(isset($fields)) {
$field = array();
$field['name'] = $name;
if(isset($fields)) {
$field['fields'] = $fields;
}
if(!empty($customCode)) {
$field['customCode'] = $customCode;
}
$col = $field;
} else {
$emptyCount = $name == '' ? $emptyCount + 1 : $emptyCount;
$col = $name;
}
} //if-else if-else block
$metarow[] = $col;
} //foreach
// One last final check. If $emptyCount does not equal Array $col count, don't add
if($emptyCount != count($col)) {
//$metarow[] = $col;
} //if
} //foreach
return $metarow;
}
function applyRules($moduleDir, $section=array()) {
require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
$baseRule = new BaseRule();
if(!is_array($section)) {
$GLOBALS['log']->error("Error: SearchFormMetaParser->applyRules expects Array");
return $section;
}
foreach($section as $key=>$row) {
//Override email1 fields
if($baseRule->matches($row, '/^email1$/si')) {
$section[$key] = array('name' => 'email', 'label' =>'LBL_ANY_EMAIL', 'type' => 'name');
}
}
return $section;
}
}
?>

View File

@@ -0,0 +1,150 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
class SugarFieldHandler {
function SugarFieldHandler() {
}
static function fixupFieldType($field) {
switch($field) {
case 'double':
case 'decimal':
$field = 'float';
break;
case 'uint':
case 'ulong':
case 'long':
case 'short':
case 'tinyint':
$field = 'int';
break;
case 'date':
$field = 'datetime';
break;
case 'url':
$field = 'link';
break;
case 'varchar':
$field = 'base';
break;
}
return ucfirst($field);
}
/**
* return the singleton of the SugarField
*
* @param field string field type
*/
static function getSugarField($field, $returnNullIfBase=false) {
static $sugarFieldObjects = array();
$field = self::fixupFieldType($field);
$field = ucfirst($field);
if(!isset($sugarFieldObjects[$field])) {
//check custom directory
if(file_exists('custom/include/SugarFields/Fields/' . $field . '/SugarField' . $field. '.php')){
$file = 'custom/include/SugarFields/Fields/' . $field . '/SugarField' . $field. '.php';
$type = $field;
//else check the fields directory
}else if(file_exists('include/SugarFields/Fields/' . $field . '/SugarField' . $field. '.php')){
$file = 'include/SugarFields/Fields/' . $field . '/SugarField' . $field. '.php';
$type = $field;
}else{
// No direct class, check the directories to see if they are defined
if( $returnNullIfBase &&
!is_dir('custom/include/SugarFields/Fields/'.$field) &&
!is_dir('include/SugarFields/Fields/'.$field) ) {
return null;
}
$file = 'include/SugarFields/Fields/Base/SugarFieldBase.php';
$type = 'Base';
}
require_once($file);
$class = 'SugarField' . $type;
//could be a custom class check it
$customClass = 'Custom' . $class;
if(class_exists($customClass)){
$sugarFieldObjects[$field] = new $customClass($field);
}else{
$sugarFieldObjects[$field] = new $class($field);
}
}
return $sugarFieldObjects[$field];
}
/**
* Returns the smarty code to be used in a template built by TemplateHandler
* The SugarField class is choosen dependant on the vardef's type field.
*
* @param parentFieldArray string name of the variable in the parent template for the bean's data
* @param vardef vardef field defintion
* @param displayType string the display type for the field (eg DetailView, EditView, etc)
* @param displayParam parameters for displayin
* available paramters are:
* * labelSpan - column span for the label
* * fieldSpan - column span for the field
*/
static function displaySmarty($parentFieldArray, $vardef, $displayType, $displayParams = array(), $tabindex = 1) {
$string = '';
$displayTypeFunc = 'get' . $displayType . 'Smarty'; // getDetailViewSmarty, getEditViewSmarty, etc...
// This will handle custom type fields.
// The incoming $vardef Array may have custom_type set.
// If so, set $vardef['type'] to the $vardef['custom_type'] value
if(isset($vardef['custom_type'])) {
$vardef['type'] = $vardef['custom_type'];
}
if(empty($vardef['type'])) {
$vardef['type'] = 'varchar';
}
$field = self::getSugarField($vardef['type']);
if ( !empty($vardef['function']) ) {
$string = $field->displayFromFunc($displayType, $parentFieldArray, $vardef, $displayParams, $tabindex);
} else {
$string = $field->$displayTypeFunc($parentFieldArray, $vardef, $displayParams, $tabindex);
}
return $string;
}
}
?>