コード例 #1
0
ファイル: view.edit.php プロジェクト: switcode/SuiteCRM
 private function getConditionLines()
 {
     if (!$this->bean->id) {
         return array();
     }
     $sql = "SELECT id FROM aor_conditions WHERE aor_report_id = '" . $this->bean->id . "' AND deleted = 0 ORDER BY condition_order ASC";
     $result = $this->bean->db->query($sql);
     $conditions = array();
     while ($row = $this->bean->db->fetchByAssoc($result)) {
         $condition_name = new AOR_Condition();
         $condition_name->retrieve($row['id']);
         if (!$condition_name->parenthesis) {
             $condition_name->module_path = implode(":", unserialize(base64_decode($condition_name->module_path)));
         }
         if ($condition_name->value_type == 'Date') {
             $condition_name->value = unserialize(base64_decode($condition_name->value));
         }
         $condition_item = $condition_name->toArray();
         if (!$condition_name->parenthesis) {
             $display = getDisplayForField($condition_name->module_path, $condition_name->field, $this->bean->report_module);
             $condition_item['module_path_display'] = $display['module'];
             $condition_item['field_label'] = $display['field'];
         }
         if (isset($conditions[$condition_item['condition_order']])) {
             $conditions[] = $condition_item;
         } else {
             $conditions[$condition_item['condition_order']] = $condition_item;
         }
     }
     return $conditions;
 }
コード例 #2
0
 public function testsave_lines()
 {
     error_reporting(E_ERROR | E_PARSE);
     $aor_Condition = new AOR_Condition();
     //preset the required data
     $post_data = array();
     $post_data['field'][] = 'test field';
     $post_data['name'][] = 'test';
     $post_data['parameter'][] = '1';
     $post_data['module_path'][] = 'test path';
     $post_data['operator'][] = 'test';
     $post_data['value_type'][] = 'test type';
     //execute the method and test if it works and does not throws an exception.
     try {
         $aor_Condition->save_lines($post_data, new AOR_Report());
         $this->assertTrue(true);
     } catch (Exception $e) {
         $this->fail();
     }
 }
コード例 #3
0
ファイル: AOR_Condition.php プロジェクト: MexinaD/SuiteCRM
 function save_lines($post_data, $parent, $key = '')
 {
     require_once 'modules/AOW_WorkFlow/aow_utils.php';
     $line_count = count($post_data[$key . 'field']);
     $j = 0;
     for ($i = 0; $i < $line_count; ++$i) {
         if ($post_data[$key . 'deleted'][$i] == 1) {
             $this->mark_deleted($post_data[$key . 'id'][$i]);
         } else {
             $condition = new AOR_Condition();
             foreach ($this->field_defs as $field_def) {
                 if (isset($post_data[$key . $field_def['name']][$i])) {
                     if (is_array($post_data[$key . $field_def['name']][$i])) {
                         switch ($condition->value_type) {
                             case 'Date':
                                 $post_data[$key . $field_def['name']][$i] = base64_encode(serialize($post_data[$key . $field_def['name']][$i]));
                             default:
                                 $post_data[$key . $field_def['name']][$i] = encodeMultienumValue($post_data[$key . $field_def['name']][$i]);
                         }
                     } else {
                         if ($field_def['name'] == 'value') {
                             $post_data[$key . $field_def['name']][$i] = fixUpFormatting($_REQUEST['report_module'], $condition->field, $post_data[$key . $field_def['name']][$i]);
                         } else {
                             if ($field_def['name'] == 'parameter') {
                                 $post_data[$key . $field_def['name']][$i] = isset($post_data[$key . $field_def['name']][$i]);
                             } else {
                                 if ($field_def['name'] == 'module_path') {
                                     $post_data[$key . $field_def['name']][$i] = base64_encode(serialize(explode(":", $post_data[$key . $field_def['name']][$i])));
                                 }
                             }
                         }
                     }
                     $condition->{$field_def}['name'] = $post_data[$key . $field_def['name']][$i];
                 } else {
                     if ($field_def['name'] == 'parameter') {
                         $condition->{$field_def}['name'] = 0;
                     }
                 }
             }
             // Period must be saved as a string instead of a base64 encoded datetime.
             // Overwriting value
             if ($condition->value_type == 'Period') {
                 $condition->value = base64_encode($_POST['aor_conditions_value'][$i]);
                 //                    $condition->value = $_POST['aor_conditions_value'][$i];
             }
             if (trim($condition->field) != '') {
                 $condition->condition_order = ++$j;
                 $condition->aor_report_id = $parent->id;
                 $condition->save();
             }
         }
     }
 }
