]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/utils/layout_utils.php
Release 6.3.1
[Github/sugarcrm.git] / include / utils / layout_utils.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 /**
40  * Contains a variety of utility functions used to display UI components such as form headers and footers.
41  *
42  * @todo refactor out these functions into the base UI objects as indicated
43  */
44
45 /**
46  * Create HTML to display formatted form title.
47  * 
48  * @param  $form_title string to display as the title in the header
49  * @param  $other_text string to next to the title.  Typically used for form buttons.
50  * @param  $show_help  boolean which determines if the print and help links are shown.
51  * @return string HTML
52  */
53 function get_form_header(
54     $form_title, 
55     $other_text, 
56     $show_help
57     )
58 {
59     global $sugar_version, $sugar_flavor, $server_unique_key, $current_language, $current_module, $current_action;
60     global $app_strings;
61     
62     $blankImageURL = SugarThemeRegistry::current()->getImageURL('blank.gif');
63     $printImageURL = SugarThemeRegistry::current()->getImageURL("print.gif");
64     $helpImageURL  = SugarThemeRegistry::current()->getImageURL("help.gif");
65     
66     $is_min_max = strpos($other_text,"_search.gif");
67     if($is_min_max !== false)
68         $form_title = "{$other_text}&nbsp;{$form_title}";
69
70     $the_form = <<<EOHTML
71 <table width="100%" cellpadding="0" cellspacing="0" border="0" class="formHeader h3Row">
72 <tr>
73 <td nowrap><h3><span>{$form_title}</span></h3></td>
74 EOHTML;
75     
76     $keywords = array("/class=\"button\"/","/class='button'/","/class=button/","/<\/form>/");
77     $match="";
78     foreach ($keywords as $left)
79         if (preg_match($left,$other_text))
80             $match = true;
81     
82     if ($other_text && $match) {
83         $the_form .= <<<EOHTML
84 <td colspan='10' width='100%'><IMG height='1' width='1' src='$blankImageURL' alt=''></td>
85 </tr>
86 <tr>
87 <td align='left' valign='middle' nowrap style='padding-bottom: 2px;'>$other_text</td>
88 <td width='100%'><IMG height='1' width='1' src='$blankImageURL' alt=''></td>
89 EOHTML;
90         if ($show_help) {
91             $the_form .= "<td align='right' nowrap>";
92             if ($_REQUEST['action'] != "EditView") {
93                 $the_form .= <<<EOHTML
94     <a href='index.php?{$GLOBALS['request_string']}' class='utilsLink'>
95     <img src='{$printImageURL}' alt='Print' border='0' align='absmiddle'>
96     </a>&nbsp;
97     <a href='index.php?{$GLOBALS['request_string']}' class='utilsLink'>
98     {$app_strings['LNK_PRINT']}
99     </a>
100 EOHTML;
101             }
102             $the_form .= <<<EOHTML
103 &nbsp;
104     <a href='index.php?module=Administration&action=SupportPortal&view=documentation&version={$sugar_version}&edition={$sugar_flavor}&lang={$current_language}&help_module={$current_module}&help_action={$current_action}&key={$server_unique_key}'
105        class='utilsLink' target='_blank'>
106     <img src='{$helpImageURL}' alt='Help' border='0' align='absmiddle'>
107     </a>&nbsp;
108     <a href='index.php?module=Administration&action=SupportPortal&view=documentation&version={$sugar_version}&edition={$sugar_flavor}&lang={$current_language}&help_module={$current_module}&help_action={$current_action}&key={$server_unique_key}'
109         class='utilsLink' target='_blank'>
110     {$app_strings['LNK_HELP']}
111     </a>
112 </td>
113 EOHTML;
114         }
115     } 
116     else {
117         if ($other_text && $is_min_max === false) {
118             $the_form .= <<<EOHTML
119 <td width='20'><img height='1' width='20' src='$blankImageURL' alt=''></td>
120 <td valign='middle' nowrap width='100%'>$other_text</td>
121 EOHTML;
122         }
123         else {
124             $the_form .= <<<EOHTML
125 <td width='100%'><IMG height='1' width='1' src='$blankImageURL' alt=''></td>
126 EOHTML;
127         }
128     
129         if ($show_help) {
130             $the_form .= "<td align='right' nowrap>";
131             if ($_REQUEST['action'] != "EditView") {
132                 $the_form .= <<<EOHTML
133     <a href='index.php?{$GLOBALS['request_string']}' class='utilsLink'>
134     <img src='{$printImageURL}' alt='Print' border='0' align='absmiddle'>
135     </a>&nbsp;
136     <a href='index.php?{$GLOBALS['request_string']}' class='utilsLink'>
137     {$app_strings['LNK_PRINT']}</a>
138 EOHTML;
139             }
140             $the_form .= <<<EOHTML
141     &nbsp;
142     <a href='index.php?module=Administration&action=SupportPortal&view=documentation&version={$sugar_version}&edition={$sugar_flavor}&lang={$current_language}&help_module={$current_module}&help_action={$current_action}&key={$server_unique_key}'
143        class='utilsLink' target='_blank'>
144     <img src='{$helpImageURL}' alt='Help' border='0' align='absmiddle'>
145     </a>&nbsp;
146     <a href='index.php?module=Administration&action=SupportPortal&view=documentation&version={$sugar_version}&edition={$sugar_flavor}&lang={$current_language}&help_module={$current_module}&help_action={$current_action}&key={$server_unique_key}'
147         class='utilsLink' target='_blank'>{$app_strings['LNK_HELP']}</a>
148 </td>
149 EOHTML;
150         }
151     }
152     
153     $the_form .= <<<EOHTML
154 </tr>
155 </table>
156 EOHTML;
157     
158     return $the_form;
159 }
160
161 /**
162  * Wrapper function for the get_module_title function, which is mostly used for pre-MVC modules.
163  * 
164  * @deprecated use SugarView::getModuleTitle() for MVC modules, or getClassicModuleTitle() for non-MVC modules
165  *
166  * @param  $module       string  to next to the title.  Typically used for form buttons.
167  * @param  $module_title string  to display as the module title
168  * @param  $show_help    boolean which determines if the print and help links are shown.
169  * @return string HTML
170  */
171 function get_module_title(
172     $module, 
173     $module_title, 
174     $show_create,
175     $count=0
176     )
177 {
178     global $sugar_version, $sugar_flavor, $server_unique_key, $current_language, $action;
179     global $app_strings;
180     
181     $the_title = "<div class='moduleTitle'>\n<h2>";
182     $module = preg_replace("/ /","",$module);
183     $iconPath = "";
184     if(is_file(SugarThemeRegistry::current()->getImageURL('icon_'.$module.'_32.png',false)))
185     {
186         $iconPath = SugarThemeRegistry::current()->getImageURL('icon_'.$module.'_32.png');
187     } else if (is_file(SugarThemeRegistry::current()->getImageURL('icon_'.ucfirst($module).'_32.png',false)))
188     {
189         $iconPath = SugarThemeRegistry::current()->getImageURL('icon_'.ucfirst($module).'_32.png');
190     }
191     if (!empty($iconPath)) {
192         if (SugarThemeRegistry::current()->directionality == "ltr") {
193                 $the_title .= "<a href='index.php?module={$module}&action=index'><img src='{$iconPath}' " 
194                             . "alt='".$module."' title='".$module."' align='absmiddle'></a>";
195                 $the_title .= ($count >= 1) ? SugarView::getBreadCrumbSymbol() : "";
196                 $the_title .=  $module_title;   
197         } else {
198                 $the_title .= $module_title;
199                 $the_title .= ($count > 1) ? SugarView::getBreadCrumbSymbol() : "";
200                 $the_title .= "<a href='index.php?module={$module}&action=index'><img src='{$iconPath}' " 
201                             . "alt='".$module."' title='".$module."' align='absmiddle'></a>";
202         }
203     } else {
204                 $the_title .= $module_title;
205         }
206     $the_title .= "</h2>\n";
207     
208     if ($show_create) {
209         $the_title .= "<span class='utils'>";
210         $createRecordURL = SugarThemeRegistry::current()->getImageURL('create-record.gif');
211         $url = ajaxLink("index.php?module=$module&action=EditView&return_module=$module&return_action=DetailView");
212         $the_title .= <<<EOHTML
213 &nbsp;
214 <a href="{$url}" class="utilsLink">
215 <img src='{$createRecordURL}' alt='{$GLOBALS['app_strings']['LNK_CREATE']}'></a>
216 <a href="{$url}" class="utilsLink">
217 {$GLOBALS['app_strings']['LNK_CREATE']}
218 </a>
219 EOHTML;
220
221         $the_title .= '</span>';
222     }
223     
224     $the_title .= "</div>\n";
225     return $the_title;
226 }
227
228 /**
229  * Handles displaying the header for classic view modules
230  *
231  * @param  $module      string  to next to the title.  Typically used for form buttons.
232  * @param array $params optional, params to display in the breadcrumb, overriding SugarView::_getModuleTitleParams()
233  * These should be in the form of array('label' => '<THE LABEL>', 'link' => '<HREF TO LINK TO>');
234  * the first breadcrumb should be index at 0, and built from there e.g.
235  * <code>
236  * array(
237  *    '<a href="index.php?module=Contacts&action=index">Contacts</a>',
238  *    '<a href="index.php?module=Contacts&action=DetailView&record=123">John Smith</a>',
239  *    'Edit',
240  *    );
241  * </code>
242  * would display as:
243  * <code>
244  * <a href='index.php?module=Contacts&action=index'>Contacts</a> >> <a href='index.php?module=Contacts&action=DetailView&record=123'>John Smith</a> >> Edit   
245  * </code>
246  * @param  $show_help    boolean which determines if the print and help links are shown.
247  * @return string HTML
248  */
249 function getClassicModuleTitle(
250     $module, 
251     $params, 
252     $show_create,
253     $index_url_override="")
254 {
255         global $sugar_version, $sugar_flavor, $server_unique_key, $current_language, $action;
256     global $app_strings;
257     
258         $module_title = '';
259         $count = count($params);
260         $index = 0;
261
262
263
264     $module = preg_replace("/ /","",$module);
265     $iconPath = "";
266     $the_title = "<div class='moduleTitle'>\n<h2>";
267     
268     if(!empty($GLOBALS['app_list_strings']['moduleList'][$module]))
269         $moduleName = $GLOBALS['app_list_strings']['moduleList'][$module];
270     else
271         $moduleName = $module;
272
273     if(is_file(SugarThemeRegistry::current()->getImageURL('icon_'.$module.'_32.png',false)))
274     {
275         $iconPath = SugarThemeRegistry::current()->getImageURL('icon_'.$module.'_32.png');
276     } else if (is_file(SugarThemeRegistry::current()->getImageURL('icon_'.ucfirst($module).'_32.png',false)))
277     {
278         $iconPath = SugarThemeRegistry::current()->getImageURL('icon_'.ucfirst($module).'_32.png');
279     }
280     if (!empty($iconPath)) {
281         $url = (!empty($index_url_override)) ? $index_url_override : "index.php?module={$module}&action=index";
282         array_unshift ($params,"<a href='{$url}'><img src='{$iconPath}' " 
283                             . "alt='".$moduleName."' title='".$moduleName."' align='absmiddle'></a>");
284         }
285         
286         $new_params = array();
287         $i = 0;
288         foreach ($params as $value) {
289           if ((!is_null($value)) && ($value !== "")) {
290             $new_params[$i] = $value;
291             $i++;
292           }
293         } 
294
295
296         if(SugarThemeRegistry::current()->directionality == "rtl") {
297                 $new_params = array_reverse($new_params);
298         }
299         
300         $module_title = join(SugarView::getBreadCrumbSymbol(),$new_params);
301         
302         
303         
304     $the_title .= $module_title."</h2>\n";
305     
306     if ($show_create) {
307         $the_title .= "<span class='utils'>";
308         $createRecordURL = SugarThemeRegistry::current()->getImageURL('create-record.gif');
309         $url = ajaxLink("index.php?module=$module&action=EditView&return_module=$module&return_action=DetailView");
310         $the_title .= <<<EOHTML
311 &nbsp;
312 <a href="{$url}" class="utilsLink">
313 <img src='{$createRecordURL}' alt='{$GLOBALS['app_strings']['LNK_CREATE']}'></a>
314 <a href="{$url}" class="utilsLink">
315 {$GLOBALS['app_strings']['LNK_CREATE']}
316 </a>
317 EOHTML;
318
319         $the_title .= '</span>';
320     }
321     
322     $the_title .= "</div>\n";
323     return $the_title;
324     
325 }
326
327 /**
328  * Create a header for a popup.
329  *
330  * @todo refactor this into the base Popup_Picker class
331  *
332  * @param  $theme string the name of the current theme, ignorred to use SugarThemeRegistry::current() instead.
333  * @return string HTML
334  */
335 function insert_popup_header(
336     $theme = null,
337     $includeJS = true
338     )
339 {
340     global $app_strings, $sugar_config;
341     
342     $charset = isset($app_strings['LBL_CHARSET']) 
343         ? $app_strings['LBL_CHARSET'] : $sugar_config['default_charset'];
344     
345     $themeCSS = SugarThemeRegistry::current()->getCSS();
346
347     //The SugarView will insert the header now, this function should no longer do the actual head element.
348     if ($includeJS)
349     {
350         echo <<<EOHTML
351 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
352 <html>
353 <head>
354 <meta http-equiv="Content-Type" content="text/html; charset="{$charset}">
355 EOHTML;
356     }
357     echo "<title>{$app_strings['LBL_BROWSER_TITLE']}</title>" . $themeCSS;
358     if ($includeJS)
359     {
360         echo '<script type="text/javascript" src="' . getJSPath('include/javascript/sugar_grp1_yui.js') . '"></script>';
361         echo '<script type="text/javascript" src="' . getJSPath('include/javascript/sugar_grp1.js') . '"></script>';
362         echo '</head>';
363     }
364     echo  '<body class="popupBody">';
365 }
366
367 /**
368  * Create a footer for a popup.
369  *
370  * @todo refactor this into the base Popup_Picker class
371  *
372  * @return string HTML
373  */
374 function insert_popup_footer()
375 {
376     echo <<<EOQ
377 </body>
378 </html>
379 EOQ;
380 }