Exemplo n.º 1
0
 public function testsave_lines()
 {
     error_reporting(E_ERROR | E_PARSE);
     $aor_Field = new AOR_Field();
     //preset the required data
     $post_data = array();
     $post_data['field'][] = 'test field';
     $post_data['name'][] = 'test';
     $post_data['module_path'][] = 'test path';
     $post_data['display'][] = '1';
     $post_data['link'][] = '1';
     $post_data['label'][] = 'test label';
     $post_data['field_function'][] = 'test function';
     $post_data['total'][] = 'total';
     $post_data['group_by'][] = '1';
     $post_data['group_order'][] = 'desc';
     $post_data['group_display'][] = '1';
     //execute the method and test if it works and does not throws an exception.
     try {
         $aor_Field->save_lines($post_data, new AOR_Report());
         $this->assertTrue(true);
     } catch (Exception $e) {
         $this->fail();
     }
 }
Exemplo n.º 2
0
 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 {
             $field = new AOR_Field();
             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])) {
                         $post_data[$key . $field_def['name']][$i] = base64_encode(serialize($post_data[$key . $field_def['name']][$i]));
                     } else {
                         if ($field_def['name'] == 'value') {
                             $post_data[$key . $field_def['name']][$i] = fixUpFormatting($_REQUEST['report_module'], $field->field, $post_data[$key . $field_def['name']][$i]);
                         }
                     }
                     $field->{$field_def}['name'] = $post_data[$key . $field_def['name']][$i];
                 }
             }
             if (trim($field->field) != '') {
                 $field->aor_report_id = $parent->id;
                 $field->save();
             }
         }
     }
 }
Exemplo n.º 3
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_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;
}
Exemplo n.º 4
0
 function save_lines($post_data, $parent, $key = '')
 {
     require_once 'modules/AOW_WorkFlow/aow_utils.php';
     $line_count = count($post_data[$key . 'field']);
     for ($i = 0; $i < $line_count; ++$i) {
         if ($post_data[$key . 'deleted'][$i] == 1) {
             $this->mark_deleted($post_data[$key . 'id'][$i]);
         } else {
             $field = new AOR_Field();
             $field->group_display = false;
             if ($key == 'aor_fields_') {
                 foreach ($post_data['aor_fields_group_display'] as $gdKey => $gdValue) {
                     if ($gdValue == $i) {
                         $field->group_display = $gdKey + 1;
                         break;
                     }
                 }
             }
             foreach ($this->field_defs as $field_def) {
                 $field_name = $field_def['name'];
                 if (is_array($post_data[$key . $field_name])) {
                     if ($field_name != 'group_display' && isset($post_data[$key . $field_name][$i])) {
                         if (is_array($post_data[$key . $field_name][$i])) {
                             $post_data[$key . $field_name][$i] = base64_encode(serialize($post_data[$key . $field_name][$i]));
                         } else {
                             if ($field_name == 'value') {
                                 $post_data[$key . $field_name][$i] = fixUpFormatting($_REQUEST['report_module'], $field->field, $post_data[$key . $field_name][$i]);
                             }
                         }
                         if ($field_name == 'module_path') {
                             $post_data[$key . $field_name][$i] = base64_encode(serialize(explode(":", $post_data[$key . $field_name][$i])));
                         }
                         $field->{$field_name} = $post_data[$key . $field_name][$i];
                     }
                 } else {
                     if (is_null($post_data[$key . $field_name])) {
                         // do nothing
                     } else {
                         throw new Exception('illegal type in post data at key ' . $key . $field_name . ' ' . gettype($post_data[$key . $field_name]));
                     }
                 }
             }
             if (trim($field->field) != '') {
                 $field->aor_report_id = $parent->id;
                 $field->save();
             }
         }
     }
 }