コード例 #4
0
 function save_lines($post_data, $parent, $key = '')
 {
     require_once 'modules/AOR_Reports/aor_utils.php';
     $line_count = count($post_data[$key . 'field']);
     $j = 0;
     for ($i = 0; $i < $line_count; ++$i) {
         if ($post_data[$key . 'deleted'][$i] == 1) {
             $this->mark_deleted($post_data[$key . 'id'][$i]);
         } else {
             $condition = new AOR_Condition();
             foreach ($this->field_defs as $field_def) {
                 if (isset($post_data[$key . $field_def['name']][$i])) {
                     if (is_array($post_data[$key . $field_def['name']][$i])) {
                         if ($field_def['name'] == 'module_path') {
                             $post_data[$key . $field_def['name']][$i] = base64_encode(serialize($post_data[$key . $field_def['name']][$i]));
                         } else {
                             switch ($condition->value_type) {
                                 case 'Date':
                                     $post_data[$key . $field_def['name']][$i] = base64_encode(serialize($post_data[$key . $field_def['name']][$i]));
                                 default:
                                     $post_data[$key . $field_def['name']][$i] = encodeMultienumValue($post_data[$key . $field_def['name']][$i]);
                             }
                         }
                     } else {
                         if ($field_def['name'] == 'value') {
                             $post_data[$key . $field_def['name']][$i] = fixUpFormatting($_REQUEST['report_module'], $condition->field, $post_data[$key . $field_def['name']][$i]);
                         }
                     }
                     $condition->{$field_def}['name'] = $post_data[$key . $field_def['name']][$i];
                 }
             }
             if (trim($condition->field) != '') {
                 $condition->condition_order = ++$j;
                 $condition->aor_report_id = $parent->id;
                 $condition->save();
             }
         }
     }
 }
コード例 #5
0
ファイル: AOR_Condition.php プロジェクト: auf/crm_auf_org
 function save_lines($post_data, $parent, $key = '')
 {
     require_once 'modules/AOW_WorkFlow/aow_utils.php';
     $line_count = count($post_data[$key . 'field']);
     $j = 0;
     for ($i = 0; $i < $line_count; ++$i) {
         if ($post_data[$key . 'deleted'][$i] == 1) {
             $this->mark_deleted($post_data[$key . 'id'][$i]);
         } else {
             $condition = new AOR_Condition();
             foreach ($this->field_defs as $field_def) {
                 $field_name = $field_def['name'];
                 if (isset($post_data[$key . $field_name][$i])) {
                     if (is_array($post_data[$key . $field_name][$i])) {
                         switch ($condition->value_type) {
                             case 'Date':
                                 $post_data[$key . $field_name][$i] = base64_encode(serialize($post_data[$key . $field_name][$i]));
                                 break;
                             default:
                                 $post_data[$key . $field_name][$i] = encodeMultienumValue($post_data[$key . $field_name][$i]);
                         }
                     } else {
                         if ($field_name == 'value' && $post_data[$key . 'value_type'][$i] === 'Value') {
                             $post_data[$key . $field_name][$i] = fixUpFormatting($_REQUEST['report_module'], $condition->field, $post_data[$key . $field_name][$i]);
                         } else {
                             if ($field_name == 'parameter') {
                                 $post_data[$key . $field_name][$i] = isset($post_data[$key . $field_name][$i]);
                             } else {
                                 if ($field_name == 'module_path') {
                                     $post_data[$key . $field_name][$i] = base64_encode(serialize(explode(":", $post_data[$key . $field_name][$i])));
                                 }
                             }
                         }
                     }
                     if ($field_name == 'parenthesis' && $post_data[$key . $field_name][$i] == 'END') {
                         if (!isset($lastParenthesisStartConditionId)) {
                             throw new Exception('a closure parenthesis has no starter pair');
                         }
                         $condition->parenthesis = $lastParenthesisStartConditionId;
                     } else {
                         $condition->{$field_name} = $post_data[$key . $field_name][$i];
                     }
                 } else {
                     if ($field_name == 'parameter') {
                         $condition->{$field_name} = 0;
                     }
                 }
             }
             // Period must be saved as a string instead of a base64 encoded datetime.
             // Overwriting value
             if ((!isset($condition->parenthesis) || !$condition->parenthesis) && isset($condition->value_type) && $condition->value_type == 'Period') {
                 $condition->value = base64_encode($_POST['aor_conditions_value'][$i]);
             }
             if (trim($condition->field) != '' || $condition->parenthesis) {
                 if (isset($_POST['aor_conditions_order'][$i])) {
                     $condition->condition_order = (int) $_POST['aor_conditions_order'][$i];
                 } else {
                     $condition->condition_order = ++$j;
                 }
                 $condition->aor_report_id = $parent->id;
                 $conditionId = $condition->save();
                 if ($condition->parenthesis == 'START') {
                     $lastParenthesisStartConditionId = $conditionId;
                 }
             }
         }
     }
 }
