/**
  * Merge determined bean data into an determined text template, this could be
  * an email template, expression template, or another type of text with
  * bean variables in it.
  *
  * @global type $beanList
  * @param type $bean
  * @param type $template
  * @param type $component_array
  * @param type $evaluate
  * @return type
  */
 public function mergeTemplate($bean, $template, $component_array, $evaluate = false)
 {
     global $beanList;
     $replace_array = array();
     $replace_type_array = array();
     foreach ($component_array as $module_name => $module_array) {
         //base module
         if ($module_name == $bean->module_dir) {
             foreach ($module_array as $field => $field_array) {
                 if ($field_array['value_type'] == 'href_link') {
                     //Create href link to target record
                     $replacement_value = $this->get_href_link($bean);
                 }
                 if ($field_array['value_type'] == 'future') {
                     if ($evaluate) {
                         $replacement_value = bpminbox_check_special_fields($field_array['name'], $bean, false, array());
                     } else {
                         $replacement_value = bpminbox_check_special_fields($field_array['name'], $bean, false, array());
                     }
                 }
                 if ($field_array['value_type'] == 'past') {
                     $replacement_value = bpminbox_check_special_fields($field_array['name'], $bean, true, array());
                 }
                 $replace_type_array[$field_array['original']] = get_bean_field_type($field_array['name'], $bean);
                 $replace_array[$field_array['original']] = implode(', ', unencodeMultienum($replacement_value));
             }
         } else {
             //Confirm this is an actual module in the beanlist
             if (isset($beanList[$module_name]) || isset($bean->field_defs[$module_name])) {
                 ///Build the relationship information using the Relationship handler
                 $rel_handler = $bean->call_relationship_handler("module_dir", true);
                 if (isset($bean->field_defs[$module_name])) {
                     $rel_handler->rel1_relationship_name = $bean->field_defs[$module_name]['relationship'];
                     $rel_module = get_rel_module_name($bean->module_dir, $rel_handler->rel1_relationship_name, $bean->db);
                     $rel_handler->rel1_module = $rel_module;
                     $rel_handler->rel1_bean = get_module_info($rel_module);
                 } else {
                     $rel_handler->process_by_rel_bean($module_name);
                 }
                 foreach ($bean->field_defs as $field => $attribute_array) {
                     if (!empty($attribute_array['relationship']) && $attribute_array['relationship'] == $rel_handler->rel1_relationship_name) {
                         $rel_handler->base_vardef_field = $field;
                         break;
                     }
                 }
                 //obtain the rel_module object
                 $rel_list = $rel_handler->build_related_list("base");
                 if (!empty($rel_list[0])) {
                     $rel_object = $rel_list[0];
                     $rel_module_present = true;
                 } else {
                     $rel_module_present = false;
                 }
                 foreach ($module_array as $field => $field_array) {
                     if ($rel_module_present == true) {
                         if ($field_array['value_type'] == 'href_link') {
                             //Create href link to target record
                             $replacement_value = $this->get_href_link($rel_object);
                         } else {
                             //use future always for rel because fetched should always be the same
                             $replacement_value = bpminbox_check_special_fields($field_array['name'], $rel_object, false, array());
                         }
                     } else {
                         $replacement_value = "Invalid Value";
                     }
                     $replace_array[$field_array['original']] = implode(', ', unencodeMultienum($replacement_value));
                 }
             }
         }
     }
     foreach ($replace_array as $name => $replacement_value) {
         if ($evaluate) {
             $replacement_value = str_replace("\n", ' ', $replacement_value);
             $type = $replace_type_array[$name]['type'];
             $dbtype = $replace_type_array[$name]['db_type'];
             //TODO evaluate more types even Ids perhaps
             $this->logger->info("Field : {$name} , type: '{$type}',  DBtype: '{$dbtype}'");
             if (($dbtype == 'double' || $dbtype == 'int') && $type != 'currency') {
                 $replacement_value = trim($replacement_value);
             } elseif ($type == 'currency') {
                 //TODO hardcoded . , should use system currency format
                 $replacement_value = str_replace(",", '', $replacement_value);
                 $replacement_value = str_replace(".", ',', $replacement_value);
                 $replacement_value = floatval($replacement_value);
             } else {
                 //here $replacement_value must be datatime, time, string datatype values
                 $replacement_value = "'" . $replacement_value . "'";
             }
         } else {
             $replacement_value = nl2br($replacement_value);
         }
         $template = str_replace($name, $replacement_value, $template);
     }
     return $template;
 }
