Files
crm.e5.pl/modules/EcmPriceBooks/EditView1.php
2024-04-27 09:23:34 +02:00

368 lines
15 KiB
PHP
Executable File

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*****************************************************************************
* The contents of this file are subject to the RECIPROCAL PUBLIC LICENSE
* Version 1.1 ("License"); You may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/rpl.php. Software distributed under the
* License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
* either express or implied.
*
* You may:
* a) Use and distribute this code exactly as you received without payment or
* a royalty or other fee.
* b) Create extensions for this code, provided that you make the extensions
* publicly available and document your modifications clearly.
* c) Charge for a fee for warranty or support or for accepting liability
* obligations for your customers.
*
* You may NOT:
* a) Charge for the use of the original code or extensions, including in
* electronic distribution models, such as ASP (Application Service
* Provider).
* b) Charge for the original source code or your extensions other than a
* nominal fee to cover distribution costs where such distribution
* involves PHYSICAL media.
* c) Modify or delete any pre-existing copyright notices, change notices,
* or License text in the Licensed Software
* d) Assert any patent claims against the Licensor or Contributors, or
* which would in any way restrict the ability of any third party to use the
* Licensed Software.
*
* You must:
* a) Document any modifications you make to this code including the nature of
* the change, the authors of the change, and the date of the change.
* b) Make the source code for any extensions you deploy available via an
* Electronic Distribution Mechanism such as FTP or HTTP download.
* c) Notify the licensor of the availability of source code to your extensions
* and include instructions on how to acquire the source code and updates.
* d) Grant Licensor a world-wide, non-exclusive, royalty-free license to use,
* reproduce, perform, modify, sublicense, and distribute your extensions.
*
* The Original Code is: CommuniCore
* Olavo Farias
* 2006-04-7 olavo.farias@gmail.com
*
* The Initial Developer of the Original Code is CommuniCore.
* Portions created by CommuniCore are Copyright (C) 2005 CommuniCore Ltda
* All Rights Reserved.
********************************************************************************/
include("modules/EcmProducts/moduleMenu.php");
// INCLUDE SUPPPORT MODULES
require_once('XTemplate/xtpl.php');
require_once('data/Tracker.php');
// INCLUDE MODULE OBJECT AND FORMS
require_once('modules/EcmPriceBooks/EcmPriceBook.php');
require_once('modules/EcmPriceBooks/Forms.php');
global $app_strings;
global $mod_strings;
global $mod_strings;
global $current_user;
global $sugar_version, $sugar_config;
global $db;
echo 'test';
// INSTANTIATES THE MODULE CLASSES
$focus = new EcmPriceBook();
// IF PROCESSING AN EXISTING RECORD, RETRIEVE IT
if(isset($_REQUEST['record'])) {
$focus->retrieve($_REQUEST['record']);
$focus->unformat_all_fields();
}
if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
$_SESSION['pricebook_duplicate_id']=$_REQUEST['record'];
$focus->id = "";
$focus->simplemodule_number = "";
echo 't'.$_SESSION['pricebook_duplicate_id'];
}
$prefillArray = array(
'priority' => 'priority',
'name' => 'name',
'description' => 'description',
'status' => 'status',
'type' => 'type',
);
foreach($prefillArray as $requestKey => $focusVar) {
if (isset($_REQUEST[$requestKey]) && is_null($focus->$focusVar)) {
$focus->$focusVar = urldecode($_REQUEST[$requestKey]);
}
}
// BUILD MODULE TITLE LINE
echo "\n<p>\n";
echo get_module_title($mod_strings['LBL_MODULE_ID'], $mod_strings['LBL_MODULE_NAME'].": ".$focus->name, true);
echo "\n</p>\n";
global $theme;
$theme_path = "themes/".$theme."/";
$image_path = $theme_path."images/";
require_once ($theme_path.'layout_utils.php');
$GLOBALS['log']->info("EcmPriceBooks detail view");
// ASSIGN XTEMPLATE
$xtpl = new XTemplate ('modules/EcmPriceBooks/EditView.html');
// FILL XTEMPLATE MODULE & APPLICATION LANGUAGE STRINGS
$xtpl->assign("MOD", $mod_strings);
$xtpl->assign("APP", $app_strings);
$xtpl->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format());
if (isset($_REQUEST['return_module'])) $xtpl->assign("RETURN_MODULE", $_REQUEST['return_module']);
if (isset($_REQUEST['return_action'])) $xtpl->assign("RETURN_ACTION", $_REQUEST['return_action']);
if (isset($_REQUEST['return_id'])) $xtpl->assign("RETURN_ID", $_REQUEST['return_id']);
if (empty($_REQUEST['return_id'])) {
$xtpl->assign("RETURN_ACTION", 'index');
}
///////////////////////////////////////
// SETUP POPUPS START
// Users Popup
$json = getJSONobj();
$popup_request_data = array(
'call_back_function' => 'set_return',
'form_name' => 'EditView',
'field_to_name_array' => array(
'id' => 'assigned_user_id',
'user_name' => 'assigned_user_name',
),
);
$xtpl->assign('encoded_users_popup_request_data', $json->encode($popup_request_data));
$popup_request_data = array(
'call_back_function' => 'set_return',
'form_name' => 'EditView',
'field_to_name_array' => array(
'id' => 'account_id',
'name' => 'account_name',
),
);
$xtpl->assign('encoded_accounts_popup_request_data', $json->encode($popup_request_data));
$popup_request_data = array(
'call_back_function' => 'set_return',
'form_name' => 'EditView',
'field_to_name_array' => array(
'id' => 'lead_id',
'name' => 'lead_name',
),
);
$xtpl->assign('encoded_leads_popup_request_data', $json->encode($popup_request_data));
//
////////////////////////////////////////////////////////////////////////////////
// ACCOUNT_ID WILL BE SET WHEN USER CHOOSES TO CREATE A NEW SIMPLEMODULE FROM ACCOUNT DETAIL VIEW.
if (isset($_REQUEST['account_id'])) $xtpl->assign("ACCOUNT_ID", $_REQUEST['account_id']);
if (isset($_REQUEST['contact_id'])) $xtpl->assign("CONTACT_ID", $_REQUEST['contact_id']);
// SET THE CASE_ID, IF SET.
// WITH NEW CONCEPT OF SUBPANELS IT,
// WHEN THE SUBPANEL IS DISPLAYED IT PULLS FROM THE CLASS NAME WHICH IN THE SITUATION OF CASES IS ACASE SO THE FORM IS GENERATED
// WITH ACASE_ID INSTEAD OF CASE_ID, SO I HAVE DONE THE MAPPING HERE
if (isset($_REQUEST['acase_id'])) $xtpl->assign("CASE_ID",$_REQUEST['acase_id']);
else if(isset($_REQUEST['case_id'])) $xtpl->assign("CASE_ID",$_REQUEST['case_id']);
////////////////////////////////////////////////////////////////////////////////
// QUICK SEARCH SETUP
require_once('include/QuickSearchDefaults.php');
$qsd = new QuickSearchDefaults();
$sqs_objects = array(
'assigned_user_name' => $qsd->getQSUser(),
'account_name' => array(
'method' => 'query',
'modules' => array('Accounts'),
'group' => 'or',
'field_list' => array('name', 'id'),
'populate_list' => array('account_name', 'account_id'),
'conditions' => array(array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')),
'order' => 'name',
'limit' => '30',
'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
),
'lead_name' => array(
'method' => 'query',
'modules' => array('Leads'),
'group' => 'or',
'field_list' => array('last_name', 'id'),
'populate_list' => array('lead_name', 'lead_id'),
'conditions' => array(array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')),
'order' => 'last_name',
'limit' => '30',
'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
),
/*
//BUILDER:START Pro only
'team_name' => $qsd->getQSTeam()
//BUILDER:END Pro only
*/
);
$quicksearch_js = $qsd->getQSScripts();
$quicksearch_js .= '<script type="text/javascript" language="javascript">sqs_objects = ' . $json->encode($sqs_objects) . '</script>';
// QUICK SEARCH SETUP
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ASSIGN GLOBAL VARIABLES
$xtpl->assign("THEME", $theme);
$xtpl->assign("IMAGE_PATH", $image_path);$xtpl->assign("PRINT_URL", "index.php?".$GLOBALS['request_string']);
$xtpl->assign("JAVASCRIPT", get_set_focus_js().get_validate_record_js(). $quicksearch_js);
$xtpl->assign("USER_DATEFORMAT", '('. $timedate->get_user_date_format().')');
$xtpl->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format());
// ASSIGN GLOBAL VARIABLES
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ASSIGN MODULE DEFAULT VARIABLES
$xtpl->assign("ID", $focus->id);
if (!empty($focus->name))
$xtpl->assign("NAME", $focus->name);
else $xtpl->assign("NAME", "");
$xtpl->assign("DATE_ENTERED", $focus->date_entered);
$xtpl->assign("DATE_MODIFIED", $focus->date_modified);
$xtpl->assign("CREATED_BY", $focus->created_by_name);
$xtpl->assign("MODIFIED_BY", $focus->modified_by_name);
if (empty($focus->assigned_user_id) && empty($focus->id)) $focus->assigned_user_id = $current_user->id;
if (empty($focus->assigned_name) && empty($focus->id)) $focus->assigned_user_name = $current_user->user_name;
$xtpl->assign("ASSIGNED_USER_OPTIONS", get_select_options_with_id(get_user_array(TRUE, "Active", $focus->assigned_user_id), $focus->assigned_user_id));
$xtpl->assign("ASSIGNED_USER_NAME", $focus->assigned_user_name);
$xtpl->assign("ASSIGNED_USER_ID", $focus->assigned_user_id );
// ASSIGN MODULE SPECIFIC VARIABLES
if (!empty($_REQUEST['active'])) {
$xtpl->assign("ACTIVE", "checked");
}
if ($focus->active == '1') $xtpl->assign("ACTIVE", "checked");
$xtpl->assign("DESCRIPTION", $focus->description);
$xtpl->assign("EXCHANGE_RATE_NAME", $focus->exchange_rate_name);
$xtpl->assign("EXCHANGE_RATE_ID", $focus->exchange_rate_id);
$xtpl->assign("ACCOUNT_NAME", $focus->account_name);
$xtpl->assign("ACCOUNT_ID", $focus->account_id);
$xtpl->assign("LEAD_NAME", $focus->lead_name);
$xtpl->assign("LEAD_ID", $focus->lead_id);
//load currencies
require_once('modules/Currencies/Currency.php');
$currency = new Currency();
$currency_list = $currency->get_full_list('name');
$currency->retrieve('-99');
if(is_array($currency_list))
{
$currency_list = array_merge(Array($currency), $currency_list);
}
else
{
$currency_list = Array($currency);
}
$arr = array();
foreach($currency_list as $key=>$value)
{
$arr[$value->id] = $value->name;
}
$xtpl->assign("EXCHANGE_RATE_ID", get_select_options_with_id($arr, $focus->exchange_rate_id));
// ASSIGN MODULE DROPDOWNS WITH DEFAULT KEY
// ASSIGN MODULE VARIABLES AFFECTED BY DUPLICATE ACTION
if(!isset($_REQUEST['isDuplicate'])) {
$focus->id = "";
}
// ASSIGN MODULE DROPDOWNS WITHOUT DEFAULT KEY
//BUILDER:END of xtpl
// ADD CUSTOM FIELDS
require_once('modules/DynamicFields/templates/Files/EditView.php');
////////////////////////////////////////////////////////////////////////////////
// USER ASSIGNMENT
global $current_user;
if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
$record = '';
// USER ASSIGNMENT
////////////////////////////////////////////////////////////////////////////////
if(!empty($_REQUEST['record'])){
$record = $_REQUEST['record'];
}
$xtpl->assign("ADMIN_EDIT","<a href='index.php?action=index&module=DynamicLayout&from_action=".$_REQUEST['action'] ."&from_module=".$_REQUEST['module'] ."&record=".$record. "'>".get_image($image_path."EditLayout","border='0' alt='Edit Layout' align='bottom'")."</a>");
}
$xtpl->parse("main");
$xtpl->out("main");
require_once('include/javascript/javascript.php');
$javascript = new javascript();
$javascript->setFormName('EditView');
$javascript->setSugarBean($focus);
$javascript->addAllFields('');
//BUILDER:START Pro only
// $javascript->addFieldGeneric( 'team_name', 'varchar', $app_strings['LBL_TEAM'] ,'true');
// $javascript->addToValidateBinaryDependency('team_name', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_TEAM'], 'false', '', 'team_id');
//BUILDER:END Pro only
$javascript->addToValidateBinaryDependency('assigned_user_name', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ASSIGNED_TO'], 'false', '', 'assigned_user_id');
echo $javascript->getScript();
////////////////////////////////////////////////////////////////////////////////
/// SELECT CHANGES TEXT INPUT FIELD
/*
$prob_array = $json->encode($app_list_strings['sales_probability_dom']);
$prePopProb = '';
if(empty($focus->id)) $prePopProb = 'document.getElementsByName(\'sales_stage\')[0].onchange();';
echo <<<EOQ
<script>
prob_array = $prob_array;
document.getElementsByName('sales_stage')[0].onchange = function() {
if(typeof(document.getElementsByName('sales_stage')[0].value) != "undefined" && prob_array[document.getElementsByName('sales_stage')[0].value]) {
document.getElementsByName('probability')[0].value = prob_array[document.getElementsByName('sales_stage')[0].value];
}
};
$prePopProb
</script>
EOQ;
*/
//
/// SELECT CHANGES TEXT INPUT FIELD
////////////////////////////////////////////////////////////////////////////////
require_once('modules/SavedSearch/SavedSearch.php');
$savedSearch = new SavedSearch();
$json = getJSONobj();
$savedSearchSelects = $json->encode(array($GLOBALS['app_strings']['LBL_SAVED_SEARCH_SHORTCUT'] . '<br>' . $savedSearch->getSelect('EcmPriceBooks')));
$str = "<script>
YAHOO.util.Event.addListener(window, 'load', SUGAR.util.fillShortcuts, $savedSearchSelects);
</script>";
echo $str;
?>