コード例 #6
0
 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;
 }
コード例 #7
0
ファイル: AOR_Report.php プロジェクト: auf/crm_auf_org
 /**
  * @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;
 }
コード例 #8
0
/**
 * 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_condition_lines($focus, $field, $value, $view)
{
    global $locale, $app_list_strings, $mod_strings;
    $html = '';
    if (!is_file('cache/jsLanguage/AOR_Conditions/' . $GLOBALS['current_language'] . '.js')) {
        require_once 'include/language/jsLanguage.php';
        jsLanguage::createModuleStringsCache('AOR_Conditions', $GLOBALS['current_language']);
    }
    $html .= '<script src="cache/jsLanguage/AOR_Conditions/' . $GLOBALS['current_language'] . '.js"></script>';
    if ($view == 'EditView') {
        $html .= '<script src="modules/AOR_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->report_module) && $focus->report_module != '') {
            require_once "modules/AOR_Reports/aor_utils.php";
            $html .= "<script>";
            $html .= "report_module = \"" . $focus->report_module . "\";";
            $html .= "document.getElementById('btn_ConditionLine').disabled = '';";
            if ($focus->id != '') {
                $sql = "SELECT id FROM aor_conditions WHERE aor_report_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 AOR_Condition();
                    $condition_name->retrieve($row['id']);
                    $condition_name->module_path = unserialize(base64_decode($condition_name->module_path));
                    $html .= "report_fields = \"" . trim(preg_replace('/\\s+/', ' ', getModuleFields(getRelatedModule($focus->report_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 .= "report_fields = \"" . trim(preg_replace('/\\s+/', ' ', getModuleFields($focus->report_module))) . "\";";
            $html .= "</script>";
        }
    } else {
        if ($view == 'DetailView') {
            $html .= '<script src="modules/AOR_Conditions/conditionLines.js"></script>';
            $html .= "<table border='0' cellspacing='0' width='100%' id='conditionLines'></table>";
            if (isset($focus->report_module) && $focus->report_module != '') {
                require_once "modules/AOR_Reports/aor_utils.php";
                $html .= "<script>";
                $html .= "report_fields = \"" . trim(preg_replace('/\\s+/', ' ', getModuleFields($focus->report_module))) . "\";";
                $html .= "report_module = \"" . $focus->report_module . "\";";
                $sql = "SELECT id FROM aor_conditions WHERE aor_report_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 AOR_Condition();
                    $condition_name->retrieve($row['id']);
                    $condition_name->module_path = unserialize(base64_decode($condition_name->module_path));
                    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;
}