]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Configurator/views/view.fontmanager.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Configurator / views / view.fontmanager.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
4 /*********************************************************************************
5  * SugarCRM Community Edition is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2012 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 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 {
43    
44     /**
45      * Constructor
46      */
47     public function FontManager(){
48         parent::SugarView();
49     }
50     /** 
51      * display the form
52      */
53     public function display(){
54         global $mod_strings, $app_list_strings, $app_strings, $current_user;
55         $error="";
56         if(!is_admin($current_user)){
57             sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']); 
58         }
59         $fontManager = new FontManager();
60         if(!$fontManager->listFontFiles()){
61             $error = implode("<br>",$fontManager->errors);
62         }
63
64         $this->ss->assign("MODULE_TITLE", 
65             getClassicModuleTitle(
66                 $mod_strings['LBL_MODULE_ID'], 
67                 array($mod_strings['LBL_FONTMANAGER_TITLE']), 
68                 false
69                 )
70             );
71         if(!empty($_REQUEST['error'])){
72             $error .= "<br>".$_REQUEST['error'];
73         }
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']);
80         }else{
81             $this->ss->assign("RETURN_ACTION", 'SugarpdfSettings');
82         }
83         $this->ss->assign("K_PATH_FONTS", K_PATH_FONTS);
84 // YUI List
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());
88         
89 //display
90         $this->ss->display('modules/Configurator/tpls/fontmanager.tpl');
91     }
92     
93     /**
94      * Returns JS used in this view
95      */
96     private function _getJS()
97     {
98         global $mod_strings;
99         return <<<EOJAVASCRIPT
100
101 EOJAVASCRIPT;
102     }
103     
104     /**
105      * Return the columnDefs for the YUI datatable
106      * @return String
107      */
108     private function getYuiColumnDefs($fontList){
109         global $mod_strings;
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))
113             $removeColumn = '';
114             
115         $return = <<<BSOFR
116
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},
124     $removeColumn
125 ]
126 BSOFR;
127         return $return;
128     }
129     
130      /**
131      * Return the dataSource for the YUI Data Table
132      * @param $fontList
133      * @return String
134      */
135     private function getYuiDataSource($fontList){
136         $return = "[";
137         $first=true;
138         foreach($fontList as $k=>$v){
139             if($first){
140                 $first=false;
141             }else{
142                 $return .= ',';
143             }
144             $return .= '{';
145             if(!empty($v['displayname'])){
146                 $return .= 'name:"'.$v['displayname'].'"';
147             }else if(!empty($v['name'])){
148                 $return .= 'name:"'.$v['name'].'"';
149             }
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'].'"';
157             }
158             if($v['embedded'] == true){
159                 $return .= ', embedded:"<input type=\'checkbox\' checked disabled/>"}';
160             }else{
161                 $return .= ', embedded:"<input type=\'checkbox\' disabled/>"}';
162             }
163         }
164         $return .= "]";
165         return $return;
166     }
167     
168      /**
169      * Return the Response Schema for the YUI data table
170      * @return String
171      */
172     private function getYuiResponseSchema(){
173         return <<<BSOFR
174         { 
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"}] 
183         }
184 BSOFR;
185     }
186     
187      /**
188      * Return the label of the passed style
189      * @param $style
190      * @return String
191      */
192     private function formatStyle($style){
193         global $mod_strings;
194         $return = "";
195         if(count($style) == 2){
196             $return .= "<b><i>".$mod_strings['LBL_FONT_BOLDITALIC']."</b></i>";
197         }else{
198             switch($style[0]){
199                 case "bold":
200                     $return .= "<b>".$mod_strings['LBL_FONT_BOLD']."</b>";
201                     break;
202                 case "italic":
203                     $return .= "<i>".$mod_strings['LBL_FONT_ITALIC']."</i>";
204                     break;
205                 default:
206                     $return .= $mod_strings['LBL_FONT_REGULAR'];
207             }
208         }
209         return $return;
210     }
211     
212     private function formatType($type){
213         global $mod_strings;
214         switch($type){
215             case "cidfont0":
216                 $return = $mod_strings['LBL_FONT_TYPE_CID0'];break;
217             case "core":
218                 $return = $mod_strings['LBL_FONT_TYPE_CORE'];break;
219             case "TrueType":
220                 $return = $mod_strings['LBL_FONT_TYPE_TRUETYPE'];break;
221             case "Type1":
222                 $return = $mod_strings['LBL_FONT_TYPE_TYPE1'];break;
223             case "TrueTypeUnicode":
224                 $return = $mod_strings['LBL_FONT_TYPE_TRUETYPEU'];break;
225             default:
226                 $return = "";
227         }
228         return $return;
229     }
230     
231     /**
232      * Determine if all the fonts are core fonts
233      * @param $fontList
234      * @return boolean return true if all the fonts are core type
235      */
236     private function isAllOOBFont($fontList){
237         foreach($fontList as $v){
238             if($v['type'] != "core" && $v['fontpath'] != K_PATH_FONTS)
239                 return false;
240         }
241         return true;
242     }
243 }
244
245