Beispiel #2
0
function reconstruct_target_body($focus, $target_body, $component_array, $notify_user_id = "", $alert_user_array = array())
{
    global $beanList;
    $replace_array = array();
    foreach ($component_array as $module_name => $module_array) {
        if ($module_name == $focus->module_dir) {
            //base module
            foreach ($module_array as $field => $field_array) {
                if ($field_array['value_type'] == 'href_link') {
                    //Create href link to target record
                    $replacement_value = get_href_link($focus);
                }
                if ($field_array['value_type'] == 'invite_link') {
                    //Create href link to target record
                    $replacement_value = get_invite_link($focus, $notify_user_id);
                }
                if ($field_array['value_type'] == 'future') {
                    $replacement_value = check_special_fields($field_array['name'], $focus, false, array());
                }
                if ($field_array['value_type'] == 'past') {
                    $replacement_value = check_special_fields($field_array['name'], $focus, true, array());
                }
                $replace_array[$field_array['original']] = $replacement_value;
                //end foreach module_array
            }
            //end if base module array
        } else {
            //Confirm this is an actual module in the beanlist
            if (isset($beanList[$module_name]) || isset($focus->field_defs[$module_name])) {
                ///Build the relationship information using the Relationship handler
                $rel_handler = $focus->call_relationship_handler("module_dir", true);
                if (isset($focus->field_defs[$module_name])) {
                    $rel_handler->rel1_relationship_name = $focus->field_defs[$module_name]['relationship'];
                    $rel_module = get_rel_module_name($focus->module_dir, $rel_handler->rel1_relationship_name, $focus->db);
                    $rel_handler->rel1_module = $rel_module;
                    $rel_handler->rel1_bean = BeanFactory::getBean($rel_module);
                } else {
                    $rel_handler->process_by_rel_bean($module_name);
                }
                foreach ($focus->field_defs as $field => $attribute_array) {
                    if (!empty($attribute_array['relationship']) && $attribute_array['relationship'] == $rel_handler->rel1_relationship_name) {
                        //$relationship_name = $field;
                        $rel_handler->base_vardef_field = $field;
                        break;
                    }
                }
                //obtain the rel_module object
                $rel_list = $rel_handler->build_related_list("base");
                foreach ($alert_user_array as $user_meta_array) {
                    ////Filter the first related module
                    $rel_list = process_rel_type("rel_module1_type", "rel1_filter", $rel_list, $user_meta_array);
                    ////Filter using second filter if necessary
                    if (!empty($user_meta_array['expression']) && $user_meta_array['rel_module2'] == "") {
                        $rel_list = process_rel_type("filter", "expression", $rel_list, $user_meta_array, true);
                        //end second filter if necessary
                    }
                }
                //$rel_list = $focus->get_linked_beans($relationship_name, $bean_name);
                if (!empty($rel_list[0])) {
                    $rel_object = $rel_list[0];
                    $rel_module_present = true;
                } else {
                    $rel_module_present = false;
                }
                foreach ($module_array as $field => $field_array) {
                    if ($rel_module_present == true) {
                        if ($field_array['value_type'] == 'href_link') {
                            //Create href link to target record
                            $replacement_value = get_href_link($rel_object);
                        } elseif ($field_array['value_type'] == 'invite_link') {
                            //Create href link to target record
                            $replacement_value = get_invite_link($rel_object, $notify_user_id);
                        } else {
                            //use future always for rel because fetched should always be the same
                            $replacement_value = check_special_fields($field_array['name'], $rel_object, false, array());
                        }
                    } else {
                        $replacement_value = "Invalid Value";
                    }
                    $replace_array[$field_array['original']] = $replacement_value;
                    //end foreach module_array
                }
                //end check to see if this is an actual module in the beanlist
            }
            //end if else base or related module array
        }
        //end outside foreach
    }
    $parsed_target_body = replace_target_body_items($target_body, $replace_array);
    return $parsed_target_body;
    //end function reconstruct_target_body
}
Beispiel #3
0
 function get_rel_module($var_rel_name, $get_rel_name = false)
 {
     //get the vardef fields relationship name
     //get the base_module bean
     $module_bean = BeanFactory::getBean($this->base_module);
     require_once 'data/Link.php';
     $rel_name = Relationship::retrieve_by_modules($var_rel_name, $this->base_module, $GLOBALS['db']);
     if (!empty($module_bean->field_defs[$rel_name])) {
         $var_rel_name = $rel_name;
     }
     $var_rel_name = strtolower($var_rel_name);
     if ($get_rel_name) {
         //bug #46246: should set relationship name instead of related field name
         $this->rel_name = isset($rel_name) ? $rel_name : $var_rel_name;
     }
     $rel_attribute_name = $module_bean->field_defs[$var_rel_name]['relationship'];
     //use the vardef to retrive the relationship attribute
     unset($module_bean);
     return get_rel_module_name($this->base_module, $rel_attribute_name, $this->db);
 }
    $rel_attribute_name = "";
    //First, see if there is a link field with the name of the related module
    if (!empty($temp_module->field_defs[$target_module]) && !empty($temp_module->field_defs[$target_module]['relationship'])) {
        $rel_attribute_name = $temp_module->field_defs[$target_module]['relationship'];
    } elseif (!empty($temp_module->field_defs[strtolower($target_module)]) && !empty($temp_module->field_defs[strtolower($target_module)]['relationship'])) {
        $rel_attribute_name = $temp_module->field_defs[strtolower($target_module)]['relationship'];
    } else {
        //Next, Find the first link field associated with the requested module
        foreach ($temp_module->get_linked_fields() as $name => $def) {
            if (isset($def['module']) && $def['module'] == $target_module && !empty($def['relationship'])) {
                $rel_attribute_name = $def['relationship'];
                break;
            }
        }
    }
    $rel_module = get_rel_module_name($base_module, $rel_attribute_name, $temp_module->db);
    $temp_module = BeanFactory::getBean($rel_module);
    $temp_module->call_vardef_handler("template_filter");
    $temp_module->vardef_handler->extra_array['href_link'] = $GLOBALS['mod_strings']['LBL_LINK_RECORD'];
    $target_dropdown = get_select_options_with_id($temp_module->vardef_handler->get_vardef_array(true), "");
    $select_jscript = "onchange=\"window.parent.copy_text('fields_iframe', 'variable_text')";
    $ext_value = $base_module . "::" . $target_module;
    $on_start = "window.parent.copy_text('fields_iframe', 'variable_text');";
}
if ($iframe_type == "base_fields") {
    $temp_module = BeanFactory::getBean($target_module);
    $temp_module->call_vardef_handler("template_filter");
    $temp_module->vardef_handler->extra_array['href_link'] = $GLOBALS['mod_strings']['LBL_LINK_RECORD'];
    if ($target_module == "Meetings" || $target_module == "Calls" || $target_module == "meetings" || $target_module == "calls") {
        $temp_module->vardef_handler->extra_array['invite_link'] = $GLOBALS['mod_strings']['LBL_INVITE_LINK'];
    }