Example #1
0
/**
 * Create merge query depending on the modules being merged
 * @param SugarBean $seed Object being queried
 * @param string $merge_module Module being merged
 * @param string $key ID of the record in module being merged
 */
function get_merge_query($seed, $merge_module, $key)
{
    $selQuery = array('Contacts' => array('Accounts' => 'SELECT contacts.first_name, contacts.last_name, contacts.id, contacts.date_entered FROM contacts LEFT JOIN accounts_contacts ON contacts.id=accounts_contacts.contact_id AND (accounts_contacts.deleted is NULL or accounts_contacts.deleted=0)', 'Opportunities' => 'SELECT contacts.first_name, contacts.last_name, contacts.id, contacts.date_entered FROM contacts LEFT JOIN opportunities_contacts ON contacts.id=opportunities_contacts.contact_id AND (opportunities_contacts.deleted is NULL or opportunities_contacts.deleted=0)', 'Cases' => 'SELECT contacts.first_name, contacts.last_name, contacts.id, contacts.date_entered FROM contacts LEFT JOIN contacts_cases ON contacts.id=contacts_cases.contact_id AND (contacts_cases.deleted is NULL or contacts_cases.deleted=0)', 'Bugs' => 'SELECT contacts.first_name, contacts.last_name, contacts.id, contacts.date_entered FROM contacts LEFT JOIN contacts_bugs ON contacts.id=contacts_bugs.contact_id AND (contacts_bugs.deleted is NULL or contacts_bugs.deleted=0)', 'Quotes' => 'SELECT contacts.first_name, contacts.last_name, contacts.id, contacts.date_entered FROM contacts LEFT JOIN quotes_contacts ON contacts.id=quotes_contacts.contact_id AND (quotes_contacts.deleted is NULL or quotes_contacts.deleted=0)'), 'Opportunities' => array("Accounts" => 'SELECT opportunities.id, opportunities.name FROM opportunities LEFT JOIN accounts_opportunities ON opportunities.id = accounts_opportunities.opportunity_id AND (accounts_opportunities.deleted is NULL or accounts_opportunities.deleted=0)'), 'Accounts' => array("Opportunities" => 'SELECT accounts.id, accounts.name FROM accounts LEFT JOIN accounts_opportunities ON accounts.id = accounts_opportunities.account_id AND (accounts_opportunities.deleted is NULL or accounts_opportunities.deleted=0)'));
    $whereQuery = array('Contacts' => array('Accounts' => 'accounts_contacts.contact_id = contacts.id AND accounts_contacts.account_id = ', 'Opportunities' => 'opportunities_contacts.contact_id = contacts.id AND opportunities_contacts.opportunity_id = ', 'Cases' => 'contacts_cases.contact_id = contacts.id AND contacts_cases.case_id = ', 'Bugs' => 'contacts_bugs.contact_id = contacts.id AND contacts_bugs.bug_id = ', 'Quotes' => 'quotes_contacts.contact_id = contacts.id AND quotes_contacts.quote_id = '), 'Opportunities' => array('Accounts' => 'accounts_opportunities.opportunity_id = opportunities.id AND accounts_opportunities.account_id = '), 'Accounts' => array('Opportunities' => 'accounts_opportunities.account_id = accounts.id  AND accounts_opportunities.opportunity_id = '));
    $relModule = $seed->module_dir;
    $select = "";
    if (!empty($selQuery[$relModule][$merge_module])) {
        $select = $selQuery[$relModule][$merge_module];
    } else {
        $lowerRelModule = strtolower($relModule);
        if ($seed->load_relationship($lowerRelModule)) {
            $params = array('join_table_alias' => 'r1', 'join_table_link_alias' => 'r2', 'join_type' => 'LEFT JOIN');
            $join = $seed->{$lowerRelModule}->getJoin($params);
            $select = "SELECT {$seed->table_name}.* FROM {$seed->table_name} {$join}";
        }
    }
    if (empty($select)) {
        $select = "SELECT contacts.first_name, contacts.last_name, contacts.id, contacts.date_entered FROM contacts";
    }
    if (empty($whereQuery[$relModule][$merge_module])) {
        $select .= " WHERE {$seed->table_name}.id = '{$seed->db->quote($key)}'";
    } else {
        $select .= " WHERE " . $whereQuery[$relModule][$merge_module] . "'{$seed->db->quote($key)}'";
    }
    $select .= " ORDER BY {$seed->table_name}.date_entered";
    return $select;
}
 /**
  * Determines if a portal user "owns" a record
  * @param SugarBean $bean
  */
 protected function isPortalOwner(SugarBean $bean)
 {
     if (empty($bean->id) || $bean->new_with_id) {
         // New record, they are the owner.
         $bean->portal_owner = true;
     }
     // Cache portal owner on bean so that we aren't loading Contacts for each ACL check
     // Performance Bug58133
     if (!isset($bean->portal_owner)) {
         switch ($bean->module_dir) {
             case 'Contacts':
                 $bean->portal_owner = $bean->id == $_SESSION['contact_id'];
                 break;
                 // Cases & Bugs work the same way, so handily enough we can share the code.
             // Cases & Bugs work the same way, so handily enough we can share the code.
             case 'Cases':
             case 'Bugs':
                 $bean->load_relationship('contacts');
                 $rows = $bean->contacts->query(array('where' => array('lhs_field' => 'id', 'operator' => '=', 'rhs_value' => $GLOBALS['db']->quote($_SESSION['contact_id']))));
                 $bean->portal_owner = count($rows) > 0;
                 break;
             default:
                 // Unless we know how to find the "owner", they can't own it.
                 $bean->portal_owner = false;
         }
     }
     return $bean->portal_owner;
 }
