function smarty_function_sugar_teamset_list($params, &$smarty)
{
    if (!isset($params['row']) && !isset($params['col'])) {
        $smarty->trigger_error("sugar_phone: missing parameters, cannot continue");
        return '';
    }
    require_once 'include/SugarFields/SugarFieldHandler.php';
    $sfh = new SugarFieldHandler();
    return $sfh->displaySmarty($params['row'], $params['vardef'], 'ListView', array('col' => $params['col']));
}
function smarty_function_sugar_field($params, &$smarty)
{
    if (!isset($params['vardef']) || !isset($params['displayType']) || !isset($params['parentFieldArray'])) {
        if (!isset($params['vardef'])) {
            $smarty->trigger_error("sugar_field: missing 'vardef' parameter");
        }
        if (!isset($params['displayType'])) {
            $smarty->trigger_error("sugar_field: missing 'displayType' parameter");
        }
        if (!isset($params['parentFieldArray'])) {
            $smarty->trigger_error("sugar_field: missing 'parentFieldArray' parameter");
        }
        return;
    }
    static $sfh;
    if (!isset($sfh)) {
        $sfh = new SugarFieldHandler();
    }
    if (!isset($params['displayParams'])) {
        $displayParams = array();
    } else {
        $displayParams = $params['displayParams'];
    }
    if (isset($params['labelSpan'])) {
        $displayParams['labelSpan'] = $params['labelSpan'];
    } else {
        $displayParams['labelSpan'] = null;
    }
    if (isset($params['fieldSpan'])) {
        $displayParams['fieldSpan'] = $params['fieldSpan'];
    } else {
        $displayParams['fieldSpan'] = null;
    }
    if (isset($params['typeOverride'])) {
        // override the type in the vardef?
        $params['vardef']['type'] = $params['typeOverride'];
    }
    if (isset($params['formName'])) {
        $displayParams['formName'] = $params['formName'];
    }
    $_contents = $sfh->displaySmarty($params['parentFieldArray'], $params['vardef'], $params['displayType'], $displayParams, $params['tabindex']);
    return $_contents;
}
function getModuleField($module, $fieldname, $aow_field, $view = 'EditView', $value = '', $alt_type = '')
{
    global $current_language, $app_strings, $app_list_strings, $current_user, $beanFiles, $beanList;
    // use the mod_strings for this module
    $mod_strings = return_module_language($current_language, $module);
    // set the filename for this control
    $file = create_cache_directory('modules/AOW_WorkFlow/') . $module . $view . $alt_type . $fieldname . '.tpl';
    if (!is_file($file) || inDeveloperMode() || !empty($_SESSION['developerMode'])) {
        if (!isset($vardef)) {
            require_once $beanFiles[$beanList[$module]];
            $focus = new $beanList[$module]();
            $vardef = $focus->getFieldDefinition($fieldname);
        }
        $displayParams = array();
        //$displayParams['formName'] = 'EditView';
        // if this is the id relation field, then don't have a pop-up selector.
        if ($vardef['type'] == 'relate' && $vardef['id_name'] == $vardef['name']) {
            $vardef['type'] = 'varchar';
        }
        if (isset($vardef['precision'])) {
            unset($vardef['precision']);
        }
        //$vardef['precision'] = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user);
        //TODO Fix datetimecomebo
        //temp work around
        if ($vardef['type'] == 'datetimecombo') {
            $vardef['type'] = 'datetime';
        }
        // trim down textbox display
        if ($vardef['type'] == 'text') {
            $vardef['rows'] = 2;
            $vardef['cols'] = 32;
        }
        // create the dropdowns for the parent type fields
        if ($vardef['type'] == 'parent_type') {
            $vardef['type'] = 'enum';
        }
        if ($vardef['type'] == 'link') {
            $vardef['type'] = 'relate';
            $vardef['rname'] = 'name';
            $vardef['id_name'] = $vardef['name'] . '_id';
            if ((!isset($vardef['module']) || $vardef['module'] == '') && $focus->load_relationship($vardef['name'])) {
                $vardef['module'] = $focus->{$vardef}['name']->getRelatedModuleName();
            }
        }
        //check for $alt_type
        if ($alt_type != '') {
            $vardef['type'] = $alt_type;
        }
        // remove the special text entry field function 'getEmailAddressWidget'
        if (isset($vardef['function']) && ($vardef['function'] == 'getEmailAddressWidget' || $vardef['function']['name'] == 'getEmailAddressWidget')) {
            unset($vardef['function']);
        }
        if (isset($vardef['name']) && ($vardef['name'] == 'date_entered' || $vardef['name'] == 'date_modified')) {
            $vardef['name'] = 'aow_temp_date';
        }
        // load SugarFieldHandler to render the field tpl file
        static $sfh;
        if (!isset($sfh)) {
            require_once 'include/SugarFields/SugarFieldHandler.php';
            $sfh = new SugarFieldHandler();
        }
        $contents = $sfh->displaySmarty('fields', $vardef, $view, $displayParams);
        // Remove all the copyright comments
        $contents = preg_replace('/\\{\\*[^\\}]*?\\*\\}/', '', $contents);
        if ($view == 'EditView' && ($vardef['type'] == 'relate' || $vardef['type'] == 'parent')) {
            $contents = str_replace('"' . $vardef['id_name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.id_name}"{literal}', $contents);
            $contents = str_replace('"' . $vardef['name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.name}"{literal}', $contents);
        }
        // hack to disable one of the js calls in this control
        if (isset($vardef['function']) && ($vardef['function'] == 'getCurrencyDropDown' || $vardef['function']['name'] == 'getCurrencyDropDown')) {
            $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}";
        }
        // Save it to the cache file
        if ($fh = @sugar_fopen($file, 'w')) {
            fputs($fh, $contents);
            fclose($fh);
        }
    }
    // Now render the template we received
    $ss = new Sugar_Smarty();
    // Create Smarty variables for the Calendar picker widget
    global $timedate;
    $time_format = $timedate->get_user_time_format();
    $date_format = $timedate->get_cal_date_format();
    $ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
    $ss->assign('TIME_FORMAT', $time_format);
    $time_separator = ":";
    $match = array();
    if (preg_match('/\\d+([^\\d])\\d+([^\\d]*)/s', $time_format, $match)) {
        $time_separator = $match[1];
    }
    $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
    if (!isset($match[2]) || $match[2] == '') {
        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M");
    } else {
        $pm = $match[2] == "pm" ? "%P" : "%p";
        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm);
    }
    $ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week());
    // populate the fieldlist from the vardefs
    $fieldlist = array();
    if (!isset($focus) || !$focus instanceof SugarBean) {
        require_once $beanFiles[$beanList[$module]];
    }
    $focus = new $beanList[$module]();
    // create the dropdowns for the parent type fields
    if (isset($vardef['type']) && $vardef['type'] == 'parent_type') {
        $focus->field_defs[$vardef['name']]['options'] = $focus->field_defs[$vardef['group']]['options'];
    }
    $vardefFields = $focus->getFieldDefinitions();
    foreach ($vardefFields as $name => $properties) {
        $fieldlist[$name] = $properties;
        // fill in enums
        if (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']])) {
            $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']];
        } elseif (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']])) {
            $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']];
        }
        // Bug 22730: make sure all enums have the ability to select blank as the default value.
        if (!isset($fieldlist[$name]['options'][''])) {
            $fieldlist[$name]['options'][''] = '';
        }
    }
    // fill in function return values
    if (!in_array($fieldname, array('email1', 'email2'))) {
        if (!empty($fieldlist[$fieldname]['function']['returns']) && $fieldlist[$fieldname]['function']['returns'] == 'html') {
            $function = $fieldlist[$fieldname]['function']['name'];
            // include various functions required in the various vardefs
            if (isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include'])) {
                require_once $fieldlist[$fieldname]['function']['include'];
            }
            $_REQUEST[$fieldname] = $value;
            $value = $function($focus, $fieldname, $value, $view);
            $value = str_ireplace($fieldname, $aow_field, $value);
        }
    }
    if ($fieldlist[$fieldname]['type'] == 'link') {
        $fieldlist[$fieldname]['id_name'] = $fieldlist[$fieldname]['name'] . '_id';
        if ((!isset($fieldlist[$fieldname]['module']) || $fieldlist[$fieldname]['module'] == '') && $focus->load_relationship($fieldlist[$fieldname]['name'])) {
            $fieldlist[$fieldname]['module'] = $focus->{$fieldlist}[$fieldname]['name']->getRelatedModuleName();
        }
    }
    if (isset($fieldlist[$fieldname]['name']) && ($fieldlist[$fieldname]['name'] == 'date_entered' || $fieldlist[$fieldname]['name'] == 'date_modified')) {
        $fieldlist[$fieldname]['name'] = 'aow_temp_date';
        $fieldlist['aow_temp_date'] = $fieldlist[$fieldname];
        $fieldname = 'aow_temp_date';
    }
    if (isset($fieldlist[$fieldname]['id_name']) && $fieldlist[$fieldname]['id_name'] != '' && $fieldlist[$fieldname]['id_name'] != $fieldlist[$fieldname]['name']) {
        $rel_value = $value;
        if (isset($fieldlist[$fieldname]['module']) && $fieldlist[$fieldname]['module'] == 'Users') {
            $rel_value = get_assigned_user_name($value);
        } else {
            if (isset($fieldlist[$fieldname]['module'])) {
                require_once $beanFiles[$beanList[$fieldlist[$fieldname]['module']]];
                $rel_focus = new $beanList[$fieldlist[$fieldname]['module']]();
                $rel_focus->retrieve($value);
                if (isset($fieldlist[$fieldname]['rname']) && $fieldlist[$fieldname]['rname'] != '') {
                    $rel_value = $rel_focus->{$fieldlist}[$fieldname]['rname'];
                } else {
                    $rel_value = $rel_focus->name;
                }
            }
        }
        $fieldlist[$fieldlist[$fieldname]['id_name']]['value'] = $value;
        $fieldlist[$fieldname]['value'] = $rel_value;
        $fieldlist[$fieldname]['id_name'] = $aow_field;
        $fieldlist[$fieldlist[$fieldname]['id_name']]['name'] = $aow_field;
        $fieldlist[$fieldname]['name'] = $aow_field . '_display';
    } else {
        if (isset($fieldlist[$fieldname]['type']) && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime' || $fieldlist[$fieldname]['type'] == 'date')) {
            $fieldlist[$fieldname]['value'] = $timedate->to_display_date($value);
            //$fieldlist[$fieldname]['value'] = $timedate->to_display_date_time($value, true, true);
            //$fieldlist[$fieldname]['value'] = $value;
            $fieldlist[$fieldname]['name'] = $aow_field;
        } else {
            $fieldlist[$fieldname]['value'] = $value;
            $fieldlist[$fieldname]['name'] = $aow_field;
        }
    }
    $ss->assign("fields", $fieldlist);
    $ss->assign("form_name", $view);
    $ss->assign("bean", $focus);
    // add in any additional strings
    $ss->assign("MOD", $mod_strings);
    $ss->assign("APP", $app_strings);
    //$return = str_replace($fieldname,$ss->fetch($file));
    return $ss->fetch($file);
}
Exemple #4
0
 /**
  * @return void
  * @param unknown $data
  * @param unknown $xTemplateSection
  * @param unknown $html_varName
  * @desc INTERNAL FUNCTION handles the rows
  */
 function process_dynamic_listview_rows($data, $parent_data, $xtemplateSection, $html_varName, $subpanel_def)
 {
     global $odd_bg;
     global $even_bg;
     global $hilite_bg;
     global $click_bg;
     $this->xTemplate->assign("BG_HILITE", $hilite_bg);
     $this->xTemplate->assign('CHECKALL', "<img src='" . SugarThemeRegistry::current()->getImageURL('blank.gif') . "' width=\"1\" height=\"1\" alt=\"\" />");
     //$this->xTemplate->assign("BG_CLICK", $click_bg);
     $oddRow = true;
     $count = 0;
     reset($data);
     //GETTING OFFSET
     $offset = $this->getOffset($html_varName);
     //$totaltime = 0;
     $processed_ids = array();
     $fill_additional_fields = array();
     //Either retrieve the is_fill_in_additional_fields property from the lone
     //subpanel or visit each subpanel's subpanels to retreive the is_fill_in_addition_fields
     //property
     $subpanel_list = array();
     if ($subpanel_def->isCollection()) {
         $subpanel_list = $subpanel_def->sub_subpanels;
     } else {
         $subpanel_list[] = $subpanel_def;
     }
     foreach ($subpanel_list as $this_subpanel) {
         if ($this_subpanel->is_fill_in_additional_fields()) {
             $fill_additional_fields[] = $this_subpanel->bean_name;
             $fill_additional_fields[$this_subpanel->bean_name] = true;
         }
     }
     if (empty($data)) {
         $this->xTemplate->assign("ROW_COLOR", 'oddListRow');
         $thepanel = $subpanel_def;
         if ($subpanel_def->isCollection()) {
             $thepanel = $subpanel_def->get_header_panel_def();
         }
         $this->xTemplate->assign("COL_COUNT", count($thepanel->get_list_fields()));
         $this->xTemplate->parse($xtemplateSection . ".nodata");
     }
     while (list($aVal, $aItem) = each($data)) {
         $aItem->check_date_relationships_load();
         // TODO: expensive and needs to be removed and done better elsewhere
         if (!empty($fill_additional_fields[$aItem->object_name]) || $aItem->object_name == 'Case' && !empty($fill_additional_fields['aCase'])) {
             $aItem->fill_in_additional_list_fields();
             //$aItem->fill_in_additional_detail_fields();
         }
         //rrs bug: 25343
         $aItem->call_custom_logic("process_record");
         if (isset($parent_data[$aItem->id])) {
             $aItem->parent_name = $parent_data[$aItem->id]['parent_name'];
             if (!empty($parent_data[$aItem->id]['parent_name_owner'])) {
                 $aItem->parent_name_owner = $parent_data[$aItem->id]['parent_name_owner'];
                 $aItem->parent_name_mod = $parent_data[$aItem->id]['parent_name_mod'];
             }
         }
         $fields = $aItem->get_list_view_data();
         if (isset($processed_ids[$aItem->id])) {
             continue;
         } else {
             $processed_ids[$aItem->id] = 1;
         }
         //ADD OFFSET TO ARRAY
         $fields['OFFSET'] = $offset + $count + 1;
         if ($this->shouldProcess) {
             if ($aItem->ACLAccess('EditView')) {
                 $this->xTemplate->assign('PREROW', "<input type='checkbox' class='checkbox' name='mass[]' value='" . $fields['ID'] . "' />");
             } else {
                 $this->xTemplate->assign('PREROW', '');
             }
             if ($aItem->ACLAccess('DetailView')) {
                 $this->xTemplate->assign('TAG_NAME', 'a');
             } else {
                 $this->xTemplate->assign('TAG_NAME', 'span');
             }
             $this->xTemplate->assign('CHECKALL', "<input type='checkbox' class='checkbox' name='massall' id='massall' value='' onclick='sListView.check_all(document.MassUpdate, \"mass[]\", this.checked);' />");
         }
         if ($oddRow) {
             $ROW_COLOR = 'oddListRow';
             $BG_COLOR = $odd_bg;
         } else {
             $ROW_COLOR = 'evenListRow';
             $BG_COLOR = $even_bg;
         }
         $oddRow = !$oddRow;
         $this->xTemplate->assign("ROW_COLOR", $ROW_COLOR);
         $this->xTemplate->assign("BG_COLOR", $BG_COLOR);
         $layout_manager = $this->getLayoutManager();
         $layout_manager->setAttribute('context', 'List');
         $layout_manager->setAttribute('image_path', $this->local_image_path);
         $layout_manager->setAttribute('module_name', $subpanel_def->_instance_properties['module']);
         if (!empty($this->child_focus)) {
             $layout_manager->setAttribute('related_module_name', $this->child_focus->module_dir);
         }
         //AG$subpanel_data = $this->list_field_defs;
         //$bla = array_pop($subpanel_data);
         //select which sub-panel to display here, the decision will be made based on the type of
         //the sub-panel and panel in the bean being processed.
         if ($subpanel_def->isCollection()) {
             $thepanel = $subpanel_def->sub_subpanels[$aItem->panel_name];
         } else {
             $thepanel = $subpanel_def;
         }
         //get data source name
         $linked_field = $thepanel->get_data_source_name();
         $linked_field_set = $thepanel->get_data_source_name(true);
         foreach ($thepanel->get_list_fields() as $field_name => $list_field) {
             //add linked field attribute to the array.
             $list_field['linked_field'] = $linked_field;
             $list_field['linked_field_set'] = $linked_field_set;
             $usage = empty($list_field['usage']) ? '' : $list_field['usage'];
             if ($usage != 'query_only') {
                 $list_field['name'] = $field_name;
                 $module_field = $field_name . '_mod';
                 $owner_field = $field_name . '_owner';
                 if (!empty($aItem->{$module_field})) {
                     $list_field['owner_id'] = $aItem->{$owner_field};
                     $list_field['owner_module'] = $aItem->{$module_field};
                 } else {
                     $list_field['owner_id'] = false;
                     $list_field['owner_module'] = false;
                 }
                 if (isset($list_field['alias'])) {
                     $list_field['name'] = $list_field['alias'];
                 } else {
                     $list_field['name'] = $field_name;
                 }
                 $list_field['fields'] = $fields;
                 $list_field['module'] = $aItem->module_dir;
                 $list_field['start_link_wrapper'] = $this->start_link_wrapper;
                 $list_field['end_link_wrapper'] = $this->end_link_wrapper;
                 $list_field['subpanel_id'] = $this->subpanel_id;
                 $list_field['DetailView'] = $aItem->ACLAccess('DetailView');
                 $list_field['ListView'] = $aItem->ACLAccess('ListView');
                 $list_field['EditView'] = $aItem->ACLAccess('EditView');
                 $list_field['Delete'] = $aItem->ACLAccess('Delete');
                 if (isset($aItem->field_defs[strtolower($list_field['name'])])) {
                     require_once 'include/SugarFields/SugarFieldHandler.php';
                     // We need to see if a sugar field exists for this field type first,
                     // if it doesn't, toss it at the old sugarWidgets. This is for
                     // backwards compatibilty and will be removed in a future release
                     $vardef = $aItem->field_defs[strtolower($list_field['name'])];
                     if (isset($vardef['type'])) {
                         $fieldType = isset($vardef['custom_type']) ? $vardef['custom_type'] : $vardef['type'];
                         $tmpField = SugarFieldHandler::getSugarField($fieldType, true);
                     } else {
                         $tmpField = NULL;
                     }
                     if ($tmpField != NULL) {
                         $widget_contents = SugarFieldHandler::displaySmarty($list_field['fields'], $vardef, 'ListView', $list_field);
                     } else {
                         // No SugarField for this particular type
                         // Use the old, icky, SugarWidget for now
                         $widget_contents = $layout_manager->widgetDisplay($list_field);
                     }
                     if (isset($list_field['widget_class']) && $list_field['widget_class'] == 'SubPanelDetailViewLink') {
                         // We need to call into the old SugarWidgets for the time being, so it can generate a proper link with all the various corner-cases handled
                         // So we'll populate the field data with the pre-rendered display for the field
                         $list_field['fields'][$field_name] = $widget_contents;
                         if ('full_name' == $field_name) {
                             //bug #32465
                             $list_field['fields'][strtoupper($field_name)] = $widget_contents;
                         }
                         $widget_contents = $layout_manager->widgetDisplay($list_field);
                     } else {
                         if (isset($list_field['widget_class']) && $list_field['widget_class'] == 'SubPanelEmailLink') {
                             $widget_contents = $layout_manager->widgetDisplay($list_field);
                         }
                     }
                 } else {
                     // This handles the edit and remove buttons
                     $widget_contents = $layout_manager->widgetDisplay($list_field);
                 }
                 static $count;
                 if (!isset($count)) {
                     $count = 0;
                 } else {
                     $count++;
                 }
                 $this->xTemplate->assign('CELL_COUNT', $count);
                 if (empty($widget_contents)) {
                     $widget_contents = '&nbsp;';
                 }
                 $this->xTemplate->assign('CELL', $widget_contents);
                 $this->xTemplate->parse($xtemplateSection . ".row.cell");
             }
         }
         $aItem->setupCustomFields($aItem->module_dir);
         $aItem->custom_fields->populateAllXTPL($this->xTemplate, 'detail', $html_varName, $fields);
         $count++;
         $this->xTemplate->parse($xtemplateSection . ".row");
     }
     $this->xTemplate->parse($xtemplateSection);
 }