Exemplo n.º 5
0
 function build_report_query_select($query = array(), $group_value = '')
 {
     global $beanList;
     if ($beanList[$this->report_module]) {
         $module = new $beanList[$this->report_module]();
         $query['select'][] = $this->db->quoteIdentifier($module->table_name) . ".id AS '" . $module->table_name . "_id'";
         $sql = "SELECT id FROM aor_fields WHERE aor_report_id = '" . $this->id . "' AND deleted = 0 ORDER BY field_order ASC";
         $result = $this->db->query($sql);
         $i = 0;
         while ($row = $this->db->fetchByAssoc($result)) {
             $field = new AOR_Field();
             $field->retrieve($row['id']);
             $field->label = str_replace(' ', '_', $field->label) . $i;
             $path = unserialize(base64_decode($field->module_path));
             $field_module = $module;
             $table_alias = $field_module->table_name;
             if (!empty($path[0]) && $path[0] != $module->module_dir) {
                 foreach ($path as $rel) {
                     $new_field_module = new $beanList[getRelatedModule($field_module->module_dir, $rel)]();
                     $oldAlias = $table_alias;
                     $table_alias = $table_alias . ":" . $rel;
                     $query = $this->build_report_query_join($rel, $table_alias, $oldAlias, $field_module, 'relationship', $query, $new_field_module);
                     $field_module = $new_field_module;
                 }
             }
             $data = $field_module->field_defs[$field->field];
             if ($data['type'] == 'relate' && isset($data['id_name'])) {
                 $field->field = $data['id_name'];
                 $data_new = $field_module->field_defs[$field->field];
                 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'])]();
                 $table_alias = $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;
                 $field->field = 'id';
             }
             if ($data['type'] == 'currency' && isset($field_module->field_defs['currency_id'])) {
                 if (isset($field_module->field_defs['currency_id']['source']) && $field_module->field_defs['currency_id']['source'] == 'custom_fields') {
                     $query['select'][$table_alias . '_currency_id'] = $this->db->quoteIdentifier($table_alias . '_cstm') . ".currency_id AS '" . $table_alias . "_currency_id'";
                 } else {
                     $query['select'][$table_alias . '_currency_id'] = $this->db->quoteIdentifier($table_alias) . ".currency_id AS '" . $table_alias . "_currency_id'";
                 }
             }
             if (isset($data['source']) && $data['source'] == 'custom_fields') {
                 $select_field = $table_alias . '_cstm.' . $field->field;
                 $query = $this->build_report_query_join($table_alias . '_cstm', $table_alias . '_cstm', $table_alias, $field_module, 'custom', $query);
             } else {
                 $select_field = $this->db->quoteIdentifier($table_alias) . '.' . $field->field;
             }
             if ($field->sort_by != '') {
                 $query['sort_by'][] = $select_field . " " . $field->sort_by;
             }
             if ($field->group_by == 1) {
                 $query['group_by'][] = $select_field;
             }
             if ($field->field_function != null) {
                 $select_field = $field->field_function . '(' . $select_field . ')';
             }
             $query['select'][] = $select_field . " AS '" . $field->label . "'";
             if ($field->group_display) {
                 $query['where'][] = $select_field . " = '" . $group_value . "'";
             }
             ++$i;
         }
     }
     return $query;
 }
Exemplo n.º 6
0
 function build_report_query_select($query = array())
 {
     global $beanList;
     if ($beanList[$this->report_module]) {
         $module = new $beanList[$this->report_module]();
         $query['select'][] = $module->table_name . ".id AS '" . $module->table_name . "_id'";
         $sql = "SELECT id FROM aor_fields WHERE aor_report_id = '" . $this->id . "' AND deleted = 0 ORDER BY field_order ASC";
         $result = $this->db->query($sql);
         $i = 0;
         while ($row = $this->db->fetchByAssoc($result)) {
             $field = new AOR_Field();
             $field->retrieve($row['id']);
             $field->label = str_replace(' ', '_', $field->label) . $i;
             $path = unserialize(base64_decode($field->module_path));
             $field_module = $module;
             $table_alias = $field_module->table_name;
             if ($path[0] != $module->module_dir) {
                 foreach ($path as $rel) {
                     $query = $this->build_report_query_join($rel, $field_module, 'relationship', $query);
                     $field_module = new $beanList[getRelatedModule($field_module->module_dir, $rel)]();
                     $table_alias = $rel;
                 }
             }
             $data = $field_module->field_defs[$field->field];
             if ($data['type'] == 'relate' && isset($data['id_name'])) {
                 $field->field = $data['id_name'];
             }
             if (isset($data['source']) && $data['source'] == 'custom_fields') {
                 $select_field = $table_alias . '_cstm.' . $field->field;
                 $query = $this->build_report_query_join($table_alias . '_cstm', $field_module, 'custom', $query);
             } else {
                 $select_field = $table_alias . '.' . $field->field;
             }
             if ($field->sort_by != '') {
                 $query['sort_by'][] = $field->label . ' ' . $field->sort_by;
             }
             if ($field->group_by == 1) {
                 $query['group_by'][] = $select_field;
             }
             if ($field->field_function != null) {
                 $select_field = $field->field_function . '(' . $select_field . ')';
             }
             $query['select'][] = $select_field . " AS '" . $field->label . "'";
             ++$i;
         }
     }
     return $query;
 }
Exemplo n.º 7
0
 function build_report_query_select($query = array(), $group_value = '')
 {
     global $beanList;
     $has_group_by = false;
     if ($beanList[$this->report_module]) {
         $module = new $beanList[$this->report_module]();
         $sql = "SELECT id FROM aor_fields WHERE aor_report_id = '" . $this->id . "' AND deleted = 0 ORDER BY field_order ASC";
         $result = $this->db->query($sql);
         $i = 0;
         while ($row = $this->db->fetchByAssoc($result)) {
             $field = new AOR_Field();
             $field->retrieve($row['id']);
             $field->label = str_replace(' ', '_', $field->label) . $i;
             $path = unserialize(base64_decode($field->module_path));
             $field_module = $module;
             $table_alias = $field_module->table_name;
             $oldAlias = $table_alias;
             if (!empty($path[0]) && $path[0] != $module->module_dir) {
                 foreach ($path as $rel) {
                     $new_field_module = new $beanList[getRelatedModule($field_module->module_dir, $rel)]();
                     $oldAlias = $table_alias;
                     $table_alias = $table_alias . ":" . $rel;
                     $query = $this->build_report_query_join($rel, $table_alias, $oldAlias, $field_module, 'relationship', $query, $new_field_module);
                     $_id_query = $this->db->quoteIdentifier($module->table_name . ':' . implode(':', $path)) . ".id AS '" . $module->table_name . ':' . implode(':', $path) . "_id'";
                     // Add the id field to the select query if field is a link
                     // Run  a duplicate check - prevents SQL errors
                     if (array_search($_id_query, $query['select']) === FALSE) {
                         if ($field->link == '1') {
                             $query['select'][] = $_id_query;
                             $query['select_id'][] = array("field" => $this->db->quoteIdentifier($module->table_name . ':' . implode(':', $path)) . ".id", "alias" => $module->table_name . ':' . implode(':', $path) . "_id");
                         }
                     }
                     $field_module = $new_field_module;
                 }
             }
             $data = $field_module->field_defs[$field->field];
             if ($data['type'] == 'relate' && isset($data['id_name'])) {
                 $field->field = $data['id_name'];
                 $data_new = $field_module->field_defs[$field->field];
                 if (isset($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($field_module->module_dir, $data['relationship'])]();
                 $table_alias = $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;
                 $field->field = 'id';
             }
             if ($data['type'] == 'currency' && isset($field_module->field_defs['currency_id'])) {
                 if (isset($field_module->field_defs['currency_id']['source']) && $field_module->field_defs['currency_id']['source'] == 'custom_fields') {
                     $query['select'][$table_alias . '_currency_id'] = $this->db->quoteIdentifier($table_alias . '_cstm') . ".currency_id AS '" . $table_alias . "_currency_id'";
                     $query['second_group_by'][] = $this->db->quoteIdentifier($table_alias . '_cstm') . ".currency_id";
                 } else {
                     $query['select'][$table_alias . '_currency_id'] = $this->db->quoteIdentifier($table_alias) . ".currency_id AS '" . $table_alias . "_currency_id'";
                     $query['second_group_by'][] = $this->db->quoteIdentifier($table_alias) . ".currency_id";
                 }
             }
             if (isset($data['source']) && $data['source'] == 'custom_fields') {
                 $select_field = $this->db->quoteIdentifier($table_alias . '_cstm') . '.' . $field->field;
                 $query = $this->build_report_query_join($table_alias . '_cstm', $table_alias . '_cstm', $table_alias, $field_module, 'custom', $query);
             } else {
                 $select_field = $this->db->quoteIdentifier($table_alias) . '.' . $field->field;
             }
             if ($field->group_by == 1) {
                 $has_group_by = true;
                 $query['group_by'][] = $field->format ? str_replace('(%1)', '(' . $select_field . ')', preg_replace(array('/\\s+/', '/Y/', '/m/', '/d/'), array(', ', 'YEAR(%1)', 'MONTH(%1)', 'DAY(%1)'), trim(preg_replace('/[^Ymd]/', ' ', $field->format)))) : $select_field;
             } else {
                 $query['second_group_by'][] = $field->format ? str_replace('(%1)', '(' . $select_field . ')', preg_replace(array('/\\s+/', '/Y/', '/m/', '/d/'), array(', ', 'YEAR(%1)', 'MONTH(%1)', 'DAY(%1)'), trim(preg_replace('/[^Ymd]/', ' ', $field->format)))) : $select_field;
             }
             if ($field->field_function != null) {
                 $select_field = $field->field_function . '(' . $select_field . ')';
             }
             if ($field->sort_by != '') {
                 $query['sort_by'][] = $select_field . " " . $field->sort_by;
             }
             $query['select'][] = $select_field . " AS '" . $field->label . "'";
             if ($field->group_display == 1 && $group_value) {
                 $query['where'][] = $select_field . " = '" . $group_value . "' AND ";
             }
             ++$i;
         }
     }
     if ($has_group_by) {
         // add fields to the group by MS SQL Requirement
         foreach ($query['select_id'] as $s => $select) {
             $query['group_by'][] = $select['field'];
         }
     }
     $this->injectParentModuleIDField($module->table_name, $query);
     return $query;
 }
Exemplo n.º 8
0
 private function getFieldLines()
 {
     if (!$this->bean->id) {
         return array();
     }
     $sql = "SELECT id FROM aor_fields WHERE aor_report_id = '" . $this->bean->id . "' AND deleted = 0 ORDER BY field_order ASC";
     $result = $this->bean->db->query($sql);
     $fields = array();
     while ($row = $this->bean->db->fetchByAssoc($result)) {
         $field_name = new AOR_Field();
         $field_name->retrieve($row['id']);
         $field_name->module_path = implode(":", unserialize(base64_decode($field_name->module_path)));
         $arr = $field_name->toArray();
         $arr['field_type'] = $this->getDisplayForField($field_name->module_path, $field_name->field, $this->bean->report_module);
         $display = getDisplayForField($field_name->module_path, $field_name->field, $this->bean->report_module);
         $arr['module_path_display'] = $display['module'];
         $arr['field_label'] = $display['field'];
         $fields[] = $arr;
     }
     return $fields;
 }