Example #3
0
function get_message_scope_dom($campaign_id, $campaign_name, $db = null, $mod_strings = array())
{
    //find prospect list attached to this campaign..
    $query = "SELECT prospect_list_id, prospect_lists.name ";
    $query .= "FROM prospect_list_campaigns ";
    $query .= "INNER join prospect_lists on prospect_lists.id = prospect_list_campaigns.prospect_list_id ";
    // We need to confirm that the user is a member of the team of the item.
    $bean = new SugarBean();
    $bean->disable_row_level_security = false;
    $bean->add_team_security_where_clause($query, "prospect_lists");
    $query .= "WHERE prospect_lists.deleted = 0 ";
    $query .= "AND prospect_list_campaigns.deleted=0 ";
    $query .= "AND campaign_id='" . $campaign_id . "'";
    $query .= " and prospect_lists.list_type not like 'exempt%'";
    if (empty($db)) {
        $db = DBManagerFactory::getInstance();
    }
    if (empty($mod_strings) or !isset($mod_strings['LBL_DEFAULT'])) {
        global $current_language;
        $mod_strings = return_module_language($current_language, 'Campaigns');
    }
    //add campaign to the result array.
    //$return_array[$campaign_id]= $campaign_name . ' (' . $mod_strings['LBL_DEFAULT'] . ')';
    $result = $db->query($query);
    while (($row = $db->fetchByAssoc($result)) != null) {
        $return_array[$row['prospect_list_id']] = $row['name'];
    }
    if (empty($return_array)) {
        $return_array = array();
    } else {
        return $return_array;
    }
}
/**
 * @param SugarBean $bean
 * @param string $user_id
 * @param string $where
 *
 * @return array
 */
function build_related_list_by_user_id($bean, $user_id, $where)
{
    $bean_id_name = strtolower($bean->object_name) . '_id';
    $select = "SELECT {$bean->table_name}.* from {$bean->rel_users_table},{$bean->table_name} ";
    $auto_where = ' WHERE ';
    if (!empty($where)) {
        $auto_where .= $where . ' AND ';
    }
    $auto_where .= " {$bean->rel_users_table}.{$bean_id_name}={$bean->table_name}.id AND {$bean->rel_users_table}.user_id='{$user_id}' AND {$bean->table_name}.deleted=0 AND {$bean->rel_users_table}.deleted=0";
    $query = $select . $auto_where;
    $result = $bean->db->query($query, true);
    $list = [];
    while ($row = $bean->db->fetchByAssoc($result)) {
        $row = $bean->convertRow($row);
        $bean->fetched_row = $row;
        $bean->fromArray($row);
        $bean->processed_dates_times = [];
        $bean->check_date_relationships_load();
        $bean->fill_in_additional_detail_fields();
        /**
         * PHP  5+ always treats objects as passed by reference
         * Need to clone it if we're using 5.0+
         * clone() not supported by 4.x
         */
        if (version_compare(phpversion(), "5.0", ">=")) {
            $newBean = clone $bean;
        } else {
            $newBean = $bean;
        }
        $list[] = $newBean;
    }
    return $list;
}
 public function testGetUnionRelatedList()
 {
     $subpanel = array('order' => 20, 'sort_order' => 'desc', 'sort_by' => 'date_entered', 'type' => 'collection', 'subpanel_name' => 'history', 'top_buttons' => array(), 'collection_list' => array('meetings' => array('module' => 'Meetings', 'subpanel_name' => 'ForHistory', 'get_subpanel_data' => 'meetings'), 'emails' => array('module' => 'Emails', 'subpanel_name' => 'ForHistory', 'get_subpanel_data' => 'emails', 'get_distinct_data' => true), 'linkedemails_contacts' => array('module' => 'Emails', 'subpanel_name' => 'ForHistory', 'generate_select' => true, 'get_distinct_data' => true, 'get_subpanel_data' => 'function:GetUnionRelatedTest_get_select', 'function_parameters' => array('import_function_file' => __FILE__))));
     $subpanel_def = new aSubPanel("testpanel", $subpanel, $this->bean);
     $query = $this->bean->get_union_related_list($this->bean, "", '', "", 0, 5, -1, 0, $subpanel_def);
     $result = $this->bean->db->query($query["query"]);
     $this->assertNotEmpty($result, "Bad query: {$query["query"]}");
 }
Example #6
0
 /**
  * Test asserts that fetched row has more priority then property
  *
  * @group 60442
  * @return void
  */
 public function testIsOwner()
 {
     $bean = new SugarBean();
     $bean->id = create_guid();
     $bean->fetched_row['assigned_user_id'] = 1;
     $bean->assigned_user_id = 2;
     $this->assertTrue($bean->isOwner(1), 'Incorrect ownership');
 }
 /**
  * @param SugarBean $lhs              SugarBean left side bean to add to the relationship.
  * @param SugarBean $rhs              SugarBean right side bean to add to the relationship.
  * @param array     $additionalFields key=>value pairs of fields to save on the relationship
  *
  * @return bool true if successful
  */
 public function add($lhs, $rhs, $additionalFields = [])
 {
     $lhsLinkName = $this->lhsLink;
     //In a one to one, any existing links from both sides must be removed first.
     //one2Many will take care of the right side, so we'll do the left.
     $lhs->load_relationship($lhsLinkName);
     $this->removeAll($lhs->{$lhsLinkName});
     return parent::add($lhs, $rhs, $additionalFields);
 }
Example #8
0
 /**
  * Test tries to emulate changing of related field and assert correct result
  *
  * @group 44930
  * @return void
  */
 public function testChangingOfRelation()
 {
     $_REQUEST['relate_id'] = '2';
     $_REQUEST['relate_to'] = 'test';
     $bean = new SugarBean();
     $bean->id = '1';
     $bean->test_id = '3';
     $bean->field_defs = array('test' => array('type' => 'link', 'relationship' => 'test', 'link_file' => 'data/SugarBean.php', 'link_class' => 'Link44930'));
     $bean->relationship_fields = array('test_id' => 'test');
     $bean->save_relationship_changes(true);
     $this->assertEquals($bean->test_id, $bean->test->lastCall, 'Last relation should point to test_id instead of relate_id');
 }
 /**
  * Track a view for a particular bean.
  *
  * @param SugarBean $seed
  * @param string $current_view
  */
 function trackView($seed, $current_view)
 {
     $trackerManager = TrackerManager::getInstance();
     if ($monitor = $trackerManager->getMonitor('tracker')) {
         $monitor->setValue('date_modified', TimeDate::getInstance()->nowDb());
         $monitor->setValue('user_id', $GLOBALS['current_user']->id);
         $monitor->setValue('module_name', $seed->module_dir);
         $monitor->setValue('action', $current_view);
         $monitor->setValue('item_id', $seed->id);
         $monitor->setValue('item_summary', $seed->get_summary_text());
         $monitor->setValue('visible', true);
         $trackerManager->saveMonitor($monitor, TRUE, TRUE);
     }
 }