Exemple #5
0
/**
 * Returns an input control for this fieldname given
 *
 * @param  string $module
 * @param  string $fieldname
 * @param  string $vardef
 * @param  string $value
 * @return string html for input element for this control
 */
function getControl($module, $fieldname, $vardef = null, $value = '')
{
    global $current_language, $app_strings, $dictionary, $app_list_strings;
    // use the mod_strings for this module
    $mod_strings = return_module_language($current_language, $module);
    // set the filename for this control
    $file = create_cache_directory('modules/Import/') . $module . $fieldname . '.tpl';
    if (!is_file($file) || !empty($GLOBALS['sugar_config']['developerMode']) || !empty($_SESSION['developerMode'])) {
        if (!isset($vardef)) {
            $focus = loadBean($module);
            $vardef = $focus->getFieldDefinition($fieldname);
        }
        // if this is the id relation field, then don't have a pop-up selector.
        if ($vardef['type'] == 'relate' && $vardef['id_name'] == $vardef['name']) {
            $vardef['type'] = 'varchar';
        }
        // create the dropdowns for the parent type fields
        if ($vardef['type'] == 'parent_type') {
            $vardef['type'] = 'enum';
        }
        // remove the special text entry field function 'getEmailAddressWidget'
        if (isset($vardef['function']) && ($vardef['function'] == 'getEmailAddressWidget' || $vardef['function']['name'] == 'getEmailAddressWidget')) {
            unset($vardef['function']);
        }
        // load SugarFieldHandler to render the field tpl file
        static $sfh;
        if (!isset($sfh)) {
            require_once 'include/SugarFields/SugarFieldHandler.php';
            $sfh = new SugarFieldHandler();
        }
        $displayParams = array();
        $displayParams['formName'] = 'importstep3';
        $contents = $sfh->displaySmarty('fields', $vardef, 'ImportView', $displayParams);
        // Remove all the copyright comments
        $contents = preg_replace('/\\{\\*[^\\}]*?\\*\\}/', '', $contents);
        // hack to disable one of the js calls in this control
        if (isset($vardef['function']) && ($vardef['function'] == 'getCurrencyDropDown' || $vardef['function']['name'] == 'getCurrencyDropDown')) {
            $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}";
        }
        // Save it to the cache file
        if ($fh = @sugar_fopen($file, 'w')) {
            fputs($fh, $contents);
            fclose($fh);
        }
    }
    // Now render the template we received
    $ss = new Sugar_Smarty();
    // Create Smarty variables for the Calendar picker widget
    global $timedate;
    $time_format = $timedate->get_user_time_format();
    $date_format = $timedate->get_cal_date_format();
    $ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
    $ss->assign('TIME_FORMAT', $time_format);
    $time_separator = ":";
    $match = array();
    if (preg_match('/\\d+([^\\d])\\d+([^\\d]*)/s', $time_format, $match)) {
        $time_separator = $match[1];
    }
    $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
    if (!isset($match[2]) || $match[2] == '') {
        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M");
    } else {
        $pm = $match[2] == "pm" ? "%P" : "%p";
        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm);
    }
    // populate the fieldlist from the vardefs
    $fieldlist = array();
    if (!isset($focus) || !$focus instanceof SugarBean) {
        $focus = loadBean($module);
    }
    // create the dropdowns for the parent type fields
    if ($vardef['type'] == 'parent_type') {
        $focus->field_defs[$vardef['name']]['options'] = $focus->field_defs[$vardef['group']]['options'];
    }
    $vardefFields = $focus->getFieldDefinitions();
    foreach ($vardefFields as $name => $properties) {
        $fieldlist[$name] = $properties;
        // fill in enums
        if (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']])) {
            $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']];
        } elseif (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']])) {
            $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']];
        }
        // Bug 22730: make sure all enums have the ability to select blank as the default value.
        if (!isset($fieldlist[$name]['options'][''])) {
            $fieldlist[$name]['options'][''] = '';
        }
    }
    // fill in function return values
    if (!in_array($fieldname, array('email1', 'email2'))) {
        if (!empty($fieldlist[$fieldname]['function']['returns']) && $fieldlist[$fieldname]['function']['returns'] == 'html') {
            $function = $fieldlist[$fieldname]['function']['name'];
            // include various functions required in the various vardefs
            if (isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include'])) {
                require_once $fieldlist[$fieldname]['function']['include'];
            }
            $value = $function($focus, $fieldname, $value, 'EditView');
            // Bug 22730 - add a hack for the currency type dropdown, since it's built by a function.
            if (preg_match('/getCurrency.*DropDown/s', $function)) {
                $value = str_ireplace('</select>', '<option value="">' . $app_strings['LBL_NONE'] . '</option></select>', $value);
            }
        } elseif ($fieldname == 'assigned_user_name' && empty($value)) {
            $fieldlist['assigned_user_id']['value'] = $GLOBALS['current_user']->id;
            $value = get_assigned_user_name($GLOBALS['current_user']->id);
        } elseif ($fieldname == 'team_name' && empty($value)) {
            $value = json_encode(array());
        }
    }
    $fieldlist[$fieldname]['value'] = $value;
    $ss->assign("fields", $fieldlist);
    $ss->assign("form_name", 'importstep3');
    $ss->assign("bean", $focus);
    // add in any additional strings
    $ss->assign("MOD", $mod_strings);
    $ss->assign("APP", $app_strings);
    return $ss->fetch($file);
}
Exemple #6
0
 /**
  * @return void
  * @param unknown $data
  * @param unknown $xTemplateSection
  * @param unknown $html_varName
  * @desc INTERNAL FUNCTION handles the rows
  */
 function process_dynamic_listview_rows($data, $parent_data, $xtemplateSection, $html_varName, $subpanel_def)
 {
     global $subpanel_item_count;
     global $odd_bg;
     global $even_bg;
     global $hilite_bg;
     global $click_bg;
     $this->xTemplate->assign("BG_HILITE", $hilite_bg);
     $this->xTemplate->assign('CHECKALL', SugarThemeRegistry::current()->getImage('blank', '', 1, 1, ".gif", ''));
     //$this->xTemplate->assign("BG_CLICK", $click_bg);
     $subpanel_item_count = 0;
     $oddRow = true;
     $count = 0;
     reset($data);
     //GETTING OFFSET
     $offset = $this->getOffset($html_varName);
     //$totaltime = 0;
     $processed_ids = array();
     $fill_additional_fields = array();
     //Either retrieve the is_fill_in_additional_fields property from the lone
     //subpanel or visit each subpanel's subpanels to retrieve the is_fill_in_addition_fields
     //property
     $subpanel_list = array();
     if ($subpanel_def->isCollection()) {
         $subpanel_list = $subpanel_def->sub_subpanels;
     } else {
         $subpanel_list[] = $subpanel_def;
     }
     foreach ($subpanel_list as $this_subpanel) {
         if ($this_subpanel->is_fill_in_additional_fields()) {
             $fill_additional_fields[] = $this_subpanel->bean_name;
             $fill_additional_fields[$this_subpanel->bean_name] = true;
         }
     }
     if (empty($data)) {
         $this->xTemplate->assign("ROW_COLOR", 'oddListRow');
         $thepanel = $subpanel_def;
         if ($subpanel_def->isCollection()) {
             $thepanel = $subpanel_def->get_header_panel_def();
         }
         $this->xTemplate->assign("COL_COUNT", count($thepanel->get_list_fields()));
         $this->xTemplate->parse($xtemplateSection . ".nodata");
     }
     while (list($aVal, $aItem) = each($data)) {
         $subpanel_item_count++;
         $aItem->check_date_relationships_load();
         // TODO: expensive and needs to be removed and done better elsewhere
         if (!empty($fill_additional_fields[$aItem->object_name]) || $aItem->object_name == 'Case' && !empty($fill_additional_fields['aCase'])) {
             $aItem->fill_in_additional_list_fields();
             //$aItem->fill_in_additional_detail_fields();
         }
         //rrs bug: 25343
         $aItem->call_custom_logic("process_record");
         if (isset($parent_data[$aItem->id])) {
             $aItem->parent_name = $parent_data[$aItem->id]['parent_name'];
             if (!empty($parent_data[$aItem->id]['parent_name_owner'])) {
                 $aItem->parent_name_owner = $parent_data[$aItem->id]['parent_name_owner'];
                 $aItem->parent_name_mod = $parent_data[$aItem->id]['parent_name_mod'];
             }
         }
         $fields = $aItem->get_list_view_data();
         if (isset($processed_ids[$aItem->id])) {
             continue;
         } else {
             $processed_ids[$aItem->id] = 1;
         }
         //ADD OFFSET TO ARRAY
         $fields['OFFSET'] = $offset + $count + 1;
         if ($this->shouldProcess) {
             if ($aItem->ACLAccess('EditView')) {
                 $this->xTemplate->assign('PREROW', "<input type='checkbox' class='checkbox' name='mass[]' value='" . $fields['ID'] . "' />");
             } else {
                 $this->xTemplate->assign('PREROW', '');
             }
             if ($aItem->ACLAccess('DetailView')) {
                 $this->xTemplate->assign('TAG_NAME', 'a');
             } else {
                 $this->xTemplate->assign('TAG_NAME', 'span');
             }
             $this->xTemplate->assign('CHECKALL', "<input type='checkbox'  title='" . $GLOBALS['app_strings']['LBL_SELECT_ALL_TITLE'] . "' class='checkbox' name='massall' id='massall' value='' onclick='sListView.check_all(document.MassUpdate, \"mass[]\", this.checked);' />");
         }
         if ($oddRow) {
             $ROW_COLOR = 'oddListRow';
             $BG_COLOR = $odd_bg;
         } else {
             $ROW_COLOR = 'evenListRow';
             $BG_COLOR = $even_bg;
         }
         $oddRow = !$oddRow;
         $button_contents = array();
         $this->xTemplate->assign("ROW_COLOR", $ROW_COLOR);
         $this->xTemplate->assign("BG_COLOR", $BG_COLOR);
         $layout_manager = $this->getLayoutManager();
         $layout_manager->setAttribute('context', 'List');
         $layout_manager->setAttribute('image_path', $this->local_image_path);
         $layout_manager->setAttribute('module_name', $subpanel_def->_instance_properties['module']);
         if (!empty($this->child_focus)) {
             $layout_manager->setAttribute('related_module_name', $this->child_focus->module_dir);
         }
         //AG$subpanel_data = $this->list_field_defs;
         //$bla = array_pop($subpanel_data);
         //select which sub-panel to display here, the decision will be made based on the type of
         //the sub-panel and panel in the bean being processed.
         if ($subpanel_def->isCollection()) {
             $thepanel = $subpanel_def->sub_subpanels[$aItem->panel_name];
         } else {
             $thepanel = $subpanel_def;
         }
         //get data source name
         $linked_field = $thepanel->get_data_source_name();
         $linked_field_set = $thepanel->get_data_source_name(true);
         static $count;
         if (!isset($count)) {
             $count = 0;
         }
         $field_acl['DetailView'] = $aItem->ACLAccess('DetailView');
         $field_acl['ListView'] = $aItem->ACLAccess('ListView');
         $field_acl['EditView'] = $aItem->ACLAccess('EditView');
         $field_acl['Delete'] = $aItem->ACLAccess('Delete');
         foreach ($thepanel->get_list_fields() as $field_name => $list_field) {
             //add linked field attribute to the array.
             $list_field['linked_field'] = $linked_field;
             $list_field['linked_field_set'] = $linked_field_set;
             $usage = empty($list_field['usage']) ? '' : $list_field['usage'];
             if ($usage != 'query_only') {
                 $list_field['name'] = $field_name;
                 $module_field = $field_name . '_mod';
                 $owner_field = $field_name . '_owner';
                 if (!empty($aItem->{$module_field})) {
                     $list_field['owner_id'] = $aItem->{$owner_field};
                     $list_field['owner_module'] = $aItem->{$module_field};
                 } else {
                     $list_field['owner_id'] = false;
                     $list_field['owner_module'] = false;
                 }
                 if (isset($list_field['alias'])) {
                     $list_field['name'] = $list_field['alias'];
                 } else {
                     $list_field['name'] = $field_name;
                 }
                 $list_field['fields'] = $fields;
                 $list_field['module'] = $aItem->module_dir;
                 $list_field['start_link_wrapper'] = $this->start_link_wrapper;
                 $list_field['end_link_wrapper'] = $this->end_link_wrapper;
                 $list_field['subpanel_id'] = $this->subpanel_id;
                 $list_field += $field_acl;
                 if (isset($aItem->field_defs[strtolower($list_field['name'])])) {
                     require_once 'include/SugarFields/SugarFieldHandler.php';
                     // We need to see if a sugar field exists for this field type first,
                     // if it doesn't, toss it at the old sugarWidgets. This is for
                     // backwards compatibility and will be removed in a future release
                     $vardef = $aItem->field_defs[strtolower($list_field['name'])];
                     if (isset($vardef['type'])) {
                         $fieldType = isset($vardef['custom_type']) ? $vardef['custom_type'] : $vardef['type'];
                         $tmpField = SugarFieldHandler::getSugarField($fieldType, true);
                     } else {
                         $tmpField = NULL;
                     }
                     if ($tmpField != NULL) {
                         $widget_contents = SugarFieldHandler::displaySmarty($list_field['fields'], $vardef, 'ListView', $list_field);
                     } else {
                         // No SugarField for this particular type
                         // Use the old, icky, SugarWidget for now
                         $widget_contents = $layout_manager->widgetDisplay($list_field);
                     }
                     if (isset($list_field['widget_class']) && $list_field['widget_class'] == 'SubPanelDetailViewLink') {
                         // We need to call into the old SugarWidgets for the time being, so it can generate a proper link with all the various corner-cases handled
                         // So we'll populate the field data with the pre-rendered display for the field
                         $list_field['fields'][$field_name] = $widget_contents;
                         if ('full_name' == $field_name) {
                             //bug #32465
                             $list_field['fields'][strtoupper($field_name)] = $widget_contents;
                         }
                         //vardef source is non db, assign the field name to varname for processing of column.
                         if (!empty($vardef['source']) && $vardef['source'] == 'non-db') {
                             $list_field['varname'] = $field_name;
                         }
                         $widget_contents = $layout_manager->widgetDisplay($list_field);
                     } else {
                         if (isset($list_field['widget_class']) && $list_field['widget_class'] == 'SubPanelEmailLink') {
                             $widget_contents = $layout_manager->widgetDisplay($list_field);
                         }
                     }
                     $count++;
                     $this->xTemplate->assign('CELL_COUNT', $count);
                     $this->xTemplate->assign('CLASS', "");
                     if (empty($widget_contents)) {
                         $widget_contents = '&nbsp;';
                     }
                     $this->xTemplate->assign('CELL', $widget_contents);
                     $this->xTemplate->parse($xtemplateSection . ".row.cell");
                 } else {
                     // This handles the edit and remove buttons and icon widget
                     if (isset($list_field['widget_class']) && $list_field['widget_class'] == "SubPanelIcon") {
                         $count++;
                         $widget_contents = $layout_manager->widgetDisplay($list_field);
                         $this->xTemplate->assign('CELL_COUNT', $count);
                         $this->xTemplate->assign('CLASS', "");
                         if (empty($widget_contents)) {
                             $widget_contents = '&nbsp;';
                         }
                         $this->xTemplate->assign('CELL', $widget_contents);
                         $this->xTemplate->parse($xtemplateSection . ".row.cell");
                     } elseif (preg_match("/button/i", $list_field['name'])) {
                         if ($layout_manager->widgetDisplay($list_field) != "") {
                             $button_contents[] = $layout_manager->widgetDisplay($list_field);
                         }
                     } else {
                         $count++;
                         $this->xTemplate->assign('CLASS', "");
                         $widget_contents = $layout_manager->widgetDisplay($list_field);
                         $this->xTemplate->assign('CELL_COUNT', $count);
                         if (empty($widget_contents)) {
                             $widget_contents = '&nbsp;';
                         }
                         $this->xTemplate->assign('CELL', $widget_contents);
                         $this->xTemplate->parse($xtemplateSection . ".row.cell");
                     }
                 }
             }
         }
         // Make sure we have at least one button before rendering a column for
         // the action buttons in a list view. Relevant bugs: #51647 and #51640.
         if (isset($button_contents[0])) {
             // this is for inline buttons on listviews
             // bug#51275: smarty widget to help provide the action menu functionality as it is currently sprinkled throughout the app with html
             require_once 'include/Smarty/plugins/function.sugar_action_menu.php';
             $tempid = create_guid();
             $button_contents[0] = "<div style='display: inline' id='{$tempid}'>" . $button_contents[0] . "</div>";
             $action_button = smarty_function_sugar_action_menu(array('id' => $tempid, 'buttons' => $button_contents, 'class' => 'clickMenu subpanel records fancymenu button', 'flat' => false), $this->xTemplate);
             $this->xTemplate->assign('CLASS', "inlineButtons");
             $this->xTemplate->assign('CELL_COUNT', ++$count);
             //Bug#51275 for beta3 pre_script is not required any more
             $this->xTemplate->assign('CELL', $action_button);
             $this->xTemplate->parse($xtemplateSection . ".row.cell");
         }
         $aItem->setupCustomFields($aItem->module_dir);
         $aItem->custom_fields->populateAllXTPL($this->xTemplate, 'detail', $html_varName, $fields);
         $count++;
         $this->xTemplate->parse($xtemplateSection . ".row");
     }
     $this->xTemplate->parse($xtemplateSection);
 }
    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 = YAHOO.lang.JSON.stringify(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';
        }
    }
