]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/SubPanel/SubPanelDefinitions.php
Release 6.2.2
[Github/sugarcrm.git] / include / SubPanel / SubPanelDefinitions.php
1 <?php
2 if (! defined ( 'sugarEntry' ) || ! sugarEntry)
3         die ( 'Not A Valid Entry Point' ) ;
4 /*********************************************************************************
5  * SugarCRM Community Edition is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7  * 
8  * This program is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Affero General Public License version 3 as published by the
10  * Free Software Foundation with the addition of the following permission added
11  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14  * 
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
18  * details.
19  * 
20  * You should have received a copy of the GNU Affero General Public License along with
21  * this program; if not, see http://www.gnu.org/licenses or write to the Free
22  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23  * 02110-1301 USA.
24  * 
25  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27  * 
28  * The interactive user interfaces in modified source and object code versions
29  * of this program must display Appropriate Legal Notices, as required under
30  * Section 5 of the GNU Affero General Public License version 3.
31  * 
32  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33  * these Appropriate Legal Notices must retain the display of the "Powered by
34  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35  * technical reasons, the Appropriate Legal Notices must display the words
36  * "Powered by SugarCRM".
37  ********************************************************************************/
38
39
40
41
42
43 //input
44 //      module directory
45 //constructor
46 //      open the layout_definitions file.
47 //
48 class aSubPanel
49 {
50
51         var $name ;
52         var $_instance_properties ;
53
54         var $mod_strings ;
55         var $panel_definition ;
56         var $sub_subpanels ;
57         var $parent_bean ;
58
59         //module's table name and column fields.
60         var $table_name ;
61         var $db_fields ;
62         var $bean_name ;
63         var $template_instance ;
64
65         function aSubPanel ( $name , $instance_properties , $parent_bean , $reload = false , $original_only = false )
66         {
67
68                 $this->_instance_properties = $instance_properties ;
69                 $this->name = $name ;
70                 $this->parent_bean = $parent_bean ;
71
72                 //set language
73                 global $current_language ;
74                 if (! isset ( $parent_bean->mbvardefs ))
75                 {
76                         $mod_strings = return_module_language ( $current_language, $parent_bean->module_dir ) ;
77                 }
78                 $this->mod_strings = $mod_strings ;
79
80                 if ($this->isCollection ())
81                 {
82                         $this->load_sub_subpanels () ; //load sub-panel definition.
83                 } else
84                 {
85                         if (!is_dir('modules/' . $this->_instance_properties [ 'module' ])){
86                                 _pstack_trace();
87                         }
88                         $def_path = 'modules/' . $this->_instance_properties [ 'module' ] . '/metadata/subpanels/' . $this->_instance_properties [ 'subpanel_name' ] . '.php' ;
89
90                         $orig_exists = is_file($def_path);
91                         $loaded = false;
92                         if ($orig_exists)
93                         {
94                                 require ($def_path);
95                                 $loaded = true;
96                         }
97                         if (is_file("custom/$def_path") && (!$original_only  || !$orig_exists))
98                         {
99                                 require ("custom/$def_path");
100                                 $loaded = true;
101                         }
102
103                         if (! $original_only && isset ( $this->_instance_properties [ 'override_subpanel_name' ] ) && file_exists ( 'custom/modules/' . $this->_instance_properties [ 'module' ] . '/metadata/subpanels/' . $this->_instance_properties [ 'override_subpanel_name' ] . '.php' ))
104                         {
105                                 $cust_def_path = 'custom/modules/' . $this->_instance_properties [ 'module' ] . '/metadata/subpanels/' . $this->_instance_properties [ 'override_subpanel_name' ] . '.php' ;
106                                 require ($cust_def_path) ;
107                                 $loaded = true;
108                         }
109
110                         if (!$loaded)
111                         {
112                                 $GLOBALS['log']->fatal("Failed to load original or custom subpanel data for $name in $def_path");
113                         }
114
115                         // check that the loaded subpanel definition includes a $subpanel_layout section - some, such as projecttasks/default do not...
116                         $this->panel_definition = array () ;
117                         if (isset($subpanel_layout))
118                         {
119                                 $this->panel_definition = $subpanel_layout ;
120
121                         }
122                         $this->load_module_info () ; //load module info from the module's bean file.
123                 }
124
125         }
126
127         function distinct_query ()
128         {
129                 if (isset ( $this->_instance_properties [ 'get_distinct_data' ] ))
130                 {
131
132                         if (! empty ( $this->_instance_properties [ 'get_distinct_data' ] ))
133                         return true ; else
134                         return false ;
135                 }
136                 return false ;
137         }
138
139         //return the translated header value.
140         function get_title ()
141         {
142                 if (empty ( $this->mod_strings [ $this->_instance_properties [ 'title_key' ] ] ))
143                 {
144                         return translate ( $this->_instance_properties [ 'title_key' ], $this->_instance_properties [ 'module' ] ) ;
145                 }
146                 return $this->mod_strings [ $this->_instance_properties [ 'title_key' ] ] ;
147         }
148
149         //return the definition of buttons. looks for buttons in 2 locations.
150         function get_buttons ()
151         {
152                 $buttons = array ( ) ;
153                 if (isset ( $this->_instance_properties [ 'top_buttons' ] ))
154                 {
155                         //this will happen only in the case of sub-panels with multiple sources(activities).
156                         $buttons = $this->_instance_properties [ 'top_buttons' ] ;
157                 } else
158                 {
159                         $buttons = $this->panel_definition [ 'top_buttons' ] ;
160                 }
161
162                 // permissions. hide SubPanelTopComposeEmailButton from activities if email module is disabled.
163                 //only email is  being tested becuase other submodules in activites/history such as notes, tasks, meetings and calls cannot be disabled.
164                 //as of today these are the only 2 sub-panels that use the union clause.
165                 $mod_name = $this->get_module_name () ;
166                 if ($mod_name == 'Activities' || $mod_name == 'History')
167                 {
168                         global $modListHeader ;
169                         global $modules_exempt_from_availability_check ;
170                         if (isset ( $modListHeader ) && (! (array_key_exists ( 'Emails', $modListHeader ) or array_key_exists ( 'Emails', $modules_exempt_from_availability_check ))))
171                         {
172                                 foreach ( $buttons as $key => $button )
173                                 {
174                                         foreach ( $button as $property => $value )
175                                         {
176                                                 if ($value === 'SubPanelTopComposeEmailButton' || $value === 'SubPanelTopArchiveEmailButton')
177                                                 {
178                                                         //remove this button from the array.
179                                                         unset ( $buttons [ $key ] ) ;
180                                                 }
181                                         }
182                                 }
183                         }
184                 }
185
186                 return $buttons ;
187         }
188
189
190         //call this function for sub-panels that have unions.
191         function load_sub_subpanels ()
192         {
193
194                 global $modListHeader ;
195                 // added a check for security of tabs to see if an user has access to them
196                 // this prevents passing an "unseen" tab to the query string and pulling up its contents
197                 if (! isset ( $modListHeader ))
198                 {
199                         global $current_user ;
200                         if (isset ( $current_user ))
201                         {
202                                 $modListHeader = query_module_access_list ( $current_user ) ;
203                         }
204                 }
205
206                 global $modules_exempt_from_availability_check ;
207
208                 $listFieldMap = array();
209
210                 if (empty ( $this->sub_subpanels ))
211                 {
212                         $panels = $this->get_inst_prop_value ( 'collection_list' ) ;
213                         foreach ( $panels as $panel => $properties )
214                         {
215                                 if (array_key_exists ( $properties [ 'module' ], $modListHeader ) or array_key_exists ( $properties [ 'module' ], $modules_exempt_from_availability_check ))
216                                 {
217                                         $this->sub_subpanels [ $panel ] = new aSubPanel ( $panel, $properties, $this->parent_bean ) ;
218                                 }
219                         }
220                         //Sync displayed list fields across the subpanels
221                         $display_fields = $this->getDisplayFieldsFromCollection($this->sub_subpanels);
222                         $query_fields = array();
223                         foreach ( $this->sub_subpanels as $key => $subpanel )
224                         {
225                                 $list_fields = $subpanel->get_list_fields();
226                                 $listFieldMap[$key] = array();
227                                 $index = 0;
228                                 foreach($list_fields as $field => $def)
229                                 {
230                                         if (isset($def['vname']) && isset($def['width']))
231                                         {
232                                                 $index++;
233                                                 if(!empty($def['alias']))
234                                                         $listFieldMap[$key][$def['alias']] = $field;
235                                                 else
236                                                         $listFieldMap[$key][$field] = $field;
237                                                 if (!isset($display_fields[$def['vname']]))
238                                                 {
239                                                         if(sizeof($display_fields) > $index)
240                                                         {
241                                                                 //Try to insert the new field in an order that makes sense
242                                                                 $start = array_slice($display_fields, 0, $index);
243                                                                 $end = array_slice($display_fields, $index);
244                                                                 $display_fields = array_merge(
245                                                                         $start,
246                                                                         array($def['vname'] => array('name' => $field, 'vname' => $def['vname'], 'width' => $def['width'] )),
247                                                                         $end
248                                                                 );
249                                                         } else
250                                                         {
251                                                                 $display_fields[$def['vname']] = array(
252                                                                         'name' => empty($def['alias']) ? $field : $def['alias'],
253                                                                         'vname' => $def['vname'],
254                                                                         'width' => $def['width'],
255                                                                 );
256                                                         }
257                                                 }
258                                         } else {
259                                                 $query_fields[$field] = $def;
260                                         }
261                                 }
262                         }
263                         foreach ( $this->sub_subpanels as $key => $subpanel )
264                         {
265                                 $list_fields = array();
266                                 foreach($display_fields as $vname => $def)
267                                 {
268                                         $field = $def['name'];
269                                         $list_key = isset($listFieldMap[$key][$field]) ? $listFieldMap[$key][$field] : $field;
270
271                                         if (isset($subpanel->panel_definition['list_fields'][$field]))
272                                         {
273                                                 $list_fields[$field] = $subpanel->panel_definition['list_fields'][$field];
274                                         }
275                                     else if ($list_key != $field && isset($subpanel->panel_definition['list_fields'][$list_key]))
276                     {
277                         $list_fields[$list_key] = $subpanel->panel_definition['list_fields'][$list_key];
278
279                     }
280                                         else {
281                                                 $list_fields[$field] = $display_fields[$vname];
282                                         }
283                                 }
284                                 foreach($query_fields as $field => $def)
285                                 {
286                                         if (isset($subpanel->panel_definition['list_fields'][$field]))
287                                         {
288                                                 $list_fields[$field] = $subpanel->panel_definition['list_fields'][$field];
289                                         }
290                                         else {
291                                                 $list_fields[$field] = $def;
292                                         }
293                                 }
294                                 $subpanel->panel_definition['list_fields'] = $list_fields;
295                         }
296                 }
297         }
298
299         protected function getDisplayFieldsFromCollection($sub_subpanels)
300         {
301                 $display_fields = array();
302                 foreach ($sub_subpanels as $key => $subpanel )
303                 {
304                         $list_fields = $subpanel->get_list_fields();
305                         $index = 0;
306                         foreach($list_fields as $field => $def)
307                         {
308                                 if (isset($def['vname']) && isset($def['width']))
309                                 {
310                                         $index++;
311                                         if (!isset($display_fields[$def['vname']]))
312                                         {
313                                                 if(sizeof($display_fields) > $index)
314                                                 {
315                                                         //Try to insert the new field in an order that makes sense
316                                                         $start = array_slice($display_fields, 0, $index);
317                                                         $end = array_slice($display_fields, $index);
318                                                         $display_fields = array_merge(
319                                                                 $start,
320                                                                 array($def['vname'] => array('name' => $field, 'vname' => $def['vname'], 'width' => $def['width'] )),
321                                                                 $end
322                                                         );
323                                                 } else
324                                                 {
325                                                         $display_fields[$def['vname']] = array(
326                                                                 'name' => $field,
327                                                                 'vname' => $def['vname'],
328                                                                 'width' => $def['width'],
329                                                         );
330                                                 }
331                                         }
332                                 }
333                         }
334                 }
335         }
336
337         function isDatasourceFunction ()
338         {
339                 if (strpos ( $this->get_inst_prop_value ( 'get_subpanel_data' ), 'function' ) === false)
340                 {
341                         return false ;
342                 }
343                 return true ;
344         }
345         function isCollection ()
346         {
347                 if ($this->get_inst_prop_value ( 'type' ) == 'collection')
348                 return true ; else
349                 return false ;
350         }
351
352         //get value of a property defined at the panel instance level.
353         function get_inst_prop_value ( $name )
354         {
355                 if (isset ( $this->_instance_properties [ $name ] ))
356                 return $this->_instance_properties [ $name ] ; else
357                 return null ;
358         }
359         //get value of a property defined at the panel definition level.
360         function get_def_prop_value ( $name )
361         {
362                 if (isset ( $this->panel_definition [ $name ] ))
363                 {
364                         return $this->panel_definition [ $name ] ;
365                 } else
366                 {
367                         return null ;
368                 }
369         }
370
371         //if datasource is of the type function then return the function name
372         //else return the value as is.
373         function get_function_parameters ()
374         {
375                 $parameters = array ( ) ;
376                 if ($this->isDatasourceFunction ())
377                 {
378                         $parameters = $this->get_inst_prop_value ( 'function_parameters' ) ;
379                 }
380                 return $parameters ;
381         }
382
383         function get_data_source_name ( $check_set_subpanel_data = false )
384         {
385                 $prop_value = null ;
386                 if ($check_set_subpanel_data)
387                 {
388                         $prop_value = $this->get_inst_prop_value ( 'set_subpanel_data' ) ;
389                 }
390                 if (! empty ( $prop_value ))
391                 {
392                         return $prop_value ;
393                 } else
394                 {
395                         //fall back to default behavior.
396                 }
397                 if ($this->isDatasourceFunction ())
398                 {
399                         return (substr_replace ( $this->get_inst_prop_value ( 'get_subpanel_data' ), '', 0, 9 )) ;
400                 } else
401                 {
402                         return $this->get_inst_prop_value ( 'get_subpanel_data' ) ;
403                 }
404         }
405
406         //returns the where clause for the query.
407         function get_where ()
408         {
409                 return $this->get_def_prop_value ( 'where' ) ;
410         }
411
412         function is_fill_in_additional_fields ()
413         {
414                 // do both. inst_prop returns values from metadata/subpaneldefs.php and def_prop returns from subpanel/default.php
415                 $temp = $this->get_inst_prop_value ( 'fill_in_additional_fields' ) || $this->get_def_prop_value ( 'fill_in_additional_fields' ) ;
416                 return $temp ;
417         }
418
419         function get_list_fields ()
420         {
421                 if (isset ( $this->panel_definition [ 'list_fields' ] ))
422                 {
423                         return $this->panel_definition [ 'list_fields' ] ;
424                 } else
425                 {
426                         return array ( ) ;
427                 }
428         }
429
430         function get_module_name ()
431         {
432                 return $this->get_inst_prop_value ( 'module' ) ;
433         }
434
435         function get_name ()
436         {
437                 return $this->name ;
438         }
439
440         //load subpanel mdoule's table name and column fields.
441         function load_module_info ()
442         {
443                 global $beanList ;
444                 global $beanFiles ;
445
446                 $module_name = $this->get_module_name () ;
447                 if (! empty ( $module_name ))
448                 {
449
450                         $bean_name = $beanList [ $this->get_module_name () ] ;
451
452                         $this->bean_name = $bean_name ;
453
454                         include_once ($beanFiles [ $bean_name ]) ;
455                         $this->template_instance = new $bean_name ( ) ;
456                         $this->template_instance->force_load_details = true ;
457                         $this->table_name = $this->template_instance->table_name ;
458                         //$this->db_fields=$this->template_instance->column_fields;
459                 }
460         }
461         //this function is to be used only with sub-panels that are based
462         //on collections.
463         function get_header_panel_def ()
464         {
465                 if (! empty ( $this->sub_subpanels ))
466                 {
467                         if (! empty ( $this->_instance_properties [ 'header_definition_from_subpanel' ] ) && ! empty ( $this->sub_subpanels [ $this->_instance_properties [ 'header_definition_from_subpanel' ] ] ))
468                         {
469                                 return $this->sub_subpanels [ $this->_instance_properties [ 'header_definition_from_subpanel' ] ] ;
470                         } else
471                         {
472                                 $display_fields = array();
473                                 //If we are not pulling from a specific subpanel, create a list of all list fields and use that.
474                                 foreach($this->sub_subpanels as $subpanel)
475                                 {
476                                         $list_fields = $subpanel->get_list_fields();
477                                         foreach($list_fields as $field => $def)
478                                         {
479
480                                         }
481                                 }
482
483                                 reset ( $this->sub_subpanels ) ;
484                                 return current ( $this->sub_subpanels ) ;
485                         }
486                 }
487                 return null ;
488         }
489
490         /**
491          * Returns an array of current properties of the class.
492          * It will simply give the class name for instances of classes.
493          */
494         function _to_array ()
495         {
496                 return array ( '_instance_properties' => $this->_instance_properties , 'db_fields' => $this->db_fields , 'mod_strings' => $this->mod_strings , 'name' => $this->name , 'panel_definition' => $this->panel_definition , 'parent_bean' => get_class ( $this->parent_bean ) , 'sub_subpanels' => $this->sub_subpanels , 'table_name' => $this->table_name , 'template_instance' => get_class ( $this->template_instance ) ) ;
497         }
498 }
499 ;
500
501 class SubPanelDefinitions
502 {
503
504         var $_focus ;
505         var $_visible_tabs_array ;
506         var $panels ;
507         var $layout_defs ;
508
509         /**
510          * Enter description here...
511          *
512          * @param BEAN $focus - this is the bean you want to get the data from
513          * @param STRING $layout_def_key - if you wish to use a layout_def defined in the default metadata/subpaneldefs.php that is not keyed off of $bean->module_dir pass in the key here
514          * @param ARRAY $layout_def_override - if you wish to override the default loaded layout defs you pass them in here.
515          * @return SubPanelDefinitions
516          */
517         function SubPanelDefinitions ( $focus , $layout_def_key = '' , $layout_def_override = '' )
518         {
519                 $this->_focus = $focus ;
520                 if (! empty ( $layout_def_override ))
521                 {
522                         $this->layout_defs = $layout_def_override ;
523
524                 } else
525                 {
526                         $this->open_layout_defs ( false, $layout_def_key ) ;
527                 }
528         }
529
530         /**
531          * This function returns an ordered list of all "tabs", actually subpanels, for this module
532          * The source list is obtained from the subpanel layout contained in the layout_defs for this module,
533          * found either in the modules metadata/subpaneldefs.php file, or in the modules custom/.../Ext/Layoutdefs/layoutdefs.ext.php file
534          * and filtered through an ACL check.
535          * Note that the keys for the resulting array of tabs are in practice the name of the underlying source relationship for the subpanel
536          * So for example, the key for a custom module's subpanel with Accounts might be 'one_one_accounts', as generated by the Studio Relationship Editor
537          * Although OOB module subpanels have keys such as 'accounts', which might on the face of it appear to be a reference to the related module, in fact 'accounts' is still the relationship name
538          * @param boolean       Optional - include the subpanel title label in the return array (false)
539          * @return array        All tabs that pass an ACL check
540          */
541         function get_available_tabs ($FromGetModuleSubpanels=false)
542         {
543                 global $modListHeader ;
544                 global $modules_exempt_from_availability_check ;
545
546                 if (isset ( $this->_visible_tabs_array ))
547                         return $this->_visible_tabs_array ;
548
549                 if (empty($modListHeader))
550                     $modListHeader = query_module_access_list($GLOBALS['current_user']);
551
552                 $this->_visible_tabs_array = array ( ) ; // bug 16820 - make sure this is an array for the later ksort
553
554                 if (isset ( $this->layout_defs [ 'subpanel_setup' ] )) // bug 17434 - belts-and-braces - check that we have some subpanels first
555                 {
556                         //retrieve list of hidden subpanels
557                         $hidden_panels = $this->get_hidden_subpanels();
558
559                         //activities is a special use case in that if it is hidden,
560                         //then the history tab should be hidden too.
561                         if(!empty($hidden_panels) && is_array($hidden_panels) && in_array('activities',$hidden_panels)){
562                                 //add history to list hidden_panels
563                                 $hidden_panels['history'] = 'history';
564                         }
565
566                         foreach ( $this->layout_defs [ 'subpanel_setup' ] as $key => $values_array )
567                         {
568                                 //exclude if this subpanel is hidden from admin screens
569                 $module = $key;
570                 if ( isset($values_array['module']) )
571                     $module = strtolower($values_array['module']);
572                                  if ($hidden_panels && is_array($hidden_panels) && (in_array($module, $hidden_panels) || array_key_exists($module, $hidden_panels)) ){
573                                         //this panel is hidden, skip it
574                                         continue;
575                                  }
576
577                                 // make sure the module attribute is set, else none of this works...
578                                 if ( !isset($values_array [ 'module' ])) {
579                                         $GLOBALS['log']->debug("SubPanelDefinitions->get_available_tabs(): no module defined in subpaneldefs for '$key' =>" . var_export($values_array,true) . " - ingoring subpanel defintion") ;
580                                         continue;
581                                 }
582
583                                 //check permissions.
584                                 $exempt = array_key_exists ( $values_array [ 'module' ], $modules_exempt_from_availability_check ) ;
585                                 $ok = $exempt || ( (! ACLController::moduleSupportsACL ( $values_array [ 'module' ] ) || ACLController::checkAccess ( $values_array [ 'module' ], 'list', true ) ) ) ;
586
587                                 $GLOBALS [ 'log' ]->debug ( "SubPanelDefinitions->get_available_tabs(): " . $key . "= " . ( $exempt ? "exempt " : "not exempt " .( $ok ? " ACL OK" : "" ) ) ) ;
588
589                                 if ( $ok )
590                                 {
591                                         while ( ! empty ( $this->_visible_tabs_array [ $values_array [ 'order' ] ] ) )
592                                         {
593                                                 $values_array [ 'order' ] ++ ;
594                                         }
595
596                                         $this->_visible_tabs_array [ $values_array ['order'] ] = ($FromGetModuleSubpanels) ? array($key=>$values_array['title_key']) : $key ;
597                                 }
598                         }
599                 }
600
601                 ksort ( $this->_visible_tabs_array ) ;
602                 return $this->_visible_tabs_array ;
603         }
604
605         /**
606          * Load the definition of the a sub-panel.
607          * Also the sub-panel is added to an array of sub-panels.
608          * use of reload has been deprecated, since the subpanel is initialized every time.
609          */
610         function load_subpanel ( $name , $reload = false , $original_only = false )
611         {
612                 if (!is_dir('modules/' . $this->layout_defs [ 'subpanel_setup' ][ strtolower ( $name ) ] [ 'module' ]))
613                   return false;
614                 return new aSubPanel ( $name, $this->layout_defs [ 'subpanel_setup' ] [ strtolower ( $name ) ], $this->_focus, $reload, $original_only ) ;
615         }
616
617         /**
618          * Load the layout def file and associate the definition with a variable in the file.
619          */
620         function open_layout_defs ( $reload = false , $layout_def_key = '' , $original_only = false )
621         {
622                 $layout_defs [ $this->_focus->module_dir ] = array ( ) ;
623                 $layout_defs [ $layout_def_key ] = array ( ) ;
624
625                 if (empty ( $this->layout_defs ) || $reload || (! empty ( $layout_def_key ) && ! isset ( $layout_defs [ $layout_def_key ] )))
626                 {
627                         if (file_exists ( 'modules/' . $this->_focus->module_dir . '/metadata/subpaneldefs.php' ))
628                                 require ('modules/' . $this->_focus->module_dir . '/metadata/subpaneldefs.php') ;
629
630                         if (! $original_only && file_exists ( 'custom/modules/' . $this->_focus->module_dir . '/Ext/Layoutdefs/layoutdefs.ext.php' ))
631                                 require ('custom/modules/' . $this->_focus->module_dir . '/Ext/Layoutdefs/layoutdefs.ext.php') ;
632
633                         if (! empty ( $layout_def_key ))
634                                 $this->layout_defs = $layout_defs [ $layout_def_key ] ;
635                         else
636                                 $this->layout_defs = $layout_defs [ $this->_focus->module_dir ] ;
637
638                 }
639
640         }
641
642         /**
643          * Removes a tab from the list of loaded tabs.
644          * Returns true if successful, false otherwise.
645          * Hint: Used by Campaign's DetailView.
646          */
647         function exclude_tab ( $tab_name )
648         {
649                 $result = false ;
650                 //unset layout definition
651                 if (! empty ( $this->layout_defs [ 'subpanel_setup' ] [ $tab_name ] ))
652                 {
653                         unset ( $this->layout_defs [ 'subpanel_setup' ] [ $tab_name ] ) ;
654                 }
655                 //unset instance from _visible_tab_array
656                 if (! empty ( $this->_visible_tabs_array ))
657                 {
658                         $key = array_search ( $tab_name, $this->_visible_tabs_array ) ;
659                         if ($key !== false)
660                         {
661                                 unset ( $this->_visible_tabs_array [ $key ] ) ;
662                         }
663                 }
664                 return $result ;
665         }
666
667
668         /**
669          * return all available subpanels that belong to the list of tab modules.  You can optionally return all
670          * available subpanels, and also optionally group by module (prepends the key with the bean class name).
671          */
672         function get_all_subpanels( $return_tab_modules_only = true, $group_by_module = false )
673         {
674                 global $moduleList, $beanFiles, $beanList, $module;
675
676                 //use tab controller function to get module list with named keys
677                 require_once("modules/MySettings/TabController.php");
678                 $modules_to_check = TabController::get_key_array($moduleList);
679
680                 //change case to match subpanel processing later on
681                 $modules_to_check = array_change_key_case($modules_to_check);
682         // Append on the CampaignLog module, because that is where the subpanels point, not directly to Campaigns
683         $modules_to_check['campaignlog'] = "CampaignLog";
684
685
686                 $spd = '';
687                 $spd_arr = array();
688                 //iterate through modules and build subpanel array
689                 foreach($modules_to_check as $mod_name){
690
691                         //skip if module name is not in bean list, otherwise get the bean class name
692                         if(!isset($beanList[$mod_name])) continue;
693                         $class = $beanList[$mod_name];
694
695                         //skip if class name is not in file list, otherwise require the bean file and create new class
696                         if(!isset($beanFiles[$class]) || !file_exists($beanFiles[$class])) continue;
697
698                         //retrieve subpanels for this bean
699                         require_once($beanFiles[$class]);
700                         $bean_class = new $class();
701
702                         //create new subpanel definition instance and get list of tabs
703                         $spd = new SubPanelDefinitions($bean_class) ;
704                         $sub_tabs = $spd->get_available_tabs();
705
706                         //add each subpanel to array of total subpanles
707                         foreach( $sub_tabs as $panel_key){
708                                 $panel_key = strtolower($panel_key);
709                 $panel_module = $panel_key;
710                 if ( isset($spd->layout_defs['subpanel_setup'][$panel_key]['module']) )
711                     $panel_module = strtolower($spd->layout_defs['subpanel_setup'][$panel_key]['module']);
712                 //if module_only flag is set, only if it is also in module array
713                                 if($return_tab_modules_only && !array_key_exists($panel_module, $modules_to_check)) continue;
714                                 $panel_key_name = $panel_module;
715
716                                 //group_by_key_name is set to true, then array will hold an entry for each
717                                 //subpanel, with the module name prepended in the key
718                                 if($group_by_module) $panel_key_name = $class.'_'.$panel_key_name;
719                                 //add panel name to subpanel array
720                                 $spd_arr[$panel_key_name] = $panel_module;
721                         }
722                 }
723                 return  $spd_arr;
724         }
725
726         /*
727          * save array of hidden panels to mysettings category in config table
728          */
729         function set_hidden_subpanels($panels){
730                 $administration = new Administration();
731                 $serialized = base64_encode(serialize($panels));
732                 $administration->saveSetting('MySettings', 'hide_subpanels', $serialized);
733         }
734
735         /*
736          * retrieve hidden subpanels
737          */
738         function get_hidden_subpanels(){
739                 global $moduleList;
740
741                 //create variable as static to minimize queries
742                 static $hidden_subpanels = null;
743
744                 // if the static value is not already cached, then retrieve it.
745                 if(empty($hidden_subpanels))
746                 {
747
748                         //create Administration object and retrieve any settings for panels
749                         $administration = new Administration();
750                         $administration->retrieveSettings('MySettings');
751
752                         if(isset($administration->settings) && isset($administration->settings['MySettings_hide_subpanels'])){
753                                 $hidden_subpanels = $administration->settings['MySettings_hide_subpanels'];
754                                 $hidden_subpanels = trim($hidden_subpanels);
755
756                                 //make sure serialized string is not empty
757                                 if (!empty($hidden_subpanels)){
758                                         //decode and unserialize to retrieve the array
759                                         $hidden_subpanels = base64_decode($hidden_subpanels);
760                                         $hidden_subpanels = unserialize($hidden_subpanels);
761
762                                         //Ensure modules saved in the preferences exist.
763                                         //get user preference
764                                         //unserialize and add to array if not empty
765                                         $pref_hidden = array();
766                                         foreach($pref_hidden as $id => $pref_hidden_panel) {
767                                                 $hidden_subpanels[] = $pref_hidden_panel;
768                                         }
769
770
771                                 }else{
772                                         //no settings found, return empty
773                                         return $hidden_subpanels;
774                                 }
775                         }
776                         else
777                         {       //no settings found, return empty
778                                 return $hidden_subpanels;
779                         }
780                 }
781
782                 return $hidden_subpanels;
783         }
784
785
786 }
787 ?>