Example #10
0
 /**
  * {@inheritDoc}
  */
 public function apiFormatField(array &$data, SugarBean $bean, array $args, $fieldName, $properties, array $fieldList = null, ServiceBase $service = null)
 {
     $this->ensureApiFormatFieldArguments($fieldList, $service);
     // this is only for generated links
     if (isset($bean->field_defs[$fieldName]['gen']) && isTruthy($bean->field_defs[$fieldName]['gen'])) {
         $subject = $bean->field_defs[$fieldName]['default'];
         if (!empty($subject)) {
             $data[$fieldName] = replace_sugar_vars($subject, $bean->toArray(), true);
         } else {
             $data[$fieldName] = "";
         }
     } else {
         parent::apiFormatField($data, $bean, $args, $fieldName, $properties, $fieldList, $service);
     }
 }
 function __construct()
 {
     parent::__construct();
     $this->db = DBManagerFactory::getInstance();
     $this->dbManager = DBManagerFactory::getInstance();
     $this->disable_row_level_security = true;
 }
Example #12
0
 public function __construct()
 {
     parent::__construct();
     $this->team_id = 1;
     // make the item globally accessible
     $this->disable_row_level_security = true;
 }
Example #13
0
 function create_tables()
 {
     global $current_language;
     $mod_strings = return_module_language($current_language, 'Teams');
     parent::create_tables();
     Team::create_team("Global", $mod_strings['LBL_GLOBAL_TEAM_DESC'], $this->global_team);
 }
Example #14
0
 function save($check_notify = false)
 {
     global $sugar_config;
     if (!empty($_FILES['image_file'])) {
         if ($_FILES['image_file']['error'] == 0) {
             $file_name = $_FILES['image_file']['name'];
             $tmp_name = $_FILES['image_file']['tmp_name'];
             $ext = explode('.', $file_name);
             $img_ext = $ext[count($ext) - 1];
             $img_valid = false;
             $image_extension = 'jpg_jpeg_gif_bmp_png';
             $image_extension_arr = explode('_', $image_extension);
             for ($i = 0; $i < count($image_extension_arr); $i++) {
                 if ($img_ext != $image_extension_arr[$i]) {
                     $img_valid = true;
                 }
             }
             if ($img_valid == false) {
                 echo "<script language='javascript'> alert('file ảnh không hợp lệ'); </script>";
                 return;
             }
             if (is_file('modules/images/' . $this->image)) {
                 @unlink('modules/images/' . $this->image);
             }
             $destination = 'modules/images/' . $file_name;
             if (move_uploaded_file($tmp_name, $destination)) {
                 $this->picture = "<img src='" . $sugar_config['site_url'] . "/modules/images/" . $file_name . "' width='350' height='200'/>";
                 $this->image = $file_name;
             }
         }
     }
     return parent::save($check_notify);
 }
 function save($check_notify = false)
 {
     parent::save($check_notify);
     //update documents table.
     //$query = "UPDATE documents set document_version_id='$this->id' where id = '$this->document_id'";
     //$this->db->query($query);
 }
Example #16
0
 function save($check_notify = false)
 {
     if (!empty($this->number)) {
         $this->name = $this->number;
     }
     return parent::save($check_notify);
 }