Exemple #8
0
function getEditFieldHTML($module, $fieldname, $aow_field, $view = 'EditView', $id = '', $alt_type = '', $currency_id = '')
{
    global $current_language, $app_strings, $app_list_strings, $current_user, $beanFiles, $beanList;
    $bean = BeanFactory::getBean($module, $id);
    if (!checkAccess($bean)) {
        return false;
    }
    $value = getFieldValueFromModule($fieldname, $module, $id);
    // use the mod_strings for this module
    $mod_strings = return_module_language($current_language, $module);
    // set the filename for this control
    $file = create_cache_directory('include/InlineEditing/') . $module . $view . $alt_type . $fieldname . '.tpl';
    if (!is_file($file) || inDeveloperMode() || !empty($_SESSION['developerMode'])) {
        if (!isset($vardef)) {
            require_once $beanFiles[$beanList[$module]];
            $focus = new $beanList[$module]();
            $vardef = $focus->getFieldDefinition($fieldname);
        }
        $displayParams = array();
        //$displayParams['formName'] = 'EditView';
        // if this is the id relation field, then don't have a pop-up selector.
        if ($vardef['type'] == 'relate' && $vardef['id_name'] == $vardef['name']) {
            $vardef['type'] = 'varchar';
        }
        if (isset($vardef['precision'])) {
            unset($vardef['precision']);
        }
        //$vardef['precision'] = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user);
        //TODO Fix datetimecomebo
        //temp work around
        if ($vardef['type'] == 'datetime') {
            $vardef['type'] = 'datetimecombo';
        }
        // trim down textbox display
        if ($vardef['type'] == 'text') {
            $vardef['rows'] = 2;
            $vardef['cols'] = 32;
        }
        // create the dropdowns for the parent type fields
        if ($vardef['type'] == 'parent_type') {
            $vardef['type'] = 'enum';
        }
        if ($vardef['type'] == 'link') {
            $vardef['type'] = 'relate';
            $vardef['rname'] = 'name';
            $vardef['id_name'] = $vardef['name'] . '_id';
            if ((!isset($vardef['module']) || $vardef['module'] == '') && $focus->load_relationship($vardef['name'])) {
                $vardef['module'] = $focus->{$vardef['name']}->getRelatedModuleName();
            }
        }
        //check for $alt_type
        if ($alt_type != '') {
            $vardef['type'] = $alt_type;
        }
        // remove the special text entry field function 'getEmailAddressWidget'
        if (isset($vardef['function']) && ($vardef['function'] == 'getEmailAddressWidget' || $vardef['function']['name'] == 'getEmailAddressWidget')) {
            unset($vardef['function']);
        }
        if (isset($vardef['name']) && $vardef['name'] == 'date_modified') {
            $vardef['name'] = 'aow_temp_date';
        }
        // load SugarFieldHandler to render the field tpl file
        static $sfh;
        if (!isset($sfh)) {
            require_once 'include/SugarFields/SugarFieldHandler.php';
            $sfh = new SugarFieldHandler();
        }
        $contents = $sfh->displaySmarty('fields', $vardef, $view, $displayParams);
        // Remove all the copyright comments
        $contents = preg_replace('/\\{\\*[^\\}]*?\\*\\}/', '', $contents);
        // remove extra wrong javascript which breaks auto complete on flexi relationship parent fields
        $contents = preg_replace("/<script language=\"javascript\">if\\(typeof sqs_objects == \\'undefined\\'\\){var sqs_objects = new Array;}sqs_objects\\[\\'EditView_parent_name\\'\\].*?<\\/script>/", "", $contents);
        if ($view == 'EditView' && ($vardef['type'] == 'relate' || $vardef['type'] == 'parent')) {
            $contents = str_replace('"' . $vardef['id_name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.id_name}"{literal}', $contents);
            $contents = str_replace('"' . $vardef['name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.name}"{literal}', $contents);
            // regex below fixes button javascript for flexi relationship
            if ($vardef['type'] == 'parent') {
                $contents = str_replace("onclick='open_popup(document.{\$form_name}.parent_type.value, 600, 400, \"\", true, false, {literal}{\"call_back_function\":\"set_return\",\"form_name\":\"EditView\",\"field_to_name_array\":{\"id\":{/literal}\"{\$fields.parent_name.id_name}", "onclick='open_popup(document.{\$form_name}.parent_type.value, 600, 400, \"\", true, false, {literal}{\"call_back_function\":\"set_return\",\"form_name\":\"EditView\",\"field_to_name_array\":{\"id\":{/literal}\"parent_id", $contents);
            }
        }
        // hack to disable one of the js calls in this control
        if (isset($vardef['function']) && ($vardef['function'] == 'getCurrencyDropDown' || $vardef['function']['name'] == 'getCurrencyDropDown')) {
            $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}";
        }
        // Save it to the cache file
        if ($fh = @sugar_fopen($file, 'w')) {
            fputs($fh, $contents);
            fclose($fh);
        }
    }
    // Now render the template we received
    $ss = new Sugar_Smarty();
    // Create Smarty variables for the Calendar picker widget
    global $timedate;
    $time_format = $timedate->get_user_time_format();
    $date_format = $timedate->get_cal_date_format();
    $ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
    $ss->assign('TIME_FORMAT', $time_format);
    $time_separator = ":";
    $match = array();
    if (preg_match('/\\d+([^\\d])\\d+([^\\d]*)/s', $time_format, $match)) {
        $time_separator = $match[1];
    }
    $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
    if (!isset($match[2]) || $match[2] == '') {
        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M");
    } else {
        $pm = $match[2] == "pm" ? "%P" : "%p";
        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm);
    }
    $ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week());
    $fieldlist = array();
    if (!isset($focus) || !$focus instanceof SugarBean) {
        require_once $beanFiles[$beanList[$module]];
    }
    $focus = new $beanList[$module]();
    // create the dropdowns for the parent type fields
    $vardefFields[$fieldname] = $focus->field_defs[$fieldname];
    if ($vardefFields[$fieldname]['type'] == 'parent') {
        $focus->field_defs[$fieldname]['options'] = $focus->field_defs[$vardefFields[$fieldname]['group']]['options'];
    }
    foreach ($vardefFields as $name => $properties) {
        $fieldlist[$name] = $properties;
        // fill in enums
        if (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']])) {
            $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']];
        } elseif (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']])) {
            $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']];
        }
    }
    // fill in function return values
    if (!in_array($fieldname, array('email1', 'email2'))) {
        if (!empty($fieldlist[$fieldname]['function']['returns']) && $fieldlist[$fieldname]['function']['returns'] == 'html') {
            $function = $fieldlist[$fieldname]['function']['name'];
            // include various functions required in the various vardefs
            if (isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include'])) {
                require_once $fieldlist[$fieldname]['function']['include'];
            }
            $_REQUEST[$fieldname] = $value;
            $value = $function($focus, $fieldname, $value, $view);
            $value = str_ireplace($fieldname, $aow_field, $value);
        }
    }
    if ($fieldlist[$fieldname]['type'] == 'link') {
        $fieldlist[$fieldname]['id_name'] = $fieldlist[$fieldname]['name'] . '_id';
        if ((!isset($fieldlist[$fieldname]['module']) || $fieldlist[$fieldname]['module'] == '') && $focus->load_relationship($fieldlist[$fieldname]['name'])) {
            $relateField = $fieldlist[$fieldname]['name'];
            $fieldlist[$fieldname]['module'] = $focus->{$relateField}->getRelatedModuleName();
        }
    }
    if ($fieldlist[$fieldname]['type'] == 'parent') {
        $fieldlist['parent_id']['name'] = 'parent_id';
    }
    if (isset($fieldlist[$fieldname]['name']) && $fieldlist[$fieldname]['name'] == 'date_modified') {
        $fieldlist[$fieldname]['name'] = 'aow_temp_date';
        $fieldlist['aow_temp_date'] = $fieldlist[$fieldname];
        $fieldname = 'aow_temp_date';
    }
    if (isset($fieldlist[$fieldname]['id_name']) && $fieldlist[$fieldname]['id_name'] != '' && $fieldlist[$fieldname]['id_name'] != $fieldlist[$fieldname]['name']) {
        if ($value) {
            $relateIdField = $fieldlist[$fieldname]['id_name'];
            $rel_value = $bean->{$relateIdField};
        }
        $fieldlist[$fieldlist[$fieldname]['id_name']]['value'] = $rel_value;
        $fieldlist[$fieldname]['value'] = $value;
        $fieldlist[$fieldname]['id_name'] = $aow_field;
        $fieldlist[$fieldname]['name'] = $aow_field . '_display';
    } else {
        if (isset($fieldlist[$fieldname]['type']) && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime')) {
            $value = $focus->convertField($value, $fieldlist[$fieldname]);
            if (!$value) {
                $value = date($timedate->get_date_time_format());
            }
            $fieldlist[$fieldname]['name'] = $aow_field;
            $fieldlist[$fieldname]['value'] = $value;
        } else {
            if (isset($fieldlist[$fieldname]['type']) && $fieldlist[$fieldname]['type'] == 'date') {
                $value = $focus->convertField($value, $fieldlist[$fieldname]);
                $fieldlist[$fieldname]['name'] = $aow_field;
                if (empty($value) == "") {
                    $value = str_replace("%", "", date($date_format));
                }
                $fieldlist[$fieldname]['value'] = $value;
            } else {
                $fieldlist[$fieldname]['value'] = $value;
                $fieldlist[$fieldname]['name'] = $aow_field;
            }
        }
    }
    if ($fieldlist[$fieldname]['type'] == 'currency' && $view != 'EditView') {
        static $sfh;
        if (!isset($sfh)) {
            require_once 'include/SugarFields/SugarFieldHandler.php';
            $sfh = new SugarFieldHandler();
        }
        if ($currency_id != '' && !stripos($fieldname, '_USD')) {
            $userCurrencyId = $current_user->getPreference('currency');
            if ($currency_id != $userCurrencyId) {
                $currency = new Currency();
                $currency->retrieve($currency_id);
                $value = $currency->convertToDollar($value);
                $currency->retrieve($userCurrencyId);
                $value = $currency->convertFromDollar($value);
            }
        }
        $parentfieldlist[strtoupper($fieldname)] = $value;
        return $sfh->displaySmarty($parentfieldlist, $fieldlist[$fieldname], 'ListView', $displayParams);
    }
    $ss->assign("fields", $fieldlist);
    $ss->assign("form_name", $view);
    $ss->assign("bean", $focus);
    $ss->assign("MOD", $mod_strings);
    $ss->assign("APP", $app_strings);
    return json_encode($ss->fetch($file));
}
Exemple #9
0
 /**
  * Add Team selection popup window HTML code
  * @param displayname Name to display in the popup window
  * @param varname name of the variable
  */
 function addTeamList($displayname, $field)
 {
     require_once 'include/SugarFields/SugarFieldHandler.php';
     $sfh = new SugarFieldHandler();
     $field['custom_type'] = 'Teamset';
     $field['name'] = 'team_name';
     $html = "<td width='15%' scope='row'>{$displayname}</td>";
     $html .= "<td>" . $sfh->displaySmarty('fields', $field, 'MassUpdateView') . "</td>";
     return $html;
 }