/** * Advanced OpenReports, SugarCRM Reporting. * @package Advanced OpenReports for SugarCRM * @copyright SalesAgility Ltd http://www.salesagility.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * 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 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 * * @author SalesAgility <*****@*****.**> */ function display_field_lines($focus, $field, $value, $view) { global $mod_strings, $app_list_strings; $html = ''; if (!is_file('cache/jsLanguage/AOR_Fields/' . $GLOBALS['current_language'] . '.js')) { require_once 'include/language/jsLanguage.php'; jsLanguage::createModuleStringsCache('AOR_Fields', $GLOBALS['current_language']); } $html .= '<script src="include/javascript/yui3/build/yui/yui-min.js"></script>'; $html .= '<script src="cache/jsLanguage/AOR_Fields/' . $GLOBALS['current_language'] . '.js"></script>'; if ($view == 'EditView') { $html .= '<script src="modules/AOR_Fields/fieldLines.js"></script>'; $html .= '<script></script>'; $html .= "<table border='0' cellspacing='4' width='100%' id='fieldLines'></table>"; $html .= "<div style='padding-top: 10px; padding-bottom:10px;'>"; $html .= "<input type=\"button\" tabindex=\"116\" class=\"button\" value=\"" . $mod_strings['LBL_ADD_FIELD'] . "\" id=\"btn_FieldLine\" onclick=\"insertFieldLine()\" disabled/>"; $html .= "</div>"; $html .= "<script>"; $html .= "sort_by_values = \"" . trim(preg_replace('/\\s+/', ' ', get_select_options_with_id($app_list_strings['aor_sort_operator'], ''))) . "\";"; $html .= "</script>"; if (isset($focus->report_module) && $focus->report_module != '') { require_once "modules/AOW_WorkFlow/aow_utils.php"; $html .= "<script>"; $html .= "report_rel_modules = \"" . trim(preg_replace('/\\s+/', ' ', getModuleRelationships($focus->report_module))) . "\";"; $html .= "report_module = \"" . $focus->report_module . "\";"; $html .= "document.getElementById('btn_FieldLine').disabled = '';"; if ($focus->id != '') { $sql = "SELECT id FROM aor_fields WHERE aor_report_id = '" . $focus->id . "' AND deleted = 0 ORDER BY field_order ASC"; $result = $focus->db->query($sql); while ($row = $focus->db->fetchByAssoc($result)) { $field_name = new AOR_Field(); $field_name->retrieve($row['id']); $field_name->module_path = unserialize(base64_decode($field_name->module_path)); $html .= "report_fields = \"" . trim(preg_replace('/\\s+/', ' ', getModuleFields(getRelatedModule($focus->report_module, $field_name->module_path[0])))) . "\";"; $field_item = json_encode($field_name->toArray()); $html .= "loadFieldLine(" . $field_item . ");"; } } $html .= "report_fields = \"" . trim(preg_replace('/\\s+/', ' ', getModuleFields($focus->report_module))) . "\";"; $html .= "</script>"; } } else { if ($view == 'DetailView') { /*$html .= '<script src="include/SugarCharts/Jit/js/sugarCharts.js"></script>'; $html .= '<script language="javascript" type="text/javascript" src="include/MySugar/javascript/MySugar.js"></script>'; $html .= '<script language="javascript" type="text/javascript" src="include/SugarCharts/Jit/js/Jit/jit.js"></script>'; $html .= '<script language="javascript" type="text/javascript" src="include/SugarCharts/Jit/js/sugarCharts.js"></script>'; $html .= '<script language="javascript" type="text/javascript" src="include/SugarCharts/Jit/js/mySugarCharts.js"></script>';*/ $html .= $focus->build_group_report(0) . '<br />'; } } return $html; }
function build_report_query_where($query = array()) { global $beanList, $app_list_strings, $sugar_config; if ($beanList[$this->report_module]) { $module = new $beanList[$this->report_module](); $sql = "SELECT id FROM aor_conditions WHERE aor_report_id = '" . $this->id . "' AND deleted = 0 ORDER BY condition_order ASC"; $result = $this->db->query($sql); while ($row = $this->db->fetchByAssoc($result)) { $condition = new AOR_Condition(); $condition->retrieve($row['id']); $path = unserialize(base64_decode($condition->module_path)); $condition_module = $module; $table_alias = $condition_module->table_name; if (!empty($path[0]) && $path[0] != $module->module_dir) { foreach ($path as $rel) { if (empty($rel)) { continue; } $rel = strtolower($rel); $new_condition_module = new $beanList[getRelatedModule($condition_module->module_dir, $rel)](); $oldAlias = $table_alias; $table_alias = $table_alias . ":" . $rel; $query = $this->build_report_query_join($rel, $table_alias, $oldAlias, $condition_module, 'relationship', $query, $new_condition_module); $condition_module = $new_condition_module; } } if (isset($app_list_strings['aor_sql_operator_list'][$condition->operator])) { $where_set = false; $data = $condition_module->field_defs[$condition->field]; if ($data['type'] == 'relate' && isset($data['id_name'])) { $condition->field = $data['id_name']; $data_new = $condition_module->field_defs[$condition->field]; if (!empty($data_new['source']) && $data_new['source'] == 'non-db' && $data_new['type'] != 'link' && isset($data['link'])) { $data_new['type'] = 'link'; $data_new['relationship'] = $data['link']; } $data = $data_new; } if ($data['type'] == 'link' && $data['source'] == 'non-db') { $relModule = getRelatedModule($condition_module->module_dir, $data['relationship']); $new_field_module = new $beanList[$relModule](); $query = $this->build_report_query_join($data['relationship'], $table_alias . ':' . strtolower($relModule), $oldAlias, $condition_module, 'relationship', $query, $new_field_module); $field_module = $new_field_module; $table_alias = $table_alias . ':' . $data['relationship']; $condition->field = 'id'; } if (isset($data['source']) && $data['source'] == 'custom_fields') { $field = $this->db->quoteIdentifier($table_alias . '_cstm') . '.' . $condition->field; $query = $this->build_report_query_join($table_alias . '_cstm', $table_alias . '_cstm', $oldAlias, $condition_module, 'custom', $query); } else { $field = $this->db->quoteIdentifier($table_alias) . '.' . $condition->field; } if (!empty($this->user_parameters[$condition->id]) && $condition->parameter) { $condParam = $this->user_parameters[$condition->id]; $condition->value = $condParam['value']; $condition->operator = $condParam['operator']; $condition->value_type = $condParam['type']; } switch ($condition->value_type) { case 'Field': $data = $condition_module->field_defs[$condition->value]; if ($data['type'] == 'relate' && isset($data['id_name'])) { $condition->value = $data['id_name']; $data_new = $condition_module->field_defs[$condition->value]; if ($data_new['source'] == 'non-db' && $data_new['type'] != 'link' && isset($data['link'])) { $data_new['type'] = 'link'; $data_new['relationship'] = $data['link']; } $data = $data_new; } if ($data['type'] == 'link' && $data['source'] == 'non-db') { $new_field_module = new $beanList[getRelatedModule($field_module->module_dir, $data['relationship'])](); $query = $this->build_report_query_join($data['relationship'], $table_alias, $oldAlias, $field_module, 'relationship', $query, $new_field_module); $field_module = $new_field_module; $table_alias = $data['relationship']; $field->field = 'id'; } if (isset($data['source']) && $data['source'] == 'custom_fields') { $value = $condition_module->table_name . '_cstm.' . $condition->value; $query = $this->build_report_query_join($condition_module->table_name . '_cstm', $table_alias . '_cstm', $table_alias, $condition_module, 'custom', $query); } else { $value = $condition_module->table_name . '.' . $condition->value; } break; case 'Date': $params = unserialize(base64_decode($condition->value)); if ($params[0] == 'now') { if ($sugar_config['dbconfig']['db_type'] == 'mssql') { $value = 'GetDate()'; } else { $value = 'NOW()'; } } else { $data = $condition_module->field_defs[$params[0]]; if (isset($data['source']) && $data['source'] == 'custom_fields') { $value = $condition_module->table_name . '_cstm.' . $params[0]; $query = $this->build_report_query_join($condition_module->table_name . '_cstm', $table_alias . '_cstm', $table_alias, $condition_module, 'custom', $query); } else { $value = $condition_module->table_name . '.' . $params[0]; } } if ($params[1] != 'now') { switch ($params[3]) { case 'business_hours': //business hours not implemented for query, default to hours $params[3] = 'hours'; default: if ($sugar_config['dbconfig']['db_type'] == 'mssql') { $value = "DATEADD(" . $params[3] . ", " . $app_list_strings['aor_date_operator'][$params[1]] . " {$params['2']}, {$value})"; } else { $value = "DATE_ADD({$value}, INTERVAL " . $app_list_strings['aor_date_operator'][$params[1]] . " {$params['2']} " . $params[3] . ")"; } break; } } break; case 'Multi': $sep = ' AND '; if ($condition->operator == 'Equal_To') { $sep = ' OR '; } $multi_values = unencodeMultienum($condition->value); if (!empty($multi_values)) { $value = '('; foreach ($multi_values as $multi_value) { if ($value != '(') { $value .= $sep; } $value .= $field . ' ' . $app_list_strings['aor_sql_operator_list'][$condition->operator] . " '" . $multi_value . "'"; } $value .= ')'; } $query['where'][] = $value; $where_set = true; break; case 'Value': default: $value = "'" . $this->db->quote($condition->value) . "'"; break; } if (!$where_set) { $query['where'][] = $field . ' ' . $app_list_strings['aor_sql_operator_list'][$condition->operator] . ' ' . $value; } } } $query['where'][] = $module->table_name . ".deleted = 0 " . $this->build_report_access_query($module, $module->table_name); } return $query; }
function getConditionsAsParameters($report, $override = array()) { if (empty($report)) { return array(); } global $app_list_strings; $conditions = array(); foreach ($report->get_linked_beans('aor_conditions', 'AOR_Conditions') as $key => $condition) { if (!$condition->parameter) { continue; } $path = unserialize(base64_decode($condition->module_path)); $field_module = $report->report_module; if ($path[0] != $report->report_module) { foreach ($path as $rel) { if (empty($rel)) { continue; } $field_module = getRelatedModule($field_module, $rel); } } $additionalConditions = unserialize(base64_decode($condition->value)); $value = isset($override[$condition->id]['value']) ? $override[$condition->id]['value'] : ($value = $condition->value); $field = getModuleField($field_module, $condition->field, "parameter_value[{$key}]", 'EditView', $value); $disp = getDisplayForField($path, $condition->field, $report->report_module); $conditions[] = array('id' => $condition->id, 'operator' => $condition->operator, 'operator_display' => $app_list_strings['aor_operator_list'][$condition->operator], 'value_type' => $condition->value_type, 'value' => $value, 'field_display' => $disp['field'], 'module_display' => $disp['module'], 'field' => $field, 'additionalConditions' => $additionalConditions); } return $conditions; }
protected function action_getModuleFieldType() { if (isset($_REQUEST['rel_field']) && $_REQUEST['rel_field'] != '') { $rel_module = getRelatedModule($_REQUEST['aow_module'], $_REQUEST['rel_field']); } else { $rel_module = $_REQUEST['aow_module']; } $module = $_REQUEST['aow_module']; $fieldname = $_REQUEST['aow_fieldname']; $aow_field = $_REQUEST['aow_newfieldname']; if (isset($_REQUEST['view'])) { $view = $_REQUEST['view']; } else { $view = 'EditView'; } if (isset($_REQUEST['aow_value'])) { $value = $_REQUEST['aow_value']; } else { $value = ''; } switch ($_REQUEST['aow_type']) { case 'Field': if (isset($_REQUEST['alt_module']) && $_REQUEST['alt_module'] != '') { $module = $_REQUEST['alt_module']; } if ($view == 'EditView') { echo "<select type='text' style='width:178px;' name='{$aow_field}' id='{$aow_field} ' title='' tabindex='116'>" . getModuleFields($module, $view, $value, getValidFieldsTypes($module, $fieldname)) . "</select>"; } else { echo getModuleFields($module, $view, $value); } break; case 'Any_Change': echo ''; break; case 'Date': echo getDateField($module, $aow_field, $view, $value, false); break; case 'Multi': echo getModuleField($rel_module, $fieldname, $aow_field, $view, $value, 'multienum'); break; case 'SecurityGroup': $module = 'Accounts'; $fieldname = 'SecurityGroups'; case 'Value': default: echo getModuleField($rel_module, $fieldname, $aow_field, $view, $value); break; } die; }
function run_action(SugarBean $bean, $params = array(), $in_save = false) { if (isset($params['rel_type']) && $params['rel_type'] != '' && $bean->module_dir != $params['rel_type']) { $relatedFields = $bean->get_linked_fields(); $field = $relatedFields[$params['rel_type']]; if (!isset($field['module']) || $field['module'] == '') { $field['module'] = getRelatedModule($bean->module_dir, $field['name']); } $linkedBeans = $bean->get_linked_beans($field['name'], $field['module']); if ($linkedBeans) { foreach ($linkedBeans as $linkedBean) { $this->set_record($linkedBean, $bean, $params, 'false'); $this->set_relationships($linkedBean, $bean, $params); } } } else { $this->set_record($bean, $bean, $params, $in_save); $this->set_relationships($bean, $bean, $params); } return true; }
protected function action_getModuleFieldType() { if (isset($_REQUEST['rel_field']) && $_REQUEST['rel_field'] != '') { $rel_module = getRelatedModule($_REQUEST['aor_module'], $_REQUEST['rel_field']); } else { $rel_module = $_REQUEST['aor_module']; } $module = $_REQUEST['aor_module']; $fieldname = $_REQUEST['aor_fieldname']; $aor_field = $_REQUEST['aor_newfieldname']; if (isset($_REQUEST['view'])) { $view = $_REQUEST['view']; } else { $view = 'EditView'; } if (isset($_REQUEST['aor_value'])) { $value = $_REQUEST['aor_value']; } else { $value = ''; } switch ($_REQUEST['aor_type']) { case 'Field': if (isset($_REQUEST['alt_module']) && $_REQUEST['alt_module'] != '') { $module = $_REQUEST['alt_module']; } if ($view == 'EditView') { echo "<select type='text' style='width:178px;' name='{$aor_field}' id='{$aor_field}' title='' tabindex='116'>" . getModuleFields($module, $view, $value) . "</select>"; } else { echo getModuleFields($module, $view, $value); } break; case 'Date': echo getDateField($module, $aor_field, $view, $value, false); break; case 'Multi': echo getModuleField($rel_module, $fieldname, $aor_field, $view, $value, 'multienum'); break; case 'Period': if ($view == 'EditView') { echo "<select type='text' style='width:178px;' name='{$aor_field}' id='{$aor_field}' title='' tabindex='116'>" . getDropdownList('date_time_period_list', $_REQUEST['aor_value']) . "</select>"; } else { echo getDropdownList('date_time_period_list', $_REQUEST['aor_value']); } break; case 'CurrentUserID': break; case 'Value': default: echo getModuleField($rel_module, $fieldname, $aor_field, $view, $value); break; } die; }
/** * @param array $query * @return array */ function build_report_query_where($query = array()) { global $beanList, $app_list_strings, $sugar_config; $closure = false; if (!empty($query['where'])) { $query['where'][] = '('; $closure = true; } if ($beanList[$this->report_module]) { $module = new $beanList[$this->report_module](); $sql = "SELECT id FROM aor_conditions WHERE aor_report_id = '" . $this->id . "' AND deleted = 0 ORDER BY condition_order ASC"; $result = $this->db->query($sql); $tiltLogicOp = true; while ($row = $this->db->fetchByAssoc($result)) { $condition = new AOR_Condition(); $condition->retrieve($row['id']); $path = unserialize(base64_decode($condition->module_path)); $condition_module = $module; $table_alias = $condition_module->table_name; $oldAlias = $table_alias; if (!empty($path[0]) && $path[0] != $module->module_dir) { foreach ($path as $rel) { if (empty($rel)) { continue; } // Bug: Prevents relationships from loading. //$rel = strtolower($rel); $new_condition_module = new $beanList[getRelatedModule($condition_module->module_dir, $rel)](); $oldAlias = $table_alias; $table_alias = $table_alias . ":" . $rel; $query = $this->build_report_query_join($rel, $table_alias, $oldAlias, $condition_module, 'relationship', $query, $new_condition_module); $condition_module = $new_condition_module; } } if (isset($app_list_strings['aor_sql_operator_list'][$condition->operator])) { $where_set = false; $data = $condition_module->field_defs[$condition->field]; if ($data['type'] == 'relate' && isset($data['id_name'])) { $condition->field = $data['id_name']; $data_new = $condition_module->field_defs[$condition->field]; if (!empty($data_new['source']) && $data_new['source'] == 'non-db' && $data_new['type'] != 'link' && isset($data['link'])) { $data_new['type'] = 'link'; $data_new['relationship'] = $data['link']; } $data = $data_new; } if ($data['type'] == 'link' && $data['source'] == 'non-db') { $new_field_module = new $beanList[getRelatedModule($condition_module->module_dir, $data['relationship'])](); $table_alias = $data['relationship']; $query = $this->build_report_query_join($data['relationship'], $table_alias, $oldAlias, $condition_module, 'relationship', $query, $new_field_module); $condition_module = $new_field_module; // Debugging: security groups conditions - It's a hack to just get the query working if ($condition_module->module_dir = 'SecurityGroups' && count($path) > 1) { // $table_alias = 'opportunities:assigned_user_link:SecurityGroups' ; $table_alias = $oldAlias . ':' . $rel; } $condition->field = 'id'; } if (isset($data['source']) && $data['source'] == 'custom_fields') { $field = $this->db->quoteIdentifier($table_alias . '_cstm') . '.' . $condition->field; $query = $this->build_report_query_join($table_alias . '_cstm', $table_alias . '_cstm', $oldAlias, $condition_module, 'custom', $query); } else { $field = $this->db->quoteIdentifier($table_alias) . '.' . $condition->field; } if (!empty($this->user_parameters[$condition->id]) && $condition->parameter) { $condParam = $this->user_parameters[$condition->id]; $condition->value = $condParam['value']; $condition->operator = $condParam['operator']; $condition->value_type = $condParam['type']; } switch ($condition->value_type) { case 'Field': $data = $condition_module->field_defs[$condition->value]; if ($data['type'] == 'relate' && isset($data['id_name'])) { $condition->value = $data['id_name']; $data_new = $condition_module->field_defs[$condition->value]; if ($data_new['source'] == 'non-db' && $data_new['type'] != 'link' && isset($data['link'])) { $data_new['type'] = 'link'; $data_new['relationship'] = $data['link']; } $data = $data_new; } if ($data['type'] == 'link' && $data['source'] == 'non-db') { $new_field_module = new $beanList[getRelatedModule($condition_module->module_dir, $data['relationship'])](); $table_alias = $data['relationship']; $query = $this->build_report_query_join($data['relationship'], $table_alias, $oldAlias, $condition_module, 'relationship', $query, $new_field_module); $condition_module = $new_field_module; $condition->field = 'id'; } if (isset($data['source']) && $data['source'] == 'custom_fields') { $value = $condition_module->table_name . '_cstm.' . $condition->value; $query = $this->build_report_query_join($condition_module->table_name . '_cstm', $table_alias . '_cstm', $table_alias, $condition_module, 'custom', $query); } else { $value = ($table_alias ? "`{$table_alias}`" : $condition_module->table_name) . '.' . $condition->value; } break; case 'Date': $params = unserialize(base64_decode($condition->value)); // Fix for issue #1272 - AOR_Report module cannot update Date type parameter. if ($params == false) { $params = $condition->value; } if ($params[0] == 'now') { if ($sugar_config['dbconfig']['db_type'] == 'mssql') { $value = 'GetDate()'; } else { $value = 'NOW()'; } } else { if ($params[0] == 'today') { if ($sugar_config['dbconfig']['db_type'] == 'mssql') { //$field = $value = 'CAST(GETDATE() AS DATE)'; } else { $field = 'DATE(' . $field . ')'; $value = 'Curdate()'; } } else { $data = $condition_module->field_defs[$params[0]]; if (isset($data['source']) && $data['source'] == 'custom_fields') { $value = $condition_module->table_name . '_cstm.' . $params[0]; $query = $this->build_report_query_join($condition_module->table_name . '_cstm', $table_alias . '_cstm', $table_alias, $condition_module, 'custom', $query); } else { $value = $condition_module->table_name . '.' . $params[0]; } } } if ($params[1] != 'now') { switch ($params[3]) { case 'business_hours': //business hours not implemented for query, default to hours $params[3] = 'hours'; default: if ($sugar_config['dbconfig']['db_type'] == 'mssql') { $value = "DATEADD(" . $params[3] . ", " . $app_list_strings['aor_date_operator'][$params[1]] . " {$params['2']}, {$value})"; } else { $value = "DATE_ADD({$value}, INTERVAL " . $app_list_strings['aor_date_operator'][$params[1]] . " {$params['2']} " . $params[3] . ")"; } break; } } break; case 'Multi': $sep = ' AND '; if ($condition->operator == 'Equal_To') { $sep = ' OR '; } $multi_values = unencodeMultienum($condition->value); if (!empty($multi_values)) { $value = '('; foreach ($multi_values as $multi_value) { if ($value != '(') { $value .= $sep; } $value .= $field . ' ' . $app_list_strings['aor_sql_operator_list'][$condition->operator] . " '" . $multi_value . "'"; } $value .= ')'; } $query['where'][] = ($tiltLogicOp ? '' : ($condition->logic_op ? $condition->logic_op . ' ' : 'AND ')) . $value; $where_set = true; break; case "Period": if (array_key_exists($condition->value, $app_list_strings['date_time_period_list'])) { $params = $condition->value; } else { $params = base64_decode($condition->value); } $value = '"' . getPeriodDate($params)->format('Y-m-d H:i:s') . '"'; break; case "CurrentUserID": global $current_user; $value = '"' . $current_user->id . '"'; break; case 'Value': default: $value = "'" . $this->db->quote($condition->value) . "'"; break; } //handle like conditions switch ($condition->operator) { case 'Contains': $value = "CONCAT('%', " . $value . " ,'%')"; break; case 'Starts_With': $value = "CONCAT(" . $value . " ,'%')"; break; case 'Ends_With': $value = "CONCAT('%', " . $value . ")"; break; } if ($condition->value_type == 'Value' && !$condition->value && $condition->operator == 'Equal_To') { $value = "{$value} OR {$field} IS NULL"; } if (!$where_set) { if ($condition->value_type == "Period") { if (array_key_exists($condition->value, $app_list_strings['date_time_period_list'])) { $params = $condition->value; } else { $params = base64_decode($condition->value); } $date = getPeriodEndDate($params)->format('Y-m-d H:i:s'); $value = '"' . getPeriodDate($params)->format('Y-m-d H:i:s') . '"'; $query['where'][] = $tiltLogicOp ? '' : ($condition->logic_op ? $condition->logic_op . ' ' : 'AND '); $tiltLogicOp = false; switch ($app_list_strings['aor_sql_operator_list'][$condition->operator]) { case "=": $query['where'][] = $field . ' BETWEEN ' . $value . ' AND ' . '"' . $date . '"'; break; case "!=": $query['where'][] = $field . ' NOT BETWEEN ' . $value . ' AND ' . '"' . $date . '"'; break; case ">": case "<": case ">=": case "<=": $query['where'][] = $field . ' ' . $app_list_strings['aor_sql_operator_list'][$condition->operator] . ' ' . $value; break; } } else { if (!$where_set) { $query['where'][] = ($tiltLogicOp ? '' : ($condition->logic_op ? $condition->logic_op . ' ' : 'AND ')) . $field . ' ' . $app_list_strings['aor_sql_operator_list'][$condition->operator] . ' ' . $value; } } } $tiltLogicOp = false; } else { if ($condition->parenthesis) { if ($condition->parenthesis == 'START') { $query['where'][] = ($tiltLogicOp ? '' : ($condition->logic_op ? $condition->logic_op . ' ' : 'AND ')) . '('; $tiltLogicOp = true; } else { $query['where'][] = ')'; $tiltLogicOp = false; } } else { $GLOBALS['log']->debug('illegal condition'); } } } if (isset($query['where']) && $query['where']) { array_unshift($query['where'], '('); $query['where'][] = ') AND '; } $query['where'][] = $module->table_name . ".deleted = 0 " . $this->build_report_access_query($module, $module->table_name); } if ($closure) { $query['where'][] = ')'; } return $query; }
function parse_template(SugarBean $bean, &$template, $object_override = array()) { global $sugar_config; require_once 'modules/AOW_Actions/actions/templateParser.php'; $object_arr[$bean->module_dir] = $bean->id; foreach ($bean->field_defs as $bean_arr) { if ($bean_arr['type'] == 'relate') { if (isset($bean_arr['module']) && $bean_arr['module'] != '' && isset($bean_arr['id_name']) && $bean_arr['id_name'] != '' && $bean_arr['module'] != 'EmailAddress') { $idName = $bean_arr['id_name']; if (isset($bean->field_defs[$idName]) && $bean->field_defs[$idName]['source'] != 'non-db') { if (!isset($object_arr[$bean_arr['module']])) { $object_arr[$bean_arr['module']] = $bean->{$idName}; } } } } else { if ($bean_arr['type'] == 'link') { if (!isset($bean_arr['module']) || $bean_arr['module'] == '') { $bean_arr['module'] = getRelatedModule($bean->module_dir, $bean_arr['name']); } if (isset($bean_arr['module']) && $bean_arr['module'] != '' && !isset($object_arr[$bean_arr['module']]) && $bean_arr['module'] != 'EmailAddress') { $linkedBeans = $bean->get_linked_beans($bean_arr['name'], $bean_arr['module'], array(), 0, 1); if ($linkedBeans) { $linkedBean = $linkedBeans[0]; if (!isset($object_arr[$linkedBean->module_dir])) { $object_arr[$linkedBean->module_dir] = $linkedBean->id; } } } } } } $object_arr['Users'] = is_a($bean, 'User') ? $bean->id : $bean->assigned_user_id; $object_arr = array_merge($object_arr, $object_override); $parsedSiteUrl = parse_url($sugar_config['site_url']); $host = $parsedSiteUrl['host']; if (!isset($parsedSiteUrl['port'])) { $parsedSiteUrl['port'] = 80; } $port = $parsedSiteUrl['port'] != 80 ? ":" . $parsedSiteUrl['port'] : ''; $path = !empty($parsedSiteUrl['path']) ? $parsedSiteUrl['path'] : ""; $cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}"; $url = $cleanUrl . "/index.php?module={$bean->module_dir}&action=DetailView&record={$bean->id}"; $template->subject = str_replace("\$contact_user", "\$user", $template->subject); $template->body_html = str_replace("\$contact_user", "\$user", $template->body_html); $template->body = str_replace("\$contact_user", "\$user", $template->body); $template->subject = aowTemplateParser::parse_template($template->subject, $object_arr); $template->body_html = aowTemplateParser::parse_template($template->body_html, $object_arr); $template->body_html = str_replace("\$url", $url, $template->body_html); $template->body = aowTemplateParser::parse_template($template->body, $object_arr); $template->body = str_replace("\$url", $url, $template->body); }
function build_flow_query_where($query = array()) { global $beanList, $app_list_strings, $sugar_config, $timedate; if ($beanList[$this->flow_module]) { $module = new $beanList[$this->flow_module](); $sql = "SELECT id FROM aow_conditions WHERE aow_workflow_id = '" . $this->id . "' AND deleted = 0 ORDER BY condition_order ASC"; $result = $this->db->query($sql); while ($row = $this->db->fetchByAssoc($result)) { $condition = new AOW_Condition(); $condition->retrieve($row['id']); $path = unserialize(base64_decode($condition->module_path)); $condition_module = $module; $table_alias = $condition_module->table_name; if (isset($path[0]) && $path[0] != $module->module_dir) { foreach ($path as $rel) { $query = $this->build_flow_query_join($rel, $condition_module, 'relationship', $query); $condition_module = new $beanList[getRelatedModule($condition_module->module_dir, $rel)](); $table_alias = $rel; } } if (isset($app_list_strings['aow_sql_operator_list'][$condition->operator])) { $where_set = false; $data = $condition_module->field_defs[$condition->field]; if ($data['type'] == 'relate' && isset($data['id_name'])) { $condition->field = $data['id_name']; } if (isset($data['source']) && $data['source'] == 'custom_fields') { $field = $table_alias . '_cstm.' . $condition->field; $query = $this->build_flow_query_join($table_alias . '_cstm', $condition_module, 'custom', $query); } else { $field = $table_alias . '.' . $condition->field; } switch ($condition->value_type) { case 'Field': $data = $module->field_defs[$condition->value]; if ($data['type'] == 'relate' && isset($data['id_name'])) { $condition->value = $data['id_name']; } if (isset($data['source']) && $data['source'] == 'custom_fields') { $value = $module->table_name . '_cstm.' . $condition->value; $query = $this->build_flow_query_join($module->table_name . '_cstm', $module, 'custom', $query); } else { $value = $module->table_name . '.' . $condition->value; } break; case 'Any_Change': //can't detect in scheduler so return return array(); case 'Date': $params = unserialize(base64_decode($condition->value)); if ($params[0] == 'now') { if ($sugar_config['dbconfig']['db_type'] == 'mssql') { $value = 'GetUTCDate()'; } else { $value = 'UTC_TIMESTAMP()'; } } else { $data = $module->field_defs[$params[0]]; if (isset($data['source']) && $data['source'] == 'custom_fields') { $value = $module->table_name . '_cstm.' . $params[0]; $query = $this->build_flow_query_join($module->table_name . '_cstm', $module, 'custom', $query); } else { $value = $module->table_name . '.' . $params[0]; } } if ($params[1] != 'now') { switch ($params[3]) { case 'business_hours': if (file_exists('modules/AOBH_BusinessHours/AOBH_BusinessHours.php') && $params[0] == 'now') { require_once 'modules/AOBH_BusinessHours/AOBH_BusinessHours.php'; $businessHours = new AOBH_BusinessHours(); $amount = $params[2]; if ($params[1] != "plus") { $amount = 0 - $amount; } $value = $businessHours->addBusinessHours($amount); $value = "'" . $timedate->asDb($value) . "'"; break; } //No business hours module found - fall through. $params[3] = 'hour'; default: if ($sugar_config['dbconfig']['db_type'] == 'mssql') { $value = "DATEADD(" . $params[3] . ", " . $app_list_strings['aow_date_operator'][$params[1]] . " {$params['2']}, {$value})"; } else { $value = "DATE_ADD({$value}, INTERVAL " . $app_list_strings['aow_date_operator'][$params[1]] . " {$params['2']} " . $params[3] . ")"; } break; } } break; case 'Multi': $sep = ' AND '; if ($condition->operator == 'Equal_To') { $sep = ' OR '; } $multi_values = unencodeMultienum($condition->value); if (!empty($multi_values)) { $value = '('; if ($data['type'] == 'multienum') { $multi_operator = $condition->operator == 'Equal_To' ? 'LIKE' : 'NOT LIKE'; foreach ($multi_values as $multi_value) { if ($value != '(') { $value .= $sep; } $value .= $field . " {$multi_operator} '%^" . $multi_value . "^%'"; } } else { foreach ($multi_values as $multi_value) { if ($value != '(') { $value .= $sep; } $value .= $field . ' ' . $app_list_strings['aow_sql_operator_list'][$condition->operator] . " '" . $multi_value . "'"; } } $value .= ')'; $query['where'][] = $value; } $where_set = true; break; case 'SecurityGroup': if (file_exists('modules/SecurityGroups/SecurityGroup.php')) { //TODO check bean in group return array(); break; } case 'Value': default: $value = "'" . $condition->value . "'"; break; } if (!$where_set) { $query['where'][] = $field . ' ' . $app_list_strings['aow_sql_operator_list'][$condition->operator] . ' ' . $value; } } } if ($this->flow_run_on) { switch ($this->flow_run_on) { case 'New_Records': $query['where'][] = $module->table_name . '.' . 'date_entered' . ' > ' . "'" . $this->date_entered . "'"; break; case 'Modified_Records': $query['where'][] = $module->table_name . '.' . 'date_modified' . ' > ' . "'" . $this->date_entered . "'" . ' AND ' . $module->table_name . '.' . 'date_entered' . ' <> ' . $module->table_name . '.' . 'date_modified'; break; } } if (!$this->multiple_runs) { $query['where'][] .= "NOT EXISTS (SELECT * FROM aow_processed WHERE aow_processed.aow_workflow_id='" . $this->id . "' AND aow_processed.parent_id=" . $module->table_name . ".id AND aow_processed.status = 'Complete' AND aow_processed.deleted = 0)"; } $query['where'][] = $module->table_name . ".deleted = 0 "; } return $query; }
/** * Advanced OpenWorkflow, Automating SugarCRM. * @package Advanced OpenWorkflow for SugarCRM * @copyright SalesAgility Ltd http://www.salesagility.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * 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 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 * * @author SalesAgility <*****@*****.**> */ function display_condition_lines($focus, $field, $value, $view) { global $locale, $app_list_strings, $mod_strings; $html = ''; if (!is_file('cache/jsLanguage/AOW_Conditions/' . $GLOBALS['current_language'] . '.js')) { require_once 'include/language/jsLanguage.php'; jsLanguage::createModuleStringsCache('AOW_Conditions', $GLOBALS['current_language']); } $html .= '<script src="cache/jsLanguage/AOW_Conditions/' . $GLOBALS['current_language'] . '.js"></script>'; if ($view == 'EditView') { $html .= '<script src="modules/AOW_Conditions/conditionLines.js"></script>'; $html .= "<table border='0' cellspacing='4' width='100%' id='conditionLines'></table>"; $html .= "<div style='padding-top: 10px; padding-bottom:10px;'>"; $html .= "<input type=\"button\" tabindex=\"116\" class=\"button\" value=\"" . $mod_strings['LBL_ADD_CONDITION'] . "\" id=\"btn_ConditionLine\" onclick=\"insertConditionLine()\" disabled/>"; $html .= "</div>"; if (isset($focus->flow_module) && $focus->flow_module != '') { require_once "modules/AOW_WorkFlow/aow_utils.php"; $html .= "<script>"; $html .= "flow_rel_modules = \"" . trim(preg_replace('/\\s+/', ' ', getModuleRelationships($focus->flow_module))) . "\";"; $html .= "flow_module = \"" . $focus->flow_module . "\";"; $html .= "document.getElementById('btn_ConditionLine').disabled = '';"; if ($focus->id != '') { $sql = "SELECT id FROM aow_conditions WHERE aow_workflow_id = '" . $focus->id . "' AND deleted = 0 ORDER BY condition_order ASC"; $result = $focus->db->query($sql); while ($row = $focus->db->fetchByAssoc($result)) { $condition_name = new AOW_Condition(); $condition_name->retrieve($row['id']); $condition_name->module_path = unserialize(base64_decode($condition_name->module_path)); if ($condition_name->module_path == '') { $condition_name->module_path = $focus->flow_module; } $html .= "flow_fields = \"" . trim(preg_replace('/\\s+/', ' ', getModuleFields(getRelatedModule($focus->flow_module, $condition_name->module_path[0])))) . "\";"; if ($condition_name->value_type == 'Date') { $condition_name->value = unserialize(base64_decode($condition_name->value)); } $condition_item = json_encode($condition_name->toArray()); $html .= "loadConditionLine(" . $condition_item . ");"; } } $html .= "flow_fields = \"" . trim(preg_replace('/\\s+/', ' ', getModuleFields($focus->flow_module))) . "\";"; $html .= "</script>"; } } else { if ($view == 'DetailView') { $html .= '<script src="modules/AOW_Conditions/conditionLines.js"></script>'; $html .= "<table border='0' cellspacing='0' width='100%' id='conditionLines'></table>"; if (isset($focus->flow_module) && $focus->flow_module != '') { require_once "modules/AOW_WorkFlow/aow_utils.php"; $html .= "<script>"; $html .= "flow_rel_modules = \"" . trim(preg_replace('/\\s+/', ' ', getModuleRelationships($focus->flow_module))) . "\";"; $html .= "flow_module = \"" . $focus->flow_module . "\";"; $sql = "SELECT id FROM aow_conditions WHERE aow_workflow_id = '" . $focus->id . "' AND deleted = 0 ORDER BY condition_order ASC"; $result = $focus->db->query($sql); while ($row = $focus->db->fetchByAssoc($result)) { $condition_name = new AOW_Condition(); $condition_name->retrieve($row['id']); $condition_name->module_path = unserialize(base64_decode($condition_name->module_path)); if (empty($condition_name->module_path)) { $condition_name->module_path[0] = $focus->flow_module; } $html .= "flow_fields = \"" . trim(preg_replace('/\\s+/', ' ', getModuleFields(getRelatedModule($focus->flow_module, $condition_name->module_path[0])))) . "\";"; if ($condition_name->value_type == 'Date') { $condition_name->value = unserialize(base64_decode($condition_name->value)); } $condition_item = json_encode($condition_name->toArray()); $html .= "loadConditionLine(" . $condition_item . ");"; } $html .= "</script>"; } } } return $html; }
function build_query_where(AOW_Condition $condition, $module, $query = array()){ global $beanList, $app_list_strings, $sugar_config, $timedate; $path = unserialize(base64_decode($condition->module_path)); $condition_module = $module; $table_alias = $condition_module->table_name; if(isset($path[0]) && $path[0] != $module->module_dir){ foreach($path as $rel){ $query = $this->build_flow_query_join($rel, $condition_module, 'relationship', $query); $condition_module = new $beanList[getRelatedModule($condition_module->module_dir,$rel)]; $table_alias = $rel; } } if(isset($app_list_strings['aow_sql_operator_list'][$condition->operator])){ $where_set = false; $data = $condition_module->field_defs[$condition->field]; if($data['type'] == 'relate' && isset($data['id_name'])) { $condition->field = $data['id_name']; } if( (isset($data['source']) && $data['source'] == 'custom_fields')) { $field = $table_alias.'_cstm.'.$condition->field; $query = $this->build_flow_query_join($table_alias.'_cstm', $condition_module, 'custom', $query); } else { $field = $table_alias.'.'.$condition->field; } if($condition->operator == 'is_null'){ $query['where'][] = '('.$field.' '.$app_list_strings['aow_sql_operator_list'][$condition->operator].' OR '.$field.' '.$app_list_strings['aow_sql_operator_list']['Equal_To']." '')"; return $query; } switch($condition->value_type) { case 'Field': $data = $module->field_defs[$condition->value]; if($data['type'] == 'relate' && isset($data['id_name'])) { $condition->value = $data['id_name']; } if( (isset($data['source']) && $data['source'] == 'custom_fields')) { $value = $module->table_name.'_cstm.'.$condition->value; $query = $this->build_flow_query_join($module->table_name.'_cstm', $module, 'custom', $query); } else { $value = $module->table_name.'.'.$condition->value; } break; case 'Any_Change': //can't detect in scheduler so return return array(); case 'Date': $params = unserialize(base64_decode($condition->value)); if($params[0] == 'now'){ if($sugar_config['dbconfig']['db_type'] == 'mssql'){ $value = 'GetUTCDate()'; } else { $value = 'UTC_TIMESTAMP()'; } } else if($params[0] == 'today'){ if($sugar_config['dbconfig']['db_type'] == 'mssql'){ //$field = $value = 'CAST(GETDATE() AS DATE)'; } else { $field = 'DATE('.$field.')'; $value = 'Curdate()'; } } else { $data = $module->field_defs[$params[0]]; if( (isset($data['source']) && $data['source'] == 'custom_fields')) { $value = $module->table_name.'_cstm.'.$params[0]; $query = $this->build_flow_query_join($module->table_name.'_cstm', $module, 'custom', $query); } else { $value = $module->table_name.'.'.$params[0]; } } if($params[1] != 'now'){ switch($params[3]) { case 'business_hours'; if(file_exists('modules/AOBH_BusinessHours/AOBH_BusinessHours.php') && $params[0] == 'now'){ require_once('modules/AOBH_BusinessHours/AOBH_BusinessHours.php'); $businessHours = new AOBH_BusinessHours(); $amount = $params[2]; if($params[1] != "plus"){ $amount = 0-$amount; } $value = $businessHours->addBusinessHours($amount); $value = "'".$timedate->asDb( $value )."'"; break; } //No business hours module found - fall through. $params[3] = 'hour'; default: if($sugar_config['dbconfig']['db_type'] == 'mssql'){ $value = "DATEADD(".$params[3].", ".$app_list_strings['aow_date_operator'][$params[1]]." $params[2], $value)"; } else { $value = "DATE_ADD($value, INTERVAL ".$app_list_strings['aow_date_operator'][$params[1]]." $params[2] ".$params[3].")"; } break; } } break; case 'Multi': $sep = ' AND '; if($condition->operator == 'Equal_To') $sep = ' OR '; $multi_values = unencodeMultienum($condition->value); if(!empty($multi_values)){ $value = '('; if($data['type'] == 'multienum'){ $multi_operator = $condition->operator == 'Equal_To' ? 'LIKE' : 'NOT LIKE'; foreach($multi_values as $multi_value){ if($value != '(') $value .= $sep; $value .= $field." $multi_operator '%^".$multi_value."^%'"; } } else { foreach($multi_values as $multi_value){ if($value != '(') $value .= $sep; $value .= $field.' '.$app_list_strings['aow_sql_operator_list'][$condition->operator]." '".$multi_value."'"; } } $value .= ')'; $query['where'][] = $value; } $where_set = true; break; case 'SecurityGroup': if(file_exists('modules/SecurityGroups/SecurityGroup.php')){ //TODO check bean in group return array(); break; } case 'Value': default: $value = "'".$condition->value."'"; break; } //handle like conditions Switch($condition->operator) { case 'Contains': $value = "CONCAT('%', ".$value." ,'%')"; break; case 'Starts_With': $value = "CONCAT(".$value." ,'%')"; break; case 'Ends_With': $value = "CONCAT('%', ".$value.")"; break; } if(!$where_set) $query['where'][] = $field.' '.$app_list_strings['aow_sql_operator_list'][$condition->operator].' '.$value; } return $query; }
public function getDisplayForField($modulePath, $field, $reportModule) { $modulePathDisplay = array(); $currentBean = BeanFactory::getBean($reportModule); $modulePathDisplay[] = $currentBean->module_name; if (is_array($modulePath)) { $split = $modulePath; } else { $split = explode(':', $modulePath); } if ($split && $split[0] == $currentBean->module_dir) { array_shift($split); } foreach ($split as $relName) { if (empty($relName)) { continue; } if (!empty($currentBean->field_name_map[$relName]['vname'])) { $moduleLabel = trim(translate($currentBean->field_name_map[$relName]['vname'], $currentBean->module_dir), ':'); } $thisModule = getRelatedModule($currentBean->module_dir, $relName); $currentBean = BeanFactory::getBean($thisModule); if (!empty($moduleLabel)) { $modulePathDisplay[] = $moduleLabel; } else { $modulePathDisplay[] = $currentBean->module_name; } } $fieldDisplay = $currentBean->field_name_map[$field]['type']; return $fieldDisplay; }
function run_action(SugarBean $bean, $params = array(), $in_save = false) { global $sugar_config, $beanList; include_once 'modules/EmailTemplates/EmailTemplate.php'; require_once 'modules/AOW_Actions/actions/templateParser.php'; $emailTemp = new EmailTemplate(); $emailTemp->retrieve($params['email_template']); if ($emailTemp->id == '') { return false; } $object_arr[$bean->module_dir] = $bean->id; foreach ($bean->field_defs as $bean_arr) { if ($bean_arr['type'] == 'relate') { if (isset($bean_arr['module']) && $bean_arr['module'] != '' && isset($bean_arr['id_name']) && $bean_arr['id_name'] != '' && $bean_arr['module'] != 'EmailAddress') { $relate_bean = new $beanList[$bean_arr['module']](); if (!isset($object_arr[$relate_bean->module_dir])) { $object_arr[$relate_bean->module_dir] = $bean->{$bean_arr}['id_name']; } } } else { if ($bean_arr['type'] == 'link') { if (!isset($bean_arr['module']) || $bean_arr['module'] == '') { $bean_arr['module'] = getRelatedModule($bean->module_dir, $bean_arr['name']); } if (isset($bean_arr['module']) && $bean_arr['module'] != '' && !isset($object_arr[$bean_arr['module']]) && $bean_arr['module'] != 'EmailAddress') { $linkedBeans = $bean->get_linked_beans($bean_arr['name'], $bean_arr['module']); if ($linkedBeans) { $linkedBean = $linkedBeans[0]; if (!isset($object_arr[$linkedBean->module_dir])) { $object_arr[$linkedBean->module_dir] = $linkedBean->id; } } } } } } $object_arr['Users'] = $bean->assigned_user_id; $parsedSiteUrl = parse_url($sugar_config['site_url']); $host = $parsedSiteUrl['host']; if (!isset($parsedSiteUrl['port'])) { $parsedSiteUrl['port'] = 80; } $port = $parsedSiteUrl['port'] != 80 ? ":" . $parsedSiteUrl['port'] : ''; $path = !empty($parsedSiteUrl['path']) ? $parsedSiteUrl['path'] : ""; $cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}"; $url = $cleanUrl . "/index.php?module={$bean->module_dir}&action=DetailView&record={$bean->id}"; $subject = str_replace("\$contact_user", "\$user", $emailTemp->subject); $body_html = str_replace("\$contact_user", "\$user", $emailTemp->body_html); $body_plain = str_replace("\$contact_user", "\$user", $emailTemp->body); $subject = aowTemplateParser::parse_template($subject, $object_arr); $body_html = aowTemplateParser::parse_template($body_html, $object_arr); $body_html = str_replace("\$url", $url, $body_html); $body_plain = aowTemplateParser::parse_template($body_plain, $object_arr); $body_plain = str_replace("\$url", $url, $body_plain); $emails = $this->getEmailsFromParams($bean, $params); return $this->sendEmail($emails['to'], $subject, $body_html, $body_plain, $bean, $emails['cc'], $emails['bcc']); }