Example #17
0
 /**
  * This function is used to popluate an fields on the relationship from the request
  *
  * @param $api ServiceBase The API class of the request, used in cases where the API changes how security is applied
  * @param $args array The arguments array passed in from the API
  * @param $primaryBean SugarBean The near side of the link
  * @param $linkName string What is the name of the link field that you want to get the related fields for
  *
  * @return array A list of the related fields pulled out of the $args array
  */
 protected function getRelatedFields(ServiceBase $api, $args, SugarBean $primaryBean, $linkName, $seed = null)
 {
     $relatedData = array();
     if (!empty($primaryBean->{$linkName}) || $primaryBean->load_relationship($linkName)) {
         $otherLink = $primaryBean->{$linkName}->getLinkForOtherSide();
         if ($seed instanceof SugarBean) {
             foreach ($args as $field => $value) {
                 if (empty($seed->field_defs[$field]['rname_link']) || empty($seed->field_defs[$field]['link']) || $seed->field_defs[$field]['link'] != $otherLink) {
                     continue;
                 }
                 $relatedData[$seed->field_defs[$field]['rname_link']] = $value;
             }
         }
     }
     return $relatedData;
 }
 /**
  * @param SugarBean $lhs
  * @param SugarBean $rhs
  *
  * @return bool
  */
 public function remove($lhs, $rhs)
 {
     $lhsLinkName = $this->lhsLink;
     if (!$lhs instanceof SugarBean) {
         Log::fatal("LHS is not a SugarBean object");
         return false;
     }
     if (!$rhs instanceof SugarBean) {
         Log::fatal("RHS is not a SugarBean object");
         return false;
     }
     if (empty($lhs->{$lhsLinkName}) && !$lhs->load_relationship($lhsLinkName)) {
         Log::fatal("could not load LHS {$lhsLinkName}");
         return false;
     }
     if (empty($_SESSION['disable_workflow']) || $_SESSION['disable_workflow'] != "Yes") {
         if (!empty($lhs->{$lhsLinkName})) {
             $lhs->{$lhsLinkName}->load();
             $this->callBeforeDelete($lhs, $rhs, $lhsLinkName);
         }
     }
     $dataToRemove = [$this->def['join_key_lhs'] => $lhs->id, $this->def['join_key_rhs'] => $rhs->id];
     $this->removeRow($dataToRemove);
     if ($this->self_referencing) {
         $this->removeSelfReferencing($lhs, $rhs);
     }
     if (empty($_SESSION['disable_workflow']) || $_SESSION['disable_workflow'] != "Yes") {
         if (!empty($lhs->{$lhsLinkName})) {
             $lhs->{$lhsLinkName}->load();
             $this->callAfterDelete($lhs, $rhs, $lhsLinkName);
         }
     }
     return true;
 }
 function get_list_view_data()
 {
     $data = parent::get_list_view_data();
     $data['LABEL'] = translate($this->label, $this->custom_module);
     $data['NAMELINK'] = '<a href="index.php?module=Studio&action=wizard&wizard=EditCustomFieldsWizard&option=EditCustomField&record=' . $this->id . '" class="listViewTdLinkS1">';
     return $data;
 }
Example #20
0
 /**
  * Save changes that have been made to a relationship.
  *
  * @param $is_update true if this save is an update.
  */
 function save_relationship_changes($is_update, $exclude = array())
 {
     parent::save_relationship_changes($is_update, $exclude);
     $new_rel_id = false;
     $new_rel_link = false;
     //this allows us to dynamically relate modules without adding it to the relationship_fields array
     if (!empty($_REQUEST['relate_id']) && !in_array($_REQUEST['relate_to'], $exclude) && $_REQUEST['relate_id'] != $this->id) {
         $new_rel_id = $_REQUEST['relate_id'];
         $new_rel_relname = $_REQUEST['relate_to'];
         if (!empty($this->in_workflow) && !empty($this->not_use_rel_in_req)) {
             $new_rel_id = $this->new_rel_id;
             $new_rel_relname = $this->new_rel_relname;
         }
         $new_rel_link = $new_rel_relname;
         //Try to find the link in this bean based on the relationship
         foreach ($this->field_defs as $key => $def) {
             if (isset($def['type']) && $def['type'] == 'link' && isset($def['relationship']) && $def['relationship'] == $new_rel_relname) {
                 $new_rel_link = $key;
             }
         }
         if ($new_rel_link == 'contacts') {
             $accountId = $this->db->getOne('SELECT account_id FROM accounts_contacts WHERE contact_id=' . $this->db->quoted($new_rel_id));
             if ($accountId !== false) {
                 if ($this->load_relationship('accounts')) {
                     $this->accounts->add($accountId);
                 }
             }
         }
     }
 }
