]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Documents/views/view.extdoc.php
Release 6.2.3
[Github/sugarcrm.git] / modules / Documents / views / view.extdoc.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-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 require_once('include/Sugar_Smarty.php');
41 require_once('include/externalAPI/ExternalAPIFactory.php');
42
43
44 class DocumentsViewExtdoc extends SugarView
45 {
46     var $options = array('show_header' => false, 'show_title' => false, 'show_subpanels' => false, 'show_search' => true, 'show_footer' => false, 'show_javascript' => false, 'view_print' => false,);
47
48     public function init($bean, $view_object_map) {
49         $this->seed = $bean;
50     }
51
52         public function display(){
53
54         if ( isset($_REQUEST['name_basic']) ) {
55             $file_search = trim($_REQUEST['name_basic']);
56         } else {
57             $file_search = '';
58         }
59         
60         if ( !isset($_REQUEST['apiName']) ) {
61             $apiName = 'LotusLive';
62         } else {
63             $tmpApi = ExternalAPIFactory::loadAPI($_REQUEST['apiName'],true);
64             if ( $tmpApi === false ) {
65                 $GLOBALS['log']->error('The user attempted to access an invalid external API ('.$_REQUEST['apiName'].')');
66                 return;
67             }
68             $apiName = $_REQUEST['apiName'];
69         }
70
71         // See if we are running as a popup window
72         if ( isset($_REQUEST['isPopup']) && $_REQUEST['isPopup'] == 1 && !empty($_REQUEST['elemBaseName']) ) {
73             $isPopup = true;
74         } else {
75             $isPopup = false;
76         }
77
78         // Need to manually attempt to fetch the EAPM record, we don't want to give them the signup screen when they just have a deactivated account.
79         
80         if ( !$eapmBean = EAPM::getLoginInfo($apiName,true) ) {
81             $smarty = new Sugar_Smarty();
82             echo $smarty->fetch('include/externalAPI/'.$apiName.'/'.$apiName.'Signup.'.$GLOBALS['current_language'].'.tpl');
83             return;
84         }
85
86
87         $api = ExternalAPIFactory::loadAPI($apiName,true);
88         $api->loadEAPM($eapmBean);
89
90         $quickCheck = $api->quickCheckLogin();
91         if ( ! $quickCheck['success'] ) {
92             $errorMessage = string_format(translate('LBL_ERR_FAILED_QUICKCHECK','EAPM'), array($apiName));
93             $errorMessage .= '<form method="POST" target="_EAPM_CHECK" action="index.php">';
94             $errorMessage .= '<input type="hidden" name="module" value="EAPM">';
95             $errorMessage .= '<input type="hidden" name="action" value="Save">';
96             $errorMessage .= '<input type="hidden" name="record" value="'.$eapmBean->id.'">';
97             $errorMessage .= '<input type="hidden" name="active" value="1">';
98             $errorMessage .= '<input type="hidden" name="closeWhenDone" value="1">';
99             $errorMessage .= '<input type="hidden" name="refreshParentWindow" value="1">';
100
101             $errorMessage .= '<br><input type="submit" value="'.$GLOBALS['app_strings']['LBL_EMAIL_OK'].'">&nbsp;';
102             $errorMessage .= '<input type="button" onclick="lastLoadedMenu=undefined;DCMenu.closeOverlay();return false;" value="'.$GLOBALS['app_strings']['LBL_CANCEL_BUTTON_LABEL'].'">';
103             $errorMessage .= '</form>';
104             echo $errorMessage;
105             return;
106         }
107
108         $searchDataLower = $api->searchDoc($file_search,true);
109
110
111         // In order to emulate the list views for the SugarFields, I need to uppercase all of the key names.
112         $searchData = array();
113
114         if ( is_array($searchDataLower) ) {
115             foreach ( $searchDataLower as $row ) {
116                 $newRow = array();
117                 foreach ( $row as $key => $value ) {
118                     $newRow[strtoupper($key)] = $value;
119                 }
120                 
121                 if ( $isPopup ) {
122                     // We are running as a popup window, we need to replace the direct url with some javascript
123                     $newRow['DOC_URL'] = "javascript:window.opener.SUGAR.field.file.populateFromPopup('".addslashes($_REQUEST['elemBaseName'])."','".addslashes($newRow['ID'])."','".addslashes($newRow['NAME'])."','".addslashes($newRow['URL'])."','".addslashes($newRow['URL'])."'); window.close();";
124                 }else{
125                     $newRow['DOC_URL'] = $newRow['URL'];
126                 }
127                 $searchData[] = $newRow;
128             }
129         }
130
131         $displayColumns = array(
132             'NAME' => array(
133                 'label' => 'LBL_LIST_EXT_DOCUMENT_NAME',
134                 'type' => 'varchar',
135                 'link' => true,
136                 ),
137             'DATE_MODIFIED' => array(
138                 'label' => 'LBL_DATE',
139                 'type' => 'date',
140                 ),
141         );
142
143         $ss = new Sugar_Smarty();
144         $ss->assign('searchFieldLabel',translate('LBL_SEARCH_EXTERNAL_DOCUMENT','Documents'));
145         $ss->assign('displayedNote',translate('LBL_EXTERNAL_DOCUMENT_NOTE','Documents'));
146         $ss->assign('APP',$GLOBALS['app_strings']);
147         $ss->assign('MOD',$GLOBALS['mod_strings']);
148         $ss->assign('data', $searchData);
149         $ss->assign('displayColumns',$displayColumns);
150         $ss->assign('imgPath',SugarThemeRegistry::current()->getImageURL($apiName.'_image_inline.png'));
151
152         if ( $isPopup ) { 
153             $ss->assign('linkTarget','');
154             $ss->assign('isPopup',1);
155             $ss->assign('elemBaseName',$_REQUEST['elemBaseName']);
156         } else {
157             $ss->assign('linkTarget','_new');
158             $ss->assign('isPopup',0);
159             $ss->assign('elemBaseName','');
160         }
161         $ss->assign('apiName',$apiName);
162         $ss->assign('DCSEARCH',$file_search);
163
164         if ( $isPopup ) {
165             // Need the popup header... I feel so dirty.
166             ob_start();
167             echo('<div class="dccontent">');
168             insert_popup_header($GLOBALS['theme']);
169             $output_html = ob_get_contents();
170             ob_end_clean();
171             
172             $output_html .= get_form_header(translate('LBL_SEARCH_FORM_TITLE','Documents'), '', false);
173             
174             echo($output_html);
175         }
176
177         $ss->display('modules/Documents/tpls/view.extdoc.tpl');
178         
179         if ( $isPopup ) {
180             // Close the dccontent div
181             echo('</div>');
182         }
183         }
184 }