2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 /*********************************************************************************
40 * Description: Business Card Wizard
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
47 global $app_list_strings;
52 global $current_language;
53 $mod_strings = return_module_language($current_language, 'Contacts');
54 echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_MODULE_NAME'].": ".$mod_strings['LBL_BUSINESSCARD'], true);
55 $xtpl=new XTemplate ('modules/Contacts/BusinessCard.html');
56 $xtpl->assign("MOD", $mod_strings);
57 $xtpl->assign("APP", $app_strings);
58 $xtpl->assign("PRINT_URL", "index.php?".$GLOBALS['request_string']);
60 $xtpl->assign("HEADER", $mod_strings['LBL_ADD_BUSINESSCARD']);
62 $xtpl->assign("MODULE", $_REQUEST['module']);
65 $xtpl->assign("ERROR", $error_msg);
66 $xtpl->parse("main.error");
69 if(isset($_POST['handle']) && $_POST['handle'] == 'Save'){
71 require_once('modules/Contacts/ContactFormBase.php');
72 $contactForm = new ContactFormBase();
73 require_once('modules/Accounts/AccountFormBase.php');
74 $accountForm = new AccountFormBase();
76 require_once('modules/Opportunities/OpportunityFormBase.php');
77 $oppForm = new OpportunityFormBase();
78 if(!isset($_POST['selectedContact']) && !isset($_POST['ContinueContact'])){
79 $duplicateContacts = $contactForm->checkForDuplicates('Contacts');
80 if(isset($duplicateContacts)){
81 $formBody = $contactForm->buildTableForm($duplicateContacts);
82 $xtpl->assign('FORMBODY', $formBody);
83 $xtpl->parse('main.formnoborder');
90 if(empty($_POST['selectedAccount']) && empty($_POST['ContinueAccount'])){
91 $duplicateAccounts = $accountForm->checkForDuplicates('Accounts');
93 if(isset($duplicateAccounts)){
94 $xtpl->assign('FORMBODY', $accountForm->buildTableForm($duplicateAccounts));
95 $xtpl->parse('main.formnoborder');
103 if(isset($_POST['newopportunity']) && $_POST['newopportunity']=='on' &&!isset($_POST['selectedOpportunity']) && !isset($_POST['ContinueOpportunity'])){
105 $duplicateOpps = $oppForm->checkForDuplicates('Opportunities');
106 if(isset($duplicateOpps)){
107 $xtpl->assign('FORMBODY', $oppForm->buildTableForm($duplicateOpps));
108 $xtpl->parse('main.formnoborder');
109 $xtpl->parse('main');
114 if(!empty($_POST['selectedContact'])){
115 $contact = new Contact();
116 $contact->retrieve($_POST['selectedContact']);
118 $contact= $contactForm->handleSave('Contacts',false, false);
120 if(!empty($_POST['selectedAccount'])){
121 $account = new Account();
122 $account->retrieve($_POST['selectedAccount']);
123 }else if(isset($_POST['newaccount']) && $_POST['newaccount']=='on' ){
124 $account= $accountForm->handleSave('Accounts',false, false);
126 if(isset($_POST['newopportunity']) && $_POST['newopportunity']=='on' ){
127 if(!empty($_POST['selectedOpportunity'])){
128 $opportunity = new Opportunity();
129 $opportunity->retrieve($_POST['selectedOpportunity']);
132 $_POST['Opportunitiesaccount_id'] = $account->id;
133 $_POST['Opportunitiesaccount_name'] = $account->name;
136 if(isset($_POST['Contactslead_source']) && !empty($_POST['Contactslead_source'])){
137 $_POST['Opportunitieslead_source'] = $_POST['Contactslead_source'];
139 $opportunity= $oppForm->handleSave('Opportunities',false, false);
143 require_once('modules/Notes/NoteFormBase.php');
145 $noteForm = new NoteFormBase();
147 $_POST['AccountNotesparent_id'] = $account->id;
148 $accountnote= $noteForm->handleSave('AccountNotes',false, false);
150 $_POST['ContactNotesparent_type'] = "Contacts";
151 $_POST['ContactNotesparent_id'] = $contact->id;
152 $contactnote= $noteForm->handleSave('ContactNotes',false, false);
153 if(isset($opportunity)){
154 $_POST['OpportunityNotesparent_type'] = "Opportunities";
155 $_POST['OpportunityNotesparent_id'] = $opportunity->id;
156 $opportunitynote= $noteForm->handleSave('OpportunityNotes',false, false);
158 if(isset($_POST['newappointment']) && $_POST['newappointment']=='on' ){
159 if(isset($_POST['appointment']) && $_POST['appointment'] == 'Meeting'){
160 require_once('modules/Meetings/MeetingFormBase.php');
161 $meetingForm = new MeetingFormBase();
162 $meeting= $meetingForm->handleSave('Appointments',false, false);
164 require_once('modules/Calls/CallFormBase.php');
165 $callForm = new CallFormBase();
166 $call= $callForm->handleSave('Appointments',false, false);
171 if(isset($contact)) {
172 $call->load_relationship('contacts');
173 $call->contacts->add($contact->id);
174 } else if(isset($account)){
175 $call->load_relationship('account');
176 $call->account->add($account->id);
177 }else if(isset($opportunity)){
178 $call->load_relationship('opportunity');
179 $call->opportunity->add($opportunity->id);
183 if(isset($contact)) {
184 $meeting->load_relationship('contacts');
185 $meeting->contacts->add($contact->id);
186 } else if(isset($account)){
187 $meeting->load_relationship('account');
188 $meeting->account->add($account->id);
189 }else if(isset($opportunity)){
190 $meeting->load_relationship('opportunity');
191 $meeting->opportunity->add($opportunity->id);
195 if(isset($contact)) {
196 $account->load_relationship('contacts');
197 $account->contacts->add($contact->id);
198 } else if(isset($accountnote)){
199 $account->load_relationship('notes');
200 $account->notes->add($accountnote->id);
201 }else if(isset($opportunity)){
202 $account->load_relationship('opportunities');
203 $account->opportunities->add($opportunity->id);
206 if(isset($opportunity)){
207 if(isset($contact)) {
208 $opportunity->load_relationship('contacts');
209 $opportunity->contacts->add($contact->id);
210 } else if(isset($accountnote)){
211 $opportunity->load_relationship('notes');
212 $opportunity->notes->add($accountnote->id);
216 if(isset($contactnote)){
217 $contact->load_relationship('notes');
218 $contact->notes->add($contactnote->id);
223 $contact->track_view($current_user->id, 'Contacts');
224 if(isset($_POST['selectedContact']) && $_POST['selectedContact'] == $contact->id){
225 $xtpl->assign('ROWVALUE', "<LI>".$mod_strings['LBL_EXISTING_CONTACT']." - <a href='index.php?action=DetailView&module=Contacts&record=".$contact->id."'>".$locale->getLocaleFormattedName($contact->first_name, $contact->last_name)."</a>" );
226 $xtpl->parse('main.row');
229 $xtpl->assign('ROWVALUE', "<LI>".$mod_strings['LBL_CREATED_CONTACT']." - <a href='index.php?action=DetailView&module=Contacts&record=".$contact->id."'>".$locale->getLocaleFormattedName($contact->first_name, $contact->last_name)."</a>" );
230 $xtpl->parse('main.row');
234 $account->track_view($current_user->id, 'Accounts');
235 if(isset($_POST['selectedAccount']) && $_POST['selectedAccount'] == $account->id){
236 $xtpl->assign('ROWVALUE', "<LI>".$mod_strings['LBL_EXISTING_ACCOUNT']. " - <a href='index.php?action=DetailView&module=Accounts&record=".$account->id."'>".$account->name."</a>");
237 $xtpl->parse('main.row');
239 $xtpl->assign('ROWVALUE', "<LI>".$mod_strings['LBL_CREATED_ACCOUNT']. " - <a href='index.php?action=DetailView&module=Accounts&record=".$account->id."'>".$account->name."</a>");
240 $xtpl->parse('main.row');
244 if(isset($opportunity)){
245 $opportunity->track_view($current_user->id, 'Opportunities');
246 if(isset($_POST['selectedOpportunity']) && $_POST['selectedOpportunity'] == $opportunity->id){
247 $xtpl->assign('ROWVALUE', "<LI>".$mod_strings['LBL_EXISTING_OPPORTUNITY']. " - <a href='index.php?action=DetailView&module=Opportunities&record=".$opportunity->id."'>".$opportunity->name."</a>");
248 $xtpl->parse('main.row');
250 $xtpl->assign('ROWVALUE', "<LI>".$mod_strings['LBL_CREATED_OPPORTUNITY']. " - <a href='index.php?action=DetailView&module=Opportunities&record=".$opportunity->id."'>".$opportunity->name."</a>");
251 $xtpl->parse('main.row');
257 $call->track_view($current_user->id, 'Calls');
258 $xtpl->assign('ROWVALUE', "<LI>".$mod_strings['LBL_CREATED_CALL']. " - <a href='index.php?action=DetailView&module=Calls&record=".$call->id."'>".$call->name."</a>");
259 $xtpl->parse('main.row');
262 $meeting->track_view($current_user->id, 'Meetings');
263 $xtpl->assign('ROWVALUE', "<LI>".$mod_strings['LBL_CREATED_MEETING']. " - <a href='index.php?action=DetailView&module=Calls&record=".$meeting->id."'>".$meeting->name."</a>");
264 $xtpl->parse('main.row');
266 $xtpl->assign('ROWVALUE'," ");
267 $xtpl->parse('main.row');
268 $xtpl->assign('ROWVALUE',"<a href='index.php?module=Contacts&action=BusinessCard'>{$mod_strings['LBL_ADDMORE_BUSINESSCARD']}</a>");
269 $xtpl->parse('main.row');
270 $xtpl->parse('main');
277 $xtpl->assign('FORMHEADER',$mod_strings['LNK_NEW_CONTACT']);
278 $xtpl->parse("main.startform");
279 $xtpl->parse("main.savebegin");
280 require_once('modules/Contacts/ContactFormBase.php');
281 $xtpl->assign('OPPNEEDSACCOUNT',$mod_strings['NTC_OPPORTUNITY_REQUIRES_ACCOUNT']);
282 if ($sugar_config['require_accounts']) {
283 $xtpl->assign('CHECKOPPORTUNITY', "&& checkOpportunity()");
286 $xtpl->assign('CHECKOPPORTUNITY', "");
288 $contactForm = new ContactFormBase();
289 $xtpl->assign('FORMBODY',$contactForm->getWideFormBody('Contacts', 'Contacts', 'BusinessCard', '', false));
290 $xtpl->assign('TABLECLASS', 'edit view');
291 $xtpl->assign('CLASS', 'dataLabel');
292 require_once('modules/Notes/NoteFormBase.php');
293 $noteForm = new NoteFormBase();
294 $postform = "<h5 class='dataLabel'><input class='checkbox' type='checkbox' name='newcontactnote' onclick='toggleDisplay(\"contactnote\");'> ${mod_strings['LNK_NEW_NOTE']}</h5>";
295 $postform .= '<div id="contactnote" style="display:none">'.$noteForm->getFormBody('ContactNotes','Notes','BusinessCard', 85).'</div>';
297 $xtpl->assign('POSTFORM',$postform);
298 $xtpl->parse("main.form");
301 $xtpl->assign('HEADER', $app_strings['LBL_RELATED_RECORDS']);
302 $xtpl->parse("main.hrrow");
303 $popup_request_data = array(
304 'call_back_function' => 'set_return',
305 'form_name' => 'BusinessCard',
306 'field_to_name_array' => array(
307 'id' => 'selectedAccount',
308 'name' => 'display_account_name',
312 $json = getJSONobj();
313 $encoded_contact_popup_request_data = $json->encode($popup_request_data);
316 require_once('include/QuickSearchDefaults.php');
317 $qsd = new QuickSearchDefaults();
318 $qsd->setFormName('BusinessCard');
319 $sqs_objects = array('BusinessCard_display_account_name' => $qsd->getQSParent());
320 $sqs_objects['BusinessCard_display_account_name']['populate_list'] = array('display_account_name', 'selectedAccount');
321 $quicksearch_js = '<script type="text/javascript" language="javascript">
322 sqs_objects = ' . $json->encode($sqs_objects) . ';
323 addToValidateBinaryDependency(\'BusinessCard\', \'display_account_name\', \'alpha\', false, \'' . $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ACCOUNT'] . '\', \'selectedAccount\' );
326 $selectAccountButton = $quicksearch_js;
327 $selectAccountButton .= "<div id='newaccountdivlink' style='display:inline' class='dataLabel'>{$mod_strings['LNK_SELECT_ACCOUNT']}: <input class='sqsEnabled' name='display_account_name' id='display_account_name' type=\"text\" value=\"\"><input name='selectedAccount' id='selectedAccount' type=\"hidden\" value=''> <input type='button' title=\"{$app_strings['LBL_SELECT_BUTTON_TITLE']}\" accessKey=\"{$app_strings['LBL_SELECT_BUTTON_KEY']}\" type=\"button\" class=\"button\" value='{$app_strings['LBL_SELECT_BUTTON_LABEL']}' name=btn1 LANGUAGE=javascript onclick='open_popup(\"Accounts\", 600, 400, \"\", true, false, $encoded_contact_popup_request_data);'/> <input type='button' title=\"{$app_strings['LBL_CLEAR_BUTTON_TITLE']}\" accessKey=\"{$app_strings['LBL_CLEAR_BUTTON_KEY']}\" type=\"button\" class=\"button\" value='{$app_strings['LBL_CLEAR_BUTTON_LABEL']}' name=btn1 LANGUAGE=javascript onclick='document.forms[\"BusinessCard\"].selectedAccount.value=\"\";document.forms[\"BusinessCard\"].display_account_name.value=\"\"; '><br><b>{$app_strings['LBL_OR']}</b></div><br><br>";
328 $xtpl->assign('FORMHEADER',get_form_header($mod_strings['LNK_NEW_ACCOUNT'], '', ''));
329 require_once('modules/Accounts/AccountFormBase.php');
330 $accountForm = new AccountFormBase();
331 $xtpl->assign('CLASS', 'evenListRow');
332 $xtpl->assign('FORMBODY',$selectAccountButton."<slot class='dataLabel'><input class='checkbox' type='checkbox' name='newaccount' onclick='document.forms[\"BusinessCard\"].selectedAccount.value=\"\";document.forms[\"BusinessCard\"].display_account_name.value=\"\";toggleDisplay(\"newaccountdiv\");'> ".$mod_strings['LNK_NEW_ACCOUNT']."</slot> <div id='newaccountdiv' style='display:none'>".$accountForm->getWideFormBody('Accounts', 'Accounts','BusinessCard', '' ));
333 require_once('modules/Notes/NoteFormBase.php');
334 $noteForm = new NoteFormBase();
335 $postform = "<div id='accountnotelink'><p><a href='javascript:toggleDisplay(\"accountnote\");'>${mod_strings['LNK_NEW_NOTE']}</a></p></div>";
336 $postform .= '<div id="accountnote" style="display:none">'.$noteForm->getFormBody('AccountNotes', 'Notes', 'BusinessCard', 85).'</div>';
337 $xtpl->assign('POSTFORM',$postform);
338 $xtpl->parse("main.headlessform");
341 $xtpl->assign('FORMHEADER',get_form_header($mod_strings['LNK_NEW_OPPORTUNITY'], '', ''));
342 require_once('modules/Opportunities/OpportunityFormBase.php');
343 $oppForm = new OpportunityFormBase();
344 $xtpl->assign('CLASS', 'evenListRow');
345 $xtpl->assign('FORMBODY',"<slot class='dataLabel'><input class='checkbox' type='checkbox' name='newopportunity' onclick='toggleDisplay(\"newoppdiv\");'> ".$mod_strings['LNK_NEW_OPPORTUNITY']."</slot><div id='newoppdiv' style='display:none'>".$oppForm->getWideFormBody('Opportunities', 'Opportunities','BusinessCard', '' , false));
346 require_once('modules/Notes/NoteFormBase.php');
347 $noteForm = new NoteFormBase();
348 $postform = "<div id='oppnotelink'><a href='javascript:toggleDisplay(\"oppnote\");'>${mod_strings['LNK_NEW_NOTE']}</a></div>";
349 $postform .= '<div id="oppnote" style="display:none">'.$noteForm->getFormBody('OpportunityNotes', 'Notes','BusinessCard', 85).'</div><br>';
350 $xtpl->assign('POSTFORM',$postform);
351 $xtpl->parse("main.headlessform");
354 $xtpl->assign('FORMHEADER',$mod_strings['LNK_NEW_APPOINTMENT']);
355 require_once('modules/Calls/CallFormBase.php');
356 $callForm = new CallFormBase();
357 $xtpl->assign('FORMBODY', "<input class='checkbox' type='checkbox' name='newappointment' onclick='toggleDisplay(\"newappointmentdiv\");'> ".$mod_strings['LNK_NEW_APPOINTMENT']."<div id='newappointmentdiv' style='display:none'>".$callForm->getWideFormBody('Appointments', 'Calls',85));
358 $xtpl->assign('POSTFORM','');
359 $xtpl->parse("main.headlessform");
360 $xtpl->parse("main.saveend");
361 $xtpl->parse("main.endform");
362 $xtpl->parse("main");