Files
crm.twinpol.com/modules/EcmDocs/EditView.php
2025-05-12 15:44:39 +00:00

496 lines
20 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.
********************************************************************************/
//*****************************************************************
if(!function_exists('calculateGMT')) {
function calculateGMT() {
static $gmt;
if(!isset($gmt)) {
global $timedate;
$dd = gmdate("Y-m-d H:i:s");
$dd2 = $timedate->handle_offset($dd, "Y-m-d H:i:s", true);
$gmt = strtotime($dd2) - strtotime($dd);
}
return $gmt;
}
}
//*****************************************************************
$_SESSION['email_id']=$_REQUEST['inbound_email_id'];
$_REQUEST['inbound_email_id']="";
if($_SESSION['email_id'])
{
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select emails.name as name,emails_text.description description,emails.parent_id,emails.parent_type from emails inner join emails_text on emails_text.email_id=emails.id where emails.id='".$_SESSION['email_id']."'"));
$description_email=$r['description'];
$name_email=$r['name'];
$query = "select filename,id from notes where parent_id='".$_SESSION['email_id']."' and parent_type='Emails'";
$w=$GLOBALS['db']->query($query);
$i=0;
$msel='<select ondblclick="location.href=\'download.php?id=\'+this.value.replace(\'cache/upload/\',\'\')+\'&type=Notes\'" id="efiles" name="efiles[]" size="6" multiple="multiple" tabindex="6">';
while($r=$GLOBALS['db']->fetchByAssoc($w))
{
$_SESSION['filename_email'][$i]['filename']=$sugar_config['upload_dir'].$r['id'];
$_SESSION['filename_email'][$i]['name']=$r['filename'];
$_SESSION['emails_files']=1;
$msel.='<option value="'.$_SESSION['filename_email'][$i]['filename'].'" selected>'.$_SESSION['filename_email'][$i]['name'].'</option>';
$i++;
}
$nmail=$i;
$msel.="</select>";
$_SESSION['email_id']="";
}
if($_REQUEST['samba_file'])
{
$expn=explode("/",$_REQUEST['samba_file']);
$filename=$expn[count($expn)-1];
$path=str_replace($filename,"",$_REQUEST['samba_file']);
$exp=explode("/",str_replace("[s]"," ",$_REQUEST['samba_file']));
$sname=$exp[count($exp)-1];
$msel='<select id="sfiles" name="sfiles[]" size="6" multiple="multiple"><option ondblclick="location.href=\'DownloadSMB.php?ps='.$path.'&file='.$filename.'\';" value="'.str_replace("[s]"," ",$_REQUEST['samba_file']).'" selected>'.$sname.'</option></select>';
$msel.="</select>";
}
// INCLUDE SUPPPORT MODULES
require_once('XTemplate/xtpl.php');
require_once('data/Tracker.php');
// INCLUDE MODULE OBJECT AND FORMS
require_once('modules/EcmDocs/EcmDoc.php');
require_once('modules/EcmDocs/Forms.php');
global $app_strings;
global $mod_strings;
global $mod_strings;
global $current_user;
global $sugar_version, $sugar_config;
// INSTANTIATES THE MODULE CLASSES
$focus = new EcmDoc();
// IF PROCESSING AN EXISTING RECORD, RETRIEVE IT
if(isset($_REQUEST['record'])) {
$focus->retrieve($_REQUEST['record']);
$focus->format_all_fields();
}
if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
$focus->id = "";
$focus->simplemodule_number = "";
}
$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("EcmDocs detail view");
// ASSIGN XTEMPLATE
$xtpl = new XTemplate ('modules/EcmDocs/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',
),
);
$json = getJSONobj();
$xtpl->assign('encoded_account_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' => 'contact_id',
'name' => 'contact_name',
),
);
$json = getJSONobj();
$xtpl->assign('encoded_contact_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('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']
),
'contact_name' => array(
'method' => 'query',
'modules' => array('Contacts'),
'group' => 'or',
'field_list' => array('name', 'id'),
'populate_list' => array('contact_name', 'contact_id'),
'conditions' => array(array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')),
'order' => 'name',
'limit' => '30',
'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
),
'assigned_user_name' => $qsd->getQSUser()
);
$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);
$xtpl->assign("DB_ID", $_REQUEST['db_id']);
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 );
if(!$_REQUEST['record'])$xtpl->assign("ONSUBMITFILE",' onSubmit="return showuploadingafile();"');
if($_REQUEST['return_module']=="Accounts" && $_REQUEST['return_id']){
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select name from accounts where id='".$_REQUEST['return_id']."'"));
$focus->account_id=$_REQUEST['return_id'];
$focus->account_name=$r['name'];
}
// ASSIGN MODULE SPECIFIC VARIABLES
$group="<select name='group_id' tabindex='8'>";
$z="select id,name from ecmdocs_group where deleted='0' order by name asc";
$w=$GLOBALS['db']->query($z);
while($r=$GLOBALS['db']->fetchByAssoc($w))
{
$group.="<option value='".$r['id']."'";
if($r['id']==$focus->group_id)$group.=" selected";
$group.=">".$r['name']."</option>";
}
$group.="</select>";
$xtpl->assign("GROUP", $group);
$xtpl->assign("UID", $_REQUEST['uid']);
$xtpl->assign("IEID", $_REQUEST['ieId']);
$xtpl->assign("DESCRIPTION", $focus->description);
$xtpl->assign("GROUP_ID", $focus->group_id);
$xtpl->assign("GROUP_NAME", $focus->group_name);
$xtpl->assign("ACCOUNT_ID", $focus->account_id);
$xtpl->assign("ACCOUNT_NAME", $focus->account_name);
$xtpl->assign("CONTACT_ID", $focus->contact_id);
$xtpl->assign("CONTACT_NAME", $focus->contact_name);
$xtpl->assign("RELATION", $focus->relation);
$rs = $GLOBALS['db']->query("select reminder_time,date,reminder_date from ecmdocs where id='".$_REQUEST['record']."'");
if($rs && is_resource($rs)) $r=$GLOBALS['db']->fetchByAssoc($rs);
$xtpl->assign("WORTH", $focus->value);
if(!$_REQUEST['record'])$date=$timedate->to_display(date("Y-m-d"), "Y-m-d", $timedate->get_date_format());
else $date=$timedate->to_display($r['date'], "Y-m-d", $timedate->get_date_format());
$xtpl->assign("DATE", $date);
if(!$_REQUEST['record'] || $r['reminder_time'] == -1)$r_date=$timedate->to_display_date(gmdate("Y-m-d"));
else
{
$exp=explode(" ",$r['reminder_date']);
$exp1=$exp[0];
$exp2=$exp[1];
$expd=explode("-",$exp1);
$expt=explode(":",$exp2);
$rdate=@mktime($expt[0],$expt[1],$expt[2],$expd[1],$expd[2],$expd[0]);
$rdate=date("Y-m-d H:i:s",$rdate+calculateGMT());
$exp=explode(" ",$rdate);
$exp1=$exp[0];
$exp2=$exp[1];
$expd=explode("-",$exp1);
$expt=explode(":",$exp2);
$r_date=$timedate->to_display($exp1, "Y-m-d", $timedate->get_date_format());
}
$xtpl->assign("REMINDER_DATE", $r_date);
if(!$_REQUEST['record'] || $r['reminder_time'] == -1)$expt[0]= date("H",strtotime(gmdate("Y-m-d H:i:s"))+calculateGMT());
$xtpl->assign("HOUR", $expt[0]);
if(!$_REQUEST['record'] || $r['reminder_time'] == -1)$expt[1]=date("i",strtotime(gmdate("Y-m-d H:i:s"))+calculateGMT());
$xtpl->assign("MINUTES", $expt[1]);
// 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->assign("DESCRIPTION", $focus->description);
$xtpl->assign("INBOUND_EMAIL_ID", $_GET['inbound_email_id']);
$xtpl->assign("SAMBA_FILE", $_REQUEST['samba_file']);
if($_REQUEST['samba_file'])$xtpl->assign("NAME",str_replace(".pdf","",str_replace(".doc","",str_replace(".jpg","",str_replace(".gif","",str_replace(".txt","",$sname))))));
if($_GET['inbound_email_id'] || $_REQUEST['samba_file'])
{
$xtpl->assign("MSEL", $msel);
$xtpl->assign("DMSEL", $mod_strings['LBL_FILES_TO_SAVE']);
if($nmail>=1)$mcheck=" checked";
else $mcheck="";
if(!$_REQUEST['samba_file'])
{
$xtpl->assign("EMAILCHECK", '<input type="checkbox" tabindex="5" name="emaildel" value="1"'.$mcheck.'>');
$xtpl->assign("DEMAILCHECK", "Would you like to delete this mail?");
$xtpl->assign("BACKTOEMAILS", "Back to Emails");
$xtpl->assign("BACKTOEMAILSCHECK", '<input type="checkbox" tabindex="5" name="backtoemails" value="1" checked>');
}
}
else
{
$xtpl->assign("FILEINPUT", '<input name="filename" id="filename" title="Filename" type="file" tabindex="8" maxlength="255">');
$xtpl->assign("DFILEINPUT", $mod_strings['LBL_FILE'].'<span class="required"> *</span>');
}
if($name_email )$xtpl->assign("NAME",str_replace(".pdf","",str_replace(".doc","",str_replace(".jpg","",str_replace(".gif","",str_replace(".txt","",$name_email))))));
if($description_email)$xtpl->assign("DESCRIPTION",$description_email);
require_once("modules/EcmDocs/time_select.php");
$rs = $GLOBALS['db']->query("select reminder_time from ecmdocs where id='".$_REQUEST['record']."'");
if($rs && is_resource($rs)) $r=$GLOBALS['db']->fetchByAssoc($rs);
$reminder_time=$r['reminder_time'];
$time_select=show_time_select($reminder_time);
$xtpl->assign("REMINDER_TIME_OPTIONS", $time_select);
if (empty ($reminder_time)) {
$reminder_time = -1;
}
if ($reminder_time > -1) {
$xtpl->assign("REMINDER_TIME_DISPLAY", 'inline');
$xtpl->assign("REMINDER_CHECKED", 'checked');
} else {
$xtpl->assign("REMINDER_TIME_DISPLAY", 'none');
}
$status.='<option value="Planned"';
if($focus->status=="Planned" || $_REQUEST['status']=="Planned")$status.=' selected';
$status.='>Planned</option>';
$status.='<option value="Held"';
if($focus->status=="Held" || $_REQUEST['status']=="Held")$status.=' selected';
$status.='>Held</option>';
$xtpl->assign("STATUS",$status);
$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');
$javascript->addToValidateBinaryDependency('account_name', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ACCOUNT_NAME'], 'false', '', 'account_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('EcmDocs')));
$str = "<script>
YAHOO.util.Event.addListener(window, 'load', SUGAR.util.fillShortcuts, $savedSearchSelects);
</script>";
echo $str;
?>