2 if(!defined('sugarEntry') || !sugarEntry) 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-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 require_once('include/Sugarpdf/sugarpdf_config.php');
40 require_once('include/MVC/View/SugarView.php');
41 require_once('include/Sugarpdf/FontManager.php');
42 class ConfiguratorViewFontManager extends SugarView {
47 public function FontManager(){
53 public function display(){
54 global $mod_strings, $app_list_strings, $app_strings, $current_user;
56 if(!is_admin($current_user)){
57 sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']);
59 $fontManager = new FontManager();
60 if(!$fontManager->listFontFiles()){
61 $error = implode("<br>",$fontManager->errors);
64 $this->ss->assign("MODULE_TITLE",
65 getClassicModuleTitle(
66 $mod_strings['LBL_MODULE_ID'],
67 array($mod_strings['LBL_FONTMANAGER_TITLE']),
71 if(!empty($_REQUEST['error'])){
72 $error .= "<br>".$_REQUEST['error'];
74 $this->ss->assign("error", $error);
75 $this->ss->assign("MOD", $mod_strings);
76 $this->ss->assign("APP", $app_strings);
77 $this->ss->assign("JAVASCRIPT", $this->_getJS());
78 if(isset($_REQUEST['return_action'])){
79 $this->ss->assign("RETURN_ACTION", $_REQUEST['return_action']);
81 $this->ss->assign("RETURN_ACTION", 'SugarpdfSettings');
83 $this->ss->assign("K_PATH_FONTS", K_PATH_FONTS);
85 $this->ss->assign("COLUMNDEFS", $this->getYuiColumnDefs($fontManager->fontList));
86 $this->ss->assign("DATASOURCE", $this->getYuiDataSource($fontManager->fontList));
87 $this->ss->assign("RESPONSESCHEMA", $this->getYuiResponseSchema());
90 $this->ss->display('modules/Configurator/tpls/fontmanager.tpl');
94 * Returns JS used in this view
96 private function _getJS()
99 return <<<EOJAVASCRIPT
105 * Return the columnDefs for the YUI datatable
108 private function getYuiColumnDefs($fontList){
110 // Do not show the column with the delete buttons if there is only core fonts
111 $removeColumn = '{key:"button", label:"", formatter:removeFormatter}';
112 if($this->isAllOOBFont($fontList))
117 {key:"name", minWidth:140, label:"{$mod_strings['LBL_FONT_LIST_NAME']}", sortable:true},
118 {key:"filename", minWidth:120, label:"{$mod_strings['LBL_FONT_LIST_FILENAME']}", sortable:true},
119 {key:"type", minWidth:100, label:"{$mod_strings['LBL_FONT_LIST_TYPE']}", sortable:true},
120 {key:"style", minWidth:90, label:"{$mod_strings['LBL_FONT_LIST_STYLE']}", sortable:true},
121 {key:"filesize", minWidth:70, label:"{$mod_strings['LBL_FONT_LIST_FILESIZE']}", formatter:YAHOO.widget.DataTable.formatNumber, sortable:true},
122 {key:"enc", minWidth:80, label:"{$mod_strings['LBL_FONT_LIST_ENC']}", sortable:true},
123 {key:"embedded", minWidth:70, label:"{$mod_strings['LBL_FONT_LIST_EMBEDDED']}", sortable:true},
131 * Return the dataSource for the YUI Data Table
135 private function getYuiDataSource($fontList){
138 foreach($fontList as $k=>$v){
145 if(!empty($v['displayname'])){
146 $return .= 'name:"'.$v['displayname'].'"';
147 }else if(!empty($v['name'])){
148 $return .= 'name:"'.$v['name'].'"';
150 $return .= ', filename:"'.$v['filename'].'"';
151 $return .= ', fontpath:"'.$v['fontpath'].'"';
152 $return .= ', style:"'.$this->formatStyle($v['style']).'"';
153 $return .= ', type:"'.$this->formatType($v['type']).'"';
154 $return .= ', filesize:'.$v['filesize'];
155 if(!empty($v['enc'])){
156 $return .= ', enc:"'.$v['enc'].'"';
158 if($v['embedded'] == true){
159 $return .= ', embedded:"<input type=\'checkbox\' checked disabled/>"}';
161 $return .= ', embedded:"<input type=\'checkbox\' disabled/>"}';
169 * Return the Response Schema for the YUI data table
172 private function getYuiResponseSchema(){
175 fields: [{key:"name", parser:"string"},
176 {key:"filename", parser:"string"},
177 {key:"fontpath", parser:"string"},
178 {key:"type", parser:"string"},
179 {key:"style", parser:"string"},
180 {key:"filesize", parser:"number"},
181 {key:"enc", parser:"string"},
182 {key:"embedded", parser:"string"}]
188 * Return the label of the passed style
192 private function formatStyle($style){
195 if(count($style) == 2){
196 $return .= "<b><i>".$mod_strings['LBL_FONT_BOLDITALIC']."</b></i>";
200 $return .= "<b>".$mod_strings['LBL_FONT_BOLD']."</b>";
203 $return .= "<i>".$mod_strings['LBL_FONT_ITALIC']."</i>";
206 $return .= $mod_strings['LBL_FONT_REGULAR'];
212 private function formatType($type){
216 $return = $mod_strings['LBL_FONT_TYPE_CID0'];break;
218 $return = $mod_strings['LBL_FONT_TYPE_CORE'];break;
220 $return = $mod_strings['LBL_FONT_TYPE_TRUETYPE'];break;
222 $return = $mod_strings['LBL_FONT_TYPE_TYPE1'];break;
223 case "TrueTypeUnicode":
224 $return = $mod_strings['LBL_FONT_TYPE_TRUETYPEU'];break;
232 * Determine if all the fonts are core fonts
234 * @return boolean return true if all the fonts are core type
236 private function isAllOOBFont($fontList){
237 foreach($fontList as $v){
238 if($v['type'] != "core" && $v['fontpath'] != K_PATH_FONTS)