]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Documents/views/view.extdoc.php
Release 6.5.6
[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-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
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         global $mod_strings;
55
56         if ( isset($_REQUEST['name_basic']) ) {
57             $file_search = trim($_REQUEST['name_basic']);
58         } else {
59             $file_search = '';
60         }
61         
62         if ( !isset($_REQUEST['apiName']) ) {
63             $apiName = 'IBMSmartCloud';
64         } else {
65             $tmpApi = ExternalAPIFactory::loadAPI($_REQUEST['apiName'],true);
66             if ( $tmpApi === false )
67             {
68                 $GLOBALS['log']->error(string_format($mod_strings['ERR_INVALID_EXTERNAL_API_ACCESS'], array($_REQUEST['apiName'])));
69                 return;
70             }
71             $apiName = $_REQUEST['apiName'];
72         }
73
74         // See if we are running as a popup window
75         if ( isset($_REQUEST['isPopup']) && $_REQUEST['isPopup'] == 1 && !empty($_REQUEST['elemBaseName']) ) {
76             $isPopup = true;
77         } else {
78             $isPopup = false;
79         }
80
81          // bug50952 - must actually make sure we can log in, not just that we've got a EAPM record
82          // getLoginInfo only checks to see if user has logged in correctly ONCE to ExternalAPI
83          // 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.
84          $eapmBean = EAPM::getLoginInfo($apiName,true);
85          $api = ExternalAPIFactory::loadAPI($apiName,true);
86          $validSession = true;
87
88          if(!empty($eapmBean))
89          {
90              try {
91                $api->loadEAPM($eapmBean);
92                // $api->checkLogin() does the same thing as quickCheckLogin plus actually makes sure the user CAN log in to the API currently
93                $loginCheck = $api->checkLogin($eapmBean);
94                if(isset($loginCheck['success']) && !$loginCheck['success'])
95                {
96                    $validSession = false;
97                }
98              } catch(Exception $ex) {
99                $validSession = false;
100                $GLOBALS['log']->error(string_format($mod_strings['ERR_INVALID_EXTERNAL_API_LOGIN'], array($apiName)));
101              }
102          }
103
104          if (!$validSession || empty($eapmBean))
105          {
106              // Bug #49987 : Documents view.extdoc.php doesn't allow custom override
107              $tpl_file = get_custom_file_if_exists('include/externalAPI/'.$apiName.'/'.$apiName.'Signup.'.$GLOBALS['current_language'].'.tpl');
108
109              if (file_exists($tpl_file))
110              {
111                  $smarty = new Sugar_Smarty();
112                  echo $smarty->fetch($tpl_file);
113              } else  {
114                  $output = string_format(translate('LBL_ERR_FAILED_QUICKCHECK','EAPM'), array($apiName));
115                  $output .= '<form method="POST" target="_EAPM_CHECK" action="index.php">';
116                  $output .= '<input type="hidden" name="module" value="EAPM">';
117                  $output .= '<input type="hidden" name="action" value="Save">';
118                  $output .= '<input type="hidden" name="record" value="'.$eapmBean->id.'">';
119                  $output .= '<input type="hidden" name="active" value="1">';
120                  $output .= '<input type="hidden" name="closeWhenDone" value="1">';
121                  $output .= '<input type="hidden" name="refreshParentWindow" value="1">';
122
123                  $output .= '<br><input type="submit" value="'.$GLOBALS['app_strings']['LBL_EMAIL_OK'].'">&nbsp;';
124                  $output .= '<input type="button" onclick="lastLoadedMenu=undefined;DCMenu.closeOverlay();return false;" value="'.$GLOBALS['app_strings']['LBL_CANCEL_BUTTON_LABEL'].'">';
125                  $output .= '</form>';
126                  echo $output;
127              }
128
129              return;
130          }
131
132         $searchDataLower = $api->searchDoc($file_search,true);
133
134         // In order to emulate the list views for the SugarFields, I need to uppercase all of the key names.
135         $searchData = array();
136
137         if ( is_array($searchDataLower) ) {
138             foreach ( $searchDataLower as $row ) {
139                 $newRow = array();
140                 foreach ( $row as $key => $value ) {
141                     $newRow[strtoupper($key)] = $value;
142                 }
143                 
144                 if ( $isPopup ) {
145                     // We are running as a popup window, we need to replace the direct url with some javascript
146                     $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();";
147                 }else{
148                     $newRow['DOC_URL'] = $newRow['URL'];
149                 }
150                 $searchData[] = $newRow;
151             }
152         }
153
154         $displayColumns = array(
155             'NAME' => array(
156                 'label' => 'LBL_LIST_EXT_DOCUMENT_NAME',
157                 'type' => 'varchar',
158                 'link' => true,
159                 ),
160             'DATE_MODIFIED' => array(
161                 'label' => 'LBL_DATE',
162                 'type' => 'date',
163                 ),
164         );
165
166         $ss = new Sugar_Smarty();
167         $ss->assign('searchFieldLabel',translate('LBL_SEARCH_EXTERNAL_DOCUMENT','Documents'));
168         $ss->assign('displayedNote',translate('LBL_EXTERNAL_DOCUMENT_NOTE','Documents'));
169         $ss->assign('APP',$GLOBALS['app_strings']);
170         $ss->assign('MOD',$GLOBALS['mod_strings']);
171         $ss->assign('data', $searchData);
172         $ss->assign('displayColumns',$displayColumns);
173         $ss->assign('imgPath',SugarThemeRegistry::current()->getImageURL($apiName.'_image_inline.png'));
174
175         if ( $isPopup ) { 
176             $ss->assign('linkTarget','');
177             $ss->assign('isPopup',1);
178             $ss->assign('elemBaseName',$_REQUEST['elemBaseName']);
179         } else {
180             $ss->assign('linkTarget','_new');
181             $ss->assign('isPopup',0);
182             $ss->assign('elemBaseName','');
183         }
184         $ss->assign('apiName',$apiName);
185         $ss->assign('DCSEARCH',$file_search);
186
187         if ( $isPopup ) {
188             // Need the popup header... I feel so dirty.
189             ob_start();
190             echo('<div class="dccontent">');
191             insert_popup_header($GLOBALS['theme'], false);
192             $output_html = ob_get_contents();
193             ob_end_clean();
194             
195             $output_html .= get_form_header(translate('LBL_SEARCH_FORM_TITLE','Documents'), '', false);
196             
197             echo($output_html);
198         }
199
200         $ss->display('modules/Documents/tpls/view.extdoc.tpl');
201         
202         if ( $isPopup ) {
203             // Close the dccontent div
204             echo('</div>');
205         }
206         }
207 }