CRM Open Source Business & Social CRM Software

Results 1 to 5 of 5

Thread: HOWTO: Hack - Relate to custom modules pre 5.1

  1. #1
    kenneth.thorman is offline Sugar Community Member
    Join Date
    Oct 2007
    Posts
    191

    Default HOWTO: Hack - Relate to custom modules pre 5.1

    You can only relate built in modules specified in a list (a dropdown list actually) but custom module is not in that list.

    This is a hack that allows you to relate to custom modules

    This code below is based on release 5.0.0e but I am sure that by pasting the lines in the correct location for any of the release 5 version that you will be able to get this to work. It is a bit ugly, by ugly I mean adding a non language line in the language files. But my goal was the fastest cheapest way to the goal.

    Change the file modules/ModuleBuilder/MB/MBLanguage.php the function save

    Code:
    		function save($key_name, $duplicate=false){
    			global $mod_strings;
    			$header = file_get_contents('modules/ModuleBuilder/MB/header.php');
    			$required = array(
    			'LBL_LIST_FORM_TITLE'=>$this->label . " " . $mod_strings['LBL_LIST'],
    			'LBL_MODULE_NAME'=>$this->label,
    			'LBL_MODULE_TITLE'=>$this->label,
    			//FOR GENERIC MENU
    			'LNK_NEW_RECORD'=>$mod_strings['LBL_CREATE'] ." ". $this->label,
    			'LNK_LIST'=>$this->label,
    			'LBL_SEARCH_FORM_TITLE'=>$mod_strings['LBL_SEARCH'] ." ". $this->label,	
    			'LBL_HISTORY_SUBPANEL_TITLE'=>$mod_strings['LBL_HISTORY'],
    			'LBL_ACTIVITIES_SUBPANEL_TITLE'=>$mod_strings['LBL_ACTIVITIES'],
    			'LBL_'.strtoupper($this->key_name).'_SUBPANEL_TITLE'=>$this->label,	
    			'LBL_NEW_FORM_TITLE' => $mod_strings['LBL_NEW'] ." ". $this->label,
    			);
    			$save_path = $this->path . '/language';
    			mkdir_recursive($save_path);
    			foreach($this->strings as $lang=>$values){
    				foreach($required as $k=>$v){
    					$values[$k] = $v;
    				}
    				write_array_to_file('mod_strings', $values, $save_path .'/'.$lang,'w', $header);
    			}
    			$app_save_path = $this->path . '/../../language/application';
    			mkdir_recursive($app_save_path);
    			$key_changed = ($this->key_name != $key_name);
    			
    			foreach($this->appListStrings as $lang=>$values){
    				if(!$duplicate){
    					unset($values['moduleList'][$this->key_name]);
    				}
    				$values['moduleList'][$key_name]= $this->label;
    				$appFile = $header. "\n";
    				foreach($values as $key=>$array){
    					if($key == 'moduleList'){
    						foreach($array as $k=>$v){
    							
    							$appFile .= '$app_list_strings["moduleList"]["'. $k .'"] = ' . var_export_helper($v) . ";\n";
    						}
    					}else{
    						if($duplicate){
    							//keep the original when duplicating
    							$appFile .= '$app_list_strings["'. $key .'"] = ' . var_export_helper($array) . ";\n";
    						}
    						$okey = $key;
    						if($key_changed)$key = str_replace($this->key_name, $key_name, $key);
    						if($key_changed)$key = str_replace(strtolower($this->key_name), strtolower($key_name), $key);
    						// if we aren't duplicating or the key has changed let's add it
    						if(!$duplicate || $okey != $key){
    							$appFile .= '$app_list_strings["'. $key .'"] = ' . var_export_helper($array) . ";\n";
    						}
    					}
    				}
                   
                                    $fp = fopen($app_save_path . '/'. $lang, 'w');
    				fwrite($fp, $appFile);
    				fclose($fp);
    			}
    		}

    to this

    Code:
    		function save($key_name, $duplicate=false){
    			global $mod_strings;
    			$header = file_get_contents('modules/ModuleBuilder/MB/header.php');
    			$required = array(
    			'LBL_LIST_FORM_TITLE'=>$this->label . " " . $mod_strings['LBL_LIST'],
    			'LBL_MODULE_NAME'=>$this->label,
    			'LBL_MODULE_TITLE'=>$this->label,
    			//FOR GENERIC MENU
    			'LNK_NEW_RECORD'=>$mod_strings['LBL_CREATE'] ." ". $this->label,
    			'LNK_LIST'=>$this->label,
    			'LBL_SEARCH_FORM_TITLE'=>$mod_strings['LBL_SEARCH'] ." ". $this->label,	
    			'LBL_HISTORY_SUBPANEL_TITLE'=>$mod_strings['LBL_HISTORY'],
    			'LBL_ACTIVITIES_SUBPANEL_TITLE'=>$mod_strings['LBL_ACTIVITIES'],
    			'LBL_'.strtoupper($this->key_name).'_SUBPANEL_TITLE'=>$this->label,	
    			'LBL_NEW_FORM_TITLE' => $mod_strings['LBL_NEW'] ." ". $this->label,
    			);
    			$save_path = $this->path . '/language';
    			mkdir_recursive($save_path);
    			foreach($this->strings as $lang=>$values){
    				foreach($required as $k=>$v){
    					$values[$k] = $v;
    				}
    				write_array_to_file('mod_strings', $values, $save_path .'/'.$lang,'w', $header);
    			}
    			$app_save_path = $this->path . '/../../language/application';
    			mkdir_recursive($app_save_path);
    			$key_changed = ($this->key_name != $key_name);
    			
    			foreach($this->appListStrings as $lang=>$values){
    				if(!$duplicate){
    					unset($values['moduleList'][$this->key_name]);
    				}
    				$values['moduleList'][$key_name]= $this->label;
    				$appFile = $header. "\n";
    				foreach($values as $key=>$array){
    					if($key == 'moduleList'){
    						foreach($array as $k=>$v){
    							
    							$appFile .= '$app_list_strings["moduleList"]["'. $k .'"] = ' . var_export_helper($v) . ";\n";
    						}
    					}else{
    						if($duplicate){
    							//keep the original when duplicating
    							$appFile .= '$app_list_strings["'. $key .'"] = ' . var_export_helper($array) . ";\n";
    						}
    						$okey = $key;
    						if($key_changed)$key = str_replace($this->key_name, $key_name, $key);
    						if($key_changed)$key = str_replace(strtolower($this->key_name), strtolower($key_name), $key);
    						// if we aren't duplicating or the key has changed let's add it
    						if(!$duplicate || $okey != $key){
    							$appFile .= '$app_list_strings["'. $key .'"] = ' . var_export_helper($array) . ";\n";
    						}
    					}
    				}
    			
                    // Hack by Kenneth Thorman to allow relate to custom modules
    				$appFile .= 'if (!empty($GLOBALS["app_list_strings"]["record_type_display"])) {$GLOBALS["app_list_strings"]["record_type_display"]=array_unique(array_merge($GLOBALS["app_list_strings"]["record_type_display"], array("' . $key_name . '"=>"' . $key_name . '")));}';
                    // Hack by Kenneth Thorman to allow relate to custom modules
                    
                    $fp = fopen($app_save_path . '/'. $lang, 'w');
    				fwrite($fp, $appFile);
    				fclose($fp);
    			}
    		}

    The lines added are

    // Hack by Kenneth Thorman to allow relate to custom modules
    $appFile .= 'if (!empty($GLOBALS["app_list_strings"]["record_type_display"])) {$GLOBALS["app_list_strings"]["record_type_display"]=array_unique(array_merge($GLOBALS["app_list_strings"]["record_type_display"], array("' . $key_name . '"=>"' . $key_name . '")));}';
    // Hack by Kenneth Thorman to allow relate to custom modules


    This works as soon as you create a new module.
    You can also relate to self.


    Regards
    Kenneth Thorman
    Last edited by kenneth.thorman; 2008-07-03 at 01:14 PM.

  2. #2
    kenneth.thorman is offline Sugar Community Member
    Join Date
    Oct 2007
    Posts
    191

    Default Re: HOWTO: Hack - Relate to custom modules pre 5.1

    This can be found as part of a installable module here

    https://sourceforge.net/project/show...roup_id=210096

    both for version 5.0.0e and 5.0.0f

    PLEASE NOTE: there are multiple patches to sugar in this module:


    Multienum search revisited
    SugarCrm 5.0 CE Scheduler not working
    "Create new" - security right
    Subpanel: Create new AJAX without hidding existing rows
    Module Builder - one-to-many relationships in subpanel
    as well as this thread (HOWTO: Hack - Relate to custom modules pre 5.1)

    Please test properly before installing, use at your own risc, no responsibilities assumed yada yada ...

    Regards
    Kenneth Thorman

  3. #3
    jepoytan is offline Junior Member
    Join Date
    Jan 2011
    Posts
    6

    Default Re: HOWTO: Hack - Relate to custom modules pre 5.1

    Hi,

    I also have the same problem. Is this solution still applicable in Version 6.0.1 (Community Edition)?

    Thanks!

  4. #4
    Rochelle123 is offline Junior Member
    Join Date
    Jan 2011
    Posts
    2

    Default Re: HOWTO: Hack - Relate to custom modules pre 5.1

    Quote Originally Posted by jepoytan View Post
    Hi,

    I also have the same problem. Is this solution still applicable in Version 6.0.1 (Community Edition)?

    Thanks!


  5. #5
    kenneth.thorman is offline Sugar Community Member
    Join Date
    Oct 2007
    Posts
    191

    Default Re: HOWTO: Hack - Relate to custom modules pre 5.1

    Hi

    There are 2 ways to make relates in SugarCrm.

    One is a relate (the one you are mentioning, and the other is a one-many relationship.
    In the database these are represented in 2 different ways.

    relate is a true: RDBMS one-many
    one.many : is a many-many restricted to have only one relationship.

    If you can live with the latter then you can see my blog posting at http://kenneththorman.blogspot.com/2...bpanel-at.html.

    I have not been following the development of the latest releases of SugarCrm so I would not know if the hack works anymore. The only way for sure is to try it out I guess.

    Regards
    Kenneth Thorman

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 2009-07-06, 03:25 PM
  2. Does relate feild contains custom modules
    By Mubi in forum Developer Help
    Replies: 2
    Last Post: 2008-07-03, 01:03 PM
  3. upgraded to 4.5.1e, received "Metadata for table tracker does not exist"
    By sfgeorge in forum Installation and Upgrade Help
    Replies: 0
    Last Post: 2007-09-03, 03:24 PM
  4. Asterisk Patch 1.1.0 Crash on logon
    By skyracer in forum Help
    Replies: 6
    Last Post: 2006-07-08, 07:30 AM
  5. Replies: 7
    Last Post: 2006-06-06, 08:56 PM

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
  •