Example #21
0
 /**
  * Create a from statement
  *
  * @param SugarBean|array $bean
  * @return string
  */
 protected function compileFrom($bean)
 {
     $alias = "";
     $return = array();
     if (is_array($bean)) {
         list($bean, $alias) = $bean;
         $this->from_alias = $alias;
     }
     $this->from_bean = $bean;
     $table = $bean->getTableName();
     $table_cstm = '';
     $from_clause = "{$table}";
     if (!empty($alias)) {
         $from_clause .= " {$alias}";
     }
     //SugarQuery will determine if we actually need to add the table or not.
     $this->sugar_query->joinCustomTable($bean, $alias);
     if (!empty($this->from_alias)) {
         $this->primary_table = $this->from_alias;
         $this->primary_custom_table = $this->from_alias . '_c';
     } else {
         $this->primary_table = $this->from_bean->getTableName();
         $this->primary_custom_table = $this->from_bean->get_custom_table_name();
     }
     $return = $from_clause;
     return $return;
 }
Example #22
0
 function Worksheets()
 {
     $this->worksheet_tour_id = $id;
     global $sugar_config;
     $noidung = new stdClass();
     parent::SugarBean();
 }
Example #23
0
 function get_list_view_data()
 {
     $data = parent::get_list_view_data();
     $data['VNAME'] = translate($this->vname, $this->custom_module);
     $data['NAMELINK'] = '<input class="checkbox" type="checkbox" name="remove[]" value="' . $this->id . '">&nbsp;&nbsp;<a href="index.php?module=Studio&action=wizard&wizard=EditCustomFieldsWizard&option=EditCustomField&record=' . $this->id . '" >';
     return $data;
 }
Example #24
0
 function UserSignature()
 {
     //Ensure the vardefs get loaded.
     global $dictionary;
     require_once "metadata/users_signaturesMetaData.php";
     parent::SugarBean();
 }
Example #25
0
 function save($id = '', $module = '', $new_addrs = array(), $primary = '', $replyTo = '', $invalid = '', $optOut = '', $in_workflow = false)
 {
     if (func_num_args() > 1) {
         parent::save($id, $module, $new_addrs, $primary, $replyTo, $invalid, $optOut, $in_workflow);
     } else {
         SugarBean::save($id);
     }
 }
Example #26
0
 /**
  * Fetches data from the $args array and updates the bean with that data
  * @param $bean SugarBean The bean to be updated
  * @param $api ServiceBase The API class of the request, used in cases where the API changes how the fields are pulled from the args array.
  * @param $args array The arguments array passed in from the API
  * @return id Bean id
  */
 protected function updateBean(SugarBean $bean, ServiceBase $api, $args)
 {
     // Bug 54515: Set modified by and created by users to assigned to user. If not set default to admin.
     $bean->update_modified_by = false;
     $bean->set_created_by = false;
     $admin = Administration::getSettings();
     if (isset($admin->settings['supportPortal_RegCreatedBy']) && !empty($admin->settings['supportPortal_RegCreatedBy'])) {
         $bean->created_by = $admin->settings['supportPortal_RegCreatedBy'];
         $bean->modified_user_id = $admin->settings['supportPortal_RegCreatedBy'];
     } else {
         $bean->created_by = '1';
         $bean->modified_user_id = '1';
     }
     // Bug 54516 users not getting notified on new record creation
     $bean->save(true);
     return parent::updateBean($bean, $api, $args);
 }
Example #27
0
 public function __construct($name, $vardefs)
 {
     global $dictionary;
     $this->object_name = $name;
     $this->table_name = $name;
     $dictionary[$this->object_name] = $vardefs;
     parent::SugarBean();
 }
Example #28
0
 public function __construct()
 {
     global $dictionary;
     if (isset($this->module_dir) && isset($this->object_name) && !isset($dictionary[$this->object_name])) {
         require SugarAutoLoader::existingCustomOne('metadata/workflow_schedulesMetaData.php');
     }
     parent::__construct();
 }
Example #29
0
 function get_full_list($order_by = "", $where = "")
 {
     $list = parent::get_full_list($order_by, $where);
     if (!empty($list)) {
         $list = SimpleTeams::filterBeanList($list);
     }
     return $list;
 }
Example #30
0
 function get_all($order_by = "", $where = "")
 {
     $list = parent::get_list($order_by, $where, 0, 1000, 1000, 0);
     $list = $list["list"];
     if (!empty($list)) {
         $list = SimpleTeams::filterBeanList($list);
     }
     return $list;
 }