Results 1 to 8 of 8

Thread: view.edit.php

  1. #1
    Iggby's Avatar
    Iggby is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    Huntingtonton Beach, Ca
    Posts
    101

    Default view.edit.php

    I am trying to get the related field to auto populate when creating the child relationship via the subpanel. I have read some relevant wiki items, and posts but still am having a bit of a problem.

    I want to create an opportunity by clicking the create button from the subpanel. This works fine. When I get the create form, I use the Full form and one of the fields is a relate field to show the relationship between the contact and the opportunity. Mind you all of this works perfectly. The part I am having a problem with is that the field does not auto populate with the contact name or contact id as I would expect. I am trying to get a similar result to creating a direct report from the contacts module.

    To accomplish this I have made the following change to the /modules/Conatcts/view/view.edit.php file:

    PHP Code:
                   if ( !empty($_REQUEST['contact_name']) && !empty($_REQUEST['contact_id'])
                && 
    $this->ev->fieldDefs['contact_c']['value'] == ''
                
    && $this->ev->fieldDefs['contact_id_c']['value'] == '') {
                
    $this->ev->fieldDefs['contact_c']['value'] = $_REQUEST['contact_name'];
                
    $this->ev->fieldDefs['contact_id_c']['value'] = $_REQUEST['contact_id'];
            } 
    Where contact_c and contact_id_c are the related fields in the opportunity table.

    The entire file looks like this:

    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    /*********************************************************************************
     * SugarCRM is a customer relationship management program developed by
     * SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
     *
     * This program is free software; you can redistribute it and/or modify it under
     * the terms of the GNU General Public License version 3 as published by the
     * Free Software Foundation with the addition of the following permission added
     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
     * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
     *
     * 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 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.
     *
     * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
     * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
     *
     * The interactive user interfaces in modified source and object code versions
     * of this program must display Appropriate Legal Notices, as required under
     * Section 5 of the GNU General Public License version 3.
     *
     * In accordance with Section 7(b) of the GNU General Public License version 3,
     * these Appropriate Legal Notices must retain the display of the "Powered by
     * SugarCRM" logo. If the display of the logo is not reasonably feasible for
     * technical reasons, the Appropriate Legal Notices must display the words
     * "Powered by SugarCRM".
     ********************************************************************************/
    /*********************************************************************************

     * Description: This file is used to override the default Meta-data EditView behavior
     * to provide customization specific to the Contacts module.
     * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
     * All Rights Reserved.
     * Contributor(s): ______________________________________..
     ********************************************************************************/

    require_once('include/json_config.php');
    require_once(
    'include/MVC/View/views/view.edit.php');

    class 
    OpportunitiesViewEdit extends ViewEdit {


            function 
    OpportunitiesViewEdit(){
                    
    parent::ViewEdit();
                    
    $this->useForSubpanel true;
            }

            
    /**
             * display
             *
             * We are overridding the display method to manipulate the sectionPanels.
             * If portal is not enabled then don't show the Portal Information panel.
             */
            
    function display() {
            
    $this->ev->process();
                    if ( !empty(
    $_REQUEST['contact_name']) && !empty($_REQUEST['contact_id'])
                && 
    $this->ev->fieldDefs['report_to_name']['value'] == ''
                
    && $this->ev->fieldDefs['reports_to_id']['value'] == '') {
                
    $this->ev->fieldDefs['report_to_name']['value'] = $_REQUEST['contact_name'];
                
    $this->ev->fieldDefs['reports_to_id']['value'] = $_REQUEST['contact_id'];
            }
                    if ( !empty(
    $_REQUEST['contact_name']) && !empty($_REQUEST['contact_id'])
                && 
    $this->ev->fieldDefs['contact_c']['value'] == ''
                
    && $this->ev->fieldDefs['contact_id_c']['value'] == '') {
                
    $this->ev->fieldDefs['contact_c']['value'] = $_REQUEST['contact_name'];
                
    $this->ev->fieldDefs['contact_id_c']['value'] = $_REQUEST['contact_id'];
            }        
            
    $admin = new Administration();
                    
    $admin->retrieveSettings();
                    if(empty(
    $admin->settings['portal_on']) || !$admin->settings['portal_on']) {
                       unset(
    $this->ev->sectionPanels[strtoupper('lbl_portal_information')]);
                    } else {
                       echo 
    '<script src="modules/Contacts/Contact.js"></script>';
                       echo 
    '<script language="javascript">addToValidateComparison(\'EditView\', \'portal_password\', \'varchar\', false, SUGAR.language.get(\'app_strings\', \'ERR_SQS_NO_MATCH_FIELD\') + SUGAR.language.get(\'Contacts\', \'LBL_PORTAL_PASSWORD\'), \'portal_password1\');</script>';
                    }

                    echo 
    $this->ev->display($this->showTitle);
            }
    }
    ?>
    I am not sure that this file should be in the contacts module or the opportunities module, but contacts seemed right based on the fact that thats how it worked for direct report.

    Any suggestions?

    BTW

    Fedora Core 6
    Sugar 5.0.0c

  2. #2
    dlorenzetti's Avatar
    dlorenzetti is offline Sugar Community Member
    Join Date
    Jan 2008
    Location
    São Paulo, Brasil
    Posts
    189

    Default Re: view.edit.php

    Hi Iggby,

    This code appers great, but it should be in Opportunities:

    modules/Opportunities/views/view.edit.php
    Diego Lorenzetti
    Lampada Global Services - Open Source Solutions
    Phone: +55 11 3237-3110
    Email: equipe@lampadaglobal.com
    Site: www.lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

  3. #3
    Iggby's Avatar
    Iggby is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    Huntingtonton Beach, Ca
    Posts
    101

    Default Re: view.edit.php

    Interesting result

    I moved my backup of the original view.edit.php file back in place in modules/Contacts/views

    I modified the code posted above for the Opportunities module and placed it in custom/modules/Opportunities/views the code is below:

    PHP Code:
    require_once('include/json_config.php');
    require_once(
    'include/MVC/View/views/view.edit.php');

    class 
    OpportunitiesViewEdit extends ViewEdit {


            function 
    OpportunitiesViewEdit(){
                    
    parent::ViewEdit();
                    
    $this->useForSubpanel true;
            }

            
    /**
             * display
             *
             * We are overridding the display method to manipulate the sectionPanels.
             */
            
    function display() {
            
    $this->ev->process();
       
                    if ( !empty(
    $_REQUEST['contact_name']) && !empty($_REQUEST['contact_id'])
                && 
    $this->ev->fieldDefs['contact_c']['value'] == ''
                
    && $this->ev->fieldDefs['contact_id_c']['value'] == '') {
                
    $this->ev->fieldDefs['contact_c']['value'] = $_REQUEST['contact_name'];
                
    $this->ev->fieldDefs['contact_id_c']['value'] = $_REQUEST['contact_id'];
            }        
     echo 
    $this->ev->display($this->showTitle);
     }

    It appears to be calling the code, because the first time I forgot echo $this->ev->display($this->showTitle); and it broke the display. Now it displays. But the field is still not populated.

    The wierd part is I also tried a direct report again and now it doesn't auto populate the parent either.

    Yes I did repair and rebuild after. Any suggestions why this would happen?

  4. #4
    frankext is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    43

    Default Re: view.edit.php

    Quote Originally Posted by Iggby
    Interesting result

    I moved my backup of the original view.edit.php file back in place in modules/Contacts/views

    I modified the code posted above for the Opportunities module and placed it in custom/modules/Opportunities/views the code is below:

    PHP Code:
    require_once('include/json_config.php');
    require_once(
    'include/MVC/View/views/view.edit.php');

    class 
    OpportunitiesViewEdit extends ViewEdit {


            function 
    OpportunitiesViewEdit(){
                    
    parent::ViewEdit();
                    
    $this->useForSubpanel true;
            }

            
    /**
             * display
             *
             * We are overridding the display method to manipulate the sectionPanels.
             */
            
    function display() {
            
    $this->ev->process();
       
                    if ( !empty(
    $_REQUEST['contact_name']) && !empty($_REQUEST['contact_id'])
                && 
    $this->ev->fieldDefs['contact_c']['value'] == ''
                
    && $this->ev->fieldDefs['contact_id_c']['value'] == '') {
                
    $this->ev->fieldDefs['contact_c']['value'] = $_REQUEST['contact_name'];
                
    $this->ev->fieldDefs['contact_id_c']['value'] = $_REQUEST['contact_id'];
            }        
     echo 
    $this->ev->display($this->showTitle);
     }

    It appears to be calling the code, because the first time I forgot echo $this->ev->display($this->showTitle); and it broke the display. Now it displays. But the field is still not populated.

    The wierd part is I also tried a direct report again and now it doesn't auto populate the parent either.

    Yes I did repair and rebuild after. Any suggestions why this would happen?
    Hi lggby,

    According to the wiki and my personal test, the code should be as follows, may you have a try:
    PHP Code:
    require_once('include/json_config.php');
    require_once(
    'include/MVC/View/views/view.edit.php');

    class 
    OpportunitiesViewEdit extends ViewEdit {


            function 
    OpportunitiesViewEdit(){
                    
    parent::ViewEdit();
                    
    $this->useForSubpanel true;
            }

            
    /**
             * display
             *
             * We are overridding the display method to manipulate the sectionPanels.
             */
            
    function display(){
        
    $this->ev->process();
        if (empty(
    $this->ev->focus->id) && ($_REQUEST['parent_type'] == 'Contacts'&& isset($_REQUEST['parent_name']) && isset($_REQUEST['parent_id']))) {
        
    $this->ev->fieldDefs['contact_c']['value'] = $_REQUEST['parent_name'];
        
    $this->ev->fieldDefs['contact_id_c']['value'] = $_REQUEST['parent_id'];
    }

     echo 
    $this->ev->display();
     }

    note: remain ['parent_name'] and ['parent_id']

    rgs
    frankext

  5. #5
    Iggby's Avatar
    Iggby is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    Huntingtonton Beach, Ca
    Posts
    101

    Default Re: view.edit.php

    Unfortunately that did not work.

    The reason I had made the changes to the suggested code from the wiki was because after some testing I found that the conditional if () statement was not being executed. I started playing around with the code and found that the if ( ) statement was not being executed. I then added print_r($_REQUEST) to the code and found that the variable in the statement were not in $_REQUEST. The only _id in the $_REQUEST is relate_id. Below is a portion of what is returned. In my testing, I can populate the relate_id, but have been unable to come up with a way to get the human readable name from that id to populate for obvious reasons...its not their.

    Array ( [module] => Opportunities [record] => [isDuplicate] => false [action] => EditView [return_module] => Contacts [return_action] => DetailView [return_id] => f3225a9a-f7bd-1941-249e-47a7f8de6c76 [contact_role] => [relate_to] => Contacts [relate_id] => f3225a9a-f7bd-1941-249e-47a7f8de6c76 [offset] => 0 [button] => Full Form [name] => [date_closed] => [assigned_user_name] => admin [assigned_user_id] => 1

    Any other suggestions? Since this works for you is there different data in your $_REQUEST output. What version are you using? Could the info being passed have been changed in a recent update?
    Development Setup
    Sugar 5.0.0c
    Fedora Core 7
    Plesk 8.3
    PHP 5.2.4-1.fc7
    MySQL 5.0.45.fc7

  6. #6
    frankext is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    43

    Default Re: view.edit.php

    Quote Originally Posted by Iggby
    Unfortunately that did not work.

    The reason I had made the changes to the suggested code from the wiki was because after some testing I found that the conditional if () statement was not being executed. I started playing around with the code and found that the if ( ) statement was not being executed. I then added print_r($_REQUEST) to the code and found that the variable in the statement were not in $_REQUEST. The only _id in the $_REQUEST is relate_id. Below is a portion of what is returned. In my testing, I can populate the relate_id, but have been unable to come up with a way to get the human readable name from that id to populate for obvious reasons...its not their.

    Array ( [module] => Opportunities [record] => [isDuplicate] => false [action] => EditView [return_module] => Contacts [return_action] => DetailView [return_id] => f3225a9a-f7bd-1941-249e-47a7f8de6c76 [contact_role] => [relate_to] => Contacts [relate_id] => f3225a9a-f7bd-1941-249e-47a7f8de6c76 [offset] => 0 [button] => Full Form [name] => [date_closed] => [assigned_user_name] => admin [assigned_user_id] => 1

    Any other suggestions? Since this works for you is there different data in your $_REQUEST output. What version are you using? Could the info being passed have been changed in a recent update?
    Hi,
    Mine is 5.0.0c, same as yours, I think.
    Could you post the other related code:
    vardefs.php, which is located in custom\Extension\modules\Contacts\Ext\Vardefs
    It should be caused by the [name] definition I suppose, for there is no [name] but just [first name] and [last name]
    in contacts table.

    frankext

  7. #7
    frankext is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    43

    Default Re: view.edit.php

    Quote Originally Posted by frankext
    Hi,
    Mine is 5.0.0c, same as yours, I think.
    Could you post the other related code:
    vardefs.php, which is located in custom\Extension\modules\Contacts\Ext\Vardefs
    It should be caused by the [name] definition I suppose, for there is no [name] but just [first name] and [last name]
    in contacts table.

    frankext
    Hi,
    You may right-click to view your page source code to check what exactly sent from your server, here's my case:
    ------------------
    <td valign="top" width='37.5%' class='tabEditViewDF' NOWRAP>
    <input type="text" name="account_c" class="sqsEnabled" tabindex="1" id="account_c" size="" value="IBM" title='' autocomplete="off" >
    <input type="hidden" name="account_id_c" id="account_id_c" value="893a54f1-98b3-cfae-8de6-48155af048f8">
    <input type="button" name="btn_account_c" tabindex="1" title="Select [Alt+T]" accessKey="T" class="button" value="Select" onclick='open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"Ed itView","field_to_name_array":{"id":"account_id_c" ,"name":"account_c"}}, "single", true);'>
    <input type="button" name="btn_clr_account_c" tabindex="1" title="Clear [Alt+C]" accessKey="C" class="button" onclick="this.form.account_c.value = ''; this.form.account_id_c.value = '';" value="Clear">
    </tr>
    </table>
    ------------------
    In your case, it should be something like
    "<input type="text" name="contact_c" class="sqsEnabled" tabindex="1" id="contact_c" size="" value="<YOUR PARENT CONTACT NAME>" title='' autocomplete="off" >",
    if not, which means no contact name sent from the server, so you cann't get the right visible name. Have to check related vardefs.

    Hope that helpful to you.

    rgs

    frankext

  8. #8
    Iggby's Avatar
    Iggby is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    Huntingtonton Beach, Ca
    Posts
    101

    Default Re: view.edit.php

    This is clearly the problem. The variables needed are not being passed. Problem is I am not familiar with how to get sugar to pass them.

    It seems that if you click the "create" button from a subpanel, at the very least the info from the record that you were in should be passed to the new record being created. That is not the case. Some info is passed and some is not.

    I have not figured out how to get more of the data passed to the new form. That would solve my problem, once the data is being passed getting into the proper places can be accomplished in a couple of ways.
    Development Setup
    Sugar 5.0.0c
    Fedora Core 7
    Plesk 8.3
    PHP 5.2.4-1.fc7
    MySQL 5.0.45.fc7

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •